KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
21
22 import org.apache.geronimo.util.asn1.DERBMPString;
23 import org.apache.geronimo.util.asn1.DERIA5String;
24 import org.apache.geronimo.util.asn1.DERObject;
25 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
26 import org.apache.geronimo.util.asn1.DERPrintableString;
27 import org.apache.geronimo.util.asn1.DERUTF8String;
28
29 /**
30  * The default converter for X509 DN entries when going from their
31  * string value to
32  */

33 public class X509DefaultEntryConverter
34     extends X509NameEntryConverter
35 {
36     /**
37      * Apply default coversion for the given value depending on the oid
38      * and the character range of the value.
39      *
40      * @param oid the object identifier for the DN entry
41      * @param value the value associated with it
42      * @return the ASN.1 equivalent for the string value.
43      */

44     public DERObject getConvertedValue(
45         DERObjectIdentifier oid,
46         String JavaDoc value)
47     {
48         if (value.length() != 0 && value.charAt(0) == '#')
49         {
50             try
51             {
52                 return convertHexEncoded(value, 1);
53             }
54             catch (IOException JavaDoc e)
55             {
56                 throw new RuntimeException JavaDoc("can't recode value for oid " + oid.getId());
57             }
58         }
59         else if (oid.equals(X509Name.EmailAddress))
60         {
61             return new DERIA5String(value);
62         }
63         else if (canBePrintable(value))
64         {
65             return new DERPrintableString(value);
66         }
67         else if (canBeUTF8(value))
68         {
69             return new DERUTF8String(value);
70         }
71
72         return new DERBMPString(value);
73     }
74 }
75
Popular Tags