1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import org.apache.geronimo.util.asn1.ASN1Encodable;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
24 import org.apache.geronimo.util.asn1.DERObject;
25 import org.apache.geronimo.util.asn1.DERSequence;
26
27 public class GeneralNames
28 extends ASN1Encodable
29 {
30 ASN1Sequence seq;
31
32 public static GeneralNames getInstance(
33 Object obj)
34 {
35 if (obj == null || obj instanceof GeneralNames)
36 {
37 return (GeneralNames)obj;
38 }
39
40 if (obj instanceof ASN1Sequence)
41 {
42 return new GeneralNames((ASN1Sequence)obj);
43 }
44
45 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
46 }
47
48 public static GeneralNames getInstance(
49 ASN1TaggedObject obj,
50 boolean explicit)
51 {
52 return getInstance(ASN1Sequence.getInstance(obj, explicit));
53 }
54
55 /**
56 * Construct a GeneralNames object containing one GeneralName.
57 *
58 * @param name the name to be contained.
59 */
60 public GeneralNames(
61 GeneralName name)
62 {
63 this.seq = new DERSequence(name);
64 }
65
66 public GeneralNames(
67 ASN1Sequence seq)
68 {
69 this.seq = seq;
70 }
71
72 public GeneralName[] getNames()
73 {
74 GeneralName[] names = new GeneralName[seq.size()];
75
76 for (int i = 0; i != seq.size(); i++)
77 {
78 names[i] = GeneralName.getInstance(seq.getObjectAt(i));
79 }
80
81 return names;
82 }
83
84 /**
85 * Produce an object suitable for an ASN1OutputStream.
86 * <pre>
87 * GeneralNames ::= SEQUENCE SIZE {1..MAX} OF GeneralName
88 * </pre>
89 */
90 public DERObject toASN1Object()
91 {
92 return seq;
93 }
94 }