Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMAttribute


                handleException("Delivery element is not found in the subscription message");
            }

            OMElement filterElem = elem.getFirstChildWithName(FILTER_QNAME);
            if (subscription != null && filterElem != null) {
                OMAttribute dialectAttr = filterElem.getAttribute(ATT_DIALECT);
                if (dialectAttr != null && dialectAttr.getAttributeValue() != null) {
                    subscription.setFilterDialect(dialectAttr.getAttributeValue());
                    subscription.setFilterValue(filterElem.getText());
                } else {
                    handleException("Error in creating subscription. Filter dialect not defined");
                }
            }
View Full Code Here


    public Evaluator create(OMElement e) throws EvaluatorException {
        EqualEvaluator equal = new EqualEvaluator();
        SourceTextRetriever textRetriever = getSourceTextRetriever(e);
        equal.setTextRetriever(textRetriever);

        OMAttribute valueAttr = e.getAttribute(new QName(EvaluatorConstants.VALUE));

        if (valueAttr == null) {
            handleException(EvaluatorConstants.VALUE + " attribute is required");
            return null;
        }

        equal.setValue(valueAttr.getAttributeValue());
        return equal;
    }
View Full Code Here

    protected Mediator createSpecificMediator(OMElement elem, Properties properties) {

        CloneMediator mediator = new CloneMediator();
        processAuditStatus(mediator, elem);
       
        OMAttribute continueParent = elem.getAttribute(ATT_CONTINUE_PARENT);
        if (continueParent != null) {
            mediator.setContinueParent(JavaUtils.isTrueExplicitly(
                    continueParent.getAttributeValue()));
        }

        Iterator targetElements = elem.getChildrenWithName(TARGET_Q);
        while (targetElements.hasNext()) {
            mediator.addTarget(TargetFactory.createTarget(
View Full Code Here

        QName queueQName = createQname(namespace, ExecutorConstants.QUEUE);
        QName threadsQName = createQname(namespace, ExecutorConstants.THREADS);

        PriorityExecutor executor = new PriorityExecutor();

        OMAttribute nameAtt = e.getAttribute(NAME_ATT);
        if (nameAtt != null && !"".equals(nameAtt.getAttributeValue())) {
            executor.setName(nameAtt.getAttributeValue());
        } else if (requireName){
            handlerException(ExecutorConstants.NAME +
                    " is required for a " + ExecutorConstants.PRIORITY_EXECUTOR);
        }

        // set the handler for calling before the message is put in to the queue
        OMAttribute handlerAtt = e.getAttribute(BEFORE_EXECUTE_HANDLER);
        if (handlerAtt != null) {
            BeforeExecuteHandler beh =
                    createExecuteBeforeHandler(handlerAtt.getAttributeValue());
            executor.setBeforeExecuteHandler(beh);
        }

        // create the queue configuration
        OMElement queuesEle = e.getFirstChildWithName(queuesQName);
        if (queuesEle != null) {
            OMAttribute nextQueueAtt = queuesEle.getAttribute(NEXT_QUEUE_ATT);

            NextQueueAlgorithm<Runnable> nqa = null;
            if (nextQueueAtt != null) {
                 nqa = createNextQueueAlgo(nextQueueAtt.getAttributeValue());
            }

            boolean isFixedSize = true;

            OMAttribute fixedSizeAtt = queuesEle.getAttribute(IS_FIXED_ATT);
            if (fixedSizeAtt != null) {
                isFixedSize = Boolean.parseBoolean(fixedSizeAtt.getAttributeValue());
            }

            // create the queue configuration
            List<InternalQueue<Runnable>> intQueues
                    = createQueues(queueQName, queuesEle, isFixedSize);

            MultiPriorityBlockingQueue<Runnable> queue =
                    new MultiPriorityBlockingQueue<Runnable>(intQueues, isFixedSize, nqa);

            executor.setQueue(queue);
        } else {
            handlerException("Queues configuration is mandatory");
        }

        OMElement threadsEle = e.getFirstChildWithName(threadsQName);
        if (threadsEle != null) {
            OMAttribute maxAttr = threadsEle.getAttribute(MAX_ATT);
            if (maxAttr != null) {
                executor.setMax(Integer.parseInt(maxAttr.getAttributeValue()));
            }
            OMAttribute coreAttr = threadsEle.getAttribute(CORE_ATT);
            if (coreAttr != null) {
                executor.setCore(Integer.parseInt(coreAttr.getAttributeValue()));
            }
            OMAttribute keepAliveAttr = threadsEle.getAttribute(KEEP_ALIVE_ATT);
            if (keepAliveAttr != null) {
                executor.setKeepAlive(Integer.parseInt(keepAliveAttr.getAttributeValue()));
            }
        }
               
        return executor;
    }
View Full Code Here

    private static final QName ATT_SINGLE = new QName("single");

    protected Mediator createSpecificMediator(OMElement elem, Properties properties) {

        RMSequenceMediator sequenceMediator = new RMSequenceMediator();
        OMAttribute correlation = elem.getAttribute(ATT_CORR);
        OMAttribute lastMessage = elem.getAttribute(ATT_LASTMSG);
        OMAttribute single = elem.getAttribute(ATT_SINGLE);
        OMAttribute version = elem.getAttribute(ATT_VERSION);

        if (single == null && correlation == null) {
            String msg = "The 'single' attribute value of true or a 'correlation' attribute is " +
                "required for the configuration of a RMSequence mediator";
            log.error(msg);
            throw new SynapseException(msg);
        }

        if (correlation != null) {
            if (correlation.getAttributeValue() != null &&
                correlation.getAttributeValue().trim().length() == 0) {
                String msg = "Invalid attribute value specified for correlation";
                log.error(msg);
                throw new SynapseException(msg);

            } else {
                try {
                    sequenceMediator.setCorrelation(
                        SynapseXPathFactory.getSynapseXPath(elem, ATT_CORR));
                } catch (JaxenException e) {
                    String msg = "Invalid XPath expression for attribute correlation : "
                        + correlation.getAttributeValue();
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        }

        if (single != null) {
            sequenceMediator.setSingle(Boolean.valueOf(single.getAttributeValue()));
        }

        if (sequenceMediator.isSingle() && sequenceMediator.getCorrelation() != null) {
            String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
                + "single attribute value of true and a correlation attribute specified.";
            log.error(msg);
            throw new SynapseException(msg);

        } else if (!sequenceMediator.isSingle() && sequenceMediator.getCorrelation() == null) {
            String msg = "Invalid RMSequence mediator. A RMSequence must have a "
                + "single attribute value of true or a correlation attribute specified.";
            log.error(msg);
            throw new SynapseException(msg);
        }

        if (lastMessage != null) {
            if (lastMessage.getAttributeValue() != null &&
                lastMessage.getAttributeValue().trim().length() == 0) {
                String msg = "Invalid attribute value specified for last-message";
                log.error(msg);
                throw new SynapseException(msg);

            } else {
                try {
                    sequenceMediator.setLastMessage(
                        SynapseXPathFactory.getSynapseXPath(elem, ATT_LASTMSG));
                } catch (JaxenException e) {
                    String msg = "Invalid XPath expression for attribute last-message : "
                        + lastMessage.getAttributeValue();
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            }
        }

        if (sequenceMediator.isSingle() && sequenceMediator.getLastMessage() != null) {
            String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
                + "single attribute value of true and a last-message attribute specified.";
            log.error(msg);
            throw new SynapseException(msg);
        }

        if (version != null) {
            if (!XMLConfigConstants.SEQUENCE_VERSION_1_0.equals(version.getAttributeValue()) &&
                !XMLConfigConstants.SEQUENCE_VERSION_1_1.equals(version.getAttributeValue())) {
                String msg = "Only '" + XMLConfigConstants.SEQUENCE_VERSION_1_0 + "' or '" +
                    XMLConfigConstants.SEQUENCE_VERSION_1_1
                    + "' values are allowed for attribute version for a RMSequence mediator"
                    + ", Unsupported version " + version.getAttributeValue();
                log.error(msg);
                throw new SynapseException(msg);
            }
            sequenceMediator.setVersion(version.getAttributeValue());
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(sequenceMediator, elem);
View Full Code Here

    private static final QName ATT_ACTION = new QName("action");

    protected Mediator createSpecificMediator(OMElement elem, Properties properties) {

        HeaderMediator headerMediator = new HeaderMediator();
        OMAttribute name   = elem.getAttribute(ATT_NAME);
        OMAttribute value  = elem.getAttribute(ATT_VALUE);
        OMAttribute exprn  = elem.getAttribute(ATT_EXPRN);
        OMAttribute action = elem.getAttribute(ATT_ACTION);

        if (name == null || name.getAttributeValue() == null) {
            String msg = "A valid name attribute is required for the header mediator";
            log.error(msg);
            throw new SynapseException(msg);
        } else {
            String nameAtt = name.getAttributeValue();
            int colonPos = nameAtt.indexOf(":");
            if (colonPos != -1) {
                // has a NS prefix.. find it and the NS it maps into
                String prefix = nameAtt.substring(0, colonPos);
                String namespaceURI = OMElementUtils.getNameSpaceWithPrefix(prefix, elem);
                if (namespaceURI == null) {
                    handleException("Invalid namespace prefix '" + prefix + "' in name attribute");
                } else {
                  headerMediator.setQName(new QName(namespaceURI, nameAtt.substring(colonPos+1),
                            prefix));
                }
            } else {
                // no prefix
                if (SynapseConstants.HEADER_TO.equals(nameAtt) ||
                        SynapseConstants.HEADER_FROM.equals(nameAtt) ||
                        SynapseConstants.HEADER_ACTION.equals(nameAtt) ||
                        SynapseConstants.HEADER_FAULT.equals(nameAtt) ||
                        SynapseConstants.HEADER_REPLY_TO.equals(nameAtt) ||
                        SynapseConstants.HEADER_RELATES_TO.equals(nameAtt)) {

                    headerMediator.setQName(new QName(nameAtt));
                } else {
                    handleException("Invalid SOAP header: " + nameAtt + " specified at the " +
                            "header mediator. All SOAP headers must be namespace qualified.");
                }
            }
        }

        // after successfully creating the mediator
        // set its common attributes such as tracing etc
        processAuditStatus(headerMediator,elem);

        // The action attribute is optional, if provided and equals to 'remove' the
        // header mediator will act as a header remove mediator
        if (action != null && "remove".equals(action.getAttributeValue())) {
            headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
        }

        if (headerMediator.getAction() == HeaderMediator.ACTION_SET &&
            value == null && exprn == null) {
View Full Code Here

                "Unexpected element as the cache mediator configuration");
        }

        CacheMediator cache = new CacheMediator();

        OMAttribute idAttr = elem.getAttribute(ATT_ID);
        if (idAttr != null && idAttr.getAttributeValue() != null) {
            cache.setId(idAttr.getAttributeValue());
        }

        OMAttribute scopeAttr = elem.getAttribute(ATT_SCOPE);
        if (scopeAttr != null && scopeAttr.getAttributeValue() != null &&
            isValidScope(scopeAttr.getAttributeValue(), cache.getId())) {
            cache.setScope(scopeAttr.getAttributeValue());
        } else {
            cache.setScope(CachingConstants.SCOPE_PER_HOST);
        }

        OMAttribute collectorAttr = elem.getAttribute(ATT_COLLECTOR);
        if (collectorAttr != null && collectorAttr.getAttributeValue() != null &&
            "true".equals(collectorAttr.getAttributeValue())) {

            cache.setCollector(true);
        } else {
           
            cache.setCollector(false);

            OMAttribute hashGeneratorAttr = elem.getAttribute(ATT_HASH_GENERATOR);
            if (hashGeneratorAttr != null && hashGeneratorAttr.getAttributeValue() != null) {
                try {
                    Class generator = Class.forName(hashGeneratorAttr.getAttributeValue());
                    Object o = generator.newInstance();
                    if (o instanceof DigestGenerator) {
                        cache.setDigestGenerator((DigestGenerator) o);
                    } else {
                        handleException("Specified class for the hashGenerator is not a " +
                            "DigestGenerator. It *must* implement " +
                            "org.wso2.caching.digest.DigestGenerator interface");
                    }
                } catch (ClassNotFoundException e) {
                    handleException("Unable to load the hash generator class", e);
                } catch (IllegalAccessException e) {
                    handleException("Unable to access the hash generator class", e);
                } catch (InstantiationException e) {
                    handleException("Unable to instantiate the hash generator class", e);
                }
            }

            OMAttribute timeoutAttr = elem.getAttribute(ATT_TIMEOUT);
            if (timeoutAttr != null && timeoutAttr.getAttributeValue() != null) {
                cache.setTimeout(Long.parseLong(timeoutAttr.getAttributeValue()));
            } else {
                cache.setTimeout(DEFAULT_TIMEOUT);
            }

            OMAttribute maxMessageSizeAttr = elem.getAttribute(ATT_MAX_MSG_SIZE);
            if (maxMessageSizeAttr != null && maxMessageSizeAttr.getAttributeValue() != null) {
                cache.setMaxMessageSize(Integer.parseInt(maxMessageSizeAttr.getAttributeValue()));
            }

            OMElement onCacheHitElem = elem.getFirstChildWithName(ON_CACHE_HIT_Q);
            if (onCacheHitElem != null) {
                OMAttribute sequenceAttr = onCacheHitElem.getAttribute(ATT_SEQUENCE);
                if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
                    cache.setOnCacheHitRef(sequenceAttr.getAttributeValue());
                } else if (onCacheHitElem.getFirstElement() != null) {
                    cache.setOnCacheHitSequence(new SequenceMediatorFactory()
                            .createAnonymousSequence(onCacheHitElem, properties));
                }
            }

            for (Iterator itr = elem.getChildrenWithName(IMPLEMENTATION_Q); itr.hasNext();) {
                OMElement implElem = (OMElement) itr.next();
                OMAttribute typeAttr = implElem.getAttribute(ATT_TYPE);
                OMAttribute sizeAttr = implElem.getAttribute(ATT_SIZE);
                if (typeAttr != null && typeAttr.getAttributeValue() != null) {
                    String type = typeAttr.getAttributeValue();
                    if (CachingConstants.TYPE_MEMORY.equals(type) && sizeAttr != null &&
                        sizeAttr.getAttributeValue() != null) {
                        cache.setInMemoryCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                    } else if (CachingConstants.TYPE_DISK.equals(type)) {
                        log.warn("Disk based and hirearchycal caching is not implemented yet");
                        if (sizeAttr != null && sizeAttr.getAttributeValue() != null) {
                            cache.setDiskCacheSize(Integer.parseInt(sizeAttr.getAttributeValue()));
                        } else {
                            cache.setDiskCacheSize(DEFAULT_DISK_CACHE_SIZE);
                        }
                    } else {
                        handleException("unknown implementation type for the Cache mediator");
View Full Code Here

            // elements are found, the method returns null.
            if (resourceMap == null) {
                resourceMap = new ResourceMap();
            }
            OMElement resourceElem = (OMElement)it.next();
            OMAttribute location = resourceElem.getAttribute
                (new QName(XMLConfigConstants.NULL_NAMESPACE, "location"));
            if (location == null) {
                handleException("The 'location' attribute is required for a resource definition");
            }
            OMAttribute key = resourceElem.getAttribute(
                new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
            if (key == null) {
                handleException("The 'key' attribute is required for a resource definition");
            }
            resourceMap.addResource(location.getAttributeValue(), key.getAttributeValue());
        }
        return resourceMap;
    }
View Full Code Here

    protected Mediator createSpecificMediator(OMElement omElement, Properties properties) {

        SamplingThrottleMediator samplingThrottleMediator = new SamplingThrottleMediator();
        processAuditStatus(samplingThrottleMediator, omElement);

        OMAttribute idAttribute = omElement.getAttribute(ID_ATTR);
        if (idAttribute != null) {
            samplingThrottleMediator.setId(idAttribute.getAttributeValue());
        }

        OMAttribute rateAttribute = omElement.getAttribute(RATE_ATTR);
        if (rateAttribute != null) {
            try {
                samplingThrottleMediator.setSamplingRate(
                        Integer.parseInt(rateAttribute.getAttributeValue()));
            } catch (NumberFormatException nfe) {
                handleException("Sampling rate has to be an integer value, but found : "
                        + rateAttribute.getAttributeValue());
            }
        }

        OMAttribute unitTimeAttribute = omElement.getAttribute(UNIT_TIME_ATTR);
        if (unitTimeAttribute != null) {
            try {
                samplingThrottleMediator.setUnitTime(
                        Long.parseLong(unitTimeAttribute.getAttributeValue()));
            } catch (NumberFormatException nfe) {
                handleException("Sampling unitTime has to be a long value in milliseconds, " +
                        "but found : " + rateAttribute.getAttributeValue());
            }
        }
View Full Code Here

       
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMElement orgRoot = factory.createOMElement(new QName("root"));
        OMElement orgElement = factory.createOMElement(new QName("urn:mynamespace", "element1"));
        orgElement.setText("test");
        OMAttribute orgAttribute = orgElement.addAttribute("att", "testValue", null);
        orgRoot.addChild(orgElement);
       
        mc.getEnvelope().getBody().addChild(orgRoot);
       
        transformMediator.addAttribute(XSLTMediator.SOURCE_BUILDER_FACTORY, sbf.getName());
        transformMediator.addAttribute(XSLTMediator.RESULT_BUILDER_FACTORY, rbf.getName());
       
        transformMediator.mediate(mc);
       
        OMElement root = mc.getEnvelope().getBody().getFirstElement();
        assertEquals(orgRoot.getQName(), root.getQName());
        OMElement element = (OMElement)root.getFirstOMChild();
        assertEquals(orgElement.getQName(), element.getQName());
        assertEquals(orgElement.getText(), element.getText());
        assertEquals(orgAttribute, orgElement.getAttribute(orgAttribute.getQName()));
        assertNull(element.getNextOMSibling());
    }
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMAttribute

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.