You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jk...@locus.apache.org on 2000/09/20 23:19:39 UTC
cvs commit: xml-xalan/java/src/synthetic/reflection Constructor.java EntryPoint.java Field.java Member.java Method.java
jkesselm 00/09/20 14:19:39
Added: java/src/synthetic/reflection Constructor.java
EntryPoint.java Field.java Member.java Method.java
Log:
synthetic.Class: IBM-developed reverse-reflection experiment, used in the compiled-Template experiment.
Incomplete but I had 'em on hand and have been meaning to publish anyway.
Arguably overkill for current compilation code, but may simplify later work.
Revision Changes Path
1.1 xml-xalan/java/src/synthetic/reflection/Constructor.java
Index: Constructor.java
===================================================================
// Synthetic Class descriptors ("reverse reflection")
// Copyright �2000 International Business Machines Corportation
// All rights reserved.
package synthetic.reflection;
import java.lang.reflect.InvocationTargetException;
import synthetic.SynthesisException;
/**
Constructor provides information about, and access to, a
single constructor for a class.
Constructor permits widening conversions to occur when
matching the actual parameters to newInstance() with
the underlying constructor's formal parameters, but
throws an IllegalArgumentException if a narrowing
conversion would occur.
@see Member
@see Class
@see getConstructors
@see getConstructor
@see getDeclaredConstructors
*/
public class Constructor
extends EntryPoint
implements Member
{
/**
Actual Java class object. When present, all interactions
are redirected to it. Allows our Class to function as a
wrapper for the Java version (in lieu of subclassing or
a shared Interface), and allows BSC or similar
compilation to replace a generated description with an
directly runnable class.
*/
private synthetic.Class declaringclass = null;
/**
Actual Java class object. When present, all interactions
are redirected to it. Allows our Class to function as a
wrapper for the Java version (in lieu of subclassing or
a shared Interface), and allows BSC or similar
compilation to replace a generated description with an
directly runnable class.
*/
private java.lang.reflect.Constructor realconstructor = null;
private synthetic.Class[] parametertypes;
private String[] parameternames;
private synthetic.Class[] exceptiontypes;
private int modifiers;
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Constructor(synthetic.Class declaringclass)
{
super(declaringclass);
}
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Constructor(java.lang.reflect.Constructor ctor,synthetic.Class declaringclass)
{
super(ctor,declaringclass);
}
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Constructor(java.lang.reflect.Constructor realconstructor)
{
super(realconstructor);
}
/**
Returns a hashcode for this Constructor. The
hashcode is the same as the hashcode for the
underlying constructor's declaring class name.
*/
public int hashCode()
{
return getDeclaringClass().getName().hashCode();
}
/**
Uses the constructor represented by this
Constructor object to create and initialize a new
instance of the constructor's declaring class, with
the specified initialization parameters. Individual
parameters are automatically unwrapped to match
primitive formal parameters, and both primitive
and reference parameters are subject to widening
conversions as necessary. Returns the newly
created and initialized object.
<p>
Creation proceeds with the following steps, in
order:
<p>
If the class that declares the underlying constructor
represents an abstract class, the creation throws an
InstantiationException.
<p>
If this Constructor object enforces Java language
access control and the underlying constructor is
inaccessible, the creation throws an
IllegalAccessException.
<p>
If the number of actual parameters supplied via
initargs is different from the number of formal
parameters required by the underlying constructor,
the creation throws an IllegalArgumentException.
<p>
A new instance of the constructor's declaring class
is created, and its fields are initialized to their
default initial values.
<p>
For each actual parameter in the supplied initargs
array:
<p>
If the corresponding formal parameter has a
primitive type, an unwrapping conversion is
attempted to convert the object value to a value of
the primitive type. If this attempt fails, the
creation throws an IllegalArgumentException.
<p>
If, after possible unwrapping, the parameter value
cannot be converted to the corresponding formal
parameter type by an identity or widening
conversion, the creation throws an
IllegalArgumentException.
<p>
Control transfers to the underlying constructor to
initialize the new instance. If the constructor
completes abruptly by throwing an exception, the
exception is placed in an
InvocationTargetException and thrown in turn to
the caller of newInstance.
<p>
If the constructor completes normally, returns the
newly created and initialized instance.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the number of actual and formal
parameters differ, or if an unwrapping
conversion fails.
@throws InstantiationException
if the class that declares the underlying
constructor represents an abstract class.
@throws InvocationTargetException
if the underlying constructor throws an
exception.
*/
public Object newInstance(Object initargs[])
throws InstantiationException, IllegalAccessException,
IllegalArgumentException,
java.lang.reflect.InvocationTargetException
{
if(realep!=null)
return ((java.lang.reflect.Constructor)realep).newInstance(initargs);
else
throw new InstantiationException("Un-reified synthetic.Class doesn't yet support invocation");
}
}
1.1 xml-xalan/java/src/synthetic/reflection/EntryPoint.java
Index: EntryPoint.java
===================================================================
// Synthetic Class descriptors ("reverse reflection")
// Copyright �2000 International Business Machines Corportation
// All rights reserved.
package synthetic.reflection;
import java.lang.reflect.InvocationTargetException;
import synthetic.SynthesisException;
/***** OPEN ISSUES:
Reflection doesn't tell us about deprecation; if we want
that info, MFC advises mousing our way into the class (ugh).
Should we at least model that for synthetics?
*/
/**
API/behaviors shared between Constructors and Methods.
They're mostly similar, except for what they proxy and
a few specific calls (name, invoke/getInstance).
*/
abstract public class EntryPoint
implements Member
{
protected Object realep;
private synthetic.Class declaringclass = null;
protected synthetic.Class returntype = null;
private String[] parameternames=new String[0];
private synthetic.Class[] parametertypes=new synthetic.Class[0];
private synthetic.Class[] exceptiontypes=new synthetic.Class[0];;
private int modifiers;
protected String name=null; // for Methods
// For synthesis:
private StringBuffer body=null;
private String language=null;
// For reifying:
Class[] realE,realP;
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public EntryPoint(synthetic.Class declaringclass)
{
this.declaringclass=declaringclass;
}
/** Nonpublic constructor. Wrap this to appropriate "real" type */
protected EntryPoint(Object ep,synthetic.Class declaringclass)
throws IllegalArgumentException
{
realep=ep;
this.declaringclass=declaringclass;
if(ep instanceof java.lang.reflect.Method)
{
java.lang.reflect.Method m=(java.lang.reflect.Method)ep;
if(declaringclass==null)
{
declaringclass=synthetic.Class.forClass(m.getDeclaringClass());
}
name=m.getName();
modifiers=m.getModifiers();
returntype=synthetic.Class.forClass(m.getReturnType());
realP=m.getParameterTypes();
realE=m.getExceptionTypes();
}
else if(ep instanceof java.lang.reflect.Constructor)
{
java.lang.reflect.Constructor c=(java.lang.reflect.Constructor)ep;
if(declaringclass==null)
{
declaringclass=synthetic.Class.forClass(c.getDeclaringClass());
}
name=declaringclass.getShortName();
modifiers=c.getModifiers();
returntype=declaringclass;
realP=c.getParameterTypes();
realE=c.getExceptionTypes();
}
else
throw new IllegalArgumentException();
}
/** Nonpublic constructor. Wrap this to appropriate "real" type */
protected EntryPoint(Object ep)
throws IllegalArgumentException
{
this(ep,null);
}
/**
Compares this against the specified
object. Returns true if the objects are the same.
Two EntryPoints are the same if they were
declared by the same class, have the same name
(or are both ctors) and have the same
formal parameter types.
*/
public boolean equals(Object obj)
{
EntryPoint otherep=null;
if (obj instanceof EntryPoint)
otherep=(EntryPoint)obj;
else if (obj instanceof java.lang.reflect.Constructor ||
obj instanceof java.lang.reflect.Method)
otherep = (EntryPoint)obj;
return (otherep!=null
&& ((this instanceof Constructor && otherep instanceof Constructor)
||
(this instanceof Method && otherep instanceof Method &&
this.getName().equals(otherep.getName()) ))
&& otherep.getDeclaringClass().equals(declaringclass)
&& otherep.getParameterTypes().equals(parametertypes));
}
/**
Returns the Class object representing the class that
declares the constructor represented by this
Constructor object.
*/
public synthetic.Class getDeclaringClass()
{
return declaringclass;
}
/**
Returns the Class object representing the class that
will be returned by this EntryPoint. Needed by the Method
API, but made meaningful for Constructors as well.
*/
public synthetic.Class getReturnType()
{
return returntype;
}
/**
Returns an array of Class objects that represent the
types of the checked exceptions thrown by the
underlying constructor represented by this
Constructor object. Returns an array of length 0 if
the constructor throws no checked exceptions.
*/
public synthetic.Class[] getExceptionTypes()
{
if(realep!=null && exceptiontypes==null)
{
exceptiontypes=new synthetic.Class[realE.length];
for(int i=0;i<realE.length;++i)
exceptiontypes[i]=synthetic.Class.forClass(realE[i]);
realE=null;
}
return exceptiontypes;
}
public void addExceptionType(synthetic.Class exception)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
synthetic.Class[] e=new synthetic.Class[exceptiontypes.length+1];
System.arraycopy(exceptiontypes,0,e,0,exceptiontypes.length);
e[exceptiontypes.length]=exception;
exceptiontypes=e;
}
/**
Returns the Java language modifiers for the
constructor represented by this Constructor object,
as an integer. The Modifier class should be used to
decode the modifiers.
@see
Modifier
*/
public int getModifiers()
{
return modifiers;
}
/**
* Member method. C'tor's name is always that of the defining class.
* Methods have a "real" name.
* Creation date: (12-25-99 1:32:06 PM)
* @return java.lang.String
*/
public java.lang.String getName() {
if(this instanceof Constructor)
return declaringclass.getShortName();
return name;
}
/**
* Member method. C'tor's name is always that of the defining class.
* Methods have a "real" name.
* Creation date: (12-25-99 1:32:06 PM)
* @return java.lang.String
*/
public void setName(String name)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.name=name;
}
/**
Returns an array of Class objects that represent the
formal parameter types, in declaration order, of the
constructor represented by this Constructor object.
Returns an array of length 0 if the underlying
constructor takes no parameters.
*/
public synthetic.Class[] getParameterTypes()
{
if(realep!=null && parametertypes==null)
{
parametertypes=new synthetic.Class[realP.length];
for(int i=0;i<realP.length;++i)
parametertypes[i]=synthetic.Class.forClass(realP[i]);
realP=null;
}
return parametertypes;
}
public String[] getParameterNames()
{
return parameternames;
}
public void addParameter(synthetic.Class type,String name)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
synthetic.Class[] types=new synthetic.Class[parametertypes.length+1];
System.arraycopy(parametertypes,0,types,0,parametertypes.length);
types[parametertypes.length]=type;
parametertypes=types;
String[] names=new String[parameternames.length+1];
System.arraycopy(parameternames,0,names,0,parameternames.length);
names[parameternames.length]=name;
parameternames=names;
}
/**
Returns a hashcode for this Constructor. The
hashcode is the same as the hashcode for the
underlying constructor's declaring class name,
xor'ed (for Methods) with the method name.
(Implemented in the subclasses rather than here.)
*/
abstract public int hashCode();
/**
Assert the Class object representing the class that
declares the constructor represented by this
Constructor object.
*/
public void setDeclaringClass(synthetic.Class declaringClass)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.declaringclass=declaringClass;
}
/**
***** Should only be accepted before a "real" entrypoint is bound.
* Creation date: (12-25-99 1:28:28 PM)
* @return int
* @param modifiers int
*/
public void setModifiers(int modifiers)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.modifiers=modifiers;
}
/**
Return a string describing this Constructor. The
string is formatted as the constructor access
modifiers, if any, followed by the fully-qualified
name of the declaring class, followed by a
parenthesized, comma-separated list of the
constructor's formal parameter types. For example:
<code>
public java.util.Hashtable(int,float)
</code>
<p>
The only possible modifiers for constructors are
the access modifiers public, protected or
private. Only one of these may appear, or none
if the constructor has default (package) access.
<p>
Methods will also display their checked exceptions.
*/
public String toString()
{
StringBuffer sb=
new StringBuffer(java.lang.reflect.Modifier.toString(getModifiers()));
if(this instanceof synthetic.reflection.Method)
sb.append(' ').append(getReturnType())
.append(getDeclaringClass().getName())
.append('.').append(getName());
else
sb.append(getDeclaringClass().getName());
sb.append('(');
synthetic.Class[] p=getParameterTypes();
if(p!=null && p.length>0)
{
sb.append(p[0].getName());
for(int i=1;i<p.length;++i)
sb.append(',').append(p[i].getName());
}
sb.append(')');
if(this instanceof synthetic.reflection.Method)
{
p=getExceptionTypes();
if(p!=null && p.length>0)
{
sb.append(" throws ").append(p[0].getName());
for(int i=1;i<p.length;++i)
sb.append(',').append(p[i].getName());
}
}
return sb.toString();
}
/** Extension: For synthesis, we need a place to hang a
method body.
*/
public void setBody(String language,StringBuffer body)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.language=language;
this.body=body;
}
/** Extension: For synthesis, we need a place to hang a
method body. Note that this returns a mutable object,
for editing etc. Slightly sloppy first cut.
*/
public StringBuffer getBody()
{
if(body==null)
body=new StringBuffer();
return body;
}
/** Extension: For synthesis, we need a place to hang a
method body.
*/
public String getLanguage()
{
return language;
}
/** Generate Java code
*/
public String toSource(String basetab)
{
StringBuffer sb=new StringBuffer();
sb.append(basetab)
.append(java.lang.reflect.Modifier.toString(getModifiers()));
if(this instanceof synthetic.reflection.Method)
{
if (returntype!=null)
sb.append(" ").append(getReturnType().getJavaName());
else
sb.append(" void");
}
sb.append(" ").append(getName())
.append("(");
synthetic.Class[] types=getParameterTypes();
if(types!=null & types.length>0)
{
sb.append(types[0].getJavaName());
if(parameternames!=null)
sb.append(' ').append(parameternames[0]);
for(int i=1;i<types.length;++i)
{
sb.append(',').append(types[i].getJavaName());
if(parameternames!=null)
sb.append(' ').append(parameternames[i]);
}
}
sb.append(')');
types=getExceptionTypes();
if(types!=null & types.length>0)
{
sb.append(" throws ").append(types[0].getJavaName());
for(int i=1;i<types.length;++i)
{
sb.append(',').append(types[i].getJavaName());
}
}
if(body==null)
sb.append("; // No method body available\n");
else
{
sb.append("\n"+basetab+"{\n");
if(language==null || "java".equals(language))
{
sb.append(basetab+"// ***** Should prettyprint this code...\n");
sb.append(basetab+body+"\n");
}
else
{
sb.append(basetab+"// ***** Generate BSF invocation!?\n");
}
sb.append(basetab+"}\n");
}
return sb.toString();
}
}
1.1 xml-xalan/java/src/synthetic/reflection/Field.java
Index: Field.java
===================================================================
// Synthetic Class descriptors ("reverse reflection")
// Copyright �2000 International Business Machines Corportation
// All rights reserved.
package synthetic.reflection;
import synthetic.Class;
import synthetic.SynthesisException;
/**
A Field provides information about, and dynamic access
to, a single field of a class or an interface. The reflected
field may be a class (static) field or an instance field.
<p>
A Field permits widening conversions to occur during a
get or set access operation, but throws an
IllegalArgumentException if a narrowing conversion
would occur.
@see Member
@see Class
@see getFields
@see getField
@see getDeclaredFields
@see getDeclaredField
**/
public class Field
extends Object
implements Member
{
public String name, initializer=null;
int modifiers;
java.lang.reflect.Field realfield=null;
Class declaringClass,type;
/** Proxy constructor */
public Field(java.lang.reflect.Field realfield, synthetic.Class declaringClass)
{
this(realfield.getName(),declaringClass);
this.realfield=realfield;
this.type=synthetic.Class.forClass(realfield.getType());
}
/** Synthesis constructor */
public Field(String name,synthetic.Class declaringClass)
{
this.name=name;
this.declaringClass=declaringClass;
}
/**
Compares this Field against the specified object.
Returns true if the objects are the same. Two
Fields are the same if they were declared by the
same class and have the same name and type.
*/
public boolean equals(Object obj)
{
if(realfield!=null)
return realfield.equals(obj);
else if(obj instanceof Field)
{
Field objf=(Field)obj;
return(declaringClass.equals(objf.declaringClass) &&
name.equals(objf.name) && type.equals(objf.type) );
}
else return false;
}
/**
Returns the value of the field represented by this
Field, on the specified object. The value is
automatically wrapped in an object if it has a
primitive type.
<p>
The underlying field's value is obtained as follows:
<p>
If the underlying field is a static field, the object
argument is ignored; it may be null.
<p>
Otherwise, the underlying field is an instance
field. If the specified object argument is null, the
method throws a NullPointerException. If the
specified object is not an instance of the class or
interface declaring the underlying field, the
method throws an IllegalArgumentException.
<p>
If this Field object enforces Java language access
control, and the underlying field is inaccessible,
the method throws an IllegalAccessException.
<p>
Otherwise, the value is retrieved from the
underlying instance or static field. If the field has a
primitive type, the value is wrapped in an object
before being returned, otherwise it is returned as
is.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field.
@throws NullPointerException
if the specified object is null.
*/
public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.get(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a boolean on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getBoolean(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a byte on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getByte(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a char on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public char getChar(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getChar(obj);
throw new java.lang.IllegalStateException();
}
/**
Returns the Class object representing the class or
interface that declares the field represented by this
Field object.
*/
public synthetic.Class getDeclaringClass()
{
if(realfield!=null)
return synthetic.Class.forClass(realfield.getDeclaringClass());
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a double on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public double getDouble(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getDouble(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a float on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public float getFloat(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getFloat(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a int on specified object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getInt(obj);
throw new java.lang.IllegalStateException();
}
/**
Get the value of a field as a long on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getLong(obj);
throw new java.lang.IllegalStateException();
}
/**
Returns the Java language modifiers for the field
represented by this Field object, as an integer. The
Modifier class should be used to decode the
modifiers.
@see
Modifier
*/
public int getModifiers()
{
if(realfield!=null)
modifiers=realfield.getModifiers();
return modifiers;
}
public String getInitializer()
{
return initializer;
}
public void setInitializer(String i)
throws SynthesisException
{
if(realfield!=null)
throw new SynthesisException(SynthesisException.REIFIED);
initializer=i;
}
/**
* Insert the method's description here.
* Creation date: (12-25-99 2:02:26 PM)
* @return java.lang.String
*/
public java.lang.String getName() {
return name;
}
/**
Get the value of a field as a short on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the field value cannot be converted to the
return type by a widening conversion.
@see
get
*/
public short getShort(Object obj) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
return realfield.getShort(obj);
throw new java.lang.IllegalStateException();
}
/**
Returns a Class object that identifies the declared
type for the field represented by this Field object.
*/
public Class getType()
{
if(realfield!=null)
type=Class.forClass(realfield.getType());
return type;
}
public void setType(synthetic.Class type)
throws SynthesisException
{
if(realfield!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.type=type;
}
/**
Returns a hashcode for this Field. This is
computed as the exclusive-or of the hashcodes for
the underlying field's declaring class name and its
name.
*/
public int hashCode()
{
if(realfield!=null)
return realfield.hashCode();
else
return declaringClass.getName().hashCode() ^
name.hashCode();
}
/**
Sets the field represented by this Field object on
the specified object argument to the specified new
value. The new value is automatically unwrapped
if the underlying field has a primitive type.
The operation proceeds as follows:
If the underlying field is static, the object
argument is ignored; it may be null.
Otherwise the underlying field is an instance field.
If the specified object argument is null, the
method throws a NullPointerException. If the
specified object argument is not an instance of the
class or interface declaring the underlying field,
the method throws an IllegalArgumentException.
If this Field object enforces Java language access
control, and the underlying field is inaccessible,
the method throws an IllegalAccessException.
If the underlying field is final, the method throws
an IllegalAccessException.
If the underlying field is of a primitive type, an
unwrapping conversion is attempted to convert the
new value to a value of a primitive type. If this
attempt fails, the method throws an
IllegalArgumentException.
If, after possible unwrapping, the new value
cannot be converted to the type of the underlying
field by an identity or widening conversion, the
method throws an IllegalArgumentException.
The field is set to the possibly unwrapped and
widened new value.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@throws NullPointerException
if the specified object is null.
*/
public void set(Object obj,Object value) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.set(obj,value);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as a boolean on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setBoolean(Object obj,boolean z) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setBoolean(obj,z);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as a byte on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setByte(obj,b);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as a char on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setChar(obj,c);
throw new java.lang.IllegalStateException();
}
/**
Returns the Class object representing the class that
declares the constructor represented by this
Constructor object.
*/
public void setDeclaringClass(synthetic.Class declaringClass)
{
this.declaringClass=declaringClass;
}
/**
Set the value of a field as a double on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setDouble(obj,d);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as a float on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setFloat(obj,f);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as an int on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setInt(obj,i);
throw new java.lang.IllegalStateException();
}
/**
Set the value of a field as a long on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setLong(obj,l);
throw new java.lang.IllegalStateException();
}
/**
* Insert the method's description here.
* Creation date: (12-25-99 1:28:28 PM)
* @return int
* @param modifiers int
*/
public void setModifiers(int modifiers)
throws SynthesisException
{
if(realfield!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.modifiers=modifiers;
}
/**
Set the value of a field as a short on specified
object.
@throws IllegalAccessException
if the underlying constructor is inaccessible.
@throws IllegalArgumentException
if the specified object is not an instance of
the class or interface declaring the
underlying field, or if an unwrapping
conversion fails.
@see
set
*/
public void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException
{
if(realfield!=null)
realfield.setShort(obj,s);
throw new java.lang.IllegalStateException();
}
/**
Return a string describing this Field. The format is
the access modifiers for the field, if any, followed
by the field type, followed by a space, followed by
the fully-qualified name of the class declaring the
field, followed by a period, followed by the name
of the field. For example:
<code>
public static final int java.lang.Thread.MIN_PRIORITY
private int java.io.FileDescriptor.fd
</code>
The modifiers are placed in canonical order as
specified by "The Java Language Specification".
This is public, protected or private first,
and then other modifiers in the following order:
static, final, transient, volatile.
*/
public String toString()
{
if(realfield!=null)
return realfield.toString();
throw new java.lang.IllegalStateException();
}
/** Output the Field as Java sourcecode
*/
public String toSource()
{
StringBuffer sb=
new StringBuffer(java.lang.reflect.Modifier.toString(getModifiers()) )
.append(' ')
.append(getType().getJavaName())
.append(' ')
.append(getName());
String i=getInitializer();
if(i!=null && i.length()>0)
sb.append('=').append(i);
sb.append(';');
return sb.toString();
}
}
1.1 xml-xalan/java/src/synthetic/reflection/Member.java
Index: Member.java
===================================================================
// Synthetic Class descriptors ("reverse reflection")
// Copyright �2000 International Business Machines Corportation
// All rights reserved.
package synthetic.reflection;
import synthetic.SynthesisException;
/**
Member is an interface that reflects identifying
information about a single member (a field or a method)
or a constructor.
<p>
Note that this is <strong>not</strong> currently derived from
java.lang.reflect.Member, due to questions about how to handle
declarignClass.
@see Field
@see Method
@see Constructor
@see synthetic.Class
@see java.lang.reflect.Member
*/
public interface Member
{
/**
Returns the Class object representing the class or
interface that declares the member or constructor
represented by this Member.
*/
public abstract synthetic.Class getDeclaringClass();
/**
Returns the Java language modifiers for the
member or constructor represented by this
Member, as an integer. The Modifier class should
be used to decode the modifiers in the integer.
@see Modifier
**/
public abstract int getModifiers();
/**
Returns the Class object representing the class or
interface that declares the member or constructor
represented by this Member.
*/
public abstract void setDeclaringClass(synthetic.Class declaringClass)
throws SynthesisException;
/**
Returns the Java language modifiers for the
member or constructor represented by this
Member, as an integer. The Modifier class should
be used to decode the modifiers in the integer.
@see Modifier
**/
public abstract void setModifiers(int modifiers)
throws SynthesisException;
}
1.1 xml-xalan/java/src/synthetic/reflection/Method.java
Index: Method.java
===================================================================
// Synthetic Class descriptors ("reverse reflection")
// Copyright �2000 International Business Machines Corportation
// All rights reserved.
package synthetic.reflection;
import java.lang.reflect.InvocationTargetException;
import synthetic.SynthesisException;
/**
A Method provides information about, and access to, a
single method on a class or interface. The reflected
method may be a class method or an instance method
(including an abstract method).
<p>
A Method permits widening conversions to occur when
matching the actual parameters to invokewith the
underlying method's formal parameters, but it throws an
IllegalArgumentException if a narrowing conversion
would occur.
<p>
***** Need to add method body, a la Matt's codebuffer.
That may or may not imply retaining the final return value
separately and passing in a how-to-use-it mechanism...?
@see Member
@see Class
@see getMethods
@see getMethod
@see getDeclaredMethods
@see getDeclaredMethod
*/
public class Method
extends EntryPoint
implements Member
{
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Method(String name,synthetic.Class declaringclass)
{
super(declaringclass);
this.name=name;
}
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Method(java.lang.reflect.Method ctor,synthetic.Class declaringclass)
{
super(ctor,declaringclass);
}
/**
* Insert the method's description here.
* <p>
* Creation date: (12-27-99 2:31:39 PM)
* @param realConstructor java.lang.reflect.Constructor
*/
public Method(java.lang.reflect.Method realmethod)
{
super(realmethod);
}
/**
Returns a hashcode for this Method. The hashcode
is computed as the exclusive-or of the hashcodes
for the underlying method's declaring class name
and the method's name.
*/
/**
Returns a hashcode for this Constructor. The
hashcode for a Method is the hashcode for the
underlying constructor's declaring class name,
XORed with the name of this method.
*/
public int hashCode()
{
return getDeclaringClass().getName().hashCode()
^
getName().hashCode();
}
/**
Invokes the underlying method represented by this
Method object, on the specified object with the
specified parameters. Individual parameters are
automatically unwrapped to match primitive
formal parameters, and both primitive and
reference parameters are subject to widening
conversions as necessary. The value returned by
the underlying method is automatically wrapped
in an object if it has a primitive type.
Method invocation proceeds with the following
steps, in order:
If the underlying method is static, then the
specified object argument is ignored. It may be
null.
Otherwise, the method is an instance method. If
the specified object argument is null, the
invocation throws a NullPointerException.
Otherwise, if the specified object argument is not
an instance of the class or interface declaring the
underlying method, the invocation throws an
IllegalArgumentException.
If this Method object enforces Java language access
control and the underlying method is inaccessible,
the invocation throws an IllegalAccessException.
If the number of actual parameters supplied via
args is different from the number of formal
parameters required by the underlying method, the
invocation throws an IllegalArgumentException.
For each actual parameter in the supplied args
array:
If the corresponding formal parameter has a
primitive type, an unwrapping conversion is
attempted to convert the object value to a value of
a primitive type. If this attempt fails, the
invocation throws an IllegalArgumentException.
If, after possible unwrapping, the parameter value
cannot be converted to the corresponding formal
parameter type by an identity or widening
conversion, the invocation throws an
IllegalArgumentException.
If the underlying method is an instance method, it
is invoked using dynamic method lookup as
documented in The Java Language Specification,
section 15.11.4.4; in particular, overriding based
on the runtime type of the target object will occur.
If the underlying method is static, it is invoked as
exactly the method on the declaring class.
Control transfers to the underlying method. If the
method completes abruptly by throwing an
exception, the exception is placed in an
InvocationTargetException and thrown in turn to
the caller of invoke.
If the method completes normally, the value it
returns is returned to the caller of invoke; if the
value has a primitive type, it is first appropriately
wrapped in an object. If the underlying method
return type is void, the invocation returns null.
Throws: IllegalAccessException
if the underlying method is inaccessible.
Throws: IllegalArgumentException
if the number of actual and formal
parameters differ, or if an unwrapping
conversion fails.
Throws: InvocationTargetException
if the underlying method throws an
exception.
Throws: NullPointerException
if the specified object is null.
*/
public Object invoke(Object obj, Object args[])
throws IllegalAccessException, IllegalArgumentException,
java.lang.reflect.InvocationTargetException
{
if(realep!=null)
return ((java.lang.reflect.Method)realep).invoke(obj,args);
else
throw new IllegalAccessException("Un-reified synthetic.Class doesn't yet support invocation");
}
public void setReturnType(synthetic.Class returntype)
throws SynthesisException
{
if(realep!=null)
throw new SynthesisException(SynthesisException.REIFIED);
this.returntype=returntype;
}
}