Search in sources :

Example 6 with XMLContext

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

the class ExternalizedMetadataTestCases method createXmlContext.

/**
 * Convenience method that returns a newly created XMLContext based on an array of classes.
 */
protected XMLContext createXmlContext(Class<?>[] classes) {
    try {
        ClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
        Generator generator = new Generator(new JavaModelInputImpl(classes, new JavaModelImpl(classLoader)));
        CoreProject proj = generator.generateProject();
        ConversionManager manager = new ConversionManager();
        manager.setLoader(classLoader);
        for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
            ClassDescriptor descriptor = descriptorIt.next();
            if (descriptor.getJavaClass() == null) {
                descriptor.setJavaClass(manager.convertClassNameToClass(descriptor.getJavaClassName()));
            }
        }
        return new XMLContext((Project) proj, classLoader);
    } catch (Exception e) {
        e.printStackTrace();
        fail("XmlContext creation failed");
    }
    return null;
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JAXBException(jakarta.xml.bind.JAXBException) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Example 7 with XMLContext

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

the class SDOXMLHelperDelegate method getXmlUnmarshaller.

@Override
public XMLUnmarshaller getXmlUnmarshaller() {
    XMLUnmarshaller unmarshaller = xmlUnmarshallerMap.get(Thread.currentThread());
    if (null == unmarshaller) {
        unmarshaller = getXmlContext().createUnmarshaller();
        unmarshaller.getProperties().put(SDOConstants.SDO_HELPER_CONTEXT, aHelperContext);
        unmarshaller.setUnmappedContentHandlerClass(SDOUnmappedContentHandler.class);
        unmarshaller.setUnmarshalListener(new SDOUnmarshalListener(aHelperContext));
        unmarshaller.setResultAlwaysXMLRoot(true);
        xmlUnmarshallerMap.put(Thread.currentThread(), unmarshaller);
    }
    XMLContext context = getXmlContext();
    if (unmarshaller.getXMLContext() != context) {
        unmarshaller.setXMLContext(context);
    }
    return unmarshaller;
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) SDOUnmarshalListener(org.eclipse.persistence.sdo.helper.SDOUnmarshalListener) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller)

Example 8 with XMLContext

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

the class SDOXMLHelperDelegate method getXmlContext.

@Override
public synchronized XMLContext getXmlContext() {
    if (xmlContext == null) {
        xmlContext = new XMLContext(getTopLinkProject());
        XMLConversionManager xmlConversionManager = getXmlConversionManager();
        xmlConversionManager.setLoader(this.loader);
        xmlConversionManager.setTimeZone(TimeZone.getTimeZone("GMT"));
        xmlConversionManager.setTimeZoneQualified(true);
    }
    return xmlContext;
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 9 with XMLContext

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

the class ContainmentTestCases method setUp.

@Override
public void setUp() {
    ContainmentProject project = new ContainmentProject();
    XMLContext xmlContext = new XMLContext(project);
    JAXBContext jaxbContext = new JAXBContext(xmlContext);
    jaxbHelperContext = new JAXBHelperContext(jaxbContext);
    InputStream xsd = Thread.currentThread().getContextClassLoader().getResourceAsStream(XML_SCHEMA);
    jaxbHelperContext.getXSDHelper().define(xsd, null);
}
Also used : JAXBHelperContext(org.eclipse.persistence.sdo.helper.jaxb.JAXBHelperContext) XMLContext(org.eclipse.persistence.oxm.XMLContext) InputStream(java.io.InputStream) JAXBContext(org.eclipse.persistence.jaxb.JAXBContext)

Example 10 with XMLContext

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

the class SQLAsCollectionTestSuite method buildSessions.

@Override
public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
        conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);
    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
        MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
        processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
        PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
        processor.addNamedQueries();
        orProject = processor.getProject().getProject();
    } else {
        orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
        databaseSession.dontLogMessages();
    } else {
        databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);
    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
        JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
        XmlBindingsModel model = jaxbElt.getValue();
        for (XmlBindings xmlBindings : model.getBindingsList()) {
            metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
        }
    } catch (JAXBException jaxbex) {
        jaxbex.printStackTrace();
    }
    Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
        org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(parentClassLoader, properties);
        oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) HashMap(java.util.HashMap) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) JAXBContext(jakarta.xml.bind.JAXBContext) DBWSTestSuite.documentToString(dbws.testing.DBWSTestSuite.documentToString) StringReader(java.io.StringReader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) Project(org.eclipse.persistence.sessions.Project) DBWSBuilderModelProject(org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) Map(java.util.Map) HashMap(java.util.HashMap)

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