/*
* 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.apache.axis2.util.JavaUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.cep.core.exception.CEPConfigurationException;
import org.wso2.carbon.cep.core.internal.util.CEPConstants;
import org.wso2.carbon.cep.core.backend.CEPEngineProvider;
import javax.xml.namespace.QName;
/**
* This Class is used to create and load the CEP Engine provider from a given OM Element
*/
public class CEPEngineProviderHelper {
private static final Log log = LogFactory.getLog(CEPEngineProviderHelper.class);
public static CEPEngineProvider fromOM(OMElement cepEngineProviderElement)
throws CEPConfigurationException {
CEPEngineProvider cepEngineProvider = new CEPEngineProvider();
String name =
cepEngineProviderElement.getAttributeValue(
new QName(CEPConstants.CEP_CONF_ATTR_NAME));
if (name == null) {
String errorMessage = "Provider name is not given in the cep config";
log.error(errorMessage);
throw new CEPConfigurationException(errorMessage);
}
cepEngineProvider.setName(name);
String providerClassName =
cepEngineProviderElement.getAttributeValue(
new QName(CEPConstants.CEP_CONF_ATTR_CLASS));
if (providerClassName == null) {
String errorMessage = "Provider class is not given in the cep config";
log.error(errorMessage);
throw new CEPConfigurationException(errorMessage);
}
// here we assume cep provider should have given as a fragment host for this bundle
// TODO: is it necessary to publish provider as an OSGI service
try {
Class providerClass = Class.forName(providerClassName);
cepEngineProvider.setProviderClass(providerClass);
return cepEngineProvider;
} catch (ClassNotFoundException e) {
String errorMessage = "Can not load the " + providerClassName;
log.error(errorMessage);
throw new CEPConfigurationException(errorMessage, e);
}
}
}