Author: [email protected]
Date: Tue Mar 29 17:06:17 2011
New Revision: 920

Log:
AMDATU-283 cleanup old resource/context code

Modified:
   
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
   
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java

Modified: 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
     (original)
+++ 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/osgi/Activator.java
     Tue Mar 29 17:06:17 2011
@@ -36,26 +36,23 @@
  * @author ivol
  */
 public class Activator extends DependencyActivatorBase {
-    // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
-    // it is prefixed with this id
-    public final static String RESOURCE_ID = "examples/gadget/course";
+
+    public final static String CONTEXTID = "amdatu-examples";
+    public final static String ALIAS = "/examples/gadget/course";
 
     @Override
     public void init(BundleContext context, DependencyManager manager) throws 
Exception {
-        // Create the CourseGadgetService which has dependencies with the Log 
service
-        // and HTTP service
 
-        // Provide context and alias information for resources
         Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
-        properties.put(DispatcherService.CONTEXT_ID_KEY, RESOURCE_ID);
-        properties.put(DispatcherService.ALIAS_KEY, "/" + RESOURCE_ID);
+        properties.put(DispatcherService.CONTEXT_ID_KEY, CONTEXTID);
+        properties.put(DispatcherService.ALIAS_KEY, "/" + ALIAS);
 
         Component friendsgadgetService = createComponent()
             .setInterface(ResourceProvider.class.getName(), properties)
             .setImplementation(CourseGadgetServiceImpl.class)
-            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
             
.add(createServiceDependency().setService(GadgetManagement.class).setRequired(true))
-            
.add(createServiceDependency().setService(OAuthServiceConsumerRegistry.class).setRequired(true));
+            
.add(createServiceDependency().setService(OAuthServiceConsumerRegistry.class).setRequired(true))
+            
.add(createServiceDependency().setService(LogService.class).setRequired(false));
         manager.add(friendsgadgetService);
     }
 

Modified: 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
==============================================================================
--- 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
    (original)
+++ 
branches/AMDATU-283-dev/amdatu-example/course-gadget/src/main/java/org/amdatu/example/course/gadget/service/CourseGadgetServiceImpl.java
    Tue Mar 29 17:06:17 2011
@@ -36,9 +36,11 @@
 /**
  * This course gadget service implements WebResourceProvider to provide the 
resources that make up this gadget (like the
  * gadget XML).
+ * 
  * @author ivol
  */
 public class CourseGadgetServiceImpl implements ResourceProvider {
+
     // oAuth properties of this gadget as service consumer
     private final static String CONSUMER_CALLBACK_URL = 
"/gadgets/oauthcallback";
     private final static String CONSUMER_KEY = "CcourseExampleGadget";
@@ -49,19 +51,14 @@
     private volatile LogService m_logService;
     private volatile GadgetManagement m_gadgetManagement;
     private volatile OAuthServiceConsumerRegistry m_consumerRegistry;
-
-    // Instance variables, injected by the OSGi framework
-    private BundleContext m_bundleContext;
-
-    // Other instance variables
-    private Component m_httpContextComponent;
+    private volatile BundleContext m_bundleContext;
 
     /**
      * The init() method is invoked by the Felix dependency manager.
      */
     public void init() {
 
-        GadgetDefinition gadgetDef = new GadgetDefinition("/" + 
Activator.RESOURCE_ID + "/jsp/CourseGadget.jsp",
+        GadgetDefinition gadgetDef = new GadgetDefinition(Activator.ALIAS + 
"/jsp/CourseGadget.jsp",
             ExampleGadgetRepositoryService.AMDATU_EXAMPLE_CATEGORY, false);
 
         // Set oAuth parameters
@@ -83,7 +80,6 @@
      * The destroy() method is invoked by the Felix dependency manager.
      */
     public void destroy() {
-        m_httpContextComponent.stop();
         m_logService.log(LogService.LOG_INFO, getClass().getName() + " service 
destroyed");
     }
 
@@ -91,38 +87,52 @@
         try {
             if (m_consumerRegistry.getConsumer(CONSUMER_KEY) == null) {
                 m_consumerRegistry.addConsumer(new 
InternalOAuthServiceConsumer());
-            } else {
+            }
+            else {
                 m_consumerRegistry.updateConsumer(new 
InternalOAuthServiceConsumer());
             }
         }
         catch (ConsumerAlreadyExistsException e) {
-            m_logService.log(LogService.LOG_DEBUG, "Could not properly add 
service consumer '" + CONSUMER_KEY + "' in the service consumer registry");
+            m_logService.log(LogService.LOG_DEBUG, "Could not properly add 
service consumer '" + CONSUMER_KEY
+                + "' in the service consumer registry");
         }
         catch (ConsumerRegistryStorageException e) {
-            m_logService.log(LogService.LOG_DEBUG, "Could not properly add or 
update service consumer '" + CONSUMER_KEY + "' in the service consumer 
registry");
+            m_logService.log(LogService.LOG_DEBUG, "Could not properly add or 
update service consumer '" + CONSUMER_KEY
+                + "' in the service consumer registry");
         }
         catch (ConsumerNotFoundException e) {
-            m_logService.log(LogService.LOG_DEBUG, "Could not properly update 
service consumer '" + CONSUMER_KEY + "' in the service consumer registry");
+            m_logService.log(LogService.LOG_DEBUG, "Could not properly update 
service consumer '" + CONSUMER_KEY
+                + "' in the service consumer registry");
         }
     }
 
     public URL getResource(String name) {
-        final String pathPrefix = "/" + Activator.RESOURCE_ID + "/";
-        if(name != null && name.startsWith(pathPrefix)){
-            return 
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));   
         
+        final String pathPrefix = Activator.ALIAS + "/";
+        if (name != null && name.startsWith(pathPrefix)) {
+            return 
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));
         }
         return null;
     }
 
-    public String getResourceId() {
-        return Activator.RESOURCE_ID;
-    }
-
     class InternalOAuthServiceConsumer implements OAuthServiceConsumer {
-        public String getCallbackUrl() {return CONSUMER_CALLBACK_URL;}
-        public String getConsumerKey() {return CONSUMER_KEY;}
-        public String getConsumerSecret() {return CONSUMER_SECRET;}
-        public String getName() {return CONSUMER_NAME;}
-        public Map<String, String> getProperties() {return null;}
+        public String getCallbackUrl() {
+            return CONSUMER_CALLBACK_URL;
+        }
+
+        public String getConsumerKey() {
+            return CONSUMER_KEY;
+        }
+
+        public String getConsumerSecret() {
+            return CONSUMER_SECRET;
+        }
+
+        public String getName() {
+            return CONSUMER_NAME;
+        }
+
+        public Map<String, String> getProperties() {
+            return null;
+        }
     }
 }
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to