Search in sources :

Example 1 with TypeReference

use of org.glassfish.jaxb.runtime.api.TypeReference in project metro-jax-ws by eclipse-ee4j.

the class AbstractSEIModelImpl method createBridgeMap.

private void createBridgeMap(List<TypeReference> types) {
    for (TypeReference type : types) {
        Bridge bridge = jaxbContext.createBridge(type);
        bridgeMap.put(type, bridge);
    }
}
Also used : TypeReference(org.glassfish.jaxb.runtime.api.TypeReference) Bridge(org.glassfish.jaxb.runtime.api.Bridge) XMLBridge(com.sun.xml.ws.spi.db.XMLBridge)

Example 2 with TypeReference

use of org.glassfish.jaxb.runtime.api.TypeReference 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 3 with TypeReference

use of org.glassfish.jaxb.runtime.api.TypeReference in project jaxb-ri by eclipse-ee4j.

the class CompositeStructureTest method test1.

// this annotation is just so that we can pass it to tr4.
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
public void test1() throws Exception {
    TypeReference tr1 = new TypeReference(new QName("", "foo"), String.class);
    TypeReference tr2 = new TypeReference(new QName("", "bar"), int.class);
    TypeReference tr3 = new TypeReference(new QName("", "zot"), byte[].class);
    TypeReference tr4 = new TypeReference(new QName("", "zoo"), byte[].class, this.getClass().getMethod("test1").getAnnotation(XmlJavaTypeAdapter.class));
    JAXBRIContext c = JAXBRIContext.newInstance(new Class[0], Arrays.asList(tr1, tr2, tr3, tr4), "", false);
    CompositeStructure cs = new CompositeStructure();
    cs.bridges = new Bridge[] { c.createBridge(tr1), c.createBridge(tr2), c.createBridge(tr3), c.createBridge(tr4) };
    cs.values = new Object[] { "foo", 5, new byte[4], new byte[4] };
    JAXBElement<CompositeStructure> root = new JAXBElement<>(new QName("", "root"), CompositeStructure.class, cs);
    StringWriter sw = new StringWriter();
    c.createMarshaller().marshal(root, System.out);
    c.createMarshaller().marshal(root, sw);
    assertTrue(sw.toString().contains("<root><foo>foo</foo><bar>5</bar><zot>AAAAAA==</zot><zoo>00000000</zoo></root>"));
}
Also used : CompositeStructure(org.glassfish.jaxb.runtime.api.CompositeStructure) StringWriter(java.io.StringWriter) QName(javax.xml.namespace.QName) XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference) JAXBElement(jakarta.xml.bind.JAXBElement) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext) XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)

Example 4 with TypeReference

use of org.glassfish.jaxb.runtime.api.TypeReference in project metro-jax-ws by eclipse-ee4j.

the class JAXBRIContextFactory method typeInfoMappings.

private Map<TypeInfo, TypeReference> typeInfoMappings(Collection<TypeInfo> typeInfos) {
    Map<TypeInfo, TypeReference> map = new java.util.HashMap<>();
    for (TypeInfo ti : typeInfos) {
        Type type = WrapperComposite.class.equals(ti.type) ? CompositeStructure.class : ti.type;
        TypeReference tr = new TypeReference(ti.tagName, type, ti.annotations);
        map.put(ti, tr);
    }
    return map;
}
Also used : Type(java.lang.reflect.Type) WrapperComposite(com.sun.xml.ws.spi.db.WrapperComposite) TypeReference(org.glassfish.jaxb.runtime.api.TypeReference) TypeInfo(com.sun.xml.ws.spi.db.TypeInfo)

Example 5 with TypeReference

use of org.glassfish.jaxb.runtime.api.TypeReference 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)6 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)2 WrapperComposite (com.sun.xml.ws.spi.db.WrapperComposite)2 JAXBRIContext (org.glassfish.jaxb.runtime.api.JAXBRIContext)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 XMLBridge (com.sun.xml.ws.spi.db.XMLBridge)1 JAXBElement (jakarta.xml.bind.JAXBElement)1 JAXBException (jakarta.xml.bind.JAXBException)1 XmlJavaTypeAdapter (jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter)1 StringWriter (java.io.StringWriter)1 Type (java.lang.reflect.Type)1 QName (javax.xml.namespace.QName)1 Bridge (org.glassfish.jaxb.runtime.api.Bridge)1 CompositeStructure (org.glassfish.jaxb.runtime.api.CompositeStructure)1 JAXBContextImpl (org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl)1