org.apache.felix.ipojo.manipulation

## Class Manipulator

- java.lang.Object
- - org.apache.felix.ipojo.manipulation.Manipulator

    public class Manipulator
    extends Object

iPOJO Byte code Manipulator.

Author:
  Felix Project Team

### Constructor Summary

Constructors
Constructor and Description
`Manipulator(ClassLoader loader)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addMethodToInnerClass(String name, MethodDescriptor md)` Adds a method to an inner class.
`static String` `extractInnerClassName(String clazz)` Extracts the inner class simple name from the qualified name.
`int` `getClassVersion()`
`Map<String,String>` `getFields()`
`Set<String>` `getFinalFields()`
`Collection<String>` `getInnerClasses()`
`Map<String,List<MethodDescriptor>>` `getInnerClassesAndMethods()`
`org.apache.felix.ipojo.metadata.Element` `getManipulationMetadata()` Compute component type manipulation metadata.
`List<MethodDescriptor>` `getMethods()`
`List<MethodDescriptor>` `getMethodsFromInnerClass(String innerClassInternalName)`
`boolean` `isAlreadyManipulated()` Checks whether the class was already manipulated.
`byte[]` `manipulate(byte[] origin)` Manipulate the given byte array.
`byte[]` `manipulateInnerClass(String inner, byte[] bytecode)` Manipulates the inner class.
`void` `prepare(byte[] origin)` Checks the given bytecode, determines if the class was already manipulated, and collect the metadata about the class.
`void` `prepareInnerClass(String inner, byte[] bytecode)` Analyzes the given inner class.
`static String` `toQualifiedName(String clazz)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### Manipulator

    public Manipulator(ClassLoader loader)

### Method Detail

#### prepare

    public void prepare(byte[] origin)
                 throws IOException

Checks the given bytecode, determines if the class was already manipulated, and collect the metadata about the class.

Parameters:
  `origin` - the bytecode
Throws:
  `IOException`

#### manipulate

    public byte[] manipulate(byte[] origin)
                      throws IOException

Manipulate the given byte array.

Parameters:
  `origin` - : original class.
Returns:
  the manipulated class, if the class is already manipulated, the original class.
Throws:
  `IOException` - : if an error occurs during the manipulation.

#### isAlreadyManipulated

    public boolean isAlreadyManipulated()

Checks whether the class was already manipulated.

Returns:
  `true` if the class was already manipulated, `false` otherwise

#### toQualifiedName

    public static String toQualifiedName(String clazz)

#### getManipulationMetadata

    public org.apache.felix.ipojo.metadata.Element getManipulationMetadata()

Compute component type manipulation metadata.

Returns:
  the manipulation metadata of the class.

#### extractInnerClassName

    public static String extractInnerClassName(String clazz)

Extracts the inner class simple name from the qualified name. It extracts the part after the `$` character.

Parameters:
  `clazz` - the qualified class name
Returns:
  the simple inner class name

#### getFields

    public Map<String,String> getFields()

#### getFinalFields

    public Set<String> getFinalFields()

#### getMethods

    public List<MethodDescriptor> getMethods()

#### getInnerClasses

    public Collection<String> getInnerClasses()

#### getClassVersion

    public int getClassVersion()

#### addMethodToInnerClass

    public void addMethodToInnerClass(String name,
                                      MethodDescriptor md)

Adds a method to an inner class.

Parameters:
  `name` - the inner class name
  `md` - the method descriptor to add

#### prepareInnerClass

    public void prepareInnerClass(String inner,
                                  byte[] bytecode)
                           throws IOException

Analyzes the given inner class.

Parameters:
  `inner` - the inner class name
  `bytecode` - the bytecode of the inner class
Throws:
  `IOException`

#### manipulateInnerClass

    public byte[] manipulateInnerClass(String inner,
                                       byte[] bytecode)
                                throws IOException

Manipulates the inner class. If the outer class was already manipulated does not re-manipulate the inner class. We consider that the manipulation cycle of the outer and inner classes are the same.

Parameters:
  `inner` - the inner class name
  `bytecode` - input (i.e. original) class
Returns:
  the manipulated class
Throws:
  `IOException` - the class cannot be read correctly

#### getMethodsFromInnerClass

    public List<MethodDescriptor> getMethodsFromInnerClass(String innerClassInternalName)

#### getInnerClassesAndMethods

    public Map<String,List<MethodDescriptor>> getInnerClassesAndMethods()