KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > resolver > GenericSpecificationImpl


1 /*******************************************************************************
2  * Copyright (c) 2006 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.osgi.internal.resolver;
12
13 import org.eclipse.osgi.service.resolver.*;
14 import org.osgi.framework.*;
15
16 public class GenericSpecificationImpl extends VersionConstraintImpl implements GenericSpecification {
17     private Filter matchingFilter;
18     private String JavaDoc type = GenericDescription.DEFAULT_TYPE;
19     private int resolution = 0;
20     private GenericDescription[] suppliers;
21
22     public String JavaDoc getMatchingFilter() {
23         return matchingFilter == null ? null : matchingFilter.toString();
24     }
25
26     void setMatchingFilter(String JavaDoc matchingFilter) throws InvalidSyntaxException {
27         this.matchingFilter = matchingFilter == null ? null : FrameworkUtil.createFilter(matchingFilter);
28     }
29
30     public boolean isSatisfiedBy(BaseDescription supplier) {
31         if (!(supplier instanceof GenericDescription))
32             return false;
33         GenericDescription candidate = (GenericDescription) supplier;
34         if (getName() == null || !getName().equals(candidate.getName()))
35             return false;
36         if (getType() == null || !getType().equals(candidate.getType()))
37             return false;
38         // Note that versions are only matched by including them in the filter
39
return matchingFilter == null || matchingFilter.match(candidate.getAttributes());
40     }
41
42     public String JavaDoc toString() {
43         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
44         sb.append(StateBuilder.GENERIC_REQUIRE).append(": ").append(getName()); //$NON-NLS-1$
45
if (getType() != GenericDescription.DEFAULT_TYPE)
46             sb.append(':').append(getType());
47         if (matchingFilter != null)
48             sb.append("; ").append(getMatchingFilter()); //$NON-NLS-1$
49
return sb.toString();
50     }
51
52     public String JavaDoc getType() {
53         return type;
54     }
55
56     void setType(String JavaDoc type) {
57         if (type == null || type.equals(GenericDescription.DEFAULT_TYPE))
58             this.type = GenericDescription.DEFAULT_TYPE;
59         else
60             this.type = type;
61     }
62
63     public int getResolution() {
64         return resolution;
65     }
66
67     public boolean isResolved() {
68         return suppliers != null && suppliers.length > 0;
69     }
70
71     void setResolution(int resolution) {
72         this.resolution = resolution;
73     }
74
75     public BaseDescription getSupplier() {
76         return suppliers == null || suppliers.length == 0 ? null : suppliers[0];
77     }
78
79     protected void setSupplier(BaseDescription supplier) {
80         if (supplier == null) {
81             suppliers = null;
82             return;
83         }
84         int len = suppliers == null ? 0 : suppliers.length;
85         GenericDescription[] temp = new GenericDescription[len + 1];
86         if (suppliers != null)
87             System.arraycopy(suppliers, 0, temp, 0, len);
88         temp[len] = (GenericDescription) supplier;
89         suppliers = temp;
90     }
91
92     public GenericDescription[] getSuppliers() {
93         return suppliers;
94     }
95
96     void setSupplers(GenericDescription[] suppliers) {
97         this.suppliers = suppliers;
98     }
99 }
100
Popular Tags