Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 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.command;
 
 import java.util.List;
 import java.util.Map;
 

The CommandFactory returns Commands that can be used by classes that implement CommandExecutor. Typically more than one Command will want to be executed, where is where the BatchExecution comes in, which takes a List of commands, think of it as CompositeCommand.

Out of the box marshalling to XML is support for the Commands, specifically the BatchExecution command and ExecutionResults, using the Drools Pipeline. If the drools-pipeline module is added then the PipelineFactory can be used in conjunction with the BatchExecutionHelper to marshall to and from XML. BatchExecutionHelper also provides additional documentation on the supported XML format.

`

This api is experimental and thus the classes and the interfaces returned are subject to change.

BETA:
 
 public class CommandFactory {
     private static volatile CommandFactoryService provider;

    
Inserts a new instance

Parameters:
object
Returns:
 
     public static Command newInsert(Object object) {
         return getCommandFactoryProvider().newInsertobject );
     }

    
Inserts a new instance but references via the outIdentifier, which is returned as part of the ExecutionResults

Parameters:
object
outIdentifier
Returns:
 
     public static Command newInsert(Object object,
                                     String outIdentifier) {
         return getCommandFactoryProvider().newInsertobject,
                                                       outIdentifier,
                                                       true,
                                                       null );
     }
    
    
Inserts a new instance but references via the outIdentifier, which is returned as part of the ExecutionResults The outIdentifier can be null. The entryPoint, which can also be null, specifies the entrypoint the object is inserted into.

Parameters:
object
outIdentifier
entryPoint
Returns:
 
     public static Command newInsert(Object object,
                                     String outIdentifier,
                                     boolean returnObject,
                                     String entryPoint ) {
         return getCommandFactoryProvider().newInsertobject,
                                                       outIdentifier,
                                                       returnObject,
                                                       entryPoint );
     }

    
Iterate and insert each of the elements of the Collection.

Parameters:
objects The objects to insert
Returns:
 
     public static Command newInsertElements(Collection objects) {
        return getCommandFactoryProvider().newInsertElementsobjects );
    }
    
    
Iterate and insert each of the elements of the Collection.

Parameters:
objects The objects to insert
outIdentifier Identifier to lookup the returned objects
returnObject boolean to specify whether the inserted Collection is part of the ExecutionResults
entryPoint Optional EntryPoint for the insertions
Returns:
    public static Command newInsertElements(Collection objectsString outIdentifierboolean returnObjectString entryPoint) {
        return getCommandFactoryProvider().newInsertElementsobjectsoutIdentifierreturnObjectentryPoint );
    }
    public static Command newRetract(FactHandle factHandle) {
        return getCommandFactoryProvider().newRetractfactHandle );
    }
    public static Setter newSetter(String accessor,
                                   String value) {
        return getCommandFactoryProvider().newSetteraccessor,
                                                      value );
    }
    public static Command newModify(FactHandle factHandle,
                                    List<Settersetters) {
        return getCommandFactoryProvider().newModifyfactHandle,
                                                      setters );
    }
    public static Command newGetObject(FactHandle factHandle) {
        return getCommandFactoryProvider().newGetObjectfactHandle );
    }
    public static Command newGetObject(FactHandle factHandleString outIdentifier ) {
        return getCommandFactoryProvider().newGetObjectfactHandleoutIdentifier );
    }
    public static Command newGetObjects() {
        return getCommandFactoryProvider().newGetObjects();
    }
    public static Command newGetObjectsString outIdentifier ) {
        return getCommandFactoryProvider().newGetObjectsoutIdentifier );
    }
    public static Command newGetObjects(ObjectFilter filter) {
        return getCommandFactoryProvider().newGetObjectsfilter );
    }
    public static Command newGetObjects(ObjectFilter filterString outIdentifier ) {
        return getCommandFactoryProvider().newGetObjectsfilter );
    }

    
Sets the global. Does not add the global to the ExecutionResults.

Parameters:
identifier The identifier of the global
object The instance to be set as the global.
Returns:
    public static Command newSetGlobal(String identifier,
                                       Object object) {
        return getCommandFactoryProvider().newSetGlobalidentifier,
                                                         object );
    }

    
Sets the global but also when the out parameter is true specifies that the global is added to the ExecutionResults.

Parameters:
identifier The identifier of the global
object The instance to be set as the global.
out When true the global will be added to the ExecutionResults using the global's identifier.
Returns:
    public static Command newSetGlobal(String identifier,
                                       Object object,
                                       boolean out) {
        return getCommandFactoryProvider().newSetGlobalidentifier,
                                                         object,
                                                         out );
    }

    
Sets the global but also specifies that the global is added to the ExecutionResults. Instead of using the global's identifier it uses the outIdentifier when being added to the ExecutionResults.

Parameters:
identifier The identifier of the global
object The instance to be set as the global.
outIdentifier The identifier used to store the global in the ExecutionResults
Returns:
    public static Command newSetGlobal(String identifier,
                                       Object object,
                                       String outIdentifier) {
        return getCommandFactoryProvider().newSetGlobalidentifier,
                                                         object,
                                                         outIdentifier );
    }

    
Gets the global and adds it to the ExecutionResults

Parameters:
identifier
Returns:
    public static Command newGetGlobal(String identifier) {
        return getCommandFactoryProvider().newGetGlobalidentifier );
    }

    
Gets the global and adds it ot the BatchExecutionresults using the alternative outIdentifier.

Parameters:
identifier The identifier of the global
outIdentifier The identifier used in the ExecutionResults to store the global.
Returns:
    public static Command newGetGlobal(String identifier,
                                       String outIdentifier) {
        return getCommandFactoryProvider().newGetGlobalidentifier,
                                                         outIdentifier );
    }
    public static Command newFireAllRules() {
        return getCommandFactoryProvider().newFireAllRules();
    }
    public static Command newFireAllRules(int max) {
        return getCommandFactoryProvider().newFireAllRulesmax );
    }
    public static Command newFireAllRules(String outidentifier) {
        return getCommandFactoryProvider().newFireAllRulesoutidentifier );
    }

    
Start a process

Parameters:
processId
Returns:
    public static Command newStartProcess(String processId) {
        return getCommandFactoryProvider().newStartProcessprocessId );
    }

    
Start a process using the given parameters.

Parameters:
processId
parameters
Returns:
    public static Command newStartProcess(String processId,
                                          Map<StringObjectparameters) {
        return getCommandFactoryProvider().newStartProcessprocessId,
                                                            parameters );
    }
    public static Command newSignalEvent(String type,
                                         Object event) {
        return getCommandFactoryProvider().newSignalEventtype,
                                                           event );
    }
    public static Command newSignalEvent(long processInstanceId,
                                         String type,
                                         Object event) {
        return getCommandFactoryProvider().newSignalEventprocessInstanceId,
                                                           type,
                                                           event );
    }
    
                                                     String workItemName) {
                                                                              workItemName );        
    }
    public static Command newCompleteWorkItem(long workItemId,
                                              Map<StringObjectresults) {
        return getCommandFactoryProvider().newCompleteWorkItemworkItemId,
                                                                results );
    }
    
    public static Command newAbortWorkItem(long workItemId) {
        return getCommandFactoryProvider().newAbortWorkItemworkItemId );
    }

    
Executes a query. The query results will be added to the ExecutionResults using the given identifier.

Parameters:
identifier The identifier to be used for the results when added to the ExecutionResults
name The name of the query to execute
Returns:
    public static Command newQuery(String identifier,
                                   String name) {
        return getCommandFactoryProvider().newQueryidentifier,
                                                     name );
    }

    
Executes a query using the given parameters. The query results will be added to the ExecutionResults using the given identifier.

Parameters:
identifier The identifier to be used for the results when added to the ExecutionResults
name The name of the query to execute
arguments The arguments to be used for the query parameters
Returns:
    public static Command newQuery(String identifier,
                                   String name,
                                   Object[] arguments) {
        return getCommandFactoryProvider().newQueryidentifier,
                                                     name,
                                                     arguments );
    }

    
This is a special composite command and will execute all the supplied commands in turn.

Parameters:
commands
Returns:
    public static BatchExecutionCommand newBatchExecution(List< ? extends Commandcommands) {
        return getCommandFactoryProvider().newBatchExecutioncommandsnull );
    }
    
    

Returns:
    public static BatchExecutionCommand newBatchExecution(List< ? extends CommandcommandsString lookup ) {
        return getCommandFactoryProvider().newBatchExecutioncommands,
                                                              lookup);
    }
    private static synchronized void setCommandFactoryProvider(CommandFactoryService provider) {
        . = provider;
    }
    private static synchronized CommandFactoryService getCommandFactoryProvider() {
        if (  == null ) {
            loadProvider();
        }
        return ;
    }
    private static void loadProvider() {
        try {
            Class<CommandFactoryServicecls = (Class<CommandFactoryService>) Class.forName"org.drools.command.impl.CommandFactoryServiceImpl" );
            setCommandFactoryProvidercls.newInstance() );
        } catch ( Exception e2 ) {
            throw new RuntimeException"Provider org.drools.command.impl.CommandFactoryProviderImpl could not be set.",
                                                       e2 );
        }
    }
    @Deprecated
    public static Command newKBuilderSetPropertyCommand(String idString nameString value) {
        return getCommandFactoryProvider().newKBuilderSetPropertyCommand(idnamevalue);
    }
    public static Command newKnowledgeBuilderSetPropertyCommand(String idString nameString value) {
        return getCommandFactoryProvider().newKnowledgeBuilderSetPropertyCommand(idnamevalue);
    }
    
    public static Command newNewKnowledgeBuilderConfigurationCommand(String localId) {
    }
    
    public static Command<FactHandlefromExternalFactHandleCommand(String factHandleExternalForm) {
        return getCommandFactoryProvider().fromExternalFactHandleCommand(factHandleExternalForm);
    }
    public static Command<FactHandlefromExternalFactHandleCommand(String factHandleExternalFormboolean disconnected) {
        return getCommandFactoryProvider().fromExternalFactHandleCommand(factHandleExternalFormdisconnected);
    }
New to GrepCode? Check out our FAQ X