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.ASN1EncodableVector;
022    import org.apache.geronimo.util.asn1.ASN1Sequence;
023    import org.apache.geronimo.util.asn1.DERObject;
024    import org.apache.geronimo.util.asn1.DERObjectIdentifier;
025    import org.apache.geronimo.util.asn1.DERSequence;
026    
027    /**
028     * The AccessDescription object.
029     * <pre>
030     * AccessDescription  ::=  SEQUENCE {
031     *       accessMethod          OBJECT IDENTIFIER,
032     *       accessLocation        GeneralName  }
033     * </pre>
034     */
035    public class AccessDescription
036        extends ASN1Encodable
037    {
038        DERObjectIdentifier accessMethod = null;
039        GeneralName accessLocation = null;
040    
041        public static AccessDescription getInstance(
042            Object  obj)
043        {
044            if (obj instanceof AccessDescription)
045            {
046                return (AccessDescription)obj;
047            }
048            else if (obj instanceof ASN1Sequence)
049            {
050                return new AccessDescription((ASN1Sequence)obj);
051            }
052    
053            throw new IllegalArgumentException("unknown object in factory");
054        }
055    
056        public AccessDescription(
057            ASN1Sequence   seq)
058        {
059            if (seq.size() != 2)
060            {
061                throw new IllegalArgumentException("wrong number of elements in inner sequence");
062            }
063    
064            accessMethod = (DERObjectIdentifier)seq.getObjectAt(0);
065            accessLocation = GeneralName.getInstance(seq.getObjectAt(1));
066        }
067    
068        /**
069         * create an AccessDescription with the oid and location provided.
070         */
071        public AccessDescription(
072            DERObjectIdentifier oid,
073            GeneralName location)
074        {
075            accessMethod = oid;
076            accessLocation = location;
077        }
078    
079        /**
080         *
081         * @return the access method.
082         */
083        public DERObjectIdentifier getAccessMethod()
084        {
085            return accessMethod;
086        }
087    
088        /**
089         *
090         * @return the access location
091         */
092        public GeneralName getAccessLocation()
093        {
094            return accessLocation;
095        }
096    
097        public DERObject toASN1Object()
098        {
099            ASN1EncodableVector accessDescription  = new ASN1EncodableVector();
100    
101            accessDescription.add(accessMethod);
102            accessDescription.add(accessLocation);
103    
104            return new DERSequence(accessDescription);
105        }
106    
107        public String toString()
108        {
109            return ("AccessDescription: Oid(" + this.accessMethod.getId() + ")");
110        }
111    }