Search in sources :

Example 6 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class AbstractToolContainer method getBus.

public Bus getBus() {
    Bus bus = BusFactory.getDefaultBus();
    OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);
    String catalogLocation = getCatalogURL();
    if (!StringUtils.isEmpty(catalogLocation)) {
        try {
            catalogManager.loadCatalog(new URI(catalogLocation).toURL());
        } catch (Exception e) {
            e.printStackTrace(err);
            throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG, catalogLocation));
        }
    }
    return bus;
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.common.i18n.Message) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) URI(java.net.URI) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException)

Example 7 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project tomee by apache.

the class CxfCatalogUtils method loadOASISCatalog.

private static void loadOASISCatalog(Bus bus, URL catalogURL) {
    OASISCatalogManager catalog = new OASISCatalogManager();
    try {
        catalog.loadCatalog(catalogURL);
        logger.debug("Loaded " + catalogURL + " catalog.");
        bus.setExtension(catalog, OASISCatalogManager.class);
    } catch (IOException e) {
        logger.warning("Failed to load catalog file: " + catalogURL, e);
    }
}
Also used : OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) IOException(java.io.IOException)

Example 8 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class JAXBDataBinding method initialize.

public void initialize(ToolContext c) throws ToolException {
    this.context = c;
    checkEncoding(c);
    SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
    Bus bus = context.get(Bus.class);
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    Options opts = null;
    opts = getOptions(schemaCompiler);
    hackInNewInternalizationLogic(schemaCompiler, catalog, opts);
    ClassCollector classCollector = context.get(ClassCollector.class);
    ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector, c.optionSet(ToolConstants.CFG_AUTORESOLVE));
    schemaCompiler.setClassNameAllocator(allocator);
    listener = new JAXBBindErrorListener(context.isVerbose(), context.getErrorListener());
    schemaCompiler.setErrorListener(listener);
    // Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
    List<InputSource> jaxbBindings = context.getJaxbBindingFile();
    SchemaCollection schemas = (SchemaCollection) context.get(ToolConstants.XML_SCHEMA_COLLECTION);
    List<String> args = new ArrayList<>();
    if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
        // hard code to enable jaxb extensions
        args.add("-extension");
        String name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml";
        if (isJAXB22()) {
            name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml";
        }
        URL bindingFileUrl = getClass().getResource(name);
        InputSource ins = new InputSource(bindingFileUrl.toString());
        opts.addBindFile(ins);
    }
    if (context.get(ToolConstants.CFG_XJC_ARGS) != null) {
        Object o = context.get(ToolConstants.CFG_XJC_ARGS);
        if (o instanceof String) {
            o = new String[] { (String) o };
        }
        String[] xjcArgss = (String[]) o;
        for (String xjcArgs : xjcArgss) {
            StringTokenizer tokenizer = new StringTokenizer(xjcArgs, ",", false);
            while (tokenizer.hasMoreTokens()) {
                String arg = tokenizer.nextToken();
                args.add(arg);
                LOG.log(Level.FINE, "xjc arg:" + arg);
            }
        }
    }
    if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null || context.get(ToolConstants.CFG_XJC_ARGS) != null) {
        try {
            // keep parseArguments happy, supply dummy required command-line
            // opts
            opts.addGrammar(new InputSource("null"));
            opts.parseArguments(args.toArray(new String[args.size()]));
        } catch (BadCommandLineException e) {
            StringBuilder msg = new StringBuilder("XJC reported 'BadCommandLineException' for -xjc argument:");
            for (String arg : args) {
                msg.append(arg + " ");
            }
            LOG.log(Level.FINE, msg.toString(), e);
            if (opts != null) {
                String pluginUsage = getPluginUsageString(opts);
                msg.append(System.getProperty("line.separator"));
                if (args.contains("-X")) {
                    throw new ToolException(pluginUsage, e);
                }
                msg.append(pluginUsage);
            }
            throw new ToolException(msg.toString(), e);
        }
    }
    if (context.optionSet(ToolConstants.CFG_MARK_GENERATED)) {
        // '-mark-generated' attribute to jaxb xjc.
        try {
            opts.parseArgument(new String[] { "-mark-generated" }, 0);
        } catch (BadCommandLineException e) {
            LOG.log(Level.SEVERE, e.getMessage());
            throw new ToolException(e);
        }
    }
    addSchemas(opts, schemaCompiler, schemas);
    addBindingFiles(opts, jaxbBindings, schemas);
    parseSchemas(schemaCompiler);
    rawJaxbModelGenCode = schemaCompiler.bind();
    addedEnumClassToCollector(schemas, allocator);
    if (context.get(ToolConstants.CFG_DEFAULT_VALUES) != null) {
        String cname = (String) context.get(ToolConstants.CFG_DEFAULT_VALUES);
        if (StringUtils.isEmpty(cname)) {
            defaultValues = new RandomValueProvider();
        } else {
            if (cname.charAt(0) == '=') {
                cname = cname.substring(1);
            }
            try {
                defaultValues = (DefaultValueProvider) Class.forName(cname).newInstance();
            } catch (Exception e) {
                LOG.log(Level.SEVERE, e.getMessage());
                throw new ToolException(e);
            }
        }
    }
    initialized = true;
}
Also used : Bus(org.apache.cxf.Bus) Options(com.sun.tools.xjc.Options) BadCommandLineException(com.sun.tools.xjc.BadCommandLineException) InputSource(org.xml.sax.InputSource) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ArrayList(java.util.ArrayList) SchemaCompiler(com.sun.tools.xjc.api.SchemaCompiler) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) SAXException(org.xml.sax.SAXException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) BadCommandLineException(com.sun.tools.xjc.BadCommandLineException) SAXParseException(org.xml.sax.SAXParseException) StringTokenizer(java.util.StringTokenizer) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) RandomValueProvider(org.apache.cxf.tools.wsdlto.core.RandomValueProvider)

Example 9 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class CustomizationParser method resolveByCatalog.

private String resolveByCatalog(String url) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }
    Bus bus = env.get(Bus.class);
    OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
    try {
        return new OASISCatalogManagerHelper().resolve(catalogResolver, url, null);
    } catch (Exception e1) {
        Message msg = new Message("FAILED_RESOLVE_CATALOG", LOG, url);
        throw new ToolException(msg, e1);
    }
}
Also used : Bus(org.apache.cxf.Bus) OASISCatalogManagerHelper(org.apache.cxf.catalog.OASISCatalogManagerHelper) Message(org.apache.cxf.common.i18n.Message) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 10 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class CatalogTest method testCatalog.

@Test
public void testCatalog() throws Exception {
    OASISCatalogManager catalogManager = new OASISCatalogManager();
    URL jaxwscatalog = getClass().getResource("/META-INF/jax-ws-catalog.xml");
    assertNotNull(jaxwscatalog);
    catalogManager.loadCatalog(jaxwscatalog);
    String xsd = "http://www.w3.org/2005/08/addressing/ws-addr.xsd";
    String resolvedSchemaLocation = catalogManager.resolveSystem(xsd);
    assertEquals("classpath:/schemas/wsdl/ws-addr.xsd", resolvedSchemaLocation);
    ExtendedURIResolver resolver = new ExtendedURIResolver();
    InputSource in = resolver.resolve(resolvedSchemaLocation, null);
    assertTrue(in.getSystemId(), in.getSystemId().indexOf("core") != -1);
    assertTrue(in.getSystemId(), in.getSystemId().indexOf("/schemas/wsdl/ws-addr.xsd") != -1);
}
Also used : InputSource(org.xml.sax.InputSource) ExtendedURIResolver(org.apache.cxf.resource.ExtendedURIResolver) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) URL(java.net.URL) Test(org.junit.Test)

Aggregations

OASISCatalogManager (org.apache.cxf.catalog.OASISCatalogManager)14 URL (java.net.URL)10 IOException (java.io.IOException)9 URISyntaxException (java.net.URISyntaxException)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 Bus (org.apache.cxf.Bus)5 ToolException (org.apache.cxf.tools.common.ToolException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 Message (org.apache.cxf.common.i18n.Message)4 XmlSchemaSerializerException (org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException)4 DOMException (org.w3c.dom.DOMException)4 SAXException (org.xml.sax.SAXException)4 SAXParseException (org.xml.sax.SAXParseException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 WSDLException (javax.wsdl.WSDLException)3 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)3