01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.harmony.security.asn1;
22:
23: import org.apache.harmony.security.internal.nls.Messages;
24:
25: /**
26: * This abstract class represents ASN.1 type that is a collection of ASN.1 types.
27: *
28: * @see http://asn1.elibel.tm.fr/en/standards/index.htm
29: */
30:
31: public abstract class ASN1TypeCollection extends ASN1Constructured {
32:
33: public final ASN1Type[] type; //TODO comment me
34:
35: public final boolean[] OPTIONAL; //TODO comment me
36:
37: public final Object[] DEFAULT; //TODO comment me
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: public ASN1TypeCollection(int tagNumber, ASN1Type[] type) {
47: super (tagNumber);
48: // FIXME what about empty sequence?
49: // if (type.length == 0) {
50: // throw new ASN1Exception("ASN1 collection type: "
51: // + getClass().getName()
52: // + " MUST have at least one component");
53: // }
54:
55: this .type = type;
56: this .OPTIONAL = new boolean[type.length];
57: this .DEFAULT = new Object[type.length];
58: }
59:
60: /**
61: * Sets a collection component as optional
62: *
63: * @param index - an index of a component
64: */
65: protected final void setOptional(int index) {
66: OPTIONAL[index] = true;
67: }
68:
69: /**
70: * Sets a default value for a collection component.
71: * The component also became an optional component.
72: *
73: * @param object - a component's default value
74: * @param index - an index of a component
75: */
76: protected final void setDefault(Object object, int index) {
77: OPTIONAL[index] = true;
78: DEFAULT[index] = object;
79: }
80:
81: /**
82: * Provides an object's values to be encoded
83: *
84: * Derived classes should override this method to provide
85: * encoding for a selected class of objects.
86: *
87: * The default implementation throws RuntimeException.
88: *
89: * @param object - an object to be encoded
90: * @param values - an array to store an object's values to be encoded
91: */
92: protected void getValues(Object object, Object[] values) {
93: throw new RuntimeException(Messages.getString(
94: "security.101", getClass().getName())); //$NON-NLS-1$
95: }
96: }
|