Are you missing something from this commit? It looks like there is nothing
in the social/canonical directory

On Thu, Jul 3, 2008 at 2:20 PM, <[EMAIL PROTECTED]> wrote:

> Author: lryan
> Date: Thu Jul  3 14:20:23 2008
> New Revision: 673815
>
> URL: http://svn.apache.org/viewvc?rev=673815&view=rev
> Log:
> lots of misc fixes to the Bean<->JSON binder including full roundtrip
> support for all model objects.
>
> Added:
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/canonical/
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/DefaultModelGuiceModule.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/EnumUtil.java
>
>  
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/canonical/
> Modified:
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/SocialApiGuiceModule.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/AddressImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EmailImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EnumImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/MessageImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/NameImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PersonImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PhoneImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/UrlImpl.java
>
>  
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/BeanJsonConverter.java
>
>  
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
>
>  
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/SocialApiGuiceModule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/SocialApiGuiceModule.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/SocialApiGuiceModule.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/SocialApiGuiceModule.java
> Thu Jul  3 14:20:23 2008
> @@ -18,6 +18,12 @@
>  */
>  package org.apache.shindig.social;
>
> +import com.google.common.collect.Lists;
> +import com.google.inject.Inject;
> +import com.google.inject.Provider;
> +import com.google.inject.TypeLiteral;
> +import com.google.inject.name.Names;
> +
>  import org.apache.shindig.common.servlet.ParameterFetcher;
>  import org.apache.shindig.social.abdera.SocialRouteManager;
>  import org.apache.shindig.social.dataservice.ActivityService;
> @@ -26,31 +32,21 @@
>  import org.apache.shindig.social.dataservice.PersonService;
>  import org.apache.shindig.social.opensocial.ActivitiesService;
>  import org.apache.shindig.social.opensocial.DataService;
> +import org.apache.shindig.social.opensocial.DefaultModelGuiceModule;
>  import org.apache.shindig.social.opensocial.OpenSocialDataHandler;
>  import org.apache.shindig.social.opensocial.PeopleService;
> -import org.apache.shindig.social.opensocial.model.Activity;
> -import org.apache.shindig.social.opensocial.model.ActivityImpl;
> -import org.apache.shindig.social.opensocial.model.MediaItem;
> -import org.apache.shindig.social.opensocial.model.MediaItemImpl;
>  import org.apache.shindig.social.samplecontainer.BasicActivitiesService;
>  import org.apache.shindig.social.samplecontainer.BasicDataService;
>  import org.apache.shindig.social.samplecontainer.BasicPeopleService;
>  import
> org.apache.shindig.social.samplecontainer.SampleContainerRouteManager;
>  import org.apache.shindig.social.samplecontainer.StateFileDataHandler;
>
> -import com.google.common.collect.Lists;
> -import com.google.inject.AbstractModule;
> -import com.google.inject.Inject;
> -import com.google.inject.Provider;
> -import com.google.inject.TypeLiteral;
> -import com.google.inject.name.Names;
> -
>  import java.util.List;
>
>  /**
>  * Provides social api component injection
>  */
> -public class SocialApiGuiceModule extends AbstractModule {
> +public class SocialApiGuiceModule extends DefaultModelGuiceModule {
>
>   /** [EMAIL PROTECTED] */
>   @Override
> @@ -70,9 +66,6 @@
>
>
> bind(ParameterFetcher.class).annotatedWith(Names.named("GadgetDataServlet")).to(GadgetDataServletFetcher.class);
>
> bind(ParameterFetcher.class).annotatedWith(Names.named("DataServiceServlet")).to(DataServiceServletFetcher.class);
> -
> -    bind(Activity.class).to(ActivityImpl.class);
> -    bind(MediaItem.class).to(MediaItemImpl.class);
>   }
>
>   public static class GadgetDataHandlersProvider
>
> Added:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/DefaultModelGuiceModule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/DefaultModelGuiceModule.java?rev=673815&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/DefaultModelGuiceModule.java
> (added)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/DefaultModelGuiceModule.java
> Thu Jul  3 14:20:23 2008
> @@ -0,0 +1,63 @@
> +/*
> + * 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.social.opensocial;
> +
> +import com.google.inject.AbstractModule;
> +
> +import org.apache.shindig.social.opensocial.model.Activity;
> +import org.apache.shindig.social.opensocial.model.ActivityImpl;
> +import org.apache.shindig.social.opensocial.model.Address;
> +import org.apache.shindig.social.opensocial.model.AddressImpl;
> +import org.apache.shindig.social.opensocial.model.BodyType;
> +import org.apache.shindig.social.opensocial.model.BodyTypeImpl;
> +import org.apache.shindig.social.opensocial.model.Email;
> +import org.apache.shindig.social.opensocial.model.EmailImpl;
> +import org.apache.shindig.social.opensocial.model.MediaItem;
> +import org.apache.shindig.social.opensocial.model.MediaItemImpl;
> +import org.apache.shindig.social.opensocial.model.Message;
> +import org.apache.shindig.social.opensocial.model.MessageImpl;
> +import org.apache.shindig.social.opensocial.model.Name;
> +import org.apache.shindig.social.opensocial.model.NameImpl;
> +import org.apache.shindig.social.opensocial.model.Organization;
> +import org.apache.shindig.social.opensocial.model.OrganizationImpl;
> +import org.apache.shindig.social.opensocial.model.Person;
> +import org.apache.shindig.social.opensocial.model.PersonImpl;
> +import org.apache.shindig.social.opensocial.model.Phone;
> +import org.apache.shindig.social.opensocial.model.PhoneImpl;
> +import org.apache.shindig.social.opensocial.model.Url;
> +import org.apache.shindig.social.opensocial.model.UrlImpl;
> +
> +/**
> + * Module for binding standard model implementations
> + */
> +public class DefaultModelGuiceModule extends AbstractModule {
> +
> +  protected void configure() {
> +    bind(Activity.class).to(ActivityImpl.class);
> +    bind(Address.class).to(AddressImpl.class);
> +    bind(BodyType.class).to(BodyTypeImpl.class);
> +    bind(Email.class).to(EmailImpl.class);
> +    bind(MediaItem.class).to(MediaItemImpl.class);
> +    bind(Message.class).to(MessageImpl.class);
> +    bind(Name.class).to(NameImpl.class);
> +    bind(Organization.class).to(OrganizationImpl.class);
> +    bind(Person.class).to(PersonImpl.class);
> +    bind(Phone.class).to(PhoneImpl.class);
> +    bind(Url.class).to(UrlImpl.class);
> +  }
> +}
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/AddressImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/AddressImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/AddressImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/AddressImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -31,6 +31,9 @@
>   private String type;
>   private String unstructuredAddress;
>
> +  public AddressImpl() {
> +  }
> +
>   public AddressImpl(String unstructuredAddress) {
>     this.unstructuredAddress = unstructuredAddress;
>   }
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EmailImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EmailImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EmailImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EmailImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -22,6 +22,9 @@
>   private String address;
>   private String type;
>
> +  public EmailImpl() {
> +  }
> +
>   public EmailImpl(String address, String type) {
>     this.address = address;
>     this.type = type;
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/Enum.java
> Thu Jul  3 14:20:23 2008
> @@ -27,6 +27,26 @@
>  */
>  public interface Enum<E extends Enum.EnumKey> {
>
> +  /**
> +   * Set of fields associated with an Enum object
> +   */
> +  public static enum Field {
> +    KEY("key"),
> +    // TODO Shouldnt this be 'displayValue'
> +    DISPLAY_VALUE("displayvalue");
> +
> +    private final String jsonString;
> +
> +    private Field(String jsonString) {
> +      this.jsonString = jsonString;
> +    }
> +
> +    @Override
> +    public String toString() {
> +      return this.jsonString;
> +    }
> +  }
> +
>   public interface EnumKey {
>     String getDisplayValue();
>   }
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EnumImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EnumImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EnumImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/EnumImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -17,7 +17,7 @@
>  */
>  package org.apache.shindig.social.opensocial.model;
>
> -public final class EnumImpl<E extends EnumImpl.EnumKey> implements Enum<E>
> {
> +public final class EnumImpl<E extends Enum.EnumKey> implements Enum<E> {
>   private String displayValue;
>   private E key = null;
>
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/MessageImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/MessageImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/MessageImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/MessageImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -23,6 +23,9 @@
>   private String title;
>   private Type type;
>
> +  public MessageImpl() {
> +  }
> +
>   public MessageImpl(String initBody, String initTitle, Type initType) {
>     this.body = initBody;
>     this.title = initTitle;
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/NameImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/NameImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/NameImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/NameImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -26,6 +26,9 @@
>   private String honorificSuffix;
>   private String unstructured;
>
> +  public NameImpl() {
> +  }
> +
>   public NameImpl(String unstructured) {
>     this.unstructured = unstructured;
>   }
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PersonImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PersonImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PersonImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PersonImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -82,6 +82,9 @@
>   private boolean isOwner = false;
>   private boolean isViewer = false;
>
> +  public PersonImpl() {
> +  }
> +
>   public PersonImpl(String id, Name name) {
>     this.id = id;
>     this.name = name;
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PhoneImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PhoneImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PhoneImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/PhoneImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -22,6 +22,9 @@
>   private String number;
>   private String type;
>
> +  public PhoneImpl() {
> +  }
> +
>   public PhoneImpl(String number, String type) {
>     super();
>     this.number = number;
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/UrlImpl.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/UrlImpl.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/UrlImpl.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/model/UrlImpl.java
> Thu Jul  3 14:20:23 2008
> @@ -27,6 +27,9 @@
>   private String linkText;
>   private String type;
>
> +  public UrlImpl() {
> +  }
> +
>   public UrlImpl(String address, String linkText, String type) {
>     this.address = address;
>     this.linkText = linkText;
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/BeanJsonConverter.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/BeanJsonConverter.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/BeanJsonConverter.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/BeanJsonConverter.java
> Thu Jul  3 14:20:23 2008
> @@ -19,9 +19,13 @@
>
>  import com.google.common.collect.Lists;
>  import com.google.common.collect.Maps;
> +import com.google.common.collect.Sets;
>  import com.google.inject.Inject;
>  import com.google.inject.Injector;
>
> +import org.apache.shindig.social.opensocial.model.Enum;
> +import org.apache.shindig.social.opensocial.model.EnumImpl;
> +import org.joda.time.DateTime;
>  import org.json.JSONArray;
>  import org.json.JSONException;
>  import org.json.JSONObject;
> @@ -34,6 +38,7 @@
>  import java.util.Iterator;
>  import java.util.List;
>  import java.util.Map;
> +import java.util.Set;
>  import java.util.regex.Matcher;
>  import java.util.regex.Pattern;
>
> @@ -44,7 +49,7 @@
>  public class BeanJsonConverter implements BeanConverter {
>
>   private static final Object[] EMPTY_OBJECT = {};
> -  private static final String EXCLUDED_FIELDS = "class";
> +  private static final Set<String> EXCLUDED_FIELDS =
> Sets.newHashSet("class", "declaringclass");
>   private static final Pattern GETTER =
> Pattern.compile("^get([a-zA-Z]+)$");
>   private static final Pattern SETTER =
> Pattern.compile("^set([a-zA-Z]+)$");
>   private Injector injector;
> @@ -102,12 +107,13 @@
>       }
>       return map;
>
> +    } else if (val != null && val.getClass().isEnum()) {
> +      return val.toString();
>     } else if (val instanceof String
>         || val instanceof Boolean
>         || val instanceof Integer
>         || val instanceof Date
>         || val instanceof Long
> -        || val instanceof Enum
>         || val instanceof Float
>         || val instanceof JSONObject
>         || val instanceof JSONArray
> @@ -129,17 +135,20 @@
>
>     JSONObject toReturn = new JSONObject();
>     for (MethodPair getter : availableGetters) {
> -      String errorMessage = "Could not encode the " + getter.method + "
> method.";
> +      String errorMessage = "Could not encode the " + getter.method + "
> method on " +
> +          pojo.getClass().getName();
>       try {
>         Object val = getter.method.invoke(pojo, EMPTY_OBJECT);
>         if (val != null) {
>           toReturn.put(getter.fieldName, translateObjectToJson(val));
>         }
> -      } catch(JSONException e) {
> +      } catch (JSONException e) {
>         throw new RuntimeException(errorMessage, e);
> -      } catch(IllegalAccessException e) {
> +      } catch (IllegalAccessException e) {
>         throw new RuntimeException(errorMessage, e);
> -      } catch(InvocationTargetException e) {
> +      } catch (InvocationTargetException e) {
> +        throw new RuntimeException(errorMessage, e);
> +      } catch (IllegalArgumentException e) {
>         throw new RuntimeException(errorMessage, e);
>       }
>     }
> @@ -168,7 +177,7 @@
>
>       String name = matcher.group();
>       String fieldName = name.substring(3, 4).toLowerCase() +
> name.substring(4);
> -      if (fieldName.equalsIgnoreCase(EXCLUDED_FIELDS)) {
> +      if (EXCLUDED_FIELDS.contains(fieldName.toLowerCase())) {
>         continue;
>       }
>       availableGetters.add(new MethodPair(method, fieldName));
> @@ -190,12 +199,14 @@
>       throw new RuntimeException(errorMessage, e);
>     } catch (InstantiationException e) {
>       throw new RuntimeException(errorMessage, e);
> +    } catch (NoSuchFieldException e) {
> +      throw new RuntimeException(errorMessage, e);
>     }
>   }
>
>   private <T> T convertToObject(String json, T pojo)
>       throws JSONException, InvocationTargetException,
> IllegalAccessException,
> -      InstantiationException {
> +      InstantiationException, NoSuchFieldException {
>
>     if (pojo instanceof String) {
>       pojo = (T) json; // This is a weird cast...
> @@ -233,7 +244,8 @@
>
>   private <T> void callSetterWithValue(T pojo, Method method,
>       JSONObject jsonObject, String fieldName)
> -      throws IllegalAccessException, InvocationTargetException,
> JSONException {
> +      throws IllegalAccessException, InvocationTargetException,
> NoSuchFieldException,
> +      JSONException {
>
>     Class<?> expectedType = method.getParameterTypes()[0];
>     Object value = null;
> @@ -272,20 +284,50 @@
>
>       value = map;
>
> -    } else if (Enum.class.isAssignableFrom(expectedType)) {
> -      String enumString = jsonObject.getString(fieldName);
> -      value = Enum.valueOf((Class<? extends Enum>) expectedType,
> enumString);
> -
> +    } else if (org.apache.shindig.social.opensocial.model.Enum.class
> +        .isAssignableFrom(expectedType)) {
> +      // TODO Need to stop using Enum as a class name :(
> +      Class enumType = (Class) ((ParameterizedType)
> method.getGenericParameterTypes()[0])
> +          .getActualTypeArguments()[0];
> +      // TODO This isnt injector friendly but perhaps implementors dont
> need it. If they do a
> +      // refactoring of the Enum handling in general is needed.
> +      if (jsonObject.has(fieldName)) {
> +        JSONObject jsonEnum = jsonObject.getJSONObject(fieldName);
> +        if (jsonEnum.has(Enum.Field.KEY.toString())) {
> +          Enum.EnumKey enumKey = (Enum.EnumKey) enumType
> +
>  .getField(jsonEnum.getString(Enum.Field.KEY.toString())).get(null);
> +          value = new EnumImpl<Enum.EnumKey>(enumKey,
> +              jsonEnum.getString(Enum.Field.DISPLAY_VALUE.toString()));
> +        } else {
> +          value = new EnumImpl<Enum.EnumKey>(null,
> +              jsonEnum.getString(Enum.Field.DISPLAY_VALUE.toString()));
> +        }
> +      }
> +    } else if (expectedType.isEnum()) {
> +      if (jsonObject.has(fieldName)) {
> +        for (Object v : expectedType.getEnumConstants()) {
> +          if (v.toString().equals(jsonObject.getString(fieldName))) {
> +            value = v;
> +            break;
> +          }
> +        }
> +        if (value == null) {
> +          throw new IllegalArgumentException(
> +              "No enum value  '" + jsonObject.getString(fieldName) +
> +                  "' in " + expectedType.getName());
> +        }
> +      }
>     } else if (expectedType.equals(String.class)) {
>       value = jsonObject.getString(fieldName);
> -
>     } else if (expectedType.equals(Date.class)) {
> -      Long time = jsonObject.getLong(fieldName);
> -      value = new Date(time);
> -
> +      // Use JODA ISO parsing for the conversion
> +      value = new DateTime(jsonObject.getString(fieldName)).toDate();
>     } else if (expectedType.equals(Long.class)) {
>       value = jsonObject.getLong(fieldName);
> -
> +    } else if (expectedType.equals(Integer.class)) {
> +      value = jsonObject.getInt(fieldName);
> +    } else if (expectedType.equals(Boolean.class)) {
> +      value = jsonObject.getBoolean(fieldName);
>     } else if (expectedType.equals(Float.class)) {
>       String stringFloat = jsonObject.getString(fieldName);
>       value = new Float(stringFloat);
>
> Added:
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/EnumUtil.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/EnumUtil.java?rev=673815&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/EnumUtil.java
> (added)
> +++
> incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/opensocial/util/EnumUtil.java
> Thu Jul  3 14:20:23 2008
> @@ -0,0 +1,27 @@
> +package org.apache.shindig.social.opensocial.util;
> +
> +import com.google.common.collect.Sets;
> +
> +import java.util.Collections;
> +import java.util.Set;
> +
> +/**
> + * Utility class for OpenSocial enums
> + */
> +public class EnumUtil {
> +
> +  /**
> +   * @param vals array of enums
> +   * @return a set of the names for a list of Enum values defined by
> toString
> +   */
> +  public static Set<String> getEnumStrings(Enum... vals) {
> +    Set<String> result = Sets.newHashSet();
> +    for (Enum v : vals) {
> +      result.add(v.toString());
> +    }
> +    if (result.size() != vals.length) {
> +      throw new IllegalArgumentException("Enum names are not disjoint
> set");
> +    }
> +    return Collections.unmodifiableSet(result);
> +  }
> +}
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/SocialApiTestsGuiceModule.java
> Thu Jul  3 14:20:23 2008
> @@ -18,6 +18,11 @@
>  */
>  package org.apache.shindig.social;
>
> +import com.google.common.collect.Lists;
> +import com.google.common.collect.Maps;
> +import com.google.inject.Singleton;
> +import com.google.inject.name.Names;
> +
>  import org.apache.shindig.common.BasicSecurityTokenDecoder;
>  import org.apache.shindig.common.SecurityTokenDecoder;
>  import org.apache.shindig.common.servlet.ParameterFetcher;
> @@ -28,6 +33,7 @@
>  import org.apache.shindig.social.dataservice.PersonService;
>  import org.apache.shindig.social.opensocial.ActivitiesService;
>  import org.apache.shindig.social.opensocial.DataService;
> +import org.apache.shindig.social.opensocial.DefaultModelGuiceModule;
>  import org.apache.shindig.social.opensocial.PeopleService;
>  import org.apache.shindig.social.opensocial.model.Activity;
>  import org.apache.shindig.social.opensocial.model.ActivityImpl;
> @@ -39,8 +45,6 @@
>  import org.apache.shindig.social.opensocial.model.EmailImpl;
>  import org.apache.shindig.social.opensocial.model.Enum;
>  import org.apache.shindig.social.opensocial.model.EnumImpl;
> -import org.apache.shindig.social.opensocial.model.MediaItem;
> -import org.apache.shindig.social.opensocial.model.MediaItemImpl;
>  import org.apache.shindig.social.opensocial.model.NameImpl;
>  import org.apache.shindig.social.opensocial.model.Organization;
>  import org.apache.shindig.social.opensocial.model.OrganizationImpl;
> @@ -55,12 +59,6 @@
>  import
> org.apache.shindig.social.samplecontainer.SampleContainerRouteManager;
>  import org.apache.shindig.social.samplecontainer.XmlStateFileFetcher;
>
> -import com.google.common.collect.Lists;
> -import com.google.common.collect.Maps;
> -import com.google.inject.AbstractModule;
> -import com.google.inject.Singleton;
> -import com.google.inject.name.Names;
> -
>  import java.net.URI;
>  import java.util.Date;
>  import java.util.HashMap;
> @@ -71,12 +69,13 @@
>  /**
>  * Provides social api component injection for all large tests
>  */
> -public class SocialApiTestsGuiceModule extends AbstractModule {
> +public class SocialApiTestsGuiceModule extends DefaultModelGuiceModule {
>   private static Logger logger =
>       Logger.getLogger(SocialApiTestsGuiceModule.class.getName());
>
>   @Override
>   protected void configure() {
> +    super.configure();
>     bind(PeopleService.class).to(BasicPeopleService.class);
>     bind(DataService.class).to(BasicDataService.class);
>     bind(ActivitiesService.class).to(BasicActivitiesService.class);
> @@ -92,9 +91,6 @@
>
>
> bind(ParameterFetcher.class).annotatedWith(Names.named("GadgetDataServlet")).to(GadgetDataServletFetcher.class);
>
> bind(ParameterFetcher.class).annotatedWith(Names.named("DataServiceServlet")).to(DataServiceServletFetcher.class);
> -
> -    bind(Activity.class).to(ActivityImpl.class);
> -    bind(MediaItem.class).to(MediaItemImpl.class);
>   }
>
>   @Singleton
>
> Modified:
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java?rev=673815&r1=673814&r2=673815&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java
> (original)
> +++
> incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanJsonConverterTest.java
> Thu Jul  3 14:20:23 2008
> @@ -17,26 +17,27 @@
>  */
>  package org.apache.shindig.social.opensocial.util;
>
> +import com.google.common.collect.Lists;
> +import com.google.common.collect.Maps;
> +import com.google.inject.Guice;
> +
> +import junit.framework.TestCase;
> +
> +import org.apache.shindig.social.SocialApiTestsGuiceModule;
>  import org.apache.shindig.social.opensocial.model.Activity;
> -import org.apache.shindig.social.opensocial.model.Email;
> -import org.apache.shindig.social.opensocial.model.MediaItem;
> -import org.apache.shindig.social.opensocial.model.Person;
> -import org.apache.shindig.social.opensocial.model.Phone;
> -import org.apache.shindig.social.opensocial.model.DataCollection;
>  import org.apache.shindig.social.opensocial.model.ActivityImpl;
> +import org.apache.shindig.social.opensocial.model.Address;
>  import org.apache.shindig.social.opensocial.model.AddressImpl;
> +import org.apache.shindig.social.opensocial.model.DataCollection;
> +import org.apache.shindig.social.opensocial.model.Email;
>  import org.apache.shindig.social.opensocial.model.EmailImpl;
> +import org.apache.shindig.social.opensocial.model.MediaItem;
>  import org.apache.shindig.social.opensocial.model.MediaItemImpl;
>  import org.apache.shindig.social.opensocial.model.NameImpl;
> +import org.apache.shindig.social.opensocial.model.Person;
>  import org.apache.shindig.social.opensocial.model.PersonImpl;
> +import org.apache.shindig.social.opensocial.model.Phone;
>  import org.apache.shindig.social.opensocial.model.PhoneImpl;
> -import org.apache.shindig.social.opensocial.model.Address;
> -import org.apache.shindig.social.SocialApiTestsGuiceModule;
> -
> -import com.google.common.collect.Lists;
> -import com.google.common.collect.Maps;
> -import com.google.inject.Guice;
> -import junit.framework.TestCase;
>  import org.json.JSONArray;
>  import org.json.JSONObject;
>
> @@ -189,7 +190,7 @@
>
>   public void testJsonToActivity() throws Exception {
>     String jsonActivity = "{userId : 5, id : 6, mediaItems : [" +
> -        "{url : 'hello', mimeType : 'mimey', type : 'VIDEO'}" +
> +        "{url : 'hello', mimeType : 'mimey', type : 'video'}" +
>         "]}";
>     // TODO: rename the enums to be lowercase
>     Activity result = beanJsonConverter.convertToObject(jsonActivity,
>
>
>

Reply via email to