Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php 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.kuali.rice.kew.actions;
 
 
 import java.util.List;
 import java.util.Map;



A simple implementation of an ActionRegistry which includes all of the default Workflow Actions.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class ActionRegistryImpl implements ActionRegistry {
     private static final Logger LOG = Logger.getLogger(ActionRegistryImpl.class);
 
 	private static Map<StringStringactionMap = new HashMap<StringString>();
 	static {
 		//actionMap.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, SuperUserActionRequestAcknowledgeEvent.class.getName());
 		//actionMap.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, SuperUserActionRequestCompleteEvent.class.getName());
 		//actionMap.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, SuperUserActionRequestFYIEvent.class.getName());
         .put(..getCode(), RecallAction.class.getName());
 	}
 
 	public void registerAction(String actionCodeString actionClass) {
 		if (actionClass == null) {
 			throw new IllegalArgumentException("Action Code '" + actionCode + "' cannot be registered with a null action class.");
 		}
 		if (.containsKey(actionCode)) {
 			throw new WorkflowRuntimeException("Action Code is already in use.  [" +
 					actionCode + ", " + actionClass + "].  "+
 					"Please unregister the existing implementation first.");
 		}
 		.put(actionCodeactionClass);
 	}
 
 	public void unregisterAction(String actionCode) {
 		.remove(actionCode);
 	}
 
 	public Map getActionMap() {
 		return Collections.unmodifiableMap();
 	}
 
 	/* (non-Javadoc)
	 * @see org.kuali.rice.kew.actions.ActionRegistry#createAction(java.lang.String, java.util.List)
	 */
		String actionClassName = .get(actionCode);
		if (actionClassName == null) {
			throw new IllegalArgumentException("No action has been registered for the given action code of '" + actionCode + "'.");
		}
		ObjectDefinition actionDefinition = new ObjectDefinition(actionClassName);
		if (parameters != null && !parameters.isEmpty()) {
			actionDefinition.setConstructorParameters(parameters);
		}
		try {
			//ActionTakenEvent actionTaken = (ActionTakenEvent)GlobalResourceLoader.getResourceLoader().getObject(actionDefinition);
			// TODO ActionTakenEvent is not an interface so we can't fetch them through the GlobalResourceLoader, for now, just use
			// the ObjectDefinitionResolver
			ActionTakenEvent actionTaken = (ActionTakenEvent) ObjectDefinitionResolver.createObject(actionDefinition, ClassLoaderUtils.getDefaultClassLoader(), false);
			if (actionTaken == null) {
				// TODO the exception handling here is a bit wonky
				throw new ResourceUnavailableException("Could not locate action taken class '" + actionClassName + "'");
			}
			return actionTaken;
catch (Exception e) {
            .debug("createAction() Exception thrown while working with action class name '" + actionClassName + "'");
			if (e instanceof ResourceUnavailableException) {
			}
		}
	}
    	try {
    		org.kuali.rice.kew.api.action.ValidActions.Builder builder = org.kuali.rice.kew.api.action.ValidActions.Builder.create();
    		List<ActionRequestValueactiveRequests = new ArrayList<ActionRequestValue>();
            // this looks like ActionRequestServiceImpl.findAllPendingRequests
    		for ( ActionRequestValue ar : document.getActionRequests() ) {
    			if ( (ar.getCurrentIndicator() != null && ar.getCurrentIndicator()) && StringUtils.equalsar.getStatus(), ..getCode() ) ) {
    				activeRequests.add(ar);
    			}
    		}
    		for (String actionTakenCode : .keySet())
    		{
    			List<DataDefinitionparameters = new ArrayList<DataDefinition>();
    			parameters.add(new DataDefinition(document));
    			parameters.add(new DataDefinition(principal));
    			ActionTakenEvent actionEvent = createAction(actionTakenCodeparameters);
    			if (StringUtils.isEmpty(actionEvent.validateActionRules(activeRequests)))
    			{
    				builder.addValidAction(ActionType.fromCode(actionTakenCode));
    			}
    		}
    		return builder.build();
    	} catch (ResourceUnavailableException e) {
    		throw new WorkflowRuntimeException(e);
    	}
    }
New to GrepCode? Check out our FAQ X