OSGi™ Core
Release 5

org.osgi.framework.hooks.weaving
Interface WovenClass


public interface WovenClass

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.

After weaving is complete, this object becomes effectively immutable.

NotThreadSafe
Consumers of this API must not implement this interface

Method Summary
 BundleWiring getBundleWiring()
          Returns the bundle wiring whose class loader will define the woven class.
 byte[] getBytes()
          Returns the class file bytes to be used to define the named class.
 java.lang.String getClassName()
          Returns the fully qualified name of the class being woven.
 java.lang.Class<?> getDefinedClass()
          Returns the class defined by this woven class.
 java.util.List<java.lang.String> getDynamicImports()
          Returns the list of dynamic import package descriptions to add to the bundle wiring for this woven class.
 java.security.ProtectionDomain getProtectionDomain()
          Returns the protection domain to which the woven class will be assigned when it is defined.
 boolean isWeavingComplete()
          Returns whether weaving is complete in this woven class.
 void setBytes(byte[] newBytes)
          Set the class file bytes to be used to define the named class.
 

Method Detail

getBytes

byte[] getBytes()
Returns the class file bytes to be used to define the named class.

While weaving is not complete, this method returns a reference to the class files byte array contained in this object. After weaving is complete, this object becomes effectively immutable and a copy of the class file byte array is returned.

Returns:
The bytes to be used to define the named class.
Throws:
java.lang.SecurityException - If the caller does not have AdminPermission[bundle,WEAVE] and the Java runtime environment supports permissions.

setBytes

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 weaving is not complete, this method replaces the reference to the array contained in this object with the specified array. After weaving is complete, this object becomes effectively immutable and this method will throw an IllegalStateException.

Parameters:
newBytes - 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.
Throws:
java.lang.NullPointerException - If newBytes is null.
java.lang.IllegalStateException - If weaving is complete.
java.lang.SecurityException - If the caller does not have AdminPermission[bundle,WEAVE] and the Java runtime environment supports permissions.

getDynamicImports

java.util.List<java.lang.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 weaving is complete, this object becomes effectively immutable and the returned list will be unmodifiable.

If the Java runtime environment supports permissions, the caller must have AdminPermission[bundle,WEAVE] to modify the returned list.

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.
See Also:
"Core Specification, Dynamic Import Package, for the syntax of a dynamic import package description."

isWeavingComplete

boolean isWeavingComplete()
Returns whether weaving is complete in this woven class. Weaving is complete after the last weaving hook is called and the class is defined.

After weaving is complete, this object becomes effectively immutable.

Returns:
true weaving is complete, false otherwise.

getClassName

java.lang.String getClassName()
Returns the fully qualified name of the class being woven.

Returns:
The fully qualified name of the class being woven.

getProtectionDomain

java.security.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 null if no protection domain will be assigned.

getDefinedClass

java.lang.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:
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.

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.

OSGi™ Core
Release 5

Copyright © OSGi Alliance (2000, 2012). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0