001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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     */
016    package org.kuali.rice.kew.engine.node.var.schemes;
017    
018    import org.apache.log4j.Logger;
019    import org.kuali.rice.kew.engine.RouteContext;
020    import org.kuali.rice.kew.engine.node.BranchState;
021    import org.kuali.rice.kew.engine.node.service.BranchService;
022    import org.kuali.rice.kew.engine.node.var.Property;
023    import org.kuali.rice.kew.engine.node.var.PropertyScheme;
024    import org.kuali.rice.kew.service.KEWServiceLocator;
025    
026    
027    /**
028     * A property scheme that looks the property up in the state variable map
029     * 
030     * @author Kuali Rice Team (rice.collab@kuali.org)
031     */
032    public final class VariableScheme implements PropertyScheme {
033        private static final Logger LOG = Logger.getLogger(VariableScheme.class);
034    
035        public String getName() {
036            return "variable";
037        }
038        public String getShortName() {
039            return "var";
040        }
041    
042        public Object load(Property property, RouteContext context) {
043    //        try {
044    //            return PropertyUtils.getProperty(doc.getVariables(), property.locator);
045                LOG.debug("getting variable: " + property.locator);
046                BranchService branchService = KEWServiceLocator.getBranchService();
047                String value = branchService.getScopedVariableValue(context.getNodeInstance().getBranch(), BranchState.VARIABLE_PREFIX + property.locator);
048                LOG.debug("variable '" + property.locator + "': " + value);
049                return value;
050    
051    //        } catch (NoSuchMethodException nsme) {
052    //            throw new RuntimeException("Error loading resource: " + property.locator, nsme);
053    //        } catch (InvocationTargetException ite) {
054    //            throw new RuntimeException("Error loading resource: " + property.locator, ite);
055    //        } catch (IllegalAccessException iae) {
056    //            throw new RuntimeException("Error loading resource: " + property.locator, iae);
057    //        }
058        }
059    
060        public String toString() {
061            return "[VariableScheme]";
062        }
063    }