Search in sources :

Example 1 with DBWSException

use of org.eclipse.persistence.exceptions.DBWSException in project eclipselink by eclipse-ee4j.

the class XRServiceFactory method loadXMLSchema.

/**
 * <p>INTERNAL:
 * Read and unmarshal <code>XRService</code>'s <code>.xsd</code> file.
 * @param xrSchemaStream Stream resource for the <code>XRService</code>'s <code>.xsd</code> file.
 */
public void loadXMLSchema(InputStream xrSchemaStream) {
    SchemaModelProject schemaProject = new SchemaModelProject();
    XMLContext xmlContext = new XMLContext(schemaProject);
    XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
    Schema schema;
    try {
        schema = (Schema) unmarshaller.unmarshal(xrSchemaStream);
    } catch (XMLMarshalException e) {
        xmlContext.getSession().getSessionLog().log(SessionLog.WARNING, SessionLog.DBWS, "dbws_xml_schema_read_error", e.getLocalizedMessage());
        throw new DBWSException(OXM_PROCESSING_SCH, e);
    }
    NamespaceResolver nr = schema.getNamespaceResolver();
    String targetNamespace = schema.getTargetNamespace();
    nr.put(TARGET_NAMESPACE_PREFIX, targetNamespace);
    xrService.schema = schema;
    xrService.schemaNamespace = targetNamespace;
}
Also used : DBWSException(org.eclipse.persistence.exceptions.DBWSException) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException)

Example 2 with DBWSException

use of org.eclipse.persistence.exceptions.DBWSException in project eclipselink by eclipse-ee4j.

the class XRServiceFactory method loadOXMetadata.

/**
 * <p>INTERNAL:
 * Create a Project using OXM metadata.  The given classloader is expected
 * to successfully load 'META-INF/eclipselink-dbws-ox.xml'.
 * @param xrdecl  {@link ClassLoader} used to search for {@code eclipselink-dbws-ox.xml}.
 * @param session OXM session (only for logging).
 */
protected Project loadOXMetadata(final ClassLoader xrdecl, final Session session) {
    Project oxProject = null;
    InputStream inStream = null;
    String searchPath;
    // try "META-INF/" and "/META-INF/"
    for (String prefix : META_INF_PATHS) {
        searchPath = prefix + Util.DBWS_OX_XML;
        inStream = xrdecl.getResourceAsStream(searchPath);
        if (inStream != null) {
            break;
        }
    }
    if (inStream != null) {
        Map<String, OXMMetadataSource> metadataMap = null;
        StreamSource xml = new StreamSource(inStream);
        try {
            JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
            XmlBindingsModel model = jaxbElt.getValue();
            if (model.getBindingsList() != null) {
                metadataMap = new HashMap<>();
                for (XmlBindings xmlBindings : model.getBindingsList()) {
                    metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
                }
            }
        } catch (JAXBException jaxbex) {
            /* could be legacy project, or none set, so just log */
            session.getSessionLog().log(SessionLog.FINE, SessionLog.DBWS, "dbws_oxm_metadata_read_error", jaxbex.getLocalizedMessage());
            return null;
        }
        if (metadataMap != null) {
            Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<>();
            properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
            try {
                DynamicJAXBContext jCtx = DynamicJAXBContextFactory.createContextFromOXM(xrdecl, properties);
                oxProject = jCtx.getXMLContext().getSession(0).getProject();
                oxProject.setName(xrService.getName().concat(OX_PRJ_SUFFIX));
            } catch (JAXBException e) {
                throw new DBWSException(OXM_PROCESSING_EX, e);
            }
        }
    }
    return oxProject;
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) HashMap(java.util.HashMap) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) JAXBContext(jakarta.xml.bind.JAXBContext) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DynamicJAXBContext(org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext) DBWSException(org.eclipse.persistence.exceptions.DBWSException) Unmarshaller(jakarta.xml.bind.Unmarshaller) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with DBWSException

use of org.eclipse.persistence.exceptions.DBWSException 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

DBWSException (org.eclipse.persistence.exceptions.DBWSException)3 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)3 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 SimpleXMLFormatProject (org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject)2 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)2 Project (org.eclipse.persistence.sessions.Project)2 Marshaller (jakarta.xml.bind.Marshaller)1 Unmarshaller (jakarta.xml.bind.Unmarshaller)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StreamSource (javax.xml.transform.stream.StreamSource)1 DBWSModelProject (org.eclipse.persistence.dbws.DBWSModelProject)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)1 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)1