src/js/data.js
branchpopcorn-port
changeset 65 6a8cae20f190
parent 61 dc7b5ed7b02b
child 69 3f7a2e8a948f
--- a/src/js/data.js	Tue Oct 11 17:15:37 2011 +0200
+++ b/src/js/data.js	Wed Oct 12 11:54:26 2011 +0200
@@ -19,10 +19,46 @@
   }
 }
 
-IriSP.Serializer = function(DataLoader) {
-  this.DataLoader = DataLoader;
+/* the base abstract "class" */
+IriSP.Serializer = function(DataLoader, url) {
+  this._DataLoader = DataLoader;
+  this._url = url;
+};
+
+IriSP.Serializer.prototype.serialize = function(data) { };
+IriSP.Serializer.prototype.deserialize = function(data) {};
+
+IriSP.JSONSerializer = function(DataLoader, url) {
+  IriSP.Serializer.call(this, DataLoader, url);
+}
+
+IriSP.JSONSerializer.prototype = IriSP.Serializer;
+
+IriSP.JSONSerializer.prototype.serialize = function(data) {
+  return JSON.stringify(data);
 };
 
+IriSP.JSONSerializer.prototype.deserialize = function(data) {
+  return JSON.parse(data);
+};
+
+IriSP.SerializerFactory = function(DataLoader) {
+  this._dataloader = DataLoader;
+};
+
+IriSP.SerializerFactory.prototype.getSerializer = function(config) {
+  /* This function returns serializer set-up with the correct
+     configuration
+  */
+  switch(config.metadata.load) {
+    case "json":
+      return new IriSP.JSONSerializer(this._dataloader, config.metadata.src);
+    default:
+      return undefined;
+  }
+};
+
+
 IriSP.getMetadata = function() {
 	
 	IriSP.jQuery.ajax({