use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateAnyAttributeMapping.
public AnyAttributeMapping generateAnyAttributeMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
XMLAnyAttributeMapping mapping = new XMLAnyAttributeMapping();
initializeXMLMapping(mapping, property);
initializeXMLContainerMapping(mapping, property.getType().isArray());
// if the XPath is set (via xml-path) use it
if (property.getXmlPath() != null) {
mapping.setField(new XMLField(property.getXmlPath()));
}
mapping.setSchemaInstanceIncluded(false);
mapping.setNamespaceDeclarationIncluded(false);
JavaClass mapType = property.getType();
if (areEquals(mapType, Map.class)) {
mapType = jotHashMap;
}
mapping.useMapClassName(mapType.getRawName());
return mapping;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateCompositeCollectionMapping.
public CompositeCollectionMapping generateCompositeCollectionMapping(Property property, Descriptor descriptor, JavaClass javaClass, NamespaceInfo namespaceInfo, String referenceClassName) {
boolean nestedArray = false;
CompositeCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeCollectionMapping();
initializeXMLMapping((XMLMapping) mapping, property);
initializeXMLContainerMapping(mapping, property.getType().isArray());
JavaClass manyValueJavaClass = helper.getJavaClass(ManyValue.class);
if (manyValueJavaClass.isAssignableFrom(javaClass)) {
mapping.setReuseContainer(false);
}
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
} else if (property.isNillable()) {
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
if (property.isSetXmlElementWrapper()) {
mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
}
JavaClass collectionType = property.getType();
if (collectionType.isArray()) {
JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
JavaClass componentType = collectionType.getComponentType();
if (componentType.isArray()) {
Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getName());
referenceClassName = adaptedClass.getName();
accessor.setAdaptedClassName(referenceClassName);
JavaClass baseComponentType = getBaseComponentType(componentType);
if (baseComponentType.isPrimitive()) {
Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
accessor.setComponentClass(primitiveClass);
} else {
accessor.setComponentClassName(baseComponentType.getQualifiedName());
}
} else {
accessor.setComponentClassName(componentType.getQualifiedName());
}
mapping.setAttributeAccessor(accessor);
} else if (helper.isMapType(property.getType())) {
Class<?> generatedClass = generateMapEntryClassAndDescriptor(property, descriptor.getNonNullNamespaceResolver());
referenceClassName = generatedClass.getName();
String mapClassName = property.getType().getRawName();
mapping.setAttributeAccessor(new MapValueAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), generatedClass, mapClassName, helper.getClassLoader()));
}
// Nested array check (used in JSON marshalling)
if (collectionType.getComponentType() == null) {
if ((collectionType.isArray() || helper.isCollectionType(collectionType)) && (referenceClassName != null && referenceClassName.contains(AnnotationsProcessor.ARRAY_PACKAGE_NAME))) {
nestedArray = true;
}
} else if ((collectionType.isArray() || helper.isCollectionType(collectionType)) && (collectionType.getComponentType().isArray() || helper.isCollectionType(collectionType.getComponentType()))) {
nestedArray = true;
}
collectionType = containerClassImpl(collectionType);
mapping.useCollectionClassName(collectionType.getRawName());
// if the XPath is set (via xml-path) use it; otherwise figure it out
Field xmlField = getXPathForField(property, namespaceInfo, false, false);
if (helper.isMapType(property.getType())) {
JavaClass mapValueClass = helper.getJavaClass(MapValue.class);
if (mapValueClass.isAssignableFrom(javaClass)) {
mapping.setXPath("entry");
} else {
mapping.setXPath(xmlField.getXPath() + "/entry");
}
} else {
mapping.setXPath(xmlField.getXPath());
}
if (referenceClassName == null) {
setTypedTextField((Field) mapping.getField());
} else {
mapping.setReferenceClassName(referenceClassName);
}
if (property.isTransientType()) {
mapping.setReferenceClassName(Constants.UNKNOWN_OR_TRANSIENT_CLASS);
}
if (property.isRequired()) {
((Field) mapping.getField()).setRequired(true);
}
((Field) mapping.getField()).setNestedArray(nestedArray);
return mapping;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateVariableXPathObjectMapping.
private Mapping generateVariableXPathObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass actualType) {
XMLVariableXPathObjectMapping mapping = new XMLVariableXPathObjectMapping();
initializeXMLMapping(mapping, property);
initializeVariableXPathMapping(mapping, property, actualType);
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
} else {
NullPolicy nullPolicy = (NullPolicy) mapping.getNullPolicy();
nullPolicy.setSetPerformedForAbsentNode(false);
if (property.isNillable()) {
nullPolicy.setNullRepresentedByXsiNil(true);
nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
}
if (property.getXmlPath() != null) {
mapping.setField(new XMLField(property.getXmlPath()));
} else {
if (property.isSetXmlElementWrapper()) {
mapping.setField((XMLField) getXPathForField(property, namespaceInfo, false, true));
}
}
return mapping;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateVariableXPathCollectionMapping.
private Mapping generateVariableXPathCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass actualType) {
XMLVariableXPathCollectionMapping mapping = new XMLVariableXPathCollectionMapping();
mapping.setAttributeName(property.getPropertyName());
if (property.isMap()) {
actualType = property.getValueType();
}
initializeXMLContainerMapping(mapping, property.getType().isArray());
initializeXMLMapping(mapping, property);
initializeVariableXPathMapping(mapping, property, actualType);
if (property.getXmlPath() != null) {
mapping.setField(new XMLField(property.getXmlPath()));
} else {
if (property.isSetXmlElementWrapper()) {
mapping.setField((XMLField) getXPathForField(property, namespaceInfo, false, true));
}
}
if (property.isSetXmlElementWrapper()) {
mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
}
JavaClass collectionType = property.getType();
if (collectionType.isArray()) {
JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
JavaClass componentType = collectionType.getComponentType();
if (componentType.isArray()) {
JavaClass baseComponentType = getBaseComponentType(componentType);
if (baseComponentType.isPrimitive()) {
Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
accessor.setComponentClass(primitiveClass);
} else {
accessor.setComponentClassName(baseComponentType.getQualifiedName());
}
} else {
accessor.setComponentClassName(componentType.getQualifiedName());
}
mapping.setAttributeAccessor(accessor);
}
if (property.isMap()) {
JavaClass mapType = property.getType();
if (mapType.isInterface()) {
mapping.useMapClass("java.util.HashMap");
} else {
mapping.useMapClass(property.getType().getName());
}
} else {
collectionType = containerClassImpl(collectionType);
mapping.useCollectionClass(helper.getClassForJavaClass(collectionType));
}
return mapping;
}
use of org.eclipse.persistence.oxm.XMLField in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateChoiceMapping.
public ChoiceObjectMapping generateChoiceMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
XMLChoiceObjectMapping mapping = new XMLChoiceObjectMapping();
initializeXMLMapping(mapping, property);
boolean isIdRef = property.isXmlIdRef();
Iterator<Property> choiceProperties = property.getChoiceProperties().iterator();
while (choiceProperties.hasNext()) {
Property next = choiceProperties.next();
JavaClass type = next.getType();
JavaClass originalType = next.getType();
Converter converter = null;
TypeInfo info = typeInfo.get(type.getName());
if (info != null) {
XmlJavaTypeAdapter adapter = info.getXmlJavaTypeAdapter();
if (adapter != null) {
String adapterValue = adapter.getValue();
JavaClass adapterClass = helper.getJavaClass(adapterValue);
JavaClass theClass = CompilerHelper.getTypeFromAdapterClass(adapterClass, helper);
type = theClass;
converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
}
}
if (next.getXmlJoinNodes() != null) {
// handle XmlJoinNodes
List<XMLField> srcFlds = new ArrayList<>();
List<XMLField> tgtFlds = new ArrayList<>();
for (XmlJoinNode xmlJoinNode : next.getXmlJoinNodes().getXmlJoinNode()) {
srcFlds.add(new XMLField(xmlJoinNode.getXmlPath()));
tgtFlds.add(new XMLField(xmlJoinNode.getReferencedXmlPath()));
}
mapping.addChoiceElement(srcFlds, type.getQualifiedName(), tgtFlds);
} else if (isIdRef) {
// handle IDREF
String tgtXPath = null;
TypeInfo referenceType = typeInfo.get(type.getQualifiedName());
if (null != referenceType && referenceType.isIDSet()) {
Property prop = referenceType.getIDProperty();
tgtXPath = getXPathForField(prop, namespace, !prop.isAttribute(), false).getXPath();
}
// if the XPath is set (via xml-path) use it, otherwise figure it out
Field srcXPath;
if (next.getXmlPath() != null) {
srcXPath = new XMLField(next.getXmlPath());
} else {
srcXPath = getXPathForField(next, namespace, true, false);
}
mapping.addChoiceElement(srcXPath.getXPath(), type.getQualifiedName(), tgtXPath);
} else {
XMLField xpath;
if (next.getXmlPath() != null) {
xpath = new XMLField(next.getXmlPath());
} else {
xpath = (XMLField) getXPathForField(next, namespace, (!(this.typeInfo.containsKey(type.getQualifiedName()))) || next.isMtomAttachment() || type.isEnum(), false);
}
mapping.addChoiceElement(xpath, type.getQualifiedName());
if (!originalType.getQualifiedName().equals(type.getQualifiedName())) {
mapping.getClassNameToFieldMappings().putIfAbsent(originalType.getQualifiedName(), xpath);
mapping.addConverter(xpath, converter);
}
XMLMapping nestedMapping = mapping.getChoiceElementMappings().get(xpath);
if (nestedMapping instanceof BinaryDataMapping) {
((BinaryDataMapping) nestedMapping).getNullPolicy().setNullRepresentedByEmptyNode(false);
}
if (type.isEnum()) {
if (nestedMapping.isAbstractDirectMapping()) {
((DirectMapping) nestedMapping).setConverter(buildJAXBEnumTypeConverter(nestedMapping, (EnumTypeInfo) info));
}
}
}
}
return mapping;
}
Aggregations