|
||||||||||
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.MethodInvokerSynthesizer
public class MethodInvokerSynthesizer
Class MethodInvokerSynthesizer provides a Synthesizer
for synthesizing specialized method invoker
classes. Each specialized method invoker class is a subclass of class
MethodInvoker
.
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 method invoker class for target method doSomething() in target interface com.foo.Bar would look like this (the class name "MethodInvoker_1" was chosen arbitrarily):
public class MethodInvoker_1 extends MethodInvoker { private int a; private String b; public MethodInvoker_1() { super(); } public void setArgs (int a, String b) { this.a = a; this.b = b; } public void write (ObjectOutput theObjectOutput) throws IOException { theObjectOutput.writeInt (a); theObjectOutput.writeObject (b); } public void read (ObjectInput theObjectInput) throws IOException, ClassNotFoundException { a = theObjectInput.readInt(); b = (String) theObjectInput.readObject(); } public void invoke (Object theTargetObject) { ((com.foo.Bar) theTargetObject).doSomething (a, b); } }
If it were to be compiled from Java source code instead of being synthesized directly, the method invoker class for target method doSomethingElse() in target interface com.foo.Bar would look like this (the class name "MethodInvoker_2" was chosen arbitrarily):
public class MethodInvoker_2 extends MethodInvoker { private double a; public MethodInvoker_2() { super(); } public void setArgs (double a) { this.a = a; } public void write (ObjectOutput theObjectOutput) throws IOException { theObjectOutput.writeDouble (a); } public void read (ObjectInput theObjectInput) throws IOException, ClassNotFoundException { a = theObjectInput.readDouble(); } public void invoke (Object theTargetObject) { ((com.foo.Bar) theTargetObject).doSomethingElse (a); } }
If it were to be compiled from Java source code instead of being synthesized directly, the method invoker class for target method doNothing() in target interface com.foo.Bar would look like this (the class name "MethodInvoker_3" was chosen arbitrarily):
public class MethodInvoker_3 extends MethodInvoker { public MethodInvoker_3() { super(); } public void setArgs() { } public void invoke (Object theTargetObject) { ((com.foo.Bar) theTargetObject).doNothing(); } }
If it were to be compiled from Java source code instead of being synthesized directly, the method invoker class for target method doArrayStuff() in target interface com.foo.Bar would look like this (the class name "MethodInvoker_4" was chosen arbitrarily):
public class MethodInvoker_4 extends MethodInvoker { private float[][] a; private String[] b; public MethodInvoker_4() { super(); } public void setArgs (float[][] a, String[] b) { this.a = a; this.b = b; } public void write (ObjectOutput theObjectOutput) throws IOException { theObjectOutput.writeObject (a); theObjectOutput.writeObject (b); } public void read (ObjectInput theObjectInput) throws IOException, ClassNotFoundException { a = (float[][]) theObjectInput.readObject(); b = (String[]) theObjectInput.readObject(); } public void invoke (Object theTargetObject) { ((com.foo.Bar) theTargetObject).doArrayStuff (a, b); } }
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 method invoker class cannot be constructed for a target method unless these preconditions are true.
Constructor Summary | |
---|---|
MethodInvokerSynthesizer(String theClassName,
MethodDescriptor theMethodDescriptor)
Create a new method invoker synthesizer object. |
Method Summary | |
---|---|
SynthesizedClassDescription |
getClassDescription()
Obtain the class description for the class this method invoker synthesizer synthesizes. |
static SynthesizedClassDescription |
synthesizeMethodInvokerClass(String theClassName,
String theTargetInterface,
String theTargetMethod,
String theArgumentTypes)
Synthesize the class file for a specialized method invoker 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 MethodInvokerSynthesizer(String theClassName, MethodDescriptor theMethodDescriptor)
theClassName
- Fully-qualified name of the specialized method invoker subclass.theMethodDescriptor
- Method descriptor for the specialized method invoker subclass.
NullPointerException
- (unchecked exception) Thrown if theClassName is null or
theMethodDescriptor is null.Method Detail |
---|
public SynthesizedClassDescription getClassDescription()
getClassDescription
in class Synthesizer
SynthesisException
- (unchecked exception) Thrown if there was a problem synthesizing the
class.public static SynthesizedClassDescription synthesizeMethodInvokerClass(String theClassName, String theTargetInterface, String theTargetMethod, String theArgumentTypes)
MethodInvoker
. The synthesized class is customized to
invoke the given target interface name and target method name with the
given argument types.
theClassName
- Fully-qualified name of the specialized method invoker subclass.theTargetInterface
- Fully-qualified name of the target interface.theTargetMethod
- Target method name.theArgumentTypes
- Target method's argument types, specified as a Java class file method
descriptor string. The return type in the method descriptor string
must be void.
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 |