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 import org.eclipse.jetty.util.log.Logger;
19
20 /**
21 * DiscoveredAnnotation
22 *
23 * Represents an annotation that has been discovered
24 * by scanning source code of WEB-INF/classes and WEB-INF/lib jars.
25 *
26 */
27 public abstract class DiscoveredAnnotation
28 {
29 private static final Logger LOG = Log.getLogger(DiscoveredAnnotation.class);
30
31 protected WebAppContext _context;
32 protected String _className;
33 protected Class<?> _clazz;
34
35 public abstract void apply();
36
37 public DiscoveredAnnotation (WebAppContext context, String className)
38 {
39 _context = context;
40 _className = className;
41 }
42
43
44 public Class<?> getTargetClass()
45 {
46 if (_clazz != null)
47 return _clazz;
48
49 loadClass();
50
51 return _clazz;
52 }
53
54 private void loadClass ()
55 {
56 if (_clazz != null)
57 return;
58
59 if (_className == null)
60 return;
61
62 try
63 {
64 _clazz = Loader.loadClass(null, _className);
65 }
66 catch (Exception e)
67 {
68 LOG.warn(e);
69 }
70 }
71 }