KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > Tag


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
21 package org.apache.directory.ldapstudio.dsmlv2;
22
23
24 /**
25  * This class represents a XML tag.
26  * A XML tag is defined with :
27  * <ul>
28  * <li>a name</li>
29  * <li>a type (START tag or END tag)</li>
30  * </ul>
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev$, $Date$
34  */

35 public class Tag
36 {
37     /** The name of the tag */
38     private String JavaDoc name;
39
40     /** The type of the tag */
41     private int type;
42
43     /** This int represents a START tag */
44     public static int START = 0;
45
46     /** This int represents a END tag */
47     public static int END = 1;
48
49
50     /**
51      * Creates a new instance of Tag.
52      *
53      * @param name
54      * the name of the tag
55      * @param type
56      * the type of the tag
57      */

58     public Tag( String JavaDoc name, int type )
59     {
60         setName( name );
61         setType( type );
62     }
63
64
65     /**
66      * Gets the name of the tag
67      *
68      * @return
69      * the name of the tag
70      */

71     public String JavaDoc getName()
72     {
73         return name;
74     }
75
76
77     /**
78      * Sets the name of the tag
79      *
80      * @param name
81      * the name to set
82      */

83     public void setName( String JavaDoc name )
84     {
85         this.name = name.toLowerCase();
86     }
87
88
89     /**
90      * Gets the type of the tag
91      *
92      * @return
93      * the type of the tag
94      */

95     public int getType()
96     {
97         return type;
98     }
99
100
101     /**
102      * Sets the type of the tag
103      *
104      * @param type
105      * the type to set
106      */

107     public void setType( int type )
108     {
109         this.type = type;
110     }
111
112
113     /* (non-Javadoc)
114      * @see java.lang.Object#equals(java.lang.Object)
115      */

116     @Override JavaDoc
117     public boolean equals( Object JavaDoc obj )
118     {
119         if ( obj instanceof Tag )
120         {
121             Tag tag = ( Tag ) obj;
122             return ( ( this.name.equals( tag.getName() ) ) && ( this.type == tag.getType() ) );
123
124         }
125         else
126         {
127             return false;
128         }
129     }
130
131
132     /* (non-Javadoc)
133      * @see java.lang.Object#hashCode()
134      */

135     @Override JavaDoc
136     public int hashCode()
137     {
138         return name.hashCode() + type << 24;
139     }
140
141
142     /* (non-Javadoc)
143      * @see java.lang.Object#toString()
144      */

145     @Override JavaDoc
146     public String JavaDoc toString()
147     {
148         if ( name != null )
149         {
150             return "<" + ( ( type == Tag.END ) ? "/" : "" ) + name + ">";
151         }
152         else
153         {
154             return "Unknown tag";
155         }
156     }
157 }
158
Popular Tags