Device Template: make device template class
authorjihye424.kim <jihye424.kim@samsung.com>
Thu, 1 Oct 2015 06:03:35 +0000 (15:03 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Thu, 1 Oct 2015 06:03:35 +0000 (15:03 +0900)
- device template class keep information of 'DeviceTemplat.xml'
- profile has device template list

Change-Id: I8ec73f944e7b12eb203404ddba6d34b9410e2c14
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/devices/DeviceTemplate.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/DeviceTemplateList.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/SubDevice.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/SubDeviceItem.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/SubDeviceItemValue.java [new file with mode: 0644]
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/platform/ProfileList.java

diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplate.java b/src/org/tizen/emulator/manager/devices/DeviceTemplate.java
new file mode 100644 (file)
index 0000000..f75c2b6
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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 <sangho.p@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.devices;
+
+import java.io.File;
+
+import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
+
+public class DeviceTemplate {
+       private File templateFile;
+       private DeviceConfiguration conf;
+       private DeviceTemplateValue value;
+
+       public DeviceTemplate(File file, DeviceConfiguration conf) {
+               this.templateFile = file;
+               this.conf = conf;
+       }
+
+       public DeviceTemplate(DeviceTemplateValue value) {
+               this.value = value;
+       }
+
+       public DeviceTemplateValue getValue() {
+               if (value == null) {
+                       value = new DeviceTemplateValue(this);
+               }
+
+               return value;
+       }
+
+       public File getTemplateFile() {
+               return templateFile;
+       }
+
+       public void setTemplateFile(File propertyFile) {
+               this.templateFile = propertyFile;
+       }
+
+       public DeviceConfiguration getConf() {
+               return conf;
+       }
+
+       public void setConf(DeviceConfiguration conf) {
+               this.conf = conf;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java
new file mode 100644 (file)
index 0000000..0cda77a
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * 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 <sangho.p@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.devices;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
+import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.StringResources;
+
+public class DeviceTemplateList {
+       static private JAXBContext context = null;
+       static {
+               try {
+                       context = JAXBContext.newInstance(DeviceConfiguration.class);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().info(e.getMessage());
+               }
+       }
+
+       private static List<DeviceTemplate> templateList = null;
+
+       public static DeviceTemplate[] getDeviceTemplateList(boolean isRefresh) {
+               if (templateList == null || isRefresh) {
+                       templateList = loadTemplates();
+               }
+               return templateList.toArray(new DeviceTemplate[templateList.size()]);
+       }
+
+       public static void addTemplate(DeviceTemplate template) {
+               if (template != null) {
+                       templateList.add(template);
+               }
+       }
+
+       public static void removeTemplate(DeviceTemplate template) {
+               if (template != null) {
+                       templateList.remove(template);
+               }
+       }
+
+       public static void reloadDeviceConfiguration(DeviceTemplate template) {
+               DeviceConfiguration conf = parseXML(template.getTemplateFile());
+               template.setConf(conf);
+       }
+
+       public static boolean saveDeviceConfiguration(DeviceTemplate template) {
+               return saveDeviceConfiguration(template, null);
+       }
+
+       public static boolean saveDeviceConfiguration(DeviceTemplate template, File outputFile) {
+               if (outputFile == null) {
+                       outputFile = template.getTemplateFile();
+               }
+               return storeXML(template.getConf(), outputFile);
+       }
+
+       private synchronized static List<DeviceTemplate> loadTemplates() {
+               List<DeviceTemplate> deviceList = new ArrayList<DeviceTemplate>();
+               // standard
+               loadTemplates(FilePathResources.getToolEmulatorDevicePath(), deviceList);
+
+               // custom
+               loadTemplates(FilePathResources.getTizenSdkDataDevicePath(), deviceList);
+
+               return deviceList;
+       }
+
+       private static void loadTemplates(String dirPath, List<DeviceTemplate> deviceList) {
+               File deviceDir = new File(dirPath);
+               if (!deviceDir.exists() || !deviceDir.isDirectory()) {
+                       return;
+               }
+
+               DeviceTemplate property = null;
+
+               File[] devices = deviceDir.listFiles(new FileFilter() {
+                       @Override
+                       public boolean accept(File file) {
+                               if(!file.isFile()) {
+                                       return false;
+                               }
+                               if (file.isHidden()) {
+                                       return false;
+                               }
+                               return true;
+                       }
+               });
+
+               if (devices == null) {
+                       return;
+               }
+
+               for (File device : devices) {
+                       if (!device.getAbsolutePath().endsWith("xml")) {
+                               continue;
+                       }
+
+                       DeviceConfiguration conf = parseXML(device);
+                       if (conf != null) {
+                               property = new DeviceTemplate(device, conf);
+                               deviceList.add(property);
+                       }
+               }
+       }
+
+       private static DeviceConfiguration parseXML(File device) {
+               if (context == null) {
+                       EMLogger.getLogger().warning("Can not load device template file ("
+                                       + device.getName() + ")"
+                                       + StringResources.NEW_LINE
+                                       + "Failed to make JAXBContext from DeviceConfiguration class");
+                       return null;
+               }
+
+               JAXBElement<DeviceConfiguration> element = null;
+
+               try {
+                       Unmarshaller unmarshaller = context.createUnmarshaller();
+                       element = unmarshaller.unmarshal(new StreamSource(device), DeviceConfiguration.class);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().warning("Can not load device template file ( " //$NON-NLS-1$
+                                                       + device.getName() + ")" + StringResources.NEW_LINE + e.getMessage()); //$NON-NLS-1$
+                       return null;
+               }
+
+               return element.getValue();
+       }
+
+       private static boolean storeXML(DeviceConfiguration conf, File outputFile) {
+               if (context == null) {
+                       EMLogger.getLogger().warning("Can not save device template file (" //$NON-NLS-1$
+                                       + outputFile.getName() + ")"
+                                       + StringResources.NEW_LINE
+                                       + "Failed to make JAXBContext from DeviceConfiguration class");
+                       return false;
+               }
+
+               if (outputFile == null) {
+                       return false;
+               }
+
+               FileOutputStream fos = null;
+               Marshaller marshaller;
+               try {
+                       marshaller = context.createMarshaller();
+                       marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
+                       marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+
+                       if (!outputFile.exists()) {
+                               outputFile.getParentFile().mkdirs();
+                       }
+
+                       fos = new FileOutputStream(outputFile);
+                       marshaller.marshal(conf, fos);
+               } catch (JAXBException e) {
+                       EMLogger.getLogger().warning("Can not save device template file (" //$NON-NLS-1$
+                                       + outputFile.getName() + ")" + StringResources.NEW_LINE + e.getMessage());
+                       return false;
+               } catch (FileNotFoundException e) {
+                       EMLogger.getLogger().warning("Can not save device template file (" //$NON-NLS-1$
+                                       + outputFile.getName() + ")" + StringResources.NEW_LINE + e.getMessage());
+                       return false;
+               } finally {
+                       if (fos != null) {
+                               try {
+                                       fos.close();
+                               } catch (IOException e) {
+                                       EMLogger.getLogger().warning("ERROR : " + e.getMessage()); //$NON-NLS-1$
+                               }
+                       }
+               }
+
+               return true;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java
new file mode 100644 (file)
index 0000000..216f680
--- /dev/null
@@ -0,0 +1,391 @@
+/*
+ * 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 <sangho.p@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.devices;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.emulator.manager.device.xml.template.Device;
+import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration;
+import org.tizen.emulator.manager.device.xml.template.DeviceItem;
+import org.tizen.emulator.manager.device.xml.template.DeviceItemValue;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.platform.Skin;
+import org.tizen.emulator.manager.vms.RESOLUTION;
+
+public class DeviceTemplateValue implements Cloneable {
+       private DeviceTemplate template;
+       private String name = "";
+       private String type;
+       private String profile;
+       private String extenstion;
+       private int priority;
+       private String manufacturer;
+
+
+       private RESOLUTION resolution;
+       private int displayWidth = 0;
+       private int displayHeight = 0;
+       private String displaySizeUnit = "inch";
+       private double displaySize = 0;
+       private int displayDPI = 0;
+
+       private String skinName = "";
+       private String skinPath = "";
+       private Skin skin;
+
+       private String ramSizeUnit = "MB";
+       private int ramSize = 512;
+       private int cpuCount = 1;
+
+       private List<SubDevice> additionalDevices = new ArrayList<SubDevice>();
+
+       public DeviceTemplateValue(DeviceTemplate template) {
+               this.template = template;
+
+               settingConfigure(template);
+       }
+
+       void settingConfigure(DeviceTemplate template) {
+               if (template == null) {
+                       return;
+               }
+
+               DeviceConfiguration conf = template.getConf();
+               if (conf == null) {
+                       return;
+               }
+
+               if (conf.getBaseInformation() != null) {
+                       name = conf.getBaseInformation().getName();
+                       type = conf.getBaseInformation().getType();
+                       profile = conf.getBaseInformation().getProfile();
+                       extenstion = conf.getBaseInformation().getExtension();
+                       priority = conf.getBaseInformation().getPriority().intValue();
+                       manufacturer = conf.getBaseInformation().getManufacturer();
+               }
+
+               if (conf.getDisplay() != null) {
+                       if (conf.getDisplay().getResolution() != null) {
+                               displayWidth = conf.getDisplay().getResolution().getWidth();
+                               displayHeight = conf.getDisplay().getResolution().getHeight();
+                       }
+                       if (conf.getDisplay().getScreenSize() != null) {
+                               displaySizeUnit = conf.getDisplay().getScreenSize().getUnit();
+                               displaySize = conf.getDisplay().getScreenSize().getValue();
+                       } else {
+                               displaySize = 0.0; // TODO
+                       }
+
+                       displayDPI = calculatorDPI();
+
+                       for (RESOLUTION r : RESOLUTION.values()) {
+                               if (r.getResolution().getWidth() == displayWidth
+                                               && r.getResolution().getHeight() == displayHeight
+                                               && r.getDPI() == displayDPI) {
+                                       resolution = r;
+                                       break;
+                               }
+                       }
+                       if (resolution == null) {
+                               resolution = new RESOLUTION(displayWidth, displayHeight, "", displayDPI);
+                       }
+
+
+                       if (conf.getDisplay().getSkin() != null) {
+                               skinName = conf.getDisplay().getSkin().getName();
+                               skinPath = conf.getDisplay().getSkin().getPath();
+                       }
+
+                       if (skinPath != null) {
+                               try {
+                                       skin = new Skin(new File(skinPath));
+                               } catch (IOException e) {
+                                       skin = null;
+                                       EMLogger.getLogger().warning("Failed to create skin." + e.getMessage()); //$NON-NLS-1$
+                               }
+                       }
+               }
+
+               if (conf.getCpu() != null) {
+                       cpuCount = conf.getCpu().getCount();
+               }
+
+               if (conf.getRam() != null) {
+                       ramSizeUnit = conf.getRam().getSize().getUnit();
+                       ramSize = conf.getRam().getSize().getValue();
+               }
+
+               if (conf.getAdditionalDevices() != null) {
+                       additionalDevices.clear();
+                       for (Device device : conf.getAdditionalDevices().getDevice()) {
+                               SubDevice aDevice = new SubDevice();
+                               aDevice.setName(device.getName());
+                               for (DeviceItem deviceItem : device.getDeviceItem()) {
+                                       SubDeviceItem item = makeSubDeviceItem(deviceItem);
+                                       if (item != null) {
+                                               aDevice.addSubDeviceItem(item);
+                                       }
+                               }
+                               additionalDevices.add(aDevice);
+                       }
+               }
+       }
+
+       private SubDeviceItem makeSubDeviceItem(DeviceItem deviceItem) {
+               SubDeviceItem item = new SubDeviceItem(deviceItem.getId());
+               item.setName(deviceItem.getName());
+               item.setSupport(deviceItem.isSupport());
+               for (DeviceItemValue value : deviceItem.getDeviceItemValue()) {
+                       item.addDeviceItemVale(value.getName(), value.getUnit(), value.getValue());
+               }
+               return item;
+       }
+
+       private int calculatorDPI () {
+               return (int) Math.round(Math.hypot(displayWidth, displayHeight) / displaySize);
+       }
+
+       public DeviceTemplate getTemplate() {
+               return template;
+       }
+
+       public void setTemplate(DeviceTemplate template) {
+               this.template = template;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getType() {
+               return type;
+       }
+
+       public void setType(String type) {
+               this.type = type;
+       }
+
+       public String getExtenstion() {
+               return extenstion;
+       }
+
+       public void setExtenstion(String extenstion) {
+               this.extenstion = extenstion;
+       }
+
+       public String getProfile() {
+               return profile;
+       }
+
+       public void setProfile(String profile) {
+               this.profile = profile;
+       }
+
+       public int getPriority() {
+               return priority;
+       }
+
+       public void setPriority(int priority) {
+               this.priority = priority;
+       }
+
+       public String getManufacturer() {
+               return manufacturer;
+       }
+
+       public void setManufacturer(String manufacturer) {
+               this.manufacturer = manufacturer;
+       }
+
+       public RESOLUTION getResolution() {
+               return resolution;
+       }
+
+       public void setResolution(RESOLUTION resolution) {
+               this.resolution = resolution;
+       }
+
+       public int getDisplayWidth() {
+               return displayWidth;
+       }
+
+       public void setDisplayWidth(int displayWidth) {
+               this.displayWidth = displayWidth;
+       }
+
+       public int getDisplayHeight() {
+               return displayHeight;
+       }
+
+       public void setDisplayHeight(int displayHeight) {
+               this.displayHeight = displayHeight;
+       }
+
+       public double getDisplaySize() {
+               return displaySize;
+       }
+
+       public void setDisplaySize(double displaySize) {
+               this.displaySize = displaySize;
+       }
+
+       public String getDisplaySizeUnit() {
+               return displaySizeUnit;
+       }
+
+       public void setDisplaySizeUnit(String displaySizeUnit) {
+               this.displaySizeUnit = displaySizeUnit;
+       }
+
+       public int getDisplayDPI() {
+               return displayDPI;
+       }
+
+       public void setDisplayDPI(int displayDPI) {
+               this.displayDPI = displayDPI;
+       }
+
+       public String getSkinName() {
+               return skinName;
+       }
+
+       public void setSkinName(String skinName) {
+               this.skinName = skinName;
+       }
+
+       public String getSkinPath() {
+               return skinPath;
+       }
+
+       public void setSkinPath(String skinPath) {
+               this.skinPath = skinPath;
+       }
+
+       public Skin getSkin() {
+               return skin;
+       }
+
+       public void setSkin(Skin skin) {
+               this.skin = skin;
+       }
+
+       public int getRamSize() {
+               return ramSize;
+       }
+
+       public void setRamSize(int ramSize) {
+               this.ramSize = ramSize;
+       }
+
+       public String getRamSizeUnit() {
+               return ramSizeUnit;
+       }
+
+       public void setRamSizeUnit(String ramSizeUnit) {
+               this.ramSizeUnit = ramSizeUnit;
+       }
+
+       public int getCpuCount() {
+               return cpuCount;
+       }
+
+       public void setCpuCount(int cpuCount) {
+               this.cpuCount = cpuCount;
+       }
+
+       public List<SubDevice> getAdditionalDevices() {
+               return additionalDevices;
+       }
+
+       public void setAdditionalDevices(List<SubDevice> additionalDevices) {
+               this.additionalDevices = additionalDevices;
+       }
+
+       @Override
+       public DeviceTemplateValue clone() {
+               DeviceTemplateValue value = new DeviceTemplateValue(template);
+               return value;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj) {
+                       return true;
+               }
+
+               if (!(obj instanceof DeviceTemplateValue)) {
+                       return false;
+               }
+
+               DeviceTemplateValue dest = (DeviceTemplateValue)obj;
+               // TODO
+               if (!isAdditionalDeviceEquals(dest.getAdditionalDevices())) {
+                       return false;
+               }
+               return true;
+       }
+
+       public boolean isAdditionalDeviceEquals(List<SubDevice> destList) {
+               if (additionalDevices == null && destList == null) {
+                       return true;
+               }
+
+               if (additionalDevices == null || destList == null) {
+                       return false;
+               }
+
+               if (additionalDevices.size() != destList.size()) {
+                       return false;
+               }
+
+               for (SubDevice device : additionalDevices) {
+                       boolean equals = false;
+                       for (SubDevice destDevice : destList) {
+                               if (device.equals(destDevice)) {
+                                       equals = true;
+                                       break;
+                               }
+                       }
+                       if (!equals) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/devices/SubDevice.java b/src/org/tizen/emulator/manager/devices/SubDevice.java
new file mode 100644 (file)
index 0000000..221fad8
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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.devices;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SubDevice {
+       private String name = "";
+       private List<SubDeviceItem> items = new ArrayList<SubDeviceItem>();
+
+       public SubDevice() {
+
+       }
+
+       public SubDevice(String name) {
+               if (name != null) {
+                       this.name = name;
+               }
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public List<SubDeviceItem> getItems() {
+               return items;
+       }
+
+       public void setItems(List<SubDeviceItem> items) {
+               this.items = items;
+       }
+
+       public void addSubDeviceItem(SubDeviceItem item) {
+               if (item == null) {
+                       return;
+               }
+
+               this.items.add(item);
+       }
+
+       public void addSubDeviceItem(String id, boolean isSupport) {
+               if (id == null) {
+                       return;
+               }
+
+               SubDeviceItem item = new SubDeviceItem(id);
+               item.setSupport(isSupport);
+
+               items.add(item);
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               SubDevice destDevice = (SubDevice)obj;
+
+               if (!destDevice.name.equals(name)) {
+                       return false;
+               }
+
+               for (SubDeviceItem item : items) {
+                       boolean equals = false;
+                       for (SubDeviceItem destItem : destDevice.getItems()) {
+                               if (item.equals(destItem)) {
+                                       equals = true;
+                                       break;
+                               }
+                               if (!equals) {
+                                       return false;
+                               }
+                       }
+               }
+               return true;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/devices/SubDeviceItem.java b/src/org/tizen/emulator/manager/devices/SubDeviceItem.java
new file mode 100644 (file)
index 0000000..70514e8
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * 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.devices;
+
+import java.util.List;
+
+public class SubDeviceItem {
+       private String id = "";
+       private String name = "";
+       private boolean isSupport = false;
+       private List<SubDeviceItemValue> values;
+
+       public SubDeviceItem(String id) {
+               this.id = id;
+       }
+
+       public String getId() {
+               return id;
+       }
+
+       public String getName() {
+               return name;
+       }
+       public void setName(String name) {
+               this.name = name;
+       }
+       public boolean isSupport() {
+               return isSupport;
+       }
+
+       public void setSupport(boolean isSupport) {
+               this.isSupport = isSupport;
+       }
+
+       public List<SubDeviceItemValue> getValues() {
+               return values;
+       }
+
+       public void setValues(List<SubDeviceItemValue> values) {
+               this.values = values;
+       }
+
+       public void addDeviceItemValue(SubDeviceItemValue value) {
+               if (value == null) {
+                       return;
+               }
+
+               this.values.add(value);
+       }
+
+       public void addDeviceItemVale(String name, String unit, String value) {
+               if (name == null || name.isEmpty()) {
+                       return;
+               }
+
+               this.values.add(new SubDeviceItemValue(name, unit, value));
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               SubDeviceItem destDeviceItem = (SubDeviceItem)obj;
+
+               if (!destDeviceItem.id.equals(id)) {
+                       return false;
+               }
+
+               if (!destDeviceItem.name.equals(name)) {
+                       return false;
+               }
+
+               if (destDeviceItem.isSupport != isSupport) {
+                       return false;
+               }
+
+               for (SubDeviceItemValue value : values) {
+                       boolean equals = false;
+                       for (SubDeviceItemValue destValue : destDeviceItem.getValues()) {
+                               if (value.equals(destValue)) {
+                                       equals = true;
+                                       break;
+                               }
+                               if (!equals) {
+                                       return false;
+                               }
+                       }
+               }
+               return true;
+       }
+}
diff --git a/src/org/tizen/emulator/manager/devices/SubDeviceItemValue.java b/src/org/tizen/emulator/manager/devices/SubDeviceItemValue.java
new file mode 100644 (file)
index 0000000..745dc6b
--- /dev/null
@@ -0,0 +1,70 @@
+package org.tizen.emulator.manager.devices;
+
+public class SubDeviceItemValue {
+       private String name = "";
+       private String unit = "";
+       private String value = "";
+
+       public SubDeviceItemValue() {
+
+       }
+
+       public SubDeviceItemValue(String name) {
+               if (name != null) {
+                       this.name = name;
+               }
+       }
+
+       public SubDeviceItemValue(String name, String unit, String value) {
+               if (name != null) {
+                       this.name = name;
+               }
+
+               if (unit != null) {
+                       this.unit = unit;
+               }
+
+               if (value != null) {
+                       this.value = value;
+               }
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getUnit() {
+               return unit;
+       }
+
+       public void setUnit(String unit) {
+               this.unit = unit;
+       }
+
+       public String getValue() {
+               return value;
+       }
+
+       public void setValue(String value) {
+               this.value = value;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               SubDeviceItemValue destValue = (SubDeviceItemValue)obj;
+               if (!destValue.name.equals(name)) {
+                       return false;
+               }
+               if (!destValue.unit.equals(unit)) {
+                       return false;
+               }
+               if (!destValue.value.equals(value)) {
+                       return false;
+               }
+               return true;
+       }
+}
index 5360b29..c132509 100644 (file)
@@ -35,6 +35,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.tizen.emulator.manager.devices.DeviceTemplate;
+import org.tizen.emulator.manager.devices.DeviceTemplateList;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
@@ -46,6 +48,7 @@ public class Profile {
        private final List<Platform> platformList = new ArrayList<Platform>();
        private List<BaseImage> imageList = new ArrayList<BaseImage>();
        private List<VMProperty> vmList = new ArrayList<VMProperty>();
+       private List<DeviceTemplate> templateList = new ArrayList<DeviceTemplate>();
 
        protected String lastCreatedPropertyPath;
 
@@ -269,6 +272,31 @@ public class Profile {
                this.priority = priority;
        }
 
+       public void clearTemplateList() {
+               templateList.clear();
+       }
+
+       public List<DeviceTemplate> getTemplateList() {
+               return templateList;
+       }
+
+       public void addDeviceTemplate(DeviceTemplate template) {
+               if (template == null) {
+                       return;
+               }
+
+               templateList.add(template);
+       }
+
+       public void removeDeviceTemplate(DeviceTemplate template) {
+               if (template == null) {
+                       return;
+               }
+
+               DeviceTemplateList.removeTemplate(template);
+               templateList.remove(template);
+       }
+
        static class PlatformPair implements Comparable<Object> {
                Platform prop;
 
index c0654d2..0fcd6c7 100644 (file)
@@ -36,6 +36,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.devices.DeviceTemplate;
+import org.tizen.emulator.manager.devices.DeviceTemplateList;
 import org.tizen.emulator.manager.logging.EMLogger;
 import org.tizen.emulator.manager.plugin.EMPlugin;
 import org.tizen.emulator.manager.plugin.PluginStringResources;
@@ -131,6 +133,9 @@ public class ProfileList {
                // make emulator list
                settingVMPropertyListInternal();
 
+               // make device template list
+               settingDeviceTemplateListInternal();
+
                // remove invalid last-created property file.
                checkLastCreatedPropertyFile();
        }
@@ -304,4 +309,19 @@ public class ProfileList {
                        }
                }
        }
+
+       private static void settingDeviceTemplateListInternal() {
+               for (Profile p : profileList) {
+                       p.clearTemplateList();
+               }
+
+               for (DeviceTemplate template : DeviceTemplateList.getDeviceTemplateList(false)) {
+                       for (Profile profile : profileList) {
+                               if (profile.getName().equals(template.getValue().getProfile())) {
+                                       profile.addDeviceTemplate(template);
+                               }
+                       }
+               }
+       }
+
 }