diff --git a/.classpath b/.classpath index 15875b2..cbfb956 100644 --- a/.classpath +++ b/.classpath @@ -1,16 +1,12 @@ - - - - - - - - + + + + + - - - + + diff --git a/.project b/.project index 15e1086..1a8c3a7 100644 --- a/.project +++ b/.project @@ -10,8 +10,14 @@ + + org.maven.ide.eclipse.maven2Builder + + + + org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature diff --git a/.settings/org.maven.ide.eclipse.prefs b/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 0000000..04aa602 --- /dev/null +++ b/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Sun Dec 07 05:31:33 CET 2008 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..219becd --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,23 @@ +Copyright 2004-2009 IDCA. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those of the authors and +should not be interpreted as representing official policies, either expressed or implied, of IDCA. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ff15294 --- /dev/null +++ b/pom.xml @@ -0,0 +1,248 @@ + + +4.0.0 +com.idcanet +foei +jar +0.8-SNAPSHOT +foei +Creates an easy xml layer for objects and creating your own xml language implementions. +http://www.x4o.org/foei + + IDCA + http://www.idca.nl + + + + Trac + https://decaid.idca.nl/trac/oss/ + + + scm:svn:https://decaid.idca.nl/svn/oss/com.idcanet.foei/ + scm:svn:https://decaid.idca.nl/svn/oss/com.idcanet.foei/ + https://decaid.idca.nl/svn/oss/com.idcanet.foei/ + + + + + willem.cazander + Willem Cazander + w.cazander@gmail.com + IDCA + +2 + + Project Manager + Architect + + + + sqrbass + Bas van Oostveen + + IDCA + +2 + + Architect Reviewer + + + + + + + jboss + JBoss Repository Switchboard + default + http://repository.jboss.com/maven2/ + true + + + + + + + + com.idcanet.x4o + x4o-main + 0.8-SNAPSHOT + + + + + + com.idcanet.serv5 + serv5-main + 0.6-SNAPSHOT + + + + + org.testng + testng + 5.8 + test + jdk15 + + + + + + + + + + maven-compiler-plugin + + UTF-8 + 1.5 + 1.5 + + + + + + maven-site-plugin + 2.0-beta-7 + + UTF-8 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4 + + + + + + com.agilejava.docbkx + docbkx-maven-plugin + + + + src/main/docbook/ + target/site/docbook/ + + + *.xml + + + + true + + + version + ${version} + + + + + true + + + + + + + + create-pdf-docs + site + generate-pdf + + + file:///${basedir}/src/main/docbook/ + + + + + create-html-docs + site + generate-html + + + + + + + + + + + + + + + org.docbook + docbook-xml + 4.4 + runtime + + + + + + + + + target/site + + + org.codehaus.mojo + cobertura-maven-plugin + + + org.apache.maven.plugins + maven-surefire-report-plugin + + + org.apache.maven.plugins + maven-javadoc-plugin + + + org.apache.maven.plugins + maven-project-info-reports-plugin + + + + summary + dependencies + project-team + + + + + + org.codehaus.mojo + jxr-maven-plugin + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.4.2 + + + org.codehaus.mojo + jdepend-maven-plugin + + + org.apache.maven.plugins + maven-changes-plugin + 2.0 + + ${basedir}/src/site/changes.xml + + + + changes-report + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/io/ErrorOutput.java b/src/main/java/com/idcanet/foei/components/io/ErrorOutput.java new file mode 100644 index 0000000..9ea4d17 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/io/ErrorOutput.java @@ -0,0 +1,72 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.io; + +import com.idcanet.foei.event.AbstractEventInputStepController; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Prints the EventSteps to the System.err + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +public class ErrorOutput extends AbstractEventInputStepController +{ + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Creates an ErrorOutput + */ + public ErrorOutput() { + addInputPort(EventPort.INPUT); + } + + // ----------- EventInput + + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(EventPortType.input!=eventPort.getEventPortType()) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + System.err.println(processEventSteps(object)); + } + + public Object processEventSteps(Object object) { + StringBuffer buff = new StringBuffer(); + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + buff.append((String)e.processObject(object)); + } + return buff; + } +} diff --git a/src/main/java/com/idcanet/foei/components/io/FileOutput.java b/src/main/java/com/idcanet/foei/components/io/FileOutput.java new file mode 100644 index 0000000..f4cb001 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/io/FileOutput.java @@ -0,0 +1,36 @@ + +package com.idcanet.foei.components.io; +/* + +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; + +public class FileOutput extends AbstractEventInput +{ + static final String INPUT = "input"; + private ArrayList printers = new ArrayList(4); + + public FileOutput() + { + inputList.add(INPUT); + } + + + // ----------- EventInput + + public void doEvent(String inputName,Object object) + { + Iterator printerWalker = printers.iterator(); + //System.out.print("STDOUT:"); + while(printerWalker.hasNext()) + { + EventStep eventStep = (EventStep)printerWalker.next(); + String out = (String)eventStep.processObject(object); + System.out.print(out); + } + System.out.println(""); + } + +} +*/ \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/io/StandardOutput.java b/src/main/java/com/idcanet/foei/components/io/StandardOutput.java new file mode 100644 index 0000000..e9524aa --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/io/StandardOutput.java @@ -0,0 +1,73 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.io; + +import com.idcanet.foei.event.AbstractEventInputStepController; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Prints the EventSteps to the System.out + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +public class StandardOutput extends AbstractEventInputStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Creates an StandardOutput + * + */ + public StandardOutput() { + addInputPort(EventPort.INPUT); + } + + // ----------- EventInput + + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(EventPortType.input!=eventPort.getEventPortType()) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + System.out.println(processEventSteps(object)); + } + + public Object processEventSteps(Object object) { + StringBuffer buff = new StringBuffer(); + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + buff.append((String)e.processObject(object)); + } + return buff; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/lang/DestroyFoeiProcess.java b/src/main/java/com/idcanet/foei/components/lang/DestroyFoeiProcess.java new file mode 100644 index 0000000..72377d9 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/DestroyFoeiProcess.java @@ -0,0 +1,106 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventInput; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.IllegalEventPortNameException; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Destroys an FoeiContext + * + * @author Willem Cazander + * @version 1.0 Mar 3, 2006 + */ +public class DestroyFoeiProcess extends AbstractEventInput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + private Integer delayTime = null; + + private Logger logger = null; + + public void setDelayTime(Integer delayTime) { + this.delayTime=delayTime; + } + + public Integer getDelayTime() { + return delayTime; + } + + /** + * Creates the output port + */ + public DestroyFoeiProcess() { + logger = Logger.getLogger(DestroyFoeiProcess.class.getName()); + addInputPort(EventPort.INPUT,Object.class); + getInputPort(EventPort.INPUT).setImmediate(false); + setDelayTime(5000); + } + + /** + * Stops the running FoeiProcess. + * (running event wil stil run !!) + * @see EventInput#doEvent(EventPort, Object) + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(EventPortType.input!=eventPort.getEventPortType()) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + FoeiProcess process = FoeiProcessFactory.getFoeiProcess(); + + if (process.getWorkQueue().isEmpty()==false) { + logger.info("WorkQueue not empty sleeping a bit and sending retrigger myself q="+process.getWorkQueue().size()+" for proc: "+process.getName()); + try { + Thread.sleep(delayTime+500); // add some minual d + } catch (Exception e) { + logger.log(Level.WARNING,"Error sleeping: "+e.getMessage(),e); + } + process.executeEvent(getInputPort(EventPort.INPUT), "null"); + return; + } + + if(delayTime!=null) { + try { + logger.info("Sleeping "+delayTime+" ms before destoying process: "+process.getName()); + Thread.sleep(delayTime); + } catch (Exception e) { + logger.log(Level.WARNING,"Error sleeping: "+e.getMessage(),e); + } + } + // the impl prints an destory line + process.getFoeiContext().getFoeiProcessManager().destroyFoeiProcess(process.getName()); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/lang/DummyOutputPort.java b/src/main/java/com/idcanet/foei/components/lang/DummyOutputPort.java new file mode 100644 index 0000000..745572c --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/DummyOutputPort.java @@ -0,0 +1,51 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.event.AbstractEventOutput; +import com.idcanet.foei.event.EventPort; + +/** + * Defines an DummyOutputPort + * + * @author Willem Cazander + * @version 1.0 Feb 12, 2006 + * + * + */ +public class DummyOutputPort extends AbstractEventOutput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Creates the output port + */ + public DummyOutputPort() { + addOutputPort(EventPort.OUTPUT,Object.class); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/lang/EventProxy.java b/src/main/java/com/idcanet/foei/components/lang/EventProxy.java new file mode 100644 index 0000000..aaa5893 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/EventProxy.java @@ -0,0 +1,69 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventObject; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * This is a sort of dummy object. + * It only resends its events to the output. + * + * @author Willem Cazander + * @version 1.0 Feb 27, 2005 + */ +public class EventProxy extends AbstractEventObject { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Creates an EventProxy + */ + public EventProxy() { + addInputPort(EventPort.INPUT,Object.class); // define an input source + addOutputPort(EventPort.OUTPUT,Object.class); // define the outputs source. + } + + /** + * Only proxies the object from the input to the output + * @param inputName + * @param object + * @throws IllegalEventPortNameException + * @see EventInput#doEvent(EventPort, Object) + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(EventPortType.input!=eventPort.getEventPortType()) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),object); + } +} diff --git a/src/main/java/com/idcanet/foei/components/lang/Filter.java b/src/main/java/com/idcanet/foei/components/lang/Filter.java new file mode 100644 index 0000000..bc1b6cf --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/Filter.java @@ -0,0 +1,101 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventObjectStepController; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Fiters the object on the Input port throw all + * eventsteps and outputs to pass or drop. + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +/* +@SetEventPorts(ports={ + @SetEventPort(type=EventPortType.input,name=EventPort.INPUT,immediate=EventPort.TRUE), + @SetEventPort(type=EventPortType.output,name=EventPort.DROP), + @SetEventPort(type=EventPortType.output,name=EventPort.PASS), +}) +*/ +public class Filter extends AbstractEventObjectStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Creates an Filter + */ + public Filter() { + addInputPort(EventPort.INPUT,Object.class); // define an input source + addOutputPort(EventPort.DROP); // define the outputs source. + addOutputPort(EventPort.PASS); // defaults to Object.class) + } + + /** + * Filters the object with EventSteps + * @see EventInput#doEvent(EventPort, Object) + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(EventPortType.input!=eventPort.getEventPortType()) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + Object filtered = processEventSteps(object); + if(filtered==null) { + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.DROP),object); + } else { + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.PASS),object); + } + } + + /** + * Make sure that all steps are given the org object .. + */ + @Override + public Object processEventSteps(Object object) { + Object o = object; + for (int i=0;i,Object> bufferedObjects = null; + + public static final String NO_CHANGE = "noChange"; + + /** + * Creates an TapFlowWriter + * + */ + public ObjectChangedBuffer() { + logger = Logger.getLogger(ObjectChangedBuffer.class.getName()); + addInputPort(EventPort.INPUT); + addOutputPort(EventPort.OUTPUT); + addOutputPort(NO_CHANGE); + bufferedObjects = Collections.synchronizedMap(new HashMap,Object>(2)); + } + + /** + * @see com.idcanet.foei.event.AbstractEventObject#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object) + */ + @Override + public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException { + if(!EventPort.INPUT.equals(eventPort.getName())) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + if(object==null) { + logger.warning("object null; returning"); + return; + } + if(bufferedObjects.containsKey(object.getClass())) { + if(object.equals(bufferedObjects.get(object.getClass()))) { + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(NO_CHANGE),object); + return; + } + } + bufferedObjects.put(object.getClass(),object); + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),object); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/lang/SendEvent.java b/src/main/java/com/idcanet/foei/components/lang/SendEvent.java new file mode 100644 index 0000000..279ca3b --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/SendEvent.java @@ -0,0 +1,117 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventInput; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * This is a sort of dummy object. + * It only resends its events to the output. + * + * @author Willem Cazander + * @version 1.0 Feb 9, 2006 + */ +public class SendEvent extends AbstractEventInput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** The output name */ + private String inputName = null; + + /** The FoeiContext jndi name of the EventInput object to send the event to */ + private String to = null; + + /** + * Creates an SendEvent object. + */ + public SendEvent() { + // define an input source + addInputPort(EventPort.INPUT,Object.class); + } + + /** + * Sets the inputName + * @param inputName The inputName to set. + */ + public void setInputName(String inputName) { + this.inputName=inputName; + } + + /** + * Gets the inputName + * @return Returns the inputName. + */ + public String getInputName() { + return inputName; + } + + /** + * Sets the to + * @param to The to to set. + */ + public void setTo(String to) { + this.to=to; + } + + /** + * Returns the to. + * @return The to to set. + */ + public String getTo() { + return to; + } + + /** + * Send an event to "to" an input port "inputname" + * @param inputName + * @param object + * @throws IllegalEventPortNameException + * @see EventInput#doEvent(EventPort, Object) + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + if(!EventPort.INPUT.equals(eventPort.getName())) { + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + if(to==null) { + return; + } + if(inputName==null) { + return; + } + Object eo = FoeiProcessFactory.getFoeiProcess().getEventObject(to); + if(!(eo instanceof EventInput)) { + return; + } + EventPort port = ((EventInput)eo).getInputPort(inputName); + FoeiProcessFactory.getFoeiProcess().executeEvent(port,object); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/lang/SetBeanProperty.java b/src/main/java/com/idcanet/foei/components/lang/SetBeanProperty.java new file mode 100644 index 0000000..445ef75 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/SetBeanProperty.java @@ -0,0 +1,104 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.lang; + +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventObject; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; +import com.idcanet.x4o.impl.DefaultElementParameterHelper; + +/** + * Sets an property of an bean which is set on the propery input port. + * + * @author Willem Cazander + * @version 1.0 Feb 12, 2006 + */ +public class SetBeanProperty extends AbstractEventObject { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** The Property name */ + static final public String PROPERTY = "property"; + + private String property = null; + + private Object propertyValue = null; + + private DefaultElementParameterHelper helper = null; + + /** + * Creates an SetBeanProperty + */ + public SetBeanProperty() { + addInputPort(EventPort.INPUT,Object.class); + addInputPort(PROPERTY,Object.class); + addOutputPort(EventPort.OUTPUT); + helper = new DefaultElementParameterHelper(); + } + + /** + * Filters the object with EventSteps + * @see EventInput#doEvent(EventPort, Object) + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException { + + if(PROPERTY.equals(eventPort.getName())) { + propertyValue=object; + return; + } + if(EventPort.INPUT.equals(eventPort.getName())) { + if(property==null) { + return; + } + try { + helper.setParameter(object,property,propertyValue); + } catch (Exception e) { + e.printStackTrace(); + return; + } + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),object); + return; + } + throw new IllegalEventPortNameException("Not excisting input EventPort: "+eventPort.getName()); + } + + /** + * @return Returns the property. + */ + public String getProperty() { + return property; + } + + /** + * @param property The property to set. + */ + public void setProperty(String property) { + this.property = property; + } +} diff --git a/src/main/java/com/idcanet/foei/components/lang/package.html b/src/main/java/com/idcanet/foei/components/lang/package.html new file mode 100644 index 0000000..09a59c9 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/lang/package.html @@ -0,0 +1,55 @@ + + + + + + +Some wrappers for standaard java object.
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/logging/Log4jInput.java b/src/main/java/com/idcanet/foei/components/logging/Log4jInput.java new file mode 100644 index 0000000..cddb382 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/logging/Log4jInput.java @@ -0,0 +1,64 @@ +package com.idcanet.foei.components.logging; +/* + +package com.mbuyu.foei.handlers.log4j; + +import java.net.*; +import java.io.*; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Layout; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.Layout; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.WriterAppender; +import org.apache.log4j.net.SocketNode; + +public class RequestCollector implements Runnable { + + private Socket reqSocket; + private SocketNode reqNode; + private String host; + private int port; + static final String fileName = "rtrace"; + static final Logger logger = Logger.getLogger("RequestCollector.class"); + + public RequestCollector (int port, String host) { + super(); + this.host = host; + this.port = port; + } + + public void run() { + try { + BasicConfigurator.configure(); + PrintWriter writer = new PrintWriter (new FileWriter(fileName)); + Layout layout = new PatternLayout("%d{ABSOLUTE} %c{1} %m\n"); + WriterAppender appender = new WriterAppender(layout, writer); + appender.setImmediateFlush(true); + LogManager.getRootLogger().removeAllAppenders(); + LogManager.getRootLogger().addAppender(appender); + appender.activateOptions(); + logger.addAppender(appender); + reqSocket = new Socket(host, port); + System.out.println("Created Socket"); + reqNode = new SocketNode(reqSocket, LogManager.getLoggerRepository()); + System.out.println("Created SocketNode"); + new Thread(reqNode).start(); + System.out.println("After thread (reqNode)"); + + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e); + } + } + + public static void main (String args[]) { + System.out.println("B4 Starting"); + RequestCollector rq = new RequestCollector(9998, "some-host"); + new Thread(rq).start(); + System.out.println("Completed"); + } +} +*/ \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/logging/LoggerHandler.java b/src/main/java/com/idcanet/foei/components/logging/LoggerHandler.java new file mode 100644 index 0000000..52e3717 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/logging/LoggerHandler.java @@ -0,0 +1,64 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.logging; + +import java.util.HashMap; +import java.util.logging.Logger; +import java.util.logging.Handler; +import java.util.logging.LogRecord; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +public class LoggerHandler extends Handler { + + private Logger logger = Logger.getLogger(this.getClass().getName()); + private LoggerInput loggerInput = null; + + public LoggerHandler(LoggerInput loggerInput) { + this.loggerInput=loggerInput; + logger.addHandler(this); + } + + // ------------ handler + + public void publish(LogRecord record) { + HashMap event = new HashMap(); + event.put("message",record.getMessage()); + event.put("level",record.getLevel().getName()); + loggerInput.sendMessage(event); + } + + public void flush() { + } + + public void close() { + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/logging/LoggerInput.java b/src/main/java/com/idcanet/foei/components/logging/LoggerInput.java new file mode 100644 index 0000000..e7a1cb3 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/logging/LoggerInput.java @@ -0,0 +1,65 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.logging; + +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.AbstractEventOutput; +import com.idcanet.foei.event.EventPort; + +import java.util.Map; + +/** + * Reseives java logging messages + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +public class LoggerInput extends AbstractEventOutput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** */ + static final String OUTPUT = "output"; + + /** + * Creates an LoggerInput + * + */ + public LoggerInput() { + // define an outpur source. + addOutputPort(OUTPUT,Map.class); + new LoggerHandler(this); + } + + /** + * + * @param event + */ + public void sendMessage(Map event) { + FoeiProcessFactory.getFoeiProcess().executeEvent(getOutputPort(EventPort.OUTPUT),event); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/logging/package.html b/src/main/java/com/idcanet/foei/components/logging/package.html new file mode 100644 index 0000000..ee5a4dc --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/logging/package.html @@ -0,0 +1,55 @@ + + + + + + +Some EventObjects for log handing.
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/filters/ClassFilter.java b/src/main/java/com/idcanet/foei/components/steps/filters/ClassFilter.java new file mode 100644 index 0000000..e50112b --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/filters/ClassFilter.java @@ -0,0 +1,79 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.filters; + +import com.idcanet.foei.event.AbstractEventStepController; + +/** + * Filters an object and checks for the className. + * + * @author Willem Cazander + * @version 1.0 26/01/2005 + */ +public class ClassFilter extends AbstractEventStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** The class name to match */ + private String className = null; + + /** + * Sets the className which the filtered object has to have. + * @param className The className. + */ + public void setClassName(String className) { + this.className=className; + } + + /** + * Returns the className on which this filter filters. + * @return The className. + */ + public String getClassName() { + return className; + } + + /** + * Process an object.
+ * This checks if the objects class equals that of the className. + * @return The object or null is not succesfull. + */ + public Object processObject(Object object) { + if(object==null) { + return null; + } + Class[] classes = object.getClass().getClasses(); + for(int i=0;i0) { + return null; + } + return object; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/filters/StringFilter.java b/src/main/java/com/idcanet/foei/components/steps/filters/StringFilter.java new file mode 100644 index 0000000..efdb992 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/filters/StringFilter.java @@ -0,0 +1,150 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.filters; + +import com.idcanet.foei.event.AbstractEventStepController; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Filters an String object. + * + * @author Willem Cazander + * @version 1.0 26/01/2005 + */ +public class StringFilter extends AbstractEventStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + private int minLength=0; + private int maxLength=0; + private Pattern pattern = null; + + // -------------- (bean)properties. + + /** + * Sets the regulare expression on which this object filters an String.
+ *
+ * When set to Null matching is disabled.
+ * + * @param regex The regulare expression to match to. + */ + public void setRegEx(String regex) { + pattern = Pattern.compile(regex); + } + /** + * Returns the current regulare expression. + * @return The regulare expression. + */ + public String getRegEx() { + if(pattern==null) { + return null; + } + return pattern.pattern(); + } + + /** + * Set the minimal length the filtered object has to be.
+ *
+ * When set to -1 testing is disabled.
+ * + * @param minLength The minimal length to match. + */ + public void setMinLength(int minLength) { + this.minLength=minLength; + } + + /** + * Returns the current minimal length of this filter. + * @return The minimal length. + */ + public int getMinLength() { + return minLength; + } + + /** + * Set the maximal length of the filters string object.
+ *
+ * When set to -1 testing is disabled.
+ * + * @param maxLength + */ + public void setMaxLength(int maxLength) { + this.maxLength=maxLength; + } + + /** + * Returns the current maximal length. + * @return the maximal length. + */ + public int getMaxLength() { + return maxLength; + } + + // -------------- eventStep + + /** + * Filters an Object. + * If it not an String then null will be returned. + * Likewise when the String object has not matched to an certain + * propertie then also null will be returned. + * + * @param object The Object thats get filtered. + * @return null if object was not mached else the object returns. + */ + public Object processObject(Object object) { + + if(!(object instanceof String)) { + return null; + } + String string = (String)object; + + if(pattern==null) { + + } + + if(pattern!=null) { + // test if regex matches + Matcher m = pattern.matcher(string); + if(!m.find()) { + return null; + } + } + + // test min length + if(minLength!=0 && string.length()>minLength) { + return null; + } + // test max length + if(maxLength!=0 && string.length() + + + + + +EventSteps which filter an Object.
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/lang/GetBeanPropertyStep.java b/src/main/java/com/idcanet/foei/components/steps/lang/GetBeanPropertyStep.java new file mode 100644 index 0000000..eb9b90b --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/lang/GetBeanPropertyStep.java @@ -0,0 +1,82 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.lang; + +import com.idcanet.foei.event.AbstractEventStepController; +import com.idcanet.x4o.impl.DefaultElementParameterHelper; + +/** + * Gets the property of an java bean. + * + * @author Willem Cazander + * @version 1.0 Feb 9, 2006 + */ +public class GetBeanPropertyStep extends AbstractEventStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** Holds the key which contains the object in the map. */ + private String property = null; + + private DefaultElementParameterHelper helper = null; + + public GetBeanPropertyStep() { + helper = new DefaultElementParameterHelper(); + } + + //----------- get/set functions + + public void setProperty(String property) { + this.property=property; + } + + public String getProperty() { + return property; + } + + // -------------------- EventStep + + /** + * Proces an Object, when property is correcly found then + * it is processed by the eventSteps of the object. + */ + public Object processObject(Object object) { + if(property==null) { + return null; + } + Object result = null; + try { + result = helper.getParameter(object,property); + } catch (Exception e) { + //logger.log(Level.WARNING,"property:"+property+" is not an property of object: "+object.getClass().getName(),e); + e.printStackTrace(); + return null; + } + return processEventSteps(result); + } +} + diff --git a/src/main/java/com/idcanet/foei/components/steps/lang/ListValue.java b/src/main/java/com/idcanet/foei/components/steps/lang/ListValue.java new file mode 100644 index 0000000..86db41b --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/lang/ListValue.java @@ -0,0 +1,82 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.lang; + +import com.idcanet.foei.event.AbstractEventStepController; + +import java.util.List; + +/** + * Gets an Value out of an List + * + * @author Willem Cazander + * @version 1.0 Feb 9, 2006 + */ +public class ListValue extends AbstractEventStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** Holds the index which contains the object in the map. */ + private String index = null; + + static private final String FIRST = "FIRST"; + static private final String LAST = "LAST"; + + // bean + + public void setIndex(String index) { + this.index=index; + } + + public String getIndex() { + return index; + } + + @SuppressWarnings("unchecked") + public Object processObject(Object object) { + + if(!(object instanceof List)) { + return null; + } + List list = (List)object; + + if(FIRST.equalsIgnoreCase(index)) { + return processEventSteps(list.get(0)); + } + if(LAST.equalsIgnoreCase(index)) { + return processEventSteps(list.get(list.size())); + } + try { + int listIndex = new Integer(index); + return processEventSteps(list.get(listIndex)); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/lang/MapValue.java b/src/main/java/com/idcanet/foei/components/steps/lang/MapValue.java new file mode 100644 index 0000000..6967333 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/lang/MapValue.java @@ -0,0 +1,89 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.lang; + +import com.idcanet.foei.event.AbstractEventStepController; + +import java.util.Map; + +/** + * This EventStep can have nesting EventSteps. + * It it get the object out of the map object which is processed and + * let is process by an added EventStep object. + * + * @author Willem Cazander + * @version 1.0 28/03/2004 + */ +public class MapValue extends AbstractEventStepController { + + /** v1.0 */ + static final long serialVersionUID = 10l; + /** Holds the key which contains the object in the map. */ + private String key = null; + + + //----------- get/set functions + + /** + * Sets the key which is used to lookup an object in an Map.
+ * Which gets returned by the processObject() of EventStep.
+ * @param key The key of an object in an Map. + */ + public void setKey(String key) { + this.key=key; + } + + /** + * Gets the key of the Map. + * @return The current key. + */ + public String getKey() { + return key; + } + + + // -------------------- EventStep + + /** + * Process an object.
+ * This is done by the EventStep Object which is added.
+ *
+ * Current implementation returns only the object which is returned
+ * by the last EventStep in the List.
+ * + */ + @SuppressWarnings("unchecked") + public Object processObject(Object object) { + if(key==null) { + return null; + } + Map map = (Map)object; + object = map.get(key); + return processEventSteps(object); + } +} + diff --git a/src/main/java/com/idcanet/foei/components/steps/lang/package.html b/src/main/java/com/idcanet/foei/components/steps/lang/package.html new file mode 100644 index 0000000..e0601c5 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/lang/package.html @@ -0,0 +1,57 @@ + + + + + + +EventSteps which Gets of object from an Object.
+ +

Package Specification

+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/printers/DatePrinter.java b/src/main/java/com/idcanet/foei/components/steps/printers/DatePrinter.java new file mode 100644 index 0000000..f43bb2d --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/printers/DatePrinter.java @@ -0,0 +1,88 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.printers; + +import com.idcanet.foei.event.AbstractEventStep; + +import java.util.Date; +import java.text.SimpleDateFormat; + +/** + * Print an Date object. + * + * @author Willem Cazander + * @version 1.0 26/01/2005 + */ +public class DatePrinter extends AbstractEventStep +{ + /** v1.0 */ + static final long serialVersionUID = 10l; + /** An SimpleDateFormat formated date format template string */ + private SimpleDateFormat dateFormat=null; + + /** + * Emty constructor + */ + public DatePrinter() { + } + + /** + * Set the format in which the Date object is printed. + * @param pattern An SimpleDateFormat formatted string. + */ + public void setSimpleDateFormat(String pattern) { + // else use defaults !!! + // TODO log this event ... but don't let is stop it. + try { + dateFormat = new SimpleDateFormat(pattern); + } catch (NullPointerException npe) { + dateFormat = new SimpleDateFormat(); + } catch (IllegalArgumentException iae) { + dateFormat = new SimpleDateFormat(); + } + } + /** + * Returns the SimpleDateFormat formatted string being used to format an Date. + * @return The SimpleDateFormat string. + */ + public String getSimpleDateFormat() { + return dateFormat.toPattern(); + } + + /** + * Prints an Date object.
+ *
+ * If object is not an Date "" is printed.
+ * + * @param object The Object being printed. + * @return The String format of the object. + */ + public Object processObject(Object object) { + Date date = (Date)object; + return dateFormat.format(date); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/printers/DefaultPrinter.java b/src/main/java/com/idcanet/foei/components/steps/printers/DefaultPrinter.java new file mode 100644 index 0000000..7558a2e --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/printers/DefaultPrinter.java @@ -0,0 +1,98 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.components.steps.printers; + +import com.idcanet.foei.event.AbstractEventStep; + +/** + * Prints the toString of any java object.
+ * With an optioneal pre/post-fix.
+ * + * @author Willem Cazander + * @version 1.0 17/11/2004 + */ +public class DefaultPrinter extends AbstractEventStep +{ + /** v1.0 */ + static final long serialVersionUID = 10l; + /** The preFix */ + private String preFix = null; + /** The postFix */ + private String postFix = null; + + /** + * Sets the prefix + * @param preFix The String printed before the object. + */ + public void setPreFix(String preFix) { + this.preFix=preFix; + } + + /** + * Returns the prefix. + * @return The String printed before the object. + */ + public String getPreFix() { + return preFix; + } + + /** + * Sets the postfix. + * @param postFix The String printed after the object. + */ + public void setPostFix(String postFix) { + this.postFix=postFix; + } + + /** + * Returns the postfix. + * @return The String printed after the object. + */ + public String getPostFix() { + return postFix; + } + + /** + *This methode returns an String represantation of an object + *in the default toSting() of the object. + *@param object The object which need to be printed. + *@return The string represantation of the object. + */ + public Object processObject(Object object) { + String returnString = ""; + if(preFix!=null) { + returnString = preFix; + } + if(object!=null) { + returnString += object.toString(); + } + if(postFix!=null) { + returnString += postFix; + } + return returnString; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/components/steps/printers/package.html b/src/main/java/com/idcanet/foei/components/steps/printers/package.html new file mode 100644 index 0000000..c9b2d83 --- /dev/null +++ b/src/main/java/com/idcanet/foei/components/steps/printers/package.html @@ -0,0 +1,61 @@ + + + + + + +EventSteps which print objects
+ +

Package Specification

+ +
    +
  • Full J2SE 5 compatible
  • +
  • Small package
  • +
+ + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/EventExecutor.java b/src/main/java/com/idcanet/foei/core/EventExecutor.java new file mode 100644 index 0000000..9aa672a --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/EventExecutor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * Reuables EventExecutor wich are executed + * in the EcentExecutorManager + * + * @author Willem Cazander + * @version 1.0 Jan 19, 2006 + */ +public interface EventExecutor extends Runnable { + + /** + * Sets the foei process + * @param object + */ + public void setFoeiProcess(FoeiProcess foeiProcess); + + + /** + * Returns true when this EventExecutor is ready + * @return + */ + public boolean isReady(); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/EventExecutorManager.java b/src/main/java/com/idcanet/foei/core/EventExecutorManager.java new file mode 100644 index 0000000..cddc2d7 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/EventExecutorManager.java @@ -0,0 +1,81 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import com.idcanet.foei.event.EventPort; + +import java.util.List; + +/** + * The EventExecutionManager executes the event that + * executes the filter object flow. + * + * @author Willem Cazander + * @version 1.0 Jan 19, 2006 + */ +public interface EventExecutorManager extends EventPortExecutor { + + /** + * Executes an runnable object mostly this will be
+ * an reused EventExecutor. + * @param runnable The runnable to run. + */ + public void execute(Runnable runnable,FoeiProcess foeiProcess); + + /** + * + * @param eventPort + * @param eventObject + * @param foeiProcess + */ + public void executeEvent(EventPort eventPort,Object eventObject,FoeiProcess foeiProcess); + + /** + *Starts the EventExecutionManager + */ + public void start(FoeiContext foeiContext); + + /** + * Stops the EventExecutionManager + */ + public void stop(FoeiContext foeiContext); + + /** + * Gets all EventThreadListeners
+ * These are call when a new Thread is created or stops in the Threadpool of
+ * the EventExecutorManager.
+ * @return Returns all EventThreadListeners + */ + public List getEventThreadListeners(); + + /** + * Adds an EventThreadListener + * @param eventThreadListen er The EventThreadListener to add. + * @throws IllegalStateException When we are started we can't add listeners. + */ + public void addEventThreadListener(EventThreadListener eventThreadListener) throws IllegalStateException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/EventPortExecutor.java b/src/main/java/com/idcanet/foei/core/EventPortExecutor.java new file mode 100644 index 0000000..342f66c --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/EventPortExecutor.java @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import com.idcanet.foei.event.EventPort; + +/** + * Executecuts an executeEvent method + * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + * + */ +public interface EventPortExecutor { + + /** + * Send the EventObject to the eventPort + * @param eventObject + * @param eventPort + */ + public void executeEvent(EventPort eventPort,Object eventObject); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/EventThreadListener.java b/src/main/java/com/idcanet/foei/core/EventThreadListener.java new file mode 100644 index 0000000..57a6c04 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/EventThreadListener.java @@ -0,0 +1,49 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * With this interface its possible to inject some + * threadlocals in a foei event thread. + * + * @author Willem Cazander + * @version 1.0 Feb 22, 2006 + */ +public interface EventThreadListener { + + /** + * Gets called when a new Thread is created for the foei thread pool. + * @param foeiContext + */ + public void startThread(FoeiContext foeiContext); + + /** + * Gets callled when a thread is closed in the tread pool. + * @param foeiContext + */ + public void stopThread(FoeiContext foeiContext); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiConfigurator.java b/src/main/java/com/idcanet/foei/core/FoeiConfigurator.java new file mode 100644 index 0000000..421aeb4 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiConfigurator.java @@ -0,0 +1,83 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import com.idcanet.foei.core.impl.FoeiConfiguratorImpl; + +import java.util.Map; + +/** + * Start the FoeiContext from which foei in managed. + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2006 + */ +public interface FoeiConfigurator { + + /** The key of the foei fontext name */ + static public final String CONTEXT_NAME = "foei.context_name"; + + /** The key of the className of the ObjectBindingsManager */ + static public final String OBJECT_BINDINGS_MANAGER = "foei.object_bindings_manager"; + + /** The key of the className of the EventExecutor */ + static public final String EVENT_EXECUTOR = "foei.event_executor"; + + /** The key of the className of the EventExecutorManager */ + static public final String EVENT_EXECUTOR_MANAGER = "foei.event_executor_manager"; + + /** The key of the integer of the EventExecutor pool core size */ + static public final String EVENT_EXECUTOR_POOL_CORE_SIZE = "foei.event_executor_manager.pool_core_size"; + + /** The key of the integer of the EventExecutor pool max size */ + static public final String EVENT_EXECUTOR_POOL_MAX_SIZE = "foei.event_executor_manager.pool_max_size"; + + /** The key of the integer of the EventExecutor pool keep alive */ + static public final String EVENT_EXECUTOR_POOL_KEEP_ALIVE = "foei.event_executor_manager.pool_keep_alive"; + + /** The key of the className of the ObjectContextFactory */ + static public final String OBJECT_CONTEXT_FACTORY = "foei.initial_object_context_factory"; + + /** The key of the classNames (',' seperated) of the EventThreadListener */ + static public final String EVENT_THREAD_LISTENERS = "foei.event_thread_listeners"; + + /** The key of the className of the FoeiProcessManager */ + static public final String FOEI_PROCESS_MANAGER = "foei.process_manager"; + + /** The key of the rootTag of the X2O parser */ + static public final String X2O_ROOT_TAG = "foei.x2o_root_tag"; + + /** The default FoeiConfigurator */ + static public final Class DEFAULT_FOEI_CONFIGURATOR = FoeiConfiguratorImpl.class; + + /** + * Starts an FoeiContext + * @param properties + * @return + */ + public FoeiContext buildFoeiContext(Map properties) throws FoeiContextBuildingException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiContext.java b/src/main/java/com/idcanet/foei/core/FoeiContext.java new file mode 100644 index 0000000..80025a4 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiContext.java @@ -0,0 +1,75 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import java.util.Map; + +import javax.naming.Context; + +/** + * Defines the FoeiContext.
+ * + * @author Willem Cazander + * @version 1.0 Jan 19, 2005 + */ +public interface FoeiContext { + + /** + * Gets the name of the context. + * @return Returns the name of the context. + */ + public String getName(); + + /** + * Gets the EventObjectContext. + * @return Returns the Context + */ + public Context getEventObjectContext(); + + /** + * Gets the EventExecutorManager + * @return Returns the EventExecutorManager + */ + public EventExecutorManager getEventExecutorManager(); + + /** + * Gets the map of the start properties of this context. + * @return + */ + public Map getStartProperties(); + + /** + * Gets the FoeiProcessManager + * @return Returns the FoeiProcessManager + */ + public FoeiProcessManager getFoeiProcessManager(); + + /** + * Stops all stuff in this context + */ + public void destroy(); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiContextBuildingException.java b/src/main/java/com/idcanet/foei/core/FoeiContextBuildingException.java new file mode 100644 index 0000000..50edf8d --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiContextBuildingException.java @@ -0,0 +1,71 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * Can gets thrown when building an FoeiContext implementation object. + * + * @author Willem Cazander + * @version 1.0 Jan 24, 2006 + */ +public class FoeiContextBuildingException extends Exception +{ + /** v1.0 */ + static final long serialVersionUID = 10l; + + /** + * Constructs an FoeiContextBuildingException without a detail message. + */ + public FoeiContextBuildingException() { + super(); + } + + /** + * Constructs an FoeiContextBuildingException with a detail message. + * @param message The message of this Exception + */ + public FoeiContextBuildingException(String message) { + super(message); + } + + /** + * Creates an FoeiContextBuildingException from a parent exception and a message + * @param e The parent exception. + * @param message An detail message. + */ + public FoeiContextBuildingException(String message,Exception e) { + super(message,e); + } + + /** + * Creates an FoeiContextBuildingException from a parent exception. + * @param e The parant exception + */ + public FoeiContextBuildingException(Exception e) { + super(e); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiPortMessage.java b/src/main/java/com/idcanet/foei/core/FoeiPortMessage.java new file mode 100644 index 0000000..1756ccd --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiPortMessage.java @@ -0,0 +1,85 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import com.idcanet.foei.event.EventPort; + +/** + * Message block used in work queue to store non-immatiate port events. + * + * @author Willem Cazander + * @version 1.0 Apr 9, 2008 + */ +public class FoeiPortMessage { + + /** The event obect. */ + private Object eventObject = null; + /** The eventport */ + private EventPort eventPort = null; + + public FoeiPortMessage() { + } + + public FoeiPortMessage(Object eventObject,EventPort eventPort) { + setEventObject(eventObject); + setEventPort(eventPort); + } + + /** + * @return the eventObject + */ + public Object getEventObject() { + return eventObject; + } + + /** + * @param eventObject the eventObject to set + */ + public void setEventObject(Object eventObject) { + if (eventObject==null) { + throw new NullPointerException("May not set null eventObject"); + } + this.eventObject = eventObject; + } + + /** + * @return the eventPort + */ + public EventPort getEventPort() { + return eventPort; + } + + /** + * @param eventPort the eventPort to set + */ + public void setEventPort(EventPort eventPort) { + if (eventPort==null) { + throw new NullPointerException("May not set null eventPort"); + } + this.eventPort = eventPort; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiProcess.java b/src/main/java/com/idcanet/foei/core/FoeiProcess.java new file mode 100644 index 0000000..4c47ef5 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiProcess.java @@ -0,0 +1,80 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import java.util.Queue; +import java.util.Set; + +import javax.naming.Context; + +/** + * Defines an FoeiProcess interface
+ * The FoeiProcess is only accesable from an injected thread local.
+ * From the FoeiProcess we can bind object and fire events.
+ * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + */ +public interface FoeiProcess extends ObjectBindingsManager,ObjectContextManager,EventPortExecutor { + + /** + * Gets the name of the process. + * @return Returns the name of the process. + */ + public String getName(); + + /** + * Gets the EventObjectContext. + * @return Returns the Context + */ + public Context getEventObjectContext(); + + /** + * Gets the ObjectBindingsManager + * @return Retuns the ObjectBindingsManager + */ + public ObjectBindingsManager getObjectBindingsManager(); + + /** + * Gets the FoeiContext + * @return + */ + public FoeiContext getFoeiContext(); + + /** + * Stops all stuff in this process + */ + public void destroy(); + + /** + * Returns the work queue for this foei process + * @return + */ + public Queue getWorkQueue(); + + public Set getExecutors(); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiProcessFactory.java b/src/main/java/com/idcanet/foei/core/FoeiProcessFactory.java new file mode 100644 index 0000000..721a37b --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiProcessFactory.java @@ -0,0 +1,72 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * This is the only class of the core which is hardcoded.
+ * It retreives the FoeiProcess from the ThreadLocal. + * which is set in the EventExecutor + * + * @author Willem Cazander + * @version 1.0 Feb 2, 2006 + */ +public class FoeiProcessFactory { + + /** The threadlocal storing the FoeiProcess */ + private static final ThreadLocal threadLocal = new ThreadLocal(); + + /** + * Gets the FoeiProcess for the current thread. + * @return Returns the FoeiProcess for the current thread. + * @throws IllegalStateException When no FoeiProcess is set in the current Thread. + */ + static public FoeiProcess getFoeiProcess() { + FoeiProcess foeiProcess = (FoeiProcess)threadLocal.get(); + if(foeiProcess==null) { + throw new IllegalStateException("No FoeiProcess set in current thread ThreadLocal"); + } + return foeiProcess; + } + + /** + * Binds an FoeiProcess to the currentThread. + * @param foeiContext The FoeiProcess to bind. + */ + static public void bindFoeiProcess(FoeiProcess foeiProcess) { + threadLocal.set(foeiProcess); + } + + /** + * Unbinds the current FoeiProcess. + */ + static public void unbindFoeiProcess() { + if(threadLocal.get()==null) { + throw new NullPointerException("Can't unbind from an non binded thread."); + } + threadLocal.set(null); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiProcessListener.java b/src/main/java/com/idcanet/foei/core/FoeiProcessListener.java new file mode 100644 index 0000000..3f989c7 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiProcessListener.java @@ -0,0 +1,42 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * Gets called when process is created or destroyed.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public interface FoeiProcessListener { + + public void foeiProcessCreated(FoeiProcess process); + + public void foeiProcessDestroyed(FoeiProcess process); + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/FoeiProcessManager.java b/src/main/java/com/idcanet/foei/core/FoeiProcessManager.java new file mode 100644 index 0000000..b5b7eb0 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/FoeiProcessManager.java @@ -0,0 +1,70 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import java.util.Collection; + +/** + * The FoeiProcessManager manages all the FoeiProcesses + * which are running in the FoeiContext. + * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + */ +public interface FoeiProcessManager { + + /** + * Creates an new FoeiProcess. + * @param name The name of the process + * @param foeiContext The FoeiContext + * @return Returns an FoeiProcess + */ + public FoeiProcess createFoeiProcess(String name,FoeiContext foeiContext); + + /** + * destroy a FoeiProcess by its name. + * @param name + */ + public void destroyFoeiProcess(String name); + + /** + * Gets an FoeiProcess by its id. + * @param name + * @return Returns an FoeiProcess + */ + public FoeiProcess getFoeiProcess(String name); + + /** + * Gets all running FoeiProcess'es + * @return + */ + public Collection getFoeiProcesses(); + + public void addFoeiProcessListener(FoeiProcessListener foeiProcessListener); + + public void removeFoeiProcessListener(FoeiProcessListener foeiProcessListener); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/ObjectBindingsManager.java b/src/main/java/com/idcanet/foei/core/ObjectBindingsManager.java new file mode 100644 index 0000000..69c42df --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/ObjectBindingsManager.java @@ -0,0 +1,67 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import com.idcanet.foei.event.EventPort; + +import java.util.List; + +/** + * Manages all the Foei EventPort bindings. + * + * @author Willem Cazander + * @version 1.0 1/05/2005 + */ +public interface ObjectBindingsManager { + + /** + * Adds an binding from the input to the output EventPort. + * @param outputPort The output EventPort + * @param inputPort The input EventPort + */ + public void addBinding(EventPort outputPort,EventPort inputPort); + + /** + * Removes an binding. + * @param inputPort The input EventPort. + * @param outputPort The output EventPort. + */ + public void removeBinding(EventPort inputPort,EventPort outputPort); + + /** + * Gets the bindings of an EventPort + * @param eventPort The EventPort to retreive the bindings. + * @return Returns an List of the binded EventPorts + */ + public List getBindings(EventPort eventPort); + + /** + * Returns the bindings in an xml format to render with dotty. + * @return + */ + public String getBindingsAsXML(); +} diff --git a/src/main/java/com/idcanet/foei/core/ObjectContextManager.java b/src/main/java/com/idcanet/foei/core/ObjectContextManager.java new file mode 100644 index 0000000..9c51969 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/ObjectContextManager.java @@ -0,0 +1,56 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +/** + * ObjectContextManager makes it possible to get and set objects + * + * + * @author Willem Cazander + * @version 1.0 Jan 19, 2005 + */ +public interface ObjectContextManager { + + /** + * Adds an EventObject to the Context + * @param eventObject + */ + public void addEventObject(Object eventObject,String id); + + /** + * removes an EventObject from the Context + * @param eventObject + */ + public void removeEventObject(String id); + + /** + * Gets an EventObject by its id. + * @param id + * @return + */ + public Object getEventObject(String id); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/X2OExecutor.java b/src/main/java/com/idcanet/foei/core/X2OExecutor.java new file mode 100644 index 0000000..0bd02db --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/X2OExecutor.java @@ -0,0 +1,62 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core; + +import java.io.InputStream; + +/** + * Executes an X2O script. + * + * @author Willem Cazander + * @version 1.0 Feb 24, 2006 + */ +public interface X2OExecutor extends Runnable { + + /** + * Sets the fileName to parse. + * @param fileName + */ + public void setFileName(String fileName); + + /** + * Sets the inputStream to parse. + * @param inputStream + */ + public void setInputStream(InputStream inputStream); + + /** + * Sets the xml to parse. + * @param xml + */ + public void setXml(String xml); + + /** + * Returns true when this X2OExecutor is ready + * @return + */ + public boolean isReady(); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/EventExecutorImpl.java b/src/main/java/com/idcanet/foei/core/impl/EventExecutorImpl.java new file mode 100644 index 0000000..be1b041 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/EventExecutorImpl.java @@ -0,0 +1,148 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.EventExecutor; +import com.idcanet.foei.core.FoeiPortMessage; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.IllegalEventPortNameException; + +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Reuable EventExecutors + * + * @author Willem Cazander + * @version 1.0 Jan 19, 2006 + */ +public class EventExecutorImpl implements EventExecutor { + + /** The logger to log to. */ + private Logger logger = null; + /** The foei process to execute for */ + private FoeiProcess foeiProcess = null; + /** True when ready */ + private volatile boolean ready = false; + + /** + * Creates an EventExecutor + */ + public EventExecutorImpl() { + logger = Logger.getLogger(EventExecutorImpl.class.getName()); + } + + /** + * @see EventExecutor#setEventObject(Object) + */ + public void setFoeiProcess(FoeiProcess foeiProcess) { + this.foeiProcess=foeiProcess; + } + + /** + * @see EventExecutor#isReady() + */ + public boolean isReady() { + return ready; + } + + /** + * @see Runnable#run() + */ + public void run() { + if(foeiProcess==null) { + logger.warning("Can't execute event on null foeiProcess."); + return; + } + ready = false; + int processed = 0; + try { + FoeiProcessFactory.bindFoeiProcess(foeiProcess); + + FoeiPortMessage msg = foeiProcess.getWorkQueue().poll(); + while (msg!=null) { + process(msg); + processed++; + msg = foeiProcess.getWorkQueue().poll(); + + // try 3 times to get new work, if not found then exit, EventExecutorManagerImpl work auto create new EventExecutor on new work. + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + if (msg==null) { + Thread.sleep(200); + msg = foeiProcess.getWorkQueue().poll(); + } + } + } catch (Exception e) { + logger.log(Level.WARNING,"Error while Executing Event",e); + } finally { + ready = true; + FoeiProcessFactory.unbindFoeiProcess(); + foeiProcess.getExecutors().remove(this); + logger.info(Thread.currentThread().getName()+"--"+this.toString()+" executed: "+processed); + } + } + + private void process(FoeiPortMessage msg) throws IllegalEventPortNameException { + EventPort eventPort = msg.getEventPort(); + Object eventObject = msg.getEventObject(); + + if(eventPort.getEventPortType()==EventPortType.input) { + EventInput eventInput = (EventInput)eventPort.getEventObject(); + eventPort.addEventsPassed(); // inc input port + eventInput.doEvent(eventPort,eventObject); + return; + } + if(eventPort.getEventPortType()==EventPortType.output) { + eventPort.addEventsPassed(); // inc output port + + List bindings = foeiProcess.getBindings(eventPort); + for (int i=0;i eventThreadListeners = null; + /** The class for the EventExecutor */ + private Class eventExecutorClass = null; + /** + * Creates an EventExecutorManagerImpl ans inits the logger. + */ + public EventExecutorManagerImpl() { + logger = Logger.getLogger(EventExecutorManagerImpl.class.getName()); + eventThreadListeners = new ArrayList(1); + } + + // ============= EventExecutorManager + + /** + * Executes an Event mostly send from an EventObject. + * @see EventExecutorManager#executeEvent(Object, EventPort) + */ + public void executeEvent(EventPort eventPort,Object eventObject) { + executeEvent(eventPort,eventObject,FoeiProcessFactory.getFoeiProcess()); + } + + /** + * Executes an EventPort with object in an FoeiProcess. + * @param eventPort + * @param eventObject + * @param foeiProcess + */ + public void executeEvent(EventPort eventPort,Object eventObject,FoeiProcess foeiProcess) { + + FoeiPortMessage msg = new FoeiPortMessage(); + msg.setEventObject(eventObject); + msg.setEventPort(eventPort); + foeiProcess.getWorkQueue().add(msg); + + if (foeiProcess.getExecutors().size()>3) { + return; + } + + EventExecutor e = null; + try { + e = (EventExecutor)eventExecutorClass.newInstance(); + } catch (Exception ee) { + logger.log(Level.WARNING,"Error Creating EventExecutor: "+ee.getMessage(),ee); + return; + } + e.setFoeiProcess(foeiProcess); + foeiProcess.getExecutors().add(e); // else to much will be created on 1st X objects. + threadPoolExecutor.execute(e); + } + + /** + * Executes an event. + * @see EventExecutorManager#execute(Runnable) + */ + public void execute(Runnable runnable,FoeiProcess foeiProcess) { + if(threadPoolExecutor==null) { + throw new IllegalStateException("EventExecutorManager has not been started."); + } + threadPoolExecutor.execute(new FoeiProcessRunnableWrapper(runnable,foeiProcess)); + } + + /** + * Starts the ThreadPool + * @see EventExecutorManager#start() + */ + public void start(FoeiContext foeiContext) { + if(foeiContext==null) { + throw new NullPointerException("FoeiContext may not be null."); + } + logger.info("Starting EventExecutorManagerImpl"); + + try { + eventExecutorClass = FoeiConfiguratorImpl.newEventExecutorClass(foeiContext.getStartProperties()); + } catch (ClassNotFoundException cce) { + logger.log(Level.WARNING,"Error getting eventExecutor class: "+cce.getMessage(),cce); + throw new RuntimeException("Could not get EventExecutor class: "+cce.getMessage(),cce); + } + + EventExecutorThreadFactory tf = new EventExecutorThreadFactory(foeiContext); + ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor ( + FoeiConfiguratorImpl.getEventExecutorPoolCoreSize(foeiContext.getStartProperties()), + FoeiConfiguratorImpl.getEventExecutorPoolMaxSize(foeiContext.getStartProperties()), + FoeiConfiguratorImpl.getEventExecutorPoolKeepAlive(foeiContext.getStartProperties()), + TimeUnit.SECONDS, + new LinkedBlockingQueue(), + tf + ); + threadPoolExecutor.prestartAllCoreThreads(); + setThreadPoolExecutor(threadPoolExecutor); + } + + /** + * Stops the ThreadPool + * @see EventExecutorManager#stop() + */ + public void stop(FoeiContext foeiContext) { + if(threadPoolExecutor==null) { + throw new IllegalStateException("EventExecutorManager has not been started."); + } + logger.info("Stoping EventExecutorManagerImpl"); + threadPoolExecutor.shutdown(); + threadPoolExecutor=null; + } + + /** + * @see EventExecutorManager#getEventThreadListeners() + */ + public List getEventThreadListeners() { + return eventThreadListeners; + } + + /** + * @see EventExecutorManager#addEventThreadListener(EventThreadListener) + */ + public void addEventThreadListener(EventThreadListener eventThreadListener) throws IllegalStateException { + if(eventThreadListener==null) { + throw new NullPointerException("eventThreadListener may not be null."); + } + if(threadPoolExecutor!=null) { + throw new IllegalStateException("threadPoolExecutor is already started."); + } + eventThreadListeners.add(eventThreadListener); + } + + // ========== other methods: + + /** + * Can be used when override from this class. + * note: + * This method is not an interface method. + * @param threadPoolExecutor + */ + public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) { + if(this.threadPoolExecutor!=null) { + throw new IllegalStateException("ThreadPoolExecutor may only be set once"); + } + this.threadPoolExecutor=threadPoolExecutor; + } + + /** + * Returns the ThreadPoolExecutor + */ + public ThreadPoolExecutor getThreadPoolExecutor() { + if(threadPoolExecutor==null) { + throw new IllegalStateException("EventExecutorManager has not been started."); + } + return threadPoolExecutor; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/EventExecutorThreadFactory.java b/src/main/java/com/idcanet/foei/core/impl/EventExecutorThreadFactory.java new file mode 100644 index 0000000..59b4921 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/EventExecutorThreadFactory.java @@ -0,0 +1,91 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.FoeiContext; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Logger; + +/** + * Creates Thread for the threadpool and injects the threadpool runnable object with the + * FoeiContext. + * + * @author Willem Cazander + * @version 1.0 Feb 7, 2006 + */ +public class EventExecutorThreadFactory implements ThreadFactory { + + /** The pool number. */ + static private final AtomicInteger poolNumber = new AtomicInteger(1); + /** The thread group. */ + private final ThreadGroup group; + /** The thread number. */ + private final AtomicInteger threadNumber = new AtomicInteger(1); + /** The name prefix. */ + private String namePrefix = null; + /** The FoeiContext to wrap in the thread. */ + private FoeiContext foeiContext = null; + /** The logger to log to. */ + private Logger logger = null; + + /** + * Creates an EventExecutorThreadFactory + * @param foeiContext + */ + public EventExecutorThreadFactory(FoeiContext foeiContext) { + if(foeiContext==null) { + throw new NullPointerException("FoeiContext may not be null."); + } + logger = Logger.getLogger(EventExecutorThreadFactory.class.getName()); + this.foeiContext=foeiContext; + SecurityManager s = System.getSecurityManager(); + group = (s != null)? s.getThreadGroup():Thread.currentThread().getThreadGroup(); + namePrefix = "foei"+poolNumber.getAndIncrement()+"-"+foeiContext.getName()+"-"; + } + + /** + * Creates an new Thread and wrappes the Runnable with the FoeiContextRunnableWrapper + */ + public Thread newThread(Runnable r) { + Runnable runnable = new EventThreadListenersRunnableWrapper(r,foeiContext); + Thread t = new Thread(group,runnable,namePrefix+threadNumber.getAndIncrement(),0); + logger.info("Created new Executor Thread: "+t.getName()); + if (t.isDaemon()) { + t.setDaemon(false); + } + if (t.getPriority() != Thread.NORM_PRIORITY) { + t.setPriority(Thread.NORM_PRIORITY); + } + return t; + } +} + + + + diff --git a/src/main/java/com/idcanet/foei/core/impl/EventThreadListenersRunnableWrapper.java b/src/main/java/com/idcanet/foei/core/impl/EventThreadListenersRunnableWrapper.java new file mode 100644 index 0000000..d4b1e65 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/EventThreadListenersRunnableWrapper.java @@ -0,0 +1,75 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.EventThreadListener; +import com.idcanet.foei.core.FoeiContext; + +/** + * Call all EventTheadListeners of an FoeiContext + * + * @author Willem Cazander + * @version 1.0 Feb 8, 2006 + */ +public class EventThreadListenersRunnableWrapper implements Runnable { + + /** The wrapped runnable object. */ + private Runnable runnable = null; + /** The FoeiContext for this thread. */ + private FoeiContext foeiContext = null; + + /** + * creates an EventThreadListenersRunnableWrapper + * @param runnable + * @param foeiContext + */ + public EventThreadListenersRunnableWrapper(Runnable runnable,FoeiContext foeiContext) { + if(runnable==null) { + throw new NullPointerException("runnable may not be null."); + } + if(foeiContext==null) { + throw new NullPointerException("FoeiContext may not be null."); + } + this.runnable=runnable; + this.foeiContext=foeiContext; + } + + /** + * Call all EventThreadListeners + */ + public void run() { + for(EventThreadListener eth:foeiContext.getEventExecutorManager().getEventThreadListeners()) { + eth.startThread(foeiContext); + } + // Executer the runnable object we wrapped. + // this is the runnable executor of the default thread pool in java 1.5 + runnable.run(); + for(EventThreadListener eth:foeiContext.getEventExecutorManager().getEventThreadListeners()) { + eth.stopThread(foeiContext); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java b/src/main/java/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java new file mode 100644 index 0000000..5b0a194 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiConfiguratorImpl.java @@ -0,0 +1,263 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.EventExecutorManager; +import com.idcanet.foei.core.EventThreadListener; +import com.idcanet.foei.core.FoeiConfigurator; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiContextBuildingException; +import com.idcanet.foei.core.FoeiProcessManager; +import com.idcanet.foei.core.ObjectBindingsManager; +import com.idcanet.foei.utils.jndi.MemoryContextFactory; + +import java.util.Hashtable; +import java.util.Map; +import java.util.logging.Logger; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.spi.InitialContextFactory; + +/** + * Creates an default implemention an of FoeiContext. + * Which is config with the objects. + * + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2006 + */ +public class FoeiConfiguratorImpl implements FoeiConfigurator { + + static private Logger logger = Logger.getLogger(FoeiConfiguratorImpl.class.getName()); + + /** + * Creates an FoeiContext + */ + public FoeiContext buildFoeiContext(Map properties) throws FoeiContextBuildingException { + + if(properties==null) { + throw new NullPointerException("properties may not be null."); + } + String name = getContextName(properties); + Context objectContext = null; + EventExecutorManager eventExecutorManager = null; + FoeiProcessManager foeiProcessManager = null; + + try { + objectContext = newContext(properties); + eventExecutorManager = newEventExecutorManager(properties); + foeiProcessManager = newFoeiProcessManager(properties); + loadEventThreadListeners(properties,eventExecutorManager); + } catch (Exception e) { + throw new FoeiContextBuildingException("Error while building childs objects:",e); + } + return new FoeiContextImpl(name,objectContext,eventExecutorManager,properties,foeiProcessManager); + } + + /** + * Gets the contextName from the properties map. + * @param properties The properties map. + * @return Returns the contextName from the properties map. + */ + static public String getContextName(Map properties) { + String contextName = properties.get(FoeiConfigurator.CONTEXT_NAME); + if(contextName==null) { + throw new NullPointerException("contextName needs to be set in properties as: "+FoeiConfigurator.CONTEXT_NAME); + } + return contextName; + } + + /** + * + * @param properties + * @return + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + */ + static public ObjectBindingsManager newObjectBindingsManager(Map properties) throws ClassNotFoundException,InstantiationException, IllegalAccessException { + String className = properties.get(FoeiConfigurator.OBJECT_BINDINGS_MANAGER); + if(className==null) { + return new ObjectBindingsManagerImpl(); + } + return (ObjectBindingsManager)loadClass(className).newInstance(); + } + + /** + * + * @param properties + * @return + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws NamingException + */ + static public Context newContext(Map properties) throws ClassNotFoundException,InstantiationException, IllegalAccessException,NamingException { + String className = properties.get(FoeiConfigurator.OBJECT_CONTEXT_FACTORY); + if(className==null) { + return new MemoryContextFactory().getInitialContext(new Hashtable(properties)); + } + return ((InitialContextFactory)loadClass(className).newInstance()).getInitialContext(new Hashtable(properties)); + } + + /** + * + * @param properties + * @return + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + */ + static public EventExecutorManager newEventExecutorManager(Map properties) throws ClassNotFoundException,InstantiationException, IllegalAccessException { + String className = properties.get(FoeiConfigurator.EVENT_EXECUTOR_MANAGER); + if(className==null) { + return new EventExecutorManagerImpl(); + } + return (EventExecutorManager)loadClass(className).newInstance(); + } + + /** + * Loads and adds all the EventThreadListener. + * @param properties + * @param eventExecutorManager + * @throws Exception + */ + static public void loadEventThreadListeners(Map properties,EventExecutorManager eventExecutorManager) throws Exception { + String classNames = properties.get(FoeiConfigurator.EVENT_THREAD_LISTENERS); + if(classNames==null) { + logger.finer("No EventThreadListeners loading"); + return; + } + for(String className:classNames.split(",")) { + logger.finest("Loading class: "+className); + EventThreadListener eventThreadListener = (EventThreadListener)loadClass(className).newInstance(); + eventExecutorManager.addEventThreadListener(eventThreadListener); + } + } + + /** + * Gets the Pool Core Size for the EventExecutor + * @param properties + * @return + * @throws NumberFormatException + */ + static public Integer getEventExecutorPoolCoreSize(Map properties) throws NumberFormatException { + String size = properties.get(FoeiConfigurator.EVENT_EXECUTOR_POOL_CORE_SIZE); + if(size==null) { + return 3; + } + return new Integer(size); + } + + /** + * Gets the Pool Max Size for the EventExecutor + * @param properties + * @return + * @throws NumberFormatException + */ + static public Integer getEventExecutorPoolMaxSize(Map properties) throws NumberFormatException { + String size = properties.get(FoeiConfigurator.EVENT_EXECUTOR_POOL_MAX_SIZE); + if(size==null) { + return 5; + } + return new Integer(size); + } + + /** + * Gets the Pool Keep Alive Time in second for the EventExecutor + * @param properties + * @return + * @throws NumberFormatException + */ + static public Integer getEventExecutorPoolKeepAlive(Map properties) throws NumberFormatException { + String size = properties.get(FoeiConfigurator.EVENT_EXECUTOR_POOL_KEEP_ALIVE); + if(size==null) { + return 180; + } + return new Integer(size); + } + + /** + * Creates an new EventExecutor class + * @param properties + * @return + * @throws ClassNotFoundException + */ + static public Class newEventExecutorClass(Map properties) throws ClassNotFoundException { + String className = properties.get(FoeiConfigurator.EVENT_EXECUTOR); + if(className==null) { + return EventExecutorImpl.class; + } + return loadClass(className); + } + + /** + * Gets the X2O root tag + * @param properties + * @return The X2ORootTag + */ + static public String getX2ORootTag(Map properties) { + String rootTag = properties.get(FoeiConfigurator.X2O_ROOT_TAG); + if(rootTag==null) { + return "foei"; + } + return rootTag; + } + + /** + * + * @param properties + * @return + * @throws ClassNotFoundException + * @throws InstantiationException + * @throws IllegalAccessException + */ + static public FoeiProcessManager newFoeiProcessManager(Map properties) throws ClassNotFoundException,InstantiationException, IllegalAccessException { + String className = properties.get(FoeiConfigurator.FOEI_PROCESS_MANAGER); + if(className==null) { + return new FoeiProcessManagerImpl(); + } + return (FoeiProcessManager)loadClass(className).newInstance(); + } + + + /** + * Loads a Class from the ContextClassLoader and if that is not set, then + * uses the class of the String parameters + * @param className The class name to load + * @return The loaded class + * @throws Exception throws exception if class not loaded. + */ + static public Class loadClass(String className) throws ClassNotFoundException { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + if (cl == null) { + cl = className.getClass().getClassLoader(); // fallback + } + return cl.loadClass(className); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiContextImpl.java b/src/main/java/com/idcanet/foei/core/impl/FoeiContextImpl.java new file mode 100644 index 0000000..e5a5c91 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiContextImpl.java @@ -0,0 +1,135 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.EventExecutorManager; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiProcessManager; + +import java.util.Map; +import javax.naming.Context; + +/** + * Defines the FoeiContext implemention. + * + * @see FoeiContext + * @author Willem Cazander + * @version 1.0 Jan 19, 2006 + */ +public class FoeiContextImpl implements FoeiContext { + + /** The name of this Instance **/ + private String name = null; + + /** The FoeiContext where all objects are stored. **/ + private Context objectContext = null; + + /** The EventExecutorManager */ + private EventExecutorManager eventExecutorManager = null; + + /** The start properties */ + private Map startProperties = null; + + /** The FoeiProcessManager */ + private FoeiProcessManager foeiProcessManager = null; + + /** + * Creates an new FoeiContextImpl + * + * @param name + * @param rootPath + * @param objectBindingsManager + * @param objectContext + * @param eventExecutorManager + * @param startProperties + */ + public FoeiContextImpl(String name,Context objectContext,EventExecutorManager eventExecutorManager,Map startProperties,FoeiProcessManager foeiProcessManager) { + + if(name==null) { + throw new NullPointerException("name may not be null."); + } + if(objectContext==null) { + throw new NullPointerException("objectContext may not be null."); + } + if(eventExecutorManager==null) { + throw new NullPointerException("eventExecutorManager may not be null."); + } + if(foeiProcessManager==null) { + throw new NullPointerException("foeiProcessManager may not be null."); + } + + this.name=name; + this.objectContext=objectContext; + this.eventExecutorManager=eventExecutorManager; + this.startProperties=startProperties; + this.foeiProcessManager=foeiProcessManager; + eventExecutorManager.start(this); + } + + /** + * @see FoeiContext#getName() + */ + public String getName() { + return name; + } + + /** + * @see FoeiContext#getEventExecutorManager() + */ + public EventExecutorManager getEventExecutorManager() { + return eventExecutorManager; + } + + /** + * @see FoeiContext#getEventObjectContext() + */ + public Context getEventObjectContext() { + return objectContext; + } + + /** + * @see FoeiContext#getStartProperties() + */ + public Map getStartProperties() { + return startProperties; + } + + /** + * @see FoeiContext#destroy() + */ + public void destroy() { + getEventExecutorManager().stop(this); + } + + /** + * Gets the FoeiProcessManager + * @return Returns the FoeiProcessManager + */ + public FoeiProcessManager getFoeiProcessManager() { + return foeiProcessManager; + } +} diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiEventBindingRuleHandler.java b/src/main/java/com/idcanet/foei/core/impl/FoeiEventBindingRuleHandler.java new file mode 100644 index 0000000..29a8daf --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiEventBindingRuleHandler.java @@ -0,0 +1,79 @@ + + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.EventStepController; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementBindingException; +import com.idcanet.x4o.element.ElementBindingHandler; + +/** + * + * MM maybe move this class + * + * @author Willem Cazander + * @version 1.0 Feb 24, 2006 + */ +public class FoeiEventBindingRuleHandler implements ElementBindingHandler { + + /** + * + * @param object1 + * @param object2 + * @return + */ + public boolean canBind(Element element) { + Object parent = element.getParent().getElementObject(); + Object child = element.getElementObject(); + + Object object1 = parent; + Object object2 = child; // is correct ?? + if(object1==null) { + throw new NullPointerException("object1 may not be null."); + } + if(object2==null) { + throw new NullPointerException("object2 may not be null."); + } + if(object1 instanceof EventInput) { + if(object2 instanceof EventOutput) { + return true; + } + } + if(object1 instanceof EventOutput) { + if(object2 instanceof EventInput) { + return true; + } + } + if(object1 instanceof EventStep) { + if(object2 instanceof EventStepController) { + return true; + } + } + if(object1 instanceof EventStepController) { + if(object2 instanceof EventStep) { + return true; + } + } + return false; + } + + /** + * + * @param object1 + * @param object2 + * @throws ClassCastException + */ + public void doBind(Element element) throws ElementBindingException { + Object parent = element.getParent().getElementObject(); + Object child = element.getElementObject(); + if(parent==null) { + throw new NullPointerException("object1 may not be null."); + } + if(child==null) { + throw new NullPointerException("object2 may not be null."); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiProcessImpl.java b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessImpl.java new file mode 100644 index 0000000..35b71cd --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessImpl.java @@ -0,0 +1,206 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.EventExecutor; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiPortMessage; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.ObjectBindingsManager; +import com.idcanet.foei.event.EventPort; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.naming.Context; +import javax.naming.NameAlreadyBoundException; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; + +/** + * Defines the default FoeiProcess implementation + * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + */ +public class FoeiProcessImpl implements FoeiProcess { + + /** The FoeiContext */ + private FoeiContext foeiContext = null; + /** The Logger */ + private Logger logger = null; + /** The name */ + private String name = null; + /** The eventObjectContext */ + private Context eventObjectContext = null; + /** The ObjectBindingsManager */ + private ObjectBindingsManager objectBindingsManager = null; + + private Queue foeiPortMessages = new LinkedBlockingQueue(); + + private Set eventExecutors = Collections.synchronizedSet(new HashSet(10)); + + public FoeiProcessImpl(String name,FoeiContext foeiContext,Context eventObjectContext,ObjectBindingsManager objectBindingsManager) { + logger = Logger.getLogger(FoeiProcessImpl.class.getName()); + this.name=name; + this.foeiContext=foeiContext; + this.eventObjectContext=eventObjectContext; + this.objectBindingsManager=objectBindingsManager; + logger.info("Creating FoeiProcess: "+getName()); + } + + // ========= FoeiProcess + + /** + * @see com.idcanet.foei.core.FoeiProcess#getName() + */ + public String getName() { + return name; + } + + /** + * @see com.idcanet.foei.core.FoeiProcess#getEventObjectContext() + */ + public Context getEventObjectContext() { + return eventObjectContext; + } + + /** + * @see com.idcanet.foei.core.FoeiProcess#getObjectBindingsManager() + */ + public ObjectBindingsManager getObjectBindingsManager() { + return objectBindingsManager; + } + + /** + * @see com.idcanet.foei.core.FoeiProcess#destroy() + */ + public void destroy() { + logger.info("Destroying FoeiProcess: "+getName()); + } + + /** + * @see com.idcanet.foei.core.FoeiProcess#getFoeiContext() + */ + public FoeiContext getFoeiContext() { + return foeiContext; + } + + public Queue getWorkQueue() { + return foeiPortMessages; + } + + public Set getExecutors() { + return eventExecutors; + } + + // ================== EventPortExecutor + + /** + * @see com.idcanet.foei.core.EventPortExecutor#executeEvent(com.idcanet.foei.event.EventPort, java.lang.Object) + */ + public void executeEvent(EventPort eventPort, Object eventObject) { + getFoeiContext().getEventExecutorManager().executeEvent(eventPort,eventObject); + } + + // ============= ObjectContextManager + + /** + * @see com.idcanet.foei.core.ObjectContextManager#addEventObject(com.idcanet.foei.event.EventObject) + */ + public void addEventObject(Object eventObject,String id) { + try { + getEventObjectContext().bind(id,eventObject); + } catch (NameAlreadyBoundException nabe) { + logger.log(Level.WARNING,"NameAlreadyBoundException: "+nabe.getMessage(),nabe); + } catch (NamingException ne) { + logger.log(Level.WARNING,"NamingException: "+ne.getMessage(),ne); + } + } + + /** + * @see com.idcanet.foei.core.ObjectContextManager#getEventObject(java.lang.String) + */ + public Object getEventObject(String id) { + try { + return getEventObjectContext().lookup(id); + } catch (NamingException ne) { + logger.log(Level.WARNING,"NamingException: "+ne.getMessage(),ne); + } + return null; + } + + /** + * @see com.idcanet.foei.core.ObjectContextManager#removeEventObject(com.idcanet.foei.event.EventObject) + */ + public void removeEventObject(String id) { + try { + getEventObjectContext().unbind(id); + } catch (NameNotFoundException nnfe) { + logger.log(Level.WARNING,"NamingNotFoundException: "+nnfe.getMessage(),nnfe); + } catch (NamingException ne) { + logger.log(Level.WARNING,"NamingException: "+ne.getMessage(),ne); + } + } + + + // ============ ObjectBindingsManager + + /** + * @see com.idcanet.foei.core.ObjectBindingsManager#addBinding(com.idcanet.foei.event.EventPort, com.idcanet.foei.event.EventPort) + */ + public void addBinding(EventPort outputPort, EventPort inputPort) { + getObjectBindingsManager().addBinding(outputPort,inputPort); + } + + /** + * @see com.idcanet.foei.core.ObjectBindingsManager#getBindings(com.idcanet.foei.event.EventPort) + */ + public List getBindings(EventPort eventPort) { + return getObjectBindingsManager().getBindings(eventPort); + } + + /** + * @see com.idcanet.foei.core.ObjectBindingsManager#getBindingsAsXML() + */ + public String getBindingsAsXML() { + return getObjectBindingsManager().getBindingsAsXML(); + } + + /** + * @see com.idcanet.foei.core.ObjectBindingsManager#removeBinding(com.idcanet.foei.event.EventPort, com.idcanet.foei.event.EventPort) + */ + public void removeBinding(EventPort inputPort, EventPort outputPort) { + getObjectBindingsManager().removeBinding(inputPort,outputPort); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java new file mode 100644 index 0000000..7b735e7 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessManagerImpl.java @@ -0,0 +1,152 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessListener; +import com.idcanet.foei.core.FoeiProcessManager; +import com.idcanet.foei.core.ObjectBindingsManager; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.naming.Context; + +/** + * Defines the default FoeiProcessManager implementation + * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + */ +public class FoeiProcessManagerImpl implements FoeiProcessManager { + + /** Stores all foeiProcesses */ + private Map foeiProcesses = null; + /** The logger to log to. */ + private Logger logger = null; + + private List foeiProcessListeners = null; + + /** + * Creates an FoeiProcessManagerImpl + */ + public FoeiProcessManagerImpl() { + logger = Logger.getLogger(FoeiProcessManagerImpl.class.getName()); + foeiProcesses = new HashMap(5); + foeiProcessListeners = new ArrayList(5); + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#createFoeiProcess(java.lang.String, FoeiContext) + */ + public FoeiProcess createFoeiProcess(String name,FoeiContext foeiContext) { + if(name==null) { + throw new NullPointerException("name may not be null."); + } + if(foeiContext==null) { + throw new NullPointerException("foeiContext may not be null."); + } + try { + Context c = foeiContext.getEventObjectContext().createSubcontext(name); + ObjectBindingsManager objectBindingsManager = FoeiConfiguratorImpl.newObjectBindingsManager(foeiContext.getStartProperties()); + FoeiProcess fp = new FoeiProcessImpl(name,foeiContext,c,objectBindingsManager); + synchronized (foeiProcesses) { + foeiProcesses.put(fp.getName(),fp); + } + for (FoeiProcessListener l:foeiProcessListeners) { + l.foeiProcessCreated(fp); + } + + logger.finer("FoeiProcess created and added total processes: "+foeiProcesses.size()); + return fp; + } catch (Exception e) { + logger.log(Level.WARNING,"Error whiile creating FoeiProcess: "+e.getMessage(),e); + return null; + } + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#destroyFoeiProcess(java.lang.String) + */ + public void destroyFoeiProcess(String name) { + FoeiProcess p = getFoeiProcess(name); + if(p==null) { + throw new NullPointerException("No FoeiProcess found with id: "+name); + } + p.destroy(); + synchronized (foeiProcesses) { + foeiProcesses.remove(p.getName()); + } + for (FoeiProcessListener l:foeiProcessListeners) { + l.foeiProcessDestroyed(p); + } + logger.finer("FoeiProcess destroyed total processes: "+foeiProcesses.size()); + try { + p.getFoeiContext().getEventObjectContext().destroySubcontext(p.getName()); + } catch (Exception e) { + logger.log(Level.WARNING,"Error while removing process context from foei context; "+e.getMessage(),e); + } + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#getFoeiProcess(java.lang.String) + */ + public FoeiProcess getFoeiProcess(String name) { + if(name==null) { + throw new NullPointerException("name may not be null."); + } + return foeiProcesses.get(name); + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#getFoeiProcesses() + */ + public Collection getFoeiProcesses() { + return foeiProcesses.values(); + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#addFoeiProcessListener(com.idcanet.foei.core.FoeiProcessListener) + */ + public void addFoeiProcessListener(FoeiProcessListener foeiProcessListener) { + foeiProcessListeners.add(foeiProcessListener); + } + + /** + * @see com.idcanet.foei.core.FoeiProcessManager#removeFoeiProcessListener(com.idcanet.foei.core.FoeiProcessListener) + */ + public void removeFoeiProcessListener(FoeiProcessListener foeiProcessListener) { + foeiProcessListeners.remove(foeiProcessListener); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/FoeiProcessRunnableWrapper.java b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessRunnableWrapper.java new file mode 100644 index 0000000..70fa2dc --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/FoeiProcessRunnableWrapper.java @@ -0,0 +1,73 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; + +/** + * Wraps an Runnable object so it binds the FoeiProcess before running + * and unbinds it also. + * + * @author Willem Cazander + * @version 1.0 Mar 3, 2006 + */ +public class FoeiProcessRunnableWrapper implements Runnable { + + /** The wrapped runnable object. */ + private Runnable runnable = null; + /** The FoeiProcess for this Runnable. */ + private FoeiProcess foeiProcess = null; + + /** + * creates an FoeiProcessRunnableWrapper + * @param runnable + * @param foeiProcess + */ + public FoeiProcessRunnableWrapper(Runnable runnable,FoeiProcess foeiProcess) { + if(runnable==null) { + throw new NullPointerException("runnable may not be null."); + } + if(foeiProcess==null) { + throw new NullPointerException("FoeiProcess may not be null."); + } + this.runnable=runnable; + this.foeiProcess=foeiProcess; + } + + /** + * Binds and unbinds the FoeiProcess and call the runnalbe run method. + */ + public void run() { + FoeiProcessFactory.bindFoeiProcess(foeiProcess); + try { + runnable.run(); + } finally { + FoeiProcessFactory.unbindFoeiProcess(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java b/src/main/java/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java new file mode 100644 index 0000000..d192dde --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/ObjectBindingsManagerImpl.java @@ -0,0 +1,197 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.ObjectBindingsManager; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.EventPortType; +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.EventStepController; + +import java.util.HashMap; +import java.util.Map; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * Defines the ObjectBindingsManager implamentation. + * + * @author Willem Cazander + * @version 1.0 20/04/2005 + */ +public class ObjectBindingsManagerImpl implements ObjectBindingsManager { + /** */ + private Map> bindingsOutput = null; + /** Works like: eventPort(input) -> List (EventPorts(output) */ + private Map> bindingsInput = null; + /** The logger to log to. */ + private Logger logger = null; + + /** + * Creates the defaults implementation of the ObjectBindingsManager.
+ * inits the logger and de input and output Map mappings. + */ + public ObjectBindingsManagerImpl() { + logger = Logger.getLogger(ObjectBindingsManagerImpl.class.getName()); + bindingsOutput = new HashMap>(50); + bindingsInput = new HashMap>(50); + logger.finer("BindingsManager Created"); + } + + /** + * + * @see ObjectBindingsManager#addBinding(EventPort, EventPort) + */ + public void addBinding(EventPort outputPort,EventPort inputPort) { + if(inputPort==null) { + throw new NullPointerException("inputPort may not be null."); + } + if(inputPort.getEventPortType()!=EventPortType.input) { + throw new IllegalArgumentException("inputPort needs to be input type."); + } + if(outputPort==null) { + throw new NullPointerException("outputPort may not be null."); + } + if(outputPort.getEventPortType()!=EventPortType.output) { + throw new IllegalArgumentException("inputPort needs to be ouput type."); + } + + List inputPorts = bindingsInput.get(inputPort); + List outputPorts = bindingsOutput.get(outputPort); + if(inputPorts==null) { + inputPorts = new ArrayList(5); + bindingsInput.put(inputPort,inputPorts); + } + if(outputPorts==null) { + outputPorts = new ArrayList(5); + bindingsOutput.put(outputPort,outputPorts); + } + + // disables to bind twice + if(inputPorts.contains(outputPort) || outputPorts.contains(inputPort) ) { + throw new IllegalArgumentException("inputPort is already bind to outputPort"); + } + inputPorts.add(outputPort); + outputPorts.add(inputPort); + logger.fine("Bind completed: "+inputPort.getEventObject()+":"+inputPort.getName()+" to "+outputPort.getEventObject()+":"+outputPort.getName()); + } + + /** + * + * @see ObjectBindingsManager#removeBinding(EventPort, EventPort) + */ + public void removeBinding(EventPort inputPort,EventPort outputPort) { + if(inputPort==null) { + throw new NullPointerException("inputPort may not be null."); + } + if(inputPort.getEventPortType()!=EventPortType.input) { + throw new IllegalArgumentException("inputPort needs to be input type."); + } + if(outputPort==null) { + throw new NullPointerException("outputPort may not be null."); + } + if(outputPort.getEventPortType()!=EventPortType.output) { + throw new IllegalArgumentException("inputPort needs to be ouput type."); + } + + List inputPorts = bindingsInput.get(inputPort); + List outputPorts = bindingsOutput.get(outputPort); + + if(inputPorts==null || outputPorts==null) { + throw new IllegalArgumentException("Can not remove not binded ports."); + } + + inputPorts.remove(outputPort); + outputPorts.remove(inputPort); + + if(inputPorts.isEmpty()) { + bindingsInput.remove(inputPort); + } + if(outputPorts.isEmpty()) { + bindingsOutput.remove(outputPort); + } + logger.fine("Bind removed: "+inputPort.getEventObject()+":"+inputPort.getName()+" to "+outputPort.getEventObject()+":"+outputPort.getName()); + } + + /** + * Gets the bindings of an EventPort + * @param eventPort The EventPort to retreive the bindings. + * @return Returns an List of the binded EventPorts + */ + public List getBindings(EventPort eventPort) { + if(eventPort==null) { + throw new NullPointerException("eventPort may not be null."); + } + if (EventPortType.output.equals(eventPort.getEventPortType())) { + List inputPorts = bindingsOutput.get(eventPort); + if(inputPorts!=null) { + return inputPorts; + } + List result = new ArrayList(0); + return result; + } else { + List outputPorts = bindingsInput.get(eventPort); + if(outputPorts!=null) { + return outputPorts; + } + List result = new ArrayList(0); + return result; + } + } + + /** + * Returns the dotty xml bindings + */ + public String getBindingsAsXML() { + StringBuffer result = new StringBuffer(); + result.append("\n"); + result.append("\n"); + //FoeiProcess process = FoeiProcessFactory.getFoeiProcess(); + // todo: ID nameing should go automatic, and be reverse lookup'ale + + for(EventPort port:bindingsOutput.keySet()) { + for(EventPort b:getBindings(port)) { + result.append("\t\n"); + EventStepController e = (EventStepController)o; + for(EventStep es:e.getEventSteps()) { + result.append("\t\t\n"); + } + result.append("\t\n"); + } else { + result.append("\"/>\n"); + } + } + } + result.append(""); + return result.toString(); + } +} diff --git a/src/main/java/com/idcanet/foei/core/impl/X2OExecutorImpl.java b/src/main/java/com/idcanet/foei/core/impl/X2OExecutorImpl.java new file mode 100644 index 0000000..322367b --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/X2OExecutorImpl.java @@ -0,0 +1,135 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.impl; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.core.X2OExecutor; +import com.idcanet.x4o.core.X4OParser; + +import java.io.InputStream; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * The default X2OExecutor implemention + * + * @author Willem Cazander + * @version 1.0 Feb 24, 2006 + * + */ +public class X2OExecutorImpl implements X2OExecutor { + + private String parseFileName = null; + private InputStream parseInputStream = null; + private String parseXml = null; + private boolean ready = false; + private Logger logger = null; + + /** + * Constructs an X2OExecutorImpl + */ + public X2OExecutorImpl() { + logger = Logger.getLogger(X2OExecutorImpl.class.getName()); + } + + + /** + * @see java.lang.Runnable#run() + */ + public void run() { + try { + + // config parser + FoeiProcess foeiProcess = FoeiProcessFactory.getFoeiProcess(); + X4OParser parser = new X4OParser("foei"); + parser.preStart(); + parser.getElementContext().getProperties().putAll(foeiProcess.getFoeiContext().getStartProperties()); + + logger.info("Executing X2O Parsing."); + + if(parseFileName!=null) { + try { + logger.finer("Parsing File: "+parseFileName); + parser.parseFile(parseFileName); + } catch (Exception e) { + logger.log(Level.SEVERE,"Error while loading config file:"+e.getMessage(),e); + } + } + + if(parseInputStream!=null) { + try { + logger.finer("Parsing InputStream"); + parser.parse(parseInputStream); + } catch (Exception e) { + logger.log(Level.SEVERE,"Error while loading inputStream:"+e.getMessage(),e); + } + } + + if(parseXml!=null) { + try { + logger.finer("Parsing XML"); + parser.parseXml(parseXml); + } catch (Exception e) { + logger.log(Level.SEVERE,"Error while loading xml:"+e.getMessage(),e); + } + } + } catch (Throwable t) { + logger.log(Level.WARNING,"Error in X2O thread: "+t.getMessage(),t); + } finally { + ready = true; + } + } + + /** + * @see com.idcanet.foei.core.X2OExecutor#isReady() + */ + public boolean isReady() { + return ready; + } + + /** + * @see com.idcanet.foei.core.X2OExecutor#setFileName(java.lang.String) + */ + public void setFileName(String fileName) { + parseFileName=fileName; + } + + /** + * @see com.idcanet.foei.core.X2OExecutor#setInputStream(java.io.InputStream) + */ + public void setInputStream(InputStream inputStream) { + parseInputStream=inputStream; + } + + /** + * @see com.idcanet.foei.core.X2OExecutor#setXml(java.lang.String) + */ + public void setXml(String xml) { + parseXml=xml; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/impl/package.html b/src/main/java/com/idcanet/foei/core/impl/package.html new file mode 100644 index 0000000..fed3fbf --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/impl/package.html @@ -0,0 +1,58 @@ + + + + + + +Defines the Foei Event Core Implemention.
+ +Some classes are build to be used for overriding classes so
+they have method to make live easer.
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/package.html b/src/main/java/com/idcanet/foei/core/package.html new file mode 100644 index 0000000..f2bc7c4 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/package.html @@ -0,0 +1,59 @@ + + + + + + +Defines the Foei Event Core interfaces, exceptions and 1 class.
+ +

Package Specification

+ +The Foei Core objects are fully interfaced so you
+can hook into every core process.
+ + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/x4o/BindAttributeHandler.java b/src/main/java/com/idcanet/foei/core/x4o/BindAttributeHandler.java new file mode 100644 index 0000000..1cfd52b --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/x4o/BindAttributeHandler.java @@ -0,0 +1,83 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.x4o; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.x4o.element.AbstractElementParameterHandler; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementException; + +/** + * Handlers the "bind" attribute + * + * @author Willem Cazander + * @version 1.0 Apr 15, 2006 + */ +public class BindAttributeHandler extends AbstractElementParameterHandler { + + /** + * @see com.idca.foei.xml.x2o.eld.GlobalParameterHandler#doParameter(java.lang.Object, java.lang.String) + */ + @Override + public void doParameterStartTag(Element element) throws ElementException { + String parameterValue = element.getAttributes().get(getParameterName()); + String[] port = parameterValue.split(":"); + if(port.length!=2) { + return; + } + try { + + EventInput in = (EventInput)element.getElementObject(); + if(in==null) { + throw new ElementException("Could not find EventObject from inputID"); + } + EventOutput out = (EventOutput)element.getParent().getElementObject(); + if(out==null) { + throw new ElementException("Could not find EventObject from outputID"); + } + EventPort inputEventPort = in.getInputPort(port[1]); + EventPort outputEventPort = out.getOutputPort(port[0]); + + FoeiProcess foei = FoeiProcessFactory.getFoeiProcess(); + + if(inputEventPort==null) { + throw new ElementException("Could not find EventPort from inputPort"); + } + if(outputEventPort==null) { + throw new ElementException("Could not find EventPort from outputPort"); + } + foei.addBinding(outputEventPort,inputEventPort); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/idcanet/foei/core/x4o/EventStepBindRuleHandler.java b/src/main/java/com/idcanet/foei/core/x4o/EventStepBindRuleHandler.java new file mode 100644 index 0000000..8c74253 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/x4o/EventStepBindRuleHandler.java @@ -0,0 +1,66 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.x4o; + +import com.idcanet.foei.event.EventStep; +import com.idcanet.foei.event.EventStepController; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementBindingException; +import com.idcanet.x4o.element.ElementBindingHandler; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 16, 2006 + */ +public class EventStepBindRuleHandler implements ElementBindingHandler { + + /** + * @see com.idca.foei.xml.x2o.eld.BindingRuleHandler#canBind(java.lang.Object, java.lang.Object) + */ + public boolean canBind(Element element) { + Object parent = element.getParent().getElementObject(); + Object child = element.getElementObject(); + if(!(parent instanceof EventStepController)) { + return false; + } + if(!(child instanceof EventStep)) { + return false; + } + return true; + } + + /** + * @see com.idca.foei.xml.x2o.eld.BindingRuleHandler#doBind(java.lang.Object, java.lang.Object) + */ + public void doBind(Element element) throws ElementBindingException { + Object parent = element.getParent().getElementObject(); + Object child = element.getElementObject(); + ((EventStepController)parent).addEventStep((EventStep)child); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/x4o/IdAttributeHandler.java b/src/main/java/com/idcanet/foei/core/x4o/IdAttributeHandler.java new file mode 100644 index 0000000..0339532 --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/x4o/IdAttributeHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.x4o; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.x4o.element.AbstractElementParameterHandler; +import com.idcanet.x4o.element.Element; +import com.idcanet.x4o.element.ElementException; + +/** + * Handles the id + * + * @author Willem Cazander + * @version 1.0 Jul 8, 2006 + */ +public class IdAttributeHandler extends AbstractElementParameterHandler { + + /** + * @see com.idca.foei.xml.x2o.eld.GlobalParameterHandler#doParameter(java.lang.Object, java.lang.String) + */ + @Override + public void doParameterStartTag(Element element) throws ElementException { + // add to objext context + String parameterValue = element.getAttributes().get(getParameterName()); + if(element.getElementObject()==null | "".equals(parameterValue)) { + parameterValue= "auto."+Integer.toHexString(element.getElementObject().hashCode()); + //logger.finest("Generated auto id: "+parameterValue); + } + FoeiProcess process = FoeiProcessFactory.getFoeiProcess(); + process.addEventObject(element.getElementObject(),parameterValue); + } +} diff --git a/src/main/java/com/idcanet/foei/core/x4o/ObjectBindingElement.java b/src/main/java/com/idcanet/foei/core/x4o/ObjectBindingElement.java new file mode 100644 index 0000000..b58544c --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/x4o/ObjectBindingElement.java @@ -0,0 +1,85 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.core.x4o; + +import java.util.Map; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.x4o.element.AbstractElement; +import com.idcanet.x4o.element.ElementException; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Mar 2, 2006 + */ +public class ObjectBindingElement extends AbstractElement { + + private String outputID = null; + private String outputPort = null; + private String inputID = null; + private String inputPort = null; + + /** + * Do the element + */ + @Override + public void doElementStart() throws ElementException { + + Map attributes = getAttributes(); + + outputID = attributes.get("outputID"); + outputPort = attributes.get("outputPort"); + inputID = attributes.get("inputID"); + inputPort = attributes.get("inputPort"); + + FoeiProcess foei = FoeiProcessFactory.getFoeiProcess(); + + Object in = foei.getEventObject(inputID); + if(in==null) { + throw new ElementException("Could not find EventObject from inputID"); + } + Object out = foei.getEventObject(outputID); + if(out==null) { + throw new ElementException("Could not find EventObject from outputID"); + } + EventPort inputEventPort = ((EventInput)in).getInputPort(inputPort); + EventPort outputEventPort = ((EventOutput)out).getOutputPort(outputPort); + if(inputEventPort==null) { + throw new ElementException("Could not find EventPort from inputPort"); + } + if(outputEventPort==null) { + throw new ElementException("Could not find EventPort from outputPort"); + } + foei.addBinding(outputEventPort,inputEventPort); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/core/x4o/package.html b/src/main/java/com/idcanet/foei/core/x4o/package.html new file mode 100644 index 0000000..0117f6e --- /dev/null +++ b/src/main/java/com/idcanet/foei/core/x4o/package.html @@ -0,0 +1,55 @@ + + + + + + +Special Element object for foei xml.
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java b/src/main/java/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java new file mode 100644 index 0000000..1b48918 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/EJBFoeiProcessListener.java @@ -0,0 +1,85 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.spi.endpoint.MessageEndpointFactory; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessListener; +import com.idcanet.foei.ee.jca.spi.FoeiActivationSpec; +import com.idcanet.foei.ee.jca.spi.FoeiEventWrapper; +import com.idcanet.foei.ee.jca.spi.FoeiResourceAdapter; + +/** + * Injects the ejb3 beans in the process.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public class EJBFoeiProcessListener implements FoeiProcessListener { + + private FoeiResourceAdapter foeiResourceAdapter = null; + + + public EJBFoeiProcessListener(FoeiResourceAdapter foeiResourceAdapter) { + this.foeiResourceAdapter=foeiResourceAdapter; + } + + /** + * @see com.idcanet.foei.core.FoeiProcessListener#foeiProcessCreated(com.idcanet.foei.core.FoeiProcess) + */ + public void foeiProcessCreated(FoeiProcess process) { + + // list all beans. + for (String name:foeiResourceAdapter.getEJBFoeiBeanNames()) { + + FoeiActivationSpec foeiActivationSpec = foeiResourceAdapter.getFoeiActivationSpec(name); + MessageEndpointFactory endpointFactory = foeiResourceAdapter.getMessageEndpointFactory(name); + + // check context name + if (process.getFoeiContext().getName().matches(foeiActivationSpec.getFoeiContextName())) { + + // check process name + if (process.getName().matches(foeiActivationSpec.getFoeiProcessName())) { + + // create wrapper for in foei, which can get an instance of the EJB bean. + FoeiEventWrapper wrapper = new FoeiEventWrapper(endpointFactory,process); + + // inject bean + process.addEventObject(wrapper, foeiActivationSpec.getFoeiBeanName()); + } + } + } + } + + /** + * @see com.idcanet.foei.core.FoeiProcessListener#foeiProcessDestroyed(com.idcanet.foei.core.FoeiProcess) + */ + public void foeiProcessDestroyed(FoeiProcess process) { + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnection.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnection.java new file mode 100644 index 0000000..2c0a9e0 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnection.java @@ -0,0 +1,49 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.ResourceException; + +import com.idcanet.foei.core.FoeiContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public interface FoeiConnection { + + /** + * Retrieves instance of the Foei Context + * @return File Retriever connection instance + * @throws ResourceException in case of any problem + */ + public FoeiContext getFoeiContext() throws ResourceException; + + public void close() throws ResourceException; +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactory.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactory.java new file mode 100644 index 0000000..399e3be --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactory.java @@ -0,0 +1,45 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.ResourceException; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public interface FoeiConnectionFactory { + + /** + * Retrieves instance of the Foei Context Connection + * @return File Retriever connection instance + * @throws ResourceException in case of any problem + */ + public FoeiConnection getFoeiConnection() throws ResourceException; +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactoryImpl.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactoryImpl.java new file mode 100644 index 0000000..665effa --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionFactoryImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import java.io.Serializable; + +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.resource.Referenceable; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ManagedConnectionFactory; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +@SuppressWarnings("serial") +public class FoeiConnectionFactoryImpl implements FoeiConnectionFactory, Serializable, Referenceable { + + /** Managed connection factory */ + private ManagedConnectionFactory mcf; + + /** Connection manager */ + private ConnectionManager cm; + + /** JNDI reference */ + private Reference reference; + + + /** + * The constructor + * @param factory managed connection factory + * @param cm connection manager + */ + public FoeiConnectionFactoryImpl(ManagedConnectionFactory factory,ConnectionManager cm) { + this.mcf = factory; + this.cm = cm; + } + + + /** + * @see javax.resource.Referenceable#setReference(javax.naming.Reference) + */ + public void setReference(Reference reference) { + this.reference=reference; + } + + /** + * @see javax.naming.Referenceable#getReference() + */ + public Reference getReference() throws NamingException { + return reference; + } + + /** + * @see com.idcanet.foei.jca.cci.FoeiConnectionFactory#getFoeiConnection() + */ + public FoeiConnection getFoeiConnection() throws ResourceException { + return (FoeiConnection) cm.allocateConnection(mcf, null); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionImpl.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionImpl.java new file mode 100644 index 0000000..31e80a5 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiConnectionImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.ResourceException; +import com.idcanet.foei.core.FoeiContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public class FoeiConnectionImpl implements FoeiConnection { + + + /** Underlying physical connection instance */ + private FoeiManagedConnection mc; + + /** + * The constructor + * @param mc underlying physical connection instance + */ + public FoeiConnectionImpl(FoeiManagedConnection mc) { + this.mc = mc; + } + + /** + * Associates this handle with given underlying physical + * connection instance + * @param newMc underlying physical connection instance + */ + public void associateConnection(FoeiManagedConnection newMc) { + this.mc.removeConnection(this); + newMc.addConnection(this); + this.mc = newMc; + } + + /** + * Invalidates the connection + */ + public void invalidate() { + mc = null; + } + + /** + * @see com.idcanet.foei.jca.cci.FoeiContextConnection#getFoeiContext() + */ + public FoeiContext getFoeiContext() throws ResourceException { + return mc.getFoeiContext(); + } + + /**oeiContextConnection#close() + */ + public void close() throws ResourceException { + mc.close(this); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java new file mode 100644 index 0000000..2d9f920 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnection.java @@ -0,0 +1,237 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.resource.NotSupportedException; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionEvent; +import javax.resource.spi.ConnectionEventListener; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.LocalTransaction; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionMetaData; +import javax.security.auth.Subject; +import javax.transaction.xa.XAResource; + +import com.idcanet.foei.core.FoeiContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public class FoeiManagedConnection implements ManagedConnection { + + /** Log writer */ + private PrintWriter writer; + + /** List of listeners */ + private List listeners; + + /** Set of application-level handlers */ + private Set connectionSet; + + private FoeiContext foeiContext = null; + + /** + * The constructor + * @param conReqInfo {@link ConnectionRequestInfo} + * @param writer log writer of the factory that calls this constructor + * @param repositoryPath path to the repository containing files to retireve + */ + public FoeiManagedConnection(ConnectionRequestInfo conReqInfo,PrintWriter writer, FoeiContext foeiContext) { + this.writer = writer; + this.listeners = new ArrayList(10); + this.connectionSet = new HashSet(10); + this.foeiContext = foeiContext; + } + + /** + * @see javax.resource.spi.ManagedConnection#getConnection(javax.security.auth.Subject, + * javax.resource.spi.ConnectionRequestInfo) + */ + public Object getConnection(Subject subj, ConnectionRequestInfo conReqInfo) throws ResourceException { + if (this.foeiContext == null) { + throw new ResourceException("foeiContext is null"); + } + + FoeiConnectionImpl conn = new FoeiConnectionImpl(this); + addConnection(conn); + return conn; + } + + /** + * @see javax.resource.spi.ManagedConnection#destroy() + */ + public void destroy() throws ResourceException { + invalidateAllConnections(); + synchronized (this.listeners) { + listeners = null; + } + foeiContext.destroy(); + foeiContext = null; + } + + /** + * @see javax.resource.spi.ManagedConnection#cleanup() + */ + public void cleanup() throws ResourceException { + invalidateAllConnections(); + } + + /** + * @see javax.resource.spi.ManagedConnection#associateConnection(java.lang.Object) + */ + public void associateConnection(Object conn) throws ResourceException { + if (!(conn instanceof FoeiConnectionImpl)) { + throw new ResourceException("Connection has an incorrect type"); + } + ((FoeiConnectionImpl)conn).associateConnection(this); + } + + /** + * @see javax.resource.spi.ManagedConnection#addConnectionEventListener(javax.resource.spi.ConnectionEventListener) + */ + public void addConnectionEventListener(ConnectionEventListener listener) { + synchronized (this.listeners) { + listeners.add(listener); + } + } + + /** + * @see javax.resource.spi.ManagedConnection#removeConnectionEventListener(javax.resource.spi.ConnectionEventListener) + */ + public void removeConnectionEventListener(ConnectionEventListener listener) { + synchronized (this.listeners) { + listeners.remove(listener); + } + } + + /** + * @see javax.resource.spi.ManagedConnection#getXAResource() + */ + public XAResource getXAResource() throws ResourceException { + throw new NotSupportedException("XA transactions are not supported"); + } + + /** + * @see javax.resource.spi.ManagedConnection#getLocalTransaction() + */ + public LocalTransaction getLocalTransaction() throws ResourceException { + throw new NotSupportedException("Transactions are not supported"); + } + + /** + * @see javax.resource.spi.ManagedConnection#getMetaData() + */ + public ManagedConnectionMetaData getMetaData() throws ResourceException { + return new FoeiManagedConnectionMetaData(); + } + + /** + * @see javax.resource.spi.ManagedConnection#setLogWriter(java.io.PrintWriter) + */ + public void setLogWriter(PrintWriter out) throws ResourceException { + this.writer = out; + } + + /** + * @see javax.resource.spi.ManagedConnection#getLogWriter() + */ + public PrintWriter getLogWriter() throws ResourceException { + return writer; + } + + /** + * Removes application-level handler from handlers set + * @param con handler to remove + * @see FileRetrieverConnectionImpl#associateConnection(FileRetrieverManagedConnection) + */ + void removeConnection(FoeiConnectionImpl con) { + synchronized (this.connectionSet) { + connectionSet.remove(con); + } + } + + /** + * Adds application-level handler to handlers set + * @param con handler to add + * @see FileRetrieverConnectionImpl#associateConnection(FileRetrieverManagedConnection) + */ + void addConnection(FoeiConnectionImpl con) { + synchronized (this.connectionSet) { + connectionSet.add(con); + } + } + + /** + * Invalidate all application-level handlers and clears handlers set + */ + void invalidateAllConnections() { + synchronized (this.connectionSet) { + Iterator itr = connectionSet.iterator(); + while (itr.hasNext()) { + FoeiConnectionImpl con = itr.next(); + con.invalidate(); + } + connectionSet.clear(); + } + } + + public FoeiContext getFoeiContext() { + return foeiContext; + } + + + /** + * Closes connection + * @param con connection to close + */ + public void close(FoeiConnectionImpl con) { + ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); + event.setConnectionHandle(con); + synchronized (this.listeners) { + Iterator itr = listeners.iterator(); + while (itr.hasNext()) { + try { + itr.next().connectionClosed(event); + } catch (Throwable e) { + } + } + } + con.invalidate(); + removeConnection(con); + } +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java new file mode 100644 index 0000000..ef0229e --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionFactory.java @@ -0,0 +1,204 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import javax.naming.Context; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionFactory; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterAssociation; +import javax.security.auth.Subject; + +import com.idcanet.foei.core.EventExecutorManager; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiProcessManager; +import com.idcanet.foei.core.impl.FoeiConfiguratorImpl; +import com.idcanet.foei.core.impl.FoeiContextImpl; +import com.idcanet.foei.ee.jca.spi.FoeiResourceAdapter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +@SuppressWarnings("serial") +public class FoeiManagedConnectionFactory implements ManagedConnectionFactory,ResourceAdapterAssociation { + + private Logger logger = Logger.getLogger(FoeiManagedConnectionFactory.class.getName()); + + /** Log writer */ + private transient PrintWriter writer; + + /** Path to file system repository */ + private String foeiContextName = null; + + private FoeiContext foeiContext = null; + + private ResourceAdapter resourceAdapter = null; + + /** + * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory(javax.resource.spi.ConnectionManager) + */ + public Object createConnectionFactory(ConnectionManager cm) throws ResourceException { + + if (foeiContext==null) { + logger.info("Starting foeiContext: "+foeiContextName); + Context objectContext = null; + EventExecutorManager eventExecutorManager = null; + FoeiProcessManager foeiProcessManager = null; + + Map properties = new HashMap(0); + try { + objectContext = FoeiConfiguratorImpl.newContext(properties); + //eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter()); + eventExecutorManager = FoeiConfiguratorImpl.newEventExecutorManager(properties); + foeiProcessManager = FoeiConfiguratorImpl.newFoeiProcessManager(properties); + + // inject ejb beans per process + foeiProcessManager.addFoeiProcessListener(new EJBFoeiProcessListener((FoeiResourceAdapter)getResourceAdapter())); + + FoeiConfiguratorImpl.loadEventThreadListeners(properties,eventExecutorManager); + } catch (Exception e) { + throw new ResourceException("Error while building childs objects:",e); + } + foeiContext = new FoeiContextImpl(foeiContextName,objectContext,eventExecutorManager,properties,foeiProcessManager); + } + + return new FoeiConnectionFactoryImpl(this, cm); + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory() + */ + public Object createConnectionFactory() throws ResourceException { + return createConnectionFactory(null); + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#createManagedConnection(javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo) + */ + public ManagedConnection createManagedConnection(Subject subj,ConnectionRequestInfo conReqInfo) throws ResourceException { + return new FoeiManagedConnection(conReqInfo, writer, foeiContext); + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#matchManagedConnections(java.util.Set, javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo) + */ + @SuppressWarnings("unchecked") + public ManagedConnection matchManagedConnections(Set set, Subject subj, ConnectionRequestInfo conReqInfo) throws ResourceException { + Iterator itr = set.iterator(); + if (itr.hasNext()) { + Object obj = itr.next(); + if (obj instanceof FoeiManagedConnection) { + return (FoeiManagedConnection)obj; + } + } + return null; + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#setLogWriter(java.io.PrintWriter) + */ + public void setLogWriter(PrintWriter out) throws ResourceException { + this.writer = out; + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#getLogWriter() + */ + public PrintWriter getLogWriter() throws ResourceException { + return writer; + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#hashCode() + */ + public int hashCode() { + if (foeiContextName == null) { + return super.hashCode(); + } else { + return foeiContextName.hashCode(); + } + } + + /** + * @see javax.resource.spi.ManagedConnectionFactory#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof FoeiManagedConnectionFactory)) { + return false; + } + if (foeiContextName == null) { + return false; + } + return foeiContextName.equals(((FoeiManagedConnectionFactory)obj).getFoeiContextName()); + } + + /** + * @return the foeiContextName + */ + public String getFoeiContextName() { + return foeiContextName; + } + + /** + * @param foeiContextName the foeiContextName to set + */ + public void setFoeiContextName(String foeiContextName) { + this.foeiContextName = foeiContextName; + } + + + + /** + * @see javax.resource.spi.ResourceAdapterAssociation#getResourceAdapter() + */ + public ResourceAdapter getResourceAdapter() { + return resourceAdapter; + } + + /** + * @see javax.resource.spi.ResourceAdapterAssociation#setResourceAdapter(javax.resource.spi.ResourceAdapter) + */ + public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException { + this.resourceAdapter=resourceAdapter; + } +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionMetaData.java b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionMetaData.java new file mode 100644 index 0000000..38e2f0f --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/cci/FoeiManagedConnectionMetaData.java @@ -0,0 +1,70 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.cci; + +import javax.resource.ResourceException; +import javax.resource.spi.ManagedConnectionMetaData; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public class FoeiManagedConnectionMetaData implements ManagedConnectionMetaData { + + /** Default instance of the class */ + public final static FoeiManagedConnectionMetaData INSTANCE = new FoeiManagedConnectionMetaData(); + + /** + * @see javax.resource.spi.ManagedConnectionMetaData#getEISProductName() + */ + public String getEISProductName() throws ResourceException { + return "Foei EE EIS"; + } + + /** + * @see javax.resource.spi.ManagedConnectionMetaData#getEISProductVersion() + */ + public String getEISProductVersion() throws ResourceException { + return "1.0"; + } + + /** + * @see javax.resource.spi.ManagedConnectionMetaData#getMaxConnections() + */ + public int getMaxConnections() throws ResourceException { + return 0; + } + + /** + * @see javax.resource.spi.ManagedConnectionMetaData#getUserName() + */ + public String getUserName() throws ResourceException { + return "IDCANET"; + } +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java b/src/main/java/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java new file mode 100644 index 0000000..ad403f2 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/spi/EJBFoeiBean.java @@ -0,0 +1,45 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.event.EventInput; +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Gets called when process is created or destroyed.
+ * + * + * @author Willem Cazander + * @version 1.0 Apr 26, 2008 + */ +public interface EJBFoeiBean extends EventInput,EventOutput { + + public void doEvent(FoeiProcess process,FoeiEventWrapper wrapper,EventPort eventPort,Object object) throws IllegalEventPortNameException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java new file mode 100644 index 0000000..72ea2a9 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiActivationSpec.java @@ -0,0 +1,144 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import java.io.Serializable; + +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.InvalidPropertyException; +import javax.resource.spi.ResourceAdapter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +@SuppressWarnings("serial") +public class FoeiActivationSpec implements ActivationSpec, Serializable { + + /** The resource adapter */ + private transient ResourceAdapter resourceAdapter = null; + + private String foeiBeanName = null; + + private String foeiProcessName = null; + + private String foeiContextName = null; + + /** + * @see javax.resource.spi.ActivationSpec#validate() + */ + public void validate() throws InvalidPropertyException { + if (foeiBeanName==null) { + throw new InvalidPropertyException("foeiBeanName is null,please set foeiBeanName property."); + } + if (foeiBeanName.isEmpty()) { + throw new InvalidPropertyException("foeiBeanName is empty,please set foeiBeanName property."); + } + if (foeiProcessName==null) { + foeiProcessName=".*"; + } + if (foeiProcessName.isEmpty()) { + foeiProcessName=".*"; + } + if ("*".equals(foeiProcessName)) { + foeiProcessName=".*"; + } + if (foeiContextName==null) { + foeiContextName=".*"; + } + if (foeiContextName.isEmpty()) { + foeiContextName=".*"; + } + if ("*".equals(foeiContextName)) { + foeiContextName=".*"; + } + + // TODO: check if is regex + } + + /** + * @see javax.resource.spi.ResourceAdapterAssociation#getResourceAdapter() + */ + public ResourceAdapter getResourceAdapter() { + return resourceAdapter; + } + + /** + * @see javax.resource.spi.ResourceAdapterAssociation#setResourceAdapter(javax.resource.spi.ResourceAdapter) + */ + public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException { + if (resourceAdapter==null) { + throw new ResourceException("ResourceAdapter may not be null."); + } + this.resourceAdapter=resourceAdapter; + } + + /** + * @return the foeiBeanName + */ + public String getFoeiBeanName() { + return foeiBeanName; + } + + /** + * @param foeiBeanName the foeiBeanName to set + */ + public void setFoeiBeanName(String foeiBeanName) { + this.foeiBeanName = foeiBeanName; + } + + /** + * @return the foeiProcessName + */ + public String getFoeiProcessName() { + return foeiProcessName; + } + + /** + * @param foeiProcessName the foeiProcessName to set + */ + public void setFoeiProcessName(String foeiProcessName) { + this.foeiProcessName = foeiProcessName; + } + + /** + * @return the foeiContextName + */ + public String getFoeiContextName() { + return foeiContextName; + } + + /** + * @param foeiContextName the foeiContextName to set + */ + public void setFoeiContextName(String foeiContextName) { + this.foeiContextName = foeiContextName; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java new file mode 100644 index 0000000..68057ad --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiEventWrapper.java @@ -0,0 +1,113 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import java.util.logging.Logger; + +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; + +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.event.AbstractEventObject; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; + +/** + * Wrappers the ejb bean into the foei executing context. + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +@SuppressWarnings("serial") +public class FoeiEventWrapper extends AbstractEventObject { + + private Logger logger = Logger.getLogger(FoeiEventWrapper.class.getName()); + + private MessageEndpointFactory endpointFactory = null; + + private FoeiProcess foeiProcess = null; + + public FoeiEventWrapper(MessageEndpointFactory endpointFactory,FoeiProcess foeiProcess) { + this.endpointFactory=endpointFactory; + this.foeiProcess=foeiProcess; + + MessageEndpoint endpoint = null; + try { + endpoint = endpointFactory.createEndpoint(null); // creates new EJB3 bean instance !! + if (endpoint != null) { + EJBFoeiBean bean = (EJBFoeiBean) endpoint; + + // copy ports, todo: go to annotations + + // TODO: check if has input port at all... + for (EventPort p:bean.getInputPorts()) { + this.addInputPort(p.getName(), p.getObjectClass()); + } + for (EventPort p:bean.getOutputPorts()) { + this.addOutputPort(p.getName(), p.getObjectClass()); + } + + } else { + logger.warning("MessageEndPoint is null."); + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (endpoint != null) { + endpoint.release(); + } + } + + } + + /** + * @see com.idcanet.foei.event.AbstractEventInput#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object) + */ + @Override + public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException { + MessageEndpoint endpoint = null; + try { + endpoint = endpointFactory.createEndpoint(null); // creates new EJB3 bean instance !! + if (endpoint != null) { + EJBFoeiBean input = (EJBFoeiBean) endpoint; + + // mmm needed ? + // yes for normaly equals .. + EventPort port = input.getInputPort(eventPort.getName()); + input.doEvent(foeiProcess,this,port, object); + } else { + logger.warning("MessageEndPoint is null."); + } + } catch (Exception e) { + throw new IllegalEventPortNameException(e); + } finally { + if (endpoint != null) { + endpoint.release(); // release ejb bean + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java new file mode 100644 index 0000000..510a6b9 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/spi/FoeiResourceAdapter.java @@ -0,0 +1,135 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.transaction.xa.XAResource; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public class FoeiResourceAdapter implements ResourceAdapter { + + private Logger logger = Logger.getLogger(FoeiResourceAdapter.class.getName()); + + private BootstrapContext bootstrapContext = null; + + private Map ejbs = null; + + /** + * @see javax.resource.spi.ResourceAdapter#start(javax.resource.spi.BootstrapContext) + */ + public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException { + logger.info("Starting FoeiResourceAdapter"); + ejbs = new HashMap(5); + this.bootstrapContext=bootstrapContext; + } + + /** + * @see javax.resource.spi.ResourceAdapter#stop() + */ + public void stop() { + logger.info("Stopping FoeiResourceAdapter"); + ejbs.clear(); + bootstrapContext=null; + } + + /** + * @see javax.resource.spi.ResourceAdapter#getXAResources(javax.resource.spi.ActivationSpec[]) + */ + public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException { + return null; + } + + /** + * @see javax.resource.spi.ResourceAdapter#endpointActivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec) + */ + public void endpointActivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) throws ResourceException { + FoeiActivationSpec fac = (FoeiActivationSpec)spec; + logger.info("Activation of: "+fac.getFoeiBeanName()); + SpecBean s = new SpecBean(); + s.messageEndpointFactory=endPointFactory; + s.foeiActivationSpec=fac; + ejbs.put(fac.getFoeiBeanName(),s); + } + + /** + * @see javax.resource.spi.ResourceAdapter#endpointDeactivation(javax.resource.spi.endpoint.MessageEndpointFactory, javax.resource.spi.ActivationSpec) + */ + public void endpointDeactivation(MessageEndpointFactory endPointFactory,ActivationSpec spec) { + FoeiActivationSpec fac = (FoeiActivationSpec)spec; + logger.info("Deactivation of "+fac.getFoeiBeanName()); + ejbs.remove(fac.getFoeiBeanName()); + } + + /** + * @return the bootstrapContext + */ + public BootstrapContext getBootstrapContext() { + return bootstrapContext; + } + + /** + * @param bootstrapContext the bootstrapContext to set + */ + public void setBootstrapContext(BootstrapContext bootstrapContext) { + this.bootstrapContext = bootstrapContext; + } + + public List getEJBFoeiBeanNames() { + return new ArrayList(ejbs.keySet()); + } + + public FoeiActivationSpec getFoeiActivationSpec(String name) { + SpecBean s = ejbs.get(name); + return s.foeiActivationSpec; + } + + public MessageEndpointFactory getMessageEndpointFactory(String name) { + SpecBean s = ejbs.get(name); + return s.messageEndpointFactory; + } + + private class SpecBean { + FoeiActivationSpec foeiActivationSpec; + MessageEndpointFactory messageEndpointFactory; + } +} diff --git a/src/main/java/com/idcanet/foei/ee/jca/spi/JCAEventExecutorManager.java b/src/main/java/com/idcanet/foei/ee/jca/spi/JCAEventExecutorManager.java new file mode 100644 index 0000000..9a49917 --- /dev/null +++ b/src/main/java/com/idcanet/foei/ee/jca/spi/JCAEventExecutorManager.java @@ -0,0 +1,200 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.ee.jca.spi; + +import com.idcanet.foei.core.EventExecutor; +import com.idcanet.foei.core.EventExecutorManager; +import com.idcanet.foei.core.EventThreadListener; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiPortMessage; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.core.FoeiProcessFactory; +import com.idcanet.foei.core.impl.FoeiConfiguratorImpl; +import com.idcanet.foei.core.impl.FoeiProcessRunnableWrapper; +import com.idcanet.foei.event.EventPort; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkException; + +/** + * Defines the EventExecutorManager implementation + * + * @author Willem Cazander + * @version 1.0 Apr 19, 2008 + */ +public class JCAEventExecutorManager implements EventExecutorManager { + + /** The logger to log to. */ + private Logger logger = null; + /** The EventThreadListeners */ + private List eventThreadListeners = null; + /** The class for the EventExecutor */ + private Class eventExecutorClass = null; + + private FoeiResourceAdapter foeiResourceAdapter = null; + /** + * Creates an EventExecutorManagerImpl ans inits the logger. + */ + public JCAEventExecutorManager(FoeiResourceAdapter foeiResourceAdapter) { + logger = Logger.getLogger(JCAEventExecutorManager.class.getName()); + eventThreadListeners = new ArrayList(1); + this.foeiResourceAdapter=foeiResourceAdapter; + } + + // ============= EventExecutorManager + + /** + * Executes an Event mostly send from an EventObject. + * @see EventExecutorManager#executeEvent(Object, EventPort) + */ + public void executeEvent(EventPort eventPort,Object eventObject) { + executeEvent(eventPort,eventObject,FoeiProcessFactory.getFoeiProcess()); + } + + /** + * Executes an EventPort with object in an FoeiProcess. + * @param eventPort + * @param eventObject + * @param foeiProcess + */ + public void executeEvent(EventPort eventPort,Object eventObject,FoeiProcess foeiProcess) { + + FoeiPortMessage msg = new FoeiPortMessage(); + msg.setEventObject(eventObject); + msg.setEventPort(eventPort); + foeiProcess.getWorkQueue().add(msg); + + if (foeiProcess.getExecutors().size()>3) { + return; + } + + EventExecutor e = null; + try { + e = (EventExecutor)eventExecutorClass.newInstance(); + } catch (Exception ee) { + logger.log(Level.WARNING,"Error Creating EventExecutor: "+ee.getMessage(),ee); + return; + } + e.setFoeiProcess(foeiProcess); + foeiProcess.getExecutors().add(e); + try { + logger.info("Setting work to EE workmanager"); + foeiResourceAdapter.getBootstrapContext().getWorkManager().scheduleWork(new WorkWrapper(e)); + } catch (WorkException ee) { + ee.printStackTrace(); + } + } + + /** + * Executes an event. + * @see EventExecutorManager#execute(Runnable) + */ + public void execute(Runnable runnable,FoeiProcess foeiProcess) { + try { + foeiResourceAdapter.getBootstrapContext().getWorkManager().scheduleWork(new WorkWrapper(new FoeiProcessRunnableWrapper(runnable,foeiProcess))); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Starts the ThreadPool + * @see EventExecutorManager#start() + */ + public void start(FoeiContext foeiContext) { + if(foeiContext==null) { + throw new NullPointerException("FoeiContext may not be null."); + } + logger.info("Starting EventExecutorManagerImpl"); + + try { + eventExecutorClass = FoeiConfiguratorImpl.newEventExecutorClass(foeiContext.getStartProperties()); + } catch (ClassNotFoundException cce) { + logger.log(Level.WARNING,"Error getting eventExecutor class: "+cce.getMessage(),cce); + throw new RuntimeException("Could not get EventExecutor class: "+cce.getMessage(),cce); + } + } + + /** + * Stops the ThreadPool + * @see EventExecutorManager#stop() + */ + public void stop(FoeiContext foeiContext) { + } + + /** + * @see EventExecutorManager#getEventThreadListeners() + */ + public List getEventThreadListeners() { + return eventThreadListeners; + } + + /** + * @see EventExecutorManager#addEventThreadListener(EventThreadListener) + */ + public void addEventThreadListener(EventThreadListener eventThreadListener) throws IllegalStateException { + if(eventThreadListener==null) { + throw new NullPointerException("eventThreadListener may not be null."); + } + eventThreadListeners.add(eventThreadListener); + } +} +class WorkWrapper implements Work { + + private Runnable run = null; + private Logger logger = Logger.getLogger(WorkWrapper.class.getName()); + + public WorkWrapper(Runnable run) { + this.run=run; + } + + /** + * @see javax.resource.spi.work.Work#release() + */ + public void release() { + logger.info("Releasing jca foei adapter."); + } + + /** + * @see java.lang.Runnable#run() + */ + public void run() { + try { + logger.info("Executing job: "+run); + run.run(); + } catch (Throwable e) { + logger.log(Level.WARNING,"Error in jca foei work unit: "+e.getMessage(),e); + } finally { + logger.info("Done running jobs"); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventInput.java b/src/main/java/com/idcanet/foei/event/AbstractEventInput.java new file mode 100644 index 0000000..5895ab3 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventInput.java @@ -0,0 +1,101 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import com.idcanet.foei.event.EventInput; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Defines an AbstractEventInput which implements most
+ * methods needed for an Foei EventInput bean. + * + * @author Willem Cazander + * @version 1.0 Aug 20, 2005 + */ +abstract public class AbstractEventInput implements EventInput { + + /** The input EventPorts */ + private Map inputs = null; + + /** + * The constuctor + */ + public AbstractEventInput() { + inputs = new HashMap(1); + } + + /** + * Adds an input EventPort + * @param inputName The inputName of the EventPort + */ + protected void addInputPort(String inputName) { + addInputPort(inputName,Object.class); + } + + /** + * Adds an input EventPort + * @param inputName The inputName of the EventPort + * @param inputType The inputClass of the EventPort + */ + protected void addInputPort(String inputName,Class inputClass) { + if(inputName==null) { + throw new NullPointerException("inputName may not be null."); + } + if(inputClass==null) { + throw new NullPointerException("inputClass may not be null."); + } + inputs.put(inputName,new EventPort(inputName,inputClass,EventPortType.input,this)); + } + + // ---------------- EventInput + + /** + * Gets all input EventPorts + * @see EventInput#getInputPorts() + * @return Returns an List of input EventPorts + */ + public Collection getInputPorts() { + return inputs.values(); + } + + /** + * + * @param name + * @return + */ + public EventPort getInputPort(String name) { + return inputs.get(name); + } + + /** + * @see EventInput#doEvent(EventPort, Object) + */ + abstract public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventInputStepController.java b/src/main/java/com/idcanet/foei/event/AbstractEventInputStepController.java new file mode 100644 index 0000000..75d4fbe --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventInputStepController.java @@ -0,0 +1,97 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +abstract public class AbstractEventInputStepController extends AbstractEventInput implements EventStepController +{ + /** The EventStep List */ + private List eventSteps = null; + /** The Logger to log to. */ + private Logger logger = null; + + /** + * Creates the EventStep list and the logger. + */ + public AbstractEventInputStepController() { + eventSteps = new ArrayList(); + logger = Logger.getLogger(AbstractEventStepController.class.getName()); + } + + /** + * Adds an EventStep + * @see EventStepController#addEventStep(EventStep) + */ + public void addEventStep(EventStep eventStep) { + logger.finer("Adding EventStep to: "+this); + eventSteps.add(eventStep); + } + + /** + * Removes an EventStep + * @see EventStepController#removeEventStep(EventStep) + */ + public void removeEventStep(EventStep eventStep) { + logger.finer("Removing EventStep to: "+this); + eventSteps.remove(eventStep); + } + + /** + * Gets all EventSteps. + * @see EventStepController#getEventSteps() + * @returns Returns all EventSteps. + */ + public List getEventSteps() { + return eventSteps; + } + + /** + * Process all EventSteps of the EventStepController + * Override for other behavior + * @see EventStepController#processEventSteps(Object) + * @param object The object to pass to the EventSteps + * @return The object or null. + */ + public Object processEventSteps(Object object) { + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + object = e.processObject(object); + } + return object; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventObject.java b/src/main/java/com/idcanet/foei/event/AbstractEventObject.java new file mode 100644 index 0000000..e1cd1d1 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventObject.java @@ -0,0 +1,98 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import com.idcanet.foei.event.EventInput; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Defines an AbstractEventInput which implements most
+ * methods needed for an Foei EventInput and EventOutput bean. + * + * @author Willem Cazander + * @version 1.0 Aug 17, 2005 + */ +abstract public class AbstractEventObject extends AbstractEventOutput implements EventInput { + + /** The input EventPorts */ + private Map inputs = null; + + public AbstractEventObject() { + inputs = new HashMap(1); + } + + /** + * Adds an input EventPort + * @param inputName The inputName of the EventPort + */ + protected void addInputPort(String inputName) { + addInputPort(inputName,Object.class); + } + + /** + * Adds an input EventPort + * @param inputName The inputName of the EventPort + * @param inputType The inputType of the EventPort + */ + protected void addInputPort(String inputName,Class inputType) { + if(inputName==null) { + throw new NullPointerException("inputName may not be null."); + } + if(inputType==null) { + throw new NullPointerException("inputType may not be null."); + } + inputs.put(inputName,new EventPort(inputName,inputType,EventPortType.input,this)); + } + + // ---------------- EventInput + + /** + * Gets all input EventPorts + * @see EventInput#getInputPorts() + * @return Returns an List of input EventPorts + */ + public Collection getInputPorts() { + return inputs.values(); + } + + /** + * + * @param name + * @return + */ + public EventPort getInputPort(String name) { + return inputs.get(name); + } + + /** + * @see EventInput#doEvent(EventPort, Object) + */ + abstract public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException; +} diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventObjectStepController.java b/src/main/java/com/idcanet/foei/event/AbstractEventObjectStepController.java new file mode 100644 index 0000000..e7d5838 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventObjectStepController.java @@ -0,0 +1,97 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +abstract public class AbstractEventObjectStepController extends AbstractEventObject implements EventStepController +{ + /** The EventStep List */ + private List eventSteps = null; + /** The Logger to log to. */ + private Logger logger = null; + + /** + * Creates the EventStep list and the logger. + */ + public AbstractEventObjectStepController() { + eventSteps = new ArrayList(); + logger = Logger.getLogger(AbstractEventStepController.class.getName()); + } + + /** + * Adds an EventStep + * @see EventStepController#addEventStep(EventStep) + */ + public void addEventStep(EventStep eventStep) { + logger.finer("Adding EventStep to: "+this); + eventSteps.add(eventStep); + } + + /** + * Removes an EventStep + * @see EventStepController#removeEventStep(EventStep) + */ + public void removeEventStep(EventStep eventStep) { + logger.finer("Removing EventStep to: "+this); + eventSteps.remove(eventStep); + } + + /** + * Gets all EventSteps. + * @see EventStepController#getEventSteps() + * @returns Returns all EventSteps. + */ + public List getEventSteps() { + return eventSteps; + } + + /** + * Process all EventSteps of the EventStepController + * Override for other behavior + * @see EventStepController#processEventSteps(Object) + * @param object The object to pass to the EventSteps + * @return The object or null. + */ + public Object processEventSteps(Object object) { + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + object = e.processObject(object); + } + return object; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventOutput.java b/src/main/java/com/idcanet/foei/event/AbstractEventOutput.java new file mode 100644 index 0000000..27e6259 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventOutput.java @@ -0,0 +1,98 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import com.idcanet.foei.event.EventOutput; +import com.idcanet.foei.event.EventPort; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Defines an AbstractEventInput which implements most
+ * methods needed for an Foei EventOutput bean. + * + * @author Willem Cazander + * @version 1.0 Aug 17, 2005 + */ +abstract public class AbstractEventOutput implements EventOutput { + + /** The output EventPorts */ + private Map outputs = null; + + /** + * Creates an AbstractEventOutput + */ + public AbstractEventOutput() { + outputs = new HashMap(1); + } + + /** + * Adds an OutputPort to this bean. + * @param outputName The outputName of the EventPort. + */ + protected void addOutputPort(String outputName) { + addOutputPort(outputName,Object.class); + } + + /** + * Adds an Output to this bean which an certain class type. + * @param outputName The outputName of the EventPort. + * @param outputType The output Class type of the EventPort. + */ + protected void addOutputPort(String outputName,Class outputType) { + if(outputName==null) { + throw new NullPointerException("outputName may not be null."); + } + if(outputType==null) { + throw new NullPointerException("outputType may not be null."); + } + outputs.put(outputName,new EventPort(outputName,outputType,EventPortType.output,this)); + } + + // ---------------- EventOutput + + /** + * Returns an List of OutputPorts + * @returns Returns an List of OutputPorts + * @see EventOutput#getOutputPorts() + */ + public Collection getOutputPorts() { + return outputs.values(); + } + + /** + * Gets an output EventPort by its name. + * @param name The name of the outputPort + * @returns Returns the EventPort + * @see EventOutput#getOutputPort(String) + */ + public EventPort getOutputPort(String name) { + return outputs.get(name); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventOutputStepController.java b/src/main/java/com/idcanet/foei/event/AbstractEventOutputStepController.java new file mode 100644 index 0000000..1898b2e --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventOutputStepController.java @@ -0,0 +1,97 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +abstract public class AbstractEventOutputStepController extends AbstractEventOutput implements EventStepController +{ + /** The EventStep List */ + private List eventSteps = null; + /** The Logger to log to. */ + private Logger logger = null; + + /** + * Creates the EventStep list and the logger. + */ + public AbstractEventOutputStepController() { + eventSteps = new ArrayList(); + logger = Logger.getLogger(AbstractEventStepController.class.getName()); + } + + /** + * Adds an EventStep + * @see EventStepController#addEventStep(EventStep) + */ + public void addEventStep(EventStep eventStep) { + logger.finer("Adding EventStep to: "+this); + eventSteps.add(eventStep); + } + + /** + * Removes an EventStep + * @see EventStepController#removeEventStep(EventStep) + */ + public void removeEventStep(EventStep eventStep) { + logger.finer("Removing EventStep to: "+this); + eventSteps.remove(eventStep); + } + + /** + * Gets all EventSteps. + * @see EventStepController#getEventSteps() + * @returns Returns all EventSteps. + */ + public List getEventSteps() { + return eventSteps; + } + + /** + * Process all EventSteps of the EventStepController + * Override for other behavior + * @see EventStepController#processEventSteps(Object) + * @param object The object to pass to the EventSteps + * @return The object or null. + */ + public Object processEventSteps(Object object) { + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + object = e.processObject(object); + } + return object; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventStep.java b/src/main/java/com/idcanet/foei/event/AbstractEventStep.java new file mode 100644 index 0000000..e71d01b --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventStep.java @@ -0,0 +1,37 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +/** + * Defines an abstract EventStep + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +abstract public class AbstractEventStep implements EventStep { + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/AbstractEventStepController.java b/src/main/java/com/idcanet/foei/event/AbstractEventStepController.java new file mode 100644 index 0000000..a0124bb --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/AbstractEventStepController.java @@ -0,0 +1,97 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jan 25, 2006 + */ +abstract public class AbstractEventStepController extends AbstractEventStep implements EventStepController +{ + /** The EventStep List */ + private List eventSteps = null; + /** The Logger to log to. */ + private Logger logger = null; + + /** + * Should be implemented by the overriding class. + */ + abstract public Object processObject(Object object) throws ClassCastException; + + /** + * Creates the list and the logger. + */ + public AbstractEventStepController() { + eventSteps = new ArrayList(); + logger = Logger.getLogger(AbstractEventStepController.class.getName()); + } + + /** + * + */ + public void addEventStep(EventStep eventStep) { + logger.finer("Adding EventStep to: "+this); + eventSteps.add(eventStep); + } + + /** + * + */ + public void removeEventStep(EventStep eventStep) { + logger.finer("Removing EventStep to: "+this); + eventSteps.remove(eventStep); + } + + /** + * + */ + public List getEventSteps() { + return eventSteps; + } + + /** + * Calls all EventSteps the processObject method + * until one returns null. + * @param object + * @return + */ + public Object processEventSteps(Object object) { + for(EventStep e:getEventSteps()) { + if(object==null) { + return null; + } + object = e.processObject(object); + } + return object; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/EventInput.java b/src/main/java/com/idcanet/foei/event/EventInput.java new file mode 100644 index 0000000..a2a71c4 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventInput.java @@ -0,0 +1,61 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.io.Serializable; +import java.util.Collection; + +/** + * An Object that implments thius interface can receive events.
+ * Which can be directed at different inputs of the object.
+ * + * @author Willem Cazander + * @version 1.0 01/02/2005 + */ +public interface EventInput extends Serializable { + + /** + * Gets the all input EventPorts.
+ * + * @return An List with the current EventPort's. + */ + public Collection getInputPorts(); + + /** + * Gets an input EventPort by its name + * @param name The name of the eventPort + * @return Returns an input EventPort by its name + */ + public EventPort getInputPort(String name); + + /** + * Process an Object.
+ * @param inputPort The input channel name of this object. + * @param object The object this input needs to process. + */ + public void doEvent(EventPort eventPort,Object object) throws IllegalEventPortNameException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/EventOutput.java b/src/main/java/com/idcanet/foei/event/EventOutput.java new file mode 100644 index 0000000..c144bf0 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventOutput.java @@ -0,0 +1,54 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.util.Collection; +import java.io.Serializable; + +/** + * An Object that implments thius interface can send events to
+ * inputsEvent objects.
+ *
+ * So send en event it most use the defined methods in EventBinding class. + * + * @author Willem Cazander + * @version 1.0 01/02/2005 + */ +public interface EventOutput extends Serializable { + /** + * Gets the current list of valid outputs. + * @return A List with the current EventPort's. + */ + public Collection getOutputPorts(); + + /** + * Gets an OutputPort by its name. + * @param name The name of the output port. + * @return Returns the outputPort + */ + public EventPort getOutputPort(String name); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/EventPort.java b/src/main/java/com/idcanet/foei/event/EventPort.java new file mode 100644 index 0000000..e89d24d --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventPort.java @@ -0,0 +1,167 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +/** + * Defines an EventPort which can be an input or output for + * traveling object.
+ *
+ * All the public final are for progroming + * + * @author Willem Cazander + * @version 1.0 18/04/2005 + */ +public class EventPort { + + /** public type for defining TRUE */ + static final public String TRUE = "true"; + /** public type for defining FALSE */ + static final public String FALSE = "false"; + /** public type for defining INPUT */ + static final public String INPUT = "input"; + /** public type for defining OUTPUT */ + static final public String OUTPUT = "output"; + /** public type for defining PASS */ + static final public String PASS = "pass"; + /** public type for defining DROP */ + static final public String DROP = "drop"; + + /** The name of the port */ + private String name = null; + /** The type of Object class which can be handled by the port.*/ + private Class objectType = null; + /** The total number of events this port has had. */ + private long eventsPassed = 0; + /** The type of event port */ + private EventPortType eventPortType = null; + /**The EventObject of this port */ + private Object eventObject = null; + /** The immediate if true i*/ + private boolean immediate = false; + + /** + * Contructs an EventPort with an name and a certain type. + *
+ * immediate has 2 defaults depending on the EventPortType of the EventPort.
+ * input=true
+ * output=false
+ * This defines the default behouvier of the foei events and newexecutors
+ * + * @param name The name of the EventPort. + * @param objectType The class type which it accepts. + */ + public EventPort(String name,Class objectType,EventPortType eventPortType,Object eventObject) { + if(name==null) { + throw new NullPointerException("name may not be null."); + } + if(objectType==null) { + throw new NullPointerException("eventPortType may not be null."); + } + if(eventPortType==null) { + throw new NullPointerException("eventPortType may not be null."); + } + if(eventObject==null) { + throw new NullPointerException("eventObject may not be null."); + } + this.name=name; + this.objectType=objectType; + this.eventPortType=eventPortType; + this.eventObject=eventObject; + + if(eventPortType==EventPortType.input) { + immediate=true; + } + if(eventPortType==EventPortType.output) { + immediate=false; + } + + } + + /** + * Returns the name of the EventPort. + * @return The name of the EventPort. + */ + public String getName() { + return name; + } + + /** + * Returns the class of the object this EventPort handleds. + * @return the class of the transfering object. + */ + public Class getObjectClass() { + return objectType; + } + + /** + * Adds the event to the eventsPassed value. + */ + public void addEventsPassed() { + eventsPassed++; + } + + + /** + * The number of events that this port has done. + * @return Returns the number of events of this port. + */ + public long getEventsPassed() { + return eventsPassed; + } + + /** + * Returns the EventPortType + * @return Returns the EventPortType. + */ + public EventPortType getEventPortType() { + return eventPortType; + } + + /** + * Gets the EventObject. + * @return Returns the EventObject. + */ + public Object getEventObject() { + return eventObject; + } + + /** + * Gets the immediate + * @return Returns immediate + */ + public boolean isImmediate() { + return immediate; + } + + /** + * Sets the immediate state of this event port + * @param immediate + */ + public void setImmediate(boolean immediate) { + this.immediate=immediate; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/EventPortType.java b/src/main/java/com/idcanet/foei/event/EventPortType.java new file mode 100644 index 0000000..fc434a0 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventPortType.java @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +/** + * EventPortType of an EventPort + * + * @author Willem Cazander + * @version 1.0 Mar 3, 2006 + */ +public enum EventPortType { + + /** + * Type for input ports + */ + input, + + /** + * Type for output ports + */ + output; +} diff --git a/src/main/java/com/idcanet/foei/event/EventStep.java b/src/main/java/com/idcanet/foei/event/EventStep.java new file mode 100644 index 0000000..29e1566 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventStep.java @@ -0,0 +1,46 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import java.io.Serializable; + +/** + * Process an object an gives an object back. + * + * @author Willem Cazander + * @version 1.0 27/02/2005 + */ +public interface EventStep extends Serializable { + + /** + * Process an object and gives it back. + * + * @param object The Object which need to be processed. + * @returns An object or null if not succesfull. + */ + public Object processObject(Object object) throws ClassCastException; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/EventStepController.java b/src/main/java/com/idcanet/foei/event/EventStepController.java new file mode 100644 index 0000000..4235596 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/EventStepController.java @@ -0,0 +1,67 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +import com.idcanet.foei.event.EventStep; + +import java.io.Serializable; +import java.util.List; + +/** + * The implementing object of this interface.
+ * Gets the possibilty to add/remove EventSteps.
+ * + * @author Willem Cazander + * @version 1.0 28/02/2005 + */ +public interface EventStepController extends Serializable { + + /** + * Adds an EventStep to the object. + * @param eventStep The EventStep to be added. + */ + public void addEventStep(EventStep eventStep); + + /** + * Removes an EventStep of the object. + * @param eventStep The EventStep to be removed. + */ + public void removeEventStep(EventStep eventStep); + + /** + * Gets an List of the EventSteps which are registrated to this object. + * @return The List of EventSteps. + */ + public List getEventSteps(); + + /** + * Executes all EventSteps until there is null or we are done. + * @param object + * @return + */ + public Object processEventSteps(Object object); +} diff --git a/src/main/java/com/idcanet/foei/event/IllegalEventPortNameException.java b/src/main/java/com/idcanet/foei/event/IllegalEventPortNameException.java new file mode 100644 index 0000000..dac860c --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/IllegalEventPortNameException.java @@ -0,0 +1,71 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event; + +/** + * May be throw when we try to send to in EventPort that doen't excists. + * + * @author Willem Cazander + * @version 1.0 Feb 4, 2006 + */ +public class IllegalEventPortNameException extends Exception +{ + /** Version 1.0 */ + final static long serialVersionUID = 10l; + + /** + * Constructs an IllegalEventPortNameException without a detail message. + */ + public IllegalEventPortNameException() { + super(); + } + + /** + * Constructs an IllegalEventPortNameException with a detail message. + * @param message The message of this Exception + */ + public IllegalEventPortNameException(String message) { + super(message); + } + + /** + * Creates an IllegalEventPortNameException from a parent exception. + * @param e The parent Exception + */ + public IllegalEventPortNameException(Exception e) { + super(e); + } + + /** + * Creates an IllegalEventPortNameException from a parent exception and a detail message + * @param message The message of this Exception + * @param e The parent Exception + */ + public IllegalEventPortNameException(String message,Exception e) { + super(message,e); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/annotations/SetEventPort.java b/src/main/java/com/idcanet/foei/event/annotations/SetEventPort.java new file mode 100644 index 0000000..b352b42 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/annotations/SetEventPort.java @@ -0,0 +1,70 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event.annotations; + +import com.idcanet.foei.event.EventPortType; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Defines an input EventPort + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2006 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SetEventPort { + + /** + * + * @return + */ + EventPortType type(); + + /** + * Gets the name of the input EventPort + * @return Returns the name of the input EventPort + */ + String name(); + + /** + * Gets the objectType of the input EventPort + * it defaults to Object.class but is lookuped in the annotated method. + * @return Returns the objectType of the input EventPort + */ + Class objectType() default Object.class; + + /** + * + * @return + */ + String immediate() default "null"; +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/annotations/SetEventPorts.java b/src/main/java/com/idcanet/foei/event/annotations/SetEventPorts.java new file mode 100644 index 0000000..8fcc109 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/annotations/SetEventPorts.java @@ -0,0 +1,49 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.event.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Defines an output EventPort + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2006 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface SetEventPorts { + + /** + * An array of SetEventPort annotations + * @return Returns an array of SetEventPort annotations + */ + SetEventPort[] ports(); +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/event/package.html b/src/main/java/com/idcanet/foei/event/package.html new file mode 100644 index 0000000..9a13aa3 --- /dev/null +++ b/src/main/java/com/idcanet/foei/event/package.html @@ -0,0 +1,61 @@ + + + + + + +Provides abstract classes and interfaces to send/receive events.
+ +

Package Specification

+ +
    +
  • Full J2SE 5 compatible
  • +
  • Small package
  • +
+ + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/FoeiContextManager.java b/src/main/java/com/idcanet/foei/server/FoeiContextManager.java new file mode 100644 index 0000000..6e8a71d --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/FoeiContextManager.java @@ -0,0 +1,112 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.server; + +import com.idcanet.foei.core.FoeiConfigurator; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.impl.FoeiConfiguratorImpl; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Manages the different FoeiContext. + * + * @author Willem Cazander + * @version 1.0 Feb 6, 2006 + */ +public class FoeiContextManager { + + /** The logger to log to. */ + private Logger logger = null; + /** All FoeiContext */ + private Map contexts = null; + + /** + * Inits the logger and the FoeiContext storage. + */ + public FoeiContextManager() { + logger = Logger.getLogger(FoeiContextManager.class.getName()); + contexts = new HashMap(2); + } + + /** + * Create an FoeiContext. + * @param properties The properties of the FoeiContext. + */ + public void createFoeiContext(Map properties) { + FoeiConfigurator config = null; + try { + config = (FoeiConfigurator) FoeiConfigurator.DEFAULT_FOEI_CONFIGURATOR.newInstance(); + logger.info("Building FoeiContext: "+FoeiConfiguratorImpl.getContextName(properties)); + FoeiContext context = config.buildFoeiContext(properties); + addFoeiContext(context); + } catch (Exception e) { + logger.log(Level.WARNING,"Error while starting FoeiContext: "+e.getMessage(),e); + } + } + + /** + * Add an FoeiContext + * @param foeiContext The FoeiContext to add. + */ + public void addFoeiContext(FoeiContext foeiContext) { + if(foeiContext==null) { + throw new NullPointerException("FoeiContext may not be null."); + } + contexts.put(foeiContext.getName(),foeiContext); + } + + /** + * USE AS LESS AS POSIBLE, MOSTLY NOT !!
+ * + * Be aware that a lot of functions in Foei depent on the + * thread locale being injected in the current thread. + * + * For sake of OO dividing layers its not recommened to do Foei Logic + * in the request/event/etc thread. + * + * Gets an FoeiContext by its name. + * @param name The name of the FoeiContext + * @return Returns the FoeiContext or null if none was found by its name. + */ + public FoeiContext getFoeiContext(String name) { + return contexts.get(name); + } + + + /** + * Destroys all FoeiContexts. + */ + public void destroyAll() { + for(FoeiContext context:contexts.values()) { + context.destroy(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/FoeiContextManagerFactory.java b/src/main/java/com/idcanet/foei/server/FoeiContextManagerFactory.java new file mode 100644 index 0000000..8a7a71b --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/FoeiContextManagerFactory.java @@ -0,0 +1,67 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.server; + +/** + * Provides the method to get the FoeiContextManager + * + * @author Willem Cazander + * @version 1.0 Feb 6, 2006 + */ +public class FoeiContextManagerFactory { + + /** */ + static private FoeiContextManager foeiContextManager = null; + + /** + * Gets the FoeiContextManager + * @return Returns the FoeiContextManager + */ + static public FoeiContextManager getFoeiContextManager() { + if(foeiContextManager==null) { + throw new IllegalStateException("no FoeiContextManager has been set."); + } + return foeiContextManager; + } + + /** + * Sets an FoeiContextManager.
+ * note: + * May only be set once !. + * + * @param foeiContextManager + */ + static public void setFoeiContextManager(FoeiContextManager foeiContextManager) { + if(foeiContextManager==null) { + throw new NullPointerException("foeiContextManager may not be null."); + } + if(FoeiContextManagerFactory.foeiContextManager!=null) { + throw new IllegalStateException("foeiContextManager may only be set once."); + } + FoeiContextManagerFactory.foeiContextManager=foeiContextManager; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/config/FoeiConfigContext.java b/src/main/java/com/idcanet/foei/server/config/FoeiConfigContext.java new file mode 100644 index 0000000..03de6a9 --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/config/FoeiConfigContext.java @@ -0,0 +1,37 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.server.config; + +import java.util.Map; + +public class FoeiConfigContext { + + private String name = null; + private Map properties = null; + private Map processes = null; + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/config/package.html b/src/main/java/com/idcanet/foei/server/config/package.html new file mode 100644 index 0000000..bdf2d88 --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/config/package.html @@ -0,0 +1,69 @@ + + + + + + +Provides some startup util classes for starting and config multipe Foei instances in a ServletContainer.
+ +

Package Specification

+ +We can access an FoeiContext here in the FoeiContextManager.
+Use with care !!
+
+To be sure of your code use something like:
+
+		FoeiContext foeiContext = FoeiContextManagerFactory.getFoeiContextManager().getFoeiContext("Test-Context");
+		FoeiContextFactory.bindFoeiContext(foeiContext);
+		// Do your stuff here.
+		//....
+		FoeiContextFactory.unbindFoeiContext();
+
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/package.html b/src/main/java/com/idcanet/foei/server/package.html new file mode 100644 index 0000000..97ab0e0 --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/package.html @@ -0,0 +1,55 @@ + + + + + + +Foei server objects
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/startup/FoeiStartupListener.java b/src/main/java/com/idcanet/foei/server/startup/FoeiStartupListener.java new file mode 100644 index 0000000..f7424aa --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/startup/FoeiStartupListener.java @@ -0,0 +1,103 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.server.startup; + +import com.idcanet.foei.core.FoeiConfigurator; +import com.idcanet.foei.server.FoeiContextManager; +import com.idcanet.foei.server.FoeiContextManagerFactory; + +import java.io.InputStream; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +/** + * Helps to startup Foei in a J2EE context. + * + * Its creates the FoeiContextManager and builds FoeiContext for us. + * + * @author Willem Cazander + * @version 1.0 Jan 20, 2006 + */ +public class FoeiStartupListener implements ServletContextListener { + + /** The logger to log to. */ + private Logger logger = null; + + /** The key for in web.xml */ + static public final String FOEI_CONFIG_RESOURCES = "FOEI_CONFIG_RESOURCES"; + + /** + * Starts Foei + */ + public void contextInitialized(ServletContextEvent event) { + logger = Logger.getLogger(FoeiStartupListener.class.getName()); + + // Creates FoeiContextManager + FoeiContextManager foeiContextManager = new FoeiContextManager(); + FoeiContextManagerFactory.setFoeiContextManager(foeiContextManager); + + String resources = event.getServletContext().getInitParameter(FOEI_CONFIG_RESOURCES); + if(resources==null) { + logger.warning("No "+FOEI_CONFIG_RESOURCES+" defined in web.xml not starting foei."); + return; + } + + String[] resource = resources.split(","); + for(String className:resource) { + try { + InputStream foeiProperties = this.getClass().getResourceAsStream(className); + if(foeiProperties==null) { + logger.warning("Can't load: '"+className+"'"); + continue; + } + Properties properties = new Properties(); + properties.load(foeiProperties); + foeiProperties.close(); + foeiContextManager.createFoeiContext(properties); + } catch (Exception e) { + logger.log(Level.WARNING,"Error while starting FoeiContext: "+e.getMessage(),e); + } + } + } + + /** + * Stop Foei + */ + public void contextDestroyed(ServletContextEvent event) { + logger.info("Stopping Foei Contexts"); + try { + FoeiContextManagerFactory.getFoeiContextManager().destroyAll(); + } catch (Exception e) { + logger.log(Level.WARNING,"Error while shutdowning Foei: "+e.getMessage(),e); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/server/startup/package.html b/src/main/java/com/idcanet/foei/server/startup/package.html new file mode 100644 index 0000000..bdf2d88 --- /dev/null +++ b/src/main/java/com/idcanet/foei/server/startup/package.html @@ -0,0 +1,69 @@ + + + + + + +Provides some startup util classes for starting and config multipe Foei instances in a ServletContainer.
+ +

Package Specification

+ +We can access an FoeiContext here in the FoeiContextManager.
+Use with care !!
+
+To be sure of your code use something like:
+
+		FoeiContext foeiContext = FoeiContextManagerFactory.getFoeiContextManager().getFoeiContext("Test-Context");
+		FoeiContextFactory.bindFoeiContext(foeiContext);
+		// Do your stuff here.
+		//....
+		FoeiContextFactory.unbindFoeiContext();
+
+ + + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/utils/jndi/ContextListWriter.java b/src/main/java/com/idcanet/foei/utils/jndi/ContextListWriter.java new file mode 100644 index 0000000..ce8b502 --- /dev/null +++ b/src/main/java/com/idcanet/foei/utils/jndi/ContextListWriter.java @@ -0,0 +1,70 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.utils.jndi; + +import javax.naming.Binding; +import javax.naming.Context; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import java.io.PrintStream; + +/** + * A util recursive method which prints the jndi tree. + * + * @author Willem Cazander + * @version 1.0 Jan 18, 2006 + */ +public class ContextListWriter { + + /** + * writes an context tree to the printstream out. + * @param out The printstream to which the text line are printed. + * @param ctx The context to list. + * @param indent The intext text for sub contexts. + */ + public static void writeContextTree(PrintStream out,Context ctx, String indent) { + + if(out==null | ctx==null | indent==null) { + return; + } + try { + NamingEnumeration list = ctx.listBindings(""); + while (list.hasMore()) { + Binding item = (Binding)list.next(); + String className = item.getClassName(); + String name = item.getName(); + out.println(indent+" class: "+className+" name="+name); + Object o = item.getObject(); + if (o instanceof javax.naming.Context) { + writeContextTree(out,(Context)o,indent+indent); + } + } + } catch (NamingException ne) { + out.println("Nameing Exception: "+ne.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/utils/jndi/MemoryContext.java b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContext.java new file mode 100644 index 0000000..7e20496 --- /dev/null +++ b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContext.java @@ -0,0 +1,670 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.utils.jndi; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.NoSuchElementException; + +import javax.naming.Binding; +import javax.naming.CompositeName; +import javax.naming.Context; +import javax.naming.InvalidNameException; +import javax.naming.Name; +import javax.naming.NameAlreadyBoundException; +import javax.naming.NameClassPair; +import javax.naming.NameNotFoundException; +import javax.naming.NameParser; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.NotContextException; +import javax.naming.OperationNotSupportedException; +import javax.naming.spi.NamingManager; + + +/** + * A sample service provider that implements a hierarchical namespace in memory. + * + * @author Willem Cazander + * @version 1.0 Jan 18, 2006 + */ +@SuppressWarnings("unchecked") +public class MemoryContext implements Context { + + protected Hashtable myEnv; + protected Hashtable bindings = new Hashtable(11); + protected final static NameParser myParser = new MemoryContextNameParser(); + protected MemoryContext parent = null; + protected String myAtomicName = null; + + /** + * Creates an new FoeiContext without an everment + * note: + * This should be done via an Factrory + * but then the server loader can not easaly load this class + */ + public MemoryContext() + { + //super()FoeiContext(null); + } + + MemoryContext(Hashtable inEnv) + { + myEnv = (inEnv != null) + ? (Hashtable)(inEnv.clone()) + : null; + } + + protected MemoryContext(MemoryContext parent, String name, Hashtable inEnv,Hashtable bindings) + { + this(inEnv); + this.parent = parent; + myAtomicName = name; + this.bindings = (Hashtable)bindings.clone(); + } + + protected Context createFoeiContext(MemoryContext parent, String name, Hashtable inEnv) + { + return new MemoryContext(parent, name, inEnv, new Hashtable(11)); + } + + protected Context cloneCtx() + { + return new MemoryContext(parent, myAtomicName, myEnv, bindings); + } + + /** + * Utility method for processing composite/compound name. + * @param name The non-null composite or compound name to process. + * @return The non-null string name in this namespace to be processed. + */ + protected Name getMyComponents(Name name) throws NamingException + { + if (name instanceof CompositeName) + { + if (name.size() > 1) + { + throw new InvalidNameException(name.toString()+" has more components than namespace can handle"); + } + // Turn component that belongs to us into compound name + return myParser.parse(name.get(0)); + } + // Already parsed + return name; + } + + public Object lookup(String name) throws NamingException + { + return lookup(new CompositeName(name)); + } + + public Object lookup(Name name) throws NamingException + { + if (name.isEmpty()) + { + return cloneCtx(); + } + + // Extract components that belong to this namespace + Name nm = getMyComponents(name); + String atom = nm.get(0); + Object inter = bindings.get(atom); + + if (nm.size() == 1) + { + // Atomic name: Find object in internal data structure + if (inter == null) + { + throw new NameNotFoundException(name + " not found"); + } + + // Call getObjectInstance for using any object factories + try + { + return NamingManager.getObjectInstance(inter,new CompositeName().add(atom),this, myEnv); + } + catch (Exception e) + { + NamingException ne = new NamingException("getObjectInstance failed"); + ne.setRootCause(e); + throw ne; + } + } + // else + // { + // Intermediate name: Consume name in this context and continue + if (!(inter instanceof Context)) + { + throw new NotContextException(atom+" does not name a context"); + } + return ((Context)inter).lookup(nm.getSuffix(1)); + // } + } + + public void bind(String name, Object obj) throws NamingException + { + bind(new CompositeName(name), obj); + } + + public void bind(Name name, Object obj) throws NamingException + { + if (name.isEmpty()) + { + throw new InvalidNameException("Cannot bind empty name"); + } + + Name nm = getMyComponents(name); + String atom = nm.get(0); + Object inter = bindings.get(atom); + + if (nm.size() == 1) + { + // Atomic name: Find object in internal data structure + if (inter != null) + { + throw new NameAlreadyBoundException("Use rebind to override"); + } + + // Call getStateToBind for using any state factories + obj = NamingManager.getStateToBind(obj,new CompositeName().add(atom),this, myEnv); + + // Add object to internal data structure + bindings.put(atom, obj); + } + else + { + // Intermediate name: Consume name in this context and continue + if(inter==null) + { + // auto create sub context. + inter = createSubcontext(atom); + } + + if (!(inter instanceof Context)) + { + throw new NotContextException(atom+" does not name a context"); + } + ((Context)inter).bind(nm.getSuffix(1), obj); + } + } + + public void rebind(String name, Object obj) throws NamingException + { + rebind(new CompositeName(name), obj); + } + + public void rebind(Name name, Object obj) throws NamingException + { + if (name.isEmpty()) + { + throw new InvalidNameException("Cannot bind empty name"); + } + + // Extract components that belong to this namespace + Name nm = getMyComponents(name); + String atom = nm.get(0); + + if (nm.size() == 1) + { + // Atomic name + // Call getStateToBind for using any state factories + obj = NamingManager.getStateToBind(obj,new CompositeName().add(atom),this, myEnv); + + // Add object to internal data structure + bindings.put(atom, obj); + } + else + { + // Intermediate name: Consume name in this context and continue + Object inter = bindings.get(atom); + if(inter==null) + { + // auto create sub context. + inter = createSubcontext(atom); + } + + if (!(inter instanceof Context)) + { + throw new NotContextException(atom+" does not name a context"); + } + ((Context)inter).rebind(nm.getSuffix(1), obj); + } + } + + public void unbind(String name) throws NamingException + { + unbind(new CompositeName(name)); + } + + public void unbind(Name name) throws NamingException + { + if (name.isEmpty()) + { + throw new InvalidNameException("Cannot unbind empty name"); + } + + // Extract components that belong to this namespace + Name nm = getMyComponents(name); + String atom = nm.get(0); + + // Remove object from internal data structure + if (nm.size() == 1) + { + // Atomic name: Find object in internal data structure + bindings.remove(atom); + } + else + { + // Intermediate name: Consume name in this context and continue + Object inter = bindings.get(atom); + if (!(inter instanceof Context)) + { + throw new NotContextException(atom+" does not name a context"); + } + ((Context)inter).unbind(nm.getSuffix(1)); + } + } + + public void rename(String oldName, String newName) throws NamingException + { + rename(new CompositeName(oldName), new CompositeName(newName)); + } + + public void rename(Name oldname, Name newname) throws NamingException + { + if (oldname.isEmpty() || newname.isEmpty()) + { + throw new InvalidNameException("Cannot rename empty name"); + } + + Name oldnm = getMyComponents(oldname); + Name newnm = getMyComponents(newname); + + // Simplistic implementation: support only rename within same context + if (oldnm.size() != newnm.size()) + { + throw new OperationNotSupportedException("Do not support rename across different contexts"); + } + + String oldatom = oldnm.get(0); + String newatom = newnm.get(0); + + if (oldnm.size() == 1) + { + if (bindings.get(newatom) != null) + { + throw new NameAlreadyBoundException(newname.toString()+" is already bound"); + } + + // Check if old name is bound + Object oldBinding = bindings.remove(oldatom); + if (oldBinding == null) + { + throw new NameNotFoundException(oldname.toString() + " not bound"); + } + bindings.put(newatom, oldBinding); + } + else + { + if (!oldatom.equals(newatom)) + { + throw new OperationNotSupportedException("Do not support rename across different contexts"); + } + + // Intermediate name: Consume name in this context and continue + Object inter = bindings.get(oldatom); + if (!(inter instanceof Context)) + { + throw new NotContextException(oldatom+" does not name a context"); + } + ((Context)inter).rename(oldnm.getSuffix(1), newnm.getSuffix(1)); + } + } + + public NamingEnumeration list(String name) throws NamingException + { + return list(new CompositeName(name)); + } + + public NamingEnumeration list(Name name) throws NamingException + { + if (name.isEmpty()) + { + // listing this context + return new ListOfNames(bindings.keys()); + } + + // Perhaps 'name' names a context + Object target = lookup(name); + if (target instanceof Context) + { + return ((Context)target).list(""); + } + throw new NotContextException(name + " cannot be listed"); + } + + public NamingEnumeration listBindings(String name) throws NamingException + { + return listBindings(new CompositeName(name)); + } + + public NamingEnumeration listBindings(Name name) throws NamingException + { + //System.err.println("FoeiContext list bindings is called "+this+" map size:"+bindings.size()); + + if (name.isEmpty()) { + // listing this context + return new ListOfBindings(bindings.keys()); + } + + // Perhaps 'name' names a context + Object target = lookup(name); + if (target instanceof Context) { + return ((Context)target).listBindings(""); + } + throw new NotContextException(name + " cannot be listed"); + } + + public void destroySubcontext(String name) throws NamingException { + destroySubcontext(new CompositeName(name)); + } + + public void destroySubcontext(Name name) throws NamingException + { + if (name.isEmpty()) + { + throw new InvalidNameException("Cannot destroy context using empty name"); + } + + // Simplistic implementation: not checking for nonempty context first + // Use same implementation as unbind + unbind(name); + } + + public Context createSubcontext(String name) throws NamingException + { + return createSubcontext(new CompositeName(name)); + } + + public Context createSubcontext(Name name) throws NamingException + { + if (name.isEmpty()) + { + throw new InvalidNameException("Cannot bind empty name"); + } + + // Extract components that belong to this namespace + Name nm = getMyComponents(name); + String atom = nm.get(0); + Object inter = bindings.get(atom); + + if (nm.size() == 1) + { + // Atomic name: Find object in internal data structure + if (inter != null) + { + throw new NameAlreadyBoundException("Use rebind to override"); + } + + // Create child + Context child = createFoeiContext(this, atom, myEnv); + + // Add child to internal data structure + bindings.put(atom, child); + return child; + } + else + { + // Intermediate name: Consume name in this context and continue + if (!(inter instanceof Context)) + { + throw new NotContextException(atom+" does not name a context"); + } + return ((Context)inter).createSubcontext(nm.getSuffix(1)); + } + } + + public Object lookupLink(String name) throws NamingException + { + return lookupLink(new CompositeName(name)); + } + + public Object lookupLink(Name name) throws NamingException + { + return lookup(name); + } + + public NameParser getNameParser(String name) throws NamingException + { + return getNameParser(new CompositeName(name)); + } + + public NameParser getNameParser(Name name) throws NamingException + { + // Do lookup to verify name exists + Object obj = lookup(name); + if (obj instanceof Context) + { + ((Context)obj).close(); + } + return myParser; + } + + public String composeName(String name, String prefix) throws NamingException + { + Name result = composeName(new CompositeName(name),new CompositeName(prefix)); + return result.toString(); + } + + public Name composeName(Name name, Name prefix) throws NamingException + { + Name result; + + // Both are compound names, compose using compound name rules + if (!(name instanceof CompositeName) && !(prefix instanceof CompositeName)) + { + result = (Name)(prefix.clone()); + result.addAll(name); + return new CompositeName().add(result.toString()); + } + + // Simplistic implementation: do not support federation + throw new OperationNotSupportedException("Do not support composing composite names"); + } + + public Object addToEnvironment(String propName, Object propVal) throws NamingException + { + if (myEnv == null) + { + myEnv = new Hashtable(5, 0.75f); + } + return myEnv.put(propName, propVal); + } + + public Object removeFromEnvironment(String propName) throws NamingException + { + if (myEnv == null) + { + return null; + } + return myEnv.remove(propName); + } + + public Hashtable getEnvironment() throws NamingException + { + if (myEnv == null) + { + return new Hashtable(3, 0.75f); + } + else + { + return (Hashtable)myEnv.clone(); + } + } + + public String getNameInNamespace() throws NamingException + { + MemoryContext ancestor = parent; + + // No ancestor + if (ancestor == null) + { + return ""; + } + + Name name = myParser.parse(""); + name.add(myAtomicName); + + // Get parent's names + while (ancestor != null && ancestor.myAtomicName != null) + { + name.add(0, ancestor.myAtomicName); + ancestor = ancestor.parent; + } + return name.toString(); + } + + public String toString() + { + if (myAtomicName != null) + { + return myAtomicName; + } + else + { + return "ROOT CONTEXT"; + } + } + + public void close() throws NamingException + { + } + + // Class for enumerating name/class pairs + class ListOfNames implements NamingEnumeration { + protected Enumeration names; + + ListOfNames (Enumeration names) { + this.names = names; + } + + public boolean hasMoreElements() { + try { + return hasMore(); + } catch (NamingException e) { + return false; + } + } + + public boolean hasMore() throws NamingException { + return names.hasMoreElements(); + } + + public Object next() throws NamingException { + String name = (String)names.nextElement(); + String className = bindings.get(name).getClass().getName(); + return new NameClassPair(name, className); + } + + public Object nextElement() { + try { + return next(); + } catch (NamingException e) { + throw new NoSuchElementException(e.toString()); + } + } + + public void close() { + } + } + + // Class for enumerating bindings + class ListOfBindings extends ListOfNames { + + ListOfBindings(Enumeration names) { + super(names); + } + + public Object next() throws NamingException { + String name = (String)names.nextElement(); + Object obj = bindings.get(name); + + try { + obj = NamingManager.getObjectInstance(obj, + new CompositeName().add(name), MemoryContext.this, + MemoryContext.this.myEnv); + } catch (Exception e) { + NamingException ne = new NamingException( + "getObjectInstance failed"); + ne.setRootCause(e); + throw ne; + } + + return new Binding(name, obj); + } + } + + /* + static FoeiContext testRoot; + static { + try { + testRoot = new FoeiContext(null); + + Context a = testRoot.createSubcontext("a"); + Context b = a.createSubcontext("b"); + Context c = b.createSubcontext("c"); + + testRoot.createSubcontext("x"); + testRoot.createSubcontext("y"); + } catch (NamingException e) { + } + } + + public static Context getStaticNamespace(Hashtable env) { + return testRoot; + } + + public static void main(String[] args) { + try { + Context ctx = new FoeiContext(null); + + Context a = ctx.createSubcontext("a"); + Context b = a.createSubcontext("b"); + Context c = b.createSubcontext("c"); + + System.out.println(c.getNameInNamespace()); + + System.out.println(ctx.lookup("")); + System.out.println(ctx.lookup("a")); + System.out.println(ctx.lookup("b.a")); + System.out.println(a.lookup("c.b")); + } catch (NamingException e) { + e.printStackTrace(); + } + } + */ +} diff --git a/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextFactory.java b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextFactory.java new file mode 100644 index 0000000..d38ac66 --- /dev/null +++ b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextFactory.java @@ -0,0 +1,61 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.utils.jndi; + +import java.util.Hashtable; +import javax.naming.spi.InitialContextFactory; +import javax.naming.Context; +import javax.naming.NamingException; + + +/** + * Creates an new MemoryContext + * + * @author Willem Cazander + * @version 1.0 Jan 18, 2006 + * + */ +public class MemoryContextFactory implements InitialContextFactory { + + /** Stores the jvm wide instance of the FoeiContext */ + static private Context context = null; + + /** + * Returns the FoeiContext + * @param environment + * @return + * @throws NamingException + */ + @SuppressWarnings("unchecked") + public Context getInitialContext(Hashtable environment) throws NamingException { + if (context!=null) { + return context; + } + context = new MemoryContext(environment); + return context; + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextNameParser.java b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextNameParser.java new file mode 100644 index 0000000..bf818bf --- /dev/null +++ b/src/main/java/com/idcanet/foei/utils/jndi/MemoryContextNameParser.java @@ -0,0 +1,66 @@ +/* + * Copyright 2004-2006 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei.utils.jndi; + +import java.util.Properties; +import javax.naming.NameParser; +import javax.naming.Name; +import javax.naming.CompoundName; +import javax.naming.NamingException; + +/** + * A jndi name parser + * + * @author Willem Cazander + * @version 1.0 Jan 18, 2006 + */ +class MemoryContextNameParser implements NameParser { + + /** The syntax to use. */ + private static Properties syntax = null; + + static { + try { + syntax = new Properties(); + syntax.put("jndi.syntax.direction", "left_to_right"); + syntax.put("jndi.syntax.separator", "."); + syntax.put("jndi.syntax.ignorecase", "false"); + syntax.put("jndi.syntax.escape", "\\"); + syntax.put("jndi.syntax.beginquote", "'"); + } catch (Exception e) { + throw new RuntimeException("Error while creating FoeiNameParser",e); + } + } + + /** + * Parses the String name into an Jndi name. + * @see NameParser#parse(java.lang.String) + */ + public Name parse(String name) throws NamingException { + return new CompoundName(name, syntax); + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/foei/utils/jndi/package.html b/src/main/java/com/idcanet/foei/utils/jndi/package.html new file mode 100644 index 0000000..31461d4 --- /dev/null +++ b/src/main/java/com/idcanet/foei/utils/jndi/package.html @@ -0,0 +1,61 @@ + + + + + + +Defines an MemoryContext for storing object in a jndi tree.
+ +

Package Specification

+ +
    +
  • Full J2SE 5 compatible
  • +
  • Small package
  • +
+ + +

Related Documentation

+ +None. + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-context-defaults.xml b/src/main/resources/META-INF/foei-context-defaults.xml new file mode 100644 index 0000000..ef2c196 --- /dev/null +++ b/src/main/resources/META-INF/foei-context-defaults.xml @@ -0,0 +1,23 @@ + + + + + + + + + com.idcanet.foei.core.impl.ObjectBindingsManagerImpl + + diff --git a/src/main/resources/META-INF/foei-events.eld b/src/main/resources/META-INF/foei-events.eld new file mode 100644 index 0000000..4ffc61b --- /dev/null +++ b/src/main/resources/META-INF/foei-events.eld @@ -0,0 +1,29 @@ + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-filters.eld b/src/main/resources/META-INF/foei-filters.eld new file mode 100644 index 0000000..17acc49 --- /dev/null +++ b/src/main/resources/META-INF/foei-filters.eld @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-io.eld b/src/main/resources/META-INF/foei-io.eld new file mode 100644 index 0000000..47f0cb0 --- /dev/null +++ b/src/main/resources/META-INF/foei-io.eld @@ -0,0 +1,33 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-lang.eld b/src/main/resources/META-INF/foei-lang.eld new file mode 100644 index 0000000..ab144aa --- /dev/null +++ b/src/main/resources/META-INF/foei-lang.eld @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-logging.eld b/src/main/resources/META-INF/foei-logging.eld new file mode 100644 index 0000000..896ae95 --- /dev/null +++ b/src/main/resources/META-INF/foei-logging.eld @@ -0,0 +1,29 @@ + + + + + diff --git a/src/main/resources/META-INF/foei-namespaces.xml b/src/main/resources/META-INF/foei-namespaces.xml new file mode 100644 index 0000000..53f2fe3 --- /dev/null +++ b/src/main/resources/META-INF/foei-namespaces.xml @@ -0,0 +1,13 @@ + + + + + Foei namespace + + /META-INF/foei-events.eld + /META-INF/foei-filters.eld + /META-INF/foei-io.eld + /META-INF/foei-lang.eld + /META-INF/foei-logging.eld + /META-INF/foei-printers.eld + \ No newline at end of file diff --git a/src/main/resources/META-INF/foei-printers.eld b/src/main/resources/META-INF/foei-printers.eld new file mode 100644 index 0000000..b2d541e --- /dev/null +++ b/src/main/resources/META-INF/foei-printers.eld @@ -0,0 +1,32 @@ + + + + + + + + \ No newline at end of file diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt new file mode 100644 index 0000000..b0efedd --- /dev/null +++ b/src/site/apt/index.apt @@ -0,0 +1,20 @@ +Welcome too the FOEI project. + + FOEI is a Event -> Input -> Filter -> Output framework. + +* Goals Overview + + Make event based processing really simple. + + +* Usage + + Instructions on how to use FOEI can be found {{{usage.html}here.}} + +* Examples + + Todo put an example here. + + {{{example1.html}example1}} + + {{{example2.html}example1}} diff --git a/src/site/changes.xml b/src/site/changes.xml new file mode 100644 index 0000000..23b8814 --- /dev/null +++ b/src/site/changes.xml @@ -0,0 +1,14 @@ + + + + Changes FOEI Project + Willem Cazander + + + + + Released 0.8 of x4o. + + + + \ No newline at end of file diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml new file mode 100644 index 0000000..a328ed8 --- /dev/null +++ b/src/site/fml/faq.fml @@ -0,0 +1,22 @@ + + + + + General + + + What is FOEI + +

FOEI is an filter framework.

+
+
+ + + What is the linence of FOEI + +

FOEI has an BSD style licence, use it for free as beer.

+
+
+ +
+
diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..a9a461c --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,35 @@ + + + docbook/images/logo-x4o.png + http://www.idca.nl/media/idca/images/logo_correct.gif + + + + + + + + + + + + + + + + + + + + + + + ${reports} + + + diff --git a/src/test/java/com/idcanet/foei/SimpleFoeiTests.java b/src/test/java/com/idcanet/foei/SimpleFoeiTests.java new file mode 100644 index 0000000..bd29205 --- /dev/null +++ b/src/test/java/com/idcanet/foei/SimpleFoeiTests.java @@ -0,0 +1,166 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei; + +import java.io.InputStream; +import java.util.Date; +import java.util.Properties; + +import com.idcanet.foei.components.lang.DummyOutputPort; +import com.idcanet.foei.components.lang.Filter; +import com.idcanet.foei.core.FoeiContext; +import com.idcanet.foei.core.FoeiProcess; +import com.idcanet.foei.event.AbstractEventInput; +import com.idcanet.foei.event.EventPort; +import com.idcanet.foei.event.IllegalEventPortNameException; +import com.idcanet.foei.server.FoeiContextManager; +import com.idcanet.foei.server.FoeiContextManagerFactory; + +import junit.framework.TestCase; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jul 27, 2006 + */ +public class SimpleFoeiTests extends TestCase { + + private static FoeiContext test0 = null; + + private void start() throws Exception { + if (test0!=null) { + return; + } + + // Creates FoeiContextManager + FoeiContextManager foeiContextManager = new FoeiContextManager(); + FoeiContextManagerFactory.setFoeiContextManager(foeiContextManager); + + InputStream foeiProperties = this.getClass().getResourceAsStream("/META-INF/test-foei.properties"); + Properties properties = new Properties(); + properties.load(foeiProperties); + foeiProperties.close(); + //properties.put(FoeiConfigurator.ROOT_PATH,"/tmp"); + foeiContextManager.createFoeiContext(properties); + + test0 = foeiContextManager.getFoeiContext("TEST-0"); + } + + public void testStartup() throws Exception { + start(); + assertNotNull(test0); + } + + public void testFoeiProcessLife() throws Exception { + start(); + FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testProces",test0); + assertNotNull(proc); + test0.getFoeiProcessManager().destroyFoeiProcess("testProces"); + assertNull(test0.getFoeiProcessManager().getFoeiProcess("testProces")); + } + + + + public void testSimpleSpeed() throws Exception { + start(); + FoeiProcess proc = test0.getFoeiProcessManager().createFoeiProcess("testSpeed0",test0); + assertNotNull(proc); + + DummyOutputPort in = new DummyOutputPort(); + Filter f1 = new Filter(); + Filter f2 = new Filter(); + Filter f3 = new Filter(); + SpeedTestPort out = new SpeedTestPort(); + + //in.getOutputPort(EventPort.OUTPUT).setImmediate(true); + + // saves 300ms on 100k records + f1.getOutputPort(EventPort.PASS).setImmediate(true); + f2.getOutputPort(EventPort.PASS).setImmediate(true); + f3.getOutputPort(EventPort.PASS).setImmediate(true); + + // has no effect !! + //out.getInputPort(EventPort.INPUT).setImmediate(true); + + proc.addBinding(in.getOutputPort(EventPort.OUTPUT), f1.getInputPort(EventPort.INPUT)); + proc.addBinding(f1.getOutputPort(EventPort.PASS), f2.getInputPort(EventPort.INPUT)); + proc.addBinding(f2.getOutputPort(EventPort.PASS), f3.getInputPort(EventPort.INPUT)); + proc.addBinding(f3.getOutputPort(EventPort.PASS), out.getInputPort(EventPort.INPUT)); + + long startTime = System.currentTimeMillis(); + for (int i=0;i<100000;i++) { + SpeedModel m = new SpeedModel(); + + // IN FOEI it is; + //proc.executeEvent(in.getOutputPort(EventPort.OUTPUT), m); + + // running outside foei context thread use; + proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), m, proc); + } + proc.getFoeiContext().getEventExecutorManager().executeEvent(in.getOutputPort(EventPort.OUTPUT), new Date(), proc); + long endTime = System.currentTimeMillis(); + System.out.println("Done sending in: "+(endTime-startTime)+" ms."); + Thread.sleep(5000); // todo: create destory context on end of event que + System.out.println("End speedtest"); + test0.getFoeiProcessManager().destroyFoeiProcess("testSpeed0"); + } + +} +class SpeedModel { + Date dateCreated = new Date(); + Date dateDone = null; +} +class SpeedTestPort extends AbstractEventInput { + + /** v1.0 */ + static final long serialVersionUID = 10l; + Date startTime = new Date(); + + + /** + * Creates the output port + */ + public SpeedTestPort() { + addInputPort(EventPort.INPUT,Object.class); + } + + /** + * @see com.idcanet.foei.event.AbstractEventInput#doEvent(com.idcanet.foei.event.EventPort, java.lang.Object) + */ + @Override + public void doEvent(EventPort eventPort, Object object) throws IllegalEventPortNameException { + if (object instanceof SpeedModel) { + SpeedModel m = (SpeedModel)object; + m.dateDone=new Date(); + return; + } + // other object == end of test + long endTime = System.currentTimeMillis(); + System.out.println("End of test: "+(endTime-startTime.getTime())+" ms."); + } +} \ No newline at end of file diff --git a/src/test/java/com/idcanet/foei/TestEventThreadListener.java b/src/test/java/com/idcanet/foei/TestEventThreadListener.java new file mode 100644 index 0000000..da12890 --- /dev/null +++ b/src/test/java/com/idcanet/foei/TestEventThreadListener.java @@ -0,0 +1,47 @@ +/* + * Copyright 2004-2008 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.foei; + +import com.idcanet.foei.core.EventThreadListener; +import com.idcanet.foei.core.FoeiContext; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Jul 27, 2006 + */ +public class TestEventThreadListener implements EventThreadListener { + + public void startThread(FoeiContext foeiContext) { + System.out.println("START: "+Thread.currentThread().getName()+" context: "+foeiContext.getName()); + } + + public void stopThread(FoeiContext foeiContext) { + System.out.println("STOP: "+Thread.currentThread().getName()+" context: "+foeiContext.getName()); + } +} \ No newline at end of file diff --git a/src/test/resources/META-INF/test-foei-config.xml b/src/test/resources/META-INF/test-foei-config.xml new file mode 100644 index 0000000..05f5afd --- /dev/null +++ b/src/test/resources/META-INF/test-foei-config.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/META-INF/test-foei.properties b/src/test/resources/META-INF/test-foei.properties new file mode 100644 index 0000000..127520f --- /dev/null +++ b/src/test/resources/META-INF/test-foei.properties @@ -0,0 +1,26 @@ + +foei.context_name=TEST-0 + +foei.event_thread_listeners=com.idcanet.foei.TestEventThreadListener + +foei.event_executor_manager.pool_core_size=5 +foei.event_executor_manager.pool_max_size=10 +foei.event_executor_manager.pool_keep_alive=300 + +############ +## DEFAULTS ## +############ +# +#foei.context_name= +#foei.root_path= +# +#foei.object_bindings_manager=com.idca.foei.core.impl.ObjectBindingsManagerImpl +#foei.event_executor=com.idca.foei.core.impl.EventExecutorImpl +#foei.event_executor_manager=com.idca.foei.core.impl.EventExecutorManagerImpl +#foei.event_executor_manager.pool_core_size=3 +#foei.event_executor_manager.pool_max_size=5 +#foei.event_executor_manager.pool_keep_alive=180 +#foei.initial_object_context_factory=com.idca.foei.utils.jndi.MemoryContextFactory +#foei.event_thread_listeners= +#foei.x2o_root_tag=foei +#foei.x2o_default_element_configurator=com.idca.foei.xml.x2o.DefaultX2OElementConfigurator