com.arsdigita.cms
Class ACSObjectFactory

java.lang.Object
  extended bycom.arsdigita.domain.DomainService
      extended bycom.arsdigita.cms.ACSObjectFactory

public class ACSObjectFactory
extends com.arsdigita.domain.DomainService

Provides static methods to instantiate proper subclasses of ACSObject domain objects, based on the object type and the Java class name.

Version:
$Id: //cms/dev/src/com/arsdigita/cms/ACSObjectFactory.java#15 $
See Also:
ACSObject

Field Summary
static String versionId
           
 
Constructor Summary
ACSObjectFactory()
           
 
Method Summary
static com.arsdigita.kernel.ACSObject castACSObject(com.arsdigita.kernel.ACSObject obj)
          Attempt to "cast" an ACSObject to a proper ACSObject subclass.
static com.arsdigita.kernel.ACSObject castACSObject(com.arsdigita.persistence.DataObject obj)
          Attempt to "cast" a DataObject to a proper ACSObject subclass.
static ContentItem castContentItem(ContentItem item)
          "Cast" the ContentItem to its proper subclass, based on the values in its content type.
static ContentItem castContentItem(com.arsdigita.persistence.DataObject obj)
          Attempt to "cast" a DataObject to a proper ContentItem subclass.
static ContentItem castContentItem(com.arsdigita.persistence.DataObject obj, boolean useContentType)
          Attempt to "cast" a DataObject to a proper ContentItem subclass.
static ContentItem castContentItem(com.arsdigita.domain.DomainObject obj)
          Attempt to "cast" a DomainObject to a proper ContentItem subclass.
static com.arsdigita.kernel.ACSObject createACSObject(String javaClassName)
          Instantiate a subclass of ACSObject, blatantly disregarding ObjectType.
static com.arsdigita.kernel.ACSObject createACSObject(String javaClassName, String objectType)
          Create a proper subclass of ACSObject.
static Collection getKeyAttributeNames(com.arsdigita.persistence.metadata.ObjectType type)
          Get an array of all attribute names which comprise the type's primary key
static Collection getKeyAttributes(com.arsdigita.persistence.metadata.ObjectType type)
          Get a collection of all attributes which comprise the type's primary key
static com.arsdigita.persistence.metadata.ObjectType getSpecificObjectType(com.arsdigita.kernel.ACSObject obj)
          Attempt to retrieve the true object type of the item from the "object_type" column of ACSObject.
static com.arsdigita.kernel.ACSObject loadACSObject(Class javaClass, String objectType, BigDecimal id)
          Load a proper subclass of the ACSObject domain object from the database
static com.arsdigita.kernel.ACSObject loadACSObject(String javaClass, String objectType, BigDecimal id)
          Load a proper subclass of the ACSObject domain object from the database
 
Methods inherited from class com.arsdigita.domain.DomainService
add, add, clear, get, getDataCollection, getDataObject, remove, remove, set, setAssociation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

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

ACSObjectFactory

public ACSObjectFactory()
Method Detail

loadACSObject

public static com.arsdigita.kernel.ACSObject loadACSObject(Class javaClass,
                                                           String objectType,
                                                           BigDecimal id)
Load a proper subclass of the ACSObject domain object from the database

Parameters:
javaClass - The Java Class to be instantiated
objectType - the object type of the object to instantiated; should extend the ACSObject
id - the primary key for the new object
Returns:
the loaded object, or null on failure. It is safe to cast the return value to the javaClass

loadACSObject

public static com.arsdigita.kernel.ACSObject loadACSObject(String javaClass,
                                                           String objectType,
                                                           BigDecimal id)
Load a proper subclass of the ACSObject domain object from the database

Parameters:
javaClass - The name of the Java class to be instantiated
objectType - the object type of the object to instantiate; should extend the ACSObject
id - the primary key for the new object
Returns:
the loaded object, or null on failure. It is safe to cast the return value to the javaClass

castContentItem

public static ContentItem castContentItem(ContentItem item)
"Cast" the ContentItem to its proper subclass, based on the values in its content type. Return the item itself on failure.

Note that this method performs 2 extra database hits: one hit to get the content type, and another hit to get the new item.

Parameters:
item - the ContentItem to cast
Returns:
the proper subclass of ContentItem, such as ContentPage

getSpecificObjectType

public static com.arsdigita.persistence.metadata.ObjectType getSpecificObjectType(com.arsdigita.kernel.ACSObject obj)
Attempt to retrieve the true object type of the item from the "object_type" column of ACSObject. On failure, return the type which is recorder in the item's OID

Parameters:
obj - the ACSObject
Returns:
the true (most specific) object type of the object

castACSObject

public static com.arsdigita.kernel.ACSObject castACSObject(com.arsdigita.persistence.DataObject obj)
Attempt to "cast" a DataObject to a proper ACSObject subclass. Return null if the data object does not represent an ACSObject.

This method assumes that the Java class name is the same as the object type name of the object. If this assumption fails, the method will return null.

If the assumption turns out to be true, this method will try to instantiate the desired object with the constructor public Foo(DataObject obj). If the constructor does not exist, the method will return null.

The data object obj is specialized to the right subclass if that is necessary.

Parameters:
obj - the DataObject to cast
Returns:
the proper subclass of ACSObject, or null on failure
See Also:
castContentItem(com.arsdigita.cms.ContentItem)

castACSObject

public static com.arsdigita.kernel.ACSObject castACSObject(com.arsdigita.kernel.ACSObject obj)
Attempt to "cast" an ACSObject to a proper ACSObject subclass. Return the original object on failure

This method assumes that the Java class name is the same as the object type name of the object. If this assumption fails, the method will return null.

Parameters:
obj - the ACSObject to cast
Returns:
the proper subclass of ACSObject, or null on failure
See Also:
castContentItem(com.arsdigita.cms.ContentItem)

castContentItem

public static ContentItem castContentItem(com.arsdigita.persistence.DataObject obj,
                                          boolean useContentType)
Attempt to "cast" a DataObject to a proper ContentItem subclass. Return null if the data object does not represent a content item.

Note that this method performs 2 extra database hits: one hit to get the content type, and another hit to get the new item.

Parameters:
obj - the DataObject to cast
useContentType - if true, try to access the item's content type in order to get the Java class name. If false, assume that the java class name is the same as the object type.
Returns:
the proper subclass of ContentItem, such as ContentPage

castContentItem

public static ContentItem castContentItem(com.arsdigita.persistence.DataObject obj)
Attempt to "cast" a DataObject to a proper ContentItem subclass. Return null if the data object does not represent a content item.

Note that this method performs 2 extra database hits: one hit to get the content type, and another hit to get the new item.

Parameters:
obj - the DataObject to cast
Returns:
the proper subclass of ContentItem, such as ContentPage

castContentItem

public static ContentItem castContentItem(com.arsdigita.domain.DomainObject obj)
Attempt to "cast" a DomainObject to a proper ContentItem subclass. Return null if the domain object does not represent a content item.

Note that this method performs 2 extra database hits: one hit to get the content type, and another hit to get the new item.

Parameters:
obj - the DomainObject to cast
Returns:
the proper subclass of ContentItem, such as ContentPage

createACSObject

public static com.arsdigita.kernel.ACSObject createACSObject(String javaClassName,
                                                             String objectType)
Create a proper subclass of ACSObject. Requires the class designated by javaClassName to have a constructor with a single String parameter. The String parameter should specify the object type of the new object.

Parameters:
javaClassName - The name of the Java Class to be instantiated
objectType - the object type of the object to instantiated; should extend the ACSObject
Returns:
the new ACSObject on success, null on failure

createACSObject

public static com.arsdigita.kernel.ACSObject createACSObject(String javaClassName)
Instantiate a subclass of ACSObject, blatantly disregarding ObjectType.

Parameters:
javaClassName - The name of the Java Class to be instantiated
Returns:
the new ACSObject on success, null on failure

getKeyAttributes

public static Collection getKeyAttributes(com.arsdigita.persistence.metadata.ObjectType type)
Get a collection of all attributes which comprise the type's primary key

Returns:
an array of primary key attribute names

getKeyAttributeNames

public static Collection getKeyAttributeNames(com.arsdigita.persistence.metadata.ObjectType type)
Get an array of all attribute names which comprise the type's primary key

Returns:
an array of primary key attribute names


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