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