1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.dsmlv2; 21 22 23 import org.apache.directory.api.util.Strings; 24 25 26 /** 27 * This class represents a XML tag. 28 * <br/> 29 * A XML tag is defined with : 30 * <ul> 31 * <li>a name</li> 32 * <li>a type (START tag or END tag)</li> 33 * </ul> 34 * 35 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 36 */ 37 public class Tag 38 { 39 /** The name of the tag */ 40 private String name; 41 42 /** The type of the tag */ 43 private int type; 44 45 /** This int represents a START tag */ 46 public static final int START = 0; 47 48 /** This int represents a END tag */ 49 public static final int END = 1; 50 51 52 /** 53 * Creates a new instance of Tag. 54 * 55 * @param name the name of the tag 56 * @param type the type of the tag 57 */ 58 public Tag( String name, int type ) 59 { 60 setName( name ); 61 setType( type ); 62 } 63 64 65 /** 66 * Gets the name of the tag 67 * 68 * @return the name of the tag 69 */ 70 public String getName() 71 { 72 return name; 73 } 74 75 76 /** 77 * Sets the name of the tag 78 * 79 * @param name the name to set 80 */ 81 public void setName( String name ) 82 { 83 this.name = Strings.toLowerCase( name ); 84 } 85 86 87 /** 88 * Gets the type of the tag 89 * 90 * @return the type of the tag 91 */ 92 public int getType() 93 { 94 return type; 95 } 96 97 98 /** 99 * Sets the type of the tag 100 * 101 * @param type the type to set 102 */ 103 public void setType( int type ) 104 { 105 this.type = type; 106 } 107 108 109 /** 110 * {@inheritDoc} 111 */ 112 public boolean equals( Object obj ) 113 { 114 if ( obj instanceof Tag ) 115 { 116 Tag tag = ( Tag ) obj; 117 118 return ( ( this.name.equals( tag.getName() ) ) && ( this.type == tag.getType() ) ); 119 120 } 121 else 122 { 123 return false; 124 } 125 } 126 127 128 /** 129 * {@inheritDoc} 130 */ 131 public int hashCode() 132 { 133 return name.hashCode() + type << 24; 134 } 135 136 137 /** 138 * {@inheritDoc} 139 */ 140 public String toString() 141 { 142 if ( name != null ) 143 { 144 return "<" + ( ( type == Tag.END ) ? "/" : "" ) + name + ">"; 145 } 146 else 147 { 148 return "Unknown tag"; 149 } 150 } 151 }