Voyager ORB

com.objectspace.voyager
Class Facets

java.lang.Object
  |
  +--com.objectspace.voyager.Facets

public class Facets
extends java.lang.Object
implements IFacets, java.io.Serializable

Facets is a distributed implementation of the IFacets interface. An instance of Facets is automatically allocated to an object when its first facet is added. The Facets instance is responsible for tracking the facets of an object and ensuring that the object and its facets are garbage collected as a single entity.

Facets uses a simple scheme for determining the class of facet that is added during a MyFacet.of( object ) operation. Assuming that the class of object is MyClass, it attempts to attach a facet that implements IMyFacet and is called XXXMyFacet, where the search starts with XXX="MyClass" and moves up MyClass's superclass chain. If the head of the superclass chain is reached and there is no match for ObjectMyFacet, the last attempted match uses XXX="". During each search cycle, the candidate class is first looked for in the package of MyClass and then in the package of MyFacet.

For example, assume that company.Programmer extends company.Employee which in turn extends java.lang.Object. Assume also that the full path of Hobbies is fun.Hobbies. If the statement Hobbies.of( object ) is executed where object is an instance of Programmer, the search process picks the first class in the following series that exists and implements IHobbies:

company.ProgrammerHobbies
fun.ProgrammerHobbies
company.EmployeeHobbies
fun.EmployeeHobbies
company.ObjectHobbies
fun.ObjectHobbies
company.Hobbies
fun.Hobbies

Version:
3.0
See Also:
Serialized Form

Method Summary
static IFacets get(java.lang.Object object)
          If the specified object implements IFacets, return the object.
static java.lang.Object get(java.lang.Object object, java.lang.Class type)
          If the specified object is an instance of the specified type, return the object.
 java.lang.Object get(java.lang.String classname)
          Return a proxy to a facet that implements the specified class.
 java.lang.Object[] getFacets()
          Return an array of proxies to the primary object's facets.
 java.lang.Object getPrimary()
          Return a proxy to the primary object.
static IFacets of(java.lang.Object object)
          If the specified object implements IFacets, return the object.
static java.lang.Object of(java.lang.Object object, java.lang.Class type)
          If the specified object is an instance of the specified type, return the object.
 java.lang.Object of(java.lang.String classname)
          Return a proxy to a facet that implements the specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public java.lang.Object get(java.lang.String classname)
Return a proxy to a facet that implements the specified class. If no such facet is found, return null.
Specified by:
get in interface IFacets
Parameters:
classname - The class of facet to get.

of

public java.lang.Object of(java.lang.String classname)
                    throws java.lang.ClassCastException
Return a proxy to a facet that implements the specified class. If no such facet is found, add one automatically before returning it.
Specified by:
of in interface IFacets
Parameters:
classname - The class of facet to get/add.
Throws:
java.lang.ClassCastException - The facet could not be found or added.

getPrimary

public java.lang.Object getPrimary()
Return a proxy to the primary object.
Specified by:
getPrimary in interface IFacets

getFacets

public java.lang.Object[] getFacets()
Return an array of proxies to the primary object's facets.
Specified by:
getFacets in interface IFacets

get

public static IFacets get(java.lang.Object object)
If the specified object implements IFacets, return the object. If the specified object has facets, return a proxy to the its Facets instance. If neither rule applies, return null.
Parameters:
object - The primary object.

of

public static IFacets of(java.lang.Object object)
                  throws java.lang.ClassCastException
If the specified object implements IFacets, return the object. If the specified object has facets, return a proxy to its Facets instance. If neither rule applies, facet-enable the object and return a proxy to its Facets instance.
Parameters:
object - The primary object.
Throws:
java.lang.ClassCastException - The Facets instance could not be added.

get

public static java.lang.Object get(java.lang.Object object,
                                   java.lang.Class type)
If the specified object is an instance of the specified type, return the object. If the specified object has a facet that is an instance of the specified type, return a proxy to that facet. If neither rule applies, return null.
Parameters:
object - The primary object.
type - The required facet type.

of

public static java.lang.Object of(java.lang.Object object,
                                  java.lang.Class type)
                           throws java.lang.ClassCastException
If the specified object is an instance of the specified type, return the object. If the specified object has a facet that is an instance of the specified type, return a proxy to that facet. If neither rule applies, add a facet that implements the specified type.
Parameters:
object - The primary object.
type - The required facet type.
Throws:
java.lang.ClassCastException - The facet could not be added.

ObjectSpace Inc.

(c) Copyright 1997-1999 ObjectSpace, Inc.
14850 Quorum Drive, Suite 500
Dallas, Texas 75240