1 // ======================================================================== 2 // Copyright (c) 2010 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // The Eclipse Public License is available at 8 // http://www.eclipse.org/legal/epl-v10.html 9 // The Apache License v2.0 is available at 10 // http://www.opensource.org/licenses/apache2.0.php 11 // You may elect to redistribute this code under either of these licenses. 12 // ======================================================================== 13 14 package org.eclipse.jetty.webapp; 15 16 import org.eclipse.jetty.util.Loader; 17 import org.eclipse.jetty.util.log.Log; 18 19 /** 20 * DiscoveredAnnotation 21 * 22 * Represents an annotation that has been discovered 23 * by scanning source code of WEB-INF/classes and WEB-INF/lib jars. 24 * 25 */ 26 public abstract class DiscoveredAnnotation 27 { 28 protected WebAppContext _context; 29 protected String _className; 30 protected Class _clazz; 31 32 public abstract void apply(); 33 34 public DiscoveredAnnotation (WebAppContext context, String className) 35 { 36 _context = context; 37 _className = className; 38 } 39 40 41 public Class getTargetClass() 42 { 43 if (_clazz != null) 44 return _clazz; 45 46 loadClass(); 47 48 return _clazz; 49 } 50 51 private void loadClass () 52 { 53 if (_clazz != null) 54 return; 55 56 if (_className == null) 57 return; 58 59 try 60 { 61 _clazz = Loader.loadClass(null, _className); 62 } 63 catch (Exception e) 64 { 65 Log.warn(e); 66 } 67 } 68 }