001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.util.asn1.x509; 019 020 import org.apache.geronimo.util.asn1.ASN1Encodable; 021 import org.apache.geronimo.util.asn1.ASN1Sequence; 022 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 023 import org.apache.geronimo.util.asn1.DERObject; 024 import org.apache.geronimo.util.asn1.DERSequence; 025 026 public class GeneralNames 027 extends ASN1Encodable 028 { 029 ASN1Sequence seq; 030 031 public static GeneralNames getInstance( 032 Object obj) 033 { 034 if (obj == null || obj instanceof GeneralNames) 035 { 036 return (GeneralNames)obj; 037 } 038 039 if (obj instanceof ASN1Sequence) 040 { 041 return new GeneralNames((ASN1Sequence)obj); 042 } 043 044 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); 045 } 046 047 public static GeneralNames getInstance( 048 ASN1TaggedObject obj, 049 boolean explicit) 050 { 051 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 052 } 053 054 /** 055 * Construct a GeneralNames object containing one GeneralName. 056 * 057 * @param name the name to be contained. 058 */ 059 public GeneralNames( 060 GeneralName name) 061 { 062 this.seq = new DERSequence(name); 063 } 064 065 public GeneralNames( 066 ASN1Sequence seq) 067 { 068 this.seq = seq; 069 } 070 071 public GeneralName[] getNames() 072 { 073 GeneralName[] names = new GeneralName[seq.size()]; 074 075 for (int i = 0; i != seq.size(); i++) 076 { 077 names[i] = GeneralName.getInstance(seq.getObjectAt(i)); 078 } 079 080 return names; 081 } 082 083 /** 084 * Produce an object suitable for an ASN1OutputStream. 085 * <pre> 086 * GeneralNames ::= SEQUENCE SIZE {1..MAX} OF GeneralName 087 * </pre> 088 */ 089 public DERObject toASN1Object() 090 { 091 return seq; 092 } 093 }