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