Ejemplo n.º 1
0
    public void marshall(Object object, Type type, MarshallerContext ctx) {
      if (object == null) {
        ctx.getAppender().append("null");
        return;
      }

      if (type != Type.OBJECT) {
        marshallValue(object, type, ctx);
      } else {
        Class cls = object.getClass();
        ObjectConverter converter = this.converters.get(cls);
        if (converter == null) {
          converter = generateConverter(cls);
          this.converters.put(cls, converter);
        }

        try {
          int i = 0;
          ctx.getAppender().append("new " + cls.getName() + "().{ ");
          for (ObjectConverterEntry entry : converter.getFields()) {
            if (i++ != 0) {
              ctx.getAppender().append(", ");
            }
            ctx.getAppender().append(entry.getName());
            ctx.getAppender().append(" = ");

            marshallValue(entry.getMethod().invoke(object, null), entry.getType(), ctx);
          }
        } catch (Exception e) {
          throw new IllegalStateException("Unable to marshall object " + object, e);
        }
        ctx.getAppender().append(" }");
      }
    }
Ejemplo n.º 2
0
  public WCHectare getHectareById(int id) {

    resource =
        client.resource(
            WebServicePaths.getHectareById + UserConstants.getSessionUser().getFarm() + id);
    WebServiceHectare webServiceHectare = resource.get(WebServiceHectare.class);

    return (WCHectare) ObjectConverter.convertWebObjectToNormalObject(webServiceHectare);
  }
Ejemplo n.º 3
0
  public Version checkVersion() throws ParseException {

    resource = client.resource(Paths.VERSION_WEBSERVICE_PATH);
    WebServiceVersion webServiceVersion = resource.get(WebServiceVersion.class);

    Version version = (Version) ObjectConverter.convertWebObjectToNormalObject(webServiceVersion);

    return version;
  }
Ejemplo n.º 4
0
  public String upsertTheRemoteDB(WCHectare hectare) {

    WebServiceHectare webServiceHectare =
        (WebServiceHectare) ObjectConverter.convertNormalObjectToWebObject(hectare);
    resource =
        client.resource(WebServicePaths.upsertHectare + UserConstants.getSessionUser().getFarm());
    clientResponse =
        resource.type(MediaType.APPLICATION_XML).post(ClientResponse.class, webServiceHectare);

    return "success";
  }
Ejemplo n.º 5
0
  public List<WCHectare> getAllHectares() {

    List<WCHectare> hectares = new ArrayList<WCHectare>();

    resource =
        client.resource(WebServicePaths.getHectares + UserConstants.getSessionUser().getFarm());
    WebServiceHectare[] hectareArray = resource.get(WebServiceHectare[].class);

    List<WebServiceHectare> hectareList = Arrays.asList(hectareArray);

    WCHectare hectare = new WCHectare();
    for (WebServiceHectare webServiceHectare : hectareList) {

      hectare = (WCHectare) ObjectConverter.convertWebObjectToNormalObject(webServiceHectare);
      hectares.add(hectare);
    }

    return hectares;
  }