diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java
index 0649a9d6a3..9802fe30fe 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java
@@ -34,7 +34,7 @@ public final class DeviceManagementConstants {
public static final String SECURE_VAULT_NS = "http://org.wso2.securevault/configuration";
}
- public static class MobileDeviceTypes {
+ public static final class MobileDeviceTypes {
private MobileDeviceTypes() {
throw new AssertionError();
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java
index 2300db16b7..5f81287390 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java
@@ -118,7 +118,7 @@ public final class DeviceManagementDAOUtil {
deviceBO.setOwnerId(device.getOwner());
deviceBO.setOwnerShip(device.getOwnership());
deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId());
- deviceBO.setDeviceType(Integer.parseInt(device.getType()));
+ //deviceBO.setDeviceType(Integer.parseInt(device.getType()));
return deviceBO;
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml
index 8dd8ef138c..510ee66d72 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/pom.xml
@@ -74,10 +74,13 @@
org.wso2.carbonorg.wso2.carbon.logging
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ org.eclipse.osgiorg.eclipse.osgi.services
- 3.2.0.v20090520-1800
diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyMgtServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/DataSourceListener.java
similarity index 71%
rename from components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyMgtServiceComponent.java
rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/DataSourceListener.java
index b66e04262e..61c881745f 100644
--- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyMgtServiceComponent.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/DataSourceListener.java
@@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.wso2.carbon.policy.mgt.core.internal;
+package org.wso2.carbon.device.mgt.mobile.impl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+public interface DataSourceListener {
-public class PolicyMgtServiceComponent {
-
- private static Log log = LogFactory.getLog(PolicyMgtServiceComponent.class);
+ void notifyObserver();
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java
index 3246b21f21..805345e743 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java
@@ -86,4 +86,6 @@ public class AndroidDeviceManagerService implements DeviceManagerService {
return true;
}
+ //should implement equals and hashcode in all service bundles
+
}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceConfigurationManager.java
new file mode 100644
index 0000000000..1a24811996
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceConfigurationManager.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.config;
+
+import org.w3c.dom.Document;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.mobile.impl.util.MobileDeviceManagerUtil;
+import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.MobileDataSourceConfig;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+
+/**
+ * Class responsible for the mobile device manager configuration initialization
+ */
+public class MobileDeviceConfigurationManager {
+
+ private static final String MOBILE_DEVICE_CONFIG_XML_NAME = "mobile-config.xml";
+ private MobileDeviceManagementConfig currentMobileDeviceConfig;
+ private static MobileDeviceConfigurationManager mobileDeviceConfigManager;
+
+ private final String mobileDeviceMgtConfigXMLPath =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ MOBILE_DEVICE_CONFIG_XML_NAME;
+
+ public static MobileDeviceConfigurationManager getInstance() {
+ if (mobileDeviceConfigManager == null) {
+ synchronized (MobileDeviceConfigurationManager.class) {
+ if (mobileDeviceConfigManager == null) {
+ mobileDeviceConfigManager = new MobileDeviceConfigurationManager();
+ }
+ }
+ }
+ return mobileDeviceConfigManager;
+ }
+
+ public synchronized void initConfig() throws DeviceManagementException {
+ try {
+ File mobileDeviceMgtConfig = new File(mobileDeviceMgtConfigXMLPath);
+ Document doc = MobileDeviceManagerUtil.convertToDocument(mobileDeviceMgtConfig);
+ JAXBContext mobileDeviceMgmtContext =
+ JAXBContext.newInstance(MobileDeviceManagementConfig.class);
+ Unmarshaller unmarshaller = mobileDeviceMgmtContext.createUnmarshaller();
+ this.currentMobileDeviceConfig =
+ (MobileDeviceManagementConfig) unmarshaller.unmarshal(doc);
+ } catch (Exception e) {
+ throw new DeviceManagementException(
+ "Error occurred while initializing Mobile Device Management config", e);
+ }
+ }
+
+ public MobileDeviceManagementConfig getMobileDeviceManagementConfig() {
+ return currentMobileDeviceConfig;
+ }
+
+ public MobileDataSourceConfig getMobileDataSourceConfig() {
+ return currentMobileDeviceConfig.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementConfig.java
new file mode 100644
index 0000000000..203245e5bd
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementConfig.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.config;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents Mobile Device Mgt configuration.
+ */
+@XmlRootElement(name = "MobileDeviceMgtConfiguration")
+public final class MobileDeviceManagementConfig {
+
+ private MobileDeviceManagementRepository mobileDeviceMgtRepository;
+
+ @XmlElement(name = "ManagementRepository", nillable = false)
+ public MobileDeviceManagementRepository getMobileDeviceMgtRepository() {
+ return mobileDeviceMgtRepository;
+ }
+
+ public void setMobileDeviceMgtRepository(
+ MobileDeviceManagementRepository mobileDeviceMgtRepository) {
+ this.mobileDeviceMgtRepository = mobileDeviceMgtRepository;
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementRepository.java
new file mode 100644
index 0000000000..9987d1763d
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/MobileDeviceManagementRepository.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.config;
+
+import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.MobileDataSourceConfig;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding management repository data
+ */
+@XmlRootElement(name = "ManagementRepository")
+public class MobileDeviceManagementRepository {
+
+ private MobileDataSourceConfig mobileDataSourceConfig;
+
+ @XmlElement(name = "DataSourceConfiguration", nillable = false)
+ public MobileDataSourceConfig getMobileDataSourceConfig() {
+ return mobileDataSourceConfig;
+ }
+
+ public void setMobileDataSourceConfig(MobileDataSourceConfig mobileDataSourceConfig) {
+ this.mobileDataSourceConfig = mobileDataSourceConfig;
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/JNDILookupDefinition.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/JNDILookupDefinition.java
new file mode 100644
index 0000000000..94d62a1d26
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/JNDILookupDefinition.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.config.datasource;
+
+import javax.xml.bind.annotation.*;
+import java.util.List;
+
+/**
+ * Class for hold JndiLookupDefinition of mobile-config.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/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/MobileDataSourceConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/MobileDataSourceConfig.java
new file mode 100644
index 0000000000..a3e3f6ae0b
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/config/datasource/MobileDataSourceConfig.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding data source configuration in mobile-config.xml at parsing with JAXB
+ */
+@XmlRootElement(name = "DataSourceConfiguration")
+public class MobileDataSourceConfig {
+
+ 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/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAO.java
index 1d4ab3ab80..16330df10c 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAO.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAO.java
@@ -19,7 +19,8 @@ package org.wso2.carbon.device.mgt.mobile.impl.dao;
import org.wso2.carbon.device.mgt.mobile.impl.dto.MobileDevice;
/**
- * This class represents the key operations associated with persisting mobile-device related information.
+ * This class represents the key operations associated with persisting mobile-device related
+ * information.
*/
public interface MobileDeviceDAO {
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOFactory.java
new file mode 100644
index 0000000000..fabb81d8d3
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceDAOFactory.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.dao;
+
+import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceModelDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceVendorDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileOSVersionDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDeviceManagementDAOUtil;
+import org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementBundleActivator;
+
+import javax.sql.DataSource;
+
+public class MobileDeviceDAOFactory implements DataSourceListener {
+
+ private static DataSource dataSource;
+
+ public MobileDeviceDAOFactory() {
+ MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
+ }
+
+ @Override
+ public void notifyObserver() {
+ dataSource = MobileDeviceManagementDAOUtil.resolveDataSource();
+ }
+
+ public static MobileDeviceDAO getMobileDeviceDAO() {
+ return new MobileDeviceDAOImpl(dataSource);
+ }
+
+ public static MobileDeviceModelDAO getMobileDeviceModelDAO() {
+ return new MobileDeviceModelDAOImpl(dataSource);
+ }
+
+ public static MobileDeviceVendorDAO getMobileDeviceVendorDAO() {
+ return new MobileDeviceVendorDAOImpl(dataSource);
+ }
+
+ public static MobileOSVersionDAO getMobileOSVersionDAO() {
+ return new MobileOSVersionDAOImpl(dataSource);
+ }
+
+}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOException.java
index 8047d932a2..d0d03fcacf 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOException.java
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOException.java
@@ -25,9 +25,10 @@ public class MobileDeviceManagementDAOException extends Exception {
private static final long serialVersionUID = 2021891706072918865L;
/**
- * Constructs a new exception with the specified detail message and nested exception.
+ * Constructs a new MobileDeviceManagementDAOException with the specified detail message and
+ * nested exception.
*
- * @param message error message
+ * @param message error message
* @param nestedException exception
*/
public MobileDeviceManagementDAOException(String message, Exception nestedException) {
@@ -36,7 +37,8 @@ public class MobileDeviceManagementDAOException extends Exception {
}
/**
- * Constructs a new exception with the specified detail message and cause.
+ * Constructs a new MobileDeviceManagementDAOException with the specified detail message
+ * and cause.
*
* @param message the detail message.
* @param cause the cause of this exception.
@@ -47,7 +49,7 @@ public class MobileDeviceManagementDAOException extends Exception {
}
/**
- * Constructs a new exception with the specified detail message
+ * Constructs a new MobileDeviceManagementDAOException with the specified detail message
*
* @param message the detail message.
*/
@@ -57,9 +59,9 @@ public class MobileDeviceManagementDAOException extends Exception {
}
/**
- * Constructs a new exception with the specified and cause.
+ * Constructs a new MobileDeviceManagementDAOException with the specified and cause.
*
- * @param cause the cause of this exception.
+ * @param cause the cause of this exception.
*/
public MobileDeviceManagementDAOException(Throwable cause) {
super(cause);
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOFactory.java
new file mode 100644
index 0000000000..65750447d5
--- /dev/null
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/dao/MobileDeviceManagementDAOFactory.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2014, 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.device.mgt.mobile.impl.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.MobileDataSourceConfig;
+import org.wso2.carbon.device.mgt.mobile.impl.config.datasource.JNDILookupDefinition;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceModelDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceVendorDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileOSVersionDAOImpl;
+import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDeviceManagementDAOUtil;
+
+import javax.sql.DataSource;
+import java.util.Hashtable;
+import java.util.List;
+
+/**
+ * Factory class used to create MobileDeviceManagement related DAO objects.
+ */
+public class MobileDeviceManagementDAOFactory {
+
+ private static DataSource dataSource;
+ private static final Log log = LogFactory.getLog(MobileDeviceManagementDAOFactory.class);
+
+ public static MobileDeviceDAO getMobileDeviceDAO() {
+ return new MobileDeviceDAOImpl(dataSource);
+ }
+
+ public static MobileDeviceModelDAO getMobileDeviceModelDAO() {
+ return new MobileDeviceModelDAOImpl(dataSource);
+ }
+
+ public static MobileDeviceVendorDAO getMobileDeviceVendorDAO() {
+ return new MobileDeviceVendorDAOImpl(dataSource);
+ }
+
+ public static MobileOSVersionDAO getMobileOSVersionDAO() {
+ return new MobileOSVersionDAOImpl(dataSource);
+ }
+
+ public static void init(MobileDataSourceConfig config) {
+ dataSource = resolveDataSource(config);
+ }
+
+ public static void init(DataSource dtSource) {
+ dataSource = dtSource;
+ }
+
+ /**
+ * 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(MobileDataSourceConfig 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