1 /* 2 * Redistribution and use of this software and associated documentation ("Software"), with or 3 * without modification, are permitted provided that the following conditions are met: 4 * 5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions 6 * must also contain a copy of this document. 7 * 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided with 10 * the distribution. 11 * 12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software 13 * without prior written permission of Intalio, Inc. For written permission, please contact 14 * info@exolab.org. 15 * 16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in 17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of 18 * Intalio, Inc. 19 * 20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). 21 * 22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Copyright 2000-2003 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 package org.exolab.castor.types; 36 37 import org.exolab.castor.mapping.FieldDescriptor; 38 import org.exolab.castor.mapping.ValidityException; 39 import org.exolab.castor.xml.NodeType; 40 import org.exolab.castor.xml.XMLFieldDescriptor; 41 import org.exolab.castor.xml.XMLFieldHandler; 42 import org.exolab.castor.xml.util.XMLFieldDescriptorImpl; 43 44 /** 45 * The RecurringDuration Descriptor. 46 * 47 * @author <a href="mailto:blandin@intalio.com">Arnaud Blandin</a> 48 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 49 * @version $Revision$ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $ 50 * @deprecated since Castor 1.0.6 since this type is not in any recommendation. 51 */ 52 public class RecurringDurationDescriptor extends BaseDescriptor { 53 54 /** The name of the XML element. */ 55 private static final String XML_NAME = "recurringDuration"; 56 /** Our field descriptor. */ 57 private static final XMLFieldDescriptorImpl CONTENT_DESCRIPTOR; 58 /** Our field descriptor array. Lists the fields we describe. */ 59 private static final FieldDescriptor[] FIELDS; 60 61 static { 62 CONTENT_DESCRIPTOR = 63 new XMLFieldDescriptorImpl(String.class, "content", "content", NodeType.Text); 64 CONTENT_DESCRIPTOR 65 .setHandler(new RecurringDurationDescriptor().new RecurringDurationFieldHandler()); 66 FIELDS = new FieldDescriptor[1]; 67 FIELDS[0] = CONTENT_DESCRIPTOR; 68 } 69 70 // ----------------/ 71 // - Constructors -/ 72 // ----------------/ 73 74 public RecurringDurationDescriptor() { 75 super(XML_NAME, RecurringDuration.class); 76 } 77 78 // ------------------/ 79 // - Public Methods -/ 80 // ------------------/ 81 82 /** 83 * Returns the XMLFieldDescriptor for the member that should be marshalled as text content. 84 * 85 * @return the XMLFieldDescriptor for the member that should be marshalled as text content. 86 */ 87 public XMLFieldDescriptor getContentDescriptor() { 88 return CONTENT_DESCRIPTOR; 89 } // getContentDescriptor 90 91 /** 92 * Returns a list of fields represented by this descriptor. 93 * 94 * @return A list of fields 95 */ 96 public FieldDescriptor[] getFields() { 97 return FIELDS; 98 } // -- getFields 99 100 /** 101 * A specialized FieldHandler for the XML Schema TimeDuration related types 102 * 103 * @author <a href="blandin@intalio.com">Arnaud Blandin</a> 104 * @version $Revision$ $Date: $ 105 */ 106 class RecurringDurationFieldHandler extends XMLFieldHandler { 107 108 // ----------------/ 109 // - Constructors -/ 110 // ----------------/ 111 112 /** 113 * Creates a new TimeFieldHandler 114 */ 115 public RecurringDurationFieldHandler() { 116 super(); 117 } // -- TimeFieldHandler 118 119 // ------------------/ 120 // - Public Methods -/ 121 // ------------------/ 122 123 /** 124 * Returns the value of the field associated with this descriptor from the given target object. 125 * 126 * @param target the object to get the value from 127 * @return the value of the field associated with this descriptor from the given target object. 128 */ 129 public Object getValue(Object target) throws java.lang.IllegalStateException { 130 // -- check for TimeDuration class -- add later 131 RecurringDuration recurr = (RecurringDuration) target; 132 return recurr.toString(); 133 } // -- getValue 134 135 /** 136 * Sets the value of the field associated with this descriptor. 137 * 138 * @param target the object in which to set the value 139 * @param value the value of the field 140 */ 141 public void setValue(Object target, Object value) throws java.lang.IllegalStateException { 142 if (!(target instanceof RecurringDuration)) { 143 // -- throw exception 144 } 145 146 RecurringDuration recurTarget = (RecurringDuration) target; 147 148 if (value == null) { 149 /// do something 150 } 151 152 // -- update current instance of time with new time 153 try { 154 RecurringDuration temp = RecurringDuration.parseRecurringDuration(value.toString()); 155 recurTarget.setCentury(temp.getCentury()); 156 recurTarget.setYear(temp.getYear()); 157 recurTarget.setMonth(temp.getMonth()); 158 recurTarget.setDay(temp.getDay()); 159 recurTarget.setHour(temp.getHour()); 160 recurTarget.setMinute(temp.getMinute()); 161 recurTarget.setSecond(temp.getSeconds(), temp.getMilli()); 162 recurTarget.setZone(temp.getZoneHour(), temp.getZoneMinute()); 163 recurTarget.isUTC(); 164 } catch (Exception ex) { 165 // -- ignore for now 166 } 167 } // -- setValue 168 169 public void resetValue(Object target) throws java.lang.IllegalStateException { 170 // Nothing to do? 171 } 172 173 /** 174 * Checks the field validity. Returns successfully if the field can be stored, is valid, etc, 175 * throws an exception otherwise. 176 * 177 * @param object The object 178 * @throws ValidityException The field is invalid, is required and null, or any other validity 179 * violation 180 * @throws IllegalStateException The Java object has changed and is no longer supported by this 181 * handler, or the handler is not compatiable with the Java object 182 */ 183 public void checkValidity(Object object) throws ValidityException, IllegalStateException { 184 // nothing to do? 185 } // -- checkValidity 186 187 /** 188 * Creates a new instance of the object described by this field. 189 * 190 * @param parent The object for which the field is created 191 * @return A new instance of the field's value 192 * @throws IllegalStateException This field is a simple type and cannot be instantiated 193 */ 194 public Object newInstance(Object parent) throws IllegalStateException { 195 return new RecurringDuration(); 196 } // -- newInstance 197 198 } // -- RecurringDurationFieldHandler 199 200 } // -- RecurringDurationValidator