| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Jetty
Revision: 3610
Author: janb
Date: 05 Sep 2008 01:35:43
Changes:| ... | ...@@ -15,14 +15,20 @@ | |
| 15 | 15 | |
| 16 | 16 | package org.mortbay.jetty.annotations.resources; |
| 17 | 17 | |
| 18 | import java.io.IOException; | |
| 19 | ||
| 18 | 20 | import javax.annotation.Resource; |
| 21 | import javax.servlet.ServletConfig; | |
| 22 | import javax.servlet.ServletException; | |
| 23 | import javax.servlet.ServletRequest; | |
| 24 | import javax.servlet.ServletResponse; | |
| 19 | 25 | |
| 20 | 26 | /** |
| 21 | 27 | * ResourceA |
| 22 | 28 | * |
| 23 | 29 | * |
| 24 | 30 | */ |
| 25 | public class ResourceA | |
| 31 | public class ResourceA implements javax.servlet.Servlet | |
| 26 | 32 | { |
| 27 | 33 | private Integer e; |
| 28 | 34 | private Integer h; |
| ... | ...@@ -82,4 +88,30 @@ | |
| 82 | 88 | { |
| 83 | 89 | System.err.println("ResourceA.x"); |
| 84 | 90 | } |
| 91 | public void destroy() | |
| 92 | { | |
| 93 | // TODO Auto-generated method stub | |
| 94 | ||
| 95 | } | |
| 96 | public ServletConfig getServletConfig() | |
| 97 | { | |
| 98 | // TODO Auto-generated method stub | |
| 99 | return null; | |
| 100 | } | |
| 101 | public String getServletInfo() | |
| 102 | { | |
| 103 | // TODO Auto-generated method stub | |
| 104 | return null; | |
| 105 | } | |
| 106 | public void init(ServletConfig arg0) throws ServletException | |
| 107 | { | |
| 108 | // TODO Auto-generated method stub | |
| 109 | ||
| 110 | } | |
| 111 | public void service(ServletRequest arg0, ServletResponse arg1) | |
| 112 | throws ServletException, IOException | |
| 113 | { | |
| 114 | // TODO Auto-generated method stub | |
| 115 | ||
| 116 | } | |
| 85 | 117 | } |
| 86 | 118 | \ No newline at end of file |
| ... | ...@@ -9,6 +9,7 @@ | |
| 9 | 9 | + JETTY-682 Added listeners and queue methods to cometd |
| 10 | 10 | + JETTY-687 Issue with servlet-mapping in dynamic servlet invoker |
| 11 | 11 | + JETTY-688 Cookie causes NumberFormatException |
| 12 | + JETTY-689 processing of non-servlet related annotations | |
| 12 | 13 | + JETTY-690 Updated XBean dependencies to XBean version 3.4.3 and Spring 2.0.5. |
| 13 | 14 | + JETTY-696 ./jetty.sh restart not working |
| 14 | 15 | + JETTY-698 org.mortbay.resource.JarResource.extract does not close JarInputStream jin |
| ... | ...@@ -268,6 +268,11 @@ | |
| 268 | 268 | { |
| 269 | 269 | for (Class clazz:_finder.getClassesForAnnotation(RunAs.class)) |
| 270 | 270 | { |
| 271 | if (!javax.servlet.Servlet.class.isAssignableFrom(clazz) && !(_pojoInstances.containsKey(clazz))) | |
| 272 | { | |
| 273 | Log.debug("Ignoring runAs notation on on-servlet class "+clazz.getName()); | |
| 274 | continue; | |
| 275 | } | |
| 271 | 276 | RunAs runAs = (RunAs)clazz.getAnnotation(RunAs.class); |
| 272 | 277 | if (runAs != null) |
| 273 | 278 | { |
| ... | ...@@ -297,7 +302,11 @@ | |
| 297 | 302 | // TODO: check that the same class does not have more than one |
| 298 | 303 | for (Method m:_finder.getMethodsForAnnotation(PostConstruct.class)) |
| 299 | 304 | { |
| 300 | ||
| 305 | if (!isServletType(m.getDeclaringClass())) | |
| 306 | { | |
| 307 | Log.debug("Ignoring "+m.getName()+" as non-servlet type"); | |
| 308 | continue; | |
| 309 | } | |
| 301 | 310 | if (m.getParameterTypes().length != 0) |
| 302 | 311 | throw new IllegalStateException(m+" has parameters"); |
| 303 | 312 | if (m.getReturnType() != Void.TYPE) |
| ... | ...@@ -321,6 +330,11 @@ | |
| 321 | 330 | |
| 322 | 331 | for (Method m: _finder.getMethodsForAnnotation(PreDestroy.class)) |
| 323 | 332 | { |
| 333 | if (!isServletType(m.getDeclaringClass())) | |
| 334 | { | |
| 335 | Log.debug("Ignoring "+m.getName()+" as non-servlet type"); | |
| 336 | continue; | |
| 337 | } | |
| 324 | 338 | if (m.getParameterTypes().length != 0) |
| 325 | 339 | throw new IllegalStateException(m+" has parameters"); |
| 326 | 340 | if (m.getReturnType() != Void.TYPE) |
| ... | ...@@ -347,6 +361,11 @@ | |
| 347 | 361 | List<Class<?>> classes = _finder.getClassesForAnnotation(Resources.class); |
| 348 | 362 | for (Class<?> clazz:classes) |
| 349 | 363 | { |
| 364 | if (!isServletType(clazz)) | |
| 365 | { | |
| 366 | Log.debug("Ignoring @Resources annotation on on-servlet type class "+clazz.getName()); | |
| 367 | continue; | |
| 368 | } | |
| 350 | 369 | //Handle Resources annotation - add namespace entries |
| 351 | 370 | Resources resources = (Resources)clazz.getAnnotation(Resources.class); |
| 352 | 371 | if (resources == null) |
| ... | ...@@ -402,6 +421,11 @@ | |
| 402 | 421 | List<Class<?>> classes = _finder.getClassesForAnnotation(Resource.class); |
| 403 | 422 | for (Class<?> clazz:classes) |
| 404 | 423 | { |
| 424 | if (!isServletType(clazz)) | |
| 425 | { | |
| 426 | Log.debug("Ignoring @Resource annotation on on-servlet type class "+clazz.getName()); | |
| 427 | continue; | |
| 428 | } | |
| 405 | 429 | //Handle Resource annotation - add namespace entries |
| 406 | 430 | Resource resource = (Resource)clazz.getAnnotation(Resource.class); |
| 407 | 431 | if (resource != null) |
| ... | ...@@ -445,6 +469,11 @@ | |
| 445 | 469 | |
| 446 | 470 | for (Method m: methods) |
| 447 | 471 | { |
| 472 | if (!isServletType(m.getDeclaringClass())) | |
| 473 | { | |
| 474 | Log.debug("Ignoring @Resource annotation on on-servlet type method "+m.getName()); | |
| 475 | continue; | |
| 476 | } | |
| 448 | 477 | /* |
| 449 | 478 | * Commons Annotations Spec 2.3 |
| 450 | 479 | * " The Resource annotation is used to declare a reference to a resource. |
| ... | ...@@ -588,6 +617,11 @@ | |
| 588 | 617 | List<Field> fields = _finder.getFieldsForAnnotation(Resource.class); |
| 589 | 618 | for (Field f: fields) |
| 590 | 619 | { |
| 620 | if (!isServletType(f.getDeclaringClass())) | |
| 621 | { | |
| 622 | Log.debug("Ignoring @Resource annotation on on-servlet type field "+f.getName()); | |
| 623 | continue; | |
| 624 | } | |
| 591 | 625 | Resource resource = (Resource)f.getAnnotation(Resource.class); |
| 592 | 626 | if (resource == null) |
| 593 | 627 | continue; |
| ... | ...@@ -686,7 +720,41 @@ | |
| 686 | 720 | } |
| 687 | 721 | } |
| 688 | 722 | } |
| 723 | ||
| 689 | 724 | |
| 725 | /** | |
| 726 | * Check if the presented method belongs to a class that is one | |
| 727 | * of the classes with which a servlet container should be concerned. | |
| 728 | * @param m | |
| 729 | * @return | |
| 730 | */ | |
| 731 | private boolean isServletType (Class c) | |
| 732 | { | |
| 733 | boolean isServlet = false; | |
| 734 | if (javax.servlet.Servlet.class.isAssignableFrom(c) || | |
| 735 | javax.servlet.Filter.class.isAssignableFrom(c) || | |
| 736 | javax.servlet.ServletContextListener.class.isAssignableFrom(c) || | |
| 737 | javax.servlet.ServletContextAttributeListener.class.isAssignableFrom(c) || | |
| 738 | javax.servlet.ServletRequestListener.class.isAssignableFrom(c) || | |
| 739 | javax.servlet.ServletRequestAttributeListener.class.isAssignableFrom(c) || | |
| 740 | javax.servlet.http.HttpSessionListener.class.isAssignableFrom(c) || | |
| 741 | javax.servlet.http.HttpSessionAttributeListener.class.isAssignableFrom(c) || | |
| 742 | (_pojoInstances.get(c) != null)) | |
| 743 | ||
| 744 | isServlet=true; | |
| 745 | ||
| 746 | return isServlet; | |
| 747 | } | |
| 748 | ||
| 749 | ||
| 750 | /** | |
| 751 | * Get an already-created instance of a pojo, or create one | |
| 752 | * otherwise. | |
| 753 | * @param clazz | |
| 754 | * @return | |
| 755 | * @throws InstantiationException | |
| 756 | * @throws IllegalAccessException | |
| 757 | */ | |
| 690 | 758 | private Object getPojoInstanceFor (Class clazz) |
| 691 | 759 | throws InstantiationException, IllegalAccessException |
| 692 | 760 | { |