morphing into shape
[OpenSRF.git] / src / extras / fieldmapper.pl
index bd90d0b..defcd73 100644 (file)
@@ -10,8 +10,17 @@ print <<JS;
 
 //  ----------------------------------------------------------------
 // Autogenerated by fieldmapper.pl
+// Requires JSON.js
 //  ----------------------------------------------------------------
 
+function FieldmapperException(message) {
+       this.message = message;
+}
+FieldmapperException.toString = function() {
+       return "FieldmapperException: " + this.message + "\\n";
+}
+
+
 JS
 
 for my $object (keys %$map) {
@@ -27,12 +36,26 @@ print <<JS;
 JS
 
 print  <<JS;
+
 function $short_name(array) {
-       if(array) { this.array = array; } 
-       else { this.array = []; }
+
+       this.classname = "$short_name";
+       this._isfieldmapper = true;
+
+       if(array) { 
+               if( array.constructor == Array) 
+                       this.array = array;  
+
+               else
+                       throw new FieldmapperException(
+                               "Attempt to build fieldmapper object with non-array");
+
+       } else { this.array = []; }
+
 }
 
-$short_name.classname = "$short_name";
+$short_name._isfieldmapper = true;
+
 
 JS