|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rit.m2mi.Synthesizer
edu.rit.m2mi.HandleSynthesizer
public class HandleSynthesizer
Class HandleSynthesizer provides a Synthesizer
for synthesizing specialized handle classes. Each
specialized handle is a subclass of class
Omnihandle
,
Multihandle
, or
Unihandle
, which in turn is a subclass of
class
Handle
.
Consider this example of a target interface. (Note that all M2MI-callable methods must return void and must throw no checked exceptions.)
package com.foo; public interface Bar { public void doSomething (int x, String y); public void doSomethingElse (double z); public void doNothing(); public void doArrayStuff (float[][] a, String[] b); }
If it were to be compiled from Java source code instead of being synthesized directly, the omnihandle class for target interface com.foo.Bar would look like this (the class name "Omnihandle_1" was chosen arbitrarily):
public class Omnihandle_1 extends Omnihandle implements com.foo.Bar { private static MethodDescriptor[] methdesc = new MethodDescriptor[] { new MethodDescriptor ("com.foo.bar", "doSomething", "(ILjava/lang/String;)V"), new MethodDescriptor ("com.foo.bar", "doSomethingElse", "(D)V"), new MethodDescriptor ("com.foo.bar", "doNothing", "()V"), new MethodDescriptor ("com.foo.bar", "doArrayStuff", "([[F[Ljava/lang/String;)V"), }; public Omnihandle_1() { super(); } public void doSomething (int x, String y) { MethodInvoker_1 methinv = new MethodInvoker_1(); methinv.setArgs (x, y); myInvocationFactory.newInvocation (myEoid, methdesc[0], methinv) .processFromHandle(); } public void doSomethingElse (double z) { MethodInvoker_2 methinv = new MethodInvoker_2(); methinv.setArgs (z); myInvocationFactory.newInvocation (myEoid, methdesc[1], methinv) .processFromHandle(); } public void doNothing() { MethodInvoker_3 methinv = new MethodInvoker_3(); myInvocationFactory.newInvocation (myEoid, methdesc[2], methinv) .processFromHandle(); } public void doArrayStuff (float[][] a, String[] b) { MethodInvoker_4 methinv = new MethodInvoker_4(); methinv.setArgs (a, b); myInvocationFactory.newInvocation (myEoid, methdesc[3], methinv) .processFromHandle(); } private Object writeReplace() throws ObjectStreamException { return new Omnihandle (myEoid, myTargetInterface); } }
Notes:
Handle
containing this handle's EOID.
Handle
containing this handle's target interface.
Handle
containing this handle's invocation factory, which
creates instances of class
OmniInvocation
.
The multihandle class for target interface com.foo.Bar would be identical to
the above, except it would extend class Multihandle
, and the writeReplace() method would
return an instance of class
Multihandle
.
The unihandle class for target interface com.foo.Bar would be identical to
the above, except it would extend class Unihandle
, and the writeReplace() method would return
an instance of class
Unihandle
.
When a target method is invoked via M2MI from some ultimate calling object, the method's return value if any is not returned to the calling object, and any exception the method throws is not thrown back in the calling object. Consequently, the target method must return void and must not throw any checked exceptions. A handle class cannot be constructed for a target interface unless these preconditions are true for all methods in the interface.
Constructor Summary | |
---|---|
HandleSynthesizer(String theClassName,
String theSuperclassName,
Class theTargetInterface)
Create a new handle synthesizer object. |
Method Summary | |
---|---|
SynthesizedClassDescription |
getClassDescription()
Obtain the class description for the class this handle synthesizer synthesizes. |
static SynthesizedClassDescription |
synthesizeHandleClass(String theClassName,
String theSuperclassName,
Class theTargetInterface)
Synthesize the class file for a specialized handle subclass. |
Methods inherited from class edu.rit.m2mi.Synthesizer |
---|
getClassFile |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HandleSynthesizer(String theClassName, String theSuperclassName, Class theTargetInterface)
theClassName
- Fully-qualified name of the specialized handle subclass.theSuperclassName
- Fully-qualified name of the superclass for the specialized handle
subclass.theTargetInterface
- Target interface for the specialized handle subclass.
NullPointerException
- (unchecked exception) Thrown if theClassName is null,
theSuperclassName is null, or
theTargetInterface is null.Method Detail |
---|
public SynthesizedClassDescription getClassDescription()
getClassDescription
in class Synthesizer
InvalidMethodException
- (unchecked exception) Thrown if any target interface is a class
rather than an interface, if any method in any target interface
returns a value, or if any method in any target interface throws any
checked exceptions.
SynthesisException
- (unchecked exception) Thrown if there was a problem synthesizing the
class.public static SynthesizedClassDescription synthesizeHandleClass(String theClassName, String theSuperclassName, Class theTargetInterface)
theClassName
- Fully-qualified name of the specialized handle subclass.theSuperclassName
- Fully-qualified name of the superclass for the specialized handle
subclass.theTargetInterface
- Target interface for the specialized handle subclass.
InvalidMethodException
- (unchecked exception) Thrown if the target interface is a class
rather than an interface, if any method in the target interface
returns a value, or if any method in the target interface throws any
checked exceptions.
SynthesisException
- (unchecked exception) Thrown if there was a problem synthesizing the
class.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |