Search in sources :

Example 66 with ToolException

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);
    }
}
Also used : DefaultIncludeResolver(org.apache.cxf.tools.corba.idlpreprocessor.DefaultIncludeResolver) TokenStreamHiddenTokenFilter(antlr.TokenStreamHiddenTokenFilter) URL(java.net.URL) IdlPreprocessorReader(org.apache.cxf.tools.corba.idlpreprocessor.IdlPreprocessorReader) ToolException(org.apache.cxf.tools.common.ToolException) DefineState(org.apache.cxf.tools.corba.idlpreprocessor.DefineState) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File)

Example 67 with ToolException

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);
    }
}
Also used : ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 68 with ToolException

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());
    }
}
Also used : BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) WSDLToCorbaProcessor(org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaProcessor) ProcessorEnvironment(org.apache.cxf.tools.corba.common.ProcessorEnvironment) CommandDocument(org.apache.cxf.tools.common.toolspec.parser.CommandDocument) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException)

Example 69 with ToolException

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);
}
Also used : WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) BufferedReader(java.io.BufferedReader) Service(javax.wsdl.Service) FileReader(java.io.FileReader) ToolException(org.apache.cxf.tools.common.ToolException) AddressType(org.apache.cxf.binding.corba.wsdl.AddressType) File(java.io.File) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 70 with ToolException

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);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) Definition(javax.wsdl.Definition) ToolException(org.apache.cxf.tools.common.ToolException) JAXBException(javax.xml.bind.JAXBException) ToolException(org.apache.cxf.tools.common.ToolException)

Aggregations

ToolException (org.apache.cxf.tools.common.ToolException)129 Message (org.apache.cxf.common.i18n.Message)69 IOException (java.io.IOException)38 File (java.io.File)30 QName (javax.xml.namespace.QName)19 WSDLException (javax.wsdl.WSDLException)18 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)16 ToolContext (org.apache.cxf.tools.common.ToolContext)15 XMLStreamException (javax.xml.stream.XMLStreamException)14 FileNotFoundException (java.io.FileNotFoundException)12 Test (org.junit.Test)12 Element (org.w3c.dom.Element)10 InputStream (java.io.InputStream)9 Writer (java.io.Writer)9 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)8 WSDLWriter (javax.wsdl.xml.WSDLWriter)7