KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > PropertyChangeEvent


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.properties;
21
22 import com.sslexplorer.boot.PropertyDefinition;
23 import com.sslexplorer.core.CoreAttributeConstants;
24 import com.sslexplorer.core.CoreEvent;
25 import com.sslexplorer.core.CoreEventConstants;
26 import com.sslexplorer.properties.impl.profile.ProfileProperties;
27 import com.sslexplorer.security.SessionInfo;
28
29 /**
30  * Event fired when a property stored in the {@link com.sslexplorer.properties.PropertyDatabase}
31  * is changed.
32  *
33  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
34  */

35 public class PropertyChangeEvent extends CoreEvent {
36
37     // Private instance variables
38

39     private String JavaDoc oldValue;
40     private String JavaDoc newValue;
41     private PropertyProfile profile;
42     
43     /**
44      * Constructor
45      *
46      * @param source source of event
47      * @param def definition of property that has changed
48      * @param session the session were the property change occured or <code>null</code> if the change was not user initiated
49      * @param oldValue old value of property
50      * @param newValue new value of property
51      * @param state event state. Can be one of {@link CoreEvent#STATE_SUCCESSFUL} or {@link CoreEvent#STATE_UNSUCCESSFUL}
52      */

53     public PropertyChangeEvent(Object JavaDoc source, PropertyDefinition def, SessionInfo session, String JavaDoc oldValue, String JavaDoc newValue, int state) {
54         this(source, CoreEventConstants.PROPERTY_CHANGED, def, session, oldValue, newValue, state);
55     }
56
57     
58     /**
59      * Constructor
60      *
61      * @param source source of event
62      * @param code event code
63      * @param def definition of property that has changed
64      * @param session the session were the property change occured or <code>null</code> if the change was not user initiated
65      * @param oldValue old value of property
66      * @param newValue new value of property
67      * @param state event state. Can be one of {@link CoreEvent#STATE_SUCCESSFUL} or {@link CoreEvent#STATE_UNSUCCESSFUL}
68      */

69     public PropertyChangeEvent(Object JavaDoc source, int code, PropertyDefinition def, SessionInfo session, String JavaDoc oldValue, String JavaDoc newValue, int state) {
70         this(source, code, def, session, null, oldValue, newValue, state);
71     }
72
73     
74     /**
75      * Constructor
76      *
77      * @param source source of event
78      * @param code event code
79      * @param def definition of property that has changed
80      * @param session the session were the property change occured or <code>null</code> if the change was not user initiated
81      * @param profile property profile that change
82      * @param oldValue old value of property
83      * @param newValue new value of property
84      * @param state event state. Can be one of {@link CoreEvent#STATE_SUCCESSFUL} or {@link CoreEvent#STATE_UNSUCCESSFUL}
85      */

86     public PropertyChangeEvent(Object JavaDoc source, int code, PropertyDefinition def, SessionInfo session, PropertyProfile profile, String JavaDoc oldValue, String JavaDoc newValue, int state) {
87         super(source, code, def, session, state);
88         if (oldValue == null) {
89             oldValue = "";
90         }
91         this.oldValue = oldValue;
92         this.newValue = newValue;
93         this.addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_CLASS, def.getPropertyClass().getName());
94         this.addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_OLD_VALUE, oldValue == null ? def.getDefaultValue() : oldValue);
95         this.addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_NEW_VALUE, newValue);
96         this.addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_NAME, def == null ? "<unknown>" : def.getName());
97         this.profile = profile;
98         if(profile != null && def != null && def.getPropertyClass() instanceof ProfileProperties) {
99             addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_PROFILE_NAME, profile.getResourceName());
100             addAttribute(CoreAttributeConstants.EVENT_ATTR_PROPERTY_PROFILE_DESCRIPTION, profile.getResourceDescription());
101         }
102     }
103     
104     /**
105      * Get the old value of the property that was changed
106      *
107      * @return old value
108      */

109     public String JavaDoc getOldValue() {
110         return oldValue;
111     }
112     
113     /**
114      * Get the new value of the property that was changed
115      *
116      * @return new value
117      */

118     public String JavaDoc getNewValue() {
119         return newValue;
120     }
121     
122     /**
123      * Get the property definition that changed
124      *
125      * @return property definition
126      */

127     public PropertyDefinition getDefinition() {
128         return (PropertyDefinition)getParameter();
129     }
130
131 }
132
Popular Tags