T
- the interface that represents the the native COM interfacepublic abstract class ComEventObject<T extends com4j.Com4jObject> extends ComObject<T>
ComEventObject
class adds support for registering for native
COM events. It is the base class of all COM derived Java classes, that
support native COM events.Modifier and Type | Field and Description |
---|---|
protected Map<ComEventListener,com4j.EventCookie> |
events
Stores all event cookies obtained from method
Com4jObject.advise(Class
, using the event receiver ComEventListener as key. |
Modifier | Constructor and Description |
---|---|
protected |
ComEventObject(T base)
Constructs a new
ComEventObject descendant object by using
the COM object's proxy class specified. |
Modifier and Type | Method and Description |
---|---|
<E extends ComEventListener> |
addComEventListener(Class<E> eventInterface,
E listener)
Adds the specified COM event listener to receive events for the specified
event interface from the underlying COM event source.
|
protected int |
comEventListeners()
Returns the number of currently registered COM event listeners.
|
void |
dispose()
Releases the reference to the native COM object exposed by this object.
|
<E extends ComEventListener> |
getComEventListeners(Class<E> listenerType)
Returns an array of all the objects currently registered as
ComEventListener s upon this ComEventObject . |
boolean |
isComEventListener(ComEventListener listener)
Indicates whether the specified listener
listener is a
registered COM event listener for this ComEventObject . |
protected void |
removeComEventListener(ComEventListener listener)
Removes the specified COM event listener for the specified event
interface so that it no longer receives events from the underlying COM
event source.
|
clone, equals, hashCode, isDisposed, isInstanceOf, referenceEquals, toString
protected Map<ComEventListener,com4j.EventCookie> events
Com4jObject.advise(Class nativeEventInterface, T receiver)
, using the event receiver ComEventListener
as key.protected ComEventObject(T base)
ComEventObject
descendant object by using
the COM object's proxy class specified.
Since this class is abstract
, this constructor is never
called directly but only though a constructor of any subclass, which
extends this class. Its only purposes are to pick up the proxy class.
base
- the native COM object's proxy classpublic <E extends ComEventListener> void addComEventListener(Class<E> eventInterface, E listener)
listener
is null
or event interface
nativeEventInterface
is null
, no exception is
thrown and no action is performed.E
- an interface that derives from
com.datagis.com4j.ComEventListener
eventInterface
- the type of listeners requested; this parameter should specify
an interface that derives from
com.datagis.com4j.ComEventListener
listener
- the COM event listener to be addedremoveComEventListener(ComEventListener)
,
getComEventListeners(java.lang.Class<E>)
,
ComEventListener
protected void removeComEventListener(ComEventListener listener)
listener
is null
, no exception is thrown and no
action is performed.listener
- the COM event listener to be removedaddComEventListener(ComEventListener)
,
getComEventListeners(java.lang.Class<E>)
,
ComEventListener
public <E extends ComEventListener> E[] getComEventListeners(Class<E> listenerType)
ComEventListener
s upon this ComEventObject
.
ComEventListener
s are registered using the
addComEventListener
method.
You can specify the listenerType
argument with a class
literal, such as FooComEventListener.class
. For
example, you can query the COM class Application
a
for its COM event listeners with the following code:
ApplicationListener[] ls = (ApplicationListener[]) (a .getComEventListeners(ApplicationListener.class));If no such listeners exist, this method returns an empty array.
E
- an interface that derives from
com.datagis.com4j.ComEventListener
listenerType
- the type of listeners requested; this parameter should specify
an interface that derives from
com.datagis.com4j.ComEventListener
ComEventListener
s on this component, or an empty
array if no such listeners have been addedClassCastException
- if listenerType
doesn't specify a class or
interface that implements
com.datagis.com4j.ComEventListener
addComEventListener(ComEventListener)
,
removeComEventListener(ComEventListener)
,
ComEventListener
protected int comEventListeners()
public boolean isComEventListener(ComEventListener listener)
listener
is a
registered COM event listener for this ComEventObject
.listener
- the COM event listener to testtrue
if the specified listener listener
is a registered COM event listener for this
ComEventObject
; false
otherwise.public void dispose()
dispose
can be called on an object multiple times,
regardless whether the object is already disposed, method
isDisposed
may be used to determine, whether an object is
disposed or not.
Since Java objects tend to live longer in memory until they are garbage collected, and applications have generally no control over when this happens, calling the dispose method at any time enables applications to dispose the native COM objects deterministically.
After having disposed a native COM object, one has no longer access to
the object's methods nor will any events be delivered to any event
listener that still may be registered. Accessing methods of a disposed
native COM object will throw an IllegalStateException
.
dispose
in interface Disposable
dispose
in class ComObject<T extends com4j.Com4jObject>
ComObject.isDisposed()
Copyright © 2009 - 2016 DataGis. All Rights Reserved.