コード例 #1
0
    /* @see com.hp.hpl.jena.sparql.syntax.ElementVisitorBase#visit(com.hp.hpl.jena.sparql.syntax.ElementTriplesBlock) */
    @Override
    public void visit(final ElementTriplesBlock elementtriplesblock) {
      for (final Triple t : elementtriplesblock.getPattern()) {
        try {
          if (t.getPredicate().isVariable())
            throw new IllegalArgumentException(
                "Variables cannot be used in predicate position in ABoxQuery");

          Atom atom = null;
          final String predURI = t.getPredicate().getURI();
          if (RDF.type.getURI().equals(predURI)) {
            if (t.getObject().isVariable())
              throw new IllegalArgumentException(
                  "Variables cannot be used as objects of rdf:type triples in ABoxQuery");

            final OWLClass c = owlModel.createClass(new URI(t.getObject().getURI()));
            final SWRLIndividualObject arg = makeIndividalObject(t.getSubject());

            atom = swrlFactory.createClassAtom(c, arg);
          } else {
            final OWLProperty p = owlModel.getProperty(new URI(predURI));

            if (p == null)
              throw new IllegalArgumentException(
                  predURI + " is unknown [Object|Datatype]Property in the backing OWL model.");
            else if (p.isDatatypeProperty()) {
              final OWLDataProperty dp = owlModel.createDataProperty(p.getURI());
              final SWRLIndividualObject arg1 = makeIndividalObject(t.getSubject());
              final SWRLDataObject arg2 = makeDataObject(t.getObject());

              atom = swrlFactory.createDataPropertyAtom(dp, arg1, arg2);
            } else if (p.isObjectProperty()) {
              final OWLObjectProperty op = owlModel.createObjectProperty(p.getURI());
              final SWRLIndividualObject arg1 = makeIndividalObject(t.getSubject());
              final SWRLIndividualObject arg2 = makeIndividalObject(t.getObject());

              atom = swrlFactory.createIndividualPropertyAtom(op, arg1, arg2);
            }
            // else it could be a annotation property, which are not relevant anyway
          }

          if (atom != null) atoms = atoms.cons(atom);
        } catch (final URISyntaxException e) {
          throw new IllegalArgumentException(
              e.getInput() + " appearing in the query string is not a valid URI!");
        }
      }
    }
コード例 #2
0
    /* @see com.hp.hpl.jena.sparql.syntax.ElementVisitorBase#visit(com.hp.hpl.jena.sparql.syntax.ElementFilter) */
    @Override
    public void visit(final ElementFilter elementfilter) {
      final Expr expr = elementfilter.getExpr();
      final BuiltinAtom atom;
      try {
        if (expr instanceof Expression) // RDQL
        {
          final Expression e = (Expression) expr;
          final SWRLDataObject arg1 = makeDataObject(e.getArg(0));
          final SWRLDataObject arg2 = makeDataObject(e.getArg(1));

          if (e instanceof Q_Equal) atom = swrlFactory.createEqual(arg1, arg2);
          else if (e instanceof Q_NotEqual) atom = swrlFactory.createNotEqual(arg1, arg2);
          else if (e instanceof Q_GreaterThan) atom = swrlFactory.createGreaterThan(arg1, arg2);
          else if (e instanceof Q_GreaterThanOrEqual)
            atom = swrlFactory.createGreaterThanOrEqual(arg1, arg2);
          else if (e instanceof Q_LessThan) atom = swrlFactory.createLessThan(arg1, arg2);
          else if (e instanceof Q_LessThanOrEqual)
            atom = swrlFactory.createLessThanOrEqual(arg1, arg2);
          else
            throw new IllegalArgumentException(
                "Unsupported constraint expression " + e + " used in RDQL query.");
        } else if (expr.isFunction()) // SPARQL
        {
          final ExprFunction f = (ExprFunction) expr;
          final SWRLDataObject arg1 = makeDataObject(f.getArg(0));
          final SWRLDataObject arg2 = makeDataObject(f.getArg(1));

          if (f instanceof E_Equals) atom = swrlFactory.createEqual(arg1, arg2);
          else if (f instanceof E_NotEquals) atom = swrlFactory.createNotEqual(arg1, arg2);
          else if (f instanceof E_GreaterThan) atom = swrlFactory.createGreaterThan(arg1, arg2);
          else if (f instanceof E_GreaterThanOrEqual)
            atom = swrlFactory.createGreaterThanOrEqual(arg1, arg2);
          else if (f instanceof E_LessThan) atom = swrlFactory.createLessThan(arg1, arg2);
          else if (f instanceof E_LessThanOrEqual)
            atom = swrlFactory.createLessThanOrEqual(arg1, arg2);
          else
            throw new IllegalArgumentException(
                "Unsupported constraint (filter) " + f + " used in SPARQL query.");
        } else return;
        atoms = atoms.cons(atom);
      } catch (final URISyntaxException e) {
        throw new IllegalArgumentException(e.getInput() + " is not a valid URI!");
      }
    }
コード例 #3
0
ファイル: UnparsedText.java プロジェクト: nuxleus/saxonica
  public static URI getAbsoluteURI(String href, String baseURI) throws XPathException {
    URI absoluteURI;
    try {
      absoluteURI = ResolveURI.makeAbsolute(href, baseURI);
    } catch (java.net.URISyntaxException err) {
      XPathException e = new XPathException(err.getReason() + ": " + err.getInput(), err);
      e.setErrorCode("XTDE1170");
      throw e;
    }

    if (absoluteURI.getFragment() != null) {
      XPathException e =
          new XPathException("URI for unparsed-text() must not contain a fragment identifier");
      e.setErrorCode("XTDE1170");
      throw e;
    }

    // The URL dereferencing classes throw all kinds of strange exceptions if given
    // ill-formed sequences of %hh escape characters. So we do a sanity check that the
    // escaping is well-formed according to UTF-8 rules

    EscapeURI.checkPercentEncoding(absoluteURI.toString());
    return absoluteURI;
  }
コード例 #4
0
  private void healthCheck(Id id) {
    final HealthChecks healthChecks = conf(id).getHealthChecks();
    for (Ping ping : healthChecks.getPings()) {
      URI uri;
      if (ping.getUrl().toString().contains(CONTAINER_IP_PATTERN)) {
        try {
          uri =
              new URI(
                  ping.getUrl()
                      .toString()
                      .replace(CONTAINER_IP_PATTERN, getIPAddresses().get(id.toString())));
        } catch (URISyntaxException e) {
          throw new OrchestrationException(
              "Bad health check URI syntax: "
                  + e.getMessage()
                  + ", input: "
                  + e.getInput()
                  + ", index:"
                  + e.getIndex());
        }
      } else {
        uri = ping.getUrl();
      }
      logger.info(String.format("Pinging %s for pattern \"%s\"", uri, ping.getPattern()));

      if (!Pinger.ping(uri, ping.getPattern(), ping.getTimeout())) {
        throw new OrchestrationException(
            "timeout waiting for "
                + uri
                + " for "
                + ping.getTimeout()
                + " with pattern "
                + ping.getPattern());
      }
    }
  }