Source Code Cross Referenced for Timestamp.java in  » JDK-Core » security » java » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. JDK Core
2. JDK Modules
3. JDK Modules com.sun
4. JDK Modules com.sun.java
5. JDK Modules Platform
6. JDK Modules sun
7. Open Source Build
8. Open Source Graphic Library
9. Open Source IDE Eclipse
10. Open Source J2EE
11. Open Source JDBC Driver
12. Open Source Library
13. Open Source Library Database
14. Open Source Net
15. Open Source Script
16. Science
17. Security
18. Sevlet Container
19. SUN GlassFish
20. Swing Library
21. Web Services apache cxf 2.0.1
22. Web Services AXIS2
23. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java Source Code / Java Documentation » JDK Core » security » java.security 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package java.security;
027:
028:        import java.io.Serializable;
029:        import java.security.cert.CertPath;
030:        import java.security.cert.X509Extension;
031:        import java.util.Date;
032:
033:        /**
034:         * This class encapsulates information about a signed timestamp.
035:         * It is immutable.
036:         * It includes the timestamp's date and time as well as information about the 
037:         * Timestamping Authority (TSA) which generated and signed the timestamp.
038:         *
039:         * @since 1.5
040:         * @version 1.9, 05/05/07
041:         * @author Vincent Ryan
042:         */
043:
044:        public final class Timestamp implements  Serializable {
045:
046:            private static final long serialVersionUID = -5502683707821851294L;
047:
048:            /**
049:             * The timestamp's date and time
050:             *
051:             * @serial
052:             */
053:            private Date timestamp;
054:
055:            /**
056:             * The TSA's certificate path.
057:             *
058:             * @serial
059:             */
060:            private CertPath signerCertPath;
061:
062:            /*
063:             * Hash code for this timestamp.
064:             */
065:            private transient int myhash = -1;
066:
067:            /**
068:             * Constructs a Timestamp.
069:             *
070:             * @param timestamp is the timestamp's date and time. It must not be null.
071:             * @param signerCertPath is the TSA's certificate path. It must not be null.
072:             * @throws NullPointerException if timestamp or signerCertPath is null.
073:             */
074:            public Timestamp(Date timestamp, CertPath signerCertPath) {
075:                if (timestamp == null || signerCertPath == null) {
076:                    throw new NullPointerException();
077:                }
078:                this .timestamp = new Date(timestamp.getTime()); // clone
079:                this .signerCertPath = signerCertPath;
080:            }
081:
082:            /**
083:             * Returns the date and time when the timestamp was generated.
084:             *
085:             * @return The timestamp's date and time.
086:             */
087:            public Date getTimestamp() {
088:                return new Date(timestamp.getTime()); // clone
089:            }
090:
091:            /**
092:             * Returns the certificate path for the Timestamping Authority.
093:             *
094:             * @return The TSA's certificate path.
095:             */
096:            public CertPath getSignerCertPath() {
097:                return signerCertPath;
098:            }
099:
100:            /**
101:             * Returns the hash code value for this timestamp. 
102:             * The hash code is generated using the date and time of the timestamp
103:             * and the TSA's certificate path.
104:             *
105:             * @return a hash code value for this timestamp.
106:             */
107:            public int hashCode() {
108:                if (myhash == -1) {
109:                    myhash = timestamp.hashCode() + signerCertPath.hashCode();
110:                }
111:                return myhash;
112:            }
113:
114:            /**
115:             * Tests for equality between the specified object and this
116:             * timestamp. Two timestamps are considered equal if the date and time of
117:             * their timestamp's and their signer's certificate paths are equal.
118:             * 
119:             * @param obj the object to test for equality with this timestamp.
120:             * 
121:             * @return true if the timestamp are considered equal, false otherwise.
122:             */
123:            public boolean equals(Object obj) {
124:                if (obj == null || (!(obj instanceof  Timestamp))) {
125:                    return false;
126:                }
127:                Timestamp that = (Timestamp) obj;
128:
129:                if (this  == that) {
130:                    return true;
131:                }
132:                return (timestamp.equals(that.getTimestamp()) && signerCertPath
133:                        .equals(that.getSignerCertPath()));
134:            }
135:
136:            /**
137:             * Returns a string describing this timestamp.
138:             * 
139:             * @return A string comprising the date and time of the timestamp and
140:             *         its signer's certificate.
141:             */
142:            public String toString() {
143:                StringBuffer sb = new StringBuffer();
144:                sb.append("(");
145:                sb.append("timestamp: " + timestamp);
146:                sb.append("TSA: " + signerCertPath.getCertificates().get(0));
147:                sb.append(")");
148:                return sb.toString();
149:            }
150:        }
ww__w.j_a___v__a__2___s_.___c___om_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.