Implement the toJSON method in all the JSONSerializable implementing classes that were missed in the previous iteration.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_result_distribution@1163 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
index 8ec036e..bfc0aba 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/IAObject.java
@@ -14,17 +14,15 @@
*/
package edu.uci.ics.asterix.om.base;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.types.IAType;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
+import edu.uci.ics.hyracks.api.dataflow.value.JSONSerializable;
/**
* Represents an object in Asterix.
*/
-public interface IAObject {
+public interface IAObject extends JSONSerializable {
public IAType getType();
public void accept(IOMVisitor visitor) throws AsterixException;
@@ -32,6 +30,4 @@
public boolean deepEqual(IAObject obj);
public int hash();
-
- public JSONObject toJSON() throws JSONException;
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AOrderedListType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AOrderedListType.java
index 59423e2..5620e4e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AOrderedListType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AOrderedListType.java
@@ -1,5 +1,8 @@
package edu.uci.ics.asterix.om.types;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import edu.uci.ics.asterix.om.base.IAObject;
public class AOrderedListType extends AbstractCollectionType {
@@ -52,4 +55,11 @@
public int hash() {
return hashCode();
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException{
+ JSONObject type = new JSONObject();
+ type.put("type", itemType);
+ return type;
+ }
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
index 1cf6ba7..9ad960f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/ARecordType.java
@@ -6,6 +6,10 @@
import java.util.List;
import java.util.Map;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import edu.uci.ics.asterix.common.annotations.IRecordTypeAnnotation;
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.base.IAObject;
@@ -123,4 +127,23 @@
return h;
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ if (isOpen) {
+ type.put("open", true);
+ } else {
+ type.put("open", false);
+ }
+
+ JSONArray fields = new JSONArray();
+ for (int i = 0; i < fieldNames.length; i++) {
+ JSONObject field = new JSONObject();
+ field.put(fieldNames[i], fieldTypes[i].toJSON());
+ fields.put(field);
+ }
+
+ type.put("fields", fields);
+ return type;
+ }
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnionType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnionType.java
index 1e70f15..dc74b6e 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnionType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnionType.java
@@ -4,6 +4,10 @@
import java.util.Iterator;
import java.util.List;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.base.IAObject;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
@@ -27,7 +31,7 @@
}
public boolean isNullableType() {
- return unionList.size() == 2 && unionList.get(0).equals(BuiltinType.ANULL);
+ return unionList.size() == 2 && unionList.get(0).equals(BuiltinType.ANULL);
}
@Override
@@ -100,4 +104,23 @@
return h;
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "UNION");
+
+ JSONArray fields = new JSONArray();
+
+ Iterator<IAType> iter = unionList.iterator();
+ if (iter.hasNext()) {
+ IAType t0 = iter.next();
+ fields.put(t0.toJSON());
+ while (iter.hasNext()) {
+ fields.put(iter.next().toJSON());
+ }
+ }
+
+ type.put("fields", fields);
+ return type;
+ }
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnorderedListType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnorderedListType.java
index c15dc49..a62bd5b 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnorderedListType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/AUnorderedListType.java
@@ -1,5 +1,8 @@
package edu.uci.ics.asterix.om.types;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import edu.uci.ics.asterix.om.base.IAObject;
public class AUnorderedListType extends AbstractCollectionType {
@@ -53,4 +56,10 @@
return hashCode();
}
+ @Override
+ public JSONObject toJSON() throws JSONException{
+ JSONObject type = new JSONObject();
+ type.put("type", itemType);
+ return type;
+ }
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/BuiltinType.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/BuiltinType.java
index 0ec3b21..4099c40 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/BuiltinType.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/types/BuiltinType.java
@@ -1,5 +1,8 @@
package edu.uci.ics.asterix.om.types;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import edu.uci.ics.asterix.common.exceptions.AsterixException;
import edu.uci.ics.asterix.om.base.IAObject;
import edu.uci.ics.asterix.om.visitors.IOMVisitor;
@@ -41,6 +44,13 @@
public String getConstructor() {
return null;
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AsterixType");
+ return type;
+ }
};
public final static BuiltinType AINT8 = new LowerCaseConstructorType() {
@@ -61,6 +71,13 @@
public String getTypeName() {
return "int8";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AInt8");
+ return type;
+ }
};
public final static BuiltinType AINT16 = new LowerCaseConstructorType() {
@@ -81,6 +98,13 @@
public String getTypeName() {
return "int16";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AInt16");
+ return type;
+ }
};
public final static BuiltinType AINT32 = new LowerCaseConstructorType() {
@@ -101,6 +125,13 @@
public String getTypeName() {
return "int32";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AInt32");
+ return type;
+ }
};
public static final BuiltinType AINT64 = new LowerCaseConstructorType() {
@@ -122,6 +153,12 @@
return "int64";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AInt64");
+ return type;
+ }
};
public final static BuiltinType ABINARY = new LowerCaseConstructorType() {
@@ -143,6 +180,12 @@
return "binary";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ABinary");
+ return type;
+ }
};
public final static BuiltinType AFLOAT = new LowerCaseConstructorType() {
@@ -164,6 +207,12 @@
return "float";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AFloat");
+ return type;
+ }
};
public final static BuiltinType ADOUBLE = new LowerCaseConstructorType() {
@@ -184,6 +233,13 @@
public String getTypeName() {
return "double";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ADouble");
+ return type;
+ }
};
public final static BuiltinType ASTRING = new LowerCaseConstructorType() {
@@ -204,6 +260,13 @@
public String getTypeName() {
return "string";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "AString");
+ return type;
+ }
};
public final static BuiltinType ANULL = new LowerCaseConstructorType() {
@@ -225,6 +288,12 @@
return "null";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "Null");
+ return type;
+ }
};
public final static BuiltinType ABOOLEAN = new LowerCaseConstructorType() {
@@ -246,6 +315,12 @@
return "boolean";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ABoolean");
+ return type;
+ }
};
public final static BuiltinType ATIME = new LowerCaseConstructorType() {
@@ -266,6 +341,13 @@
public String getTypeName() {
return "time";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ATime");
+ return type;
+ }
};
public final static BuiltinType ADATE = new LowerCaseConstructorType() {
@@ -286,6 +368,13 @@
public String getTypeName() {
return "date";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ADate");
+ return type;
+ }
};
public final static BuiltinType ADATETIME = new LowerCaseConstructorType() {
@@ -306,6 +395,13 @@
public String getTypeName() {
return "datetime";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ADateTime");
+ return type;
+ }
};
public final static BuiltinType ADURATION = new LowerCaseConstructorType() {
@@ -327,6 +423,12 @@
return "duration";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ADuration");
+ return type;
+ }
};
public final static BuiltinType APOINT = new LowerCaseConstructorType() {
@@ -347,6 +449,13 @@
public String getTypeName() {
return "point";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "APoint");
+ return type;
+ }
};
public final static BuiltinType APOINT3D = new LowerCaseConstructorType() {
@@ -367,6 +476,13 @@
public String getTypeName() {
return "point3d";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "APoint3D");
+ return type;
+ }
};
public final static BuiltinType ALINE = new LowerCaseConstructorType() {
@@ -388,6 +504,12 @@
return "line";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ALINE");
+ return type;
+ }
};
public final static BuiltinType APOLYGON = new LowerCaseConstructorType() {
@@ -409,6 +531,12 @@
return "polygon";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "APOLYGON");
+ return type;
+ }
};
public final static BuiltinType ACIRCLE = new LowerCaseConstructorType() {
@@ -430,6 +558,12 @@
return "circle";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ACIRCLE");
+ return type;
+ }
};
public final static BuiltinType ARECTANGLE = new LowerCaseConstructorType() {
@@ -451,6 +585,12 @@
return "rectangle";
}
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ARECTANGLE");
+ return type;
+ }
};
public static final IAType ABITARRAY = new LowerCaseConstructorType() {
@@ -471,6 +611,13 @@
public String getTypeName() {
return "abitarray";
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ABitArray");
+ return type;
+ }
};
public static final IAType ANY = new BuiltinType() {
@@ -496,6 +643,13 @@
public String getConstructor() {
return null;
}
+
+ @Override
+ public JSONObject toJSON() throws JSONException {
+ JSONObject type = new JSONObject();
+ type.put("type", "ANY");
+ return type;
+ }
};
public abstract String getConstructor();
@@ -515,25 +669,25 @@
return getTypeTag().toString();
}
- @Override
- public boolean deepEqual(IAObject obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof BuiltinType)) {
- return false;
- }
- return ((BuiltinType) obj).getTypeTag().equals(getTypeTag());
- }
+ @Override
+ public boolean deepEqual(IAObject obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof BuiltinType)) {
+ return false;
+ }
+ return ((BuiltinType) obj).getTypeTag().equals(getTypeTag());
+ }
@Override
public boolean equals(Object object) {
return this.deepEqual((IAObject) object);
}
-
+
@Override
public int hashCode() {
- return getTypeTag().hashCode();
+ return getTypeTag().hashCode();
}
@Override