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