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.Map; 016import java.util.Set; 017 018import javax.ws.rs.core.Application; 019 020import org.nuxeo.ecm.webengine.jaxrs.ApplicationFactory; 021import org.osgi.framework.Bundle; 022 023/** 024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 025 */ 026public class DynamicApplicationFactory implements ApplicationFactory { 027 028 @Override 029 public Application getApplication(Bundle bundle, Map<String, String> args) throws ReflectiveOperationException, 030 IOException { 031 String pkg = args.get("package"); 032 if (pkg == null) { 033 pkg = "/"; 034 } 035 Scanner scanner = new Scanner(bundle, pkg); 036 scanner.scan(); 037 final Set<Class<?>> classes = scanner.getClasses(); 038 return new Application() { 039 @Override 040 public Set<Class<?>> getClasses() { 041 return classes; 042 } 043 }; 044 } 045 046}