Source Code Cross Referenced for Timestamp.java in  » 6.0-JDK-Modules-com.sun » xws-security » com » sun » xml » ws » security » opt » impl » tokens » 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 » 6.0 JDK Modules com.sun » xws security » com.sun.xml.ws.security.opt.impl.tokens 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Timestamp.java
003:         *
004:         * Created on August 30, 2006, 11:16 PM
005:         *
006:         * The contents of this file are subject to the terms
007:         * of the Common Development and Distribution License
008:         * (the License).  You may not use this file except in
009:         * compliance with the License.
010:         *
011:         * You can obtain a copy of the license at
012:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013:         * See the License for the specific language governing
014:         * permissions and limitations under the License.
015:         *
016:         * When distributing Covered Code, include this CDDL
017:         * Header Notice in each file and include the License file
018:         * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019:         * If applicable, add the following below the CDDL Header,
020:         * with the fields enclosed by brackets [] replaced by
021:         * you own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025:         */
026:
027:        package com.sun.xml.ws.security.opt.impl.tokens;
028:
029:        import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
030:        import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
031:        import com.sun.xml.ws.security.opt.impl.util.JAXBUtil;
032:        import com.sun.xml.ws.security.wsu10.AttributedDateTime;
033:        import com.sun.xml.ws.security.wsu10.ObjectFactory;
034:        import com.sun.xml.ws.security.wsu10.TimestampType;
035:        import java.io.OutputStream;
036:        import java.text.SimpleDateFormat;
037:        import java.util.Calendar;
038:        import java.util.GregorianCalendar;
039:        import java.util.HashMap;
040:        import java.util.Iterator;
041:        import java.util.Map;
042:        import javax.xml.bind.JAXBElement;
043:        import javax.xml.bind.Marshaller;
044:        import javax.xml.bind.JAXBException;
045:        import javax.xml.namespace.QName;
046:        import com.sun.xml.wss.impl.MessageConstants;
047:        import com.sun.xml.stream.buffer.XMLStreamBufferResult;
048:        import com.sun.xml.ws.api.SOAPVersion;
049:        import javax.xml.stream.XMLStreamException;
050:
051:        import com.sun.xml.wss.XWSSecurityException;
052:
053:        /**
054:         * Representation of Timestamp SecurityHeaderElement
055:         * @author Ashutosh.Shahi@sun.com
056:         */
057:        public class Timestamp extends TimestampType implements 
058:                com.sun.xml.ws.security.opt.api.tokens.Timestamp,
059:                SecurityHeaderElement, SecurityElementWriter {
060:
061:            private long timeout = 0;
062:            private SOAPVersion soapVersion = SOAPVersion.SOAP_11;
063:            private ObjectFactory objFac = new ObjectFactory();
064:
065:            /**
066:             * Creates a new instance of Timestamp
067:             * @param sv the soapVersion for this message
068:             */
069:            public Timestamp(SOAPVersion sv) {
070:                this .soapVersion = sv;
071:            }
072:
073:            /**
074:             * 
075:             * @param created set the creation time on timestamp
076:             */
077:            public void setCreated(final String created) {
078:                AttributedDateTime timeCreated = objFac
079:                        .createAttributedDateTime();
080:                timeCreated.setValue(created);
081:                setCreated(timeCreated);
082:            }
083:
084:            /**
085:             * 
086:             * @param expires set the expiry time on timestamp
087:             */
088:            public void setExpires(final String expires) {
089:                AttributedDateTime timeExpires = objFac
090:                        .createAttributedDateTime();
091:                timeExpires.setValue(expires);
092:                setExpires(timeExpires);
093:            }
094:
095:            /**
096:             * 
097:             * @return the creation time value
098:             */
099:            public String getCreatedValue() {
100:                String createdValue = null;
101:                AttributedDateTime created = getCreated();
102:                if (created != null)
103:                    createdValue = created.getValue();
104:                return createdValue;
105:            }
106:
107:            /**
108:             * 
109:             * @return the expiry time value
110:             */
111:            public String getExpiresValue() {
112:                String expiresValue = null;
113:                AttributedDateTime expires = getExpires();
114:                if (expires != null)
115:                    expiresValue = expires.getValue();
116:                return expiresValue;
117:            }
118:
119:            /**
120:             * The timeout is assumed to be in seconds
121:             */
122:            public void setTimeout(long timeout) {
123:                this .timeout = timeout;
124:            }
125:
126:            public String getNamespaceURI() {
127:                return MessageConstants.WSU_NS;
128:            }
129:
130:            public String getLocalPart() {
131:                return MessageConstants.TIMESTAMP_LNAME;
132:            }
133:
134:            public String getAttribute(String nsUri, String localName) {
135:                QName qname = new QName(nsUri, localName);
136:                Map<QName, String> otherAttributes = this .getOtherAttributes();
137:                return otherAttributes.get(qname);
138:            }
139:
140:            public String getAttribute(QName name) {
141:                Map<QName, String> otherAttributes = this .getOtherAttributes();
142:                return otherAttributes.get(name);
143:            }
144:
145:            public javax.xml.stream.XMLStreamReader readHeader()
146:                    throws javax.xml.stream.XMLStreamException {
147:                XMLStreamBufferResult xbr = new XMLStreamBufferResult();
148:                JAXBElement<TimestampType> tsElem = new ObjectFactory()
149:                        .createTimestamp(this );
150:                try {
151:                    getMarshaller().marshal(tsElem, xbr);
152:
153:                } catch (JAXBException je) {
154:                    throw new XMLStreamException(je);
155:                }
156:                return xbr.getXMLStreamBuffer().readAsXMLStreamReader();
157:            }
158:
159:            /**
160:             * 
161:             * @param os 
162:             */
163:            public void writeTo(OutputStream os) {
164:            }
165:
166:            /**
167:             * Writes out the header.
168:             *
169:             * @throws XMLStreamException
170:             *      if the operation fails for some reason. This leaves the
171:             *      writer to an undefined state.
172:             */
173:            public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter)
174:                    throws javax.xml.stream.XMLStreamException {
175:                JAXBElement<TimestampType> tsElem = new ObjectFactory()
176:                        .createTimestamp(this );
177:                try {
178:                    // If writing to Zephyr, get output stream and use JAXB UTF-8 writer
179:                    if (streamWriter instanceof  Map) {
180:                        OutputStream os = (OutputStream) ((Map) streamWriter)
181:                                .get("sjsxp-outputstream");
182:                        if (os != null) {
183:                            streamWriter.writeCharacters(""); // Force completion of open elems
184:                            getMarshaller().marshal(tsElem, os);
185:                            return;
186:                        }
187:                    }
188:
189:                    getMarshaller().marshal(tsElem, streamWriter);
190:                } catch (JAXBException e) {
191:                    throw new XMLStreamException(e);
192:                }
193:            }
194:
195:            private Marshaller getMarshaller() throws JAXBException {
196:                return JAXBUtil.createMarshaller(soapVersion);
197:            }
198:
199:            /*
200:             * The <wsu:Created> element specifies a timestamp used to
201:             * indicate the creation time. It is defined as part of the
202:             * <wsu:Timestamp> definition.
203:             *
204:             * Time reference in WSS work should be in terms of
205:             * dateTime type specified in XML Schema in UTC time(Recommmended)
206:             */
207:            public void createDateTime() throws XWSSecurityException {
208:                if (created == null) {
209:                    Calendar c = new GregorianCalendar();
210:                    int offset = c.get(Calendar.ZONE_OFFSET);
211:                    if (c.getTimeZone().inDaylightTime(c.getTime())) {
212:                        offset += c.getTimeZone().getDSTSavings();
213:                    }
214:                    synchronized (calendarFormatter1) {
215:                        calendarFormatter1.setTimeZone(c.getTimeZone());
216:
217:                        // always send UTC/GMT time
218:                        long beforeTime = c.getTimeInMillis();
219:                        long currentTime = 0;
220:                        currentTime = beforeTime - offset;
221:                        c.setTimeInMillis(currentTime);
222:                        // finished UTC/GMT adjustment
223:
224:                        setCreated(calendarFormatter1.format(c.getTime()));
225:
226:                        c.setTimeInMillis(currentTime + timeout);
227:                        setExpires(calendarFormatter1.format(c.getTime()));
228:                    }
229:                }
230:            }
231:
232:            /**
233:             * 
234:             * @param id 
235:             * @return 
236:             */
237:            public boolean refersToSecHdrWithId(String id) {
238:                return false;
239:            }
240:
241:            /**
242:             * 
243:             * @param streamWriter 
244:             * @param props 
245:             * @throws javax.xml.stream.XMLStreamException 
246:             */
247:            public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter,
248:                    HashMap props) throws javax.xml.stream.XMLStreamException {
249:                try {
250:                    Marshaller marshaller = getMarshaller();
251:                    Iterator<Map.Entry<Object, Object>> itr = props.entrySet()
252:                            .iterator();
253:                    while (itr.hasNext()) {
254:                        Map.Entry<Object, Object> entry = itr.next();
255:                        marshaller.setProperty((String) entry.getKey(), entry
256:                                .getValue());
257:                    }
258:                    writeTo(streamWriter);
259:                } catch (JAXBException jbe) {
260:                    throw new XMLStreamException(jbe);
261:                }
262:            }
263:
264:            public static final SimpleDateFormat calendarFormatter1 = new SimpleDateFormat(
265:                    "yyyy-MM-dd'T'HH:mm:ss'Z'");
266:
267:        }
ww__w__.__jav___a___2_s__.___co_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.