KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > model > LDAPModelEvent


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.schemas.model;
22
23
24 /**
25  * This class is a model for creation of events related to modifications of the model elements
26  * manipulated by this application. Like when a schema is added to the pool, or when the properties
27  * of an attributeType are modified.
28  * When creating an event, the reason is mandatory, but not the originating element.
29  *
30  * @see the Reason enumeration for the complete list of supported events
31  *
32  */

33 public class LDAPModelEvent
34 {
35
36     /**
37      * This Enum is used to indicate the reason of the launch of the event.
38      *
39      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40      * @version $Rev$, $Date$
41      */

42     public enum Reason
43     {
44         SchemaAdded, SchemaRemoved, SchemaSaved, OCAdded, OCModified, OCRemoved, ATAdded, ATModified, ATRemoved, PoolReloaded
45     }
46
47     /** The reason */
48     private Reason reason;
49
50     /** The old value of the element */
51     private Object JavaDoc oldValue;
52
53     /** The new value of the element */
54     private Object JavaDoc newValue;
55
56
57     /**
58      * Creates a new instance of LDAPModelEvent.
59      *
60      * @param reason
61      * the reason
62      */

63     public LDAPModelEvent( Reason reason )
64     {
65         this.reason = reason;
66     }
67
68
69     /**
70      * Creates a new instance of LDAPModelEvent for object class motivated events.
71      *
72      * @param reason
73      * the reason (must be OCAdded, OCRemoved or OCModified)
74      * @param oldObjectClass
75      * the old object class
76      * @param newObjectClass
77      * the new object class
78      * @throws Exception
79      * if bad reason
80      */

81     public LDAPModelEvent( Reason reason, ObjectClass oldObjectClass, ObjectClass newObjectClass ) throws Exception JavaDoc
82     {
83         this( reason );
84         if ( ( reason == Reason.OCAdded ) || ( reason == Reason.OCModified ) || ( reason == Reason.OCRemoved ) )
85         {
86             newValue = newObjectClass;
87             oldValue = oldObjectClass;
88         }
89         else
90         {
91             throw new Exception JavaDoc( "Event creation exception " + reason + " " + newObjectClass ); //$NON-NLS-1$ //$NON-NLS-2$
92
}
93     }
94
95
96     /**
97      * Creates a new instance of LDAPModelEvent for attribute type motivated events.
98      *
99      * @param reason
100      * the reason (must be ATAdded, ATRemoved or ATModified)
101      * @param oldAttributeType
102      * the old attribute type
103      * @param newAttributeType
104      * the new attribute type
105      * @throws Exception
106      * if bad reason
107      */

108     public LDAPModelEvent( Reason reason, AttributeType oldAttributeType, AttributeType newAttributeType )
109         throws Exception JavaDoc
110     {
111         this( reason );
112         if ( ( reason == Reason.ATAdded ) || ( reason == Reason.ATModified ) || ( reason == Reason.ATRemoved ) )
113         {
114             newValue = newAttributeType;
115             oldValue = oldAttributeType;
116         }
117         else
118         {
119             throw new Exception JavaDoc( "Event creation exception " + reason + " " + oldAttributeType ); //$NON-NLS-1$ //$NON-NLS-2$
120
}
121     }
122
123
124     /**
125      * Creates a new instance of LDAPModelEvent for schema motivated events.
126      *
127      * @param reason
128      * the reason (must be SchemaAdded or SchemaRemoved)
129      * @param schema
130      * the associated schema
131      * @throws Exception
132      * if bad reason
133      */

134     public LDAPModelEvent( Reason reason, Schema schema ) throws Exception JavaDoc
135     {
136         this( reason );
137
138         if ( reason == Reason.SchemaAdded )
139         {
140             oldValue = null;
141             newValue = schema;
142         }
143         else if ( reason == Reason.SchemaRemoved )
144         {
145             oldValue = schema;
146             newValue = null;
147         }
148         else
149         {
150             throw new Exception JavaDoc( "Event creation exception " + reason + " " + schema ); //$NON-NLS-1$ //$NON-NLS-2$
151
}
152     }
153
154
155     /**
156      * Gets the reason of the the event.
157      *
158      * @return
159      * the reason of the event
160      */

161     public Reason getReason()
162     {
163         return reason;
164     }
165
166
167     /**
168      * Gets the new value of the element.
169      *
170      * @return
171      * the new value of the element.
172      */

173     public Object JavaDoc getNewValue()
174     {
175         return newValue;
176     }
177
178
179     /**
180      * Gets the new value of the element.
181      *
182      * @return
183      * the new value of the element.
184      */

185     public Object JavaDoc getOldValue()
186     {
187         return oldValue;
188     }
189 }
190
Popular Tags