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