Package org.jabsorb.serializer

Examples of org.jabsorb.serializer.UnmarshallException


      throws UnmarshallException {
    try {
      JSONObject jso = (JSONObject) o;
      String name = jso.getString("_name");
      if (name == null)
        throw new UnmarshallException("The specified JSONObject of type "
            + clazz.getName() + " didn't contain a _name attribute");
      return Enum.valueOf(clazz, name);
    } catch (JSONException e) {
      e.printStackTrace();
      throw new UnmarshallException(e.getMessage());
    }
  }
View Full Code Here


    try {
      JSONObject jso = (JSONObject) arg2;
      int value = jso.getInt("value");
      return BigInteger.valueOf(Integer.valueOf(value).longValue());
    } catch (Throwable t) {
      throw new UnmarshallException(t.getMessage());
    }
  }
View Full Code Here

    {
      throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
    }
    catch (UnmarshallException e)
    {
      throw new UnmarshallException("arg " + (i + 1) + " " + e.getMessage(), e);
    }
    return candidate;
  }
View Full Code Here

    {
      throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
    }
    catch (UnmarshallException e)
    {
      throw new UnmarshallException("arg " + (i + 1) + " could not unmarshall", e);
    }

    return javaArgs;
  }
View Full Code Here

          {
            return resolverData.getArgResolver().resolveArg(context[j]);
          }
          catch (LocalArgResolveException e)
          {
            throw new UnmarshallException("error resolving local argument: "
                + e, e);
          }
        }
      }
    }
    throw new UnmarshallException("couldn't find local arg resolver");
  }
View Full Code Here

  }

  public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    try {
      if (o == null) {
        throw new UnmarshallException("eo missing");
      }
      JSONObject eoDict = (JSONObject) o;
      if(eoDict.has("eo")) {
        eoDict.getJSONObject("eo");
      }
      String gidString = eoDict.getString("gid");
      if (gidString == null) {
        throw new UnmarshallException("gid missing");
      }
      String parts[] = gidString.split("/");
      String ecid = parts[0];
      String entityName = parts[1];
 
      EOEditingContext ec = null;
      if(ecid != null) {
        ec = editingContextForKey(ecid);
      }
      if(ec == null) {
        ec = _editingContextFactory.newEditingContext();
        registerEditingContext(ec);
      }
      ec.lock();
      try {
        String type = null;
        String pk = null;
        if (parts.length > 2) {
          type = parts[2];
          pk = parts[3];
        }
        EOEnterpriseObject eo;
        EOGlobalID gid;
        if(pk != null && pk.length() > 0) {
          if ("T".equals(type)) {
            byte[] bytes = ERXStringUtilities.hexStringToByteArray(pk);
            gid = EOTemporaryGlobalID._gidForRawBytes(bytes);
            eo = ec.objectForGlobalID(gid);
          }
          else {
            pk = ERXStringUtilities.urlDecode(pk);
            gid = ERXEOControlUtilities.globalIDForString(ec, entityName, pk);
            eo = ec.faultForGlobalID(gid, ec);
          }
        }
        else if (_canInsert(entityName)) {
          eo = ERXEOControlUtilities.createAndInsertObject(ec, entityName);
        }
        else {
          eo = null;
        }
        if (eo != null) {
          NSArray<String> attributeNames = _writableAttributeNames(eo);
          NSArray<String> relationshipNames = _includedRelationshipNames(eo);
          for (Iterator iterator = eoDict.keys(); iterator.hasNext();) {
            String key = (String) iterator.next();
            if(!("javaClass".equals(key) || "gid".equals(key))) {
              Object value = eoDict.get(key);
              Object obj = ser.unmarshall(state, null, value);
              if (attributeNames.containsObject(key)) {
                if (obj == null && !relationshipNames.containsObject(key) && (eo.toOneRelationshipKeys().containsObject(key) || eo.toManyRelationshipKeys().containsObject(key))) {
                  // ignore nulls for non-included relationships
                }
                else {
                  eo.takeValueForKey(obj, key);
                }
              }
            }
          }
        }
        state.setSerialized(o, eo);
        return eo;
      }
      finally {
        ec.unlock();
      }
    }
    catch (JSONException e) {
      throw new UnmarshallException("Failed to unmarshall EO.", e);
    }
  }
View Full Code Here

    String java_class;
    try {
      java_class = jso.getString("javaClass");
    }
    catch (JSONException e) {
      throw new UnmarshallException("Could not read javaClass", e);
    }
    if (java_class == null) {
      throw new UnmarshallException("no type hint");
    }
    if (!(java_class.equals("com.webobjects.foundation.NSDictionary") || java_class.equals("com.webobjects.foundation.NSMutableDictionary"))) {
      throw new UnmarshallException("not an NSDictionary");
    }
    JSONObject jsondictionary;
    try {
      jsondictionary = jso.getJSONObject("nsdictionary");
    }
    catch (JSONException e) {
      throw new UnmarshallException("Could not read dictionary: " + e.getMessage(), e);
    }
    if (jsondictionary == null) {
      throw new UnmarshallException("nsdictionary missing");
    }
    ObjectMatch m = new ObjectMatch(-1);
    Iterator i = jsondictionary.keys();
    String key = null;
    state.setSerialized(o, m);
    try {
      while (i.hasNext()) {
        key = (String) i.next();
        m.setMismatch(ser.tryUnmarshall(state, null, jsondictionary.get(key)).max(m).getMismatch());
      }
    }
    catch (UnmarshallException e) {
      throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }
    catch (JSONException e) {
      throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }
    return m;
  }
View Full Code Here

    String java_class;
    try {
      java_class = jso.getString("javaClass");
    }
    catch (JSONException e) {
      throw new UnmarshallException("Could not read javaClass", e);
    }
    if (java_class == null) {
      throw new UnmarshallException("no type hint");
    }
    boolean immutableClone = false;
    NSMutableDictionary abdictionary;
    if (java_class.equals("com.webobjects.foundation.NSDictionary")) {
      abdictionary = new NSMutableDictionary();
      immutableClone = true;
    }
    else if (java_class.equals("com.webobjects.foundation.NSMutableDictionary")) {
      abdictionary = new NSMutableDictionary();
    }
    else {
      throw new UnmarshallException("not an NSDictionary");
    }
    JSONObject jsondictionary;
    try {
      jsondictionary = jso.getJSONObject("nsdictionary");
    }
    catch (JSONException e) {
      throw new UnmarshallException("Could not read dictionary: " + e.getMessage(), e);
    }
    if (jsondictionary == null) {
      throw new UnmarshallException("nsdictionary missing");
    }
    Iterator i = jsondictionary.keys();
    String key = null;
    try {
      while (i.hasNext()) {
        key = (String) i.next();
        Object value = ser.unmarshall(state, null, jsondictionary.get(key));
        if (value != null) {
          abdictionary.setObjectForKey(value, key);
        }
        else {
          abdictionary.setObjectForKey(NSKeyValueCoding.NullValue, key);
        }
      }
      NSDictionary finalDictionary = abdictionary;
      if (immutableClone) {
        finalDictionary = abdictionary.immutableClone();
      }
      state.setSerialized(o, finalDictionary);
      return finalDictionary;
    }
    catch (UnmarshallException e) {
      throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }
    catch (JSONException e) {
      throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }
  }
View Full Code Here

  public ObjectMatch tryUnmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    try {
      JSONObject jso = (JSONObject) o;
      String java_class = jso.getString("javaClass");
      if (java_class == null) {
        throw new UnmarshallException("no type hint");
      }

      String string = jso.getString("bytes");
      NSData data = (NSData) NSPropertyListSerialization.propertyListFromString(string);
      if (NSData.class.isAssignableFrom(clazz)) {
        return ObjectMatch.OKAY;
      }
      throw new UnmarshallException("invalid class " + clazz);
    }
    catch (JSONException e) {
      throw new UnmarshallException("Failed to unmarshall NSData.", e);
    }
  }
View Full Code Here

  public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    try {
      JSONObject jso = (JSONObject) o;
      String java_class = jso.getString("javaClass");
      if (java_class == null) {
        throw new UnmarshallException("no type hint");
      }

      String string = jso.getString("bytes");
      NSData data = (NSData) NSPropertyListSerialization.propertyListFromString(string);
      if (NSMutableData.class.equals(clazz)) {
        NSMutableData mutableData = new NSMutableData(data);
        state.setSerialized(o, mutableData);
        return mutableData;
      }
      else if (NSData.class.equals(clazz)) {
        state.setSerialized(o, data);
        return data;
      }
      throw new UnmarshallException("invalid class " + clazz);
    }
    catch (JSONException e) {
      throw new UnmarshallException("Failed to unmarshall NSData.", e);
    }

  }
View Full Code Here

TOP

Related Classes of org.jabsorb.serializer.UnmarshallException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.