use of org.eclipse.persistence.sdo.types.SDOWrapperType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method define.
/**
* Define the DataObject as a Type.
* The Type is available through TypeHelper and DataGraph getType() methods.
* @param dataObject the DataObject representing the Type.
* @return the defined Type.
* @throws IllegalArgumentException if the Type could not be defined.
*/
public synchronized Type define(DataObject dataObject, List types) {
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
if ((dataObject == null) || (dataObject.getType() == null) || (!dataObject.getType().getURI().equals(SDOConstants.SDO_URL)) || (!dataObject.getType().getName().equals(SDOConstants.TYPE))) {
throw new IllegalArgumentException(SDOException.errorDefiningType());
}
String uri = dataObject.getString("uri");
String name = dataObject.getString("name");
if (name == null) {
throw new IllegalArgumentException(SDOException.errorDefiningTypeNoName());
}
SDOType type = (SDOType) typeHelper.getType(uri, name);
if (null != type) {
return type;
}
if (isXmlNameValidationEnabled && !SDOUtil.isValidXmlNCName(name)) {
throw new IllegalArgumentException(SDOException.errorDefiningTypeInvalidName(name));
}
boolean isDataType = dataObject.getBoolean("dataType");
if (isDataType) {
type = new SDODataType(uri, name, this);
} else {
type = new SDOType(uri, name, this);
if (dataObject.getBoolean("sequenced")) {
type.setSequenced(true);
type.setMixed(true);
}
}
type.setDataType(isDataType);
addType(type);
types.add(type);
type.setAppInfoElements((List) dataObject.get(SDOConstants.APPINFO));
type.setAbstract(dataObject.getBoolean("abstract"));
List baseTypes = dataObject.getList("baseType");
for (int i = 0; i < baseTypes.size(); i++) {
SDOType baseType = (SDOType) getValueFromObject(baseTypes.get(i), types);
type.addBaseType(baseType);
}
List aliasNames = dataObject.getList("aliasName");
for (int i = 0; i < aliasNames.size(); i++) {
Object aliasName = aliasNames.get(i);
type.getAliasNames().add(aliasName);
}
List openProps = ((SDODataObject) dataObject)._getOpenContentProperties();
for (int i = 0; i < openProps.size(); i++) {
SDOProperty nextProp = (SDOProperty) openProps.get(i);
Object value = getValueFromObject(dataObject.get(nextProp), types);
type.setInstanceProperty(nextProp, value);
}
List openPropsAttrs = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
for (int i = 0; i < openPropsAttrs.size(); i++) {
SDOProperty nextProp = (SDOProperty) openPropsAttrs.get(i);
Object value = getValueFromObject(dataObject.get(nextProp), types);
type.setInstanceProperty(nextProp, value);
}
if (!type.isDataType()) {
type.preInitialize(null, null);
}
List properties = dataObject.getList("property");
for (int i = 0; i < properties.size(); i++) {
Object nextValue = properties.get(i);
if (nextValue instanceof DataObject) {
buildPropertyFromDataObject((DataObject) nextValue, type, types);
}
}
type.setOpen(dataObject.getBoolean("open"));
if (type.isDataType()) {
QName typeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, name);
if (typeHelper.getWrappersHashMap().get(typeQName) != null) {
// wrappers created, so do not continue on building a new WrapperType.
return type;
}
// Defining a new simple type from a DataObject.
// See also: SDOTypesGenerator:startNewSimpleType for "types from XSD" equivalent
// If this simple type is a restriction, get the QName for the base type and
// include it when creating the WrapperType. The QName will be used during
// conversions (eg. "myBinaryElement" could be a restriction of base64Binary
// or hexBinary.
QName currentTypeQName = null;
if (type.isSubType()) {
SDOType baseType = (SDOType) type.getBaseTypes().get(0);
currentTypeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, baseType.getName());
}
// Create the new WrapperType
SDOWrapperType wrapperType = new SDOWrapperType(type, name, this, currentTypeQName);
// Register WrapperType with maps on TypeHelper
typeHelper.getWrappersHashMap().put(typeQName, wrapperType);
typeHelper.getTypesHashMap().put(typeQName, wrapperType);
typeHelper.getImplClassesToSDOType().put(wrapperType.getXmlDescriptor().getJavaClass(), wrapperType);
// Add descriptor to XMLHelper
ArrayList list = new ArrayList(1);
list.add(wrapperType);
((SDOXMLHelper) aHelperContext.getXMLHelper()).addDescriptors(list);
}
return type;
}
use of org.eclipse.persistence.sdo.types.SDOWrapperType in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method addRootElementToDescriptor.
private void addRootElementToDescriptor(SDOProperty p, String targetNamespace, String xsdName) {
if (!p.getType().isDataType()) {
String prefix = null;
if (targetNamespace != null && !XMLConstants.EMPTY_STRING.equals(targetNamespace)) {
NamespaceResolver nr = p.getType().getXmlDescriptor().getNamespaceResolver();
if (nr != null) {
prefix = nr.resolveNamespaceURI(targetNamespace);
if (null == prefix) {
prefix = nr.generatePrefix();
nr.put(prefix, targetNamespace);
}
}
}
if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
p.getType().getXmlDescriptor().addRootElement(xsdName);
} else {
p.getType().getXmlDescriptor().addRootElement(//
prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + xsdName);
}
} else {
// Types from Schema: isDataType() == true so:
// - find the SDOWrapperType from TypeHelper's WrappersHashMap
// - set the root element name on it
// - add the descriptor to XMLContext's DescriptorsByQName map
// See also: SDOTypeHelperDelegate:defineOpenContentProperty
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(p.getType().getQName());
XMLDescriptor d = wrapperType.getXmlDescriptor(p.getXsdType());
if (wrapperType != null) {
d.addRootElement(xsdName);
QName descriptorQname = new QName(targetNamespace, xsdName);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, d);
}
}
}
use of org.eclipse.persistence.sdo.types.SDOWrapperType in project eclipselink by eclipse-ee4j.
the class SDOTypesGenerator method startNewSimpleType.
private SDOType startNewSimpleType(String targetNamespace, String defaultNamespace, String sdoTypeName, String xsdLocalName, SimpleType simpleType) {
SDOType currentType;
if (null == simpleType.getName()) {
currentType = createSDOTypeForName(targetNamespace, sdoTypeName, xsdLocalName);
currentType.setDataType(true);
} else {
currentType = getGeneratedTypesByXsdQName().get(new QName(targetNamespace, simpleType.getName()));
}
// Defining a new simple type from XSD.
// See also: SDOTypeHelperDelegate:define for "types from DataObjects" equivalent
SDOTypeHelper typeHelper = ((SDOTypeHelper) aHelperContext.getTypeHelper());
// If this simple type is a restriction, get the QName for the base type and
// include it when creating the WrapperType. The QName will be used during
// conversions (eg. "myBinaryElement" could be a restriction of base64Binary
// or hexBinary.
QName baseTypeQName = null;
if (simpleType.getRestriction() != null) {
String baseType = simpleType.getRestriction().getBaseType();
baseTypeQName = this.getQNameForString(defaultNamespace, baseType);
SDOType baseSDOType = getTypeForXSDQName(baseTypeQName);
currentType.addBaseType(baseSDOType);
currentType.setInstanceClass(baseSDOType.getInstanceClass());
}
// Create the new WrapperType
SDOWrapperType wrapperType = new SDOWrapperType(currentType, sdoTypeName, typeHelper, baseTypeQName);
// Register WrapperType with maps on TypeHelper
typeHelper.getWrappersHashMap().put(currentType.getQName(), wrapperType);
typeHelper.getTypesHashMap().put(wrapperType.getQName(), wrapperType);
typeHelper.getImplClassesToSDOType().put(wrapperType.getXmlDescriptor().getJavaClass(), wrapperType);
// Add descriptor to XMLHelper
ArrayList<SDOWrapperType> list = new ArrayList<>(1);
list.add(wrapperType);
((SDOXMLHelper) aHelperContext.getXMLHelper()).addDescriptors(list);
if (simpleType.getAnnotation() != null) {
currentType.setAppInfoElements(simpleType.getAnnotation().getAppInfo());
}
return currentType;
}
use of org.eclipse.persistence.sdo.types.SDOWrapperType in project eclipselink by eclipse-ee4j.
the class SDOHelperTestCases method testUnwrapTypeToSDOWrapperType.
public void testUnwrapTypeToSDOWrapperType() {
Type wrapperType = new SDOWrapperType(teamType, "MyTeamTypeWrapper", (SDOTypeHelper) typeHelper);
assertTrue(SDOHelper.unwrap(wrapperType, SDOWrapperType.class) instanceof SDOWrapperType);
}
use of org.eclipse.persistence.sdo.types.SDOWrapperType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method defineOpenContentProperty.
/**
* INTERNAL:
* @param propertyUri
* @param property
*/
private void defineOpenContentProperty(String propertyUri, String propertyName, Property property) {
if (propertyUri != null) {
QName propertyQName = new QName(propertyUri, propertyName);
openContentProperties.put(propertyQName, property);
boolean isElement = aHelperContext.getXSDHelper().isElement(property);
((SDOXSDHelper) aHelperContext.getXSDHelper()).addGlobalProperty(propertyQName, property, isElement);
((SDOProperty) property).setUri(propertyUri);
XMLDescriptor aDescriptor;
if (property.getType().isDataType()) {
// RICK: Types from DataObjects: isDataType() == true so:
// - find the SDOWrapperType from TypeHelper's WrappersHashMap
// - add the descriptor to XMLContext's DescriptorsByQName map
// See also: SDOTypesGenerator:addRootElementToDescriptor
SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(((SDOProperty) property).getType().getQName());
if (wrapperType != null) {
QName descriptorQname = new QName(propertyUri, propertyName);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, wrapperType.getXmlDescriptor(((SDOProperty) property).getXsdType()));
}
return;
} else {
aDescriptor = ((SDOType) property.getType()).getXmlDescriptor();
}
// synchronized threads that access the NonSynchronizedVector tables in XMLDescriptor
if (aDescriptor != null) {
synchronized (aDescriptor) {
String rootName = propertyName;
String prefix = aDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(propertyUri);
if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(propertyUri);
aDescriptor.getNonNullNamespaceResolver().put(prefix, propertyUri);
}
if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) {
rootName = prefix + ":" + rootName;
}
aDescriptor.setDefaultRootElement(rootName);
QName elementType = new QName(propertyUri, rootName);
aDescriptor.setDefaultRootElementType(elementType);
((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().storeXMLDescriptorByQName(aDescriptor);
}
}
}
}
Aggregations