use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDODataObject method defineOpenContentProperty.
public Property defineOpenContentProperty(String name, Object value, Type sdotype) throws UnsupportedOperationException, IllegalArgumentException {
if (value == null) {
return null;
}
if (sdotype == null) {
return defineOpenContentProperty(name, value);
}
DataObject propertyDO = aHelperContext.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
propertyDO.set("name", name);
boolean isMany = false;
boolean isContainment = false;
Class<? extends Object> valueClass = value.getClass();
if (value instanceof Collection) {
if (((Collection) value).size() > 0) {
Object firstObject = ((Collection) value).iterator().next();
if (firstObject != null) {
valueClass = firstObject.getClass();
if (firstObject instanceof DataObject) {
if (((DataObject) firstObject).getContainer() == null) {
isContainment = true;
}
sdotype = ((DataObject) firstObject).getType();
} else {
sdotype = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(valueClass);
}
}
}
isMany = true;
} else if (value instanceof DataObject) {
if (((DataObject) value).getContainer() == null) {
isContainment = true;
}
sdotype = ((DataObject) value).getType();
} else {
sdotype = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(valueClass);
}
propertyDO.set("type", sdotype);
propertyDO.set("many", isMany);
propertyDO.set("containment", isContainment);
return aHelperContext.getTypeHelper().defineOpenContentProperty(null, propertyDO);
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOSequence method convertToSetting.
private Setting convertToSetting(Property property, Object value) {
SDOProperty sdoProperty = (SDOProperty) property;
DatabaseMapping mapping = sdoProperty.getXmlMapping();
Setting setting = new Setting();
SDOType sdoType = dataObject.getType();
XMLDescriptor xmlDescriptor = sdoType.getXmlDescriptor();
if (null == mapping) {
setting.setObject(dataObject);
mapping = xmlDescriptor.getMappingForAttributeName("openContentProperties");
setting.setMapping(mapping);
XMLRoot xmlRoot = new XMLRoot();
if (value instanceof XMLRoot) {
xmlRoot.setLocalName(((XMLRoot) value).getLocalName());
xmlRoot.setNamespaceURI(((XMLRoot) value).getNamespaceURI());
xmlRoot.setObject(((XMLRoot) value).getObject());
} else {
xmlRoot.setLocalName(sdoProperty.getName());
xmlRoot.setNamespaceURI(sdoProperty.getUri());
xmlRoot.setObject(value);
// do not set schema type for global properties
SDOTypeHelper hlpr = (SDOTypeHelper) dataObject.getType().getHelperContext().getTypeHelper();
if (hlpr.getOpenContentProperty(sdoProperty.getUri(), sdoProperty.getName()) == null) {
QName schemaTypeQName = hlpr.getXSDTypeFromSDOType(property.getType());
if (schemaTypeQName != null && schemaTypeQName != XMLConstants.STRING_QNAME) {
xmlRoot.setSchemaType(schemaTypeQName);
}
}
}
setting.setValue(xmlRoot, false);
} else {
setting = convertToSetting(mapping, value);
}
return setting;
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOXMLHelperDelegate method getTopLinkProject.
@Override
public Project getTopLinkProject() {
if (topLinkProject == null) {
topLinkProject = new Project();
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.setEqualNamespaceResolvers(false);
topLinkProject.setDatasourceLogin(xmlLogin);
// 200606_changeSummary
NamespaceResolver nr = new NamespaceResolver();
SDOTypeHelper sdoTypeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
String sdoPrefix = sdoTypeHelper.getPrefix(SDOConstants.SDO_URL);
nr.put(sdoPrefix, SDOConstants.SDO_URL);
SDOType changeSummaryType = (SDOType) sdoTypeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
changeSummaryType.getXmlDescriptor().setNamespaceResolver(nr);
topLinkProject.addDescriptor(changeSummaryType.getXmlDescriptor());
SDOType openSequencedType = (SDOType) aHelperContext.getTypeHelper().getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType");
topLinkProject.addDescriptor(openSequencedType.getXmlDescriptor());
SDOTypeType typeType = (SDOTypeType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
typeType.getXmlDescriptor().setNamespaceResolver(nr);
if (!typeType.isInitialized()) {
typeType.initializeMappings();
}
topLinkProject.addDescriptor(typeType.getXmlDescriptor());
SDOPropertyType propertyType = (SDOPropertyType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
if (!propertyType.isInitialized()) {
propertyType.initializeMappings();
}
topLinkProject.addDescriptor(propertyType.getXmlDescriptor());
((SDOTypeHelper) aHelperContext.getTypeHelper()).addWrappersToProject(topLinkProject);
}
return topLinkProject;
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper in project eclipselink by eclipse-ee4j.
the class SDOXMLHelperDelegate method getXmlMarshaller.
private XMLMarshaller getXmlMarshaller(Object options) {
XMLMarshaller xmlMarshaller = getXmlMarshaller().clone();
if (null == options) {
return xmlMarshaller;
}
try {
DataObject optionsDO = (DataObject) options;
if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) {
xmlMarshaller.setAttachmentMarshaller((XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION));
}
xmlMarshaller.setMarshalListener(new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
return xmlMarshaller;
} catch (ClassCastException ccException) {
throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
}
}
use of org.eclipse.persistence.sdo.helper.SDOTypeHelper 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;
}
Aggregations