Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.automation.core.impl
Class OperationServiceImpl

java.lang.Object
  extended by org.nuxeo.ecm.automation.core.impl.OperationServiceImpl
All Implemented Interfaces:
AutomationService

public class OperationServiceImpl
extends Object
implements AutomationService

The operation registry is thread safe and optimized for modifications at startup and lookups at runtime.

Author:
Bogdan Stefanescu

Constructor Summary
OperationServiceImpl()
           
 
Method Summary
 CompiledChain compileChain(Class<?> inputType, OperationChain chain)
          Builds the operation chain given a context.
 CompiledChain compileChain(Class<?> inputType, OperationParameters... chain)
          Same as previous but takes an array of operation parameters
 void flushCompiledChains()
           
<T> T
getAdaptedValue(OperationContext ctx, Object toAdapt, Class<?> targetType)
          Adapts an object to a target type if possible otherwise throws an exception.
 org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.ChainEntry getChainEntry(String id)
           
 List<OperationDocumentation> getDocumentation()
          Generates a documentation model for all registered operations.
 OperationType getOperation(String id)
          Gets an operation type given its ID.
 OperationChain getOperationChain(String id)
          Gets a registered operation chain.
 List<OperationChain> getOperationChains()
          Gets a list of all registered chains
 OperationType[] getOperations()
          Gets all operation types that was registered.
 TypeAdapter getTypeAdapter(Class<?> accept, Class<?> produce)
          Gets a type adapter for the input type accept and the output type produce.
static Class<?> getTypeForPrimitive(Class<?> primitiveType)
           
 boolean isTypeAdaptable(Class<?> typeToAdapt, Class<?> targetType)
          Checks whether or not the given type is adaptable into the target type.
 void putOperation(Class<?> type)
          Registers an operation given its class.
 void putOperation(Class<?> type, boolean replace)
          Registers an operation given its class.
 void putOperationChain(OperationChain chain)
          Registers a parametrized operation chain.
 void putOperationChain(OperationChain chain, boolean replace)
          Registers a parametrized operation chain.
 void putTypeAdapter(Class<?> accept, Class<?> produce, TypeAdapter adapter)
          Registers a new type adapter that can adapt an instance of the accepted type into one of the produced type.
 void removeOperation(Class<?> key)
          Removes an operation given its class.
 void removeOperationChain(String id)
          Removes a registered operation chain given its ID.
 void removeTypeAdapter(Class<?> accept, Class<?> produce)
          Removes a type adapter
 Object run(OperationContext ctx, OperationChain chain)
          Builds and runs the operation chain given a context.
 Object run(OperationContext ctx, String chainId)
          Same as previous but for managed chains identified by an ID.
 Object run(OperationContext ctx, String id, Map<String,Object> params)
          TODO avoid creating a temporary chain and then compile it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperationServiceImpl

public OperationServiceImpl()
Method Detail

run

public Object run(OperationContext ctx,
                  String chainId)
           throws OperationException,
                  InvalidChainException,
                  Exception
Description copied from interface: AutomationService
Same as previous but for managed chains identified by an ID. For managed chains always use this method since the compiled chain is cached and run will be faster

Specified by:
run in interface AutomationService
Throws:
OperationException
InvalidChainException
Exception

run

public Object run(OperationContext ctx,
                  OperationChain chain)
           throws OperationException,
                  InvalidChainException,
                  Exception
Description copied from interface: AutomationService
Builds and runs the operation chain given a context. If the context input object or the chain cannot be resolved (no path can be found through all the operation in the chain) then InvalidChainException is thrown.

Specified by:
run in interface AutomationService
Throws:
OperationException
InvalidChainException
Exception

run

public Object run(OperationContext ctx,
                  String id,
                  Map<String,Object> params)
           throws OperationException,
                  InvalidChainException,
                  Exception
TODO avoid creating a temporary chain and then compile it. try to find a way to execute the single operation without compiling it. (for optimization)

Specified by:
run in interface AutomationService
Throws:
OperationException
InvalidChainException
Exception

putOperationChain

public void putOperationChain(OperationChain chain)
                       throws OperationException
Description copied from interface: AutomationService
Registers a parametrized operation chain. This chain can be executed later by calling run and passing the chain ID. If a chain having the same ID exists an exception is thrown

Specified by:
putOperationChain in interface AutomationService
Throws:
OperationException

putOperationChain

public void putOperationChain(OperationChain chain,
                              boolean replace)
                       throws OperationException
Description copied from interface: AutomationService
Registers a parametrized operation chain. This chain can be executed later by calling run and passing the chain ID. If the replace attribute is true then any chain already registered under the same id will be replaced otherwise an exception is thrown.

Specified by:
putOperationChain in interface AutomationService
Throws:
OperationException

removeOperationChain

public void removeOperationChain(String id)
Description copied from interface: AutomationService
Removes a registered operation chain given its ID. Do nothing if the chain was not registered.

Specified by:
removeOperationChain in interface AutomationService

getOperationChain

public OperationChain getOperationChain(String id)
                                 throws OperationNotFoundException
Description copied from interface: AutomationService
Gets a registered operation chain.

Specified by:
getOperationChain in interface AutomationService
Throws:
OperationNotFoundException

getOperationChains

public List<OperationChain> getOperationChains()
Description copied from interface: AutomationService
Gets a list of all registered chains

Specified by:
getOperationChains in interface AutomationService
Returns:
the list or an empty list if no registered chains exists

getChainEntry

public org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.ChainEntry getChainEntry(String id)
                                                                                 throws OperationException
Throws:
OperationException

flushCompiledChains

public void flushCompiledChains()

putOperation

public void putOperation(Class<?> type)
                  throws OperationException
Description copied from interface: AutomationService
Registers an operation given its class. The operation class MUST be annotated using Operation annotation. If an operation having the same ID exists an exception will be thrown.

Specified by:
putOperation in interface AutomationService
Throws:
OperationException

putOperation

public void putOperation(Class<?> type,
                         boolean replace)
                  throws OperationException
Description copied from interface: AutomationService
Registers an operation given its class. The operation class MUST be annotated using Operation annotation. If the replace argument is true then any existing operation having the same ID will replaced with this one.

Specified by:
putOperation in interface AutomationService
Throws:
OperationException

removeOperation

public void removeOperation(Class<?> key)
Description copied from interface: AutomationService
Removes an operation given its class. If the operation was not registered does nothing.

Specified by:
removeOperation in interface AutomationService

getOperations

public OperationType[] getOperations()
Description copied from interface: AutomationService
Gets all operation types that was registered.

Specified by:
getOperations in interface AutomationService

getOperation

public OperationType getOperation(String id)
                           throws OperationNotFoundException
Description copied from interface: AutomationService
Gets an operation type given its ID. Throws an exception if the operation is not found.

Specified by:
getOperation in interface AutomationService
Throws:
OperationNotFoundException

compileChain

public CompiledChain compileChain(Class<?> inputType,
                                  OperationChain chain)
                           throws Exception,
                                  InvalidChainException
Description copied from interface: AutomationService
Builds the operation chain given a context. If the context input object or the chain cannot be resolved (no path can be found through all the operation in the chain) then InvalidChainException is thrown. The returned object can be used to run the chain.

Specified by:
compileChain in interface AutomationService
Throws:
Exception
InvalidChainException

compileChain

public CompiledChain compileChain(Class<?> inputType,
                                  OperationParameters... chain)
                           throws Exception,
                                  InvalidChainException
Description copied from interface: AutomationService
Same as previous but takes an array of operation parameters

Specified by:
compileChain in interface AutomationService
Throws:
Exception
InvalidChainException

putTypeAdapter

public void putTypeAdapter(Class<?> accept,
                           Class<?> produce,
                           TypeAdapter adapter)
Description copied from interface: AutomationService
Registers a new type adapter that can adapt an instance of the accepted type into one of the produced type.

Specified by:
putTypeAdapter in interface AutomationService

removeTypeAdapter

public void removeTypeAdapter(Class<?> accept,
                              Class<?> produce)
Description copied from interface: AutomationService
Removes a type adapter

Specified by:
removeTypeAdapter in interface AutomationService

getTypeAdapter

public TypeAdapter getTypeAdapter(Class<?> accept,
                                  Class<?> produce)
Description copied from interface: AutomationService
Gets a type adapter for the input type accept and the output type produce. Returns null if no adapter was registered for these types.

Specified by:
getTypeAdapter in interface AutomationService

isTypeAdaptable

public boolean isTypeAdaptable(Class<?> typeToAdapt,
                               Class<?> targetType)
Description copied from interface: AutomationService
Checks whether or not the given type is adaptable into the target type. An instance of an adaptable type can be converted into an instance of the target type.

This is a shortcut to getTypeAdapter(typeToAdapt, targetType) != null

Specified by:
isTypeAdaptable in interface AutomationService

getAdaptedValue

public <T> T getAdaptedValue(OperationContext ctx,
                             Object toAdapt,
                             Class<?> targetType)
                  throws Exception
Description copied from interface: AutomationService
Adapts an object to a target type if possible otherwise throws an exception. The method must be called in an operation execution with a valid operation context.

Specified by:
getAdaptedValue in interface AutomationService
Throws:
Exception

getDocumentation

public List<OperationDocumentation> getDocumentation()
Description copied from interface: AutomationService
Generates a documentation model for all registered operations. The documentation model is generated from operation annotations and can be used in UI tools to describe operations. The returned list is sorted using operation ID. Optional method.

Specified by:
getDocumentation in interface AutomationService

getTypeForPrimitive

public static Class<?> getTypeForPrimitive(Class<?> primitiveType)

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.