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