Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/port80/graph/impl/GraphFactory.java


1   //
2   // Copyright(c) 2002, Chris Leung
3   //
4   
5   package com.port80.graph.impl;
6   
7   import com.port80.util.*;
8   import com.port80.graph.*;
9   import com.port80.graph.dot.parser.DotParser;
10  
11  /** Factory class that produce a SubGraph.  The factory also provide
12   *  an IAttrRegistry interface for client to check for unqiue
13   *  attribute names.
14   */
15  public class GraphFactory implements IGraphFactory {
16  
17      ////////////////////////////////////////////////////////////////////////
18  
19      private static GraphFactory instance = null;
20  
21      ////////////////////////////////////////////////////////////////////////
22  
23      public static GraphFactory getInstance() {
24          if (instance == null) instance = new GraphFactory();
25          return instance;
26      }
27  
28      public static IGraph getInstance(int type, String name, IGraph parent) {
29          if (instance == null) instance = new GraphFactory();
30          return instance.newGraph(type, name, parent);
31      }
32  
33  private GraphFactory() {}
34  
35      ////////////////////////////////////////////////////////////////////////
36  
37      public IGraph newGraph(int type, String name, IGraph parent) {
38          switch (type) {
39          case DotParser.DOTDIGRAPH:
40          case DotParser.DOTSTRICTDIGRAPH:
41              return new DirectedGraph(name, null, parent);
42          default:
43              msg.err("GraphFactory.newGraph(): Accept digraph only for now"
44                      + ": type=" + type
45                      + ", name=" + name
46                      + ", parent=" + parent
47                     );
48              return null;
49          }
50      }
51  
52      ////////////////////////////////////////////////////////////////////////
53  
54  }
55