KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > elementvalues > ElementValuePair


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7 package org.gjt.jclasslib.structures.elementvalues;
8
9 import org.gjt.jclasslib.structures.*;
10
11 import java.io.*;
12
13 /**
14  * Describes an <tt>ElementValuePair</tt> attribute structure.
15  *
16  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
17  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:32 $
18  */

19 public class ElementValuePair extends AbstractStructure {
20
21     public final static String JavaDoc ENTRY_NAME = "ElementValuePair";
22
23     private static final int INITIAL_LENGTH = 2;
24
25     private int elementNameIndex;
26     private ElementValue elementValue;
27
28
29     /**
30      * Factory for creating <tt>ElementValuePair</tt> structures.
31      *
32      * @param in the <tt>DataInput</tt> from which to read the
33      * <tt>ElementValuePair</tt> structure
34      * @param classFile the parent class file of the structure to be created
35      * @return the new <tt>ElementValue</tt> structure
36      * @throws org.gjt.jclasslib.structures.InvalidByteCodeException
37      * if the byte code is invalid
38      * @throws java.io.IOException if an exception occurs with the <tt>DataInput</tt>
39      */

40     public static ElementValuePair create(DataInput in, ClassFile classFile)
41             throws InvalidByteCodeException, IOException {
42
43         ElementValuePair elementValuePairEntry = new ElementValuePair();
44         elementValuePairEntry.setClassFile(classFile);
45         elementValuePairEntry.read(in);
46
47         return elementValuePairEntry;
48     }
49
50
51     /**
52      * Get the <tt>element_value</tt> of this element value pair.
53      *
54      * @return the <tt>element_value</tt>
55      */

56     public ElementValue getElementValue() {
57         return this.elementValue;
58     }
59
60     /**
61      * Set the <tt>element_value</tt> of this element value pair.
62      *
63      * @param elementValue the <tt>element_value</tt>
64      */

65     public void setElementValue(ElementValue elementValue) {
66         this.elementValue = elementValue;
67     }
68
69     /**
70      * Get the <tt>element_name_index</tt> of this element value pair.
71      *
72      * @return the <tt>element_name_index</tt>
73      */

74     public int getElementNameIndex() {
75         return elementNameIndex;
76     }
77
78     /**
79      * Set the <tt>element_name_index</tt> of this element value pair.
80      *
81      * @param elementNameIndex the <tt>element_name_index</tt>
82      */

83     public void setElementNameIndex(int elementNameIndex) {
84         this.elementNameIndex = elementNameIndex;
85     }
86
87     public void read(DataInput in) throws InvalidByteCodeException, IOException {
88         super.read(in);
89
90         elementNameIndex = in.readUnsignedShort();
91         elementValue = ElementValue.create(in, classFile);
92
93         if (debug) debug("read ");
94     }
95
96     public void write(DataOutput out) throws InvalidByteCodeException, IOException {
97         super.write(out);
98
99         out.writeShort(elementNameIndex);
100         elementValue.write(out);
101
102         if (debug) debug("wrote ");
103     }
104
105
106     protected String JavaDoc printAccessFlagsVerbose(int accessFlags) {
107         if (accessFlags != 0)
108             throw new RuntimeException JavaDoc("Access flags should be zero: " +
109                     Integer.toHexString(accessFlags));
110         return "";
111     }
112
113     protected int getLength() {
114         return INITIAL_LENGTH + elementValue.getLength();
115     }
116
117     public String JavaDoc getEntryName() {
118         return ENTRY_NAME;
119     }
120 }
121
Popular Tags