11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -20,49 +20,48 @@ import java.io.ObjectStreamException;
2020import java.io.Serializable ;
2121
2222/**
23- * An aspect that injects dependency into any object whose type implements the {@link ConfigurableObject} interface.
24- * <p >
25- * This aspect supports injecting into domain objects when they are created for the first time as well as
26- * upon deserialization. Subaspects need to simply provide definition for the configureBean() method. This
27- * method may be implemented without relying on Spring container if so desired.
28- * </p>
29- * <p >
30- * There are two cases that needs to be handled:
23+ * An aspect that injects dependency into any object whose type implements the
24+ * {@link ConfigurableObject} interface.
25+ *
26+ * <p >This aspect supports injecting into domain objects when they are created
27+ * for the first time as well as upon deserialization. Subaspects need to simply
28+ * provide definition for the configureBean() method. This method may be
29+ * implemented without relying on Spring container if so desired.
30+ *
31+ * <p >There are two cases that needs to be handled:
3132 * <ol >
32- * <li >Normal object creation via the '{@code new }' operator: this is
33- * taken care of by advising {@code initialization() } join points.</li>
34- * <li >Object creation through deserialization: since no constructor is
35- * invoked during deserialization, the aspect needs to advise a method that a
36- * deserialization mechanism is going to invoke. Ideally, we should not
37- * require user classes to implement any specific method. This implies that
38- * we need to <i >introduce</i> the chosen method. We should also handle the cases
39- * where the chosen method is already implemented in classes (in which case,
40- * the user's implementation for that method should take precedence over the
41- * introduced implementation). There are a few choices for the chosen method:
42- * <ul >
43- * <li >readObject(ObjectOutputStream): Java requires that the method must be
44- * {@code private }</p>. Since aspects cannot introduce a private member,
45- * while preserving its name, this option is ruled out.</li>
46- * <li >readResolve(): Java doesn't pose any restriction on an access specifier.
47- * Problem solved! There is one (minor) limitation of this approach in
48- * that if a user class already has this method, that method must be
49- * {@code public }. However, this shouldn't be a big burden, since
50- * use cases that need classes to implement readResolve() (custom enums,
51- * for example) are unlikely to be marked as @ ; Configurable, and
52- * in any case asking to make that method {@code public } should not
53- * pose any undue burden.</li>
54- * </ul>
55- * The minor collaboration needed by user classes (i.e., that the
56- * implementation of {@code readResolve() }, if any, must be
57- * {@code public }) can be lifted as well if we were to use an
58- * experimental feature in AspectJ - the {@code hasmethod() } PCD.</li>
33+ * <li >Normal object creation via the '{@code new }' operator: this is
34+ * taken care of by advising {@code initialization() } join points.</li>
35+ * <li >Object creation through deserialization: since no constructor is
36+ * invoked during deserialization, the aspect needs to advise a method that a
37+ * deserialization mechanism is going to invoke. Ideally, we should not
38+ * require user classes to implement any specific method. This implies that
39+ * we need to <i >introduce</i> the chosen method. We should also handle the cases
40+ * where the chosen method is already implemented in classes (in which case,
41+ * the user's implementation for that method should take precedence over the
42+ * introduced implementation). There are a few choices for the chosen method:
43+ * <ul >
44+ * <li >readObject(ObjectOutputStream): Java requires that the method must be
45+ * {@code private }</p>. Since aspects cannot introduce a private member,
46+ * while preserving its name, this option is ruled out.</li>
47+ * <li >readResolve(): Java doesn't pose any restriction on an access specifier.
48+ * Problem solved! There is one (minor) limitation of this approach in
49+ * that if a user class already has this method, that method must be
50+ * {@code public }. However, this shouldn't be a big burden, since
51+ * use cases that need classes to implement readResolve() (custom enums,
52+ * for example) are unlikely to be marked as @ ; Configurable, and
53+ * in any case asking to make that method {@code public } should not
54+ * pose any undue burden.</li>
55+ * </ul>
56+ * The minor collaboration needed by user classes (i.e., that the implementation of
57+ * {@code readResolve() }, if any, must be {@code public }) can be lifted as well if we
58+ * were to use an experimental feature in AspectJ - the {@code hasmethod() } PCD.</li>
5959 * </ol>
60-
61- * <p >
62- * While having type implement the {@link ConfigurableObject} interface is certainly a valid choice, an alternative
63- * is to use a 'declare parents' statement another aspect (a subaspect of this aspect would be a logical choice)
64- * that declares the classes that need to be configured by supplying the {@link ConfigurableObject} interface.
65- * </p>
60+ *
61+ * <p >While having type implement the {@link ConfigurableObject} interface is certainly
62+ * a valid choice, an alternative is to use a 'declare parents' statement another aspect
63+ * (a subaspect of this aspect would be a logical choice) that declares the classes that
64+ * need to be configured by supplying the {@link ConfigurableObject} interface.
6665 *
6766 * @author Ramnivas Laddad
6867 * @since 2.5.2
@@ -72,35 +71,33 @@ public abstract aspect AbstractInterfaceDrivenDependencyInjectionAspect extends
7271 * Select initialization join point as object construction
7372 */
7473 public pointcut beanConstruction (Object bean ) :
75- initialization (ConfigurableObject + . new(.. )) && this (bean);
74+ initialization (ConfigurableObject + . new(.. )) && this (bean);
7675
7776 /**
7877 * Select deserialization join point made available through ITDs for ConfigurableDeserializationSupport
7978 */
8079 public pointcut beanDeserialization (Object bean ) :
81- execution (Object ConfigurableDeserializationSupport + . readResolve()) &&
82- this (bean);
80+ execution (Object ConfigurableDeserializationSupport + . readResolve()) && this (bean);
8381
8482 public pointcut leastSpecificSuperTypeConstruction () : initialization (ConfigurableObject . new(.. ));
8583
8684
8785
8886 // Implementation to support re-injecting dependencies once an object is deserialized
87+
8988 /**
9089 * Declare any class implementing Serializable and ConfigurableObject as also implementing
91- * ConfigurableDeserializationSupport. This allows us to introduce the readResolve()
90+ * ConfigurableDeserializationSupport. This allows us to introduce the { @code readResolve()}
9291 * method and select it with the beanDeserialization() pointcut.
93- *
9492 * <p >Here is an improved version that uses the hasmethod() pointcut and lifts
9593 * even the minor requirement on user classes:
96- *
97- * < pre class = " code " > declare parents: ConfigurableObject+ Serializable+
98- * && !hasmethod(Object readResolve() throws ObjectStreamException)
99- * implements ConfigurableDeserializationSupport;
94+ * < pre class = " code " >
95+ * declare parents: ConfigurableObject+ Serializable+
96+ * && !hasmethod(Object readResolve() throws ObjectStreamException)
97+ * implements ConfigurableDeserializationSupport;
10098 * </pre>
10199 */
102- declare parents :
103- ConfigurableObject+ && Serializable+ implements ConfigurableDeserializationSupport;
100+ declare parents : ConfigurableObject+ && Serializable+ implements ConfigurableDeserializationSupport;
104101
105102 /**
106103 * A marker interface to which the {@code readResolve() } is introduced.
@@ -111,7 +108,6 @@ public abstract aspect AbstractInterfaceDrivenDependencyInjectionAspect extends
111108 /**
112109 * Introduce the {@code readResolve() } method so that we can advise its
113110 * execution to configure the object.
114- *
115111 * <p >Note if a method with the same signature already exists in a
116112 * {@code Serializable } class of ConfigurableObject type,
117113 * that implementation will take precedence (a good thing, since we are
0 commit comments