001 // Copyright 2011 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.plastic;
016
017 /**
018 * Allows read/write access directly to a field (bypassing accessors). Does not use reflection, even
019 * if the field is private (the normal case for Plastic classes).
020 */
021 public interface FieldHandle
022 {
023 /**
024 * Gets the current value of the field. If the field is a primitive value, then the primitive
025 * will be wrapped.
026 *
027 * @throws NullPointerException
028 * if the instance is null
029 * @throws ClassCastException
030 * if the instance is not the type that contains the field
031 */
032 Object get(Object instance);
033
034 /**
035 * Updates the current value of the field. If the field is a primitive value, then the newValue
036 * will be unwrapped automatically.
037 *
038 * @throws NullPointerException
039 * if the instance is null
040 * @throws NullPointerException
041 * if the newValue is null and the field is a primitive type
042 * @throws ClassCastException
043 * if the instance is not the type that contains the field
044 * @throws ClassCastException
045 * if the newValue is not assignable to the field type (or not the matching wrapper type
046 * for a primitive field)
047 */
048 void set(Object instance, Object newValue);
049 }