001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.webengine.jaxrs.scan; 020 021import java.io.IOException; 022import java.util.ArrayList; 023import java.util.List; 024import java.util.Set; 025 026import org.objectweb.asm.AnnotationVisitor; 027import org.objectweb.asm.ClassVisitor; 028import org.objectweb.asm.Opcodes; 029 030/** 031 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 032 */ 033public class AnnotationReader extends ClassVisitor { 034 035 protected Set<String> annotations; 036 037 protected List<String> results; 038 039 protected String cname; 040 041 public AnnotationReader(Set<String> annotations) throws IOException { 042 super(Opcodes.ASM5); 043 results = new ArrayList<String>(); 044 this.annotations = annotations; 045 } 046 047 public String getClassName() { 048 return cname.replace('/', '.'); 049 } 050 051 public String getFileName() { 052 return cname; 053 } 054 055 public List<String> getResults() { 056 return results; 057 } 058 059 public boolean hasResults() { 060 return !results.isEmpty(); 061 } 062 063 @Override 064 public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { 065 cname = name; 066 } 067 068 @Override 069 public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { 070 if (annotations.contains(arg0)) { 071 results.add(arg0); 072 } 073 return null; 074 } 075 076}