00001 /* 00002 * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM) 00003 * Copyright (C) 2004-2006 Philippe Delrieu 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 */ 00025 00026 package org.openmobileis.common.user.profile; 00027 00028 import org.openmobileis.common.user.profile.ProfileProperty; 00029 import org.openmobileis.common.user.profile.ProfileRubric; 00030 import org.openmobileis.common.util.OpenMISSerializable; 00031 import org.openmobileis.common.util.collection.Array; 00032 00037 public final class Profile implements OpenMISSerializable { 00038 static final long serialVersionUID = 5521257935120563452L; 00042 public String userID; 00043 00047 public ProfileProperty[] profilProperties; 00048 00052 public ProfileRubric[] profilRubric; 00053 00057 public String profilName; 00058 00062 public Profile() { } 00063 00071 public Profile(String userID, ProfileProperty[] profilProperties, ProfileRubric[] profilRubric) { 00072 this.userID = userID; 00073 this.profilProperties = profilProperties; 00074 this.profilRubric = profilRubric; 00075 } 00076 00077 public String toXML() { 00078 StringBuffer buff = new StringBuffer(); 00079 buff.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\t"); 00080 buff.append("<PROFILLIST>"); 00081 buff.append("<PROFILNAME name=\""+this.profilName+"\">"); 00082 for (int i=0; i<profilRubric.length; i++) { 00083 buff.append("<ENTRY moduleName=\""+profilRubric[i].moduleName+"\" rubricName=\""+profilRubric[i].rubricName+"\""); 00084 if (profilRubric[i].description != null) { 00085 buff.append(" description=\""+profilRubric[i].description+"\""); 00086 } 00087 if (profilRubric[i].version != null) { 00088 buff.append(" version=\""+profilRubric[i].version+"\""); 00089 } 00090 buff.append(" />"); 00091 } 00092 for (int i=0; i<profilProperties.length; i++) { 00093 buff.append("<PROPERTY key=\""+profilProperties[i].key+"\" value=\""+profilProperties[i].value+"\" "); 00094 if (profilProperties[i].moduleName!= null) { 00095 buff.append(" module=\""+profilProperties[i].moduleName+"\""); 00096 } 00097 buff.append(" />"); 00098 } 00099 buff.append("</PROFILNAME>"); 00100 buff.append("</PROFILLIST>"); 00101 return buff.toString(); 00102 } 00103 00104 public boolean equals(Object obj) { 00105 if (obj instanceof Profile) { 00106 Profile nobj = (Profile) obj; 00107 if (nobj.profilName.equals(this.profilName)) { 00108 //validate profil rubric 00109 Array thisrubric = new Array(this.profilRubric); 00110 for (int i=0; i<nobj.profilRubric.length; i++) { 00111 if (!thisrubric.contains(nobj.profilRubric[i])) { 00112 return false; 00113 } 00114 } 00115 Array nobjrubric = new Array(nobj.profilRubric); 00116 for (int i=0; i<this.profilRubric.length; i++) { 00117 if (!nobjrubric.contains(this.profilRubric[i])) { 00118 return false; 00119 } 00120 } 00121 //validate profil properties 00122 Array thisprop = new Array(this.profilProperties); 00123 for (int i=0; i<nobj.profilProperties.length; i++) { 00124 if (!thisprop.contains(nobj.profilProperties[i])) { 00125 return false; 00126 } 00127 } 00128 Array nobjprop= new Array(nobj.profilProperties); 00129 for (int i=0; i<this.profilProperties.length; i++) { 00130 if (!nobjprop.contains(this.profilProperties[i])) { 00131 return false; 00132 } 00133 } 00134 00135 return true; 00136 } 00137 } 00138 return false; 00139 } 00140 00141 public int hashCode() { 00142 return profilName.hashCode(); 00143 } 00144 00145 }