Java Objects

  • Object names - like function arguments, object names are converted to camel case, starting with upper-case, e.g., crawl-url becomes CrawlUrl.
  • Enumerations - are currently handled like strings though we plan to add constants in the near future to avoid the need to type strings.
  • Properties - are objects that can be undefined (e.g., java.lang.Integer instead of int) when they are not required or have a default.
    warning: Always check that a property is specified before accessing it to avoid null pointer errors.
  • Name collisions - when importing all the Watson Explorer Engine object types, you will need to use the full namespace for Java lists (i.e., java.util.List), because it conflicts with the schema's list element.
  • Multi-typed lists: an xs:choice is translated into multi-typed lists whose name concatenates all of the available types separated by Or

    To read such a list, check the type of each element and cast accordingly:

    QuerySearchResponse qsr = port.querySearch(qs);
    
    Query q = qsr.getQueryResults().getQuery().get(0);
    if (q != null && q.getParamOrParseParamOrOperator() != null) {
        for (Object paramOrParseParamOrOp: q.getParamOrParseParamOrOperator()) {
            if (paramOrParseParamOrOp.getClass() == Operator.class) {
                for (Object opOrTerm: q.getOperator().getOperatorOrTermOrLabel()) {
                    if (opOrTerm.getClass() == Term.class) {
                        Term t = (Term)opOrTerm;
                        System.out.println(t.getStr());
                    } else if (opOrTerm.getClass() == Operator.class) {
                        Operator o = (Operator)opOrTerm;
                        System.out.println(o.getLogic());
                    }
                }
            }
        }
    }

    To create such a list, pass the necessary objects as elements.

    QuerySearch qs = new QuerySearch();
    qs.setQueryObject(new QuerySearch.QueryObject());
    Operator op = new Operator();
    op.setLogic("or");
    qs.getQueryObject().setOperator(op);
    java.util.List<Object> opl = op.getOperatorOrTermOrLabel();
    Term te1 = new Term();
    te1.setField("title");
    te1.setStr("test");
    opl.add(te1);