com.arsdigita.metadata
Class DynamicObjectType

java.lang.Object
  extended bycom.arsdigita.metadata.DynamicElement
      extended bycom.arsdigita.metadata.DynamicObjectType

public class DynamicObjectType
extends com.arsdigita.metadata.DynamicElement

DynamicObjectType is a class that can be used to dynamically create and modify ObjectType. It can be used to create the subtype, add and remove Attributes and RoleReferences as well as perform many other tasks related to the new object type. When the application is done creating the object type, it should call save() to persist the information about the newly created object type.

Version:
$Revision: #23 $ $Date: 2004/04/07 $
Author:
randyg@alum.mit.edu

Field Summary
static String versionId
           
 
Constructor Summary
DynamicObjectType(ObjectType objectType)
          This allows the programmer to instantiate an already existing dynamic object type.
DynamicObjectType(String typeName)
          This allows the programmer to instantiate an already existing dynamic object type.
DynamicObjectType(String name, ObjectType supertype)
          This procedures allows developers to dynamically create object types that subtype existing object types.
DynamicObjectType(String name, ObjectType supertype, Model model)
          This procedures allows developers to dynamically create object types that may or may not subtype an object.
 
Method Summary
 Property addAssociation(String name, ObjectType objType, int mult, Object defaultValue)
          Adds a one-way association (a role reference) to this Dynamic ObjectType.
 Property addCollectionAssociation(String name, ObjectType type)
          Adds a multiplicitous one-way association (a role reference) to this Dynamic ObjectType.
 Property addOptionalAssociation(String name, ObjectType type)
          Adds an optional one-way association (a role reference) to this Dynamic ObjectType.
 Property addOptionalAttribute(String name, SimpleType propertyType)
          This adds an Attribute of multiplicity 0..1 which is the equivalent to adding a column to a table without a "not null" constraint
 Property addOptionalAttribute(String name, SimpleType propertyType, int size)
          This adds an Attribute of multiplicity 0..1 which is the equivalent to adding a column to a table without a "not null" constraint
 Property addRequiredAssociation(String name, ObjectType type, Object defaultValue)
          Adds an required one-way association (a role reference) to this Dynamic ObjectType.
 Property addRequiredAttribute(String name, SimpleType propertyType, int size, Object defaultValue)
          This adds an Attribute of multiplicity 1..1 which is the equivalent to adding a column to a table with a "not null" constraint
 Property addRequiredAttribute(String name, SimpleType propertyType, Object defaultValue)
          This adds an Attribute of multiplicity 1..1 which is the equivalent to adding a column to a table with a "not null" constraint
 ObjectType getObjectType()
          This method returns the ObjectType that is being manipulated by this DynamicObjectType
 boolean hasProperty(String name)
          Returns true if this object type has the specified property.
static void main(String[] args)
          This allows the user to either input or output a given data object type x
 String[] makeMappingTablesDDL()
          Returns an array of Strings containing DDL for new mapping tables.
 String makeObjectTypePDL()
          Creates the PDL for the object type.
 Collection makeTableDDL()
          Returns the table creaton DDL.
 void removeAttribute(String name)
          This removes an attribute from object type definition.
 ObjectType save()
          This persists the changes made so that the information is stored and will not be lost on server restart.
 String toString()
          This prints out a String representation of this object type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

DynamicObjectType

public DynamicObjectType(String name,
                         ObjectType supertype)
This procedures allows developers to dynamically create object types that subtype existing object types. The model.name string must be unique

Parameters:
supertype - This is the existing ObjectType that should be extended to create this ObjectType. If the supertype is a DynamicObjectType, it must be saved before saving this new DynamicObjectType. A supertype can not be null
name - This is the name of the new object type. This should only be the name and should not contain and "." The fully qualified name (which is required by the other constructor) is the model of the supertype followed by a "." followed by the passed in name. This can be retrieved by calling DataType.getQualifiedName(). The name must not be null.

DynamicObjectType

public DynamicObjectType(String name,
                         ObjectType supertype,
                         Model model)
This procedures allows developers to dynamically create object types that may or may not subtype an object. The model.name string must be unique and either the model or the supertype must not be null. If the model is null, the model from the supertype is used.

Parameters:
supertype - This is the existing ObjectType that should be extended to create this ObjectType. If the supertype is a DynamicObjectType, it must be saved before saving this new DynamicObjectType. A supertype can be null.
name - This is the name of the new object type. This should only be the name and should not contain and "." The fully qualified name (which is required by the other constructor) is the model of the supertype followed by a "." followed by the passed in name. This can be retrieved by calling DataType.getQualifiedName(). The name must not be null and must only contain alpha-numeric characters.
model - This is the name of the model that will be used for the object type. If this is specified, it is used as the object type.

DynamicObjectType

public DynamicObjectType(String typeName)
This allows the programmer to instantiate an already existing dynamic object type. Specifically, if a content manager has created an object type and later wants to go back and edit/add the object type definition. This does NOT allow developers to instantiate statically defined ObjectTypes (e.g. com.arsdigita.kernel.User).

Parameters:
typeName - The name of the object type to instantiate. This needs to be the fully qualified name such as "com.arsdigita.cms.metadata.Hotel" This is the same name that is returned by calling DataType.getQualifiedName()
Throws:
PersistenceException - thrown if the requested type cannot be found or has not yet been saved

DynamicObjectType

public DynamicObjectType(ObjectType objectType)
This allows the programmer to instantiate an already existing dynamic object type. Specifically, if a content manager has created an object type and later wants to go back and edit/add the object type definition. This does NOT allow developers to instantiate statically defined ObjectTypes (e.g. com.arsdigita.kernel.User).

Parameters:
objectType - The object type that should be mutated
Throws:
PersistenceException - is thrown if passed in ObjectType is not mutable
Method Detail

hasProperty

public boolean hasProperty(String name)
Returns true if this object type has the specified property.


addOptionalAttribute

public Property addOptionalAttribute(String name,
                                     SimpleType propertyType)
This adds an Attribute of multiplicity 0..1 which is the equivalent to adding a column to a table without a "not null" constraint

Parameters:
name - The name of the new attribute
propertyType - The type of the Property. This should be one of the SimpleTypes specified in MetadataRoot
Returns:
This returns the Attribute that has been added to this DynamicObjectType
Throws:
PersistenceException - if the name is already in use for this object type

addOptionalAttribute

public Property addOptionalAttribute(String name,
                                     SimpleType propertyType,
                                     int size)
This adds an Attribute of multiplicity 0..1 which is the equivalent to adding a column to a table without a "not null" constraint

Parameters:
name - The name of the new attribute
propertyType - The type of the Property. This should be one of the SimpleTypes specified in MetadataRoot
size - This is the size of the attribute. This is an optional argument but is important for Strings. Specifically, if the String size > 4000 then a Clob is used. Otherwise, a varchar is used.
Returns:
This returns the Attribute that has been added to this DynamicObjectType
Throws:
PersistenceException - if the name is already in use for this object type

addRequiredAttribute

public Property addRequiredAttribute(String name,
                                     SimpleType propertyType,
                                     Object defaultValue)
This adds an Attribute of multiplicity 1..1 which is the equivalent to adding a column to a table with a "not null" constraint

You must call save() for the changes to be permanent

Parameters:
name - The name of the new attribute
propertyType - The type of the Property. This should be one of the SimpleTypes specified in MetadataRoot
defaultValue - This is the default value for this column. This is required to be "not null" because it is used to fill in the values for any rows already in the table. Due to limitations in the system, however, you must still set the value on new rows so that you avoid the "not null" constraint violation
Returns:
This returns the Attribute that has been added to this DynamicObjectType
Throws:
PersistenceException - if the name is already in use for this object type or the default value is null

addRequiredAttribute

public Property addRequiredAttribute(String name,
                                     SimpleType propertyType,
                                     int size,
                                     Object defaultValue)
This adds an Attribute of multiplicity 1..1 which is the equivalent to adding a column to a table with a "not null" constraint

You must call save() for the changes to be permanent

Parameters:
name - The name of the new attribute
propertyType - The type of the Property. This should be one of the SimpleTypes specified in MetadataRoot
size - This is the size of the attribute. This is an optional argument but is important for Strings. Specifically, if the String size > 4000 then a Clob is used. Otherwise, a varchar is used.
Returns:
This returns the Attribute that has been added to this DynamicObjectType
Throws:
PersistenceException - if the name is already in use for this object type or the provided default is null.

removeAttribute

public void removeAttribute(String name)
This removes an attribute from object type definition. This can only remove attributes from the dynamic definition and not from the parent defintion. That is, the attribute that should be removed should be found in getAttributes()

This does not remove any information from the database. Rather, it simply dereferences the column in the object type. Therefore, if an attribute is removed, the data can still be recovered

You must call save() for the changes to be permanent

Parameters:
name - the name of the attribute to remove
Throws:
ModelException - if the name passed in is not an Attribute that can be removed

addOptionalAssociation

public Property addOptionalAssociation(String name,
                                       ObjectType type)
Adds an optional one-way association (a role reference) to this Dynamic ObjectType. The referenced type must support MDSQL.

Parameters:
name - the name of the role reference
type - the type of the referenced type
Returns:
the Property that was added to the ObjectType

addRequiredAssociation

public Property addRequiredAssociation(String name,
                                       ObjectType type,
                                       Object defaultValue)
Adds an required one-way association (a role reference) to this Dynamic ObjectType. A default value must be specified. The referenced type must support MDSQL.

Parameters:
name - the name of the role reference
type - the type of the referenced type
defaultValue - the default value of this Property
Returns:
the Property that was added to the ObjectType

addCollectionAssociation

public Property addCollectionAssociation(String name,
                                         ObjectType type)
Adds a multiplicitous one-way association (a role reference) to this Dynamic ObjectType. The referenced type must support MDSQL.

Parameters:
name - the name of the role reference
type - the type of the referenced type
Returns:
the Property that was added to the ObjectType

addAssociation

public Property addAssociation(String name,
                               ObjectType objType,
                               int mult,
                               Object defaultValue)
Adds a one-way association (a role reference) to this Dynamic ObjectType. The referenced type must support MDSQL.

Parameters:
name - the name of the role reference
mult - the multiplicity of the type to add
defaultValue - the default value of the new Property
Returns:
the Property that was added to the ObjectType

save

public ObjectType save()
This persists the changes made so that the information is stored and will not be lost on server restart. No Events will work for new Attributes or RoleReferences before this is called because this generates the Events that need to be executed. Specifically, this
  1. creates the DDL that must be executed to bring the database in sync with the events and prepare the object events to be generated
  2. creates or updates the needed events in memory
  3. generate the new PDL file to represent this object type
  4. execute the DDL
  5. if the DDL executes successfully, update the database to reflect the new syntax. Otherwise, throw a PersistenceException

getObjectType

public ObjectType getObjectType()
This method returns the ObjectType that is being manipulated by this DynamicObjectType


makeObjectTypePDL

public String makeObjectTypePDL()
Creates the PDL for the object type. Is public for testing/debugging purposes.

Returns:
PDL for ObjectType

makeTableDDL

public final Collection makeTableDDL()
Returns the table creaton DDL. Is public for testing/debugging purposes.

Returns:
Table creation DDL

makeMappingTablesDDL

public final String[] makeMappingTablesDDL()
Returns an array of Strings containing DDL for new mapping tables. Is public for testing/debugging purposes.

Returns:
Mapping table creation DDL

toString

public String toString()
This prints out a String representation of this object type


main

public static void main(String[] args)
This allows the user to either input or output a given data object type x

This is only meant to be called from the command line. the usage is java com.arsdigita.persistence.metadataDyanmicObjectType <[import | export]> <DynamicObjectType> <FileLocation> <StartupScript> <WebAppRoot>

So, to export the dynamic type MyDynamicType from the database to the file system, you can type java com.arsdigita.persistence.metadata.DynamicObjectType export com.arsdigita.cms.MyDynamicType /tmp/MyDynamicType.pdl /home/tomcat/webapps/enterprise/WEB-INF/resources/enterprise.init /home/tomcat/webapps/enterprise

Make sure that you have the DynamicObjectType.class file in your classpath (which is something that is not in your classpath when you typically start your server)



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC