KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > impl > DefaultAjaxFilterManager


1 /*
2  * Copyright 2005 Joe Walker
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 org.directwebremoting.impl;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.directwebremoting.AjaxFilter;
26 import org.directwebremoting.extend.AjaxFilterManager;
27
28 /**
29  * The default implementation of AjaxFilterManager
30  * @author Joe Walker [joe at getahead dot ltd dot uk]
31  */

32 public class DefaultAjaxFilterManager implements AjaxFilterManager
33 {
34     /* (non-Javadoc)
35      * @see org.directwebremoting.AjaxFilterManager#getAjaxFilters(java.lang.String)
36      */

37     public Iterator JavaDoc getAjaxFilters(String JavaDoc scriptname)
38     {
39         // PERFORMANCE: we could probably cache the results of these if we wanted to
40
List JavaDoc reply = new ArrayList JavaDoc();
41
42         reply.addAll(global);
43
44         List JavaDoc classBased = (List JavaDoc) classBasedMap.get(scriptname);
45         if (classBased != null)
46         {
47             reply.addAll(classBased);
48         }
49
50         reply.add(executor);
51
52         return Collections.unmodifiableList(reply).iterator();
53     }
54
55     /* (non-Javadoc)
56      * @see org.directwebremoting.AjaxFilterManager#addAjaxFilter(org.directwebremoting.AjaxFilter)
57      */

58     public void addAjaxFilter(AjaxFilter filter)
59     {
60         global.add(filter);
61     }
62
63     /* (non-Javadoc)
64      * @see org.directwebremoting.AjaxFilterManager#addAjaxFilter(org.directwebremoting.AjaxFilter, java.lang.String)
65      */

66     public void addAjaxFilter(AjaxFilter filter, String JavaDoc scriptname)
67     {
68         List JavaDoc classBased = (List JavaDoc) classBasedMap.get(scriptname);
69         if (classBased == null)
70         {
71             classBased = new ArrayList JavaDoc();
72             classBasedMap.put(scriptname, classBased);
73         }
74
75         classBased.add(filter);
76     }
77
78     /**
79      * The base filter that actually does the execution
80      */

81     private AjaxFilter executor = new ExecuteAjaxFilter();
82
83     /**
84      * The list of all global filters
85      */

86     private List JavaDoc global = new ArrayList JavaDoc();
87
88     /**
89      * The map of lists of class based filters
90      */

91     private Map JavaDoc classBasedMap = new HashMap JavaDoc();
92 }
93
Popular Tags