Dashboard > RIFE > ... > Web engine > Site structure and element declaration without XML
RIFE Log In | Sign Up   View a printable version of the current page.
Site structure and element declaration without XML


Added by Geert Bevin, last edited by Geert Bevin on Apr 05, 2005  (view change)
Labels: 
(None)

Element declarations and site structures are traditionally defined in one fixed XML format. A first step has been made to enable the transparent integration of other declaration methods. Each declaration method is identified through a unique identifier which allows you to mix them freely. This identifier can be added in front of the declaration name of the element or site (the file attribute in the XML format). If no identifier is added, it defaults to the 'corexml' declaration method which is what you've always been using. RIFE currently ships with one others declaration method: 'manual'. This essentially means that the rest of the declaration is up to you and that the declaration name will not be automatically processed (with corexml, the declaration name is parsed as an XML document that builds the structure). We'll provide some documentation later about how to define your own identifiers and we're in the process of implementing other structure builders for various purposes.

Here is a small example of how to declare an entire site structure with all the elements in Java only. You'll see this is the same as what's done by the 4 XML files in the basic numberguess example.

src/tutorial/numberguess/Site.java

package tutorial.numberguess;

import com.uwyn.rife.engine.SiteBuilder;
import com.uwyn.rife.rep.BlockingParticipant;

public class Site extends BlockingParticipant
{
    private Object    mSite = null;

    protected void initialize()
    {
        SiteBuilder    builder = new SiteBuilder("numberguess", getResourceFinder());
        builder
            .setArrival("START")
            
            .enterElement("START")
                .setImplementation("tutorial.numberguess.Start")
                .setUrl("/start")
            
                .addInput("gameid")
                .addExit("started")
                .addOutput("gameid")
            
                .addFlowLink("started", "GUESS")
                .addDataLink("gameid", "GUESS", "gameid")
            .leaveElement()
            
            .enterElement("GUESS")
                .setImplementation("tutorial.numberguess.Guess")
                .setUrl("/guess")
            
                .addInput("gameid")
                .enterSubmission("perform_guess")
                    .addParameter("guess")
                .leaveSubmission()
                .addExit("start")
                .addExit("success")
                .addOutput("gameid")

                .addFlowLink("start", "START")
                .addDataLink("gameid", "START", "gameid")

                .addFlowLink("success", "SUCCESS")
                .addDataLink("gameid", "SUCCESS", "gameid")
            .leaveElement()
            
            .enterElement("SUCCESS")
                .setImplementation("tutorial.numberguess.Success")
            
                .addInput("gameid")
                .addExit("start")

                .addFlowLink("start", "GUESS")
            .leaveElement();
        
        mSite = builder.getSite();
    }
    
    protected Object _getObject(Object key)
    {
        return mSite;
    }
}

classes/rep/participants.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE rep SYSTEM "/dtd/rep.dtd">

<rep>
    <participant name="ParticipantSite">tutorial.numberguess.Site</participant>
</rep>

Support for Groovy and Janino

Site structures and elements can also be declared in Groovy and Janino, for instance:

Element declaration

using Groovy (you can find more examples in the SVN repository)

processor.element(implementation:"com.package.MyElement") {
    input(name:"input1")
    input(name:"input2")
    output(name:"output1")
    exit(name:"exit1")
    submission(name:"submission1") {
        param(name:"param1") {
            defaultvalue("default1")
            defaultvalue("default2")
        }
        param(name:"param2")
        param(regexp:"paramC(.*)")
        file(name:"file1")
    }
}

using Janino (you can find more examples in the SVN repository)

builder
    .setImplementation("com.uwyn.rife.engine.testelements.engine.Simple")
    .addInput("input1")
    .addInput("input2")
    .addOutput("output1")
    .addExit("exit1")
    .enterSubmission("submission1")
        .addParameter("param1", new String[] {"default1", "default2"})
        .addParameter("param2")
        .addParameterRegexp("paramC(.*)")
        .addFile("file1")
    .leaveSubmission();

Site structure declaration

using Groovy (you can find more examples in the SVN repository)

processor.site(fallbackid:"ELEMENT4") {
    globalexit(name:"globalexit1", destid:"ELEMENT6")
    globalvar(name:"globalvar1") {
        defaultvalue("default1")
    }
    globalvar(name:"globalvar2")

    element(id:"ELEMENT4", file:"element4.xml")
    element(id:"ELEMENT5", file:"element5.xml")

    subsite(id:"SUBSITE", file:"subsite.groovy", urlprefix:"/subsite", inherits:"ELEMENT4")

    group(inherits:"ELEMENT5") {
        globalvar(name:"globalvar4")

        element(id:"ELEMENT6", file:"element6.janino", url:"/test/element6", inherits:"ELEMENT4")
        element(file:"element7.groovy", url:"/test/element7")
    }
}

using Janino (you can find more examples in the SVN repository)

builder
    .setFallback("ELEMENT4")
    
    .addGlobalExit("globalexit1","ELEMENT6")

    .addGlobalVar("globalvar1", new String[] {"default1"})
    .addGlobalVar("globalvar2")
        
    .enterElement("element4.xml")
        .setId("ELEMENT4")
    .leaveElement()
        
    .enterElement("element5.xml")
        .setId("ELEMENT5")
    .leaveElement()

    .enterSubsite("subsite.groovy")
        .setId("SUBSITE")
        .setUrlPrefix("/subsite")
        .setInherits("ELEMENT4")
    .leaveSubsite()

    .enterGroup()
        .setInherits("ELEMENT5")
    
        .addGlobalVar("globalvar4")
    
        .enterElement("element6.janino")
            .setId("ELEMENT6")
            .setUrl("/test/element6")
            .setInherits("ELEMENT3")
        .leaveElement()
    
        .enterElement("element7.groovy")
            .setUrl("/test/element7")
        .leaveElement()
    .leaveGroup();



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators