001/*
002 * (C) Copyright 2006-2010 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 *     Thierry Delprat
018 */
019package org.nuxeo.apidoc.snapshot;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import org.nuxeo.apidoc.api.SeamComponentInfo;
025import org.nuxeo.apidoc.introspection.OperationInfoImpl;
026
027public class SnapshotFilter {
028
029    protected final String bundleGroupName;
030
031    protected final List<String> bundlePrefixes = new ArrayList<>();
032
033    protected final List<String> packagesPrefixes = new ArrayList<>();
034
035    public SnapshotFilter(String groupName) {
036        bundleGroupName = groupName;
037    }
038
039    public String getBundleGroupName() {
040        return bundleGroupName;
041    }
042
043    public List<String> getBundlePrefixes() {
044        return bundlePrefixes;
045    }
046
047    public void addBundlePrefix(String bundlePrefix) {
048        bundlePrefixes.add(bundlePrefix);
049    }
050
051    public List<String> getPackagesPrefixes() {
052        return packagesPrefixes;
053    }
054
055    public void addPackagesPrefix(String packagesPrefix) {
056        packagesPrefixes.add(packagesPrefix);
057    }
058
059    public boolean includeBundleId(String bundleId) {
060        for (String bprefix : bundlePrefixes) {
061            if (bundleId.startsWith(bprefix)) {
062                return true;
063            }
064        }
065        return false;
066    }
067
068    public boolean includeSeamComponent(SeamComponentInfo seamComponent) {
069
070        for (String iface : seamComponent.getInterfaceNames()) {
071            for (String pprefix : packagesPrefixes) {
072                if (iface.startsWith(pprefix)) {
073                    return true;
074                }
075            }
076        }
077        return false;
078    }
079
080    public boolean includeOperation(OperationInfoImpl op) {
081        for (String pprefix : packagesPrefixes) {
082            if (op.getOperationClass().startsWith(pprefix)) {
083                return true;
084            }
085        }
086        return false;
087    }
088}