use of org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class XMLEntityMappingsMappingProject method getParametersMapping.
/**
* INTERNAL:
*/
protected XMLCompositeCollectionMapping getParametersMapping() {
XMLCompositeCollectionMapping parametersMapping = new XMLCompositeCollectionMapping();
parametersMapping.setAttributeName("m_parameters");
parametersMapping.setGetMethodName("getParameters");
parametersMapping.setSetMethodName("setParameters");
parametersMapping.setReferenceClass(StoredProcedureParameterMetadata.class);
parametersMapping.setXPath("orm:parameter");
return parametersMapping;
}
use of org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class XMLEntityMappingsMappingProject method buildTransformationDescriptor.
/**
* INTERNAL:
* XSD: transformation
*/
protected ClassDescriptor buildTransformationDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(TransformationAccessor.class);
// Element mappings - must remain in order of definition in XML.
XMLCompositeObjectMapping readTransformerMapping = new XMLCompositeObjectMapping();
readTransformerMapping.setAttributeName("m_readTransformer");
readTransformerMapping.setGetMethodName("getReadTransformer");
readTransformerMapping.setSetMethodName("setReadTransformer");
readTransformerMapping.setReferenceClass(ReadTransformerMetadata.class);
readTransformerMapping.setXPath("orm:read-transformer");
descriptor.addMapping(readTransformerMapping);
XMLCompositeCollectionMapping writeTransformersMapping = new XMLCompositeCollectionMapping();
writeTransformersMapping.setAttributeName("m_writeTransformers");
writeTransformersMapping.setGetMethodName("getWriteTransformers");
writeTransformersMapping.setSetMethodName("setWriteTransformers");
writeTransformersMapping.setReferenceClass(WriteTransformerMetadata.class);
writeTransformersMapping.setXPath("orm:write-transformer");
descriptor.addMapping(writeTransformersMapping);
descriptor.addMapping(getPropertyMapping());
descriptor.addMapping(getAccessMethodsMapping());
// Attribute mappings
descriptor.addMapping(getNameAttributeMapping());
descriptor.addMapping(getFetchAttributeMapping());
descriptor.addMapping(getOptionalAttributeMapping());
descriptor.addMapping(getAccessAttributeMapping());
descriptor.addMapping(getMutableAttributeMapping());
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping 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.mappings.XMLCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class XmlElementTestCases method testContainerType.
/*
public void testTeamWithListOfPlayersSchemaGen() {
String metadataFile = PATH + "team-oxm.xml";
InputStream iStream = loader.getResourceAsStream(metadataFile);
if (iStream == null) {
fail("Couldn't load metadata file [" + metadataFile + "]");
}
HashMap<String, Source> metadataSourceMap = new HashMap<String, Source>();
metadataSourceMap.put(CONTEXT_PATH, new StreamSource(iStream));
Map<String, Map<String, Source>> properties = new HashMap<String, Map<String, Source>>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
try {
JAXBContext jContext = (JAXBContext) JAXBContextFactory.createContext(new Class[] { Team.class }, properties, loader);
MySchemaOutputResolver oResolver = new MySchemaOutputResolver();
jContext.generateSchema(oResolver);
// validate schema
String controlSchema = PATH + "team-schema.xsd";
compareSchemas(oResolver.schemaFiles.get(EMPTY_NAMESPACE), new File(controlSchema));
} catch (JAXBException e) {
fail("An exception occurred creating the JAXBContext: " + e.getMessage());
}
}
*/
/**
* Test setting the container class via container-type attribute.
*
* Positive test.
*/
public void testContainerType() {
XMLDescriptor xDesc = ((JAXBContext) jaxbContext).getXMLContext().getDescriptor(new QName("employee"));
assertNotNull("No descriptor was generated for Employee.", xDesc);
DatabaseMapping mapping = xDesc.getMappingForAttributeName("myEmployees");
assertNotNull("No mapping exists on Employee for attribute [myEmployees].", mapping);
assertTrue("Expected an XMLCompositeCollectionMapping for attribute [myEmployees], but was [" + mapping.toString() + "].", mapping instanceof XMLCompositeCollectionMapping);
assertTrue("Expected container class [java.util.LinkedList] but was [" + mapping.getContainerPolicy().getContainerClassName() + "]", mapping.getContainerPolicy().getContainerClassName().equals("java.util.LinkedList"));
}
use of org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping in project eclipselink by eclipse-ee4j.
the class PersistenceXMLMappings method buildPersistenceXMLDescriptor.
/**
* INTERNAL:
*/
private static XMLDescriptor buildPersistenceXMLDescriptor(NamespaceResolver resolver) {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setNamespaceResolver(resolver);
descriptor.setJavaClass(PersistenceXML.class);
descriptor.setDefaultRootElement("persistence");
XMLCompositeCollectionMapping puMapping = new XMLCompositeCollectionMapping();
puMapping.setAttributeName("persistenceUnitInfos");
puMapping.setReferenceClass(SEPersistenceUnitInfo.class);
puMapping.setXPath("persistence-unit");
descriptor.addMapping(puMapping);
return descriptor;
}
Aggregations