use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class XMLLoginDeploymentXMLTestCases method testDocumentPreservationPolicy.
// Bug - test 'DocumentPreservationPolicy' in project.xml
public void testDocumentPreservationPolicy() {
Project roundTrippedProject;
XMLLogin roundTrippedLogin;
// DocumentPreservationPolicy = DescriptorLevelDocumentPreservationPolicy
// NodeOrderingPolicy = AppendNewElementsOrderingPolicy
// ======================================================================
m_login.setDocumentPreservationPolicy(new DescriptorLevelDocumentPreservationPolicy());
m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new AppendNewElementsOrderingPolicy());
roundTrippedProject = writeAndReadProject();
roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
// NodeOrderingPolicy = IgnoreNewElementsOrderingPolicy
// DocumentPreservationPolicy = NoDocumentPreservationPolicy
// =========================================================
m_login.setDocumentPreservationPolicy(new NoDocumentPreservationPolicy());
m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new IgnoreNewElementsOrderingPolicy());
roundTrippedProject = writeAndReadProject();
roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
// DocumentPreservationPolicy = XMLBinderPolicy
// NodeOrderingPolicy = RelativePositionOrderingPolicy
// ===================================================
m_login.setDocumentPreservationPolicy(new XMLBinderPolicy());
m_login.getDocumentPreservationPolicy().setNodeOrderingPolicy(new RelativePositionOrderingPolicy());
roundTrippedProject = writeAndReadProject();
roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
assertEquals(m_login.getDocumentPreservationPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getClass());
assertEquals(m_login.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass(), roundTrippedLogin.getDocumentPreservationPolicy().getNodeOrderingPolicy().getClass());
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class XMLLoginDeploymentXMLTestCases method testDataSourcePlatform.
// Bug 242452 - test 'DatasourcePlatform' in project.xml
public void testDataSourcePlatform() {
Project roundTrippedProject;
XMLLogin roundTrippedLogin;
// DatasourcePlatform = SAXPlatform
// ================================
m_login.setDatasourcePlatform(new SAXPlatform());
roundTrippedProject = writeAndReadProject();
roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
assertEquals(m_login.getDatasourcePlatform().getClass(), roundTrippedLogin.getDatasourcePlatform().getClass());
// DatasourcePlatform = DOMPlatform
// ================================
m_login.setDatasourcePlatform(new DOMPlatform());
roundTrippedProject = writeAndReadProject();
roundTrippedLogin = (XMLLogin) roundTrippedProject.getDatasourceLogin();
assertEquals(m_login.getDatasourcePlatform().getClass(), roundTrippedLogin.getDatasourcePlatform().getClass());
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class GenerateSchemaTestCases method loginProject.
/**
* Login the session to ensure that the descriptors are initialized.
*/
protected void loginProject(Project prj) {
XMLPlatform<XMLUnmarshaller> platform = new SAXPlatform();
prj.setLogin(new XMLLogin(platform));
DatabaseSession session = prj.createDatabaseSession();
session.setLogLevel(SessionLog.OFF);
for (Iterator<ClassDescriptor> descriptorIt = prj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
ClassDescriptor descriptor = descriptorIt.next();
if (descriptor.getJavaClass() == null) {
descriptor.setJavaClass(session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(descriptor.getJavaClassName()));
}
}
session.login();
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class XRServiceFactory method buildSessions.
/**
* <p>INTERNAL:
*/
@SuppressWarnings("rawtypes")
public void buildSessions() {
XRDynamicClassLoader projectLoader = new XRDynamicClassLoader(parentClassLoader);
SessionManager sessionManager = SessionManager.getManager();
boolean found = false;
String sessionsFile = xrService.sessionsFile == null ? DBWS_SESSIONS_XML : xrService.sessionsFile;
for (String prefix : META_INF_PATHS) {
String searchPath = prefix + sessionsFile;
XRSessionConfigLoader loader = new XRSessionConfigLoader(searchPath);
loader.setShouldLogin(false);
try {
found = loader.load(sessionManager, projectLoader);
} catch (RuntimeException e) {
/* ignore */
}
if (found) {
break;
}
}
if (!found) {
throw DBWSException.couldNotLocateFile(DBWS_SESSIONS_XML);
}
// make sure the OR/OX sessions were loaded successfully
Map sessions = sessionManager.getSessions();
String orSessionKey = xrService.name + DASH_STR + DBWS_OR_SESSION_NAME_SUFFIX;
if (!sessions.containsKey(orSessionKey)) {
throw DBWSException.couldNotLocateORSessionForService(xrService.name);
}
String oxSessionKey = xrService.name + DASH_STR + DBWS_OX_SESSION_NAME_SUFFIX;
if (!sessions.containsKey(oxSessionKey)) {
throw DBWSException.couldNotLocateOXSessionForService(xrService.name);
}
xrService.orSession = (Session) sessions.get(orSessionKey);
xrService.oxSession = (Session) sessions.get(oxSessionKey);
// load OX project via xml-bindings
Project oxProject;
if ((oxProject = loadOXMetadata(projectLoader, xrService.oxSession)) == null) {
// at this point we may have a legacy deployment XML project, or none set
oxProject = xrService.oxSession.getProject();
// check to see if it's a default Project
if (oxProject.getName().length() == 0) {
// default to SimpleXMLFormat
oxProject = new SimpleXMLFormatProject();
}
}
((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
// load OR project via entity-mappings
Project orProject;
if ((orProject = loadORMetadata(projectLoader, (ServerSession) xrService.orSession)) == null) {
// at this point we may have a legacy deployment XML project, or none set
orProject = xrService.orSession.getProject();
updateFindQueryNames(orProject);
}
prepareDescriptors(oxProject, orProject, projectLoader);
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.xmlContext = new XMLContext(oxProject);
xrService.oxSession = xrService.xmlContext.getSession(0);
}
use of org.eclipse.persistence.oxm.XMLLogin 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;
}
Aggregations