XMLStubs Configuration Reference

XMLStubs configuration files are written in XML. This document describes the XML elements and attributes for a valid configuration file.

Hierarchical Index

<stub-beans>
   <stub-bean>
      <method>
         <case>
            IReturn
         </case>
      </method>
   </new-bean>
   <new-bean>   
     New Object
   </stub-bean>
</stub-beans>

What is a New Object? 
      <new>
         <property>
            IReturn
         </property>
      </new>

What can be an IReturn ? Choose above :
     <bean-ref/>
     <new-bean-ref/>
     <collection>
     	 IReturn (value)
     </collection>
     <map>
         <entry>
            IReturn (key)
            IReturn (value)
         </entry>
     </map>
     New Object
     <null/>
     <static/>
     <throw/>
     <value/>

 

top

<stub-beans>

<stub-beans>

The <stub-beans> element is the root element of the configuration, and acts as a container to the rest of the configuration elements.

Child Elements

Element Cardinality Description
<stub-bean> 0 .. * Define a stub that implements a Java interface.
<new-bean> 0 .. * Defines a bean that will be filled using its setter methods.
top

<stub-bean>

<stub-beans>
  <stub-bean id="fooID" implements="fooInterface">

The <stub-bean> element can be used to simulate an Java Interface implementation. Each method needed for the simulation will be described using the <method> tag

Attributes

Attribute Required Description
id Yes Name of the stub, it is the key used to store and retrieve the object
implements Yes Full name of the interface implemented. e.g : net.sf.azote.xmlstubs.Interface

Child Elements

Element Cardinality Description
<method> 0 .. * Define a method element that describe a method of the implemented interface
top

<method>

<stub-beans>
  <stub-bean id="foo" implements="fooInterface">
    <method signature="mathodName(paramClass, paramClass,....)">
     

The <method> element is used to describe a method of a stub-bean object. The method must describe : the name and the full-qualified parameters classes. The returned value is described by the enclosed tags <case>

Attributes

Attribute Required Description
signature Yes method signature : e.g : <method signature="getIntValue(java.lang.String)">

Child Elements

Element Cardinality Description
<case> 0 .. * Define a return value according to method arguments
top

<case>

<stub-beans>
  <stub-bean>
     <method signature="getIntValue(java.lang.String)">
       <case condition="arg0 eq '4'">
         <IReturn>
       </case>
       <case>
         <IReturn>
       </case>
       

The <case> element is used to describe a return value for a method. The case can evaluate a JEXL expression to choose between different return values. The case element are evaluated in the order describe in the XML

Attributes

Attribute Required Description
condition No JEXL expression. If this expression is true, the result of the case will be result of the method

Child Elements

Element Cardinality Description
<IReturn> 1 an element that will return an object.
top

<new-bean>

<stub-beans>
  <new-bean id="barID">
       

The <new-bean> element is used to enclose a new object and associate an id to it.

Attributes

Attribute Required Description
id Yes Name of the bean, it is the key used to store and retrieve the object

Child Elements

Element Cardinality Description
<new> 1 the description of the object
top

<new>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
       

The <new> element is used to instantiate an object and fill it with its setter. Take care of the inner classes :
- static inner class can be instatiate as other object with the java syntax : net.sf.azote.xmlstubs.Container$StaticInner where StaticInner is an inner class of net.sf.azote.xmlstubs.Container
- non static inner class must furthermore declare the inner class with nonStaticInnerClass attribute

Concerning inherited class with inner class from superclass, put in beanclass the name of the inherited class and in the nonStaticInnerClass attribute, the name of the inner class as follow superclass$innerclass

Attributes

Attribute Required Description
beanClass Yes Fully qualified class name of the object. e.g : net.sf.azote.xmlstubs.beans.BeanRef. You can also put here the name of a static inner class : e.g : beanClass="net.sf.azote.xmlstubs.Container$StaticInner
nonStaticInnerClass No In the special case of the inner public class which are not static, put here the name of the inner class. e.g : net.sf.azote.xmlstubs.Container$NonStaticInner

Child Elements

Element Cardinality Description
<property> 0 .. * a property that will be set with its standard setter
top

<property>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
        <IReturn>
      </property>
       

The <property> element is used to set an attribute on the given object. It uses reflection to set the attribute value.

Attributes

Attribute Required Description
name Yes Name of the attribute to set. The value is an IReturn object
nonStaticInnerClass No In the special case of the inner public class which are not static, put here the name of the inner class. e.g : net.sf.azote.xmlstubs.Container$NonStaticInner

Child Elements

Element Cardinality Description
<property> 0 .. * a property that will be set with its standard setter
top

<bean-ref>

<stub-beans>
  <bean-ref>id</bean-ref>
       

The <bean-ref> element is used to make a reference to another bean declared with <stub-bean> element

Value

the value is the ID of the stub bean declared before.
top

<new-bean-ref>

<stub-beans>
  <new-bean-ref>fooID</new-bean-ref>
       

The <new-bean-ref> element is used to make a reference to another bean declared with element

Value

the value is the ID of the stub bean declared before.
top

<collection>

<stub-beans>
<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
        <collection collectionClass="class" itemClass="class">
	      <IReturn>
	      <IReturn>
	      <IReturn>
        </collection>
      </property>
       

The <collection> element is used to instantiate a collection (ArrayList, HashSet...) or an array. If the collection is an array add '[]' at the end of the class name and do not set itemClass attribute.

<collection collectionClass="Foo[]"> is an array of Foo items.
<collection collectionClass="java.util.ArrayList" itemClass="Foo"> is an ArrayList of Foo items.

Attributes

Attribute Required Description
collectionClass No Fully qualified class name of the collection object. (cannot put interface class here) e.g : java.util.ArrayList, java.util.Hashset or Fully qualified class name of the array object with '[]'
HashSet is the default Collection implementation.
itemClass No Fully qualified class name of the items type. e.g : java.lang.String, foo.Bar.
Object is the default item class.

Child Elements

Element Cardinality Description
<IReturn> 0 .. * an object of type IReturn
top

<map>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
	    <map mapClass="class" keyClass="class" itemClass="class">
	      <IReturn>
	      <IReturn>
	      <IReturn>
	    </map>
      </property>
       

The <map> element is used to instantiate a map (hashmap, set...)

Attributes

Attribute Required Description
mapClass Yes Fully qualified class name of the map object. (cannot put interface class here) e.g : java.util.Hashmap, java.util.Hashtable
keyClass Yes Fully qualified class name of the keys type. e.g : java.lang.String, foo.Bar
itemClass Yes Fully qualified class name of the items type. e.g : java.lang.String, foo.Bar

Child Elements

Element Cardinality Description
<IReturn> 0 .. * an object of type IReturn
top

<null>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
	    <null/>
      </property>
       

The <null> element is used to return the null value.

top

<static>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
	    <static staticClass="barClass" staticMethod="batStaticMethodName" />
      </property>
       

The <static> element is used to call or get a static element. The element is described by the staticMethod attribute. This element can me a method name or an attribute name.
if "staticMethod" is a methode name, the same syntax as <method> is used to send argument.

Attributes

Attribute Required Description
staticClass Yes Fully qualified class name of the static object.
staticMethod Yes Method or attribute name. If method name is set, arguments can also be set.
top

<throw>

<stub-beans>
  <stub-bean id="foo" implements="fooInterface">
    <method signature="mathodName(paramClass, paramClass,....)">
	  <throw throwable="foo.bar.FooException" message="foobar" cause="foo.bar.BarException"/>
    </method>
       

The <throw> element is used to send an exception

Attributes

Attribute Required Description
throwable No Fully qualified class name of the exception that will be thrown.
message No Message to be set on the exception. (String format)
cause No Fully qualified class name of the cause that will be set on the exception.
top

<value>

<stub-beans>
  <new-bean id="barID">
    <new beanClass="barClass">
      <property name="attributeName">
	    <value>12345</value>
      </property>
       

The <value> element return the content of the value tag as value. The cast is done regarding property type.