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.webapp.WebAppContext;
23
24 public class ResourcesAnnotationHandler extends AbstractIntrospectableAnnotationHandler
25 {
26
27 protected WebAppContext _wac;
28
29 public ResourcesAnnotationHandler (WebAppContext wac)
30 {
31 super(true);
32 _wac = wac;
33 }
34
35 public void doHandle (Class clazz)
36 {
37 Resources resources = (Resources)clazz.getAnnotation(Resources.class);
38 if (resources != null)
39 {
40 Resource[] resArray = resources.value();
41 if (resArray==null||resArray.length==0)
42 {
43 Log.warn ("Skipping empty or incorrect Resources annotation on "+clazz.getName());
44 return;
45 }
46
47 for (int j=0;j<resArray.length;j++)
48 {
49
50 String name = resArray[j].name();
51 String mappedName = resArray[j].mappedName();
52 Resource.AuthenticationType auth = resArray[j].authenticationType();
53 Class type = resArray[j].type();
54 boolean shareable = resArray[j].shareable();
55
56 if (name==null || name.trim().equals(""))
57 throw new IllegalStateException ("Class level Resource annotations must contain a name (Common Annotations Spec Section 2.3)");
58
59 try
60 {
61
62
63 if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac, name, mappedName))
64 if (!org.eclipse.jetty.plus.jndi.NamingEntryUtil.bindToENC(_wac.getServer(), name, mappedName))
65 Log.warn("Skipping Resources(Resource) annotation on "+clazz.getName()+" for name "+name+": No resource bound at "+(mappedName==null?name:mappedName));
66 }
67 catch (NamingException e)
68 {
69 Log.warn(e);
70 }
71 }
72 }
73 }
74
75 }