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.ASN1Set;
024    import org.apache.geronimo.util.asn1.ASN1TaggedObject;
025    import org.apache.geronimo.util.asn1.DEREncodable;
026    import org.apache.geronimo.util.asn1.DERObject;
027    import org.apache.geronimo.util.asn1.DERTaggedObject;
028    
029    /**
030     * The DistributionPointName object.
031     * <pre>
032     * DistributionPointName ::= CHOICE {
033     *     fullName                 [0] GeneralNames,
034     *     nameRelativeToCRLIssuer  [1] RelativeDistinguishedName
035     * }
036     * </pre>
037     */
038    public class DistributionPointName
039        extends ASN1Encodable
040        implements ASN1Choice
041    {
042        DEREncodable        name;
043        int                 type;
044    
045        public static final int FULL_NAME = 0;
046        public static final int NAME_RELATIVE_TO_CRL_ISSUER = 1;
047    
048        public static DistributionPointName getInstance(
049            ASN1TaggedObject obj,
050            boolean          explicit)
051        {
052            return getInstance(ASN1TaggedObject.getInstance(obj, true));
053        }
054    
055        public static DistributionPointName getInstance(
056            Object  obj)
057        {
058            if (obj == null || obj instanceof DistributionPointName)
059            {
060                return (DistributionPointName)obj;
061            }
062            else if (obj instanceof ASN1TaggedObject)
063            {
064                return new DistributionPointName((ASN1TaggedObject)obj);
065            }
066    
067            throw new IllegalArgumentException("unknown object in factory");
068        }
069    
070        /*
071         * @deprecated use ASN1Encodable
072         */
073        public DistributionPointName(
074            int             type,
075            DEREncodable    name)
076        {
077            this.type = type;
078            this.name = name;
079        }
080    
081        public DistributionPointName(
082            int             type,
083            ASN1Encodable   name)
084        {
085            this.type = type;
086            this.name = name;
087        }
088    
089        /**
090         * Return the tag number applying to the underlying choice.
091         *
092         * @return the tag number for this point name.
093         */
094        public int getType()
095        {
096            return this.type;
097        }
098    
099        /**
100         * Return the tagged object inside the distribution point name.
101         *
102         * @return the underlying choice item.
103         */
104        public ASN1Encodable getName()
105        {
106            return (ASN1Encodable)name;
107        }
108    
109        public DistributionPointName(
110            ASN1TaggedObject    obj)
111        {
112            this.type = obj.getTagNo();
113    
114            if (type == 0)
115            {
116                this.name = GeneralNames.getInstance(obj, false);
117            }
118            else
119            {
120                this.name = ASN1Set.getInstance(obj, false);
121            }
122        }
123    
124        public DERObject toASN1Object()
125        {
126            return new DERTaggedObject(false, type, name);
127        }
128    }