|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.xml.utils.synthetic.Class
**For internal use only** org.apache.xml.utils.synthetic.Class is a mutable equivalent of java.lang.Class. Instances represent classes and interfaces in a running Java application, or class descriptions under construction. In the former case, org.apache.xml.utils.synthetic.Class operates as a proxy for the "real" java.lang.Class object; in the latter, it consults data structures defined in the org.apache.xml.utils.synthetic.reflection.* package.
Unlike java.lang.Class, org.apache.xml.utils.synthetic.Class has a pair of factories (fromName and fromClass). It can also be switched from synthetic to proxy operation after construction, by setting the realClass property; this is intended to allow these definitions to be "compiled in place".
For convenient use, org.apache.xml.utils.synthetic.Class implements an extended version of the java.lang.Class API -- but is not a subclass thereof, since java.lang.Class is Final (presumably for security reasons).
DEVELOPMENT NOTE: Methods not yet implemented will throw IllegalStateException
I've added code to convert primitive names into their TYPEs, to accept foo[] as a synonym for [Lfoo, and to generate the right thing on output (getJava[Short]Name). Useful extension for code generation from Java-like source. We may want to factor these and toSource out, making org.apache.xml.utils.synthetic.Class addess only the JVM level and providing subclasses or access tools that handle language syntax (Java source, NetRexx source, etc.)
Method Summary | |
void |
addExtends(Class newclass)
Adds an "extends" description for the class or interface represented by this Class object |
void |
addImplements(Class newclass)
Adds an "implements" description for the class or interface represented by this Class object |
static Class |
declareClass(java.lang.String className)
Start to create a synthetic Class with the given fully-qualified name. |
Constructor |
declareConstructor()
Adds a Constructor description for the class or interface represented by this Class object |
Field |
declareField(java.lang.String name)
Adds a Field description for the class or interface represented by this Class object |
Class |
declareInnerClass(java.lang.String className)
Declare a class contained within this class. |
Class |
declareInterface(Class newifce)
State that this class implements a specified interface. |
Method |
declareMethod(java.lang.String name)
Adds a Method description for the class or interface represented by this Class object |
static Class |
forClass(java.lang.Class cls)
Returns the synthetic Class object associated with the "real" class specified, creating one if it didn't already exist. |
static Class |
forName(java.lang.String className)
Returns the synthetic Class object associated with the class with the given fully-qualified name. |
Class |
forNameInContext(java.lang.String classname)
Like forName, but if the classname doesn't have a package prefix we first attempt to look it up as one of our own inner clases. |
Class[] |
getClasses()
Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. |
java.lang.ClassLoader |
getClassLoader()
Determines the class loader for the class. |
Class |
getComponentType()
If this class represents an array type, returns the Class object representing the component type of the array; otherwise returns null. |
Constructor |
getConstructor(Class[] parameterTypes)
Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. |
Constructor[] |
getConstructors()
Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. |
Class[] |
getDeclaredClasses()
This method is not implemented in VAJAVA 3.0 |
Constructor |
getDeclaredConstructor(Class[] parameterTypes)
Returns a Constructor object that reflects the specified declared constructor of the class or interface represented by this Class object. |
Constructor[] |
getDeclaredConstructors()
Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. |
Field |
getDeclaredField(java.lang.String name)
Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. |
Field[] |
getDeclaredFields()
Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. |
Method |
getDeclaredMethod(java.lang.String name,
Class[] parameterTypes)
Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. |
Method[] |
getDeclaredMethods()
Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. |
Class |
getDeclaringClass()
This method is not implemented in VAJava 3.0 |
Field |
getField(java.lang.String name)
Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. |
Field[] |
getFields()
Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. |
Class[] |
getInnerClasses()
Fetch a list of classes contained within this class. |
Class[] |
getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object. |
java.lang.String |
getJavaName()
Like getName, but back-convert array notation escapes. |
java.lang.String |
getJavaShortName()
Like getShortName, but back-convert array notation escapes. |
Method |
getMethod(java.lang.String name,
Class[] parameterTypes)
Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. |
Method[] |
getMethods()
Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. |
int |
getModifiers()
Returns the Java language modifiers for this class or interface, encoded in an integer. |
java.lang.String |
getName()
Retrieve the fully-qualified classname. |
java.lang.String |
getPackageName()
Extract the package name for this class. |
java.lang.Class |
getRealClass()
If this synthetic class is a wrapper for a "real" java.lang.Class -- either because it was instantiated as such or because it has been compiled -- this method will return that class. |
java.net.URL |
getResource(java.lang.String name)
Finds a resource with the specified name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Finds a resource with a given name. |
java.lang.String |
getShortName()
Extract just the local name of this class, minus the package prefix. |
java.lang.Object[] |
getSigners()
Get the signers of this class. |
Class |
getSuperclass()
If this object represents any class other than the class Object, then the object that represents the superclass of that class is returned. |
boolean |
isArray()
If this Class object represents an array type, returns true, otherwise returns false. |
boolean |
isAssignableFrom(Class cls)
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. |
boolean |
isAssignableFrom(java.lang.Class cls)
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. |
boolean |
isInstance(java.lang.Object obj)
This method is the dynamic equivalent of the Java language instanceof operator. |
boolean |
isInterface()
Determines if the specified Class object represents an interface type. |
void |
isInterface(boolean isInterface)
Assert that the specified Class object represents an interface type. |
boolean |
isPrimitive()
Determines if the specified Class object represents a primitive Java type. |
static int |
modifierFromString(java.lang.String t)
Method modifierFromString |
static int |
modifiersFromString(java.lang.String s)
Method modifiersFromString |
java.lang.Object |
newInstance()
Creates a new instance of a class. |
static Class |
reallyDeclareClass(java.lang.String className)
Start to create a synthetic Class with the given fully-qualified name. |
void |
setModifiers(int modifiers)
Set the Java language modifiers for this class or interface, encoded in an integer. |
void |
setRealClass(java.lang.Class realclass)
This call is intended to allow an existing org.apache.xml.utils.synthetic.Class to be switched from purely descriptive mode to proxy mode ("reified"). |
void |
setSuperClass(Class superclass)
Set the superclass for this synthetic class. |
void |
setSuperClass(java.lang.Class superclass)
Set the superclass for this synthetic class. |
void |
toSource(java.io.OutputStream out,
int depth)
Convenience for writing to, eg, System.out |
void |
toSource(java.io.PrintWriter out,
int depth)
Converts the object to a Java code stream. |
java.lang.String |
toString()
Converts the object to a string. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Method Detail |
public static Class forClass(java.lang.Class cls)
For example, the following code fragment returns
the runtime Class descriptor for the class named
mypackage.MyClass.
Class t =
Class.forName(java.lang.Class.forName("mypackage.MyClass"))
Note that if the user has manually created a org.apache.xml.utils.synthetic.Class with the same name before this call is issued, that object will be found instead. See also the declareClass call.
We need a better way to declare/define array classes, given a class object (synthetic or not).
cls
- the desired Java class.public Class forNameInContext(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- the full or partial class name.public static Class forName(java.lang.String className) throws java.lang.ClassNotFoundException
For example, the following code fragment returns
the runtime Class descriptor for the class named
mypackage.MyClass -- either as a synthetic or as
a standard Java class.
Class t =
Class.forName("mypackage.MyClass")
I've added support for arrays -- assuming any name that ends with ']' is an array. It probably needs to be made smarter, possibly via a subclass of org.apache.xml.utils.synthetic.Class.
className
- the fully qualified name of the desired class.public static Class declareClass(java.lang.String className) throws SynthesisException
className
- the fully qualified name of the desired class.public static Class reallyDeclareClass(java.lang.String className)
className
- the fully qualified name of the desired class.public Class[] getClasses()
NOTE: In a significant number of existing Java environments, this method is not implemented by the official Class object and always returns an empty array. So if you don't get any useful information from a proxied java.lang.Class, don't be surprised. I'm not sure if someone decided it was a potential security issue, or if Sun was lazy and everyone else followed suit.
ALSO NOTE: The above spec, as taken from java.lang.Class, doesn't provide any good way to distinguish the immediate superclass from all other superclasses. That makes it only marginally useful, which is no doubt one of the reasons folks have declined to implement it.
public java.lang.ClassLoader getClassLoader()
public Class getComponentType()
NOTE: Since org.apache.xml.utils.synthetic.Class doesn't yet attempt to model array types, this will currently return false unless we are proxying such a type.
public Constructor getConstructor(Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.SecurityException, SynthesisException
The constructor to reflect is located by searching all the constructors of the class represented by this Class object for a public constructor with the exactly the same formal parameter types.
parameterTypes
- array of Class
objects that identify the constructor's formal
parameter types, in declared order.public Constructor[] getConstructors() throws java.lang.SecurityException
public Class[] getDeclaredClasses() throws java.lang.SecurityException
Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. This includes public, protected, default (package) access, and private classes and interfaces declared by the class, but excludes inherited classes and interfaces. Returns an array of length 0 if the class declares no classes or interfaces as members, or if this Class object represents a primitive type.
public void addExtends(Class newclass) throws SynthesisException
newclass
- The class that this class extends.public Constructor getDeclaredConstructor(Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.SecurityException
parameterTypes
- array of Class
objects that identify the constructor's formal
parameter types, in declared order.public Constructor declareConstructor() throws SynthesisException
public Class declareInterface(Class newifce) throws SynthesisException
newifce
- org.apache.xml.utils.synthetic.Class representing the interface we want to add.public Constructor[] getDeclaredConstructors() throws java.lang.SecurityException
See The Java Language Specification, section 8.2.
public Field getDeclaredField(java.lang.String name) throws java.lang.NoSuchFieldException, java.lang.SecurityException
name
- String that specifies the simple name of the desired
field.public Field declareField(java.lang.String name) throws SynthesisException
name
- The name of the field.public Field[] getDeclaredFields() throws java.lang.SecurityException
public Method getDeclaredMethod(java.lang.String name, Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.SecurityException
name
- String that specifies the simple
name of the desired method.parameterTypes
- array of Class
objects that identify the method's formal parameter
types, in declared order.public Method declareMethod(java.lang.String name) throws SynthesisException
name
- Name of method.public Method[] getDeclaredMethods() throws java.lang.SecurityException
See The Java Language Specification, section 8.2.
public Class getDeclaringClass()
If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class of which it is a member (its declaring class). Returns null if this class or interface is not a member of any other class.
public Class declareInnerClass(java.lang.String className) throws SynthesisException
***** This requires lookup methods that operate in the context of a specific class, and per-class registries!
className
- Local name of inner class to create. This should _not_ be a
qualified name, unlike the normal forName() call. Its
hierarchy is established by the class within which it is
created.public Class[] getInnerClasses()
public Field getField(java.lang.String name) throws java.lang.NoSuchFieldException, java.lang.SecurityException
The field to be reflected is located by searching all the member fields of the class or interface represented by this Class object for a public field with the specified name.
See The Java Language Specification, sections 8.2 and 8.3.
name
- public Field[] getFields() throws java.lang.SecurityException
Specifically, if this Class object represents a class, returns the public fields of this class and of all its superclasses. If this Class object represents an interface, returns the fields of this interface and of all its superinterfaces. If this Class object represents an array type or a primitive type, returns an array of length 0.
The implicit length field for array types is not reflected by this method. User code should use the methods of class Array to manipulate arrays.
See The Java Language Specification, sections 8.2 and 8.3.
public Class[] getInterfaces()
If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the declaration of the class represented by this object.
If this object represents an interface, the array contains objects representing all interfaces extended by the interface. The order of the interface objects in the array corresponds to the order of the interface names in the extends clause of the declaration of the interface represented by this object.
If the class or interface implements no interfaces, the method returns an array of length 0. an array of interfaces implemented by this class.
public void addImplements(Class newclass) throws SynthesisException
newclass
- public Method getMethod(java.lang.String name, Class[] parameterTypes) throws java.lang.NoSuchMethodException, java.lang.SecurityException
The method to reflect is located by searching all the member methods of the class or interface represented by this Class object for a public method with the specified name and exactly the same formal parameter types.
See The Java Language Specification, sections 8.2 and 8.4.
name
- parameterTypes
- public Method[] getMethods() throws java.lang.SecurityException
See The Java Language Specification, sections 8.2 and 8.4.
public int getModifiers()
public void setModifiers(int modifiers) throws SynthesisException
modifiers
- public java.lang.String getName()
public java.lang.String getJavaName()
public java.lang.String getShortName()
public java.lang.String getJavaShortName()
public java.lang.String getPackageName()
public java.lang.Class getRealClass()
public void setRealClass(java.lang.Class realclass) throws SynthesisException
This should have the side-effect of limiting further mutation of the org.apache.xml.utils.synthetic.Class to things which can not be obtained from the real Class object, to avoid "lying" to the user
NOTE: Not all information defined by the Java libraries is in fact available in all Java environments. We assume the calls will work; if they return null or empty lists, there's nothing we can do about it. Note that this may mean that a reified class tells us less about itself than the synthetic description used to generate it.
Creation date: (12-25-99 12:26:01 PM)
java.lang.class
- realclass nonsynthetic Class object to proxyrealclass
- public void setSuperClass(Class superclass) throws SynthesisException
superclass
- public void setSuperClass(java.lang.Class superclass) throws java.lang.ClassNotFoundException, SynthesisException
superclass
- public java.net.URL getResource(java.lang.String name)
The Class methods delegate to ClassLoader methods, after applying a naming convention: if the resource name starts with "/", it is used as is. Otherwise, the name of the package is prepended, after converting "." to "/".
name
- - the string representing the resource to
be found.
the URL object having the specified name, or
null if no resource with the specified name
is found.public java.io.InputStream getResourceAsStream(java.lang.String name)
The Class methods delegate to ClassLoader methods, after applying a naming convention: if the resource name starts with "/", it is used as is. Otherwise, the name of the package is prepended, after converting "." to "/".
name
- - the string representing the resource to
be found
the InputStream object having the
specified name, or null if no resource with
the specified name is found.public java.lang.Object[] getSigners()
public Class getSuperclass()
If this object is the one that represents the class Object or this object represents an interface, null is returned. the superclass of the class represented by this object.
public boolean isArray()
public boolean isAssignableFrom(Class cls)
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
cls
- public boolean isAssignableFrom(java.lang.Class cls)
Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
cls
- public boolean isInstance(java.lang.Object obj)
Specifically, if this Class object represents a declared class, returns true if the specified Object argument is an instance of the represented class (or of any of its subclasses); false otherwise. If this Class object represents an array class, returns true if the specified Object argument can be converted to an object of the array type by an identity conversion or by a widening reference conversion; false otherwise. If this Class object represents an interface, returns true if the class or any superclass of the specified Object argument implements this interface; false otherwise. If this Class object represents a primitive type, returns false.
obj
- The object to checkpublic boolean isInterface()
public void isInterface(boolean isInterface) throws SynthesisException
true
- if this object represents an interface;
false otherwise.isInterface
- public boolean isPrimitive()
There are nine predefined Class objects to represent the eight primitive Java types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double, and void.
These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.
public java.lang.Object newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException
public java.lang.String toString()
Should this say "synthetic" as well as "class" or "interface"? Or should that be gated on whether we're proxy to a realclass?
public void toSource(java.io.OutputStream out, int depth)
out
- depth
- public void toSource(java.io.PrintWriter out, int depth)
out
- depth
- public static int modifierFromString(java.lang.String t)
t
- (modifierFromString) @returnpublic static int modifiersFromString(java.lang.String s)
s
- (modifiersFromString) @return
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |