/** * Create a Java3D node which does not have a default constructor * * <p>parameterTypes must contain the classes required by the constructor, use Interger.TYPE, * Float.TYPE etc to specifiy primitive types * * <p>paramters should contain the list of parameters for the constructor, primitive types should * be wrapped in the appropriate class (ie Integer, Float ) */ protected SceneGraphObject createNode( Class j3dClass, Class[] parameterTypes, Object[] parameters) { SceneGraphObject ret; Constructor constructor; try { constructor = j3dClass.getConstructor(parameterTypes); ret = (SceneGraphObject) constructor.newInstance(parameters); } catch (IllegalAccessException e2) { throw new SGIORuntimeException( "Broken State class for " + j3dClass.getClass().getName() + " - IllegalAccess"); } catch (InstantiationException e3) { throw new SGIORuntimeException("Broken State class for " + j3dClass.getClass().getName()); } catch (java.lang.reflect.InvocationTargetException e4) { throw new SGIORuntimeException( "InvocationTargetException for " + j3dClass.getClass().getName()); } catch (NoSuchMethodException e5) { for (int i = 0; i < parameterTypes.length; i++) System.err.println(parameterTypes[i].getName()); System.err.println("------"); throw new SGIORuntimeException("Invalid constructor for " + j3dClass.getClass().getName()); } return ret; }
/** * Create a new Java3D node from the supplied class using the parameterless constructor * * <p>For Java3D nodes which do not have a default constructor you must overload this method and * create the object using createNode( className, parameters ) This will correctly handle * subclasses of Java3D classes */ protected SceneGraphObject createNode(Class state) { SceneGraphObject ret; try { ret = (SceneGraphObject) state.newInstance(); // System.err.println("Created J3D node for "+className ); } catch (IllegalAccessException exce) { throw new SGIORuntimeException( "Broken State class for " + state.getClass().getName() + " - IllegalAccess"); } catch (InstantiationException excep) { throw new SGIORuntimeException("Broken State class for " + state.getClass().getName()); } return ret; }