    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 int signature_index;
    028    private final CPUTF8 signature;
    029
    030    private static CPUTF8 attributeName;
    031
    032    public static void setAttributeName(final CPUTF8 cpUTF8Value) {
    033        attributeName = cpUTF8Value;
    034    }
    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        signature_index = pool.indexOf(signature);
    061    }
    062
    063    /*
    064     * (non-Javadoc)
    065     *
    066     * @see org.apache.commons.compress.harmony.unpack200.bytecode.Attribute#writeBody(java.io.DataOutputStream)
    067     */
    068    @Override
    069    protected void writeBody(final DataOutputStream dos) throws IOException {
    070        dos.writeShort(signature_index);
    071    }
    072
    073    /*
    074     * (non-Javadoc)
    075     *
    076     * @see org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry#toString()
    077     */
    078    @Override
    079    public String toString() {
    080        // TODO Auto-generated method stub
    081        return "Signature: " + signature;
    082    }
    083
    084}