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;
}
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;
}
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);
}
Aggregations