예제 #1
0
 /**
  * Add an adaptor for a kind of object so ST knows how to pull properties from them. Add adaptors
  * in increasing order of specificity. ST adds Object, Map, and ST model adaptors for you first.
  * Adaptors you add have priority over default adaptors.
  *
  * <p>If an adaptor for type T already exists, it is replaced by the adaptor arg.
  *
  * <p>This must invalidate cache entries, so set your adaptors up before render()ing your
  * templates for efficiency.
  */
 public void registerModelAdaptor(Class attributeType, ModelAdaptor adaptor) {
   if (attributeType.isPrimitive()) {
     throw new IllegalArgumentException(
         "can't register ModelAdaptor for primitive type " + attributeType.getSimpleName());
   }
   adaptors.put(attributeType, adaptor);
   invalidateModelAdaptorCache(attributeType);
 }
예제 #2
0
 /**
  * Register a renderer for all objects of a particular "kind" for all templates evaluated relative
  * to this group. Use r to render if object in question is instanceof(attributeType).
  */
 public void registerRenderer(Class attributeType, AttributeRenderer r) {
   if (attributeType.isPrimitive()) {
     throw new IllegalArgumentException(
         "can't register renderer for primitive type " + attributeType.getSimpleName());
   }
   typeToAdaptorCache.clear(); // be safe, not clever; wack all values
   if (renderers == null) {
     renderers = Collections.synchronizedMap(new LinkedHashMap<Class, AttributeRenderer>());
   }
   renderers.put(attributeType, r);
 }