1. /*
  2. * Copyright 2000-2002,2004 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. package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
  18. import java.io.DataInputStream;
  19. import java.io.IOException;
  20. /**
  21. * The constant pool entry which stores class information.
  22. *
  23. */
  24. public class ClassCPInfo extends ConstantPoolEntry {
  25. /**
  26. * The class' name. This will be only valid if the entry has been
  27. * resolved against the constant pool.
  28. */
  29. private String className;
  30. /**
  31. * The index into the constant pool where this class' name is stored. If
  32. * the class name is changed, this entry is invalid until this entry is
  33. * connected to a constant pool.
  34. */
  35. private int index;
  36. /**
  37. * Constructor. Sets the tag value for this entry to type Class
  38. */
  39. public ClassCPInfo() {
  40. super(CONSTANT_CLASS, 1);
  41. }
  42. /**
  43. * Read the entry from a stream.
  44. *
  45. * @param cpStream the stream containing the constant pool entry to be
  46. * read.
  47. * @exception IOException thrown if there is a problem reading the entry
  48. * from the stream.
  49. */
  50. public void read(DataInputStream cpStream) throws IOException {
  51. index = cpStream.readUnsignedShort();
  52. className = "unresolved";
  53. }
  54. /**
  55. * Generate a string readable version of this entry
  56. *
  57. * @return string representation of this constant pool entry
  58. */
  59. public String toString() {
  60. return "Class Constant Pool Entry for " + className + "[" + index + "]";
  61. }
  62. /**
  63. * Resolve this class info against the given constant pool.
  64. *
  65. * @param constantPool the constant pool with which to resolve the
  66. * class.
  67. */
  68. public void resolve(ConstantPool constantPool) {
  69. className = ((Utf8CPInfo) constantPool.getEntry(index)).getValue();
  70. super.resolve(constantPool);
  71. }
  72. /**
  73. * Get the class name of this entry.
  74. *
  75. * @return the class' name.
  76. */
  77. public String getClassName() {
  78. return className;
  79. }
  80. }