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 18/** 19* @author Vladimir N. Molotkov, Stepan M. Mishura 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.asn1; 24 25 26/** 27 * This abstract class represents ASN.1 type that is a collection of ASN.1 types. 28 * 29 * @see <a href="http://asn1.elibel.tm.fr/en/standards/index.htm">ASN.1</a> 30 */ 31public abstract class ASN1TypeCollection extends ASN1Constructed { 32 33 public final ASN1Type[] type; 34 35 public final boolean[] OPTIONAL; 36 37 public final Object[] DEFAULT; 38 39 /** 40 * Constructs ASN.1 collection type. 41 * 42 * @param tagNumber ASN.1 tag number 43 * @param type a collection of one or more ASN.1 types. 44 * @throws IllegalArgumentException if tagNumber is invalid 45 */ 46 protected ASN1TypeCollection(int tagNumber, ASN1Type[] type) { 47 super(tagNumber); 48 this.type = type; 49 this.OPTIONAL = new boolean[type.length]; 50 this.DEFAULT = new Object[type.length]; 51 } 52 53 /** 54 * Sets a collection component as optional 55 * 56 * @param index an index of a component 57 */ 58 protected final void setOptional(int index) { 59 OPTIONAL[index] = true; 60 } 61 62 /** 63 * Sets a default value for a collection component. 64 * The component also became an optional component. 65 * 66 * @param object a component's default value 67 * @param index an index of a component 68 */ 69 protected final void setDefault(Object object, int index) { 70 OPTIONAL[index] = true; 71 DEFAULT[index] = object; 72 } 73 74 /** 75 * Provides an object's values to be encoded 76 * 77 * Derived classes should override this method to provide 78 * encoding for a selected class of objects. 79 * 80 * The default implementation throws RuntimeException. 81 * 82 * @param object an object to be encoded 83 * @param values an array to store an object's values to be encoded 84 */ 85 protected void getValues(Object object, Object[] values) { 86 throw new RuntimeException("ASN.1 type is not designed to be encoded: " + getClass().getName()); 87 } 88} 89