1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.plus.annotation;
15
16 import java.util.HashMap;
17
18 import javax.servlet.ServletException;
19
20 import org.eclipse.jetty.servlet.ServletHolder;
21 import org.eclipse.jetty.util.log.Log;
22 import org.eclipse.jetty.util.log.Logger;
23
24
25
26
27
28
29
30 public class RunAsCollection
31 {
32 private static final Logger LOG = Log.getLogger(RunAsCollection.class);
33
34 public static final String RUNAS_COLLECTION = "org.eclipse.jetty.runAsCollection";
35 private HashMap<String, RunAs> _runAsMap = new HashMap<String, RunAs>();
36
37
38
39 public void add (RunAs runAs)
40 {
41 if ((runAs==null) || (runAs.getTargetClassName()==null))
42 return;
43
44 if (LOG.isDebugEnabled())
45 LOG.debug("Adding run-as for class="+runAs.getTargetClassName());
46 _runAsMap.put(runAs.getTargetClassName(), runAs);
47 }
48
49 public RunAs getRunAs (Object o)
50 throws ServletException
51 {
52 if (o==null)
53 return null;
54
55 return (RunAs)_runAsMap.get(o.getClass().getCanonicalName());
56 }
57
58 public void setRunAs(Object o)
59 throws ServletException
60 {
61 if (o == null)
62 return;
63
64 if (!ServletHolder.class.isAssignableFrom(o.getClass()))
65 return;
66
67 RunAs runAs = (RunAs)_runAsMap.get(o.getClass().getName());
68 if (runAs == null)
69 return;
70
71 runAs.setRunAs((ServletHolder)o);
72 }
73
74 }