Profile.java

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.profil;
00027 
00028 import org.openmobileis.common.util.OpenMISSerializable;
00029 import org.openmobileis.common.util.collection.Array;
00030 
00035 public final class Profile implements OpenMISSerializable {
00036   static final long serialVersionUID = 5521257935120563452L;
00040     public String userID;
00041 
00045     public ProfileProperty[] profilProperties;
00046 
00050     public ProfileRubric[] profilRubric;
00051     
00055    public String profilName;
00056 
00060     public Profile()  { }
00061 
00069     public Profile(String userID, ProfileProperty[] profilProperties, ProfileRubric[] profilRubric)  {
00070         this.userID = userID;
00071         this.profilProperties = profilProperties;
00072         this.profilRubric = profilRubric;
00073     }
00074     
00075     public String toXML()   {
00076       StringBuffer buff = new StringBuffer();
00077       buff.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\t");
00078       buff.append("<PROFILLIST>");
00079       buff.append("<PROFILNAME name=\""+this.profilName+"\">");
00080       for (int i=0; i<profilRubric.length; i++) {
00081         buff.append("<ENTRY moduleName=\""+profilRubric[i].moduleName+"\" rubricName=\""+profilRubric[i].rubricName+"\"");
00082         if (profilRubric[i].description != null)    {
00083           buff.append(" description=\""+profilRubric[i].description+"\"");
00084         }
00085         if (profilRubric[i].version != null)    {
00086           buff.append(" version=\""+profilRubric[i].version+"\"");
00087         }
00088         buff.append(" />");
00089       }
00090       for (int i=0; i<profilProperties.length; i++) {
00091         buff.append("<PROPERTY key=\""+profilProperties[i].key+"\" value=\""+profilProperties[i].value+"\" ");
00092         if (profilProperties[i].moduleName!= null)    {
00093           buff.append(" module=\""+profilProperties[i].moduleName+"\"");
00094         }
00095         buff.append(" />");
00096       }
00097       buff.append("</PROFILNAME>");
00098       buff.append("</PROFILLIST>");
00099       return buff.toString();
00100     }
00101     
00102     public boolean equals(Object obj) {
00103       if (obj instanceof Profile) {
00104         Profile nobj = (Profile) obj;
00105         if (nobj.profilName.equals(this.profilName))    {
00106            //validate profil rubric
00107           Array thisrubric = new Array(this.profilRubric);
00108           for (int i=0; i<nobj.profilRubric.length; i++)    {
00109             if (!thisrubric.contains(nobj.profilRubric[i])) {
00110               return false;
00111             }
00112           }
00113           Array nobjrubric = new Array(nobj.profilRubric);
00114           for (int i=0; i<this.profilRubric.length; i++)    {
00115             if (!nobjrubric.contains(this.profilRubric[i])) {
00116               return false;
00117             }
00118           }
00119           //validate profil properties
00120           Array thisprop = new Array(this.profilProperties);
00121           for (int i=0; i<nobj.profilProperties.length; i++)    {
00122             if (!thisprop.contains(nobj.profilProperties[i])) {
00123               return false;
00124             }
00125           }
00126           Array nobjprop= new Array(nobj.profilProperties);
00127           for (int i=0; i<this.profilProperties.length; i++)    {
00128             if (!nobjprop.contains(this.profilProperties[i])) {
00129               return false;
00130             }
00131           }
00132           
00133           return true;
00134         }
00135       }
00136       return false;
00137     }
00138     
00139     public int hashCode() {
00140       return profilName.hashCode();
00141     }
00142 
00143 }

Generated on Mon Dec 4 11:03:29 2006 for OpenMobileIS by  doxygen 1.5.1-p1