Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

ProfilManager.java

00001 package org.openmobileis.modules.profils.embedded.data;
00002 
00003 import java.io.File;
00004 import java.io.FileReader;
00005 
00006 import org.openmobileis.common.util.PropertiesManager;
00007 import org.openmobileis.common.util.collection.Array;
00008 import org.openmobileis.common.util.exception.ServerException;
00009 import org.openmobileis.common.util.log.LogManager;
00010 import org.openmobileis.common.util.log.LogServices;
00011 
00012 public class ProfilManager {
00013 
00014         private static ProfilManager manager;
00015         private String profilFile;
00016         private Array profilRubrics = null;
00017         private Array profilModules = null;
00018           
00019         private ProfilManager() {
00020                 profilFile = PropertiesManager.getManager().getProperty("org.openmobileis.profil.file");
00021                 // TODO : get it a nicer way :
00022                 profilFile = System.getProperty("user.dir")+File.separator+"WEB-INF"+File.separator+"conf"+File.separator+"properties"+File.separator+"profilData";
00023                 System.out.println("profilFile : "+profilFile);
00024         }
00025         
00026         public static ProfilManager getManager() {
00027                 if (manager == null)  {
00028                         synchronized(org.openmobileis.modules.profils.embedded.data.ProfilManager.class) {
00029                                 if (manager == null)  {
00030                                         manager = new ProfilManager();
00031                                 }
00032                         }
00033                 }
00034                 return manager;
00035         }
00036         
00037         public Array getProfilRubrics() {
00038                 if(profilRubrics != null) {
00039                         return profilRubrics;
00040                 }
00041                 this.parseFile();
00042 
00043                 return profilRubrics;
00044         }
00045         
00046         public Array getProfilModules() {
00047                 if(profilModules != null) {
00048                         return profilModules;
00049                 }
00050                 this.parseFile();
00051 
00052                 return profilModules;
00053         }
00054         
00055         private void parseFile () {
00056                 try {
00057                         FileReader reader = new FileReader(this.profilFile);
00058                         ProfilParser parser = new ProfilParser(reader);
00059                         parser.parse();
00060                         
00061                         this.profilRubrics = parser.getRubrics();
00062                         this.profilModules = parser.getModules();
00063                 } catch (java.io.FileNotFoundException e) {
00064                         LogManager.traceError(LogServices.WEBSERVICE, "Can not read profil file : " + this.profilFile);
00065                 } catch (java.io.IOException e) {
00066                         LogManager.traceError(LogServices.WEBSERVICE, "Can not read profil file : " + this.profilFile);
00067                 } catch (Exception e) {
00068                         LogManager.trace(new ServerException("Error during parsing XML data for profils ",e));
00069                         return;
00070                 }
00071         }
00072         
00073         public String toString() {
00074                 if (profilModules == null || profilRubrics == null) {
00075                         this.parseFile();
00076                 }
00077                 
00078                 StringBuffer strBuf = new StringBuffer();
00079                 for (int i = 0; i < profilRubrics.size(); i++) {
00080                         ProfilRubric rubric = (ProfilRubric)profilRubrics.get(i);
00081                         strBuf.append("Rubric : "+rubric.getName()+"\n");
00082                         for (int j = 0; j < rubric.getAllPropertiesNames().length; j++) {
00083                                 strBuf.append("  Property : "+rubric.getAllPropertiesNames()[j]+" ==> "+rubric.getProperty(rubric.getAllPropertiesNames()[j])+"\n");
00084                         }
00085                 }
00086                 
00087                 for (int i = 0; i < profilModules.size(); i++) {
00088                         ProfilModule module = (ProfilModule)profilModules.get(i);
00089                         strBuf.append("Module : "+module.getName()+" version : "+module.getVersion()+"\n");
00090                         Array rubrics = module.getRubrics();
00091                         for (int j = 0; j < rubrics.size(); j++) {
00092                                 strBuf.append("  Rubric : "+(String)rubrics.get(j)+"\n");
00093                         }
00094                         for (int j = 0; j < module.getAllPropertiesNames().length; j++) {
00095                                 strBuf.append("  Property : "+module.getAllPropertiesNames()[j]+" ==> "+module.getProperty(module.getAllPropertiesNames()[j])+"\n");
00096                         }
00097                 }
00098                 
00099                 return strBuf.toString();
00100         }
00101 }

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4