examples.adapter
public class: AdapterClass [javadoc |
source]
java.lang.Object
openjava.mop.OJClass
examples.adapter.AdapterClass
The metaclass
AdapterClass supports classes
implementing an adapter role of the Adapter pattern.
The target's methods with same signatures as the adaptee's are
automatically implemented into the adapter class.
For example, the class VectorStack:
public class VectorStack instantiates AdapterClass
adapts Vector in v to Stack
{
Vector v;
public VectorStack( Vector v ) {
this.v = v;
}
public void push( Object o ) {
v.addElement( o );
}
public Object pop() {
return v.removeElementAt( v.size() - 1 );
}
}
would be automatically implemented with the forwarding methods
size(), isEmpty(), hashCode(), etc, which are found in both
the class Vector(adaptee) and the class Stack(target).
Also see:
- java.lang.Object
- author:
Michiaki - Tatsubori
- version:
1.0 -
- since:
$ - Id: AdapterClass.java,v 1.2 2003/02/19 02:55:02 tatsubori Exp $
| Field Summary |
|---|
| public static final String | KEY_ADAPTS | |
| Method from examples.adapter.AdapterClass Detail: |
public static SyntaxRule getDeclSuffixRule(String keyword) {
if (keyword.equals( KEY_ADAPTS )) {
return new openjava.syntax.CompositeRule( new openjava.syntax.TypeNameRule(), new openjava.syntax.PrepPhraseRule( "in", new openjava.syntax.NameRule() ), new openjava.syntax.PrepPhraseRule( "to", new openjava.syntax.TypeNameRule() ) );
}
return null;
}
|
public static boolean isRegisteredKeyword(String keyword) {
return keyword.equals( KEY_ADAPTS );
}
|
public void translateDefinition() throws MOPException {
/* overrides for translation */
openjava.mop.OJClass target = getTarget();
openjava.mop.OJClass adaptee = getAdaptee();
if (target == null || adaptee == null) {
return;
}
openjava.mop.OJMethod[] adapteds = adaptee.getMethods( this );
for (int i = 0; i < adapteds.length; ++i) {
openjava.mop.OJMethod m;
try {
m = getTarget().getMethod( adapteds[i].getName(), adapteds[i].getParameterTypes(), this );
} catch ( openjava.mop.NoSuchMemberException e ) {
continue;
}
addMethod( makeForwardingMethod( m.getName(), m ) );
}
addInterface( getTarget() );
}
|