Writing your first Falcon file
The function of Falcon's dependency injection engine is based
on the information provided in a falcon file (*.fal). It is
essentially a XML file that uses a XSD schema specifically
design for this application. The XSD schemas can be found
under ./src/main/xsd/falconBind.xsd.
step 1
Create a xml file and change the extension to 'fal'
rather then the default 'xml'. As it is possible to have
multiple 'fal' files. Falcon will then only pass files
that has a 'fal' extension. The id attribute is not use
for now so can be left empty. It is intended to be use
for identifying when you have loaded multiple falcon
files.
<?xml version="1.0" encoding="UTF-8"?>
<falconBind:falcon id=""
xmlns:falconBind="www.falcon.com/bindingSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="www.falcon.com/bindingSchema ../../../../target/classes/falconBind.xsd">
....
</falconBind:falcon>
step 2
Between the 'falcon' tag create the 'binding' tag. It has
no attribute.
....
<falconBind:binding>
....
</falconBind:binding>
....
step 3
Now you can create the data binding specifics using the
'dataTransfer' tag. This example illustrates the
injection of object
com.falcon.mock.testObjects.SimpleBean
is required. The datatransfer tag requires a few
attributes:
-
classObject: This is the fully qualified class
name
-
name: A unique identifier for the object. This
means you can have multiple description of the
same object to bind differently.
-
type: The type of the object. The options are:
pojo, JPA, ejb
....
<falconBind:dataTransfer classObject="com.falcon.mock.testObjects.SimpleBean"
name="testPojo" type="pojo">
....
</falconBind:dataTransfer>
....
step 4
After specifying the object. You can now specify the
methods of a Object by using the method tag. Only 1
mandatory attribute here:
-
name: This is the name of the method within the class
....
<falconBind:method name="setSt">
....
</falconBind:method>
....
step 5
....
<falconBind:argument type="input" array="false" dataType="xs:string">
<falconBind:static>
someSt
</falconBind:static>
</falconBind:argument>
....
Putting it all together
<falconBind:falcon
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="www.falcon.com/bindingSchema ../../../main/resources/falconBind.xsd"
xmlns:falconBind="www.falcon.com/bindingSchema" id="testId">
<falconBind:binding>
<falconBind:dataTransfer
classObject="com.falcon.mock.testObjects.SimpleBean"
name="testPojo" type="pojo">
<falconBind:method name="setSt">
<falconBind:argument type="input" array="false" dataType="xs:string">
<falconBind:static>
someSt
</falconBind:static>
</falconBind:argument>
</falconBind:method>
</falconBind:dataTransfer>
</falconBind:binding>
</falconBind:falcon>
Get a dependancy injected object from Falcon engine
This is done via 2 steps...
Getting the Runner object
com.falcon.core.FalconRunner runner = FalconCoreFactory.getFalconRunner(<location of .fal file>);
Get your obejct via the 'name' of the object
SimpleBean simpleBean = (SimpleBean) runner.getObject('testPojo');