Top Description Fields Methods
org.osgi.framework.hooks.weaving

public Interface WovenClass

Annotations
@ProviderType
Imports
java.security.ProtectionDomain, java.util.List, org.osgi.annotation.versioning.ProviderType, org.osgi.framework.wiring.BundleWiring

A class being woven. This object represents a class being woven and is passed to each 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

Modifier and TypeField and Description
public static final int
DEFINE_FAILED

The woven class failed to define.

public static final int
DEFINED

The woven class has been defined.

public static final int
TRANSFORMED

The woven class has been transformed.

public static final int
TRANSFORMING

The woven class is being transformed.

public static final int
TRANSFORMING_FAILED

The woven class failed to transform.

Method Summary

Modifier and TypeMethod and Description
public BundleWiring

Returns:

The bundle wiring whose class loader will define the woven class.
getBundleWiring
()

Returns the bundle wiring whose class loader will define the woven class.

public byte[]

Returns:

The bytes to be used to define the named class.
getBytes
()

Returns the class file bytes to be used to define the named class.

public String

Returns:

The fully qualified name of the class being woven.
getClassName
()

Returns the fully qualified name of the class being woven.

public Class<?>

Returns:

The class associated with this woven class, or null if weaving is not complete, the class definition failed or this woven class was not used to define the class.
getDefinedClass
()

Returns the class defined by this woven class.

public List<String>

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 IllegalArgumentException if a malformed dynamic import package description is added.
getDynamicImports
()

Returns the list of dynamic import package descriptions to add to the bundle wiring for this woven class.

public ProtectionDomain

Returns:

The protection domain to which the woven class will be assigned when it is defined, or null if no protection domain will be assigned.
getProtectionDomain
()

Returns the protection domain to which the woven class will be assigned when it is defined.

public int
getState()

Returns the current state of this woven class.

public boolean

Returns:

true if state is DEFINED, TRANSFORMING_FAILED or DEFINE_FAILED; false otherwise.
isWeavingComplete
()

Returns whether weaving is complete in this woven class.

public void
setBytes(byte[]
The new classfile that will be used to define the named class. The specified array is retained by this object and the caller must not modify the specified array.
newBytes
)

Set the class file bytes to be used to define the named class.

Field Detail

DEFINE_FAILEDback to summary
public static final int DEFINE_FAILED

The 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
DEFINEDback to summary
public static final int DEFINED

The 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 wiring has been updated with the dynamic import requirements and the class has been defined.

Since
1.1
TRANSFORMEDback to summary
public static final int TRANSFORMED

The woven class has been transformed.

The woven class is in this state after weaving hooks have 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 to DEFINE_FAILED. Otherwise, after the class has been defined, the state transitions to DEFINED.

Since
1.1
TRANSFORMINGback to summary
public static final int TRANSFORMING

The woven class is being transformed.

The woven class is in this state while weaving hooks are being called. The woven class is mutable so the class bytes may be modified and dynamic imports may be added. If a weaving hook throws an exception the state transitions to TRANSFORMING_FAILED. Otherwise, after the last weaving hook has been successfully called, the state transitions to TRANSFORMED.

Since
1.1
TRANSFORMING_FAILEDback to summary
public static final int TRANSFORMING_FAILED

The woven class failed to transform.

The woven class is in this state if a weaving hook threw 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

Method Detail

getBundleWiringback to summary
public BundleWiring getBundleWiring()

Returns the bundle wiring whose class loader will define the woven class.

Returns:BundleWiring

The bundle wiring whose class loader will define the woven class.

getBytesback to summary
public byte[] getBytes()

Returns the class file bytes to be used to define the named class.

While in the TRANSFORMING state, this method returns a reference to the class files byte array contained in this object. After leaving the TRANSFORMING state, this woven class can no longer be transformed and a copy of the class file byte array is returned.

Returns:byte[]

The bytes to be used to define the named class.

Exceptions
SecurityException:
If the caller does not have AdminPermission[bundle,WEAVE] and the Java runtime environment supports permissions.
getClassNameback to summary
public String getClassName()

Returns the fully qualified name of the class being woven.

Returns:String

The fully qualified name of the class being woven.

getDefinedClassback to summary
public Class<?> getDefinedClass()

Returns the class defined by this woven class. During weaving, this method will return null. Once weaving is complete, this method will return the class object if this woven class was used to define the class.

Returns:Class<?>

The class associated with this woven class, or null if weaving is not complete, the class definition failed or this woven class was not used to define the class.

getDynamicImportsback to summary
public List<String> getDynamicImports()

Returns the list of dynamic import package descriptions to add to the bundle wiring for this woven class. Changes made to the returned list will be visible to later weaving hooks called with this object. The returned list must not be modified outside invocations of the weave method by the framework.

After leaving the TRANSFORMING state, 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 requires PackagePermission[package,IMPORT].

Returns:List<String>

A list containing zero or more dynamic import package descriptions to add to the bundle wiring for this woven class. This list must throw IllegalArgumentException if a malformed dynamic import package description is added.

See Also
Core Specification, Dynamic Import Package, for the syntax of a dynamic import package description.
getProtectionDomainback to summary
public ProtectionDomain getProtectionDomain()

Returns the protection domain to which the woven class will be assigned when it is defined.

Returns:ProtectionDomain

The protection domain to which the woven class will be assigned when it is defined, or null if no protection domain will be assigned.

getStateback to summary
public int getState()

Returns the current state of this woven class.

A woven class can be in only one state at any time.

Returns:int

Either TRANSFORMING, TRANSFORMED, DEFINED, TRANSFORMING_FAILED or DEFINE_FAILED.

Since
1.1
isWeavingCompleteback to summary
public boolean isWeavingComplete()

Returns whether weaving is complete in this woven class. Weaving is complete after the class is defined.

Returns:boolean

true if state is DEFINED, TRANSFORMING_FAILED or DEFINE_FAILED; false otherwise.

setBytesback to summary
public void setBytes(byte[] newBytes)

Set the class file bytes to be used to define the named class. This method must not be called outside invocations of the weave method by the framework.

While in the TRANSFORMING state, this method replaces the reference to the array contained in this object with the specified array. After leaving the TRANSFORMING state, this woven class can no longer be transformed and this method will throw an IllegalStateException.

Parameters
newBytes:byte[]

The new classfile that will be used to define the named class. The specified array is retained by this object and the caller must not modify the specified array.

Exceptions
NullPointerException:
If newBytes is null.
IllegalStateException:
If state is TRANSFORMED, DEFINED, TRANSFORMING_FAILED or DEFINE_FAILED.
SecurityException:
If the caller does not have AdminPermission[bundle,WEAVE] and the Java runtime environment supports permissions.