001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.hivemind.schema.rules; 016 017 import org.apache.hivemind.Element; 018 import org.apache.hivemind.schema.SchemaProcessor; 019 import org.apache.hivemind.schema.Translator; 020 021 /** 022 * A rule that reads an attribute, passes it through a translator, then pushes the result onto the 023 * processor stack. 024 * 025 * @author Howard Lewis Ship 026 */ 027 public class PushAttributeRule extends BaseRule 028 { 029 private String _attributeName; 030 031 /** 032 * Uses the translator to convert the specified attribute into an object and pushes that object 033 * onto the processor stack. 034 */ 035 public void begin(SchemaProcessor processor, Element element) 036 { 037 Translator t = processor.getAttributeTranslator(_attributeName); 038 039 String attributeValue = element.getAttributeValue(_attributeName); 040 String value = RuleUtils.processText(processor, element, attributeValue); 041 042 Object finalValue = t.translate( 043 processor.getContributingModule(), 044 Object.class, 045 value, 046 element.getLocation()); 047 048 processor.push(finalValue); 049 } 050 051 /** 052 * Invokes {@link SchemaProcessor#pop()}. 053 */ 054 public void end(SchemaProcessor processor, Element element) 055 { 056 processor.pop(); 057 } 058 059 public void setAttributeName(String string) 060 { 061 _attributeName = string; 062 } 063 064 public String getAttributeName() 065 { 066 return _attributeName; 067 } 068 069 }