org.dynalang.mop.impl
Class StandardMetaobjectProtocolFactory

java.lang.Object
  extended by org.dynalang.mop.impl.StandardMetaobjectProtocolFactory

public class StandardMetaobjectProtocolFactory
extends java.lang.Object

A class with static utility methods for creating a "standard" MOP. A standard MOP is a MOP that is a compositional of MOPs known and precreated by the caller as well as any automatically discovered MOPs.

Version:
$Id: $
Author:
Attila Szegedi

Method Summary
static MetaobjectProtocol[] createStandardFallback(boolean elementsShadowMethods, boolean methodsEnumerable)
          Creates "standard" fallback MOP sequence to use as the fallback parameter in createStandardMetaobjectProtocol(ClassLoader, MetaobjectProtocol[], MetaobjectProtocol[]).
static MetaobjectProtocol createStandardMetaobjectProtocol(boolean elementsShadowMethods, boolean methodsEnumerable)
          This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs in the classpath of the current thread's class loader.
static MetaobjectProtocol createStandardMetaobjectProtocol(java.lang.ClassLoader classLoader, MetaobjectProtocol[] prioritized, MetaobjectProtocol[] fallbacks)
          This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs.
static MetaobjectProtocol createStandardMetaobjectProtocol(MetaobjectProtocol nativeProtocol, boolean elementsShadowMethods, boolean methodsEnumerable)
          This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs in the classpath of the current thread's class loader, adding a single metaobject protocol as the first MOP of the composite.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createStandardMetaobjectProtocol

public static MetaobjectProtocol createStandardMetaobjectProtocol(boolean elementsShadowMethods,
                                                                  boolean methodsEnumerable)
                                                           throws java.io.IOException,
                                                                  java.lang.InstantiationException,
                                                                  java.lang.IllegalAccessException,
                                                                  java.lang.ClassNotFoundException
This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs in the classpath of the current thread's class loader. This makes this method useful for creating a class loader specific composite MOP for environments that do not have their own native object model but wish to manipulate all available object models. The returned composite MOP will feature all MOPs found in the class loader's JAR files, followed by standard fallback MOPs for beans (POJOs), Maps, and Lists.

Parameters:
elementsShadowMethods - the order of fallback MOPs. If true, List and Map MOP are put before the beans MOP. If false, beans MOP is put before the List and Map MOP. Note that List and Map MOPs implement ClassBasedMetaobjectProtocol while beans MOP does not, so you'll generally get better performance if you pass true for this parameter.
methodsEnumerable - if true, then objects' methods and JavaBeans properties show up in the results of BaseMetaobjectProtocol.properties(Object) and MetaobjectProtocol.propertyIds(Object). If false, these can still be accessed by directly addressing them, but don't show up in aforementioned methods' results.
Returns:
a MetaobjectProtocol that optimally composes the automatically discovered and fallback MOPs.
Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException

createStandardMetaobjectProtocol

public static MetaobjectProtocol createStandardMetaobjectProtocol(MetaobjectProtocol nativeProtocol,
                                                                  boolean elementsShadowMethods,
                                                                  boolean methodsEnumerable)
                                                           throws java.io.IOException,
                                                                  java.lang.InstantiationException,
                                                                  java.lang.IllegalAccessException,
                                                                  java.lang.ClassNotFoundException
This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs in the classpath of the current thread's class loader, adding a single metaobject protocol as the first MOP of the composite. This single metaobject protocol usually implements the default MOP for the environment's "standard" language. This makes this method useful for creating a class loader specific composite MOP for environments that have their own native object model (i.e. dynamic language runtimes). The returned composite MOP will feature the passed MOP as its first element, followed by any other MOPs found in the class loader's JAR files, followed by standard fallback MOPs for beans (POJOs), Maps, and Lists.

Parameters:
nativeProtocol - the MOP for the environment's native objects (i.e. a JavaScript runtime creating a MOP will pass a JavaScript MOP here). If a MOP of the same class is later discovered in JARs on the class path, it will be ignored and the explicitly passed instance used.
elementsShadowMethods - the order of fallback MOPs. If true, List and Map MOP are put before the beans MOP. If false, beans MOP is put before the List and Map MOP. Note that List and Map MOPs implement ClassBasedMetaobjectProtocol while beans MOP does not, so you'll generally get better performance if you pass true for this parameter.
methodsEnumerable - if true, then objects' methods and JavaBeans properties show up in the results of BaseMetaobjectProtocol.properties(Object) and MetaobjectProtocol.propertyIds(Object). If false, these can still be accessed by directly addressing them, but don't show up in aforementioned methods' results.
Returns:
a MetaobjectProtocol that optimally composes the preferred MOP, automatically discovered, and fallback MOPs. Those automatically discovered MOPs that are of the same class as any of the prioritized or fallback MOPs are ignored.
Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException

createStandardMetaobjectProtocol

public static MetaobjectProtocol createStandardMetaobjectProtocol(java.lang.ClassLoader classLoader,
                                                                  MetaobjectProtocol[] prioritized,
                                                                  MetaobjectProtocol[] fallbacks)
                                                           throws java.io.IOException,
                                                                  java.lang.InstantiationException,
                                                                  java.lang.IllegalAccessException,
                                                                  java.lang.ClassNotFoundException
This method implements the "usual" way for creation of a composite metaobject protocol instance that encompasses all available MOPs. It is more generic than the other two methods of the same name, allowing maximum flexibility in configuration.

Parameters:
classLoader - the class loader within which the MOPs are discovered. null can be used to denote the system class loader, although you'll usually want the thread context class loader instead.
prioritized - an array of precreated, prioritized MOPs. These MOPs will be given a chance to handle objects before any automatically discovered MOPs. Can be null.
fallbacks - an array of precreated fallback MOPs. These MOPs will be given a chance to handle objects after any automatically discovered MOPs. Tipically, you'll want to specify an instance of BeansMetaobjectProtocol, an instance of ListMetaobjectProtocol, an instance of MapMetaobjectProtocol (in order of your preference), and an instance of BottomMetaobjectProtocol to seal it all. The method createStandardFallback(boolean, boolean) can be used to conveniently create this standard fallback MOP configuration.
Returns:
a MetaobjectProtocol that optimally composes all prioritized, automatically discovered, and fallback MOPs. Those automatically discovered MOPs that are of the same class as any of the prioritized or fallback MOPs are ignored.
Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException

createStandardFallback

public static MetaobjectProtocol[] createStandardFallback(boolean elementsShadowMethods,
                                                          boolean methodsEnumerable)
Creates "standard" fallback MOP sequence to use as the fallback parameter in createStandardMetaobjectProtocol(ClassLoader, MetaobjectProtocol[], MetaobjectProtocol[]). The sequence consists of a BeansMetaobjectProtocol, MapMetaobjectProtocol, ListMetaobjectProtocol, and ultimately of a BottomMetaobjectProtocol.

Parameters:
elementsShadowMethods - if true, map and list MOPs are put before the beans MOP (thus, map elements will hide bean properties and methods). If false, beans MOP is put first (thus, bean properties and methods will shadow map elements). Note that List and Map MOPs implement ClassBasedMetaobjectProtocol while beans MOP does not, so you'll generally get better performance if you pass true for this parameter.
methodsEnumerable - if true, then objects' methods and JavaBeans properties show up in the results of BaseMetaobjectProtocol.properties(Object) and MetaobjectProtocol.propertyIds(Object). If false, these can still be accessed by directly addressing them, but don't show up in aforementioned methods' results.
Returns:
an array containing the four standard fallback MOPs.