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
029    public static void setAttributeName(final CPUTF8 cpUTF8Value) {
030        attributeName = cpUTF8Value;
031    }
032
033    private int signatureIndex;
034
035    private final CPUTF8 signature;
036
037    public SignatureAttribute(final CPUTF8 value) {
038        super(attributeName);
039        this.signature = value;
040    }
041
042    /*
043     * (non-Javadoc)
044     *
045     * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#getLength()
046     */
047    @Override
048    protected int getLength() {
049        return 2;
050    }
051
052    @Override
053    protected ClassFileEntry[] getNestedClassFileEntries() {
054        return new ClassFileEntry[] { getAttributeName(), signature };
055    }
056
057    @Override
058    protected void resolve(final ClassConstantPool pool) {
059        super.resolve(pool);
060        signature.resolve(pool);
061        signatureIndex = pool.indexOf(signature);
062    }
063
064    /*
065     * (non-Javadoc)
066     *
067     * @see org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry#toString()
068     */
069    @Override
070    public String toString() {
071        // TODO Auto-generated method stub
072        return "Signature: " + signature;
073    }
074
075    /*
076     * (non-Javadoc)
077     *
078     * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#writeBody(java.io.DataOutputStream)
079     */
080    @Override
081    protected void writeBody(final DataOutputStream dos) throws IOException {
082        dos.writeShort(signatureIndex);
083    }
084
085}