use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addXPathToSchema.
/**
* Process a given XmlPath, and create the required schema components. The last
* fragment may not be processed; in this case the returned XmlPathResult is
* used to set the current schema and parent complex type, then the owning
* property is processed as per usual. Note the last fragment may be processed
* if it has a namespace or is an 'any'.
*
* @param property the property containing the XmlPath for which schema components are to be built
* @param compositor the sequence/choice/all to modify
* @param schema the schema being built when this method is called - this could
* if the XmlPath contains an entry that references a different namespace
* @param isChoice indicates if the given property is a choice property
* @param type the ComplexType which compositor(s) should be added to
* @return AddToSchemaResult containing current schema and sequence/all/choice build
* based on the given XmlPath
*/
private AddToSchemaResult addXPathToSchema(Property property, TypeDefParticle compositor, Schema schema, boolean isChoice, ComplexType type) {
// '.' xml-path requires special handling
if (property.getXmlPath().equals(DOT)) {
TypeInfo info = typeInfo.get(property.getActualType().getQualifiedName());
JavaClass infoClass = property.getActualType();
addSelfProperties(infoClass, info, compositor, type);
return null;
}
// create the XPathFragment(s) for the path
Field<XMLConversionManager, NamespaceResolver> xfld = new XMLField(property.getXmlPath());
xfld.setNamespaceResolver(schema.getNamespaceResolver());
xfld.initialize();
// build the schema components for the xml-path
return buildSchemaComponentsForXPath(xfld.getXPathFragment(), new AddToSchemaResult(compositor, schema), isChoice, property);
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class PersistenceXMLMappings method createXMLContext.
/**
* INTERNAL:
*/
protected static XMLContext createXMLContext(String namespaceURI) {
Project project = new Project();
NamespaceResolver resolver = new NamespaceResolver();
resolver.setDefaultNamespaceURI(namespaceURI);
project.addDescriptor(buildPersistenceXMLDescriptor(resolver));
project.addDescriptor(buildPUInfoDescriptor(resolver));
project.addDescriptor(buildPUPropertyDescriptor(resolver));
return new XMLContext(project);
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class XMLProcessor method processXmlSchema.
/**
* Process an XmlSchema. This involves creating a NamespaceInfo instance and
* populating it based on the given XmlSchema.
*
* @see NamespaceInfo
* @see AnnotationsProcessor
* @return newly created namespace info, or null if schema is null
*/
private NamespaceInfo processXmlSchema(XmlBindings xmlBindings, String packageName) {
XmlSchema schema = xmlBindings.getXmlSchema();
if (schema == null) {
return null;
}
// create NamespaceInfo
NamespaceInfo nsInfo = this.aProcessor.findInfoForNamespace(schema.getNamespace());
if (nsInfo == null) {
nsInfo = new NamespaceInfo();
}
// process XmlSchema
XmlNsForm form = schema.getAttributeFormDefault();
nsInfo.setAttributeFormQualified(form.equals(XmlNsForm.QUALIFIED));
form = schema.getElementFormDefault();
nsInfo.setElementFormQualified(form.equals(XmlNsForm.QUALIFIED));
if (!nsInfo.isElementFormQualified() || nsInfo.isAttributeFormQualified()) {
aProcessor.setDefaultNamespaceAllowed(false);
}
// make sure defaults are set, not null
nsInfo.setLocation(schema.getLocation() == null ? GENERATE : schema.getLocation());
String namespace = schema.getNamespace();
if (namespace == null) {
namespace = this.aProcessor.getDefaultTargetNamespace();
}
nsInfo.setNamespace(namespace == null ? "" : schema.getNamespace());
NamespaceResolver nsr = new NamespaceResolver();
// process XmlNs
for (XmlNs xmlns : schema.getXmlNs()) {
nsr.put(xmlns.getPrefix(), xmlns.getNamespaceUri());
}
nsInfo.setNamespaceResolver(nsr);
return nsInfo;
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class JAXBContextXPathTestCases method setUp.
@Override
protected void setUp() throws Exception {
jaxbContext = (JAXBContext) JAXBContextFactory.createContext(new Class<?>[] { Customer.class }, null);
nsResolver = new NamespaceResolver();
nsResolver.setDefaultNamespaceURI("http://www.example.org");
}
use of org.eclipse.persistence.oxm.NamespaceResolver in project eclipselink by eclipse-ee4j.
the class SDOProperty method buildXMLTransformationMapping.
private DatabaseMapping buildXMLTransformationMapping(String mappingUri) {
XMLTransformationMapping mapping = new XMLTransformationMapping();
mapping.setAttributeName(getName());
String xpath = getQualifiedXPath(mappingUri, true);
String xpathMinusText;
int indexOfTextXPath = xpath.lastIndexOf("/text()");
if (indexOfTextXPath < 0) {
xpathMinusText = xpath;
} else {
xpathMinusText = xpath.substring(0, indexOfTextXPath);
}
QNameTransformer transformer = new QNameTransformer(xpath);
mapping.setAttributeTransformer(transformer);
mapping.addFieldTransformer(xpath, transformer);
NamespaceResolver nsr = new NamespaceResolver();
nsr.put(javax.xml.XMLConstants.XMLNS_ATTRIBUTE, javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
XMLField field = new XMLField();
field.setNamespaceResolver(nsr);
field.setXPath(xpathMinusText + "/@" + javax.xml.XMLConstants.XMLNS_ATTRIBUTE + ":" + QNameTransformer.QNAME_NAMESPACE_PREFIX);
mapping.addFieldTransformer(field, new NamespaceURITransformer());
return mapping;
}
Aggregations