Search in sources :

Example 1 with CachedContextAndSchemas

use of org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas in project cxf by apache.

the class AbstractBPBeanDefinitionParser method getContext.

protected synchronized JAXBContext getContext(Class<?> cls) {
    if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
        try {
            Set<Class<?>> tmp = new HashSet<Class<?>>();
            if (jaxbClasses != null) {
                tmp.addAll(jaxbClasses);
            }
            JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), cls == null ? getClass().getClassLoader() : cls.getClassLoader());
            if (cls != null) {
                boolean hasOf = false;
                for (Class<?> c : tmp) {
                    if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName())) {
                        hasOf = true;
                    }
                }
                if (!hasOf) {
                    tmp.add(cls);
                }
            }
            JAXBContextCache.scanPackages(tmp);
            CachedContextAndSchemas ccs = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null, false);
            jaxbClasses = ccs.getClasses();
            jaxbContext = ccs.getContext();
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
    return jaxbContext;
}
Also used : JAXBException(javax.xml.bind.JAXBException) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas) HashSet(java.util.HashSet)

Example 2 with CachedContextAndSchemas

use of org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas in project cxf by apache.

the class TLSClientParametersConfig method getContext.

private static synchronized JAXBContext getContext() throws JAXBException {
    if (context == null || classes == null) {
        Set<Class<?>> c2 = new HashSet<Class<?>>();
        JAXBContextCache.addPackage(c2, PackageUtils.getPackageName(TLSClientParametersType.class), TLSClientParametersConfig.class.getClassLoader());
        CachedContextAndSchemas ccs = JAXBContextCache.getCachedContextAndSchemas(c2, null, null, null, false);
        classes = ccs.getClasses();
        context = ccs.getContext();
    }
    return context;
}
Also used : TLSClientParametersType(org.apache.cxf.configuration.security.TLSClientParametersType) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas) HashSet(java.util.HashSet)

Example 3 with CachedContextAndSchemas

use of org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas in project cxf by apache.

the class JAXBDataBinding method initialize.

@SuppressWarnings("unchecked")
public synchronized void initialize(Service service) {
    inInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
    inFaultInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
    // context is already set, don't redo it
    if (context != null) {
        return;
    }
    contextClasses = new LinkedHashSet<Class<?>>();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        JAXBContextInitializer initializer = new JAXBContextInitializer(serviceInfo, contextClasses, typeRefs, this.getUnmarshallerProperties());
        initializer.walk();
        if (serviceInfo.getProperty("extra.class") != null) {
            Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class", Set.class);
            contextClasses.addAll(exClasses);
        }
    }
    String tns = getNamespaceToUse(service);
    CachedContextAndSchemas cachedContextAndSchemas = null;
    JAXBContext ctx = null;
    try {
        cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
    } catch (JAXBException e1) {
        throw new ServiceConstructionException(e1);
    }
    ctx = cachedContextAndSchemas.getContext();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "CREATED_JAXB_CONTEXT", new Object[] { ctx, contextClasses });
    }
    setContext(ctx);
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection col = serviceInfo.getXmlSchemaCollection();
        if (col.getXmlSchemas().length > 1) {
            // someone has already filled in the types
            justCheckForJAXBAnnotations(serviceInfo);
            continue;
        }
        boolean schemasFromCache = false;
        Collection<DOMSource> schemas = getSchemas();
        if (schemas == null || schemas.isEmpty()) {
            schemas = cachedContextAndSchemas.getSchemas();
            if (schemas != null) {
                schemasFromCache = true;
            }
        } else {
            schemasFromCache = true;
        }
        Set<DOMSource> bi = new LinkedHashSet<DOMSource>();
        if (schemas == null) {
            schemas = new LinkedHashSet<DOMSource>();
            try {
                for (DOMResult r : generateJaxbSchemas()) {
                    DOMSource src = new DOMSource(r.getNode(), r.getSystemId());
                    if (BUILT_IN_SCHEMAS.containsValue(r)) {
                        bi.add(src);
                    } else {
                        schemas.add(src);
                    }
                }
                // put any builtins at the end.   Anything that DOES import them
                // will cause it to load automatically and we'll skip them later
                schemas.addAll(bi);
            } catch (IOException e) {
                throw new ServiceConstructionException("SCHEMA_GEN_EXC", LOG, e);
            }
        }
        Set<String> ids = new HashSet<>();
        for (DOMSource r : schemas) {
            ids.add(r.getSystemId());
        }
        for (DOMSource r : schemas) {
            if (bi.contains(r)) {
                String ns = ((Document) r.getNode()).getDocumentElement().getAttribute("targetNamespace");
                if (serviceInfo.getSchema(ns) != null) {
                    continue;
                }
            }
            // StaxUtils.print(r.getNode());
            // System.out.println();
            addSchemaDocument(serviceInfo, col, (Document) r.getNode(), r.getSystemId());
        }
        JAXBSchemaInitializer schemaInit = new JAXBSchemaInitializer(serviceInfo, col, context, this.qualifiedSchemas, tns);
        schemaInit.walk();
        if (cachedContextAndSchemas != null && !schemasFromCache) {
            cachedContextAndSchemas.setSchemas(schemas);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) IOException(java.io.IOException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with CachedContextAndSchemas

use of org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas in project cxf by apache.

the class JAXBExtensionHelper method createUnmarshaller.

private synchronized Unmarshaller createUnmarshaller() throws JAXBException {
    if (unmarshalContext == null || classes == null) {
        try {
            CachedContextAndSchemas ccs = JAXBContextCache.getCachedContextAndSchemas(extensionClass);
            classes = ccs.getClasses();
            unmarshalContext = ccs.getContext();
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
    return unmarshalContext.createUnmarshaller();
}
Also used : JAXBException(javax.xml.bind.JAXBException) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas)

Example 5 with CachedContextAndSchemas

use of org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas in project cxf by apache.

the class JAXBExtensionHelper method createMarshaller.

private synchronized Marshaller createMarshaller() throws JAXBException {
    if (marshalContext == null || classes == null) {
        try {
            CachedContextAndSchemas ccs = JAXBContextCache.getCachedContextAndSchemas(typeClass);
            classes = ccs.getClasses();
            marshalContext = ccs.getContext();
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
    }
    return marshalContext.createMarshaller();
}
Also used : JAXBException(javax.xml.bind.JAXBException) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas)

Aggregations

CachedContextAndSchemas (org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas)10 HashSet (java.util.HashSet)6 JAXBException (javax.xml.bind.JAXBException)6 JAXBContext (javax.xml.bind.JAXBContext)2 IOException (java.io.IOException)1 Principal (java.security.Principal)1 LinkedHashSet (java.util.LinkedHashSet)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 DOMResult (javax.xml.transform.dom.DOMResult)1 DOMSource (javax.xml.transform.dom.DOMSource)1 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)1 TLSClientParametersType (org.apache.cxf.configuration.security.TLSClientParametersType)1 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)1 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)1 UsernameTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType)1 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)1