use of org.eclipse.persistence.jaxb.javamodel.JavaClass in project eclipselink by eclipse-ee4j.
the class PropertyTypeTestCases method testPropertyTypes.
public void testPropertyTypes() throws Exception {
JaxbClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
Generator generator = new Generator(new JavaModelInputImpl(new Class<?>[] { TestObject.class }, new JavaModelImpl(this.classLoader)));
CoreProject proj = generator.generateProject();
TypeInfo info = generator.getAnnotationsProcessor().getTypeInfos().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
Property booleanProp = info.getProperties().get("booleanTest");
JavaClass type = booleanProp.getType();
assertEquals("java.lang.Boolean", type.getRawName());
Property booleanListProp = info.getProperties().get("booleanListTest");
type = booleanListProp.getType();
assertEquals("java.util.List", type.getRawName());
Property byteArrayProp = info.getProperties().get("byteArrayTest");
type = byteArrayProp.getType();
assertEquals("java.lang.String", type.getRawName());
Property byteArrayListProp = info.getProperties().get("byteArrayListTest");
type = byteArrayListProp.getType();
assertEquals("java.util.List", type.getRawName());
assertEquals("java.lang.String", byteArrayListProp.getGenericType().getRawName());
}
use of org.eclipse.persistence.jaxb.javamodel.JavaClass in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateInverseReferenceMapping.
private InverseReferenceMapping generateInverseReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
InverseReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, DatabaseMapping, org.eclipse.persistence.internal.oxm.record.XMLRecord> invMapping = new XMLInverseReferenceMapping();
boolean isCollection = helper.isCollectionType(property.getType());
if (isCollection) {
invMapping.setReferenceClassName(property.getGenericType().getQualifiedName());
} else {
invMapping.setReferenceClassName(property.getType().getQualifiedName());
}
invMapping.setAttributeName(property.getPropertyName());
String setMethodName = property.getInverseReferencePropertySetMethodName();
String getMethodName = property.getInverseReferencePropertyGetMethodName();
if (setMethodName != null && !setMethodName.equals(Constants.EMPTY_STRING)) {
invMapping.setSetMethodName(setMethodName);
}
if (getMethodName != null && !getMethodName.equals(Constants.EMPTY_STRING)) {
invMapping.setGetMethodName(getMethodName);
}
invMapping.setMappedBy(property.getInverseReferencePropertyName());
if (isCollection) {
JavaClass collectionType = property.getType();
collectionType = containerClassImpl(collectionType);
invMapping.useCollectionClass(org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(collectionType.getQualifiedName(), helper.getClassLoader()));
}
if (property.isWriteableInverseReference()) {
if (isCollection) {
JavaClass descriptorClass = helper.getJavaClass(descriptor.getJavaClassName());
invMapping.setInlineMapping((XMLCompositeCollectionMapping) generateCompositeCollectionMapping(property, descriptor, descriptorClass, namespace, invMapping.getReferenceClassName()));
} else {
invMapping.setInlineMapping((XMLCompositeObjectMapping) generateCompositeObjectMapping(property, descriptor, namespace, invMapping.getReferenceClassName()));
}
}
return invMapping;
}
use of org.eclipse.persistence.jaxb.javamodel.JavaClass in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateCollectionMapping.
public Mapping generateCollectionMapping(Property property, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
// check to see if this should be a composite or direct mapping
JavaClass javaClass = property.getActualType();
if (property.isMixedContent()) {
return generateAnyCollectionMapping(property, descriptor, namespaceInfo, true);
}
if (property.isXmlIdRef() || property.isSetXmlJoinNodes()) {
return generateXMLCollectionReferenceMapping(property, descriptor, namespaceInfo, javaClass);
}
if (javaClass != null && typeInfo.get(javaClass.getQualifiedName()) != null) {
TypeInfo referenceInfo = typeInfo.get(javaClass.getQualifiedName());
if (referenceInfo.isEnumerationType()) {
return generateEnumCollectionMapping(property, descriptor, namespaceInfo, (EnumTypeInfo) referenceInfo);
}
return generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, javaClass.getQualifiedName());
}
if (!property.isAttribute() && javaClass != null && javaClass.getQualifiedName().equals(OBJECT_CLASS_NAME)) {
CompositeCollectionMapping ccMapping = generateCompositeCollectionMapping(property, descriptor, descriptorJavaClass, namespaceInfo, null);
ccMapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
return ccMapping;
}
if (isBinaryData(javaClass)) {
return generateBinaryDataCollectionMapping(property, descriptor, namespaceInfo);
}
return generateDirectCollectionMapping(property, descriptor, namespaceInfo);
}
use of org.eclipse.persistence.jaxb.javamodel.JavaClass 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.jaxb.javamodel.JavaClass 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;
}
Aggregations