View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.util.asn1.x509;
20  
21  import org.apache.geronimo.util.asn1.ASN1Encodable;
22  import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23  import org.apache.geronimo.util.asn1.ASN1Sequence;
24  import org.apache.geronimo.util.asn1.DERObject;
25  import org.apache.geronimo.util.asn1.DERObjectIdentifier;
26  import org.apache.geronimo.util.asn1.DERSequence;
27  
28  /**
29   * The AccessDescription object.
30   * <pre>
31   * AccessDescription  ::=  SEQUENCE {
32   *       accessMethod          OBJECT IDENTIFIER,
33   *       accessLocation        GeneralName  }
34   * </pre>
35   */
36  public class AccessDescription
37      extends ASN1Encodable
38  {
39      DERObjectIdentifier accessMethod = null;
40      GeneralName accessLocation = null;
41  
42      public static AccessDescription getInstance(
43          Object  obj)
44      {
45          if (obj instanceof AccessDescription)
46          {
47              return (AccessDescription)obj;
48          }
49          else if (obj instanceof ASN1Sequence)
50          {
51              return new AccessDescription((ASN1Sequence)obj);
52          }
53  
54          throw new IllegalArgumentException("unknown object in factory");
55      }
56  
57      public AccessDescription(
58          ASN1Sequence   seq)
59      {
60          if (seq.size() != 2)
61          {
62              throw new IllegalArgumentException("wrong number of elements in inner sequence");
63          }
64  
65          accessMethod = (DERObjectIdentifier)seq.getObjectAt(0);
66          accessLocation = GeneralName.getInstance(seq.getObjectAt(1));
67      }
68  
69      /**
70       * create an AccessDescription with the oid and location provided.
71       */
72      public AccessDescription(
73          DERObjectIdentifier oid,
74          GeneralName location)
75      {
76          accessMethod = oid;
77          accessLocation = location;
78      }
79  
80      /**
81       *
82       * @return the access method.
83       */
84      public DERObjectIdentifier getAccessMethod()
85      {
86          return accessMethod;
87      }
88  
89      /**
90       *
91       * @return the access location
92       */
93      public GeneralName getAccessLocation()
94      {
95          return accessLocation;
96      }
97  
98      public DERObject toASN1Object()
99      {
100         ASN1EncodableVector accessDescription  = new ASN1EncodableVector();
101 
102         accessDescription.add(accessMethod);
103         accessDescription.add(accessLocation);
104 
105         return new DERSequence(accessDescription);
106     }
107 
108     public String toString()
109     {
110         return ("AccessDescription: Oid(" + this.accessMethod.getId() + ")");
111     }
112 }