From c37416d69f6ffbc1d53ff08d3c950febd633e9dd Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Thu, 28 May 2015 16:18:54 +0900 Subject: [PATCH] Property: move function loading property and property-template - move function loading property to 'Platform' class from 'Bsae Image' class - delete 'CustomBaseImage' class Change-Id: Ib173a5c61bd497f0381d39b83855221f00825635 Signed-off-by: jihye424.kim --- .../emulator/manager/console/ConsoleCreateVM.java | 2 +- .../tizen/emulator/manager/platform/BaseImage.java | 227 ++++++----- .../emulator/manager/platform/CustomBaseImage.java | 83 ----- .../platform/CustomPropertyTemplateLoader.java | 248 +++++++++++++ .../tizen/emulator/manager/platform/Platform.java | 413 ++++++--------------- .../manager/platform/PlatformStringResources.java | 8 +- .../tizen/emulator/manager/platform/Profile.java | 4 +- .../emulator/manager/vms/VMPropertyValue.java | 9 +- 8 files changed, 476 insertions(+), 518 deletions(-) delete mode 100644 src/org/tizen/emulator/manager/platform/CustomBaseImage.java create mode 100644 src/org/tizen/emulator/manager/platform/CustomPropertyTemplateLoader.java diff --git a/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java b/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java index 96f1f67..178cb4d 100644 --- a/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java +++ b/src/org/tizen/emulator/manager/console/ConsoleCreateVM.java @@ -132,7 +132,7 @@ public class ConsoleCreateVM { image = ProfileList.getProfileList().get(0).getImageList().get(0); } else { // default profile is mobile profile - Profile profile = ProfileList.getProfile(PlatformStringResources.MobileProfile); + Profile profile = ProfileList.getProfile(PlatformStringResources.MOBILE_PROFILE); if (profile != null) { image = profile.getImageList().get(0); } diff --git a/src/org/tizen/emulator/manager/platform/BaseImage.java b/src/org/tizen/emulator/manager/platform/BaseImage.java index f907680..f712b58 100644 --- a/src/org/tizen/emulator/manager/platform/BaseImage.java +++ b/src/org/tizen/emulator/manager/platform/BaseImage.java @@ -36,16 +36,9 @@ import java.util.List; import java.util.Properties; import java.util.logging.Level; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; import org.tizen.emulator.manager.logging.EMLogger; -import org.tizen.emulator.manager.resources.FilePathResources; import org.tizen.emulator.manager.resources.StringResources; -import org.tizen.emulator.manager.vms.EmulatorVMList; import org.tizen.emulator.manager.vms.SKIN_SHAPE; import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.option.IOption; @@ -77,28 +70,96 @@ public class BaseImage { protected List optionList; private LaunchConfig launchTemplate; // TODO replace xDefaultOption.java - public static JAXBContext templateContext = null; - - static { - try { - templateContext = JAXBContext.newInstance(ItemList.class); - } catch (JAXBException e){ - EMLogger.getLogger().info(e.getMessage()); - } - } - protected BaseImage() { } + /** + * Create standard base image instance + * @param platform + * @param path directory path that have base image and info.ini file + * @throws IOException + */ public BaseImage(Platform platform, File path) throws IOException { this.platform = platform; isStandard = true; - loadProperty(path); + settingProperty(path); settingImagePath(path); loadTemplate(); } + /** + * Create custom base image instance + * @param platform + * @param path base image path + * @throws IOException + */ + public BaseImage(Platform platform, String path) throws IOException { + if (platform == null) { + throw new IOException("Failed to create custom base image " + + StringResources.NEW_LINE + "because platform is null."); + } + this.platform = platform; + isStandard = false; + + this.path = path; + if (path != null && !path.isEmpty()) { + imageName = pathName = path.substring(path.lastIndexOf(File.separator) + 1); + } + + settingProperty(platform); + loadTemplate(); + } + + @Override + public String toString() { + return information; + } + + public String getPath() { + return path; + } + + public String getPathName() { + return pathName; + } + + public String getID() { + return id; + } + + public String getName() { + return imageName; + } + + public String getProfile() { + return profile; + } + + public String getVersion() { + return version; + } + + public String getCpu() { + return cpu; + } + + public String getType() { + return type; + } + + public String getPlatformName() { + return platform.getName(); + } + + public Platform getPlatform() { + return platform; + } + + public String getBinaryVersion() { + return binaryVersion; + } + public List getOptionList() { if (optionList == null) { optionList = platform.loadOptionList(getItemList()); @@ -110,10 +171,6 @@ public class BaseImage { return defaultProperty; } - public void setDefaultProperty(VMProperty property) { - this.defaultProperty = property; - } - public ItemList getItemList() { return itemList; } @@ -136,7 +193,12 @@ public class BaseImage { } } - private void loadProperty(File path) throws IOException { + /** + * Setting standard base image property using info.ini file + * @param path info.ini file + * @throws IOException + */ + private void settingProperty(File path) throws IOException { File f = new File(path + File.separator + StringResources.IMAGE_INFO_FILENAME); FileInputStream inputStream = null; try { @@ -147,7 +209,7 @@ public class BaseImage { imageName = prop.getProperty(StringResources.IMAGE_NAME, ""); checkBaseImageName(); version = prop.getProperty(StringResources.IMAGE_VERSION, "2.4"); - profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MobileProfile).toLowerCase(); + profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MOBILE_PROFILE).toLowerCase(); type = prop.getProperty(StringResources.IMAGE_TYPE, "default"); cpu = prop.getProperty(StringResources.TARGET_CPU, "x86"); cpu = cpu.toLowerCase(); @@ -168,6 +230,19 @@ public class BaseImage { } } + /** + * Setting custom base image property + * @param platform + */ + private void settingProperty(Platform platform) { + version = platform.getVersion(); + profile = platform.getProfile(); + type = "custom"; // TODO + cpu = "x86"; + skinShape = SKIN_SHAPE.NONE; // TODO + binaryVersion = ""; + } + private void settingImagePath(File path) throws IOException { for (File f : path.listFiles()) { if (f.isFile() && f.getName().endsWith(cpu.toLowerCase())) { @@ -197,105 +272,13 @@ public class BaseImage { // } - public String getPath() { - return path; - } - - public String getPathName() { - return pathName; - } - - public String toString() { - return information; - - } - - public String getID() { - return id; - } - - // Platform name - public String getVersion() { - return version; - } - - public String getCpu() { - return cpu; - } - - public String getProfile() { - return profile; - } - - public String getName() { - return imageName; - } - - public String getType() { - return type; - } - - public String getPlatformName() { - return platform.getName(); - } - - public Platform getPlatform() { - return platform; - } - - public String getBinaryVersion() { - return binaryVersion; - } - private void loadTemplate() { - // load template - File templateFile = new File(platform.platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + imageName + "-" + PlatformStringResources.TEMPLATE - + "." + PlatformStringResources.CONFIG_EXTENSION); - - if (!templateFile.exists()) { - // load standard-template file (x86-standard-template.xml) - templateFile = new File(platform.platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + cpu + "-standard-" + PlatformStringResources.TEMPLATE - + "." + PlatformStringResources.CONFIG_EXTENSION); - } - - if (templateFile.exists()) { - JAXBElement element = null; - try { - Unmarshaller unmarshaller = templateContext.createUnmarshaller(); - element = unmarshaller.unmarshal(new StreamSource(templateFile), ItemList.class); - } catch (JAXBException e) { - e.printStackTrace(); - EMLogger.getLogger().warning("Can not load config file( " - + templateFile.getName() + ")" + StringResources.NEW_LINE + e.getMessage()); - element = null; - } - if (element != null) { - itemList = element.getValue(); - } - } - - // load default - File propertyFile = new File(platform.platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + imageName + "." + PlatformStringResources.CONFIG_EXTENSION); - - if (!propertyFile.exists()) { - // load standard-default file.(x86-standard.xml) - propertyFile = new File(platform.platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + cpu + "-standard" + "." + PlatformStringResources.CONFIG_EXTENSION); - } - if (propertyFile.exists()) { - EmulatorVMList vmList = EmulatorVMList.getInstance(); - defaultProperty = vmList.parseXML(propertyFile); + if (isStandard) { + itemList = platform.findItemList(imageName); + defaultProperty = platform.findVMProperty(imageName); + } else { + itemList = platform.getCustomItemList(); + defaultProperty = platform.getCustomDefaultProperty(); } } diff --git a/src/org/tizen/emulator/manager/platform/CustomBaseImage.java b/src/org/tizen/emulator/manager/platform/CustomBaseImage.java deleted file mode 100644 index ac615a0..0000000 --- a/src/org/tizen/emulator/manager/platform/CustomBaseImage.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Emulator Manager - * - * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * JiHye Kim - * YeongKyoon Lee - * SeokYeon Hwang - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Contributors: - * - S-Core Co., Ltd - * - */ - -package org.tizen.emulator.manager.platform; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.tizen.emulator.manager.resources.StringResources; -import org.tizen.emulator.manager.vms.SKIN_SHAPE; -import org.tizen.emulator.manager.vms.VMProperty; -import org.tizen.emulator.manager.vms.option.IOption; -import org.tizen.emulator.manager.vms.xml.template.ItemList; - -public class CustomBaseImage extends BaseImage { - - public CustomBaseImage(Platform platform, String path) throws IOException { - if (platform == null) { - throw new IOException("Failed to create custom base image " - + StringResources.NEW_LINE + "because platform is null."); - } - this.platform = platform; - isStandard = false; - - this.path = path; - if (path != null && !path.isEmpty()) { - imageName = pathName = path.substring(path.lastIndexOf(File.separator) + 1); - } - - settingProperty(platform); - } - - private void settingProperty(Platform platform) { - version = platform.getVersion(); - profile = platform.getProfile(); - type = "custom"; // TODO - cpu = "x86"; - skinShape = SKIN_SHAPE.NONE; // TODO - binaryVersion = ""; - } - - @Override - public List getOptionList() { - return platform.getCustomOptionList(); - } - - @Override - public VMProperty getDefaultProperty() { - return platform.getCustomDefaultProperty(); - } - - @Override - public ItemList getItemList() { - return platform.getCustomItemList(); - } -} diff --git a/src/org/tizen/emulator/manager/platform/CustomPropertyTemplateLoader.java b/src/org/tizen/emulator/manager/platform/CustomPropertyTemplateLoader.java new file mode 100644 index 0000000..520f605 --- /dev/null +++ b/src/org/tizen/emulator/manager/platform/CustomPropertyTemplateLoader.java @@ -0,0 +1,248 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.emulator.manager.platform; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.tizen.emulator.manager.ui.detail.item.OptionType; +import org.tizen.emulator.manager.vms.xml.template.DeviceList; +import org.tizen.emulator.manager.vms.xml.template.Item; +import org.tizen.emulator.manager.vms.xml.template.ItemList; +import org.tizen.emulator.manager.vms.xml.template.ObjectFactory; +import org.tizen.emulator.manager.vms.xml.template.Option; +import org.tizen.emulator.manager.vms.xml.template.PropertyList; + +public class CustomPropertyTemplateLoader { + public static ObjectFactory factory = new ObjectFactory(); + + public static ItemList makeCustomPropertyTemplate(List templateList) { + if (templateList.size() == 0) { + return null; + + } else if (templateList.size() == 1) { + ItemList template = cloneTemplate(templateList.get(0)); + template.setImage(null); + return template; + + } else { // Make union set + ItemList base = cloneTemplate(templateList.get(0)); + for (int i=1 ; i < templateList.size() ; i++) { + addToBase(base,templateList.get(i)); + } + return base; + } + } + + private static void addToBase(ItemList base, ItemList newOne) { + // Property list add + PropertyList newPropertyList = newOne.getPropertyList(); + PropertyList basePropertyList = base.getPropertyList(); + if (newPropertyList != null) { + if (basePropertyList == null) { + basePropertyList = factory.createPropertyList(); + base.setPropertyList(basePropertyList); + } + for (Item newItem : newPropertyList.getItem()) { + boolean itemExistInBase = false; + for (Item baseItem : basePropertyList.getItem()) { + if (baseItem.getName().equals(newItem.getName())) { + itemExistInBase = true; + joinItem(baseItem, newItem); + } + } + if (!itemExistInBase) { + basePropertyList.getItem().add(cloneItem(newItem)); + } + } + } + + // Device list add + DeviceList newDeviceList = newOne.getDeviceList(); + DeviceList baseDeviceList = base.getDeviceList(); + if (newDeviceList != null) { + if (baseDeviceList == null) { + baseDeviceList = factory.createDeviceList(); + base.setDeviceList(baseDeviceList); + } + for (Item newItem : newDeviceList.getItem()) { + boolean itemExistInBase = false; + for (Item baseItem : baseDeviceList.getItem()) { + if (baseItem.getName().equals(newItem.getName())) { + itemExistInBase = true; + joinItem(baseItem, newItem); + } + } + if (!itemExistInBase) { + baseDeviceList.getItem().add(cloneItem(newItem)); + } + } + } + } + + private static void joinItem(Item baseItem, Item newItem) { + // join sub items + for (Item newSub : newItem.getItem()) { + boolean itemExistInBase = false; + for (Item baseSub : baseItem.getItem()) { + if (baseSub.getName().equals(newSub.getName())) { + itemExistInBase = true; + joinItem(baseSub, newSub); + } + } + if (!itemExistInBase) { + baseItem.getItem().add(cloneItem(newSub)); + } + } + // join options + for (Option newOption : newItem.getOption()) { + boolean optionExistInBase = false; + for (Option baseOption : baseItem.getOption()) { + if (baseOption.getName().equals(newOption.getName())) { + optionExistInBase = true; + if (isListOption(baseOption, newOption)) { + joinOption(baseOption, newOption); + } + } + } + + if (!optionExistInBase) { + baseItem.getOption().add(cloneOption(newOption)); + } + } + + } + + private static void joinOption(Option baseOption, Option newOption) { + baseOption.setValue(joinCommaString(baseOption.getValue(), newOption.getValue())); + } + + private static String joinCommaString(String base, String newOne) { + List optionList = new ArrayList(); + if (base != null) { + String[] split = base.split(","); + for (String str : split) { + optionList.add(str.trim()); + } + } + if (newOne != null) { + String[] split = newOne.split(","); + for (String str : split) { + optionList.add(str.trim()); + } + } + + if (optionList.size() > 0) { + Set optionSet = new HashSet(); + optionSet.addAll(optionList); + optionList.clear(); + optionList.addAll(optionSet); +// Collections.sort(optionList); + StringBuilder sb = new StringBuilder(); + + for (int i=0 ; iskinList = new ArrayList(); - protected EMPlugin plugin; + private String platformName = null; + private String platformPath = null; + private String profile = null; + private Profile profileClass = null; + private String version = null; + //private static int id = 1; + + private ArrayListskinList = new ArrayList(); + private EMPlugin plugin; + + // for standard base images + private List propertyList = new ArrayList(); + private List itemListList = new ArrayList(); + private VMProperty defaultProperty; + private ItemList defaultItemList; // for custom base image private ItemList customItemList; - private VMProperty customDefaultProperty; - private List customOptionList; + + public static JAXBContext templateContext = null; + + static { + try { + templateContext = JAXBContext.newInstance(ItemList.class); + } catch (JAXBException e){ + EMLogger.getLogger().info(e.getMessage()); + } + } protected Platform() { } @@ -86,6 +98,7 @@ public class Platform { loadSkins(); loadPlugin(); + loadTemplate(); } public static String getPlatformPath(String platformName) { @@ -99,40 +112,19 @@ public class Platform { return ""; } - // Load option list for each image. - public List loadOptionList(ItemList itemTemplate) { - if (plugin != null) { - ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory); - IOptionFactory f = (IOptionFactory)(exItem.createInstance()); - if (f != null) { - return f.makeOptionList(itemTemplate); - } - } - return null; - } - - // Load option list for custom image - public List getCustomOptionList() { - if (customOptionList == null) { - if (plugin != null) { - ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory); - IOptionFactory f = (IOptionFactory)(exItem.createInstance()); - if (f != null) { - customOptionList = f.makeOptionList(getCustomItemList()); - } - } - } - return customOptionList; - } - public String getName() { return platformName; } + // TODO: delete this function public String getPluginPlatformName() { return platformName; } + public String getPlatformPath() { + return platformPath; + } + public String getProfile() { return profile; } @@ -141,57 +133,96 @@ public class Platform { return version; } - public boolean isOldVersion() { - return isOldVersion; + public EMPlugin getPlugin() { + return plugin; } - private void createCustomDefaultProperty() { - // If custom default property not exist, load standard property - for (BaseImage image : getProfileClass().getImageList()) { - if (image.getPlatform() == this) { - if (image.getType() != null && image.getType().equals("default")) { - customDefaultProperty = image.getDefaultProperty(); - } + public Profile getProfileClass() { + return profileClass; + } + + public ItemList getCustomItemList() { + return customItemList; + } + + public VMProperty getCustomDefaultProperty() { + return defaultProperty; + } + + // Load option list for each image. + public List loadOptionList(ItemList itemTemplate) { + if (plugin != null) { + ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory); + IOptionFactory f = (IOptionFactory)(exItem.createInstance()); + if (f != null) { + return f.makeOptionList(itemTemplate); } } + return null; + } - if (customDefaultProperty == null) { - for (BaseImage image : getProfileClass().getImageList()) { - if (image.getPlatform() == this) { - customDefaultProperty = image.getDefaultProperty(); + private void loadTemplate() { + File template = new File(platformPath + File.separator + + FilePathResources.getPlatformTemplatePath()); + if (template == null || !template.exists() || !template.isDirectory()) { + return; + } + for (File f : template.listFiles()) { + if (f.getName().contains(PlatformStringResources.TEMPLATE)) { // ui template file for detail view + JAXBElement element = null; + try { + Unmarshaller unmarshaller = templateContext.createUnmarshaller(); + element = unmarshaller.unmarshal(new StreamSource(f), ItemList.class); + } catch (JAXBException e) { + e.printStackTrace(); + EMLogger.getLogger().warning("Can not load config file( " + + f.getName() + ")" + StringResources.NEW_LINE + e.getMessage()); + element = null; + } + if (element != null) { + ItemList itemList = element.getValue(); + if (itemList != null) { + itemListList.add(itemList); + + // setting default item list + if (f.getName().contains(PlatformStringResources.STANDARD)) { + this.defaultItemList = itemList; + } + } + } + } else { // property file + EmulatorVMList vmList = EmulatorVMList.getInstance(); + VMProperty defaultProperty = vmList.parseXML(f); + if (defaultProperty != null) { + propertyList.add(defaultProperty); + + // setting default property + if (f.getName().contains(PlatformStringResources.STANDARD)) { + this.defaultProperty = defaultProperty; + } } } } - // TODO: if customDefaultProperty is still null ??? + + customItemList = CustomPropertyTemplateLoader.makeCustomPropertyTemplate(itemListList); } - private void createCustomItemList() { - List templateList = new ArrayList(); - for (BaseImage image : getProfileClass().getImageList()) { - if (image.getPlatform() == this) { - templateList.add(image.getItemList()); + public ItemList findItemList(String imageName) { + for (ItemList itemList : itemListList) { + if (itemList.getImage().equals(imageName)) { + return itemList; } } - customItemList = createCustomTemplate(templateList); + return defaultItemList; } - private ItemList createCustomTemplate(List templateList) { - - if (templateList.size() == 0) { - return null; - - } else if (templateList.size() == 1) { - ItemList template = cloneTemplate(templateList.get(0)); - template.setImage(null); - return template; - - } else { // Make union set - ItemList base = cloneTemplate(templateList.get(0)); - for (int i=1 ; i < templateList.size() ; i++) { - addToBase(base,templateList.get(i)); + public VMProperty findVMProperty(String imageName) { + for (VMProperty property : propertyList) { + if (property.getPropertyFile().getName().contains(imageName)) { + return property; } - return base; } + return defaultProperty; } private void loadPlugin() { @@ -204,8 +235,8 @@ public class Platform { File pluginJar = null; File[] fileList = pluginDir.listFiles(); for (File file : fileList) { - if (file.getName().startsWith(PlatformStringResources.PluginFilePrefix) && - file.getName().endsWith(".jar")) { + if (file.getName().startsWith(PlatformStringResources.PLUGIN_PREFIX) && + file.getName().endsWith(PlatformStringResources.PLUGIN_EXTENSION)) { pluginJar = file; break; } @@ -280,220 +311,4 @@ public class Platform { public ArrayList findGeneralSkinList() { return SkinList.getInstance().findGeneralSkinList(skinList); } - - public EMPlugin getPlugin() { - return plugin; - } - - public void setPlugin(EMPlugin plugin) { - this.plugin = plugin; - } - - public Profile getProfileClass() { - return profileClass; - } - - public void setProfileClass(Profile profileClass) { - this.profileClass = profileClass; - } - - public ItemList getCustomItemList() { - if (customItemList == null) { - createCustomItemList(); - } - - return customItemList; - } - - public VMProperty getCustomDefaultProperty() { - if (customDefaultProperty == null) { - createCustomDefaultProperty(); - } - return customDefaultProperty; - } - - public static ObjectFactory factory = new ObjectFactory(); - private void addToBase(ItemList base, ItemList newOne) { - // Property list add - PropertyList newPropertyList = newOne.getPropertyList(); - PropertyList basePropertyList = base.getPropertyList(); - if (newPropertyList != null) { - if (basePropertyList == null) { - basePropertyList = factory.createPropertyList(); - base.setPropertyList(basePropertyList); - } - for (Item newItem : newPropertyList.getItem()) { - boolean itemExistInBase = false; - for (Item baseItem : basePropertyList.getItem()) { - if (baseItem.getName().equals(newItem.getName())) { - itemExistInBase = true; - joinItem(baseItem, newItem); - } - } - if (!itemExistInBase) { - basePropertyList.getItem().add(cloneItem(newItem)); - } - } - } - - // Device list add - DeviceList newDeviceList = newOne.getDeviceList(); - DeviceList baseDeviceList = base.getDeviceList(); - if (newDeviceList != null) { - if (baseDeviceList == null) { - baseDeviceList = factory.createDeviceList(); - base.setDeviceList(baseDeviceList); - } - for (Item newItem : newDeviceList.getItem()) { - boolean itemExistInBase = false; - for (Item baseItem : baseDeviceList.getItem()) { - if (baseItem.getName().equals(newItem.getName())) { - itemExistInBase = true; - joinItem(baseItem, newItem); - } - } - if (!itemExistInBase) { - baseDeviceList.getItem().add(cloneItem(newItem)); - } - } - } - } - - - private void joinItem(Item baseItem, Item newItem) { - // join sub items - for (Item newSub : newItem.getItem()) { - boolean itemExistInBase = false; - for (Item baseSub : baseItem.getItem()) { - if (baseSub.getName().equals(newSub.getName())) { - itemExistInBase = true; - joinItem(baseSub, newSub); - } - } - if (!itemExistInBase) { - baseItem.getItem().add(cloneItem(newSub)); - } - } - // join options - for (Option newOption : newItem.getOption()) { - boolean optionExistInBase = false; - for (Option baseOption : baseItem.getOption()) { - if (baseOption.getName().equals(newOption.getName())) { - optionExistInBase = true; - if (isListOption(baseOption, newOption)) { - joinOption(baseOption, newOption); - } - } - } - - if (!optionExistInBase) { - baseItem.getOption().add(cloneOption(newOption)); - } - } - - } - - private void joinOption(Option baseOption, Option newOption) { - baseOption.setValue(joinCommaString(baseOption.getValue(), newOption.getValue())); - } - - - private String joinCommaString(String base, String newOne) { - List optionList = new ArrayList(); - if (base != null) { - String[] split = base.split(","); - for (String str : split) { - optionList.add(str.trim()); - } - } - if (newOne != null) { - String[] split = newOne.split(","); - for (String str : split) { - optionList.add(str.trim()); - } - } - - if (optionList.size() > 0) { - Set optionSet = new HashSet(); - optionSet.addAll(optionList); - optionList.clear(); - optionList.addAll(optionSet); -// Collections.sort(optionList); - StringBuilder sb = new StringBuilder(); - - for (int i=0 ; i