myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Myfaces Wiki] Update of "Extensions/Validator/DevDoc" by GerhardPetracek
Date Sun, 27 Sep 2009 02:27:38 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The "Extensions/Validator/DevDoc" page has been changed by GerhardPetracek:
http://wiki.apache.org/myfaces/Extensions/Validator/DevDoc?action=diff&rev1=29&rev2=30

  
  === implementing a new storage ===
   * storage interface with specific storage api (each storage type has a different api)
+ {{{
+ public interface MyStorage
+ {
+     //custom methods - e.g.:
+     void add(String key, MyObject1 o1, MyObject2 o2, ...);
+     MyObject1 getO1(String key);
+     MyObject2 getO2(String key);
+ }
+ }}}
   * storage implementation
   * storage manager implementation (to provide a key to cache storages of the same type in
a given scope)
+ {{{
+ //there are already implementations for request and application scoped storage implementations
+ //which extend a generic implementation (AbstractStorageManager) which uses the name mapper
concept
+ public class MyStorageManager extends AbstractRequestScopeAwareStorageManager<MyStorage>
+ {
+     public MyStorageManager()
+     {
+         register(new MyNameMapper());
+     }
+ 
+     public String getStorageManagerKey()
+     {
+         return "[unique key for my-storage]";
+     }
+ }
+ }}}
   * name mapper (storage interface to storage implementation) – if a storage manager implementation
requires it
- 
+ {{{
+ public class MyNameMapper implements NameMapper<String>
+ {
+     public String createName(String source)
+     {
+         return (MyStorage.class.getName().equals(source)) ? MyStorageImpl.class.getName()
: null;
+     }
+ }
+ }}}
+  * use it
+ {{{
+ //1. arg: storage type 2. arg: storage name
+ ExtValUtils.getStorage(MyStorage.class, "st1").add(...);
+ ExtValUtils.getStorage(MyStorage.class, "st2").add(...);
+ }}}
+ {{{
+ ExtValUtils.getStorage(MyStorage.class, "st1").getO1(...);
+ }}}
+  * reset it
+ {{{
+ ExtValUtils.resetStorage(MyStorage.class, "st1");
+ }}}
  === get the storage manager holder ===
  {{{
  StorageManagerHolder storageManagerHolder = (ExtValContext.getContext().getFactoryFinder()
@@ -368, +414 @@

  
  === register custom storage managers ===
  {{{
- storageManagerHolder.setStorageManager(MyStorageType.class, new MyStorageManager(), true);
+ storageManagerHolder.setStorageManager(MyStorage.class, new MyStorageManager(), true);
  }}}
  
  ----

Mime
View raw message