Ejemplo n.º 1
1
    public void generateObjects(String arrayName, Object... parent) {
      if (mRec == null) return;

      Object rawObj;
      try {
        rawObj = mParser.parse(mJson);
        if (rawObj == null) return;

        JSONObject obj = (JSONObject) rawObj;
        JSONArray arr = (JSONArray) obj.get(arrayName);
        int cnt = 0;
        if (arr != null) {
          for (Object jb : arr.toArray()) // each object
          {
            JSONObject jo = (JSONObject) jb;
            mCls.getConstructors()[0].setAccessible(true);

            Object w;
            if (parent != null && parent.length != 0) // Inner class
            w = mCls.getConstructors()[0].newInstance(parent[0]);
            else {
              w = mCls.getConstructors()[0].newInstance((Object) null);
            }
            for (Field f : mCls.getDeclaredFields()) // each field
            {
              try {
                Object fieldVal = jo.get(f.getName());
                if (fieldVal == null) continue;
                if (f.getType() == Integer.class) f.set(w, Integer.parseInt(fieldVal.toString()));
                else if (f.getType() == Date.class)
                  f.set(w, new Date(Long.parseLong(fieldVal.toString())));
                else if (f.getType() == String.class) f.set(w, fieldVal.toString());
              } catch (IllegalArgumentException e) {
                e.printStackTrace();
              } catch (IllegalAccessException e) {
                e.printStackTrace();
              }
            }
            mRec.receiveObject(w);
          }
        }
      } catch (ParseException e1) {
        e1.printStackTrace();
      } catch (IllegalArgumentException e1) {
        e1.printStackTrace();
      } catch (SecurityException e1) {
        e1.printStackTrace();
      } catch (InstantiationException e1) {
        e1.printStackTrace();
      } catch (IllegalAccessException e1) {
        e1.printStackTrace();
      } catch (InvocationTargetException e1) {
        e1.printStackTrace();
      }
    }
 private void closeClientChannel() {
   try {
     if (_inboundChannel != null) _inboundChannel.disconnect();
     if (_network != null) _network.close();
   } catch (IOException ignorable) {
   } finally {
     _network = null;
     _inboundChannel = null;
   }
 }
 private synchronized boolean forwarded(Object object) {
   try {
     if (_network == null) {
       return false;
     }
     _network.receive(object);
     return true;
   } catch (IOException handle) {
     return false;
   }
 }