From 6bc84366f2140764d0bb130633beae391365b9bb Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Tue, 9 Dec 2014 18:53:16 +0530 Subject: [PATCH 1/2] Fixing starting problems --- .../config/datasource/DataSourceConfig.java | 38 ++++++++++ .../datasource/JNDILookupDefinition.java | 76 +++++++++++++++++++ .../core/dao/PolicyManagementDAOFactory.java | 22 ++++++ .../dao/util/PolicyManagementDAOUtil.java | 22 ++++++ .../internal/PolicyManagementDataHolder.java | 22 ++++++ product/modules/p2-profile-gen/pom.xml | 38 ++++++++++ 6 files changed, 218 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/DataSourceConfig.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/JNDILookupDefinition.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/DataSourceConfig.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/DataSourceConfig.java new file mode 100644 index 0000000000..d451b0442d --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/DataSourceConfig.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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. + * 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.policy.mgt.core.config.datasource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Class for holding data source configuration in rss-config.xml at parsing with JAXB + */ +@XmlRootElement(name = "DataSourceConfiguration") +public class DataSourceConfig { + + private JNDILookupDefinition jndiLookupDefintion; + + @XmlElement(name = "JndiLookupDefinition", nillable = true) + public JNDILookupDefinition getJndiLookupDefintion() { + return jndiLookupDefintion; + } + + public void setJndiLookupDefintion(JNDILookupDefinition jndiLookupDefintion) { + this.jndiLookupDefintion = jndiLookupDefintion; + } + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/JNDILookupDefinition.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/JNDILookupDefinition.java new file mode 100644 index 0000000000..32fa2de644 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/config/datasource/JNDILookupDefinition.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 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. + * 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.policy.mgt.core.config.datasource; + +import javax.xml.bind.annotation.*; +import java.util.List; + +/** + * Class for hold JndiLookupDefinition of rss-manager.xml at parsing with JAXB + */ +@XmlRootElement(name = "JndiLookupDefinition") +public class JNDILookupDefinition { + + private String jndiName; + private List jndiProperties; + + @XmlElement(name = "Name", nillable = false) + public String getJndiName() { + return jndiName; + } + + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @XmlElementWrapper(name = "Environment", nillable = false) + @XmlElement(name = "Property", nillable = false) + public List getJndiProperties() { + return jndiProperties; + } + + public void setJndiProperties(List jndiProperties) { + this.jndiProperties = jndiProperties; + } + + @XmlRootElement(name = "Property") + public static class JNDIProperty { + + private String name; + + private String value; + + @XmlAttribute(name = "Name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlValue + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java new file mode 100644 index 0000000000..0e2b1c91a5 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java @@ -0,0 +1,22 @@ +/* +* Copyright (c) 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.policy.mgt.core.dao; + +public class PolicyManagementDAOFactory { +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java new file mode 100644 index 0000000000..e8c0c39068 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java @@ -0,0 +1,22 @@ +/* +* Copyright (c) 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.policy.mgt.core.dao.util; + +public class PolicyManagementDAOUtil { +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java new file mode 100644 index 0000000000..8726335f11 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java @@ -0,0 +1,22 @@ +/* +* Copyright (c) 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.policy.mgt.core.internal; + +public class PolicyManagementDataHolder { +} diff --git a/product/modules/p2-profile-gen/pom.xml b/product/modules/p2-profile-gen/pom.xml index 7883a73640..8d755249fe 100644 --- a/product/modules/p2-profile-gen/pom.xml +++ b/product/modules/p2-profile-gen/pom.xml @@ -107,6 +107,24 @@ org.wso2.carbon:org.wso2.carbon.device.mgt.server.feature:${project.version} + + org.wso2.carbon:org.wso2.carbon.webapp.mgt.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.transport.mgt.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.service.mgt.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.security.mgt.server.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.security.mgt.feature:${carbon.platform.version} + + + org.wso2.carbon:org.wso2.carbon.module.mgt.feature:${carbon.platform.version} + @@ -140,6 +158,26 @@ org.wso2.carbon.device.mgt.server.feature.group ${project.version} + + org.wso2.carbon.webapp.mgt.feature.group + ${carbon.platform.version} + + + org.wso2.carbon.transport.mgt.feature.group + ${carbon.platform.version} + + + org.wso2.carbon.service.mgt.feature.group + ${carbon.platform.version} + + + org.wso2.carbon.security.mgt.feature.group + ${carbon.platform.version} + + + org.wso2.carbon.module.mgt.feature.group + ${carbon.platform.version} + From 233c3c60b24ac527f2f8396d0b4fa1d64068a5a2 Mon Sep 17 00:00:00 2001 From: Geeth Munasinghe Date: Tue, 9 Dec 2014 18:54:05 +0530 Subject: [PATCH 2/2] Adding policy mgt daos --- .../org.wso2.carbon.policy.mgt.core/pom.xml | 22 ++++++ .../carbon/policy/mgt/core/dao/PolicyDAO.java | 38 ++++++++++ .../core/dao/PolicyManagementDAOFactory.java | 58 +++++++++++++++ .../core/dao/PolicyManagerDAOException.java | 55 ++++++++++++++ .../mgt/core/dao/impl/PolicyDAOImpl.java | 73 +++++++++++++++++++ .../dao/util/PolicyManagementDAOUtil.java | 16 ++++ .../internal/PolicyManagementDataHolder.java | 35 +++++++++ pom.xml | 9 ++- 8 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagerDAOException.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index d66e9ff997..5b9b7deb78 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -83,6 +83,28 @@ org.wso2.carbon org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.policy.mgt.common + + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + org.wso2.carbon + org.wso2.carbon.ndatasource.rdbms + org.wso2.carbon org.wso2.carbon.logging diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java new file mode 100644 index 0000000000..944bf89a9e --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyDAO.java @@ -0,0 +1,38 @@ +/* +* Copyright (c) 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.policy.mgt.core.dao; + +import org.wso2.carbon.policy.mgt.common.Policy; + +public interface PolicyDAO { + + int addPolicy(Policy policy) throws PolicyManagerDAOException; + + int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException; + + int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException; + + void updatePolicy(int id) throws PolicyManagerDAOException; + + Policy getPolicy() throws PolicyManagerDAOException; + + Policy getPolicy(String deviceType) throws PolicyManagerDAOException; + + Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException; +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java index 0e2b1c91a5..f1d9cf56ca 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagementDAOFactory.java @@ -18,5 +18,63 @@ package org.wso2.carbon.policy.mgt.core.dao; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.policy.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl; +import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; + +import javax.sql.DataSource; +import java.util.Hashtable; +import java.util.List; + public class PolicyManagementDAOFactory { + + private static DataSource dataSource; + private static final Log log = LogFactory.getLog(PolicyManagementDAOFactory.class); + + + public static PolicyDAO getDeviceTypeDAO() { + return new PolicyDAOImpl(dataSource); + } + + public static void init(DataSourceConfig config) { + dataSource = resolveDataSource(config); + } + + /** + * Resolve data source from the data source definition + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException("Device Management Repository data source configuration " + + "is null and thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = + PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = PolicyManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagerDAOException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagerDAOException.java new file mode 100644 index 0000000000..4913f6752c --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/PolicyManagerDAOException.java @@ -0,0 +1,55 @@ +/* +* Copyright (c) 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.policy.mgt.core.dao; + +public class PolicyManagerDAOException extends Exception{ + + private String policyDAOErrorMessage; + + public String getPolicyDAOErrorMessage() { + return policyDAOErrorMessage; + } + + public void setPolicyDAOErrorMessage(String policyDAOErrorMessage) { + this.policyDAOErrorMessage = policyDAOErrorMessage; + } + + public PolicyManagerDAOException(String message) { + super(message); + setPolicyDAOErrorMessage(message); + } + + public PolicyManagerDAOException(String message, Exception ex) { + super(message, ex); + setPolicyDAOErrorMessage(message); + } + + public PolicyManagerDAOException(String message, Throwable cause) { + super(message, cause); + setPolicyDAOErrorMessage(message); + } + + public PolicyManagerDAOException() { + super(); + } + + public PolicyManagerDAOException(Throwable cause) { + super(cause); + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java new file mode 100644 index 0000000000..0a5c6bc744 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/PolicyDAOImpl.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 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.policy.mgt.core.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO; +import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; + +import javax.sql.DataSource; + +public class PolicyDAOImpl implements PolicyDAO { + + private static DataSource dataSource; + private static final Log log = LogFactory.getLog(PolicyDAOImpl.class); + + public PolicyDAOImpl(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public int addPolicy(Policy policy) throws PolicyManagerDAOException { + + return 0; + } + + @Override + public int addPolicy(String deviceType, Policy policy) throws PolicyManagerDAOException { + return 0; + } + + @Override + public int addPolicy(String deviceID, String deviceType, Policy policy) throws PolicyManagerDAOException { + return 0; + } + + @Override + public void updatePolicy(int id) throws PolicyManagerDAOException { + + } + + @Override + public Policy getPolicy() throws PolicyManagerDAOException { + return null; + } + + @Override + public Policy getPolicy(String deviceType) throws PolicyManagerDAOException { + return null; + } + + @Override + public Policy getPolicy(String deviceID, String deviceType) throws PolicyManagerDAOException { + return null; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java index e8c0c39068..55d4be5ec9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/util/PolicyManagementDAOUtil.java @@ -18,5 +18,21 @@ package org.wso2.carbon.policy.mgt.core.dao.util; +import javax.naming.InitialContext; +import javax.sql.DataSource; +import java.util.Hashtable; + public class PolicyManagementDAOUtil { + public static DataSource lookupDataSource(String dataSourceName, final Hashtable jndiProperties) { + try { + if (jndiProperties == null || jndiProperties.isEmpty()) { + return (DataSource) InitialContext.doLookup(dataSourceName); + } + final InitialContext context = new InitialContext(jndiProperties); + return (DataSource) context.doLookup(dataSourceName); + } catch (Exception e) { + throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); + } + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java index 8726335f11..afbf02eca0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java @@ -18,5 +18,40 @@ package org.wso2.carbon.policy.mgt.core.internal; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.user.core.tenant.TenantManager; + public class PolicyManagementDataHolder { + + private RealmService realmService; + private TenantManager tenantManager; + private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder(); + + private PolicyManagementDataHolder() {} + + public static PolicyManagementDataHolder getInstance() { + return thisInstance; + } + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + this.setTenantManager(realmService); + } + + private void setTenantManager(RealmService realmService) { + if (realmService == null) { + throw new IllegalStateException("Realm service is not initialized properly"); + } + this.tenantManager = realmService.getTenantManager(); + } + + public TenantManager getTenantManager() { + return tenantManager; + } + + } diff --git a/pom.xml b/pom.xml index 73843cab13..1d092189aa 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,14 @@ ${project.version} - + + org.wso2.carbon + org.wso2.carbon.policy.mgt.common + ${project.version} + + + + org.eclipse.osgi org.eclipse.osgi