View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.commons.compress.harmony.unpack200.bytecode;
20  
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  /**
25   * Signature class file attribute
26   */
27  public class SignatureAttribute extends Attribute {
28  
29      private static CPUTF8 attributeName;
30  
31      public static void setAttributeName(final CPUTF8 cpUTF8Value) {
32          attributeName = cpUTF8Value;
33      }
34  
35      private int signatureIndex;
36  
37      private final CPUTF8 signature;
38  
39      public SignatureAttribute(final CPUTF8 value) {
40          super(attributeName);
41          this.signature = value;
42      }
43  
44      /*
45       * (non-Javadoc)
46       *
47       * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#getLength()
48       */
49      @Override
50      protected int getLength() {
51          return 2;
52      }
53  
54      @Override
55      protected ClassFileEntry[] getNestedClassFileEntries() {
56          return new ClassFileEntry[] { getAttributeName(), signature };
57      }
58  
59      @Override
60      protected void resolve(final ClassConstantPool pool) {
61          super.resolve(pool);
62          signature.resolve(pool);
63          signatureIndex = pool.indexOf(signature);
64      }
65  
66      /*
67       * (non-Javadoc)
68       *
69       * @see org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry#toString()
70       */
71      @Override
72      public String toString() {
73          // TODO Auto-generated method stub
74          return "Signature: " + signature;
75      }
76  
77      /*
78       * (non-Javadoc)
79       *
80       * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#writeBody(java.io.DataOutputStream)
81       */
82      @Override
83      protected void writeBody(final DataOutputStream dos) throws IOException {
84          dos.writeShort(signatureIndex);
85      }
86  
87  }