[jgentle commit] r67 - fix for issue 3 - optimize performance

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 17, 2009, 11:55:08 AM7/17/09
to jgentl...@googlegroups.com
Author: Skydunkpro
Date: Fri Jul 17 08:54:34 2009
New Revision: 67

Modified:
trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java

trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/ObjectAttachImpl.java
trunk/JGentleProject/src/org/jgentleframework/context/JGentle.java

trunk/JGentleProject/src/org/jgentleframework/context/ProviderCoreCreator.java

trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java

trunk/JGentleProject/src/org/jgentleframework/context/injecting/Provider.java

trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManager.java

trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManagerImpl.java
trunk/JGentleProject/src/org/jgentleframework/utils/Utils.java

Log:
fix for issue 3 - optimize performance

Modified:
trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/configure/enums/Scope.java
Fri Jul 17 08:54:34 2009
@@ -35,8 +35,10 @@
import org.jgentleframework.core.InvalidOperationException;
import org.jgentleframework.core.factory.BeanCreationProcessor;
import org.jgentleframework.core.reflection.metadata.Definition;
+import org.jgentleframework.utils.DefinitionUtils;
import org.jgentleframework.utils.ReflectUtils;
import org.jgentleframework.utils.data.NullClass;
+import org.jgentleframework.utils.data.Pair;
import org.jgentleframework.web.WebProvider;

/**
@@ -84,7 +86,19 @@
}

/** The log. */
- private final Log log = LogFactory.getLog(getClass());
+ private final Log log = LogFactory.getLog(getClass());
+
+ /** The obj factory. */
+ ObjectBeanFactory objFactory = null;
+
+ /** The provider. */
+ Provider provider = null;
+
+ /** The scope list. */
+ Map<String, ScopeInstance> scopeList = null;
+
+ /** The map direct list. */
+ Map<String, Object> mapDirectList = null;

/*
* (non-Javadoc)
@@ -146,9 +160,16 @@
ObjectBeanFactory objFactory) {

Object result = null;
- Provider provider = objFactory.getProvider();
- Map<String, ScopeInstance> scopeList = objFactory.getScopeList();
- Map<String, Object> mapDirectList = objFactory.getMapDirectList();
+ this.objFactory = objFactory == null ? objFactory : this.objFactory;
+ this.provider = provider == null
+ || provider != objFactory.getProvider() ? objFactory
+ .getProvider() : this.provider;
+ this.scopeList = this.scopeList == null
+ || scopeList != objFactory.getScopeList() ? objFactory
+ .getScopeList() : this.scopeList;
+ this.mapDirectList = this.mapDirectList == null
+ || mapDirectList != objFactory.getMapDirectList() ? objFactory
+ .getMapDirectList() : this.mapDirectList;
// If is Singleton scope
Scope scope = null;
synchronized (scopeList) {
@@ -162,7 +183,14 @@
}
}
if (selector instanceof CoreInstantiationSelectorImpl) {
+ Pair<Class<?>[], Object[]> pairCons = DefinitionUtils
+ .findArgsOfDefaultConstructor(selector
+ .getDefinition(), this.provider);
+ Class<?>[] argTypes = pairCons.getKeyPair();
+ Object[] args = pairCons.getValuePair();
CoreInstantiationSelector coreSelector = (CoreInstantiationSelector)
selector;
+ coreSelector.setArgTypes(argTypes);
+ coreSelector.setArgs(args);
String mappingName = coreSelector.getMappingName();
if (mappingName != null && !mappingName.isEmpty()) {
if (mappingName.indexOf(":") != -1) {
@@ -189,10 +217,10 @@
}
if (result == NullClass.class)
result = null;
- // Đưa object vừa khởi tạo vào danh sách singleton cache
- synchronized (mapDirectList) {
- mapDirectList.put(scopeName, result);
- }
+ }
+ // Đưa object vừa khởi tạo vào danh sách singleton cache
+ synchronized (mapDirectList) {
+ mapDirectList.put(scopeName, result);
}
}
}

Modified:
trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/ObjectAttachImpl.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/ObjectAttachImpl.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/configure/objectmeta/ObjectAttachImpl.java
Fri Jul 17 08:54:34 2009
@@ -53,8 +53,8 @@
/** The type list. */
private ArrayList<Class<?>> typeList = new ArrayList<Class<?>>();

- /** lazy_init property, default setting is <b>true</b>. */
- private boolean lazyInit = true;
+ /** lazy_init property, default setting is <b>false</b>. */
+ private boolean lazyInit = false;

/**
* The Constructor.

Modified: trunk/JGentleProject/src/org/jgentleframework/context/JGentle.java
==============================================================================
--- trunk/JGentleProject/src/org/jgentleframework/context/JGentle.java
(original)
+++ trunk/JGentleProject/src/org/jgentleframework/context/JGentle.java Fri
Jul 17 08:54:34 2009
@@ -466,7 +466,7 @@
/*
* Thực thi các xử lý trước khi khởi tạo CSC
*/
- ArrayList<Configurable> configInstances = result.getConfigInstances();
+ List<Configurable> configInstances = result.getConfigInstances();
for (BeforeInitContext obj : JGentle.beforeInitContextList) {
obj.beforeInitContext(result, configInstances
.toArray(new Configurable[configInstances.size()]));
@@ -656,10 +656,10 @@
*/
protected static void invokeCSCInit(ServiceProvider provider,
ComponentServiceContextType<Configurable> csc,
- ArrayList<Configurable> configInstances) {
+ List<Configurable> configInstances) {

Class<? extends Configurable> rct = csc.returnClassType();
- ArrayList<Configurable> configList = new ArrayList<Configurable>();
+ List<Configurable> configList = new ArrayList<Configurable>();
// Thực thi lọc các config instances phù hợp.
for (Configurable config : configInstances) {
if (ReflectUtils.isCast(rct, config)) {

Modified:
trunk/JGentleProject/src/org/jgentleframework/context/ProviderCoreCreator.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/context/ProviderCoreCreator.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/context/ProviderCoreCreator.java
Fri Jul 17 08:54:34 2009
@@ -36,16 +36,17 @@
import
org.jgentleframework.context.injecting.autodetect.ExtensionPointsDetector;
import org.jgentleframework.context.injecting.autodetect.FirstDetector;
import org.jgentleframework.context.injecting.scope.ScopeImplementation;
-import org.jgentleframework.context.injecting.scope.ScopeInstance;
import org.jgentleframework.context.services.ServiceHandler;
import org.jgentleframework.context.support.CoreInstantiationSelector;
import org.jgentleframework.context.support.CoreInstantiationSelectorImpl;
-import org.jgentleframework.core.JGentleRuntimeException;
import org.jgentleframework.core.JGentleException;
+import org.jgentleframework.core.JGentleRuntimeException;
import org.jgentleframework.core.factory.BeanCreationProcessor;
import org.jgentleframework.core.factory.InOutDependencyException;
import org.jgentleframework.core.intercept.support.Matcher;
import org.jgentleframework.core.reflection.metadata.Definition;
+import org.jgentleframework.utils.ReflectUtils;
+import org.jgentleframework.utils.Utils;

/**
* This is an implementation of {@link Provider} interface, is responsible
for
@@ -65,7 +66,7 @@
* The {@link ArrayList} holds a list of config instance of this
* {@link Provider}.
*/
- private ArrayList<Configurable> configInstances = null;
+ private List<Configurable> configInstances = null;

/** the detector controller. */
private Detector detectorController = null;
@@ -102,6 +103,10 @@
return ProviderCoreCreator.this.getBean(refer);
}
};
+ this.mappingList = this.objectBeanFactory.getMappingList();
+ this.mapDirectList = this.objectBeanFactory.getMapDirectList();
+ this.aliasMap = this.objectBeanFactory.getAliasMap();
+ this.scopeList = this.objectBeanFactory.getScopeList();
this.detectorController = new FirstDetector(this);
this.matcherCache = new ConcurrentHashMap<Definition,
Matcher<Definition>>();
this.interceptorList = new HashMap<Matcher<Definition>,
ArrayList<Object>>();
@@ -115,6 +120,64 @@
init(OLArray);
}

+ /** The NUL l_ sharedobject. */
+ static Object NULL_SHAREDOBJECT = new Object();
+
+ /**
+ * Return shared object.
+ *
+ * @param scopeName
+ * the scope name
+ * @return the object
+ */
+ protected Object returnSharedObject(String scopeName) {
+
+ if (null != scopeName) {
+ synchronized (mapDirectList) {
+ if (mapDirectList.containsKey(scopeName)) {
+ return mapDirectList.get(scopeName);
+ }
+ }
+ }
+ return NULL_SHAREDOBJECT;
+ }
+
+ /**
+ * The Class AppropriateScopeNameClass.
+ *
+ * @author Quoc Chung - mailto: <a
+ * href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
+ * @date Jul 17, 2009
+ */
+ static class AppropriateScopeNameClass {
+ /**
+ * Instantiates a new appropriate scope name class.
+ *
+ * @param clazz
+ * the clazz
+ * @param targetClass
+ * the target class
+ * @param defininition
+ * the defininition
+ */
+ public AppropriateScopeNameClass(Class<?> clazz, Class<?> targetClass,
+ Definition defininition) {
+
+ this.clazz = clazz;
+ this.targetClass = targetClass;
+ this.definition = defininition;
+ }
+
+ /** The clazz. */
+ Class<?> clazz = null;
+
+ /** The target class. */
+ Class<?> targetClass = null;
+
+ /** The definition. */
+ Definition definition = null;
+ }
+
/*
* (non-Javadoc)
* @see
@@ -124,14 +187,52 @@
@Override
public <T> T getBean(Class<T> clazz) {

+ String scopeName = this.rootScopeName.get(clazz);
+ Object result = returnSharedObject(scopeName);
+ if (result != ProviderCoreCreator.NULL_SHAREDOBJECT)
+ return (T) result;
+ AppropriateScopeNameClass asc = doAppropriateScopeName(clazz);
+ return (T) getBeanInstance(clazz, asc.targetClass, null, asc.definition);
+ }
+
+ /**
+ * Do appropriate scope name.
+ *
+ * @param obj
+ * the obj
+ * @return the appropriate scope name class
+ */
+ protected AppropriateScopeNameClass doAppropriateScopeName(Object obj) {
+
+ Class<?> clazz = null;
Class<?> targetClass = null;
- if (this.objectBeanFactory.getMappingList().containsKey(clazz)) {
- targetClass = this.objectBeanFactory.getMappingList().get(clazz);
+ Definition definition = null;
+ String mappingName = null;
+ if (ReflectUtils.isClass(obj)) {
+ clazz = (Class<?>) obj;
+ targetClass = this.mappingList.get(obj);
+ targetClass = null == targetClass ? clazz : targetClass;
+ definition = this.defManager.getDefinition(targetClass);
}
- else
- targetClass = clazz;
- Definition def = this.defManager.getDefinition(targetClass);
- return (T) getBeanInstance(clazz, targetClass, null, def);
+ else if (ReflectUtils.isCast(Definition.class, obj)) {
+ definition = (Definition) obj;
+ clazz = (Class<?>) definition.getKey();
+ targetClass = (Class<?>) definition.getKey();
+ }
+ else if (ReflectUtils.isCast(String.class, obj)) {
+ String str = (String) obj;
+ mappingName = str.replaceAll(Configurable.REF_MAPPING, "").trim();
+ if (str.startsWith(Configurable.REF_MAPPING)) {
+ clazz = aliasMap.get(mappingName).getKey();
+ targetClass = aliasMap.get(mappingName).getValue();
+ definition = this.getDefinitionManager().getDefinition(
+ aliasMap.get(mappingName).getValue());
+ }
+ }
+ if (clazz != null && targetClass != null && definition != null)
+ this.rootScopeName.put(clazz, Utils.createScopeName(clazz,
+ targetClass, definition, mappingName));
+ return new AppropriateScopeNameClass(clazz, targetClass, definition);
}

/*
@@ -143,10 +244,15 @@
@Override
public Object getBean(Definition def) {

- if (def != null) {
+ if (null != def) {
+ String scopeName = this.rootScopeName.get(def);
+ Object result = returnSharedObject(scopeName);
+ if (result != ProviderCoreCreator.NULL_SHAREDOBJECT)
+ return result;
+ AppropriateScopeNameClass asc = doAppropriateScopeName(def);
if (def.isInterpretedOfClass()) {
- return this.getBeanInstance((Class<?>) def.getKey(),
- (Class<?>) def.getKey(), null, def);
+ return this.getBeanInstance(asc.clazz, asc.targetClass, null,
+ def);
}
else {
if (log.isErrorEnabled()) {
@@ -197,9 +303,13 @@

Definition def = this.defManager.getDefinition(ID);
if (def != null) {
+ String scopeName = this.rootScopeName.get(def);
+ Object result = returnSharedObject(scopeName);
+ if (result != ProviderCoreCreator.NULL_SHAREDOBJECT)
+ return result;
+ AppropriateScopeNameClass asc = doAppropriateScopeName(def);
if (def.isInterpretedOfClass()) {
- return getBeanInstance((Class<?>) def.getKey(), (Class<?>) def
- .getKey(), null, def);
+ return getBeanInstance(asc.clazz, asc.targetClass, null, def);
}
else {
if (log.isErrorEnabled()) {
@@ -221,19 +331,18 @@
@Override
public Object getBeanBoundToMapping(String mappingName) {

- if (this.objectBeanFactory.getAliasMap().containsKey(mappingName)) {
- Class<?> type = this.objectBeanFactory.getAliasMap().get(
- mappingName).getKey();
- Class<?> targetClass = this.objectBeanFactory.getAliasMap().get(
- mappingName).getValue();
- Definition def = this.getDefinitionManager().getDefinition(
- this.objectBeanFactory.getAliasMap().get(mappingName)
- .getValue());
- return getBeanInstance(type, targetClass, null, def);
- }
- else {
- return null;
+ if (this.aliasMap.containsKey(mappingName)) {
+ String scopeName = this.rootScopeName.get(Configurable.REF_MAPPING
+ + mappingName);
+ Object result = returnSharedObject(scopeName);
+ if (result != ProviderCoreCreator.NULL_SHAREDOBJECT)
+ return result;
+ AppropriateScopeNameClass asc =
doAppropriateScopeName(Configurable.REF_MAPPING
+ + mappingName);
+ return getBeanInstance(asc.clazz, asc.targetClass, null,
+ asc.definition);
}
+ return null;
}

/*
@@ -254,8 +363,6 @@
CoreInstantiationSelector coreSelector = new
CoreInstantiationSelectorImpl(
ref);
// creates scope info, default is SINGLETON
- Map<String, ScopeInstance> scopeList = this.objectBeanFactory
- .getScopeList();
synchronized (scopeList) {
if (!scopeList.containsKey(ref)) {
scopeList.put(ref, Scope.SINGLETON);
@@ -280,7 +387,7 @@
* @see
org.jgentleframework.context.injecting.Provider#getConfigInstances()
*/
@Override
- public ArrayList<Configurable> getConfigInstances() {
+ public List<Configurable> getConfigInstances() {

return this.configInstances;
}
@@ -297,6 +404,8 @@
}

/**
+ * Gets the object bean factory.
+ *
* @return the objectBeanFactory
*/
public ObjectBeanFactory getObjectBeanFactory() {

Modified:
trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/context/injecting/AbstractBeanFactory.java
Fri Jul 17 08:54:34 2009
@@ -21,8 +21,10 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.Map.Entry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -64,13 +66,20 @@
*/
public abstract class AbstractBeanFactory extends AbstractLoadingFactory
implements IAbstractBeanFactory, Provider {
- /** The log. */
- protected final Log log = LogFactory.getLog(getClass());
-
/** The Constant staticLog. */
private final static Log staticLog = LogFactory
.getLog(AbstractBeanFactory.class);

+ /*
+ * (non-Javadoc)
+ * @see org.jgentleframework.context.injecting.Provider#getRootScopeName()
+ */
+ @Override
+ public Map<Object, String> getRootScopeName() {
+
+ return rootScopeName;
+ }
+
/**
* This method is responsible for annotating {@link Definition}
* instantiation.
@@ -249,11 +258,30 @@
}
}

+ /** The alias map. */
+ protected Map<String, Entry<Class<?>, Class<?>>> aliasMap = null;
+
+ /** The log. */
+ protected final Log log = LogFactory
+ .getLog(getClass());
+
+ /** The map direct list. */
+ protected Map<String, Object> mapDirectList = null;
+
+ /** The mapping list. */
+ protected Map<Class<?>, Class<?>> mappingList = null;
+
/** The {@link ScopeController}. */
- protected ScopeController scopeController = new ScopeController();
+ protected ScopeController scopeController = new ScopeController();
+
+ /** The scope list. */
+ protected Map<String, ScopeInstance> scopeList = null;

/** The {@link ServiceHandler}. */
- protected ServiceHandler serviceHandler = null;
+ protected ServiceHandler serviceHandler = null;
+
+ /** The root scope name. */
+ protected Map<Object, String> rootScopeName = new Hashtable<Object,
String>();

/**
* Finds args of default constructor.
@@ -313,17 +341,8 @@
String mappingName, Definition definition) {

Assertor.notNull(type);
- targetClass = targetClass == null ? this.objectBeanFactory
- .getMappingList().get(type) : targetClass;
- targetClass = targetClass == null ? type : targetClass;
- if (definition == null) {
- definition = this.defManager.getDefinition(targetClass);
- }
- Pair<Class<?>[], Object[]> pairCons =
findArgsOfDefaultConstructor(definition);
- Class<?>[] argTypes = pairCons.getKeyPair();
- Object[] args = pairCons.getValuePair();
CoreInstantiationSelector coreSelector = new
CoreInstantiationSelectorImpl(
- type, targetClass, mappingName, argTypes, args, definition);
+ type, targetClass, mappingName, null, null, definition);
return getBeanInstance(coreSelector);
}


Modified:
trunk/JGentleProject/src/org/jgentleframework/context/injecting/Provider.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/context/injecting/Provider.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/context/injecting/Provider.java
Fri Jul 17 08:54:34 2009
@@ -18,6 +18,8 @@
package org.jgentleframework.context.injecting;

import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;

import org.jgentleframework.configure.Configurable;
import org.jgentleframework.context.Context;
@@ -60,6 +62,13 @@
public <T> T getBean(Class<T> type);

/**
+ * Gets the root scope name {@link Map map}.
+ *
+ * @return the singletonScopeName
+ */
+ public Map<Object, String> getRootScopeName();
+
+ /**
* Returns an instance bound to the given {@link Definition}
*
* @param def
@@ -107,10 +116,8 @@

/**
* Returns the list of configurable instances of this container.
- *
- * @return {@link ArrayList}
*/
- public ArrayList<Configurable> getConfigInstances();
+ public List<Configurable> getConfigInstances();

/**
* Returns the detector controller of this container.

Modified:
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManager.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManager.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManager.java
Fri Jul 17 08:54:34 2009
@@ -43,6 +43,7 @@
* href="mailto:skydu...@yahoo.com">skydu...@yahoo.com</a>
* @date Oct 10, 2007
* @see IAbstractDefinitionExceptionCatcher
+ * @see DefinitionManagerImpl
*/
public interface DefinitionManager extends IAnnotationVisitor,
IAbstractDefinitionExceptionCatcher {
@@ -113,9 +114,20 @@
public Definition getDefinition(Object obj);

/**
- * Returns the interpreted {@link Definition} of given object. In case the
- * corresponding {@link Definition} is not existed, returned value will be
- * <b>null</b>.
+ * Returns the interpreted {@link Definition} of given object class. In
case
+ * the corresponding {@link Definition} is not existed, returned value
will
+ * be <b>null</b>.
+ *
+ * @param clazz
+ * the given object class
+ * @return a {@link Definition} is it exists, if not, return <b>null</b>.
+ */
+ public Definition getDefinition(Class<?> clazz);
+
+ /**
+ * Returns the interpreted {@link Definition} of given string ID. In case
+ * the corresponding {@link Definition} is not existed, returned value
will
+ * be <b>null</b>.
*
* @param ID
* the given ID of {@link Definition}

Modified:
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManagerImpl.java
==============================================================================
---
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManagerImpl.java
(original)
+++
trunk/JGentleProject/src/org/jgentleframework/core/handling/DefinitionManagerImpl.java
Fri Jul 17 08:54:34 2009
@@ -35,7 +35,6 @@
import org.jgentleframework.utils.Assertor;
import org.jgentleframework.utils.ReflectUtils;

-// TODO: Auto-generated Javadoc
/**
* An implementation of {@link DefinitionManager}.
*
@@ -171,6 +170,26 @@
}

/**
+ * Kiểm tra loop validate thông qua hệ thống cây annotation.
+ *
+ * @param object
+ * đối tượng cần kiểm tra loop validate annotation.
+ * @return Trả về <b>true</b> nếu object có chứa annotation đính kèm,
ngược
+ * lại trả về <b>false</b>.
+ */
+ private boolean checkLoopValidation(Object object) {
+
+ // validate dữ liệu thông tin annotation trước khi diễn dịch thành
+ // definition.
+ if (AnnotationUtils.getAnnotations(object, Types.DEFAULT).length > 0) {
+ checkLoopValidation(object, AnnotationUtils.getAnnotations(object,
+ Types.DEFAULT));
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Check loop validation.
*
* @param object
@@ -259,26 +278,6 @@
while (temp.size() != 0);
}

- /**
- * Kiểm tra loop validate thông qua hệ thống cây annotation.
- *
- * @param object
- * đối tượng cần kiểm tra loop validate annotation.
- * @return Trả về <b>true</b> nếu object có chứa annotation đính kèm,
ngược
- * lại trả về <b>false</b>.
- */
- private boolean checkLoopValidation(Object object) {
-
- // validate dữ liệu thông tin annotation trước khi diễn dịch thành
- // definition.
- if (AnnotationUtils.getAnnotations(object, Types.DEFAULT).length > 0) {
- checkLoopValidation(object, AnnotationUtils.getAnnotations(object,
- Types.DEFAULT));
- return true;
- }
- return false;
- }
-
/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
@@ -330,6 +329,20 @@

/*
* (non-Javadoc)
+ * @see
+ * org.jgentleframework.core.handling.DefinitionManager#getDefinition(java
+ * .lang.Class)
+ */
+ @Override
+ public Definition getDefinition(Class<?> clazz) {
+
+ if (!containsDefinition(clazz))
+ this.loadDefinition(clazz);
+ return this.defList.get(clazz);
+ }
+
+ /*
+ * (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
* DefinitionManager#getDefinition(java.lang.String)
*/
@@ -364,173 +377,6 @@
/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * IDefinitionManager#loadDefinition(java.lang.Class)
- */
- @Override
- public void loadDefinition(Class<?> clazz) {
-
- Assertor.notNull(clazz);
- Definition definition = loadDefinition((Object) clazz);
- this.putDefinition(clazz, definition);
- }
-
- /*
- * (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * DefinitionManager#loadDefinition(java.lang.Class, java.lang.String)
- */
- @Override
- public void loadDefinition(Class<?> clazz, String ID) {
-
- Assertor.notNull(clazz);
- Definition definition = loadDefinition((Object) clazz);
- this.putDefinition(ID, definition);
- }
-
- /*
- * (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * IDefinitionManager#loadDefinition(java.lang.reflect.Field)
- */
- @Override
- public void loadDefinition(Field field) {
-
- Assertor.notNull(field);
- Definition definition = loadDefinition((Object) field);
- this.putDefinition(field, definition);
- }
-
- /*
- * (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * IDefinitionManager#loadDefinition(java.lang.reflect.Method)
- */
- @Override
- public void loadDefinition(Method method) {
-
- Assertor.notNull(method);
- Definition definition = loadDefinition((Object) method);
- this.putDefinition(method, definition);
- }
-
- /*
- * (non-Javadoc)
- * @see
- *
org.jgentleframework.core.metadatahandling.defhandling.DefinitionManager
- * #loadDefinition(java.lang.reflect.Constructor)
- */
- @Override
- public void loadDefinition(Constructor<?> constructor) {
-
- Assertor.notNull(constructor);
- Definition definition = loadDefinition((Object) constructor);
- this.putDefinition(constructor, definition);
- }
-
- /**
- * Creates {@link Definition}.
- *
- * @param object
- * the object
- * @return the definition
- */
- private synchronized Definition loadDefinition(Object object) {
-
- // validate thông tin annotation trước khi
- // diễn dịch thành definition.
- checkLoopValidation(object);
- Definition result = buildDefinition(object);
- // Nếu đối tượng truyền vào là một method.
- if (ReflectUtils.isMethod(object)) {
- Method method = (Method) object;
- /*
- * Kiểm tra thông tin parameter nếu có
- */
- if (method.getParameterTypes().length > 0) {
- Definition[] paraDefLst = new Definition[method
- .getParameterTypes().length];
- for (int i = 0; i < paraDefLst.length; i++) {
- Annotation[] list = method.getParameterAnnotations()[i];
- if (list.length != 0) {
- // validate thông tin annotation trước khi
- // diễn dịch thành definition.
- checkLoopValidation(method, list);
- Definition def = buildDefinition(list, method);
- paraDefLst[i] = def;
- }
- }
- result.setParameterDefList(paraDefLst);
- }
- }
- else if (ReflectUtils.isConstructor(object)) {
- Constructor<?> constructor = (Constructor<?>) object;
- if (constructor.getParameterTypes().length > 0) {
- Definition[] paraDefLst = new Definition[constructor
- .getParameterTypes().length];
- for (int i = 0; i < paraDefLst.length; i++) {
- Annotation[] list = constructor.getParameterAnnotations()[i];
- if (list.length != 0) {
- // validate thông tin annotation trước khi
- // diễn dịch thành definition.
- checkLoopValidation(constructor, list);
- Definition def = buildDefinition(list, constructor);
- paraDefLst[i] = def;
- }
- }
- result.setParameterDefList(paraDefLst);
- }
- }
- // Nếu đối tượng truyền vào là một Class
- else if (ReflectUtils.isClass(object)) {
- Class<?> clazz = (Class<?>) object;
- // Khởi tạo definition cho field của class nếu có
- Field[] fieldList = ReflectUtils.getAllDeclaredFields(clazz);
- if (fieldList != null && fieldList.length != 0) {
- for (Field field : fieldList) {
- int check = 0;
- for (Field fil : result.getFieldDefList().keySet()) {
- if (ReflectUtils.equals(field, fil)) {
- check++;
- }
- }
- if (check == 0 && checkLoopValidation(field)) {
- result.getFieldDefList().put(field,
- getDefinition(field));
- }
- }
- }
- // creates definition of constructors if they exist.
- Constructor<?>[] constructorList = clazz.getDeclaredConstructors();
- if (constructorList != null && constructorList.length != 0) {
- for (Constructor<?> constructor : constructorList) {
- Definition def = getDefinition(constructor);
- result.getConstructorDefList().put(constructor, def);
- }
- }
- // creates definition of all methods and their parameters in this
- // declaring class if they exist.
- Method[] methodList = ReflectUtils.getAllDeclaredMethods(clazz);
- if (methodList != null && methodList.length != 0) {
- for (Method method : methodList) {
- int check = 0;
- for (Method met : result.getMethodDefList().keySet()) {
- if (ReflectUtils.equals(met, method)) {
- check++;
- }
- }
- if (check == 0 && checkLoopValidation(method)) {
- result.getMethodDefList().put(method,
- getDefinition(method));
- }
- }
- }
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
* DefinitionManager#loadCustomizedDefinition(java.lang.Class,
* java.lang.annotation.Annotation)
*/
@@ -607,40 +453,27 @@
/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * DefinitionManager#loadDefinition(java.lang.String, java.lang.Object,
+ * DefinitionManager#loadCustomizedDefinition(java.lang.reflect.Field,
* java.lang.Class, java.lang.annotation.Annotation)
*/
@Override
- public Definition loadCustomizedDefinition(String ID, Object obj,
+ public synchronized Definition loadCustomizedDefinition(Field field,
Class<?> clazz, Annotation annotation) {

- if (ReflectUtils.isCast(Field.class, obj)) {
- return loadCustomizedDefinition(ID, (Field) obj, clazz, annotation);
- }
- else if (ReflectUtils.isCast(Method.class, obj)) {
- return loadCustomizedDefinition(ID, (Method) obj, clazz, annotation);
- }
- else {
- throw new InOutDependencyException(
- "Invalid type '"
- + obj.getClass()
- + "' for arguments 'obj' of loadDefinition method! Only Field '"
- + Field.class + "' or Method '" + Method.class
- + "' are permitted !");
- }
+ return loadCustomizedDefinition(null, field, clazz, annotation);
}

/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * DefinitionManager#loadCustomizedDefinition(java.lang.reflect.Field,
+ * DefinitionManager#loadCustomizedDefinition(java.lang.reflect.Method,
* java.lang.Class, java.lang.annotation.Annotation)
*/
@Override
- public synchronized Definition loadCustomizedDefinition(Field field,
+ public synchronized Definition loadCustomizedDefinition(Method method,
Class<?> clazz, Annotation annotation) {

- return loadCustomizedDefinition(null, field, clazz, annotation);
+ return loadCustomizedDefinition(null, method, clazz, annotation);
}

/*
@@ -695,19 +528,6 @@
/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * DefinitionManager#loadCustomizedDefinition(java.lang.reflect.Method,
- * java.lang.Class, java.lang.annotation.Annotation)
- */
- @Override
- public synchronized Definition loadCustomizedDefinition(Method method,
- Class<?> clazz, Annotation annotation) {
-
- return loadCustomizedDefinition(null, method, clazz, annotation);
- }
-
- /*
- * (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
* DefinitionManager#loadDefinition(java.lang.String,
* java.lang.reflect.Method, java.lang.annotation.Annotation[])
*/
@@ -754,6 +574,199 @@
return result;
}

+ /*
+ * (non-Javadoc)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * DefinitionManager#loadDefinition(java.lang.String, java.lang.Object,
+ * java.lang.Class, java.lang.annotation.Annotation)
+ */
+ @Override
+ public Definition loadCustomizedDefinition(String ID, Object obj,
+ Class<?> clazz, Annotation annotation) {
+
+ if (ReflectUtils.isCast(Field.class, obj)) {
+ return loadCustomizedDefinition(ID, (Field) obj, clazz, annotation);
+ }
+ else if (ReflectUtils.isCast(Method.class, obj)) {
+ return loadCustomizedDefinition(ID, (Method) obj, clazz, annotation);
+ }
+ else {
+ throw new InOutDependencyException(
+ "Invalid type '"
+ + obj.getClass()
+ + "' for arguments 'obj' of loadDefinition method! Only Field '"
+ + Field.class + "' or Method '" + Method.class
+ + "' are permitted !");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * IDefinitionManager#loadDefinition(java.lang.Class)
+ */
+ @Override
+ public void loadDefinition(Class<?> clazz) {
+
+ Assertor.notNull(clazz);
+ Definition definition = loadDefinition((Object) clazz);
+ this.putDefinition(clazz, definition);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * DefinitionManager#loadDefinition(java.lang.Class, java.lang.String)
+ */
+ @Override
+ public void loadDefinition(Class<?> clazz, String ID) {
+
+ Assertor.notNull(clazz);
+ Definition definition = loadDefinition((Object) clazz);
+ this.putDefinition(ID, definition);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ *
org.jgentleframework.core.metadatahandling.defhandling.DefinitionManager
+ * #loadDefinition(java.lang.reflect.Constructor)
+ */
+ @Override
+ public void loadDefinition(Constructor<?> constructor) {
+
+ Assertor.notNull(constructor);
+ Definition definition = loadDefinition((Object) constructor);
+ this.putDefinition(constructor, definition);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * IDefinitionManager#loadDefinition(java.lang.reflect.Field)
+ */
+ @Override
+ public void loadDefinition(Field field) {
+
+ Assertor.notNull(field);
+ Definition definition = loadDefinition((Object) field);
+ this.putDefinition(field, definition);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * IDefinitionManager#loadDefinition(java.lang.reflect.Method)
+ */
+ @Override
+ public void loadDefinition(Method method) {
+
+ Assertor.notNull(method);
+ Definition definition = loadDefinition((Object) method);
+ this.putDefinition(method, definition);
+ }
+
+ /**
+ * Creates {@link Definition}.
+ *
+ * @param object
+ * the object
+ * @return the definition
+ */
+ private synchronized Definition loadDefinition(Object object) {
+
+ // validate thông tin annotation trước khi
+ // diễn dịch thành definition.
+ checkLoopValidation(object);
+ Definition result = buildDefinition(object);
+ // Nếu đối tượng truyền vào là một method.
+ if (ReflectUtils.isMethod(object)) {
+ Method method = (Method) object;
+ /*
+ * Kiểm tra thông tin parameter nếu có
+ */
+ if (method.getParameterTypes().length > 0) {
+ Definition[] paraDefLst = new Definition[method
+ .getParameterTypes().length];
+ for (int i = 0; i < paraDefLst.length; i++) {
+ Annotation[] list = method.getParameterAnnotations()[i];
+ if (list.length != 0) {
+ // validate thông tin annotation trước khi
+ // diễn dịch thành definition.
+ checkLoopValidation(method, list);
+ Definition def = buildDefinition(list, method);
+ paraDefLst[i] = def;
+ }
+ }
+ result.setParameterDefList(paraDefLst);
+ }
+ }
+ else if (ReflectUtils.isConstructor(object)) {
+ Constructor<?> constructor = (Constructor<?>) object;
+ if (constructor.getParameterTypes().length > 0) {
+ Definition[] paraDefLst = new Definition[constructor
+ .getParameterTypes().length];
+ for (int i = 0; i < paraDefLst.length; i++) {
+ Annotation[] list = constructor.getParameterAnnotations()[i];
+ if (list.length != 0) {
+ // validate thông tin annotation trước khi
+ // diễn dịch thành definition.
+ checkLoopValidation(constructor, list);
+ Definition def = buildDefinition(list, constructor);
+ paraDefLst[i] = def;
+ }
+ }
+ result.setParameterDefList(paraDefLst);
+ }
+ }
+ // Nếu đối tượng truyền vào là một Class
+ else if (ReflectUtils.isClass(object)) {
+ Class<?> clazz = (Class<?>) object;
+ // Khởi tạo definition cho field của class nếu có
+ Field[] fieldList = ReflectUtils.getAllDeclaredFields(clazz);
+ if (fieldList != null && fieldList.length != 0) {
+ for (Field field : fieldList) {
+ int check = 0;
+ for (Field fil : result.getFieldDefList().keySet()) {
+ if (ReflectUtils.equals(field, fil)) {
+ check++;
+ }
+ }
+ if (check == 0 && checkLoopValidation(field)) {
+ result.getFieldDefList().put(field,
+ getDefinition(field));
+ }
+ }
+ }
+ // creates definition of constructors if they exist.
+ Constructor<?>[] constructorList = clazz.getDeclaredConstructors();
+ if (constructorList != null && constructorList.length != 0) {
+ for (Constructor<?> constructor : constructorList) {
+ Definition def = getDefinition(constructor);
+ result.getConstructorDefList().put(constructor, def);
+ }
+ }
+ // creates definition of all methods and their parameters in this
+ // declaring class if they exist.
+ Method[] methodList = ReflectUtils.getAllDeclaredMethods(clazz);
+ if (methodList != null && methodList.length != 0) {
+ for (Method method : methodList) {
+ int check = 0;
+ for (Method met : result.getMethodDefList().keySet()) {
+ if (ReflectUtils.equals(met, method)) {
+ check++;
+ }
+ }
+ if (check == 0 && checkLoopValidation(method)) {
+ result.getMethodDefList().put(method,
+ getDefinition(method));
+ }
+ }
+ }
+ }
+ return result;
+ }
+
/**
* Put definition.
*
@@ -794,36 +807,36 @@

/*
* (non-Javadoc)
- * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * IDefinitionManager#removeDefinition(java.lang.reflect.Field)
+ * @see
+ *
org.jgentleframework.core.metadatahandling.defhandling.DefinitionManager
+ * #removeDefinition(java.lang.reflect.Constructor)
*/
@Override
- public Definition removeDefinition(Field field) {
+ public Definition removeDefinition(Constructor<?> constructor) {

- return this.defList.remove((Object) field);
+ return this.defList.remove((Object) constructor);
}

/*
* (non-Javadoc)
* @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
- * IDefinitionManager#removeDefinition(java.lang.reflect.Method)
+ * IDefinitionManager#removeDefinition(java.lang.reflect.Field)
*/
@Override
- public Definition removeDefinition(Method method) {
+ public Definition removeDefinition(Field field) {

- return this.defList.remove((Object) method);
+ return this.defList.remove((Object) field);
}

/*
* (non-Javadoc)
- * @see
- *
org.jgentleframework.core.metadatahandling.defhandling.DefinitionManager
- * #removeDefinition(java.lang.reflect.Constructor)
+ * @seeorg.jgentleframework.core.metadatahandling.aohhandling.defhandling.
+ * IDefinitionManager#removeDefinition(java.lang.reflect.Method)
*/
@Override
- public Definition removeDefinition(Constructor<?> constructor) {
+ public Definition removeDefinition(Method method) {

- return this.defList.remove((Object) constructor);
+ return this.defList.remove((Object) method);
}

/*

Modified: trunk/JGentleProject/src/org/jgentleframework/utils/Utils.java
==============================================================================
--- trunk/JGentleProject/src/org/jgentleframework/utils/Utils.java
(original)
+++ trunk/JGentleProject/src/org/jgentleframework/utils/Utils.java Fri Jul
17 08:54:34 2009
@@ -273,13 +273,20 @@
Assertor.notNull(type);
Assertor.notNull(targetClass);
Assertor.notNull(definition);
- String nameScope = null;
- nameScope = type.toString() + ":" + targetClass.toString() + ":"
- + definition.toString();
+ StringBuffer buffer = new StringBuffer();
if (mappingName != null && !mappingName.isEmpty()) {
- nameScope = type.toString() + ":" + nameScope + ":" + mappingName;
+ buffer.append(type.toString());
+ buffer.append(":");
+ buffer.append(mappingName);
}
- return nameScope;
+ else {
+ buffer.append(type.toString());
+ buffer.append(":");
+ buffer.append(targetClass.toString());
+ buffer.append(":");
+ buffer.append(definition.toString());
+ }
+ return buffer.toString();
}

/**
Reply all
Reply to author
Forward
0 new messages