B-1_14-DEV merge back to main

This commit is contained in:
clay_shooter
2008-02-02 01:38:25 +00:00
parent cd58b57a99
commit df0ba33797
97 changed files with 12208 additions and 8816 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -26,67 +26,78 @@ import com.jacob.com.InvocationProxy;
/**
* RELEASE 1.12 EXPERIMENTAL.
* <p>
* Use this exactly like the DispatchEvents class. This class plugs in
* an ActiveXInvocationProxy instead of an InvocationProxy. It is the
* ActiveXInvocationProxy that implements the reflection calls and invoke
* the found java event callbacks. See ActiveXInvocationProxy for details.
* Use this exactly like the DispatchEvents class. This class plugs in an
* ActiveXInvocationProxy instead of an InvocationProxy. It is the
* ActiveXInvocationProxy that implements the reflection calls and invoke the
* found java event callbacks. See ActiveXInvocationProxy for details.
*
*
*
*/
public class ActiveXDispatchEvents extends DispatchEvents {
/**
* This is the most commonly used constructor.
* <p>
* Creates the event callback linkage between the the
* MS program represented by the Dispatch object and the
* Java object that will receive the callback.
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
super(sourceOfEvent, eventSink, null );
}
/**
* This is the most commonly used constructor.
* <p>
* Creates the event callback linkage between the the MS program represented
* by the Dispatch object and the Java object that will receive the
* callback.
*
* @param sourceOfEvent
* Dispatch object who's MS app will generate callbacks
* @param eventSink
* Java object that wants to receive the events
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
super(sourceOfEvent, eventSink, null);
}
/**
* None of the samples use this constructor.
* <p>
* Creates the event callback linkage between the the
* MS program represented by the Dispatch object and the
* Java object that will receive the callback.
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
* @param progId ???
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink, String progId) {
super(sourceOfEvent, eventSink, progId, null );
}
/**
* None of the samples use this constructor.
* <p>
* Creates the event callback linkage between the the MS program represented
* by the Dispatch object and the Java object that will receive the
* callback.
*
* @param sourceOfEvent
* Dispatch object who's MS app will generate callbacks
* @param eventSink
* Java object that wants to receive the events
* @param progId
* ???
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
String progId) {
super(sourceOfEvent, eventSink, progId, null);
}
/**
* Creates the event callback linkage between the the
* MS program represented by the Dispatch object and the
* Java object that will receive the callback.
* <pre>
* >ActiveXDispatchEvents de =
* new ActiveXDispatchEvents(someDispatch,someEventHAndler,
* "Excel.Application",
* "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE");
*
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
* @param progId , mandatory if the typelib is specified
* @param typeLib The location of the typelib to use
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink, String progId, String typeLib)
{
super(sourceOfEvent, eventSink, progId, typeLib);
}
/**
* Creates the event callback linkage between the the MS program represented
* by the Dispatch object and the Java object that will receive the
* callback.
*
* <pre>
* &gt;ActiveXDispatchEvents de =
* new ActiveXDispatchEvents(someDispatch,someEventHAndler,
* &quot;Excel.Application&quot;,
* &quot;C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE&quot;);
*
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
* @param progId , mandatory if the typelib is specified
* @param typeLib The location of the typelib to use
*
*/
public ActiveXDispatchEvents(Dispatch sourceOfEvent, Object eventSink,
String progId, String typeLib) {
super(sourceOfEvent, eventSink, progId, typeLib);
}
/*
* (non-Javadoc)
* @see com.jacob.com.DispatchEvents#getInvocationProxy(java.lang.Object)
*/
protected InvocationProxy getInvocationProxy(Object pTargetObject){
/*
* (non-Javadoc)
*
* @see com.jacob.com.DispatchEvents#getInvocationProxy(java.lang.Object)
*/
protected InvocationProxy getInvocationProxy(Object pTargetObject) {
InvocationProxy newProxy = new ActiveXInvocationProxy();
newProxy.setTarget(pTargetObject);
return newProxy;

View File

@@ -29,63 +29,70 @@ import com.jacob.com.Variant;
/**
* RELEASE 1.12 EXPERIMENTAL.
* <p>
* This class that lets event handlers receive events with all java
* objects as parameters. The standard Jacob event methods all accept an array of
* Variant objects. When using this class, you can set up your event methods
* as regular java methods with the correct number of parameters of the correct
* java type. This does NOT work for any event that wishes to accept a call
* back and modify the calling parameters to tell windows what to do. An example
* is when an event lets the receiver cancel the action by setting a boolean flag
* to false. The java objects cannot be modified and their values will not be passed
* back into the originating Variants even if they could be modified.
* This class that lets event handlers receive events with all java objects as
* parameters. The standard Jacob event methods all accept an array of Variant
* objects. When using this class, you can set up your event methods as regular
* java methods with the correct number of parameters of the correct java type.
* This does NOT work for any event that wishes to accept a call back and modify
* the calling parameters to tell windows what to do. An example is when an
* event lets the receiver cancel the action by setting a boolean flag to false.
* The java objects cannot be modified and their values will not be passed back
* into the originating Variants even if they could be modified.
* <p>
* This class acts as a proxy between the windows event callback mechanism and
* the Java classes that are looking for events. It assumes that
* all of the Java classes that are looking for events implement methods with the
* same names as the windows events and that the implemented methods native
* java objects of the type and order that match the windows documentation.
* The methods can return void or a Variant that
* will be returned to the calling layer. All Event methods that will be
* recognized by InvocationProxyAllEvents have the signature
*
* <code> void eventMethodName(Object,Object...)</code>
* or
* <code> Object eventMethodName(Object,Object...)</code>
* the Java classes that are looking for events. It assumes that all of the Java
* classes that are looking for events implement methods with the same names as
* the windows events and that the implemented methods native java objects of
* the type and order that match the windows documentation. The methods can
* return void or a Variant that will be returned to the calling layer. All
* Event methods that will be recognized by InvocationProxyAllEvents have the
* signature
*
* <code> void eventMethodName(Object,Object...)</code> or
* <code> Object eventMethodName(Object,Object...)</code>
*/
public class ActiveXInvocationProxy extends InvocationProxy {
/*
* (non-Javadoc)
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String, com.jacob.com.Variant[])
*
* @see com.jacob.com.InvocationProxy#invoke(java.lang.String,
* com.jacob.com.Variant[])
*/
@SuppressWarnings("unchecked")
public Variant invoke(String methodName, Variant targetParameters[]) {
Variant mVariantToBeReturned = null;
if (mTargetObject == null){
// structured programming guidlines say this return should not be up here
Variant mVariantToBeReturned = null;
if (mTargetObject == null) {
// structured programming guidlines say this return should not be up
// here
return null;
}
Class targetClass = mTargetObject.getClass();
if (methodName == null){
throw new IllegalArgumentException("InvocationProxy: missing method name");
if (methodName == null) {
throw new IllegalArgumentException(
"InvocationProxy: missing method name");
}
if (targetParameters == null){
throw new IllegalArgumentException("InvocationProxy: missing Variant parameters");
if (targetParameters == null) {
throw new IllegalArgumentException(
"InvocationProxy: missing Variant parameters");
}
try {
Method targetMethod;
Object parametersAsJavaObjects[] = getParametersAsJavaObjects(targetParameters);
Class parametersAsJavaClasses[] = getParametersAsJavaClasses(parametersAsJavaObjects);
targetMethod = targetClass.getMethod(methodName, parametersAsJavaClasses);
if (targetMethod != null){
Class parametersAsJavaClasses[] = getParametersAsJavaClasses(parametersAsJavaObjects);
targetMethod = targetClass.getMethod(methodName,
parametersAsJavaClasses);
if (targetMethod != null) {
// protected classes can't be invoked against even if they
// let you grab the method. you could do targetMethod.setAccessible(true);
// let you grab the method. you could do
// targetMethod.setAccessible(true);
// but that should be stopped by the security manager
Object mReturnedByInvocation = null;
mReturnedByInvocation =
targetMethod.invoke(mTargetObject,parametersAsJavaObjects);
if (mReturnedByInvocation == null){
mReturnedByInvocation = targetMethod.invoke(mTargetObject,
parametersAsJavaObjects);
if (mReturnedByInvocation == null) {
mVariantToBeReturned = null;
} else if (!(mReturnedByInvocation instanceof Variant)){
} else if (!(mReturnedByInvocation instanceof Variant)) {
mVariantToBeReturned = new Variant(mReturnedByInvocation);
} else {
mVariantToBeReturned = (Variant) mReturnedByInvocation;
@@ -95,11 +102,13 @@ public class ActiveXInvocationProxy extends InvocationProxy {
// what causes this exception?
e.printStackTrace();
} catch (NoSuchMethodException e) {
// this happens whenever the listener doesn't implement all the methods
// this happens whenever the listener doesn't implement all the
// methods
} catch (IllegalArgumentException e) {
// we can throw these inside the catch block so need to re-throw it
Exception oneWeShouldToss = new IllegalArgumentException("Unable to map parameters for method "+methodName
+ ": "+e.toString());
// we can throw these inside the catch block so need to re-throw it
Exception oneWeShouldToss = new IllegalArgumentException(
"Unable to map parameters for method " + methodName + ": "
+ e.toString());
oneWeShouldToss.printStackTrace();
} catch (IllegalAccessException e) {
// can't access the method on the target instance for some reason
@@ -109,23 +118,27 @@ public class ActiveXInvocationProxy extends InvocationProxy {
e.printStackTrace();
}
return mVariantToBeReturned;
}
/**
* creates a method signature compatible array of classes from an array of parameters
* creates a method signature compatible array of classes from an array of
* parameters
*
* @param parametersAsJavaObjects
* @return
*/
@SuppressWarnings("unchecked")
private Class[] getParametersAsJavaClasses(Object[] parametersAsJavaObjects) {
if (parametersAsJavaObjects == null){
throw new IllegalArgumentException("This only works with an array of parameters");
if (parametersAsJavaObjects == null) {
throw new IllegalArgumentException(
"This only works with an array of parameters");
}
int numParameters = parametersAsJavaObjects.length;
Class parametersAsJavaClasses[] = new Class[numParameters];
for ( int parameterIndex = 0 ; parameterIndex < numParameters; parameterIndex++){
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
Object oneParameterObject = parametersAsJavaObjects[parameterIndex];
if (oneParameterObject == null){
if (oneParameterObject == null) {
parametersAsJavaClasses[parameterIndex] = null;
} else {
Class oneParameterClass = oneParameterObject.getClass();
@@ -137,31 +150,34 @@ public class ActiveXInvocationProxy extends InvocationProxy {
/**
* converts an array of Variants to their associated Java types
*
* @param targetParameters
* @return
*/
private Object[] getParametersAsJavaObjects(Variant[] targetParameters) {
if (targetParameters == null){
throw new IllegalArgumentException("This only works with an array of parameters");
if (targetParameters == null) {
throw new IllegalArgumentException(
"This only works with an array of parameters");
}
int numParameters = targetParameters.length;
Object parametersAsJavaObjects[] = new Object[numParameters];
for ( int parameterIndex = 0 ; parameterIndex < numParameters; parameterIndex++){
for (int parameterIndex = 0; parameterIndex < numParameters; parameterIndex++) {
Variant oneParameterObject = targetParameters[parameterIndex];
if (oneParameterObject == null){
if (oneParameterObject == null) {
parametersAsJavaObjects[parameterIndex] = null;
} else {
try {
parametersAsJavaObjects[parameterIndex] = oneParameterObject.toJavaObject();
} catch (NotImplementedException nie){
throw new IllegalArgumentException("Can't convert parameter "+parameterIndex+
" type "+oneParameterObject.getvt()
+" to java object: "+nie.getMessage());
parametersAsJavaObjects[parameterIndex] = oneParameterObject
.toJavaObject();
} catch (NotImplementedException nie) {
throw new IllegalArgumentException(
"Can't convert parameter " + parameterIndex
+ " type " + oneParameterObject.getvt()
+ " to java object: " + nie.getMessage());
}
}
}
return parametersAsJavaObjects;
}
}