KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > search > BackLevelFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.search;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.update.core.*;
15 import org.eclipse.update.internal.operations.*;
16
17 /**
18  * This class can be added to the update search request
19  * to filter out features that are back-level (are
20  * older or the same as the features already installed).
21  *
22  * <p>
23  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
24  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
25  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
26  * (repeatedly) as the API evolves.
27  * </p>
28  * @see UpdateSearchRequest
29  * @see IUpdateSearchFilter
30  * @since 3.0
31  */

32 public class BackLevelFilter extends BaseFilter {
33     
34     public boolean accept(IFeature match) {
35         
36             PluginVersionIdentifier matchVid = match.getVersionedIdentifier().getVersion();
37             IFeature [] installed = UpdateUtils.getInstalledFeatures(match.getVersionedIdentifier(), false);
38             if (installed.length==0) return true;
39             
40             for (int i=0; i<installed.length; i++) {
41                 PluginVersionIdentifier ivid = installed[i].getVersionedIdentifier().getVersion();
42                 if (matchVid.isGreaterThan(ivid))
43                     continue;
44                 // installed version is the same or newer than
45
// the match - filter out
46
return false;
47             }
48             return true;
49         
50     }
51     
52     public boolean accept(IFeatureReference match) {
53         try {
54             PluginVersionIdentifier matchVid = match.getVersionedIdentifier().getVersion();
55             IFeature [] installed = UpdateUtils.getInstalledFeatures(match.getVersionedIdentifier(), false);
56             if (installed.length==0) return true;
57             
58             for (int i=0; i<installed.length; i++) {
59                 PluginVersionIdentifier ivid = installed[i].getVersionedIdentifier().getVersion();
60                 if (matchVid.isGreaterThan(ivid))
61                     continue;
62                 // installed version is the same or newer than
63
// the match - filter out
64
return false;
65             }
66             return true;
67         } catch (CoreException e) {
68             return false;
69         }
70     }
71 }
72
Popular Tags