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.ASN1Choice;
022    import org.apache.geronimo.util.asn1.ASN1Encodable;
023    import org.apache.geronimo.util.asn1.ASN1Sequence;
024    import org.apache.geronimo.util.asn1.ASN1TaggedObject;
025    import org.apache.geronimo.util.asn1.DERObject;
026    import org.apache.geronimo.util.asn1.DERTaggedObject;
027    
028    public class AttCertIssuer
029        extends ASN1Encodable
030        implements ASN1Choice
031    {
032        ASN1Encodable   obj;
033        DERObject       choiceObj;
034    
035        public static AttCertIssuer getInstance(
036            Object  obj)
037        {
038            if (obj instanceof AttCertIssuer)
039            {
040                return (AttCertIssuer)obj;
041            }
042            else if (obj instanceof V2Form)
043            {
044                return new AttCertIssuer(V2Form.getInstance(obj));
045            }
046            else if (obj instanceof GeneralNames)
047            {
048                return new AttCertIssuer((GeneralNames)obj);
049            }
050            else if (obj instanceof ASN1TaggedObject)
051            {
052                return new AttCertIssuer(V2Form.getInstance((ASN1TaggedObject)obj, false));
053            }
054            else if (obj instanceof ASN1Sequence)
055            {
056                return new AttCertIssuer(GeneralNames.getInstance(obj));
057            }
058    
059            throw new IllegalArgumentException("unknown object in factory: " + obj.getClass());
060        }
061    
062        public static AttCertIssuer getInstance(
063            ASN1TaggedObject obj,
064            boolean          explicit)
065        {
066            return getInstance(obj.getObject()); // must be explictly tagged
067        }
068    
069        /**
070         * Don't use this one if you are trying to be RFC compliant.
071         *
072         * @param names our GeneralNames structure
073         */
074        public AttCertIssuer(
075            GeneralNames  names)
076        {
077            obj = names;
078            choiceObj = obj.getDERObject();
079        }
080    
081        public AttCertIssuer(
082            V2Form  v2Form)
083        {
084            obj = v2Form;
085            choiceObj = new DERTaggedObject(false, 0, obj);
086        }
087    
088        public ASN1Encodable getIssuer()
089        {
090            return obj;
091        }
092    
093        /**
094         * Produce an object suitable for an ASN1OutputStream.
095         * <pre>
096         *  AttCertIssuer ::= CHOICE {
097         *       v1Form   GeneralNames,  -- MUST NOT be used in this
098         *                               -- profile
099         *       v2Form   [0] V2Form     -- v2 only
100         *  }
101         * </pre>
102         */
103        public DERObject toASN1Object()
104        {
105            return choiceObj;
106        }
107    }