-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
4,401 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...test/resources/oracle/commits/jetty.project-fc5dd874f3deda71e6cd42af994a5af5cb6be4af.json
Large diffs are not rendered by default.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
...jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationIntrospector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.annotations; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* AnnotationIntrospector | ||
* | ||
* | ||
*/ | ||
public class AnnotationIntrospector | ||
{ | ||
protected List<IntrospectableAnnotationHandler> _handlers = new ArrayList<IntrospectableAnnotationHandler>(); | ||
|
||
|
||
/** | ||
* IntrospectableAnnotationHandler | ||
* | ||
* Interface for all handlers that wish to introspect a class to find a particular annotation | ||
*/ | ||
public interface IntrospectableAnnotationHandler | ||
{ | ||
public void handle(Class<?> clazz); | ||
} | ||
|
||
|
||
|
||
/** | ||
* AbstractIntrospectableAnnotationHandler | ||
* | ||
* Base class for handlers that introspect a class to find a particular annotation. | ||
* A handler can optionally introspect the parent hierarchy of a class. | ||
*/ | ||
public static abstract class AbstractIntrospectableAnnotationHandler implements IntrospectableAnnotationHandler | ||
{ | ||
private boolean _introspectAncestors; | ||
|
||
public abstract void doHandle(Class<?> clazz); | ||
|
||
|
||
public AbstractIntrospectableAnnotationHandler(boolean introspectAncestors) | ||
{ | ||
_introspectAncestors = introspectAncestors; | ||
} | ||
|
||
@Override | ||
public void handle(Class<?> clazz) | ||
{ | ||
Class<?> c = clazz; | ||
|
||
//process the whole inheritance hierarchy for the class | ||
while (c!=null && (!c.equals(Object.class))) | ||
{ | ||
doHandle(c); | ||
if (!_introspectAncestors) | ||
break; | ||
|
||
c = c.getSuperclass(); | ||
} | ||
} | ||
} | ||
|
||
public void registerHandler (IntrospectableAnnotationHandler handler) | ||
{ | ||
_handlers.add(handler); | ||
} | ||
|
||
public void introspect (Class<?> clazz) | ||
{ | ||
if (_handlers == null) | ||
return; | ||
if (clazz == null) | ||
return; | ||
|
||
for (IntrospectableAnnotationHandler handler:_handlers) | ||
{ | ||
try | ||
{ | ||
handler.handle(clazz); | ||
} | ||
catch (RuntimeException e) | ||
{ | ||
throw e; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.