Property: move function loading property and property-template
authorjihye424.kim <jihye424.kim@samsung.com>
Thu, 28 May 2015 07:18:54 +0000 (16:18 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 29 May 2015 02:06:45 +0000 (11:06 +0900)
- move function loading property to 'Platform' class from 'Bsae Image' class
- delete 'CustomBaseImage' class

Change-Id: Ib173a5c61bd497f0381d39b83855221f00825635
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/console/ConsoleCreateVM.java
src/org/tizen/emulator/manager/platform/BaseImage.java
src/org/tizen/emulator/manager/platform/CustomBaseImage.java [deleted file]
src/org/tizen/emulator/manager/platform/CustomPropertyTemplateLoader.java [new file with mode: 0644]
src/org/tizen/emulator/manager/platform/Platform.java
src/org/tizen/emulator/manager/platform/PlatformStringResources.java
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/vms/VMPropertyValue.java

index 96f1f67..178cb4d 100644 (file)
@@ -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);
                                        }
index f907680..f712b58 100644 (file)
@@ -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<IOption> 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<IOption> 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<ItemList> 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 (file)
index ac615a0..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Emulator Manager
- *
- * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * JiHye Kim <jihye1128.kim@samsung.com>
- * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
- * SeokYeon Hwang <syeon.hwang@samsung.com>
- *
- * 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<IOption> 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 (file)
index 0000000..520f605
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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<ItemList> 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<String> optionList = new ArrayList<String>();
+               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<String> optionSet = new HashSet<String>();
+                       optionSet.addAll(optionList);
+                       optionList.clear();
+                       optionList.addAll(optionSet);
+//                     Collections.sort(optionList);
+                       StringBuilder sb = new StringBuilder();
+
+                       for (int i=0 ; i<optionList.size() ; i++) {
+                               sb.append(optionList.get(i));
+                               if (i < optionList.size()-1) {
+                                       sb.append(",");
+                               }
+                       }
+
+                       return sb.toString();
+               }
+
+               return null;
+       }
+
+       private static ItemList cloneTemplate(ItemList template) {
+               ItemList newTemplate = factory.createItemList();
+               newTemplate.setProfile(template.getProfile());
+               newTemplate.setImage(template.getImage());
+
+               // clone property list
+               PropertyList propertyList = template.getPropertyList();
+               if (propertyList != null) {
+                       PropertyList newPropertyList = factory.createPropertyList();
+                       newTemplate.setPropertyList(newPropertyList);
+
+                       for (Item item : propertyList.getItem()) {
+                               newPropertyList.getItem().add(cloneItem(item));
+                       }
+               }
+
+               // clone device list.
+               DeviceList deviceList = template.getDeviceList();
+               if (deviceList != null) {
+                       DeviceList newDeviceList = factory.createDeviceList();
+                       newTemplate.setDeviceList(newDeviceList);
+
+                       for (Item item : deviceList.getItem()) {
+                               newDeviceList.getItem().add(cloneItem(item));
+                       }
+               }
+
+               return newTemplate;
+       }
+
+       private static Item cloneItem(Item item) {
+               Item newItem = factory.createItem();
+               newItem.setType(item.getType());
+               newItem.setName(item.getName());
+               newItem.setTitle(item.getTitle());
+
+               for (Option option : item.getOption()) {
+                       newItem.getOption().add(cloneOption(option));
+               }
+
+               for (Item subItem : item.getItem()) {
+                       newItem.getItem().add(cloneItem(subItem));
+               }
+
+               return newItem;
+       }
+
+       private static Option cloneOption(Option option) {
+               Option newOption = factory.createOption();
+               newOption.setName(option.getName());
+               newOption.setValue(option.getValue());
+               return newOption;
+       }
+
+       private static boolean isListOption(Option baseOption, Option newOption) {
+               if (baseOption.getName().equals(OptionType.COMBO_LIST.getName())
+                               && newOption.getName().equals(OptionType.COMBO_LIST.getName())) {
+                       return true;
+               }
+
+               return false;
+       }
+}
index fec8a77..9e6245d 100644 (file)
@@ -33,9 +33,13 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
+
+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.plugin.EMPlugin;
@@ -44,35 +48,43 @@ import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
-import org.tizen.emulator.manager.ui.detail.item.OptionType;
+import org.tizen.emulator.manager.vms.EmulatorVMList;
 import org.tizen.emulator.manager.vms.RESOLUTION;
 import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.option.IOption;
 import org.tizen.emulator.manager.vms.option.IOptionFactory;
-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 Platform {
        // platform name = profile + version = profile-version
-       protected String platformName = null;
-       protected String platformPath = null;
-       protected String profile = null;
-       protected Profile profileClass = null;
-       protected String version = null;
-       protected static int id = 1;
-       protected boolean isOldVersion = false;
-
-       protected ArrayList<Skin>skinList = new ArrayList<Skin>();
-       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 ArrayList<Skin>skinList = new ArrayList<Skin>();
+       private EMPlugin plugin;
+
+       // for standard base images
+       private List<VMProperty> propertyList = new ArrayList<VMProperty>();
+       private List<ItemList> itemListList = new ArrayList<ItemList>();
+       private VMProperty defaultProperty;
+       private ItemList defaultItemList;
 
        // for custom base image
        private ItemList customItemList;
-       private VMProperty customDefaultProperty;
-       private List<IOption> 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<IOption> 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<IOption> 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<IOption> 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<ItemList> 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<ItemList> templateList = new ArrayList<ItemList>();
-               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<ItemList> 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<Skin> 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<String> optionList = new ArrayList<String>();
-               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<String> optionSet = new HashSet<String>();
-                       optionSet.addAll(optionList);
-                       optionList.clear();
-                       optionList.addAll(optionSet);
-//                     Collections.sort(optionList);
-                       StringBuilder sb = new StringBuilder();
-
-                       for (int i=0 ; i<optionList.size() ; i++) {
-                               sb.append(optionList.get(i));
-                               if (i < optionList.size()-1) {
-                                       sb.append(",");
-                               }
-                       }
-
-                       return sb.toString();
-               }
-
-               return null;
-       }
-
-       private ItemList cloneTemplate(ItemList template) {
-               ItemList newTemplate = factory.createItemList();
-               newTemplate.setProfile(template.getProfile());
-               newTemplate.setImage(template.getImage());
-
-               // clone property list
-               PropertyList propertyList = template.getPropertyList();
-               if (propertyList != null) {
-                       PropertyList newPropertyList = factory.createPropertyList();
-                       newTemplate.setPropertyList(newPropertyList);
-
-                       for (Item item : propertyList.getItem()) {
-                               newPropertyList.getItem().add(cloneItem(item));
-                       }
-               }
-
-               // clone device list.
-               DeviceList deviceList = template.getDeviceList();
-               if (deviceList != null) {
-                       DeviceList newDeviceList = factory.createDeviceList();
-                       newTemplate.setDeviceList(newDeviceList);
-
-                       for (Item item : deviceList.getItem()) {
-                               newDeviceList.getItem().add(cloneItem(item));
-                       }
-               }
-
-               return newTemplate;
-       }
-
-       private Item cloneItem(Item item) {
-               Item newItem = factory.createItem();
-               newItem.setType(item.getType());
-               newItem.setName(item.getName());
-               newItem.setTitle(item.getTitle());
-
-               for (Option option : item.getOption()) {
-                       newItem.getOption().add(cloneOption(option));
-               }
-
-               for (Item subItem : item.getItem()) {
-                       newItem.getItem().add(cloneItem(subItem));
-               }
-
-               return newItem;
-       }
-
-       private Option cloneOption(Option option) {
-               Option newOption = factory.createOption();
-               newOption.setName(option.getName());
-               newOption.setValue(option.getValue());
-               return newOption;
-       }
-
-       private boolean isListOption(Option baseOption, Option newOption) {
-               if (baseOption.getName().equals(OptionType.COMBO_LIST.getName())
-                               && newOption.getName().equals(OptionType.COMBO_LIST.getName())) {
-                       return true;
-               }
-
-               return false;
-       }
 }
index c6fd521..b6cdb22 100644 (file)
 package org.tizen.emulator.manager.platform;
 
 public class PlatformStringResources {
+       public static String MOBILE_PROFILE = "mobile";
 
-       public static String OldMobileProfile = "phone";
-       public static String MobileProfile = "mobile";
+       public static String PLUGIN_PREFIX = "em-plugin";
+       public static String PLUGIN_EXTENSION = "jar";
 
-       public static String PluginFilePrefix = "em-plugin";
-       public static String TemplateFile = "standard.xml";
        public static String CONFIG_EXTENSION = "xml";
        public static String TEMPLATE = "template";
+       public static String STANDARD = "standard";
 }
index 0db9cbe..573aba5 100644 (file)
@@ -94,7 +94,7 @@ public class Profile {
                Platform platform = ProfileList.getProfile(createProperty.getImageProfile()).
                                getPlatformByVersion(createProperty.getImageVersion());
                try {
-                       return new CustomBaseImage(platform, createProperty.getBaseImagePath());
+                       return new BaseImage(platform, createProperty.getBaseImagePath());
                } catch (IOException e) {
                        EMLogger.getLogger().warning("Failed to find baseimage. No platform");
                        return null;
@@ -183,7 +183,7 @@ public class Profile {
                                        if (vm.getImagePlatform().equals(p.getName())) {
                                                try {
                                                        vm.getPropertyValue().baseImage
-                                                               = new CustomBaseImage(p,
+                                                               = new BaseImage(p,
                                                                                vm.getBaseImagePath());
                                                } catch (IOException e) {
                                                        EMLogger.getLogger().warning(e.getMessage());
index ffc0fff..4726a6b 100644 (file)
@@ -37,7 +37,6 @@ import java.util.List;
 
 import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.platform.BaseImage;
-import org.tizen.emulator.manager.platform.CustomBaseImage;
 import org.tizen.emulator.manager.platform.PlatformStringResources;
 import org.tizen.emulator.manager.platform.Skin;
 import org.tizen.emulator.manager.resources.StringResources;
@@ -129,11 +128,7 @@ public class VMPropertyValue implements Cloneable {
                baseName        = image.getName();
                skinShape = image.getSkinShape();
 
-               if (image instanceof CustomBaseImage) {
-                       isStandard      = false;
-               } else {
-                       isStandard = true;
-               }
+               isStandard      = image.isStandard();
 
                settingConfigure(template);
        }
@@ -155,7 +150,7 @@ public class VMPropertyValue implements Cloneable {
                        if (property.getImageProfile() != null) {
                                profile = property.getImageProfile();
                        } else {
-                               profile = PlatformStringResources.MobileProfile;
+                               profile = PlatformStringResources.MOBILE_PROFILE;
                        }
 
                        version = property.getConfiguration().getBaseInformation().getDiskImage().getVersion();