[Carbon-dev] svn commit r42518 - in trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core: service templateregister
ajithv at wso2.com
ajithv at wso2.com
Mon Aug 3 23:26:17 PDT 2009
Author: ajithv
Date: Mon Aug 3 23:26:17 2009
New Revision: 42518
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=42518
Log:
reportTemplate.xml file put to registry
Added:
trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/service/
trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/service/ReportingComponentConstant.java
trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/templateregister/
trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/templateregister/ReportTemplateRegister.java
Added: trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/service/ReportingComponentConstant.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/service/ReportingComponentConstant.java?pathrev=42518
==============================================================================
--- (empty file)
+++ trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/service/ReportingComponentConstant.java Mon Aug 3 23:26:17 2009
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.reporting.core.service;
+
+import org.wso2.carbon.core.RegistryResources;
+
+
+public class ReportingComponentConstant {
+
+ public static final String REPORT_TEMPLATE_URI = RegistryResources.MODULES + "wso2reporting/templates/";
+
+ public static final String GLOBAL_LEVEL = "global";
+ public static final String SERVICE_LEVEL = "service";
+ public static final String OPERATION_LEVEL = "operation";
+ public static final String MEDIATION_LEVEL = "mediator";
+}
Added: trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/templateregister/ReportTemplateRegister.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/templateregister/ReportTemplateRegister.java?pathrev=42518
==============================================================================
--- (empty file)
+++ trunk/carbon-components/reporting/org.wso2.carbon.reporting.core/src/main/java/org/wso2/carbon/reporting/core/templateregister/ReportTemplateRegister.java Mon Aug 3 23:26:17 2009
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * 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.reporting.core.templateregister;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.Registry;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.reporting.core.service.ReportingComponentConstant;
+import org.wso2.carbon.reporting.core.ReportXmlFinder;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.framework.BundleContext;
+
+import java.io.IOException;
+
+/**
+ * @scr.component name="reporting.services" immediate="true"
+ * @scr.reference name="registry.service" interface="org.wso2.carbon.registry.core.service.RegistryService"
+ * cardinality="1..1" policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
+ */
+
+public class ReportTemplateRegister {
+ public static ReportXmlFinder reportXmlFinder = null;
+ private static Log log = LogFactory.getLog(ReportTemplateRegister.class);
+ private static RegistryService registryServiceInstance;
+
+
+ protected void activate(ComponentContext ctxt) {
+ try {
+ BundleContext bundleContext = ctxt.getBundleContext();
+ reportXmlFinder = new ReportXmlFinder(bundleContext);
+ log.info("reporting component activated");
+
+ //save reportTemplate.xml file
+ saveReportTemplate(bundleContext);
+
+ } catch (Throwable e) {
+ log.error("reportTemplate activation process failed ", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext ctxt) {
+ log.debug("reportTemplate deactivated");
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+
+ registryServiceInstance = registryService;
+
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ registryServiceInstance = null;
+ }
+
+
+ public static RegistryService getRegistryService() throws Exception {
+ if (registryServiceInstance == null) {
+
+ throw new Exception();
+
+ }
+ return registryServiceInstance;
+ }
+
+
+ /**
+ * Save the reportTemplate in the registry. These will be used to
+ * generate the report file by the user
+ * @param bundleContext execution context of the reporting bundle
+ * @throws java.io.IOException
+ * @throws org.wso2.carbon.registry.core.exceptions.RegistryException
+ *
+ */
+ private void saveReportTemplate(BundleContext bundleContext) throws RegistryException, IOException {
+ //Get the registry from the registry service
+ Registry registry;
+ if (registryServiceInstance != null) {
+ registry = registryServiceInstance.getSystemRegistry();
+ } else {
+ log.error("failed reportTemplate save process");
+ return;
+ }
+
+ try {
+ registry.beginTransaction();
+ Resource reportTemplateService = registry.newResource();
+ reportTemplateService.setContentStream(bundleContext.getBundle().getResource("reportTemplate.xml").openStream());
+ registry.put(ReportingComponentConstant.REPORT_TEMPLATE_URI, reportTemplateService);
+ registry.commitTransaction();
+ } catch (Exception e) {
+ registry.rollbackTransaction();
+ String msg = "failed to save template";
+ log.error(msg, e);
+ }
+ }
+}
More information about the Carbon-dev
mailing list