001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.opensource.org/licenses/ecl2.php
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.kuali.rice.kew.engine.node.var.schemes;
019
020 import org.apache.log4j.Logger;
021 import org.kuali.rice.kew.engine.RouteContext;
022 import org.kuali.rice.kew.engine.node.BranchState;
023 import org.kuali.rice.kew.engine.node.service.BranchService;
024 import org.kuali.rice.kew.engine.node.var.Property;
025 import org.kuali.rice.kew.engine.node.var.PropertyScheme;
026 import org.kuali.rice.kew.service.KEWServiceLocator;
027
028
029 /**
030 * A property scheme that looks the property up in the state variable map
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034 public final class VariableScheme implements PropertyScheme {
035 private static final Logger LOG = Logger.getLogger(VariableScheme.class);
036
037 public String getName() {
038 return "variable";
039 }
040 public String getShortName() {
041 return "var";
042 }
043
044 public Object load(Property property, RouteContext context) {
045 // try {
046 // return PropertyUtils.getProperty(doc.getVariables(), property.locator);
047 LOG.debug("getting variable: " + property.locator);
048 BranchService branchService = KEWServiceLocator.getBranchService();
049 String value = branchService.getScopedVariableValue(context.getNodeInstance().getBranch(), BranchState.VARIABLE_PREFIX + property.locator);
050 LOG.debug("variable '" + property.locator + "': " + value);
051 return value;
052
053 // } catch (NoSuchMethodException nsme) {
054 // throw new RuntimeException("Error loading resource: " + property.locator, nsme);
055 // } catch (InvocationTargetException ite) {
056 // throw new RuntimeException("Error loading resource: " + property.locator, ite);
057 // } catch (IllegalAccessException iae) {
058 // throw new RuntimeException("Error loading resource: " + property.locator, iae);
059 // }
060 }
061
062 public String toString() {
063 return "[VariableScheme]";
064 }
065 }