KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > schema > rules > PushAttributeRule


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 JavaDoc _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         String JavaDoc attributeValue = element.getAttributeValue(_attributeName);
38
39         if (attributeValue == null)
40             attributeValue = processor.getAttributeDefault(_attributeName);
41
42         String JavaDoc value = RuleUtils.processText(processor, element, attributeValue);
43
44         Translator t = processor.getAttributeTranslator(_attributeName);
45
46         Object JavaDoc finalValue = t.translate(
47                 processor.getContributingModule(),
48                 Object JavaDoc.class,
49                 value,
50                 element.getLocation());
51
52         processor.push(finalValue);
53     }
54
55     /**
56      * Invokes {@link SchemaProcessor#pop()}.
57      */

58     public void end(SchemaProcessor processor, Element element)
59     {
60         processor.pop();
61     }
62
63     public void setAttributeName(String JavaDoc string)
64     {
65         _attributeName = string;
66     }
67
68     public String JavaDoc getAttributeName()
69     {
70         return _attributeName;
71     }
72
73 }
74
Popular Tags