summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-02-26 08:26:48 (EST)
committerStefan Liebig2008-02-26 08:26:48 (EST)
commitb23d37d2add8e4a942cba1675ef6cdd3934689f0 (patch)
tree88a607d4a9ceea55e18cc64d1dba3797e577f198
parent76545247c73e014760536267fe3494782008e64d (diff)
downloadorg.eclipse.riena-b23d37d2add8e4a942cba1675ef6cdd3934689f0.zip
org.eclipse.riena-b23d37d2add8e4a942cba1675ef6cdd3934689f0.tar.gz
org.eclipse.riena-b23d37d2add8e4a942cba1675ef6cdd3934689f0.tar.bz2
introduced an enum, simplified and made testable
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/util/ContainerModel.java97
1 files changed, 59 insertions, 38 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ContainerModel.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ContainerModel.java
index 145315d..8156a8b 100644
--- a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ContainerModel.java
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/ContainerModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 compeople AG and others.
+ * Copyright (c) 2007, 2008 compeople AG and others.
* 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
@@ -15,55 +15,76 @@ import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;
/**
- * This class can be used by other to find out whether the container they are
- * running in is a Riena client or a Riena server container. The consequence can
- * be things like storing objects in a singleton (for client) vs storing them in
- * a ThreadLocal (server) or others. The class can be driven be the
- * system.property "riena.container.model" that can be set to "client" or
- * "server". The ContainerModel also checks to see whether there is a bundle
- * called org.eclipse.equinox.http in which case it assumes a server model. In
- * any case, it creates a LOG_INFO entry to post what it has chosen.
+ * This class can be used by other to find out whether the container we are
+ * running in is a Riena client or a Riena server. <br>
+ * This information may be useful to components that need to behave differently
+ * on client and server, e.g. storing objects in a singleton (for client) versa
+ * storing them in a ThreadLocal (server). <br>
+ * The class can be driven be the system.property "riena.container.model" that
+ * can be set to "client" or "server". The ContainerModel also checks to see
+ * whether there is a bundle called org.eclipse.equinox.http in which case it
+ * assumes a server model. In any case, it creates a LOG_INFO entry to post what
+ * it has chosen.
*/
public class ContainerModel {
- private static final int CLIENT = 1;
- private static final int SERVER = 2;
+ /**
+ * System property defining the container type.
+ */
+ public static final String RIENA_CONTAINER_TYPE = "riena.container.type"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ public static final String ORG_ECLIPSE_EQUINOX_HTTP = "org.eclipse.equinox.http"; //$NON-NLS-1$
+
+ private enum Type {
+ CLIENT, SERVER
+ };
+
+ private static Type containerType;
- private static int containerModel = CLIENT;
static {
- String s = System.getProperty("riena.container.model");
- if (s != null) {
- if (s.equals("server")) {
- containerModel = SERVER;
- }
- } else {
- Bundle[] bundles = Activator.getContext().getBundles();
- for (Bundle bundle : bundles) {
- if (bundle.getSymbolicName().startsWith("org.eclipse.equinox.http")) {
- containerModel = SERVER;
- }
- }
- }
- if (containerModel == SERVER) {
- Activator.getDefault().getLogger(ContainerModel.class.getName()).log(LogService.LOG_INFO,
- "!!! Riena is running in SERVERMODEL !!!");
- }
+ // This makes the init code available for testing!!
+ initialize();
}
+ /**
+ * Are we running on the client?
+ *
+ * @return
+ */
public static boolean isClient() {
- if (containerModel == CLIENT) {
- return true;
- } else {
- return false;
- }
+ return containerType == Type.CLIENT;
}
+ /**
+ * Are we running on the server?
+ *
+ * @return
+ */
public static boolean isServer() {
- if (containerModel == SERVER) {
- return true;
+ return containerType == Type.SERVER;
+ }
+
+ private static void initialize() {
+ String s = System.getProperty(RIENA_CONTAINER_TYPE);
+ containerType = Type.CLIENT;
+ if (s != null) {
+ if (s.equals("server")) { //$NON-NLS-1$
+ containerType = Type.SERVER;
+ }
} else {
- return false;
+ Bundle[] bundles = Activator.getDefault().getContext().getBundles();
+ for (Bundle bundle : bundles) {
+ if (bundle.getSymbolicName().startsWith(ORG_ECLIPSE_EQUINOX_HTTP)) {
+ containerType = Type.SERVER;
+ break;
+ }
+ }
}
- }
+ Activator.getDefault().getLogger(ContainerModel.class.getName()).log(LogService.LOG_INFO,
+ "!!! Riena is running in " + containerType + " mode !!!");
+ }
}