1 //========================================================================
2 //$Id: RunAsCollection.java 1604 2007-02-15 12:49:23Z janb $
3 //Copyright 2006 Mort Bay Consulting Pty. Ltd.
4 //------------------------------------------------------------------------
5 //Licensed under the Apache License, Version 2.0 (the "License");
6 //you may not use this file except in compliance with the License.
7 //You may obtain a copy of the License at
8 //http://www.apache.org/licenses/LICENSE-2.0
9 //Unless required by applicable law or agreed to in writing, software
10 //distributed under the License is distributed on an "AS IS" BASIS,
11 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //See the License for the specific language governing permissions and
13 //limitations under the License.
14 //========================================================================
15
16 package org.mortbay.jetty.plus.annotation;
17
18 import java.util.HashMap;
19
20 import org.mortbay.jetty.servlet.ServletHolder;
21 import org.mortbay.log.Log;
22
23
24 /**
25 * RunAsCollection
26 *
27 *
28 */
29 public class RunAsCollection
30 {
31 private HashMap _runAsMap = new HashMap();//map of classname to run-as
32
33
34 public void add (RunAs runAs)
35 {
36 if ((runAs==null) || (runAs.getTargetClass()==null))
37 return;
38
39 if (Log.isDebugEnabled())
40 Log.debug("Adding run-as for class="+runAs.getTargetClass());
41 _runAsMap.put(runAs.getTargetClass().getName(), runAs);
42 }
43
44
45 public void setRunAs (Object o)
46 {
47 if (o==null)
48 return;
49
50 if (!(o instanceof ServletHolder))
51 return;
52
53 ServletHolder holder = (ServletHolder)o;
54
55 RunAs runAs = (RunAs)_runAsMap.get(holder.getClassName());
56 if (runAs == null)
57 return;
58
59 runAs.setRunAs(holder);
60 }
61
62 }