1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.annotations;
20
21 import javax.annotation.Resource;
22 import javax.annotation.Resources;
23 import javax.naming.NamingException;
24
25 import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler;
26 import org.eclipse.jetty.util.log.Log;
27 import org.eclipse.jetty.util.log.Logger;
28 import org.eclipse.jetty.webapp.WebAppContext;
29
30 public class ResourcesAnnotationHandler extends AbstractIntrospectableAnnotationHandler
31 {
32 private static final Logger LOG = Log.getLogger(ResourcesAnnotationHandler.class);
33
34
35 protected WebAppContext _wac;
36
37 public ResourcesAnnotationHandler (WebAppContext wac)
38 {
39 super(true);
40 _wac = wac;
41 }
42
43 public void doHandle (Class<?> clazz)
44 {
45 Resources resources = (Resources)clazz.getAnnotation(Resources.class);
46 if (resources != null)
47 {
48 Resource[] resArray = resources.value();
49 if (resArray==null||resArray.length==0)
50 {
51 LOG.warn ("Skipping empty or incorrect Resources annotation on "+clazz.getName());
52 return;
53 }
54
55 for (int j=0;j<resArray.length;j++)
56 {
57 String name = resArray[j].name();
58 String mappedName = resArray[j].mappedName();
59
60 if (name==null || name.trim().equals(""))
61 throw new IllegalStateException ("Class level Resource annotations must contain a name (Common Annotations Spec Section 2.3)");
62
63 try
64 {
65
66
67 if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac, name, mappedName))
68 if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac.getServer(), name, mappedName))
69 LOG.warn("Skipping Resources(Resource) annotation on "+clazz.getName()+" for name "+name+": No resource bound at "+(mappedName==null?name:mappedName));
70 }
71 catch (NamingException e)
72 {
73 LOG.warn(e);
74 }
75 }
76 }
77 }
78
79 }