Package org.wso2.carbon.rulecep.commons

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


        if (namespace != null && !"".equals(namespace.getPrefix())) {

            try {
                xpath.addNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
            } catch (JaxenException je) {
                throw new LoggedRuntimeException(
                        "Error adding declared name space with prefix : "
                                + namespace.getPrefix() + "and uri : " + namespace.getNamespaceURI()
                                + " to the XPath : " + xpath, je, log);
            }
        }
View Full Code Here


            PropertyDescription prop = new PropertyDescription();

            if (attName == null || attName.getAttributeValue() == null ||
                    attName.getAttributeValue().trim().length() == 0) {
                throw new LoggedRuntimeException("Name is a required attribute for a " +
                        "property", log);
            } else {
                prop.setName(attName.getAttributeValue());
            }

            // if a value is specified, use it, else look for an expression
            if (attValue != null) {

                if (attValue.getAttributeValue() == null ||
                        attValue.getAttributeValue().trim().length() == 0) {

                    throw new LoggedRuntimeException("Attribute value (if specified) " +
                            "is required for a property", log);

                } else {
                    prop.setValue(attValue.getAttributeValue());
                }

            } else if (attExpr != null) {

                if (attExpr.getAttributeValue() == null ||
                        attExpr.getAttributeValue().trim().length() == 0) {

                    throw new LoggedRuntimeException("Attribute expression (if specified) " +
                            "is required for a property", log);

                } else {
                    BaseXPath xpath = xPathFactory.createXPath(propEle,
                            PropertyDescription.ATT_EXPR_Q);
                    prop.setExpression(xpath);
                }

            } else if (propEle.getFirstElement() != null) {
                prop.setValue(propEle.getFirstElement().toString());
            } else {
                throw new LoggedRuntimeException(
                        "Attribute value OR expression must " +
                                "be specified for a property", log);
            }

            propertyList.add(prop);
View Full Code Here

        String key = description.getKey();
        String path = description.getPath();
        Object inLinedScript = description.getQuerySource();

        if (key == null && inLinedScript == null && path == null) {
            throw new LoggedRuntimeException("Invalid Configuration !!- Either script in-lined " +
                    "value or key or path should be presented", log);
        }

        if (key != null && !"".equals(key)) {
            parent.addAttribute(OM_FACTORY.createOMAttribute(
View Full Code Here

                    new StringReader(xml));
            StAXOMBuilder builder = new StAXOMBuilder(reader);
            return builder.getDocumentElement();

        } catch (XMLStreamException e) {
            throw new LoggedRuntimeException("Error creating a OMElement from text : " + xml,
                    e, log);
        }
    }
View Full Code Here

                    XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
            StAXOMBuilder builder = new StAXOMBuilder(reader);
            return builder.getDocumentElement();

        } catch (XMLStreamException e) {
            throw new LoggedRuntimeException("Error creating a OMElement from an input stream : ",
                    e, log);
        }
    }
View Full Code Here

                serviceElement = OM_FACTORY.createOMElement(CommonsConstants.ELE_SERVICE,
                        omNamespaceFactory.createOMNamespace(new QName(name)));
                serviceElement.addAttribute(OM_FACTORY.createOMAttribute("name", NULL_NS,
                        name.trim()));
            } else {
                throw new LoggedRuntimeException("Service name missing", log);
            }
            // set description
            OMNamespace omNamespace = omNamespaceFactory.createOMNamespace(
                    serviceElement.getQName());
View Full Code Here

                omNamespace);
        String name = description.getName();
        if (name != null && !"".equals(name.trim())) {
            serviceElement.addAttribute(OM_FACTORY.createOMAttribute("name", NULL_NS, name.trim()));
        } else {
            throw new LoggedRuntimeException("Service name missing", log);
        }

        String tns = description.getTargetNamespace();
        if (tns != null && !"".equals(tns)) {
            serviceElement.addAttribute(OM_FACTORY.createOMAttribute(
View Full Code Here

     * @return a POJO of the type specified in the given resource description if there is no errors.
     */
    public Object adaptInput(ResourceDescription description, Object source) {
        String className = description.getType();
        if (className == null) {
            throw new LoggedRuntimeException("The class name cannot be found.", log);
        }
        if (source instanceof OMText) {
            source = ((OMText) source).getText();
        }
        if (className.equals(source.getClass().getName())) {
            return source;
        } else if (source instanceof String && ClassHelper.isWrapperType(className)) {
            return ClassHelper.createWrapperTypeInstance(className, (String) source);
        } else if (source instanceof OMElement) {
            OMElement omElement = (OMElement) source;
            int index = className.indexOf(",");
            if (index > 0) {
                String[] classNames = className.split(",");
                return adaptToMultiplePOJOs(omElement, classNames);
            } else if (description.hasChildren()) {
                final Collection<ResourceDescription> children = description.getChildResources();
                Collection<Class> classes = description.getChildrenClasses();
                if (classes.isEmpty()) {
                    classes = new ArrayList<Class>();
                    for (ResourceDescription child : children) {
                        if (child == null) {
                            continue;
                        }
                        String childClass = child.getType();
                        Class aClass = ClassHelper.loadAClass(childClass,
                                description.getResourceClassLoader());
                        if (aClass == null) {
                            continue;
                        }
                        classes.add(aClass);
                    }
                    description.addChildrenClasses(classes);
                }

                if (classes.isEmpty()) {
                    if (log.isDebugEnabled()) {
                        log.debug("Required arguments can not be found." + "Returning null");
                    }
                    return null;
                }
                Collection<String> childrenNames = description.getChildrenNames();

                Iterator it = omElement.getChildElements();
                OMElement tobeAdapted;

                ArrayList<String> childTypeList =new ArrayList<String>();
                for (ResourceDescription child : children) {
                    if (child == null) {
                        continue;
                    }
                    childTypeList.add(child.getType());
                }
                classes.clear();
                while (it.hasNext()) {
                    tobeAdapted = (OMElement) it.next();
                    String localClass = tobeAdapted.getQName().getLocalPart();
                    for (String name : childTypeList) {
                        String classNamePart = name.substring(name.lastIndexOf(".") + 1);
                        if (classNamePart.equals(localClass)) {
                            Class aClass = ClassHelper.loadAClass(name,
                                    description.getResourceClassLoader());
                            if (aClass == null) {
                                continue;
                            }
                            classes.add(aClass);
                        }
                    }

                }

                if (childrenNames.size() != classes.size()) {
                    return toObjects(omElement, classes, null);
                } else {
                    return toObjects(omElement, classes,
                            childrenNames.toArray(new String[childrenNames.size()]));
                }
            } else {
                OMElement tobeAdapted;
                if (omElement.getParent() instanceof SOAPBody) {
                    tobeAdapted = omElement.getFirstElement();
                    Iterator it = omElement.getChildElements();
                    List adaptedInputs = new ArrayList();
                    while (it.hasNext()) {
                        tobeAdapted = (OMElement) it.next();
                        adaptedInputs.add(getAdaptedFacts(description, className, tobeAdapted, source));
                    }
                    return adaptedInputs;
                } else {
                    tobeAdapted = omElement;
                }
                QName qName = getQName(description, className, tobeAdapted);
                if (!qName.equals(tobeAdapted.getQName())) {
                    if (log.isDebugEnabled()) {
                        log.debug("The source element QName does not match with the expected QName." +
                                "[ Source Element QName:  " + tobeAdapted.getQName() + " ] " +
                                "[ Expected QName : " + qName + " ].");
                    }
                    return null;
                }
                try {
                    return BeanUtil.deserialize(ClassHelper.loadAClass(className,
                            description.getResourceClassLoader()),
                            tobeAdapted, new DefaultObjectSupplier(), null);
                } catch (AxisFault axisFault) {
                    throw new LoggedRuntimeException("Cannot create a custom Java object " +
                            "form XML. Java class is : " + className + " and XML is : " +
                            source, log);
                }
            }

        } else {
            throw new LoggedRuntimeException("Incompatible type , " +
                    "the provided class name ' " +
                    className + " ' doesn't match " +
                    "with the class name of the custom Java object.", log);
        }
    }
View Full Code Here

        try {
            return BeanUtil.deserialize(ClassHelper.loadAClass(className,
                    description.getResourceClassLoader()),
                    tobeAdapted, new DefaultObjectSupplier(), null);
        } catch (AxisFault axisFault) {
            throw new LoggedRuntimeException("Cannot create a custom Java object " +
                    "form XML. Java class is : " + className + " and XML is : " +
                    source, log);
        }
    }
View Full Code Here

                    BeanUtil.deserialize(tobeAdapted, parameters.toArray(
                            new Object[parameters.size()]), new DefaultObjectSupplier(),
                            strings, null);

            if (parameters.size() != objects.length) {
                throw new LoggedRuntimeException("Error processing value for the " +
                        "Axis2operation : required arguments can not be found." +
                        tobeAdapted, log);
            }

            final List<Object> pairs = new ArrayList<Object>();
            for (Object value : objects) {
                if (value != null) {
                    pairs.add(value);
                }
            }
            return pairs;
        } catch (AxisFault axisFault) {
            throw new LoggedRuntimeException("Error processing value for the Axis2operation " +
                    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.