(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