org.iqual.chaplin
Class DynaCastUtils

java.lang.Object
  extended by org.iqual.chaplin.DynaCastUtils

public class DynaCastUtils
extends Object

This class introduces the $ utility static method. This method can be used in situations when it is not possible to cast an object directly to the type. You can use this method also when you do not want to assign null values to the context local variables because it results in warnings that the variable is being used uninitialized - ie. it serves as a sort of dummy plug.

      This static import is assumed:
 

import static org.iqual.chaplin.DynaCastUtils.$;

Example 1 - "incorvertible" types made convertible:

File file = (File)$("addresses.txt")

Example 2 - context local variable "appears" initialized to the code inspector (no warning):

String $userName = $(); System.out.println(userName);

Since:
Mar 16, 2009 1:05:17 AM
Author:
Zbynek Slajchrt

Field Summary
static Object $
           
 
Constructor Summary
DynaCastUtils()
           
 
Method Summary
static
<T> T
$()
           
static
<T,E extends Throwable>
T
$(Class<E> ec, Object... args)
           
static
<T> T
$(Object... args)
           
static Composite $$(Object... args)
           
static String $alias(Object instance)
           
static
<T> T
$alias(String aliasName, T instance)
           
static
<T> T
$bind(Object composite, Object... boundComponents)
          Bind the components to the composite.
static boolean $contains(Object composite, Class componentClass)
           
static
<T> T
$context()
           
static MessageReceiver $declass(Object object)
           
static void $disjoin(Object component)
          Pulls the component out of the composite.
static
<T> T
$emitter(Object instance)
           
static Object $for(String alias, Object component)
          Filters out all messages whose source component is not aliased as alias.
static boolean $hasVar(Object object, String varName)
           
static void $join(Object newComponent, int index, Object companion, String name)
          Inserts the component to the composite.
static void $join(Object component, Object companion)
          Attaches the component to the composite.
static void $join(Object newComponent, Object companion, String name)
          Attaches the component to the composite.
static
<T> T
$meta(Object instance, Object key)
           
static void $meta(Object instance, Object key, Object value)
          Sets the role name of the component in the composite.
static String $name(Object instance)
           
static
<T> T
$name(String name, T instance)
           
static MessageReceiver $named(String name, Class context, Object value)
           
static MessageReceiver $named(String name, Object value)
           
static void $next(MessageReplies replies, Object... args)
           
static
<T> T
$next(Object... args)
           
static
<T> T
$proxy(Class<T> intf, Object object)
           
static String $qrole(Object instance)
           
static String $role(Object instance)
           
static
<T> T
$role(String roleName, T instance)
           
static void $unbind(Object composite)
           
static
<T> Var<T>
$var(Object object, String name)
          Defines a new var.
static Map<?,?> createMapFromCollection(Iterable<?> iterable)
          Create a map from a collection.
static Composite getComposite(Object object)
           
static Class getPrimitiveType(String type)
           
static Class[] getTypesArrayFromObjects(Object[] objects, Class[] defaultTypes)
           
static boolean isEmptyObjectArray(Object arg)
           
static boolean isInComposite(Object object)
           
static MessageReceiver makeReceiver(Object component)
           
static Object resolveName(Object elem)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

$

public static final Object $
Constructor Detail

DynaCastUtils

public DynaCastUtils()
Method Detail

$$

public static Composite $$(Object... args)

$

public static <T> T $(Object... args)

$

public static <T> T $()

$next

public static void $next(MessageReplies replies,
                         Object... args)

$next

public static <T> T $next(Object... args)

$context

public static <T> T $context()
Returns:
the composite context attached to the current thread or null.

$

public static <T,E extends Throwable> T $(Class<E> ec,
                                          Object... args)
           throws E extends Throwable
Throws:
E extends Throwable

getPrimitiveType

public static Class getPrimitiveType(String type)

getTypesArrayFromObjects

public static Class[] getTypesArrayFromObjects(Object[] objects,
                                               Class[] defaultTypes)

$bind

public static <T> T $bind(Object composite,
                          Object... boundComponents)
Bind the components to the composite.

Parameters:
composite -
boundComponents -
Returns:
the enhanced composite

$unbind

public static void $unbind(Object composite)

makeReceiver

public static MessageReceiver makeReceiver(Object component)

$named

public static MessageReceiver $named(String name,
                                     Class context,
                                     Object value)

$named

public static MessageReceiver $named(String name,
                                     Object value)

$declass

public static MessageReceiver $declass(Object object)
Parameters:
object - the object which receives messages with stripped information on the message classification.
Returns:
the receiver which strips the information on the message classification. It passes the stripped message to another receiver which is created for the object argument. It allows processing messages which would be otherwise impossible because of the message classification.

isEmptyObjectArray

public static boolean isEmptyObjectArray(Object arg)

isInComposite

public static boolean isInComposite(Object object)

getComposite

public static Composite getComposite(Object object)

$proxy

public static <T> T $proxy(Class<T> intf,
                           Object object)

$contains

public static boolean $contains(Object composite,
                                Class componentClass)
Parameters:
composite - the composite
componentClass - the component clas
Returns:
true if the composite contains a component of the specified type

$emitter

public static <T> T $emitter(Object instance)
Parameters:
instance - a component in a composite context or a composite context
Returns:
An emitter instance of the target interface for the composite context.

$meta

public static <T> T $meta(Object instance,
                          Object key)

$meta

public static void $meta(Object instance,
                         Object key,
                         Object value)
Sets the role name of the component in the composite.

Parameters:
instance -
key -
value -

$name

public static <T> T $name(String name,
                          T instance)
Parameters:
name -
instance -
Returns:
the name of the component

$name

public static String $name(Object instance)
Parameters:
instance -
Returns:
the name of the component

$role

public static <T> T $role(String roleName,
                          T instance)
Parameters:
roleName -
instance -
Returns:
the role name of the component in the composite

$role

public static String $role(Object instance)

$qrole

public static String $qrole(Object instance)
Parameters:
instance - the instance in a composite
Returns:
the fully qualified role, ie. if the instance is in a composite then the result is a path composed of the roles of the composite nodes in the branch leading from the instance upwards. The branch includes the instance too.

$alias

public static <T> T $alias(String aliasName,
                           T instance)

$alias

public static String $alias(Object instance)

$for

public static Object $for(String alias,
                          Object component)
Filters out all messages whose source component is not aliased as alias.

Parameters:
alias - the component's alias
component - the component
Returns:
the filtering message receiver

$disjoin

public static void $disjoin(Object component)
Pulls the component out of the composite.

Parameters:
component - the component

$join

public static void $join(Object component,
                         Object companion)
Attaches the component to the composite. The composite given by the companion object which is either a component already belonging to the composite or the composite itself.

Parameters:
component - the component to be inserted to the composite
companion - the companion compoent

$join

public static void $join(Object newComponent,
                         Object companion,
                         String name)
Attaches the component to the composite. The composite given by the companion object which is either a component already belonging to the composite or the composite itself.

Parameters:
newComponent - the component to be inserted to the composite
companion - the companion compoent
name - the name (role) of the component in the composite

$join

public static void $join(Object newComponent,
                         int index,
                         Object companion,
                         String name)
Inserts the component to the composite. The composite given by the companion object which is either a component already belonging to the composite or the composite itself.

Parameters:
newComponent - the component to be inserted to the composite
index - the index at which the component is inserted. The value -1 means that the component is appended at the end.
companion - the companion compoent
name - the name (role) of the component in the composite

createMapFromCollection

public static Map<?,?> createMapFromCollection(Iterable<?> iterable)
Create a map from a collection.

Parameters:
iterable -
Returns:

resolveName

public static Object resolveName(Object elem)

$var

public static <T> Var<T> $var(Object object,
                              String name)
Defines a new var. The new var is stored into the object's metadata.

Type Parameters:
T - the type of the var
Parameters:
object - the object
name - the name of the var
Returns:
the var
See Also:
Var

$hasVar

public static boolean $hasVar(Object object,
                              String varName)
Parameters:
object - the object
varName - the name of the var
Returns:
Returns true if the var has been defined in the object's metadata.
See Also:
Var


Copyright © 2009 iquality.org. All Rights Reserved.