aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Terry2013-03-22 13:40:06 (EDT)
committerDavid Terry2013-03-22 13:40:06 (EDT)
commiteff902ba11944292e08d03b493e9ad25f85cbef0 (patch)
tree657030ea7ff1037cf58a107c7917d72e87d37239
parentb349a3cd01469331e195c71cfea1a6fea6d60f4b (diff)
downloadorg.eclipse.lyo.rio-eff902ba11944292e08d03b493e9ad25f85cbef0.zip
org.eclipse.lyo.rio-eff902ba11944292e08d03b493e9ad25f85cbef0.tar.gz
org.eclipse.lyo.rio-eff902ba11944292e08d03b493e9ad25f85cbef0.tar.bz2
Bug 404172 Enhance TRS reference application to support listener patternrefs/changes/95/11395/1
Change-Id: I70ac9b7f7fdd78f4b805427c57e985d42a6235f2 Signed-off-by: David Terry <dgterry@us.ibm.com>
-rw-r--r--org.eclipse.lyo.rio.trs/pom.xml4
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/ChangeRequestListener.java6
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java (renamed from org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/Persistence.java)40
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java2
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtilHelper.java1
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/webapp/ChangeReq_modify.jsp2
6 files changed, 46 insertions, 9 deletions
diff --git a/org.eclipse.lyo.rio.trs/pom.xml b/org.eclipse.lyo.rio.trs/pom.xml
index ff306d9..86acb00 100644
--- a/org.eclipse.lyo.rio.trs/pom.xml
+++ b/org.eclipse.lyo.rio.trs/pom.xml
@@ -59,9 +59,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
- <version>2.0</version>
+ <version>2.1.1</version>
<configuration>
- <!-- no default value -->
+ <attachClasses>true</attachClasses>
</configuration>
</plugin>
<plugin>
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/ChangeRequestListener.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/ChangeRequestListener.java
new file mode 100644
index 0000000..2bb9433
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/ChangeRequestListener.java
@@ -0,0 +1,6 @@
+package org.eclipse.lyo.rio.trs.cm;
+
+
+public interface ChangeRequestListener {
+ public void changeRequestAltered(ChangeRequest changeRequest, String type);
+}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/Persistence.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java
index b5ab989..fab38ba 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/Persistence.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java
@@ -12,9 +12,10 @@
* Contributors:
*
* Ernest Mah - Initial implementation
+ * David Terry - Add Listener Mechanisms
*******************************************************************************/
-package org.eclipse.lyo.rio.trs.util;
+package org.eclipse.lyo.rio.trs.cm;
import java.io.File;
import java.io.FileInputStream;
@@ -24,6 +25,10 @@ import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Set;
import java.util.TreeMap;
import javax.ws.rs.WebApplicationException;
@@ -33,10 +38,8 @@ import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException;
import org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JContext;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JMarshaller;
-import org.eclipse.lyo.rio.trs.cm.ChangeRequest;
-import org.eclipse.lyo.rio.trs.cm.Constants;
-import org.eclipse.lyo.rio.trs.cm.Type;
+import com.hp.hpl.jena.graph.impl.FileGraph.NotifyOnClose;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileUtils;
@@ -45,8 +48,10 @@ public class Persistence {
private final static TreeMap<Long, ChangeRequest> CHANGE_REQUESTS_MAP = new TreeMap<Long, ChangeRequest>();
private static boolean CHANGE_REQUESTS_LOADED = false;
private static long MAX_IDENTIFIER;
-
public static int PAGE_SIZE = 3;
+
+ private static Set<ChangeRequestListener> listeners = new HashSet<ChangeRequestListener>();
+
private Persistence() {
super();
}
@@ -259,6 +264,9 @@ public class Persistence {
// save out to file here
save(Constants.PATH_FLAT_FILE);
+
+ // Notify any listeners of creation event
+ notifyListeners(changeRequest, "create");
}
}
@@ -276,6 +284,9 @@ public class Persistence {
// save out to file here
save(Constants.PATH_FLAT_FILE);
+ // Notify any listeners of the update event
+ notifyListeners(changeRequest, "update");
+
return changeRequest;
}
}
@@ -291,9 +302,28 @@ public class Persistence {
if (result != null) {
// save out to file here
save(Constants.PATH_FLAT_FILE);
+
+ // Notify any listeners of the deletion event
+ notifyListeners(result, "delete");
}
return result;
}
}
+
+ public static void addListner(ChangeRequestListener listener) {
+ listeners.add(listener);
+ }
+
+ public static void removeListener(ChangeRequestListener listener) {
+ listeners.remove(listener);
+ }
+
+ private static void notifyListeners(ChangeRequest changeRequest, String type) {
+ Iterator<ChangeRequestListener> iter = listeners.iterator();
+
+ while (iter.hasNext()) {
+ iter.next().changeRequestAltered(changeRequest, type);
+ }
+ }
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
index 58234f9..0a973e1 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
@@ -58,7 +58,7 @@ import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
import org.eclipse.lyo.oslc4j.core.model.ResponseInfoArray;
import org.eclipse.lyo.rio.trs.cm.ChangeRequest;
import org.eclipse.lyo.rio.trs.cm.Constants;
-import org.eclipse.lyo.rio.trs.util.Persistence;
+import org.eclipse.lyo.rio.trs.cm.Persistence;
import org.eclipse.lyo.rio.trs.util.TRSUtil;
@OslcService(Constants.CHANGE_MANAGEMENT_DOMAIN)
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtilHelper.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtilHelper.java
index 6d93fe6..de2d28c 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtilHelper.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtilHelper.java
@@ -33,6 +33,7 @@ import org.eclipse.lyo.core.trs.EmptyChangeLog;
import org.eclipse.lyo.core.trs.TRSConstants;
import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
import org.eclipse.lyo.rio.trs.cm.ChangeRequest;
+import org.eclipse.lyo.rio.trs.cm.Persistence;
public class TRSUtilHelper {
diff --git a/org.eclipse.lyo.rio.trs/src/main/webapp/ChangeReq_modify.jsp b/org.eclipse.lyo.rio.trs/src/main/webapp/ChangeReq_modify.jsp
index 7ae6e4e..91ef141 100644
--- a/org.eclipse.lyo.rio.trs/src/main/webapp/ChangeReq_modify.jsp
+++ b/org.eclipse.lyo.rio.trs/src/main/webapp/ChangeReq_modify.jsp
@@ -10,7 +10,7 @@
<%@ page import="java.io.Console"%>
<%@ page import="org.eclipse.lyo.rio.trs.cm.Severity" %>
<%@ page import="org.eclipse.lyo.rio.trs.cm.ChangeRequest" %>
- <%@ page import="org.eclipse.lyo.rio.trs.util.Persistence" %>
+ <%@ page import="org.eclipse.lyo.rio.trs.cm.Persistence" %>
<%
String modifyUri = (String) request.getAttribute("modifyUri");
String scriptPath = (String) request.getContextPath()+"/TestApp.js";