KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > Attribute


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.ASN1Sequence;
23 import org.apache.geronimo.util.asn1.ASN1Set;
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 public class Attribute
29     extends ASN1Encodable
30 {
31     private DERObjectIdentifier attrType;
32     private ASN1Set attrValues;
33
34     /**
35      * return an Attribute object from the given object.
36      *
37      * @param o the object we want converted.
38      * @exception IllegalArgumentException if the object cannot be converted.
39      */

40     public static Attribute getInstance(
41         Object JavaDoc o)
42     {
43         if (o == null || o instanceof Attribute)
44         {
45             return (Attribute)o;
46         }
47
48         if (o instanceof ASN1Sequence)
49         {
50             return new Attribute((ASN1Sequence)o);
51         }
52
53         throw new IllegalArgumentException JavaDoc("unknown object in factory");
54     }
55
56     public Attribute(
57         ASN1Sequence seq)
58     {
59         attrType = (DERObjectIdentifier)seq.getObjectAt(0);
60         attrValues = (ASN1Set)seq.getObjectAt(1);
61     }
62
63     public Attribute(
64         DERObjectIdentifier attrType,
65         ASN1Set attrValues)
66     {
67         this.attrType = attrType;
68         this.attrValues = attrValues;
69     }
70
71     public DERObjectIdentifier getAttrType()
72     {
73         return attrType;
74     }
75
76     public ASN1Set getAttrValues()
77     {
78         return attrValues;
79     }
80
81     /**
82      * Produce an object suitable for an ASN1OutputStream.
83      * <pre>
84      * Attribute ::= SEQUENCE {
85      * attrType OBJECT IDENTIFIER,
86      * attrValues SET OF AttributeValue
87      * }
88      * </pre>
89      */

90     public DERObject toASN1Object()
91     {
92         ASN1EncodableVector v = new ASN1EncodableVector();
93
94         v.add(attrType);
95         v.add(attrValues);
96
97         return new DERSequence(v);
98     }
99 }
100
Popular Tags