Adding Behavior

Top  Previous  Next

Adding behavior to a schema is as simple as setting the type to behavior and using the following attributes.

 

- returnType* [void] (void|<type>)

 

- alias <name>

- comment <value>

- methodParams <string>

- throws <Exception>

 

Schema:

 

<hello packageScope="com.wickedfastsolutions.build.domain.domain.hello" charset="ascii">
    <id type="integer" minInclusive="1">14</id>
    <add alias="addTwoNumbers" type="behavior" returnType="int" methodParams="final int a, final int b" throws="Exception"></add>
    <print type="behavior" returnType="void" methodParams="final String value"></print>
</hello>
 

Generated Code:
 

interface Hello
{
    int getId();
 
    int addTwoNumbers(final int a, final int b) throws Exception;
 
    void print(final String value);
 
    HelloBehavior getBehavior();
 
    void setBehavior(final HelloBehavior behavior);
}

 

Generated Code:

 
interface HelloBehavior
{
  int addTwoNumbers(final int a, final int b) throws Exception;
 
  void print(final String value);
}
 

Generated Code:

 
class HelloBehaviorAdapter implements HelloBehavior
{
  public int addTwoNumbers(final int a, final int b) throws Exception
   {
      throw new RuntimeException("Behavior has not yet been set!");
   }
 
  public void print(final String value)
   {
      throw new RuntimeException("Behavior has not yet been set!");
   }
}
 
class ObjectFactory
{
  public static Hello createHello();
 
  public static Hello createHello(final HelloBehavior behavior);
}

 

 
Schema With Logic:

 

<LastFillDate>
    <Date minOccurs="0" dateFormat="yyyy-MM-dd">2010-10-26</Date>
    <DateTime minOccurs="0" type="date" dateFormat="xsd:datetime" timeZone="UTC">2010-10-26T00:00:00</DateTime>
    <LastFillDate type="behavior" returnType="java.util.Date">
        <![CDATA[
            return (getDate() != null ? new java.text.SimpleDateFormat("yyyy-MM-dd").parse(getDate()) : getDateTime()); 
        ]]>
    </LastFillDate>
</LastFillDate>