Coverage Report - org.apache.tapestry5.beaneditor.BeanModel
 
Classes in this File Line Coverage Branch Coverage Complexity
BeanModel
N/A
N/A
0
 
 1  
 // Copyright 2007, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.beaneditor;
 16  
 
 17  
 import org.apache.tapestry5.PropertyConduit;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 /**
 22  
  * Provides the information necessary to build a user interface to view, create or edit an instance of a particular
 23  
  * type.
 24  
  * <p/>
 25  
  * BeanModels are not thread-safe, they are also not serializable.
 26  
  * <p/>
 27  
  * Here, and in {@link org.apache.tapestry5.beaneditor.PropertyModel}, the term "propertyName" is used for simplicitly.
 28  
  * However, a full {@linkplain org.apache.tapestry5.services.PropertyConduitSource#create(Class, String) property
 29  
  * expression} may be utilized when {@linkplain #add(String) adding new properties to an existing BeanModel}.
 30  
  *
 31  
  * @see org.apache.tapestry5.services.BeanModelSource
 32  
  */
 33  
 public interface BeanModel<T>
 34  
 {
 35  
     /**
 36  
      * Returns the type of bean for which this model was initially created.
 37  
      */
 38  
     Class<T> getBeanType();
 39  
 
 40  
 
 41  
     /**
 42  
      * Creates a new bean instance.  This is based on {@link org.apache.tapestry5.ioc.ObjectLocator#autobuild(Class)},
 43  
      * so a public constructor will be used, and dependencies injected.
 44  
      *
 45  
      * @return new instance of the bean
 46  
      */
 47  
     T newInstance();
 48  
 
 49  
     /**
 50  
      * Returns a list of the editable properties of the bean, in <em>presentation</em> order.
 51  
      */
 52  
     List<String> getPropertyNames();
 53  
 
 54  
     /**
 55  
      * Returns the named model.
 56  
      *
 57  
      * @param propertyName name of property to retrieve model for (case is ignored)
 58  
      * @return the model for the property
 59  
      * @throws RuntimeException if the bean editor model does not have a property model for the provided name
 60  
      */
 61  
     PropertyModel get(String propertyName);
 62  
 
 63  
     /**
 64  
      * Returns the identified model.  Property ids are a stripped version of the property name. Case is ignored.
 65  
      *
 66  
      * @param propertyId matched caselessly against {@link org.apache.tapestry5.beaneditor.PropertyModel#getId()}
 67  
      * @throws RuntimeException if the bean editor model does not have a property model with the indicated id
 68  
      */
 69  
     PropertyModel getById(String propertyId);
 70  
 
 71  
     /**
 72  
      * Adds a new property to the model, returning its mutable model for further refinement. The property is added to
 73  
      * the <em>end</em> of the list of properties. The property must be real (but may have been excluded if there was no
 74  
      * {@linkplain org.apache.tapestry5.beaneditor.DataType datatype} associated with the property). To add a synthetic
 75  
      * property, use {@link #add(String, org.apache.tapestry5.PropertyConduit)}
 76  
      *
 77  
      * @param propertyName name of property to add
 78  
      * @return the new property model (for further configuration)
 79  
      * @throws RuntimeException if the property already exists
 80  
      */
 81  
     PropertyModel add(String propertyName);
 82  
 
 83  
     /**
 84  
      * Adds a new property to the model (as with {@link #add(String)}), ordered before or after an existing property.
 85  
      *
 86  
      * @param position             controls whether the new property is ordered before or after the existing property
 87  
      * @param existingPropertyName the name of an existing property (this must exist)
 88  
      * @param propertyName         the new property to add
 89  
      * @return the new property model (for further configuration)
 90  
      * @throws RuntimeException if the existing property does not exist, or if the new property already does exist
 91  
      */
 92  
     PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName);
 93  
 
 94  
     /**
 95  
      * Adds a new property to the model, ordered before or after an existing property.
 96  
      *
 97  
      * @param position             controls whether the new property is ordered before or after the existing property
 98  
      * @param existingPropertyName the name of an existing property (this must exist)
 99  
      * @param propertyName         the new property to add
 100  
      * @param conduit              conduit used to read or update the property; this may be null for a synthetic or
 101  
      *                             placeholder property
 102  
      * @return the new property model (for further configuration)
 103  
      * @throws RuntimeException if the existing property does not exist, or if the new property already does exist
 104  
      */
 105  
     PropertyModel add(RelativePosition position, String existingPropertyName, String propertyName,
 106  
                       PropertyConduit conduit);
 107  
 
 108  
     /**
 109  
      * Adds a new, synthetic property to the model, returning its mutable model for further refinement.
 110  
      *
 111  
      * @param propertyName name of property to add
 112  
      * @param conduit      the conduit used to read or update the property; this may be null for a synthetic or
 113  
      *                     placeholder property
 114  
      * @return the model for the property
 115  
      * @throws RuntimeException if the property already exists
 116  
      */
 117  
     PropertyModel add(String propertyName, PropertyConduit conduit);
 118  
 
 119  
     /**
 120  
      * Removes the named properties from the model, if present. It is not considered an error to remove a property that
 121  
      * does not exist.
 122  
      *
 123  
      * @param propertyNames the names of properties to be removed (case insensitive)
 124  
      * @return the model for further modifications
 125  
      */
 126  
     BeanModel exclude(String... propertyNames);
 127  
 
 128  
     /**
 129  
      * Re-orders the properties of the model into the specified order. Existing properties that are not indicated are
 130  
      * retained, but ordered to the end of the list.
 131  
      *
 132  
      * @param propertyNames property names in order they should be displayed (case insensitive)
 133  
      * @return the model for further modifications
 134  
      */
 135  
     BeanModel reorder(String... propertyNames);
 136  
 
 137  
     /**
 138  
      * Re-orders the properties of the model into the specified order. Existing properties that are not indicated are
 139  
      * <<removed>>.
 140  
      *
 141  
      * @param propertyNames the names of properties to be retained
 142  
      * @return the model for further modifications
 143  
      */
 144  
     BeanModel include(String... propertyNames);
 145  
 }