Permalink
Browse files

- removed commons and aop package (moved to projects/ folder)

  • Loading branch information...
1 parent 740ba4c commit 3f982bd67ddcab5fe5731dd6c6745cb6ae9517d0 costin committed Mar 8, 2006
@@ -1,145 +0,0 @@
-package org.springmodules.aop.framework;
-
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import ognl.Ognl;
-import ognl.OgnlException;
-
-import org.springframework.aop.AfterReturningAdvice;
-import org.springframework.beans.BeanWrapper;
-import org.springframework.beans.BeanWrapperImpl;
-import org.springframework.beans.BeansException;
-import org.springframework.util.MethodInvoker;
-
-/**
- * <p>Touches configurable properties on the return value of a method invocation.
- * This approach is an alternative to the open session in view pattern.
- *
- * <p>If the return value is a single object the properties are touched on this
- * object. If the return value is an instance of java.util.Collection or Object[]
- * the properties are touched on every element.
- *
- * <p>If no properties are specified collections will still be iterated entirely.
- *
- * <p>Property values can be either property names or maps containing property names
- * as keys and lists containing property names as values. Maps entries represent bean
- * properties (the key of the map entries) that are collections. All elements of those collection will
- * be touched by the properties (the values of the map entries). This construct can
- * be cascaded.
- *
- * <p>OGNL expressions are also supported. These expression will be executed after the properties
- * have been executed on the return value of the method invocation. To support the evaluation of collections
- * you can use the <code>#returned</code> variable in the OGNL context which holds the return value.
- *
- * <p>To load all elements of a returned collection instance use OGNL's pseudo-property size:
- *
- * <pre>
- * #returned.size
- * </pre>
- *
- * @author Steven Devijver
- * @since 20-06-2005
- *
- */
-public class TouchingAfterReturningAdvice implements AfterReturningAdvice {
-
- private Object[] properties = null;
- private String[] ognlExpressions = null;
-
- /**
- * <p>The [properties] properties takes a list of property strings.
- * The return value of the method invocation will be touched with these
- * properties.
- *
- * @param properties the property strings
- */
- public void setProperties(Object[] properties) {
- this.properties = properties;
- }
-
- /**
- * <p>The [ognl] property takes a list of OGNL expressions that will be
- * evaluated on the return value of the method invocation.
- *
- * @param ognlExpressions the OGNL expressions
- */
- public void setOgnl(String[] ognlExpressions) {
- this.ognlExpressions = ognlExpressions;
- }
-
- public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
- if (returnValue == null) {
- return;
- }
-
- if (returnValue instanceof MethodInvoker.VoidType) {
- return;
- } else if (returnValue instanceof Collection) {
- touch(((Collection)returnValue).toArray(), properties);
- } else if (returnValue instanceof Object[]) {
- touch((Object[])returnValue, properties);
- } else {
- touch(returnValue, properties);
- }
- touchOgnl(returnValue, ognlExpressions);
-
- }
-
- private static void touch(Object[] objects, Object[] properties) {
- for (int i = 0; objects != null && properties != null && i < objects.length; i++) {
- Object target = objects[i];
- touch(target, properties);
- }
- }
-
- private static void touch(Object target, Object[] properties) {
- BeanWrapper beanWrapper = new BeanWrapperImpl(target);
- for (int x = 0; properties != null && x < properties.length; x++) {
- Object property = properties[x];
- if (property instanceof String) {
- Object result = beanWrapper.getPropertyValue((String)property);
- if (result instanceof Collection) {
- ((Collection)result).size();
- }
- } else if (property instanceof Map) {
- for (Iterator iter = ((Map)property).keySet().iterator(); iter.hasNext();) {
- Object key = iter.next();
- Object tmpProperties = ((Map)property).get(key);
- if (!(key instanceof String)) {
- throw new IllegalArgumentException("Maps configured in the [properties] property should have a string key!");
- }
- if (!(tmpProperties instanceof Collection)) {
- throw new IllegalArgumentException("Maps configured in the [properties] property should have a list value!");
- }
- Object result = beanWrapper.getPropertyValue((String)key);
- if (result instanceof Collection) {
- touch(((Collection)result).toArray(), ((Collection)tmpProperties).toArray());
- } else if (result instanceof Object[]) {
- touch((Object[])result, ((Collection)tmpProperties).toArray());
- } else {
- touch(result, ((Collection)tmpProperties).toArray());
- }
- }
- } else {
- throw new IllegalArgumentException("[properties] property should only contain string and map instances!");
- }
- }
- }
-
- private static void touchOgnl(Object target, String[] ognlExpressions) {
- for (int i = 0; ognlExpressions != null && i < ognlExpressions.length; i++) {
- String ognlExpression = ognlExpressions[i];
- try {
- Map context = new HashMap();
- context.put("returned", target);
- Ognl.getValue(ognlExpression, context, target);
- } catch (OgnlException e) {
- throw new BeansException("Error occured while evaluating OGNL expression [" + ognlExpression + "]!", e) {};
- }
- }
- }
-}
@@ -1,39 +0,0 @@
-package org.springmodules.aop.framework;
-
-import org.springframework.aop.support.NameMatchMethodPointcutAdvisor;
-import org.springframework.beans.factory.InitializingBean;
-
-/**
- * <p>Convenience class based on NameMatchMethodPointcutAdvisor that
- * has a TouchingAfterReturningAdvice advice.
- *
- * @author Steven Devijver
- * @since 21-06-2005
- * @see org.springframework.aop.support.NameMatchMethodPointcutAdvisor
- * @see org.springmodules.aop.framework.TouchingAfterReturningAdvice
- */
-public class TouchingNameMatchMethodAdvisor extends
- NameMatchMethodPointcutAdvisor {
-
- private TouchingAfterReturningAdvice advice = null;
-
- public TouchingNameMatchMethodAdvisor() {
- super();
- this.advice = new TouchingAfterReturningAdvice();
- setAdvice(advice);
- }
-
- /**
- * <p>Property to access the TouchingAfterReturningAdvice
- * configured with this advisor.
- *
- * <p>To access the [properties] and [ognl] properties of
- * TouchingAfterReturningAdvice use <code>touchingAdvice.properties</code>
- * and <code>touchingAdvice.ognl</code>.
- *
- * @return the TouchingAfterReturningAdvice instance
- */
- public TouchingAfterReturningAdvice getTouchingAdvice() {
- return this.advice;
- }
-}
@@ -1,4 +0,0 @@
-#
-# JackRabbit specific SessionHolderProvider.
-#
-org.springmodules.jcr.jackrabbit.support.JackRabbitSessionHolderProvider
@@ -1,133 +0,0 @@
-package org.springmodules.aop.framework;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.springframework.aop.framework.ProxyFactory;
-
-public class TouchingAfterReturningAdviceTests extends TestCase {
-
- public TouchingAfterReturningAdviceTests() {
- super();
- }
-
- private static final String BEAN_NAME = "Bean name";
-
- private Bean getBean() {
- Bean bean = new DefaultBean();
- bean.setBeans(new Bean[] {
- new DefaultBean() {
- {
- setBean(new DefaultBean());
- setBeans(new Bean[] { new DefaultBean() });
- }
- },
- new DefaultBean() {
- {
- setBeans(new Bean[] { new DefaultBean() });
- }
- }
- });
- bean.setBean(bean);
- bean.setOtherBeans(Arrays.asList(bean.getBeans()));
- return bean;
- }
-
-
- public void testTouchingAdvice() {
- Bean bean = (Bean)getProxy(getBean(), new String[] { "autoName" }, new String[] { "autoName"}, new String[] { "getBean" });
- bean.getBean();
- assertEquals(BEAN_NAME, bean.getName());
-
- bean = (Bean)getProxy(getBean(), new String[] { "autoName" }, new String[] { "#returned.{autoName}" }, new String[] { "getBeans" });
- Bean[] beans = bean.getBeans();
- assertEquals(BEAN_NAME, beans[0].getName());
- assertEquals(BEAN_NAME, beans[1].getName());
-
- bean = (Bean)getProxy(getBean(), new Object[] { "autoName" }, new String[] { "#returned.{autoName}" }, new String[] { "getOtherBeans" });
- List otherBeans = bean.getOtherBeans();
- assertEquals(BEAN_NAME, ((Bean)otherBeans.get(0)).getName());
- assertEquals(BEAN_NAME, ((Bean)otherBeans.get(1)).getName());
-
- Map map = new HashMap();
- List list = new ArrayList();
- list.add("autoName");
- map.put("beans", list);
- bean = (Bean)getProxy(getBean(), new Object[] { "autoName", map }, new String[] { "#returned.{beans.{autoName}}" }, new String[] { "getBeans" });
- beans = bean.getBeans();
- assertEquals(BEAN_NAME, beans[0].getName());
- assertEquals(BEAN_NAME, beans[1].getName());
- assertEquals(BEAN_NAME, beans[0].getBeans()[0].getName());
- assertEquals(BEAN_NAME, beans[1].getBeans()[0].getName());
- }
-
-
-
- private Object getProxy(Object target, Object[] properties, String[] ognl, String[] mappedNames) {
- TouchingNameMatchMethodAdvisor advisor = new TouchingNameMatchMethodAdvisor();
- advisor.setMappedNames(mappedNames);
- advisor.getTouchingAdvice().setProperties(properties);
- advisor.getTouchingAdvice().setOgnl(ognl);
- ProxyFactory pf = new ProxyFactory(target);
- pf.addAdvisor(advisor);
- return pf.getProxy();
- }
-
-
-
- public interface Bean {
- public Bean[] getBeans();
- public void setBeans(Bean[] beans);
- public List getOtherBeans();
- public void setOtherBeans(List otherBeans);
- public Bean getBean();
- public void setBean(Bean bean);
- public String getName();
- public String getAutoName();
- }
-
- public static class DefaultBean implements Bean {
- private Bean[] beans = null;
- private Bean bean = null;
- private List otherBeans = null;
- public String name = null;
-
- public Bean getBean() {
- return this.bean;
- }
-
- public Bean[] getBeans() {
- return this.beans;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getAutoName() {
- this.name = BEAN_NAME;
- return this.name;
- }
-
- public List getOtherBeans() {
- return this.otherBeans;
- }
-
- public void setBean(Bean bean) {
- this.bean = bean;
- }
-
- public void setBeans(Bean[] beans) {
- this.beans = beans;
- }
-
- public void setOtherBeans(List otherBeans) {
- this.otherBeans = otherBeans;
- }
- }
-}
Oops, something went wrong.

0 comments on commit 3f982bd

Please sign in to comment.