[jboss-svn-commits] JBL Code SVN: r21402 - in labs/jbossrules/trunk/drools-jsr94/src: main/java/org/drools/jsr94/rules/admin and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 7 20:44:16 EDT 2008


Author: michael.neale at jboss.com
Date: 2008-08-07 20:44:15 -0400 (Thu, 07 Aug 2008)
New Revision: 21402

Added:
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/DefaultRuleExecutionSetRepository.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepository.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryException.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoader.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/package.html
   labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/
   labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoaderTest.java
   labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/TestRuleExecutionSetRepository.java
Removed:
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetRepository.java
Modified:
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleRuntimeImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleServiceProviderImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java
   labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleAdministratorImpl.java
Log:
JBRULES-1721 patch from Rainer Langbehn for repository support in JSR-94

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/AbstractRuleSessionImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,148 +1,168 @@
-package org.drools.jsr94.rules;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.rules.InvalidRuleSessionException;
-import javax.rules.RuleExecutionSetMetadata;
-import javax.rules.RuleSession;
-import javax.rules.admin.RuleExecutionSet;
-
-import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
-import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
-
-/**
- * The Drools implementation of the <code>RuleSession</code> interface which is
- * a representation of a client session with a rules engine. A rules engine
- * session serves as an entry point into an underlying rules engine. The
- * <code>RuleSession</code> is bound to a rules engine instance and exposes a
- * vendor-neutral rule processing API for executing <code>Rule</code>s within a
- * bound <code>RuleExecutionSet</code>.
- * <p/>
- * Note: the <code>release</code> method must be called to clean up all
- * resources used by the <code>RuleSession</code>. Calling <code>release</code>
- * may make the <code>RuleSession</code> eligible to be returned to a
- * <code>RuleSession</code> pool.
- *
- * @see RuleSession
- *
- * @author N. Alex Rupp (n_alex <at>codehaus.org)
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-abstract class AbstractRuleSessionImpl
-    implements
-    RuleSession {
-    private RuleExecutionSetRepository repository;
-
-    public AbstractRuleSessionImpl(final RuleExecutionSetRepository repository) {
-        this.repository = repository;
-    }
-    
-    /**
-     * The Drools <code>RuleExecutionSet</code> associated
-     * with this <code>RuleSession</code>.
-     */
-    private RuleExecutionSetImpl ruleExecutionSet;
-
-    /**
-     * A <code>Map</code> of <code>String</code>/<code>Object</code> pairs
-     * passed as application data to the Drools <code>WorkingMemory</code>.
-     */
-    private Map                  properties;
-
-    /**
-     * Sets additional properties used to create this <code>RuleSession</code>.
-     *
-     * @param properties additional properties used to create the
-     *        <code>RuleSession</code> implementation.
-     */
-    protected void setProperties(final Map properties) {
-        this.properties = properties;
-    }
-
-    /**
-     * Returns the additional properties used to create this
-     * <code>RuleSession</code>.
-     *
-     * @return the additional properties used to create this
-     *         <code>RuleSession</code>.
-     */
-    protected Map getProperties() {
-        return this.properties;
-    }
-
-    /**
-     * Sets the Drools <code>RuleExecutionSet</code> associated
-     * with this <code>RuleSession</code>.
-     *
-     * @param ruleExecutionSet the Drools <code>RuleExecutionSet</code> to associate
-     *        with this <code>RuleSession</code>.
-     */
-    protected void setRuleExecutionSet(final RuleExecutionSetImpl ruleExecutionSet) {
-        this.ruleExecutionSet = ruleExecutionSet;
-    }
-
-    /**
-     * Returns the Drools <code>RuleExecutionSet</code> associated
-     * with this <code>RuleSession</code>.
-     *
-     * @return the Drools <code>RuleExecutionSet</code> associated
-     * with this <code>RuleSession</code>.
-     */
-    protected RuleExecutionSetImpl getRuleExecutionSet() {
-        return this.ruleExecutionSet;
-    }
-    
-    protected abstract void checkRuleSessionValidity() throws InvalidRuleSessionException;    
-    
-
-    // JSR94 interface methods start here -------------------------------------
-
-    /**
-     * Returns the meta data for the rule execution set bound to this rule
-     * session.
-     *
-     * @return the RuleExecutionSetMetaData bound to this rule session.
-     */
-    public RuleExecutionSetMetadata getRuleExecutionSetMetadata() {
-        String theBindUri = null;
-        for ( final Iterator i = this.repository.getRegistrations().iterator(); i.hasNext(); ) {
-            final String aBindUri = (String) i.next();
-            final RuleExecutionSet aRuleSet = this.repository.getRuleExecutionSet( aBindUri );
-            if ( aRuleSet == this.ruleExecutionSet ) {
-                theBindUri = aBindUri;
-                break;
-            }
-        }
-
-        return new RuleExecutionSetMetadataImpl( theBindUri,
-                                                 this.ruleExecutionSet.getName(),
-                                                 this.ruleExecutionSet.getDescription() );
-    }
-
-    /**
-     * Releases all resources used by this rule session.
-     * This method renders this rule session unusable until
-     * it is reacquired through the <code>RuleRuntime</code>.
-     */
-    public void release() {
-        setProperties( null );
-        setRuleExecutionSet( null );
-    }
-}
+package org.drools.jsr94.rules;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.InvalidRuleSessionException;
+import javax.rules.RuleExecutionSetMetadata;
+import javax.rules.RuleSession;
+import javax.rules.admin.RuleExecutionSet;
+
+import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;
+
+/**
+ * The Drools implementation of the <code>RuleSession</code> interface which is
+ * a representation of a client session with a rules engine. A rules engine
+ * session serves as an entry point into an underlying rules engine. The
+ * <code>RuleSession</code> is bound to a rules engine instance and exposes a
+ * vendor-neutral rule processing API for executing <code>Rule</code>s within a
+ * bound <code>RuleExecutionSet</code>.
+ * <p/>
+ * Note: the <code>release</code> method must be called to clean up all
+ * resources used by the <code>RuleSession</code>. Calling <code>release</code>
+ * may make the <code>RuleSession</code> eligible to be returned to a
+ * <code>RuleSession</code> pool.
+ *
+ * @see RuleSession
+ *
+ * @author N. Alex Rupp (n_alex <at>codehaus.org)
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+abstract class AbstractRuleSessionImpl
+    implements
+    RuleSession {
+    private RuleExecutionSetRepository repository;
+
+    public AbstractRuleSessionImpl(final RuleExecutionSetRepository repository) {
+        this.repository = repository;
+    }
+    
+    /**
+     * The Drools <code>RuleExecutionSet</code> associated
+     * with this <code>RuleSession</code>.
+     */
+    private RuleExecutionSetImpl ruleExecutionSet;
+
+    /**
+     * A <code>Map</code> of <code>String</code>/<code>Object</code> pairs
+     * passed as application data to the Drools <code>WorkingMemory</code>.
+     */
+    private Map                  properties;
+
+    /**
+     * Sets additional properties used to create this <code>RuleSession</code>.
+     *
+     * @param properties additional properties used to create the
+     *        <code>RuleSession</code> implementation.
+     */
+    protected void setProperties(final Map properties) {
+        this.properties = properties;
+    }
+
+    /**
+     * Returns the additional properties used to create this
+     * <code>RuleSession</code>.
+     *
+     * @return the additional properties used to create this
+     *         <code>RuleSession</code>.
+     */
+    protected Map getProperties() {
+        return this.properties;
+    }
+
+    /**
+     * Sets the Drools <code>RuleExecutionSet</code> associated
+     * with this <code>RuleSession</code>.
+     *
+     * @param ruleExecutionSet the Drools <code>RuleExecutionSet</code> to associate
+     *        with this <code>RuleSession</code>.
+     */
+    protected void setRuleExecutionSet(final RuleExecutionSetImpl ruleExecutionSet) {
+        this.ruleExecutionSet = ruleExecutionSet;
+    }
+
+    /**
+     * Returns the Drools <code>RuleExecutionSet</code> associated
+     * with this <code>RuleSession</code>.
+     *
+     * @return the Drools <code>RuleExecutionSet</code> associated
+     * with this <code>RuleSession</code>.
+     */
+    protected RuleExecutionSetImpl getRuleExecutionSet() {
+        return this.ruleExecutionSet;
+    }
+    
+    protected abstract void checkRuleSessionValidity() throws InvalidRuleSessionException;    
+    
+
+    // JSR94 interface methods start here -------------------------------------
+
+    /**
+     * Returns the meta data for the rule execution set bound to this rule
+     * session.
+     *
+     * @return the RuleExecutionSetMetaData bound to this rule session.
+     */
+    public RuleExecutionSetMetadata getRuleExecutionSetMetadata() {
+        String theBindUri = null;
+        List registrations = null;
+        
+		try {
+			registrations = this.repository.getRegistrations();
+		} catch (RuleExecutionSetRepositoryException e) {
+			String s = "Error while retrieving rule execution set registrations";
+			throw new RuntimeException(s, e);
+		}
+        
+        for ( final Iterator i = registrations.iterator(); i.hasNext(); ) {
+            final String aBindUri = (String) i.next();
+            // FIXME: provide the correct properties
+            RuleExecutionSet aRuleSet = null;
+            
+			try {
+				aRuleSet = this.repository.getRuleExecutionSet( aBindUri, null );
+			} catch (RuleExecutionSetRepositoryException e) {
+				String s = "Error while retrieving rule execution set bound to: " + aBindUri;
+				throw new RuntimeException(s, e);
+			}
+			
+            if ( aRuleSet == this.ruleExecutionSet ) {
+                theBindUri = aBindUri;
+                break;
+            }
+        }
+
+        return new RuleExecutionSetMetadataImpl( theBindUri,
+                                                 this.ruleExecutionSet.getName(),
+                                                 this.ruleExecutionSet.getDescription() );
+    }
+
+    /**
+     * Releases all resources used by this rule session.
+     * This method renders this rule session unusable until
+     * it is reacquired through the <code>RuleRuntime</code>.
+     */
+    public void release() {
+        setProperties( null );
+        setRuleExecutionSet( null );
+    }
+}

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleRuntimeImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleRuntimeImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleRuntimeImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,114 +1,123 @@
-package org.drools.jsr94.rules;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.List;
-import java.util.Map;
-
-import javax.rules.RuleExecutionSetNotFoundException;
-import javax.rules.RuleRuntime;
-import javax.rules.RuleSession;
-import javax.rules.RuleSessionTypeUnsupportedException;
-
-import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
-
-/**
- * The Drools implementation of the <code>RuleRuntime</code> interface which
- * is the access point for runtime execution of <code>RuleExecutionSet</code>s.
- * It provides methods to create <code>RuleSession</code> implementation as
- * well as methods to retrieve <code>RuleExecutionSet</code>s that have been
- * previously registered using the <code>RuleAdministrator</code>. <p/> The
- * <code>RuleRuntime</code> should be accessed through the
- * <code>RuleServiceProvider</code>. An instance of the
- * <code>RuleRuntime</code> can be retrieved by calling: <p/> <code>
- * RuleServiceProvider ruleServiceProvider =
- *     RuleServiceProvider.newInstance();<br/>
- * RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
- * </code>
- * <p/> Note: the release method must be called on the <code>RuleSession</code>
- * to clean up all resources used by the <code>RuleSession</code>.
- * 
- * @see RuleRuntime
- * @author N. Alex Rupp (n_alex <at>codehaus.org)
- */
-public class RuleRuntimeImpl
-    implements
-    RuleRuntime {
-    private static final long          serialVersionUID = 400L;
-
-    private RuleExecutionSetRepository repository;
-
-    /**
-     * Create a new <code>RuleRuntimeImpl</code>.
-     */
-    public RuleRuntimeImpl(final RuleExecutionSetRepository repository) {
-        this.repository = repository;
-        // no special initialization required
-    }
-
-    /**
-     * Creates a <code>RuleSession</code> implementation using the supplied
-     * Drools-specific rule execution set registration URI.
-     * 
-     * @param uri
-     *            the URI for the <code>RuleExecutionSet</code>
-     * @param properties
-     *            additional properties used to create the
-     *            <code>RuleSession</code> implementation.
-     * @param ruleSessionType
-     *            the type of rule session to create.
-     * 
-     * @throws RuleSessionTypeUnsupportedException
-     *             if the ruleSessionType is not supported by Drools or the
-     *             RuleExecutionSet
-     * @throws RuleExecutionSetNotFoundException
-     *             if the URI could not be resolved into a
-     *             <code>RuleExecutionSet</code>
-     * 
-     * @return The created <code>RuleSession</code>.
-     */
-    public RuleSession createRuleSession(final String uri,
-                                         final Map properties,
-                                         final int ruleSessionType) throws RuleSessionTypeUnsupportedException,
-                                                                   RuleExecutionSetNotFoundException {
-
-        if ( ruleSessionType == RuleRuntime.STATELESS_SESSION_TYPE ) {
-            final StatelessRuleSessionImpl session = new StatelessRuleSessionImpl( uri,
-                                                                                   properties,
-                                                                                   this.repository );
-            return session;
-        } else if ( ruleSessionType == RuleRuntime.STATEFUL_SESSION_TYPE ) {
-            final StatefulRuleSessionImpl session = new StatefulRuleSessionImpl( uri,
-                                                                                 properties,
-                                                                                 this.repository );
-            return session;
-        }
-
-        throw new RuleSessionTypeUnsupportedException( "invalid session type: " + ruleSessionType );
-    }
-
-    /**
-     * Retrieves a <code>List</code> of the URIs that currently have
-     * <code>RuleExecutionSet</code>s associated with them. An empty list is
-     * returned is there are no associations.
-     * 
-     * @return a <code>List</code> of <code>String</code>s (URIs)
-     */
-    public List getRegistrations() {
-        return this.repository.getRegistrations();
-    }
-}
+package org.drools.jsr94.rules;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.RuleExecutionSetNotFoundException;
+import javax.rules.RuleRuntime;
+import javax.rules.RuleSession;
+import javax.rules.RuleSessionCreateException;
+import javax.rules.RuleSessionTypeUnsupportedException;
+
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;
+
+/**
+ * The Drools implementation of the <code>RuleRuntime</code> interface which
+ * is the access point for runtime execution of <code>RuleExecutionSet</code>s.
+ * It provides methods to create <code>RuleSession</code> implementation as
+ * well as methods to retrieve <code>RuleExecutionSet</code>s that have been
+ * previously registered using the <code>RuleAdministrator</code>. <p/> The
+ * <code>RuleRuntime</code> should be accessed through the
+ * <code>RuleServiceProvider</code>. An instance of the
+ * <code>RuleRuntime</code> can be retrieved by calling: <p/> <code>
+ * RuleServiceProvider ruleServiceProvider =
+ *     RuleServiceProvider.newInstance();<br/>
+ * RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
+ * </code>
+ * <p/> Note: the release method must be called on the <code>RuleSession</code>
+ * to clean up all resources used by the <code>RuleSession</code>.
+ * 
+ * @see RuleRuntime
+ * @author N. Alex Rupp (n_alex <at>codehaus.org)
+ */
+public class RuleRuntimeImpl
+    implements
+    RuleRuntime {
+    private static final long          serialVersionUID = 400L;
+
+    private RuleExecutionSetRepository repository;
+
+    /**
+     * Create a new <code>RuleRuntimeImpl</code>.
+     */
+    public RuleRuntimeImpl(final RuleExecutionSetRepository repository) {
+        this.repository = repository;
+        // no special initialization required
+    }
+
+    /**
+     * Creates a <code>RuleSession</code> implementation using the supplied
+     * Drools-specific rule execution set registration URI.
+     * 
+     * @param uri
+     *            the URI for the <code>RuleExecutionSet</code>
+     * @param properties
+     *            additional properties used to create the
+     *            <code>RuleSession</code> implementation.
+     * @param ruleSessionType
+     *            the type of rule session to create.
+     * 
+     * @throws RuleSessionTypeUnsupportedException
+     *             if the ruleSessionType is not supported by Drools or the
+     *             RuleExecutionSet
+     * @throws RuleExecutionSetNotFoundException
+     *             if the URI could not be resolved into a
+     *             <code>RuleExecutionSet</code>
+     * 
+     * @return The created <code>RuleSession</code>.
+     */
+    public RuleSession createRuleSession(final String uri,
+                                         final Map properties,
+                                         final int ruleSessionType)
+    throws RuleSessionTypeUnsupportedException,
+           RuleSessionCreateException,
+           RuleExecutionSetNotFoundException {
+
+        if ( ruleSessionType == RuleRuntime.STATELESS_SESSION_TYPE ) {
+            final StatelessRuleSessionImpl session = new StatelessRuleSessionImpl( uri,
+                                                                                   properties,
+                                                                                   this.repository );
+            return session;
+        } else if ( ruleSessionType == RuleRuntime.STATEFUL_SESSION_TYPE ) {
+            final StatefulRuleSessionImpl session = new StatefulRuleSessionImpl( uri,
+                                                                                 properties,
+                                                                                 this.repository );
+            return session;
+        }
+
+        throw new RuleSessionTypeUnsupportedException( "invalid session type: " + ruleSessionType );
+    }
+
+    /**
+     * Retrieves a <code>List</code> of the URIs that currently have
+     * <code>RuleExecutionSet</code>s associated with them. An empty list is
+     * returned is there are no associations.
+     * 
+     * @return a <code>List</code> of <code>String</code>s (URIs)
+     */
+    public List getRegistrations() {
+        try {
+			return this.repository.getRegistrations();
+		} catch (RuleExecutionSetRepositoryException e) {
+			String s = "Error while retrieving list of registrations";
+			throw new RuntimeException(s, e);
+		}
+    }
+}

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleServiceProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleServiceProviderImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/RuleServiceProviderImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,114 +1,125 @@
-package org.drools.jsr94.rules;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import javax.rules.ConfigurationException;
-import javax.rules.RuleRuntime;
-import javax.rules.RuleServiceProvider;
-import javax.rules.RuleServiceProviderManager;
-import javax.rules.admin.RuleAdministrator;
-
-import org.drools.jsr94.rules.admin.RuleAdministratorImpl;
-import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
-
-/**
- * This class provides access to the <code>RuleRuntime</code> and
- * <code>RuleAdministrator</code> implementation supplied by Drools when
- * running under J2SE. <p/> This class should be used in environments without a
- * JNDI provider - typically when writing standalone J2SE clients. Within the
- * J2EE environment the <code>RuleServiceProvider</code> implementation class
- * provided by Drools should be retrieved using a JNDI lookup. <p/> This class
- * should be constructed using the
- * <code>RuleServiceProviderManager.getRuleServiceProvider</code> method.
- * This class is automatically registered to "http://drools.org/" on startup, 
- * via the static block.
- * 
- * @see RuleRuntimeImpl
- * @see RuleAdministratorImpl
- * @see RuleServiceProvider
- * @see javax.rules.RuleServiceProviderManager#getRuleServiceProvider(String)
- * 
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-public class RuleServiceProviderImpl extends RuleServiceProvider implements java.io.Serializable {
-    public static final String         RULE_SERVICE_PROVIDER = "http://drools.org/";
-
-    /** An instance of <code>RuleRuntimeImpl</code>. */
-    private RuleRuntime                ruleRuntime;
-
-    /** An instance of <code>RuleAdministratorImpl</code>. */
-    private RuleAdministrator          ruleAdministrator;
-
-    private RuleExecutionSetRepository repository;
-
-    static {
-        try {
-            RuleServiceProviderManager.registerRuleServiceProvider( RULE_SERVICE_PROVIDER,
-                                                                    RuleServiceProviderImpl.class );
-        } catch ( ConfigurationException e ) {
-            System.err.println( "Unable to regiser Rule Service  Provider " + RULE_SERVICE_PROVIDER );
-        }
-    }
-
-    /**
-     * Create a new <code>RuleServiceProviderImpl</code>.
-     */
-    public RuleServiceProviderImpl() {
-        // no special initialization required
-    }
-
-    /**
-     * Returns the RuleExecutionSetRepository
-     * @return
-     */
-    public synchronized RuleExecutionSetRepository getRepository() {
-        // Lazy loaded
-        if ( this.repository == null ) {
-            this.repository = new RuleExecutionSetRepository();
-        }
-        return this.repository;
-    }
-
-    /**
-     * Returns a class instance of <code>RuleRuntime</code>. Specifically an
-     * instance of the Drools <code>RuleRuntimeImpl</code> is returned.
-     * 
-     * @return an instance of <code>RuleRuntime</code>
-     */
-    public synchronized RuleRuntime getRuleRuntime() {
-        if ( this.ruleRuntime == null ) {
-            this.ruleRuntime = new RuleRuntimeImpl( getRepository() );
-        }
-        
-        return this.ruleRuntime;       
-    }
-
-    /**
-     * Returns a class instance of <code>RuleAdministrator</code>.
-     * Specifically an instance of the Drools <code>RuleAdministratorImpl</code>
-     * is returned.
-     * 
-     * @return an instance of <code>RuleAdministrator</code>
-     */
-    public synchronized RuleAdministrator getRuleAdministrator() {
-        // Lazy instantiate
-        if ( this.ruleAdministrator == null ) {
-            this.ruleAdministrator = new RuleAdministratorImpl( getRepository() );
-        }
-        return this.ruleAdministrator;
-    }
-}
+package org.drools.jsr94.rules;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import javax.rules.ConfigurationException;
+import javax.rules.RuleRuntime;
+import javax.rules.RuleServiceProvider;
+import javax.rules.RuleServiceProviderManager;
+import javax.rules.admin.RuleAdministrator;
+
+import org.drools.jsr94.rules.admin.RuleAdministratorImpl;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryLoader;
+
+/**
+ * This class provides access to the <code>RuleRuntime</code> and
+ * <code>RuleAdministrator</code> implementation supplied by Drools when
+ * running under J2SE. <p/> This class should be used in environments without a
+ * JNDI provider - typically when writing standalone J2SE clients. Within the
+ * J2EE environment the <code>RuleServiceProvider</code> implementation class
+ * provided by Drools should be retrieved using a JNDI lookup. <p/> This class
+ * should be constructed using the
+ * <code>RuleServiceProviderManager.getRuleServiceProvider</code> method.
+ * This class is automatically registered to "http://drools.org/" on startup, 
+ * via the static block.
+ * 
+ * @see RuleRuntimeImpl
+ * @see RuleAdministratorImpl
+ * @see RuleServiceProvider
+ * @see javax.rules.RuleServiceProviderManager#getRuleServiceProvider(String)
+ * 
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public class RuleServiceProviderImpl extends RuleServiceProvider implements java.io.Serializable {
+    public static final String         RULE_SERVICE_PROVIDER = "http://drools.org/";
+
+    /** An instance of <code>RuleRuntimeImpl</code>. */
+    private RuleRuntime                ruleRuntime;
+
+    /** An instance of <code>RuleAdministratorImpl</code>. */
+    private RuleAdministrator          ruleAdministrator;
+
+    private RuleExecutionSetRepository repository;
+
+    static {
+        try {
+            RuleServiceProviderManager.registerRuleServiceProvider( RULE_SERVICE_PROVIDER,
+                                                                    RuleServiceProviderImpl.class );
+        } catch ( ConfigurationException e ) {
+            System.err.println( "Unable to regiser Rule Service  Provider " + RULE_SERVICE_PROVIDER );
+        }
+    }
+
+    /**
+     * Create a new <code>RuleServiceProviderImpl</code>.
+     */
+    public RuleServiceProviderImpl() {
+        // no special initialization required
+    }
+
+    /**
+     * Returns the RuleExecutionSetRepository
+     * @return
+     */
+    public synchronized RuleExecutionSetRepository getRepository() {
+        // Lazy loaded
+        if ( this.repository == null ) {
+            this.repository = createRuleExecutionSetRepository();
+        }
+        return this.repository;
+    }
+
+    /**
+     * Returns a class instance of <code>RuleRuntime</code>. Specifically an
+     * instance of the Drools <code>RuleRuntimeImpl</code> is returned.
+     * 
+     * @return an instance of <code>RuleRuntime</code>
+     */
+    public synchronized RuleRuntime getRuleRuntime() {
+        if ( this.ruleRuntime == null ) {
+            this.ruleRuntime = new RuleRuntimeImpl( getRepository() );
+        }
+        
+        return this.ruleRuntime;       
+    }
+
+    /**
+     * Returns a class instance of <code>RuleAdministrator</code>.
+     * Specifically an instance of the Drools <code>RuleAdministratorImpl</code>
+     * is returned.
+     * 
+     * @return an instance of <code>RuleAdministrator</code>
+     */
+    public synchronized RuleAdministrator getRuleAdministrator() {
+        // Lazy instantiate
+        if ( this.ruleAdministrator == null ) {
+            this.ruleAdministrator = new RuleAdministratorImpl( getRepository() );
+        }
+        return this.ruleAdministrator;
+    }
+    
+    /**
+     * Creates the RuleExecutionSetRepository.
+     * 
+     * @return
+     */
+    protected RuleExecutionSetRepository createRuleExecutionSetRepository() {
+    	String defaultFactoryName = "org.drools.jsr94.rules.repository.DefaultRuleExecutionSetRepository";
+    	return RuleExecutionSetRepositoryLoader.loadRuleExecutionSetRepository(defaultFactoryName);
+    }
+}

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatefulRuleSessionImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,376 +1,386 @@
-package org.drools.jsr94.rules;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.rules.Handle;
-import javax.rules.InvalidHandleException;
-import javax.rules.InvalidRuleSessionException;
-import javax.rules.ObjectFilter;
-import javax.rules.RuleExecutionSetNotFoundException;
-import javax.rules.RuleRuntime;
-import javax.rules.StatefulRuleSession;
-
-import org.drools.FactException;
-import org.drools.FactHandle;
-import org.drools.SessionConfiguration;
-import org.drools.StatefulSession;
-import org.drools.WorkingMemory;
-import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
-import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
-
-/**
- * The Drools implementation of the <code>StatefulRuleSession</code> interface
- * which is a representation of a stateful rules engine session. A stateful
- * rules engine session exposes a stateful rule execution API to an underlying
- * rules engine. The session allows arbitrary objects to be added and removed to
- * and from the rule session state. Additionally, objects currently part of the
- * rule session state may be updated. <p/> There are inherently side-effects to
- * adding objects to the rule session state. The execution of a RuleExecutionSet
- * can add, remove and update objects in the rule session state. The objects in
- * the rule session state are therefore dependent on the rules within the
- * <code>RuleExecutionSet</code> as well as the rule engine vendor's specific
- * rule engine behavior. <p/> <code>Handle</code> instances are used by the
- * rule engine vendor to track <code>Object</code>s added to the rule session
- * state. This allows multiple instances of equivalent <code>Object</code>s
- * to be added to the session state and identified, even after serialization.
- * 
- * @see StatefulRuleSession
- * 
- * @author N. Alex Rupp (n_alex <at>codehaus.org)
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-public class StatefulRuleSessionImpl extends AbstractRuleSessionImpl
-    implements
-    StatefulRuleSession {
-    // ----------------------------------------------------------------------
-    // Constructors
-    // ----------------------------------------------------------------------
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 400L;
-    
-    private StatefulSession session;
-
-    /**
-     * Gets the <code>RuleExecutionSet</code> for this URI and associates it
-     * with a RuleBase.
-     * 
-     * @param bindUri
-     *            the URI the <code>RuleExecutionSet</code> has been bound to
-     * @param properties
-     *            additional properties used to create the
-     *            <code>RuleSession</code> implementation.
-     * 
-     * @throws RuleExecutionSetNotFoundException
-     *             if there is no rule set under the given URI
-     */
-    StatefulRuleSessionImpl(final String bindUri,
-                            final Map properties,
-                            final RuleExecutionSetRepository repository) throws RuleExecutionSetNotFoundException {
-        super( repository );
-        setProperties( properties );
-
-        final RuleExecutionSetImpl ruleSet = (RuleExecutionSetImpl) repository.getRuleExecutionSet( bindUri );
-
-        if ( ruleSet == null ) {
-            throw new RuleExecutionSetNotFoundException( "no execution set bound to: " + bindUri );
-        }
-
-        this.setRuleExecutionSet( ruleSet );
-
-        SessionConfiguration conf = new SessionConfiguration();
-        conf.setKeepReference( true );
-        initSession( conf );
-    }
-    
-    /**
-     * Initialize this <code>RuleSession</code>
-     * with a new <code>WorkingMemory</code>.
-     */
-    protected void initSession(SessionConfiguration conf) {        
-        this.session = this.getRuleExecutionSet().newStatefulSession( conf );
-
-        final Map props = this.getProperties();
-        if ( props != null ) {
-            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
-                final Map.Entry entry = (Map.Entry) iterator.next();
-                this.session.setGlobal( (String) entry.getKey(),
-                                            entry.getValue() );
-            }
-        }               
-    }    
-
-    // ----------------------------------------------------------------------
-    // Instance methods
-    // ----------------------------------------------------------------------
-
-    /**
-     * Returns <code>true</code> if the given object is contained within
-     * rulesession state of this rule session.
-     * 
-     * @param objectHandle
-     *            the handle to the target object.
-     * 
-     * @return <code>true</code> if the given object is contained within the
-     *         rule session state of this rule session.
-     */
-    public boolean containsObject(final Handle objectHandle) {
-        if ( objectHandle instanceof FactHandle ) {
-            return this.session.getObject( (FactHandle) objectHandle ) != null;
-        }
-
-        return false;
-    }
-
-    /**
-     * Adds a given object to the rule session state of this rule session. The
-     * argument to this method is Object because in the non-managed env. not all
-     * objects should have to implement Serializable. If the
-     * <code>RuleSession</code> is <code>Serializable</code> and it contains
-     * non-serializable fields a runtime exception will be thrown.
-     * 
-     * @param object
-     *            the object to be added.
-     * 
-     * @return the Handle for the newly added Object
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public Handle addObject(final Object object) throws InvalidRuleSessionException {
-        checkRuleSessionValidity();
-        return (Handle) this.session.insert( object );
-    }
-
-    /**
-     * Adds a <code>List</code> of <code>Object</code>s to the rule session
-     * state of this rule session.
-     * 
-     * @param objList
-     *            the objects to be added.
-     * 
-     * @return a <code>List</code> of <code>Handle</code>s, one for each
-     *         added <code>Object</code>. The <code>List</code> must be
-     *         ordered in the same order as the input <code>objList</code>.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List addObjects(final List objList) throws InvalidRuleSessionException {
-        checkRuleSessionValidity();
-
-        final List handles = new ArrayList();
-
-        for ( final Iterator objectIter = objList.iterator(); objectIter.hasNext(); ) {
-            handles.add( addObject( objectIter.next() ) );
-        }
-        return handles;
-    }
-
-    /**
-     * Notifies the rules engine that a given object in the rule session state
-     * has changed. <p/> The semantics of this call are equivalent to calling
-     * <code>removeObject</code> followed by <code>addObject</code>. The
-     * original <code>Handle</code> is rebound to the new value for the
-     * <code>Object</code> however.
-     * 
-     * @param objectHandle
-     *            the handle to the original object.
-     * @param newObject
-     *            the new object to bind to the handle.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     * @throws InvalidHandleException
-     *             if the input <code>Handle</code> is no longer valid
-     */
-    public void updateObject(final Handle objectHandle,
-                             final Object newObject) throws InvalidRuleSessionException,
-                                                    InvalidHandleException {
-        checkRuleSessionValidity();
-
-        if ( objectHandle instanceof FactHandle ) {
-            this.session.update( (FactHandle) objectHandle,
-                                             newObject );
-        } else {
-            throw new InvalidHandleException( "invalid handle" );
-
-        }
-    }
-
-    /**
-     * Removes a given object from the rule session state of this rule session.
-     * 
-     * @param handleObject
-     *            the handle to the object to be removed from the rule session
-     *            state.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     * @throws InvalidHandleException
-     *             if the input <code>Handle</code> is no longer valid
-     */
-    public void removeObject(final Handle handleObject) throws InvalidRuleSessionException,
-                                                       InvalidHandleException {
-        checkRuleSessionValidity();
-
-        if ( handleObject instanceof FactHandle ) {
-            this.session.retract( (FactHandle) handleObject );
-        } else {
-            throw new InvalidHandleException( "invalid handle" );
-        }
-    }
-
-    /**
-     * Executes the rules in the bound rule execution set using the objects
-     * present in the rule session state. This will typically modify the rule
-     * session state - and may add, remove or update <code>Object</code>s
-     * bound to <code>Handle</code>s.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public void executeRules() throws InvalidRuleSessionException {
-        checkRuleSessionValidity();
-        this.session.fireAllRules();
-    }
-
-    /**
-     * @see StatefulRuleSessionImpl
-     */
-    public Object getObject(final Handle handle) throws InvalidRuleSessionException,
-                                                InvalidHandleException {
-       checkRuleSessionValidity();
-
-        if ( handle instanceof FactHandle ) {
-            return this.session.getObject( (FactHandle) handle );
-        } else {
-            throw new InvalidHandleException( "invalid handle" );
-        }
-    }
-
-    /**
-     * Returns a <code>List</code> of the <code>Handle</code>s being used
-     * for object identity.
-     * 
-     * @return a <code>List</code> of <code>Handle</code>s present in the
-     *         currect state of the rule session.
-     */
-    public List getHandles() {
-        return IteratorToList.convert( this.session.iterateFactHandles() );
-    }
-    
-    /**
-     * Returns a List of all objects in the rule session state of this rule
-     * session. The objects should pass the default filter test of the default
-     * <code>RuleExecutionSet</code> filter (if present). <p/> This may not
-     * neccessarily include all objects added by calls to <code>addObject</code>,
-     * and may include <code>Object</code>s created by side-effects. The
-     * execution of a <code>RuleExecutionSet</code> can add, remove and update
-     * objects as part of the rule session state. Therefore the rule session
-     * state is dependent on the rules that are part of the executed
-     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
-     * rule engine behavior.
-     * 
-     * @return a <code>List</code> of all objects part of the rule session
-     *         state.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List getObjects() throws InvalidRuleSessionException {
-        checkRuleSessionValidity();
-        return getObjects( getRuleExecutionSet().getObjectFilter() );
-    }    
-    
-    /**
-     * Returns a <code>List</code> over the objects in rule session state of
-     * this rule session. The objects should pass the filter test on the
-     * specified <code>ObjectFilter</code>. <p/> This may not neccessarily
-     * include all objects added by calls to <code>addObject</code>, and may
-     * include <code>Object</code>s created by side-effects. The execution of
-     * a <code>RuleExecutionSet</code> can add, remove and update objects as
-     * part of the rule session state. Therefore the rule session state is
-     * dependent on the rules that are part of the executed
-     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
-     * rule engine behavior.
-     * 
-     * @param filter
-     *            the object filter.
-     * 
-     * @return a <code>List</code> of all the objects in the rule session
-     *         state of this rule session based upon the given object filter.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List getObjects(final ObjectFilter filter) throws InvalidRuleSessionException {
-        checkRuleSessionValidity();
-        
-        return IteratorToList.convert( this.session.iterateObjects( new ObjectFilterAdapter( filter ) ) );
-    }     
-
-    /**
-     * Resets this rule session. Calling this method will bring the rule session
-     * state to its initial state for this rule session and will reset any other
-     * state associated with this rule session.
-     * <p/>
-     * A reset will not reset the state on the default object filter for a
-     * <code>RuleExecutionSet</code>.
-     */
-    public void reset() {
-        // stateful rule sessions should not be high load, thus safe to keep references
-        initSession( new SessionConfiguration() );
-    }
-
-    public int getType() throws InvalidRuleSessionException {
-        return RuleRuntime.STATEFUL_SESSION_TYPE;
-    }
-    
-    /**
-     * Releases all resources used by this rule session.
-     * This method renders this rule session unusable until
-     * it is reacquired through the <code>RuleRuntime</code>.
-     */
-    public void release() {
-        if ( this.session != null ) {
-            this.session.dispose();
-        }
-        this.session = null;
-        super.release();
-    }    
-    
-    /**
-     * Ensures this <code>RuleSession</code> is not
-     * in an illegal rule session state.
-     *
-     * @throws InvalidRuleSessionException on illegal rule session state.
-     */
-    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
-        if ( this.session == null ) {
-            throw new InvalidRuleSessionException( "invalid rule session" );
-        }
-    }    
-}
+package org.drools.jsr94.rules;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.Handle;
+import javax.rules.InvalidHandleException;
+import javax.rules.InvalidRuleSessionException;
+import javax.rules.ObjectFilter;
+import javax.rules.RuleExecutionSetNotFoundException;
+import javax.rules.RuleRuntime;
+import javax.rules.RuleSessionCreateException;
+import javax.rules.StatefulRuleSession;
+
+import org.drools.FactHandle;
+import org.drools.SessionConfiguration;
+import org.drools.StatefulSession;
+import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;
+
+/**
+ * The Drools implementation of the <code>StatefulRuleSession</code> interface
+ * which is a representation of a stateful rules engine session. A stateful
+ * rules engine session exposes a stateful rule execution API to an underlying
+ * rules engine. The session allows arbitrary objects to be added and removed to
+ * and from the rule session state. Additionally, objects currently part of the
+ * rule session state may be updated. <p/> There are inherently side-effects to
+ * adding objects to the rule session state. The execution of a RuleExecutionSet
+ * can add, remove and update objects in the rule session state. The objects in
+ * the rule session state are therefore dependent on the rules within the
+ * <code>RuleExecutionSet</code> as well as the rule engine vendor's specific
+ * rule engine behavior. <p/> <code>Handle</code> instances are used by the
+ * rule engine vendor to track <code>Object</code>s added to the rule session
+ * state. This allows multiple instances of equivalent <code>Object</code>s
+ * to be added to the session state and identified, even after serialization.
+ * 
+ * @see StatefulRuleSession
+ * 
+ * @author N. Alex Rupp (n_alex <at>codehaus.org)
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public class StatefulRuleSessionImpl extends AbstractRuleSessionImpl
+    implements
+    StatefulRuleSession {
+    // ----------------------------------------------------------------------
+    // Constructors
+    // ----------------------------------------------------------------------
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 400L;
+    
+    private StatefulSession session;
+
+    /**
+     * Gets the <code>RuleExecutionSet</code> for this URI and associates it
+     * with a RuleBase.
+     * 
+     * @param bindUri
+     *            the URI the <code>RuleExecutionSet</code> has been bound to
+     * @param properties
+     *            additional properties used to create the
+     *            <code>RuleSession</code> implementation.
+     * 
+     * @throws RuleExecutionSetNotFoundException
+     *             if there is no rule set under the given URI
+     * @throws RuleSessionCreateException 
+     */
+    StatefulRuleSessionImpl(final String bindUri,
+                            final Map properties,
+                            final RuleExecutionSetRepository repository)
+    throws RuleExecutionSetNotFoundException, RuleSessionCreateException {
+    	
+        super( repository );
+        setProperties( properties );
+
+        RuleExecutionSetImpl ruleSet = null;
+        
+		try {
+			ruleSet = (RuleExecutionSetImpl)
+			repository.getRuleExecutionSet(bindUri, properties);
+		} catch (RuleExecutionSetRepositoryException e) {
+			String s = "Error while retrieving rule execution set bound to: " + bindUri;
+			throw new RuleSessionCreateException(s, e);
+		}
+
+        if ( ruleSet == null ) {
+            throw new RuleExecutionSetNotFoundException( "no execution set bound to: " + bindUri );
+        }
+
+        this.setRuleExecutionSet( ruleSet );
+
+        SessionConfiguration conf = new SessionConfiguration();
+        conf.setKeepReference( true );
+        initSession( conf );
+    }
+    
+    /**
+     * Initialize this <code>RuleSession</code>
+     * with a new <code>WorkingMemory</code>.
+     */
+    protected void initSession(SessionConfiguration conf) {        
+        this.session = this.getRuleExecutionSet().newStatefulSession( conf );
+
+        final Map props = this.getProperties();
+        if ( props != null ) {
+            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
+                final Map.Entry entry = (Map.Entry) iterator.next();
+                this.session.setGlobal( (String) entry.getKey(),
+                                            entry.getValue() );
+            }
+        }               
+    }    
+
+    // ----------------------------------------------------------------------
+    // Instance methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * Returns <code>true</code> if the given object is contained within
+     * rulesession state of this rule session.
+     * 
+     * @param objectHandle
+     *            the handle to the target object.
+     * 
+     * @return <code>true</code> if the given object is contained within the
+     *         rule session state of this rule session.
+     */
+    public boolean containsObject(final Handle objectHandle) {
+        if ( objectHandle instanceof FactHandle ) {
+            return this.session.getObject( (FactHandle) objectHandle ) != null;
+        }
+
+        return false;
+    }
+
+    /**
+     * Adds a given object to the rule session state of this rule session. The
+     * argument to this method is Object because in the non-managed env. not all
+     * objects should have to implement Serializable. If the
+     * <code>RuleSession</code> is <code>Serializable</code> and it contains
+     * non-serializable fields a runtime exception will be thrown.
+     * 
+     * @param object
+     *            the object to be added.
+     * 
+     * @return the Handle for the newly added Object
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public Handle addObject(final Object object) throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+        return (Handle) this.session.insert( object );
+    }
+
+    /**
+     * Adds a <code>List</code> of <code>Object</code>s to the rule session
+     * state of this rule session.
+     * 
+     * @param objList
+     *            the objects to be added.
+     * 
+     * @return a <code>List</code> of <code>Handle</code>s, one for each
+     *         added <code>Object</code>. The <code>List</code> must be
+     *         ordered in the same order as the input <code>objList</code>.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List addObjects(final List objList) throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+
+        final List handles = new ArrayList();
+
+        for ( final Iterator objectIter = objList.iterator(); objectIter.hasNext(); ) {
+            handles.add( addObject( objectIter.next() ) );
+        }
+        return handles;
+    }
+
+    /**
+     * Notifies the rules engine that a given object in the rule session state
+     * has changed. <p/> The semantics of this call are equivalent to calling
+     * <code>removeObject</code> followed by <code>addObject</code>. The
+     * original <code>Handle</code> is rebound to the new value for the
+     * <code>Object</code> however.
+     * 
+     * @param objectHandle
+     *            the handle to the original object.
+     * @param newObject
+     *            the new object to bind to the handle.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     * @throws InvalidHandleException
+     *             if the input <code>Handle</code> is no longer valid
+     */
+    public void updateObject(final Handle objectHandle,
+                             final Object newObject) throws InvalidRuleSessionException,
+                                                    InvalidHandleException {
+        checkRuleSessionValidity();
+
+        if ( objectHandle instanceof FactHandle ) {
+            this.session.update( (FactHandle) objectHandle,
+                                             newObject );
+        } else {
+            throw new InvalidHandleException( "invalid handle" );
+
+        }
+    }
+
+    /**
+     * Removes a given object from the rule session state of this rule session.
+     * 
+     * @param handleObject
+     *            the handle to the object to be removed from the rule session
+     *            state.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     * @throws InvalidHandleException
+     *             if the input <code>Handle</code> is no longer valid
+     */
+    public void removeObject(final Handle handleObject) throws InvalidRuleSessionException,
+                                                       InvalidHandleException {
+        checkRuleSessionValidity();
+
+        if ( handleObject instanceof FactHandle ) {
+            this.session.retract( (FactHandle) handleObject );
+        } else {
+            throw new InvalidHandleException( "invalid handle" );
+        }
+    }
+
+    /**
+     * Executes the rules in the bound rule execution set using the objects
+     * present in the rule session state. This will typically modify the rule
+     * session state - and may add, remove or update <code>Object</code>s
+     * bound to <code>Handle</code>s.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public void executeRules() throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+        this.session.fireAllRules();
+    }
+
+    /**
+     * @see StatefulRuleSessionImpl
+     */
+    public Object getObject(final Handle handle) throws InvalidRuleSessionException,
+                                                InvalidHandleException {
+       checkRuleSessionValidity();
+
+        if ( handle instanceof FactHandle ) {
+            return this.session.getObject( (FactHandle) handle );
+        } else {
+            throw new InvalidHandleException( "invalid handle" );
+        }
+    }
+
+    /**
+     * Returns a <code>List</code> of the <code>Handle</code>s being used
+     * for object identity.
+     * 
+     * @return a <code>List</code> of <code>Handle</code>s present in the
+     *         currect state of the rule session.
+     */
+    public List getHandles() {
+        return IteratorToList.convert( this.session.iterateFactHandles() );
+    }
+    
+    /**
+     * Returns a List of all objects in the rule session state of this rule
+     * session. The objects should pass the default filter test of the default
+     * <code>RuleExecutionSet</code> filter (if present). <p/> This may not
+     * neccessarily include all objects added by calls to <code>addObject</code>,
+     * and may include <code>Object</code>s created by side-effects. The
+     * execution of a <code>RuleExecutionSet</code> can add, remove and update
+     * objects as part of the rule session state. Therefore the rule session
+     * state is dependent on the rules that are part of the executed
+     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
+     * rule engine behavior.
+     * 
+     * @return a <code>List</code> of all objects part of the rule session
+     *         state.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List getObjects() throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+        return getObjects( getRuleExecutionSet().getObjectFilter() );
+    }    
+    
+    /**
+     * Returns a <code>List</code> over the objects in rule session state of
+     * this rule session. The objects should pass the filter test on the
+     * specified <code>ObjectFilter</code>. <p/> This may not neccessarily
+     * include all objects added by calls to <code>addObject</code>, and may
+     * include <code>Object</code>s created by side-effects. The execution of
+     * a <code>RuleExecutionSet</code> can add, remove and update objects as
+     * part of the rule session state. Therefore the rule session state is
+     * dependent on the rules that are part of the executed
+     * <code>RuleExecutionSet</code> as well as the rule vendor's specific
+     * rule engine behavior.
+     * 
+     * @param filter
+     *            the object filter.
+     * 
+     * @return a <code>List</code> of all the objects in the rule session
+     *         state of this rule session based upon the given object filter.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List getObjects(final ObjectFilter filter) throws InvalidRuleSessionException {
+        checkRuleSessionValidity();
+        
+        return IteratorToList.convert( this.session.iterateObjects( new ObjectFilterAdapter( filter ) ) );
+    }     
+
+    /**
+     * Resets this rule session. Calling this method will bring the rule session
+     * state to its initial state for this rule session and will reset any other
+     * state associated with this rule session.
+     * <p/>
+     * A reset will not reset the state on the default object filter for a
+     * <code>RuleExecutionSet</code>.
+     */
+    public void reset() {
+        // stateful rule sessions should not be high load, thus safe to keep references
+        initSession( new SessionConfiguration() );
+    }
+
+    public int getType() throws InvalidRuleSessionException {
+        return RuleRuntime.STATEFUL_SESSION_TYPE;
+    }
+    
+    /**
+     * Releases all resources used by this rule session.
+     * This method renders this rule session unusable until
+     * it is reacquired through the <code>RuleRuntime</code>.
+     */
+    public void release() {
+        if ( this.session != null ) {
+            this.session.dispose();
+        }
+        this.session = null;
+        super.release();
+    }    
+    
+    /**
+     * Ensures this <code>RuleSession</code> is not
+     * in an illegal rule session state.
+     *
+     * @throws InvalidRuleSessionException on illegal rule session state.
+     */
+    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
+        if ( this.session == null ) {
+            throw new InvalidRuleSessionException( "invalid rule session" );
+        }
+    }    
+}

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/StatelessRuleSessionImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,169 +1,180 @@
-package org.drools.jsr94.rules;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.rules.InvalidRuleSessionException;
-import javax.rules.ObjectFilter;
-import javax.rules.RuleExecutionSetNotFoundException;
-import javax.rules.RuleRuntime;
-import javax.rules.StatelessRuleSession;
-
-import org.drools.FactException;
-import org.drools.StatelessSession;
-import org.drools.StatelessSessionResult;
-import org.drools.WorkingMemory;
-import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
-import org.drools.jsr94.rules.admin.RuleExecutionSetRepository;
-
-/**
- * The Drools implementation of the <code>StatelessRuleSession</code>
- * interface which is a representation of a stateless rules engine session. A
- * stateless rules engine session exposes a stateless rule execution API to an
- * underlying rules engine.
- * 
- * @see StatelessRuleSession
- * 
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-public class StatelessRuleSessionImpl extends AbstractRuleSessionImpl
-    implements
-    StatelessRuleSession {    
-    /**
-     * Gets the <code>RuleExecutionSet</code> for this URI and associates it
-     * with a RuleBase.
-     * 
-     * @param bindUri
-     *            the URI the <code>RuleExecutionSet</code> has been bound to
-     * @param properties
-     *            additional properties used to create the
-     *            <code>RuleSession</code> implementation.
-     * 
-     * @throws RuleExecutionSetNotFoundException
-     *             if there is no rule set under the given URI
-     */
-    StatelessRuleSessionImpl(final String bindUri,
-                             final Map properties,
-                             final RuleExecutionSetRepository repository) throws RuleExecutionSetNotFoundException {
-        super( repository );
-        setProperties( properties );
-
-        final RuleExecutionSetImpl ruleSet = (RuleExecutionSetImpl) repository.getRuleExecutionSet( bindUri );
-
-        if ( ruleSet == null ) {
-            throw new RuleExecutionSetNotFoundException( "RuleExecutionSet unbound: " + bindUri );
-        }
-
-        setRuleExecutionSet( ruleSet );
-    }
-    
-    /**
-     * Initialize this <code>RuleSession</code>
-     * with a new <code>WorkingMemory</code>.
-     */
-    protected StatelessSession newStatelessSession() {        
-        final StatelessSession session = this.getRuleExecutionSet().newStatelessSession();
-
-        final Map props = this.getProperties();
-        if ( props != null ) {
-            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
-                final Map.Entry entry = (Map.Entry) iterator.next();
-                session.setGlobal( (String) entry.getKey(),
-                                            entry.getValue() );
-            }
-        }
-        return session;
-    }    
-
-    /**
-     * Executes the rules in the bound rule execution set using the supplied
-     * list of objects. A <code>List</code> is returned containing the objects
-     * created by (or passed into the rule session) the executed rules that pass
-     * the filter test of the default <code>RuleExecutionSet</code>
-     * <code>ObjectFilter</code>
-     * (if present). <p/> The returned list may not neccessarily include all
-     * objects passed, and may include <code>Object</code>s created by
-     * side-effects. The execution of a <code>RuleExecutionSet</code> can add,
-     * remove and update objects. Therefore the returned object list is
-     * dependent on the rules that are part of the executed
-     * <code>RuleExecutionSet</code> as well as Drools specific rule engine
-     * behavior.
-     * 
-     * @param objects
-     *            the objects used to execute rules.
-     * 
-     * @return a <code>List</code> containing the objects as a result of
-     *         executing the rules.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List executeRules(final List objects) throws InvalidRuleSessionException {
-        return executeRules( objects,
-                             this.getRuleExecutionSet().getObjectFilter() );
-    }
-
-    /**
-     * Executes the rules in the bound rule execution set using the supplied
-     * list of objects. A <code>List</code> is returned containing the objects
-     * created by (or passed into the rule engine) the executed rules and
-     * filtered with the supplied object filter. <p/> The returned list may not
-     * neccessarily include all objects passed, and may include
-     * <code>Object</code>s created by side-effects. The execution of a
-     * <code>RuleExecutionSet</code> can add, remove and update objects.
-     * Therefore the returned object list is dependent on the rules that are
-     * part of the executed <code>RuleExecutionSet</code> as well as Drools
-     * specific rule engine behavior.
-     * 
-     * @param objects
-     *            the objects used to execute rules.
-     * @param filter
-     *            the object filter.
-     * 
-     * @return a <code>List</code> containing the objects as a result of
-     *         executing rules, after passing through the supplied object
-     *         filter.
-     * 
-     * @throws InvalidRuleSessionException
-     *             on illegal rule session state.
-     */
-    public List executeRules(final List objects,
-                             final ObjectFilter filter) throws InvalidRuleSessionException {
-        StatelessSession session = newStatelessSession();
-        StatelessSessionResult results = session.executeWithResults( objects );
-        
-        return IteratorToList.convert( results.iterateObjects( new ObjectFilterAdapter( filter ) ) );
-    }
-    
-    public int getType() throws InvalidRuleSessionException {
-        return RuleRuntime.STATELESS_SESSION_TYPE;
-    }
-    
-    /**
-     * Ensures this <code>RuleSession</code> is not
-     * in an illegal rule session state.
-     *
-     * @throws InvalidRuleSessionException on illegal rule session state.
-     */
-    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
-        if ( getRuleExecutionSet() == null ) {
-            throw new InvalidRuleSessionException( "invalid rule session" );
-        }
-    }     
-}
+package org.drools.jsr94.rules;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.InvalidRuleSessionException;
+import javax.rules.ObjectFilter;
+import javax.rules.RuleExecutionSetNotFoundException;
+import javax.rules.RuleRuntime;
+import javax.rules.RuleSessionCreateException;
+import javax.rules.StatelessRuleSession;
+
+import org.drools.StatelessSession;
+import org.drools.StatelessSessionResult;
+import org.drools.jsr94.rules.admin.RuleExecutionSetImpl;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;
+
+/**
+ * The Drools implementation of the <code>StatelessRuleSession</code>
+ * interface which is a representation of a stateless rules engine session. A
+ * stateless rules engine session exposes a stateless rule execution API to an
+ * underlying rules engine.
+ * 
+ * @see StatelessRuleSession
+ * 
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public class StatelessRuleSessionImpl extends AbstractRuleSessionImpl
+    implements
+    StatelessRuleSession {    
+    /**
+     * Gets the <code>RuleExecutionSet</code> for this URI and associates it
+     * with a RuleBase.
+     * 
+     * @param bindUri
+     *            the URI the <code>RuleExecutionSet</code> has been bound to
+     * @param properties
+     *            additional properties used to create the
+     *            <code>RuleSession</code> implementation.
+     * 
+     * @throws RuleExecutionSetNotFoundException
+     *             if there is no rule set under the given URI
+     * @throws RuleSessionCreateException 
+     */
+    StatelessRuleSessionImpl(final String bindUri,
+                             final Map properties,
+                             final RuleExecutionSetRepository repository)
+    throws RuleExecutionSetNotFoundException, RuleSessionCreateException {
+    	
+        super( repository );
+        setProperties( properties );
+
+        RuleExecutionSetImpl ruleSet = null;
+        
+		try {
+			ruleSet = (RuleExecutionSetImpl)
+			repository.getRuleExecutionSet(bindUri, properties);
+		} catch (RuleExecutionSetRepositoryException e) {
+			String s = "Error while retrieving rule execution set bound to: " + bindUri;
+			throw new RuleSessionCreateException(s, e);
+		}
+
+        if ( ruleSet == null ) {
+            throw new RuleExecutionSetNotFoundException( "RuleExecutionSet unbound: " + bindUri );
+        }
+
+        setRuleExecutionSet( ruleSet );
+    }
+    
+    /**
+     * Initialize this <code>RuleSession</code>
+     * with a new <code>WorkingMemory</code>.
+     */
+    protected StatelessSession newStatelessSession() {        
+        final StatelessSession session = this.getRuleExecutionSet().newStatelessSession();
+
+        final Map props = this.getProperties();
+        if ( props != null ) {
+            for ( final Iterator iterator = props.entrySet().iterator(); iterator.hasNext(); ) {
+                final Map.Entry entry = (Map.Entry) iterator.next();
+                session.setGlobal( (String) entry.getKey(),
+                                            entry.getValue() );
+            }
+        }
+        return session;
+    }    
+
+    /**
+     * Executes the rules in the bound rule execution set using the supplied
+     * list of objects. A <code>List</code> is returned containing the objects
+     * created by (or passed into the rule session) the executed rules that pass
+     * the filter test of the default <code>RuleExecutionSet</code>
+     * <code>ObjectFilter</code>
+     * (if present). <p/> The returned list may not neccessarily include all
+     * objects passed, and may include <code>Object</code>s created by
+     * side-effects. The execution of a <code>RuleExecutionSet</code> can add,
+     * remove and update objects. Therefore the returned object list is
+     * dependent on the rules that are part of the executed
+     * <code>RuleExecutionSet</code> as well as Drools specific rule engine
+     * behavior.
+     * 
+     * @param objects
+     *            the objects used to execute rules.
+     * 
+     * @return a <code>List</code> containing the objects as a result of
+     *         executing the rules.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List executeRules(final List objects) throws InvalidRuleSessionException {
+        return executeRules( objects,
+                             this.getRuleExecutionSet().getObjectFilter() );
+    }
+
+    /**
+     * Executes the rules in the bound rule execution set using the supplied
+     * list of objects. A <code>List</code> is returned containing the objects
+     * created by (or passed into the rule engine) the executed rules and
+     * filtered with the supplied object filter. <p/> The returned list may not
+     * neccessarily include all objects passed, and may include
+     * <code>Object</code>s created by side-effects. The execution of a
+     * <code>RuleExecutionSet</code> can add, remove and update objects.
+     * Therefore the returned object list is dependent on the rules that are
+     * part of the executed <code>RuleExecutionSet</code> as well as Drools
+     * specific rule engine behavior.
+     * 
+     * @param objects
+     *            the objects used to execute rules.
+     * @param filter
+     *            the object filter.
+     * 
+     * @return a <code>List</code> containing the objects as a result of
+     *         executing rules, after passing through the supplied object
+     *         filter.
+     * 
+     * @throws InvalidRuleSessionException
+     *             on illegal rule session state.
+     */
+    public List executeRules(final List objects,
+                             final ObjectFilter filter) throws InvalidRuleSessionException {
+        StatelessSession session = newStatelessSession();
+        StatelessSessionResult results = session.executeWithResults( objects );
+        
+        return IteratorToList.convert( results.iterateObjects( new ObjectFilterAdapter( filter ) ) );
+    }
+    
+    public int getType() throws InvalidRuleSessionException {
+        return RuleRuntime.STATELESS_SESSION_TYPE;
+    }
+    
+    /**
+     * Ensures this <code>RuleSession</code> is not
+     * in an illegal rule session state.
+     *
+     * @throws InvalidRuleSessionException on illegal rule session state.
+     */
+    protected void checkRuleSessionValidity() throws InvalidRuleSessionException {
+        if ( getRuleExecutionSet() == null ) {
+            throw new InvalidRuleSessionException( "invalid rule session" );
+        }
+    }     
+}

Modified: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleAdministratorImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleAdministratorImpl.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleAdministratorImpl.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,135 +1,146 @@
-package org.drools.jsr94.rules.admin;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Map;
-
-import javax.rules.admin.LocalRuleExecutionSetProvider;
-import javax.rules.admin.RuleAdministrator;
-import javax.rules.admin.RuleExecutionSet;
-import javax.rules.admin.RuleExecutionSetDeregistrationException;
-import javax.rules.admin.RuleExecutionSetProvider;
-import javax.rules.admin.RuleExecutionSetRegisterException;
-
-/**
- * The Drools implementation of the <code>RuleAdministrator</code> interface
- * which is used by rule execution set administrators to load rule execution
- * sets from external sources and create a <code>RuleExecutionSet</code>
- * runtime object. <p/> The <code>RuleAdministrator</code> should be accessed
- * by calling: <p/> <code>
- * RuleServiceProvider ruleServiceProvider =
- *     RuleServiceProvider.newInstance();<br/>
- * RuleAdministrator ruleAdministration =
- *     ruleServiceProvider.getRuleAdministrator();
- * </code>
- * <p/> In an additional step the administrator may also choose to bind the
- * <code>RuleExecutionSet</code> instance to a URI so that it is globally
- * accessible and <code>RuleSession</code>s can be created for the
- * <code>RuleExecutionSet</code> through the RuleRuntime.
- * 
- * @see RuleAdministrator
- * 
- * @author N. Alex Rupp (n_alex <at>codehaus.org)
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-public class RuleAdministratorImpl
-    implements
-    RuleAdministrator, java.io.Serializable {
-    private RuleExecutionSetRepository repository;
-
-    /** Default constructor. */
-    public RuleAdministratorImpl(final RuleExecutionSetRepository repository) {
-        super();
-        this.repository = repository;
-    }
-
-    /**
-     * Returns a <code>RuleExecutionSetProvider</code> implementation.
-     * 
-     * @param properties
-     *            additional properties
-     * 
-     * @return The created <code>RuleExecutionSetProvider</code>.
-     */
-    public RuleExecutionSetProvider getRuleExecutionSetProvider(final Map properties) {
-        return new RuleExecutionSetProviderImpl();
-    }
-
-    /**
-     * Returns a <code>LocalRuleExecutionSetProvider</code> implementation.
-     * 
-     * Returns a <code>LocalRuleExecutionSetProvider</code> implementation or
-     * null if this implementation does not support creating a
-     * <code>RuleExecutionSet</code> from non-serializable resources.
-     * 
-     * @param properties
-     *            additional properties
-     * 
-     * @return The created <code>LocalRuleExecutionSetProvider</code>.
-     */
-    public LocalRuleExecutionSetProvider getLocalRuleExecutionSetProvider(final Map properties) {
-        return new LocalRuleExecutionSetProviderImpl();
-    }
-
-    /**
-     * Registers a <code>RuleExecutionSet</code> and associates it with a
-     * given URI. Once a <code>RuleExecutionSet</code> has been registered it
-     * is accessible to runtime clients through the <code>RuleRuntime</code>.
-     * If a <code>RuleExecutionSet</code> has already been associated with the
-     * URI it should be deregistered (as if
-     * <code>deregisterRuleExecutionSet/</code> had been called) and the URI
-     * should be associated with the new <code>RuleExecutionSet</code>.
-     * 
-     * @param bindUri
-     *            the URI to associate with the <code>RuleExecutionSet</code>.
-     * @param set
-     *            the <code>RuleExecutionSet</code> to associate with the URI
-     * @param properties
-     *            additional properties used to perform the registration
-     * 
-     * @throws RuleExecutionSetRegisterException
-     *             if an error occurred that prevented registration
-     */
-    public void registerRuleExecutionSet(final String bindUri,
-                                         final RuleExecutionSet set,
-                                         final Map properties) throws RuleExecutionSetRegisterException {
-        // Note: an existing RuleExecutionSet is simply replaced
-        this.repository.registerRuleExecutionSet( bindUri,
-                                                  set );
-    }
-
-    /**
-     * Unregisters a previously registered <code>RuleExecutionSet</code> from
-     * a URI.
-     * 
-     * @param bindUri
-     *            the URI to disassociate with the <code>RuleExecutionSet</code>.
-     * @param properties
-     *            additional properties used to perform the deregistration
-     * 
-     * @throws RuleExecutionSetDeregistrationException
-     *             if an error occurred that prevented unregistration
-     */
-    public void deregisterRuleExecutionSet(final String bindUri,
-                                           final Map properties) throws RuleExecutionSetDeregistrationException {
-        if ( this.repository.getRuleExecutionSet( bindUri ) == null ) {
-            throw new RuleExecutionSetDeregistrationException( "no execution set bound to: " + bindUri );
-        }
-
-        this.repository.unregisterRuleExecutionSet( bindUri );
-    }
-}
+package org.drools.jsr94.rules.admin;
+
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Map;
+
+import javax.rules.admin.LocalRuleExecutionSetProvider;
+import javax.rules.admin.RuleAdministrator;
+import javax.rules.admin.RuleExecutionSet;
+import javax.rules.admin.RuleExecutionSetDeregistrationException;
+import javax.rules.admin.RuleExecutionSetProvider;
+import javax.rules.admin.RuleExecutionSetRegisterException;
+
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
+import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;
+
+/**
+ * The Drools implementation of the <code>RuleAdministrator</code> interface
+ * which is used by rule execution set administrators to load rule execution
+ * sets from external sources and create a <code>RuleExecutionSet</code>
+ * runtime object. <p/> The <code>RuleAdministrator</code> should be accessed
+ * by calling: <p/> <code>
+ * RuleServiceProvider ruleServiceProvider =
+ *     RuleServiceProvider.newInstance();<br/>
+ * RuleAdministrator ruleAdministration =
+ *     ruleServiceProvider.getRuleAdministrator();
+ * </code>
+ * <p/> In an additional step the administrator may also choose to bind the
+ * <code>RuleExecutionSet</code> instance to a URI so that it is globally
+ * accessible and <code>RuleSession</code>s can be created for the
+ * <code>RuleExecutionSet</code> through the RuleRuntime.
+ * 
+ * @see RuleAdministrator
+ * 
+ * @author N. Alex Rupp (n_alex <at>codehaus.org)
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public class RuleAdministratorImpl
+    implements
+    RuleAdministrator, java.io.Serializable {
+    private RuleExecutionSetRepository repository;
+
+    /** Default constructor. */
+    public RuleAdministratorImpl(final RuleExecutionSetRepository repository) {
+        super();
+        this.repository = repository;
+    }
+
+    /**
+     * Returns a <code>RuleExecutionSetProvider</code> implementation.
+     * 
+     * @param properties
+     *            additional properties
+     * 
+     * @return The created <code>RuleExecutionSetProvider</code>.
+     */
+    public RuleExecutionSetProvider getRuleExecutionSetProvider(final Map properties) {
+        return new RuleExecutionSetProviderImpl();
+    }
+
+    /**
+     * Returns a <code>LocalRuleExecutionSetProvider</code> implementation.
+     * 
+     * Returns a <code>LocalRuleExecutionSetProvider</code> implementation or
+     * null if this implementation does not support creating a
+     * <code>RuleExecutionSet</code> from non-serializable resources.
+     * 
+     * @param properties
+     *            additional properties
+     * 
+     * @return The created <code>LocalRuleExecutionSetProvider</code>.
+     */
+    public LocalRuleExecutionSetProvider getLocalRuleExecutionSetProvider(final Map properties) {
+        return new LocalRuleExecutionSetProviderImpl();
+    }
+
+    /**
+     * Registers a <code>RuleExecutionSet</code> and associates it with a
+     * given URI. Once a <code>RuleExecutionSet</code> has been registered it
+     * is accessible to runtime clients through the <code>RuleRuntime</code>.
+     * If a <code>RuleExecutionSet</code> has already been associated with the
+     * URI it should be deregistered (as if
+     * <code>deregisterRuleExecutionSet/</code> had been called) and the URI
+     * should be associated with the new <code>RuleExecutionSet</code>.
+     * 
+     * @param bindUri
+     *            the URI to associate with the <code>RuleExecutionSet</code>.
+     * @param set
+     *            the <code>RuleExecutionSet</code> to associate with the URI
+     * @param properties
+     *            additional properties used to perform the registration
+     * 
+     * @throws RuleExecutionSetRegisterException
+     *             if an error occurred that prevented registration
+     */
+    public void registerRuleExecutionSet(final String bindUri,
+                                         final RuleExecutionSet set,
+                                         final Map properties)
+    throws RuleExecutionSetRegisterException {
+    	
+        // Note: an existing RuleExecutionSet is simply replaced
+        repository.registerRuleExecutionSet(bindUri, set, properties);
+    }
+
+    /**
+     * Unregisters a previously registered <code>RuleExecutionSet</code> from
+     * a URI.
+     * 
+     * @param bindUri
+     *            the URI to disassociate with the <code>RuleExecutionSet</code>.
+     * @param properties
+     *            additional properties used to perform the deregistration
+     * 
+     * @throws RuleExecutionSetDeregistrationException
+     *             if an error occurred that prevented unregistration
+     */
+    public void deregisterRuleExecutionSet(final String bindUri,
+                                           final Map properties)
+    throws RuleExecutionSetDeregistrationException {
+    	
+        try {
+			if ( this.repository.getRuleExecutionSet(bindUri, properties) == null ) {
+			    throw new RuleExecutionSetDeregistrationException( "no execution set bound to: " + bindUri );
+			}
+		} catch (RuleExecutionSetRepositoryException e) {
+			String s = "Error while retrieving rule execution set bound to: " + bindUri;
+			throw new RuleExecutionSetDeregistrationException(s, e);
+		}
+
+        repository.unregisterRuleExecutionSet(bindUri, properties);
+    }
+}

Deleted: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetRepository.java	2008-08-07 20:09:49 UTC (rev 21401)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/admin/RuleExecutionSetRepository.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -1,127 +0,0 @@
-package org.drools.jsr94.rules.admin;
-
-/*
- * Copyright 2005 JBoss Inc
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.rules.admin.RuleExecutionSet;
-import javax.rules.admin.RuleExecutionSetRegisterException;
-
-/**
- * Stores the registered <code>RuleExecutionSet</code> objects.
- * 
- * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
- */
-public final class RuleExecutionSetRepository
-    implements
-    Serializable {
-    private static final long serialVersionUID = 400L;
-
-    /** The Singleton instance of the repository. */
-    // private static RuleExecutionSetRepository REPOSITORY;
-    /** Holds the registered <code>RuleExecutionSet</code> objects. */
-    private final Map         map              = new HashMap();
-
-    /** Private constructor; use <code>getInstance</code> instead. */
-    public RuleExecutionSetRepository() {
-        // Hide the constructor.
-    }
-
-    /**
-     * Gets the Singleton instance of a <code>RuleExecutionSetRepository</code>.
-     * 
-     * @return The Singleton instance of the repository.
-     */
-    // public static synchronized RuleExecutionSetRepository getInstance( )
-    // {
-    // if ( RuleExecutionSetRepository.REPOSITORY != null )
-    // {
-    // return RuleExecutionSetRepository.REPOSITORY;
-    // }
-    // return RuleExecutionSetRepository.REPOSITORY =
-    // new RuleExecutionSetRepository( );
-    // }
-    /**
-     * Retrieves a <code>List</code> of the URIs that currently have
-     * <code>RuleExecutionSet</code>s associated with them.
-     * 
-     * An empty list is returned is there are no associations.
-     * 
-     * @return a <code>List</code> of the URIs that currently have
-     *         <code>RuleExecutionSet</code>s associated with them.
-     */
-    public List getRegistrations() {
-        final List list = new ArrayList();
-        list.addAll( this.map.keySet() );
-        return list;
-    }
-
-    /**
-     * Get the <code>RuleExecutionSet</code> bound to this URI, or return
-     * <code>null</code>.
-     * 
-     * @param bindUri
-     *            the URI associated with the wanted
-     *            <code>RuleExecutionSet</code>.
-     * 
-     * @return the <code>RuleExecutionSet</code> bound to the given URI.
-     */
-    public RuleExecutionSet getRuleExecutionSet(final String bindUri) {
-        return (RuleExecutionSet) this.map.get( bindUri );
-    }
-
-    /**
-     * Register a <code>RuleExecutionSet</code> under the given URI.
-     * 
-     * @param bindUri
-     *            the URI to associate with the <code>RuleExecutionSet</code>.
-     * @param ruleSet
-     *            the <code>RuleExecutionSet</code> to associate with the URI
-     * 
-     * @throws RuleExecutionSetRegisterException
-     *             if an error occurred that prevented registration (i.e. if
-     *             bindUri or ruleSet are <code>null</code>)
-     */
-    public void registerRuleExecutionSet(final String bindUri,
-                                         final RuleExecutionSet ruleSet) throws RuleExecutionSetRegisterException {
-        if ( bindUri == null ) {
-            throw new RuleExecutionSetRegisterException( "bindUri cannot be null" );
-        }
-        if ( ruleSet == null ) {
-            throw new RuleExecutionSetRegisterException( "ruleSet cannot be null" );
-        }
-        this.map.put( bindUri,
-                      ruleSet );
-    }
-
-    /**
-     * Unregister a <code>RuleExecutionSet</code> from the given URI.
-     * 
-     * @param bindUri
-     *            the URI to disassociate with the <code>RuleExecutionSet</code>.
-     */
-    public void unregisterRuleExecutionSet(final String bindUri) {
-        if ( bindUri == null ) {
-            throw new NullPointerException( "bindUri cannot be null" );
-        }
-        this.map.remove( bindUri );
-    }
-}

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/DefaultRuleExecutionSetRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/DefaultRuleExecutionSetRepository.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/DefaultRuleExecutionSetRepository.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.admin.RuleExecutionSet;
+import javax.rules.admin.RuleExecutionSetDeregistrationException;
+import javax.rules.admin.RuleExecutionSetRegisterException;
+
+/**
+ * Stores the registered <code>RuleExecutionSet</code> objects.
+ * 
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public class DefaultRuleExecutionSetRepository
+    implements
+    RuleExecutionSetRepository
+{
+    private static final long serialVersionUID = 400L;
+
+    /**
+     * Holds the registered <code>RuleExecutionSet</code> objects.
+     */
+    private Map map = new HashMap();
+
+    /**
+     * 
+     */
+    public DefaultRuleExecutionSetRepository() {
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.jsr94.rules.admin.RuleExecutionSetRepository#getRegistrations()
+     */
+    public List getRegistrations()
+    throws RuleExecutionSetRepositoryException {
+        List list = new ArrayList();
+        list.addAll(map.keySet());
+        return list;
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.jsr94.rules.repository.RuleExecutionSetRepository#getRuleExecutionSet(java.lang.String, java.util.Map)
+     */
+    public RuleExecutionSet getRuleExecutionSet(
+    		String bindUri,
+    		Map properties)
+    throws RuleExecutionSetRepositoryException {
+        return (RuleExecutionSet)map.get(bindUri);
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.jsr94.rules.admin.RuleExecutionSetRepository#registerRuleExecutionSet(java.lang.String, javax.rules.admin.RuleExecutionSet, java.util.Map)
+     */
+	public void registerRuleExecutionSet(
+    		String bindUri,
+            RuleExecutionSet ruleSet,
+            Map properties)
+    throws RuleExecutionSetRegisterException {
+    	
+        if (bindUri == null) {
+            throw new RuleExecutionSetRegisterException("bindUri cannot be null");
+        }
+        
+        if (ruleSet == null) {
+            throw new RuleExecutionSetRegisterException("ruleSet cannot be null");
+        }
+        
+        map.put(bindUri, ruleSet);
+    }
+
+    /* (non-Javadoc)
+     * @see org.drools.jsr94.rules.admin.RuleExecutionSetRepository#unregisterRuleExecutionSet(java.lang.String, java.util.Map)
+     */
+	public void unregisterRuleExecutionSet(
+    		String bindUri,
+    		Map properties)
+    throws RuleExecutionSetDeregistrationException {
+    	
+        if (bindUri == null) {
+            throw new RuleExecutionSetDeregistrationException("bindUri cannot be null");
+        }
+        
+        map.remove(bindUri);
+    }
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/DefaultRuleExecutionSetRepository.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepository.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepository.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.admin.RuleExecutionSet;
+import javax.rules.admin.RuleExecutionSetDeregistrationException;
+import javax.rules.admin.RuleExecutionSetRegisterException;
+
+/**
+ * Stores the registered <code>RuleExecutionSet</code> objects.
+ * 
+ * @author <a href="mailto:thomas.diesler at softcon-itec.de">thomas diesler </a>
+ */
+public interface RuleExecutionSetRepository extends Serializable
+{
+    /**
+     * Retrieves a <code>List</code> of the URIs that currently have
+     * <code>RuleExecutionSet</code>s associated with them.
+     * 
+     * An empty list is returned if there are no associations.
+     * 
+     * @return a <code>List</code> of the URIs that currently have
+     *         <code>RuleExecutionSet</code>s associated with them.
+     * @throws RuleExecutionSetRepositoryException
+     */
+    List getRegistrations() throws RuleExecutionSetRepositoryException;
+
+    /**
+     * Get the <code>RuleExecutionSet</code> bound to this URI, or return
+     * <code>null</code>.
+     * 
+     * @param bindUri
+     *            the URI associated with the wanted
+     *            <code>RuleExecutionSet</code>.
+     * @param properties
+     * 
+     * @return the <code>RuleExecutionSet</code> bound to the given URI.
+     * @throws RuleExecutionSetRepositoryException
+     */
+    RuleExecutionSet getRuleExecutionSet(
+    		String bindUri,
+    		Map properties)
+    throws RuleExecutionSetRepositoryException;
+
+    /**
+     * Register a <code>RuleExecutionSet</code> under the given URI.
+     * 
+     * @param bindUri the URI to associate with the <code>RuleExecutionSet</code>.
+     * @param ruleSet the <code>RuleExecutionSet</code> to associate with the URI
+     * @param properties
+     * 
+     * @throws RuleExecutionSetRegisterException
+     *             if an error occurred that prevented registration (i.e. if
+     *             bindUri or ruleSet are <code>null</code>)
+     */
+	void registerRuleExecutionSet(
+    		String bindUri,
+    		RuleExecutionSet ruleSet,
+    		Map properties)
+    throws RuleExecutionSetRegisterException;
+
+    /**
+     * Unregister a <code>RuleExecutionSet</code> from the given URI.
+     * 
+     * @param bindUri the URI to disassociate with the <code>RuleExecutionSet</code>.
+     * @param properties
+     * @throws RuleExecutionSetDeregistrationException
+     *             if an error occurred that prevented deregistration
+     */
+	void unregisterRuleExecutionSet(
+    		String bindUri,
+    		Map properties)
+    throws RuleExecutionSetDeregistrationException;
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepository.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryException.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryException.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryException.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import javax.rules.RuleExecutionException;
+
+/**
+ * TODO
+ * 
+ * @version $Revision$ $Date$
+ * @author <a href="mailto:rlangbehn at users.sourceforge.net">Rainer Langbehn</a>
+ */
+public class RuleExecutionSetRepositoryException extends RuleExecutionException
+{
+	/**
+	 * Default serial version UID. 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * TODO
+	 * 
+	 * @param message
+	 */
+	public RuleExecutionSetRepositoryException(String message) {
+		super(message);
+	}
+
+	/**
+	 * TODO
+	 * 
+	 * @param message
+	 * @param exception
+	 */
+	public RuleExecutionSetRepositoryException(
+			String message,
+			Exception exception) {
+		super(message, exception);
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryException.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoader.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoader.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoader.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,180 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Properties;
+
+/**
+ * Load the <code>RuleExecutionSetRepository</code> using the following algorithm.
+ * 
+ * 1. If a resource with the name of META-INF/services/org.drools.jsr94.rules.repository.RuleExecutionSetRepository exists,
+ * then its first line, if present, is used as the UTF-8 encoded name of the implementation class.
+ * 
+ * 2. If the drools.properties file exists in the classpath and it is readable by the 
+ * java.util.Properties.load(InputStream) method and it contains an entry whose key is 
+ * org.drools.jsr94.rules.repository.RuleExecutionSetRepository, then the value of that
+ * entry is used as the name of the implementation class.
+ * 
+ * 3. If a system property with the name org.drools.jsr94.rules.repository.RuleExecutionSetRepository
+ * is defined, then its value is used as the name of the implementation class.
+ * 
+ * 4. Finally, a default implementation class name, if provided, is used.
+ * 
+ * @version $Revision$ $Date$
+ * @author <a href="mailto:rlangbehn at users.sourceforge.net">Rainer Langbehn</a>
+ */
+public abstract class RuleExecutionSetRepositoryLoader
+{
+	/**
+	 * Loads the <code>RuleExecutionSetRepository</code> using the
+	 * algorithm described above.
+	 * 
+	 * @param defaultFactoryName the className of the default
+	 * 	<code>RuleExecutionSetRepository</code> implementation
+	 * @return
+	 */
+	public static RuleExecutionSetRepository loadRuleExecutionSetRepository(
+			String defaultFactoryName) {
+
+		Object factory = null;
+		String factoryName = null;
+		ClassLoader cL = Thread.currentThread().getContextClassLoader();
+
+		// Use the Services API (as detailed in the JAR specification), if available, to determine the classname.
+		String propertyName = "org.drools.jsr94.rules.repository.RuleExecutionSetRepository";
+		String fileName = "META-INF/services/" + propertyName;
+		InputStream in = cL.getResourceAsStream(fileName);
+
+		if (in != null) {
+			BufferedReader reader = null;
+			
+			try {
+				reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
+				factoryName = reader.readLine();
+				
+				if (factoryName != null) {
+					factory = createFactory(cL, factoryName);
+				}
+				
+			} catch (UnsupportedEncodingException e) {
+				throw new IllegalStateException("Failed to load " + propertyName + ": " + factoryName, e);
+			} catch (IOException e) {
+				throw new IllegalStateException("Failed to load " + propertyName + ": " + factoryName, e);
+			} finally {
+				close(reader);
+			}
+		}
+
+		// Use the properties file "drools.properties"
+		if (factory == null) {
+			// TODO
+		}
+
+		// Use system property
+		if (factory == null) {
+			PrivilegedAction action = new PropertyAccessAction(propertyName);
+			factoryName = (String)AccessController.doPrivileged(action);
+			
+			if (factoryName != null) {
+				factory = createFactory(cL, factoryName);
+			}
+		}
+
+		// Use the default factory implementation class.
+		if (factory == null && defaultFactoryName != null) {
+			factory = createFactory(cL, defaultFactoryName);
+		}
+		
+		return (RuleExecutionSetRepository)factory;
+	}
+
+	/**
+	 * TODO
+	 * 
+	 * @param closeable
+	 */
+	private static void close(Closeable closeable) {
+		if (closeable != null) {
+			try {
+				closeable.close();
+			} catch (IOException e) {
+				// ignored
+			}
+		}
+	}
+	
+	/**
+	 * TODO
+	 * 
+	 * @param cL
+	 * @param factoryName
+	 * @return
+	 */
+	private static Object createFactory(ClassLoader cL, String factoryName) {
+		try {
+			Class factoryClass = cL.loadClass(factoryName);
+			return factoryClass.newInstance();
+		} catch (Throwable t) {
+			throw new IllegalStateException("Failed to load: " + factoryName, t);
+		}
+	}
+
+	private static class PropertyAccessAction implements PrivilegedAction
+	{
+		private String name;
+
+		PropertyAccessAction(String name) {
+			this.name = name;
+		}
+
+		public Object run() {
+			return System.getProperty(name);
+		}
+	}
+
+	private static class PropertyFileAccessAction implements PrivilegedAction
+	{
+		private String fileName;
+
+		PropertyFileAccessAction(String fileName) {
+			this.fileName = fileName;
+		}
+
+		public Object run() {
+			InputStream in = null;
+			
+			try {
+				in = new FileInputStream(fileName);
+				Properties props = new Properties();
+				props.load(in);
+				return props;
+			} catch (IOException e) {
+				throw new SecurityException("Cannot load properties: " + fileName, e);
+			} finally {
+				close(in);
+			}
+		}
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoader.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/package.html
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/package.html	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/package.html	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+</head>
+<body>
+Provides the APIs for rule execution set repositories.
+</body>
+</html>


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/main/java/org/drools/jsr94/rules/repository/package.html
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoaderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoaderTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoaderTest.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO
+ * 
+ * @version $Revision$ $Date$
+ * @author <a href="mailto:rlangbehn at users.sourceforge.net">Rainer Langbehn</a>
+ */
+public class RuleExecutionSetRepositoryLoaderTest extends TestCase
+{
+	/**
+	 * Creates a test case with the given name.
+	 * 
+	 * @param name
+	 */
+	public RuleExecutionSetRepositoryLoaderTest(String name) {
+		super(name);
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/* (non-Javadoc)
+	 * @see junit.framework.TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 * Test method for {@link org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryLoader#loadRuleExecutionSetRepository(java.lang.String)}.
+	 * 
+	 * @throws Exception
+	 */
+	public final void testLoadRuleExecutionSetRepository() throws Exception {
+		// TODO
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/RuleExecutionSetRepositoryLoaderTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/TestRuleExecutionSetRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/TestRuleExecutionSetRepository.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/TestRuleExecutionSetRepository.java	2008-08-08 00:44:15 UTC (rev 21402)
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2005 JBoss Inc
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.jsr94.rules.repository;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.rules.admin.RuleExecutionSet;
+import javax.rules.admin.RuleExecutionSetDeregistrationException;
+import javax.rules.admin.RuleExecutionSetRegisterException;
+
+/**
+ * TODO
+ * 
+ * @version $Revision$ $Date$
+ * @author <a href="mailto:rlangbehn at users.sourceforge.net">Rainer Langbehn</a>
+ */
+public class TestRuleExecutionSetRepository
+	implements RuleExecutionSetRepository
+{
+	/**
+	 * Default serial version UID.
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Required default ctor. 
+	 */
+	public TestRuleExecutionSetRepository() {
+	}
+
+	/* (non-Javadoc)
+	 * @see org.drools.jsr94.rules.repository.RuleExecutionSetRepository#getRegistrations()
+	 */
+	public List getRegistrations()
+	throws RuleExecutionSetRepositoryException {
+		String s = "Implementation outstanding";
+		throw new UnsupportedOperationException(s);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.drools.jsr94.rules.repository.RuleExecutionSetRepository#getRuleExecutionSet(java.lang.String, java.util.Map)
+	 */
+	public RuleExecutionSet getRuleExecutionSet(
+			String bindUri,
+			Map properties)
+	throws RuleExecutionSetRepositoryException {
+		String s = "Implementation outstanding";
+		throw new UnsupportedOperationException(s);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.drools.jsr94.rules.repository.RuleExecutionSetRepository#registerRuleExecutionSet(java.lang.String, javax.rules.admin.RuleExecutionSet, java.util.Map)
+	 */
+	public void registerRuleExecutionSet(
+			String bindUri,
+			RuleExecutionSet ruleSet,
+			Map properties)
+	throws RuleExecutionSetRegisterException {
+		String s = "Implementation outstanding";
+		throw new UnsupportedOperationException(s);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.drools.jsr94.rules.repository.RuleExecutionSetRepository#unregisterRuleExecutionSet(java.lang.String, java.util.Map)
+	 */
+	public void unregisterRuleExecutionSet(
+			String bindUri,
+			Map properties)
+	throws RuleExecutionSetDeregistrationException {
+		String s = "Implementation outstanding";
+		throw new UnsupportedOperationException(s);
+	}
+}


Property changes on: labs/jbossrules/trunk/drools-jsr94/src/test/java/org/drools/jsr94/rules/repository/TestRuleExecutionSetRepository.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list