Source Code Cross Referenced for Time.java in  » Security » Bouncy-Castle » org » bouncycastle » asn1 » x509 » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.asn1.x509;
002:
003:        import org.bouncycastle.asn1.ASN1Choice;
004:        import org.bouncycastle.asn1.ASN1Encodable;
005:        import org.bouncycastle.asn1.ASN1TaggedObject;
006:        import org.bouncycastle.asn1.DERGeneralizedTime;
007:        import org.bouncycastle.asn1.DERObject;
008:        import org.bouncycastle.asn1.DERUTCTime;
009:
010:        import java.text.ParseException;
011:        import java.text.SimpleDateFormat;
012:        import java.util.Date;
013:        import java.util.SimpleTimeZone;
014:
015:        public class Time extends ASN1Encodable implements  ASN1Choice {
016:            DERObject time;
017:
018:            public static Time getInstance(ASN1TaggedObject obj,
019:                    boolean explicit) {
020:                return getInstance(obj.getObject()); // must be explicitly tagged
021:            }
022:
023:            public Time(DERObject time) {
024:                if (!(time instanceof  DERUTCTime)
025:                        && !(time instanceof  DERGeneralizedTime)) {
026:                    throw new IllegalArgumentException(
027:                            "unknown object passed to Time");
028:                }
029:
030:                this .time = time;
031:            }
032:
033:            /**
034:             * creates a time object from a given date - if the date is between 1950
035:             * and 2049 a UTCTime object is generated, otherwise a GeneralizedTime
036:             * is used.
037:             */
038:            public Time(Date date) {
039:                SimpleTimeZone tz = new SimpleTimeZone(0, "Z");
040:                SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmss");
041:
042:                dateF.setTimeZone(tz);
043:
044:                String d = dateF.format(date) + "Z";
045:                int year = Integer.parseInt(d.substring(0, 4));
046:
047:                if (year < 1950 || year > 2049) {
048:                    time = new DERGeneralizedTime(d);
049:                } else {
050:                    time = new DERUTCTime(d.substring(2));
051:                }
052:            }
053:
054:            public static Time getInstance(Object obj) {
055:                if (obj instanceof  Time) {
056:                    return (Time) obj;
057:                } else if (obj instanceof  DERUTCTime) {
058:                    return new Time((DERUTCTime) obj);
059:                } else if (obj instanceof  DERGeneralizedTime) {
060:                    return new Time((DERGeneralizedTime) obj);
061:                }
062:
063:                throw new IllegalArgumentException("unknown object in factory");
064:            }
065:
066:            public String getTime() {
067:                if (time instanceof  DERUTCTime) {
068:                    return ((DERUTCTime) time).getAdjustedTime();
069:                } else {
070:                    return ((DERGeneralizedTime) time).getTime();
071:                }
072:            }
073:
074:            public Date getDate() {
075:                try {
076:                    if (time instanceof  DERUTCTime) {
077:                        return ((DERUTCTime) time).getAdjustedDate();
078:                    } else {
079:                        return ((DERGeneralizedTime) time).getDate();
080:                    }
081:                } catch (ParseException e) { // this should never happen
082:                    throw new IllegalStateException("invalid date string: "
083:                            + e.getMessage());
084:                }
085:            }
086:
087:            /**
088:             * Produce an object suitable for an ASN1OutputStream.
089:             * <pre>
090:             * Time ::= CHOICE {
091:             *             utcTime        UTCTime,
092:             *             generalTime    GeneralizedTime }
093:             * </pre>
094:             */
095:            public DERObject toASN1Object() {
096:                return time;
097:            }
098:
099:            public String toString() {
100:                return getTime();
101:            }
102:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.