示例#1
0
  /** Load from preferences file. */
  private void loadPrefs() {
    final FileWrapper oldPrefsFile =
        fileWrapperFactory.create(_userSettingsFolder, OLD_USER_PREFS_FILE_NAME);
    final FileWrapper newPrefsFile =
        fileWrapperFactory.create(_userSettingsFolder, USER_PREFS_FILE_NAME);
    final boolean oldExists = oldPrefsFile.exists();
    final boolean newExists = newPrefsFile.exists();

    try {
      if (oldExists) {
        loadOldPrefs(oldPrefsFile);
        try {
          _settingsCache.add(_lafPrefs);
        } catch (DuplicateObjectException ex) {
          s_log.error("LAFPreferences object already in cache", ex);
        }
        savePrefs(newPrefsFile);
        if (!oldPrefsFile.delete()) {
          s_log.error("Unable to delete old LAF preferences file");
        }

      } else if (newExists) {
        loadNewPrefs(newPrefsFile);
      }
    } catch (IOException ex) {
      s_log.error("Error occured in preferences file", ex);
    } catch (XMLException ex) {
      s_log.error("Error occured in preferences file", ex);
    }

    if (_lafPrefs == null) {
      _lafPrefs = new LAFPreferences(IdentifierFactory.getInstance().createIdentifier());
      _lafPrefs.setLookAndFeelClassName(MetalLookAndFeelController.METAL_LAF_CLASS_NAME);
      try {
        _settingsCache.add(_lafPrefs);
      } catch (DuplicateObjectException ex) {
        s_log.error("LAFPreferences object already in cache", ex);
      }
    }
  }
示例#2
0
 /**
  * Load from an XML document but don't ignore duplicate objects.
  *
  * @param xmlFileName Name of XML file to load from.
  * @param cl Class loader to use for object creation.
  * @exception FileNotFoundException Thrown if file not found.
  * @exception XMLException Thrown if an XML error occurs.
  * @exception DuplicateObjectException Thrown if two objects of the same class and with the same
  *     identifier are added to the cache.
  */
 public void load(String xmlFileName, ClassLoader cl)
     throws FileNotFoundException, XMLException, DuplicateObjectException {
   XMLBeanReader rdr = new XMLBeanReader();
   rdr.load(xmlFileName, cl);
   for (Iterator it = rdr.iterator(); it.hasNext(); ) {
     final Object obj = it.next();
     if (!(obj instanceof IHasIdentifier)) {
       throw new XMLException("Trying to load object that doesn't implement IHasIdentifier");
       // i18n
     }
     add((IHasIdentifier) obj);
   }
 }
示例#3
0
 /**
  * Load from a reader over an XML document.
  *
  * @param rdr Reader over the XML document.
  * @param cl Class loader to use for object creation. Pass <TT>null</TT> to use the system
  *     classloader.
  * @param ignoreDuplicates If <tt>true</TT> don't throw a <TT>DuplicateObjectException</TT> but
  *     rather ignore the attempt to add a duplicate, in this there will be only one object added
  *     to the cache.
  * @exception XMLException Thrown if an XML error occurs.
  * @exception DuplicateObjectException Thrown if two objects of the same class and with the same
  *     identifier are added to the cache.
  */
 public void load(Reader rdr, ClassLoader cl, boolean ignoreDuplicates)
     throws XMLException, DuplicateObjectException {
   XMLBeanReader xmlRdr = new XMLBeanReader();
   xmlRdr.load(rdr, cl);
   for (Iterator it = xmlRdr.iterator(); it.hasNext(); ) {
     final Object obj = it.next();
     if (!(obj instanceof IHasIdentifier)) {
       throw new XMLException("Trying to load object that doesn't implement IHasIdentifier");
       // i18n
     }
     try {
       add((IHasIdentifier) obj);
     } catch (DuplicateObjectException ex) {
       if (!ignoreDuplicates) {
         throw ex;
       }
     }
   }
 }
示例#4
0
 /** Save cached objects. */
 void save() {
   try {
     XMLObjectCache cache = new XMLObjectCache();
     try {
       if (_rootFolder != null) {
         cache.add(_rootFolder);
       }
     } catch (DuplicateObjectException ignore) {
     }
     cache.save(_queriesFileName);
   } catch (IOException ex) {
     final Logger logger = _app.getLogger();
     logger.showMessage(
         Logger.ILogTypes.ERROR, "Error occured saving queries to " + _queriesFileName);
     logger.showMessage(Logger.ILogTypes.ERROR, ex);
   } catch (XMLException ex) {
     final Logger logger = _app.getLogger();
     logger.showMessage(
         Logger.ILogTypes.ERROR, "Error occured saving queries to " + _queriesFileName);
     logger.showMessage(Logger.ILogTypes.ERROR, ex);
   }
 }