KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > method > EventMethod


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/EventMethod.java,v 1.4 2004/08/05 14:43:29 dflorey Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/08/05 14:43:29 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.webdav.method;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.slide.common.NamespaceAccessToken;
31 import org.apache.slide.event.EventDispatcher;
32 import org.apache.slide.event.GenericEvent;
33 import org.apache.slide.event.VetoException;
34 import org.apache.slide.webdav.WebdavException;
35 import org.apache.slide.webdav.WebdavServletConfig;
36 import org.apache.slide.webdav.util.NotificationConstants;
37 import org.apache.slide.webdav.util.WebdavStatus;
38 import org.jdom.Element;
39
40
41 /**
42  * Unsubscribe Method.
43  *
44  */

45 public class EventMethod extends AbstractWebdavMethod implements NotificationConstants {
46     protected static final String JavaDoc LOG_CHANNEL = EventMethod.class.getName();
47
48     private List JavaDoc eventsToFire = new ArrayList JavaDoc();
49     private List JavaDoc vetoableEventsToFire = new ArrayList JavaDoc();
50
51     /**
52      * Constructor.
53      *
54      * @param token the token for accessing the namespace
55      * @param config configuration of the WebDAV servlet
56      */

57     public EventMethod(NamespaceAccessToken token,
58                          WebdavServletConfig config) {
59         super(token, config);
60     }
61     
62     protected void parseRequest() throws WebdavException {
63         try {
64             List JavaDoc events = parseRequestContent(E_FIRE_EVENTS).getChildren();
65             for ( Iterator JavaDoc i = events.iterator(); i.hasNext(); ) {
66                 Element event = (Element)i.next();
67                 // get information
68
List JavaDoc informations = event.getChildren();
69                 String JavaDoc[][] eventInformation = new String JavaDoc[informations.size()][2];
70                 int counter = 0;
71                 for ( Iterator JavaDoc j = informations.iterator(); j.hasNext(); ) {
72                     Element information = (Element)j.next();
73                     eventInformation[counter][0] = information.getAttributeValue(A_INFORMATION_KEY);
74                     eventInformation[counter][1] = information.getText();
75                     counter++;
76                 }
77                 if ( event.getName().equals(E_EVENT) ) {
78                     eventsToFire.add(new GenericEvent(this, eventInformation));
79                 } else if ( event.getName().equals(E_VETOABLE_EVENT) ) {
80                     vetoableEventsToFire.add(new GenericEvent(this, eventInformation));
81                 }
82             }
83         } catch (Exception JavaDoc e) {
84             int statusCode = getErrorCode( (Exception JavaDoc)e );
85             sendError( statusCode, e );
86             throw new WebdavException( statusCode );
87         }
88     }
89
90     protected void executeRequest() throws WebdavException {
91         try {
92             // FIXME: Generate multi status output to give detailed information about every fired event
93
if ( GenericEvent.EVENT_FIRED.isEnabled() ) {
94                 for ( Iterator JavaDoc i = eventsToFire.iterator(); i.hasNext(); ) {
95                     GenericEvent event = (GenericEvent)i.next();
96                     EventDispatcher.getInstance().fireEvent(GenericEvent.EVENT_FIRED, event);
97                 }
98             }
99             if ( GenericEvent.VETOABLE_EVENT_FIRED.isEnabled() ) {
100                 for ( Iterator JavaDoc i = vetoableEventsToFire.iterator(); i.hasNext(); ) {
101                     GenericEvent event = (GenericEvent)i.next();
102                     try {
103                         EventDispatcher.getInstance().fireVetoableEvent(GenericEvent.VETOABLE_EVENT_FIRED, event);
104                     } catch ( VetoException exception ) {
105                         // add to multiresponse
106
}
107                 }
108             }
109             resp.setStatus(WebdavStatus.SC_OK);
110         } catch (Exception JavaDoc e) {
111             int statusCode = getErrorCode( (Exception JavaDoc)e );
112             sendError( statusCode, e );
113             throw new WebdavException( statusCode );
114         }
115     }
116 }
Popular Tags