예제 #1
0
  /** Evaluate collect expressions. */
  protected final Value evalCollectNested(EvalContext ctx) {
    // evaluate range
    Value v = fRangeExp.eval(ctx);
    if (v.isUndefined()) return UndefinedValue.instance;
    CollectionValue rangeVal = (CollectionValue) v;

    // prepare result value
    ArrayList<Value> resValues = new ArrayList<Value>();

    // loop over range elements
    for (Value elemVal : rangeVal) {

      // bind element variable to range element, if variable was
      // declared
      if (!fElemVarDecls.isEmpty()) ctx.pushVarBinding(fElemVarDecls.varDecl(0).name(), elemVal);

      // evaluate collect expression
      Value val = fQueryExp.eval(ctx);

      // add element to result
      resValues.add(val);

      if (!fElemVarDecls.isEmpty()) ctx.popVarBinding();
    }

    // result is collection with mapped values
    if (fRangeExp.type().isSequence() || fRangeExp.type().isOrderedSet())
      return new SequenceValue(fQueryExp.type(), resValues);
    else return new BagValue(fQueryExp.type(), resValues);
  }
예제 #2
0
  /**
   * Test sending of HTTP GET requests.
   *
   * @throws Exception exception
   */
  @Test
  public void postGet() throws Exception {
    // GET1 - just send a GET request
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args("<http:request method='get' href='" + REST_ROOT + "'/>"),
            ctx)) {
      final Value v = qp.value();
      checkResponse(v, 2, HttpURLConnection.HTTP_OK);

      assertEquals(NodeType.DOC, v.itemAt(1).type);
    }

    // GET2 - with override-media-type='text/plain'
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args(
                "<http:request method='get' override-media-type='text/plain'/>", REST_ROOT),
            ctx)) {
      final Value v = qp.value();
      checkResponse(v, 2, HttpURLConnection.HTTP_OK);

      assertEquals(AtomType.STR, v.itemAt(1).type);
    }

    // Get3 - with status-only='true'
    try (final QueryProcessor qp =
        new QueryProcessor(
            _HTTP_SEND_REQUEST.args("<http:request method='get' status-only='true'/>", REST_ROOT),
            ctx)) {
      checkResponse(qp.value(), 1, HttpURLConnection.HTTP_OK);
    }
  }
예제 #3
0
  @Override
  public List<FeedValue> getFeed(final int count, final String relationshipEntityKey)
      throws NimbitsException {

    final User loggedInUser = getUser();
    final User feedUser = getFeedUser(relationshipEntityKey, loggedInUser);

    if (feedUser != null) {

      final Point point = getFeedPoint(feedUser);
      if (point == null) {
        return new ArrayList<FeedValue>(0);
      } else {
        final List<Value> values =
            RecordedValueServiceFactory.getInstance().getTopDataSeries(point, count, new Date());
        final List<FeedValue> retObj = new ArrayList<FeedValue>(values.size());

        for (final Value v : values) {
          if (!Utils.isEmptyString(v.getData())) {
            try {
              retObj.add(GsonFactory.getInstance().fromJson(v.getData(), FeedValueModel.class));
            } catch (JsonSyntaxException ignored) {

            }
          }
        }
        return retObj;
      }
    } else {
      return new ArrayList<FeedValue>(0);
    }
  }
예제 #4
0
  public void exceptionEvent(ExceptionEvent event) {
    ObjectReference or = event.exception();
    ReferenceType rt = or.referenceType();
    String exceptionName = rt.name();
    // Field messageField = Throwable.class.getField("detailMessage");
    Field messageField = rt.fieldByName("detailMessage");
    //    System.out.println("field " + messageField);
    Value messageValue = or.getValue(messageField);
    //    System.out.println("mess val " + messageValue);

    // "java.lang.ArrayIndexOutOfBoundsException"
    int last = exceptionName.lastIndexOf('.');
    String message = exceptionName.substring(last + 1);
    if (messageValue != null) {
      String messageStr = messageValue.toString();
      if (messageStr.startsWith("\"")) {
        messageStr = messageStr.substring(1, messageStr.length() - 1);
      }
      message += ": " + messageStr;
    }
    //    System.out.println("mess type " + messageValue.type());
    // StringReference messageReference = (StringReference) messageValue.type();

    // First just report the exception and its placement
    reportException(message, or, event.thread());
    // Then try to pretty it up with a better message
    handleCommonErrors(exceptionName, message, listener);

    if (editor != null) {
      editor.deactivateRun();
    }
  }
예제 #5
0
파일: Path.java 프로젝트: runeengh/basex
  @Override
  public final Expr compile(final QueryContext qc, final VarScope scp) throws QueryException {
    if (root != null) root = root.compile(qc, scp);
    // no steps
    if (steps.length == 0) return root == null ? new Context(info) : root;

    final Value init = qc.value, cv = initial(qc);
    final boolean doc = cv != null && cv.type == NodeType.DOC;
    qc.value = cv;
    try {
      final int sl = steps.length;
      for (int s = 0; s < sl; s++) {
        Expr e = steps[s];

        // axis step: if input is a document, its type is temporarily generalized
        final boolean as = e instanceof Step;
        if (as && s == 0 && doc) cv.type = NodeType.NOD;

        e = e.compile(qc, scp);
        if (e.isEmpty()) return optPre(qc);
        steps[s] = e;

        // no axis step: invalidate context value
        if (!as) qc.value = null;
      }
    } finally {
      if (doc) cv.type = NodeType.DOC;
      qc.value = init;
    }
    // optimize path
    return optimize(qc, scp);
  }
예제 #6
0
파일: Path.java 프로젝트: runeengh/basex
  @Override
  public final Expr optimize(final QueryContext qc, final VarScope scp) throws QueryException {
    final Value v = initial(qc);
    if (v != null && v.isEmpty() || emptyPath(v)) return optPre(qc);

    // merge descendant steps
    Expr e = mergeSteps(qc);
    if (e == this && v != null && v.type == NodeType.DOC) {
      // check index access
      e = index(qc, v);
      // rewrite descendant to child steps
      if (e == this) e = children(qc, v);
    }
    // recompile path if it has changed
    if (e != this) return e.compile(qc, scp);

    // set atomic type for single attribute steps to speed up predicate tests
    if (root == null && steps.length == 1 && steps[0] instanceof Step) {
      final Step curr = (Step) steps[0];
      if (curr.axis == ATTR && curr.test.kind == Kind.URI_NAME) curr.seqType(SeqType.NOD_ZO);
    }

    // choose best path implementation and set type information
    final Path path = get(info, root, steps);
    path.size = path.size(qc);
    path.seqType = SeqType.get(steps[steps.length - 1].seqType().type, size);
    return path;
  }
예제 #7
0
  @Override
  @Secured
  public void removeTestExecution(TestExecution testExecution) throws ServiceException {
    TestExecution freshTestExecution = testExecutionDAO.get(testExecution.getId());
    if (freshTestExecution == null) {
      throw new ServiceException("serviceException.testExecutionNotFound", testExecution.getName());
    }
    for (TestExecutionParameter testExecutionParameter : freshTestExecution.getParameters()) {
      testExecutionParameterDAO.remove(testExecutionParameter);
    }
    for (Value value : freshTestExecution.getValues()) {
      for (ValueParameter valueParameter : value.getParameters()) {
        valueParameterDAO.remove(valueParameter);
      }
      valueDAO.remove(value);
    }

    Iterator<TestExecutionAttachment> allTestExecutionAttachments =
        freshTestExecution.getAttachments().iterator();
    while (allTestExecutionAttachments.hasNext()) {
      testExecutionAttachmentDAO.remove(allTestExecutionAttachments.next());
      allTestExecutionAttachments.remove();
    }
    testExecutionDAO.remove(freshTestExecution);
  }
예제 #8
0
파일: Path.java 프로젝트: runeengh/basex
  /**
   * Computes the number of results.
   *
   * @param qc query context (may be @code null)
   * @return number of results
   */
  private long size(final QueryContext qc) {
    final Value rt = initial(qc);
    // skip computation if value is not a document node
    if (rt == null || rt.type != NodeType.DOC) return -1;
    final Data data = rt.data();
    // skip computation if no database instance is available, is out-of-date or
    // if context does not contain all database nodes
    if (data == null || !data.meta.uptodate || data.resources.docs().size() != rt.size()) return -1;

    ArrayList<PathNode> nodes = data.paths.root();
    long m = 1;
    final int sl = steps.length;
    for (int s = 0; s < sl; s++) {
      final Step curr = axisStep(s);
      if (curr != null) {
        nodes = curr.nodes(nodes, data);
        if (nodes == null) return -1;
      } else if (s + 1 == sl) {
        m = steps[s].size();
      } else {
        // stop if a non-axis step is not placed last
        return -1;
      }
    }

    long sz = 0;
    for (final PathNode pn : nodes) sz += pn.stats.count;
    return sz * m;
  }
예제 #9
0
  /** Evaluate isUnique expression. */
  protected final Value evalIsUnique(EvalContext ctx) {
    // evaluate range
    Value v = fRangeExp.eval(ctx);
    if (v.isUndefined()) return UndefinedValue.instance;
    CollectionValue rangeVal = (CollectionValue) v;

    // collect values for finding duplicates
    Set<Value> values = new HashSet<Value>();

    // loop over range elements
    for (Value elemVal : rangeVal) {

      // bind element variable to range element, if variable was
      // declared
      if (!fElemVarDecls.isEmpty()) ctx.pushVarBinding(fElemVarDecls.varDecl(0).name(), elemVal);

      // evaluate collect expression
      Value val = fQueryExp.eval(ctx);

      if (!fElemVarDecls.isEmpty()) ctx.popVarBinding();

      // stop if duplicate element is found
      if (values.contains(val)) return BooleanValue.FALSE;
      else values.add(val);
    }

    // result is true if no duplicates where found
    return BooleanValue.TRUE;
  }
예제 #10
0
 private void printVar(OutputSink out, LocalVariable var, StackFrame frame) {
   out.print("  " + var.name());
   if (var.isVisible(frame)) {
     Value val = frame.getValue(var);
     out.println(" = " + val.toString());
   } else {
     out.println(" is not in scope");
   }
 }
예제 #11
0
 /**
  * Checks the response to an HTTP request.
  *
  * @param v query result
  * @param itemsCount expected number of items
  * @param expStatus expected status
  */
 private static void checkResponse(final Value v, final int itemsCount, final int expStatus) {
   assertEquals(itemsCount, v.size());
   assertTrue(v.itemAt(0) instanceof FElem);
   final FElem response = (FElem) v.itemAt(0);
   assertNotNull(response.attributes());
   if (!eq(response.attribute(STATUS), token(expStatus))) {
     fail("Expected: " + expStatus + "\nFound: " + response);
   }
 }
예제 #12
0
  /**
   * Evaluate exists and forAll expressions. The array <code>moreElemVars</code> may be null if
   * there is at most one element variable declared.
   */
  protected final Value evalExistsOrForAll(EvalContext ctx, boolean doExists) {
    // evaluate range
    Value v = fRangeExp.eval(ctx);
    if (v.isUndefined()) return UndefinedValue.instance;
    CollectionValue rangeVal = (CollectionValue) v;

    // we need recursion for the permutation of assignments of
    // range values to all element variables.
    boolean res = evalExistsOrForAll0(0, rangeVal, ctx, doExists);
    return BooleanValue.get(res);
  }
예제 #13
0
파일: Path.java 프로젝트: nikhi/basex
 /**
  * Returns the root of the current context or {@code null}.
  *
  * @param ctx query context
  * @return root
  */
 final Value root(final QueryContext ctx) {
   final Value v = ctx != null ? ctx.value : null;
   // no root specified: return context, if it does not reference a document
   // as e.g. happens in //a(b|c)
   if (root == null) return v == null || v.type != NodeType.DOC ? v : null;
   // root is value: return root
   if (root.isValue()) return (Value) root;
   // no root reference, no context: return null
   if (!(root instanceof Root) || v == null) return null;
   // return context sequence or root of current context
   return v.size() == 1 ? Root.root(v) : v;
 }
예제 #14
0
 private static boolean checkIfIsArrayFunction(
     SootMethod method, InstanceInvokeExpr instanceInvokeExpr) {
   String methodName = method.getName();
   Value base = instanceInvokeExpr.getBase();
   System.out.println(base.getType());
   if (base.getType().toString().equals("android.content.Intent")) {
     if (methodName.startsWith("get") && methodName.contains("Array")) {
       return true;
     }
   }
   return false;
 }
예제 #15
0
 /* Returns a negative integer, zero, or a positive integer as v1
 is less than, equal to, or greater v2.
 NOTE: assume values are ints.
 */
 public static int compareIntValues(Value val1, Value val2) {
   try {
     int vval1 = new Integer(val1.toString()).intValue();
     int vval2 = new Integer(val2.toString()).intValue();
     if (vval1 > vval2) return 1;
     else if (vval2 > vval1) return -1;
     return 0;
   } catch (Exception e) {
     Utility.Dprint("  Error in Variable.compareValues(): Vals are not ints." + e, 0);
   }
   return 0;
 }
예제 #16
0
  /**
   * @ast method
   * @aspect Expressions
   * @declaredat
   *     /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Expressions.jrag:84
   */
  public soot.Value eval(Body b) {
    TypeDecl dest = getDest().type();
    TypeDecl source = getSource().type();
    if (dest.isString()) {

      Value lvalue = getDest().eval(b);

      Value v = asImmediate(b, lvalue);

      // new StringBuffer(left)
      Local local =
          b.newTemp(b.newNewExpr(lookupType("java.lang", "StringBuffer").sootRef(), this));
      b.setLine(this);
      b.add(
          b.newInvokeStmt(
              b.newSpecialInvokeExpr(
                  local,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: void <init>(java.lang.String)>")
                      .makeRef(),
                  v,
                  this),
              this));

      // append right
      Local rightResult =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  local,
                  lookupType("java.lang", "StringBuffer")
                      .methodWithArgs("append", new TypeDecl[] {source.stringPromotion()})
                      .sootRef(),
                  asImmediate(b, getSource().eval(b)),
                  this));

      // toString
      Local result =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  rightResult,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: java.lang.String toString()>")
                      .makeRef(),
                  this));

      Value v2 = lvalue instanceof Local ? lvalue : (Value) lvalue.clone();
      getDest().emitStore(b, v2, result, this);
      return result;
    } else {
      return super.eval(b);
    }
  }
예제 #17
0
파일: Preds.java 프로젝트: dirkk/basex
 @Override
 public Expr compile(final QueryContext qc, final VarScope scp) throws QueryException {
   final Value init = qc.value;
   // never compile predicates with empty sequence as context value (#1016)
   if (init != null && init.isEmpty()) qc.value = null;
   try {
     final int pl = preds.length;
     for (int p = 0; p < pl; ++p) preds[p] = preds[p].compile(qc, scp).optimizeEbv(qc, scp);
     return this;
   } finally {
     qc.value = init;
   }
 }
  public VNodeDefinition(Node node) throws RepositoryException {
    name = node.getProperty(JCR_NODETYPENAME).getString();

    // do properties
    properties = new HashMap<String, VPropertyDefinitionI>();
    childSuggestions = new HashMap<String, String>();
    NodeIterator nodeIterator = node.getNodes();
    while (nodeIterator.hasNext()) {
      Node definitionNode = nodeIterator.nextNode();
      String nodeType = definitionNode.getProperty(AbstractProperty.JCR_PRIMARYTYPE).getString();

      // do a property
      if (NT_PROPERTYDEFINITION.equals(nodeType)) {
        String propertyName = "*"; // default to wildcard name
        if (definitionNode.hasProperty(JCR_NAME)) {

          // only add non-autogenerated properties
          if (!definitionNode.getProperty(JCR_AUTOCREATED).getBoolean()) {
            propertyName = definitionNode.getProperty(JCR_NAME).getString();
            properties.put(propertyName, new VPropertyDefinition(definitionNode));
          }
        } else {
          // property with no name means this node can accept custom properties
          canAddProperties = true;
        }
      }

      // do a child suggestion
      if (NT_CHILDNODEDEFINITION.equals(nodeType)) {
        String childName = "*";
        // only do well-defined childnodedefinitions with the following 2 jcr properties
        if (definitionNode.hasProperty(JCR_NAME)
            && definitionNode.hasProperty(JCR_DEFAULTPRIMARYTYPE)) {
          childSuggestions.put(
              definitionNode.getProperty(JCR_NAME).getString(),
              definitionNode.getProperty(JCR_DEFAULTPRIMARYTYPE).getString());
        }
      }
    }

    // do supertypes
    supertypes = new HashSet<String>();
    if (node.hasProperty(JCR_SUPERTYPES)) {
      for (Value value : node.getProperty(JCR_SUPERTYPES).getValues()) {
        supertypes.add(value.getString());
      }
    }

    // set mixin status
    isMixin = node.hasProperty(JCR_ISMIXIN) && node.getProperty(JCR_ISMIXIN).getBoolean();
  }
예제 #19
0
 @Override
 @Secured
 public void removeValue(Value value) throws ServiceException {
   TestExecution exec = testExecutionDAO.get(value.getTestExecution().getId());
   if (exec == null) {
     throw new ServiceException(
         "serviceException.removeValue.testExecutionNotFound", value.getTestExecution().getName());
   }
   Value v = valueDAO.get(value.getId());
   for (ValueParameter vp : v.getParameters()) {
     valueParameterDAO.remove(vp);
   }
   valueDAO.remove(v);
 }
예제 #20
0
 /**
  * Returns a parameter.
  *
  * @param value value
  * @param name name
  * @param declared variable declaration flags
  * @return parameter
  * @throws QueryException HTTP exception
  */
 private RestXqParam param(final Value value, final QNm name, final boolean[] declared)
     throws QueryException {
   // [CG] RESTXQ: allow identical field names?
   final long vs = value.size();
   if (vs < 2) error(ANN_PARAMS, "%", name.string(), 2);
   // name of parameter
   final String key = toString(value.itemAt(0), name);
   // variable template
   final QNm qnm = checkVariable(toString(value.itemAt(1), name), declared);
   // default value
   final ValueBuilder vb = new ValueBuilder();
   for (int v = 2; v < vs; v++) vb.add(value.itemAt(v));
   return new RestXqParam(qnm, key, vb.value());
 }
예제 #21
0
파일: Request2.java 프로젝트: jmcclell/h2o
 @Override
 protected Key parse(String input) {
   if (_validator != null) _validator.validateRaw(input);
   Key k = Key.make(input);
   Value v = DKV.get(k);
   if (v == null && _mustExist)
     throw new IllegalArgumentException("Key '" + input + "' does not exist!");
   if (_type != null) {
     if (v != null && !compatible(_type, v.get()))
       throw new IllegalArgumentException(input + ":" + errors()[0]);
     if (v == null && _required)
       throw new IllegalArgumentException("Key '" + input + "' does not exist!");
   }
   return k;
 }
예제 #22
0
파일: Path.java 프로젝트: runeengh/basex
  /**
   * Returns the path nodes that will result from this path.
   *
   * @param qc query context
   * @return path nodes, or {@code null} if nodes cannot be evaluated
   */
  public final ArrayList<PathNode> pathNodes(final QueryContext qc) {
    final Value init = initial(qc);
    final Data data = init != null && init.type == NodeType.DOC ? init.data() : null;
    if (data == null || !data.meta.uptodate) return null;

    ArrayList<PathNode> nodes = data.paths.root();
    final int sl = steps.length;
    for (int s = 0; s < sl; s++) {
      final Step curr = axisStep(s);
      if (curr == null) return null;
      nodes = curr.nodes(nodes, data);
      if (nodes == null) return null;
    }
    return nodes;
  }
  /** Implementation for getting the indices of this class. i.e. <code>$a->foo[0]</code> */
  public Value __get(Env env, Value indexV) {
    if (indexV.isString()) {
      String name = indexV.toString();

      SimpleXMLElement attr = getAttribute(name);

      if (attr != null) return wrapJava(env, _cls, attr);
      else return NullValue.NULL;
    } else if (indexV.isLongConvertible()) {
      int i = indexV.toInt();

      if (i < _attributes.size()) return wrapJava(env, _cls, _attributes.get(i));

      return NullValue.NULL;
    } else return NullValue.NULL;
  }
예제 #24
0
파일: Value.java 프로젝트: ellert/JGlobus
 /**
  * Appends the specified value to the end of the chain of concatinated values. That is, if this
  * value has no concatinated value then set the specified value as the concatinated value. If this
  * value already has a concatinated value then append the specified value to that concatinated
  * value.
  *
  * @param value the value to concatinate.
  */
 public void concat(Value value) {
   if (concatValue != null) {
     concatValue.concat(value);
   } else {
     concatValue = value;
   }
 }
예제 #25
0
  public static boolean maybeSameLocation(Value v1, Value v2) {
    if (!(v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef)
        && !(v1 instanceof ArrayRef && v2 instanceof ArrayRef)) {
      return v1.equivTo(v2);
    }
    if (v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) {
      InstanceFieldRef ifr1 = (InstanceFieldRef) v1;
      InstanceFieldRef ifr2 = (InstanceFieldRef) v2;
      if (!ifr1.getField().getName().equals(ifr2.getField().getName())) return false;

      Local base1 = (Local) ifr1.getBase();
      Local base2 = (Local) ifr2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    } else { // v1 instanceof ArrayRef && v2 instanceof ArrayRef
      ArrayRef ar1 = (ArrayRef) v1;
      ArrayRef ar2 = (ArrayRef) v2;

      Local base1 = (Local) ar1.getBase();
      Local base2 = (Local) ar2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    }
  }
예제 #26
0
파일: HandTest.java 프로젝트: yag/PokerP2P
  public static void main(String[] args) {

    List<Card> cards = new LinkedList<Card>();
    for (Value v : Value.values()) {
      for (Suit s : Suit.values()) {
        cards.add(new Card(v, s));
      }
    }

    Random rand = new Random();
    Card[] cards1 = new Card[7];
    Card[] cards2 = new Card[7];

    for (int i = 0; i < 7; i++) {
      // Card c = cards.remove(rand.nextInt(cards.size())) ;
      Card c1 = cards.remove(2 + i * 3);
      cards1[i] = c1;
      Card c2 = cards.remove(rand.nextInt(cards.size()));
      cards2[i] = c2;
    }

    System.out.println("------ Card 1 ---------");
    for (Card c : cards1) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards1));
    System.out.println("------ Card 2 ---------");
    for (Card c : cards2) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards2));
  }
예제 #27
0
 private void commandPrint(StringTokenizer t, boolean dumpObject) throws NoSessionException {
   if (!t.hasMoreTokens()) {
     // ### Probably confused if expresion contains whitespace.
     env.error("No expression specified.");
     return;
   }
   ThreadReference current = context.getCurrentThread();
   if (current == null) {
     env.failure("No default thread specified: " + "use the \"thread\" command first.");
     return;
   }
   StackFrame frame;
   try {
     frame = context.getCurrentFrame(current);
     if (frame == null) {
       env.failure("Thread has not yet created any stack frames.");
       return;
     }
   } catch (VMNotInterruptedException e) {
     env.failure("Target VM must be in interrupted state.");
     return;
   }
   while (t.hasMoreTokens()) {
     String expr = t.nextToken("");
     Value val = null;
     try {
       val = runtime.evaluate(frame, expr);
     } catch (Exception e) {
       env.error("Exception: " + e);
       // ### Fix this!
     }
     if (val == null) {
       return; // Error message already printed
     }
     OutputSink out = env.getOutputSink();
     if (dumpObject && (val instanceof ObjectReference) && !(val instanceof StringReference)) {
       ObjectReference obj = (ObjectReference) val;
       ReferenceType refType = obj.referenceType();
       out.println(expr + " = " + val.toString() + " {");
       dump(out, obj, refType, refType);
       out.println("}");
     } else {
       out.println(expr + " = " + val.toString());
     }
     out.show();
   }
 }
예제 #28
0
파일: Path.java 프로젝트: runeengh/basex
  /**
   * Converts descendant to child steps.
   *
   * @param qc query context
   * @param rt root value
   * @return original or new expression
   */
  private Expr children(final QueryContext qc, final Value rt) {
    // skip if index does not exist or is out-dated, or if several namespaces occur in the input
    final Data data = rt.data();
    if (data == null || !data.meta.uptodate || data.nspaces.globalNS() == null) return this;

    Path path = this;
    final int sl = steps.length;
    for (int s = 0; s < sl; s++) {
      // don't allow predicates in preceding location steps
      final Step prev = s > 0 ? axisStep(s - 1) : null;
      if (prev != null && prev.preds.length != 0) break;

      // ignore axes other than descendant, or numeric predicates
      final Step curr = axisStep(s);
      if (curr == null || curr.axis != DESC || curr.has(Flag.FCS)) continue;

      // check if child steps can be retrieved for current step
      ArrayList<PathNode> nodes = pathNodes(data, s);
      if (nodes == null) continue;

      // cache child steps
      final ArrayList<QNm> qnm = new ArrayList<>();
      while (nodes.get(0).parent != null) {
        QNm nm = new QNm(data.elemNames.key(nodes.get(0).name));
        // skip children with prefixes
        if (nm.hasPrefix()) return this;
        for (final PathNode p : nodes) {
          if (nodes.get(0).name != p.name) nm = null;
        }
        qnm.add(nm);
        nodes = PathSummary.parent(nodes);
      }
      qc.compInfo(OPTCHILD, steps[s]);

      // build new steps
      int ts = qnm.size();
      final Expr[] stps = new Expr[ts + sl - s - 1];
      for (int t = 0; t < ts; t++) {
        final Expr[] preds = t == ts - 1 ? ((Preds) steps[s]).preds : new Expr[0];
        final QNm nm = qnm.get(ts - t - 1);
        final NameTest nt =
            nm == null ? new NameTest(false) : new NameTest(nm, Kind.NAME, false, null);
        stps[t] = Step.get(info, CHILD, nt, preds);
      }
      while (++s < sl) stps[ts++] = steps[s];
      path = get(info, root, stps);
      break;
    }

    // check if all steps yield results; if not, return empty sequence
    final ArrayList<PathNode> nodes = pathNodes(qc);
    if (nodes != null && nodes.isEmpty()) {
      qc.compInfo(OPTPATH, path);
      return Empty.SEQ;
    }

    return path;
  }
예제 #29
0
  protected Advisory evaluateVital(Vital vital) {

    Advisory a = null;

    if (vital.isNoValueWarning() && vital.isEmpty()) {
      a = new Advisory(State.Warning, vital, null, "no source of");
    } else {
      for (Value val : vital) {
        if (val.isAtOrBelowLow()) {
          a =
              new Advisory(
                  val.isAtOrBelowCriticalLow() ? State.Alarm : State.Warning,
                  vital,
                  val.getValue(),
                  "low");
        }
        if (val.isAtOrAboveHigh()) {
          a =
              new Advisory(
                  val.isAtOrAboveCriticalHigh() ? State.Alarm : State.Warning,
                  vital,
                  val.getValue(),
                  "high");
        }
        if (a != null && a.state == State.Alarm) break;
      }
    }
    return a;
  }
예제 #30
0
파일: Value.java 프로젝트: ellert/JGlobus
 public boolean equals(Object obj) {
   if (obj instanceof Value) {
     Value src = (Value) obj;
     if (src.getValue() == null) {
       if (getValue() != null) return false;
     } else {
       if (!src.getValue().equals(getValue())) return false;
     }
     if (src.getConcat() == null) {
       if (getConcat() != null) return false;
     } else {
       if (!src.getConcat().equals(getConcat())) return false;
     }
     return true;
   } else {
     return super.equals(obj);
   }
 }