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