Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ba5cfaf1b40bb045cbb3b6cb80cfc97b505b11a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.ds.model;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * 
 * This class models the reference element.
 * A reference declares a dependency that a component has on a set 
 * of target services.
 * 
 * @see org.eclipse.equinox.ds.resolver.Reference
 * 
 * @version $Revision: 1.2 $
 */
public class ReferenceDescription implements Serializable {

	/**
	 * Eclipse-generated <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = -6454039348113422074L;

	private static final int CARDINALITY_HIGH_DEFAULT = 1;
	private static final int CARDINALITY_LOW_DEFAULT = 1;
	private static final String POLICY_DEFAULT = "static";

	private String name;
	private String interfacename;

	// Cardinality indicates the number of services, matching this
	// reference,
	// which will bind to this Service Component. Possible values are:
	// 0..1, 0..n, 1..1 (i.e. exactly one), 1..n (i.e. at least one).
	// This attribute is optional. If it is not specified, then a
	// cardinality
	// of “1..1� is used.
	private int cardinalityHigh;
	private int cardinalityLow;
	private String policy;
	private String target;
	private String bind;
	private String unbind;

	//Cache bind and unbind methods
	transient private Method bindMethod;
	transient private Method unbindMethod;

	public ReferenceDescription() {
		// set defaults
		cardinalityHigh = CARDINALITY_HIGH_DEFAULT;
		cardinalityLow = CARDINALITY_LOW_DEFAULT;
		policy = POLICY_DEFAULT;
	}

	/**
	 * @return Returns the bind method.
	 */
	public String getBind() {
		return bind;
	}

	/**
	 * @param bind The bind method.
	 */
	public void setBind(String bind) {
		this.bind = bind;
	}

	/**
	 * @return Returns the cardinality.
	 */
	public int getCardinalityHigh() {
		return cardinalityHigh;
	}

	/**
	 * @param cardinality 
	 */
	public void setCardinality(String cardinality) {
		if (cardinality.equals("0..1")) {
			cardinalityLow = 0;
			cardinalityHigh = 1;
		} else if (cardinality.equals("0..n")) {
			cardinalityLow = 0;
			cardinalityHigh = 999999999; // infinite
		} else if (cardinality.equals("1..1")) {
			cardinalityLow = 1;
			cardinalityHigh = 1;
		} else if (cardinality.equals("1..n")) {
			cardinalityLow = 1;
			cardinalityHigh = 999999999;
		} else {
			// TODO throw exception?
		}
	}

	/**
	 * @return Returns the interfacename.
	 */
	public String getInterfacename() {
		return interfacename;
	}

	/**
	 * @param interfacename The interfacename to set.
	 */
	public void setInterfacename(String interfacename) {
		this.interfacename = interfacename;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return Returns the policy.
	 */
	public String getPolicy() {
		return policy;
	}

	/**
	 * @param policy The policy to set.
	 */
	public void setPolicy(String policy) {
		// TODO validate
		this.policy = policy;
	}

	/**
	 * @return Returns the target.
	 */
	public String getTarget() {
		return target;
	}

	/**
	 * @param target The target to set.
	 */
	public void setTarget(String target) {
		// TODO validate
		this.target = target;
	}

	/**
	 * @return Returns the unbind method
	 */
	public String getUnbind() {
		return unbind;
	}

	/**
	 * @param unbind The unbind method to set.
	 */
	public void setUnbind(String unbind) {
		this.unbind = unbind;
	}

	// if the cardinality is "1..1" or "1..n" then this reference is required
	public boolean isRequired() {
		return (cardinalityLow == 1);
	}

	//Cache bind and unbind methods

	/**
	 * @return Returns the bind method.
	 */
	public Method getBindMethod() {
		return bindMethod;
	}

	/**
	 * @param bind The bind method.
	 */
	public void setBindMethod(Method method) {
		this.bindMethod = method;
	}

	/**
	 * @return Returns the unbind method
	 */
	public Method getUnbindMethod() {
		return unbindMethod;
	}

	/**
	 * @param unbind The unbind method to set.
	 */
	public void setUnbindMethod(Method method) {
		this.unbindMethod = method;
	}

}

Back to the top