use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class IDLToWSDLProcessor method addTypeMapSchemaImports.
public void addTypeMapSchemaImports(Definition def, WSDLASTVisitor visitor) {
List<CorbaType> types = visitor.getTypeMap().getStructOrExceptionOrUnion();
ModuleToNSMapper mapper = visitor.getModuleToNSMapper();
WSDLSchemaManager manager = visitor.getManager();
Collection<String> namespaces = CastUtils.cast(def.getNamespaces().values());
Set<Map.Entry<String, String>> userModuleMappings = mapper.getUserMapping().entrySet();
if (types != null) {
for (int i = 0; i < types.size(); i++) {
CorbaType type = types.get(i);
QName schemaType = type.getType();
if (schemaType != null) {
String typeNamespace = schemaType.getNamespaceURI();
try {
// a remote location.
if (!namespaces.contains(typeNamespace) && typeNamespace.equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
// build up the ws-addressing schema import
Schema wsdlSchema = (Schema) def.getExtensionRegistry().createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));
SchemaImport schemaimport = wsdlSchema.createImport();
schemaimport.setNamespaceURI(ReferenceConstants.WSADDRESSING_NAMESPACE);
schemaimport.setSchemaLocationURI(ReferenceConstants.WSADDRESSING_LOCATION);
wsdlSchema.addImport(schemaimport);
// add the import and the prefix to the definition
def.getTypes().addExtensibilityElement(wsdlSchema);
CastUtils.cast(def.getNamespaces(), String.class, String.class).put(ReferenceConstants.WSADDRESSING_PREFIX, typeNamespace);
} else if (!namespaces.contains(typeNamespace)) {
String prefix = getModulePrefixForNamespace(userModuleMappings, mapper, typeNamespace);
// prefix = mapper.mapNSToPrefix(typeNamespace);
XmlSchema schema = manager.getXmlSchema(typeNamespace);
// TODO: REVISIT - Is this the only way we can create the file name for the
// imported schema?
String importFile = visitor.getOutputDir() + System.getProperty("file.separator") + prefix + ".xsd";
manager.addWSDLSchemaImport(def, typeNamespace, importFile);
manager.getImportedXmlSchemas().put(new File(importFile), schema);
CastUtils.cast(def.getNamespaces(), String.class, String.class).put(prefix, typeNamespace);
}
} catch (Exception ex) {
throw new ToolException("Unable to add schema import for namespace" + typeNamespace);
}
}
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class IDLToWSDLProcessor method generateCORBAService.
public void generateCORBAService(Definition def, Binding[] bindings, boolean isDefaultMapping) throws Exception {
Map<String, Service> serviceMap = new HashMap<>();
Map<String, String> serviceNames = getServiceNames(bindings, isDefaultMapping);
for (int i = 0; i < bindings.length; i++) {
QName portTypeName = bindings[i].getPortType().getQName();
Service service;
if (isDefaultMapping) {
service = def.createService();
service.setQName(new QName(def.getTargetNamespace(), portTypeName.getLocalPart() + "CORBAService"));
def.addService(service);
} else {
String ns = portTypeName.getNamespaceURI();
String serviceName = serviceNames.get(ns);
service = serviceMap.get(ns);
if (service == null) {
service = def.createService();
serviceMap.put(ns, service);
String[] serviceTokens = serviceName.split("\\.");
String serviceToken = serviceTokens[serviceTokens.length - 1];
QName serviceQName = new QName(def.getTargetNamespace(), serviceToken);
Service existingService = def.getService(serviceQName);
if (existingService != null) {
String existingServiceNS = ((Port) existingService.getPorts().values().iterator().next()).getBinding().getPortType().getQName().getNamespaceURI();
existingService.setQName(new QName(def.getTargetNamespace(), serviceNames.get(existingServiceNS)));
serviceMap.put(existingServiceNS, existingService);
service.setQName(new QName(def.getTargetNamespace(), serviceName));
} else {
service.setQName(serviceQName);
}
def.addService(service);
}
}
Port port = def.createPort();
port.setName(portTypeName.getLocalPart() + "CORBAPort");
AddressType address = (AddressType) def.getExtensionRegistry().createExtension(Port.class, CorbaConstants.NE_CORBA_ADDRESS);
String addr = null;
String addrFileName = (String) env.get(ToolCorbaConstants.CFG_ADDRESSFILE);
if (addrFileName != null) {
BufferedReader bufferedReader = null;
try {
File addrFile = new File(addrFileName);
FileReader fileReader = new FileReader(addrFile);
bufferedReader = new BufferedReader(fileReader);
addr = bufferedReader.readLine();
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
} else {
addr = (String) env.get(ToolCorbaConstants.CFG_ADDRESS);
}
if (addr == null) {
addr = "IOR:";
}
address.setLocation(addr);
port.addExtensibilityElement((ExtensibilityElement) address);
service.addPort(port);
port.setBinding(bindings[i]);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class IDLToWSDLProcessor method parseIDL.
public void parseIDL(AST idlTree) throws Exception {
if (env.isVerbose()) {
System.out.println(idlTree.toStringTree());
}
// target namespace
String tns = (String) env.get(ToolCorbaConstants.CFG_TNS);
if (tns == null) {
tns = CorbaConstants.WSDL_NS_URI + idl;
}
// XmlSchema namespace
String schemans = (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE);
// corba typemap namespace
String corbatypemaptns = (String) env.get(ToolCorbaConstants.CFG_CORBATYPEMAP_NAMESPACE);
outputDir = ".";
try {
WSDLASTVisitor visitor = new WSDLASTVisitor(tns, schemans, corbatypemaptns, preprocessor.getPragmaPrefix());
visitor.getManager().setIgnoreImports(ignoreImports);
if (env.optionSet(ToolConstants.CFG_OUTPUTDIR)) {
outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
}
visitor.setOutputDir(outputDir);
Definition def = visitor.getDefinition();
if (env.optionSet(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE)) {
visitor.setSequenceOctetType((String) env.get(ToolCorbaConstants.CFG_SEQUENCE_OCTET_TYPE));
}
if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE)) {
// visitor.getDefinition()
def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX, (String) env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE));
}
if (env.optionSet(ToolCorbaConstants.CFG_BOUNDEDSTRINGS)) {
visitor.setBoundedStringOverride(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_MODULETONS)) {
String mapping = (String) env.get(ToolCorbaConstants.CFG_MODULETONS);
// parse the mapping & set a map of module to namespace mapping in the visitor
visitor.setModuleToNSMapping(getModuleToNSMapping(mapping));
}
if (env.optionSet(ToolCorbaConstants.CFG_QUALIFIED)) {
visitor.setQualified(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_POLYMORPHIC_FACTORIES)) {
visitor.setSupportPolymorphicFactories(true);
}
if (env.optionSet(ToolCorbaConstants.CFG_SCHEMA)) {
visitor.setSchemaGenerated(true);
// generate default namespace for schema if -T is used alone.
if (env.get(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE) == null) {
visitor.updateSchemaNamespace(def.getTargetNamespace() + "-types");
def.addNamespace(ToolCorbaConstants.CFG_SCHEMA_NAMESPACE_PREFIX, def.getTargetNamespace() + "-types");
}
}
if (env.optionSet(ToolCorbaConstants.CFG_EXCLUDEMODULES)) {
String modules = (String) env.get(ToolCorbaConstants.CFG_EXCLUDEMODULES);
// parse the mapping & set a map of module to namespace mapping in the visitor
visitor.setExcludedModules(getExcludedModules(modules));
}
visitor.visit(idlTree);
cleanUpTypeMap(visitor.getTypeMap());
Binding[] bindings = visitor.getCorbaBindings();
generateCORBAService(def, bindings, visitor.getModuleToNSMapper().isDefaultMapping());
writeDefinitions(visitor);
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToService method execute.
public void execute(boolean exitOnFinish) {
WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
try {
super.execute(exitOnFinish);
if (!hasInfoOption()) {
ToolContext env = new ToolContext();
env.setParameters(getParametersMap(getArrayKeys()));
if (isVerboseOn()) {
env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
}
env.put(ToolConstants.CFG_CMD_ARG, getArgument());
validate(env);
processor.setEnvironment(env);
processor.process();
}
} catch (ToolException ex) {
if (ex.getCause() instanceof BadUsageException) {
printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
}
err.println();
err.println("WSDLToService Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} catch (Exception ex) {
err.println();
err.println("WSDLToService Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} finally {
tearDown();
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToSoap method execute.
public void execute(boolean exitOnFinish) {
WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
try {
super.execute(exitOnFinish);
if (!hasInfoOption()) {
ToolContext env = new ToolContext();
env.setParameters(getParametersMap(getArrayKeys()));
if (isVerboseOn()) {
env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
}
env.put(ToolConstants.CFG_CMD_ARG, getArgument());
validate(env);
setEnvParamDefValues(env);
processor.setEnvironment(env);
processor.process();
}
} catch (ToolException ex) {
if (ex.getCause() instanceof BadUsageException) {
printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
}
err.println();
err.println("WSDLToSoap Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} catch (Exception ex) {
err.println();
err.println("WSDLToSoap Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} finally {
tearDown();
}
}
Aggregations