AttrDefinitionBands.java

  1. /*
  2.  *  Licensed to the Apache Software Foundation (ASF) under one or more
  3.  *  contributor license agreements.  See the NOTICE file distributed with
  4.  *  this work for additional information regarding copyright ownership.
  5.  *  The ASF licenses this file to You under the Apache License, Version 2.0
  6.  *  (the "License"); you may not use this file except in compliance with
  7.  *  the License.  You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.commons.compress.harmony.unpack200;

  18. import java.io.IOException;
  19. import java.io.InputStream;

  20. import org.apache.commons.compress.harmony.pack200.Codec;
  21. import org.apache.commons.compress.harmony.pack200.Pack200Exception;
  22. import org.apache.commons.compress.harmony.unpack200.bytecode.AnnotationDefaultAttribute;
  23. import org.apache.commons.compress.harmony.unpack200.bytecode.CodeAttribute;
  24. import org.apache.commons.compress.harmony.unpack200.bytecode.ConstantValueAttribute;
  25. import org.apache.commons.compress.harmony.unpack200.bytecode.DeprecatedAttribute;
  26. import org.apache.commons.compress.harmony.unpack200.bytecode.EnclosingMethodAttribute;
  27. import org.apache.commons.compress.harmony.unpack200.bytecode.ExceptionsAttribute;
  28. import org.apache.commons.compress.harmony.unpack200.bytecode.InnerClassesAttribute;
  29. import org.apache.commons.compress.harmony.unpack200.bytecode.LineNumberTableAttribute;
  30. import org.apache.commons.compress.harmony.unpack200.bytecode.LocalVariableTableAttribute;
  31. import org.apache.commons.compress.harmony.unpack200.bytecode.LocalVariableTypeTableAttribute;
  32. import org.apache.commons.compress.harmony.unpack200.bytecode.SignatureAttribute;
  33. import org.apache.commons.compress.harmony.unpack200.bytecode.SourceFileAttribute;

  34. /**
  35.  * Attribute definition bands are the set of bands used to define extra attributes transmitted in the archive.
  36.  */
  37. public class AttrDefinitionBands extends BandSet {

  38.     private int[] attributeDefinitionHeader;

  39.     private String[] attributeDefinitionLayout;

  40.     private String[] attributeDefinitionName;

  41.     private AttributeLayoutMap attributeDefinitionMap;

  42.     private final String[] cpUTF8;

  43.     public AttrDefinitionBands(final Segment segment) {
  44.         super(segment);
  45.         this.cpUTF8 = segment.getCpBands().getCpUTF8();
  46.     }

  47.     public AttributeLayoutMap getAttributeDefinitionMap() {
  48.         return attributeDefinitionMap;
  49.     }

  50.     /*
  51.      * (non-Javadoc)
  52.      *
  53.      * @see org.apache.commons.compress.harmony.unpack200.BandSet#unpack(java.io.InputStream)
  54.      */
  55.     @Override
  56.     public void read(final InputStream in) throws IOException, Pack200Exception {
  57.         final int attributeDefinitionCount = header.getAttributeDefinitionCount();
  58.         attributeDefinitionHeader = decodeBandInt("attr_definition_headers", in, Codec.BYTE1, attributeDefinitionCount);
  59.         attributeDefinitionName = parseReferences("attr_definition_name", in, Codec.UNSIGNED5, attributeDefinitionCount, cpUTF8);
  60.         attributeDefinitionLayout = parseReferences("attr_definition_layout", in, Codec.UNSIGNED5, attributeDefinitionCount, cpUTF8);

  61.         attributeDefinitionMap = new AttributeLayoutMap();

  62.         int overflowIndex = 32;
  63.         if (segment.getSegmentHeader().getOptions().hasClassFlagsHi()) {
  64.             overflowIndex = 63;
  65.         }
  66.         for (int i = 0; i < attributeDefinitionCount; i++) {
  67.             final int context = attributeDefinitionHeader[i] & 0x03;
  68.             int index = (attributeDefinitionHeader[i] >> 2) - 1;
  69.             if (index == -1) {
  70.                 index = overflowIndex++;
  71.             }
  72.             final AttributeLayout layout = new AttributeLayout(attributeDefinitionName[i], context, attributeDefinitionLayout[i], index, false);
  73.             final NewAttributeBands newBands = new NewAttributeBands(segment, layout);
  74.             attributeDefinitionMap.add(layout, newBands);
  75.         }
  76.         attributeDefinitionMap.checkMap();
  77.         setupDefaultAttributeNames();
  78.     }

  79.     private void setupDefaultAttributeNames() {
  80.         AnnotationDefaultAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("AnnotationDefault")); //$NON-NLS-1$
  81.         CodeAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Code")); //$NON-NLS-1$
  82.         ConstantValueAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("ConstantValue")); //$NON-NLS-1$
  83.         DeprecatedAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Deprecated")); //$NON-NLS-1$
  84.         EnclosingMethodAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("EnclosingMethod")); //$NON-NLS-1$
  85.         ExceptionsAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Exceptions")); //$NON-NLS-1$
  86.         InnerClassesAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("InnerClasses")); //$NON-NLS-1$
  87.         LineNumberTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LineNumberTable")); //$NON-NLS-1$
  88.         LocalVariableTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LocalVariableTable")); //$NON-NLS-1$
  89.         LocalVariableTypeTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LocalVariableTypeTable")); //$NON-NLS-1$
  90.         SignatureAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Signature")); //$NON-NLS-1$
  91.         SourceFileAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("SourceFile")); //$NON-NLS-1$
  92.         MetadataBandGroup.setRvaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleAnnotations"));
  93.         MetadataBandGroup.setRiaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeInvisibleAnnotations"));
  94.         MetadataBandGroup.setRvpaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleParameterAnnotations"));
  95.         MetadataBandGroup.setRipaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeInvisibleParameterAnnotations"));
  96.     }

  97.     @Override
  98.     public void unpack() throws Pack200Exception, IOException {

  99.     }

  100. }