Search in sources :

Example 26 with Descriptor

use of org.eclipse.persistence.internal.oxm.mappings.Descriptor in project eclipselink by eclipse-ee4j.

the class XMLDescriptor method setDeclaredTypeOnXMLRoot.

private void setDeclaredTypeOnXMLRoot(Root xmlRoot, String elementNamespaceUri, String elementLocalName, boolean isNamespaceAware, Unmarshaller unmarshaller) {
    XPathQName xpathQName = new XPathQName(elementNamespaceUri, elementLocalName, isNamespaceAware);
    Descriptor desc = unmarshaller.getContext().getDescriptor(xpathQName);
    if (desc != null) {
        xmlRoot.setDeclaredType(desc.getJavaClass());
    }
}
Also used : XPathQName(org.eclipse.persistence.internal.oxm.XPathQName) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor)

Example 27 with Descriptor

use of org.eclipse.persistence.internal.oxm.mappings.Descriptor in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormQualifiedNoDefaultRootElement.

/**
 * Test global complex type generation.  Element form default is qualified.
 */
public void testElementFormQualifiedNoDefaultRootElement() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = true;
        boolean setDefaultRootElement = false;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, true);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement, MYNS);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYNS);
        assertNotNull("No schema was generated for namespace [" + MYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_QUALIFIED_NO_DRE_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Example 28 with Descriptor

use of org.eclipse.persistence.internal.oxm.mappings.Descriptor in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormQualifiedNoSchemaContext.

/**
 * Test global element and anonymous complex type generation. Element form
 * default is qualified.
 */
public void testElementFormQualifiedNoSchemaContext() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = false;
        boolean setDefaultRootElement = true;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, true);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement, MYNS);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYNS);
        assertNotNull("No schema was generated for namespace [" + MYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_QUALIFIED_NO_CTX_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Example 29 with Descriptor

use of org.eclipse.persistence.internal.oxm.mappings.Descriptor in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormUnqualifiedNoCtxNoDRE.

/**
 * No schema should be generated since there is no default root element
 * or schema context set on any descriptors
 */
public void testElementFormUnqualifiedNoCtxNoDRE() throws Exception {
    Schema generatedSchema = null;
    try {
        boolean setSchemaContext = false;
        boolean setDefaultRootElement = false;
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYEMPTYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, false);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYEMPTYNS);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNull("A schema should not have been generated", generatedSchema);
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties)

Example 30 with Descriptor

use of org.eclipse.persistence.internal.oxm.mappings.Descriptor in project eclipselink by eclipse-ee4j.

the class GenerateSingleSchemaTestCases method testElementFormUnqualifiedNoDefaultRootElement.

/**
 * Test global complex type generation.  Element form default is unqualified.
 * Element refs will be generated for local elements whose type is that of
 * a global complex type.  In these cases, global elements will be
 * generated for the refs.
 */
public void testElementFormUnqualifiedNoDefaultRootElement() throws Exception {
    Schema generatedSchema = null;
    Document tDoc = null;
    Document cDoc = null;
    try {
        boolean setSchemaContext = true;
        boolean setDefaultRootElement = false;
        SchemaModelGeneratorProperties props = new SchemaModelGeneratorProperties();
        props.addProperty(MYEMPTYNS, SchemaModelGeneratorProperties.ELEMENT_FORM_QUALIFIED_KEY, false);
        Project prj = new TestProject(setSchemaContext, setDefaultRootElement);
        loginProject(prj);
        List<Descriptor> descriptorsToProcess = setupDescriptorList(prj);
        Map<String, Schema> generatedSchemas = sg.generateSchemas(descriptorsToProcess, props);
        generatedSchema = generatedSchemas.get(MYEMPTYNS);
        assertNotNull("No schema was generated for namespace [" + MYEMPTYNS + "]", generatedSchema);
        // debugging
        // writeSchema(generatedSchema);
        tDoc = getDocument(generatedSchema);
        cDoc = getDocument(ELEMENT_FORM_UNQUALIFIED_NO_DRE_RESOURCE);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
    assertNotNull("Schema to Document conversion failed", tDoc);
    assertNotNull("A problem occurred loading the control schema", cDoc);
    assertTrue("Schema comparsion failed", comparer.isSchemaEqual(cDoc, tDoc));
}
Also used : Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Document(org.w3c.dom.Document)

Aggregations

Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)70 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)25 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)23 QName (javax.xml.namespace.QName)19 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)18 Field (org.eclipse.persistence.internal.oxm.mappings.Field)17 Project (org.eclipse.persistence.sessions.Project)16 CoreDescriptor (org.eclipse.persistence.core.descriptors.CoreDescriptor)14 SAXException (org.xml.sax.SAXException)14 List (java.util.List)13 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)13 SchemaModelGeneratorProperties (org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties)13 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)11 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)10 Document (org.w3c.dom.Document)10 ArrayList (java.util.ArrayList)9 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)9 CoreAbstractSession (org.eclipse.persistence.internal.core.sessions.CoreAbstractSession)8 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)8 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)7