[jboss-cvs] JBossAS SVN: r75182 - projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jun 29 16:49:19 EDT 2008
Author: flavia.rainone at jboss.com
Date: 2008-06-29 16:49:18 -0400 (Sun, 29 Jun 2008)
New Revision: 75182
Added:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorType.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CalleeMetaDataKeyLoader.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CompositeDomainData.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainData.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainJoinPointGraph.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MainJoinPointGraph.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MetaDataKeyLoader.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryJoinPointGraph.java
Removed:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedClassData.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassMemberNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleClassNode.java
Modified:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedData.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldNode.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Node.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKey.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TreeInsertionUtil.java
Log:
[JBAOP-504] Fixed several bugs and tidied up the graph structure. Completed structure to handle domains.
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisableClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.jboss.aop.Advisor;
+
+/**
+ * Node that represents a class in the graph.
+ * Such class must follow one of the restrictions:
+ * <ul>
+ * <li> it is a weaved class;</li>
+ * <li> or it is a super type (class or interface) of a weaved class in the graph.
+ * </li>
+ * </ul>
+ *
+ * Every advisable class node contains:
+ * <ul>
+ * <li> references to all the nodes that represent direct subtypes of it in the
+ * graph;</li>
+ * <li> a subtree of behaviors, containing all behavior nodes associated with this
+ * class node;<li>
+ * <li> and a subtree of fields, containing all field nodes associated with this
+ * class node.</li>
+ * </ul>
+ *
+ * The subtrees are held indirectly, by a reference to {@link AdvisedData}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class AdvisableClassNode extends ClassNode
+{
+ private Class clazz;
+ private AdvisedData advisedData;
+
+ /**
+ * Creates a node that represents a class in the graph.
+ *
+ * @param clazz the type (may be a class or an interface) that the created node
+ * will represent
+ */
+ public AdvisableClassNode(Class clazz)
+ {
+ super(clazz);
+ }
+
+ /**
+ * Returns the advisor of the weaved class this node represents.
+ *
+ * @return the advisor of the weaved class this node represents. If the class
+ * represented is not weaved, this method returns a temporary advisor
+ */
+ public Advisor getMetaDataContainer()
+ {
+ if (this.advisedData != null)
+ {
+ return this.advisedData.getAdvisor();
+ }
+ return super.getMetaDataContainer();
+ }
+
+ /**
+ * Searches for all behavior nodes whose keys match {@code behaviorExpression}.
+ * The search is performed on this advisedData's behavior subtree, hence returning
+ * only members of the class this node represents.
+ *
+ * @param behaviorExpression a search expession. May contain wildcards.
+ * @return a collection containing all the behavior nodes
+ * whose keys match {@code behaviorExpression}.
+ */
+ @SuppressWarnings("all")
+ public Collection<BehaviorNode> searchBehaviors(String behaviorExpression)
+ {
+ if (advisedData == null)
+ {
+ return Collections.EMPTY_LIST;
+ }
+ return advisedData.searchBehaviors(behaviorExpression);
+ }
+
+ /**
+ * Searches for all field nodes whose keys match {@code fieldExpression}.
+ * The search is performed on this advisedData's field subtree, hence returning
+ * only members of the class this node represents.
+ *
+ * @param fieldExpression a search expession. May contain wildcards.
+ * @return a collection containing all the field nodes whose keys
+ * match {@code fieldExpression}.
+ */
+ @SuppressWarnings("all")
+ public Collection<FieldNode> searchFields(String fieldExpression)
+ {
+ if (advisedData == null)
+ {
+ return Collections.EMPTY_LIST;
+ }
+ return advisedData.searchFields(fieldExpression);
+ }
+
+ public String toString()
+ {
+ return "[node: " + clazz.getName() + "]";
+ }
+
+ /**
+ * Returns the advised data contained in this node.
+ *
+ * @return the advised data contained in this node. May be {@code null}.
+ */
+ protected final AdvisedData getAdvisedData()
+ {
+ return this.advisedData;
+ }
+
+ /**
+ * Inserts advised data to this node.
+ *
+ * @param advisedData advised data to be contained in this node
+ */
+ protected final void setAdvisedData(AdvisedData advisedData)
+ {
+ this.advisedData = advisedData;
+ }
+}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedClassData.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedClassData.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedClassData.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -1,88 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.aop.joinpoint.graph;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.jboss.aop.Advisor;
-import org.jboss.aop.AspectManager;
-import org.jboss.aop.Domain;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-class AdvisedClassData extends AdvisedData
-{
- private Set<String> tags;
- private Map<Advisor, AdvisedData> instanceAdvisedData;
-
- public AdvisedClassData(Advisor advisor)
- {
- super(advisor);
- AspectManager manager = advisor.getManager();
- if (manager instanceof Domain)
- {
- this.tags = new TreeSet<String> ();
- do
- {
- Domain domain = (Domain) manager;
- this.tags.add(domain.getDomainName());
- manager = domain.getParent();
- } while (manager instanceof Domain);
- }
- }
-
- public boolean containsTag(String tag)
- {
- return this.tags.contains(tag);
- }
-
- public AdvisedData createInstanceAdvisedData(Advisor advisor)
- {
- AdvisedData queriedData = new AdvisedData(advisor);
- instanceAdvisedData.put(advisor, queriedData);
- return queriedData;
- }
-
- public AdvisedData getInstanceAdvisedData(Advisor advisor)
- {
- if (instanceAdvisedData.containsKey(advisor))
- {
- return instanceAdvisedData.get(advisor);
- }
- AdvisedData queriedData = new AdvisedData(advisor);
- instanceAdvisedData.put(advisor, queriedData);
- return queriedData;
- }
-
- public AdvisedData getAdvisedData(Advisor advisor)
- {
- if (advisor == this.getAdvisor())
- {
- return this;
- }
- return getInstanceAdvisedData(advisor);
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedData.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedData.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/AdvisedData.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -30,6 +30,8 @@
import org.jboss.aop.joinpoint.graph.tree.Tree;
/**
+ * Contains the advised data (behavior and field nodes) associated with an advisor.
+ * All advised data is kept in internal subtrees.
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
@@ -39,6 +41,11 @@
private Tree<FieldNode> fields;
private Tree<BehaviorNode> behaviors;
+ /**
+ * Constructor.
+ *
+ * @param advisor the advisor associated with the advisedData to be created.
+ */
public AdvisedData(Advisor advisor)
{
this.advisor = advisor;
@@ -46,54 +53,115 @@
this.behaviors = new Tree<BehaviorNode>();
}
+ /**
+ * Constructor. Creates a copy of {@code advisedData}.
+ *
+ * @param advisedData advised data to be copied.
+ */
+ protected AdvisedData(AdvisedData advisedData)
+ {
+ this.advisor = advisedData.advisor;
+ this.fields = advisedData.fields;
+ this.behaviors = advisedData.behaviors;
+ }
+
+ /**
+ * Returns the advisor that manages all joinpoints contained in this advisedData.
+ *
+ * @return the advisor associated with this advisedData
+ */
public Advisor getAdvisor()
{
return this.advisor;
}
+ /**
+ * Returns the field node that represents {@code field}.
+ *
+ * @param field a member of the class managed by {@link #getAdvisor}. This field
+ * must be associated with one or more joinpoints.
+ * @return the behavior node that represents {@code field}. If such node
+ * does not exist, it is created and inserted in the field subtree.
+ */
+ public FieldNode getField(Field field)
+ {
+ String defaultKey = FieldNode.getIdentifierKey(field);
+ FieldNode fieldNode = fields.searchValue(defaultKey);
+ if (fieldNode == null)
+ {
+ fieldNode = new FieldNode(advisor, field);
+ TreeInsertionUtil.insertNode(fieldNode, fields, defaultKey);
+ }
+ return fieldNode;
+ }
+
+ /**
+ * Returns the behavior node that represents {@code constructor}.
+ *
+ * @param constructor a member of the class managed by {@link #getAdvisor}. This
+ * constructor must be associated with one or more joinpoints.
+ * @return the behavior node that represents {@code constructor}. If
+ * such node does not exist, it is created and inserted in the
+ * behavior subtree.
+ */
public BehaviorNode getBehavior(Constructor constructor)
{
- String behaviorKey = BehaviorNode.getDefaultKey(constructor);
+ String behaviorKey = BehaviorNode.getIdentifierKey(constructor);
BehaviorNode behaviorNode = behaviors.searchValue(behaviorKey);
if (behaviorNode == null)
{
behaviorNode = new BehaviorNode(advisor, constructor);
- TreeInsertionUtil.insertNode(behaviorNode, behaviorKey, behaviors);
+ TreeInsertionUtil.insertNode(behaviorNode, behaviors, behaviorKey);
}
return behaviorNode;
}
-
+
+ /**
+ * Returns the behavior node that represents {@code method}.
+ *
+ * @param method a member of the class managed by {@link #getAdvisor}. This
+ * method must be associated with one or more joinpoints.
+ * @return the behavior node that represents {@code method}. If such node
+ * does not exist, it is created and inserted in the behavior
+ * subtree.
+ */
public BehaviorNode getBehavior(Method method)
{
- String behaviorKey = BehaviorNode.getDefaultKey(method);
+ String behaviorKey = BehaviorNode.getIdentifierKey(method);
BehaviorNode behaviorNode = behaviors.searchValue(behaviorKey);
if (behaviorNode == null)
{
behaviorNode = new BehaviorNode(this.advisor, method);
- TreeInsertionUtil.insertNode(behaviorNode, behaviorKey, behaviors);
+ TreeInsertionUtil.insertNode(behaviorNode, behaviors, behaviorKey);
}
return behaviorNode;
}
+ /**
+ * Searches for all field nodes whose keys match {@code fieldExpression}.
+ * The search is performed on the field subtree, hence returning only
+ * members associated with {@link #getAdvisor()}.
+ *
+ * @param fieldExpression a search expession. May contain wildcards.
+ * @return a collection containing all the field nodes whose keys
+ * match {@code fieldExpression}.
+ */
+ public Collection<FieldNode> searchFields(String fieldExpression)
+ {
+ return fields.search(fieldExpression);
+ }
+
+ /**
+ * Searches for all behavior nodes whose keys match {@code behaviorExpression}.
+ * The search is performed on the behavior subtree, hence returning only
+ * members associated with {@link #getAdvisor()}.
+ *
+ * @param behaviorExpression a search expession. May contain wildcards.
+ * @return a collection containing all the behavior nodes
+ * whose keys match {@code behaviorExpression}.
+ */
public Collection<BehaviorNode> searchBehaviors(String behaviorExpression)
{
return behaviors.search(behaviorExpression);
}
-
- public FieldNode getField(Field field)
- {
- String defaultKey = FieldNode.getDefaultKey(field);
- FieldNode fieldNode = fields.searchValue(defaultKey);
- if (fieldNode == null)
- {
- fieldNode = new FieldNode(advisor, field);
- TreeInsertionUtil.insertNode(fieldNode, defaultKey, fields);
- }
- return fieldNode;
- }
-
- public Collection<FieldNode> searchFields(String fieldExpression)
- {
- return fields.search(fieldExpression);
- }
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -27,197 +27,323 @@
import java.util.Collection;
import org.jboss.aop.Advisor;
+import org.jboss.aop.CallerConstructorInfo;
+import org.jboss.aop.CallerMethodInfo;
import org.jboss.aop.ConstructionInfo;
import org.jboss.aop.JoinPointInfo;
import org.jboss.aop.joinpoint.graph.tree.Tree;
/**
+ * Node that represents a behavior (constructor or method) in the graph.
+ * Such behavior must have at least a joinpoint associated with it.
+ * <p>
+ * Every behavior node contains:
+ * <ul>
+ * <li> references to execution/construction joinpoints;
+ * <li> a subtree of callees, containing the associated call joinpoints.
+ * </ul>
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
class BehaviorNode implements Node
{
+ private static final CalleeMetaDataKeyLoader CALLEE_KEY_LOADER =
+ new CalleeMetaDataKeyLoader();
private Advisor advisor;
- private BehaviourType behaviourType;
- private Member member;
+ private BehaviorType behaviorType;
+ private Member behavior;
private JoinPointInfo execution;
private ConstructionInfo construction;
- private Tree<JoinPointInfo> calls;
+ private Tree<JoinPointInfo> calls = new Tree<JoinPointInfo>();
- public BehaviorNode(Advisor advisor, Method member)
+ /**
+ * Constructor. Creates a behavior node that represents {@code method} in the
+ * graph.
+ *
+ * @param advisor manages the joinpoints associated with {@code method}
+ * @param method the method to be represented by the created behavior node
+ */
+ public BehaviorNode(Advisor advisor, Method method)
{
this.advisor = advisor;
- this.member = member;
- this.behaviourType = BehaviourType.METHOD;
+ this.behavior = method;
+ this.behaviorType = BehaviorType.METHOD;
}
- public BehaviorNode(Advisor advisor, Constructor member)
+ /**
+ * Constructor. Creates a behavior node that represents {@code constructor} in the
+ * graph.
+ *
+ * @param advisor manages the joinpoints associated with {@code constructor}
+ * @param constructor the constructor to be represented by the created behavior
+ * node
+ */
+ public BehaviorNode(Advisor advisor, Constructor constructor)
{
this.advisor = advisor;
- this.member = member;
- this.behaviourType = BehaviourType.CONSTRUCTOR;
+ this.behavior = constructor;
+ this.behaviorType = BehaviorType.CONSTRUCTOR;
}
- public static final String getDefaultKey(Method member)
+ /**
+ * Returns the key that would identify a behavior node representing {@code method}
+ * in the graph.
+ * <p>
+ * This method must be called whenever there is need to search for a specific
+ * behavior node in the graph.
+ *
+ * @param method the method represented by the hypothetical node whose identifier
+ * key is to be returned
+ * @return the identifier of the behavior node that would represent {@code method}
+ * in the graph
+ * @see #getIdentifierKey()
+ */
+ public static final String getIdentifierKey(Method method)
{
- return getDefaultKey(member, BehaviourType.METHOD);
+ return getIdentifierKey(method, BehaviorType.METHOD);
}
- public static final String getDefaultKey(Constructor member)
+ /**
+ * Returns the key that would identify a behavior node representing {@code
+ * constructor} in the graph.
+ * <p>
+ * This method must be called whenever there is need to search for a specific
+ * behavior node in the graph.
+ *
+ * @param constructor the constructor represented by the hypothetical node whose
+ * identifier key is to be returned
+ * @return the identifier of the behavior node that would represent {@code
+ * constructor} in the graph
+ * @see #getIdentifierKey()
+ */
+ public static final String getIdentifierKey(Constructor constructor)
{
- return getDefaultKey(member, BehaviourType.CONSTRUCTOR);
+ return getIdentifierKey(constructor, BehaviorType.CONSTRUCTOR);
}
- private static final String getDefaultKey(Member member, BehaviourType type)
+ /**
+ * Loads all meta data keys of a behavior node representing {@code behavior}.
+ *
+ * @param behavior the behavior whose metadata keys must be loaded
+ * @param type the type of {@code behavior}
+ * @param prefix a common prefix to be inserted in all generated keys
+ * @param advisor the advisor responsible for returning the metadata associated
+ * with {@code behavior}
+ * @param keys collection where the loaded keys will be loaded
+ */
+ static final void loadMetaDataKeys(Member behavior, BehaviorType type,
+ String prefix, Advisor advisor, Collection<String> keys)
{
- return type.getName(member) + getParameterList(member, type);
- }
-
- private static final String getParameterList(Member member, BehaviourType type)
- {
- Class[] parameterTypes = type.getParameterTypes(member);
- if (parameterTypes.length == 0)
- {
- return "()";
- }
- StringBuffer paramList = new StringBuffer(type.getName(member));
- paramList.append('(');
- for (int i = 0; i < parameterTypes.length; i++)
- {
- paramList.append(parameterTypes[i].getName()).append(' ');
- }
- paramList.append(')');
- return paramList.toString();
- }
-
- public String getDefaultKey()
- {
- return getDefaultKey(this.member, this.behaviourType);
- }
-
- public void loadMetaDataKeys(Collection<String> keys)
- {
- String commonPrefix = behaviourType.getReturnType(member) + "@";
- String commonSuffix = getParameterList(member, behaviourType);
+ String commonPrefix = prefix + type.getReturnType(behavior) + "@";
+ String commonSuffix = getParameterList(behavior, type);
Collection<String> metaDataTags =
- behaviourType.getMetaDataTags(advisor, member);
+ type.getMetaDataTags(advisor, behavior);
for (String metaDataTag: metaDataTags)
{
keys.add(commonPrefix + metaDataTag + commonSuffix);
}
}
- public Member getMember()
+ public String getIdentifierKey()
{
- return this.member;
+ return getIdentifierKey(this.behavior, this.behaviorType);
}
- public Class[] getExceptionTypes()
+ public void loadMetaDataKeys(Collection<String> keys)
{
- return this.behaviourType.getExceptionTypes(member);
+ loadMetaDataKeys(behavior, behaviorType, "", advisor, keys);
}
-
- public boolean hasExecution()
+
+ /**
+ * Returns the behavior represented by this node.
+ *
+ * @return the behavior (a {@code Constructor} or {@code Method}) represented by
+ * this node
+ * @see Constructor
+ * @see Method
+ */
+ public Member getBehavior()
{
- return this.execution != null;
+ return this.behavior;
}
- public JoinPointInfo getExecution()
+ /**
+ * Returns the exception types declared to be thrown by the behavior represented
+ * by this node.
+ *
+ * @return the exceptions types thrown by the behavior represented by this node
+ */
+ public Class[] getExceptionTypes()
{
- return this.execution;
+ return this.behaviorType.getExceptionTypes(behavior);
}
+
- public void setExecution(JoinPointInfo execution)
- {
- this.execution = execution;
- }
-
+ /**
+ * Returns {@code true} if this node contains a construction joinpoint.
+ *
+ * @return {@code true} if this node contains a construction joinpoint
+ */
public boolean hasConstruction()
{
return this.construction != null;
}
+ /**
+ * Returns the construction joinpoint contained in this node.
+ *
+ * @return the construction joinpoint contained in this node. Returns {@code null}
+ * if {@code #hasConstruction()} is {@code false}.
+ */
public ConstructionInfo getConstruction()
{
return this.construction;
}
+ /**
+ * Inserts a construction joinpoint in this node.
+ * <br>
+ * This method must be called only if {@link #hasConstruction()} is {@code false}.
+ * Otherwise, the construction joinpoint previously inserted in this node will be
+ * erased.
+ *
+ * @param construction the construction joinpoint to be inserted in this node
+ */
public void setConstruction(ConstructionInfo construction)
{
this.construction = construction;
}
- public void insertCallee(String calleeName, JoinPointInfo callNode)
+ /**
+ * Returns {@code true} if this node contains an execution joinpoint.
+ *
+ * @return {@code true} if this node contains an execution joinpoint
+ */
+ public boolean hasExecution()
{
- calls.insert(calleeName, callNode);
+ return this.execution != null;
}
- public void searchCallees(String calleeExpression, Collection<JoinPointInfo> result)
+ /**
+ * Returns the execution joinpoint contained in this node.
+ *
+ * @return the execution joinpoint contained in this node. Returns {@code null} if
+ * {@code #hasExecution()} is {@code false}.
+ */
+ public JoinPointInfo getExecution()
{
- calls.search(calleeExpression, result);
+ return this.execution;
}
- private enum BehaviourType
+ /**
+ * Inserts an execution joinpoint in this node.
+ * <br>
+ * This method must be called only if {@link #hasExecution()} is {@code false}.
+ * Otherwise, the execution joinpoint previously inserted in this node will be
+ * erased.
+ *
+ * @param execution the execution joinpoint to be inserted in this node
+ */
+ public void setExecution(JoinPointInfo execution)
{
- CONSTRUCTOR
+ this.execution = execution;
+ }
+
+ /**
+ * Inserts a call joinpoint in the callee subtree.
+ *
+ * @param callInfo a constructor call joinpoint whose caller is the behavior
+ * represented by this node
+ */
+ public synchronized void addCallee(CallerConstructorInfo callInfo)
+ {
+ synchronized(CALLEE_KEY_LOADER)
{
- public String getName(Member member)
+ CALLEE_KEY_LOADER.loadCallee(callInfo.getCalledClass(),
+ callInfo.getConstructor());
+ try
{
- return "new";
+ TreeInsertionUtil.insertObject(callInfo, calls,
+ callInfo.getCalledClass().getName() + '.' + getIdentifierKey(
+ callInfo.getConstructor()), CALLEE_KEY_LOADER);
}
-
- public String getReturnType(Member member)
+ finally
{
- return "";
+ CALLEE_KEY_LOADER.unloadCallee();
}
-
- public Class[] getParameterTypes(Member member)
+ }
+ }
+
+ /**
+ * Inserts a call joinpoint in the callee subtree.
+ *
+ * @param callInfo a method call joinpoint whose caller is the behavior
+ * represented by this node
+ */
+ public synchronized void addCallee(CallerMethodInfo callInfo)
+ {
+ synchronized(CALLEE_KEY_LOADER)
+ {
+ CALLEE_KEY_LOADER.loadCallee(callInfo.getCalledClass(),
+ callInfo.getMethod());
+ try
{
- return ((Constructor) member).getParameterTypes();
+ TreeInsertionUtil.insertObject(callInfo, calls,
+ callInfo.getCalledClass().getName() + '.' + getIdentifierKey(
+ callInfo.getMethod()), CALLEE_KEY_LOADER);
}
-
- public Class[] getExceptionTypes(Member member)
+ finally
{
- return ((Constructor) member).getExceptionTypes();
+ CALLEE_KEY_LOADER.unloadCallee();
}
-
- public Collection<String> getMetaDataTags(Advisor advisor, Member member)
- {
- return advisor.getMetaDataTags((Constructor) member);
- }
- },
- METHOD
+ }
+ }
+
+ /**
+ * Returns all callees identified by keys that match {@code calleeExpression}.
+ *
+ * @param calleeExpression a search expression. This expression can follow the
+ * format {@code "[class name].[identifier key of callee]"
+ * }, where the identifier of callee can be obtained
+ * by invoking {@link #getIdentifierKey(Constructor)}
+ * or {@link #getIdentifierKey(Method)}.
+ * Another possibility is to replace the class name
+ * and/or the name of callee in the format above by
+ * meta data names, preceeded by {@code '@'}. May contain
+ * one or more wildcards ({@code '*'}).
+ * @param result all matching callees will be added to this collection. If more
+ * than one key identifying the same callee is matched by {@code
+ * calleeExpression}, the callee will be added repeatedly to this
+ * collection
+ */
+ public void searchCallees(String calleeExpression, Collection<JoinPointInfo> result)
+ {
+ calls.search(calleeExpression, result);
+ }
+
+ public String toString()
+ {
+ return "[node: " + behavior + "]";
+ }
+
+ private static final String getIdentifierKey(Member member, BehaviorType type)
+ {
+ return type.getName(member) + getParameterList(member, type);
+ }
+
+ private static final String getParameterList(Member member, BehaviorType type)
+ {
+ Class[] parameterTypes = type.getParameterTypes(member);
+ if (parameterTypes.length == 0)
{
- public String getName(Member member)
- {
- return ((Method) member).getReturnType().getName() + " " + member.getName();
- }
-
- public String getReturnType(Member member)
- {
- return ((Method) member).getReturnType().getName() + " ";
- }
-
- public Class[] getParameterTypes(Member member)
- {
- return ((Method) member).getParameterTypes();
- }
-
- public Class[] getExceptionTypes(Member member)
- {
- return ((Method) member).getExceptionTypes();
- }
-
- public Collection<String> getMetaDataTags(Advisor advisor, Member member)
- {
- return advisor.getMetaDataTags((Method) member);
- }
- };
-
- public abstract String getName(Member member);
- public abstract Class[] getExceptionTypes(Member member);
- public abstract Class[] getParameterTypes(Member member);
- public abstract Collection<String> getMetaDataTags(Advisor advisor, Member member);
- public abstract String getReturnType(Member member);
- };
+ return "()";
+ }
+ StringBuffer paramList = new StringBuffer("(");
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ paramList.append(parameterTypes[i].getName()).append(' ');
+ }
+ paramList.append(')');
+ return paramList.toString();
+ }
}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorSearcher.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -168,9 +168,9 @@
{
for (BehaviorNode behaviorNode: behaviors)
{
- if (Util.matchModifiers(attributes, behaviorNode.getMember().getModifiers())
+ if (Util.matchModifiers(attributes, behaviorNode.getBehavior().getModifiers())
&& Util.matchExceptions(exceptions, behaviorNode.getExceptionTypes())
- && (behaviorFilter == null || behaviorFilter.accept((Method) behaviorNode.getMember())))
+ && (behaviorFilter == null || behaviorFilter.accept((Method) behaviorNode.getBehavior())))
{
this.internalSearcher.search(behaviorNode, result);
}
@@ -180,9 +180,9 @@
{
for (BehaviorNode behaviorNode: behaviors)
{
- if (Util.matchModifiers(attributes, behaviorNode.getMember().getModifiers())
+ if (Util.matchModifiers(attributes, behaviorNode.getBehavior().getModifiers())
&& Util.matchExceptions(exceptions, behaviorNode.getExceptionTypes())
- && (behaviorFilter == null || behaviorFilter.accept((Constructor) behaviorNode.getMember())))
+ && (behaviorFilter == null || behaviorFilter.accept((Constructor) behaviorNode.getBehavior())))
{
this.internalSearcher.search(behaviorNode, result);
}
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorType.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorType.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/BehaviorType.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+
+/**
+ * This enum represents the type of a behavior. It allows uniform handling of
+ * {@code Method} and {@code Constructor} through a common interface.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+enum BehaviorType
+{
+ CONSTRUCTOR
+ {
+ public String getDefaultKey(Member member)
+ {
+ return BehaviorNode.getIdentifierKey((Constructor) member);
+ }
+
+ public String getName(Member member)
+ {
+ return "new";
+ }
+
+ public Class[] getParameterTypes(Member member)
+ {
+ return ((Constructor) member).getParameterTypes();
+ }
+
+ public String getReturnType(Member member)
+ {
+ return "";
+ }
+
+ public Class[] getExceptionTypes(Member member)
+ {
+ return ((Constructor) member).getExceptionTypes();
+ }
+
+ public Collection<String> getMetaDataTags(Advisor advisor, Member member)
+ {
+ return advisor.getMetaDataTags((Constructor) member);
+ }
+ },
+ METHOD
+ {
+ public String getDefaultKey(Member member)
+ {
+ return BehaviorNode.getIdentifierKey((Method) member);
+ }
+
+ public String getName(Member member)
+ {
+ return ((Method) member).getReturnType().getName() + " " + member.getName();
+ }
+
+ public Class[] getParameterTypes(Member member)
+ {
+ return ((Method) member).getParameterTypes();
+ }
+
+ public String getReturnType(Member member)
+ {
+ return ((Method) member).getReturnType().getName() + " ";
+ }
+
+ public Class[] getExceptionTypes(Member member)
+ {
+ return ((Method) member).getExceptionTypes();
+ }
+
+ public Collection<String> getMetaDataTags(Advisor advisor, Member member)
+ {
+ return advisor.getMetaDataTags((Method) member);
+ }
+ };
+
+ /**
+ * Returns the default key that would identify a behavior node representing
+ * {@code behavior}.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return the default key of a behavior node representing {@code member}
+ * @see BehaviorNode#getIdentifierKey(Constructor)
+ * @see BehaviorNode#getIdentifierKey(Method)
+ */
+ public abstract String getDefaultKey(Member behavior);
+
+ /**
+ * Returns the name of {@code behavior}.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return if {@code behavior} is a constructor, returns {@code "new"}, if it is
+ * a method, returns the name of the method
+ * @see Method#getName()
+ */
+ public abstract String getName(Member behavior);
+
+ /**
+ * Returns the parameter list of {@code behavior}.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return the parameter list of {@code behavior}
+ * @see Constructor#getParameterTypes()
+ * @see Method#getParameterTypes()
+ */
+ public abstract Class[] getParameterTypes(Member behavior);
+
+ /**
+ * Returns a {@code String} representing the return type of {@code behavior}.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return an empty {@code String} if behavior is a {@code Constructor}, the name
+ * of the return type of behavior otherwise
+ */
+ public abstract String getReturnType(Member behavior);
+
+ /**
+ * Returns the list of exceptions that {@code behavior} declares to throw.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return the list of exceptions that {@code behavior} declares to throw
+ * @see Constructor#getExceptionTypes()
+ * @see Method#getExceptionTypes()
+ */
+ public abstract Class[] getExceptionTypes(Member behavior);
+
+ /**
+ * Returns the meta data tags that apply to {@code behavior}.
+ *
+ * @param behavior a behavior ({@code Constructor} or {@code Method})
+ * @return the meta data tags that apply to {@code behavior}
+ * @see Advisor#getMetaDataTags(Constructor)
+ * @see Advisor#getMetaDataTags(Method)
+ */
+ public abstract Collection<String> getMetaDataTags(Advisor advisor, Member behavior);
+};
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CalleeMetaDataKeyLoader.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CalleeMetaDataKeyLoader.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CalleeMetaDataKeyLoader.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+
+/**
+ * Loads to a collection all meta data keys associated with a callee.
+ * <p>
+ * Must not be used concurrently.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @see MetaDataKeyLoader
+ */
+class CalleeMetaDataKeyLoader implements MetaDataKeyLoader
+{
+ // avoids the cost of creating a collection for metadata keys everytime a
+ // node is added to the graph
+ private Collection<String> tempKeys = new ArrayList<String>(1);
+
+ private String className;
+ private Advisor advisor;
+ private Member member;
+ private BehaviorType type;
+
+ /**
+ * Loads all information referent to a callee. After this method is called,
+ * {@link #loadMetaDataKeys(Collection)} will load the meta data keys that apply
+ * to the loaded callee.
+ *
+ * @param clazz callee class
+ * @param constructor callee constructor
+ */
+ public void loadCallee(Class<?> clazz, Constructor constructor)
+ {
+ this.loadCalleeClass(clazz);
+ this.member = constructor;
+ type = BehaviorType.CONSTRUCTOR;
+ }
+
+ /**
+ * Loads all information referent to a callee. After this method is called,
+ * {@link #loadMetaDataKeys(Collection)} will load the meta data keys that apply
+ * to the loaded callee.
+ *
+ * @param clazz callee class
+ * @param method callee method
+ */
+ public void loadCallee(Class<?> clazz, Method method)
+ {
+ this.loadCalleeClass(clazz);
+ this.member = method;
+ type = BehaviorType.METHOD;
+ }
+
+ /**
+ * Unloads the callee info. This method must be called to unload the information
+ * loaded by a previous execution of one of the {@code loadCallee} methods, in
+ * order to avoid memory leaks.
+ */
+ public void unloadCallee()
+ {
+ this.className = null;
+ this.advisor = null;
+ this.member = null;
+ this.type = null;
+ }
+
+ /**
+ * Load all meta data keys associated with a callee. This method must be called
+ * only after {@code loadCallee} method.
+ *
+ * @throws NullPointerException if this method is called after {@code unloadCallee}
+ * or if it is called before a call to {@code loadCallee} method is
+ * ever performed
+ */
+ public void loadMetaDataKeys(Collection<String> keys)
+ {
+ synchronized (tempKeys)
+ {
+ try
+ {
+ AdvisableClassNode.loadMetaDataKeys(advisor, tempKeys);
+ BehaviorNode.loadMetaDataKeys(member, type, className + '.', advisor, keys);
+ for (String metaDataKey: tempKeys)
+ {
+ keys.add(metaDataKey + '.' + type.getDefaultKey(member));
+ BehaviorNode.loadMetaDataKeys(member, type, metaDataKey + '.', advisor,
+ keys);
+ }
+ }
+ finally
+ {
+ tempKeys.clear();
+ }
+ }
+ }
+
+ private void loadCalleeClass(Class<?> clazz)
+ {
+ this.className = clazz.getName();
+ advisor = AspectManager.instance().getTempClassAdvisorIfNotExist(clazz);
+ }
+}
\ No newline at end of file
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassMemberNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassMemberNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassMemberNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.aop.joinpoint.graph;
-
-/**
- * Node that represents an instrumented class member in the graph.
- * Every such node is associated with the node that represents the class that
- * contains the member itself.
- *
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- */
-abstract class ClassMemberNode implements Node
-{
- private ClassNode classNode;
-
- /**
- * Creates a class member node.
- *
- * @param classNode represents the class to which the member belongs
- */
- public ClassMemberNode(ClassNode classNode)
- {
- this.classNode = classNode;
- }
-
- /**
- * Returns the class node associated with this node.
- *
- * @return the class node associated with this member node
- */
- public ClassNode getClassNode()
- {
- return this.classNode;
- }
-}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -1,18 +1,9 @@
package org.jboss.aop.joinpoint.graph;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
import java.util.Collection;
-import javassist.NotFoundException;
-
-import org.jboss.aop.Advised;
import org.jboss.aop.Advisor;
-import org.jboss.aop.InstanceAdvisor;
-import org.jboss.aop.annotation.AnnotationElement;
+import org.jboss.aop.AspectManager;
/**
* Node that represents a class in the graph.
@@ -33,199 +24,130 @@
* class node.</li>
* </ul>
*
+ * The subtrees are held indirectly, by a reference to {@link AdvisedData}.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
abstract class ClassNode implements Node
{
- private Class clazz;
- private AdvisedClassData advisedData;
+ private Class<?> clazz;
/**
- * Creates a node that represents a weaved class in the graph.
+ * Creates a node that represents a class in the graph.
*
- * @param clazz the weaved class that this node represents in the graph.
- * @param advisor the advisor of {@code clazz}
+ * @param clazz the type (may be a class or an interface) that the created node
+ * will represent
*/
- /*public ClassNode(Class clazz, Advisor advisor)
+ public ClassNode(Class<?> clazz)
{
- this(clazz);
- this.advisedData = new AdvisedClassData(advisor);
- }*/
-
- /**
- * Creates a node that represents a supertype of a weaved class in the graph.
- *
- * @param clazz the type (may be a class or an interface) that this node
- * represents
- */
- public ClassNode(Class clazz)
- {
this.clazz = clazz;
}
+
/**
- * Returns the default key that would identify a class node in the graph.
+ * Returns the key that would identify a class node in the graph.
* <p>
* This method must be called whenever there is need to search for a class node in
* the graph.
*
- * @param clazz the class represented by the hypothetical node.
- * @return the identifier of a hypothetical class node in the graph
+ * @param clazz the class represented by the hypothetical node whose identifier
+ * key is to be returned
+ * @return the identifier of the class node that would represent {@code clazz} in
+ * the graph
+ * @see #getIdentifierKey()
*/
- public static final String getDefaultKey(Class clazz)
+ public static final String getIdentifierKey(Class clazz)
{
return clazz.getName();
}
- public final Class getRepresentedClass()
- {
- return this.clazz;
- }
-
- public AdvisedData getAdvisedData(Advisor advisor)
- {
- if (advisor instanceof InstanceAdvisor)
- {
- if (this.advisedData == null)
- {
- Advisor classAdvisor = ((Advised)((InstanceAdvisor) advisor).getInstance())._getAdvisor();
- this.advisedData = new AdvisedClassData(classAdvisor);
- return this.advisedData.createInstanceAdvisedData(advisor);
- }
- return this.advisedData.getInstanceAdvisedData(advisor);
- }
- if (this.advisedData == null)
- {
- this.advisedData = new AdvisedClassData(advisor);
- }
- return this.advisedData;
- }
-
/**
- * Returns the advisor of the weaved class this node represents.
+ * Loads all meta data keys of a class node representing the {@code Class} managed
+ * by {@code advisor}.
*
- * @return the advisor of the weaved class this node represents. If the class
- * represented is not weaved, this method returns {@code null}.
+ * @param metaDataKeyContainer the advisor of the class whose node meta data keys
+ * must be loaded
+ * @param keys collection where the loaded keys will be loaded
+ * @see Advisor#getClazz()
*/
- public Advisor getAdvisor()
+ public static void loadMetaDataKeys(Advisor metaDataKeyContainer,
+ Collection<String> keys)
{
- return this.advisedData.getAdvisor();
+ for (String metaDataTag: metaDataKeyContainer.getMetaDataTags())
+ {
+ keys.add('@' + metaDataTag);
+ }
}
- public String getDefaultKey()
+ public String getIdentifierKey()
{
- return getDefaultKey(this.clazz);
+ return getIdentifierKey(this.clazz);
}
public void loadMetaDataKeys(Collection<String> keys)
{
- if (advisedData == null)
- {
- try
- {
- Collection<String> annotationNames = new ArrayList<String>();
- AnnotationElement.loadAllAnnotationsPresent(this.clazz, annotationNames);
- for (String annotationName: annotationNames)
- {
- keys.add('@' + annotationName);
- }
- }
- catch (NotFoundException e)
- {
- for (Annotation annotation: this.clazz.getAnnotations())
- {
- keys.add('@' + annotation.getClass().getName());
- }
- }
- }
- else
- {
- Advisor advisor = advisedData.getAdvisor();
- for (String metaDataTag: advisor.getMetaDataTags())
- {
- keys.add('@' + metaDataTag);
- }
- }
+ loadMetaDataKeys(this.getMetaDataContainer(), keys);
}
/**
- * Adds a direct subtype of the class represented by this node.
+ * Returns the class represented by this node.
*
- * @param directSubtype the node that represents a direct subtype of the class
- * represented by this node
+ * @return the class represented by this node
*/
- public abstract void addSubtype(ClassNode directSubtype);
+ public final Class getClazz()
+ {
+ return this.clazz;
+ }
- public abstract Collection<ClassNode> getSubtypes();
-
/**
- * Returns the behavior node that represents {@code constructor}.
+ * Searches for all behavior nodes whose keys match {@code behaviorExpression}.
+ * The search is performed on this advisedData's behavior subtree, hence returning
+ * only members of the class this node represents.
*
- * @param constructor a member of the class represented by this node. This
- * constructor must be associated with one or more weaved
- * joinpoints.
- * @return the behavior node that represents {@code constructor}. If
- * such node does not exist, it is created and inserted in the
- * behavior subtree.
+ * @param behaviorExpression a search expession. May contain wildcards.
+ * @return a collection containing all the behavior nodes
+ * whose keys match {@code behaviorExpression}.
*/
- public BehaviorNode getBehavior(Constructor constructor)
- {
- return advisedData.getBehavior(constructor);
- }
+ public abstract Collection<BehaviorNode> searchBehaviors(String behaviorExpression);
/**
- * Returns the behavior node that represents {@code method}.
+ * Searches for all field nodes whose keys match {@code fieldExpression}.
+ * The search is performed on this advisedData's field subtree, hence returning
+ * only members of the class this node represents.
*
- * @param method a member of the class represented by this node. This
- * method must be associated with one or more weaved
- * joinpoints.
- * @return the behavior node that represents {@code method}. If such
- * node does not exist, it is created and inserted in the
- * behavior subtree.
+ * @param fieldExpression a search expession. May contain wildcards.
+ * @return a collection containing all the field nodes whose keys
+ * match {@code fieldExpression}.
*/
- public BehaviorNode getBehavior(Method method)
- {
- return advisedData.getBehavior(method);
- }
+ public abstract Collection<FieldNode> searchFields(String fieldExpression);
/**
- * Searches for all behavior nodes whose keys match {@code behaviorExpression}.
- * The search is performed on this node's behavior subtree, hence returning only
- * members of the class this node represents.
+ * Adds a subtype of the class represented by this node.
*
- * @param behaviorExpression a search expession. May contain wildcards.
- * @return a collection containing all the behavior nodes
- * whose keys match {@code behaviorExpression}.
+ * @param subtype the node that represents a subtype of the class represented by
+ * this node
*/
- public Collection<BehaviorNode> searchBehaviors(String behaviorExpression)
- {
- return advisedData.searchBehaviors(behaviorExpression);
- }
-
+ public abstract void addSubtype(ClassNode subtype);
+
/**
- * Returns the field node that represents {@code field}.
+ * Returns a collection containing the subtypes of the class represented by this
+ * node in the graph.
*
- * @param field a member of the class represented by this node. This field must be
- * associated with one or more weaved joinpoints.
- * @return the behavior node that represents {@code field}. If such node
- * does not exist, it is created and inserted in the field subtree.
+ * @return a collection containing the subtype of the class represented by this
+ * node in the graph
*/
- public FieldNode getField(Field field)
- {
- return advisedData.getField(field);
- }
+ public abstract Collection<ClassNode> getSubtypes();
/**
- * Searches for all field nodes whose keys match {@code fieldExpression}.
- * The search is performed on this node's field subtree, hence returning only
- * members of the class this node represents.
+ * Returns an advisor that contains all meta datas associated with the class this
+ * node represents.
*
- * @param fieldExpression a search expession. May contain wildcards.
- * @return a collection containing all the field nodes whose keys
- * match {@code fieldExpression}.
+ * @return an advisor that contains all meta datas associated with the class this
+ * node represents.
*/
- public Collection<FieldNode> searchFields(String fieldExpression)
+ // TODO replace Advisor by an interface?
+ public Advisor getMetaDataContainer()
{
- return advisedData.searchFields(fieldExpression);
+ return AspectManager.instance().getTempClassAdvisorIfNotExist(clazz);
}
}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CompositeDomainData.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CompositeDomainData.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/CompositeDomainData.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.aop.Advisor;
+
+/**
+ * A composite domain data, used when a group of domains must be treated as a single
+ * unit (i.e., class domain containing instance domains).
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class CompositeDomainData extends DomainData
+{
+ private Map<Advisor, AdvisedData> components;
+
+ /**
+ * Constructor.
+ *
+ * @param advisor the main advisor associated with this domain. All other advisors
+ * to be associated wit this domain must be components of the
+ * smallest domain occupied by this advisor.
+ */
+ @SuppressWarnings("all")
+ public CompositeDomainData(Advisor advisor)
+ {
+ super(advisor);
+ this.components = new HashMap<Advisor, AdvisedData>();
+ }
+
+ /**
+ * Creates a composite copy of {@code advisedDomainData}.
+ * <p>
+ * The result is a domain data equal to the previous one, but with added support
+ * for components.
+ *
+ * @param advisedDomainData advisedDomainData to be copied
+ */
+ public CompositeDomainData(DomainData advisedDomainData)
+ {
+ super(advisedDomainData);
+ this.components = new HashMap<Advisor, AdvisedData>();
+ }
+
+ /**
+ * Creates a component associated with {@code Advisor}.
+ * <p>
+ * Must be called only when there is no component representing {@code advisor}
+ * yet. Otherwise, the previous component will be overwritten.
+ *
+ * @param advisor this advisor must be part of the smallest domain containing
+ * the main advisor ({@code #getAdvisor()})
+ * @return the created component
+ */
+ public AdvisedData createComponent(Advisor advisor)
+ {
+ AdvisedData queriedData = new AdvisedData(advisor);
+ components.put(advisor, queriedData);
+ return queriedData;
+ }
+
+ /**
+ * Returns the component associated with {@code advisor}. If no such component
+ * exists, it is created and inserted in this compositeDomainData.
+ *
+ * @param advisor this advisor must be part of the smallest domain containing
+ * the main advisor ({@code #getAdvisor()})
+ * @return the component associated with {@code advisor}
+ */
+ public AdvisedData getComponent(Advisor advisor)
+ {
+ if (components.containsKey(advisor))
+ {
+ return components.get(advisor);
+ }
+ return createComponent(advisor);
+ }
+
+ /**
+ * Returns the advisedData associated with {@code advisor}.
+ *
+ * @param advisor this advisor must be either part of the smallest domain
+ * containing the main advisor ({@code #getAdvisor()}) or the main
+ * advisor itself
+ * @return the advisedData associated with {@code advisor}. Maybe a component or
+ * this compositeDomainData itself, depending on {@code advisor}. In the
+ * first case, the component data will be created if it does not exist.
+ *
+ */
+ public AdvisedData getAdvisedData(Advisor advisor)
+ {
+ if (advisor == this.getAdvisor())
+ {
+ return this;
+ }
+ return getComponent(advisor);
+ }
+
+ /**
+ * Performs a search for field nodes matching {@code fieldExpression} on all
+ * components of this domain data.
+ */
+ @Override
+ public Collection<FieldNode> searchFields(String fieldExpression)
+ {
+ Collection<FieldNode> result = super.searchFields(fieldExpression);
+ for (AdvisedData advisedData: components.values())
+ {
+ result.addAll(advisedData.searchFields(fieldExpression));
+ }
+ return result;
+ }
+
+ /**
+ * Performs a search for behavior nodes matching {@code behaviorExpression} on all
+ * components of this domain data.
+ */
+ @Override
+ public Collection<BehaviorNode> searchBehaviors(String behaviorExpression)
+ {
+ Collection<BehaviorNode> result = super.searchBehaviors(behaviorExpression);
+ for (AdvisedData advisedData: components.values())
+ {
+ result.addAll(advisedData.searchBehaviors(behaviorExpression));
+ }
+ return result;
+ }
+}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ConjunctiveSearchKey.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -104,7 +104,7 @@
((ParsedSearchKey) searchKey2).replaceCalleeSearcher(restriction);
}
- public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
+ public void search(Tree<? extends ClassNode> classTree, Collection<JoinPointInfo> result)
{
Set<JoinPointInfo> firstResult = new HashSet<JoinPointInfo>();
this.searchKey1.search(classTree, firstResult);
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DisjunctiveSearchKey.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -102,7 +102,7 @@
((ParsedSearchKey) searchKey2).replaceCalleeSearcher(restriction);
}
- public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
+ public void search(Tree<? extends ClassNode> classTree, Collection<JoinPointInfo> result)
{
this.searchKey1.search(classTree, result);
this.searchKey2.search(classTree, result);
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainClassNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.aop.joinpoint.graph;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.jboss.aop.Advisor;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-class DomainClassNode extends ClassNode
-{
- /*public DomainClassNode(Class clazz, Advisor advisor)
- {
- super(clazz, advisor);
- }*/
-
- public DomainClassNode(Class clazz)
- {
- super(clazz);
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.ClassNode#addSubtype(org.jboss.aop.joinpoint.graph.ClassNode)
- */
- @Override
- public void addSubtype(ClassNode directSubtype)
- {
-
- }
-
- /* (non-Javadoc)
- * @see org.jboss.aop.joinpoint.graph.ClassNode#getSubtypes()
- */
- @Override
- public Collection<ClassNode> getSubtypes()
- {
- return (Collection<ClassNode>) Collections.EMPTY_LIST;
- }
-
-}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainData.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainData.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainData.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.Domain;
+
+/**
+ * AdvisedData associated with domain tags.
+ * <p>
+ * This class is used over {@code AdvisedData}, when the advisedData is contained in
+ * a domain that is composed of more than one {@code Advisor} unit. For unitary
+ * domains this class is never used.
+ * <p>
+ * For each domain this advisedData belongs to, it receives a tag, equal to the name
+ * of the domain it is part of. The presence of this data in a certain domain can
+ * thus be tested by calling {@code #hasTag(String)} witht the domain name as
+ * parameter.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class DomainData extends AdvisedData
+{
+ private Set<String> tags;
+
+ /**
+ * Constructor.
+ *
+ * @param advisor the advisor associated with the domain data to be created. This
+ * advisor must be contained in a non-unitary domain (i.e., there
+ * must be other advisors in its domain).
+ */
+ @SuppressWarnings("all")
+ public DomainData(Advisor advisor)
+ {
+ super(advisor);
+ AspectManager manager = advisor.getManager();
+ if (manager instanceof Domain)
+ {
+ this.tags = new TreeSet<String> ();
+ do
+ {
+ Domain domain = (Domain) manager;
+ this.tags.add(domain.getDomainName());
+ manager = domain.getParent();
+ } while (manager instanceof Domain);
+ }
+ else
+ {
+ this.tags = Collections.EMPTY_SET;
+ }
+ }
+
+ /**
+ * Constructor. Creates a copy of {@code advisedDomainData}.
+ *
+ * @param advisedDomainData domainData to be copied
+ */
+ protected DomainData(DomainData advisedDomainData)
+ {
+ super(advisedDomainData);
+ this.tags = advisedDomainData.tags;
+ }
+
+ /**
+ * Returns {@code true} if this data is inserted in a domain identified by
+ * {@code tag}.
+ *
+ * @param tag the name of a domain to be tested
+ * @return {@code true} only if this data belongs to a domain named {@code tag}
+ */
+ public boolean hasTag(String tag)
+ {
+ return this.tags.contains(tag);
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainJoinPointGraph.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainJoinPointGraph.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainJoinPointGraph.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import org.jboss.aop.Domain;
+
+/**
+ * A graph that represents a subgraph of the {@code MainJoinPointGraph main graph}.
+ * This graph contains the joinpoints managed by an aop domain.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class DomainJoinPointGraph extends MainJoinPointGraph
+{
+ private String domainTag;
+
+ public DomainJoinPointGraph(Domain domain)
+ {
+ this.domainTag = domain.getDomainName();
+ super.classTree = MainJoinPointGraph.getInstance().classTree;
+ }
+
+ // TODO override search and use a domainTagFilter
+}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/EmptySearchKey.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -36,7 +36,7 @@
*/
class EmptySearchKey extends SearchKey
{
- public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
+ public void search(Tree<? extends ClassNode> classTree, Collection<JoinPointInfo> result)
{
// do nothing
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -28,8 +28,12 @@
import org.jboss.aop.FieldInfo;
/**
+ * Node that represents a field in the graph. Such field must have at least a
+ * joinpoint associated with it.
+ * <p>
+ * Every FieldNode contains references to its read and write joinpoints.
+ *
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
*/
class FieldNode implements Node
{
@@ -38,25 +42,44 @@
private FieldInfo fieldRead;
private FieldInfo fieldWrite;
+ /**
+ * Constructor. Creates a field node that represents {@code field} in the graph.
+ *
+ * @param advisor advisor manages the joinpoints associated with {@code field}
+ * @param field the field to be represented by the created field node
+ */
public FieldNode(Advisor advisor, Field field)
{
this.advisor = advisor;
this.field = field;
}
- public static String getDefaultKey(Field field)
+ /**
+ * Returns the key that would identify a field node representing {@code field} in
+ * the graph.
+ * <p>
+ * This method must be called whenever there is need to search for a specific
+ * field node in the graph.
+ *
+ * @param field the field represented by the hypothetical node whose identifier
+ * key is to be returned
+ * @return the identifier of the field node that would represent {@code field} in
+ * the graph
+ * @see #getIdentifierKey()
+ */
+ public static String getIdentifierKey(Field field)
{
return field.getType().getName() + " " + field.getName();
}
- public String getDefaultKey()
+ public String getIdentifierKey()
{
- return getDefaultKey(this.field);
+ return getIdentifierKey(this.field);
}
public void loadMetaDataKeys(Collection<String> names)
{
- String commonPrefix = this.field.getType() + " @";
+ String commonPrefix = this.field.getType().getName() + " @";
Collection<String> metaDataTags = advisor.getMetaDataTags(this.field);
for (String metaDataTag: metaDataTags)
{
@@ -64,38 +87,88 @@
}
}
+ /**
+ * Returns the field represented by this node.
+ *
+ * @return the field represented by this node
+ */
public Field getField()
{
return this.field;
}
- public FieldInfo getFieldRead()
+ /**
+ * Returns {@code true} if this node contains a field read joinpoint.
+ *
+ * @return {@code true} if this node contains a field read joinpoint
+ */
+ public boolean hasFieldRead()
{
- return this.fieldRead;
+ return fieldRead != null;
}
- public boolean hasFieldRead()
+ /**
+ * Returns the field read joinpoint contained in this node.
+ *
+ * @return the field read contained in this node. Returns {@code null} if {@code
+ * #hasFieldRead()} is {@code false}.
+ */
+ public FieldInfo getFieldRead()
{
- return fieldRead != null;
+ return this.fieldRead;
}
+ /**
+ * Inserts a field read joinpoint in this node.
+ * <br>
+ * This method must be called only if {@link #hasFieldRead()} is {@code false}.
+ * Otherwise, the field read joinpoint previously inserted in this node will be
+ * erased.
+ *
+ * @param fieldRead the fieldRead joinpoint to be inserted in this node
+ */
public void setFieldRead(FieldInfo fieldRead)
{
this.fieldRead = fieldRead;
}
+ /**
+ * Returns {@code true} if this node contains a field write joinpoint.
+ *
+ * @return {@code true} if this node contains a field write joinpoint
+ */
public boolean hasFieldWrite()
{
return fieldWrite != null;
}
+ /**
+ * Returns the field write joinpoint contained in this node.
+ *
+ * @return the field write contained in this node. Returns {@code null} if {@code
+ * #hasFieldWrite()} is {@code false}.
+ */
public FieldInfo getFieldWrite()
{
return this.fieldWrite;
}
+ /**
+ * Inserts a field write joinpoint in this node.
+ * <br>
+ * This method must be called only if {@link #hasFieldWrite()} is {@code false}.
+ * Otherwise, the field write joinpoint previously inserted in this node will be
+ * erased.
+ *
+ * @param fieldWrite the fieldWrite joinpoint to be inserted in this node
+ */
public void setFieldWrite(FieldInfo fieldWrite)
{
this.fieldWrite = fieldWrite;
}
-}
+
+ public String toString()
+ {
+ return "[node: " + field + "]";
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphFactory.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import org.jboss.aop.Domain;
+import org.jboss.aop.joinpoint.JoinPointRegistry;
+
+/**
+ * This factory allows creation and retrieval of joinpoint graphs. The returned
+ * graphs do not support insertion of joinpoints; they support joinpoint search only.
+ * In order to have joinpoints inserted to the appropriate graphs, every joinpoint
+ * must be registered at the {@link #getRegistry() registry}.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class JoinPointGraphFactory
+{
+ /**
+ * Returns the registry where joinpoints must be recorded in order to be inserted
+ * to the appropriate joinpoint graphs.
+ *
+ * @return
+ */
+ public static JoinPointRegistry getRegistry()
+ {
+ return MainJoinPointGraph.getInstance();
+ }
+
+ /**
+ * Creates and return the main joinpoint graph. This graph is not associated with
+ * any domain and contains all joinpoints recorded in the {@link #getRegistry()
+ * registry}.
+ * <p>
+ * The main joinpoint graph is created the first time this method is called. All
+ * subsequent calls will return the same instance.
+ *
+ * @return the main joinpoint graph
+ */
+ public static JoinPointGraph create()
+ {
+ return MainJoinPointGraph.getInstance();
+ }
+
+ /**
+ * Creates a graph for indexing all joinpoints contained in {@code domain}.
+ *
+ * @param domain an aop domain
+ * @return the graph that contains all joinpoints managed by {@code domain}
+ */
+ public static JoinPointGraph create(Domain domain)
+ {
+ throw new UnsupportedOperationException();
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraphImpl.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.aop.JoinPointInfo;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ * Contains code common to all {@code JoinPointGraph} implementors.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+abstract class JoinPointGraphImpl<N extends ClassNode> implements JoinPointGraph
+{
+ /** The root of the graph */
+ protected Tree<N> classTree;
+
+ /**
+ * Constructor.
+ */
+ protected JoinPointGraphImpl()
+ {
+ classTree = new Tree<N>();
+ }
+
+ public Collection<JoinPointInfo> search(SearchKey key)
+ {
+ Collection<JoinPointInfo> result = new HashSet<JoinPointInfo>();
+ ((ParsedSearchKey) key).search(classTree, result);
+ return result;
+ }
+
+ /**
+ * Inserts a class node to the root of this graph, {@link #classTree}.
+ *
+ * @param classNode the class node to be inserted
+ * @param idKey the identifier key of {@code classNode}
+ */
+ protected void insertClassNode(N classNode, String idKey)
+ {
+ TreeInsertionUtil.insertNode(classNode, classTree, idKey);
+ insertHierarchy(classNode);
+ }
+
+ /**
+ * Creates a class node to represent a super class of {@code classNode}.
+ *
+ * @param superClazz the class to be represented by the created node
+ * @param classNode represents a subtype of {@code superClazz} in the graph
+ * @return a class node representing {@code superClazz} and its hierarchical
+ * relationship with {@code classNode} (calling {@code
+ * .getSubtypes().contains(classNode)} on the returned node returns {@code
+ * true}).
+ */
+ protected abstract N createSuperClassNode(Class<?> superClazz, N classNode);
+
+ private void insertHierarchy(N classNode)
+ {
+ Class<?> clazz = classNode.getClazz();
+ for (Class interfaceClass: clazz.getInterfaces())
+ {
+ addSubType(interfaceClass, classNode);
+ }
+ if (clazz.getSuperclass() != null)
+ {
+ addSubType(clazz.getSuperclass(), classNode);
+ }
+ }
+
+ private void addSubType(Class<?> superClazz, N classNode)
+ {
+ String defaultKey = ClassNode.getIdentifierKey(superClazz);
+ N superClassNode = classTree.searchValue(defaultKey);
+ if (classNode != null)
+ {
+ superClassNode.addSubtype(classNode);
+ }
+ else
+ {
+ superClassNode = createSuperClassNode(superClazz, classNode);
+ insertClassNode(superClassNode, defaultKey);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MainJoinPointGraph.java (from rev 74297, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MainJoinPointGraph.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MainJoinPointGraph.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Sorce
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at yor option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.ConByConInfo;
+import org.jboss.aop.ConByMethodInfo;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.ConstructorInfo;
+import org.jboss.aop.FieldInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.joinpoint.JoinPointRegistry;
+
+/**
+ * The main joinpoint graph.
+ * <p>
+ * Insertion operations are supported by the {@code register} methods. All joinpoints
+ * inserted can be retrieved through the {@link #search(SearchKey)} method.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class MainJoinPointGraph extends JoinPointGraphImpl<StandardClassNode>
+ implements JoinPointRegistry
+{
+ private static final MainJoinPointGraph INSTANCE = new MainJoinPointGraph();
+
+ /**
+ * Returns the singleton instance of the graph.
+ *
+ * @return the singleton instance of the graph
+ */
+ public static MainJoinPointGraph getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public synchronized void register(FieldInfo info)
+ {
+ Advisor advisor = info.getAdvisor();
+ AdvisedData advisedData = getClassNode(info.getClazz()).getAdvisedData(advisor);
+ FieldNode fieldNode = advisedData.getField(info.getField());
+ if (info.isRead())
+ {
+ fieldNode.setFieldRead(info);
+ }
+ else
+ {
+ fieldNode.setFieldWrite(info);
+ }
+ }
+
+ public synchronized void register(ConstructorInfo info)
+ {
+ getBehavior(info.getAdvisor(), info.getClazz(), info.getConstructor()).
+ setExecution(info);
+ }
+
+ public synchronized void register(ConstructionInfo info)
+ {
+ getBehavior(info.getAdvisor(), info.getClazz(), info.getConstructor()).
+ setConstruction(info);
+ }
+
+ public synchronized void register(MethodInfo info)
+ {
+ getBehavior(info.getAdvisor(), info.getClazz(), info.getMethod()).
+ setExecution(info);
+ }
+
+ public synchronized void register(ConByConInfo info)
+ {
+ // get caller behavior node
+ BehaviorNode behavior = getBehavior(info.getAdvisor(),
+ info.getCallingClass(), info.getCallingConstructor());
+ // insert
+ behavior.addCallee(info);
+ }
+
+ public synchronized void register(ConByMethodInfo info)
+ {
+ // get caller behavior node
+ BehaviorNode behavior = getBehavior(info.getAdvisor(),
+ info.getCallingClass(), info.getCallingMethod());
+ // insert
+ behavior.addCallee(info);
+ }
+
+ public synchronized void register(MethodByMethodInfo info)
+ {
+ // get caller behavior node
+ BehaviorNode behavior = getBehavior(info.getAdvisor(),
+ info.getCallingClass(), info.getCallingMethod());
+ // insert
+ behavior.addCallee(info);
+ }
+
+ public synchronized void register(MethodByConInfo info)
+ {
+ // get caller behavior node
+ BehaviorNode behavior = getBehavior(info.getAdvisor(),
+ info.getCallingClass(), info.getCallingConstructor());
+ // insert
+ behavior.addCallee(info);
+ }
+
+ @Override
+ protected StandardClassNode createSuperClassNode(Class<?> superClazz,
+ StandardClassNode classNode)
+ {
+ StandardClassNode superClassNode = new StandardClassNode(superClazz);
+ superClassNode.addSubtype(classNode);
+ return superClassNode;
+ }
+
+ private BehaviorNode getBehavior(Advisor advisor, Class clazz,
+ Constructor constructor)
+ {
+ AdvisedData advisedData = getClassNode(clazz).getAdvisedData(advisor);
+ return advisedData.getBehavior(constructor);
+ }
+
+ private BehaviorNode getBehavior(Advisor advisor, Class clazz, Method method)
+ {
+ AdvisedData advisedData = getClassNode(clazz).getAdvisedData(advisor);
+ return advisedData.getBehavior(method);
+ }
+
+ private StandardClassNode getClassNode(Class<?> clazz)
+ {
+ String defaultKey = ClassNode.getIdentifierKey(clazz);
+ StandardClassNode classNode = classTree.searchValue(defaultKey);
+ if (classNode == null)
+ {
+ classNode = new StandardClassNode(clazz);
+ insertClassNode(classNode, defaultKey);
+ }
+ return classNode;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MetaDataKeyLoader.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MetaDataKeyLoader.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/MetaDataKeyLoader.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+
+/**
+ * Loads meta data keys used to identify an element in a collection.
+ * <br>
+ * The target element of the operation and how meta data keys are generated
+ * depends on the implementor.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+interface MetaDataKeyLoader
+{
+ /**
+ * Loads indexing metadata keys.
+ *
+ * @param names collection that will hold all loaded meta data keys.
+ */
+ void loadMetaDataKeys(Collection<String> names);
+}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Node.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Node.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Node.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -39,7 +39,7 @@
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
-interface Node
+interface Node extends MetaDataKeyLoader
{
/**
* Returns the default key of this node. This key can be used as the unique
@@ -47,7 +47,7 @@
*
* @return a key that identifies this node uniquely in the tree it belongs
*/
- String getDefaultKey();
+ String getIdentifierKey();
/**
* Loads all metadata keys that index this node in the tree it belongs.
@@ -55,7 +55,7 @@
* The metadata keys are generated based on the metadata associated with the
* reflection element represented by this node.
* <br>
- * Differently from the {@link #getDefaultKey() default key}, these keys do not
+ * Differently from the {@link #getIdentifierKey() default key}, these keys do not
* identify this node uniquely, as they may be common to more than one node in the
* same tree.
*
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/PointcutDelegateSearchKey.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -80,9 +80,9 @@
throw new RuntimeException("UNEXPECTED");
}
- public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
+ public void search(Tree<? extends ClassNode> classTree, Collection<JoinPointInfo> result)
{
- Collection<ClassNode> allClasses = classTree.search("*");
+ Collection<? extends ClassNode> allClasses = classTree.search("*");
for (ClassNode classNode: allClasses)
{
Collection<BehaviorNode> behaviourNodes = classNode.searchBehaviors("*");
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKey.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKey.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKey.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -28,7 +28,7 @@
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
-public abstract class SearchKey implements Searcher<Tree<ClassNode>>
+public abstract class SearchKey implements Searcher<Tree<? extends ClassNode>>
{
// make sure it does not get extended
SearchKey(){}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SearchKeyImpl.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -35,9 +35,8 @@
{
private String classExpression;
private Searcher<ClassNode> searcher;
-
-
- public void search(Tree<ClassNode> classTree, Collection<JoinPointInfo> result)
+
+ public void search(Tree<? extends ClassNode> classTree, Collection<JoinPointInfo> result)
{
Collection<ClassNode> classes = new LinkedList<ClassNode>();
classTree.search(classExpression, classes);
@@ -45,7 +44,8 @@
{
for (TypeFilter restriction: typeFilters)
{
- if (!restriction.accept(classNode.getRepresentedClass(), classNode.getAdvisor()))
+ if (!restriction.accept(classNode.getClazz(),
+ classNode.getMetaDataContainer()))
{
continue outer;
}
Deleted: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleClassNode.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.aop.joinpoint.graph;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.jboss.aop.Advisor;
-
-/**
- * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
- *
- */
-class SimpleClassNode extends ClassNode
-{
- private Collection<ClassNode> directSubtypes;
-
- public SimpleClassNode(Class clazz)
- {
- super(clazz);
- this.directSubtypes = new ArrayList<ClassNode>(1);
- }
-
- /**
- * Adds a direct subtype of the class represented by this node.
- *
- * @param directSubtype the node that represents a direct subtype of the class
- * represented by this node
- */
- public void addSubtype(ClassNode directSubtype)
- {
- this.directSubtypes.add(directSubtype);
- }
-
- public Collection<ClassNode> getSubtypes()
- {
- return this.directSubtypes;
- }
-}
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java (from rev 74297, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/SimpleClassNode.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/StandardClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceAdvisor;
+
+/**
+ * The standard class node, used to represent classes in joinpoint graphs most of
+ * the times.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @see UnitaryDomainClassNode
+ * @see UnitaryDomainSuperClassNode
+ */
+class StandardClassNode extends AdvisableClassNode
+{
+ private Collection<ClassNode> directSubtypes;
+
+ /**
+ * Constructor.
+ *
+ * @param clazz the class represented by the class node to be created
+ */
+ public StandardClassNode(Class clazz)
+ {
+ super(clazz);
+ this.directSubtypes = new ArrayList<ClassNode>(1);
+ }
+
+ /**
+ * Returns all advised data associated with {@code advisor}.
+ *
+ * @param advisor an advisor that manages either all joinpoints associated with
+ * this node (class advisor) or part of them (instance advisor).
+ * @return the advised data that contains the joinpoints managed by {@code
+ * advisor}
+ */
+ public AdvisedData getAdvisedData(Advisor advisor)
+ {
+ AdvisedData advisedData = super.getAdvisedData();
+ if (advisor instanceof InstanceAdvisor)
+ {
+ if (advisedData == null)
+ {
+ Advisor classAdvisor = ((Advised)((InstanceAdvisor) advisor).getInstance())._getAdvisor();
+ CompositeDomainData compositeData = new CompositeDomainData(classAdvisor);
+ super.setAdvisedData(compositeData);
+ return compositeData.createComponent(advisor);
+ }
+ if (advisedData instanceof CompositeDomainData)
+ {
+ return ((CompositeDomainData) advisedData).getComponent(advisor);
+ }
+ //(this.advisedData.getClass() == AdvisedDomainData.class)
+ CompositeDomainData compositeData = new CompositeDomainData(
+ (DomainData) advisedData);
+ super.setAdvisedData(compositeData);
+ return compositeData.createComponent(advisor);
+ }
+ if (advisedData == null)
+ {
+ advisedData = new DomainData(advisor);
+ }
+ return advisedData;
+ }
+
+ @Override
+ public void addSubtype(ClassNode directSubtype)
+ {
+ this.directSubtypes.add(directSubtype);
+ }
+
+ @Override
+ public Collection<ClassNode> getSubtypes()
+ {
+ return this.directSubtypes;
+ }
+}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TreeInsertionUtil.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TreeInsertionUtil.java 2008-06-29 20:45:15 UTC (rev 75181)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TreeInsertionUtil.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -27,8 +27,11 @@
import org.jboss.aop.joinpoint.graph.tree.Tree;
/**
- * Utility class for inserting {@link Node nodes} on the subtrees that compose
- * the joinpoint graph.
+ * Utility class for inserting {@link Node nodes} and other objects in the subtrees
+ * that compose the joinpoint graph.
+ * <br>
+ * The usage of this class improves performance since there is no need to create
+ * a collection to keep loaded meta data keys.
*
* @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
*/
@@ -39,28 +42,54 @@
private static Collection<String> TEMP_KEYS = new ArrayList<String>(1);
/**
- * Inserts {@code node} in the {@code tree}. The insertion process is composed by
- * two steps. The first one consists in inserting {@code node} using the
- * identifier {@code key} as an index. The second step consists in inserting
- * {@code node} in the tree using all {@link Node#loadMetaDataKeys(Collection)
- * metadata keys} as indexes.
+ * Inserts {@code node} in the {@code tree}.
+ * <p>
+ * The insertion process is composed of two steps. The first one consists in
+ * inserting {@code node} using the identifier {@code idKey} as an index. The
+ * second step consists in inserting {@code node} in the tree using all {@link
+ * Node#loadMetaDataKeys(Collection) metadata keys} as indexes.
*
- * @param <N> the type of the node to be inserted in the tree
- * @param node the node to be inserted in the tree
- * @param key the {@link Node#getDefaultKey() identifier} of {@code node}
- * @param tree the subtree where {@code node} must be inserted.
+ * @param <N> the type of the node to be inserted in the tree
+ * @param node the node to be inserted in the tree
+ * @param tree the subtree where {@code node} must be inserted.
+ * @param idKey the {@link Node#getIdentifierKey() identifier} of {@code node}.
+ * While this value could be generated by calling {@code
+ * Node.getIdentifierKey()}, it is passed as an argument in
+ * order to avoid unnecessary recalculation of the key.
*/
- public static <N extends Node> void insertNode(N node, String key, Tree<N> tree)
+ public static <N extends Node> void insertNode(N node, Tree<N> tree, String idKey)
{
+ insertObject(node, tree, idKey, node);
+ }
+
+ /**
+ * Inserts {@code object} in the {@code tree}.
+ * <p>
+ * The insertion process is composed of two steps. The first one consists in
+ * inserting {@code target} using the identifier {@code idKey} as an index. The
+ * second one consists in inserting {@code target} in the tree using all
+ * {@link MetaDataKeyLoader#loadMetaDataKeys(Collection) metadata keys} as
+ * indexes.
+ *
+ * @param <T> the type of the object to be inserted in the tree
+ * @param target the object to be inserted in the tree
+ * @param tree the subtree where {@code target} must be inserted.
+ * @param idKey the identifier of {@code target}
+ * @param metaDataKeyLoader loads the metadata keys to be used as keys in {@code
+ * tree}
+ */
+ public static <T> void insertObject(T object, Tree<T> tree,
+ String idKey, MetaDataKeyLoader metaDataKeyLoader)
+ {
synchronized(TEMP_KEYS)
{
try
{
- tree.insert(key, node);
- node.loadMetaDataKeys(TreeInsertionUtil.TEMP_KEYS);
+ tree.insert(idKey, object);
+ metaDataKeyLoader.loadMetaDataKeys(TreeInsertionUtil.TEMP_KEYS);
for (String metaDataKey: TreeInsertionUtil.TEMP_KEYS)
{
- tree.insert(metaDataKey, node);
+ tree.insert(metaDataKey, object);
}
}
finally
Copied: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainClassNode.java (from rev 74297, projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/DomainClassNode.java)
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainClassNode.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * ClassNode for usage on unitary domain graphs.
+ * Since the domain is unitary, it contains only a single class advisor or instance
+ * advisor. As a consequence, there is no need to insert subtypes of this class
+ * node in the graph.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+ at SuppressWarnings("all")
+class UnitaryDomainClassNode extends AdvisableClassNode
+{
+ public UnitaryDomainClassNode(Class clazz, AdvisedData advisedData)
+ {
+ super(clazz);
+ super.setAdvisedData(advisedData);
+ }
+
+ @Override
+ public void addSubtype(ClassNode directSubtype)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<ClassNode> getSubtypes()
+ {
+ return (Collection<ClassNode>) Collections.EMPTY_LIST;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryDomainSuperClassNode.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * Lightweight node that represents the super class of a class node in an unitary
+ * domain.
+ * <br>
+ * As the domain is unitary, it contains only a single class. Yet, the complete
+ * hierarchy of this class must be inserted to the graph in order to allow search for
+ * subtypes. This node is used to represent the super classes in the described
+ * scenario.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class UnitaryDomainSuperClassNode extends ClassNode
+{
+ private Collection<ClassNode> subClass = null;
+
+ /**
+ * Constructor.
+ *
+ * @param clazz class represented by this node
+ * @param subClassNode node that represents a subtype of {@code clazz}
+ */
+ public UnitaryDomainSuperClassNode(Class<?> clazz, ClassNode subClassNode)
+ {
+ super(clazz);
+ Collection<ClassNode> subClass = new ArrayList<ClassNode>(1);
+ subClass.add(subClassNode);
+ }
+
+ @Override
+ public void addSubtype(ClassNode subtype)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Collection<ClassNode> getSubtypes()
+ {
+ return subClass;
+ }
+
+ @SuppressWarnings("all")
+ public Collection<BehaviorNode> searchBehaviors(String behaviorExpression)
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ @SuppressWarnings("all")
+ public Collection<FieldNode> searchFields(String fieldExpression)
+ {
+ return Collections.EMPTY_LIST;
+ }
+}
\ No newline at end of file
Added: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryJoinPointGraph.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryJoinPointGraph.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/UnitaryJoinPointGraph.java 2008-06-29 20:49:18 UTC (rev 75182)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aop.joinpoint.graph;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceDomain;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+import org.jboss.aop.proxy.container.ProxyAdvisorDomain;
+
+/**
+ * A graph that represents a subgraph of the {@code MainJoinPointGraph main graph}.
+ * This graph contains only the joinpoints managed by an unitary aop domain (a doman
+ * with a single advisor).
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class UnitaryJoinPointGraph extends JoinPointGraphImpl<ClassNode>
+{
+ /**
+ * Creates a graph to index the joinpoints managed by {@code domain}.
+ *
+ * @param domain an unitary domain, containg a single instance advisor
+ */
+ public UnitaryJoinPointGraph(InstanceDomain domain)
+ {
+ this(domain.getAdvisor());
+
+ }
+
+ /**
+ * Creates a graph to index the joinpoints managed by {@code domain}.
+ *
+ * @param domain a proxy advisor domain
+ */
+ public UnitaryJoinPointGraph(ProxyAdvisorDomain domain)
+ {
+ this(domain.getAdvisor());
+ }
+
+ private UnitaryJoinPointGraph(Advisor advisor)
+ {
+ Class<?> clazz = advisor.getClazz();
+ String clazzId = ClassNode.getIdentifierKey(clazz);
+ Tree<StandardClassNode> mainGraph = MainJoinPointGraph.getInstance().classTree;
+ StandardClassNode classNode = mainGraph.searchValue(clazzId);
+ insertClassNode(new UnitaryDomainClassNode(clazz,
+ classNode.getAdvisedData(advisor)), ClassNode.getIdentifierKey(clazz));
+ }
+
+ @Override
+ protected ClassNode createSuperClassNode(Class<?> superClazz, ClassNode classNode)
+ {
+ return new UnitaryDomainSuperClassNode(superClazz, classNode);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list