KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > site > FilteringState


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.site;
12
13 import java.util.*;
14 import org.eclipse.osgi.service.resolver.BundleDescription;
15 import org.eclipse.osgi.service.resolver.VersionRange;
16 import org.osgi.framework.Version;
17
18 public class FilteringState extends PDEState {
19     SortedSet allPlugins;
20
21     public void setFilter(SortedSet filter) {
22         allPlugins = filter;
23     }
24
25     public boolean addBundleDescription(BundleDescription toAdd) {
26         if (allPlugins == null) {
27             return super.addBundleDescription(toAdd);
28         }
29
30         SortedSet includedMatches = allPlugins.subSet(new ReachablePlugin(toAdd.getSymbolicName(), ReachablePlugin.WIDEST_RANGE), new ReachablePlugin(toAdd.getSymbolicName(), new VersionRange(Version.emptyVersion, true, Version.emptyVersion, true)));
31         for (Iterator iterator = includedMatches.iterator(); iterator.hasNext();) {
32             ReachablePlugin constraint = (ReachablePlugin) iterator.next();
33             if (constraint.getRange().isIncluded(toAdd.getVersion()))
34                 return super.addBundleDescription(toAdd);
35         }
36         return false;
37     }
38 }
39
Popular Tags