use of org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateWrapperClassAndDescriptor.
private Class<?> generateWrapperClassAndDescriptor(TypeInfo type, QName next, ElementDeclaration nextElement, String nextClassName, String attributeTypeName) {
String namespaceUri = null;
if (next != null) {
// generate a class/descriptor for this element
namespaceUri = next.getNamespaceURI();
if (namespaceUri == null || namespaceUri.equals(XMLProcessor.DEFAULT)) {
namespaceUri = "";
}
}
TypeMappingInfo tmi = nextElement.getTypeMappingInfo();
Class<?> generatedClass = null;
JaxbClassLoader loader = getJaxbClassLoader();
if (tmi != null) {
generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
if (generatedClass == null) {
generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
}
typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
} else {
generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
}
this.qNamesToGeneratedClasses.put(next, generatedClass);
try {
Class<Object> declaredClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
this.qNamesToDeclaredClasses.put(next, declaredClass);
} catch (Exception e) {
}
Descriptor desc = (Descriptor) project.getDescriptor(generatedClass);
if (desc == null) {
desc = new XMLDescriptor();
desc.setJavaClass(generatedClass);
if (nextElement.isList()) {
DirectCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName("value");
mapping.setXPath("text()");
mapping.setUsesSingleNode(true);
mapping.setReuseContainer(true);
if (type != null && type.isEnumerationType()) {
mapping.setValueConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
} else {
try {
Class<Object> fieldElementClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
mapping.setFieldElementClass(fieldElementClass);
} catch (ClassNotFoundException e) {
}
}
if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
} else if (nextClassName.equals("javax.xml.namespace.QName")) {
((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
}
desc.addMapping((CoreMapping) mapping);
} else {
if (nextElement.getJavaTypeName().equals(OBJECT_CLASS_NAME)) {
CompositeObjectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeObjectMapping();
mapping.setAttributeName("value");
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
mapping.setXPath(".");
setTypedTextField((Field) mapping.getField());
desc.addMapping((CoreMapping) mapping);
} else if (isBinaryData(nextElement.getJavaType())) {
BinaryDataMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, MimeTypePolicy, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("value");
mapping.setXPath(".");
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
mapping.setAttributeClassification(attributeClassification);
mapping.setShouldInlineBinaryData(false);
// if(nextElement.getTypeMappingInfo() != null) {
mapping.setSwaRef(nextElement.isXmlAttachmentRef());
mapping.setMimeType(nextElement.getXmlMimeType());
// }
desc.addMapping((CoreMapping) mapping);
} else {
DirectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLDirectMapping();
mapping.setNullValueMarshalled(true);
mapping.setAttributeName("value");
mapping.setXPath("text()");
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
if (nextElement.getDefaultValue() != null) {
mapping.setNullValue(nextElement.getDefaultValue());
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
}
if (helper.isBuiltInJavaType(nextElement.getJavaType())) {
Class<?> attributeClassification = null;
if (nextElement.getJavaType().isPrimitive()) {
attributeClassification = XMLConversionManager.getDefaultManager().convertClassNameToClass(attributeTypeName);
} else {
attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
}
mapping.setAttributeClassification(attributeClassification);
}
IsSetNullPolicy nullPolicy = new IsSetNullPolicy("isSetValue", false, true, XMLNullRepresentationType.ABSENT_NODE);
// nullPolicy.setNullRepresentedByEmptyNode(true);
mapping.setNullPolicy(nullPolicy);
if (type != null && type.isEnumerationType()) {
mapping.setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
}
if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
} else if (nextClassName.equals("javax.xml.namespace.QName")) {
((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
}
if (nextElement.getJavaTypeAdapterClass() != null) {
mapping.setConverter(new XMLJavaTypeConverter(nextElement.getJavaTypeAdapterClass()));
}
desc.addMapping((CoreMapping) mapping);
}
}
if (next != null) {
NamespaceInfo info = getNamespaceInfoForURI(namespaceUri);
if (info != null) {
NamespaceResolver resolver = getNamespaceResolverForDescriptor(info);
String prefix = null;
if (namespaceUri != Constants.EMPTY_STRING) {
prefix = resolver.resolveNamespaceURI(namespaceUri);
if (prefix == null) {
prefix = getPrefixForNamespace(namespaceUri, resolver);
}
}
desc.setNamespaceResolver(resolver);
if (nextElement.isXmlRootElement()) {
desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
} else {
desc.setDefaultRootElement("");
desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
desc.setResultAlwaysXMLRoot(true);
}
} else {
if (namespaceUri.equals("")) {
desc.setDefaultRootElement(next.getLocalPart());
} else {
NamespaceResolver resolver = new org.eclipse.persistence.oxm.NamespaceResolver();
String prefix = getPrefixForNamespace(namespaceUri, resolver);
desc.setNamespaceResolver(resolver);
if (nextElement.isXmlRootElement()) {
desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
} else {
desc.setDefaultRootElement("");
desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
desc.setResultAlwaysXMLRoot(true);
}
}
}
}
project.addDescriptor((CoreDescriptor) desc);
}
return generatedClass;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method getNullPolicyFromProperty.
/**
* Convenience method which returns an AbstractNullPolicy built from an XmlAbstractNullPolicy.
*
* @param nsr if 'NullRepresentedByXsiNil' is true, this is the resolver
* that we will add the schema instance prefix/uri pair to
* @see org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy
* @see org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy
*/
private AbstractNullPolicy getNullPolicyFromProperty(Property property, NamespaceResolver nsr) {
AbstractNullPolicy absNullPolicy = null;
XmlAbstractNullPolicy xmlAbsNullPolicy = property.getNullPolicy();
// policy is assumed to be one of XmlNullPolicy or XmlIsSetNullPolicy
if (xmlAbsNullPolicy instanceof XmlNullPolicy) {
XmlNullPolicy xmlNullPolicy = (XmlNullPolicy) xmlAbsNullPolicy;
NullPolicy nullPolicy = new NullPolicy();
nullPolicy.setSetPerformedForAbsentNode(xmlNullPolicy.isIsSetPerformedForAbsentNode());
absNullPolicy = nullPolicy;
} else {
XmlIsSetNullPolicy xmlIsSetNullPolicy = (XmlIsSetNullPolicy) xmlAbsNullPolicy;
IsSetNullPolicy isSetNullPolicy = new IsSetNullPolicy();
isSetNullPolicy.setIsSetMethodName(xmlIsSetNullPolicy.getIsSetMethodName());
// handle isSetParams
ArrayList<Object> parameters = new ArrayList<>();
ArrayList<Class<?>> parameterTypes = new ArrayList<>();
List<XmlIsSetNullPolicy.IsSetParameter> params = xmlIsSetNullPolicy.getIsSetParameter();
for (XmlIsSetNullPolicy.IsSetParameter param : params) {
String valueStr = param.getValue();
String typeStr = param.getType();
// create a conversion manager instance with the helper's loader
XMLConversionManager mgr = new XMLConversionManager();
mgr.setLoader(helper.getClassLoader());
// handle parameter type
Class<Object> typeClass = mgr.convertClassNameToClass(typeStr);
// handle parameter value
Object parameterValue = mgr.convertObject(valueStr, typeClass);
parameters.add(parameterValue);
parameterTypes.add(typeClass);
}
isSetNullPolicy.setIsSetParameters(parameters.toArray());
isSetNullPolicy.setIsSetParameterTypes(parameterTypes.toArray(new Class<?>[parameterTypes.size()]));
absNullPolicy = isSetNullPolicy;
}
// handle commmon settings
absNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.valueOf(xmlAbsNullPolicy.getNullRepresentationForXml().name()));
absNullPolicy.setNullRepresentedByEmptyNode(xmlAbsNullPolicy.isEmptyNodeRepresentsNull());
boolean xsiRepresentsNull = xmlAbsNullPolicy.isXsiNilRepresentsNull();
if (xsiRepresentsNull) {
absNullPolicy.setNullRepresentedByXsiNil(true);
}
return absNullPolicy;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class XMLEntityMappingsMappingProject method buildCascadeTypeDescriptor.
/**
* INTERNAL:
* XSD: cascade-type
*/
protected ClassDescriptor buildCascadeTypeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(CascadeMetadata.class);
XMLDirectMapping cascadeAllMapping = new XMLDirectMapping();
cascadeAllMapping.setAttributeName("m_cascadeAll");
cascadeAllMapping.setGetMethodName("getCascadeAll");
cascadeAllMapping.setSetMethodName("setCascadeAll");
cascadeAllMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy cascadeAllPolicy = new IsSetNullPolicy("isCascadeAll");
cascadeAllPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
cascadeAllMapping.setNullPolicy(cascadeAllPolicy);
cascadeAllMapping.setXPath("orm:cascade-all");
descriptor.addMapping(cascadeAllMapping);
descriptor.addMapping(getCascadePersistMapping());
XMLDirectMapping cascadeMergeMapping = new XMLDirectMapping();
cascadeMergeMapping.setAttributeName("m_cascadeMerge");
cascadeMergeMapping.setGetMethodName("getCascadeMerge");
cascadeMergeMapping.setSetMethodName("setCascadeMerge");
cascadeMergeMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy cascadeMergePolicy = new IsSetNullPolicy("isCascadeMerge");
cascadeMergePolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
cascadeMergeMapping.setNullPolicy(cascadeMergePolicy);
cascadeMergeMapping.setXPath("orm:cascade-merge");
descriptor.addMapping(cascadeMergeMapping);
XMLDirectMapping cascadeRemoveMapping = new XMLDirectMapping();
cascadeRemoveMapping.setAttributeName("m_cascadeRemove");
cascadeRemoveMapping.setGetMethodName("getCascadeRemove");
cascadeRemoveMapping.setSetMethodName("setCascadeRemove");
cascadeRemoveMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy cascadeRemovePolicy = new IsSetNullPolicy("isCascadeRemove");
cascadeRemovePolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
cascadeRemoveMapping.setNullPolicy(cascadeRemovePolicy);
cascadeRemoveMapping.setXPath("orm:cascade-remove");
descriptor.addMapping(cascadeRemoveMapping);
XMLDirectMapping cascadeRefreshMapping = new XMLDirectMapping();
cascadeRefreshMapping.setAttributeName("m_cascadeRefresh");
cascadeRefreshMapping.setGetMethodName("getCascadeRefresh");
cascadeRefreshMapping.setSetMethodName("setCascadeRefresh");
cascadeRefreshMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy cascadeRefreshPolicy = new IsSetNullPolicy("isCascadeRefresh");
cascadeRefreshPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
cascadeRefreshMapping.setNullPolicy(cascadeRefreshPolicy);
cascadeRefreshMapping.setXPath("orm:cascade-refresh");
descriptor.addMapping(cascadeRefreshMapping);
XMLDirectMapping cascadeDetachMapping = new XMLDirectMapping();
cascadeDetachMapping.setAttributeName("m_cascadeDetach");
cascadeDetachMapping.setGetMethodName("getCascadeDetach");
cascadeDetachMapping.setSetMethodName("setCascadeDetach");
cascadeDetachMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy cascadeDetachPolicy = new IsSetNullPolicy("isCascadeDetach");
cascadeDetachPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
cascadeDetachMapping.setNullPolicy(cascadeDetachPolicy);
cascadeDetachMapping.setXPath("orm:cascade-detach");
descriptor.addMapping(cascadeDetachMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class XMLEntityMappingsMappingProject method getDeleteAllMapping.
/**
* INTERNAL:
*/
protected XMLDirectMapping getDeleteAllMapping() {
XMLDirectMapping deleteAllMapping = new XMLDirectMapping();
deleteAllMapping.setAttributeName("m_deleteAll");
deleteAllMapping.setGetMethodName("getDeleteAll");
deleteAllMapping.setSetMethodName("setDeleteAll");
deleteAllMapping.setXPath("orm:delete-all");
deleteAllMapping.setConverter(new EmptyElementConverter());
IsSetNullPolicy deleteAllPolicy = new IsSetNullPolicy("isDeleteAll");
deleteAllPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
deleteAllMapping.setNullPolicy(deleteAllPolicy);
return deleteAllMapping;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class XMLEntityMappingsMappingProject method getNonCacheableMapping.
/**
* INTERNAL:
*/
protected XMLDirectMapping getNonCacheableMapping() {
XMLDirectMapping noncacheable = new XMLDirectMapping();
noncacheable.setAttributeName("m_nonCacheable");
noncacheable.setGetMethodName("getNonCacheable");
noncacheable.setSetMethodName("setNonCacheable");
noncacheable.setConverter(new EmptyElementConverter());
IsSetNullPolicy cacheablePolicy = new IsSetNullPolicy("isNonCacheable");
cacheablePolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
noncacheable.setNullPolicy(cacheablePolicy);
noncacheable.setXPath("orm:noncacheable");
return noncacheable;
}
Aggregations