001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.product.filters;
038:
039: import java.util.LinkedList;
040: import java.util.List;
041: import org.netbeans.installer.product.Registry;
042: import org.netbeans.installer.product.components.Product;
043: import org.netbeans.installer.product.RegistryNode;
044: import org.netbeans.installer.utils.helper.DetailedStatus;
045: import org.netbeans.installer.utils.helper.Feature;
046: import org.netbeans.installer.utils.helper.Status;
047: import org.netbeans.installer.utils.helper.Platform;
048: import org.netbeans.installer.utils.helper.Version;
049:
050: /**
051: *
052: * @author Kirill Sorokin
053: */
054: public class ProductFilter implements RegistryFilter {
055: private String uid;
056:
057: private List<Platform> platforms;
058:
059: private Version versionLower;
060: private Version versionUpper;
061:
062: private Status status;
063: private DetailedStatus detailedStatus;
064:
065: private Feature feature;
066:
067: private Boolean visible;
068:
069: public ProductFilter() {
070: this .platforms = new LinkedList<Platform>();
071: }
072:
073: public ProductFilter(final boolean visible) {
074: this ();
075:
076: this .visible = visible;
077: }
078:
079: public ProductFilter(final Platform platform) {
080: this ();
081:
082: this .platforms.add(platform);
083: }
084:
085: public ProductFilter(final String uid, final Platform platform) {
086: this ();
087:
088: this .uid = uid;
089: this .platforms.add(platform);
090: }
091:
092: public ProductFilter(final String uid, final Version version,
093: final Platform platform) {
094: this ();
095:
096: this .uid = uid;
097: this .versionLower = version;
098: this .versionUpper = version;
099: this .platforms.add(platform);
100: }
101:
102: public ProductFilter(final String uid, final Version version,
103: final List<Platform> platforms) {
104: this ();
105:
106: this .uid = uid;
107: this .versionLower = version;
108: this .versionUpper = version;
109: this .platforms.addAll(platforms);
110: }
111:
112: public ProductFilter(final String uid, final Version versionLower,
113: final Version versionUpper, final Platform platform) {
114: this ();
115:
116: this .uid = uid;
117: this .versionLower = versionLower;
118: this .versionUpper = versionUpper;
119: this .platforms.add(platform);
120: }
121:
122: public ProductFilter(final Status status) {
123: this (status, Registry.getInstance().getTargetPlatform());
124: }
125:
126: public ProductFilter(final Status status, final Platform platform) {
127: this ();
128:
129: this .status = status;
130: this .platforms.add(platform);
131: }
132:
133: public ProductFilter(final DetailedStatus detailedStatus) {
134: this (detailedStatus, Registry.getInstance().getTargetPlatform());
135: }
136:
137: public ProductFilter(final DetailedStatus detailedStatus,
138: final Platform platform) {
139: this ();
140:
141: this .detailedStatus = detailedStatus;
142: this .platforms.add(platform);
143: }
144:
145: public ProductFilter(final Feature feature, final Platform platform) {
146: this ();
147:
148: this .feature = feature;
149: this .platforms.add(platform);
150: }
151:
152: public boolean accept(final RegistryNode node) {
153: if (node instanceof Product) {
154: final Product product = (Product) node;
155:
156: if (uid != null) {
157: if (!product.getUid().equals(uid)) {
158: return false;
159: }
160: }
161:
162: if ((versionLower != null) && (versionUpper != null)) {
163: if (!product.getVersion().newerOrEquals(versionLower)
164: || !product.getVersion().olderOrEquals(
165: versionUpper)) {
166: return false;
167: }
168: }
169:
170: if (platforms.size() > 0) {
171: boolean intersects = false;
172:
173: for (Platform platform : platforms) {
174: for (Platform productPlatform : product
175: .getPlatforms()) {
176: if (platform.isCompatibleWith(productPlatform)
177: || productPlatform
178: .isCompatibleWith(platform)) {
179: intersects = true;
180: }
181: }
182:
183: if (intersects)
184: break;
185: }
186:
187: if (!intersects)
188: return false;
189: }
190:
191: if (status != null) {
192: if (product.getStatus() != status) {
193: return false;
194: }
195: }
196:
197: if (detailedStatus != null) {
198: if (product.getDetailedStatus() != detailedStatus) {
199: return false;
200: }
201: }
202:
203: if (feature != null) {
204: for (String id : product.getFeatures()) {
205: if (feature.getId().equals(id)) {
206: return false;
207: }
208: }
209: }
210:
211: if (visible != null) {
212: if (product.isVisible() != visible.booleanValue()) {
213: return false;
214: }
215: }
216:
217: return true;
218: }
219:
220: return false;
221: }
222: }
|