@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof ISerializer) { register((ISerializer<?>) bean); } return bean; }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { if (bean instanceof ISerializer) { unregister((ISerializer<?>) bean); } }
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } IContextSerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }
/** * Returns an object of the specified class. The class must have an associated context * serializer registered. * * @param <T> The item's class. * @param itemName Item name * @param clazz Class of item to be returned. * @return Deserialized item of specified class. * @throws ContextException If no context serializer found. */ @SuppressWarnings("unchecked") public <T> T getItem(String itemName, Class<T> clazz) throws ContextException { String item = getItem(itemName); if (item == null || item.isEmpty()) { return null; } ISerializer<?> contextSerializer = ContextSerializerRegistry.getInstance().get(clazz); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + clazz.getName()); } return (T) contextSerializer.deserialize(item); }
/** * Sets a context item value. * * @param itemName Item name. * @param value The value to set. The value's class must have an associated context serializer * registered for it. */ public void setItem(String itemName, Object value) { if (value == null) { setItem(itemName, (String) null); } else { @SuppressWarnings("unchecked") ISerializer<Object> contextSerializer = (ISerializer<Object>) ContextSerializerRegistry.getInstance() .get(value.getClass()); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + value.getClass().getName()); } setItem(itemName, contextSerializer.serialize(value)); } }
@Override public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { if (bean instanceof IContextSerializer) { unregister((IContextSerializer<?>) bean); } }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof IContextSerializer) { register((IContextSerializer<?>) bean); } return bean; }
/** * Sets a context item value. * * @param itemName Item name. * @param value The value to set. The value's class must have an associated context serializer * registered for it. */ public void setItem(String itemName, Object value) { if (value == null) { setItem(itemName, (String) null); } else { @SuppressWarnings("unchecked") IContextSerializer<Object> contextSerializer = (IContextSerializer<Object>) ContextSerializerRegistry .getInstance().get(value.getClass()); if (contextSerializer == null) { throw new ContextException("No serializer found for type " + value.getClass().getName()); } setItem(itemName, contextSerializer.serialize(value)); } }