001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * LifeTimeImpl.java
039: *
040: * Created on February 23, 2006, 12:00 PM
041: *
042: * To change this template, choose Tools | Template Manager
043: * and open the template in the editor.
044: */
045:
046: package com.sun.xml.ws.security.impl.policy;
047:
048: import com.sun.xml.ws.policy.AssertionSet;
049: import com.sun.xml.ws.policy.NestedPolicy;
050: import com.sun.xml.ws.policy.PolicyAssertion;
051: import com.sun.xml.ws.security.policy.SecurityAssertionValidator;
052: import com.sun.xml.ws.policy.sourcemodel.AssertionData;
053: import java.util.Collection;
054: import static com.sun.xml.ws.security.impl.policy.Constants.*;
055: import java.util.logging.Level;
056:
057: /**
058: *
059: * @author Abhijit Das
060: */
061: public class Lifetime extends PolicyAssertion implements
062: com.sun.xml.ws.security.policy.Lifetime,
063: SecurityAssertionValidator {
064:
065: private String created;
066: private String expires;
067: private AssertionFitness fitness = AssertionFitness.IS_VALID;
068: private boolean populated = false;
069:
070: /** Creates a new instance of LifeTimeImpl */
071: public Lifetime(AssertionData name,
072: Collection<PolicyAssertion> nestedAssertions,
073: AssertionSet nestedAlternative) {
074: super (name, nestedAssertions, nestedAlternative);
075: }
076:
077: public String getCreated() {
078: populate();
079: return created;
080: }
081:
082: public void setCreated(String created) {
083: this .created = created;
084: }
085:
086: public String getExpires() {
087: populate();
088: return expires;
089: }
090:
091: public void setExpires(String expires) {
092: this .expires = expires;
093: }
094:
095: public AssertionFitness validate(boolean isServer) {
096: return populate(isServer);
097: }
098:
099: private void populate() {
100: populate(false);
101: }
102:
103: private synchronized AssertionFitness populate(boolean isServer) {
104: if (!populated) {
105: NestedPolicy policy = this .getNestedPolicy();
106: if (policy == null) {
107: if (logger.getLevel() == Level.FINE) {
108: logger.log(Level.FINE, "NestedPolicy is null");
109: }
110: populated = true;
111: return fitness;
112: }
113: AssertionSet as = policy.getAssertionSet();
114: for (PolicyAssertion pa : as) {
115: if (PolicyUtil.isCreated(pa)) {
116: this .created = pa.getValue();
117: } else if (PolicyUtil.isExpires(pa)) {
118: this .expires = pa.getValue();
119: }
120: }
121: populated = true;
122: }
123: return fitness;
124: }
125: }
|