View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: PropertyManager.java,v 1.8 2002/09/11 19:12:29 ludovicc Exp $ 37 */ 38 package org.scopemvc.core; 39 40 import java.util.Iterator; 41 42 /*** 43 * <P> 44 * 45 * PropertyManager is a {@link ModelManager} that provides access to the 46 * properties of model objects. An implementation for JavaBean model objects is 47 * provided in org.scopemvc.model.beans.BeansPropertyManager. </P> 48 * 49 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 50 * @created 05 August 2002 51 * @version $Revision: 1.8 $ $Date: 2002/09/11 19:12:29 $ 52 */ 53 public abstract class PropertyManager extends ModelManager { 54 55 private static final String NAME = "PropertyManager"; 56 57 58 /*** 59 * Create an PropertyManager for the model class 60 * 61 * @param inModelClass The model class 62 * @return The PropertyManager instance 63 */ 64 public static PropertyManager getInstance(Class inModelClass) { 65 return (PropertyManager) make(NAME, inModelClass); 66 } 67 68 69 /*** 70 * Create an PropertyManager for the model 71 * 72 * @param inModel The model 73 * @return The PropertyManager instance 74 */ 75 public static PropertyManager getInstance(Object inModel) { 76 if (inModel == null) { 77 throw new IllegalArgumentException("Can't create a PropertyManager for null"); 78 } 79 return getInstance(inModel.getClass()); 80 } 81 82 83 /*** 84 * <P> 85 * 86 * Return the value of the property identified by the passed {@link 87 * Selector}. If the passed Selector is null, return the model object 88 * itself. </P> 89 * 90 * @param inModel model to get property from 91 * @param inSelector identify the property to be returned or null for the 92 * model object itself. 93 * @return value of selected property 94 * @throws Exception If the value of the property could not be retrieved 95 */ 96 public abstract Object get(Object inModel, Selector inSelector) 97 throws Exception; 98 99 100 /*** 101 * <P> 102 * 103 * Is a property read-only? If the passed Selector is null then is the model 104 * object as a whole read-only? </P> <P> 105 * 106 * Enforcement of the access state must be implemented by the model itself. 107 * </P> 108 * 109 * @param inModel model object to test the property on. 110 * @param inSelector The property to test or null to test the whole model 111 * object. 112 * @return whether the property is read-only or not. 113 * @throws Exception If the read-only state of the property could not be 114 * tested 115 */ 116 public abstract boolean isReadOnly(Object inModel, Selector inSelector) 117 throws Exception; 118 119 120 /*** 121 * Return the Class of a property. 122 * 123 * @param inModel model to test the property for. 124 * @param inSelector property to test. 125 * @return Class of property. Never null. 126 * @throws Exception If the class of the property could not be retrieved 127 */ 128 public abstract Class getPropertyClass(Object inModel, Selector inSelector) 129 throws Exception; 130 131 132 /*** 133 * <P> 134 * 135 * Return an Iterator that iterates over Selectors for all properties of the 136 * passed model object. </P> 137 * 138 * @param inModel model to make an Iterator for. 139 * @return Iterator that iterates over Selectors for all properties of the 140 * passed model object. 141 */ 142 public abstract Iterator getSelectorIterator(Object inModel); 143 144 145 /*** 146 * Return a Selector that would get() a property equals() to the passed 147 * Object. Guaranteed to work only for non-primitive properties. 148 * 149 * @param inProperty the property Object to find. 150 * @param inModel the model to get the property from. 151 * @return a Selector that would return an Object equals() to the passed 152 * property, or null if not found. 153 */ 154 public abstract Selector getSelectorFor(Object inModel, Object inProperty); 155 156 157 /*** 158 * <P> 159 * 160 * Set the value of the property identified by a {@link Selector} in the 161 * passed model object to a new value. </P> <P> 162 * 163 * The implementation should not set the value if the new value has the same 164 * Object reference as the original. It could also avoid setting the value 165 * if the new value is equivalent to the old value, and the value is of an 166 * immutable Class (like Integer, String). Otherwise the property must be 167 * set to the new value, even if it equals() the old value. </P> <P> 168 * 169 * Usually, a {@link ModelChangeEvent} for {@link 170 * ModelChangeEvent#VALUE_CHANGED} should be broadcast by the model when the 171 * property is set so that interested listeners know that the model's state 172 * has changed. </P> <P> 173 * 174 * If the property is a sub-model object then the parent model should be 175 * registered as a {@link ModelChangeListener} to be able to propagate 176 * events properly. This propagation is partially implemented in {@link 177 * org.scopemvc.model.basic.BasicModel} but it relies on child Models being 178 * listened to by their parent. (Note: deregister from the old Model then 179 * register with the new one). See the sample code for examples using {@link 180 * org.scopemvc.model.basic.BasicModel#listenNewSubmodel} and {@link 181 * org.scopemvc.model.basic.BasicModel#unlistenOldSubmodel}. </P> 182 * 183 * @param inModel model to set the property on. 184 * @param inSelector identify the property to be set. Can't be null. 185 * @param inValue the value to set the property to. 186 * @throws Exception if the value could not be set in the model 187 */ 188 public abstract void set(Object inModel, Selector inSelector, Object inValue) 189 throws Exception; 190 191 192 /*** 193 * Does the passed model object contain the property identified by the 194 * passed Selector? 195 * 196 * @param inModel model to test the property for. 197 * @param inSelector property to test. 198 * @return true if the property exists on the passed model. 199 */ 200 public abstract boolean hasProperty(Object inModel, Selector inSelector); 201 } 202

This page was automatically generated by Maven