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