001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.shared.dsmlv2; 021 022 023/** 024 * This class represents a XML tag. 025 * <br/> 026 * A XML tag is defined with : 027 * <ul> 028 * <li>a name</li> 029 * <li>a type (START tag or END tag)</li> 030 * </ul> 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class Tag 035{ 036 /** The name of the tag */ 037 private String name; 038 039 /** The type of the tag */ 040 private int type; 041 042 /** This int represents a START tag */ 043 public static final int START = 0; 044 045 /** This int represents a END tag */ 046 public static final int END = 1; 047 048 049 /** 050 * Creates a new instance of Tag. 051 * 052 * @param name 053 * the name of the tag 054 * @param type 055 * the type of the tag 056 */ 057 public Tag( String name, int type ) 058 { 059 setName( name ); 060 setType( type ); 061 } 062 063 064 /** 065 * Gets the name of the tag 066 * 067 * @return 068 * the name of the tag 069 */ 070 public String getName() 071 { 072 return name; 073 } 074 075 076 /** 077 * Sets the name of the tag 078 * 079 * @param name 080 * the name to set 081 */ 082 public void setName( String name ) 083 { 084 this.name = name.toLowerCase(); 085 } 086 087 088 /** 089 * Gets the type of the tag 090 * 091 * @return 092 * the type of the tag 093 */ 094 public int getType() 095 { 096 return type; 097 } 098 099 100 /** 101 * Sets the type of the tag 102 * 103 * @param type 104 * the type to set 105 */ 106 public void setType( int type ) 107 { 108 this.type = type; 109 } 110 111 112 /* (non-Javadoc) 113 * @see java.lang.Object#equals(java.lang.Object) 114 */ 115 @Override 116 public boolean equals( Object obj ) 117 { 118 if ( obj instanceof Tag ) 119 { 120 Tag tag = ( Tag ) obj; 121 return ( ( this.name.equals( tag.getName() ) ) && ( this.type == tag.getType() ) ); 122 123 } 124 else 125 { 126 return false; 127 } 128 } 129 130 131 /* (non-Javadoc) 132 * @see java.lang.Object#hashCode() 133 */ 134 @Override 135 public int hashCode() 136 { 137 return name.hashCode() + type << 24; 138 } 139 140 141 /* (non-Javadoc) 142 * @see java.lang.Object#toString() 143 */ 144 @Override 145 public String toString() 146 { 147 if ( name != null ) 148 { 149 return "<" + ( ( type == Tag.END ) ? "/" : "" ) + name + ">"; 150 } 151 else 152 { 153 return "Unknown tag"; 154 } 155 } 156}