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.servlet.config; 020 021import java.util.HashMap; 022 023import javax.servlet.Filter; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeMap; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.webengine.jaxrs.BundleNotFoundException; 029import org.nuxeo.ecm.webengine.jaxrs.Utils; 030import org.nuxeo.ecm.webengine.jaxrs.Utils.ClassRef; 031 032/** 033 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 034 */ 035@XObject("filter") 036public class FilterDescriptor { 037 038 @XNode("@class") 039 protected String classRef; 040 041 @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class, trim = true, nullByDefault = false) 042 protected HashMap<String, String> initParams; 043 044 private ClassRef ref; 045 046 public ClassRef getClassRef() throws ClassNotFoundException, BundleNotFoundException { 047 if (ref == null) { 048 ref = Utils.getClassRef(classRef); 049 } 050 return ref; 051 } 052 053 public String getRawClassRef() { 054 return classRef; 055 } 056 057 public Filter getFilter() throws ReflectiveOperationException, BundleNotFoundException { 058 return (Filter) getClassRef().get().newInstance(); 059 } 060 061 public HashMap<String, String> getInitParams() { 062 return initParams; 063 } 064 065 @Override 066 public String toString() { 067 return classRef + " " + initParams; 068 } 069}