org.dynalang.mop.collections
public class MapMetaobjectProtocol extends MetaobjectProtocolBase implements ClassBasedMetaobjectProtocol
BaseMetaobjectProtocol.Result#noAuthority
for
keys not present (thus allowing fallback to other navigators below it).BaseMetaobjectProtocol.Result
Constructor and Description |
---|
MapMetaobjectProtocol() |
Modifier and Type | Method and Description |
---|---|
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.
|
BaseMetaobjectProtocol.Result |
delete(java.lang.Object target,
java.lang.Object propertyId)
Removes a key-value mapping from the map.
|
java.lang.Object |
get(java.lang.Object target,
java.lang.Object propertyId)
Retrieves a value from the map.
|
java.lang.Boolean |
has(java.lang.Object target,
java.lang.Object propertyId)
Determines whether a key is present in the map.
|
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)
Retrieves the mappings in the map.
|
BaseMetaobjectProtocol.Result |
put(java.lang.Object target,
java.lang.Object propertyId,
java.lang.Object value,
CallProtocol callProtocol)
Binds a key-value pair into the map.
|
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.
|
call, call, delete, get, has, propertyIds, put
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
call, call, delete, get, has, propertyIds, put
public boolean isAuthoritativeForClass(java.lang.Class clazz)
ClassBasedMetaobjectProtocol
BaseMetaobjectProtocol.Result.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.isAuthoritativeForClass
in interface ClassBasedMetaobjectProtocol
clazz
- the class of the handled objectpublic java.lang.Object call(java.lang.Object callable, CallProtocol callProtocol, java.util.Map args)
CallProtocol
call
in interface CallProtocol
callable
- the callable objectcallProtocol
- 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.BaseMetaobjectProtocol.Result#noAuthority
as this MOP
has no concept of callablespublic java.lang.Object call(java.lang.Object callable, CallProtocol callProtocol, java.lang.Object... args)
CallProtocol
call
in interface CallProtocol
callable
- the callable objectcallProtocol
- 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.BaseMetaobjectProtocol.Result#noAuthority
as this MOP
has no concept of callablespublic BaseMetaobjectProtocol.Result delete(java.lang.Object target, java.lang.Object propertyId)
delete
in interface BaseMetaobjectProtocol
target
- the map to remove element frompropertyId
- the map keyBaseMetaobjectProtocol.Result#ok
if the removal was successful. If the map is
read-only (throws a UnsupportedOperationException
on removal
attempt), BaseMetaobjectProtocol.Result#notDeleteable
is returned. If the map does not
contain the key, or it throws a NullPointerException
for a null
key, or the target is not a map, BaseMetaobjectProtocol.Result#noAuthority
is
returned.public java.lang.Object get(java.lang.Object target, java.lang.Object propertyId)
get
in interface CallProtocol
target
- the map to retrieve frompropertyId
- the key for retrievalNullPointerException
for a null key, or the target is not a map,
BaseMetaobjectProtocol.Result#noAuthority
is returned.public java.lang.Boolean has(java.lang.Object target, java.lang.Object propertyId)
has
in interface BaseMetaobjectProtocol
target
- the map to testpropertyId
- the key to test forBoolean.TRUE
. If
the map does not contain the key, or it throws a
NullPointerException
for a null key, or the target is not a map,
BaseMetaobjectProtocol.Result#noAuthority
is returned.public java.util.Iterator<java.util.Map.Entry> properties(java.lang.Object target)
properties
in interface BaseMetaobjectProtocol
target
- the map whose mappings are retrievedpublic BaseMetaobjectProtocol.Result put(java.lang.Object target, java.lang.Object propertyId, java.lang.Object value, CallProtocol callProtocol)
put
in interface BaseMetaobjectProtocol
target
- the map where to bind the new mappingpropertyId
- the mapping keyvalue
- the mapped valuecallProtocol
- not usedBaseMetaobjectProtocol.Result#ok
if the binding was successful. If the map is
read-only (throws a UnsupportedOperationException
on put
attempt), BaseMetaobjectProtocol.Result#notWritable
is returned. If the map does not
contain the key, or it throws a NullPointerException
for a null
key or null value, or the target is not a map,
BaseMetaobjectProtocol.Result#noAuthority
is returned. If the map throws
ClassCastException
(because it is limited in types of values it
can accept), BaseMetaobjectProtocol.Result#noRepresentation
is returned.public java.lang.Object representAs(java.lang.Object object, java.lang.Class targetClass)
CallProtocol
representAs
in interface CallProtocol
object
- the object to representtargetClass
- the target class for representation.BaseMetaobjectProtocol.Result#noAuthority
as this MOP has no concept of type
conversion