1 /* 2 * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.] 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.opensaml.common.impl; 18 19 import org.joda.time.DateTime; 20 import org.joda.time.DateTimeZone; 21 import org.opensaml.xml.validation.AbstractValidatingXMLObject; 22 23 /** 24 * An abstract implementation of SAMLObject. 25 */ 26 public abstract class AbstractSAMLObject extends AbstractValidatingXMLObject { 27 28 /** 29 * Constructor. 30 * 31 * @param namespaceURI the namespace the element is in 32 * @param elementLocalName the local name of the XML element this Object represents 33 * @param namespacePrefix the prefix for the given namespace 34 */ 35 protected AbstractSAMLObject(String namespaceURI, String elementLocalName, String namespacePrefix) { 36 super(namespaceURI, elementLocalName, namespacePrefix); 37 } 38 39 /** {@inheritDoc} */ 40 public final boolean equals(Object obj) { 41 if(obj == this){ 42 return true; 43 } 44 45 return super.equals(obj); 46 } 47 48 /** 49 * A helper function for derived classes that checks to see if the old and new value are equal and if so releases 50 * the cached dom. Derived classes are expected to use this thus: <code> 51 * this.foo = prepareForAssignment(this.foo, foo); 52 * </code> 53 * 54 * This method will do a (null) safe compare of the objects and will also invalidate the DOM if appropriate 55 * 56 * @param oldValue - current value 57 * @param newValue - proposed new value 58 * 59 * @return The value to assign to the saved Object. 60 */ 61 protected DateTime prepareForAssignment(DateTime oldValue, DateTime newValue) { 62 DateTime utcValue = null; 63 if (newValue != null) { 64 utcValue = newValue.withZone(DateTimeZone.UTC); 65 } 66 67 return super.prepareForAssignment(oldValue, utcValue); 68 } 69 }