Source code: org/apache/hivemind/schema/rules/PushAttributeRule.java
1 // Copyright 2004, 2005 The Apache Software Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package org.apache.hivemind.schema.rules;
16
17 import org.apache.hivemind.Element;
18 import org.apache.hivemind.schema.SchemaProcessor;
19 import org.apache.hivemind.schema.Translator;
20
21 /**
22 * A rule that reads an attribute, passes it through a translator, then pushes the result onto the
23 * processor stack.
24 *
25 * @author Howard Lewis Ship
26 */
27 public class PushAttributeRule extends BaseRule
28 {
29 private String _attributeName;
30
31 /**
32 * Uses the translator to convert the specified attribute into an object and pushes that object
33 * onto the processor stack.
34 */
35 public void begin(SchemaProcessor processor, Element element)
36 {
37 Translator t = processor.getAttributeTranslator(_attributeName);
38
39 String attributeValue = element.getAttributeValue(_attributeName);
40 String value = RuleUtils.processText(processor, element, attributeValue);
41
42 Object finalValue = t.translate(
43 processor.getContributingModule(),
44 Object.class,
45 value,
46 element.getLocation());
47
48 processor.push(finalValue);
49 }
50
51 /**
52 * Invokes {@link SchemaProcessor#pop()}.
53 */
54 public void end(SchemaProcessor processor, Element element)
55 {
56 processor.pop();
57 }
58
59 public void setAttributeName(String string)
60 {
61 _attributeName = string;
62 }
63
64 public String getAttributeName()
65 {
66 return _attributeName;
67 }
68
69 }