com.sun.codemodel
Class JPackage

java.lang.Object
  extended by com.sun.codemodel.JPackage
All Implemented Interfaces:
JClassContainer, JDeclaration

public final class JPackage
extends java.lang.Object
implements JDeclaration, JClassContainer

A Java package.


Method Summary
 JDefinedClass _class(int mods, java.lang.String name)
          Add a class to this package.
 JDefinedClass _class(int mods, java.lang.String name, boolean isInterface)
          Create a new class or a new interface.
 JDefinedClass _class(java.lang.String name)
          Adds a public class to this package.
 JDefinedClass _getClass(java.lang.String name)
          Gets a reference to the already created JDefinedClass.
 JDefinedClass _interface(int mods, java.lang.String name)
          Add an interface to this package.
 JDefinedClass _interface(java.lang.String name)
          Adds a public interface to this package.
 JResourceFile addResourceFile(JResourceFile rsrc)
          Adds a new resource file to this package.
 java.util.Iterator classes()
          Returns an iterator that walks the top-level classes defined in this package.
 void declare(JFormatter f)
           
 void generate(JFormatter f)
           
 boolean hasResourceFile(java.lang.String name)
          Checks if a resource of the given name exists.
 boolean isDefined(java.lang.String classLocalName)
          Checks if a given name is already defined as a class/interface
 boolean isUnnamed()
          Checks if this package is the root, unnamed package.
 java.lang.String name()
          Get the name of this package
 JCodeModel owner()
          Return the code model root object being used to create this package.
 JPackage parent()
          Gets the parent package, or null if this class is the root package.
 JClassContainer parentContainer()
          Parent JClassContainer.
 java.util.Iterator propertyFiles()
          Iterates all resource files in this package.
 JClass ref(java.lang.String name)
          Reference a class within this package.
 void remove(JClass c)
          Removes a class from this package.
 JPackage subPackage(java.lang.String pkg)
          Gets a reference to a sub package of this package.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parentContainer

public JClassContainer parentContainer()
Description copied from interface: JClassContainer
Parent JClassContainer. If this is a package, this method returns a parent package, or null if this package is the root package. If this is an outer-most class, this method returns a package to which it belongs. If this is an inner class, this method returns the outer class.

Specified by:
parentContainer in interface JClassContainer

parent

public JPackage parent()
Gets the parent package, or null if this class is the root package.


_class

public JDefinedClass _class(int mods,
                            java.lang.String name)
                     throws JClassAlreadyExistsException
Add a class to this package.

Specified by:
_class in interface JClassContainer
Parameters:
mods - Modifiers for this class declaration
name - Name of class to be added to this package
Returns:
Newly generated class
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_class

public JDefinedClass _class(int mods,
                            java.lang.String name,
                            boolean isInterface)
                     throws JClassAlreadyExistsException
Description copied from interface: JClassContainer
Create a new class or a new interface.

Specified by:
_class in interface JClassContainer
Throws:
JClassAlreadyExistsException

_class

public JDefinedClass _class(java.lang.String name)
                     throws JClassAlreadyExistsException
Adds a public class to this package.

Specified by:
_class in interface JClassContainer
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_getClass

public JDefinedClass _getClass(java.lang.String name)
Gets a reference to the already created JDefinedClass.

Returns:
null If the class is not yet created.

_interface

public JDefinedClass _interface(int mods,
                                java.lang.String name)
                         throws JClassAlreadyExistsException
Add an interface to this package.

Specified by:
_interface in interface JClassContainer
Parameters:
mods - Modifiers for this interface declaration
name - Name of interface to be added to this package
Returns:
Newly generated interface
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

_interface

public JDefinedClass _interface(java.lang.String name)
                         throws JClassAlreadyExistsException
Adds a public interface to this package.

Specified by:
_interface in interface JClassContainer
Throws:
JClassAlreadyExistsException - When the specified class/interface was already created.

addResourceFile

public JResourceFile addResourceFile(JResourceFile rsrc)
Adds a new resource file to this package.


hasResourceFile

public boolean hasResourceFile(java.lang.String name)
Checks if a resource of the given name exists.


propertyFiles

public java.util.Iterator propertyFiles()
Iterates all resource files in this package.


remove

public void remove(JClass c)
Removes a class from this package.


ref

public JClass ref(java.lang.String name)
Reference a class within this package.


subPackage

public JPackage subPackage(java.lang.String pkg)
Gets a reference to a sub package of this package.


classes

public java.util.Iterator classes()
Returns an iterator that walks the top-level classes defined in this package.

Specified by:
classes in interface JClassContainer

isDefined

public boolean isDefined(java.lang.String classLocalName)
Checks if a given name is already defined as a class/interface


isUnnamed

public final boolean isUnnamed()
Checks if this package is the root, unnamed package.


name

public java.lang.String name()
Get the name of this package

Returns:
The name of this package, or the empty string if this is the null package. For example, this method returns strings like "java.lang"

owner

public final JCodeModel owner()
Return the code model root object being used to create this package.

Specified by:
owner in interface JClassContainer

declare

public void declare(JFormatter f)
Specified by:
declare in interface JDeclaration

generate

public void generate(JFormatter f)