From 7e253156f6d25e9efe3694da1dca2d5f6d5829ae Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 18 Mar 2015 20:23:34 +0530 Subject: [PATCH] Code cleanup --- ...Service.java => AndroidDeviceManager.java} | 6 +- .../impl/android/AndroidFeatureManager.java | 78 +++++++++++++++++++ .../mobile/impl/android/dao/FeatureDAO.java | 36 +++++++++ .../dao/FeatureManagementDAOException.java | 22 ++++++ .../dao/FeatureManagementDAOFactory.java | 29 +++++++ .../impl/android/dao/impl/FeatureDAOImpl.java | 49 ++++++++++++ ...agerService.java => IOSDeviceManager.java} | 4 +- ...Service.java => WindowsDeviceManager.java} | 4 +- ...MobileDeviceManagementBundleActivator.java | 12 +-- ...obileDeviceManagementServiceComponent.java | 15 ++-- 10 files changed, 233 insertions(+), 22 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/{AndroidDeviceManagerService.java => AndroidDeviceManager.java} (98%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/{IOSDeviceManagerService.java => IOSDeviceManager.java} (98%) rename components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/{WindowsDeviceManagerService.java => WindowsDeviceManager.java} (97%) 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/AndroidDeviceManager.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidDeviceManager.java index cffd4d882f..77b652e102 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/AndroidDeviceManager.java @@ -33,9 +33,9 @@ import java.util.List; /** * This represents the Android implementation of DeviceManagerService. */ -public class AndroidDeviceManagerService implements DeviceManager { +public class AndroidDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(AndroidDeviceManagerService.class); + private static final Log log = LogFactory.getLog(AndroidDeviceManager.class); @Override public String getProviderType() { @@ -44,7 +44,7 @@ public class AndroidDeviceManagerService implements DeviceManager { @Override public FeatureManager getFeatureManager() { - return null; + return new AndroidFeatureManager(); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java new file mode 100644 index 0000000000..be371bf344 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/AndroidFeatureManager.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015, 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.device.mgt.mobile.impl.android; + +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManagementException; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory; + +import java.util.List; + +public class AndroidFeatureManager implements FeatureManager { + + private FeatureDAO featureDAO; + + public AndroidFeatureManager() { + this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO(); + } + + @Override + public boolean addFeature(Feature feature) throws DeviceManagementException { + try { + featureDAO.addFeature(feature); + return true; + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while adding the feature", e); + } + } + + @Override + public Feature getFeature(String name) throws DeviceManagementException { + try { + return featureDAO.getFeature(name); + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the feature", e); + } + } + + @Override + public List getFeatures() throws DeviceManagementException { + try { + return featureDAO.getFeatures(); + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the list of features registered " + + "for Android platform", e); + } + } + + @Override + public boolean removeFeature(String name) throws DeviceManagementException { + try { + featureDAO.removeFeature(name); + return true; + } catch (FeatureManagementDAOException e) { + throw new DeviceManagementException("Error occurred while removing the feature", e); + } + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java new file mode 100644 index 0000000000..17b347b1f5 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, 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.device.mgt.mobile.impl.android.dao; + +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.common.FeatureManagementException; + +import java.util.List; + +public interface FeatureDAO { + + void addFeature(Feature feature) throws FeatureManagementDAOException; + + void removeFeature(String name) throws FeatureManagementDAOException; + + Feature getFeature(String name) throws FeatureManagementDAOException; + + List getFeatures() throws FeatureManagementDAOException; + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java new file mode 100644 index 0000000000..24d02f9390 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOException.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015, 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.device.mgt.mobile.impl.android.dao; + +public class FeatureManagementDAOException extends Exception { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java new file mode 100644 index 0000000000..08c207d94d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureManagementDAOFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015, 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.device.mgt.mobile.impl.android.dao; + +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl.FeatureDAOImpl; + +public class FeatureManagementDAOFactory { + + public static FeatureDAO getFeatureDAO() { + return new FeatureDAOImpl(); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java new file mode 100644 index 0000000000..d966b0304f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/impl/FeatureDAOImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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.device.mgt.mobile.impl.android.dao.impl; + +import org.wso2.carbon.device.mgt.common.Feature; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO; +import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException; + +import java.util.List; + +public class FeatureDAOImpl implements FeatureDAO { + + @Override + public void addFeature(Feature feature) throws FeatureManagementDAOException { + + } + + @Override + public void removeFeature(String name) throws FeatureManagementDAOException { + + } + + @Override + public Feature getFeature(String name) throws FeatureManagementDAOException { + return null; + } + + @Override + public List getFeatures() throws FeatureManagementDAOException { + return null; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java index 29168335b1..7f0b761f76 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSDeviceManager.java @@ -32,9 +32,9 @@ import java.util.List; /** * This represents the iOS implementation of DeviceManagerService. */ -public class IOSDeviceManagerService implements DeviceManager { +public class IOSDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(IOSDeviceManagerService.class); + private static final Log log = LogFactory.getLog(IOSDeviceManager.class); @Override public String getProviderType() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java similarity index 97% rename from components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java index 6fca617162..3776954720 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/windows/WindowsDeviceManager.java @@ -32,9 +32,9 @@ import java.util.List; /** * This represents the Windows implementation of DeviceManagerService. */ -public class WindowsDeviceManagerService implements DeviceManager { +public class WindowsDeviceManager implements DeviceManager { - private static final Log log = LogFactory.getLog(WindowsDeviceManagerService.class); + private static final Log log = LogFactory.getLog(WindowsDeviceManager.class); @Override public String getProviderType() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java index 8b851a83d8..826ff2ccfe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementBundleActivator.java @@ -32,9 +32,9 @@ import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager; +import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager; +import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; import java.util.ArrayList; @@ -75,13 +75,13 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator, B androidServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new AndroidDeviceManagerService(), null); + new AndroidDeviceManager(), null); iOSServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new IOSDeviceManagerService(), null); + new IOSDeviceManager(), null); windowsServiceRegRef = bundleContext.registerService(DeviceManager.class.getName(), - new WindowsDeviceManagerService(), null); + new WindowsDeviceManager(), null); /* Initialize all API configurations with corresponding API Providers */ this.initAPIConfigs(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index f68765bfa3..6a3dd19fc2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -34,9 +34,9 @@ import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManager; +import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManager; +import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManager; import org.wso2.carbon.device.mgt.mobile.util.DeviceManagementAPIPublisherUtil; import java.util.List; @@ -96,14 +96,11 @@ public class MobileDeviceManagementServiceComponent { } androidServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new AndroidDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new AndroidDeviceManager(), null); iOSServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new IOSDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new IOSDeviceManager(), null); windowsServiceRegRef = - bundleContext.registerService(DeviceManager.class.getName(), - new WindowsDeviceManagerService(), null); + bundleContext.registerService(DeviceManager.class.getName(), new WindowsDeviceManager(), null); serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class, new MobileDeviceManagementStartupObserver(), null);