001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.webengine.jaxrs.scan; 013 014import java.io.IOException; 015import java.util.ArrayList; 016import java.util.List; 017import java.util.Set; 018 019import org.objectweb.asm.AnnotationVisitor; 020import org.objectweb.asm.ClassVisitor; 021import org.objectweb.asm.Opcodes; 022 023/** 024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 025 */ 026public class AnnotationReader extends ClassVisitor { 027 028 protected Set<String> annotations; 029 030 protected List<String> results; 031 032 protected String cname; 033 034 public AnnotationReader(Set<String> annotations) throws IOException { 035 super(Opcodes.ASM5); 036 results = new ArrayList<String>(); 037 this.annotations = annotations; 038 } 039 040 public String getClassName() { 041 return cname.replace('/', '.'); 042 } 043 044 public String getFileName() { 045 return cname; 046 } 047 048 public List<String> getResults() { 049 return results; 050 } 051 052 public boolean hasResults() { 053 return !results.isEmpty(); 054 } 055 056 @Override 057 public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { 058 cname = name; 059 } 060 061 @Override 062 public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { 063 if (annotations.contains(arg0)) { 064 results.add(arg0); 065 } 066 return null; 067 } 068 069}