org.apache.tuscany.sdo.util
Class SDOUtil

java.lang.Object
  extended by org.apache.tuscany.sdo.util.SDOUtil

public final class SDOUtil
extends java.lang.Object

This class provides some useful static utility functions which are not specified in the SDO specification itself. Use of the functions in this class is recommended, instead of resorting to low-level implementation-specific APIs.


Constructor Summary
SDOUtil()
           
 
Method Summary
static void addAliasName(commonj.sdo.Property property, java.lang.String aliasName)
           
static void addAliasName(commonj.sdo.Type type, java.lang.String aliasName)
           
static void addBaseType(commonj.sdo.Type type, commonj.sdo.Type baseType)
           
static java.lang.String convertToString(commonj.sdo.Type dataType, java.lang.Object value)
          Converts an instance of a data type to a string literal representation.
static commonj.sdo.helper.CopyHelper createCrossScopeCopyHelper(commonj.sdo.helper.TypeHelper targetScope)
          Create a new cross scope CopyHelper.
static commonj.sdo.helper.DataFactory createDataFactory(commonj.sdo.helper.TypeHelper scope)
          Create a new DataFactory, with visibility to types in the specified TypeHelper scope.
static commonj.sdo.DataGraph createDataGraph()
          Create an empty data graph.
static commonj.sdo.DataObject createDataTypeWrapper(commonj.sdo.Type dataType, java.lang.Object value)
          Create a DataObject wrapper for an instance of the specified dataType.
static java.lang.Object createFromString(commonj.sdo.Type dataType, java.lang.String literal)
          Creates an instance of a data type from the specified string.
static commonj.sdo.Property createProperty(commonj.sdo.Type containingType, java.lang.String name, commonj.sdo.Type propertyType)
           
static commonj.sdo.Type createType(commonj.sdo.helper.TypeHelper scope, java.lang.String uri, java.lang.String name, boolean isDataType)
           
static commonj.sdo.helper.TypeHelper createTypeHelper()
          Create a new TypeHelper instance.
static commonj.sdo.helper.XMLHelper createXMLHelper(commonj.sdo.helper.TypeHelper scope)
          Create a new XMLHelper, with visibility to types in the specified TypeHelper scope.
static XMLStreamHelper createXMLStreamHelper(commonj.sdo.helper.TypeHelper scope)
          Create a new XMLStreamHelper, with visibility to types in the specified TypeHelper scope.
static commonj.sdo.helper.XSDHelper createXSDHelper(commonj.sdo.helper.TypeHelper scope)
          Create a new XSDHelper, with visibility to types in the specified TypeHelper scope.
static commonj.sdo.Type getJavaSDOType(java.lang.Class javaClass)
          Get the SDO built-in type corresponding to the specified Java instanceClass.
static commonj.sdo.Sequence getSubstitutionValues(commonj.sdo.DataObject dataObject, commonj.sdo.Property head)
          Gets the Sequence corresponding to the specified substitutable Property of the specified DataObject.
static java.util.List getTypes(commonj.sdo.helper.TypeHelper scope, java.lang.String uri)
          Gets all of the types associated with a uri.
static commonj.sdo.Type getXSDSDOType(java.lang.String xsdType)
          Get the SDO built-in type corresponding to the specified XSD type in the XML Schema namespace ("http://www.w3.org/2001/XMLSchema").
static boolean isMany(commonj.sdo.Property property, commonj.sdo.DataObject context)
          Returns whether the Property is many-valued given the specified context.
static boolean isRequired(commonj.sdo.Property property)
          Return whether at least one value is required for a valid instance of the specified property.
static commonj.sdo.DataGraph loadDataGraph(java.io.InputStream inputStream, java.util.Map options)
          Load a serialized data graph from the specified insputStream.
static void registerDataGraphTypes(commonj.sdo.DataGraph dataGraph, java.util.List types)
          Registers the specified type(s) to be serialized along with the data object(s) in the graph.
static void registerStaticTypes(java.lang.Class factoryClass)
          Register and initialize the SDO types supported by the specified generated factory class.
static void saveDataGraph(commonj.sdo.DataGraph dataGraph, java.io.OutputStream outputStream, java.util.Map options)
          Serialize the specified data graph to the specified outputStream.
static void setAbstract(commonj.sdo.Type type, boolean isAbstract)
           
static void setContainment(commonj.sdo.Property property, boolean isContainment)
           
static void setDefault(commonj.sdo.Property property, java.lang.String defaultValue)
           
static void setJavaClassName(commonj.sdo.Type type, java.lang.String javaClassName)
           
static void setMany(commonj.sdo.Property property, boolean isMany)
           
static void setOpen(commonj.sdo.Type type, boolean isOpen)
           
static void setOpposite(commonj.sdo.Property property, commonj.sdo.Property opposite)
           
static void setReadOnly(commonj.sdo.Property property, boolean isReadOnly)
           
static void setRootObject(commonj.sdo.DataGraph dataGraph, commonj.sdo.DataObject rootObject)
          Set the root object of a data graph.
static void setSequenced(commonj.sdo.Type type, boolean isSequenced)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SDOUtil

public SDOUtil()
Method Detail

createDataTypeWrapper

public static commonj.sdo.DataObject createDataTypeWrapper(commonj.sdo.Type dataType,
                                                           java.lang.Object value)
Create a DataObject wrapper for an instance of the specified dataType. This method is typically used to create a root object that can be passed to the XMLHelper.save() method when the root element to be serialized is an XMLSchema simpleType.

Parameters:
dataType - a Type for which isDataType() returns true.
value - the instance value.
Returns:
a DataObject wrapper for the specified value.

createFromString

public static java.lang.Object createFromString(commonj.sdo.Type dataType,
                                                java.lang.String literal)
Creates an instance of a data type from the specified string.

Parameters:
dataType - a Type, for which isDataType() returns true, to instantiate.
literal - the string value of the dataType.
Returns:
an instance of the dataType.
See Also:
convertToString(Type, Object)

convertToString

public static java.lang.String convertToString(commonj.sdo.Type dataType,
                                               java.lang.Object value)
Converts an instance of a data type to a string literal representation.

Parameters:
dataType - the Type, for which isDataType() returns true, of the value to convert.
value - a value of the dataType.
Returns:
the string literal representation of the value.
See Also:
createFromString(Type, String)

getXSDSDOType

public static commonj.sdo.Type getXSDSDOType(java.lang.String xsdType)
Get the SDO built-in type corresponding to the specified XSD type in the XML Schema namespace ("http://www.w3.org/2001/XMLSchema").

Parameters:
xsdType - a type name in the XML Schema namespace.
Returns:
the SDO built-in Type corresponding to the specified XSD type.

getSubstitutionValues

public static commonj.sdo.Sequence getSubstitutionValues(commonj.sdo.DataObject dataObject,
                                                         commonj.sdo.Property head)
Gets the Sequence corresponding to the specified substitutable Property of the specified DataObject.

Parameters:
dataObject - the data object.
head - a substitution group head property.
Returns:
the Sequence corresponding to the specified substitutable Property of the specified DataObject or null if the specified Property isn't a substitution head.

getJavaSDOType

public static commonj.sdo.Type getJavaSDOType(java.lang.Class javaClass)
Get the SDO built-in type corresponding to the specified Java instanceClass.

Parameters:
javaClass - the Java instanceClass of the type.
Returns:
the SDO built-in Type corresponding to the specified instanceClass.

isRequired

public static boolean isRequired(commonj.sdo.Property property)
Return whether at least one value is required for a valid instance of the specified property.

Parameters:
the - property in question.
Returns:
true if the property is required.

isMany

public static boolean isMany(commonj.sdo.Property property,
                             commonj.sdo.DataObject context)
Returns whether the Property is many-valued given the specified context.

Parameters:
property - The Property in question
context - The context to check whether the specified Property is many-valued
Returns:
true if the Property is many-valued given the specified context.

createDataGraph

public static commonj.sdo.DataGraph createDataGraph()
Create an empty data graph.

Returns:
the new data graph instance.

setRootObject

public static void setRootObject(commonj.sdo.DataGraph dataGraph,
                                 commonj.sdo.DataObject rootObject)
Set the root object of a data graph.

Parameters:
dataGraph - the data graph in which to set the root object.
rootObject - the root object.

loadDataGraph

public static commonj.sdo.DataGraph loadDataGraph(java.io.InputStream inputStream,
                                                  java.util.Map options)
                                           throws java.io.IOException
Load a serialized data graph from the specified insputStream.

Parameters:
inputStream - the inputStream of the data graph.
options - loader control options, or null.
Returns:
the de-serialized data graph.
Throws:
java.io.IOException

saveDataGraph

public static void saveDataGraph(commonj.sdo.DataGraph dataGraph,
                                 java.io.OutputStream outputStream,
                                 java.util.Map options)
                          throws java.io.IOException
Serialize the specified data graph to the specified outputStream.

Parameters:
dataGraph - the data graph to save.
outputStream - the outputStream for the data graph.
options - serializer control options, or null.
Throws:
java.io.IOException

registerDataGraphTypes

public static void registerDataGraphTypes(commonj.sdo.DataGraph dataGraph,
                                          java.util.List types)
Registers the specified type(s) to be serialized along with the data object(s) in the graph. For example, the list of types returned from TypeHelper.define(commonj.sdo.DataObject) can be registered with this method, allowing deserialization of instances of a dynamically defined model.

Parameters:
dataGraph - the DataGraph in which to register the specified type(s).
types - a list containing the type(s) to be registered (TBD or null to automatically register all types used by the objects in the DataGraph).

createTypeHelper

public static commonj.sdo.helper.TypeHelper createTypeHelper()
Create a new TypeHelper instance. The returned type helper will have visibility of types registered directly by calling a define method on it or by calling define on an associated XSDHelper. It will also have visibility of static types registered by calling SDOUtil.registerStaticTypes in the same classLoader scope.

Returns:
the new TypeHelper.

createDataFactory

public static commonj.sdo.helper.DataFactory createDataFactory(commonj.sdo.helper.TypeHelper scope)
Create a new DataFactory, with visibility to types in the specified TypeHelper scope.

Parameters:
scope - the TypeHelper to use for locating types.
Returns:
the new DataFactory.

createXMLHelper

public static commonj.sdo.helper.XMLHelper createXMLHelper(commonj.sdo.helper.TypeHelper scope)
Create a new XMLHelper, with visibility to types in the specified TypeHelper scope.

Parameters:
scope - the TypeHelper to use for locating types.
Returns:
the new XMLHelper.

createXSDHelper

public static commonj.sdo.helper.XSDHelper createXSDHelper(commonj.sdo.helper.TypeHelper scope)
Create a new XSDHelper, with visibility to types in the specified TypeHelper scope.

Parameters:
scope - the TypeHelper to use for locating and populating types.
Returns:
the new XSDHelper.

createXMLStreamHelper

public static XMLStreamHelper createXMLStreamHelper(commonj.sdo.helper.TypeHelper scope)
Create a new XMLStreamHelper, with visibility to types in the specified TypeHelper scope.

Parameters:
scope - the TypeHelper to use for locating types.
Returns:
the new XMLStreamHelper.

createCrossScopeCopyHelper

public static commonj.sdo.helper.CopyHelper createCrossScopeCopyHelper(commonj.sdo.helper.TypeHelper targetScope)
Create a new cross scope CopyHelper.

Parameters:
targetScope - the TypeHelper containing the Types to use to create the copy objects.
Returns:
the new CopyHelper.

getTypes

public static java.util.List getTypes(commonj.sdo.helper.TypeHelper scope,
                                      java.lang.String uri)
Gets all of the types associated with a uri.

Parameters:
scope - the TypeHelper to use for locating types.
uri. - Uri of the Types
Returns:
List. List containing instances of Type, null if uri is not found.

createType

public static commonj.sdo.Type createType(commonj.sdo.helper.TypeHelper scope,
                                          java.lang.String uri,
                                          java.lang.String name,
                                          boolean isDataType)

addBaseType

public static void addBaseType(commonj.sdo.Type type,
                               commonj.sdo.Type baseType)

addAliasName

public static void addAliasName(commonj.sdo.Type type,
                                java.lang.String aliasName)

setOpen

public static void setOpen(commonj.sdo.Type type,
                           boolean isOpen)

setSequenced

public static void setSequenced(commonj.sdo.Type type,
                                boolean isSequenced)

setAbstract

public static void setAbstract(commonj.sdo.Type type,
                               boolean isAbstract)

setJavaClassName

public static void setJavaClassName(commonj.sdo.Type type,
                                    java.lang.String javaClassName)

createProperty

public static commonj.sdo.Property createProperty(commonj.sdo.Type containingType,
                                                  java.lang.String name,
                                                  commonj.sdo.Type propertyType)

addAliasName

public static void addAliasName(commonj.sdo.Property property,
                                java.lang.String aliasName)

setMany

public static void setMany(commonj.sdo.Property property,
                           boolean isMany)

setContainment

public static void setContainment(commonj.sdo.Property property,
                                  boolean isContainment)

setDefault

public static void setDefault(commonj.sdo.Property property,
                              java.lang.String defaultValue)

setReadOnly

public static void setReadOnly(commonj.sdo.Property property,
                               boolean isReadOnly)

setOpposite

public static void setOpposite(commonj.sdo.Property property,
                               commonj.sdo.Property opposite)

registerStaticTypes

public static void registerStaticTypes(java.lang.Class factoryClass)
Register and initialize the SDO types supported by the specified generated factory class. This function must be called before instances of the generated types can be created/used. The registered types will be visible in all TypeHelper's created in the same classLoader scope as the call to this function.

Parameters:
factoryClass - the generated factory class.


Copyright © 2006 Apache Software Foundation. All Rights Reserved.