[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences ...

Christian Bauer christian at hibernate.org
Fri Aug 17 09:00:29 EDT 2007


  User: cbauer  
  Date: 07/08/17 09:00:29

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/preferences   
                        PreferenceProperty.java PreferenceSupport.java
                        PreferenceRegistry.java
  Log:
  Major refactoring of core data schema and some new features
  
  Revision  Changes    Path
  1.4       +0 -1      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceProperty.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PreferenceProperty.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceProperty.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- PreferenceProperty.java	26 Jun 2007 22:47:52 -0000	1.3
  +++ PreferenceProperty.java	17 Aug 2007 13:00:29 -0000	1.4
  @@ -67,7 +67,6 @@
           Component component = Component.forName(Component.getComponentName(componentInstance.getClass()));
   
           // Validate first
  -        // TODO: The exception is currently swallowed... but ideally we should never have invalid input here (from user or database)
           InvalidValue[] invalidValues = validate(component, value);
           if (invalidValues.length >0)
               throw new InvalidStateException(invalidValues, component.getName() + "." + getName());
  
  
  
  1.6       +31 -21    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceSupport.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PreferenceSupport.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceSupport.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- PreferenceSupport.java	12 Jun 2007 12:30:05 -0000	1.5
  +++ PreferenceSupport.java	17 Aug 2007 13:00:29 -0000	1.6
  @@ -1,13 +1,20 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.seam.wiki.preferences;
   
  +import org.jboss.seam.Component;
   import org.jboss.seam.annotations.Create;
   import org.jboss.seam.annotations.Logger;
  -import org.jboss.seam.Component;
  -import org.jboss.seam.log.Log;
   import org.jboss.seam.core.Events;
  +import org.jboss.seam.log.Log;
  +import org.jboss.seam.wiki.plugin.lastmodified.LastModifiedDocumentsPreferences;
   
  -import java.util.Map;
   import java.util.HashMap;
  +import java.util.Map;
   import java.util.Set;
   
   /**
  @@ -20,16 +27,20 @@
    * class is a group of preferences, the name of the group is the name of the Seam component.
    * Each property of the subclass, or even each field (whatever is annotated with <tt>@Preference</tt>)
    * is a preference property that can be loaded and stored with an implementation of <tt>PreferenceProvider</tt>.
  + * </p>
    * <p>
    * You can access preference properties transparently with either
    * <tt>#{seamNameOfThePreferenceComponent.properties['prefPropertyName']}</tt> or with
    * <tt>#{seamNameOfThePreferenceComponent.prefProperty}</tt> if there are property accessor methods, or even
    * type-safe by getting the  whole <tt>#{seamNameOfThePreferenceComponent}</tt> injected.
  + * </p>
    * <p>
    * Note that you should add <tt>@NotNull</tt> to any preference property that is critical in addition to any
    * other pattern, length, range, or other validator annotations.
  + * </p>
    * <p>
    * Subclasses should be in <tt>CONVERSATION</tt> or <tt>PAGE</tt> scope.
  + * </p>
    * <p>
    * Subclasses automatically read preference properties when they are instantiated for the current conversation or page.
    * Subclasses are  automatically notified to refresh their property values inside a conversation, however, you need
  @@ -37,17 +48,20 @@
    * <tt>@Observer("PreferenceEditor.refresh.seamNameOfThePreferenceComponent")</tt> to enable this functionality.
    * This is only used if preference values can change during a conversation, typically when a preference editor
    * is available to the user in that conversation.
  + * </p>
    * <p>
    * You can notify all users of a preference component when a preference property value is changed during the
    * same conversation in which the preference values are used. The event
  - * <tt>@Observer("Preferences.seamNameOfThePreferenceComponent")</tt> is fired when preference values are
  + * <tt>@Observer("PreferenceComponent.refresh.seamNameOfThePreferenceComponent")</tt> is fired when preference values are
    * re-loaded/loaded and you can put it on any method that needs to re-read some state after a preference value
    * change. Note again that this is mostly useful inside a conversation, instances of this class should not
    * live longer than a conversation.
  + * </p>
    * <p>
    * Override the <tt>getCurrentUserVariable</tt> and <tt>getCurrentInstanceVariable</tt> with EL expressions or
    * context variable names if you want to use a particular user or instance for lookup of the preference values.
    * These methods default to null and only system-level preference values are resolved.
  + * </p>
    *
    * @author Christian Bauer
    */
  @@ -55,18 +69,18 @@
   
       @Logger Log log;
   
  -    Map<String, Object> properties = new HashMap<String, Object>();
  +    private Map<String, Object> properties;
   
       @Create
       public void materialize() {
  -        loadPropertyValues();
  +        this.properties = loadPropertyValues();
       }
   
       public Map<String, Object> getProperties() {
           return properties;
       }
   
  -    private void loadPropertyValues() {
  +    private Map<String, Object> loadPropertyValues() {
           PreferenceRegistry registry = (PreferenceRegistry) Component.getInstance("preferenceRegistry");
           PreferenceProvider provider = (PreferenceProvider) Component.getInstance("preferenceProvider");
           Object user = getCurrentUserVariable() != null ? Component.getInstance(getCurrentUserVariable()) : null;
  @@ -76,35 +90,31 @@
               registry.getPreferenceComponentsByName().get( Component.getComponentName(getClass()) );
   
           try {
  +            Map<String, Object> loadedProperties = new HashMap<String, Object>();
  +
               Set<PreferenceValue> valueHolders = provider.load(prefComponent, user, instance, true);
               for (PreferenceValue valueHolder : valueHolders) {
  -                log.trace("loaded preference property value: " + valueHolder.getPreferenceProperty().getName());
  +                log.trace("loaded preference property value: '" + valueHolder.getPreferenceProperty().getName()
  +                          + "' value is: '" + valueHolder.getValue() + "'");
   
  -                // Write onto instance so users can call #{myPrefs.getThisPreferenceSetting}
  +                // Write onto instance so users can call #{myPrefs.thisPreferenceSetting}
                   valueHolder.getPreferenceProperty().write(this, valueHolder.getValue());
   
                   // Keep a duplicate in this map so users can call #{myPrefs.properties['thisPreferenceSetting']}
  -                properties.put(valueHolder.getPreferenceProperty().getName(), valueHolder.getValue());
  +                loadedProperties.put(valueHolder.getPreferenceProperty().getName(), valueHolder.getValue());
   
               }
  +            return loadedProperties;
           } catch (Exception ex) {
               log.warn("Could not write preference property value on component: " + prefComponent.getName(), ex);
  +            throw new RuntimeException(ex);
           }
   
       }
   
       public void refreshProperties() {
  -        PreferenceRegistry registry = (PreferenceRegistry) Component.getInstance("preferenceRegistry");
  -        PreferenceComponent prefComponent =
  -            registry.getPreferenceComponentsByName().get( Component.getComponentName(getClass()) );
  -
  -        log.debug("refreshing preference component property values: " + prefComponent.getName());
  -
  -        loadPropertyValues();
  -
  -        log.debug("notifying all preference component refresh isteners");
  -
  -        Events.instance().raiseEvent("Preferences." + prefComponent.getName());
  +        log.debug("refreshing preference component property values");
  +        this.properties = loadPropertyValues();
       }
   
       public String getCurrentUserVariable() { return null; }
  
  
  
  1.4       +0 -1      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceRegistry.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PreferenceRegistry.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/preferences/PreferenceRegistry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- PreferenceRegistry.java	11 Jul 2007 16:17:45 -0000	1.3
  +++ PreferenceRegistry.java	17 Aug 2007 13:00:29 -0000	1.4
  @@ -20,7 +20,6 @@
    */
   @Name("preferenceRegistry")
   @Scope(ScopeType.APPLICATION)
  - at Startup(depends = "wikiInit")
   public class PreferenceRegistry {
   
       @Logger static Log log;
  
  
  



More information about the jboss-cvs-commits mailing list