001/* 002 * Copyright 2014 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.workspaces.workflow; 017 018import java.util.Map; 019 020import org.ametys.plugins.explorer.ExplorerNode; 021import org.ametys.plugins.workflow.AbstractWorkflowComponent; 022 023import com.opensymphony.workflow.WorkflowException; 024 025/** 026 * Abstract class for easily retrieving environment components 027 * in a condition or a function and especially a resource. 028 */ 029public abstract class AbstractNodeWorkflowComponent extends AbstractWorkflowComponent 030{ 031 /** Constant for storing the content into the transient variables map. */ 032 public static final String EXPLORERNODE_KEY = ExplorerNode.class.getName(); 033 034 /** 035 * Retrieve the resource associated with the workflow. 036 * @param transientVars the parameters from the call. 037 * @return the resource. 038 * @throws WorkflowException if the resource is not found. 039 */ 040 protected ExplorerNode getExplorerNode(Map transientVars) throws WorkflowException 041 { 042 ExplorerNode explorerNode = (ExplorerNode) transientVars.get(AbstractNodeWorkflowComponent.EXPLORERNODE_KEY); 043 044 if (explorerNode == null) 045 { 046 throw new WorkflowException("Unable to retrieve explorer node"); 047 } 048 049 // Found in transient variables map 050 return explorerNode; 051 } 052 053}