use of org.eclipse.persistence.oxm.mappings.XMLTransformationMapping in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateTransformationMapping.
/**
* Generate an XMLTransformationMapping based on a given Property.
*/
public TransformationMapping generateTransformationMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
TransformationMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, XMLTransformationRecord, XMLRecord> mapping = new XMLTransformationMapping();
if (property.isMethodProperty()) {
if (property.getGetMethodName() == null) {
// handle case of set with no get method
String paramTypeAsString = property.getType().getName();
mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
mapping.setSetMethodName(property.getSetMethodName());
} else if (property.getSetMethodName() == null) {
mapping.setGetMethodName(property.getGetMethodName());
} else {
mapping.setSetMethodName(property.getSetMethodName());
mapping.setGetMethodName(property.getGetMethodName());
}
}
// handle transformation
if (property.isSetXmlTransformation()) {
XmlTransformation xmlTransformation = property.getXmlTransformation();
mapping.setIsOptional(xmlTransformation.isOptional());
// handle transformer(s)
if (xmlTransformation.isSetXmlReadTransformer()) {
// handle read transformer
mapping.setAttributeName(property.getPropertyName());
XmlReadTransformer readTransformer = xmlTransformation.getXmlReadTransformer();
if (readTransformer.isSetTransformerClass()) {
mapping.setAttributeTransformerClassName(xmlTransformation.getXmlReadTransformer().getTransformerClass());
} else {
mapping.setAttributeTransformation(xmlTransformation.getXmlReadTransformer().getMethod());
}
}
if (xmlTransformation.isSetXmlWriteTransformers()) {
// handle write transformer(s)
for (XmlWriteTransformer writeTransformer : xmlTransformation.getXmlWriteTransformer()) {
if (writeTransformer.isSetTransformerClass()) {
mapping.addFieldTransformerClassName(writeTransformer.getXmlPath(), writeTransformer.getTransformerClass());
} else {
mapping.addFieldTransformation(writeTransformer.getXmlPath(), writeTransformer.getMethod());
}
}
}
}
return mapping;
}
use of org.eclipse.persistence.oxm.mappings.XMLTransformationMapping in project eclipselink by eclipse-ee4j.
the class SDOProperty method buildXMLTransformationMapping.
private DatabaseMapping buildXMLTransformationMapping(String mappingUri) {
XMLTransformationMapping mapping = new XMLTransformationMapping();
mapping.setAttributeName(getName());
String xpath = getQualifiedXPath(mappingUri, true);
String xpathMinusText;
int indexOfTextXPath = xpath.lastIndexOf("/text()");
if (indexOfTextXPath < 0) {
xpathMinusText = xpath;
} else {
xpathMinusText = xpath.substring(0, indexOfTextXPath);
}
QNameTransformer transformer = new QNameTransformer(xpath);
mapping.setAttributeTransformer(transformer);
mapping.addFieldTransformer(xpath, transformer);
NamespaceResolver nsr = new NamespaceResolver();
nsr.put(javax.xml.XMLConstants.XMLNS_ATTRIBUTE, javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
XMLField field = new XMLField();
field.setNamespaceResolver(nsr);
field.setXPath(xpathMinusText + "/@" + javax.xml.XMLConstants.XMLNS_ATTRIBUTE + ":" + QNameTransformer.QNAME_NAMESPACE_PREFIX);
mapping.addFieldTransformer(field, new NamespaceURITransformer());
return mapping;
}
use of org.eclipse.persistence.oxm.mappings.XMLTransformationMapping in project eclipselink by eclipse-ee4j.
the class TableTypeTestSuite method setUp.
@BeforeClass
public static void setUp() throws WSDLException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
if (conn == null) {
try {
conn = buildConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
if ("true".equalsIgnoreCase(ddlCreateProp)) {
ddlCreate = true;
}
String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
if ("true".equalsIgnoreCase(ddlDropProp)) {
ddlDrop = true;
}
String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
if ("true".equalsIgnoreCase(ddlDebugProp)) {
ddlDebug = true;
}
if (ddlCreate) {
runDdl(conn, CREATE_TABLETYPE_TABLE, ddlDebug);
runDdl(conn, CREATE_TABLETYPE2_TABLE, ddlDebug);
try {
Statement stmt = conn.createStatement();
for (int i = 0; i < POPULATE_TABLETYPE_TABLE.length; i++) {
stmt.addBatch(POPULATE_TABLETYPE_TABLE[i]);
}
stmt.executeBatch();
stmt = conn.createStatement();
for (int i = 0; i < POPULATE_TABLETYPE2_TABLE.length; i++) {
stmt.addBatch(POPULATE_TABLETYPE2_TABLE[i]);
}
stmt.executeBatch();
} catch (SQLException e) {
// e.printStackTrace();
}
}
DBWS_BUILDER_XML_USERNAME = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<dbws-builder xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<properties>" + "<property name=\"projectName\">tabletype</property>" + "<property name=\"logLevel\">off</property>" + "<property name=\"username\">";
DBWS_BUILDER_XML_PASSWORD = "</property><property name=\"password\">";
DBWS_BUILDER_XML_URL = "</property><property name=\"url\">";
DBWS_BUILDER_XML_DRIVER = "</property><property name=\"driver\">";
DBWS_BUILDER_XML_PLATFORM = "</property><property name=\"platformClassname\">";
DBWS_BUILDER_XML_MAIN = "</property>" + "</properties>" + "<table " + "schemaPattern=\"%\" " + "tableNamePattern=\"TABLETYPE\" " + "/>" + "<table " + "schemaPattern=\"%\" " + "tableNamePattern=\"TABLETYPE2\" " + "/>" + "</dbws-builder>";
builder = new DBWSBuilder();
OracleHelper builderHelper = new OracleHelper(builder);
builder.setBuilderHelper(builderHelper);
Field workbenchProj_field = BaseDBWSBuilderHelper.class.getDeclaredField("workbenchXMLProject");
workbenchProj_field.setAccessible(true);
ObjectPersistenceWorkbenchXMLProject workbenchXMLProject = (ObjectPersistenceWorkbenchXMLProject) workbenchProj_field.get(builderHelper);
XMLTransformationMapping versionMapping = (XMLTransformationMapping) workbenchXMLProject.getDescriptor(Project.class).getMappings().get(0);
TransformerBasedFieldTransformation versionTransformer = (TransformerBasedFieldTransformation) versionMapping.getFieldTransformations().get(0);
Field transformerField = TransformerBasedFieldTransformation.class.getDeclaredField("transformer");
transformerField.setAccessible(true);
ConstantTransformer constantTransformer = (ConstantTransformer) transformerField.get(versionTransformer);
constantTransformer.setValue("Eclipse Persistence Services - " + releaseVersion);
DBWSTestSuite.setUp(".");
}
use of org.eclipse.persistence.oxm.mappings.XMLTransformationMapping in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildProjectDescriptor.
protected ClassDescriptor buildProjectDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Project.class);
descriptor.setDefaultRootElement(getPrimaryNamespaceXPath() + "object-persistence");
descriptor.setSchemaReference(new XMLSchemaClassPathReference(SCHEMA_DIR + TOPLINK_10_SCHEMA));
XMLTransformationMapping versionMapping = new XMLTransformationMapping();
versionMapping.addFieldTransformer("@version", getConstantTransformerForProjectVersionMapping());
descriptor.addMapping(versionMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setSetMethodName("setName");
nameMapping.setGetMethodName("getName");
nameMapping.setXPath(getSecondaryNamespaceXPath() + "name/text()");
descriptor.addMapping(nameMapping);
XMLCompositeCollectionMapping descriptorsMapping = new XMLCompositeCollectionMapping();
descriptorsMapping.useCollectionClass(NonSynchronizedVector.class);
descriptorsMapping.setAttributeName("descriptors");
descriptorsMapping.setSetMethodName("setOrderedDescriptors");
descriptorsMapping.setGetMethodName("getOrderedDescriptors");
descriptorsMapping.setReferenceClass(ClassDescriptor.class);
descriptorsMapping.setXPath(getSecondaryNamespaceXPath() + "class-mapping-descriptors/" + getSecondaryNamespaceXPath() + "class-mapping-descriptor");
descriptor.addMapping(descriptorsMapping);
XMLCompositeObjectMapping loginMapping = new XMLCompositeObjectMapping();
loginMapping.setSetMethodName("setDatasourceLogin");
loginMapping.setGetMethodName("getDatasourceLogin");
loginMapping.setAttributeName("login");
loginMapping.setReferenceClass(DatasourceLogin.class);
loginMapping.setXPath(getPrimaryNamespaceXPath() + "login");
descriptor.addMapping(loginMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLTransformationMapping in project eclipselink by eclipse-ee4j.
the class PLSQLcollectionTestSuite method toProjectXML.
@Test
public void toProjectXML() throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException {
ObjectPersistenceWorkbenchXMLProject runtimeProject = new ObjectPersistenceWorkbenchXMLProject();
XMLTransformationMapping versionMapping = (XMLTransformationMapping) runtimeProject.getDescriptor(Project.class).getMappings().get(0);
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 testDoc = marshaller.objectToXML(project);
Document controlDoc = xmlParser.parse(new StringReader(TEST_PROJECT_CONTROL_DOC));
assertTrue("control document not same as instance document", comparer.isNodeEqual(controlDoc, testDoc));
}
Aggregations