001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.beanutils2; 019 020/** 021 * <p> 022 * A specialized extension to {@code DynaClass} that allows properties to be added or removed dynamically. 023 * </p> 024 * 025 * <p> 026 * <strong>WARNING</strong> - No guarantees that this will be in the final APIs ... it's here primarily to preserve some concepts that were in the original 027 * proposal for further discussion. 028 * </p> 029 */ 030 031public interface MutableDynaClass extends DynaClass { 032 033 /** 034 * Add a new dynamic property with no restrictions on data type, readability, or writeability. 035 * 036 * @param name Name of the new dynamic property 037 * @throws IllegalArgumentException if name is null 038 * @throws IllegalStateException if this DynaClass is currently restricted, so no new properties can be added 039 */ 040 void add(String name); 041 042 /** 043 * Add a new dynamic property with the specified data type, but with no restrictions on readability or writeability. 044 * 045 * @param name Name of the new dynamic property 046 * @param type Data type of the new dynamic property (null for no restrictions) 047 * @throws IllegalArgumentException if name is null 048 * @throws IllegalStateException if this DynaClass is currently restricted, so no new properties can be added 049 */ 050 void add(String name, Class<?> type); 051 052 /** 053 * Add a new dynamic property with the specified data type, readability, and writeability. 054 * 055 * @param name Name of the new dynamic property 056 * @param type Data type of the new dynamic property (null for no restrictions) 057 * @param readable Set to {@code true} if this property value should be readable 058 * @param writable Set to {@code true} if this property value should be writable 059 * @throws IllegalArgumentException if name is null 060 * @throws IllegalStateException if this DynaClass is currently restricted, so no new properties can be added 061 */ 062 void add(String name, Class<?> type, boolean readable, boolean writable); 063 064 /** 065 * Is this DynaClass currently restricted, if so, no changes to the existing registration of property names, data types, readability, or writeability are 066 * allowed. 067 * 068 * @return {@code true} if this Mutable {@link DynaClass} is restricted, otherwise {@code false} 069 */ 070 boolean isRestricted(); 071 072 /** 073 * Remove the specified dynamic property, and any associated data type, readability, and writeability, from this dynamic class. <strong>NOTE</strong> - This 074 * does <strong>NOT</strong> cause any corresponding property values to be removed from DynaBean instances associated with this DynaClass. 075 * 076 * @param name Name of the dynamic property to remove 077 * @throws IllegalArgumentException if name is null 078 * @throws IllegalStateException if this DynaClass is currently restricted, so no properties can be removed 079 */ 080 void remove(String name); 081 082 /** 083 * Sets the restricted state of this DynaClass to the specified value. 084 * 085 * @param restricted The new restricted state 086 */ 087 void setRestricted(boolean restricted); 088 089}