KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > jcd > cls > attribute > GenericAttribute_info


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: GenericAttribute_info.java,v 1.1.1.1 2004/05/09 16:57:48 vlad_r Exp $
8  */

9 package com.vladium.jcd.cls.attribute;
10
11 import java.io.IOException JavaDoc;
12
13 import com.vladium.jcd.lib.UDataInputStream;
14 import com.vladium.jcd.lib.UDataOutputStream;
15
16 // ----------------------------------------------------------------------------
17
/**
18  * This attribute structure is used during parsing to absorb all attribute types
19  * that are not currently recognized.
20  *
21  * @see Attribute_info
22  *
23  * @author (C) 2001, Vlad Roubtsov
24  */

25 public
26 final class GenericAttribute_info extends Attribute_info
27 {
28     // public: ................................................................
29

30     
31     public byte [] m_info;
32     
33     
34     public GenericAttribute_info (final int attribute_name_index, final byte [] info)
35     {
36         super (attribute_name_index, (info != null ? info.length : 0));
37         
38         m_info = (info != null ? info : EMPTY_BYTE_ARRAY);
39     }
40     
41     
42     public long length ()
43     {
44         return 6 + m_info.length;
45     }
46     
47     // Visitor:
48

49     public void accept (final IAttributeVisitor visitor, final Object JavaDoc ctx)
50     {
51         visitor.visit (this, ctx);
52     }
53     
54     public String JavaDoc toString ()
55     {
56         return "generic attribute_info: [attribute_name_index = " + m_name_index + ", attribute_length = " + m_attribute_length + ']';
57     }
58     
59     // Cloneable:
60

61     /**
62      * Performs a deep copy.
63      */

64     public Object JavaDoc clone ()
65     {
66         final GenericAttribute_info _clone = (GenericAttribute_info) super.clone ();
67         
68         // do deep copy:
69
_clone.m_info = (m_info.length == 0 ? EMPTY_BYTE_ARRAY : (byte []) m_info.clone ());
70         
71         return _clone;
72     }
73     
74     // IClassFormatOutput:
75

76     public void writeInClassFormat (final UDataOutputStream out) throws IOException JavaDoc
77     {
78         super.writeInClassFormat (out);
79         
80         out.write (m_info, 0, m_info.length);
81     }
82     
83     // protected: .............................................................
84

85     // package: ...............................................................
86

87
88     GenericAttribute_info (final int attribute_name_index, final long attribute_length,
89                            final UDataInputStream bytes)
90         throws IOException JavaDoc
91     {
92         super (attribute_name_index, attribute_length);
93         
94         m_info = new byte [(int) m_attribute_length];
95         bytes.readFully (m_info);
96     }
97
98     // private: ...............................................................
99

100     
101     private static final byte [] EMPTY_BYTE_ARRAY = new byte [0];
102
103 } // end of class
104
// ----------------------------------------------------------------------------
105
Popular Tags