View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.beanutils2;
19  
20  /**
21   * <p>
22   * A specialized extension to {@code DynaClass} that allows properties to be added or removed dynamically.
23   * </p>
24   *
25   * <p>
26   * <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
27   * proposal for further discussion.
28   * </p>
29   */
30  
31  public interface MutableDynaClass extends DynaClass {
32  
33      /**
34       * Add a new dynamic property with no restrictions on data type, readability, or writeability.
35       *
36       * @param name Name of the new dynamic property
37       * @throws IllegalArgumentException if name is null
38       * @throws IllegalStateException    if this DynaClass is currently restricted, so no new properties can be added
39       */
40      void add(String name);
41  
42      /**
43       * Add a new dynamic property with the specified data type, but with no restrictions on readability or writeability.
44       *
45       * @param name Name of the new dynamic property
46       * @param type Data type of the new dynamic property (null for no restrictions)
47       * @throws IllegalArgumentException if name is null
48       * @throws IllegalStateException    if this DynaClass is currently restricted, so no new properties can be added
49       */
50      void add(String name, Class<?> type);
51  
52      /**
53       * Add a new dynamic property with the specified data type, readability, and writeability.
54       *
55       * @param name     Name of the new dynamic property
56       * @param type     Data type of the new dynamic property (null for no restrictions)
57       * @param readable Set to {@code true} if this property value should be readable
58       * @param writable Set to {@code true} if this property value should be writable
59       * @throws IllegalArgumentException if name is null
60       * @throws IllegalStateException    if this DynaClass is currently restricted, so no new properties can be added
61       */
62      void add(String name, Class<?> type, boolean readable, boolean writable);
63  
64      /**
65       * Is this DynaClass currently restricted, if so, no changes to the existing registration of property names, data types, readability, or writeability are
66       * allowed.
67       *
68       * @return {@code true} if this Mutable {@link DynaClass} is restricted, otherwise {@code false}
69       */
70      boolean isRestricted();
71  
72      /**
73       * Remove the specified dynamic property, and any associated data type, readability, and writeability, from this dynamic class. <strong>NOTE</strong> - This
74       * does <strong>NOT</strong> cause any corresponding property values to be removed from DynaBean instances associated with this DynaClass.
75       *
76       * @param name Name of the dynamic property to remove
77       * @throws IllegalArgumentException if name is null
78       * @throws IllegalStateException    if this DynaClass is currently restricted, so no properties can be removed
79       */
80      void remove(String name);
81  
82      /**
83       * Sets the restricted state of this DynaClass to the specified value.
84       *
85       * @param restricted The new restricted state
86       */
87      void setRestricted(boolean restricted);
88  
89  }