You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by lr...@apache.org on 2009/02/10 02:53:59 UTC

svn commit: r742816 [4/5] - in /incubator/shindig/trunk/java: common/ common/src/main/java/org/apache/shindig/protocol/ common/src/main/java/org/apache/shindig/protocol/conversion/ common/src/main/java/org/apache/shindig/protocol/conversion/jsonlib/ co...

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverterTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverterTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverterTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonLibConverterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverterTest.java Tue Feb 10 01:53:52 2009
@@ -15,245 +15,47 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion;
 
-import org.apache.shindig.social.JsonLibTestsGuiceModule;
-import org.apache.shindig.social.core.model.ActivityImpl;
-import org.apache.shindig.social.core.model.AddressImpl;
-import org.apache.shindig.social.core.model.ListFieldImpl;
-import org.apache.shindig.social.core.model.MediaItemImpl;
-import org.apache.shindig.social.core.model.NameImpl;
-import org.apache.shindig.social.core.model.PersonImpl;
-import org.apache.shindig.social.core.util.BeanJsonLibConversionException;
-import org.apache.shindig.social.core.util.BeanJsonLibConverter;
-import org.apache.shindig.social.opensocial.model.Activity;
-import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.ListField;
-import org.apache.shindig.social.opensocial.model.MediaItem;
-import org.apache.shindig.social.opensocial.model.Name;
-import org.apache.shindig.social.opensocial.model.Person;
+
+import org.apache.shindig.protocol.conversion.jsonlib.ApiValidator;
+import org.apache.shindig.protocol.conversion.jsonlib.JsonLibTestsGuiceModule;
+import org.apache.shindig.protocol.model.TestModel;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import junit.framework.TestCase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import net.sf.json.JSONObject;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
-public class BeanJsonLibConverterTest extends TestCase {
-
-  private static final Log log = LogFactory.getLog(BeanJsonLibConverterTest.class);
-  // taken from opensocial-reference/person.js
-  private static final String[] PERSON_FIELDS = { "id", "name", "nickname", "thumbnailUrl",
-      "profileUrl", "currentLocation", "addresses", "emails", "phoneNumbers", "aboutMe", "status",
-      "profileSong", "profileVideo", "gender", "sexualOrientation", "relationshipStatus", "age",
-      "dateOfBirth", "bodyType", "ethnicity", "smoker", "drinker", "children", "pets",
-      "livingArrangement", "timeZone", "languagesSpoken", "jobs", "jobInterests", "schools",
-      "interests", "urls", "music", "movies", "tvShows", "books", "activities", "sports", "heroes",
-      "quotes", "cars", "food", "turnOns", "turnOffs", "tags", "romance", "scaredOf",
-      "happiestWhen", "fashion", "humor", "lookingFor", "religion", "politicalViews", "hasApp",
-      "networkPresence" };
-
-  // taken from opensocial-reference/name.js
-  private static final String[] NAME_FIELDS = { "familyName", "givenName", "additionalName",
-      "honorificPrefix", "honorificSuffix", "formatted" };
-
-  private Person johnDoe;
-  private Activity activity;
 
+public class BeanJsonLibConverterTest extends TestCase {
+  private TestModel.Car car;
   private BeanJsonLibConverter beanJsonConverter;
-  private ApiValidator apiValidator;
-  // set to true to get loging output at info level
-  private boolean outputInfo = false;
 
   @Override
   public void setUp() throws Exception {
     super.setUp();
-    johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe"));
-    johnDoe.setPhoneNumbers(Lists.<ListField>newArrayList(
-        new ListFieldImpl("home", "+33H000000000"),
-        new ListFieldImpl("mobile", "+33M000000000"),
-        new ListFieldImpl("work", "+33W000000000")));
-
-    johnDoe.setAddresses(Lists.<Address>newArrayList(new AddressImpl("My home address")));
-
-    johnDoe.setEmails(Lists.<ListField>newArrayList(new ListFieldImpl("work", "john.doe@work.bar"),
-        new ListFieldImpl("home", "john.doe@home.bar")));
-
-    activity = new ActivityImpl("activityId", johnDoe.getId());
-
-    activity.setMediaItems(Lists.<MediaItem>newArrayList(new MediaItemImpl("image/jpg",
-        MediaItem.Type.IMAGE, "http://foo.bar")));
-
+    car = new TestModel.Car();
     Injector injector = Guice.createInjector(new JsonLibTestsGuiceModule());
     beanJsonConverter = injector.getInstance(BeanJsonLibConverter.class);
-
-    apiValidator = new ApiValidator();
-
-  }
-
-  public static class SpecialPerson extends PersonImpl {
-    public static final String[] OPTIONALFIELDS = {};
-    public static final String[] NULLFIELDS = { "jobInterests", "nickname", "romance", "religion",
-        "timeZone", "relationshipStatus", "tags", "networkPresence", "books", "quotes",
-        "phoneNumbers", "languagesSpoken", "activities", "jobs", "dateOfBirth", "profileVideo",
-        "bodyType", "urls", "schools", "music", "addresses", "livingArrangement", "thumbnailUrl",
-        "humor", "sports", "scaredOf", "movies", "age", "pets", "hasApp", "turnOffs", "gender",
-        "fashion", "drinker", "aboutMe", "children", "sexualOrientation", "heroes", "profileSong",
-        "lookingFor", "cars", "turnOns", "tvShows", "profileUrl", "status", "currentLocation",
-        "smoker", "happiestWhen", "ethnicity", "food", "emails", "politicalViews", "interests",
-        "familyName", "honorificSuffix", "additionalName", "honorificPrefix", "givenName" };
-
-    private String newfield;
-
-    public SpecialPerson() {
-      super();
-    }
-
-    public SpecialPerson(String id, String name, String newfield) {
-      super(id, name, new NameImpl(name));
-      this.newfield = newfield;
-    }
-
-    public String getNewfield() {
-      return newfield;
-    }
-
-    public void setNewfield(String newfield) {
-      this.newfield = newfield;
-    }
-
   }
 
   public void testToJsonOnInheritedClass() throws Exception {
-    SpecialPerson cassie = new SpecialPerson("5", "robot", "nonsense");
-
-    String result = beanJsonConverter.convertToString(cassie);
-
-    validatePerson(result, "5", "robot", SpecialPerson.OPTIONALFIELDS, SpecialPerson.NULLFIELDS);
-
-    String[] optional = {};
-    String[] nullfields = {};
-    Map<String, Object> special = apiValidator.validate(result, new String[] { "newfield" },
-        optional, nullfields);
-    assertNotNull(special.get("newfield"));
-    assertSame(String.class, special.get("newfield").getClass());
-    assertEquals("nonsense", special.get("newfield"));
-
-    // convert back into an object Tree
-
-    SpecialPerson parseCassie = beanJsonConverter.convertToObject(result, SpecialPerson.class);
-
-    assertNotNull(parseCassie);
-    assertEquals(cassie.getId(), parseCassie.getId());
-    assertEquals(cassie.getNewfield(), parseCassie.getNewfield());
-
-    Name name = parseCassie.getName();
-    Name cassieName = cassie.getName();
-    assertNotNull(name);
-    assertEquals(cassieName.getFormatted(), name.getFormatted());
-    assertEquals(cassieName.getAdditionalName(), name.getAdditionalName());
-    assertEquals(cassieName.getFamilyName(), name.getFamilyName());
-    assertEquals(cassieName.getGivenName(), name.getGivenName());
-    assertEquals(cassieName.getHonorificPrefix(), name.getHonorificPrefix());
-    assertEquals(cassieName.getHonorificSuffix(), name.getHonorificSuffix());
-
+    TestModel.ExpensiveCar roller = new TestModel.ExpensiveCar();
+    JSONObject result = beanJsonConverter.convertToJson(roller);
+    assertEquals(roller.getCost(), result.getInt("cost"));
+    assertEquals(roller.getParkingTickets().size(), result.getJSONObject("parkingTickets").size());
   }
 
-  /**
-   * @param result
-   * @throws ApiValidatorExpcetion
-   */
-  private void validatePerson(String result, String id, String name, String[] optional,
-      String[] nullfields) throws ApiValidatorExpcetion {
-
-    Map<String, Object> standard = apiValidator.validate(result, PERSON_FIELDS, optional,
-        nullfields);
-    assertNotNull(standard.get("id"));
-    assertSame(String.class, standard.get("id").getClass());
-    assertEquals(id, standard.get("id"));
-
-    assertNotNull(standard.get("name"));
-    Map<String, Object> nameJSON = apiValidator.validateObject(standard.get("name"), NAME_FIELDS,
-        optional, nullfields);
-    ApiValidator.dump(nameJSON);
-
-    assertNotNull(nameJSON.get("formatted"));
-    assertEquals(String.class, nameJSON.get("formatted").getClass());
-    assertEquals(name, nameJSON.get("formatted"));
-
-    // additional name
-    assertNull(nameJSON.get("additionalName"));
-
-  }
-
-  public void testPersonToJson() throws Exception {
-    String result = beanJsonConverter.convertToString(johnDoe);
-    if (outputInfo) {
-      log.info("JSON (" + result + ')');
-    }
-    Person parsedPerson = beanJsonConverter.convertToObject(result, Person.class);
-
-    assertEquals(johnDoe.getId(), parsedPerson.getId());
-    assertEquals(johnDoe.getName().getFormatted(), parsedPerson.getName().getFormatted());
-
-    List<Address> addresses = parsedPerson.getAddresses();
-    if (outputInfo) {
-      for (Object o : addresses) {
-        log.info("Address " + o);
-      }
-    }
-
-    assertEquals(1, addresses.size());
-    Address address = addresses.get(0);
-    String formatted = address.getFormatted();
-
-    assertNotNull(formatted);
-    assertEquals(johnDoe.getAddresses().get(0).getFormatted(), parsedPerson
-        .getAddresses().get(0).getFormatted());
-
-    assertEquals(3, parsedPerson.getPhoneNumbers().size());
-
-    for (int i = 0; i < johnDoe.getPhoneNumbers().size(); i++) {
-      ListField expectedPhone = johnDoe.getPhoneNumbers().get(i);
-      ListField actualPhone = parsedPerson.getPhoneNumbers().get(i);
-      assertEquals(expectedPhone.getType(), actualPhone.getType());
-      assertEquals(expectedPhone.getValue(), actualPhone.getValue());
-    }
-
-    assertEquals(2, parsedPerson.getEmails().size());
-
-    for (int i = 0; i < johnDoe.getEmails().size(); i++) {
-      ListField expectedEmail = johnDoe.getEmails().get(i);
-      ListField actualEmail = parsedPerson.getEmails().get(i);
-      assertEquals(expectedEmail.getType(), actualEmail.getType());
-      assertEquals(expectedEmail.getValue(), actualEmail.getValue());
-    }
-  }
-
-  public void testActivityToJson() throws Exception {
-
-    String result = beanJsonConverter.convertToString(activity);
-    if (outputInfo) {
-      log.info("JSON (" + result + ')');
-    }
-    Activity parsedActivity = beanJsonConverter.convertToObject(result, Activity.class);
-    assertEquals(activity.getUserId(), parsedActivity.getUserId());
-    assertEquals(activity.getId(), parsedActivity.getId());
-
-    assertEquals(1, parsedActivity.getMediaItems().size());
-
-    MediaItem expectedItem = activity.getMediaItems().get(0);
-    MediaItem actualItem = parsedActivity.getMediaItems().get(0);
-
-    assertEquals(expectedItem.getUrl(), actualItem.getUrl());
-    assertEquals(expectedItem.getMimeType(), actualItem.getMimeType());
-    assertEquals(expectedItem.getType().toString(), actualItem.getType().toString());
+  public void testCarToJson() throws Exception {
+    JSONObject object = beanJsonConverter.convertToJson(car);
+    assertEquals(object, JSONObject.fromObject(TestModel.Car.DEFAULT_JSON));
   }
 
   public void testMapsToJson() throws Exception {
@@ -271,18 +73,12 @@
     map.put("item2", item2Map);
 
     String result = beanJsonConverter.convertToString(map);
-    if (outputInfo) {
-      log.info("JSON (" + result + ')');
-    }
     // there is introspection that can tell jsonobject -> bean converter what a
     // map should contain, so we have to tell it
     beanJsonConverter.addMapping("item1", Map.class);
     beanJsonConverter.addMapping("item2", Map.class);
     Map<?, ?> parsedMap = beanJsonConverter.convertToObject(result, Map.class);
 
-    if (outputInfo) {
-      log.info("Dumping Map (" + parsedMap + ')');
-    }
     ApiValidator.dump(parsedMap);
 
     assertEquals("1", ((Map<?, ?>) parsedMap.get("item1")).get("value"));
@@ -304,9 +100,6 @@
     list.add(item1Map);
     list.add(item2Map);
     String result = beanJsonConverter.convertToString(list);
-    if (outputInfo) {
-      log.info("JSON (" + result + ')');
-    }
     Map<?, ?>[] parsedList = beanJsonConverter.convertToObject(result, Map[].class);
 
     assertEquals("1", parsedList[0].get("value"));
@@ -316,9 +109,6 @@
   public void testArrayToJson() throws Exception {
     String[] colors = { "blue", "green", "aquamarine" };
     String result = beanJsonConverter.convertToString(colors);
-    if (outputInfo) {
-      log.info("JSON (" + result + ')');
-    }
     String[] parsedColors = beanJsonConverter.convertToObject(result, String[].class);
     assertEquals(colors.length, parsedColors.length);
     assertEquals(colors[0], parsedColors[0]);
@@ -326,23 +116,6 @@
     assertEquals(colors[2], parsedColors[2]);
   }
 
-  public void testJsonToActivity() throws Exception {
-    String jsonActivity = "{userId : 5, id : 6, mediaItems : ["
-        + "{url : 'hello', mimeType : 'mimey', type : 'VIDEO'}" + "]}";
-    Activity result = beanJsonConverter.convertToObject(jsonActivity, Activity.class);
-
-    assertEquals("5", result.getUserId());
-    assertEquals("6", result.getId());
-
-    assertEquals(1, result.getMediaItems().size());
-
-    MediaItem actualItem = result.getMediaItems().get(0);
-
-    assertEquals("hello", actualItem.getUrl());
-    assertEquals("mimey", actualItem.getMimeType());
-    assertEquals("video", actualItem.getType().toString());
-  }
-
   @SuppressWarnings("unchecked")
   public void testJsonToMap() throws Exception {
     String jsonActivity = "{count : 0, favoriteColor : 'yellow'}";
@@ -369,13 +142,4 @@
     assertEquals(0, beanJsonConverter.convertToObject("[]", String[].class).length);
     assertEquals(2, beanJsonConverter.convertToObject("[\"a\",\"b\"]", String[].class).length);
   }
-
-  public void testException() {
-    // a bit brain dead, but makes certain the exception is available in all forms
-    assertNotNull(new BeanJsonLibConversionException());
-    assertNotNull(new BeanJsonLibConversionException("message"));
-    assertNotNull(new BeanJsonLibConversionException(new Exception()));
-    assertNotNull(new BeanJsonLibConversionException("message", new Exception()));
-  }
-
 }

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonLibConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXmlConverterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java Tue Feb 10 01:53:52 2009
@@ -15,108 +15,35 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.shindig.common.xml.XmlUtil;
-import org.apache.shindig.social.core.model.ActivityImpl;
-import org.apache.shindig.social.core.model.AddressImpl;
-import org.apache.shindig.social.core.model.ListFieldImpl;
-import org.apache.shindig.social.core.model.MediaItemImpl;
-import org.apache.shindig.social.core.model.NameImpl;
-import org.apache.shindig.social.core.model.PersonImpl;
-import org.apache.shindig.social.core.util.BeanXmlConverter;
-import org.apache.shindig.social.opensocial.model.Activity;
-import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.ListField;
-import org.apache.shindig.social.opensocial.model.MediaItem;
-import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.protocol.model.TestModel;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 import junit.framework.TestCase;
-import org.apache.commons.lang.StringUtils;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 import java.util.Map;
-import java.util.TreeMap;
 
+/**
+ * Basic test for betwixt based XML conversion
+ */
 public class BeanXmlConverterTest extends TestCase {
-  private Person johnDoe;
-  private Activity activity;
-
+  private TestModel.Car car;
   private BeanXmlConverter beanXmlConverter;
 
   @Override
   public void setUp() throws Exception {
     super.setUp();
-    johnDoe = new PersonImpl("johnDoeId", "Johnny", new NameImpl("John Doe"));
-    johnDoe.setPhoneNumbers(Lists.<ListField>newArrayList(
-        new ListFieldImpl("home", "+33H000000000"),
-        new ListFieldImpl("mobile", "+33M000000000"),
-        new ListFieldImpl("work", "+33W000000000")));
-
-    johnDoe.setAddresses(Lists.<Address>newArrayList(new AddressImpl("My home address")));
-
-    johnDoe.setEmails(Lists.<ListField>newArrayList(
-        new ListFieldImpl("work", "john.doe@work.bar"),
-        new ListFieldImpl("home", "john.doe@home.bar")));
-
-    activity = new ActivityImpl("activityId", johnDoe.getId());
-
-    activity.setMediaItems(Lists.<MediaItem>newArrayList(
-        new MediaItemImpl("image/jpg", MediaItem.Type.IMAGE, "http://foo.bar")));
-
+    car = new TestModel.Car();
     beanXmlConverter = new BeanXmlConverter();
   }
 
-  public static class SimplePerson {
-    private String id;
-    private String name;
-
-    public SimplePerson(String id, String name) {
-      this.id = id;
-      this.name = name;
-    }
-
-    public String getId() {
-      return id;
-    }
-
-    public String getName() {
-      return name;
-    }
-  }
-
-  public void testToXmlOnSimpleClass() throws Exception {
-    SimplePerson cassie = new SimplePerson("5", "robot");
-    String xml = beanXmlConverter.convertToXml(cassie);
-
-    Element element = XmlUtil.parse(xml);
-    Node id = element.getElementsByTagName("id").item(0);
-    Node name = element.getElementsByTagName("name").item(0);
-
-    assertEquals("5", id.getTextContent());
-    assertEquals("robot", name.getTextContent());
-  }
-
-  public void testPersonToXml() throws Exception {
-    String xml = beanXmlConverter.convertToXml(johnDoe);
-    // TODO: Make the person xml stop returning empty elements!
-    // TODO: Flush out the test to check all the sub fields
-    Element element = XmlUtil.parse(xml);
-    Node id = element.getElementsByTagName("id").item(0);
-    assertEquals(johnDoe.getId(), id.getTextContent());
-  }
-
-  public void testActivityToXml() throws Exception {
-    String xml = beanXmlConverter.convertToXml(activity);
-    // TODO: Make the activity xml stop returning empty elements!
-    // TODO: Flush out the test to check all the sub fields
-    Element element = XmlUtil.parse(xml);
-    Node id = element.getElementsByTagName("id").item(0);
-    assertEquals(activity.getId(), id.getTextContent());
+  public void testCarToXml() throws Exception {
+    String xml = beanXmlConverter.convertToXml(car);
+    assertEquals(xml, TestModel.Car.DEFAULT_XML);
   }
 
   public void xxxtestMapsToXml() throws Exception {

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidator.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidator.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidator.java (added)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidator.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,409 @@
+/*
+ * 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.
+ */
+package org.apache.shindig.protocol.conversion.jsonlib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.EvaluatorException;
+import org.mozilla.javascript.Script;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * A class that loads a feature set from features into a Javascript Parser to
+ * make the model available to validate JSON messages against.
+ */
+public class ApiValidator {
+
+  private static final Log log = LogFactory.getLog(ApiValidator.class);
+  private Context ctx;
+  private ScriptableObject scope;
+
+  /**
+   * @param feature
+   *                The name of the feature are eg "opensocial-reference", this
+   *                is a classpath stub (not starting with /) where the location
+   *                contains a feature.xml file.
+   * @throws SAXException
+   *                 if feature.xml is not parsable
+   * @throws ParserConfigurationException
+   *                 if the parsers are invalid
+   * @throws IOException
+   *                 if feature.xml or the javascript that represents the
+   *                 feature is missing
+   *
+   */
+  private ApiValidator(String feature) throws IOException,
+      ParserConfigurationException, SAXException {
+    ctx = Context.enter();
+    scope = ctx.initStandardObjects();
+    load(feature);
+  }
+
+  /**
+   * Load the ApiValidator with no features, this avoids having features in the classpath
+   * @throws IOException
+   */
+  public ApiValidator() throws IOException {
+    ctx = Context.enter();
+    scope = ctx.initStandardObjects();
+  }
+
+  /**
+   * @param json
+   *                The json to validate expected in a form { xyz: yyy } form
+   * @param object
+   *                The json Fields object specifying the structure of the json
+   *                object, each field in this object contains the name of the
+   *                json field in the json structure.
+   * @param optionalFields
+   *                If any of the fields that appear in the json structure are
+   *                optional, then they should be defined in this parameter.
+   * @param nullfields
+   * @throws ApiValidatorException
+   *                 if there is a problem validating the json
+   * @return a map so string object pairs containing the fields at the top level
+   *         of the json tree. Where these are native java objects, they will
+   *         appear as native object. Complex json objects will appear as Rhino
+   *         specific objects
+   */
+  public Map<String, Object> validate(String json, String object,
+      String[] optionalFields, String[] nullfields)
+      throws ApiValidatorException {
+
+    /*
+     * Object[] ids = ScriptableObject.getPropertyIds(scope); for (Object id :
+     * ids) { Object o = ScriptableObject.getProperty(scope,
+     * String.valueOf(id)); log.debug("ID is " + id + " class " + id.getClass() + "
+     * is " + o); if (o instanceof ScriptableObject) {
+     * listScriptable(String.valueOf(id), (ScriptableObject) o); } }
+     */
+
+    log.debug("Loading " + json);
+    json = json.trim();
+    if (!json.endsWith("}")) {
+      json = json + '}';
+    }
+    if (!json.startsWith("{")) {
+      json = '{' + json;
+    }
+    json = "( testingObject = " + json + " )";
+
+    Object so = null;
+    try {
+      so = ctx.evaluateString(scope, json, "test json", 0, null);
+    } catch (EvaluatorException ex) {
+      log.error("Non parseable JSON " + json);
+    }
+    log.debug("Loaded " + so);
+
+    ScriptableObject specification = getScriptableObject(object);
+    log.debug("Looking for  " + object + " found " + specification);
+    listScriptable(object, specification);
+    Object[] fields = specification.getIds();
+    String[] fieldNames = new String[fields.length];
+    for (int i = 0; i < fields.length; i++) {
+      Object fieldName = specification.get(String.valueOf(fields[i]), specification);
+      fieldNames[i] = String.valueOf(fieldName);
+    }
+
+    return validateObject(so, fieldNames, optionalFields, nullfields);
+
+  }
+
+  /**
+   * @param json
+   *                The json to validate expected in a form { xyz: yyy } form
+   * @param fieldNames
+   *                An Array of field names that the oject should be tested against
+   * @param optionalFields
+   *                If any of the fields that appear in the json structure are
+   *                optional, then they should be defined in this parameter.
+   * @param nullfields
+   * @throws ApiValidatorException
+   *                 if there is a problem validating the json
+   * @return a map so string object pairs containing the fields at the top level
+   *         of the json tree. Where these are native java objects, they will
+   *         appear as native object. Complex json objects will appear as Rhino
+   *         specific objects
+   */
+  public Map<String, Object> validate(String json, String[] fieldNames,
+      String[] optionalFields, String[] nullfields)
+      throws ApiValidatorException {
+
+
+    log.debug("Loading " + json);
+    json = json.trim();
+    if (!json.endsWith("}")) {
+      json = json + '}';
+    }
+    if (!json.startsWith("{")) {
+      json = '{' + json;
+    }
+    json = "( testingObject = " + json + " )";
+
+    Object so = null;
+    try {
+      so = ctx.evaluateString(scope, json, "test json", 0, null);
+    } catch (EvaluatorException ex) {
+      log.error("Non parseable JSON " + json);
+    }
+    log.debug("Loaded " + so);
+
+
+    return validateObject(so, fieldNames, optionalFields, nullfields);
+
+  }
+
+  /**
+   * Validate an JSON Object extracted
+  * @throws ApiValidatorException
+   */
+  public Map<String, Object> validateObject(Object jsonObject, String[] fieldNames,
+      String[] optionalFields, String[] nullFields)
+      throws ApiValidatorException {
+    Map<String, String> optional = Maps.newHashMap();
+    for (String opt : optionalFields) {
+      optional.put(opt, opt);
+    }
+    Map<String, String> nullf = Maps.newHashMap();
+    for (String nf : nullFields) {
+      nullf.put(nf, nf);
+    }
+
+
+    Map<String, Object> resultFields = Maps.newHashMap();
+
+    if (jsonObject instanceof ScriptableObject) {
+      ScriptableObject parsedJSONObject = (ScriptableObject) jsonObject;
+      listScriptable("testingObject", parsedJSONObject);
+      for (String fieldName : fieldNames) {
+        Object o = parsedJSONObject.get(fieldName,
+            parsedJSONObject);
+        if (o == Scriptable.NOT_FOUND) {
+          if (optional.containsKey(fieldName)) {
+            log.warn("Missing Optional Field " + fieldName);
+          } else if (!nullf.containsKey(fieldName)) {
+            log.error("Missing Field " + fieldName);
+            throw new ApiValidatorException("Missing Field " + fieldName);
+          }
+        } else {
+          if (nullf.containsKey(fieldName)) {
+            log.error("Field should have been null and was not");
+          }
+          if (o == null) {
+            if (nullf.containsKey(fieldName)) {
+              log.error("Null Fields has been serialized " + fieldName);
+            }
+            log.debug("Got a Null object for Field " + fieldName
+                + " on json [[" + jsonObject + "]]");
+
+          } else {
+
+            log.debug("Got JSON Field  Field,"  + fieldName + " as "
+                + o + ' ' + o.getClass());
+          }
+          resultFields.put(String.valueOf(fieldName), o);
+        }
+      }
+
+    } else {
+      throw new ApiValidatorException(
+          "Parsing JSON resulted in invalid Javascript object, which was "
+              + jsonObject + " JSON was [[" + jsonObject + "]]");
+    }
+    return resultFields;
+  }
+
+  /**
+   * get an object from the json context and scope.
+   *
+   * @param object
+   *                the name of the object specified as a path from the base
+   *                object
+   * @return the json object
+   */
+  private ScriptableObject getScriptableObject(String object) {
+    String[] path = object.split("\\.");
+    log.debug("Looking up " + object + " elements " + path.length);
+
+    ScriptableObject s = scope;
+    for (String pe : path) {
+      log.debug("Looking up " + pe + " in " + s);
+      s = (ScriptableObject) s.get(pe, s);
+      log.debug("Looking for " + pe + " in found " + s);
+    }
+    return s;
+  }
+
+  /**
+   * List a scriptable object at log debug level, constructors will not be
+   * expanded as this loads to recursion.
+   *
+   * @param id
+   *                The name of the object
+   * @param scriptableObject
+   *                the scriptable Object
+   */
+  private void listScriptable(String id, ScriptableObject scriptableObject) {
+    log.debug("ID is Scriptable " + id);
+    if (!id.endsWith("constructor")) {
+      Object[] allIDs = scriptableObject.getAllIds();
+      for (Object oid : allIDs) {
+        log.debug(id + '.' + oid);
+        Object o = scriptableObject.get(String.valueOf(oid), scriptableObject);
+        if (o instanceof ScriptableObject) {
+          listScriptable(id + '.' + String.valueOf(oid), (ScriptableObject) o);
+        }
+      }
+    }
+  }
+
+  /**
+   * Load a feature based on the spec
+   *
+   * @param spec
+   *                The name of the location of the spec in the classpath, must
+   *                not start with a '/' and must should contain a feature.xml
+   *                file in the location
+   * @throws IOException
+   *                 If any of the resources cant be found
+   * @throws ParserConfigurationException
+   *                 If the parser has a problem being constructed
+   * @throws SAXException
+   *                 on a parse error on the features.xml
+   */
+  private void load(String spec) throws IOException, SAXException,
+      ParserConfigurationException {
+
+    List<String> scripts = getScripts(spec);
+
+    List<Script> compiled = Lists.newArrayList();
+    for (String script : scripts) {
+      String scriptPath = spec + '/' + script;
+      InputStream in = this.getClass().getClassLoader().getResourceAsStream(
+          scriptPath);
+      if (in == null) {
+        in = this.getClass().getClassLoader().getResourceAsStream(
+            "features/" + scriptPath);
+        if (in == null) {
+          throw new IOException("Cant load spec " + spec + " or features/"
+              + spec + " from classpath");
+        }
+      }
+      InputStreamReader reader = new InputStreamReader(in);
+      Script compiledScript = ctx.compileReader(reader, spec, 0, null);
+      compiled.add(compiledScript);
+    }
+
+    for (Script compiledScript : compiled) {
+      compiledScript.exec(ctx, scope);
+    }
+
+  }
+
+  /**
+   * Add some javascript to the context, and execute it. If extra custom
+   * javascript is wanted in the context or scope then this method will load it.
+   *
+   * @param javascript
+   */
+  public void addScript(String javascript) {
+    Script compileScript = ctx.compileString(javascript, "AdditionalJS", 0,
+        null);
+    compileScript.exec(ctx, scope);
+  }
+
+  /**
+   * Get an ordered list of javascript resources from a feature sets.
+   *
+   * @param spec
+   *                The spec location
+   * @return An ordered list of javascript resources, these are relative to
+   *         specification file.
+   * @throws IOException
+   *                 If any of the resources can't be loaded.
+   * @throws SAXException
+   *                 Where the feature.xml file is not parsable
+   * @throws ParserConfigurationException
+   *                 where the parser can't be constructed.
+   * @return An ordered list of script that need to be loaded and executed to
+   *         make the feature available in the context.
+   */
+  private List<String> getScripts(String spec) throws SAXException,
+      IOException, ParserConfigurationException {
+    String features = spec + "/feature.xml";
+    InputStream in = this.getClass().getClassLoader().getResourceAsStream(
+        features);
+    if (in == null) {
+      in = this.getClass().getClassLoader().getResourceAsStream(
+          "features/" + features);
+      if (in == null) {
+        throw new IOException("Cant find " + features + " or features/"
+            + features + " in classpath ");
+      }
+    }
+    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
+        .newInstance();
+    DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
+    Document doc = documentBuilder.parse(in);
+    NodeList nl = doc.getElementsByTagName("script");
+    List<String> scripts = Lists.newArrayList();
+    for (int i = 0; i < nl.getLength(); i++) {
+      Node scriptNode = nl.item(i);
+      NamedNodeMap attributes = scriptNode.getAttributes();
+      Node scriptAttr = attributes.getNamedItem("src");
+      String script = scriptAttr.getNodeValue();
+      scripts.add(script);
+    }
+    return scripts;
+  }
+
+  /**
+   * @param nameJSON
+   */
+  public static void dump(Map<?, ?> nameJSON) {
+    if (log.isDebugEnabled()) {
+      for (Entry<?, ?> entry : nameJSON.entrySet()) {
+        Object k = entry.getKey();
+        Object o = entry.getValue();
+        log.info("Key [" + k + "] value:[" + (o == null ? "null" : o + ":" + o.getClass()) + ']');
+      }
+    }
+  }
+
+}

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorException.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/ApiValidatorExpcetion.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorException.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorException.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/ApiValidatorExpcetion.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/ApiValidatorExpcetion.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorException.java Tue Feb 10 01:53:52 2009
@@ -15,27 +15,27 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
 /**
  * Thrown when there is a validation exception on one of the apis
  */
-public class ApiValidatorExpcetion extends Exception {
+public class ApiValidatorException extends Exception {
 
   private static final long serialVersionUID = -8969858718669454612L;
 
-  public ApiValidatorExpcetion() {
+  public ApiValidatorException() {
   }
 
-  public ApiValidatorExpcetion(String message) {
+  public ApiValidatorException(String message) {
     super(message);
   }
 
-  public ApiValidatorExpcetion(Throwable cause) {
+  public ApiValidatorException(Throwable cause) {
     super(cause);
   }
   
-  public ApiValidatorExpcetion(String message, Throwable cause) {
+  public ApiValidatorException(String message, Throwable cause) {
     super(message, cause);
   }
 

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorTest.java?rev=742816&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorTest.java (added)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/ApiValidatorTest.java Tue Feb 10 01:53:52 2009
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+package org.apache.shindig.protocol.conversion.jsonlib;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Test the api validator to make certain it behaves as is expected.
+ */
+public class ApiValidatorTest {
+
+  /**
+   * A definition of the test json used in this unit test.
+   */
+  private static final String TEST_DEFINITION = "var TestDef = {}; "
+    + "TestDef.Field = { FIELD1 : \"json\", FIELD2 : \"xyz\", FIELD3 : \"shouldBeMissing\" };";
+  private static final String[] TEST_DEFINITION_FIELDS = {
+    "json",
+    "xyz",
+    "shouldBeMissing"
+  };
+
+  /**
+   * test the validator for successful validation.
+   * @throws ApiValidatorException
+   * @throws IOException
+   * @throws ParserConfigurationException
+   * @throws SAXException
+   */
+  @Test
+  public void testValidator() throws ApiValidatorException, IOException,
+      ParserConfigurationException, SAXException {
+    ApiValidator apiVal = new ApiValidator();
+    apiVal.addScript(TEST_DEFINITION);
+    String[] optional = { "shouldBeMissing" };
+    String[] nullfields = {};
+    Map<String, Object> result = apiVal.validate("{ json: \"A Test JSON\", xyz : 123 }",
+        "TestDef.Field", optional, nullfields);
+    Assert.assertNotNull(result);
+    Assert.assertNotNull(result.get("json"));
+    Assert.assertNotNull(result.get("xyz"));
+    Assert.assertSame(String.class, result.get("json").getClass());
+    Assert.assertSame(Integer.class, result.get("xyz").getClass());
+    Assert.assertEquals("A Test JSON", result.get("json"));
+    Assert.assertEquals(123, ((Integer) result.get("xyz")).intValue());
+  }
+
+  /**
+   * Test for a failing validation
+   *
+   * @throws ApiValidatorException
+   * @throws IOException
+   * @throws ParserConfigurationException
+   * @throws SAXException
+   */
+  @Test
+  public void testValidatorFail() throws ApiValidatorException, IOException,
+      ParserConfigurationException, SAXException {
+    ApiValidator apiVal = new ApiValidator();
+    apiVal.addScript(TEST_DEFINITION);
+    String[] optional = {};
+    String[] nullfields = {};
+    try {
+      apiVal.validate("{ jsonIsMissing: \"A Test JSON\", xyz : 123 }", "TestDef.Field", optional,
+          nullfields);
+      Assert.fail("Should have Generated an APIValidatorException ");
+    } catch (ApiValidatorException ex) {
+
+    }
+  }
+  /**
+   * test the validator for successful validation
+   *
+   * @throws ApiValidatorException
+   * @throws IOException
+   * @throws ParserConfigurationException
+   * @throws SAXException
+   */
+  @Test
+  public void testFieldsValidator() throws ApiValidatorException, IOException,
+      ParserConfigurationException, SAXException {
+    ApiValidator apiVal = new ApiValidator();
+    String[] optional = { "shouldBeMissing" };
+    String[] nullfields = {};
+    Map<String, Object> result = apiVal.validate("{ json: \"A Test JSON\", xyz : 123 }",
+        TEST_DEFINITION_FIELDS, optional, nullfields);
+    Assert.assertNotNull(result);
+    Assert.assertNotNull(result.get("json"));
+    Assert.assertNotNull(result.get("xyz"));
+    Assert.assertSame(String.class, result.get("json").getClass());
+    Assert.assertSame(Integer.class, result.get("xyz").getClass());
+    Assert.assertEquals("A Test JSON", result.get("json"));
+    Assert.assertEquals(123, ((Integer) result.get("xyz")).intValue());
+
+  }
+
+  /**
+   * Test for a failing validation
+   * @throws ApiValidatorException
+   * @throws IOException
+   * @throws ParserConfigurationException
+   * @throws SAXException
+   */
+  @Test
+  public void testFieldsValidatorFail() throws ApiValidatorException, IOException,
+      ParserConfigurationException, SAXException {
+    ApiValidator apiVal = new ApiValidator();
+    String[] optional = {};
+    String[] nullfields = {};
+    try {
+      apiVal.validate("{ jsonIsMissing: \"A Test JSON\", xyz : 123 }", TEST_DEFINITION_FIELDS,
+          optional, nullfields);
+      Assert.fail("Should have Generated an APIValidatorException ");
+    } catch (ApiValidatorException ex) {
+      // was expcting this
+    }
+  }
+
+}

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibConverterUtilsTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibConverterUtilsTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibConverterUtilsTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonLibConverterUtilsTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibConverterUtilsTest.java Tue Feb 10 01:53:52 2009
@@ -15,23 +15,20 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
-
-import org.apache.shindig.social.core.util.JsonLibConverterUtils;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
-
 import org.junit.Test;
 
 /**
- *
+ * Basic tests
  */
 public class JsonLibConverterUtilsTest {
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.JsonLibConverterUtils#dumpJsonObject(net.sf.json.JSONObject, java.lang.String)}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.JsonLibConverterUtils#dumpJsonObject(net.sf.json.JSONObject, java.lang.String)}.
    */
   @Test
   public void testDumpJsonObject() {
@@ -46,7 +43,7 @@
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.JsonLibConverterUtils#dumpJsonArray(net.sf.json.JSONArray, java.lang.String)}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.JsonLibConverterUtils#dumpJsonArray(net.sf.json.JSONArray, java.lang.String)}.
    */
   @Test
   public void testDumpJsonArray() {

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibConverterUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibTestsGuiceModule.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/JsonLibTestsGuiceModule.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibTestsGuiceModule.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibTestsGuiceModule.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/JsonLibTestsGuiceModule.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/JsonLibTestsGuiceModule.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibTestsGuiceModule.java Tue Feb 10 01:53:52 2009
@@ -16,20 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.shindig.social;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
-import org.apache.shindig.social.core.util.BeanJsonLibConfig;
+import org.apache.shindig.protocol.model.TestModel;
 
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.name.Names;
+import net.sf.ezmorph.MorpherRegistry;
 import net.sf.json.JsonConfig;
+import net.sf.json.util.EnumMorpher;
+import net.sf.json.util.JSONUtils;
 
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.name.Names;
-
 /**
  * Provides social api component injection for all large tests
  */
@@ -41,7 +45,26 @@
     bind(List.class).to(ArrayList.class);
     bind(Map[].class).to(HashMap[].class);
     bind(JsonConfig.class).annotatedWith(Names.named("ShindigJsonConfig")).to(
-        BeanJsonLibConfig.class);
+        TestJsonLibConfig.class);
   }
 
+  public static class TestJsonLibConfig extends BaseJsonLibConfig {
+    @Inject
+    public TestJsonLibConfig(Injector injector) {
+      super(injector);
+    }
+
+    protected void registerMorphers() {
+      super.registerMorphers();
+      MorpherRegistry morpherRegistry = JSONUtils.getMorpherRegistry();
+      morpherRegistry.registerMorpher(new EnumMorpher(TestModel.Engine.class));
+    }
+
+    protected Map<String, Class<?>> createClassMap() {
+      Map<String, Class<?>> classMap = super.createClassMap();
+      classMap.put("parkingTickets", Map.class);
+      classMap.put("passengers", TestModel.Passenger.class);
+      return classMap;
+    }
+  }
 }

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonLibTestsGuiceModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonObjectToMapMorpherTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonObjectToMapMorpherTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonObjectToMapMorpherTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/JsonObjectToMapMorpherTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonObjectToMapMorpherTest.java Tue Feb 10 01:53:52 2009
@@ -15,19 +15,23 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
-
-import java.util.List;
-import java.util.Map;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
 import net.sf.ezmorph.Morpher;
 import net.sf.ezmorph.ObjectMorpher;
 import net.sf.json.JSON;
 import net.sf.json.JSONObject;
-
-import org.apache.shindig.social.core.util.JsonObjectToMapMorpher;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import org.junit.Test;
-import static org.junit.Assert.*;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * Tests the JsonObjectMapMorpher
@@ -36,7 +40,7 @@
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.JsonObjectToMapMorpher#morphsTo()}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.JsonObjectToMapMorpher#morphsTo()}.
    */
   @Test
   public void testMorphsTo() {
@@ -46,7 +50,7 @@
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.JsonObjectToMapMorpher#supports(java.lang.Class)}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.JsonObjectToMapMorpher#supports(java.lang.Class)}.
    */
   @Test
   public void testSupports() {
@@ -58,7 +62,7 @@
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.JsonObjectToMapMorpher#morph(java.lang.Object)}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.JsonObjectToMapMorpher#morph(java.lang.Object)}.
    */
   @Test
   public void testMorph() {

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/JsonObjectToMapMorpherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullDefaultValueProcessorTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullDefaultValueProcessorTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullDefaultValueProcessorTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullDefaultValueProcessorTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullDefaultValueProcessorTest.java Tue Feb 10 01:53:52 2009
@@ -15,13 +15,10 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
-import static org.junit.Assert.assertNull;
 import net.sf.json.processors.DefaultValueProcessor;
-
-import org.apache.shindig.social.core.util.NullDefaultValueProcessor;
-
+import static org.junit.Assert.assertNull;
 import org.junit.Test;
 
 import java.util.List;
@@ -34,7 +31,7 @@
 
   /**
    * Test method for
-   * {@link org.apache.shindig.social.core.util.NullDefaultValueProcessor#getDefaultValue(java.lang.Class)}.
+   * {@link org.apache.shindig.protocol.conversion.jsonlib.NullDefaultValueProcessor#getDefaultValue(java.lang.Class)}.
    */
   @Test
   public void testGetDefaultValue() {

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullDefaultValueProcessorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullPropertyFilterTest.java (from r740988, incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java)
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullPropertyFilterTest.java?p2=incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullPropertyFilterTest.java&p1=incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java&r1=740988&r2=742816&rev=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/NullPropertyFilterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullPropertyFilterTest.java Tue Feb 10 01:53:52 2009
@@ -15,19 +15,14 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations under the License.
  */
-package org.apache.shindig.social.opensocial.util;
+package org.apache.shindig.protocol.conversion.jsonlib;
 
+import com.google.common.collect.Lists;
+import junit.framework.Assert;
 import net.sf.json.JSONArray;
 import net.sf.json.util.PropertyFilter;
-
-import org.apache.shindig.social.core.util.NullPropertyFilter;
-
-import com.google.common.collect.Lists;
-
 import org.junit.Test;
 
-import junit.framework.Assert;
-
 /**
  * Test the NullPropertyFilter.
  */

Propchange: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/jsonlib/NullPropertyFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.full.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.full.xml?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.full.xml (original)
+++ incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.full.xml Tue Feb 10 01:53:52 2009
@@ -116,7 +116,7 @@
   <servlet>
     <servlet-name>restapiServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.DataServiceServlet
+      org.apache.shindig.protocol.DataServiceServlet
     </servlet-class>
   </servlet>
 
@@ -124,7 +124,7 @@
   <servlet>
     <servlet-name>jsonRpcServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.JsonRpcServlet
+      org.apache.shindig.protocol.JsonRpcServlet
     </servlet-class>
   </servlet>
 

Modified: incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.social.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.social.xml?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.social.xml (original)
+++ incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.social.xml Tue Feb 10 01:53:52 2009
@@ -47,7 +47,7 @@
   <servlet>
     <servlet-name>restapiServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.DataServiceServlet
+      org.apache.shindig.protocol.DataServiceServlet
     </servlet-class>
   </servlet>
 
@@ -55,7 +55,7 @@
   <servlet>
     <servlet-name>jsonRpcServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.JsonRpcServlet
+      org.apache.shindig.protocol.JsonRpcServlet
     </servlet-class>
   </servlet>
 

Modified: incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml Tue Feb 10 01:53:52 2009
@@ -117,7 +117,7 @@
   <servlet>
     <servlet-name>restapiServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.DataServiceServlet
+      org.apache.shindig.protocol.DataServiceServlet
     </servlet-class>
   </servlet>
 
@@ -125,7 +125,7 @@
   <servlet>
     <servlet-name>jsonRpcServlet</servlet-name>
     <servlet-class>
-      org.apache.shindig.social.opensocial.service.JsonRpcServlet
+      org.apache.shindig.protocol.JsonRpcServlet
     </servlet-class>
   </servlet>
 

Modified: incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java (original)
+++ incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndModule.java Tue Feb 10 01:53:52 2009
@@ -22,23 +22,26 @@
 import org.apache.shindig.common.servlet.ParameterFetcher;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.config.JsonContainerConfig;
+import org.apache.shindig.protocol.DataServiceServletFetcher;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
 import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
-import org.apache.shindig.social.core.util.BeanJsonConverter;
 import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
-import org.apache.shindig.social.core.util.BeanXStreamConverter;
+import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
 import org.apache.shindig.social.opensocial.service.ActivityHandler;
 import org.apache.shindig.social.opensocial.service.AppDataHandler;
-import org.apache.shindig.social.opensocial.service.BeanConverter;
-import org.apache.shindig.social.opensocial.service.DataServiceServletFetcher;
 import org.apache.shindig.social.opensocial.service.PersonHandler;
-
-import java.util.List;
+import org.apache.shindig.social.sample.service.SampleContainerHandler;
 
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.TypeLiteral;
 import com.google.inject.name.Names;
 
+import java.util.List;
+
 /**
  * Guice module for the end-to-end tests.
  */
@@ -55,6 +58,7 @@
         .to(BeanXStreamConverter.class);
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.json"))
         .to(BeanJsonConverter.class);
+    bind(XStreamConfiguration.class).to(XStream081Configuration.class);
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.atom"))
         .to(BeanXStreamAtomConverter.class);
 
@@ -67,7 +71,7 @@
 
     bind(List.class).annotatedWith(Names.named("org.apache.shindig.handlers"))
         .toInstance(ImmutableList.of(ActivityHandler.class, AppDataHandler.class,
-            PersonHandler.class));
+            PersonHandler.class, SampleContainerHandler.class));
 
     bind(ContainerConfig.class).to(JsonContainerConfig.class);    
   }

Modified: incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java (original)
+++ incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java Tue Feb 10 01:53:52 2009
@@ -25,22 +25,17 @@
 import org.apache.shindig.gadgets.oauth.OAuthModule;
 import org.apache.shindig.gadgets.servlet.ConcatProxyServlet;
 import org.apache.shindig.gadgets.servlet.GadgetRenderingServlet;
-import org.apache.shindig.social.opensocial.service.DataServiceServlet;
-import org.apache.shindig.social.opensocial.service.JsonRpcServlet;
+import org.apache.shindig.protocol.DataServiceServlet;
+import org.apache.shindig.protocol.JsonRpcServlet;
 
 import com.google.common.base.Join;
 import com.google.common.collect.Maps;
-
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.ResourceHandler;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.resource.Resource;
 
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -49,6 +44,9 @@
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
 
 /**
  * Suite for running the end-to-end tests. The suite is responsible for starting up and shutting

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/config/SocialApiGuiceModule.java Tue Feb 10 01:53:52 2009
@@ -21,16 +21,18 @@
 import org.apache.shindig.auth.AnonymousAuthenticationHandler;
 import org.apache.shindig.auth.AuthenticationHandler;
 import org.apache.shindig.common.servlet.ParameterFetcher;
+import org.apache.shindig.protocol.DataServiceServletFetcher;
+import org.apache.shindig.protocol.DefaultHandlerRegistry;
+import org.apache.shindig.protocol.HandlerRegistry;
+import org.apache.shindig.protocol.conversion.BeanConverter;
+import org.apache.shindig.protocol.conversion.BeanJsonConverter;
+import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
 import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
-import org.apache.shindig.social.core.util.BeanJsonConverter;
 import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
-import org.apache.shindig.social.core.util.BeanXStreamConverter;
+import org.apache.shindig.social.core.util.xstream.XStream081Configuration;
 import org.apache.shindig.social.opensocial.service.ActivityHandler;
 import org.apache.shindig.social.opensocial.service.AppDataHandler;
-import org.apache.shindig.social.opensocial.service.BeanConverter;
-import org.apache.shindig.social.opensocial.service.DataServiceServletFetcher;
-import org.apache.shindig.social.opensocial.service.DefaultHandlerRegistry;
-import org.apache.shindig.social.opensocial.service.HandlerRegistry;
 import org.apache.shindig.social.opensocial.service.PersonHandler;
 import org.apache.shindig.social.sample.service.SampleContainerHandler;
 
@@ -63,7 +65,7 @@
     bind(Boolean.class)
         .annotatedWith(Names.named(AnonymousAuthenticationHandler.ALLOW_UNAUTHENTICATED))
         .toInstance(Boolean.TRUE);
-
+    bind(XStreamConfiguration.class).to(XStream081Configuration.class);
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.xml")).to(
         BeanXStreamConverter.class);
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.json")).to(

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/model/PersonImpl.java Tue Feb 10 01:53:52 2009
@@ -17,14 +17,18 @@
  */
 package org.apache.shindig.social.core.model;
 
+import org.apache.shindig.protocol.model.Enum;
 import org.apache.shindig.social.opensocial.model.Account;
 import org.apache.shindig.social.opensocial.model.Address;
 import org.apache.shindig.social.opensocial.model.BodyType;
-import org.apache.shindig.social.opensocial.model.Enum;
+import org.apache.shindig.social.opensocial.model.Drinker;
 import org.apache.shindig.social.opensocial.model.ListField;
+import org.apache.shindig.social.opensocial.model.LookingFor;
 import org.apache.shindig.social.opensocial.model.Name;
+import org.apache.shindig.social.opensocial.model.NetworkPresence;
 import org.apache.shindig.social.opensocial.model.Organization;
 import org.apache.shindig.social.opensocial.model.Person;
+import org.apache.shindig.social.opensocial.model.Smoker;
 import org.apache.shindig.social.opensocial.model.Url;
 
 import com.google.common.collect.Lists;
@@ -48,7 +52,7 @@
   private String children;
   private Address currentLocation;
   private String displayName;
-  private Enum<Enum.Drinker> drinker;
+  private Enum<Drinker> drinker;
   private List<ListField> emails;
   private String ethnicity;
   private String fashion;
@@ -64,11 +68,11 @@
   private String jobInterests;
   private List<String> languagesSpoken;
   private String livingArrangement;
-  private List<Enum<Enum.LookingFor>> lookingFor;
+  private List<Enum<LookingFor>> lookingFor;
   private List<String> movies;
   private List<String> music;
   private Name name;
-  private Enum<Enum.NetworkPresence> networkPresence;
+  private Enum<NetworkPresence> networkPresence;
   private String nickname;
   private List<Organization> organizations;
   private String pets;
@@ -83,7 +87,7 @@
   private String romance;
   private String scaredOf;
   private String sexualOrientation;
-  private Enum<Enum.Smoker> smoker;
+  private Enum<Smoker> smoker;
   private List<String> sports;
   private String status;
   private List<String> tags;
@@ -216,11 +220,11 @@
     this.displayName = displayName;
   }
 
-  public Enum<Enum.Drinker> getDrinker() {
+  public org.apache.shindig.protocol.model.Enum<Drinker> getDrinker() {
     return this.drinker;
   }
 
-  public void setDrinker(Enum<Enum.Drinker> newDrinker) {
+  public void setDrinker(Enum<Drinker> newDrinker) {
     this.drinker = newDrinker;
   }
 
@@ -359,11 +363,11 @@
     this.livingArrangement = livingArrangement;
   }
 
-  public List<Enum<Enum.LookingFor>> getLookingFor() {
+  public List<Enum<LookingFor>> getLookingFor() {
     return lookingFor;
   }
 
-  public void setLookingFor(List<Enum<Enum.LookingFor>> lookingFor) {
+  public void setLookingFor(List<Enum<LookingFor>> lookingFor) {
     this.lookingFor = lookingFor;
   }
 
@@ -391,11 +395,11 @@
     this.name = name;
   }
 
-  public Enum<Enum.NetworkPresence> getNetworkPresence() {
+  public Enum<NetworkPresence> getNetworkPresence() {
     return networkPresence;
   }
 
-  public void setNetworkPresence(Enum<Enum.NetworkPresence> networkPresence) {
+  public void setNetworkPresence(Enum<NetworkPresence> networkPresence) {
     this.networkPresence = networkPresence;
   }
 
@@ -511,11 +515,11 @@
     this.sexualOrientation = sexualOrientation;
   }
 
-  public Enum<Enum.Smoker> getSmoker() {
+  public Enum<Smoker> getSmoker() {
     return this.smoker;
   }
 
-  public void setSmoker(Enum<Enum.Smoker> newSmoker) {
+  public void setSmoker(Enum<Smoker> newSmoker) {
     this.smoker = newSmoker;
   }
 

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonLibConfig.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonLibConfig.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonLibConfig.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonLibConfig.java Tue Feb 10 01:53:52 2009
@@ -17,19 +17,20 @@
  */
 package org.apache.shindig.social.core.util;
 
-import com.google.common.collect.Maps;
-
+import org.apache.shindig.protocol.conversion.jsonlib.BaseJsonLibConfig;
+import org.apache.shindig.protocol.model.Enum;
 import org.apache.shindig.social.opensocial.model.Address;
-import org.apache.shindig.social.opensocial.model.Enum;
+import org.apache.shindig.social.opensocial.model.Drinker;
 import org.apache.shindig.social.opensocial.model.ListField;
 import org.apache.shindig.social.opensocial.model.MediaItem;
+import org.apache.shindig.social.opensocial.model.NetworkPresence;
 import org.apache.shindig.social.opensocial.model.Organization;
+import org.apache.shindig.social.opensocial.model.Smoker;
 import org.apache.shindig.social.opensocial.model.Url;
 
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import net.sf.ezmorph.MorpherRegistry;
-import net.sf.json.JsonConfig;
 import net.sf.json.util.EnumMorpher;
 import net.sf.json.util.JSONUtils;
 
@@ -38,60 +39,35 @@
 /**
  * A Json Config class suitable for serializing Shindig json and pojos.
  */
+public class BeanJsonLibConfig extends BaseJsonLibConfig {
 
-public class BeanJsonLibConfig extends JsonConfig {
-
-  /*
-   * Register the Enum Morphers so that JSON -> Bean works correctly for enums.
+  /**
+   * Construct the config with a Guice injector.
+   * @param injector the Guice injector
    */
-  static {
+  @Inject
+  public BeanJsonLibConfig(Injector injector) {
+    super(injector);
+  }
+
+  @Override
+  protected void registerMorphers() {
+    super.registerMorphers();
     MorpherRegistry morpherRegistry = JSONUtils.getMorpherRegistry();
     morpherRegistry.registerMorpher(new EnumMorpher(Address.Field.class));
     morpherRegistry.registerMorpher(new EnumMorpher(ListField.Field.class));
     morpherRegistry.registerMorpher(new EnumMorpher(ListField.Field.class));
     morpherRegistry.registerMorpher(new EnumMorpher(MediaItem.Field.class));
     morpherRegistry.registerMorpher(new EnumMorpher(MediaItem.Type.class));
-    morpherRegistry.registerMorpher(new EnumMorpher(Enum.Drinker.class));
+    morpherRegistry.registerMorpher(new EnumMorpher(Drinker.class));
     morpherRegistry.registerMorpher(new EnumMorpher(Enum.Field.class));
-    morpherRegistry.registerMorpher(new EnumMorpher(Enum.NetworkPresence.class));
-    morpherRegistry.registerMorpher(new EnumMorpher(Enum.Smoker.class));
-    morpherRegistry.registerMorpher(new JsonObjectToMapMorpher());
+    morpherRegistry.registerMorpher(new EnumMorpher(NetworkPresence.class));
+    morpherRegistry.registerMorpher(new EnumMorpher(Smoker.class));
   }
 
-  /**
-   * Construct the config with a Guice injector.
-   * @param injector the Guice injector
-   */
-  @Inject
-  public BeanJsonLibConfig(Injector injector) {
-    /*
-     * This hook deals with the creation of new beans in the JSON -> Java Bean
-     * conversion
-     */
-    setNewBeanInstanceStrategy(new InjectorBeanInstanceStrategy(injector));
-
-    /*
-     * We are expecting null for nulls
-     */
-    registerDefaultValueProcessor(String.class, new NullDefaultValueProcessor());
-
-    setJsonPropertyFilter(new NullPropertyFilter());
-    setJavaPropertyFilter(new NullPropertyFilter());
-    // the classMap deals with the basic json string to bean conversion
-
-    Map<String, Class<?>> classMap = Maps.newHashMap();
-
-    /*
-     * mappings are required where there is a List of objects in the interface
-     * with no indication of what type the list should contain. At the moment,
-     * we are using 1 map for all json trees, as there is no conflict, but if
-     * there is a map could be selected on the basis of the root object. It
-     * would be better to do this with generics, but this is good enough and
-     * compact enough for the moment.
-     *
-     */
-    //
-    // activity
+  @Override
+  protected Map<String, Class<?>> createClassMap() {
+    Map<String, Class<?>> classMap = super.createClassMap();
     classMap.put("mediaItems", MediaItem.class);
     // this may not be necessary
     classMap.put("templateParams", Map.class);
@@ -113,8 +89,6 @@
     classMap.put("jobs", Organization.class);
     classMap.put("schools", Organization.class);
     classMap.put("urls", Url.class);
-    setClassMap(classMap);
-
+    return classMap;
   }
-
 }

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanXStreamAtomConverter.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanXStreamAtomConverter.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanXStreamAtomConverter.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanXStreamAtomConverter.java Tue Feb 10 01:53:52 2009
@@ -17,17 +17,17 @@
  */
 package org.apache.shindig.social.core.util;
 
-import com.google.inject.Inject;
-
-import org.apache.shindig.social.core.util.atom.AtomFeed;
-import org.apache.shindig.social.core.util.xstream.XStreamConfiguration;
-import org.apache.shindig.social.core.util.xstream.XStreamConfiguration.ConverterConfig;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.shindig.protocol.conversion.BeanXStreamConverter;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
+import org.apache.shindig.social.core.util.atom.AtomFeed;
+
+import com.google.inject.Inject;
 
 /**
  * Converts output to atom.
+ * TODO: Move to common once atom binding can be decoupled form social code
  */
 public class BeanXStreamAtomConverter extends BeanXStreamConverter {
 
@@ -44,7 +44,7 @@
   /**
    * {@inheritDoc}
    *
-   * @see org.apache.shindig.social.core.util.BeanXStreamConverter#getContentType()
+   * @see org.apache.shindig.protocol.conversion.BeanXStreamConverter#getContentType()
    */
   @Override
   public String getContentType() {
@@ -54,13 +54,13 @@
   /**
    * {@inheritDoc}
    *
-   * @see org.apache.shindig.social.core.util.BeanXStreamConverter#convertToString(java.lang.Object)
+   * @see org.apache.shindig.protocol.conversion.BeanXStreamConverter#convertToString(java.lang.Object)
    */
   @Override
   public String convertToString(Object obj) {
     writerStack.reset();
     AtomFeed af = new AtomFeed(obj);
-    ConverterConfig cc = converterMap.get(XStreamConfiguration.ConverterSet.DEFAULT);
+    XStreamConfiguration.ConverterConfig cc = converterMap.get(XStreamConfiguration.ConverterSet.DEFAULT);
     cc.mapper.setBaseObject(af); // thread safe method
 
     return cc.xstream.toXML(af);

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java Tue Feb 10 01:53:52 2009
@@ -17,19 +17,19 @@
  */
 package org.apache.shindig.social.core.util.atom;
 
-import org.apache.shindig.social.opensocial.spi.DataCollection;
-import org.apache.shindig.social.opensocial.spi.RestfulCollection;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
+import org.apache.shindig.protocol.DataCollection;
+import org.apache.shindig.protocol.RestfulCollection;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
 /**
  * represents an atom:feed entry
  */

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java Tue Feb 10 01:53:52 2009
@@ -17,23 +17,21 @@
  */
 package org.apache.shindig.social.core.util.xstream;
 
-import com.google.common.collect.*;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.converters.extended.ISO8601DateConverter;
-import com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter;
-import com.thoughtworks.xstream.converters.extended.ISO8601SqlTimestampConverter;
-import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
-import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
-import com.thoughtworks.xstream.mapper.AttributeMapper;
-import com.thoughtworks.xstream.mapper.Mapper;
-
-import org.apache.shindig.social.core.model.EnumImpl;
+import org.apache.shindig.protocol.DataCollection;
+import org.apache.shindig.protocol.RestfulCollection;
+import org.apache.shindig.protocol.conversion.xstream.ClassFieldMapping;
+import org.apache.shindig.protocol.conversion.xstream.DataCollectionConverter;
+import org.apache.shindig.protocol.conversion.xstream.GuiceBeanConverter;
+import org.apache.shindig.protocol.conversion.xstream.ImplicitCollectionFieldMapping;
+import org.apache.shindig.protocol.conversion.xstream.InterfaceClassMapper;
+import org.apache.shindig.protocol.conversion.xstream.InterfaceFieldAliasMapping;
+import org.apache.shindig.protocol.conversion.xstream.InterfaceFieldAliasingMapper;
+import org.apache.shindig.protocol.conversion.xstream.MapConverter;
+import org.apache.shindig.protocol.conversion.xstream.NamespaceSet;
+import org.apache.shindig.protocol.conversion.xstream.RestfullCollectionConverter;
+import org.apache.shindig.protocol.conversion.xstream.WriterStack;
+import org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration;
+import org.apache.shindig.protocol.model.EnumImpl;
 import org.apache.shindig.social.core.util.atom.AtomAttribute;
 import org.apache.shindig.social.core.util.atom.AtomAttributeConverter;
 import org.apache.shindig.social.core.util.atom.AtomContent;
@@ -52,14 +50,33 @@
 import org.apache.shindig.social.opensocial.model.Organization;
 import org.apache.shindig.social.opensocial.model.Person;
 import org.apache.shindig.social.opensocial.model.Url;
-import org.apache.shindig.social.opensocial.spi.DataCollection;
-import org.apache.shindig.social.opensocial.spi.RestfulCollection;
 
-import java.util.*;
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ForwardingMap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Multimap;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.extended.ISO8601DateConverter;
+import com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter;
+import com.thoughtworks.xstream.converters.extended.ISO8601SqlTimestampConverter;
+import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
+import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
+import com.thoughtworks.xstream.mapper.AttributeMapper;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
- *
+ * Opensocial 0.81 compliant Xstream binding
  */
 public class XStream081Configuration implements XStreamConfiguration {
 
@@ -275,7 +292,7 @@
    * {@inheritDoc}
    *
    * @param writerStack
-   * @see XStreamConfiguration#getConverterConfig(org.apache.shindig.social.core.util.xstream.XStreamConfiguration.ConverterSet, com.thoughtworks.xstream.converters.reflection.ReflectionProvider, com.thoughtworks.xstream.mapper.Mapper, com.thoughtworks.xstream.io.HierarchicalStreamDriver, WriterStack)
+   * @see XStreamConfiguration#getConverterConfig(org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration.ConverterSet, com.thoughtworks.xstream.converters.reflection.ReflectionProvider, com.thoughtworks.xstream.mapper.Mapper, com.thoughtworks.xstream.io.HierarchicalStreamDriver, org.apache.shindig.protocol.conversion.xstream.WriterStack)
    */
   public ConverterConfig getConverterConfig(ConverterSet c, ReflectionProvider rp,
                                             Mapper dmapper, HierarchicalStreamDriver driver, WriterStack writerStack) {
@@ -317,7 +334,7 @@
   /**
    * {@inheritDoc}
    *
-   * @see org.apache.shindig.social.core.util.xstream.XStreamConfiguration#getNameSpaces()
+   * @see org.apache.shindig.protocol.conversion.xstream.XStreamConfiguration#getNameSpaces()
    */
   public Map<String, NamespaceSet> getNameSpaces() {
     return NAMESPACES;

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Account.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Account.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Account.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Account.java Tue Feb 10 01:53:52 2009
@@ -17,6 +17,7 @@
  */
 package org.apache.shindig.social.opensocial.model;
 
+import org.apache.shindig.protocol.model.Exportablebean;
 import org.apache.shindig.social.core.model.AccountImpl;
 
 import com.google.inject.ImplementedBy;

Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Activity.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Activity.java?rev=742816&r1=742815&r2=742816&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Activity.java (original)
+++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Activity.java Tue Feb 10 01:53:52 2009
@@ -18,9 +18,11 @@
 
 package org.apache.shindig.social.opensocial.model;
 
+import org.apache.shindig.protocol.model.Exportablebean;
 import org.apache.shindig.social.core.model.ActivityImpl;
 
 import com.google.inject.ImplementedBy;
+
 import java.util.Date;
 import java.util.List;
 import java.util.Map;