Package org.wso2.carbon.rulecep.commons

Examples of org.wso2.carbon.rulecep.commons.LoggedRuntimeException


     */
    public static Object evaluate(ResourceDescription description,
                                  Object context,
                                  MessageInterceptor messageInterceptor) {
        if (description == null) {
            throw new LoggedRuntimeException("Cannot find the Resource description. " +
                    "Invalid Resource!!", log);
        }

        if (ContextResourceAdapter.TYPE.equals(description.getType())) {
            return context; //TODO  remove this in a proper way
View Full Code Here


    public static Object evaluateExpression(ResourceDescription description,
                                            Object context,
                                            MessageInterceptor messageInterceptor) {

        if (description == null) {
            throw new LoggedRuntimeException("Cannot find the Resource description. " +
                    "Invalid Resource !!", log);
        }

        BaseXPath sourceExpression = description.getExpression();
        if (sourceExpression == null) {
            return null;
        }
        // evaluates the expression against source
        ReturnValue returnValue = messageInterceptor.extract(sourceExpression, context, null);
        Object o = returnValue.getValue();
        if (o instanceof OMNode) {
            return o;

        } else if (o instanceof List && !((List) o).isEmpty()) {
            Object nodeObject = ((List) o).get(0); // Always fetches *only* the first

            if (nodeObject instanceof OMNode) {
                return nodeObject;
            } else {
                throw new LoggedRuntimeException("The evaluation of the XPath expression "
                        + sourceExpression + " must target in an OMNode", log);
            }

        } else {
            throw new LoggedRuntimeException("The evaluation of the XPath expression "
                    + sourceExpression + " must target in an OMNode", log);
        }
    }
View Full Code Here

                               Object context,
                               MessageInterceptor messageInterceptor) {


        if (description == null) {
            throw new LoggedRuntimeException("Cannot find Resource description. " +
                    "Invalid Resource !!", log);
        }
        if (value == null) {
            return false;
        }

        if (propertyOutputAdapter.adaptOutput(description, value, context, messageInterceptor)) {
            return true;
        }

        Object targetNode = ResourceDescriptionEvaluator.evaluateExpression(description,
                context,
                messageInterceptor);

        if (targetNode == null) {
            ReturnValue returnValue = messageInterceptor.extractPayload(context);
            targetNode = returnValue.getValue();
        }

        if (value instanceof OMElement) {
            return false;
        }

        if (!(targetNode instanceof OMElement)) {
            throw new LoggedRuntimeException("The target node should have been an OMNode", log);
        }

        OMElement targetOMNode = (OMElement) targetNode;

        boolean baseType = ClassHelper.isWrapperType(value.getClass().getName());

        // if the type is basic , then set it as a text
        if (baseType) {
            targetOMNode.setText(String.valueOf(value));
        } else {

            // If the custom object provide the string that represents it's
            // internal data as a XML,then it will be used to replace the target node

            String methodName = "toXML";
            OMElement result = null;
            Method method = null;
            try {
                method = value.getClass().getMethod(methodName);
            } catch (NoSuchMethodException ignored) {

            }

            if (method != null) {
                try {
                    Object xml = method.invoke(value);
                    if (xml instanceof String) {
                        result = OMElementHelper.getInstance().toOM((String) xml);
                    } else if (xml instanceof OMElement) {
                        result = (OMElement) xml;
                    }
                } catch (InvocationTargetException e) {
                    throw new LoggedRuntimeException("Error invoking toXML() method " +
                            e.getMessage(),
                            e, log);
                } catch (IllegalAccessException e) {
                    throw new LoggedRuntimeException("Error invoking toXML() method " +
                            e.getMessage(),
                            e, log);
                }

            } else {
View Full Code Here

    public static Object evaluate(PropertyDescription propertyDescription,
                                  Object context, MessageInterceptor messageInterceptor) {

        String name = propertyDescription.getName();
        if (name == null || "".equals(name)) {
            throw new LoggedRuntimeException("Invalid PropertyDescription - a name cannot " +
                    "be found", log);
        }

        Object value = propertyDescription.getValue();
        if (value == null || "".equals(value)) {

            if (context == null) {
                throw new LoggedRuntimeException("Invalid property - a value cannot be found" +
                        " for property : " + name, log);
            }
            ReturnValue returnValue = messageInterceptor.extract(
                    propertyDescription.getExpression(),
                    context, value);
            value = returnValue.getValue();
        }

        if (value == null || "".equals(value)) {
            throw new LoggedRuntimeException("Invalid property - a value cannot be found " +
                    "for property : " + name, log);
        }

        return value;
    }
View Full Code Here

    public boolean adaptOutput(ResourceDescription description,
                               Object value, Object context,
                               MessageInterceptor messageInterceptor) {

        if (description == null) {
            throw new LoggedRuntimeException("Cannot find Resource description. " +
                    "Invalid Resource !!", log);
        }
        if (value == null) {
            return false;
        }
View Full Code Here

    public Object adaptInput(ResourceDescription resourceDescription, Object tobeAdapted) {

        if (tobeAdapted instanceof OMElement) {
            return tobeAdapted;
        } else {
            throw new LoggedRuntimeException("Incompatible value for the OMElement " +
                    tobeAdapted, log);
        }
    }
View Full Code Here

        if (targetNode == null) {
            ReturnValue returnValue = messageInterceptor.extractPayload(context);
            targetNode = returnValue.getValue();
        }
        if (!(targetNode instanceof OMElement)) {
            throw new LoggedRuntimeException("The target node should have been an OMNode", log);
        }

        OMElement targetOMNode = (OMElement) targetNode;

        if (targetOMNode instanceof SOAPBody) {
View Full Code Here

    public boolean adaptOutput(ResourceDescription description,
                               Object value, Object context,
                               MessageInterceptor messageInterceptor) {

        if (description == null) {
            throw new LoggedRuntimeException("Cannot find Resource description. " +
                    "Invalid Resource !!", log);
        }

        if (value == null) {
            return false;
View Full Code Here

    public Object adaptOutput(ResourceDescription description, Object value) {
        if (value instanceof OMElement) {
            return ElementHelper.importOMElement(
                    (OMElement) value, OMAbstractFactory.getOMFactory());
        }
        throw new LoggedRuntimeException("Incompatible value for the DOM " +
                value, log);
    }
View Full Code Here

            return tobeAdapted;
        } else if (tobeAdapted instanceof OMElement) {
            return ((Element) ElementHelper.importOMElement((OMElement) tobeAdapted,
                    DOOMAbstractFactory.getOMFactory())).getOwnerDocument();
        } else {
            throw new LoggedRuntimeException("Incompatible value for the DOM " +
                    tobeAdapted, log);
        }
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.rulecep.commons.LoggedRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.