public abstract class ComObject extends java.lang.Object implements WrappedResource, Deletable
comhandle
s. Does minimal
management of the COM Object.Modifier and Type | Field and Description |
---|---|
protected boolean |
includeUnannotatedMethods
When set to
true the method and property resolution mechanism will include also methods not
annotated with ComMethod or ComProperty. |
static java.util.logging.Logger |
LOGGER
The logger for COM methods
|
private static boolean |
LOGGING_ENABLED |
protected static java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> |
methodTable
Cache of Java methods implementing COM methods.
|
private java.lang.String |
name
The legacy name of this com object.
|
private ControlFrameWidget |
parentControlFrame
The parent
ControlFrameWidget widget. |
private handle |
parentProcedure
The creator of this object.
|
protected static java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> |
propertyTable
Cache of Java methods implementing COM properties.
|
private java.util.concurrent.atomic.AtomicInteger |
refcount
Counter for
comhandle s that refer this object. |
private java.lang.Long |
resourceId
The resource id.
|
private static java.lang.Class<?> |
VOID
The class for void Java type
|
Constructor and Description |
---|
ComObject()
Build a new COM Object.
|
Modifier and Type | Method and Description |
---|---|
BaseDataType |
call(java.lang.String _name,
java.lang.Object... params)
Calls a COM-method without parameters on the COM-object stored in this com-handle.
|
comhandle |
chainCall(java.lang.String methodName,
java.lang.Object... params)
Calls a COM-method on the COM-object stored in this com-handle.
|
protected static void |
checkParameters(BaseDataType[][] vals,
java.lang.Object[] params)
Check the parameters received from a COM method call and copy the values into OUTPUT or
INPUT-OUTPUT arguments.
|
(package private) static boolean |
convertInputParameter(java.lang.Object arg,
java.lang.Class<?> targetType,
java.lang.Object[] dest,
int idx)
Try to convert a value to the given type.
|
void |
delete()
Do nothing by default
|
void |
deref()
Increments the reference counter for this COM object.
|
void |
destroy()
Destroy all resources kept by FWD related to this COM object.
|
abstract java.lang.String |
getActivexName()
Obtain the name of this ActiveX object.
|
protected java.lang.Class |
getComObjectClass()
Returns the com object class.
|
protected java.lang.Object |
getComObjectInstance()
Returns the com object instance.
|
java.lang.String |
getName()
Obtain the legacy name of this COM object.
|
ControlFrameWidget |
getParentControlFrame()
Obtain the
ControlFrameWidget container for this COM, if any. |
handle |
getParentProcedure()
Get the parent procedure where this COM was created.
|
BaseDataType |
getProperty(java.lang.String prop,
java.lang.Object... indices)
Obtain a property value from the COM object stored in this handle.
|
java.lang.Long |
id()
Get this resource's ID, if is already set.
|
void |
id(long id)
Set this resource's ID.
|
protected void |
init()
Initialize internal data structure of a fresh COM: the parent procedure is detected.
|
protected static BaseDataType |
marshal(java.lang.Object aVal)
Converts a value to a BDT object.
|
private static <T extends java.lang.annotation.Annotation> |
methodsFor(java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> table,
java.lang.Class<T> annClass,
java.lang.Class<? extends ComObject> clazz,
java.lang.String comName)
Select all methods whose name, class and COM annotation match the argument.
|
void |
ref()
Increments the reference counter for this COM object.
|
void |
setName(java.lang.String newName)
Sets the legacy name of this COM object.
|
void |
setParentControlFrame(ControlFrameWidget pcf)
Sets the
ControlFrameWidget container for this COM. |
boolean |
setProperty(java.lang.String prop,
java.lang.Object newVal,
java.lang.Object... indices)
Sets a COM property for the COM object stored by the handle.
|
private static void |
testAndRegisterMethod(java.lang.Class<? extends java.lang.annotation.Annotation> annClass,
com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method> classTable,
java.lang.reflect.Method method)
Test if the method passed as the
method argument is
annotated with the annotation of the type passed in the annClass
argument. |
boolean |
unknown()
Reports if this object is unknown.
|
protected static ComParameter |
unmarshal(java.lang.Object aVal)
Converts a value from a
ComParameter , BaseDataType or other Java type to
a ComParameter instance which can be passed as an argument to a COM method call. |
protected static ComParameter[] |
unmarshal(java.lang.Object[] aVals)
Converts an array of values from a
ComParameter , BaseDataType or other Java
type to a ComParameter instance which can be passed as an argument to a COM method
call. |
boolean |
valid()
Return true by default.
|
private BaseDataType |
xcall(java.lang.String _name,
java.util.Collection<java.lang.reflect.Method> methods,
java.lang.Object[] args)
Select a method from the given list, and call the method with the arguments specified.
|
protected static final java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> propertyTable
protected static final java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> methodTable
protected boolean includeUnannotatedMethods
true
the method and property resolution mechanism will include also methods not
annotated with ComMethod or ComProperty.private java.lang.Long resourceId
WrappedResource
management.private ControlFrameWidget parentControlFrame
ControlFrameWidget
widget. This container is used during the dispatch of
the events generated by this COM Object.private java.lang.String name
private handle parentProcedure
null
. Used for locating the event callbacks
as its internal procedure. When becomes invalid, this object also gets invalid and should be
deleted.private java.util.concurrent.atomic.AtomicInteger refcount
comhandle
s that refer this object.public static final java.util.logging.Logger LOGGER
private static final boolean LOGGING_ENABLED
private static final java.lang.Class<?> VOID
public ComObject()
init()
to initialize internal data structure.protected void init()
protected static BaseDataType marshal(java.lang.Object aVal)
BaseDataType
, in fact is assume it is not. Note that, because this method uses the
best matching constructor, this method may do some implicit conversions if the passed in
value is compatible with the class required (like from a String
).aVal
- The value to be converted.BaseDataType
instance that represent the same value as aVal
.public boolean valid()
valid
in interface WrappedResource
true
if we are valid (can be used).protected static ComParameter unmarshal(java.lang.Object aVal)
ComParameter
, BaseDataType
or other Java type to
a ComParameter
instance which can be passed as an argument to a COM method call.aVal
- The value to be converted.ComParameter
instance.java.lang.IllegalArgumentException
- If the value can't be passed by FWD as an argument for a COM method call.protected static ComParameter[] unmarshal(java.lang.Object[] aVals)
ComParameter
, BaseDataType
or other Java
type to a ComParameter
instance which can be passed as an argument to a COM method
call.aVals
- The values to be converted.ComParameter
instance.java.lang.IllegalArgumentException
- If the value can't be passed by FWD as an argument for a COM method call.protected static void checkParameters(BaseDataType[][] vals, java.lang.Object[] params)
vals
- The received values. The arguments are 1-indexed (as on index 0 is the return
value), and each argument has an entry in this array; null
values
represent INPUT arguments or unknown
values.params
- The actual references received by FWD for this method call. All OUTPUT or INPUT-
OUTPUT arguments must be ComParameter
instances.public boolean unknown()
unknown
in interface WrappedResource
true
if object is unknown.public java.lang.Long id()
id
in interface WrappedResource
null
if not set.public void id(long id)
id
in interface WrappedResource
id
- The resource's ID.public java.lang.String getName()
public void setName(java.lang.String newName)
newName
- The new legacy name of this COM object.public abstract java.lang.String getActivexName()
public final void destroy()
public ControlFrameWidget getParentControlFrame()
ControlFrameWidget
container for this COM, if any.public void setParentControlFrame(ControlFrameWidget pcf)
ControlFrameWidget
container for this COM.pcf
- The container for this COM.public handle getParentProcedure()
public boolean setProperty(java.lang.String prop, java.lang.Object newVal, java.lang.Object... indices)
prop
- The legacy property name. Case insensitive. If no property is found then a warning
is displayed and method returns without altering the stored object.newVal
- The new value for the property. It must be of a compatible type with the property.indices
- A variable number of indices used to access this property's element.true
if the property was set.public BaseDataType getProperty(java.lang.String prop, java.lang.Object... indices)
prop
- The legacy name of the property. Case insensitive. If no property is found then a
warning is displayed and method returns unknown
value.indices
- A variable number of indices used to access this property's element.unknown
on exceptions.protected java.lang.Class getComObjectClass()
this.getClass
. To be overriden by classes
providing support for "dynamic" com object access.protected java.lang.Object getComObjectInstance()
this
. To be overriden by classes
providing support for "dynamic" com object access.private static <T extends java.lang.annotation.Annotation> java.util.Collection<java.lang.reflect.Method> methodsFor(java.util.Map<java.lang.String,com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method>> table, java.lang.Class<T> annClass, java.lang.Class<? extends ComObject> clazz, java.lang.String comName)
T
- the annotation type: either ComMethod
or ComProperty
.table
- the method class+name - method cache table, lazily updated by this methodannClass
- If not null
, then only methods annotated with this annotation class are tested,
otherwise all methods are tested.
The argument must match the T
template argument.clazz
- the class of the objects we are looking for the methods incomName
- the method name in any case.private static void testAndRegisterMethod(java.lang.Class<? extends java.lang.annotation.Annotation> annClass, com.google.common.collect.Multimap<java.lang.String,java.lang.reflect.Method> classTable, java.lang.reflect.Method method)
method
argument is
annotated with the annotation of the type passed in the annClass
argument. If yes, then register the method in the
classTable
under the name extracted from the annotation name()
field and converted to the upper case.annClass
- the annotation class, must be either ComParameter
or ComMethod
classTable
- the map to register the matching method inmethod
- the input method to teststatic boolean convertInputParameter(java.lang.Object arg, java.lang.Class<?> targetType, java.lang.Object[] dest, int idx)
arg
- the value to converttargetType
- the destination type to convert the value todest
- the output array to store the converted valueidx
- the index in the output array to store the successful conversion resulttrue
if conversion succeeded.public BaseDataType call(java.lang.String _name, java.lang.Object... params)
_name
- The method name, case insensitive. If the COM-object does not declare such method
an error message is displayed and this method returns an empty comhandle
.params
- The list of actual parameters. Their types must be compatible with the parameters
of called method.comhandle
if no compatible method was found.private BaseDataType xcall(java.lang.String _name, java.util.Collection<java.lang.reflect.Method> methods, java.lang.Object[] args)
_name
- the method name to search for, used for "method not found" reporting only.methods
- the list of all methods of the class matching the nameargs
- the arguments to pass to the method callBaseDataType
.
Otherwise return null
public comhandle chainCall(java.lang.String methodName, java.lang.Object... params)
methodName
- The method name. Case insensitive. If the COM-object does not declare such method
an error message is displayed and this method returns unknown
value.params
- The list of actual parameters. Their types must be compatible with the parameters
of called method.
TODO: marshal to BDT (?) When code is generated [param] is already BDT.comhandle
, so it can be used in a
chained call or property access.public void ref()
public void deref()