VisClient/org/hfbk/vis/VisNodeFactory.java

Go to the documentation of this file.
00001 package org.hfbk.vis;
00002 
00003 import java.lang.reflect.Constructor;
00004 
00005 import org.dronus.graph.Node;
00006 import org.hfbk.vis.visnode.VisNode;
00007 import org.lwjgl.util.vector.Vector3f;
00008 
00009 
00024 public class VisNodeFactory {
00025 
00029         final static Class<?>[] SIGNATURE={Node.class, Vector3f.class};
00030         
00040         public static VisNode create(Node n, Vector3f position) {
00041                 
00042                 String t=n.type;
00043                 
00044                 Class<?> cl=null; //class of VisNode to find
00045                 try{
00046                         //build java classname
00047                         String classname="org.hfbk.vis.visnode.Vis"+Character.toUpperCase(t.charAt(0))+t.substring(1);
00048                         //look up class. if it is a helper Node with no visual class, exception below. 
00049                         cl=Class.forName(classname);
00050                         //a matching visual class is found. instantiate the node. 
00051                         Constructor cns=cl.getConstructor(SIGNATURE);
00052                         return (VisNode)cns.newInstance(new Object[]{n, position});                     
00053                 
00054                 } catch (ClassNotFoundException e) {  //legal, not all nodes are visualizable.  
00055                         return null;                            
00056                 } catch (NoSuchMethodException e) {  //no useful constructor, encourage coder to do some..
00057                         throw new RuntimeException("NodeFactory: No valid public constructor at class "+cl);
00058                 } catch (Exception e){ //security, class load, ... 
00059                         throw new RuntimeException(e);
00060                 }
00061         }
00062 }

Generated on Tue Apr 7 17:57:22 2009 for visclient by  doxygen 1.5.1