Hi Sameera,

Attached here with is the reviewed diff file and in [1] is the relevant
pull request for the carban4-kernel

[1] - https://github.com/wso2-dev/carbon4-kernel/pull/103

Thanks

On Fri, Sep 12, 2014 at 3:04 PM, Anjana Fernando <anj...@wso2.com> wrote:

> Hi Sameera,
>
> Sure. I reviewed an earlier version of the code, then I told to do some
> changes. Will check the latest changes.
>
> Cheers,
> Anjana.
>
> On Fri, Sep 12, 2014 at 2:58 PM, Sameera Jayasoma <same...@wso2.com>
> wrote:
>
>> Thanks Manoj.
>>
>> Anjana, Can you please review this pull request?
>>
>> Thanks,
>> Sameera.
>>
>> On Thu, Sep 11, 2014 at 9:22 PM, Manoj Kumara <ma...@wso2.com> wrote:
>>
>>> Hi Team,
>>>
>>> Hence this is a new feature this has some API additions. Please review
>>> this and commit.
>>>
>>> Thanks
>>> Manoj
>>>
>>>
>>> *Manoj Kumara*
>>> Software Engineer
>>> WSO2 Inc. http://wso2.com/
>>> *lean.enterprise.middleware*
>>> Mobile: +94713448188
>>>
>>> On Thu, Sep 11, 2014 at 3:17 AM, Rajith Vitharana <raji...@wso2.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> please find the pull request for the carbon4-kernal git repository for
>>>> above changes in [1]
>>>>
>>>> [1] - https://github.com/wso2-dev/carbon4-kernel/pull/95
>>>>
>>>> Thanks,
>>>>
>>>> On Tue, Jul 29, 2014 at 6:12 PM, Rajith Vitharana <raji...@wso2.com>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have attached the new diff file for the data source deployer
>>>>> feature. I have added the password encryption support so the datasource 
>>>>> xml
>>>>> files can have encrypted passwords. Sample car file is also attached here
>>>>> with. Please review and commit.
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> On Mon, Jul 28, 2014 at 11:48 AM, Rajith Vitharana <raji...@wso2.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Jasintha,Sohani,
>>>>>>
>>>>>> Thanks for the quick response. The "type" defined in "artifact.xml"
>>>>>> should be "datasource/datasource" for it to be picked up by the 
>>>>>> datasource
>>>>>> deployment handler and get deployed. Below is a sample
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <artifact name="DataSourceA" version="1.0.0"
>>>>>> type="datasource/datasource" serverRole="ApplicationServer">
>>>>>>     <file>DataSource.xml</file>
>>>>>> </artifact>
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>>
>>>>>> On Mon, Jul 28, 2014 at 11:37 AM, Sohani Weerasinghe <soh...@wso2.com
>>>>>> > wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am working on implementing the Datasource editor in DevS.
>>>>>>>
>>>>>>>  Thanks,
>>>>>>> Sohani
>>>>>>>
>>>>>>> Sohani Weerasinghe
>>>>>>> Software Engineer
>>>>>>> WSO2, Inc: http://wso2.com
>>>>>>>
>>>>>>> Mobile  : +94 716439774
>>>>>>> Blog     :http://christinetechtips.blogspot.com/
>>>>>>> Twitter  : https://twitter.com/sohanichristine
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jul 28, 2014 at 11:04 AM, Jasintha Dasanayake <
>>>>>>> jasin...@wso2.com> wrote:
>>>>>>>
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> We can provide a single page form editor in DevS to edit this config
>>>>>>>>
>>>>>>>> Thanks and regards
>>>>>>>> /Jasintha
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Jul 28, 2014 at 10:36 AM, Rajith Vitharana <
>>>>>>>> raji...@wso2.com> wrote:
>>>>>>>>
>>>>>>>>> Hi Kasun,
>>>>>>>>>
>>>>>>>>> Yes these datasources only provides a read-only view. and they
>>>>>>>>> won't be saved in the registry. other than that they are same as the
>>>>>>>>> datasources which we can create using UI.
>>>>>>>>>
>>>>>>>>> Hi Nirmal,
>>>>>>>>>
>>>>>>>>> noted. I'll try out encryption of passwords and to get DevS support
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, Jul 28, 2014 at 10:28 AM, Nirmal Fernando <nir...@wso2.com
>>>>>>>>> > wrote:
>>>>>>>>>
>>>>>>>>>> Thanks Rajith. Seems like for this feature, we need DevS support
>>>>>>>>>> (data source resource type) before deployed in a production 
>>>>>>>>>> environment.
>>>>>>>>>> Also, this feature should ideally support encryption of passwords.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Jul 28, 2014 at 10:21 AM, Rajith Vitharana <
>>>>>>>>>> raji...@wso2.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi Nirmal,
>>>>>>>>>>>
>>>>>>>>>>> This is a Appdeployment handler which will pickup datasources
>>>>>>>>>>> deployed as carbon application and register them as datasources.
>>>>>>>>>>> since datasource xml file is already in car app this feature
>>>>>>>>>>> wont save it to the registry to avoid duplication.
>>>>>>>>>>> datasources deployed as car apps can't be edited using UI.
>>>>>>>>>>> Editing them should be done by redeploying the car app.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, Jul 28, 2014 at 9:49 AM, Nirmal Fernando <
>>>>>>>>>>> nir...@wso2.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi Rajith,
>>>>>>>>>>>>
>>>>>>>>>>>> Can you please also mention what new improvements this patch
>>>>>>>>>>>> brings?
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Mon, Jul 28, 2014 at 9:39 AM, Rajith Vitharana <
>>>>>>>>>>>> raji...@wso2.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Attached here with the diff for datasource deployer feature
>>>>>>>>>>>>> for org.wso2.carbon.ndatasource.core and a sample car file. 
>>>>>>>>>>>>> please review
>>>>>>>>>>>>> and commit
>>>>>>>>>>>>>
>>>>>>>>>>>>> Thanks,
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> Rajith Vitharana
>>>>>>>>>>>>>
>>>>>>>>>>>>> Software Engineer,
>>>>>>>>>>>>> WSO2 Inc. : wso2.com
>>>>>>>>>>>>> Mobile : +94715883223
>>>>>>>>>>>>> Blog : http://lankavitharana.blogspot.com/
>>>>>>>>>>>>>
>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>> Dev mailing list
>>>>>>>>>>>>> Dev@wso2.org
>>>>>>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks & regards,
>>>>>>>>>>>> Nirmal
>>>>>>>>>>>>
>>>>>>>>>>>> Senior Software Engineer- Platform Technologies Team, WSO2 Inc.
>>>>>>>>>>>> Mobile: +94715779733
>>>>>>>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Rajith Vitharana
>>>>>>>>>>>
>>>>>>>>>>> Software Engineer,
>>>>>>>>>>> WSO2 Inc. : wso2.com
>>>>>>>>>>> Mobile : +94715883223
>>>>>>>>>>> Blog : http://lankavitharana.blogspot.com/
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>> Thanks & regards,
>>>>>>>>>> Nirmal
>>>>>>>>>>
>>>>>>>>>> Senior Software Engineer- Platform Technologies Team, WSO2 Inc.
>>>>>>>>>> Mobile: +94715779733
>>>>>>>>>> Blog: http://nirmalfdo.blogspot.com/
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Rajith Vitharana
>>>>>>>>>
>>>>>>>>> Software Engineer,
>>>>>>>>> WSO2 Inc. : wso2.com
>>>>>>>>> Mobile : +94715883223
>>>>>>>>> Blog : http://lankavitharana.blogspot.com/
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>
>>>>>>>> *Jasintha Dasanayake *
>>>>>>>>
>>>>>>>> *Senior Software EngineerWSO2 Inc. | http://wso2.com
>>>>>>>> <http://wso2.com/> lean . enterprise . middleware*
>>>>>>>>
>>>>>>>>
>>>>>>>> *mobile :- 0711368118 <0711368118> *
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Dev mailing list
>>>>>>>> Dev@wso2.org
>>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Rajith Vitharana
>>>>>>
>>>>>> Software Engineer,
>>>>>> WSO2 Inc. : wso2.com
>>>>>> Mobile : +94715883223
>>>>>> Blog : http://lankavitharana.blogspot.com/
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Rajith Vitharana
>>>>>
>>>>> Software Engineer,
>>>>> WSO2 Inc. : wso2.com
>>>>> Mobile : +94715883223
>>>>> Blog : http://lankavitharana.blogspot.com/
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Rajith Vitharana
>>>>
>>>> Software Engineer,
>>>> WSO2 Inc. : wso2.com
>>>> Mobile : +94715883223
>>>> Blog : http://lankavitharana.blogspot.com/
>>>>
>>>
>>>
>>
>>
>> --
>> Sameera Jayasoma,
>> Software Architect,
>>
>> WSO2, Inc. (http://wso2.com)
>> email: same...@wso2.com
>> blog: http://sameera.adahas.org
>> twitter: https://twitter.com/sameerajayasoma
>> flickr: http://www.flickr.com/photos/sameera-jayasoma/collections
>> Mobile: 0094776364456
>>
>> Lean . Enterprise . Middleware
>>
>>
>
>
> --
> *Anjana Fernando*
> Senior Technical Lead
> WSO2 Inc. | http://wso2.com
> lean . enterprise . middleware
>



-- 
Rajith Vitharana

Software Engineer,
WSO2 Inc. : wso2.com
Mobile : +94715883223
Blog : http://lankavitharana.blogspot.com/
Index: pom.xml
===================================================================
--- pom.xml     (revision 207035)
+++ pom.xml     (working copy)
@@ -33,6 +33,11 @@
     <dependencies>
         <dependency>
             <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.application.deployer</artifactId>
+            <version>${carbon.platform.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
             <artifactId>org.wso2.carbon.utils</artifactId>
             <version>4.2.0</version>
         </dependency>
@@ -74,6 +79,7 @@
                         </Export-Package>
                         <DynamicImport-Package>*</DynamicImport-Package>
                         <DeployBefore>UserCore</DeployBefore>
+                        <WSO2-Application-Deployer>Data Source Capp 
Deployer</WSO2-Application-Deployer>
                     </instructions>
                 </configuration>
             </plugin>
Index: src/main/java/org/wso2/carbon/ndatasource/core/DataSourceMetaInfo.java
===================================================================
--- src/main/java/org/wso2/carbon/ndatasource/core/DataSourceMetaInfo.java      
(revision 207035)
+++ src/main/java/org/wso2/carbon/ndatasource/core/DataSourceMetaInfo.java      
(working copy)
@@ -43,6 +43,9 @@
        @XmlTransient
        private boolean system;
 
+    @XmlTransient
+    private boolean carbonApplicationDeployed;
+
        public void setName(String name) {
                this.name = name;
        }
@@ -59,6 +62,10 @@
                this.system = system;
        }
 
+    public void setCarbonApplicationDeployed(boolean 
carbonApplicationDeployed) {
+        this.carbonApplicationDeployed = carbonApplicationDeployed;
+    }
+
        @XmlElement (name = "name", required = true, nillable = false)
        public String getName() {
                return name;
@@ -79,6 +86,11 @@
                return system;
        }
 
+    @XmlTransient
+    public boolean isCarbonApplicationDeployed() {
+        return  carbonApplicationDeployed;
+    }
+
        @XmlElement (name = "definition", required = true, nillable = false)
        public DataSourceDefinition getDefinition() {
                return definition;
@@ -88,7 +100,12 @@
                this.definition = definition;
        }
 
-       @XmlRootElement (name = "definition")
+    @XmlTransient
+    public boolean isPersistable() {
+        return (!system && !carbonApplicationDeployed);
+    }
+
+    @XmlRootElement (name = "definition")
        public static class DataSourceDefinition {
                
                private String type;
@@ -112,7 +129,7 @@
                public void setDsXMLConfiguration(Object dsXMLConfiguration) {
                        this.dsXMLConfiguration = dsXMLConfiguration;
                }
-               
+
                public boolean equals(Object rhs) {
                        if (!(rhs instanceof DataSourceDefinition)) {
                                return false;
Index: src/main/java/org/wso2/carbon/ndatasource/core/DataSourceRepository.java
===================================================================
--- src/main/java/org/wso2/carbon/ndatasource/core/DataSourceRepository.java    
(revision 207035)
+++ src/main/java/org/wso2/carbon/ndatasource/core/DataSourceRepository.java    
(working copy)
@@ -467,11 +467,11 @@
                if (log.isDebugEnabled()) {
                        log.debug("Adding data source: " + dsmInfo.getName());
                }
-               if (!dsmInfo.isSystem()) {
+               if (dsmInfo.isPersistable()) {
                    this.persistDataSource(dsmInfo);
                }
                this.registerDataSource(dsmInfo);
-               if (!dsmInfo.isSystem()) {
+               if (dsmInfo.isPersistable()) {
                    this.notifyClusterDSChange(dsmInfo.getName());
                }
        }
@@ -491,10 +491,12 @@
                if (cds.getDSMInfo().isSystem()) {
                        throw new DataSourceException("System data sources 
cannot be deleted: " + dsName);
                }
-               this.removePersistedDataSource(dsName);
-               this.unregisterDataSource(dsName);
-               this.notifyClusterDSChange(dsName);
-       }
+        this.unregisterDataSource(dsName);
+        if (cds.getDSMInfo().isPersistable()) {
+            this.removePersistedDataSource(dsName);
+            this.notifyClusterDSChange(dsName);
+        }
+    }
        
        /**
         * Tests Connection of the data source
Index: 
src/main/java/org/wso2/carbon/ndatasource/core/deployer/DataSourceDeployer.java
===================================================================
--- 
src/main/java/org/wso2/carbon/ndatasource/core/deployer/DataSourceDeployer.java 
    (revision 0)
+++ 
src/main/java/org/wso2/carbon/ndatasource/core/deployer/DataSourceDeployer.java 
    (working copy)
@@ -0,0 +1,162 @@
+/*
+*  Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights 
Reserved.
+*
+*  WSO2 Inc. licenses this file to you 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.ndatasource.core.deployer;
+
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.w3c.dom.Document;
+import org.wso2.carbon.application.deployer.CarbonApplication;
+import org.wso2.carbon.application.deployer.config.ApplicationConfiguration;
+import org.wso2.carbon.application.deployer.config.Artifact;
+import org.wso2.carbon.application.deployer.config.CappFile;
+import org.wso2.carbon.application.deployer.handler.AppDeploymentHandler;
+import org.wso2.carbon.ndatasource.common.DataSourceException;
+import org.wso2.carbon.ndatasource.core.DataSourceManager;
+import org.wso2.carbon.ndatasource.core.DataSourceMetaInfo;
+import org.wso2.carbon.ndatasource.core.utils.DataSourceUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class is the implementation of the data source deployer which will 
deploy data sources to the server.
+ */
+public class DataSourceDeployer implements AppDeploymentHandler {
+
+    public static final String DATA_SOURCE_TYPE = "datasource/datasource";
+
+    /**
+     * Deploy the data source artifacts and add them to datasources.
+     *
+     * @param carbonApp  - store info in this object after deploying
+     * @param axisConfig - AxisConfiguration of the current tenant
+     */
+    @Override
+    public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration 
axisConfig) throws DeploymentException {
+        ApplicationConfiguration appConfig = carbonApp.getAppConfig();
+        List<Artifact.Dependency> deps = 
appConfig.getApplicationArtifact().getDependencies();
+
+        List<Artifact> artifacts = new ArrayList<Artifact>();
+        for (Artifact.Dependency dep : deps) {
+            if (dep.getArtifact() != null) {
+                artifacts.add(dep.getArtifact());
+            }
+        }
+        deployUnDeployDataSources(true, artifacts);
+    }
+
+    /**
+     * undeploy the data sources and remove them from datasources
+     *
+     * @param carbonApp  - all information about the existing artifacts are in 
this instance
+     * @param axisConfig - AxisConfiguration of the current tenant
+     */
+    @Override
+    public void undeployArtifacts(CarbonApplication carbonApp, 
AxisConfiguration axisConfig) throws DeploymentException {
+        ApplicationConfiguration appConfig = carbonApp.getAppConfig();
+        List<Artifact.Dependency> deps = 
appConfig.getApplicationArtifact().getDependencies();
+
+        List<Artifact> artifacts = new ArrayList<Artifact>();
+        for (Artifact.Dependency dep : deps) {
+            if (dep.getArtifact() != null) {
+                artifacts.add(dep.getArtifact());
+            }
+        }
+        deployUnDeployDataSources(false, artifacts);
+    }
+
+    /**
+     * deploy or undeploy data sources. if deploying, adding the data source 
to the data sources and if undeploying,
+     * removing the data source from data sources. there can be multiple data 
sources as separate xml files.
+     *
+     * @param deploy    identify whether deployment process or undeployment 
process.
+     * @param artifacts - list of artifacts to be deployed.
+     */
+    private void deployUnDeployDataSources(boolean deploy, List<Artifact> 
artifacts) throws DeploymentException {
+        for (Artifact artifact : artifacts) {
+            if (DATA_SOURCE_TYPE.equals(artifact.getType())) {
+                List<CappFile> files = artifact.getFiles();
+                if (files == null || files.isEmpty()) {
+                    throw new DeploymentException("Error No data sources found 
in the artifact to deploy");
+                }
+                for (CappFile cappFile : files) {
+                    String fileName = cappFile.getName();
+                    String dataSourceConfigPath = artifact.getExtractedPath() +
+                            File.separator + fileName;
+
+                    File file = new File(dataSourceConfigPath);
+                    if (!file.exists()) {
+                        throw new DeploymentException("Error Data source file 
cannot be found in artifact, file name - " + fileName);
+                    }
+                    DataSourceMetaInfo dataSourceMetaInfo = 
readDataSourceFile(file);
+                    if (deploy) {
+                        try {
+                            
dataSourceMetaInfo.setCarbonApplicationDeployed(true);
+                            
DataSourceManager.getInstance().getDataSourceRepository().addDataSource(dataSourceMetaInfo);
+                        } catch (DataSourceException e) {
+                            throw new DeploymentException("Error in deploying 
data source: " + e.getMessage(), e);
+                        }
+                    } else {
+                        try {
+                            
DataSourceManager.getInstance().getDataSourceRepository().deleteDataSource(dataSourceMetaInfo.getName());
+                        } catch (DataSourceException e) {
+                            throw new DeploymentException("Error in 
undeploying data source: " + e.getMessage(), e);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * method to read data source file and create the object from it.
+     *
+     * @param file - xml file
+     * @return dataSourceMetaInfo object which is created using the xml file.
+     * @throws org.apache.axis2.deployment.DeploymentException
+     */
+    private DataSourceMetaInfo readDataSourceFile(File file) throws 
DeploymentException {
+        try {
+            InputStream in = new FileInputStream(file);
+            Document doc = DataSourceUtils.convertToDocument(in);
+            /* only super tenant will lookup secure vault information for 
system data sources,
+             * others are not allowed to */
+            DataSourceUtils.secureResolveDocument(doc, false);
+            // create JAXB context and initializing Marshaller
+            JAXBContext jaxbContext = 
JAXBContext.newInstance(DataSourceMetaInfo.class);
+            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+            // this will create Java object - data source from xml file
+            DataSourceMetaInfo dataSourceMetaInfo = (DataSourceMetaInfo) 
jaxbUnmarshaller.unmarshal(doc);
+            return dataSourceMetaInfo;
+        } catch (JAXBException e) {
+            throw new DeploymentException("Error in reading data source file: 
" + e.getMessage(), e);
+        } catch (FileNotFoundException e) {
+            throw new DeploymentException("Error data source file not found: " 
+ e.getMessage(), e);
+        } catch (DataSourceException e) {
+            throw new DeploymentException("Error in decrypting data source 
file: " + e.getMessage(), e);
+        }
+    }
+
+}
Index: 
src/main/java/org/wso2/carbon/ndatasource/core/internal/DataSourceServiceComponent.java
===================================================================
--- 
src/main/java/org/wso2/carbon/ndatasource/core/internal/DataSourceServiceComponent.java
     (revision 207035)
+++ 
src/main/java/org/wso2/carbon/ndatasource/core/internal/DataSourceServiceComponent.java
     (working copy)
@@ -19,6 +19,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.application.deployer.handler.AppDeploymentHandler;
+import org.wso2.carbon.ndatasource.core.deployer.DataSourceDeployer;
 import org.wso2.carbon.base.MultitenantConstants;
 import org.wso2.carbon.base.api.ServerConfigurationService;
 import org.wso2.carbon.ndatasource.common.DataSourceException;
@@ -53,9 +55,10 @@
 * cardinality="0..1" policy="dynamic"  bind="setConfigurationContextService" 
unbind="unsetConfigurationContextService" 
 */
 public class DataSourceServiceComponent {
+
        private static final Log log = 
LogFactory.getLog(DataSourceServiceComponent.class);
 
-    private static final String 
DATA_SOURCE_REPO_CLASS_TAG="CarbonDataSourceRepositoryClass";
+    private static final String DATA_SOURCE_REPO_CLASS_TAG = 
"CarbonDataSourceRepositoryClass";
        
        private static RegistryService registryService;
        
@@ -80,8 +83,9 @@
                if (log.isDebugEnabled()) {
                        log.debug("DataSourceServiceComponent activated");
                }
+        initDataSourceDeployer();
         /** Attempting to load the DatasourceRepository implementation class 
defined in carbon.xml
-        .*If it is not there it will use default implementation
+        .* If it is not there it will use default implementation
          */
         String carbonDataSourceRepositoryClassName =
                 CarbonUtils.getServerConfiguration().getFirstProperty(
@@ -103,8 +107,22 @@
                        this.registerServices();
                }
        }
-       
-       protected synchronized void deactivate(ComponentContext ctx) {
+
+    /**
+     * initialising car app data source deployer
+     */
+    private void initDataSourceDeployer() {
+        try {
+            //register data source deployer as an OSGi service
+            DataSourceDeployer dataSourceDeployer = new DataSourceDeployer();
+            this.ctx.getBundleContext().registerService(
+                    AppDeploymentHandler.class.getName(), dataSourceDeployer, 
null);
+        } catch (Throwable e) {
+            log.error("Failed to activate Data Source Capp Deployer " + 
e.getMessage(), e);
+        }
+    }
+
+    protected synchronized void deactivate(ComponentContext ctx) {
                this.ctx = null;
                this.tenantUserDataSourcesInitialized = false;
                if (log.isDebugEnabled()) {
Index: 
src/main/java/org/wso2/carbon/ndatasource/core/services/WSDataSourceMetaInfo.java
===================================================================
--- 
src/main/java/org/wso2/carbon/ndatasource/core/services/WSDataSourceMetaInfo.java
   (revision 207035)
+++ 
src/main/java/org/wso2/carbon/ndatasource/core/services/WSDataSourceMetaInfo.java
   (working copy)
@@ -43,7 +43,7 @@
                this.name = metaInfo.getName();
                this.description = metaInfo.getDescription();
                this.jndiConfig = metaInfo.getJndiConfig();
-               this.system = metaInfo.isSystem();
+               this.system = !metaInfo.isPersistable();
                this.definition = new 
WSDataSourceDefinition(metaInfo.getDefinition());
        }
        
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to