Interface WovenClass
WeavingHook for possible modification. It allows access to the most
recently transformed class file bytes and to any additional packages that
should be added to the bundle as dynamic imports.
Upon entering one of the terminal states, this object becomes effectively immutable.
- Author:
- $Id: b86db7713c738ae7147fe86f754302e2e324676b $
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe woven class failed to define.static final intThe woven class has been defined.static final intThe woven class has been transformed.static final intThe woven class is being transformed.static final intThe woven class failed to transform. -
Method Summary
Modifier and TypeMethodDescriptionReturns the bundle wiring whose class loader will define the woven class.byte[]getBytes()Returns the class file bytes to be used to define thenamedclass.Returns the fully qualified name of the class being woven.Class<?> Returns the class defined by this woven class.Returns the list of dynamic import package descriptions to add to thebundle wiringfor this woven class.Returns the protection domain to which the woven class will be assigned when it is defined.intgetState()Returns the current state of this woven class.booleanReturns whether weaving is complete in this woven class.voidsetBytes(byte[] newBytes) Set the class file bytes to be used to define thenamedclass.
-
Field Details
-
TRANSFORMING
static final int TRANSFORMINGThe woven class is being transformed.The woven class is in this state while
weaving hooksare being called. The woven class is mutable so theclass bytesmay bemodifiedanddynamic importsmay be added. If a weaving hook throws an exception the state transitions toTRANSFORMING_FAILED. Otherwise, after the last weaving hook has been successfully called, the state transitions toTRANSFORMED.- Since:
- 1.1
- See Also:
-
TRANSFORMED
static final int TRANSFORMEDThe woven class has been transformed.The woven class is in this state after
weaving hookshave been called and before the class is defined. The woven class cannot be further transformed. The woven class is in this state while defining the class. If a failure occurs while defining the class, the state transitions toDEFINE_FAILED. Otherwise, after the class has been defined, the state transitions toDEFINED.- Since:
- 1.1
- See Also:
-
DEFINED
static final int DEFINEDThe woven class has been defined.The woven class is in this state after the class is defined. The woven class cannot be further transformed. This is a terminal state. Upon entering this state, this object is effectively immutable, the
bundle wiringhas been updated with thedynamic import requirementsand the class has beendefined.- Since:
- 1.1
- See Also:
-
TRANSFORMING_FAILED
static final int TRANSFORMING_FAILEDThe woven class failed to transform.The woven class is in this state if a
weaving hookthrew an exception. The woven class cannot be further transformed or defined. This is a terminal state. Upon entering this state, this object is effectively immutable.- Since:
- 1.1
- See Also:
-
DEFINE_FAILED
static final int DEFINE_FAILEDThe woven class failed to define.The woven class is in this state when a failure occurs while defining the class. The woven class cannot be further transformed or defined. This is a terminal state. Upon entering this state, this object is effectively immutable.
- Since:
- 1.1
- See Also:
-
-
Method Details
-
getBytes
byte[] getBytes()Returns the class file bytes to be used to define thenamedclass.While in the
TRANSFORMINGstate, this method returns a reference to the class files byte array contained in this object. After leaving theTRANSFORMINGstate, this woven class can no longer be transformed and a copy of the class file byte array is returned.- Returns:
- The bytes to be used to define the
namedclass. - Throws:
SecurityException- If the caller does not haveAdminPermission[bundle,WEAVE]and the Java runtime environment supports permissions.
-
setBytes
void setBytes(byte[] newBytes) Set the class file bytes to be used to define thenamedclass. This method must not be called outside invocations of theweavemethod by the framework.While in the
TRANSFORMINGstate, this method replaces the reference to the array contained in this object with the specified array. After leaving theTRANSFORMINGstate, this woven class can no longer be transformed and this method will throw anIllegalStateException.- Parameters:
newBytes- The new classfile that will be used to define thenamedclass. The specified array is retained by this object and the caller must not modify the specified array.- Throws:
NullPointerException- If newBytes isnull.IllegalStateException- If state isTRANSFORMED,DEFINED,TRANSFORMING_FAILEDorDEFINE_FAILED.SecurityException- If the caller does not haveAdminPermission[bundle,WEAVE]and the Java runtime environment supports permissions.
-
getDynamicImports
Returns the list of dynamic import package descriptions to add to thebundle wiringfor this woven class. Changes made to the returned list will be visible to laterweaving hookscalled with this object. The returned list must not be modified outside invocations of theweavemethod by the framework.After leaving the
TRANSFORMINGstate, this woven class can no longer be transformed and the returned list will be unmodifiable.If the Java runtime environment supports permissions, any modification to the returned list requires
AdminPermission[bundle,WEAVE]. Additionally, any add or set modification requiresPackagePermission[package,IMPORT].- Returns:
- A list containing zero or more dynamic import package
descriptions to add to the bundle wiring for this woven class.
This list must throw
IllegalArgumentExceptionif a malformed dynamic import package description is added. - See Also:
-
isWeavingComplete
boolean isWeavingComplete()Returns whether weaving is complete in this woven class. Weaving is complete after the class is defined.- Returns:
trueifstateisDEFINED,TRANSFORMING_FAILEDorDEFINE_FAILED;falseotherwise.
-
getClassName
String getClassName()Returns the fully qualified name of the class being woven.- Returns:
- The fully qualified name of the class being woven.
-
getProtectionDomain
ProtectionDomain getProtectionDomain()Returns the protection domain to which the woven class will be assigned when it is defined.- Returns:
- The protection domain to which the woven class will be assigned
when it is defined, or
nullif no protection domain will be assigned.
-
getDefinedClass
Class<?> getDefinedClass()Returns the class defined by this woven class. During weaving, this method will returnnull. Once weaving iscomplete, this method will return the class object if this woven class was used to define the class.- Returns:
- The class associated with this woven class, or
nullif weaving is not complete, the class definition failed or this woven class was not used to define the class.
-
getBundleWiring
BundleWiring getBundleWiring()Returns the bundle wiring whose class loader will define the woven class.- Returns:
- The bundle wiring whose class loader will define the woven class.
-
getState
int getState()Returns the current state of this woven class.A woven class can be in only one state at any time.
- Returns:
- Either
TRANSFORMING,TRANSFORMED,DEFINED,TRANSFORMING_FAILEDorDEFINE_FAILED. - Since:
- 1.1
-