Search in sources :

Example 1 with XMLContext

use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.

the class JAXBContext method newContextState.

/**
 * INTERNAL:
 * Build a new JAXBContextState from the current JAXBContextInput.
 */
private JAXBContextState newContextState() throws jakarta.xml.bind.JAXBException {
    if (null == contextInput) {
        return null;
    }
    synchronized (this) {
        JAXBContextState newState = contextInput.createContextState();
        XMLContext xmlContext = getXMLContext();
        xmlContext.setXMLContextState(newState.getXMLContext().getXMLContextState());
        newState.setXMLContext(xmlContext);
        newState.setTypeToTypeMappingInfo(contextState.getTypeToTypeMappingInfo());
        return newState;
    }
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext)

Example 2 with XMLContext

use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.

the class XMLEntityMappingsReader method read.

/**
 * INTERNAL:
 */
protected static XMLEntityMappings read(String mappingFile, Reader reader1, Reader reader2, ClassLoader classLoader, Map properties) {
    // Get the schema validation flag if present in the persistence unit properties
    boolean validateORMSchema = isORMSchemaValidationPerformed(properties);
    // Unmarshall JPA format.
    XMLEntityMappings xmlEntityMappings;
    try {
        // First need to determine which context/schema to use, JPA 1.0, 2.0 or EclipseLink orm (only latest supported)
        Object[] context = determineXMLContextAndSchema(mappingFile, reader1, validateORMSchema);
        XMLUnmarshaller unmarshaller = ((XMLContext) context[0]).createUnmarshaller();
        if (validateORMSchema) {
            useLocalSchemaForUnmarshaller(unmarshaller, ((Schema) context[1]));
        }
        xmlEntityMappings = (XMLEntityMappings) unmarshaller.unmarshal(reader2);
    } catch (Exception exception) {
        throw ValidationException.errorParsingMappingFile(mappingFile, exception);
    }
    if (xmlEntityMappings != null) {
        xmlEntityMappings.setMappingFile(mappingFile);
    }
    return xmlEntityMappings;
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) Schema(javax.xml.validation.Schema) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with XMLContext

use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.

the class XMLEntityMappingsWriter method write.

/**
 * INTENAL:
 */
public static void write(XMLEntityMappings entityMappings, Writer writer) {
    XMLContext context = XMLEntityMappingsReader.getEclipseLinkOrmProject();
    XMLMarshaller marshaller = context.createMarshaller();
    marshaller.setSchemaLocation(XMLEntityMappingsReader.ECLIPSELINK_ORM_NAMESPACE + " " + XMLEntityMappingsReader.ECLIPSELINK_ORM_XSD);
    marshaller.marshal(entityMappings, writer);
    try {
        writer.flush();
    } catch (IOException exception) {
        throw ValidationException.fileError(exception);
    }
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller)

Example 4 with XMLContext

use of org.eclipse.persistence.oxm.XMLContext 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 5 with XMLContext

use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.

the class JAXBEnumTypeConverterTestCases method testConverterClassNotFound.

public void testConverterClassNotFound() throws Exception {
    try {
        Project proj = new JAXBEnumTypeConverterProject();
        proj.convertClassNamesToClasses(this.getClass().getClassLoader());
        XMLContext xmlContext = new XMLContext(proj);
    } catch (ValidationException validationException) {
        Throwable nestedException = validationException.getInternalException();
        if (nestedException instanceof ClassNotFoundException) {
            return;
        }
    }
    fail("An ClassNotFoundException should have occurred.");
}
Also used : TypeSafeEnumConverterProject(org.eclipse.persistence.testing.jaxb.converter.typesafeenum.TypeSafeEnumConverterProject) Project(org.eclipse.persistence.sessions.Project) ValidationException(org.eclipse.persistence.exceptions.ValidationException) XMLContext(org.eclipse.persistence.oxm.XMLContext)

Aggregations

XMLContext (org.eclipse.persistence.oxm.XMLContext)170 Project (org.eclipse.persistence.sessions.Project)80 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)68 Document (org.w3c.dom.Document)57 StringReader (java.io.StringReader)56 Test (org.junit.Test)41 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)40 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)39 PLSQLStoredProcedureCall (org.eclipse.persistence.platform.database.oracle.plsql.PLSQLStoredProcedureCall)36 InputStream (java.io.InputStream)30 NonJDBCTestHelper.buildTestProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildTestProject)30 NonJDBCTestHelper.buildWorkbenchXMLProject (org.eclipse.persistence.testing.tests.nonJDBC.NonJDBCTestHelper.buildWorkbenchXMLProject)30 DataModifyQuery (org.eclipse.persistence.queries.DataModifyQuery)21 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)18 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)17 XMLLogin (org.eclipse.persistence.oxm.XMLLogin)17 StringWriter (java.io.StringWriter)15 StreamSource (javax.xml.transform.stream.StreamSource)15 JAXBException (jakarta.xml.bind.JAXBException)14 Map (java.util.Map)14