You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2014/02/05 02:01:00 UTC

svn commit: r1564596 - in /wookie/trunk/wookie-services: ./ wookie-redis/ wookie-spi/ wookie-spi/src/ wookie-spi/src/main/ wookie-spi/src/main/java/ wookie-spi/src/main/java/org/ wookie-spi/src/main/java/org/apache/ wookie-spi/src/main/java/org/apache/...

Author: scottbw
Date: Wed Feb  5 01:00:59 2014
New Revision: 1564596

URL: http://svn.apache.org/r1564596
Log:
added service provider (SPI) module for plugging in services

Added:
    wookie/trunk/wookie-services/
    wookie/trunk/wookie-services/wookie-redis/
    wookie/trunk/wookie-services/wookie-redis/pom.xml
    wookie/trunk/wookie-services/wookie-spi/
    wookie/trunk/wookie-services/wookie-spi/pom.xml
    wookie/trunk/wookie-services/wookie-spi/src/
    wookie/trunk/wookie-services/wookie-spi/src/main/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/PreferencesService.java
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferenceImpl.java
    wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java

Added: wookie/trunk/wookie-services/wookie-redis/pom.xml
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-redis/pom.xml?rev=1564596&view=auto
==============================================================================
--- wookie/trunk/wookie-services/wookie-redis/pom.xml (added)
+++ wookie/trunk/wookie-services/wookie-redis/pom.xml Wed Feb  5 01:00:59 2014
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.wookie</groupId>
+    <artifactId>wookie-redis</artifactId>
+    <name>Apache Wookie :: Redis Service Provider</name>
+    <description>Apache Wookie Redis Service Provider</description>
+    <packaging>jar</packaging>
+    <version>2.0.0-SNAPSHOT</version>
+    
+    <parent>
+        <groupId>org.apache.wookie</groupId>
+        <artifactId>wookie-master</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../../../wookie-master-pom/trunk/pom.xml</relativePath>
+    </parent>
+    
+    <dependencies>
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>2.2.1</version>
+            <type>jar</type>
+            <scope>compile</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.wookie</groupId>
+            <artifactId>wookie-spi</artifactId>
+            <version>2.2.1</version>
+            <type>jar</type>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+  
+</project>
\ No newline at end of file

Added: wookie/trunk/wookie-services/wookie-spi/pom.xml
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/pom.xml?rev=1564596&view=auto
==============================================================================
--- wookie/trunk/wookie-services/wookie-spi/pom.xml (added)
+++ wookie/trunk/wookie-services/wookie-spi/pom.xml Wed Feb  5 01:00:59 2014
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.wookie</groupId>
+    <artifactId>wookie-spi</artifactId>
+    <name>Apache Wookie :: Service Provider Interfaces</name>
+    <description>Apache Wookie Service Provider Interfaces</description>
+    <packaging>jar</packaging>
+    <version>2.0.0-SNAPSHOT</version>
+    
+    <parent>
+        <groupId>org.apache.wookie</groupId>
+        <artifactId>wookie-master</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../../../wookie-master-pom/trunk/pom.xml</relativePath>
+    </parent>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.wookie</groupId>
+            <artifactId>wookie-parser</artifactId>
+            <version>2.0.0-SNAPSHOT</version>
+            <type>jar</type>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+  
+</project>
\ No newline at end of file

Added: wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/PreferencesService.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/PreferencesService.java?rev=1564596&view=auto
==============================================================================
--- wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/PreferencesService.java (added)
+++ wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/PreferencesService.java Wed Feb  5 01:00:59 2014
@@ -0,0 +1,70 @@
+/*
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+package org.apache.wookie.services;
+
+import java.util.Collection;
+import java.util.ServiceLoader;
+
+import org.apache.wookie.w3c.IPreference;
+
+/**
+ * The PreferencesService is the SPI for plugins that implement a preferences service; this service
+ * must be able to store and retrieve preferences for a particular instance of a widget. This can
+ * be via a database, a file system, cache etc., or by an API call to another service - for example
+ * you may want to store preferences in a central store within the portal that hosts the widgets.
+ * 
+ * To register an implementation, edit the name of the default class in:
+ * 
+ * src/main/resources/META-INF/services/org.apache.wookie.services.PreferencesService 
+ * 
+ * ... with the name of your service implementation. It must be on the classpath for the Wookie webapp.
+ *
+ */
+public interface PreferencesService {
+	
+	public abstract String getPreference(String token, String name);
+
+	public abstract void setPreference(String token, String name, String value);
+	
+	public abstract void setPreference(String token, String name, String value, boolean readOnly);
+	
+	public abstract void setPreference(String token, IPreference preference);
+
+	public abstract Collection<IPreference> getPreferences(String token);
+	
+	public abstract void setPreferences(String token, Collection<IPreference> preferences);
+	
+	public abstract void removePreferences(String token);
+	
+	public static class Factory {
+		
+		private static PreferencesService provider;
+		
+	    public static PreferencesService getInstance() {
+	    	if (provider == null){
+	    		ServiceLoader<PreferencesService> ldr = ServiceLoader.load(PreferencesService.class);
+	    		for (PreferencesService service : ldr) {
+	    			// We are only expecting one
+	    			provider = service;
+	    		}
+	    	}if (provider != null){
+	    		return provider;
+	    	}
+	    	throw new Error ("No Preferences Service Provider registered");
+	    }
+	}
+}

Added: wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferenceImpl.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferenceImpl.java?rev=1564596&view=auto
==============================================================================
--- wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferenceImpl.java (added)
+++ wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferenceImpl.java Wed Feb  5 01:00:59 2014
@@ -0,0 +1,14 @@
+package org.apache.wookie.services.impl;
+
+import org.apache.wookie.w3c.IPreference;
+import org.apache.wookie.w3c.impl.PreferenceEntity;
+
+public class DefaultPreferenceImpl extends PreferenceEntity implements IPreference{
+
+	public DefaultPreferenceImpl(String name, String value, boolean readOnly){
+		this.setName(name);
+		this.setValue(value);
+		this.setReadOnly(readOnly);
+	}
+	
+}

Added: wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java?rev=1564596&view=auto
==============================================================================
--- wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java (added)
+++ wookie/trunk/wookie-services/wookie-spi/src/main/java/org/apache/wookie/services/impl/DefaultPreferencesService.java Wed Feb  5 01:00:59 2014
@@ -0,0 +1,93 @@
+/*
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+package org.apache.wookie.services.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.apache.wookie.services.PreferencesService;
+import org.apache.wookie.w3c.IPreference;
+
+/**
+ * A very basic preferences model backed only by a hashmap in memory. All data
+ * is lost between server launches, so only use for testing.
+ */
+public class DefaultPreferencesService implements PreferencesService {
+
+	private HashMap <String, HashMap<String,IPreference>> preferences;
+	
+	public DefaultPreferencesService(){
+		this.preferences = new HashMap <String, HashMap<String,IPreference>>();
+	}
+	
+	@Override
+	public String getPreference(String token, String name) {
+		HashMap<String, IPreference> widgetpreferences = preferences.get(token);
+		if (widgetpreferences == null){
+			widgetpreferences = new HashMap<String, IPreference>();
+			this.preferences.put(token, widgetpreferences);
+		}
+		return widgetpreferences.get(name).getValue();
+	}
+
+	@Override
+	public void setPreference(String token, IPreference preference) {
+		HashMap<String, IPreference> widgetpreferences = preferences.get(token);
+		if (widgetpreferences == null){
+			widgetpreferences = new HashMap<String, IPreference>();
+			this.preferences.put(token, widgetpreferences);
+		}
+		widgetpreferences.put(preference.getName(), preference);
+	}
+
+	@Override
+	public Collection<IPreference> getPreferences(String token) {
+		HashMap<String, IPreference> widgetpreferences = preferences.get(token);
+		if (widgetpreferences == null){
+			widgetpreferences = new HashMap<String, IPreference>();
+			this.preferences.put(token, widgetpreferences);
+		}
+		return widgetpreferences.values();
+	}
+
+	@Override
+	public void removePreferences(String token) {
+		HashMap<String, IPreference> widgetpreferences = new HashMap<String, IPreference>();
+		preferences.put(token, widgetpreferences);
+	}
+
+	@Override
+	public void setPreferences(String token, Collection<IPreference> preferences) {
+		HashMap<String, IPreference> widgetpreferences = new HashMap<String, IPreference>();
+		for (IPreference preference: preferences){
+			widgetpreferences.put(preference.getName(), preference);
+		}
+		this.preferences.put(token, widgetpreferences);
+	}
+
+	@Override
+	public void setPreference(String token, String name, String value) {
+		setPreference(token, name, value, false);
+	}
+
+	@Override
+	public void setPreference(String token, String name, String value, boolean readOnly) {
+		IPreference preference = new DefaultPreferenceImpl(name, value, readOnly);
+		setPreference(token, preference);
+	}
+
+}