use of org.eclipse.persistence.oxm.platform.DOMPlatform in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method finishUpProjects.
/**
* Complete project configuration. Build descriptors for secondary SQL
* and complex arguments. Set the projects on the DBWSBuilder instance.
*/
protected void finishUpProjects(Project orProject, Project oxProject, List<CompositeDatabaseType> typeList) {
// handle build SQL
for (OperationModel opModel : dbwsBuilder.operations) {
if (opModel.hasBuildSql()) {
addToOROXProjectsForBuildSql((ModelWithBuildSql) opModel, orProject, oxProject, nct);
}
}
// create OR/OX projects, descriptors/mappings for the types
addToOROXProjectsForComplexTypes(typeList, orProject, oxProject);
// build queries for procedures with complex arguments
for (OperationModel opModel : dbwsBuilder.operations) {
if (opModel.isProcedureOperation()) {
ProcedureOperationModel procedureOperation = (ProcedureOperationModel) opModel;
for (ProcedureType procType : procedureOperation.getDbStoredProcedures()) {
buildQueryForProcedureType(procType, orProject, oxProject, procedureOperation, hasPLSQLArgs(getArgumentListForProcedureType(procType)));
}
}
}
// set aggregate OR descriptors where appropriate
for (String refClassName : referencedORDescriptors) {
ClassDescriptor cdesc = createdORDescriptors.get(refClassName);
// should not be null, but check to avoid an exception
if (cdesc != null) {
cdesc.descriptorIsAggregate();
}
}
DatabaseLogin databaseLogin = new DatabaseLogin();
databaseLogin.removeProperty(USER_STR);
databaseLogin.removeProperty(PASSWORD_STR);
databaseLogin.setDriverClassName(null);
databaseLogin.setConnectionString(null);
orProject.setLogin(databaseLogin);
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.setDatasourcePlatform(new DOMPlatform());
xmlLogin.getProperties().remove(USER_STR);
xmlLogin.getProperties().remove(PASSWORD_STR);
oxProject.setLogin(xmlLogin);
dbwsBuilder.setOrProject(orProject);
dbwsBuilder.setOxProject(oxProject);
}
use of org.eclipse.persistence.oxm.platform.DOMPlatform 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 aSchemaLocationResolver implementation of the org.eclipse.persistence.sdo.helper.SchemaLocationResolver interface
* used for getting the value of the schemaLocation attribute of generated imports and includes
* @return String The generated XSD.
*/
public String generate(List types, SchemaLocationResolver aSchemaLocationResolver) {
schemaLocationResolver = aSchemaLocationResolver;
if ((types == null) || (types.size() == 0)) {
throw new IllegalArgumentException("No Schema was generated from null or empty list of types.");
}
String uri = null;
Type firstType = (Type) types.get(0);
uri = firstType.getURI();
allTypes = types;
generateSchema(uri, types);
// Now we have a built schema model
Project p = new SchemaModelProject();
Vector<Namespace> generatedNamespaces = generatedSchema.getNamespaceResolver().getNamespaces();
XMLDescriptor desc = ((XMLDescriptor) p.getDescriptor(Schema.class));
for (int i = 0; i < generatedNamespaces.size(); i++) {
Namespace next = generatedNamespaces.get(i);
desc.getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI());
if (next.getNamespaceURI().equals(SDOConstants.SDO_URL) || next.getNamespaceURI().equals(SDOConstants.SDOXML_URL) || next.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL)) {
if (!importExists(generatedSchema.getImports(), next.getNamespaceURI())) {
Import theImport = new Import();
theImport.setNamespace(next.getNamespaceURI());
String schemaLocation = "classpath:/xml/";
String customLocation = null;
if (next.getNamespaceURI().equals(SDOConstants.SDO_URL)) {
if (schemaLocationResolver != null) {
customLocation = schemaLocationResolver.resolveSchemaLocation(firstType, SDOConstants.SDO_BOOLEAN);
}
if (customLocation != null) {
schemaLocation = customLocation;
} else {
schemaLocation += "sdoModel.xsd";
}
} else if (next.getNamespaceURI().equals(SDOConstants.SDOXML_URL)) {
if (schemaLocationResolver != null) {
customLocation = schemaLocationResolver.resolveSchemaLocation(firstType, new SDOType(SDOConstants.SDOXML_URL, "XMLInfo"));
}
if (customLocation != null) {
schemaLocation = customLocation;
} else {
schemaLocation += "sdoXML.xsd";
}
} else if (next.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL)) {
if (schemaLocationResolver != null) {
customLocation = schemaLocationResolver.resolveSchemaLocation(firstType, SDOConstants.SDO_BOOLEANOBJECT);
}
if (customLocation != null) {
schemaLocation = customLocation;
} else {
schemaLocation += "sdoJava.xsd";
}
}
theImport.setSchemaLocation(schemaLocation);
generatedSchema.getImports().add(theImport);
}
}
}
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.platform.DOMPlatform in project eclipselink by eclipse-ee4j.
the class OracleObjecttypeTestSuite method setUp.
@BeforeClass
public static void setUp() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
if ("true".equalsIgnoreCase(ddlCreateProp)) {
ddlCreate = true;
}
final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
if ("true".equalsIgnoreCase(ddlDropProp)) {
ddlDrop = true;
}
final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
if ("true".equalsIgnoreCase(ddlDebugProp)) {
ddlDebug = true;
}
final String username = System.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
final String password = System.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
final String url = System.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
final String driver = System.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
Project orProject = new Project();
orProject.setName("or-oracleobjecttype");
ObjectRelationalDataTypeDescriptor addressORDescriptor = new ObjectRelationalDataTypeDescriptor();
addressORDescriptor.setAlias("address");
addressORDescriptor.useSoftCacheWeakIdentityMap();
addressORDescriptor.setJavaClass(Address.class);
addressORDescriptor.descriptorIsAggregate();
addressORDescriptor.setStructureName("XR_ADDRESS_TYPE");
addressORDescriptor.addFieldOrdering("STREET");
addressORDescriptor.addFieldOrdering("CITY");
addressORDescriptor.addFieldOrdering("PROV");
addressORDescriptor.addDirectMapping("street", "STREET");
addressORDescriptor.addDirectMapping("city", "CITY");
addressORDescriptor.addDirectMapping("province", "PROV");
orProject.addDescriptor(addressORDescriptor);
ObjectRelationalDataTypeDescriptor employeeORDescriptor = new ObjectRelationalDataTypeDescriptor();
employeeORDescriptor.useSoftCacheWeakIdentityMap();
employeeORDescriptor.getQueryManager().checkCacheForDoesExist();
employeeORDescriptor.setAlias("employee");
employeeORDescriptor.setJavaClass(EmployeeWithAddress.class);
employeeORDescriptor.addTableName("XR_EMP_ADDR");
employeeORDescriptor.addPrimaryKeyFieldName("XR_EMP_ADDR.EMPNO");
orProject.addDescriptor(employeeORDescriptor);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("XR_EMP_ADDR.EMPNO");
employeeORDescriptor.addMapping(idMapping);
DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setFieldName("XR_EMP_ADDR.FNAME");
employeeORDescriptor.addMapping(firstNameMapping);
DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setFieldName("XR_EMP_ADDR.LNAME");
employeeORDescriptor.addMapping(lastNameMapping);
StructureMapping addressMapping = new StructureMapping();
addressMapping.setAttributeName("address");
addressMapping.setReferenceClass(Address.class);
addressMapping.setFieldName("ADDRESS");
employeeORDescriptor.addMapping(addressMapping);
ReadAllQuery readQuery = new ReadAllQuery(EmployeeWithAddress.class);
readQuery.setName("getEmployeesByProv");
readQuery.addArgument("X");
StoredProcedureCall spCall = new StoredProcedureCall();
spCall.setProcedureName("GET_EMPLOYEES_BY_PROV");
spCall.addNamedArgument("X", "X", Types.STRUCT, "XR_ADDRESS_TYPE");
spCall.useNamedCursorOutputAsResultSet("Y");
readQuery.setCall(spCall);
employeeORDescriptor.getQueryManager().addQuery("getEmployeesByProv", readQuery);
ObjectPersistenceWorkbenchXMLProject runtimeProject = new ObjectPersistenceWorkbenchXMLProject();
XMLTransformationMapping versionMapping = (XMLTransformationMapping) runtimeProject.getDescriptor(Project.class).getMappings().firstElement();
TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
transformerField.setAccessible(true);
ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
constantTransformer.setValue(CONSTANT_PROJECT_BUILD_VERSION);
XMLContext context = new XMLContext(runtimeProject);
XMLMarshaller marshaller = context.createMarshaller();
Document orProjectDoc = xmlPlatform.createDocument();
marshaller.marshal(orProject, orProjectDoc);
Document orProjectXMLDoc = xmlParser.parse(new StringReader(OBJECTTYPE_OR_PROJECT));
assertTrue("OracleObjecttype java-built OR project not same as XML-built OR project. Expected:\n" + documentToString(orProjectXMLDoc) + "\nActual:\n" + documentToString(orProjectDoc), comparer.isNodeEqual(orProjectXMLDoc, orProjectDoc));
NamespaceResolver ns = new NamespaceResolver();
ns.setDefaultNamespaceURI("urn:oracleobjecttype");
Project oxProject = new Project();
oxProject.setName("ox-oracleobjecttype");
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.setPlatform(new DOMPlatform());
xmlLogin.getProperties().remove("user");
xmlLogin.getProperties().remove("password");
oxProject.setLogin(xmlLogin);
XMLDescriptor addressOXDescriptor = new XMLDescriptor();
addressOXDescriptor.setAlias("address");
addressOXDescriptor.setJavaClass(Address.class);
addressOXDescriptor.setDefaultRootElement("address");
addressOXDescriptor.setNamespaceResolver(ns);
XMLSchemaURLReference schemaReference = new XMLSchemaURLReference();
schemaReference.setSchemaContext("/addressType");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
addressOXDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping streetMapping = new XMLDirectMapping();
streetMapping.setAttributeName("street");
XMLField streetField = new XMLField();
streetField.setName("street/text()");
streetField.setSchemaType(STRING_QNAME);
streetMapping.setField(streetField);
addressOXDescriptor.addMapping(streetMapping);
XMLDirectMapping cityMapping = new XMLDirectMapping();
cityMapping.setAttributeName("city");
XMLField cityField = new XMLField();
cityField.setName("city/text()");
cityField.setSchemaType(STRING_QNAME);
cityMapping.setField(cityField);
addressOXDescriptor.addMapping(cityMapping);
XMLDirectMapping provinceMapping = new XMLDirectMapping();
provinceMapping.setAttributeName("province");
XMLField provinceField = new XMLField();
provinceField.setName("province/text()");
provinceField.setSchemaType(STRING_QNAME);
provinceMapping.setField(provinceField);
addressOXDescriptor.addMapping(provinceMapping);
oxProject.addDescriptor(addressOXDescriptor);
XMLDescriptor employeeOXDescriptor = new XMLDescriptor();
employeeOXDescriptor.setAlias("employee");
employeeOXDescriptor.setJavaClass(EmployeeWithAddress.class);
employeeOXDescriptor.setDefaultRootElement("employee");
employeeOXDescriptor.setNamespaceResolver(ns);
schemaReference = new XMLSchemaURLReference();
schemaReference.setSchemaContext("/employeeType");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
employeeOXDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping xmlIdMapping = new XMLDirectMapping();
xmlIdMapping.setAttributeName("id");
XMLField idField = new XMLField();
idField.setName("id/text()");
idField.setSchemaType(INT_QNAME);
xmlIdMapping.setField(idField);
employeeOXDescriptor.addMapping(xmlIdMapping);
XMLDirectMapping xmlFirstNameMapping = new XMLDirectMapping();
xmlFirstNameMapping.setAttributeName("firstName");
XMLField firstNameField = new XMLField();
firstNameField.setName("first-name/text()");
firstNameField.setSchemaType(STRING_QNAME);
xmlFirstNameMapping.setField(firstNameField);
employeeOXDescriptor.addMapping(xmlFirstNameMapping);
XMLDirectMapping xmlLastNameMapping = new XMLDirectMapping();
xmlLastNameMapping.setAttributeName("lastName");
XMLField lastNameField = new XMLField();
lastNameField.setName("last-name/text()");
lastNameField.setSchemaType(STRING_QNAME);
xmlLastNameMapping.setField(lastNameField);
employeeOXDescriptor.addMapping(xmlLastNameMapping);
XMLCompositeObjectMapping xmlAddressMapping = new XMLCompositeObjectMapping();
xmlAddressMapping.setAttributeName("address");
xmlAddressMapping.setReferenceClass(Address.class);
xmlAddressMapping.setXPath("address");
employeeOXDescriptor.addMapping(xmlAddressMapping);
oxProject.addDescriptor(employeeOXDescriptor);
Document oxProjectDoc = xmlPlatform.createDocument();
marshaller.marshal(oxProject, oxProjectDoc);
Document oxProjectXMLDoc = xmlParser.parse(new StringReader(OBJECTTYPE_OX_PROJECT));
assertTrue("OracleObjecttype java-built OX project not same as XML-built OX project. Expected:\n" + documentToString(oxProjectXMLDoc) + "\nActual:\n" + documentToString(oxProjectDoc), comparer.isNodeEqual(oxProjectXMLDoc, oxProjectDoc));
XRServiceFactory factory = new XRServiceFactory() {
XRServiceFactory init() {
parentClassLoader = ClassLoader.getSystemClassLoader();
xrSchemaStream = new ByteArrayInputStream(OBJECTTYPE_SCHEMA.getBytes());
return this;
}
@Override
public void buildSessions() {
Project orProject = XMLProjectReader.read(new StringReader(OBJECTTYPE_OR_PROJECT), parentClassLoader);
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName(driver);
login.setDatasourcePlatform(new Oracle11Platform());
login.bindAllParameters();
orProject.setDatasourceLogin(login);
DatabaseSession ds = orProject.createDatabaseSession();
ds.dontLogMessages();
xrService.setORSession(ds);
Project oxProject = XMLProjectReader.read(new StringReader(OBJECTTYPE_OX_PROJECT), parentClassLoader);
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
}.init();
context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(OBJECTTYPE_XRMODEL));
xrService = factory.buildService(model);
if (ddlCreate) {
try {
AllTests.runDdl(CREATE_DDL, ddlDebug);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
use of org.eclipse.persistence.oxm.platform.DOMPlatform in project eclipselink by eclipse-ee4j.
the class OXTestCase method getNewProject.
public Project getNewProject(Project originalProject, ClassLoader classLoader) {
Project newProject = originalProject;
switch(metadata) {
case JAVA:
break;
default:
try {
// Write the deployment XML file to deploymentXML-file.xml
String fileName = "deploymentXML-file.xml";
FileWriter fWriter = new FileWriter(fileName);
write(originalProject, fWriter);
fWriter.close();
// Also write the deployment XML file to a stringwriter for logging
if (useLogging) {
StringWriter stringWriter = new StringWriter();
write(originalProject, stringWriter);
log("DEPLOYMENT XML " + stringWriter.toString());
}
// Read the deploymentXML-file.xml back in with XMLProjectReader
FileInputStream inStream = new FileInputStream(fileName);
FileReader fileReader = new FileReader(fileName);
newProject = XMLProjectReader.read(fileReader, classLoader);
inStream.close();
fileReader.close();
File f = new File(fileName);
f.delete();
} catch (Exception e) {
e.printStackTrace();
StringWriter stringWriter = new StringWriter();
write(originalProject, stringWriter);
StringReader reader = new StringReader(stringWriter.toString());
log("DEPLOYMENT XML" + stringWriter.toString());
newProject = XMLProjectReader.read(reader, classLoader);
}
}
if ((newProject.getDatasourceLogin() == null) || (!(newProject.getDatasourceLogin() instanceof XMLLogin))) {
newProject.setDatasourceLogin(new XMLLogin());
}
switch(platform) {
case SAX:
newProject.getDatasourceLogin().setPlatform(new SAXPlatform());
break;
default:
newProject.getDatasourceLogin().setPlatform(new DOMPlatform());
}
return newProject;
}
use of org.eclipse.persistence.oxm.platform.DOMPlatform in project eclipselink by eclipse-ee4j.
the class DocumentPreservationTestCases method getXMLContext.
private XMLContext getXMLContext() {
if (metadata == Metadata.JAVA) {
if (xmlContext == null) {
xmlContext = new XMLContext(new EmployeeProject());
xmlContext.getSession(0).getDatasourceLogin().setPlatform(new DOMPlatform());
}
return xmlContext;
} else {
if (xmlContext != null) {
return xmlContext;
}
StringWriter stringWriter = new StringWriter();
XMLProjectWriter.write(new EmployeeProject(), stringWriter);
StringReader reader = new StringReader(stringWriter.toString());
Project newProject = XMLProjectReader.read(reader);
XMLContext newContext = new XMLContext(newProject);
newContext.getSession(0).getDatasourceLogin().setPlatform(new DOMPlatform());
xmlContext = newContext;
return newContext;
}
}
Aggregations