4 changed files with 0 additions and 168 deletions
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
package org.springframework.persistence.support; |
||||
|
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
import org.springframework.util.ClassUtils; |
||||
|
||||
/** |
||||
* Try for a constructor taking state: failing that, try a no-arg |
||||
* constructor and then setUnderlyingNode(). |
||||
* |
||||
* @author Rod Johnson |
||||
*/ |
||||
public abstract class AbstractConstructorEntityInstantiator<BACKING_INTERFACE, STATE> implements EntityInstantiator<BACKING_INTERFACE, STATE> { |
||||
|
||||
private final Log log = LogFactory.getLog(getClass()); |
||||
|
||||
final public <T extends BACKING_INTERFACE> T createEntityFromState(STATE n, Class<T> c) { |
||||
try { |
||||
return fromStateInternal(n, c); |
||||
} catch (InstantiationException e) { |
||||
throw new IllegalArgumentException(e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new IllegalArgumentException(e); |
||||
} catch (InvocationTargetException e) { |
||||
throw new IllegalArgumentException(e); |
||||
} |
||||
} |
||||
|
||||
final private <T extends BACKING_INTERFACE> T fromStateInternal(STATE n, Class<T> c) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { |
||||
// TODO this is fragile
|
||||
Class<? extends STATE> stateInterface = (Class<? extends STATE>) n.getClass().getInterfaces()[0]; |
||||
Constructor<T> nodeConstructor = ClassUtils.getConstructorIfAvailable(c, stateInterface); |
||||
if (nodeConstructor != null) { |
||||
// TODO is this the correct way to instantiate or does Spring have a preferred way?
|
||||
log.info("Using " + c + " constructor taking " + stateInterface); |
||||
return nodeConstructor.newInstance(n); |
||||
} |
||||
|
||||
Constructor<T> noArgConstructor = ClassUtils.getConstructorIfAvailable(c); |
||||
if (noArgConstructor != null) { |
||||
log.info("Using " + c + " no-arg constructor"); |
||||
T t = noArgConstructor.newInstance(); |
||||
setState(t, n); |
||||
return t; |
||||
} |
||||
|
||||
throw new IllegalArgumentException(getClass().getSimpleName() + ": entity " + c + " must have either a constructor taking [" + stateInterface + |
||||
"] or a no-arg constructor and state set method"); |
||||
} |
||||
|
||||
/** |
||||
* Subclasses must implement to set state |
||||
* @param entity |
||||
* @param s |
||||
*/ |
||||
protected abstract void setState(BACKING_INTERFACE entity, STATE s); |
||||
|
||||
} |
||||
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
package org.springframework.persistence.support; |
||||
|
||||
import org.apache.commons.logging.Log; |
||||
import org.apache.commons.logging.LogFactory; |
||||
import org.springframework.beans.factory.annotation.Configurable; |
||||
import org.springframework.persistence.RelatedEntity; |
||||
|
||||
/** |
||||
* Abstract superaspect to advise field read and write |
||||
* and introduce a mixin interface. |
||||
* |
||||
* @param <N> type of introduced interface |
||||
* |
||||
* @author Rod Johnson |
||||
*/ |
||||
privileged abstract public aspect AbstractMixinFields<N> { |
||||
|
||||
protected final Log log = LogFactory.getLog(getClass()); |
||||
|
||||
//------------------------------------------------------------------------- |
||||
// ITDs to add behavior and state to classes |
||||
//------------------------------------------------------------------------- |
||||
// Enable Spring DI for all mixed-in objects |
||||
declare @type: N+: @Configurable; |
||||
|
||||
//------------------------------------------------------------------------- |
||||
// Advice for field get/set to delegate to backing Node. |
||||
//------------------------------------------------------------------------- |
||||
protected pointcut entityFieldGet(N entity) : |
||||
get(* N+.*) && |
||||
this(entity) && |
||||
!(get(@RelatedEntity * *) |
||||
|| get(* N.*) |
||||
|| getsNotToAdvise()); |
||||
|
||||
/** |
||||
* Never matches. Subclasses can override to exempt certain field reads from advice |
||||
*/ |
||||
protected pointcut getsNotToAdvise(); |
||||
|
||||
protected pointcut entityFieldSet(N entity, Object newVal) : |
||||
set(* N+.*) && |
||||
this(entity) && |
||||
args(newVal) && |
||||
!(set(@RelatedEntity * *) || |
||||
set(* N.*) || |
||||
setsNotToAdvise()); |
||||
|
||||
/** |
||||
* Never matches. Subclasses can override to exempt certain field writes from advice |
||||
*/ |
||||
protected pointcut setsNotToAdvise(); |
||||
|
||||
} |
||||
@ -1,21 +0,0 @@
@@ -1,21 +0,0 @@
|
||||
package org.springframework.persistence.support; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
|
||||
/** |
||||
* Abstract superaspect for aspects that advice |
||||
* field access with a mixin for all types annotated with |
||||
* a given annotation. |
||||
* |
||||
* @param <ET> annotation on entity |
||||
* @param <N> type of introduced interface |
||||
* |
||||
* @author Rod Johnson |
||||
*/ |
||||
privileged abstract public aspect AbstractTypeAnnotatingMixinFields<ET extends Annotation, N> |
||||
extends AbstractMixinFields<N> { |
||||
|
||||
// ITD to introduce N state to Annotated objects |
||||
declare parents : (@ET *) implements N; |
||||
|
||||
} |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
package org.springframework.persistence.support; |
||||
|
||||
|
||||
/** |
||||
* Interface to be implemented by classes that can instantiate and |
||||
* configure entities. |
||||
* The framework must do this when creating objects resulting from finders, |
||||
* even when there may be no no-arg constructor supplied by the user. |
||||
* |
||||
* @author Rod Johnson |
||||
*/ |
||||
public interface EntityInstantiator<BACKING_INTERFACE,STATE> { |
||||
|
||||
/* |
||||
* The best solution if available is to add a constructor that takes Node |
||||
* to each GraphEntity. This means generating an aspect beside every |
||||
* class as Roo presently does. |
||||
* |
||||
* An alternative that does not require Roo |
||||
* is a user-authored constructor taking Node and calling setUnderlyingNode() |
||||
* but this is less elegant and pollutes the domain object. |
||||
* |
||||
* If the user supplies a no-arg constructor, instantiation can occur by invoking it |
||||
* prior to calling setUnderlyingNode(). |
||||
* |
||||
* If the user does NOT supply a no-arg constructor, we must rely on Sun-specific |
||||
* code to instantiate entities without invoking a constructor. |
||||
*/ |
||||
|
||||
<T extends BACKING_INTERFACE> T createEntityFromState(STATE s, Class<T> c); |
||||
|
||||
} |
||||
Loading…
Reference in new issue