Search in sources :

Example 1 with JAXBContextFactory

use of com.sun.xml.ws.developer.JAXBContextFactory in project metro-jax-ws by eclipse-ee4j.

the class AbstractSEIModelImpl method createJAXBContext.

private void createJAXBContext() {
    final List<TypeInfo> types = getAllTypeInfos();
    final List<Class> cls = new ArrayList<>(types.size() + additionalClasses.size());
    cls.addAll(additionalClasses);
    for (TypeInfo type : types) {
        cls.add((Class) type.type);
    }
    try {
        // jaxbContext = JAXBRIContext.newInstance(cls, types, targetNamespace, false);
        // Need to avoid doPriv block once JAXB is fixed. Afterwards, use the above
        bindingContext = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {

            @Override
            public BindingContext run() throws Exception {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST, "Creating JAXBContext with classes={0} and types={1}", new Object[] { cls, types });
                }
                UsesJAXBContextFeature f = features.get(UsesJAXBContextFeature.class);
                com.oracle.webservices.api.databinding.DatabindingModeFeature dmf = features.get(com.oracle.webservices.api.databinding.DatabindingModeFeature.class);
                JAXBContextFactory factory = f != null ? f.getFactory() : null;
                if (factory == null)
                    factory = JAXBContextFactory.DEFAULT;
                // return factory.createJAXBContext(AbstractSEIModelImpl.this,cls,types);
                databindingInfo.properties().put(JAXBContextFactory.class.getName(), factory);
                if (dmf != null) {
                    if (LOGGER.isLoggable(Level.FINE))
                        LOGGER.log(Level.FINE, "DatabindingModeFeature in SEI specifies mode: {0}", dmf.getMode());
                    databindingInfo.setDatabindingMode(dmf.getMode());
                }
                if (f != null)
                    databindingInfo.setDatabindingMode(BindingContextFactory.DefaultDatabindingMode);
                databindingInfo.setClassLoader(classLoader);
                databindingInfo.contentClasses().addAll(cls);
                databindingInfo.typeInfos().addAll(types);
                databindingInfo.properties().put("c14nSupport", Boolean.FALSE);
                databindingInfo.setDefaultNamespace(AbstractSEIModelImpl.this.getDefaultSchemaNamespace());
                BindingContext bc = BindingContextFactory.create(databindingInfo);
                if (LOGGER.isLoggable(Level.FINE))
                    LOGGER.log(Level.FINE, "Created binding context: {0}", bc.getClass().getName());
                // System.out.println("---------------------- databinding " + bc);
                return bc;
            }
        });
        // createBridgeMap(types);
        createBondMap(types);
    } catch (PrivilegedActionException e) {
        throw new WebServiceException(ModelerMessages.UNABLE_TO_CREATE_JAXB_CONTEXT(), e);
    }
    knownNamespaceURIs = new ArrayList<>();
    for (String namespace : bindingContext.getKnownNamespaceURIs()) {
        if (namespace.length() > 0) {
            if (!namespace.equals(SOAPNamespaceConstants.XSD) && !namespace.equals(SOAPNamespaceConstants.XMLNS))
                knownNamespaceURIs.add(namespace);
        }
    }
    marshallers = new Pool.Marshaller(jaxbContext);
// return getJAXBContext();
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) BindingContext(com.sun.xml.ws.spi.db.BindingContext) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) UsesJAXBContextFeature(com.sun.xml.ws.developer.UsesJAXBContextFeature) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) Pool(com.sun.xml.ws.util.Pool)

Example 2 with JAXBContextFactory

use of com.sun.xml.ws.developer.JAXBContextFactory in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIContextFactory method newContext.

@Override
public BindingContext newContext(BindingInfo bi) {
    Class[] classes = bi.contentClasses().toArray(new Class[0]);
    for (int i = 0; i < classes.length; i++) {
        if (WrapperComposite.class.equals(classes[i])) {
            classes[i] = CompositeStructure.class;
        }
    }
    Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos());
    Map<Class, Class> subclassReplacements = bi.subclassReplacements();
    String defaultNamespaceRemap = bi.getDefaultNamespace();
    Boolean c14nSupport = (Boolean) bi.properties().get("c14nSupport");
    RuntimeAnnotationReader ar = (RuntimeAnnotationReader) bi.properties().get("org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader");
    JAXBContextFactory jaxbContextFactory = (JAXBContextFactory) bi.properties().get(JAXBContextFactory.class.getName());
    try {
        JAXBRIContext context = (jaxbContextFactory != null) ? jaxbContextFactory.createJAXBContext(bi.getSEIModel(), toList(classes), toList(typeInfoMappings.values())) : ContextFactory.createContext(classes, typeInfoMappings.values(), subclassReplacements, defaultNamespaceRemap, (c14nSupport != null) ? c14nSupport : false, ar, false, false, false);
        return new JAXBRIContextWrapper(context, typeInfoMappings);
    } catch (Exception e) {
        throw new DatabindingException(e);
    }
}
Also used : TypeInfo(com.sun.xml.ws.spi.db.TypeInfo) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext) DatabindingException(com.sun.xml.ws.spi.db.DatabindingException) RuntimeAnnotationReader(org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader) JAXBContextFactory(com.sun.xml.ws.developer.JAXBContextFactory) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference)

Aggregations

JAXBContextFactory (com.sun.xml.ws.developer.JAXBContextFactory)2 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)2 UsesJAXBContextFeature (com.sun.xml.ws.developer.UsesJAXBContextFeature)1 BindingContext (com.sun.xml.ws.spi.db.BindingContext)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 Pool (com.sun.xml.ws.util.Pool)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 JAXBRIContext (org.glassfish.jaxb.runtime.api.JAXBRIContext)1 TypeReference (org.glassfish.jaxb.runtime.api.TypeReference)1 RuntimeAnnotationReader (org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader)1