KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > cms > RelativeDistinguishedName


1 /*
2  * Title: Oyster Project
3  * Description: S/MIME email sending capabilities
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8
9 package org.enhydra.oyster.cms;
10
11 import org.enhydra.oyster.exception.SMIMEException;
12 import org.enhydra.oyster.der.DERSetPr;
13 import org.enhydra.oyster.der.DERObjectIdentifier;
14 import org.enhydra.oyster.der.DERIA5String;
15 import org.enhydra.oyster.der.DERSequence;
16 import org.enhydra.oyster.der.DERPrintableString;
17
18 /**
19  * RelativeDistinguishedName class is DER encoded container represented in ASN.1
20  * notation according to RFC2630. It is used to hold just one information about
21  * owner or issuer of certificate (it can be name or country etc.). Collection
22  * of RelativeDistinguishedName builds IssuerName. Details about ASN.1 notation
23  * are described in class IssuerAndSerialNumber. RelativeDistinguishedName class
24  * is used only by addParticularRelativeDN method of IssuerAndSerialNumber.
25  */

26 public class RelativeDistinguishedName extends DERSetPr {
27
28 /**
29  * Indicator for enable/disable of use particular methods.
30  */

31   private int enable = 1;
32
33 /**
34  * Constructs empty RelativeDistinguishedName object.
35  * @exception SMIMEException thrown in super class constructor.
36  */

37   public RelativeDistinguishedName () throws SMIMEException
38   {
39   }
40
41 /**
42  * Constructs specific RelativeDistinguishedName object according to id0. This
43  * constructor has two different forms, depend on parameter typeConstruction0,
44  * which can be: DOT_SEPARATED_ARRAY or NAME_STRING. If typeConstruction0 parameter
45  * is DOT_SEPARATED_ARRAY then id0 definition is represented by numbers separated
46  * with dots (example: "2.5.4.6"). In case of NAME_STRING, id0 definition is name
47  * of object identifier (example: "COUNTRYNAME").
48  * @param id0 define Object Identifier in representation determined by second
49  * parameter - typeConstruction0.
50  * @param typeConstruction0 can take values DOT_SEPARATED_ARRAY and NAME_STRING
51  * @param value0 value of attribute of corresponding type defined by
52  * id0 and typeConstruction0
53  * @exception SMIMEException if wrong type of parameters are passed to the
54  * constructor. Also, it can be thrown by super class constructor.
55  */

56   public RelativeDistinguishedName (String JavaDoc id0, String JavaDoc typeConstruction0, String JavaDoc value0) throws SMIMEException
57   {
58     this.setAttributeTypeAndValue(id0, typeConstruction0, value0);
59     enable = 2;
60   }
61
62 /**
63  * Constructs specific RelativeDistinguishedName object according to arrayID0.
64  * Array of numbers (arrayID0) is used for constructing object identifier. Every
65  * number in array represent one number between dots in object identifier string.
66  * @param arrayID0 array of given numbers (example: for COUNTRYNAME object
67  * identifier those numbers are 2, 5, 4 and 6)
68  * @param value0 value of corresponding attribute defined by id0 and
69  * typeConstruction0
70  * @exception SMIMEException if wrong type of parameters are passed to the
71  * constructor. Also, it can be thrown by super class constructor.
72  */

73   public RelativeDistinguishedName (int[] arrayID0, String JavaDoc value0) throws SMIMEException
74   {
75     this.setAttributeTypeAndValue(arrayID0, value0);
76     enable = 3;
77   }
78
79 /**
80  * Sets type and value for particular attribute. For details about parameters
81  * look at second type of constructor.
82  * @param id0 same as in the second type of constructor.
83  * @param typeConstruction0 same as in the second type of constructor.
84  * @param value0 same as in the second type of constructor.
85  * @exception SMIMEException if method is performed twice for same object or if
86  * object wasn't constructed with the simplest constructor. Also, it can be
87  * thrown from super class addContent method.
88  */

89   public void setAttributeTypeAndValue (String JavaDoc id0, String JavaDoc typeConstruction0, String JavaDoc value0) throws SMIMEException {
90     if (enable == 4)
91       throw new SMIMEException(this, 1023);
92     else if (enable != 1)
93       throw new SMIMEException(this, 1024);
94     DERSequence seq = new DERSequence();
95     DERObjectIdentifier attribID = new DERObjectIdentifier(id0, typeConstruction0);
96     seq.addContent(attribID.getDEREncoded());
97     if (id0.equalsIgnoreCase("EMAILADDRESS") | id0.equalsIgnoreCase("1.2.840.113549.1.9.1")) {
98       DERIA5String atribString = new DERIA5String(value0);
99       seq.addContent(atribString.getDEREncoded());
100     }
101     else {
102       DERPrintableString atribString = new DERPrintableString(value0);
103       seq.addContent(atribString.getDEREncoded());
104     }
105     super.addContent(seq.getDEREncoded());
106     enable = 4;
107   }
108
109 /**
110  * Sets type and value for particular attribute. For details about parameters
111  * look at third type of constructor.
112  * @param arrayID0 same as in the third type of constructor.
113  * @param value0 same as in the third type of constructor.
114  * @exception SMIMEException if method is performed twice for same object or if
115  * object wasn't constructed with the simplest constructor. Also, it can be
116  * thrown from super class addContent method.
117  */

118   public void setAttributeTypeAndValue (int[] arrayID0, String JavaDoc value0) throws SMIMEException {
119     if (enable == 4)
120       throw new SMIMEException(this, 1023);
121     else if (enable != 1)
122       throw new SMIMEException(this, 1024);
123     DERObjectIdentifier attribID = new DERObjectIdentifier(arrayID0);
124     DERPrintableString atribString = new DERPrintableString(value0);
125     DERSequence seq = new DERSequence();
126     seq.addContent(attribID.getDEREncoded());
127     seq.addContent(atribString.getDEREncoded());
128     super.addContent(seq.getDEREncoded());
129     enable = 4;
130   }
131 }
132
133
134
135
Popular Tags