01: /*
02: * $Id: LifetimeImpl.java,v 1.1 2007/08/23 12:40:55 shyam_rao Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
25: */
26:
27: package com.sun.xml.ws.security.trust.impl.wssx.elements;
28:
29: import org.w3c.dom.Document;
30: import org.w3c.dom.Element;
31:
32: import javax.xml.bind.JAXBContext;
33: import javax.xml.bind.JAXBException;
34: import javax.xml.bind.annotation.XmlRootElement;
35:
36: import com.sun.xml.ws.security.wsu10.AttributedDateTime;
37: import com.sun.xml.ws.api.security.trust.WSTrustException;
38: import com.sun.xml.ws.security.trust.impl.wssx.bindings.LifetimeType;
39:
40: import com.sun.xml.ws.security.trust.elements.Lifetime;
41:
42: /**
43: *
44: * @author Manveen Kaur
45: */
46: public class LifetimeImpl extends LifetimeType implements Lifetime {
47:
48: public LifetimeImpl() {
49: // default empty constructor
50: }
51:
52: public LifetimeImpl(AttributedDateTime created,
53: AttributedDateTime expires) {
54: if (created != null) {
55: setCreated(created);
56: }
57: if (expires != null) {
58: setExpires(expires);
59: }
60: }
61:
62: public LifetimeImpl(LifetimeType ltType) {
63: this (ltType.getCreated(), ltType.getExpires());
64: }
65:
66: /**
67: * Constructs a <code>Lifetime</code> element from
68: * an existing XML block.
69: *
70: * @param lifetimeElement A
71: * <code>org.w3c.dom.Element</code> representing DOM tree
72: * for <code>Lifetime</code> object.
73: * @exception WSTrustException if it could not process the
74: * <code>org.w3c.dom.Element</code> properly, implying that
75: * there is an error in the sender or in the element definition.
76: */
77: public static LifetimeType fromElement(org.w3c.dom.Element element)
78: throws WSTrustException {
79: try {
80: JAXBContext jc = JAXBContext
81: .newInstance("com.sun.xml.ws.security.trust.impl.wssx.elements");
82: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
83: return (LifetimeType) u.unmarshal(element);
84: } catch (Exception ex) {
85: throw new WSTrustException(ex.getMessage(), ex);
86: }
87: }
88:
89: }
|