This is a complete example of a component. The example consists of these files:
NotifierOne.java - component notifier one
(see Example 11.3, “Component notifier”).
-
component notifier two (see Example 11.4, “NotifierTwo.java”).NotifierTwo.java
Defaults.java - example configuration
definition (see Example 11.5, “Defaults.java”).
default.kcs - configuration file loaded by
component (see Example 11.6, “default.kcs”).
ComponentMain.java - driver to execute
example (see Example 11.7, “ComponentMain.java”).
ast.properties - component property file (see
Example 11.1, “Component property file”).
Example 11.4. NotifierTwo.java
// $Revision: 1.1.2.1 $
package com.kabira.snippets.components;
import com.kabira.platform.component.Notifier;
/**
* Component notifier two
*/
public class NotifierTwo extends Notifier
{
@Override
protected void preConfigurationInitialize()
{
m_notifierName = getClass().getSimpleName();
System.out.println(m_notifierName + ": - preConfigurationInitialize");
}
@Override
protected void postConfigurationInitialize()
{
System.out.println(m_notifierName + ": - postConfigurationInitialize");
}
@Override
protected void preConfigurationTerminate()
{
System.out.println(m_notifierName + ": - preConfigurationTerminate");
}
@Override
protected void postConfigurationTerminate()
{
System.out.println(m_notifierName + ": - postConfigurationTerminate");
}
private String m_notifierName;
}
Example 11.5. Defaults.java
// $Revision: 1.1.2.1 $
package com.kabira.snippets.components;
import com.kabira.platform.kcs.Configuration;
/**
* Default component configuration
*/
public class Defaults extends Configuration
{
String defaultValue;
}
Example 11.6. default.kcs
// $Revision: 1.1.2.1 $
configuration "default" version "1.0" type "com.kabira.snippets.components"
{
configure com.kabira.snippets.components
{
Defaults
{
defaultValue = "hello world";
};
};
};
Example 11.7. ComponentMain.java
// $Revision: 1.1.2.1 $
package com.kabira.snippets.components;
import com.kabira.platform.Transaction;
import com.kabira.platform.ManagedObject;
/**
* Execute component example
*
* NOTE: This example requires the classpath to explicitly include the
* directory that contains this snippet source so that the ast.properties
* file is found.
*
* <p>
* <h2> Target Nodes</h2>
* <ul>
* <li> <b>domainnode</b> = A
* </ul>
*/
public class ComponentMain
{
/**
* @param args None supported
*/
public static void main(String[] args)
{
System.out.println("Main executed");
new Transaction("Components")
{
@Override
protected void run() throws Rollback
{
for (Defaults defaults : ManagedObject.extent(Defaults.class ))
{
System.out.println(
"Configured default value: " + defaults.defaultValue);
}
}
}.execute();
System.out.println("Main exiting");
}
}
When main is executed the following output
(annotation added) is generated.
![]() | |
This example requires that snippet be run using a JAR file
containing the |
Example 11.8. Example component output
# # # Component initialization # [A] NotifierOne: - preConfigurationInitialize [A] NotifierTwo: - preConfigurationInitialize [A] NotifierOne: - postConfigurationInitialize [A] NotifierTwo: - postConfigurationInitialize # # Main execution # [A] Main executed [A] Configured default value: hello world [A] Main exiting # # Component termination # [A] NotifierTwo: - preConfigurationTerminate [A] NotifierOne: - preConfigurationTerminate [A] NotifierTwo: - postConfigurationTerminate [A] NotifierOne: - postConfigurationTerminate