All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.milyn.javabean.BeanAccessor Maven / Gradle / Ivy

There is a newer version: 1.7.1
Show newest version
/*
	Milyn - Copyright (C) 2006 - 2010

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License (version 2.1) as published by the Free Software
	Foundation.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	See the GNU Lesser General Public License for more details:
	http://www.gnu.org/licenses/lgpl.txt
*/

package org.milyn.javabean;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.milyn.assertion.AssertArgument;
import org.milyn.container.ExecutionContext;
import org.milyn.javabean.context.BeanContext;
import org.milyn.javabean.context.BeanIdStore;
import org.milyn.javabean.lifecycle.BeanContextLifecycleEvent;
import org.milyn.javabean.lifecycle.BeanContextLifecycleObserver;
import org.milyn.javabean.lifecycle.BeanLifecycle;
import org.milyn.javabean.repository.BeanId;

/**
 * Bean Accessor.
 * 

* This class provides support for saving and accessing Javabean instance. * * @author [email protected] * @deprecated Use the {@link BeanContext} to manager the beans */ @Deprecated public class BeanAccessor { private static final Log log = LogFactory.getLog(BeanAccessor.class); private static boolean WARNED_USING_DEPRECATED_CLASS = false; /** * Public default constructor. */ public BeanAccessor(ExecutionContext executionContext) { } /** * Public constructor. *

* Creates an accessor based on the supplied result Map. * * @param resultMap The result Map. * */ public BeanAccessor(ExecutionContext executionContext, Map resultMap) { } /** * Get the current bean, specified by the supplied beanId, from the supplied request. *

* If the specified beanId refers to a bean instance list, this method returns the * last (current) bean from the list. * @param beanId Bean Identifier. * @param executionContext The request on which the bean instance is stored. * @return The bean instance, or null if no such bean instance exists on the supplied * request. * */ public static Object getBean(String beanId, ExecutionContext executionContext) { return getBean(executionContext, beanId); } /** * Get the current bean, specified by the supplied beanId, from the supplied request. *

* If the specified beanId refers to a bean instance list, this method returns the * last (current) bean from the list. * @param beanId Bean Identifier. * @param executionContext The request on which the bean instance is stored. * @return The bean instance, or null if no such bean instance exists on the supplied * request. */ public static Object getBean(ExecutionContext executionContext, String beanId) { warnUsingDeprecatedMethod(); AssertArgument.isNotNull(executionContext, "executionContext"); AssertArgument.isNotNullAndNotEmpty(beanId, "beanId"); return executionContext.getBeanContext().getBean(beanId); } /** * Get the bean map associated with the supplied request instance. * @param executionContext The execution context. * @return The bean map associated with the supplied request. * */ public static HashMap getBeans(ExecutionContext executionContext) { warnUsingDeprecatedMethod(); AssertArgument.isNotNull(executionContext, "executionContext"); return (HashMap) getBeanMap(executionContext); } /** * Get the bean map associated with the supplied request instance. * @param executionContext The execution context. * @return The bean map associated with the supplied request. */ public static Map getBeanMap(ExecutionContext executionContext) { warnUsingDeprecatedMethod(); AssertArgument.isNotNull(executionContext, "executionContext"); return executionContext.getBeanContext().getBeanMap(); } /** * Add a bean instance to the specified request under the specified beanId. * * @param executionContext The execution context within which the bean is created. * @param beanId The beanId under which the bean is to be stored. * @param bean The bean instance to be stored. */ public static void addBean(ExecutionContext executionContext, String beanId, Object bean) { warnUsingDeprecatedMethod(); AssertArgument.isNotNull(executionContext, "executionContext"); AssertArgument.isNotNullAndNotEmpty(beanId, "beanId"); AssertArgument.isNotNull(bean, "bean"); BeanId beanIdObj = getBeanId(executionContext.getContext().getBeanIdStore(), beanId); executionContext.getBeanContext().addBean(beanIdObj, bean, null); } /** * Changes a bean object of the given beanId. The difference to addBean is that the * bean must exist, the associated beans aren't removed and the observers of the * {@link BeanLifecycle#CHANGE} event are notified. * * @param executionContext The execution context within which the bean is created. * @param beanId The beanId under which the bean is to be stored. * @param bean The bean instance to be stored. */ public static void changeBean(ExecutionContext executionContext, String beanId, Object bean) { warnUsingDeprecatedMethod(); AssertArgument.isNotNull(executionContext, "executionContext"); AssertArgument.isNotNullAndNotEmpty(beanId, "beanId"); AssertArgument.isNotNull(bean, "bean"); BeanId beanIdObj = getBeanId(executionContext.getContext().getBeanIdStore(), beanId); executionContext.getBeanContext().changeBean(beanIdObj, bean, null); } /** * @param beanIdStore * @param beanId */ private static BeanId getBeanId(BeanIdStore beanIdStore, String beanId) { warnUsingDeprecatedMethod(); BeanId beanIdObj = beanIdStore.getBeanId(beanId); if (beanIdObj == null) { beanIdObj = beanIdStore.register(beanId); } return beanIdObj; } private static void warnUsingDeprecatedMethod() { if(log.isWarnEnabled()) { if(!WARNED_USING_DEPRECATED_CLASS) { WARNED_USING_DEPRECATED_CLASS = true; log.warn("The deprecated class BeanAccessor is being used! It is strongly advised to switch to the new BeanRepository class. " + "The BeanAccessor is much slower then the BeanRepository. This class will be removed in a future release!"); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy