Search in sources :

Example 1 with RuntimeAnnotationReader

use of org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader in project jaxb-ri by eclipse-ee4j.

the class ContextFactory method createContext.

/**
 * The API will invoke this method via reflection
 */
public static JAXBContext createContext(Class[] classes, Map<String, Object> properties) throws JAXBException {
    MUtils.open(classes);
    // fool-proof check, and copy the map to make it easier to find unrecognized properties.
    if (properties == null)
        properties = Collections.emptyMap();
    else
        properties = new HashMap<>(properties);
    String defaultNsUri = getPropertyValue(properties, JAXBRIContext.DEFAULT_NAMESPACE_REMAP, String.class);
    Boolean c14nSupport = getPropertyValue(properties, JAXBRIContext.CANONICALIZATION_SUPPORT, Boolean.class);
    if (c14nSupport == null)
        c14nSupport = false;
    Boolean disablesecurityProcessing = getPropertyValue(properties, JAXBRIContext.DISABLE_XML_SECURITY, Boolean.class);
    if (disablesecurityProcessing == null)
        disablesecurityProcessing = false;
    Boolean allNillable = getPropertyValue(properties, JAXBRIContext.TREAT_EVERYTHING_NILLABLE, Boolean.class);
    if (allNillable == null)
        allNillable = false;
    Boolean retainPropertyInfo = getPropertyValue(properties, JAXBRIContext.RETAIN_REFERENCE_TO_INFO, Boolean.class);
    if (retainPropertyInfo == null)
        retainPropertyInfo = false;
    Boolean supressAccessorWarnings = getPropertyValue(properties, JAXBRIContext.SUPRESS_ACCESSOR_WARNINGS, Boolean.class);
    if (supressAccessorWarnings == null)
        supressAccessorWarnings = false;
    Boolean improvedXsiTypeHandling = getPropertyValue(properties, JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING, Boolean.class);
    if (improvedXsiTypeHandling == null) {
        String improvedXsiSystemProperty = Utils.getSystemProperty(JAXBRIContext.IMPROVED_XSI_TYPE_HANDLING);
        if (improvedXsiSystemProperty == null) {
            improvedXsiTypeHandling = true;
        } else {
            improvedXsiTypeHandling = Boolean.valueOf(improvedXsiSystemProperty);
        }
    }
    Boolean xmlAccessorFactorySupport = getPropertyValue(properties, JAXBRIContext.XMLACCESSORFACTORY_SUPPORT, Boolean.class);
    if (xmlAccessorFactorySupport == null) {
        xmlAccessorFactorySupport = false;
        Utils.getClassLogger().log(Level.FINE, "Property " + JAXBRIContext.XMLACCESSORFACTORY_SUPPORT + "is not active.  Using JAXB's implementation");
    }
    Boolean backupWithParentNamespace = getPropertyValue(properties, JAXBRIContext.BACKUP_WITH_PARENT_NAMESPACE, Boolean.class);
    RuntimeAnnotationReader ar = getPropertyValue(properties, JAXBRIContext.ANNOTATION_READER, RuntimeAnnotationReader.class);
    Collection<TypeReference> tr = getPropertyValue(properties, JAXBRIContext.TYPE_REFERENCES, Collection.class);
    if (tr == null) {
        tr = Collections.emptyList();
    }
    Map<Class, Class> subclassReplacements;
    try {
        subclassReplacements = TypeCast.checkedCast(getPropertyValue(properties, JAXBRIContext.SUBCLASS_REPLACEMENTS, Map.class), Class.class, Class.class);
    } catch (ClassCastException e) {
        throw new JAXBException(Messages.INVALID_TYPE_IN_MAP.format(), e);
    }
    Integer maxErrorsCount = getPropertyValue(properties, JAXBRIContext.MAX_ERRORS, Integer.class);
    if (maxErrorsCount == null) {
        maxErrorsCount = 10;
    } else if (maxErrorsCount < 0) {
        // negative value means unlimited number of reported errors
        maxErrorsCount = Integer.MAX_VALUE;
    }
    if (!properties.isEmpty()) {
        throw new JAXBException(Messages.UNSUPPORTED_PROPERTY.format(properties.keySet().iterator().next()));
    }
    JAXBContextImpl.JAXBContextBuilder builder = new JAXBContextImpl.JAXBContextBuilder();
    builder.setClasses(classes);
    builder.setTypeRefs(tr);
    builder.setSubclassReplacements(subclassReplacements);
    builder.setDefaultNsUri(defaultNsUri);
    builder.setC14NSupport(c14nSupport);
    builder.setAnnotationReader(ar);
    builder.setXmlAccessorFactorySupport(xmlAccessorFactorySupport);
    builder.setAllNillable(allNillable);
    builder.setRetainPropertyInfo(retainPropertyInfo);
    builder.setSupressAccessorWarnings(supressAccessorWarnings);
    builder.setImprovedXsiTypeHandling(improvedXsiTypeHandling);
    builder.setDisableSecurityProcessing(disablesecurityProcessing);
    builder.setBackupWithParentNamespace(backupWithParentNamespace);
    builder.setMaxErrorsCount(maxErrorsCount);
    return builder.build();
}
Also used : JAXBException(jakarta.xml.bind.JAXBException) RuntimeAnnotationReader(org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader) JAXBContextImpl(org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference)

Example 2 with RuntimeAnnotationReader

use of org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader 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

TypeReference (org.glassfish.jaxb.runtime.api.TypeReference)2 RuntimeAnnotationReader (org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader)2 JAXBContextFactory (com.sun.xml.ws.developer.JAXBContextFactory)1 DatabindingException (com.sun.xml.ws.spi.db.DatabindingException)1 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)1 JAXBException (jakarta.xml.bind.JAXBException)1 JAXBRIContext (org.glassfish.jaxb.runtime.api.JAXBRIContext)1 JAXBContextImpl (org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl)1