1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2008 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.pde.api.tools.internal; |
12 | |
13 | import org.eclipse.pde.api.tools.internal.provisional.IRequiredComponentDescription; |
14 | import org.eclipse.pde.api.tools.internal.provisional.IVersionRange; |
15 | |
16 | /** |
17 | * Implementation of a required component description based on |
18 | * OSGi bundles. |
19 | * |
20 | * @since 1.0.0 |
21 | */ |
22 | public class RequiredComponentDescription implements IRequiredComponentDescription { |
23 | |
24 | private String fId; |
25 | private boolean fIsOptional; |
26 | private boolean fIsExprted; |
27 | private IVersionRange fRange; |
28 | |
29 | |
30 | /** |
31 | * Constructs a new required component description based on the given |
32 | * required component id and version range. The required component description is |
33 | * mandatory. |
34 | * |
35 | * @param id component's symbolic name |
36 | * @param range version range |
37 | */ |
38 | public RequiredComponentDescription(String id, IVersionRange range) { |
39 | this(id, range, false, false); |
40 | } |
41 | |
42 | /** |
43 | * Constructs a new required component description based on the given |
44 | * required component id and version range. |
45 | * |
46 | * @param id component's symbolic name |
47 | * @param range version range |
48 | * @param isOptional the optional flag of the required component |
49 | * @param isExported whether the required component is re-exported by the declaring component |
50 | */ |
51 | public RequiredComponentDescription(String id, IVersionRange range, boolean isOptional, boolean isExported) { |
52 | fId = id; |
53 | fRange = range; |
54 | fIsOptional = isOptional; |
55 | fIsExprted = isExported; |
56 | } |
57 | |
58 | /* (non-Javadoc) |
59 | * @see java.lang.Object#equals(java.lang.Object) |
60 | */ |
61 | public boolean equals(Object obj) { |
62 | if (obj instanceof RequiredComponentDescription) { |
63 | RequiredComponentDescription desc = (RequiredComponentDescription) obj; |
64 | return fId.equals(desc.fId) && fRange.equals(desc.fRange); |
65 | } |
66 | return super.equals(obj); |
67 | } |
68 | |
69 | /* (non-Javadoc) |
70 | * @see IRequiredComponentDescription#getId() |
71 | */ |
72 | public String getId() { |
73 | return fId; |
74 | } |
75 | |
76 | /** (non-Javadoc) |
77 | * @see IRequiredComponentDescription#getVersionRange() |
78 | */ |
79 | public IVersionRange getVersionRange() { |
80 | return fRange; |
81 | } |
82 | |
83 | /* (non-Javadoc) |
84 | * @see java.lang.Object#hashCode() |
85 | */ |
86 | public int hashCode() { |
87 | return fId.hashCode() + fRange.hashCode(); |
88 | } |
89 | |
90 | /* (non-Javadoc) |
91 | * @see IRequiredComponentDescription#isOptional() |
92 | */ |
93 | public boolean isOptional() { |
94 | return this.fIsOptional; |
95 | } |
96 | /* (non-Javadoc) |
97 | * @see java.lang.Object#toString() |
98 | */ |
99 | public String toString() { |
100 | StringBuffer buf = new StringBuffer(); |
101 | buf.append(fId); |
102 | buf.append(' '); |
103 | buf.append(fRange.toString()); |
104 | return buf.toString(); |
105 | } |
106 | |
107 | /* (non-Javadoc) |
108 | * @see org.eclipse.pde.api.tools.internal.provisional.IRequiredComponentDescription#isExported() |
109 | */ |
110 | public boolean isExported() { |
111 | return fIsExprted; |
112 | } |
113 | |
114 | } |