Author: angelo.vandersijpt at luminis.eu
Date: Mon Oct 18 15:02:37 2010
New Revision: 181
Log:
AMDATU-103 Refactored the LoginServiceImpl to be a ManagedService.
Modified:
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/osgi/Activator.java
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/service/LoginServiceImpl.java
Modified:
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/osgi/Activator.java
==============================================================================
---
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/osgi/Activator.java
(original)
+++
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/osgi/Activator.java
Mon Oct 18 15:02:37 2010
@@ -49,10 +49,9 @@
LoginServiceImpl.class).add(createServiceDependency().setService(LogService.class).setRequired(true))
.add(createServiceDependency().setService(UserAdmin.class).setRequired(true))
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
-
.add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
.add(createServiceDependency().setService(AuthorizationService.class).setRequired(true))
-
.add(createServiceDependency().setService(WebContainer.class).setRequired(true)));
+
.add(createConfigurationDependency().setPid(LoginServiceImpl.PID)));
}
/**
Modified:
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/service/LoginServiceImpl.java
==============================================================================
---
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/service/LoginServiceImpl.java
(original)
+++
trunk/gadget-bundles/login-gadget/src/main/java/org/amdatu/gadget/login/service/LoginServiceImpl.java
Mon Oct 18 15:02:37 2010
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.net.URL;
+import java.util.Dictionary;
import org.amdatu.application.gadgetmanagement.GadgetManagement;
import org.amdatu.gadget.login.osgi.Activator;
@@ -28,11 +29,13 @@
import org.apache.felix.dm.Component;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.log.LogService;
-public class LoginServiceImpl implements ResourceProvider {
- // The PID
- private final static String PID = "org.amdatu.gadget.login.service";
+public class LoginServiceImpl implements ResourceProvider, ManagedService {
+ // The PID and configuration properties
+ public final static String PID = "org.amdatu.gadget.login.service";
private final static String HOSTNAME = "hostname";
private final static String PORTNR = "portnr";
@@ -41,11 +44,13 @@
private volatile BundleContext m_bundleContext;
private volatile HttpContextServiceFactory m_httpContextServiceFactory;
private volatile GadgetManagement m_gadgetManagement;
- private volatile ConfigurationAdmin m_configurationAdmin;
// The private HTTP context service for this bundle
private Component m_httpContextComponent;
+ private String m_hostname;
+ private String m_portnr;
+
/**
* The init() method is invoked by the Felix dependency manager.
*/
@@ -53,18 +58,12 @@
// Create our own http context service which registers static
resources and JSPs automatically
m_httpContextComponent =
m_httpContextServiceFactory.create(m_bundleContext, this);
- try {
- // Register the gadget with the Gadget management service. Note
that we can do this as
- // many times as we want, since the gadget URL is the unique
identifier
- String hostName =
m_configurationAdmin.getConfiguration(PID).getProperties().get(HOSTNAME).toString();
- String portNr =
m_configurationAdmin.getConfiguration(PID).getProperties().get(PORTNR).toString();
- GadgetDefinition gadgetDef = new GadgetDefinition("http://" +
hostName + ":" + portNr + "/" + Activator.RESOURCE_ID + "/jsp/LoginGadget.jsp",
- GadgetCategory.AMDATU_PLATFORM, true);
- gadgetDef.setRank(0);
- m_gadgetManagement.addGadget(gadgetDef);
- } catch (IOException e) {
- m_logService.log(LogService.LOG_ERROR, "Could not register course
gadget", e);
- }
+ // Register the gadget with the Gadget management service. Note that
we can do this as
+ // many times as we want, since the gadget URL is the unique identifier
+ GadgetDefinition gadgetDef = new GadgetDefinition("http://" +
m_hostname + ":" + m_portnr + "/" + Activator.RESOURCE_ID +
"/jsp/LoginGadget.jsp",
+ GadgetCategory.AMDATU_PLATFORM, true);
+ gadgetDef.setRank(0);
+ m_gadgetManagement.addGadget(gadgetDef);
m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
initialized");
}
@@ -88,4 +87,20 @@
public String getResourceId() {
return Activator.RESOURCE_ID;
}
+
+ public void updated(Dictionary dictionary) throws ConfigurationException {
+ if (dictionary != null) {
+ checkAvailability(dictionary, new String[] {HOSTNAME, PORTNR});
+ m_hostname = (String) dictionary.get(HOSTNAME);
+ m_portnr = (String) dictionary.get(PORTNR);
+ }
+ }
+
+ private void checkAvailability(Dictionary dictionary, String[]
mandatoryKeys) throws ConfigurationException {
+ for (String mandatoryKey : mandatoryKeys) {
+ if (dictionary.get(mandatoryKey) == null) {
+ throw new ConfigurationException("Missing configuration key",
mandatoryKey);
+ }
+ }
+ }
}