    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;
    021import java.util.ArrayList;
    022import java.util.List;
    023
    024/**
    025 * AnnotationDefault class file attribute
    026 */
    027public class AnnotationDefaultAttribute extends AnnotationsAttribute {
    028
    029    private final ElementValue element_value;
    030
    031    private static CPUTF8 attributeName;
    032
    033    public static void setAttributeName(final CPUTF8 cpUTF8Value) {
    034        attributeName = cpUTF8Value;
    035    }
    036
    037    public AnnotationDefaultAttribute(final ElementValue element_value) {
    038        super(attributeName);
    039        this.element_value = element_value;
    040    }
    041
    042    @Override
    043    protected int getLength() {
    044        return element_value.getLength();
    045    }
    046
    047    @Override
    048    protected void writeBody(final DataOutputStream dos) throws IOException {
    049        element_value.writeBody(dos);
    050    }
    051
    052    @Override
    053    protected void resolve(final ClassConstantPool pool) {
    054        super.resolve(pool);
    055        element_value.resolve(pool);
    056    }
    057
    058    @Override
    059    public String toString() {
    060        return "AnnotationDefault: " + element_value;
    061    }
    062
    063    @Override
    064    public boolean equals(final Object obj) {
    065        return this == obj;
    066    }
    067
    068    @Override
    069    protected ClassFileEntry[] getNestedClassFileEntries() {
    070        final List nested = new ArrayList();
    071        nested.add(attributeName);
    072        nested.addAll(element_value.getClassFileEntries());
    073        final ClassFileEntry[] nestedEntries = new ClassFileEntry[nested.size()];
    074        for (int i = 0; i < nestedEntries.length; i++) {
    075            nestedEntries[i] = (ClassFileEntry) nested.get(i);
    076        }
    077        return nestedEntries;
    078    }
    079
    080}