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);
}
}
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();
}
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>"));
}
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;
}
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);
}
}
Aggregations