Fusebox 4.1 newly introduced the XML file rather than the
previous version. This version uses XML for two purposes:
·
To provide configuration and initialization information application
(i.e fusebox.xml file)
·
To provide configuration and initialization information for
individual circuits (i.e circuit.xml file)
The Fusebox application has only one fusebox.xml file. It is
located in the root directory of that application.
Let us first explain fusebox.xml.
The Fusebox XML file consists of root element, Fusebox and
five prime sub elements.
·
Circuits
·
Classes
·
Parameters
·
Globalfuseactions
·
Plugins
Circuits
The circuits' elements define each circuit in the Fusebox application.
The circuits' elements contain one or more circuit elements. Each circuit has
an attribute such as alias, path, and parent. The Syntax is:
Listing 2
<circuits>
<circuit alias=”document1” path=”member1” parent=””\>
<circuit alias=”document2” path=”member2” parent=””\>
<circuit alias=”document3” path=”member3” parent=””\>
</circuits>
·
The attribute alias is the name by which the circuit is called.
·
The attribute path defines the path to the directory which
contains the circuit's own XML definition files.
·
The attribute parent is the name of the parent circuit, if
required.
Classes
The classes element allows map aliases to the component
objects. These component objects are ColdFusion component (CFC) files. The
classes element consists of one or more class elements.
Here is an example using class elements.
Listing 3
<classes>
<class alias=”Google” class path=”http://www.google.com” type=”webservice” />
<class alias=”Address” class path=”member.com.Address” type=”component”
constructor=”init” />
</classes>
·
The attribute alias is the name and specifies the class that will
access in circuit.xml.
·
The attribute type defines the type of object for the class. The
valid objects are:
a) component (if the class is CFC's)
b) java (for Java classes)
c) webservice (for Web services)
d) com (for COM object)
e) corba (for CORBA objects)
·
The attribute class path defines the path to the class. When we
use the CFC, the class path is fulldot separated path to the CFC either from
the webroot or a custom tag path. When we use java class, the class path is the
java class path. For web service, the class path is the url to call the WSDL
file for the web service.
·
The attribute constructor specifies the method within the object
that defines its constructor. This attribute is optional.
Parameters
The parameter elements are used to set the fusebox
application parameter. Each parameter has attributes name and value.
Listing 4
<parameters>
<parameter name="fuseactionVariable" value="fuseaction" />
<parameter name="defaultFuseaction" value="document.login" />
</parameters>
The attribute fuseaction variable is used to set the value
that your application will use. So the URL's and Forms can pass the fuseaction.
Listing 5
index.cfm?fuseaction=document.login
Globalfuseactions
The Globalfuseaction has two sub elements.
a) Preprocess
b) Postprocess
In Preprocess, the fuseactions are executed at the beginning
of every request. But in post process, the fuseactions are executed at the end
of the every request.
Listing 6
<globalfuseaction>
<preprocess>
........................
........................
</preprocess>
<postprocess>
..........................
..........................
</postprocess>
</globalfuseaction>
Plugins
The last element in fusebox.xml is plugins. The plugin
element can contain several phase elements which define six possible places
where the Fusebox core can be extended.
Listing 7
<plugins>
<phase name=”preProcess”></phase>
<phase name=”preFuseaction”></phase>
<phase name=”postFuseaction”></phase>
<phase name=”postProcess ”></phase>
<phase name=”fuseactionException”></phase>
<phase name=”processError”></phase>
</plugins>
An individual plugin can be declared inside any phase.
Listing 8
<plugin name="pluginName" template="pluginFile">
This declaration tells Fusebox to execute the plugin file
during the lifecycle of Fusebox.
So the structure of Fusebox.xml is:
Listing 9
<fusebox>
<circuits>
.............................
.............................
</circuits>
<classes>
............................
.............................
</classes>
<parameters>
............................
...........................
</parameters>
<globalfuseactions>
..........................
..........................
</globalfuseactions>
<plugins>
........................
........................
</plugins>
</fusebox>
Circuit.xml file
As there is only one fusebox.xml file in Fusebox application.
We need the circuital file in each circuit's directory. This is defined as:
Listing 10
<circuit access=”public”>
<prefuseaction>
<do action=”document.hello”>
</prefuseaction>
<fuseaction name=”helloworld”>
<include template=”dsp_helloworld.cfm” />
</fuseaction>
</circuits>
Circuit
The root element of circuit.xml is circuit. Within the circuit
there are three sub elements.
a) prefuseaction
b) fuseaction
c) postfuseaction
The circuit has two optional attributes: access and
permission. They are used to set default values for the same attributes on the
fuseactions within the circuit.
The attribute access may be public, internal and private. If
no access attribute is specified, the default value is internal. There is no
default value for permissions.
The prefuseaction holds the fuseactions to be executed
automatically before the initially called fuseaction is executed. If you have a
request of index.cfm?fuseaction=document.helloworld and you have a fuseaction
of home.foo within your prefuseaction element, document.home will be executed,
followed by document.helloworld. The postfuseaction element automatically
executes after the called fuseaction is completed.