001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017package org.nuxeo.apidoc.snapshot;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.nuxeo.apidoc.api.SeamComponentInfo;
023import org.nuxeo.apidoc.introspection.OperationInfoImpl;
024
025public class SnapshotFilter {
026
027    protected final String bundleGroupName;
028
029    protected final List<String> bundlePrefixes = new ArrayList<String>();
030
031    protected final List<String> packagesPrefixes = new ArrayList<String>();
032
033    public SnapshotFilter(String groupName) {
034        bundleGroupName = groupName;
035    }
036
037    public String getBundleGroupName() {
038        return bundleGroupName;
039    }
040
041    public List<String> getBundlePrefixes() {
042        return bundlePrefixes;
043    }
044
045    public void addBundlePrefix(String bundlePrefix) {
046        bundlePrefixes.add(bundlePrefix);
047    }
048
049    public List<String> getPackagesPrefixes() {
050        return packagesPrefixes;
051    }
052
053    public void addPackagesPrefix(String packagesPrefix) {
054        packagesPrefixes.add(packagesPrefix);
055    }
056
057    public boolean includeBundleId(String bundleId) {
058        for (String bprefix : bundlePrefixes) {
059            if (bundleId.startsWith(bprefix)) {
060                return true;
061            }
062        }
063        return false;
064    }
065
066    public boolean includeSeamComponent(SeamComponentInfo seamComponent) {
067
068        for (String iface : seamComponent.getInterfaceNames()) {
069            for (String pprefix : packagesPrefixes) {
070                if (iface.startsWith(pprefix)) {
071                    return true;
072                }
073            }
074        }
075        return false;
076    }
077
078    public boolean includeOperation(OperationInfoImpl op) {
079        for (String pprefix : packagesPrefixes) {
080            if (op.getOperationClass().startsWith(pprefix)) {
081                return true;
082            }
083        }
084        return false;
085    }
086}