From 394258d10f02fe558e4cadbce088854f3730be53 Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 5 Feb 2015 13:10:26 +0530 Subject: [PATCH] Default License feature --- .../config/LicenseConfigurationManager.java | 73 ++++++++++++ .../core/config/LicenseManagementConfig.java | 41 +++++++ .../mgt/core/config/license/License.java | 104 ++++++++++++++++++ .../device/mgt/core/util/DateAdapter.java | 40 +++++++ 4 files changed, 258 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseManagementConfig.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java new file mode 100644 index 0000000000..2995c6b14f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseConfigurationManager.java @@ -0,0 +1,73 @@ +/* + * + * 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.core.config; + +import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.common.LicenseManagementException; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.File; + +public class LicenseConfigurationManager { + + private LicenseManagementConfig licenseMgtConfig; + private static LicenseConfigurationManager licenseConfigManager; + + private static final String licenseMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + + DeviceManagementConstants.Common.DEFAULT_LICENSE_CONFIG_XML_NAME; + + public static LicenseConfigurationManager getInstance() { + if (licenseConfigManager == null) { + synchronized (LicenseConfigurationManager.class) { + if (licenseConfigManager == null) { + licenseConfigManager = new LicenseConfigurationManager(); + } + } + } + return licenseConfigManager; + } + + public synchronized void initConfig() throws LicenseManagementException { + + //catch generic exception.if any exception occurs wrap and throw LicenseManagementException + try { + File licenseMgtConfig = new File(licenseMgtConfigXMLPath); + Document doc = DeviceManagerUtil.convertToDocument(licenseMgtConfig); + + /* Un-marshaling License Management configuration */ + JAXBContext cdmContext = JAXBContext.newInstance(LicenseManagementConfig.class); + Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); + this.licenseMgtConfig = (LicenseManagementConfig) unmarshaller.unmarshal(doc); + } catch (Exception e) { + throw new LicenseManagementException("Error occurred while initializing RSS config", e); + } + } + + public LicenseManagementConfig getLicenseMgtConfig() { + return licenseMgtConfig; + } + + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseManagementConfig.java new file mode 100644 index 0000000000..dc61771e7f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/LicenseManagementConfig.java @@ -0,0 +1,41 @@ +/* + * + * 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.core.config; + +import org.wso2.carbon.device.mgt.core.config.license.License; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +@XmlRootElement(name = "DefaultLicense") +public class LicenseManagementConfig { + + private List licenseList; + + @XmlElement(name = "License") + public List getLicenseList() { + return licenseList; + } + + public void setLicenseList(List licenseList) { + this.licenseList = licenseList; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java new file mode 100644 index 0000000000..1ad70a3952 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/license/License.java @@ -0,0 +1,104 @@ +/* + * + * 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.core.config.license; + +import org.wso2.carbon.device.mgt.core.util.DateAdapter; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Date; + +@XmlRootElement(name = "License") +public class License { + + private String provider; + private String name; + private String version; + private String language; + private Date validFrom; + private Date validTo; + private String license; + + @XmlElement(name = "provider") + public String getProvider() { + return provider; + } + + public void setProvider(String provider) { + this.provider = provider; + } + + @XmlElement(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlElement(name = "version") + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @XmlElement(name = "language") + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + @XmlJavaTypeAdapter(DateAdapter.class) + public Date getValidFrom() { + return validFrom; + } + + public void setValidFrom(Date validFrom) { + this.validFrom = validFrom; + } + + @XmlJavaTypeAdapter(DateAdapter.class) + public Date getValidTo() { + return validTo; + } + + public void setValidTo(Date validTo) { + this.validTo = validTo; + } + + @XmlElement(name = "license") + public String getLicense() { + return license; + } + + public void setLicense(String license) { + this.license = license; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java new file mode 100644 index 0000000000..246852c80d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DateAdapter.java @@ -0,0 +1,40 @@ +/* + * + * 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.core.util; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class DateAdapter extends XmlAdapter { + + private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy"); + + @Override + public Date unmarshal(String strDate) throws ParseException { + return dateFormat.parse(strDate); + } + @Override + public String marshal(Date date) throws ParseException { + return dateFormat.format(date); + } +}