Runtime components : Core components : ElementFactory : Tasks : Handling reference in definition
  
Handling reference in definition
You can define an element, and point the element definition to another element definition. This section introduces how to define element reference and alias.
Define element reference
Take the following sample for example:
public class SimpleElement {
private String fieldA;
private int fieldB;
//getters and setters here
}
public class ComplexElement {
private String fieldA;
private SimpleElement simpleElement1;
private SimpleElement simpleElement2;
//getters and setters here
}
You can define the element instance as follows:
<mypackage.SimpleElement id="aSimpleElement" fieldA="valueA" fieldB="321"/>
<mypackage.ComplexElement id="aComplexElement" fieldA="valueA">
<mypackage.SimpleElement Injection="simpleElement1" fieldA="valueA" fieldB="123" />
<ref Injection="simpleElement2" refId="aSimpleElement"/>
</mypackage.ComplexElement>
To refer to another element, you must use ref as tag name. And the value of the attribute refId should be the id of the referred element instance.
Following is another sample element:
public interface ProductInterface {
  //Some logic here
}
public class MyProduct {
  public MyProduct(String content) {
    //Some logic here
  }
  //Some logic here
}
You can define it as follows:
<arguments id="aArguments">
  <string ArgumentType="java.lang.String" value="This is productA"/>
</arguments>
<mypackage.Product id="productA" Instantiate="staticFactory"
FactoryClass="mypackage.MyStaticFactory">
  <ref CreateParent="createProduct" refId="aArguments"/>
</ mypackage.Product>
Define alias
You can also use the tag ref to define alias for an element instance. Take the following element for example:
public class SimpleElement {
  private String fieldA;
  private int fieldB;
  //getters and setters here
}
public class ComplexElement {
  private String fieldA;
  private SimpleElement simpleElement1;
  private SimpleElement simpleElement2;
  //getters and setters here
}
You can define it as follows:
<mypackage.SimpleElement id="aSimpleElement" fieldA="valueA" fieldB="321"/>
<ref id="anotherId" refId="aSimpleElement"/>
<mypackage.ComplexElement id="aComplexElement" fieldA="valueA">
  <mypackage.SimpleElement Injection="simpleElement1" fieldA="valueA" fieldB="123" />
  <ref Injection="simpleElement2" refId="anotherId"/>
</mypackage.ComplexElement>
Note There are three reserved tag names: arguments, entry and ref. See Referencefor more details.
Go up to
Tasks