Source Code Cross Referenced for NameOrPseudonym.java in  » Security » Bouncy-Castle » org » bouncycastle » asn1 » x509 » sigi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.asn1.x509.sigi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.asn1.x509.sigi;
002:
003:        import org.bouncycastle.asn1.ASN1Choice;
004:        import org.bouncycastle.asn1.ASN1Encodable;
005:        import org.bouncycastle.asn1.ASN1EncodableVector;
006:        import org.bouncycastle.asn1.ASN1Sequence;
007:        import org.bouncycastle.asn1.DERObject;
008:        import org.bouncycastle.asn1.DERSequence;
009:        import org.bouncycastle.asn1.DERString;
010:        import org.bouncycastle.asn1.x500.DirectoryString;
011:
012:        import java.util.Enumeration;
013:
014:        /**
015:         * Structure for a name or pseudonym.
016:         * 
017:         * <pre>
018:         *       NameOrPseudonym ::= CHOICE {
019:         *            surAndGivenName SEQUENCE {
020:         *              surName DirectoryString,
021:         *              givenName SEQUENCE OF DirectoryString 
022:         *         },
023:         *            pseudonym DirectoryString 
024:         *       }
025:         * </pre>
026:         * 
027:         * @see org.bouncycastle.asn1.x509.sigi.PersonalData
028:         * 
029:         */
030:        public class NameOrPseudonym extends ASN1Encodable implements 
031:                ASN1Choice {
032:            private DirectoryString pseudonym;
033:
034:            private DirectoryString surname;
035:
036:            private ASN1Sequence givenName;
037:
038:            public static NameOrPseudonym getInstance(Object obj) {
039:                if (obj == null || obj instanceof  NameOrPseudonym) {
040:                    return (NameOrPseudonym) obj;
041:                }
042:
043:                if (obj instanceof  DERString) {
044:                    return new NameOrPseudonym(DirectoryString.getInstance(obj));
045:                }
046:
047:                if (obj instanceof  ASN1Sequence) {
048:                    return new NameOrPseudonym((ASN1Sequence) obj);
049:                }
050:
051:                throw new IllegalArgumentException(
052:                        "illegal object in getInstance: "
053:                                + obj.getClass().getName());
054:            }
055:
056:            /**
057:             * Constructor from DERString.
058:             * <p/>
059:             * The sequence is of type NameOrPseudonym:
060:             * <p/>
061:             * <pre>
062:             *       NameOrPseudonym ::= CHOICE {
063:             *            surAndGivenName SEQUENCE {
064:             *              surName DirectoryString,
065:             *              givenName SEQUENCE OF DirectoryString
066:             *         },
067:             *            pseudonym DirectoryString
068:             *       }
069:             * </pre>
070:             * @param pseudonym pseudonym value to use.
071:             */
072:            public NameOrPseudonym(DirectoryString pseudonym) {
073:                this .pseudonym = pseudonym;
074:            }
075:
076:            /**
077:             * Constructor from ASN1Sequence.
078:             * <p/>
079:             * The sequence is of type NameOrPseudonym:
080:             * <p/>
081:             * <pre>
082:             *       NameOrPseudonym ::= CHOICE {
083:             *            surAndGivenName SEQUENCE {
084:             *              surName DirectoryString,
085:             *              givenName SEQUENCE OF DirectoryString
086:             *         },
087:             *            pseudonym DirectoryString
088:             *       }
089:             * </pre>
090:             *
091:             * @param seq The ASN.1 sequence.
092:             */
093:            private NameOrPseudonym(ASN1Sequence seq) {
094:                if (seq.size() != 2) {
095:                    throw new IllegalArgumentException("Bad sequence size: "
096:                            + seq.size());
097:                }
098:
099:                if (!(seq.getObjectAt(0) instanceof  DERString)) {
100:                    throw new IllegalArgumentException(
101:                            "Bad object encountered: "
102:                                    + seq.getObjectAt(0).getClass());
103:                }
104:
105:                surname = DirectoryString.getInstance(seq.getObjectAt(0));
106:                givenName = ASN1Sequence.getInstance(seq.getObjectAt(1));
107:            }
108:
109:            /**
110:             * Constructor from a given details.
111:             *
112:             * @param pseudonym The pseudonym.
113:             */
114:            public NameOrPseudonym(String pseudonym) {
115:                this (new DirectoryString(pseudonym));
116:            }
117:
118:            /**
119:             * Constructor from a given details.
120:             *
121:             * @param surname   The surname.
122:             * @param givenName A sequence of directory strings making up the givenName
123:             */
124:            public NameOrPseudonym(DirectoryString surname,
125:                    ASN1Sequence givenName) {
126:                this .surname = surname;
127:                this .givenName = givenName;
128:            }
129:
130:            public DirectoryString getPseudonym() {
131:                return pseudonym;
132:            }
133:
134:            public DirectoryString getSurname() {
135:                return surname;
136:            }
137:
138:            public DirectoryString[] getGivenName() {
139:                DirectoryString[] items = new DirectoryString[givenName.size()];
140:                int count = 0;
141:                for (Enumeration e = givenName.getObjects(); e
142:                        .hasMoreElements();) {
143:                    items[count++] = DirectoryString.getInstance(e
144:                            .nextElement());
145:                }
146:                return items;
147:            }
148:
149:            /**
150:             * Produce an object suitable for an ASN1OutputStream.
151:             * <p/>
152:             * Returns:
153:             * <p/>
154:             * <pre>
155:             *       NameOrPseudonym ::= CHOICE {
156:             *            surAndGivenName SEQUENCE {
157:             *              surName DirectoryString,
158:             *              givenName SEQUENCE OF DirectoryString
159:             *         },
160:             *            pseudonym DirectoryString
161:             *       }
162:             * </pre>
163:             *
164:             * @return a DERObject
165:             */
166:            public DERObject toASN1Object() {
167:                if (pseudonym != null) {
168:                    return pseudonym.toASN1Object();
169:                } else {
170:                    ASN1EncodableVector vec1 = new ASN1EncodableVector();
171:                    vec1.add(surname);
172:                    vec1.add(givenName);
173:                    return new DERSequence(vec1);
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.