001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.compress.harmony.unpack200.bytecode; 018 019import java.io.DataOutputStream; 020import java.io.IOException; 021 022/** 023 * Signature class file attribute 024 */ 025public class SignatureAttribute extends Attribute { 026 027 private static CPUTF8 attributeName; 028 public static void setAttributeName(final CPUTF8 cpUTF8Value) { 029 attributeName = cpUTF8Value; 030 } 031 032 private int signatureIndex; 033 034 private final CPUTF8 signature; 035 036 public SignatureAttribute(final CPUTF8 value) { 037 super(attributeName); 038 this.signature = value; 039 } 040 041 /* 042 * (non-Javadoc) 043 * 044 * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#getLength() 045 */ 046 @Override 047 protected int getLength() { 048 return 2; 049 } 050 051 @Override 052 protected ClassFileEntry[] getNestedClassFileEntries() { 053 return new ClassFileEntry[] {getAttributeName(), signature}; 054 } 055 056 @Override 057 protected void resolve(final ClassConstantPool pool) { 058 super.resolve(pool); 059 signature.resolve(pool); 060 signatureIndex = pool.indexOf(signature); 061 } 062 063 /* 064 * (non-Javadoc) 065 * 066 * @see org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry#toString() 067 */ 068 @Override 069 public String toString() { 070 // TODO Auto-generated method stub 071 return "Signature: " + signature; 072 } 073 074 /* 075 * (non-Javadoc) 076 * 077 * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#writeBody(java.io.DataOutputStream) 078 */ 079 @Override 080 protected void writeBody(final DataOutputStream dos) throws IOException { 081 dos.writeShort(signatureIndex); 082 } 083 084}