use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.
the class XMLRootComplexInheritanceProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.getInheritancePolicy().setParentClass(Person.class);
// descriptor.setDefaultRootElement("oxm:eRoot");
// descriptor.setDefaultRootElement("oxm:pRoot");
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("empId");
nameMapping.setGetMethodName("getEmpId");
nameMapping.setSetMethodName("setEmpId");
// nameMapping.setNullValue(Integer.valueOf(0));
nameMapping.setXPath("id/text()");
descriptor.addMapping(nameMapping);
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/oxm:emp");
schemaReference.setType(XMLSchemaClassPathReference.COMPLEX_TYPE);
descriptor.setSchemaReference(schemaReference);
namespaceResolver.put("oxm", "test");
descriptor.setNamespaceResolver(namespaceResolver);
return descriptor;
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method setSchemaContext.
private void setSchemaContext(Descriptor desc, TypeInfo info) {
XMLSchemaClassPathReference schemaRef = new XMLSchemaClassPathReference();
if (info.getClassNamespace() == null || info.getClassNamespace().equals("")) {
schemaRef.setSchemaContext("/" + info.getSchemaTypeName());
schemaRef.setSchemaContextAsQName(new QName(info.getSchemaTypeName()));
} else {
String prefix = desc.getNonNullNamespaceResolver().resolveNamespaceURI(info.getClassNamespace());
if (prefix != null && !prefix.equals("")) {
schemaRef.setSchemaContext("/" + prefix + ":" + info.getSchemaTypeName());
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), prefix));
} else {
String generatedPrefix = getPrefixForNamespace(info.getClassNamespace(), desc.getNonNullNamespaceResolver(), false);
schemaRef.setSchemaContext("/" + getQualifiedString(generatedPrefix, info.getSchemaTypeName()));
if (generatedPrefix == null || generatedPrefix.equals(Constants.EMPTY_STRING)) {
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName()));
} else {
schemaRef.setSchemaContextAsQName(new QName(info.getClassNamespace(), info.getSchemaTypeName(), generatedPrefix));
}
}
}
// the default type is complex; need to check for simple type case
if (info.isEnumerationType() || (info.getPropertyNames().size() == 1 && helper.isAnnotationPresent(info.getProperties().get(info.getPropertyNames().get(0)).getElement(), XmlValue.class))) {
schemaRef.setType(XMLSchemaReference.SIMPLE_TYPE);
}
desc.setSchemaReference(schemaRef);
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.
the class XSDHelperProject method getChild2Descriptor.
private XMLDescriptor getChild2Descriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Child2.class);
xmlDescriptor.setDefaultRootElement("tns:child2");
xmlDescriptor.addPrimaryKeyFieldName("@id");
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/tns:child2");
schemaReference.setType(XMLSchemaReference.ELEMENT);
xmlDescriptor.setSchemaReference(schemaReference);
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("tns", "urn:xsd");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
xmlDescriptor.addMapping(idMapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.
the class XSDHelperProject method getChild1Descriptor.
private XMLDescriptor getChild1Descriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Child1.class);
xmlDescriptor.addPrimaryKeyFieldName("@id");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("tns", "urn:xsd");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/tns:child1");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
xmlDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
xmlDescriptor.addMapping(idMapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference in project eclipselink by eclipse-ee4j.
the class OppositeProject method getChild1Descriptor.
private XMLDescriptor getChild1Descriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Child1.class);
xmlDescriptor.addPrimaryKeyFieldName("@id");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("tns", "urn:opposite");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLSchemaClassPathReference schemaReference = new XMLSchemaClassPathReference();
schemaReference.setSchemaContext("/tns:child1");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
xmlDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
xmlDescriptor.addMapping(idMapping);
XMLObjectReferenceMapping child2Mapping = new XMLObjectReferenceMapping();
child2Mapping.setReferenceClass(Child2.class);
child2Mapping.setAttributeName("child2");
child2Mapping.addSourceToTargetKeyFieldAssociation("tns:child2/text()", "@id");
xmlDescriptor.addMapping(child2Mapping);
XMLCollectionReferenceMapping child2CollectionMapping = new XMLCollectionReferenceMapping();
child2CollectionMapping.setReferenceClass(Child2.class);
child2CollectionMapping.setAttributeName("child2Collection");
child2CollectionMapping.addSourceToTargetKeyFieldAssociation("tns:child2collection/text()", "@id");
xmlDescriptor.addMapping(child2CollectionMapping);
return xmlDescriptor;
}
Aggregations