Java Doc for ClassPool.java in  » Byte-Code » Javassist » javassist » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » Javassist » javassist 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javassist.ClassPool

All known Subclasses:   javassist.scopedpool.ScopedClassPool,
ClassPool
public class ClassPool (Code)
A container of CtClass objects. A CtClass object must be obtained from this object. If get() is called on this object, it searches various sources represented by ClassPath to find a class file and then it creates a CtClass object representing that class file. The created object is returned to the caller.

Memory consumption memo:

ClassPool objects hold all the CtClasses that have been created so that the consistency among modified classes can be guaranteed. Thus if a large number of CtClasses are processed, the ClassPool will consume a huge amount of memory. To avoid this, a ClassPool object should be recreated, for example, every hundred classes processed. Note that getDefault() is a singleton factory. Otherwise, detach() in CtClass should be used to avoid huge memory consumption.

ClassPool hierarchy:

ClassPools can make a parent-child hierarchy as java.lang.ClassLoaders. If a ClassPool has a parent pool, get() first asks the parent pool to find a class file. Only if the parent could not find the class file, get() searches the ClassPaths of the child ClassPool. This search order is reversed if ClassPath.childFirstLookup is true.
See Also:   javassist.CtClass
See Also:   javassist.ClassPath



Field Summary
public  booleanchildFirstLookup
     Determines the search order.
protected  Hashtableclasses
    
public static  booleandoPruning
     Turning the automatic pruning on/off.

If this field is true, CtClass objects are automatically pruned by default when toBytecode() etc. are called.

protected  ClassPoolparent
    
public static  booleanreleaseUnmodifiedClassFile
     If true, unmodified and not-recently-used class files are periodically released for saving memory.
protected  ClassPoolTailsource
    

Constructor Summary
public  ClassPool()
     Creates a root class pool.
public  ClassPool(boolean useDefaultPath)
     Creates a root class pool.
public  ClassPool(ClassPool parent)
     Creates a class pool.
Parameters:
  parent - the parent of this class pool.

Method Summary
public  ClassPathappendClassPath(ClassPath cp)
     Appends a ClassPath object to the end of the search path.
public  ClassPathappendClassPath(String pathname)
     Appends a directory or a jar (or zip) file to the end of the search path.
Parameters:
  pathname - the path name of the directory or jar file.It must not end with a path separator ("/").
public  voidappendPathList(String pathlist)
     Appends directories and jar files for search.
public  ClassPathappendSystemPath()
     Appends the system search path to the end of the search path.
protected  voidcacheCtClass(String classname, CtClass c, boolean dynamic)
     Provides a hook so that subclasses can do their own caching of classes.
 voidcheckNotFrozen(String classname)
    
synchronized  voidclassNameChanged(String oldname, CtClass clazz)
    
public  voidclearImportedPackages()
     Clear all the package names recorded by importPackage().
protected  CtClasscreateCtClass(String classname, boolean useCache)
     Creates a CtClass object representing the specified class. It first examines whether or not the corresponding class file exists.
public  URLfind(String classname)
     Searches the class path to obtain the URL of the class file specified by classname.
public  CtClassget(String classname)
     Reads a class file from the source and returns a reference to the CtClass object representing that class file.
public  CtClass[]get(String[] classnames)
     Reads class files from the source and returns an array of CtClass objects representing those class files.
protected synchronized  CtClassget0(String classname, boolean useCache)
    
Parameters:
  useCache - false if the cached CtClass must be ignored.
Parameters:
  searchParent - false if the parent class pool is not searched.
public  CtClassgetAndRename(String orgName, String newName)
     Reads a class file and constructs a CtClass object with a new name. This method is useful if you want to generate a new class as a copy of another class (except the class name).
protected  CtClassgetCached(String classname)
     Provide a hook so that subclasses can do their own caching of classes.
public  ClassLoadergetClassLoader()
     Get the classloader for toClass(), getAnnotations() in CtClass, etc.
static  ClassLoadergetContextClassLoader()
     Obtains a class loader that seems appropriate to look up a class by name.
public static synchronized  ClassPoolgetDefault()
     Returns the default class pool.
public  IteratorgetImportedPackages()
     Returns all the package names recorded by importPackage().
public  CtMethodgetMethod(String classname, String methodname)
     Reads a class file and obtains a compile-time method.
public  voidimportPackage(String packageName)
     Record a package name so that the Javassist compiler searches the package to resolve a class name. Don't record the java.lang package, which has been implicitly recorded by default.

Note that get() in ClassPool does not search the recorded package.

public  ClassPathinsertClassPath(ClassPath cp)
     Insert a ClassPath object at the head of the search path.
public  ClassPathinsertClassPath(String pathname)
     Inserts a directory or a jar (or zip) file at the head of the search path.
Parameters:
  pathname - the path name of the directory or jar file.It must not end with a path separator ("/").
public  Object[]lookupCflow(String name)
     Undocumented method.
public  CtClassmakeClass(InputStream classfile)
     Creates a new class (or interface) from the given class file. If there already exists a class with the same name, the new class overwrites that previous class.

This method is used for creating a CtClass object directly from a class file.

public  CtClassmakeClass(String classname)
     Creates a new public class.
public synchronized  CtClassmakeClass(String classname, CtClass superclass)
     Creates a new public class.
public  CtClassmakeInterface(String name)
     Creates a new public interface.
public synchronized  CtClassmakeInterface(String name, CtClass superclass)
     Creates a new public interface.
synchronized  CtClassmakeNestedClass(String classname)
     Creates a new public nested class. This method is called by CtClassType.makeNestedClass().
Parameters:
  classname - a fully-qualified class name.
 InputStreamopenClassfile(String classname)
    
 voidrecordCflow(String name, String cname, String fname)
     Records the $cflow variable for the field specified by cname and fname.
public  voidrecordInvalidClassName(String name)
     Records a name that never exists.
protected  CtClassremoveCached(String classname)
     Provide a hook so that subclasses can do their own caching of classes.
public  voidremoveClassPath(ClassPath cp)
     Detatches the ClassPath object from the search path.
public  ClasstoClass(CtClass clazz)
     Converts the given class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more. To load the class, this method uses the context class loader of the current thread.
public  ClasstoClass(CtClass ct, ClassLoader loader)
     Converts the class to a java.lang.Class object.
public  ClasstoClass(CtClass ct, ClassLoader loader, ProtectionDomain domain)
     Converts the class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more.

The class file represented by the given CtClass is loaded by the given class loader to construct a java.lang.Class object.

public  StringtoString()
     Returns the class search path.
 voidwriteClassfile(String classname, OutputStream out)
    

Field Detail
childFirstLookup
public boolean childFirstLookup(Code)
Determines the search order.

If this field is true, get() first searches the class path associated to this ClassPool and then the class path associated with the parent ClassPool. Otherwise, the class path associated with the parent is searched first.

The default value is false.




classes
protected Hashtable classes(Code)



doPruning
public static boolean doPruning(Code)
Turning the automatic pruning on/off.

If this field is true, CtClass objects are automatically pruned by default when toBytecode() etc. are called. The automatic pruning can be turned on/off individually for each CtClass object.

The initial value is true.
See Also:   CtClass.prune
See Also:   CtClass.stopPruning(boolean)




parent
protected ClassPool parent(Code)



releaseUnmodifiedClassFile
public static boolean releaseUnmodifiedClassFile(Code)
If true, unmodified and not-recently-used class files are periodically released for saving memory.

The initial value is true.




source
protected ClassPoolTail source(Code)




Constructor Detail
ClassPool
public ClassPool()(Code)
Creates a root class pool. No parent class pool is specified.



ClassPool
public ClassPool(boolean useDefaultPath)(Code)
Creates a root class pool. If useDefaultPath is true, appendSystemPath() is called. Otherwise, this constructor is equivalent to the constructor taking no parameter.
Parameters:
  useDefaultPath - true if the system search path isappended.



ClassPool
public ClassPool(ClassPool parent)(Code)
Creates a class pool.
Parameters:
  parent - the parent of this class pool. If this is a rootclass pool, this parameter must be null.
See Also:   javassist.ClassPool.getDefault




Method Detail
appendClassPath
public ClassPath appendClassPath(ClassPath cp)(Code)
Appends a ClassPath object to the end of the search path. the appended class path.
See Also:   javassist.ClassPath
See Also:   javassist.URLClassPath
See Also:   javassist.ByteArrayClassPath



appendClassPath
public ClassPath appendClassPath(String pathname) throws NotFoundException(Code)
Appends a directory or a jar (or zip) file to the end of the search path.
Parameters:
  pathname - the path name of the directory or jar file.It must not end with a path separator ("/"). the appended class path.
throws:
  NotFoundException - if the jar file is not found.



appendPathList
public void appendPathList(String pathlist) throws NotFoundException(Code)
Appends directories and jar files for search.

The elements of the given path list must be separated by colons in Unix or semi-colons in Windows.
Parameters:
  pathlist - a (semi)colon-separated list ofthe path names of directories and jar files.The directory name must not end with a pathseparator ("/").
throws:
  NotFoundException - if a jar file is not found.




appendSystemPath
public ClassPath appendSystemPath()(Code)
Appends the system search path to the end of the search path. The system search path usually includes the platform library, extension libraries, and the search path specified by the -classpath option or the CLASSPATH environment variable. the appended class path.



cacheCtClass
protected void cacheCtClass(String classname, CtClass c, boolean dynamic)(Code)
Provides a hook so that subclasses can do their own caching of classes.
See Also:   ClassPool.getCached(String)
See Also:   ClassPool.removeCached(String,CtClass)



checkNotFrozen
void checkNotFrozen(String classname) throws RuntimeException(Code)



classNameChanged
synchronized void classNameChanged(String oldname, CtClass clazz)(Code)



clearImportedPackages
public void clearImportedPackages()(Code)
Clear all the package names recorded by importPackage(). The java.lang package is not removed.
See Also:   ClassPool.importPackage(String)
since:
   3.1



createCtClass
protected CtClass createCtClass(String classname, boolean useCache)(Code)
Creates a CtClass object representing the specified class. It first examines whether or not the corresponding class file exists. If yes, it creates a CtClass object. null if the class file could not be found.



find
public URL find(String classname)(Code)
Searches the class path to obtain the URL of the class file specified by classname. It is also used to determine whether the class file exists.
Parameters:
  classname - a fully-qualified class name. null if the class file could not be found.
See Also:   CtClass.getURL



get
public CtClass get(String classname) throws NotFoundException(Code)
Reads a class file from the source and returns a reference to the CtClass object representing that class file. If that class file has been already read, this method returns a reference to the CtClass created when that class file was read at the first time.

If classname ends with "[]", then this method returns a CtClass object for that array type.

To obtain an inner class, use "$" instead of "." for separating the enclosing class name and the inner class name.
Parameters:
  classname - a fully-qualified class name.




get
public CtClass[] get(String[] classnames) throws NotFoundException(Code)
Reads class files from the source and returns an array of CtClass objects representing those class files.

If an element of classnames ends with "[]", then this method returns a CtClass object for that array type.
Parameters:
  classnames - an array of fully-qualified class name.




get0
protected synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException(Code)

Parameters:
  useCache - false if the cached CtClass must be ignored.
Parameters:
  searchParent - false if the parent class pool is not searched. null if the class could not be found.



getAndRename
public CtClass getAndRename(String orgName, String newName) throws NotFoundException(Code)
Reads a class file and constructs a CtClass object with a new name. This method is useful if you want to generate a new class as a copy of another class (except the class name). For example,
     getAndRename("Point", "Pair")
     
returns a CtClass object representing Pair class. The definition of Pair is the same as that of Point class except the class name since Pair is defined by reading Point.class.
Parameters:
  orgName - the original (fully-qualified) class name
Parameters:
  newName - the new class name



getCached
protected CtClass getCached(String classname)(Code)
Provide a hook so that subclasses can do their own caching of classes.
See Also:   ClassPool.cacheCtClass(String,CtClass,boolean)
See Also:   ClassPool.removeCached(String)



getClassLoader
public ClassLoader getClassLoader()(Code)
Get the classloader for toClass(), getAnnotations() in CtClass, etc.

The default is the context class loader. the classloader for the pool
See Also:   ClassPool.toClass(CtClass)
See Also:   CtClass.getAnnotations




getContextClassLoader
static ClassLoader getContextClassLoader()(Code)
Obtains a class loader that seems appropriate to look up a class by name.



getDefault
public static synchronized ClassPool getDefault()(Code)
Returns the default class pool. The returned object is always identical since this method is a singleton factory.

The default class pool searches the system search path, which usually includes the platform library, extension libraries, and the search path specified by the -classpath option or the CLASSPATH environment variable.

When this method is called for the first time, the default class pool is created with the following code snippet:

    ClassPool cp = new ClassPool(); cp.appendSystemPath();

If the default class pool cannot find any class files, try ClassClassPath and LoaderClassPath.
See Also:   ClassClassPath
See Also:   LoaderClassPath




getImportedPackages
public Iterator getImportedPackages()(Code)
Returns all the package names recorded by importPackage().
See Also:   ClassPool.importPackage(String)
since:
   3.1



getMethod
public CtMethod getMethod(String classname, String methodname) throws NotFoundException(Code)
Reads a class file and obtains a compile-time method.
Parameters:
  classname - the class name
Parameters:
  methodname - the method name
See Also:   CtClass.getDeclaredMethod(String)



importPackage
public void importPackage(String packageName)(Code)
Record a package name so that the Javassist compiler searches the package to resolve a class name. Don't record the java.lang package, which has been implicitly recorded by default.

Note that get() in ClassPool does not search the recorded package. Only the compiler searches it.
Parameters:
  packageName - the package name.It must not include the last '.' (dot).For example, "java.util" is valid but "java.util." is wrong.
since:
   3.1




insertClassPath
public ClassPath insertClassPath(ClassPath cp)(Code)
Insert a ClassPath object at the head of the search path. the inserted class path.
See Also:   javassist.ClassPath
See Also:   javassist.URLClassPath
See Also:   javassist.ByteArrayClassPath



insertClassPath
public ClassPath insertClassPath(String pathname) throws NotFoundException(Code)
Inserts a directory or a jar (or zip) file at the head of the search path.
Parameters:
  pathname - the path name of the directory or jar file.It must not end with a path separator ("/"). the inserted class path.
throws:
  NotFoundException - if the jar file is not found.



lookupCflow
public Object[] lookupCflow(String name)(Code)
Undocumented method. Do not use; internal-use only.
Parameters:
  name - the name of $cflow variable



makeClass
public CtClass makeClass(InputStream classfile) throws IOException, RuntimeException(Code)
Creates a new class (or interface) from the given class file. If there already exists a class with the same name, the new class overwrites that previous class.

This method is used for creating a CtClass object directly from a class file. The qualified class name is obtained from the class file; you do not have to explicitly give the name.
Parameters:
  classfile - class file.
throws:
  RuntimeException - if there is a frozen class with thethe same name.
See Also:   javassist.ByteArrayClassPath




makeClass
public CtClass makeClass(String classname) throws RuntimeException(Code)
Creates a new public class. If there already exists a class with the same name, the new class overwrites that previous class.
Parameters:
  classname - a fully-qualified class name.
throws:
  RuntimeException - if the existing class is frozen.



makeClass
public synchronized CtClass makeClass(String classname, CtClass superclass) throws RuntimeException(Code)
Creates a new public class. If there already exists a class/interface with the same name, the new class overwrites that previous class.
Parameters:
  classname - a fully-qualified class name.
Parameters:
  superclass - the super class.
throws:
  RuntimeException - if the existing class is frozen.



makeInterface
public CtClass makeInterface(String name) throws RuntimeException(Code)
Creates a new public interface. If there already exists a class/interface with the same name, the new interface overwrites that previous one.
Parameters:
  name - a fully-qualified interface name.
throws:
  RuntimeException - if the existing interface is frozen.



makeInterface
public synchronized CtClass makeInterface(String name, CtClass superclass) throws RuntimeException(Code)
Creates a new public interface. If there already exists a class/interface with the same name, the new interface overwrites that previous one.
Parameters:
  name - a fully-qualified interface name.
Parameters:
  superclass - the super interface.
throws:
  RuntimeException - if the existing interface is frozen.



makeNestedClass
synchronized CtClass makeNestedClass(String classname)(Code)
Creates a new public nested class. This method is called by CtClassType.makeNestedClass().
Parameters:
  classname - a fully-qualified class name. the nested class.



openClassfile
InputStream openClassfile(String classname) throws NotFoundException(Code)



recordCflow
void recordCflow(String name, String cname, String fname)(Code)
Records the $cflow variable for the field specified by cname and fname.
Parameters:
  name - variable name
Parameters:
  cname - class name
Parameters:
  fname - field name



recordInvalidClassName
public void recordInvalidClassName(String name)(Code)
Records a name that never exists. For example, a package name can be recorded by this method. This would improve execution performance since get() does not search the class path at all if the given name is an invalid name recorded by this method. Note that searching the class path takes relatively long time.
Parameters:
  name - a class name (separeted by dot).



removeCached
protected CtClass removeCached(String classname)(Code)
Provide a hook so that subclasses can do their own caching of classes.
See Also:   ClassPool.getCached(String)
See Also:   ClassPool.cacheCtClass(String,CtClass,boolean)



removeClassPath
public void removeClassPath(ClassPath cp)(Code)
Detatches the ClassPath object from the search path. The detached ClassPath object cannot be added to the pathagain.



toClass
public Class toClass(CtClass clazz) throws CannotCompileException(Code)
Converts the given class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more. To load the class, this method uses the context class loader of the current thread. It is obtained by calling getClassLoader().

This behavior can be changed by subclassing the pool and changing the getClassLoader() method. If the program is running on some application server, the context class loader might be inappropriate to load the class.

This method is provided for convenience. If you need more complex functionality, you should write your own class loader.

Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified.
See Also:   ClassPool.toClass(CtClass,java.lang.ClassLoader,ProtectionDomain)
See Also:   ClassPool.getClassLoader()




toClass
public Class toClass(CtClass ct, ClassLoader loader) throws CannotCompileException(Code)
Converts the class to a java.lang.Class object. Do not override this method any more at a subclass because toClass(CtClass) never calls this method.

Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified. ClassPool.toClass(CtClass,ClassLoader,ProtectionDomain)ClassPool.toClass(CtClass,ClassLoader,ProtectionDomain)




toClass
public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException(Code)
Converts the class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more.

The class file represented by the given CtClass is loaded by the given class loader to construct a java.lang.Class object. Since a private method on the class loader is invoked through the reflection API, the caller must have permissions to do that.

An easy way to obtain ProtectionDomain object is to call getProtectionDomain() in java.lang.Class. It returns the domain that the class belongs to.

This method is provided for convenience. If you need more complex functionality, you should write your own class loader.
Parameters:
  loader - the class loader used to load this class.For example, the loader returned bygetClassLoader() can be usedfor this parameter.
Parameters:
  domain - the protection domain for the class.If it is null, the default domain createdby java.lang.ClassLoader is used.
See Also:   ClassPool.getClassLoader()
since:
   3.3




toString
public String toString()(Code)
Returns the class search path.



writeClassfile
void writeClassfile(String classname, OutputStream out) throws NotFoundException, IOException, CannotCompileException(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.