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.


Field Summary
static java.lang.String XML_LOAD_LaxForm
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_LOAD_SCHEMA
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_SAVE_DocType
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_SAVE_INDENT
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_SAVE_LineBreak
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_SAVE_LineWidth
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
static java.lang.String XML_SAVE_MARGIN
          Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
 
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)
           
protected static void addInstanceProperties(org.eclipse.emf.ecore.EModelElement metaObject, commonj.sdo.DataObject dataObject)
           
static void addPropertyInstanceProperties(commonj.sdo.Property definedProperty, commonj.sdo.DataObject modeledProperty)
           
static void addTypeInstanceProperties(commonj.sdo.Type definedType, commonj.sdo.DataObject modeledType)
           
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)
          Deprecated. see #createHelperContext(TypeHelper)
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 createGlobalProperty(commonj.sdo.helper.TypeHelper scope, java.lang.String uri, java.lang.String name, commonj.sdo.Type type)
           
static commonj.sdo.helper.HelperContext createHelperContext()
          Create a HelperContext.
static commonj.sdo.helper.HelperContext createHelperContext(boolean extensibleNamespaces)
          Create a HelperContext to provide access to a consistent set of Helpers which make use of a new TypeHelper instance to provide scope for type definitions.
static java.io.ObjectInputStream createObjectInputStream(java.io.InputStream inputStream, commonj.sdo.helper.HelperContext helperContext)
          Create a new ObjectInputStream, under the helperContextScope
static java.io.ObjectOutputStream createObjectOutputStream(java.io.OutputStream outputStream, commonj.sdo.helper.HelperContext helperContext)
          Create a new ObjectOutputStream, under the helperContextScope.
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()
          Deprecated. see #createHelperContext(TypeHelper)
static commonj.sdo.helper.XMLHelper createXMLHelper(commonj.sdo.helper.TypeHelper scope)
          Deprecated. see #createHelperContext(TypeHelper)
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)
          Deprecated. see #createHelperContext(TypeHelper)
static commonj.sdo.Type getJavaSDOType(java.lang.Class javaClass)
          Get the SDO built-in type corresponding to the specified Java instanceClass.
static java.util.List getOpenContentProperties(commonj.sdo.DataObject dataObject)
           
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 isDocumentRoot(commonj.sdo.Type type)
           
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 commonj.sdo.DataGraph loadDataGraph(java.io.InputStream inputStream, java.util.Map options, commonj.sdo.helper.TypeHelper scope)
          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.
protected static void registerLoadingScope(java.util.Map options, commonj.sdo.helper.TypeHelper scope)
           
static void registerStaticTypes(java.lang.Class factoryClass)
          Deprecated. see the register(HelperContext) metods on generated Factory classes
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
 

Field Detail

XML_SAVE_LineBreak

public static final java.lang.String XML_SAVE_LineBreak
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_SAVE_INDENT

public static final java.lang.String XML_SAVE_INDENT
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_SAVE_MARGIN

public static final java.lang.String XML_SAVE_MARGIN
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_SAVE_LineWidth

public static final java.lang.String XML_SAVE_LineWidth
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_SAVE_DocType

public static final java.lang.String XML_SAVE_DocType
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_LOAD_SCHEMA

public static final java.lang.String XML_LOAD_SCHEMA
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values

XML_LOAD_LaxForm

public static final java.lang.String XML_LOAD_LaxForm
Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)

See Also:
Constant Field Values
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

registerLoadingScope

protected static void registerLoadingScope(java.util.Map options,
                                           commonj.sdo.helper.TypeHelper scope)

loadDataGraph

public static commonj.sdo.DataGraph loadDataGraph(java.io.InputStream inputStream,
                                                  java.util.Map options,
                                                  commonj.sdo.helper.TypeHelper scope)
                                           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.
scope - To register deserialized Types and utilize already registered Types in order to instantiate expected DataObject instances, null for TypeHelper.INSTANCE.
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).

createHelperContext

public static commonj.sdo.helper.HelperContext createHelperContext(boolean extensibleNamespaces)
Create a HelperContext to provide access to a consistent set of Helpers which make use of a new TypeHelper instance to provide scope for type definitions.

Parameters:
extensibleNamespaces - true if the contents of a namespaces should be incrementally modifiable
Returns:
the new HelperContext

createHelperContext

public static commonj.sdo.helper.HelperContext createHelperContext()
Create a HelperContext.

Returns:
the new HelperContext
See Also:
createHelperContext(boolean)

createTypeHelper

public static commonj.sdo.helper.TypeHelper createTypeHelper()
Deprecated. see #createHelperContext(TypeHelper)

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)
Deprecated. see #createHelperContext(TypeHelper)

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)
Deprecated. see #createHelperContext(TypeHelper)

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)
Deprecated. see #createHelperContext(TypeHelper)

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.

createObjectInputStream

public static java.io.ObjectInputStream createObjectInputStream(java.io.InputStream inputStream,
                                                                commonj.sdo.helper.HelperContext helperContext)
                                                         throws java.io.IOException
Create a new ObjectInputStream, under the helperContextScope

Parameters:
scope - the TypeHelper to use for locating types.
Returns:
the new XMLStreamHelper.
Throws:
java.io.IOException

createObjectOutputStream

public static java.io.ObjectOutputStream createObjectOutputStream(java.io.OutputStream outputStream,
                                                                  commonj.sdo.helper.HelperContext helperContext)
                                                           throws java.io.IOException
Create a new ObjectOutputStream, under the helperContextScope.

Parameters:
scope - the TypeHelper to use for locating types.
Returns:
the new XMLStreamHelper.
Throws:
java.io.IOException

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.

getOpenContentProperties

public static java.util.List getOpenContentProperties(commonj.sdo.DataObject dataObject)

isDocumentRoot

public static boolean isDocumentRoot(commonj.sdo.Type type)

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)

createGlobalProperty

public static commonj.sdo.Property createGlobalProperty(commonj.sdo.helper.TypeHelper scope,
                                                        java.lang.String uri,
                                                        java.lang.String name,
                                                        commonj.sdo.Type type)

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)

addTypeInstanceProperties

public static void addTypeInstanceProperties(commonj.sdo.Type definedType,
                                             commonj.sdo.DataObject modeledType)

addPropertyInstanceProperties

public static void addPropertyInstanceProperties(commonj.sdo.Property definedProperty,
                                                 commonj.sdo.DataObject modeledProperty)

addInstanceProperties

protected static void addInstanceProperties(org.eclipse.emf.ecore.EModelElement metaObject,
                                            commonj.sdo.DataObject dataObject)

registerStaticTypes

public static void registerStaticTypes(java.lang.Class factoryClass)
Deprecated. see the register(HelperContext) metods on generated Factory classes

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 © 2007 Apache Software Foundation. All Rights Reserved.