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