org.dynalang.mop.collections
Class ListMetaobjectProtocol

java.lang.Object
  extended by org.dynalang.mop.collections.ListMetaobjectProtocol
All Implemented Interfaces:
BaseMetaobjectProtocol, CallProtocol, ClassBasedMetaobjectProtocol, MetaobjectProtocol

public class ListMetaobjectProtocol
extends java.lang.Object
implements ClassBasedMetaobjectProtocol

A metaobject protocol that knows how to manipulate Java lists.

Version:
$Id: $
Author:
Attila Szegedi

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.dynalang.mop.BaseMetaobjectProtocol
BaseMetaobjectProtocol.Results
 
Constructor Summary
ListMetaobjectProtocol()
           
 
Method Summary
 java.lang.Object call(java.lang.Object callable, CallProtocol callProtocol, java.util.Map args)
          Calls a callable object with named arguments.
 java.lang.Object call(java.lang.Object callable, CallProtocol callProtocol, java.lang.Object... args)
          Calls a callable object with positional arguments.
 java.lang.Object call(java.lang.Object target, java.lang.Object callableId, CallProtocol callProtocol, java.util.Map args)
          Calls a method on the target object with supplied named arguments.
 java.lang.Object call(java.lang.Object target, java.lang.Object callableId, CallProtocol callProtocol, java.lang.Object... args)
          Calls a method on the target object with supplied positional arguments.
 BaseMetaobjectProtocol.Results delete(java.lang.Object target, long propertyId)
          Handles the delete attempt from the list.
 BaseMetaobjectProtocol.Results delete(java.lang.Object target, java.lang.Object propertyId)
          Handles the delete attempt from the list.
 java.lang.Object get(java.lang.Object target, long propertyId)
          Retrieves a value from the list.
 java.lang.Object get(java.lang.Object target, java.lang.Object propertyId)
          Retrieves a value from the list.
 java.lang.Boolean has(java.lang.Object target, long propertyId)
          Tells whether the index is valid for the list.
 java.lang.Boolean has(java.lang.Object target, java.lang.Object propertyId)
          Tells whether the index is valid for the list.
 boolean isAuthoritativeForClass(java.lang.Class clazz)
          Returns whether this metaobject protocol has authority over objects of the specified class.
 java.util.Iterator<java.util.Map.Entry> properties(java.lang.Object target)
          Returns mappings from indexes to elements for a list.
 java.util.Iterator<? extends java.lang.Object> propertyIds(java.lang.Object target)
          Returns an iterator over all indexes in a list
 BaseMetaobjectProtocol.Results put(java.lang.Object target, long propertyId, java.lang.Object value, CallProtocol callProtocol)
          Puts an element into the list.
 BaseMetaobjectProtocol.Results put(java.lang.Object target, java.lang.Object propertyId, java.lang.Object value, CallProtocol callProtocol)
          Puts an element into the list.
 java.lang.Object representAs(java.lang.Object object, java.lang.Class targetClass)
          Returns a representation of the specified target object as an object of the specified target class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListMetaobjectProtocol

public ListMetaobjectProtocol()
Method Detail

isAuthoritativeForClass

public boolean isAuthoritativeForClass(java.lang.Class clazz)
Description copied from interface: ClassBasedMetaobjectProtocol
Returns whether this metaobject protocol has authority over objects of the specified class. Note that if a MOP claims that it has authority over objects of a certain class, it can still return BaseMetaobjectProtocol.Results.noAuthority for certain objects. In that case - when used in CompositeClassBasedMetaobjectProtocol - the other participating MOPs will also be given the chance to handle the object after this MOP was given the chance first.

Specified by:
isAuthoritativeForClass in interface ClassBasedMetaobjectProtocol
Parameters:
clazz - the class of the handled object
Returns:
true if this metaobject protocol has authority over objects of the specified class, false otherwise.

call

public java.lang.Object call(java.lang.Object callable,
                             CallProtocol callProtocol,
                             java.util.Map args)
Description copied from interface: CallProtocol
Calls a callable object with named arguments.

Specified by:
call in interface CallProtocol
Parameters:
callable - the callable object
callProtocol - a marshaller that should be used by this metaobject protocol to convert the arguments to conform to expected argument types for the call.
args - the named arguments for the callable object. null must be treated as empty map. Usually, the map keys are strings, but it is possible that some protocols support non-string keys.
Returns:
BaseMetaobjectProtocol.Results#noAuthority as this MOP has no concept of callables

call

public java.lang.Object call(java.lang.Object callable,
                             CallProtocol callProtocol,
                             java.lang.Object... args)
Description copied from interface: CallProtocol
Calls a callable object with positional arguments.

Specified by:
call in interface CallProtocol
Parameters:
callable - the callable object
callProtocol - a marshaller that should be used by this metaobject protocol to convert the arguments to conform to expected argument types for the call.
args - the positional arguments for the callable object. null must be treated as empty array.
Returns:
BaseMetaobjectProtocol.Results#noAuthority as this MOP has no concept of callables

call

public java.lang.Object call(java.lang.Object target,
                             java.lang.Object callableId,
                             CallProtocol callProtocol,
                             java.lang.Object... args)
Description copied from interface: MetaobjectProtocol
Calls a method on the target object with supplied positional arguments. Must behave identically to:
 Object callable = get(target, callableId);
 if(callable instanceof Results) {
     return callable;
 }
 return call(callable, args);
 

Specified by:
call in interface MetaobjectProtocol
Parameters:
target - the target object
callableId - the ID of the method to call
callProtocol - a marshaller that should be used by this metaobject protocol to convert the arguments to conform to expected argument types for the call.
args - the arguments of the call
Returns:
BaseMetaobjectProtocol.Results#noAuthority as this MOP has no concept of callables

call

public java.lang.Object call(java.lang.Object target,
                             java.lang.Object callableId,
                             CallProtocol callProtocol,
                             java.util.Map args)
Description copied from interface: MetaobjectProtocol
Calls a method on the target object with supplied named arguments. Must behave identically to:
 Object callable = get(target, callableId);
 if(callable instanceof Results) {
     return callable;
 }
 return call(callable, args);
 

Specified by:
call in interface MetaobjectProtocol
Parameters:
target - the target object
callableId - the ID of the method to call
callProtocol - a marshaller that should be used by this metaobject protocol to convert the arguments to conform to expected argument types for the call.
args - the arguments of the call
Returns:
BaseMetaobjectProtocol.Results#noAuthority as this MOP has no concept of callables

delete

public BaseMetaobjectProtocol.Results delete(java.lang.Object target,
                                             long propertyId)
Handles the delete attempt from the list. Note that the list semantics actually don't allow an element to be deleted from it.

Specified by:
delete in interface MetaobjectProtocol
Parameters:
target - the list to remove element from
propertyId - the numeric index of the element
Returns:
If the index is within the bounds of the target list, BaseMetaobjectProtocol.Results#notDeleteable is returned. If the index is out of bounds, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned.

delete

public BaseMetaobjectProtocol.Results delete(java.lang.Object target,
                                             java.lang.Object propertyId)
Handles the delete attempt from the list. Note that the list semantics actually don't allow an element to be deleted from it.

Specified by:
delete in interface BaseMetaobjectProtocol
Parameters:
target - the list to remove element from
propertyId - the numeric index of the element
Returns:
If the index is a number, and it is within the bounds of the list, BaseMetaobjectProtocol.Results#notDeleteable is returned. If the index is out of bounds, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned.

get

public java.lang.Object get(java.lang.Object target,
                            long propertyId)
Retrieves a value from the list.

Specified by:
get in interface MetaobjectProtocol
Parameters:
target - the list to retrieve from
propertyId - the numeric index of the element
Returns:
If the list contains the element, returns it. If the index is out of bounds, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned.

get

public java.lang.Object get(java.lang.Object target,
                            java.lang.Object propertyId)
Retrieves a value from the list.

Specified by:
get in interface CallProtocol
Parameters:
target - the list to retrieve from
propertyId - the numeric index of the element
Returns:
If the list contains the element at the index Number.longValue(), returns it. If the index is out of bounds, or it is not an instance of Number, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned.

has

public java.lang.Boolean has(java.lang.Object target,
                             long propertyId)
Tells whether the index is valid for the list.

Specified by:
has in interface MetaobjectProtocol
Parameters:
target - the list
propertyId - the index
Returns:
if propertyId is a valid index for this list, returns Boolean.TRUE. If it is not valid, or the target is not a list, returns null (meaning, no authority).

has

public java.lang.Boolean has(java.lang.Object target,
                             java.lang.Object propertyId)
Tells whether the index is valid for the list.

Specified by:
has in interface BaseMetaobjectProtocol
Parameters:
target - the list
propertyId - the index
Returns:
if Number.longValue() of propertyId is a valid index for this list, returns Boolean.TRUE. If it is not valid, or the target is not a list, or propertyId is not a Number, returns null (meaning, no authority).

properties

public java.util.Iterator<java.util.Map.Entry> properties(java.lang.Object target)
Returns mappings from indexes to elements for a list.

Specified by:
properties in interface BaseMetaobjectProtocol
Parameters:
target - the list
Returns:
an iterator of map entries, keys being Integer objects. The iterator does not support removal.

propertyIds

public java.util.Iterator<? extends java.lang.Object> propertyIds(java.lang.Object target)
Returns an iterator over all indexes in a list

Specified by:
propertyIds in interface MetaobjectProtocol
Parameters:
target - the list
Returns:
an iterator of valid indexes (Integer objects). The iterator does not support removal.

put

public BaseMetaobjectProtocol.Results put(java.lang.Object target,
                                          long propertyId,
                                          java.lang.Object value,
                                          CallProtocol callProtocol)
Puts an element into the list.

Specified by:
put in interface MetaobjectProtocol
Parameters:
target - the list to put the element into
propertyId - the numeric index of the element
callProtocol - not used
value - the new value for the property
Returns:
BaseMetaobjectProtocol.Results#ok if the put was successful. If the list is read-only (throws a UnsupportedOperationException on put attempt), BaseMetaobjectProtocol.Results#notWritable is returned. If the index is out of bounds, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned. If the list throws ClassCastException (because it is limited in types of values it can accept), BaseMetaobjectProtocol.Results#noRepresentation is returned.

put

public BaseMetaobjectProtocol.Results put(java.lang.Object target,
                                          java.lang.Object propertyId,
                                          java.lang.Object value,
                                          CallProtocol callProtocol)
Puts an element into the list.

Specified by:
put in interface BaseMetaobjectProtocol
Parameters:
target - the list to put the element into
propertyId - the numeric index of the element. If this argument is a Number, it's Number.longValue() method is used.
callProtocol - not used
value - the new value for the property
Returns:
BaseMetaobjectProtocol.Results#ok if the put was successful. If the list is read-only (throws a UnsupportedOperationException on put attempt), BaseMetaobjectProtocol.Results#notWritable is returned. If the index is out of bounds, or is not a Number, or the target is not a list, BaseMetaobjectProtocol.Results#noAuthority is returned. If the list throws ClassCastException (because it is limited in types of values it can accept), BaseMetaobjectProtocol.Results#noRepresentation is returned.

representAs

public java.lang.Object representAs(java.lang.Object object,
                                    java.lang.Class targetClass)
Description copied from interface: CallProtocol
Returns a representation of the specified target object as an object of the specified target class. Typical supported target classes would be wrappers for Java primitive types that map to native types of the higher level languages. I.e. if an object is used as a boolean expression, then the language would ask the protocol to interpret it as boolean by calling representAs(Boolean.TYPE).

Specified by:
representAs in interface CallProtocol
Parameters:
object - the object to represent
targetClass - the target class for representation.
Returns:
BaseMetaobjectProtocol.Results#noAuthority as this MOP has no concept of type conversion