Search in sources :

Example 1 with MissingDescriptorListener

use of org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener in project eclipselink by eclipse-ee4j.

the class XMLProjectReader method readObjectPersistenceRuntimeFormat.

/**
 * Read a project in the format of an ObjectPersistenceRuntimeXMLProject.
 * This could include a TopLink 11.1.1 project or a TopLink 10.1.3 project
 */
public static Project readObjectPersistenceRuntimeFormat(Document document, ClassLoader classLoader, Project opmProject) {
    XMLLogin xmlLogin = new XMLLogin();
    xmlLogin.setDatasourcePlatform(new org.eclipse.persistence.oxm.platform.DOMPlatform());
    opmProject.setDatasourceLogin(xmlLogin);
    // Create the OPM project.
    if (classLoader != null) {
        xmlLogin.getDatasourcePlatform().getConversionManager().setLoader(classLoader);
    }
    // Marshal OPM format.
    XMLContext context = new XMLContext(opmProject);
    context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener());
    XMLUnmarshaller unmarshaller = context.createUnmarshaller();
    Project project = (Project) unmarshaller.unmarshal(document);
    // Set the project's class loader.
    if ((classLoader != null) && (project.getDatasourceLogin() != null)) {
        project.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(classLoader);
    }
    return project;
}
Also used : EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) Project(org.eclipse.persistence.sessions.Project) ObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller)

Example 2 with MissingDescriptorListener

use of org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener in project eclipselink by eclipse-ee4j.

the class XMLProjectWriter method write.

/**
 * PUBLIC:
 * Given the writer, and a project,
 * this writes out the deployment XML file storing the project's descriptor and mapping information.
 *
 * @param writer writer to writer to
 * @param project the project instance to write
 */
public static void write(Project project, Writer writer) {
    XMLContext context = new XMLContext(new ObjectPersistenceWorkbenchXMLProject());
    context.getSession(project).getEventManager().addListener(new MissingDescriptorListener());
    XMLMarshaller marshaller = context.createMarshaller();
    marshaller.marshal(project, writer);
    try {
        writer.flush();
    } catch (IOException exception) {
        throw ValidationException.fileError(exception);
    }
}
Also used : ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener)

Example 3 with MissingDescriptorListener

use of org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener in project eclipselink by eclipse-ee4j.

the class XRSessionsFactory method loadProjectConfig.

@Override
protected Project loadProjectConfig(ProjectConfig projectConfig) {
    Project project = null;
    String projectString = projectConfig.getProjectString();
    if (projectConfig.isProjectClassConfig()) {
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                project = (Project) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(m_classLoader.loadClass(projectString)));
            } else {
                project = (Project) PrivilegedAccessHelper.newInstanceFromClass(m_classLoader.loadClass(projectString));
            }
        } catch (Throwable exception) {
            throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
        }
    } else {
        try {
            URL url = null;
            Matcher matcher = matchDBWSOrProject.matcher(projectString);
            if (matcher.find()) {
                // need to try a variety of URLs to find DBWS OR/OX Project
                String orXml = matcher.group();
                for (String prefix : META_INF_PATHS) {
                    String searchPath = prefix + orXml;
                    url = m_classLoader.getResource(searchPath);
                    if (url != null) {
                        break;
                    }
                }
            } else {
                matcher = matchDBWSOxProject.matcher(projectString);
                if (matcher.find()) {
                    String oxXml = matcher.group();
                    for (String prefix : META_INF_PATHS) {
                        String searchPath = prefix + oxXml;
                        url = m_classLoader.getResource(searchPath);
                        if (url != null) {
                            break;
                        }
                    }
                }
            }
            if (url != null) {
                Project p = new EclipseLinkObjectPersistenceRuntimeXMLProject();
                XMLLogin xmlLogin = new XMLLogin();
                xmlLogin.setDatasourcePlatform(new DOMPlatform());
                p.setDatasourceLogin(xmlLogin);
                if (m_classLoader != null) {
                    p.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(m_classLoader);
                }
                XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
                XMLParser parser = xmlPlatform.newXMLParser();
                parser.setNamespaceAware(true);
                parser.setWhitespacePreserving(false);
                XMLContext context = new XMLContext(p);
                context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener());
                XMLUnmarshaller unmarshaller = context.createUnmarshaller();
                project = (Project) unmarshaller.unmarshal(url);
            }
        } catch (ValidationException validationException) {
            if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {
                throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
            } else {
                throw SessionLoaderException.failedToParseXML(projectString, validationException);
            }
        }
    }
    return project;
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) ValidationException(org.eclipse.persistence.exceptions.ValidationException) Matcher(java.util.regex.Matcher) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) URL(java.net.URL) Project(org.eclipse.persistence.sessions.Project) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLPlatform(org.eclipse.persistence.platform.xml.XMLPlatform) EclipseLinkObjectPersistenceRuntimeXMLProject(org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLParser(org.eclipse.persistence.platform.xml.XMLParser)

Example 4 with MissingDescriptorListener

use of org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener in project eclipselink by eclipse-ee4j.

the class OXTestCase method write.

// Write out deployment XML
public void write(Project project, Writer writer) {
    // Write out EclipseLink deployment XML
    if (metadata == Metadata.XML_ECLIPSELINK) {
        XMLProjectWriter.write(project, writer);
        return;
    }
    // Write out TL deployment XML
    XMLContext context = new XMLContext(new ObjectPersistenceRuntimeXMLProject_11_1_1());
    context.getSession(project).getEventManager().addListener(new MissingDescriptorListener());
    XMLMarshaller marshaller = context.createMarshaller();
    marshaller.marshal(project, 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) ObjectPersistenceRuntimeXMLProject_11_1_1(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceRuntimeXMLProject_11_1_1) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) IOException(java.io.IOException)

Example 5 with MissingDescriptorListener

use of org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method writeOROXProjects.

public void writeOROXProjects(OutputStream dbwsOrStream, OutputStream dbwsOxStream) {
    Project orProject = dbwsBuilder.getOrProject();
    Project oxProject = dbwsBuilder.getOxProject();
    boolean writeORProject = false;
    if (hasTables() || dbwsBuilder.hasBuildSqlOperations()) {
        writeORProject = true;
    }
    if (!writeORProject) {
        // check for any named queries - SimpleXMLFormatProject sometimes need them
        if (orProject.getQueries().size() > 0) {
            writeORProject = true;
        } else // check for ObjectRelationalDataTypeDescriptor's - Advanced JDBC object/varray types
        if (orProject.getDescriptors().size() > 0) {
            Collection<ClassDescriptor> descriptors = orProject.getDescriptors().values();
            for (ClassDescriptor desc : descriptors) {
                if (desc.isObjectRelationalDataTypeDescriptor()) {
                    writeORProject = true;
                    break;
                }
            }
        }
    }
    if ((writeORProject || !dbwsBuilder.xrServiceModel.getOperations().isEmpty()) && !isNullStream(dbwsOrStream)) {
        XMLContext context = new XMLContext(workbenchXMLProject);
        context.getSession(orProject).getEventManager().addListener(new MissingDescriptorListener());
        XMLEntityMappings mappings = XmlEntityMappingsGenerator.generateXmlEntityMappings(orProject, complextypes, crudOps);
        if (mappings != null) {
            XMLEntityMappingsWriter.write(mappings, dbwsOrStream);
        }
    }
    if (!isNullStream(dbwsOxStream)) {
        boolean writeOXProject = false;
        if (hasTables() || dbwsBuilder.hasBuildSqlOperations()) {
            writeOXProject = true;
        }
        if (!writeOXProject) {
            // check for any named queries - SimpleXMLFormatProject's sometimes need them
            if (orProject.getQueries().size() > 0) {
                writeOXProject = true;
            } else // check for ObjectRelationalDataTypeDescriptor's - Advanced JDBC object/varray types
            if (orProject.getDescriptors().size() > 0) {
                Collection<ClassDescriptor> descriptors = orProject.getDescriptors().values();
                for (ClassDescriptor desc : descriptors) {
                    if (desc.isObjectRelationalDataTypeDescriptor()) {
                        writeOXProject = true;
                        break;
                    }
                }
            }
        }
        if (writeOXProject) {
            List<XmlBindings> xmlBindingsList = XmlBindingsGenerator.generateXmlBindings(oxProject.getOrderedDescriptors());
            if (xmlBindingsList.size() > 0) {
                XmlBindingsModel model = new XmlBindingsModel();
                model.setBindingsList(xmlBindingsList);
                try {
                    JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
                    Marshaller marshaller = jc.createMarshaller();
                    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                    marshaller.marshal(model, dbwsOxStream);
                } catch (JAXBException jaxbEx) {
                    throw new DBWSException(OXM_MARSHAL_EX_MSG, jaxbEx);
                }
            }
        }
    }
    dbwsBuilder.getPackager().closeOrStream(dbwsOrStream);
    dbwsBuilder.getPackager().closeOxStream(dbwsOxStream);
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) Marshaller(jakarta.xml.bind.Marshaller) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) JAXBException(jakarta.xml.bind.JAXBException) JAXBContext(jakarta.xml.bind.JAXBContext) MissingDescriptorListener(org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) DBWSException(org.eclipse.persistence.exceptions.DBWSException) Collection(java.util.Collection) PLSQLCollection(org.eclipse.persistence.platform.database.oracle.plsql.PLSQLCollection) XmlBindingsModel(org.eclipse.persistence.internal.xr.XmlBindingsModel)

Aggregations

MissingDescriptorListener (org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener)5 XMLContext (org.eclipse.persistence.oxm.XMLContext)4 Project (org.eclipse.persistence.sessions.Project)3 EclipseLinkObjectPersistenceRuntimeXMLProject (org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject)2 ObjectPersistenceWorkbenchXMLProject (org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject)2 XMLLogin (org.eclipse.persistence.oxm.XMLLogin)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)2 JAXBContext (jakarta.xml.bind.JAXBContext)1 JAXBException (jakarta.xml.bind.JAXBException)1 Marshaller (jakarta.xml.bind.Marshaller)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DBWSException (org.eclipse.persistence.exceptions.DBWSException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)1