Search in sources :

Example 6 with NamespaceResolver

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);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 7 with NamespaceResolver

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);
}
Also used : Project(org.eclipse.persistence.sessions.Project) XMLContext(org.eclipse.persistence.oxm.XMLContext) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 8 with NamespaceResolver

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;
}
Also used : XmlSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema) XmlNsForm(org.eclipse.persistence.jaxb.xmlmodel.XmlNsForm) XmlNs(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema.XmlNs) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 9 with NamespaceResolver

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");
}
Also used : NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 10 with NamespaceResolver

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) QNameTransformer(org.eclipse.persistence.sdo.helper.metadata.QNameTransformer) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) NamespaceURITransformer(org.eclipse.persistence.sdo.helper.metadata.NamespaceURITransformer)

Aggregations

NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)227 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)142 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)74 XMLField (org.eclipse.persistence.oxm.XMLField)36 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)36 Document (org.w3c.dom.Document)35 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)23 QName (javax.xml.namespace.QName)20 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)17 StringWriter (java.io.StringWriter)17 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)16 InputSource (org.xml.sax.InputSource)14 Element (org.w3c.dom.Element)13 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)12 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)12 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)10 HashMap (java.util.HashMap)9 Project (org.eclipse.persistence.sessions.Project)9 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)8