Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OpenToken |
|
| 1.1428571428571428;1.143 |
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; | |
18 | import java.util.Map; | |
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 _tag; | |
37 | ||
38 | private String _id; | |
39 | ||
40 | private String _componentType; | |
41 | ||
42 | private Map _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 tag, String id, String componentType, Location location) | |
59 | { | |
60 | 0 | super(TokenType.OPEN, location); |
61 | ||
62 | 0 | _tag = tag; |
63 | 0 | _id = id; |
64 | 0 | _componentType = componentType; |
65 | 0 | } |
66 | ||
67 | /** | |
68 | * Returns the id for the component. | |
69 | */ | |
70 | ||
71 | public String getId() | |
72 | { | |
73 | 0 | return _id; |
74 | } | |
75 | ||
76 | /** | |
77 | * Returns the tag used to represent the component within the template. | |
78 | */ | |
79 | ||
80 | public String getTag() | |
81 | { | |
82 | 0 | 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 getComponentType() | |
91 | { | |
92 | 0 | return _componentType; |
93 | } | |
94 | ||
95 | public void addAttribute(String name, String value) | |
96 | { | |
97 | 0 | if (_attributes == null) |
98 | 0 | _attributes = new HashMap(); |
99 | ||
100 | 0 | _attributes.put(name, value); |
101 | 0 | } |
102 | ||
103 | /** | |
104 | * Returns a Map of attributes. Keys and values are strings. | |
105 | */ | |
106 | ||
107 | public Map getAttributesMap() | |
108 | { | |
109 | 0 | return _attributes; |
110 | } | |
111 | ||
112 | protected void extendDescription(ToStringBuilder builder) | |
113 | { | |
114 | 0 | builder.append("id", _id); |
115 | 0 | builder.append("componentType", _componentType); |
116 | 0 | builder.append("tag", _tag); |
117 | 0 | builder.append("attributes", _attributes); |
118 | 0 | } |
119 | ||
120 | } |