use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class IDLProcessor method process.
public void process() throws ToolException {
String location = env.get(ToolCorbaConstants.CFG_IDLFILE).toString();
File file = new File(location).getAbsoluteFile();
if (!file.exists()) {
throw new ToolException("IDL file " + file.getName() + " doesn't exist");
}
try {
URL orig = file.toURI().toURL();
DefaultIncludeResolver includeResolver = getDefaultIncludeResolver(file.getParentFile());
DefineState defineState = new DefineState(new HashMap<String, String>());
preprocessor = new IdlPreprocessorReader(orig, location, includeResolver, defineState);
IDLLexer lexer = new IDLLexer(new java.io.LineNumberReader(preprocessor));
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
TokenStreamHiddenTokenFilter filter = new TokenStreamHiddenTokenFilter(lexer);
filter.discard(IDLTokenTypes.WS);
filter.hide(IDLTokenTypes.SL_COMMENT);
filter.hide(IDLTokenTypes.ML_COMMENT);
parser = new IDLParser(filter);
parser.setASTNodeClass("antlr.CommonASTWithHiddenTokens");
parser.specification();
} catch (Exception ex) {
throw new ToolException(ex);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class IDLToWSDLProcessor method process.
public void process(AST idlTree) throws ToolException {
idl = getBaseFilename(env.get(ToolCorbaConstants.CFG_IDLFILE).toString());
checkFileOptions();
try {
parseIDL(idlTree);
} catch (Exception e) {
throw new ToolException(e);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToIDL method execute.
public void execute(boolean exitOnFinish) {
WSDLToCorbaProcessor corbaProcessor = new WSDLToCorbaProcessor();
ProcessorEnvironment env = null;
try {
super.execute(exitOnFinish);
if (!hasInfoOption()) {
env = new ProcessorEnvironment();
env.setParameters(getParametersMap(getArrayKeys()));
if (isVerboseOn()) {
env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
}
env.put(ToolConstants.CFG_CMD_ARG, args);
CommandDocument doc = super.getCommandDocument();
if (doc.hasParameter("corba")) {
env.put(ToolCorbaConstants.CFG_CORBA, Boolean.TRUE);
}
if (doc.hasParameter("idl")) {
env.put(ToolCorbaConstants.CFG_IDL, Boolean.TRUE);
}
initialise(env);
validate(env);
corbaProcessor.setEnvironment(env);
corbaProcessor.process();
}
} catch (ToolException ex) {
err.println("Error : " + ex.getMessage());
if (ex.getCause() instanceof BadUsageException) {
printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
}
err.println();
if (isVerboseOn()) {
ex.printStackTrace(err);
}
throw ex;
} catch (Exception ex) {
err.println("Error : " + ex.getMessage());
err.println();
if (isVerboseOn()) {
ex.printStackTrace(err);
}
throw new ToolException(ex.getMessage(), ex.getCause());
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToCorbaBinding method generateCORBAServiceForBinding.
private void generateCORBAServiceForBinding(Definition definition, PortType portType, Binding binding) throws Exception {
if (extReg == null) {
extReg = def.getExtensionRegistry();
}
String interfaceName = portType.getQName().getLocalPart();
interfaceName = mangleInterfaceName(interfaceName);
String serviceName = interfaceName + "CORBAService";
String portName = interfaceName + "CORBAPort";
String prefix = definition.getPrefix(definition.getTargetNamespace());
if (prefix == null) {
prefix = "";
}
String corbaPrefix = definition.getPrefix(CorbaConstants.NU_WSDL_CORBA);
if (corbaPrefix == null) {
corbaPrefix = "corba";
def.addNamespace(corbaPrefix, CorbaConstants.NU_WSDL_CORBA);
}
// Build the service and port information and add it to the wsdl
Service service = def.createService();
Port servicePort = def.createPort();
servicePort.setName(portName);
servicePort.setBinding(binding);
try {
AddressType addressType = (AddressType) def.getExtensionRegistry().createExtension(Port.class, CorbaConstants.NE_CORBA_ADDRESS);
String addr = null;
if (getAddressFile() != null) {
BufferedReader bufferedReader = null;
try {
File addrFile = new File(getAddressFile());
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 = getAddress();
}
if (addr == null) {
addr = "file:./" + interfaceName + ".ref";
}
addressType.setLocation(addr);
servicePort.addExtensibilityElement((ExtensibilityElement) addressType);
} catch (WSDLException ex) {
throw new Exception("Failed to create CORBA address for service", ex);
}
QName serviceQName = new QName(definition.getTargetNamespace(), serviceName, prefix);
service.setQName(serviceQName);
service.addPort(servicePort);
definition.addService(service);
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToCorbaProcessor method process.
public void process() throws ToolException {
Definition def = null;
env = getEnvironment();
try {
// if the corba option is specified - generates wsdl
if (env.optionSet(ToolCorbaConstants.CFG_CORBA)) {
wsdlToCorbaBinding = new WSDLToCorbaBinding();
}
if (env.optionSet(ToolCorbaConstants.CFG_IDL)) {
// if idl option specified it generated idl
idlAction = new WSDLToIDLAction();
}
if (wsdlToCorbaBinding == null && idlAction == null) {
wsdlToCorbaBinding = new WSDLToCorbaBinding();
idlAction = new WSDLToIDLAction();
}
setOutputFile();
String filename = getFileBase(env.get("wsdlurl").toString());
if ((wsdlOutput == null) && (wsdlToCorbaBinding != null)) {
wsdlOutput = filename + "-corba.wsdl";
}
if ((idlOutput == null) && (idlAction != null)) {
idlOutput = filename + ".idl";
}
if (wsdlToCorbaBinding != null) {
wsdltoCorba();
def = wsdlToCorbaBinding.generateCORBABinding();
writeToWSDL(def);
}
if (idlAction != null) {
wsdltoIdl();
idlAction.generateIDL(def);
writeToIDL(def);
}
} catch (ToolException ex) {
throw ex;
} catch (JAXBException ex) {
throw new ToolException(ex);
} catch (Exception ex) {
throw new ToolException(ex);
}
}
Aggregations