KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > parse > OpenToken


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.tapestry.parse;
16
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.util.ToStringBuilder;
22
23 /**
24  * Token representing the open tag for a component. Components may be either specified or implicit.
25  * Specified components (the traditional type, dating back to the origin of Tapestry) are matched by
26  * an entry in the containing component's specification. Implicit components specify their type in
27  * the component template and must not have an entry in the containing component's specification.
28  *
29  * @see TokenType#OPEN
30  * @author Howard Lewis Ship
31  * @since 3.0
32  */

33
34 public class OpenToken extends TemplateToken
35 {
36     private String JavaDoc _tag;
37
38     private String JavaDoc _id;
39
40     private String JavaDoc _componentType;
41
42     private Map JavaDoc _attributes;
43
44     /**
45      * Creates a new token with the given tag, id and type
46      *
47      * @param tag
48      * the template tag which represents the component, typically "span"
49      * @param id
50      * the id for the component, which may be assigned by the template parser for
51      * implicit components
52      * @param componentType
53      * the type of component, if an implicit component, or null for a specified component
54      * @param location
55      * location of tag represented by this token
56      */

57
58     public OpenToken(String JavaDoc tag, String JavaDoc id, String JavaDoc componentType, Location location)
59     {
60         super(TokenType.OPEN, location);
61
62         _tag = tag;
63         _id = id;
64         _componentType = componentType;
65     }
66
67     /**
68      * Returns the id for the component.
69      */

70
71     public String JavaDoc getId()
72     {
73         return _id;
74     }
75
76     /**
77      * Returns the tag used to represent the component within the template.
78      */

79
80     public String JavaDoc getTag()
81     {
82         return _tag;
83     }
84
85     /**
86      * Returns the specified component type, or null for a component where the type is not defined
87      * in the template. The type may include a library id prefix.
88      */

89
90     public String JavaDoc getComponentType()
91     {
92         return _componentType;
93     }
94
95     public void addAttribute(String JavaDoc name, String JavaDoc value)
96     {
97         if (_attributes == null)
98             _attributes = new HashMap JavaDoc();
99
100         _attributes.put(name, value);
101     }
102
103     /**
104      * Returns a Map of attributes. Keys and values are strings.
105      */

106
107     public Map JavaDoc getAttributesMap()
108     {
109         return _attributes;
110     }
111
112     protected void extendDescription(ToStringBuilder builder)
113     {
114         builder.append("id", _id);
115         builder.append("componentType", _componentType);
116         builder.append("tag", _tag);
117         builder.append("attributes", _attributes);
118     }
119
120 }
Popular Tags