View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.jdo.impl.enhancer.classfile;
19  
20  import java.io.*;
21  import java.util.Stack;
22  
23  /***
24   * Class representing a utf8 string value in the constant pool
25   */
26  public class ConstUtf8 extends ConstBasic {
27      /* The tag associated with ConstClass entries */
28      public static final int MyTag = CONSTANTUtf8;
29   
30      /* The unicode string of interest */
31      private String stringValue;
32  
33      /* public accessors */
34  
35      /***
36       * The tag of this constant entry
37       */
38      public int tag () { return MyTag; }
39  
40      /***
41       * return the value associated with the entry
42       */
43      public String asString () {
44          return stringValue;
45      }
46  
47      /***
48       * A printable representation
49       */
50      public String toString () {
51          return "CONSTANTUtf8(" + indexAsString() + "): " + asString();
52      }
53  
54      /***
55       * Compares this instance with another for structural equality.
56       */
57      //@olsen: added method
58      public boolean isEqual(Stack msg, Object obj) {
59          if (!(obj instanceof ConstUtf8)) {
60              msg.push("obj/obj.getClass() = "
61                       + (obj == null ? null : obj.getClass()));
62              msg.push("this.getClass() = "
63                       + this.getClass());
64              return false;
65          }
66          ConstUtf8 other = (ConstUtf8)obj;
67  
68          if (!super.isEqual(msg, other)) {
69              return false;
70          }
71  
72          if (!this.stringValue.equals(other.stringValue)) {
73              msg.push(String.valueOf("stringValue = "
74                                      + other.stringValue));
75              msg.push(String.valueOf("stringValue = "
76                                      + this.stringValue));
77              return false;
78          }
79          return true;
80      }
81  
82      /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">/* package local methods *//package-summary.html">class="comment"> package local methods */
83  
84      ConstUtf8 (String s) {
85          stringValue = s;
86      }
87  
88      void formatData (DataOutputStream b) throws IOException {
89          b.writeUTF(stringValue);
90      }
91  
92      static ConstUtf8 read (DataInputStream input) throws IOException {
93          return new ConstUtf8 (input.readUTF());
94      }
95  
96      void resolve (ConstantPool p) {
97      }
98  }
99  
100