Package org.wso2.carbon.cep.core.internal.config

Source Code of org.wso2.carbon.cep.core.internal.config.BucketHelper

/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wso2.carbon.cep.core.internal.config;

import org.apache.axiom.om.OMElement;
import org.wso2.carbon.cep.core.Bucket;
import org.wso2.carbon.cep.core.internal.util.CEPConstants;
import org.wso2.carbon.cep.core.exception.CEPConfigurationException;

import javax.xml.namespace.QName;
import java.util.Iterator;

/**
* this class is used to parse the top level bucket attributes
*/

public class BucketHelper {

    public static Bucket fromOM(OMElement bucketElement) throws CEPConfigurationException {

        Bucket bucket = new Bucket();

        String name =
                bucketElement.getAttributeValue(new QName(CEPConstants.CEP_CONF_ATTR_NAME));
        bucket.setName(name);

        OMElement descriptionElement =
                bucketElement.getFirstChildWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
                        CEPConstants.CEP_CONF_ELE_DESCRIPTION));
        if (descriptionElement != null) {
            bucket.setDescription(descriptionElement.getText());
        }

        String engineProvider =
                bucketElement.getAttributeValue(
                        new QName(CEPConstants.CEP_CONF_ATTR_ENGINE_PROVIDER));
        bucket.setEngineProvider(engineProvider);


        OMElement inputOmElement = null;
        for (Iterator iter = bucketElement.getChildrenWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
                CEPConstants.CEP_CONF_ELE_INPUT)); iter.hasNext();) {
            inputOmElement = (OMElement) iter.next();
            bucket.addInput(InputHelper.fromOM(inputOmElement));
        }


        OMElement queryOmElement = null;
        for (Iterator iterator = bucketElement.getChildrenWithName(new QName(CEPConstants.CEP_CONF_NAMESPACE,
                CEPConstants.CEP_CONF_ELE_QUERY)); iterator.hasNext();) {
            queryOmElement = (OMElement) iterator.next();
            bucket.addQuery(QueryHelper.fromOM(queryOmElement));

        }


        return bucket;

    }

}
TOP

Related Classes of org.wso2.carbon.cep.core.internal.config.BucketHelper

TOP
Copyright © 2018 www.massapi.com. 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.