Object readResolve() throws java.io.ObjectStreamException {
   ParametersValue.Builder builder = ParametersValue.make();
   builder.params.putAll(map);
   return builder.get();
 }
Пример #2
0
  /**
   * Method main.
   *
   * @param args String[]
   * @throws Exception
   */
  public static void main(String... args) throws Exception {

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    ASObject obj =
        object()
            .action("view", httpAction, embedAction, urlTemplate, intent)
            .action("share", "http://example.org/foo")
            .get();

    io.write(obj, System.out);

    System.out.println("\n\n");

    io.write(obj, out);

    obj = io.read(new ByteArrayInputStream(out.toByteArray()));

    ActionsValue actions = obj.actions();
    for (LinkValue lv : actions.get("view")) {
      if (lv instanceof HttpActionHandler) {
        HttpActionHandler httpAction = (HttpActionHandler) lv;
        System.out.println("Auth:     " + httpAction.auth());
        System.out.println("Method:   " + httpAction.method());
        System.out.println("URL:      " + httpAction.url());
        System.out.println("Target:   " + httpAction.target());
        System.out.println("Returns:  " + httpAction.returns());
        System.out.println("Expects:  " + httpAction.expects());
        System.out.println("Requires: " + httpAction.requires());
        System.out.println("Prefers:  " + httpAction.prefers());
      } else if (lv instanceof EmbedActionHandler) {
        EmbedActionHandler embed = (EmbedActionHandler) lv;
        for (StylesValue style : embed.styles("print")) {
          System.out.println(style.get("height"));
          System.out.println(style.get("width"));
        }
      } else if (lv instanceof UrlTemplate) {
        UrlTemplate template = (UrlTemplate) lv;
        System.out.println(template.template());
        ParametersValue pv = template.parameters();
        for (String s : pv) {
          TypeValue param = pv.get(s);
          if (param.valueType() == ValueType.SIMPLE) {
            System.out.println(s + " = " + param.id());
          } else {
            if (param instanceof Parameter) {
              Parameter par = (Parameter) param;
              System.out.println(
                  s
                      + " = "
                      + par.id()
                      + ", "
                      + par.required()
                      + ", "
                      + par.format()
                      + ", "
                      + par.enumVals());
            } else {
              System.out.println(s + " = " + param);
            }
          }
        }
      }
    }
  }