[jboss-svn-commits] JBL Code SVN: r34005 - in labs/jbossrules/trunk: drools-core/src/main/java/org/drools and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 18 18:45:52 EDT 2010
Author: tirelli
Date: 2010-07-18 18:45:52 -0400 (Sun, 18 Jul 2010)
New Revision: 34005
Added:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/conf/WorkItemHandlerOption.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
Log:
Adding configuration option for WorkItemHandlers
Added: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/conf/WorkItemHandlerOption.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/conf/WorkItemHandlerOption.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/conf/WorkItemHandlerOption.java 2010-07-18 22:45:52 UTC (rev 34005)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2008 Red Hat
+ *
+ * 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.runtime.conf;
+
+import org.drools.runtime.process.WorkItemHandler;
+
+/**
+ * WorkItemHandlers configuration option
+ *
+ * @author etirelli
+ */
+public class WorkItemHandlerOption implements MultiValueKnowledgeSessionOption {
+
+ private static final long serialVersionUID = -8461267995706982981L;
+
+ /**
+ * The prefix for the property name for work item handlers
+ */
+ public static final String PROPERTY_NAME = "drools.workItemHandlers";
+
+ /**
+ * work item handler name
+ */
+ private final String name;
+
+ /**
+ * the accumulate function instance
+ */
+ private final WorkItemHandler handler;
+
+ /**
+ * Private constructor to enforce the use of the factory method
+ * @param name
+ */
+ private WorkItemHandlerOption( final String name, final WorkItemHandler handler ) {
+ this.name = name;
+ this.handler = handler;
+ }
+
+ /**
+ * This is a factory method for this WorkItemHandler configuration.
+ * The factory method is a best practice for the case where the
+ * actual object construction is changed in the future.
+ *
+ * @param name the name of the work item handler to be configured
+ *
+ * @return the actual type safe work item handler configuration.
+ */
+ public static WorkItemHandlerOption get( final String name, final WorkItemHandler handler ) {
+ return new WorkItemHandlerOption( name, handler );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPropertyName() {
+ return PROPERTY_NAME+name;
+ }
+
+ /**
+ * Returns the name of the configured work item handler
+ *
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the work item handler instance
+ * @return
+ */
+ public WorkItemHandler getHandler() {
+ return handler;
+ }
+
+ @Override
+ public String toString() {
+ return "WorkItemHandler( name="+name+" handler="+handler+" )";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((handler == null) ? 0 : handler.getClass().hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ WorkItemHandlerOption other = (WorkItemHandlerOption) obj;
+ if ( handler == null ) {
+ if ( other.handler != null ) return false;
+ } else if ( other.handler == null ) {
+ return false;
+ } else if( !handler.getClass().getName().equals( other.handler.getClass().getName() ) ) return false;
+ if ( name == null ) {
+ if ( other.name != null ) return false;
+ } else if ( !name.equals( other.name ) ) return false;
+ return true;
+ }
+}
Property changes on: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/conf/WorkItemHandlerOption.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java 2010-07-18 22:40:20 UTC (rev 34004)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/SessionConfiguration.java 2010-07-18 22:45:52 UTC (rev 34005)
@@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Properties;
+import org.drools.builder.conf.AccumulateFunctionOption;
import org.drools.command.CommandService;
import org.drools.core.util.ConfFileUtils;
import org.drools.core.util.StringUtils;
@@ -37,6 +38,7 @@
import org.drools.runtime.conf.KnowledgeSessionOption;
import org.drools.runtime.conf.MultiValueKnowledgeSessionOption;
import org.drools.runtime.conf.SingleValueKnowledgeSessionOption;
+import org.drools.runtime.conf.WorkItemHandlerOption;
import org.drools.runtime.process.WorkItemHandler;
import org.drools.util.ChainedProperties;
import org.drools.util.ClassLoaderUtil;
@@ -64,24 +66,24 @@
implements
KnowledgeSessionConfiguration,
Externalizable {
- private static final long serialVersionUID = 500L;
+ private static final long serialVersionUID = 500L;
- private ChainedProperties chainedProperties;
+ private ChainedProperties chainedProperties;
- private volatile boolean immutable;
+ private volatile boolean immutable;
- private boolean keepReference;
+ private boolean keepReference;
- private ClockType clockType;
+ private ClockType clockType;
- private Map<String, WorkItemHandler> workItemHandlers;
- private ProcessInstanceManagerFactory processInstanceManagerFactory;
- private SignalManagerFactory processSignalManagerFactory;
- private WorkItemManagerFactory workItemManagerFactory;
- private CommandService commandService;
+ private Map<String, WorkItemHandler> workItemHandlers;
+ private ProcessInstanceManagerFactory processInstanceManagerFactory;
+ private SignalManagerFactory processSignalManagerFactory;
+ private WorkItemManagerFactory workItemManagerFactory;
+ private CommandService commandService;
- private transient ClassLoader classLoader;
-
+ private transient ClassLoader classLoader;
+
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject( chainedProperties );
out.writeBoolean( immutable );
@@ -104,27 +106,32 @@
* @param properties
*/
public SessionConfiguration(Properties properties) {
- init( null, properties );
+ init( null,
+ properties );
}
/**
* Creates a new session configuration with default configuration options.
*/
public SessionConfiguration() {
- init( null, null );
+ init( null,
+ null );
}
-
+
public SessionConfiguration(ClassLoader classLoader) {
- init ( classLoader, null );
+ init( classLoader,
+ null );
}
- private void init(ClassLoader classLoader, Properties properties) {
- this.classLoader = ClassLoaderUtil.getClassLoader( classLoader,
- getClass(),
- false );
-
+ private void init(ClassLoader classLoader,
+ Properties properties) {
+ this.classLoader = ClassLoaderUtil.getClassLoader( classLoader,
+ getClass(),
+ false );
+
this.immutable = false;
- this.chainedProperties = new ChainedProperties( "session.conf", this.classLoader );
+ this.chainedProperties = new ChainedProperties( "session.conf",
+ this.classLoader );
if ( properties != null ) {
this.chainedProperties.addProperties( properties );
@@ -136,41 +143,41 @@
setClockType( ClockType.resolveClockType( this.chainedProperties.getProperty( ClockTypeOption.PROPERTY_NAME,
"realtime" ) ) );
}
-
+
public void addProperties(Properties properties) {
if ( properties != null ) {
this.chainedProperties.addProperties( properties );
- }
+ }
}
-
+
public void setProperty(String name,
String value) {
name = name.trim();
if ( StringUtils.isEmpty( name ) ) {
return;
}
-
+
if ( name.equals( KeepReferenceOption.PROPERTY_NAME ) ) {
- setKeepReference( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
+ setKeepReference( StringUtils.isEmpty( value ) ? true : Boolean.parseBoolean( value ) );
} else if ( name.equals( ClockTypeOption.PROPERTY_NAME ) ) {
- setClockType( ClockType.resolveClockType( StringUtils.isEmpty( value ) ? "realtime" : value ) );
+ setClockType( ClockType.resolveClockType( StringUtils.isEmpty( value ) ? "realtime" : value ) );
}
- }
-
+ }
+
public String getProperty(String name) {
name = name.trim();
if ( StringUtils.isEmpty( name ) ) {
return null;
}
-
+
if ( name.equals( KeepReferenceOption.PROPERTY_NAME ) ) {
return Boolean.toString( this.keepReference );
} else if ( name.equals( ClockTypeOption.PROPERTY_NAME ) ) {
return this.clockType.toExternalForm();
}
-
+
return null;
- }
+ }
/**
* Makes the configuration object immutable. Once it becomes immutable,
@@ -360,21 +367,25 @@
throw new IllegalArgumentException( "Work item manager factory '" + className + "' not found" );
}
}
-
- public CommandService getCommandService(KnowledgeBase kbase, Environment environment) {
+
+ public CommandService getCommandService(KnowledgeBase kbase,
+ Environment environment) {
if ( this.commandService == null ) {
- initCommandService(kbase, environment);
+ initCommandService( kbase,
+ environment );
}
return this.commandService;
}
@SuppressWarnings("unchecked")
- private void initCommandService(KnowledgeBase kbase, Environment environment) {
- String className = this.chainedProperties.getProperty( "drools.commandService", null );
- if (className == null) {
- return;
+ private void initCommandService(KnowledgeBase kbase,
+ Environment environment) {
+ String className = this.chainedProperties.getProperty( "drools.commandService",
+ null );
+ if ( className == null ) {
+ return;
}
-
+
Class<CommandService> clazz = null;
try {
clazz = (Class<CommandService>) Thread.currentThread().getContextClassLoader().loadClass( className );
@@ -390,7 +401,11 @@
if ( clazz != null ) {
try {
- this.commandService = clazz.getConstructor(KnowledgeBase.class, KnowledgeSessionConfiguration.class, Environment.class).newInstance(kbase, this, environment);
+ this.commandService = clazz.getConstructor( KnowledgeBase.class,
+ KnowledgeSessionConfiguration.class,
+ Environment.class ).newInstance( kbase,
+ this,
+ environment );
} catch ( Exception e ) {
throw new IllegalArgumentException( "Unable to instantiate command service '" + className + "'",
e );
@@ -404,22 +419,30 @@
public <T extends SingleValueKnowledgeSessionOption> T getOption(Class<T> option) {
if ( ClockTypeOption.class.equals( option ) ) {
return (T) ClockTypeOption.get( getClockType().toExternalForm() );
- } else if( KeepReferenceOption.class.equals( option ) ) {
- return (T) ( this.keepReference ? KeepReferenceOption.YES : KeepReferenceOption.NO );
+ } else if ( KeepReferenceOption.class.equals( option ) ) {
+ return (T) (this.keepReference ? KeepReferenceOption.YES : KeepReferenceOption.NO);
}
return null;
}
+ @SuppressWarnings("unchecked")
public <T extends MultiValueKnowledgeSessionOption> T getOption(Class<T> option,
String key) {
+ if ( WorkItemHandlerOption.class.equals( option ) ) {
+ return (T) WorkItemHandlerOption.get( key,
+ getWorkItemHandlers().get( key ) );
+ }
return null;
}
public <T extends KnowledgeSessionOption> void setOption(T option) {
if ( option instanceof ClockTypeOption ) {
- setClockType( ClockType.resolveClockType( ((ClockTypeOption) option ).getClockType() ) );
- } else if( option instanceof KeepReferenceOption ) {
+ setClockType( ClockType.resolveClockType( ((ClockTypeOption) option).getClockType() ) );
+ } else if ( option instanceof KeepReferenceOption ) {
setKeepReference( ((KeepReferenceOption) option).isKeepReference() );
+ } else if ( option instanceof WorkItemHandlerOption ) {
+ getWorkItemHandlers().put( ((WorkItemHandlerOption)option).getName(),
+ ((WorkItemHandlerOption)option).getHandler() );
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2010-07-18 22:40:20 UTC (rev 34004)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Package.java 2010-07-18 22:45:52 UTC (rev 34005)
@@ -33,7 +33,6 @@
import org.drools.base.ClassFieldAccessorStore;
import org.drools.common.DroolsObjectInputStream;
import org.drools.common.DroolsObjectOutputStream;
-import org.drools.definition.KnowledgeDefinition;
import org.drools.definition.process.Process;
import org.drools.definition.type.FactType;
import org.drools.facttemplates.FactTemplate;
More information about the jboss-svn-commits
mailing list