001 // Copyright 2006 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.internal.parser;
016
017 import org.apache.tapestry5.ioc.Location;
018
019 /**
020 * Stores an attribute/value pair (as part of an XML element).
021 */
022 public class AttributeToken extends TemplateToken
023 {
024 private final String namespaceURI;
025
026 private final String name;
027
028 private final String value;
029
030 public AttributeToken(String namespaceURI, String name, String value, Location location)
031 {
032 super(TokenType.ATTRIBUTE, location);
033
034 this.namespaceURI = namespaceURI;
035 this.name = name;
036 this.value = value;
037 }
038
039 /**
040 * Returns local name for the attribute.
041 */
042 public String getName()
043 {
044 return name;
045 }
046
047 /**
048 * Returns the value for the attribute.
049 */
050 public String getValue()
051 {
052 return value;
053 }
054
055 /**
056 * Returns the namespace URI containing the attribute, or the empty string for the default namespace.
057 */
058 public String getNamespaceURI()
059 {
060 return namespaceURI;
061 }
062
063 @Override
064 public String toString()
065 {
066 StringBuilder builder = new StringBuilder("Attribute[");
067
068 if (namespaceURI.length() > 0) builder.append(namespaceURI).append(" ");
069
070 builder.append(name).append("=").append(value).append("]");
071
072 return builder.toString();
073 }
074 }