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: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
19: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
20: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
21: import org.apache.geronimo.crypto.asn1.DERObject;
22: import org.apache.geronimo.crypto.asn1.DERSequence;
23:
24: public class GeneralNames extends ASN1Encodable {
25: ASN1Sequence seq;
26:
27: public static GeneralNames getInstance(Object obj) {
28: if (obj == null || obj instanceof GeneralNames) {
29: return (GeneralNames) obj;
30: }
31:
32: if (obj instanceof ASN1Sequence) {
33: return new GeneralNames((ASN1Sequence) obj);
34: }
35:
36: throw new IllegalArgumentException(
37: "illegal object in getInstance: "
38: + obj.getClass().getName());
39: }
40:
41: public static GeneralNames getInstance(ASN1TaggedObject obj,
42: boolean explicit) {
43: return getInstance(ASN1Sequence.getInstance(obj, explicit));
44: }
45:
46: /**
47: * Construct a GeneralNames object containing one GeneralName.
48: *
49: * @param name the name to be contained.
50: */
51: public GeneralNames(GeneralName name) {
52: this .seq = new DERSequence(name);
53: }
54:
55: public GeneralNames(ASN1Sequence seq) {
56: this .seq = seq;
57: }
58:
59: public GeneralName[] getNames() {
60: GeneralName[] names = new GeneralName[seq.size()];
61:
62: for (int i = 0; i != seq.size(); i++) {
63: names[i] = GeneralName.getInstance(seq.getObjectAt(i));
64: }
65:
66: return names;
67: }
68:
69: /**
70: * Produce an object suitable for an ASN1OutputStream.
71: * <pre>
72: * GeneralNames ::= SEQUENCE SIZE {1..MAX} OF GeneralName
73: * </pre>
74: */
75: public DERObject toASN1Object() {
76: return seq;
77: }
78: }
|