summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-03-11 02:50:26 (EDT)
committerStefan Liebig2008-03-11 02:50:26 (EDT)
commitd92b080167de1fba947b0e1627b53966561cd5af (patch)
tree65e7a7f1bc1da189f9863e30087dddc8954f9f15
parent0e4c61a0f4c4114b496e4f86bbe7ce4ceb156632 (diff)
downloadorg.eclipse.riena-d92b080167de1fba947b0e1627b53966561cd5af.zip
org.eclipse.riena-d92b080167de1fba947b0e1627b53966561cd5af.tar.gz
org.eclipse.riena-d92b080167de1fba947b0e1627b53966561cd5af.tar.bz2
uses Assert.... instead of if () throw ...
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/service/Injector.java22
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/service/ServiceId.java26
2 files changed, 25 insertions, 23 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/service/Injector.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/service/Injector.java
index f6bad26..f8e699c 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/service/Injector.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/service/Injector.java
@@ -15,6 +15,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.equinox.log.Logger;
import org.eclipse.riena.core.logging.ConsoleLogger;
import org.osgi.framework.BundleContext;
@@ -77,16 +78,16 @@ public abstract class Injector {
/**
* Start the binding/un-binding/tracking for the target.
*
- * @throws IllegalStateException
+ * @throws some_kind_of_unchecked_exception
* if injector has already been started.
- * @throws IllegalArgumentException
+ * @throws some_kind_of_unchecked_exception
* if the bind/un-bind methods are wrong
* @param context
* @return this injector
*/
public Injector andStart(BundleContext context) {
- if (started)
- throw new IllegalStateException("Injector already started!");
+ Assert.isNotNull(context, "Bundle context must be not null.");
+ Assert.isTrue(!started, "Injector already started!");
started = true;
this.context = context;
if (bindMethodName == null)
@@ -125,14 +126,13 @@ public abstract class Injector {
* Specify the bind method. If not specified
* {@link #DEFAULT_BIND_METHOD_NAME} will be used.
*
- * @throws IllegalStateException
+ * @throws some_kind_of_unchecked_exception
* if the the injector had already been started
* @param bindMethodName
* @return this injector
*/
public Injector bind(String bindMethodName) {
- if (started)
- throw new IllegalStateException("Injector already started!");
+ Assert.isTrue(!started, "Injector already started!");
this.bindMethodName = bindMethodName;
return this;
}
@@ -141,14 +141,13 @@ public abstract class Injector {
* Specify the un-bind method. If not specified
* {@link #DEFAULT_UNBIND_METHOD_NAME} will be used.
*
- * @throws IllegalStateException
+ * @throws some_kind_of_unchecked_exception
* if the the injector had already been started
* @param unbindMethodName
* @return this injector
*/
public synchronized Injector unbind(String unbindMethodName) {
- if (started)
- throw new IllegalStateException("Injector already started!");
+ Assert.isTrue(!started, "Injector already started!");
this.unbindMethodName = unbindMethodName;
return this;
}
@@ -215,9 +214,6 @@ public abstract class Injector {
*/
protected ServiceReference[] getServiceReferences() {
try {
- if (context == null) {
- System.out.println(context);
- }
return context.getServiceReferences(serviceId.getServiceId(), filter);
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException("The specified filter has syntax errors.", e);
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/service/ServiceId.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/service/ServiceId.java
index 5b9a893..1ce0768 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/service/ServiceId.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/service/ServiceId.java
@@ -12,6 +12,7 @@ package org.eclipse.riena.core.service;
import java.util.Hashtable;
+import org.eclipse.core.runtime.Assert;
import org.osgi.framework.Constants;
/**
@@ -62,7 +63,15 @@ public class ServiceId {
private boolean ranking;
private String filter;
+ /**
+ * Create a service id.
+ *
+ * @throws some_kind_of_unchecked_exception
+ * if service id is null.
+ * @param serviceId
+ */
public ServiceId(String serviceId) {
+ Assert.isNotNull(serviceId, "Service id must not be null.");
this.serviceId = serviceId;
}
@@ -70,13 +79,13 @@ public class ServiceId {
* Use filtering {@link org.osgi.framework.Filter} for picking the tracked
* service(s) to inject.
*
- * @throws IllegalStateException
+ * @throws some_kind_of_unchecked_exception
* if a filter has already been set.
* @return this service id
*/
public ServiceId useFilter(String filter) {
- if (this.filter != null)
- throw new IllegalStateException("Filter has already been set!");
+ Assert.isTrue(this.filter == null, "Filter has already been set!");
+ Assert.isNotNull(filter, "Filter must not be null.");
this.filter = filter;
return this;
}
@@ -85,13 +94,12 @@ public class ServiceId {
* Use service ranking {@link org.osgi.framework.Constants#SERVICE_RANKING}
* picking the tracked service to inject.
*
- * @throws IllegalStateException
+ * @throws some_kind_of_unchecked_exception
* if ranking has already been activated
* @return this service id
*/
public ServiceId useRanking() {
- if (ranking)
- throw new IllegalStateException("Ranking has already been set!");
+ Assert.isTrue(!ranking, "Ranking has already been set!");
ranking = true;
return this;
}
@@ -100,14 +108,12 @@ public class ServiceId {
* Inject this service id into the specified target.
*
* @param target
- * @throws IllegalArgumentException
+ * @throws some_kind_of_unchecked_exception
* on target == null
* @return the injector responsible for tracking this service id
*/
public Injector injectInto(Object target) {
- if (target == null)
- throw new IllegalArgumentException("target may not be null.");
-
+ Assert.isNotNull(target, "Target must not be null.");
return ranking ? new RankingInjector(this, target) : new FilterInjector(this, target);
}