org.dynalang.mop.beans
public class BeansMetaobjectProtocol extends java.lang.Object implements MetaobjectProtocol
BeanMetaobjectProtocol
objects using
getBeanMetaobjectProtocol(Class)
. These objects can subsequently
be used to access constructors and static methods of the Java classes they
represent, but be aware that functionality falls outside of the generic MOP
API.BaseMetaobjectProtocol.Result
Constructor and Description |
---|
BeansMetaobjectProtocol()
Creates a new JavaBeans metaobject protocol that doesn't expose objects'
methods and JavaBeans properties as enumerable.
|
BeansMetaobjectProtocol(boolean methodsEnumerable)
Creates a new JavaBeans metaobject protocol.
|
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.
|
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.Result |
delete(java.lang.Object target,
long propertyId)
Behaves as
BaseMetaobjectProtocol.delete(Object, Object) with an
integer property ID. |
BaseMetaobjectProtocol.Result |
delete(java.lang.Object target,
java.lang.Object propertyId)
Deletes an association of a value with a property in the target object.
|
java.lang.Object |
get(java.lang.Object target,
long propertyId)
Behaves as
CallProtocol.get(Object, Object) with an
integer property ID. |
java.lang.Object |
get(java.lang.Object target,
java.lang.Object propertyId)
Retrieves the property value from the target object.
|
<T> BeanMetaobjectProtocol<T> |
getBeanMetaobjectProtocol(java.lang.Class<T> clazz)
Returns a MOP instance for a specified Java class that treats the class
instances as a generic JavaBean.
|
java.lang.Boolean |
has(java.lang.Object target,
long propertyId)
Behaves as
BaseMetaobjectProtocol.has(Object, Object) with an
integer property ID. |
java.lang.Boolean |
has(java.lang.Object target,
java.lang.Object propertyId)
Tells whether the target object has a particular property.
|
java.util.Iterator<java.util.Map.Entry> |
properties(java.lang.Object target)
Returns an iterator over the property ID-value pairs in the target
object this MOP knows about (and chooses to expose - not all properties
must be exposed; hidden properties are allowed).
|
java.util.Iterator<? extends java.lang.Object> |
propertyIds(java.lang.Object target)
Returns an iterator over the property IDs in the target object this MOP
knows about (and chooses to expose - not all properties must be exposed;
hidden properties are allowed).
|
BaseMetaobjectProtocol.Result |
put(java.lang.Object target,
long propertyId,
java.lang.Object value,
CallProtocol callProtocol)
Behaves as
BaseMetaobjectProtocol.put(Object, Object, Object,CallProtocol)
with an integer property ID. |
BaseMetaobjectProtocol.Result |
put(java.lang.Object target,
java.lang.Object propertyId,
java.lang.Object value,
CallProtocol callProtocol)
Associates a value with a property in the target object.
|
java.lang.Object |
representAs(java.lang.Object object,
java.lang.Class targetClass)
In case object is an instance of the target class, returns it unchanged.
|
public BeansMetaobjectProtocol()
public BeansMetaobjectProtocol(boolean methodsEnumerable)
methodsEnumerable
- if true, then objects' methods and JavaBeans
properties show up in the results of properties(Object)
and
propertyIds(Object)
. If false, these can still be accessed by
directly addressing them, but don't show up in aforementioned methods'
results.public 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.notCallable
is returned if the protocol can
authoritatively decide that the target is not a callable, or is not
callable with named arguments. BaseMetaobjectProtocol.Result.doesNotExist
is returned
if the callable does not exist at all. BaseMetaobjectProtocol.Result.noAuthority
is
returned if the protocol can not authoritatively decide whether the
target is callable.public java.lang.Object call(java.lang.Object target, java.lang.Object callableId, CallProtocol callProtocol, java.util.Map args)
MetaobjectProtocol
Object callable = get(target, callableId); if(callable instanceof Result) { return callable; } return call(callable, args);
call
in interface MetaobjectProtocol
target
- the target objectcallableId
- the ID of the method to callcallProtocol
- 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 callCallProtocol.get(Object, Object)
would return while looking up the callable. Can also return any return
value that CallProtocol.call(Object, CallProtocol, Map)
would return while calling.public java.lang.Object call(java.lang.Object target, java.lang.Object callableId, CallProtocol callProtocol, java.lang.Object... args)
MetaobjectProtocol
Object callable = get(target, callableId); if(callable instanceof Result) { return callable; } return call(callable, args);
call
in interface MetaobjectProtocol
target
- the target objectcallableId
- the ID of the method to callcallProtocol
- 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 callCallProtocol.get(Object, Object)
would return while looking up the callable. Can also return any return
value that CallProtocol.call(Object, CallProtocol, Object[])
would return while calling.public 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.notCallable
is returned if the protocol can
authoritatively decide that the target is not a callable, or is not
callable with positional arguments. BaseMetaobjectProtocol.Result.doesNotExist
is
returned if the callable does not exist at all.
BaseMetaobjectProtocol.Result.noAuthority
is returned if the protocol can not
authoritatively decide whether the target is callable.public BaseMetaobjectProtocol.Result delete(java.lang.Object target, long propertyId)
MetaobjectProtocol
BaseMetaobjectProtocol.delete(Object, Object)
with an
integer property ID.delete
in interface MetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property.BaseMetaobjectProtocol.delete(Object, Object)
.public BaseMetaobjectProtocol.Result delete(java.lang.Object target, java.lang.Object propertyId)
BaseMetaobjectProtocol
delete
in interface BaseMetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property. Usually a String or an
Integer, but other property ID types can also be supported.BaseMetaobjectProtocol.Result.doesNotExist
. If the protocol authoritatively decides
that the property can not be deleted, it will return
BaseMetaobjectProtocol.Result.notDeleteable
. If the protocol doesn't have the
authority to delete the property, it will leave the object unchanged,
and return BaseMetaobjectProtocol.Result.noAuthority
. If the operation succeeds,
BaseMetaobjectProtocol.Result.ok
is returned.public java.lang.Object get(java.lang.Object target, long propertyId)
MetaobjectProtocol
CallProtocol.get(Object, Object)
with an
integer property ID.get
in interface MetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property.CallProtocol.get(Object, Object)
.public java.lang.Object get(java.lang.Object target, java.lang.Object propertyId)
CallProtocol
get
in interface CallProtocol
target
- the target objectpropertyId
- the ID of the property. Usually a String or an
Integer, but other property ID types can also be supported.BaseMetaobjectProtocol.Result.doesNotExist
. If the protocol decides that
the property exists, but is not readable, it will return
BaseMetaobjectProtocol.Result.notReadable
. If the protocol can not make
an authoritative decision, it will return BaseMetaobjectProtocol.Result.noAuthority
.public java.lang.Boolean has(java.lang.Object target, long propertyId)
MetaobjectProtocol
BaseMetaobjectProtocol.has(Object, Object)
with an
integer property ID.has
in interface MetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property.BaseMetaobjectProtocol.has(Object, Object)
.public java.lang.Boolean has(java.lang.Object target, java.lang.Object propertyId)
BaseMetaobjectProtocol
has
in interface BaseMetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property. Usually a String or an
Integer, but other property ID types can also be supported.Boolean.TRUE
or Boolean.FALSE
if the protocol
can authoritatively decide whether the target has or has not the
property, or null if it does not have the authority to decide.public java.util.Iterator<java.util.Map.Entry> properties(java.lang.Object target)
BaseMetaobjectProtocol
properties
in interface BaseMetaobjectProtocol
target
- the target objectpublic java.util.Iterator<? extends java.lang.Object> propertyIds(java.lang.Object target)
MetaobjectProtocol
propertyIds
in interface MetaobjectProtocol
target
- the target objectpublic BaseMetaobjectProtocol.Result put(java.lang.Object target, long propertyId, java.lang.Object value, CallProtocol callProtocol)
MetaobjectProtocol
BaseMetaobjectProtocol.put(Object, Object, Object,CallProtocol)
with an integer property ID.
Associates a value with a property in the target object.put
in interface MetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property. Usually a String or an
Integer, but other property ID types can also be supported.value
- the new value for the propertycallProtocol
- a marshaller that is used to convert the value in
case the property can only accept values of certain types, and the
metaobject protocol allows automatic coercing to those types.BaseMetaobjectProtocol.Result.doesNotExist
. If the protocol can not set the new value,
it will return BaseMetaobjectProtocol.Result.notWritable
. If the protocol
doesn't have the authority to put the new property value, it will leave
the object unchanged, and return BaseMetaobjectProtocol.Result.noAuthority
. If the
operation succeeds, BaseMetaobjectProtocol.Result.ok
is returned.public BaseMetaobjectProtocol.Result put(java.lang.Object target, java.lang.Object propertyId, java.lang.Object value, CallProtocol callProtocol)
BaseMetaobjectProtocol
put
in interface BaseMetaobjectProtocol
target
- the target objectpropertyId
- the ID of the property. Usually a String or an
Integer, but other property ID types can also be supported.value
- the new value for the propertycallProtocol
- a marshaller that is used to convert the value in
case the property can only accept values of certain types, and the
metaobject protocol allows automatic coercing to those types.BaseMetaobjectProtocol.Result.doesNotExist
. If the protocol
authoritatively decides that the property is read-only, it will return
BaseMetaobjectProtocol.Result.notWritable
. If the property has a limitation on types
it can take as values, and the supplied marshaller is not able to
provide a suitable representation, then the value of the property is not
changed, and BaseMetaobjectProtocol.Result.noRepresentation
is returned. Finally, if
the protocol doesn't have the authority to put the new property value,
it will leave the property value unchanged, and return
BaseMetaobjectProtocol.Result.noAuthority
. If the operation succeeds,
BaseMetaobjectProtocol.Result.ok
is returned.public java.lang.Object representAs(java.lang.Object object, java.lang.Class targetClass)
BaseMetaobjectProtocol.Result#noRepresentation
.
In case the target class is primitive, and there exists a
widening primitive conversion from the object's class unboxed
primitive type to the target class, returns a boxed representation of
the widened value. In all other cases,
BaseMetaobjectProtocol.Result#noRepresentation
is returned.representAs
in interface CallProtocol
object
- the object to representtargetClass
- the target class for representation.BaseMetaobjectProtocol.Result.noAuthority
is returned if the
marshaller can not authoritatively decide on a representation;
BaseMetaobjectProtocol.Result.noRepresentation
is returned if
the marshaller can authoritatively decide that the requested
representation is not possible. representation of null should be null,
except when the target class is a primitive type in which case
BaseMetaobjectProtocol.Result.noRepresentation
should be
returned.public <T> BeanMetaobjectProtocol<T> getBeanMetaobjectProtocol(java.lang.Class<T> clazz)
T
- the type of the classclazz
- the class in question