use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class TwoProjectsTestSuite method testAddDuplicateSession.
public void testAddDuplicateSession() throws Exception {
XMLContext xmlContext = new XMLContext(CONTEXT_PATH_SAX);
Project empProject = new EmployeeProject();
XMLPlatform<org.eclipse.persistence.internal.oxm.XMLUnmarshaller> platform = new SAXPlatform();
empProject.setLogin(new XMLLogin(platform));
DatabaseSession employeeSession = empProject.createDatabaseSession();
xmlContext.addSession(employeeSession);
xmlMarshaller = xmlContext.createMarshaller();
Employee employee = getControlEmployee();
Document controlDocument = getControlDocument(XML_RESOURCE_EMPLOYEE);
Document testDocument = parser.newDocument();
xmlMarshaller.marshal(employee, testDocument);
log("\nExpected:");
log(controlDocument);
log("\nActual:");
log(testDocument);
log("");
this.assertXMLIdentical(controlDocument, testDocument);
int numSessions = xmlContext.getSessions().size();
assertEquals(3, numSessions);
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class TwoProjectsTestSuite method testAddLoggedOutSession.
public void testAddLoggedOutSession() throws Exception {
XMLContext xmlContext = new XMLContext(new CustomerProject());
Project empProject = new EmployeeProject();
XMLPlatform<org.eclipse.persistence.internal.oxm.XMLUnmarshaller> platform = new SAXPlatform();
empProject.setLogin(new XMLLogin(platform));
DatabaseSession employeeSession = empProject.createDatabaseSession();
employeeSession.logout();
xmlContext.addSession(employeeSession);
xmlMarshaller = xmlContext.createMarshaller();
Employee employee = getControlEmployee();
Document controlDocument = getControlDocument(XML_RESOURCE_EMPLOYEE);
Document testDocument = parser.newDocument();
xmlMarshaller.marshal(employee, testDocument);
log("\nExpected:");
log(controlDocument);
log("\nActual:");
log(testDocument);
log("");
this.assertXMLIdentical(controlDocument, testDocument);
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class SDOSchemaGenerator method generate.
/**
* <p>Method to generate an XSD. Note the following:<ul>
* <li> All types must have same URI
* <li> Referenced types in same URI will also be generated in schema
* <li> Includes will never be generated
* <li> Imports will be generated for referenced types in other URIs
* </ul>
* @param types The list of commonj.sdo.Type objects to generate the XSD from
* @param aNamespaceToSchemaLocation map of namespaces to schemaLocations
* used for getting the value of the schemaLocation attribute of generated imports and includes
* @return String The generated XSD.
*/
public String generate(List types, Map<String, String> aNamespaceToSchemaLocation) {
if ((types == null) || (types.size() == 0)) {
throw new IllegalArgumentException("No Schema was generated from null or empty list of types.");
}
String uri = null;
namespaceToSchemaLocation = aNamespaceToSchemaLocation;
Type firstType = (Type) types.get(0);
if (firstType == null) {
throw new IllegalArgumentException("No Schema was generated from a list of types containing null elements");
} else {
uri = firstType.getURI();
}
allTypes = types;
generateSchema(uri, types);
// Now we have a built schema model
Project p = new SchemaModelProject();
Vector<Namespace> namespaces = generatedSchema.getNamespaceResolver().getNamespaces();
for (int i = 0; i < namespaces.size(); i++) {
Namespace next = namespaces.get(i);
((XMLDescriptor) p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
}
XMLLogin login = new XMLLogin();
login.setDatasourcePlatform(new DOMPlatform());
p.setDatasourceLogin(login);
XMLContext context = new XMLContext(p);
XMLMarshaller marshaller = context.createMarshaller();
StringWriter generatedSchemaWriter = new StringWriter();
marshaller.marshal(generatedSchema, generatedSchemaWriter);
return generatedSchemaWriter.toString();
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildSchema.
/**
* Build the schema
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public void buildSchema(NamingConventionTransformer nct) {
Project oxProject = dbwsBuilder.getOxProject();
Schema schema = null;
List<Descriptor> descriptorsToProcess = new ArrayList<Descriptor>();
for (Descriptor desc : (List<Descriptor>) (List) oxProject.getOrderedDescriptors()) {
String alias = desc.getAlias();
if (!DEFAULT_SIMPLE_XML_FORMAT_TAG.equals(alias)) {
descriptorsToProcess.add(desc);
}
}
if (descriptorsToProcess.size() > 0) {
// need a deep-copy clone of oxProject; simplest way is to marshall/unmarshall to a stream
StringWriter sw = new StringWriter();
XMLProjectWriter.write(oxProject, sw);
XRDynamicClassLoader specialLoader = new XRDynamicClassLoader(this.getClass().getClassLoader());
Project oxProjectClone = XMLProjectReader.read(new StringReader(sw.toString()), specialLoader);
ProjectHelper.fixOROXAccessors(oxProjectClone, null);
XMLLogin xmlLogin = new XMLLogin();
DOMPlatform domPlatform = new DOMPlatform();
domPlatform.getConversionManager().setLoader(specialLoader);
xmlLogin.setPlatform(domPlatform);
oxProjectClone.setLogin(xmlLogin);
// initialize reference descriptors
oxProjectClone.createDatabaseSession();
SchemaModelGenerator schemaGenerator = new SchemaModelGenerator(XMLConversionManager.getDefaultXMLManager(), true);
SchemaModelGeneratorProperties sgProperties = new SchemaModelGeneratorProperties();
// set element form default to qualified for target namespace
sgProperties.addProperty(dbwsBuilder.getTargetNamespace(), ELEMENT_FORM_QUALIFIED_KEY, true);
Map<String, Schema> schemaMap = schemaGenerator.generateSchemas(descriptorsToProcess, sgProperties);
Schema s = schemaMap.get(dbwsBuilder.getTargetNamespace());
// check existing schema for any top-level ComplexTypes
if (dbwsBuilder.getSchema() != null && s != null) {
Map<String, ComplexType> topLevelComplexTypes = dbwsBuilder.getSchema().getTopLevelComplexTypes();
for (Map.Entry<String, ComplexType> me : topLevelComplexTypes.entrySet()) {
s.addTopLevelComplexTypes(me.getValue());
}
// add any additional namespaces
NamespaceResolver snr = s.getNamespaceResolver();
NamespaceResolver nr = dbwsBuilder.getSchema().getNamespaceResolver();
// we only want to add prefix/uri pairs for prefixes that don't already exist
for (String prefix : nr.getPrefixesToNamespaces().keySet()) {
if (snr.resolveNamespacePrefix(prefix) == null) {
snr.put(prefix, nr.resolveNamespacePrefix(prefix));
}
}
// switch
schema = s;
schema.setNamespaceResolver(snr);
}
} else {
schema = new Schema();
addSimpleXMLFormat(schema);
schema.setTargetNamespace(dbwsBuilder.getTargetNamespace());
}
dbwsBuilder.setSchema(schema);
}
use of org.eclipse.persistence.oxm.XMLLogin in project eclipselink by eclipse-ee4j.
the class SOAP12TestSuite method buildSessions.
@Override
public void buildSessions() {
XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
DatasourceLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
((DatabaseLogin) login).setConnectionString(url);
((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
Platform platform = builder.getDatabasePlatform();
ConversionManager conversionManager = platform.getConversionManager();
if (conversionManager != null) {
conversionManager.setLoader(xrdecl);
}
login.setDatasourcePlatform(platform);
((DatabaseLogin) login).bindAllParameters();
((DatabaseLogin) login).setUsesStreamsForBinding(true);
Project orProject = null;
if (DBWS_OR_STREAM.size() != 0) {
MetadataProcessor processor = new MetadataProcessor(new XRPersistenceUnitInfo(xrdecl), new DatabaseSessionImpl(login), xrdecl, false, true, false, false, false, null, null);
processor.setMetadataSource(new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
PersistenceUnitProcessor.processORMetadata(processor, true, PersistenceUnitProcessor.Mode.ALL);
processor.addNamedQueries();
orProject = processor.getProject().getProject();
} else {
orProject = new Project();
}
orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
orProject.setDatasourceLogin(login);
DatabaseSession databaseSession = orProject.createDatabaseSession();
if ("off".equalsIgnoreCase(builder.getLogLevel())) {
databaseSession.dontLogMessages();
} else {
databaseSession.setLogLevel(AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
}
xrService.setORSession(databaseSession);
orProject.convertClassNamesToClasses(xrdecl);
Project oxProject = null;
Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
try {
JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
XmlBindingsModel model = jaxbElt.getValue();
for (XmlBindings xmlBindings : model.getBindingsList()) {
metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
}
} catch (JAXBException jaxbex) {
jaxbex.printStackTrace();
}
Map<String, Map<String, OXMMetadataSource>> properties = new HashMap<String, Map<String, OXMMetadataSource>>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
try {
org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx = org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(parentClassLoader, properties);
oxProject = jCtx.getXMLContext().getSession(0).getProject();
} catch (JAXBException e) {
e.printStackTrace();
}
((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);
prepareDescriptors(oxProject, orProject, xrdecl);
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(databaseSession);
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
Aggregations