[jboss-cvs] JBossAS SVN: r70725 - 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
Tue Mar 11 00:49:11 EDT 2008
Author: flavia.rainone at jboss.com
Date: 2008-03-11 00:49:11 -0400 (Tue, 11 Mar 2008)
New Revision: 70725
Added:
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/ClassNode.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/JoinPointGraph.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/TreeInsertionUtil.java
Log:
[JBAOP-504] Initial untested graph structure.
Added: 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 (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassMemberNode.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -0,0 +1,54 @@
+/*
+ * 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
Added: 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 (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/ClassNode.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -0,0 +1,291 @@
+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.Advisor;
+import org.jboss.aop.annotation.AnnotationElement;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ * 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 class node contains
+ * <ul>
+ * <li> references to all the nodes that represent direct subtypes of it in the
+ * graph;</li>
+ * <li> a subtree of behaviours, containing all behaviour nodes associated with this
+ * class node;<li>
+ * <li> and a subtree of fields, containing all field nodes associated with this
+ * class node.</li>
+ * </ul>
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class ClassNode implements Node
+{
+ private Class clazz;
+ private Collection<ClassNode> directSubtypes;
+ private AdvisedClassData advisedData;
+
+ /**
+ * Creates a node that represents a weaved class in the graph.
+ *
+ * @param clazz the weaved class that this node represents in the graph.
+ * @param advisor the advisor of {@code clazz}
+ */
+ public ClassNode(Class clazz, Advisor advisor)
+ {
+ this(clazz);
+ this.directSubtypes = new ArrayList<ClassNode>(0);
+ 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;
+ this.directSubtypes = new ArrayList<ClassNode>(1);
+ }
+
+ /**
+ * Returns the default 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
+ */
+ public static final String getDefaultKey(Class clazz)
+ {
+ return clazz.getName();
+ }
+
+ public final Class getRepresentedClass()
+ {
+ return this.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 {@code null}.
+ */
+ public Advisor getAdvisor()
+ {
+ return this.advisedData.getAdvisor();
+ }
+
+ public String getDefaultKey()
+ {
+ return getDefaultKey(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);
+ }
+ }
+ }
+
+ /**
+ * 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 addDirectSubtype(ClassNode directSubtype)
+ {
+ this.directSubtypes.add(directSubtype);
+ }
+
+ public Collection<ClassNode> getDirectSubtypes()
+ {
+ return this.directSubtypes;
+ }
+
+ /**
+ * Returns the behaviour node that represents {@code constructor}.
+ *
+ * @param constructor a member of the class represented by this node. This
+ * constructor must be associated with one or more weaved
+ * joinpoints.
+ * @return the behaviour node that represents {@code constructor}. If
+ * such node does not exist, it is created and inserted in the
+ * behaviour subtree.
+ */
+ public BehaviourNode getBehaviour(Constructor constructor)
+ {
+ return advisedData.getBehaviour(constructor);
+ }
+
+ /**
+ * Returns the behaviour node that represents {@code method}.
+ *
+ * @param method a member of the class represented by this node. This
+ * method must be associated with one or more weaved
+ * joinpoints.
+ * @return the behaviour node that represents {@code method}. If such
+ * node does not exist, it is created and inserted in the
+ * behaviour subtree.
+ */
+ public BehaviourNode getBehaviour(Method method)
+ {
+ return advisedData.getBehaviour(method);
+ }
+
+ /**
+ * Searches for all behaviour nodes whose keys match {@code behaviourExpression}.
+ * The search is performed on this node's behaviour subtree, hence returning only
+ * members of the class this node represents.
+ *
+ * @param behaviourExpression a search expession. May contain wildcards.
+ * @return a collection containing all the behaviour nodes
+ * whose keys match {@code behaviourExpression}.
+ */
+ public Collection<BehaviourNode> searchBehaviours(String behaviourExpression)
+ {
+ return advisedData.searchBehaviours(behaviourExpression);
+ }
+
+ /**
+ * Returns the field node that represents {@code field}.
+ *
+ * @param field a member of the class represented by this node. This field must be
+ * associated with one or more weaved joinpoints.
+ * @return the behaviour 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)
+ {
+ return advisedData.getField(field);
+ }
+
+ /**
+ * 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.
+ *
+ * @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 advisedData.searchFields(fieldExpression);
+ }
+
+ /**
+ * Private class
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+ private class AdvisedClassData
+ {
+ private Advisor advisor;
+ private Tree<FieldNode> fields;
+ private Tree<BehaviourNode> behaviours;
+
+
+ public AdvisedClassData(Advisor advisor)
+ {
+ this.advisor = advisor;
+ this.fields = new Tree<FieldNode>();
+ this.behaviours = new Tree<BehaviourNode>();
+ }
+
+ public Advisor getAdvisor()
+ {
+ return this.advisor;
+ }
+
+ public BehaviourNode getBehaviour(Constructor constructor)
+ {
+ String behaviourKey = BehaviourNode.getDefaultKey(constructor);
+ BehaviourNode behaviourNode = behaviours.searchValue(behaviourKey);
+ if (behaviourNode == null)
+ {
+ behaviourNode = new BehaviourNode(ClassNode.this, constructor);
+ TreeInsertionUtil.insertNode(behaviourNode, behaviourKey, behaviours);
+ }
+ return behaviourNode;
+ }
+
+ public BehaviourNode getBehaviour(Method method)
+ {
+ String behaviourKey = BehaviourNode.getDefaultKey(method);
+ BehaviourNode behaviourNode = behaviours.searchValue(behaviourKey);
+ if (behaviourNode == null)
+ {
+ behaviourNode = new BehaviourNode(ClassNode.this, method);
+ TreeInsertionUtil.insertNode(behaviourNode, behaviourKey, behaviours);
+ }
+ return behaviourNode;
+ }
+
+ public Collection<BehaviourNode> searchBehaviours(String behaviourExpression)
+ {
+ return behaviours.search(behaviourExpression);
+ }
+
+ public FieldNode getField(Field field)
+ {
+ String defaultKey = FieldNode.getDefaultKey(field);
+ FieldNode fieldNode = fields.searchValue(defaultKey);
+ if (fieldNode == null)
+ {
+ fieldNode = new FieldNode(ClassNode.this, field);
+ TreeInsertionUtil.insertNode(fieldNode, defaultKey, fields);
+ }
+ return fieldNode;
+ }
+
+ public Collection<FieldNode> searchFields(String fieldExpression)
+ {
+ return fields.search(fieldExpression);
+ }
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/FieldNode.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -0,0 +1,105 @@
+/*
+ * 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.Field;
+import java.util.Collection;
+
+import org.jboss.aop.FieldInfo;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ */
+class FieldNode implements Node
+{
+ private ClassNode classNode;
+ private Field field;
+ private FieldInfo fieldRead;
+ private FieldInfo fieldWrite;
+
+ public FieldNode(ClassNode classNode, Field field)
+ {
+ this.classNode = classNode;
+ this.field = field;
+ }
+
+ public static String getDefaultKey(Field field)
+ {
+ return field.getType().getName() + " " + field.getName();
+ }
+
+ public ClassNode getClassNode()
+ {
+ return this.classNode;
+ }
+
+ public String getDefaultKey()
+ {
+ return getDefaultKey(this.field);
+ }
+
+ public void loadMetaDataKeys(Collection<String> names)
+ {
+ String commonPrefix = this.field.getType() + " @";
+ Collection<String> metaDataTags = classNode.getAdvisor().getMetaDataTags(this.field);
+ for (String metaDataTag: metaDataTags)
+ {
+ names.add(commonPrefix + metaDataTag);
+ }
+ }
+
+ public Field getField()
+ {
+ return this.field;
+ }
+
+ public FieldInfo getFieldRead()
+ {
+ return this.fieldRead;
+ }
+
+ public boolean hasFieldRead()
+ {
+ return fieldRead != null;
+ }
+
+ public void setFieldRead(FieldInfo fieldRead)
+ {
+ this.fieldRead = fieldRead;
+ }
+
+ public boolean hasFieldWrite()
+ {
+ return fieldWrite != null;
+ }
+
+ public FieldInfo getFieldWrite()
+ {
+ return this.fieldWrite;
+ }
+
+ public void setFieldWrite(FieldInfo fieldWrite)
+ {
+ this.fieldWrite = fieldWrite;
+ }
+}
Added: 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/JoinPointGraph.java (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/JoinPointGraph.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -0,0 +1,205 @@
+/*
+ * 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.Method;
+import java.util.Collection;
+import java.util.HashSet;
+
+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.JoinPointInfo;
+import org.jboss.aop.MethodByConInfo;
+import org.jboss.aop.MethodByMethodInfo;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ * Searchable data structure containing all loaded prepared joinpoints.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class JoinPointGraph
+{
+ private static final JoinPointGraph INSTANCE = new JoinPointGraph();
+
+ private Tree<ClassNode> classTree;
+
+ private JoinPointGraph()
+ {
+ this.classTree = new Tree<ClassNode>();
+ }
+
+ public static JoinPointGraph getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public Collection<JoinPointInfo> search(SearchKey key)
+ {
+ Collection<JoinPointInfo> result = new HashSet<JoinPointInfo>();
+ ((ParsedSearchKey) key).search(classTree, result);
+ return result;
+ }
+
+ public synchronized void register(FieldInfo info)
+ {
+ ClassNode classNode = getClassNode(info.getClazz(), info.getAdvisor());
+ FieldNode fieldNode = classNode.getField(info.getField());
+ if (info.isRead())
+ {
+ fieldNode.setFieldRead(info);
+ }
+ else
+ {
+ fieldNode.setFieldWrite(info);
+ }
+ }
+
+ public synchronized void register(ConstructorInfo info)
+ {
+ getBehaviour(info.getAdvisor(), info.getClazz(), info.getConstructor()).
+ setExecution(info);
+ }
+
+ public synchronized void register(ConstructionInfo info)
+ {
+ getBehaviour(info.getAdvisor(), info.getClazz(), info.getConstructor()).
+ setConstruction(info);
+ }
+
+ public synchronized void register(MethodInfo info)
+ {
+ getBehaviour(info.getAdvisor(), info.getClazz(), info.getMethod()).
+ setExecution(info);
+ }
+
+ public synchronized void register(ConByConInfo info)
+ {
+ BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ info.getCalledClass(), info.getConstructor());
+ String callName = BehaviourNode.getDefaultKey(info.getCallingConstructor());
+ behaviour.insertCaller(callName, info);
+ }
+
+ public synchronized void register(ConByMethodInfo info)
+ {
+ BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ info.getCalledClass(), info.getConstructor());
+ String callName = BehaviourNode.getDefaultKey(info.getCallingMethod());
+ behaviour.insertCaller(callName, info);
+ }
+
+ public synchronized void register(MethodByMethodInfo info)
+ {
+ BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ info.getCalledClass(), info.getMethod());
+ String callerName = BehaviourNode.getDefaultKey(info.getCallingMethod());
+ behaviour.insertCaller(callerName, info);
+ }
+
+ public synchronized void register(MethodByConInfo info)
+ {
+ BehaviourNode behaviour = getBehaviour(info.getAdvisor(),
+ info.getCalledClass(), info.getMethod());
+ String callerName = BehaviourNode.getDefaultKey(info.getCallingConstructor());
+ behaviour.insertCaller(callerName, info);
+ }
+
+ /**
+ * @param classNode
+ * @param constructor
+ * @return
+ */
+ private BehaviourNode getBehaviour(Advisor advisor, Class clazz, Constructor constructor)
+ {
+ ClassNode classNode = getClassNode(clazz, advisor);
+ return classNode.getBehaviour(constructor);
+ }
+
+ /**
+ * @param classNode
+ * @param method
+ * @return
+ */
+ private BehaviourNode getBehaviour(Advisor advisor, Class clazz, Method method)
+ {
+ ClassNode classNode = getClassNode(clazz, advisor);
+ return classNode.getBehaviour(method);
+ }
+
+ private ClassNode getClassNode(Class clazz, Advisor advisor)
+ {
+ String defaultKey = ClassNode.getDefaultKey(clazz);
+ ClassNode classNode = classTree.searchValue(defaultKey);
+ if (classNode == null)
+ {
+ classNode = new ClassNode(clazz, advisor);
+ insertClassNode(clazz, defaultKey, classNode);
+ }
+ return classNode;
+ }
+
+ /**
+ * @param clazz
+ * @param classNode
+ */
+ private void insertClassNode(Class clazz, String defaultKey, ClassNode classNode)
+ {
+ TreeInsertionUtil.insertNode(classNode, defaultKey, classTree);
+ insertHierarchy(clazz, classNode);
+ }
+
+ /**
+ * @param clazz
+ * @param classNode
+ */
+ private void insertHierarchy(Class clazz, ClassNode classNode)
+ {
+ if (clazz.getSuperclass() != null)
+ {
+ getClassNode(clazz.getSuperclass()).addDirectSubtype(classNode);
+ for (Class interfaceClass: clazz.getInterfaces())
+ {
+ getClassNode(interfaceClass).addDirectSubtype(classNode);
+ }
+ }
+ }
+
+ private ClassNode getClassNode(Class clazz)
+ {
+ String defaultKey = ClassNode.getDefaultKey(clazz);
+ ClassNode classNode = classTree.searchValue(defaultKey);
+ if (classNode != null)
+ {
+ return classNode;
+ }
+ classNode = new ClassNode(clazz);
+ insertClassNode(clazz, defaultKey, classNode);
+ return classNode;
+ }
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/Node.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+/**
+ * A node in the graph.
+ * <br>
+ * Every node has the following properties:
+ * <ul>
+ * <li> contains one or more instrumented joinpoints;</li>
+ * <li> is reachable by at least one search mechanism;</li>
+ * <li> is inserted in one of the graph's subtrees;</li>
+ * <li> represents a reflected code element;</li>
+ * <li> has an identifier key in the tree it belongs;</li>
+ * <li> may have additional keys in the tree, if the reflected code element is
+ * associated with metadata.</li>
+ * </ul>
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+interface Node
+{
+ /**
+ * Returns the default key of this node. This key can be used as the unique
+ * identifier of this node in the tree it belongs.
+ *
+ * @return a key that identifies this node uniquely in the tree it belongs
+ */
+ String getDefaultKey();
+
+ /**
+ * Loads all metadata keys that index this node in the tree it belongs.
+ * <br>
+ * 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
+ * identify this node uniquely, as they may be common to more than one node in the
+ * same tree.
+ *
+ * @param names collection that will hold all loaded meta data keys.
+ */
+ void loadMetaDataKeys(Collection<String> names);
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/TreeInsertionUtil.java 2008-03-11 04:49:11 UTC (rev 70725)
@@ -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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.aop.joinpoint.graph.tree.Tree;
+
+/**
+ * Utility class for inserting {@link Node nodes} on the subtrees that compose
+ * the joinpoint graph.
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+class TreeInsertionUtil
+{
+ // avoids the cost of creating a collection for metadata keys everytime a
+ // node is added to the graph
+ 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.
+ *
+ * @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.
+ */
+ public static <N extends Node> void insertNode(N node, String key, Tree<N> tree)
+ {
+ synchronized(TEMP_KEYS)
+ {
+ try
+ {
+ tree.insert(key, node);
+ node.loadMetaDataKeys(TreeInsertionUtil.TEMP_KEYS);
+ for (String metaDataKey: TreeInsertionUtil.TEMP_KEYS)
+ {
+ tree.insert(metaDataKey, node);
+ }
+ }
+ finally
+ {
+ TEMP_KEYS.clear();
+ }
+
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list