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 unicode string value in the constant pool
25   *
26   * Note: evidence suggests that this is no longer part of the java VM
27   * spec.
28   */
29  public class ConstUnicode extends ConstBasic {
30      /* The tag associated with ConstClass entries */
31      public static final int MyTag = CONSTANTUnicode;
32   
33      /* The unicode string of interest */
34      private String stringValue;
35  
36      /* public accessors */
37  
38      /***
39       * The tag of this constant entry
40       */
41      public int tag () { return MyTag; }
42  
43      /***
44       * return the value associated with the entry
45       */
46      public String asString() {
47          return stringValue;
48      }
49  
50      /***
51       * A printable representation
52       */
53      public String toString () {
54          return "CONSTANTUnicode(" + indexAsString() + "): " + stringValue;
55      }
56  
57      /***
58       * Compares this instance with another for structural equality.
59       */
60      //@olsen: added method
61      public boolean isEqual(Stack msg, Object obj) {
62          if (!(obj instanceof ConstUnicode)) {
63              msg.push("obj/obj.getClass() = "
64                       + (obj == null ? null : obj.getClass()));
65              msg.push("this.getClass() = "
66                       + this.getClass());
67              return false;
68          }
69          ConstUnicode other = (ConstUnicode)obj;
70  
71          if (!super.isEqual(msg, other)) {
72              return false;
73          }
74  
75          if (!this.stringValue.equals(other.stringValue)) {
76              msg.push(String.valueOf("stringValue = "
77                                      + other.stringValue));
78              msg.push(String.valueOf("stringValue = "
79                                      + this.stringValue));
80              return false;
81          }
82          return true;
83      }
84  
85      /* 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 */
86  
87      ConstUnicode (String s) {
88          stringValue = s;
89      }
90  
91      void formatData (DataOutputStream b) throws IOException {
92          b.writeBytes(stringValue);
93      }
94  
95      static ConstUnicode read (DataInputStream input) throws IOException {
96          int count = input.readShort(); // Is this chars or bytes?
97          StringBuffer b = new StringBuffer();
98          for (int i=0; i < count; i++) { 
99              b.append(input.readChar());
100         }
101         return new ConstUnicode (b.toString());
102     }
103 
104     void resolve (ConstantPool p) {
105     }
106 }