00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.openmobileis.module.profiles.terminal;
00029
00030 import java.util.Hashtable;
00031
00032 import org.openmobileis.common.user.profile.Profile;
00033 import org.openmobileis.common.util.OpenMISSerializable;
00034
00043 public final class TerminalProfile implements OpenMISSerializable {
00044 static final long serialVersionUID = 5521257935120563452L;
00045
00046 public String profileName;
00047 public TerminalProfilModule[] moduleList;
00051 public TerminalProfile() {
00052 }
00053
00054 public String toXML() {
00055 StringBuffer buff = new StringBuffer();
00056 buff.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\t");
00057 buff.append("<PROFILNAME name=\""+this.profileName+"\">");
00058 for (int i=0; moduleList!=null && i<this.moduleList.length; i++) {
00059 buff.append("<MODULE moduleName=\""+moduleList[i].moduleName+"\" version=\""+moduleList[i].moduleVersion+"\"/>");
00060 }
00061 buff.append("</PROFILNAME>");
00062 return buff.toString();
00063 }
00064
00065 public static TerminalProfile convertProfileToTerminalProfile(Profile profile) {
00066 TerminalProfile tp = new TerminalProfile();
00067 tp.profileName = profile.profilName;
00068 Hashtable moduleList = new Hashtable();
00069 for (int i=0; i<profile.ProfileServices.length; i++) {
00070 String name = profile.ProfileServices[i].moduleName;
00071 if (!moduleList.containsKey(name)) {
00072 TerminalProfilModule tm = new TerminalProfilModule();
00073 tm.moduleName = name;
00074 moduleList.put(name, tm);
00075 }
00076 if (name.equals(profile.ProfileServices[i].serviceName) && profile.ProfileServices[i].version != null) {
00077 TerminalProfilModule tm = (TerminalProfilModule)moduleList.get(name);
00078 tm.moduleVersion = profile.ProfileServices[i].version;
00079 }
00080 }
00081 TerminalProfilModule[] ml = new TerminalProfilModule[moduleList.size()];
00082 moduleList.values().toArray(ml);
00083 tp.moduleList = ml;
00084 return tp;
00085 }
00086
00087 public boolean equals(Object obj) {
00088 if (obj instanceof TerminalProfile) {
00089 TerminalProfile nobj = (TerminalProfile) obj;
00090 if (nobj.profileName.equals(this.profileName) && nobj.moduleList.length == this.moduleList.length) {
00091 boolean found = false;
00092 for (int i=0; i<nobj.moduleList.length; i++) {
00093 found = false;
00094 for (int j=0; j<this.moduleList.length; j++) {
00095 if (nobj.moduleList[i].moduleName.equals(this.moduleList[j].moduleName)) {
00096 found = true;
00097 if (!nobj.moduleList[i].moduleVersion.equals(this.moduleList[j].moduleVersion)) {
00098 return false;
00099 }
00100 }
00101 }
00102 if (!found) return false;
00103 }
00104 return true;
00105 }
00106 }
00107 return false;
00108 }
00109
00110 public int hashCode() {
00111 return this.profileName.hashCode();
00112 }
00113
00114 }