KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > ConfigChangeEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.event;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import java.util.regex.Pattern JavaDoc;
37 import java.util.regex.Matcher JavaDoc;
38 import com.sun.enterprise.admin.event.AdminEvent;
39 import com.sun.enterprise.config.ConfigChange;
40
41 /**
42  * Configuration Change Event. This event is raised when one or more
43  * configuration attributes are changed. The user interface supports a feature
44  * because of which edits to configuration attributes are applied only at
45  * user request. Therefore, configuration change events can be associated to
46  * more than one configuration change.
47  */

48 public class ConfigChangeEvent extends AdminEvent {
49
50     /**
51      * Event type
52      */

53     static final String JavaDoc eventType = ConfigChangeEvent.class.getName();
54
55     /**
56      * Is web core reconfig needed.
57      */

58     private boolean webCoreReconfigNeeded = false;
59
60     /**
61      * Has init or obj conf file changed.
62      */

63     private boolean initOrObjConfChanged = false;
64
65     /**
66      * A map to track config changes that match any ConfigChangeCategory
67      * regular expression.
68      */

69     private HashMap JavaDoc matchMap;
70
71     /**
72      * Create a new ConfigChangeEvent. Every element in configChangeList should
73      * be of type com.sun.enterprise.config.ConfigChange.
74      * @param instanceName name of the instance to which this event applies
75      * @param configChangeList list of configuration attribute changes.
76      */

77     public ConfigChangeEvent(String JavaDoc instanceName,
78             ArrayList JavaDoc configChangeList) {
79         super(eventType, instanceName);
80         this.configChangeList = configChangeList;
81     }
82
83     /**
84      * Get config changes list. The list contains objects of type ConfigAdd,
85      * ConfigUpdate or ConfigDelete from package com.sun.enterprise.config (all
86      * of them are sub-classes of ConfigChange). In some cases, this event may
87      * be created by specifying null for Config change list and if no changes
88      * are added post creation by invoking package method addConfigChange then
89      * this method will return null.
90      * @return list of config changes
91      */

92     public ArrayList JavaDoc getConfigChangeList() {
93         return configChangeList;
94     }
95
96     /**
97      * Set web core reconfig needed status. Some of the changes are handled
98      * by reconfig signal in web core. Setting the status to true results in
99      * invokation of web core reconfig.
100      * @param reconfig whether web core reconfig is needed
101      */

102     void setWebCoreReconfigNeeded(boolean reconfig) {
103         webCoreReconfigNeeded = reconfig;
104     }
105
106     /**
107      * Is web core reconfig needed. Web core reconfig is needed if init.conf,
108      * obj.conf or mime type files have been changed or if server.xml elements
109      * http-service or web-container have been changed.
110      */

111     boolean isWebCoreReconfigNeeded() {
112         return webCoreReconfigNeeded;
113     }
114
115     /**
116      * Set whether init.conf or obj.conf files have changed.
117      * @param changed true if init.conf or obj.conf has changed
118      */

119     void setInitOrObjConfChanged(boolean changed) {
120         initOrObjConfChanged = changed;
121     }
122
123     /**
124      * Is init.conf or obj.conf changed. If true, then a restart will be
125      * required to handle this change.
126      */

127     boolean isInitOrObjConfChanged() {
128         return initOrObjConfChanged;
129     }
130
131     /**
132      * Match the specified regular expression pattern against all changed XPath
133      * associated to the event.
134      * @param pattern the pattern to match xpath with
135      * @return true if any xpath matches, false otherwise
136      */

137     boolean matchXPathToPattern(Pattern JavaDoc pattern) {
138         boolean match = false;
139         if (configChangeList == null) {
140             return match;
141         }
142         Iterator JavaDoc iter = configChangeList.iterator();
143         while (iter.hasNext()) {
144             ConfigChange change = (ConfigChange)iter.next();
145             String JavaDoc xpath = change.getXPath();
146             if (xpath != null) {
147                 Matcher JavaDoc matcher = pattern.matcher(xpath);
148                 match = matcher.matches();
149                 if (match) {
150                     setConfigChangeMatched(change);
151                 }
152             }
153         }
154         return match;
155     }
156
157     /**
158      * Is this event no op. A ConfigChangeEvent is no op, if it does not have
159      * any server.xml changes or if it has not been told that web core
160      * reconfig is needed.
161      */

162     boolean isNoOp() {
163         boolean isNoOp = false;
164         if (configChangeList == null && !webCoreReconfigNeeded) {
165             isNoOp = true;
166         }
167         return isNoOp;
168     }
169
170     /**
171      * Set specified config change as matched. This method is called when the
172      * change xpath matches a pattern from a ConfigChangeEvent listener.
173      * @param change the config change that contains matched xpath.
174      */

175     private void setConfigChangeMatched(ConfigChange change) {
176         synchronized (this) {
177             if (matchMap == null) {
178                 matchMap = new HashMap JavaDoc();
179             }
180         }
181         matchMap.put(change, change);
182     }
183
184     /**
185      * Is all xpath in this event matched to at least one listener. The event
186      * contains a list of config changes and if xpaths for all the changes are
187      * mactehd to at least one listener then the method returns true. If change
188      * list is empty then the method returns false.
189      */

190     boolean isAllXPathMatched() {
191         boolean matched = true;
192         if (configChangeList == null || matchMap == null) {
193             matched = false;
194             return matched;
195         }
196         Iterator JavaDoc iter = configChangeList.iterator();
197         while (iter.hasNext()) {
198             if (!matchMap.containsKey(iter.next())) {
199                 matched = false;
200                 break;
201             }
202         }
203         return matched;
204     }
205 }
206
Popular Tags