use of org.eclipse.persistence.sdo.SDOType in project metro-jax-ws by eclipse-ee4j.
the class SDOUtils method validateSupportedType.
public static boolean validateSupportedType(HelperContext hc, String javaType, QName qname) {
TypeHelper typeHelper = hc.getTypeHelper();
if (qname != null) {
Type type = typeHelper.getType(qname.getNamespaceURI(), qname.getLocalPart());
String java = ((SDOType) type).getInstanceClassName();
if (java != null) {
return java.equals(javaType);
}
return false;
} else {
if (isPrimitive(javaType)) {
return true;
}
try {
Class cls = Thread.currentThread().getContextClassLoader().loadClass(javaType);
Type type = typeHelper.getType(cls);
return type != null;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
use of org.eclipse.persistence.sdo.SDOType in project metro-jax-ws by eclipse-ee4j.
the class Xsd2JavaSDOModel method getJavaTypeForElementName.
/**
* return the java type used for the element, only Global elements can be located.
* Containing types are not searched
*/
public String getJavaTypeForElementName(QName qname) {
XSDHelper xsdHelper = context.getXSDHelper();
Property globalProperty = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
if (globalProperty == null) {
throw new RuntimeException("Given element with name: " + qname + "is not found.");
}
Type elementType = globalProperty.getType();
if (elementType == null) {
throw new RuntimeException("Given element with name: " + qname + "is not found.");
}
return ((SDOType) elementType).getInstanceClassName();
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method initOpenProps.
private void initOpenProps() {
SDOType typeType = this.getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
openContentProperties = new HashMap();
openContentProperties.put(SDOConstants.MIME_TYPE_QNAME, SDOConstants.MIME_TYPE_PROPERTY);
openContentProperties.put(SDOConstants.MIME_TYPE_PROPERTY_QNAME, SDOConstants.MIME_TYPE_PROPERTY_PROPERTY);
openContentProperties.put(SDOConstants.SCHEMA_TYPE_QNAME, new SDOProperty(aHelperContext, SDOConstants.ORACLE_SDO_URL, SDOConstants.XML_SCHEMA_TYPE_NAME, typeType));
openContentProperties.put(SDOConstants.JAVA_CLASS_QNAME, SDOConstants.JAVA_CLASS_PROPERTY);
openContentProperties.put(SDOConstants.XML_ELEMENT_QNAME, SDOConstants.XMLELEMENT_PROPERTY);
openContentProperties.put(SDOConstants.XML_DATATYPE_QNAME, new SDOProperty(aHelperContext, SDOConstants.SDOXML_URL, SDOConstants.SDOXML_DATATYPE, typeType));
openContentProperties.put(SDOConstants.XML_ID_PROPERTY_QNAME, SDOConstants.ID_PROPERTY);
openContentProperties.put(SDOConstants.DOCUMENTATION_PROPERTY_QNAME, SDOConstants.DOCUMENTATION_PROPERTY);
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method getType.
/**
* Return the Type for this interfaceClass or null if not found.
* @param interfaceClass is the interface for the DataObject's Type -
* type.getInstanceClass();
* @return the Type for this interfaceClass or null if not found.
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public SDOType getType(Class interfaceClass) {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Looking for : " + interfaceClass);
}
final Object[] searchSources = new Object[] { interfacesToSDOTypeHashMap, sdoTypeForSimpleJavaType, getTypesHashMap().values(), anonymousTypes, commonjHashMap.values() };
for (int i = 0; i < searchSources.length; i++) {
Object searchSource = searchSources[i];
if (searchSource == null)
continue;
SDOType type;
if (searchSource instanceof Map) {
type = ((Map<Class<?>, SDOType>) searchSource).get(interfaceClass);
} else {
// collection
type = getFromCollection(((Collection<SDOType>) searchSource), interfaceClass);
}
if (type != null) {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(interfaceClass + " was found in: " + SEARCH_SOURCES_NAMES[i] + '.');
}
return type;
}
}
if (LOGGER.isLoggable(Level.INFO)) {
final StringBuilder log = new StringBuilder();
log.append("Not found: ").append(interfaceClass).append('\n');
for (int i = 0; i < searchSources.length; i++) {
// let's show content of all search sources
log.append("Content of ").append(SEARCH_SOURCES_NAMES[i]).append(": ");
final Object searchSource = searchSources[i];
if (searchSource == null) {
log.append("null");
} else {
if (searchSource instanceof Map) {
log.append(((Map) searchSource).keySet());
} else {
// collection
for (SDOType sdoType : (Collection<SDOType>) searchSource) {
log.append(sdoType.getInstanceClass()).append(", ");
}
}
}
log.append('\n');
}
LOGGER.info(log.toString());
}
return null;
}
use of org.eclipse.persistence.sdo.SDOType in project eclipselink by eclipse-ee4j.
the class SDOTypeHelperDelegate method buildPropertyFromDataObject.
private SDOProperty buildPropertyFromDataObject(DataObject dataObject, Type containingType, List types) {
String nameValue = dataObject.getString("name");
Object typeObjectValue = dataObject.get("type");
if (isXmlNameValidationEnabled && !SDOUtil.isValidXmlNCName(nameValue)) {
throw new IllegalArgumentException(SDOException.errorDefiningPropertyInvalidName(nameValue));
}
SDOProperty newProperty = new SDOProperty(aHelperContext);
newProperty.setName(nameValue);
Type typeValue = (Type) getValueFromObject(typeObjectValue, types);
newProperty.setType(typeValue);
if (typeValue != null) {
if (typeValue == SDOConstants.SDO_BYTES) {
newProperty.setXsdType(XMLConstants.BASE_64_BINARY_QNAME);
} else if (typeValue.isDataType()) {
if (isBaseTypeBytes(typeValue)) {
newProperty.setXsdType(XMLConstants.BASE_64_BINARY_QNAME);
}
}
}
newProperty.setAppInfoElements((List) dataObject.get(SDOConstants.APPINFO));
if (dataObject.isSet("containment")) {
newProperty.setContainment(dataObject.getBoolean("containment"));
} else {
if (typeValue != null) {
newProperty.setContainment(!typeValue.isDataType());
}
}
newProperty.setReadOnly(dataObject.getBoolean("readOnly"));
newProperty.setMany(dataObject.getBoolean("many"));
newProperty.setNullable(dataObject.getBoolean("nullable"));
List aliasNames = dataObject.getList("aliasName");
for (int i = 0; i < aliasNames.size(); i++) {
Object aliasName = aliasNames.get(i);
newProperty.getAliasNames().add(aliasName);
}
Object opposite = dataObject.get("opposite");
if (opposite != null) {
if (opposite instanceof SDOProperty) {
newProperty.setOpposite((SDOProperty) opposite);
((SDOProperty) opposite).setOpposite(newProperty);
} else if (opposite instanceof DataObject) {
SDOProperty prop = (SDOProperty) typeValue.getProperty(((DataObject) opposite).getString("name"));
if (prop != null) {
newProperty.setOpposite(prop);
prop.setOpposite(newProperty);
}
}
}
// set the default only if the default on the dataObject is set
if (dataObject.isSet("default")) {
newProperty.setDefault(dataObject.get("default"));
}
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);
newProperty.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);
newProperty.setInstanceProperty(nextProp, value);
}
// verify that this property has a type set bug 5768381
if (newProperty.getType() == null) {
throw SDOException.noTypeSpecifiedForProperty(newProperty.getName());
}
if (containingType != null) {
((SDOType) containingType).addDeclaredProperty(newProperty);
if (aHelperContext.getXSDHelper().isElement(newProperty) || newProperty.getType().isChangeSummaryType()) {
newProperty.setNamespaceQualified(true);
}
newProperty.buildMapping(containingType.getURI());
}
return newProperty;
}
Aggregations