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