Package org.wso2.carbon.rulecep.commons

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


     * @return the stream object of the given object value
     */
    public static InputStream toInputStream(Object value, Map<String, Object> properties) {

        if (value == null) {
            throw new LoggedRuntimeException("Cannot convert null object to a stream", log);
        }

        if (value instanceof InputStream) {
            return (InputStream) value;
        }

        if (log.isDebugEnabled()) {
            log.debug("Value to be converted to stream : " + value);
        }

        if (value instanceof OMElement) {
            if (properties != null) {
                String sourceFormat = (String) properties.get(CommonsConstants.SOURCE);
                if (!CommonsConstants.FORMAT_XML.equals(sourceFormat)) {
                    // if the rule format is native , it have to be wrapped by CDATA
                    String source = ((OMElement) (value)).getText();
                    if (source != null && !"".equals(source)) {
                        return new ByteArrayInputStream(source.trim().getBytes());
                    }
                }
            }
            OMElement omElement = (OMElement) value;
            ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
            try {
                omElement.serialize(arrayOutputStream);
                return new ByteArrayInputStream(arrayOutputStream.toByteArray());
            } catch (XMLStreamException e) {
                throw new LoggedRuntimeException("Error converting to a Stream from OMElement : " +
                        value, e, log);
            }

        } else if (value instanceof OMText) {
            DataHandler dataHandler = (DataHandler) ((OMText) value).getDataHandler();
            if (dataHandler != null) {
                try {
                    return dataHandler.getInputStream();
                } catch (IOException e) {
                    throw new LoggedRuntimeException("Error in reading content as a stream " +
                            "from DataHandler", log);
                }
            }
        } else if (value instanceof URI) {
            try {
                return ((URI) (value)).toURL().openStream();
            } catch (IOException e) {
                throw new LoggedRuntimeException("Error opening stream form URI " + value, e, log);
            }
        } else if (value instanceof String) {
            return new ByteArrayInputStream(((String) value).trim().getBytes());
        } else {
            throw new LoggedRuntimeException("Cannot convert object to a Stream : " + value, log);
        }
        return null;
    }
View Full Code Here


            try {
                AXIOMXPath xpath = new AXIOMXPath(omAttribute.getAttributeValue());
                XPathHelper.addNameSpaces(xpath, element);
                return xpath;
            } catch (JaxenException e) {
                throw new LoggedRuntimeException("Invalid XPapth expression : " +
                        omAttribute.getAttributeValue(), e, log);
            }

        } else {
            throw new LoggedRuntimeException("Couldn't find the XPath attribute with the QName : "
                    + attributeName.toString() + " in the element : " + element.toString(), log);
        }
    }
View Full Code Here

     * @return <code>AXIOMXPath</code> if the expression is valid
     */
    public BaseXPath createXPath(String xpath, Collection<OMNamespace> omNameSpaces) {

        if (xpath == null || "".equals(xpath)) {
            throw new LoggedRuntimeException("XPath expression is null or empty", log);
        }
        try {
            AXIOMXPath axiomxPath = new AXIOMXPath(xpath.trim());
            for (OMNamespace omNamespace : omNameSpaces) {
                if (omNamespace != null) {
                    axiomxPath.addNamespace(omNamespace.getPrefix(), omNamespace.getNamespaceURI());
                }
            }
            return axiomxPath;
        } catch (JaxenException e) {
            throw new LoggedRuntimeException("Invalid XPapth expression : " +
                    xpath, e, log);
        }
    }
View Full Code Here

    public static OMElement serialize(ResourceDescription description,
                                      QName root,
                                      XPathSerializer xPathSerializer) {

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

        String id = description.getName();
        OMElement resourceElem = OM_FACTORY.createOMElement(root.getLocalPart(),
View Full Code Here

        }
        try {
            return classLoader.loadClass(className);

        } catch (ClassNotFoundException e) {
            throw new LoggedRuntimeException("The class with name '" + className +
                    " ' cannot found " + e, log);

        }
    }
View Full Code Here

            return null;
        }
        try {
            return aClass.newInstance();
        } catch (IllegalAccessException e) {
            throw new LoggedRuntimeException("Error when initiating new class" +
                    " instance with name " +
                    "' " + className + " '", e, log);
        } catch (InstantiationException e) {
            throw new LoggedRuntimeException("Error when initiating new class " +
                    "instance with name " +
                    "' " + className + " '", e, log);
        }
    }
View Full Code Here

        if (String.class.getName().equals(className)) {
            return value;
        } else {
            Class aClass = loadAClass(className);
            if (aClass == null) {
                throw new LoggedRuntimeException("Cannot find a class with name : " + className,
                        log);
            }
            String mName = "valueOf";
            try {
                Method method = aClass.getMethod(mName, value.getClass());
                if (log.isDebugEnabled()) {
                    log.debug("Invoking method "
                            + mName + "(" + value + ")");
                }
                return method.invoke(null, value);

            } catch (InvocationTargetException e) {
                throw new LoggedRuntimeException("Error Invoking method : " + mName + "into " +
                        className + " with parameter " + value + ": " + e.getMessage(), e, log);
            } catch (NoSuchMethodException e) {
                throw new LoggedRuntimeException("Error locating a method : " + mName + " from " +
                        className + " with parameter " + value + ": " + e.getMessage(), e, log);
            } catch (IllegalAccessException e) {
                throw new LoggedRuntimeException("Error Invoking method : " + mName + "into " +
                        className + " with parameter " + value + ": " + e.getMessage(), e, log);
            }
        }
    }
View Full Code Here

    public static InputOutputAdaptersConfiguration create(OMElement configurationXML,
                                                          XPathFactory xPathFactory) {

        if (configurationXML == null) {
            throw new LoggedRuntimeException("Invalid  configuration. " +
                    "The configuration cannot be null.", log);
        }

        InputOutputAdaptersConfiguration configuration = new InputOutputAdaptersConfiguration();
        QName tagQName = configurationXML.getQName();
View Full Code Here

     */
    public static Object evaluateAsAXIOMXPath(Object source, String xPath) {
        try {
            return evaluate(source, new AXIOMXPath(xPath));
        } catch (JaxenException e) {
            throw new LoggedRuntimeException("Error creating XPath " + xPath, log);
        }
    }
View Full Code Here

                return result;
            } else {
                return result;
            }
        } catch (JaxenException e) {
            throw new LoggedRuntimeException("Error evaluating XPath " + expression +
                    " on message" + source, 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.