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