Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
<dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.apache.felix.ipojo.annotations</artifactId>
      <version>0.7.35-SNAPSHOT</version>
</dependency>

...

Code Block
package ipojo.example.hello.client;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;

import ipojo.example.hello.Hello;

@Component(name="AnnotedHelloClient", immediate=true)
public class HelloClient implements Runnable {

@Requires
private Hello[] m_hello; // Service Dependency

private final static int DELAY=10000;
private boolean end;

 public void run() {
    while (!end) {
               try {
		invoke();
                Thread.sleep(DELAY);
              } catch (InterruptedException ie) { }
              /* will recheck end */
     }
}

public void invoke() {
	for (int i = 0; i < m_hello.length; i++) { System.out.println(m_hello[i].sayHello("Clement")); }
}

 @Validate
 public void starting() {    Thread T = new Thread(this);     end = false;     T.start();   }
 
 @Invalidate
 public void stopping() {    end = true;  }
}

...

Goal: Defines that the component type provide services
Target: The component implementation class
Attributes:

  • specificationspecifications: defines the provided interface (optional, default = all implemented interfaces)
  • factory: defines the service object creation policy ("SINGLETON" or "SERVICE") (optional, default = "SINGLETON")

...

Code Block
xml
xml
<instance component="ipojo.example.hello.impl.HelloImpl"/>
<instance component="AnnotedHelloClient"/>

...

Using Custom Annotations

To support external handlers, iPOJO defines two generic annotations. These annotations can be used if you want to use an external handler. However, due to annotation limitation, not all external handlers can be used with these annotations.

@Element

Goal: defines an element
Target: component implementation class
Attributes:

  • Name : element name (mandatory)
  • Namespace: element namespace (mandatory)
  • Attributes: array of @Attribute (optional)
  • Elements: array of @SubElement (optional)

@Attribute

Goal: defines an element attribute
Attributes:

  • Name: attribute name
  • Value: attribute value

@SubElement

Goal: defines an sub-element
Attributes:

...

External handlers can provides their own annotations. Using these annotations just requires to add them to your build path. To external handlers annotations, please refer to the external handler documentation.