View Javadoc

1   /*
2    * $Id: PlugInConfig.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.config;
19  
20  import java.io.Serializable;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /***
26   * <p>A JavaBean representing the configuration information of a
27   * <code>&lt;plug-in&gt;</code> element in a Struts configuration file.</p>
28   * <p>Note that this class does not extend <code>BaseConfig</code> because it
29   * is more "internal" than the other classes which do, and because this class
30   * has an existing "properties" object which collides with the one in
31   * <code>BaseConfig</code>.  Also, since one always writes a concrete PlugIn
32   * implementation, there seems to be less call for an arbitrary property map;
33   * one can simply use bean properties instead.</p>
34   *
35   * @version $Rev: 421119 $ $Date: 2005-05-12 18:41:19 -0400 (Thu, 12 May 2005)
36   *          $
37   * @since Struts 1.1
38   */
39  public class PlugInConfig implements Serializable {
40      // ----------------------------------------------------- Instance Variables
41  
42      /***
43       * Has this component been completely configured?
44       */
45      protected boolean configured = false;
46  
47      /***
48       * A <code>Map</code> of the name-value pairs that will be used to
49       * configure the property values of a <code>PlugIn</code> instance.
50       */
51      protected Map properties = new HashMap();
52  
53      // ------------------------------------------------------------- Properties
54  
55      /***
56       * The fully qualified Java class name of the <code>PlugIn</code>
57       * implementation class being configured.
58       */
59      protected String className = null;
60  
61      public String getClassName() {
62          return (this.className);
63      }
64  
65      public void setClassName(String className) {
66          this.className = className;
67      }
68  
69      // --------------------------------------------------------- Public Methods
70  
71      /***
72       * Add a new property name and value to the set that will be used to
73       * configure the <code>PlugIn</code> instance.
74       *
75       * @param name  Property name
76       * @param value Property value
77       */
78      public void addProperty(String name, String value) {
79          if (configured) {
80              throw new IllegalStateException("Configuration is frozen");
81          }
82  
83          properties.put(name, value);
84      }
85  
86      /***
87       * Freeze the configuration of this component.
88       */
89      public void freeze() {
90          configured = true;
91      }
92  
93      /***
94       * Return the properties that will be used to configure a
95       * <code>PlugIn</code> instance.
96       */
97      public Map getProperties() {
98          return (properties);
99      }
100 }