TerminalProfile.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2006-2008 Ubikis
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  Creation P.Delrieu
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)  { //module has same service name
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 }

Generated on Mon Jan 11 21:19:17 2010 for OpenMobileIS by  doxygen 1.5.4