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 *      https://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.beanutils;
019
020/**
021 * <p>A specialized extension to <code>DynaClass</code> that allows properties
022 * to be added or removed dynamically.</p>
023 *
024 * <p><strong>WARNING</strong> - No guarantees that this will be in the final
025 * APIs ... it's here primarily to preserve some concepts that were in the
026 * original proposal for further discussion.</p>
027 *
028 */
029
030public interface MutableDynaClass extends DynaClass {
031
032    /**
033     * Add a new dynamic property with no restrictions on data type,
034     * 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
039     *  restricted, so no new properties can be added
040     */
041    void add(String name);
042
043    /**
044     * Add a new dynamic property with the specified data type, but with
045     * no restrictions on readability or writeability.
046     *
047     * @param name Name of the new dynamic property
048     * @param type Data type of the new dynamic property (null for no
049     *  restrictions)
050     *
051     * @throws IllegalArgumentException if name is null
052     * @throws IllegalStateException if this DynaClass is currently
053     *  restricted, so no new properties can be added
054     */
055    void add(String name, Class<?> type);
056
057    /**
058     * Add a new dynamic property with the specified data type, readability,
059     * and writeability.
060     *
061     * @param name Name of the new dynamic property
062     * @param type Data type of the new dynamic property (null for no
063     *  restrictions)
064     * @param readable Set to <code>true</code> if this property value
065     *  should be readable
066     * @param writeable Set to <code>true</code> if this property value
067     *  should be writeable
068     *
069     * @throws IllegalArgumentException if name is null
070     * @throws IllegalStateException if this DynaClass is currently
071     *  restricted, so no new properties can be added
072     */
073    void add(String name, Class<?> type, boolean readable,
074                    boolean writeable);
075
076    /**
077     * Is this DynaClass currently restricted, if so, no changes to the
078     * existing registration of property names, data types, readability, or
079     * writeability are allowed.
080     *
081     * @return <code>true</code> if this Mutable {@link DynaClass} is restricted,
082     * otherwise <code>false</code>
083     */
084    boolean isRestricted();
085
086    /**
087     * Remove the specified dynamic property, and any associated data type,
088     * readability, and writeability, from this dynamic class.
089     * <strong>NOTE</strong> - This does <strong>NOT</strong> cause any
090     * corresponding property values to be removed from DynaBean instances
091     * associated with this DynaClass.
092     *
093     * @param name Name of the dynamic property to remove
094     * @throws IllegalArgumentException if name is null
095     * @throws IllegalStateException if this DynaClass is currently
096     *  restricted, so no properties can be removed
097     */
098    void remove(String name);
099
100    /**
101     * Set the restricted state of this DynaClass to the specified value.
102     *
103     * @param restricted The new restricted state
104     */
105    void setRestricted(boolean restricted);
106
107}