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