Package fbench.graph.model

Source Code of fbench.graph.model.GraphModel

//Copyright (c)2005 Holobloc Inc.
//Contributed to the OOONEIDA FBench project under the Common Public License.
package fbench.graph.model;

import java.util.Vector;

import fbench.FBench;
import fbench.dom.ElementModel;
import fbench.graph.GraphElement;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* An ElementModel for a GraphView.
*
* @author JHC
* @version 20051028/JHC - Set default value for <TT>canAccept()</TT>.
* @version 20050825/JHC
*/
public abstract class GraphModel extends ElementModel {
    public GraphModel() {
        super();
    }

    public GraphModel(Element el) {
        super(el);
    }

    /**
     * Returns a GraphModel encapsulating the given DOM Element, or <TT>null
     * </TT> if no such GraphModel exists.
     */
    public static GraphModel forElement(Element el) {
//      try FBench Static list
      String classname = FBench.getGraphModel(el.getTagName());
      //System.out.println("Looking for Element Model for type:" + el.getTagName());
      if ( classname != null )
      {
        //System.out.println("Existing: " + classname);
        try {
              Class geclass = Class.forName(classname);
              Object obj = geclass.newInstance();
              if (obj instanceof GraphModel) {
                GraphModel em = (GraphModel) obj;
                  em.setElement(el);
                  return em;
              }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
      }
      else
      {
        ElementModel ans = forElement(el, "fbench.graph.model.");
            if (ans instanceof GraphModel)
                return (GraphModel) ans;
      }
        java.lang.System.out.println("No GraphModel for " + el.getTagName());
        return null;
       
    }

    /**
     * Returns a Vector of GraphElements (if any) to be used for drawing the
     * graph of the contained Element. Default is the GraphElements (if any)
     * corresponding to the children of the contained Element.
     */
    public Vector getGraph() {
        NodeList nl = getElement().getChildNodes();
        Vector ans = new Vector(nl.getLength());
        for (int i = 0; i < nl.getLength(); i++) {
            GraphElement ge = GraphElement.forElement((Element) nl.item(i));
            if (ge != null)
                ans.add(ge);
        }
        return ans;
    }

    /**
     * Returns <B>true </B> if the graph represented by this model can accept a
     * new LibraryElement stored with the given file name. This is typically
     * done by checking the file suffix. The default value is <B>false </B>.
     */
    public boolean canAccept(String filename) {
        return false;
    }
}
TOP

Related Classes of fbench.graph.model.GraphModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.