View Javadoc

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