| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| StartComponentToken |
|
| 0.0;0 |
| 1 | // Copyright 2006, 2007 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.tapestry5.internal.parser; | |
| 16 | ||
| 17 | import org.apache.tapestry5.ioc.Location; | |
| 18 | ||
| 19 | /** | |
| 20 | * The start element of a component within the template. Will be followed by a series of {@link | |
| 21 | * org.apache.tapestry5.internal.parser.AttributeToken}s for any attributes (outside of id and type), and eventually | |
| 22 | * will be balanced by an {@link org.apache.tapestry5.internal.parser.EndElementToken}. | |
| 23 | */ | |
| 24 | public class StartComponentToken extends TemplateToken | |
| 25 | { | |
| 26 | private final String elementName; | |
| 27 | ||
| 28 | private final String id; | |
| 29 | ||
| 30 | private final String componentType; | |
| 31 | ||
| 32 | private final String mixins; | |
| 33 | ||
| 34 | /** | |
| 35 | * @param elementName the name of the element from which this component was parsed, or null if the element was the | |
| 36 | * t:comp placeholder | |
| 37 | * @param id the id of the component (may be null for anonymous components) | |
| 38 | * @param type the type of component (may be null if the component type is specified outside the template) | |
| 39 | * @param mixins a comma-separated list of mixins (possibly null) | |
| 40 | * @param location the location within the template at which the element was parsed | |
| 41 | */ | |
| 42 | public StartComponentToken(String elementName, String id, String type, String mixins, | |
| 43 | Location location) | |
| 44 | { | |
| 45 | 1570 | super(TokenType.START_COMPONENT, location); |
| 46 | ||
| 47 | // TODO: id or type may be null, but not both! | |
| 48 | ||
| 49 | 1570 | this.elementName = elementName; |
| 50 | 1570 | this.id = id; |
| 51 | 1570 | componentType = type; |
| 52 | 1570 | this.mixins = mixins; |
| 53 | 1570 | } |
| 54 | ||
| 55 | /** | |
| 56 | * Returns the element for this component. When using the <t:comp> placeholder, this value will be null. When | |
| 57 | * using "invisible instrumentation", where t:id or t:type attributes are added to existing elements, this is the | |
| 58 | * local name of the element so attached. | |
| 59 | * | |
| 60 | * @return the element name or null | |
| 61 | */ | |
| 62 | public String getElementName() | |
| 63 | { | |
| 64 | 1668 | return elementName; |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Returns a non-blank id if one was provided in the template. If the id attribute was missing (or the value was | |
| 69 | * blank), returns null. | |
| 70 | */ | |
| 71 | public String getId() | |
| 72 | { | |
| 73 | 1672 | return id; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Returns a non-blank component type if one was provided in the template. If the type attribute was missing (or the | |
| 78 | * value was blank), returns null. | |
| 79 | */ | |
| 80 | public String getComponentType() | |
| 81 | { | |
| 82 | 1678 | return componentType; |
| 83 | } | |
| 84 | ||
| 85 | @Override | |
| 86 | public String toString() | |
| 87 | { | |
| 88 | 0 | StringBuilder builder = new StringBuilder(); |
| 89 | ||
| 90 | 0 | add(builder, "element", elementName); |
| 91 | 0 | add(builder, "id", id); |
| 92 | 0 | add(builder, "type", componentType); |
| 93 | 0 | add(builder, "mixins", mixins); |
| 94 | ||
| 95 | 0 | builder.insert(0, "StartComponentToken["); |
| 96 | 0 | builder.append("]"); |
| 97 | ||
| 98 | 0 | return builder.toString(); |
| 99 | } | |
| 100 | ||
| 101 | private void add(StringBuilder builder, String label, String value) | |
| 102 | { | |
| 103 | 0 | if (value == null) |
| 104 | 0 | return; |
| 105 | ||
| 106 | 0 | if (builder.length() > 0) |
| 107 | 0 | builder.append(" "); |
| 108 | ||
| 109 | 0 | builder.append(label); |
| 110 | 0 | builder.append("="); |
| 111 | 0 | builder.append(value); |
| 112 | 0 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Returns the list of mixins for this component instance, or null for no mixins. | |
| 116 | */ | |
| 117 | public String getMixins() | |
| 118 | { | |
| 119 | 1666 | return mixins; |
| 120 | } | |
| 121 | ||
| 122 | } |