Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

In this page you can find the example usage for java.lang Throwable Throwable.

Prototype

public Throwable(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause and a detail message of (cause==null ?

Usage

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.KeyphraseEvaluator.java

private void computeThresholdPerformanceResults(int i, int n, List<Keyphrase> keyphrases,
        Set<String> goldKeyphrases, String title) throws AnalysisEngineProcessException {

    List<String> keyphrasesToConsider = getKeyphrasesToConsider(keyphrases, i);

    // update true positives and false positives
    int tp = 0;/*  www .j a  va 2 s. com*/
    int fp = 0;

    int nrOfGoldKeyphrases = goldKeyphrases.size();

    // get the set of matching goldkeyphrases and equivalent extracted keyphrases
    Matchings matchings = getMatchings(new HashSet<String>(goldKeyphrases), keyphrasesToConsider);

    tp = matchings.getNumberOfMatchings();
    fp = keyphrasesToConsider.size() - tp;

    // sanity check
    if (tp > nrOfGoldKeyphrases) {
        throw new AnalysisEngineProcessException(
                new Throwable("More true positives than gold standard keyphrases."));
    }

    // do not show more than the first 100 keyphrases candidates
    if ((i == n) && (i < 100)) {
        getContext().getLogger().log(Level.INFO, "KEYPHRASES:" + keyphrasesToConsider);
        getContext().getLogger().log(Level.INFO, matchings.toString());
    } else if (i == n) {
        getContext().getLogger().log(Level.INFO,
                "KEYPHRASES: " + i + " keyphrases retrieved. Too much to display.");
        getContext().getLogger().log(Level.INFO, matchings.toString());
    }

    performanceCounterAll.setFileTPcount(title, i, tp);
    performanceCounterAll.setFileFPcount(title, i, fp);
    performanceCounterAll.setFileFNcount(title, i, nrOfGoldKeyphrases - tp);
    if (i == nrOfGoldKeyphrases) {
        performanceCounterAll.setRPrecision(title, (double) tp / nrOfGoldKeyphrases);
    }
}

From source file:org.apache.ode.bpel.runtime.ASSIGN.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>//from  w w  w  . j  a va2s .  c om
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 *
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference
                ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        List<Node> l;
        OExpression expr = ((OAssign.Expression) from).expression;
        try {
            l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext());
            if (l.size() == 0 || l.get(0) == null || !(l.get(0) instanceof Element)) {
                if (__log.isTraceEnabled()) {
                    __log.trace("evalRValue: OAssign.Expression: eval reult not Element or node=null");
                }
            } else {
                Element element = (Element) l.get(0);
                for (Map.Entry<String, String> entry : DOMUtils.getMyNSContext(element).toMap().entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (entry.getKey() == null || entry.getKey().length() == 0) {
                        element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", value);
                    } else {
                        element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + key, value);
                    }
                }
            }
        } catch (EvaluationException e) {
            String msg = __msgs.msgEvalException(from.toString(), e.getMessage());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            if (e.getCause() instanceof FaultException)
                throw (FaultException) e.getCause();
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = (Node) l.get(0);
    } else if (from instanceof OAssign.Literal) {
        String literal = ((OAssign.Literal) from).getXmlLiteral();
        Element literalRoot;
        try {
            literalRoot = DOMUtils.stringToDOM(literal);
        } catch (Exception e) {
            throw new RuntimeException("XML literal parsing failed " + literal, e);
        }
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:com.tesora.dve.sql.logfile.LogFileTest.java

/**
 * @param tn//from   www  .  ja  v  a  2s . co  m
 * @param backingType
 * @return
 * @throws Throwable
 */
protected ConnectionResource getConnectionResource(TestName tn, BackingSchema backingType) throws Throwable {
    if ((backingType == BackingSchema.MULTI) || (backingType == BackingSchema.SINGLE)) {
        return new ProxyConnectionResource();
    } else if (backingType == BackingSchema.NATIVE) {
        return new DBHelperConnectionResource(getUrlOptions());
    } else if ((backingType == BackingSchema.SINGLE_PORTAL) || (backingType == BackingSchema.MULTI_PORTAL)) {
        return new PortalDBHelperConnectionResource(getUrlOptions());
    } else if (backingType == null) {
        return null;
    } else {
        throw new Throwable("Unknown backing schema type: " + backingType);
    }

}

From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>//from   w w w . ja v  a 2  s.co  m
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 * (madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here)
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
public Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof OAssign.DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntime().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntime().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.ContextRef) {
        OAssign.ContextRef ctxRef = (OAssign.ContextRef) from;
        ContextData cdata = getBpelRuntime().fetchContextData(_scopeFrame.resolve(ctxRef.partnerLink));
        retVal = evalQuery(cdata.toXML(ctxRef.contexts), null, ctxRef.location, getEvaluationContext());
    } else if (from instanceof OAssign.Expression) {
        OExpression expr = ((OAssign.Expression) from).expression;
        List<Node> l = getBpelRuntime().getExpLangRuntime().evaluate(expr, getEvaluationContext());

        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = l.get(0);
    } else if (from instanceof OAssign.Literal) {
        Element literalRoot = ((OAssign.Literal) from).getXmlLiteral().getDocumentElement();
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.ode.bpel.runtime.AssignHelper.java

/**
 * Get the r-value. There are several possibilities:
 * <ul>//from   w ww.jav a2  s . c  o m
 * <li>a message is selected - an element representing the whole message is
 * returned.</li>
 * <li>a (element) message part is selected - the element is returned.
 * </li>
 * <li>a (typed) message part is select - a wrapper element is returned.
 * </li>
 * <li>an attribute is selected - an attribute node is returned. </li>
 * <li>a text node/string expression is selected - a text node is returned.
 * </li>
 * </ul>
 *
 * @param from
 *
 * @return Either {@link Element}, {@link org.w3c.dom.Text}, or
 *         {@link org.w3c.dom.Attr} node representing the r-value.
 *
 * @throws FaultException
 *             DOCUMENTME
 * @throws UnsupportedOperationException
 *             DOCUMENTME
 * @throws IllegalStateException
 *             DOCUMENTME
 */
private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException {
    if (__log.isDebugEnabled())
        __log.debug("Evaluating FROM expression \"" + from + "\".");

    Node retVal;
    if (from instanceof DirectRef) {
        OAssign.DirectRef dref = (OAssign.DirectRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(dref.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false);
        retVal = DOMUtils.findChildByName((Element) data, dref.elName);
    } else if (from instanceof OAssign.VariableRef) {
        OAssign.VariableRef varRef = (OAssign.VariableRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(varRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false);
        retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PropertyRef) {
        OAssign.PropertyRef propRef = (OAssign.PropertyRef) from;
        sendVariableReadEvent(_scopeFrame.resolve(propRef.variable));
        Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false);
        retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location,
                getEvaluationContext());
    } else if (from instanceof OAssign.PartnerLinkRef) {
        OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from;
        PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink);
        Node tempVal = pLinkRef.isMyEndpointReference
                ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink)
                : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink);
        if (__log.isDebugEnabled())
            __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName()
                    + " has value " + DOMUtils.domToString(tempVal));
        retVal = tempVal;
    } else if (from instanceof OAssign.Expression) {
        List<Node> l;
        OExpression expr = ((OAssign.Expression) from).expression;
        try {
            l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext());
        } catch (EvaluationException e) {
            String msg = __msgs.msgEvalException(from.toString(), e.getMessage());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            if (e.getCause() instanceof FaultException)
                throw (FaultException) e.getCause();
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        if (l.size() == 0) {
            String msg = __msgs.msgRValueNoNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg,
                    new Throwable("ignoreMissingFromData"));
        } else if (l.size() > 1) {
            String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString());
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
        retVal = (Node) l.get(0);
    } else if (from instanceof OAssign.Literal) {
        String literal = ((OAssign.Literal) from).getXmlLiteral();
        Element literalRoot;
        try {
            literalRoot = DOMUtils.stringToDOM(literal);
        } catch (Exception e) {
            throw new RuntimeException("XML literal parsing failed " + literal, e);
        }
        assert literalRoot.getLocalName().equals("literal");
        // We'd like a single text node...

        literalRoot.normalize();
        retVal = literalRoot.getFirstChild();

        // Adjust for whitespace before an element.
        if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE
                && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) {
            retVal = retVal.getNextSibling();
        }

        if (retVal == null) {
            // Special case, no children --> empty TII
            retVal = literalRoot.getOwnerDocument().createTextNode("");
        } else if (retVal.getNodeType() == Node.ELEMENT_NODE) {
            // Make sure there is no more elements.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMultipleEIIs();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }
        } else if (retVal.getNodeType() == Node.TEXT_NODE) {
            // Make sure there are no elements following this text node.
            Node x = retVal.getNextSibling();
            while (x != null) {
                if (x.getNodeType() == Node.ELEMENT_NODE) {
                    String msg = __msgs.msgLiteralContainsMixedContent();
                    if (__log.isDebugEnabled())
                        __log.debug(from + ": " + msg);
                    throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

                }
                x = x.getNextSibling();
            }

        }

        if (retVal == null) {
            String msg = __msgs.msgLiteralMustContainTIIorEII();
            if (__log.isDebugEnabled())
                __log.debug(from + ": " + msg);
            throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
        }
    } else {
        String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from);
        if (__log.isErrorEnabled())
            __log.error(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now verify we got something.
    if (retVal == null) {
        String msg = __msgs.msgEmptyRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);
        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);
    }

    // Now check that we got the right thing.
    switch (retVal.getNodeType()) {
    case Node.TEXT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ELEMENT_NODE:
    case Node.CDATA_SECTION_NODE:
        break;
    default:
        String msg = __msgs.msgInvalidRValue();
        if (__log.isDebugEnabled())
            __log.debug(from + ": " + msg);

        throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg);

    }

    return retVal;
}

From source file:org.apache.gobblin.data.management.conversion.hive.validation.ValidationJob.java

/**
 * Validates that partitions are in a given format
 * Partitions to be processed are picked up from the config store which are tagged.
 * Tag can be passed through key GOBBLIN_CONFIG_TAGS_WHITELIST
 * Datasets tagged by the above key will be picked up.
 * PathName will be treated as tableName and ParentPathName will be treated as dbName
 *
 * For example if the dataset uri picked up by is /data/hive/myDb/myTable
 * Then myTable is tableName and myDb is dbName
 *///from   w  ww  . j a  v  a2s  .c o  m
private void runFileFormatValidation() throws IOException {
    Preconditions.checkArgument(this.props.containsKey(VALIDATION_FILE_FORMAT_KEY));

    this.configStoreUri = StringUtils
            .isNotBlank(this.props.getProperty(ConfigurationKeys.CONFIG_MANAGEMENT_STORE_URI))
                    ? Optional.of(this.props.getProperty(ConfigurationKeys.CONFIG_MANAGEMENT_STORE_URI))
                    : Optional.<String>absent();
    if (!Boolean.valueOf(this.props.getProperty(ConfigurationKeys.CONFIG_MANAGEMENT_STORE_ENABLED,
            ConfigurationKeys.DEFAULT_CONFIG_MANAGEMENT_STORE_ENABLED))) {
        this.configStoreUri = Optional.<String>absent();
    }
    List<Partition> partitions = new ArrayList<>();
    if (this.configStoreUri.isPresent()) {
        Preconditions.checkArgument(this.props.containsKey(GOBBLIN_CONFIG_TAGS_WHITELIST),
                "Missing required property " + GOBBLIN_CONFIG_TAGS_WHITELIST);
        String tag = this.props.getProperty(GOBBLIN_CONFIG_TAGS_WHITELIST);
        ConfigClient configClient = ConfigClient
                .createConfigClient(VersionStabilityPolicy.WEAK_LOCAL_STABILITY);
        Path tagUri = PathUtils.mergePaths(new Path(this.configStoreUri.get()), new Path(tag));
        try (AutoReturnableObject<IMetaStoreClient> client = pool.getClient()) {
            Collection<URI> importedBy = configClient.getImportedBy(new URI(tagUri.toString()), true);
            for (URI uri : importedBy) {
                String dbName = new Path(uri).getParent().getName();
                Table table = new Table(client.get().getTable(dbName, new Path(uri).getName()));
                for (org.apache.hadoop.hive.metastore.api.Partition partition : client.get()
                        .listPartitions(dbName, table.getTableName(), maxParts)) {
                    partitions.add(new Partition(table, partition));
                }
            }
        } catch (Exception e) {
            this.throwables.add(e);
        }
    }

    for (Partition partition : partitions) {
        if (!shouldValidate(partition)) {
            continue;
        }
        String fileFormat = this.props.getProperty(VALIDATION_FILE_FORMAT_KEY);
        Optional<HiveSerDeWrapper.BuiltInHiveSerDe> hiveSerDe = Enums
                .getIfPresent(HiveSerDeWrapper.BuiltInHiveSerDe.class, fileFormat.toUpperCase());
        if (!hiveSerDe.isPresent()) {
            throwables.add(new Throwable("Partition SerDe is either not supported or absent"));
            continue;
        }

        String serdeLib = partition.getTPartition().getSd().getSerdeInfo().getSerializationLib();
        if (!hiveSerDe.get().toString().equalsIgnoreCase(serdeLib)) {
            throwables.add(new Throwable("Partition " + partition.getCompleteName() + " SerDe " + serdeLib
                    + " doesn't match with the required SerDe " + hiveSerDe.get().toString()));
        }
    }
    if (!this.throwables.isEmpty()) {
        for (Throwable e : this.throwables) {
            log.error("Failed to validate due to " + e);
        }
        throw new RuntimeException("Validation Job Failed");
    }
}

From source file:io.openkit.OKLeaderboard.java

/**
 * Gets the current user's top score for this leaderboard. If the user is not logged in, calls onFailure and returns.
 * @param responseHandler Response handler for the request.
 *//* www .  ja  v  a 2s. c  o  m*/
public void getUsersTopScoreForLeaderboard(final OKScoresResponseHandler responseHandler) {
    OKUser currentUser = OpenKit.getCurrentUser();

    if (currentUser == null) {
        responseHandler.onSuccess(getPlayerTopScoreFromCache());
        return;
    }

    RequestParams params = new RequestParams();
    params.put("leaderboard_id", Integer.toString(this.OKLeaderboard_id));
    params.put("user_id", Integer.toString(currentUser.getOKUserID()));
    params.put("leaderboard_range", getParamForLeaderboardDisplayRange());

    OKHTTPClient.get("best_scores/user", params, new OKJsonHttpResponseHandler() {

        @Override
        public void onSuccess(JSONObject object) {
            OKScore topScore = new OKScore(object);
            List<OKScore> list = new ArrayList<OKScore>();
            list.add(topScore);
            responseHandler.onSuccess(list);
        }

        //We expect a single OKScore object from the API, not an array
        @Override
        public void onSuccess(JSONArray array) {
            responseHandler.onFailure(
                    new Throwable("Received an array when getting users top score. Expected a single object!"),
                    null);
        }

        @Override
        public void onFailure(Throwable error, String content) {
            responseHandler.onFailure(error, null);
        }

        @Override
        public void onFailure(Throwable e, JSONArray errorResponse) {
            responseHandler.onFailure(e, null);
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            responseHandler.onFailure(e, errorResponse);
        }
    });
}

From source file:org.apache.nifi.web.api.FlowResource.java

/**
 * Retrieves the identity of the user making the request.
 *
 * @return An identityEntity/*from   w  ww  .  j  a v  a  2s. c om*/
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("current-user")
@ApiOperation(value = "Retrieves the user identity of the user making the request", response = CurrentUserEntity.class, authorizations = {
        @Authorization(value = "Read - /flow", type = "") })
public Response getCurrentUser() {

    authorizeFlow();

    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }

    // note that the cluster manager will handle this request directly
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        throw new WebApplicationException(new Throwable("Unable to access details for current user."));
    }

    // create the response entity
    final CurrentUserEntity entity = serviceFacade.getCurrentUser();

    // generate the response
    return clusterContext(generateOkResponse(entity)).build();
}

From source file:org.apache.geode.management.internal.cli.commands.GfshCommandJUnitTest.java

@Test
public void testToStringOnThrowable() {
    assertEquals("test", defaultGfshCommand.toString(new Throwable("test"), false));
}

From source file:org.apache.geode.management.internal.cli.commands.GfshCommandJUnitTest.java

@Test
public void testToStringOnThrowablePrintingStackTrace() {
    final StringWriter writer = new StringWriter();
    final Throwable t = new Throwable("test");

    t.printStackTrace(new PrintWriter(writer));

    assertEquals(writer.toString(), defaultGfshCommand.toString(t, true));
}