Ejemplo n.º 1
0
  private Asset createAssetFromResource(Resource resource) {
    // The class of the resource is derived from the class of the base resource.
    // So we can then use the class of the resource as a key to locate the correct asset
    // factory.

    try {
      upgradeReadLockToWriteLock();

      // Check for competing thread beat us to it (not very likely!):

      Asset result = TapestryInternalUtils.getAndDeref(cache, resource);

      if (result != null) {
        return result;
      }

      Class resourceClass = resource.getClass();

      AssetFactory factory = registry.get(resourceClass);

      return factory.createAsset(resource);
    } finally {
      downgradeWriteLockToReadLock();
    }
  }
Ejemplo n.º 2
0
  @Override
  public <T> CacheProcessor<T> getProcessor(final Class<T> clazz) {
    CacheProcessor processor = registry.get(clazz);
    if (processor != null) {
      return processor;
    }
    if (clazz.isAnnotationPresent(Entity.class)) {
      return new CacheProcessor() {
        @Override
        public Object fromCache(List cacheObject, Method method) {
          // fetch id property class
          Class<?> idClass =
              propertyAccess
                  .getAdapter(clazz)
                  .getPropertyAdapter(EntityConstants.ID_PROPERTY_NAME)
                  .getType();
          // convert id value
          Object obj = coercer.coerce(cacheObject, idClass);
          // find object
          obj = entityService.get(clazz, obj);
          return obj;
        }

        @Override
        public List toCache(Object value) {
          return convertAsListObject(value);
        }
      };
    } else {
      return new CacheProcessor() {
        @Override
        public Object fromCache(List cacheObject, Method method) {
          return coercer.coerce(cacheObject, clazz);
        }

        @Override
        public List toCache(Object value) {
          return convertAsListObject(value);
        }
      };
    }
  }
 private MonitorNameGenerator getNameGenerator(Class owningClass) {
   MonitorNameGenerator nameGenerator = strategyRegistry.get(owningClass);
   if (nameGenerator == null) nameGenerator = defaultMonitorNameGenerator;
   return nameGenerator;
 }