use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class ContainmentProject method getChildDescriptor.
private XMLDescriptor getChildDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Child.class);
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("tns", "urn:containment");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/tns:child");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
xmlDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping mapping = new XMLDirectMapping();
mapping.setAttributeName("value");
mapping.setXPath("tns:value/text()");
xmlDescriptor.addMapping(mapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class ContainmentProject method getRootDescriptor.
private XMLDescriptor getRootDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Root.class);
xmlDescriptor.setDefaultRootElement("tns:root-element");
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/tns:root");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
xmlDescriptor.setSchemaReference(schemaReference);
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("tns", "urn:containment");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLCompositeObjectMapping mapping = new XMLCompositeObjectMapping();
mapping.setReferenceClass(Child.class);
if (mapping.getInverseReferenceMapping() != null) {
mapping.getInverseReferenceMapping().setAttributeName("container");
}
mapping.setAttributeName("childProperty");
mapping.setXPath("tns:child");
xmlDescriptor.addMapping(mapping);
XMLCompositeCollectionMapping mapping2 = new XMLCompositeCollectionMapping();
mapping2.setReferenceClass(Child.class);
if (mapping.getInverseReferenceMapping() != null) {
mapping2.getInverseReferenceMapping().setAttributeName("container");
}
mapping2.setAttributeName("childCollectionProperty");
mapping2.setXPath("tns:child-many");
mapping2.getContainerPolicy().setContainerClass(ArrayList.class);
xmlDescriptor.addMapping(mapping2);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SDOMarshalListener method marshalNilAttribute.
private void marshalNilAttribute(SDOProperty property, DOMRecord row) {
// Marshal out xsi:nil=true
NamespaceResolver resolver = null;
if (property.getContainingType() != null) {
resolver = property.getContainingType().getXmlDescriptor().getNamespaceResolver();
}
if (null == resolver) {
resolver = typeHelper.getNamespaceResolver();
}
String xsiPrefix = resolver.resolveNamespaceURI(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
if ((xsiPrefix == null) || xsiPrefix.equals(SDOConstants.EMPTY_STRING)) {
NamespaceResolver nsResolverWithXsi = new NamespaceResolver();
copyNamespaces(resolver, nsResolverWithXsi);
resolver = nsResolverWithXsi;
xsiPrefix = resolver.generatePrefix(XMLConstants.SCHEMA_INSTANCE_PREFIX);
resolver.put(xsiPrefix, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
}
String xPath = getXPathForProperty(property, true, resolver);
xPath = xPath + "/@" + xsiPrefix + XMLConstants.COLON + XMLConstants.SCHEMA_NIL_ATTRIBUTE;
XMLField field = new XMLField(xPath);
field.setNamespaceResolver(resolver);
row.put(field, XMLConstants.BOOLEAN_STRING_TRUE);
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method getURIForPrefix.
private String getURIForPrefix(String prefix) {
String uri = null;
for (int i = namespaceResolvers.size() - 1; i >= 0; i--) {
NamespaceResolver next = namespaceResolvers.get(i);
uri = next.resolveNamespacePrefix(prefix);
if ((uri != null) && !uri.equals(SDOConstants.EMPTY_STRING)) {
break;
}
}
if (null == uri) {
throw SDOException.prefixUsedButNotDefined(prefix);
}
return uri;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method addRootElementToDescriptor.
private void addRootElementToDescriptor(SDOProperty p, String targetNamespace, String xsdName) {
if (!p.getType().isDataType()) {
String prefix = null;
if (targetNamespace != null && !XMLConstants.EMPTY_STRING.equals(targetNamespace)) {
NamespaceResolver nr = p.getType().getXmlDescriptor().getNamespaceResolver();
if (nr != null) {
prefix = nr.resolveNamespaceURI(targetNamespace);
if (null == prefix) {
prefix = nr.generatePrefix();
nr.put(prefix, targetNamespace);
}
}
}
if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
p.getType().getXmlDescriptor().addRootElement(xsdName);
} else {
p.getType().getXmlDescriptor().addRootElement(//
prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + xsdName);
}
} else {
// Types from Schema: isDataType() == true so:
// - find the SDOWrapperType from TypeHelper's WrappersHashMap
// - set the root element name on it
// - add the descriptor to XMLContext's DescriptorsByQName map
// See also: SDOTypeHelperDelegate:defineOpenContentProperty
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(p.getType().getQName());
XMLDescriptor d = wrapperType.getXmlDescriptor(p.getXsdType());
if (wrapperType != null) {
d.addRootElement(xsdName);
QName descriptorQname = new QName(targetNamespace, xsdName);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, d);
}
}
}
Aggregations