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