KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > event > DozerEventManager


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */

16 package net.sf.dozer.util.mapping.event;
17
18 import java.util.List JavaDoc;
19
20 import net.sf.dozer.util.mapping.MappingException;
21 import net.sf.dozer.util.mapping.util.MapperConstants;
22
23 /**
24  * @author garsombke.franz
25  * @author tierney.matt
26 */

27 public class DozerEventManager implements EventManagerIF {
28   private final List JavaDoc eventListeners;
29   
30   public DozerEventManager(List JavaDoc eventListeners) {
31     this.eventListeners = eventListeners;
32   }
33   
34   public void fireEvent(DozerEvent event) {
35     //If no listeners were specified, then just return.
36
if (eventListeners == null) {
37       return;
38     }
39     String JavaDoc eventType = event.getType();
40     int size = eventListeners.size();
41     for (int i = 0; i < size; i++) {
42       DozerEventListener listener = (DozerEventListener) eventListeners.get(i);
43       if(eventType.equals(MapperConstants.MAPPING_STARTED_EVENT)) {
44         listener.mappingStarted(event);
45       } else if (eventType.equals(MapperConstants.MAPPING_PRE_WRITING_DEST_VALUE)) {
46         listener.preWritingDestinationValue(event);
47       } else if (eventType.equals(MapperConstants.MAPPING_POST_WRITING_DEST_VALUE)) {
48         listener.postWritingDestinationValue(event);
49       } else if (eventType.equals(MapperConstants.MAPPING_FINISHED_EVENT)) {
50         listener.mappingFinished(event);
51       } else {
52         throw new MappingException("Unsupported event type: " + eventType);
53       }
54     }
55   }
56   
57 }
58
Popular Tags