use of org.eclipse.persistence.oxm.XMLDescriptor in project eclipselink by eclipse-ee4j.
the class EmployeeProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setDefaultRootElement("employee");
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setGetMethodName("getID");
idMapping.setSetMethodName("setID");
idMapping.setXPath("id/text()");
descriptor.addMapping(idMapping);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setGetMethodName("getName");
nameMapping.setSetMethodName("setName");
nameMapping.setXPath("name/text()");
descriptor.addMapping(nameMapping);
XMLCompositeObjectMapping homeAddressMapping = new XMLCompositeObjectMapping();
homeAddressMapping.setReferenceClass(Address.class);
homeAddressMapping.setAttributeName("home-address");
homeAddressMapping.setGetMethodName("getHomeAddress");
homeAddressMapping.setSetMethodName("setHomeAddress");
homeAddressMapping.setXPath("home-address");
descriptor.addMapping(homeAddressMapping);
XMLCompositeObjectMapping workAddressMapping = new XMLCompositeObjectMapping();
workAddressMapping.setReferenceClass(Address.class);
workAddressMapping.setAttributeName("work-address");
workAddressMapping.setGetMethodName("getWorkAddress");
workAddressMapping.setSetMethodName("setWorkAddress");
workAddressMapping.setXPath("work-address");
descriptor.addMapping(workAddressMapping);
XMLCompositeObjectMapping phoneMapping = new XMLCompositeObjectMapping();
phoneMapping.setReferenceClass(Phone.class);
phoneMapping.setAttributeName("phone");
phoneMapping.setGetMethodName("getPhone");
phoneMapping.setSetMethodName("setPhone");
phoneMapping.setXPath("phone");
descriptor.addMapping(phoneMapping);
XMLCompositeObjectMapping badgeMapping = new XMLCompositeObjectMapping();
badgeMapping.setReferenceClass(Badge.class);
badgeMapping.setAttributeName("badge");
badgeMapping.setGetMethodName("getBadge");
badgeMapping.setSetMethodName("setBadge");
badgeMapping.setXPath("badge-id");
descriptor.addMapping(badgeMapping);
XMLDirectMapping empCodeMapping = new XMLDirectMapping();
empCodeMapping.setAttributeName("empCode");
empCodeMapping.setGetMethodName("getEmpCode");
empCodeMapping.setSetMethodName("setEmpCode");
empCodeMapping.setXPath("@empCode");
descriptor.addMapping(empCodeMapping);
URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
schemaRef.setType(XMLSchemaReference.ELEMENT);
schemaRef.setSchemaContext("/employee");
descriptor.setSchemaReference(schemaRef);
return descriptor;
}
use of org.eclipse.persistence.oxm.XMLDescriptor in project eclipselink by eclipse-ee4j.
the class EmployeeProject method getPhoneDescriptor.
private XMLDescriptor getPhoneDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Phone.class);
XMLDirectMapping numberMapping = new XMLDirectMapping();
numberMapping.setAttributeName("number");
numberMapping.setGetMethodName("getNumber");
numberMapping.setSetMethodName("setNumber");
numberMapping.setXPath("text()");
descriptor.addMapping(numberMapping);
URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
schemaRef.setType(XMLSchemaReference.SIMPLE_TYPE);
schemaRef.setSchemaContext("/phone-type");
descriptor.setSchemaReference(schemaRef);
return descriptor;
}
use of org.eclipse.persistence.oxm.XMLDescriptor in project eclipselink by eclipse-ee4j.
the class EmployeeProject method getJobDescriptor.
private XMLDescriptor getJobDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Job.class);
descriptor.setDefaultRootElement("job");
XMLDirectMapping titleMapping = new XMLDirectMapping();
titleMapping.setAttributeName("title");
titleMapping.setGetMethodName("getTitle");
titleMapping.setSetMethodName("setTitle");
titleMapping.setXPath("title/text()");
descriptor.addMapping(titleMapping);
URL schemaURL = ClassLoader.getSystemResource("org/eclipse/persistence/testing/jaxb/xmlmarshaller/Employee.xsd");
XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
schemaRef.setType(XMLSchemaReference.ELEMENT);
schemaRef.setSchemaContext("/employee/job");
descriptor.setSchemaReference(schemaRef);
return descriptor;
}
use of org.eclipse.persistence.oxm.XMLDescriptor in project eclipselink by eclipse-ee4j.
the class SDOSequence method convertToSetting.
private Setting convertToSetting(Property property, Object value) {
SDOProperty sdoProperty = (SDOProperty) property;
DatabaseMapping mapping = sdoProperty.getXmlMapping();
Setting setting = new Setting();
SDOType sdoType = dataObject.getType();
XMLDescriptor xmlDescriptor = sdoType.getXmlDescriptor();
if (null == mapping) {
setting.setObject(dataObject);
mapping = xmlDescriptor.getMappingForAttributeName("openContentProperties");
setting.setMapping(mapping);
XMLRoot xmlRoot = new XMLRoot();
if (value instanceof XMLRoot) {
xmlRoot.setLocalName(((XMLRoot) value).getLocalName());
xmlRoot.setNamespaceURI(((XMLRoot) value).getNamespaceURI());
xmlRoot.setObject(((XMLRoot) value).getObject());
} else {
xmlRoot.setLocalName(sdoProperty.getName());
xmlRoot.setNamespaceURI(sdoProperty.getUri());
xmlRoot.setObject(value);
// do not set schema type for global properties
SDOTypeHelper hlpr = (SDOTypeHelper) dataObject.getType().getHelperContext().getTypeHelper();
if (hlpr.getOpenContentProperty(sdoProperty.getUri(), sdoProperty.getName()) == null) {
QName schemaTypeQName = hlpr.getXSDTypeFromSDOType(property.getType());
if (schemaTypeQName != null && schemaTypeQName != XMLConstants.STRING_QNAME) {
xmlRoot.setSchemaType(schemaTypeQName);
}
}
}
setting.setValue(xmlRoot, false);
} else {
setting = convertToSetting(mapping, value);
}
return setting;
}
use of org.eclipse.persistence.oxm.XMLDescriptor in project eclipselink by eclipse-ee4j.
the class SDOSequence method convertToSetting.
private Setting convertToSetting(DatabaseMapping mapping, Object value) {
XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor();
NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver();
Setting rootSetting = new Setting();
XMLField xmlField = (XMLField) mapping.getField();
if (xmlField == null) {
if (mapping instanceof XMLObjectReferenceMapping) {
xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0);
} else if (mapping instanceof XMLCollectionReferenceMapping) {
xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0);
}
}
Setting setting = rootSetting;
if (xmlField != null) {
XPathFragment xPathFragment = xmlField.getXPathFragment();
rootSetting = convertToSetting(xPathFragment, nsResolver);
setting = rootSetting;
while (xPathFragment.getNextFragment() != null) {
xPathFragment = xPathFragment.getNextFragment();
Setting childSetting = convertToSetting(xPathFragment, nsResolver);
setting.addChild(childSetting);
setting = childSetting;
}
}
setting.setObject(dataObject);
setting.setMapping(mapping);
setting.setValue(value, false);
return rootSetting;
}
Aggregations