[jboss-cvs] JBossCache/src/org/jboss/cache/factories ...

Elias Ross genman at noderunner.net
Sun Nov 19 22:53:54 EST 2006


  User: genman  
  Date: 06/11/19 22:53:54

  Modified:    src/org/jboss/cache/factories  NodeFactory.java
  Log:
  JBCACHE-867, Move methods from the ProxyImpl to Node, refactor Node classes as well
  
  Revision  Changes    Path
  1.15      +56 -70    JBossCache/src/org/jboss/cache/factories/NodeFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/NodeFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- NodeFactory.java	14 Aug 2006 17:20:34 -0000	1.14
  +++ NodeFactory.java	20 Nov 2006 03:53:54 -0000	1.15
  @@ -6,14 +6,20 @@
    */
   package org.jboss.cache.factories;
   
  -import org.jboss.cache.*;
  -import org.jboss.cache.optimistic.WorkspaceNodeImpl;
  -import org.jboss.cache.optimistic.WorkspaceNode;
  -import org.jboss.cache.optimistic.TransactionWorkspace;
  -import org.jboss.cache.optimistic.DataVersion;
  -
   import java.util.Map;
   
  +import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.DataNode;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.Node;
  +import org.jboss.cache.NodeImpl;
  +import org.jboss.cache.OptimisticTreeNode;
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.optimistic.DataVersion;
  +import org.jboss.cache.optimistic.TransactionWorkspace;
  +import org.jboss.cache.optimistic.WorkspaceNode;
  +import org.jboss.cache.optimistic.WorkspaceNodeImpl;
  +
   /**
    * A factory that generates nodes.
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  @@ -22,12 +28,15 @@
   public class NodeFactory
   {
      private static NodeFactory _singleton;
  +
      public static final byte NODE_TYPE_TREENODE = 1;
  +
      public static final byte NODE_TYPE_WORKSPACE_NODE = 2;
  +
      public static final byte NODE_TYPE_OPTIMISTIC_NODE = 3;
  +
      /**
       * private empty ctor
  -    *
       */
      private NodeFactory()
      {
  @@ -39,43 +48,12 @@
       */
      public static NodeFactory getInstance()
      {
  -      if (_singleton == null) _singleton = new NodeFactory();
  +      if (_singleton == null)
  +         _singleton = new NodeFactory();
         return _singleton;
      }
   
      /**
  -    * Returns a new root node.
  -    */
  -   public DataNode createRootDataNode(byte nodeType, TreeCache cache)
  -   {
  -       return createDataNode(nodeType, null, Fqn.ROOT, null, null, cache);
  -   }
  -
  -   /**
  -    * Returns a new data node.
  -    */
  -   public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, DataNode parent, Map data, TreeCache cache, DataVersion version)
  -   {
  -       return createDataNode(nodeType, childName, fqn, parent, data, false, cache, version);
  -   }
  -
  -   /**
  -    * Returns a new data node.
  -    */
  -   public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, DataNode parent, Map data, TreeCache cache)
  -   {
  -      return createDataNode(nodeType, childName, fqn, parent, data, false, cache, null);
  -   }
  -
  -   /**
  -    * Returns a new data node.
  -    */
  -    public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, DataNode parent, Map data, boolean mapSafe, TreeCache cache)
  -    {
  -        return createDataNode(nodeType, childName, fqn, parent, data, mapSafe, cache, null);
  -    }
  -
  -   /**
       * Creates a new {@link DataNode} instance.
       * 
       * @param nodeType  either {@link #NODE_TYPE_TREENODE} or {@link #NODE_TYPE_TREENODE}
  @@ -91,18 +69,18 @@
       * 
       * @return  the new node
       */
  -   public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, DataNode parent, Map data, boolean mapSafe, TreeCache cache, DataVersion version)
  +   public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe,
  +         DataVersion version, CacheSPI cache)
      {
  -      DataNode n = null;
         switch (nodeType)
         {
  -         case NODE_TYPE_TREENODE: n = new NodeImpl(childName, fqn, (NodeImpl) parent, data, mapSafe, cache);
  -            break;
  -         case NODE_TYPE_OPTIMISTIC_NODE: n = new OptimisticTreeNode(childName, fqn, (NodeImpl) parent, data, mapSafe, cache, version);
  -             break;
  -
  +         case NODE_TYPE_TREENODE :
  +            return new NodeImpl(childName, fqn, data, mapSafe, cache);
  +         case NODE_TYPE_OPTIMISTIC_NODE :
  +            return new OptimisticTreeNode(childName, fqn, parent, data, cache);
  +         default :
  +            throw new IllegalArgumentException();
         }
  -      return n;
      }
      
      /**
  @@ -111,12 +89,12 @@
       * @deprecated - passing in childName and fqn shuld be redundant.
       * @return TreeNode
       */
  -   public TreeNode createNode(Object childName, Fqn fqn, TreeNode parent, Map data, TreeCache cache)
  +   public Node createNode(Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache)
      {
          return createNodeOfType(parent, childName, fqn, parent, data, cache, null);
      }
   
  -    public TreeNode createNode(Object childName, TreeNode parent, Map data, TreeCache cache)
  +   public Node createNode(Object childName, Node parent, Map data, CacheSPI cache)
       {
           return createNodeOfType(parent, childName, new Fqn(parent.getFqn(), childName), parent, data, cache, null);
       }
  @@ -125,27 +103,35 @@
        * same as above, passing in an explicit version
        * @deprecated - passing in childName and fqn shuld be redundant.
        */
  -    public TreeNode createNodeOfType(TreeNode template, Object childName, Fqn fqn, TreeNode parent, Map data, TreeCache cache, DataVersion version)
  +   public Node createNodeOfType(Node template, Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache,
  +         DataVersion version)
       {
         // TODO: MANIK - not the most elegant - temporary for now.
         if (template instanceof WorkspaceNode)
         {
  -          DataNode dataNodeParent = ((WorkspaceNode) parent).getNode();
  +         Node dataNodeParent = ((WorkspaceNode) parent).getNode();
             TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
             return createWorkspaceNode(dataNodeParent, workspace);
         }
   
         if (parent instanceof DataNode)
         {
  -          if (template instanceof OptimisticTreeNode) return createDataNode( NODE_TYPE_OPTIMISTIC_NODE, childName, fqn, (DataNode) parent, data, cache, version );
  -          if (template instanceof NodeImpl) return createDataNode( NODE_TYPE_TREENODE, childName, fqn, (DataNode) parent, data, cache );
  +         if (template instanceof OptimisticTreeNode)
  +            return createDataNode(NODE_TYPE_OPTIMISTIC_NODE, childName, fqn, parent, data, false, version, cache);
  +         if (template instanceof NodeImpl)
  +            return createDataNode(NODE_TYPE_TREENODE, childName, fqn, parent, data, false, null, cache);
         }
         return null;
      }
   
  -   public WorkspaceNode createWorkspaceNode(TreeNode dataNode, TransactionWorkspace workspace)
  +   public WorkspaceNode createWorkspaceNode(Node dataNode, TransactionWorkspace workspace)
  +   {
  +      return new WorkspaceNodeImpl(dataNode, workspace);
  +   }
  +
  +   public DataNode createRootDataNode(byte type, CacheSPI cache)
      {
  -       return new WorkspaceNodeImpl( dataNode, workspace );
  +      return (DataNode) this.createDataNode(type, null, Fqn.ROOT, null, null, false, null, cache);
      }
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list