• Prefuse 4未完


    今天才发现,prefuse的官方用户手册没有写完,只能自己边研究边写了。

        之前用到一个GraphMLReader类的GraphReader函数,就先从他入手吧:

        1、GraphMlReader

        定义:

    public class GraphMLReader extends AbstractGraphReader  implements GraphReader{
    /***
    .....
    ***/


       其中:GraphReader仅仅定义了四个不同参数reader函数,其内容为:

    public interface GraphReader {
      public Graph readGraph(String location) throws DataIOException;
      public Graph readGraph(URL url) throws DataIOException;
      public Graph readGraph(File f) throws DataIOException;
      public Graph readGraph(InputStream is) throws DataIOException;
    }

        AbstractGraphReader也是一个抽象类,对前三个Reader进行了实现,最后一个参数为InputStream is的仍然保留为抽象函数,但是,如果观察这些实现的函数会发现,所有的读入动作,最后都交给了public Graph readGraph(InputStream is) throws DataIOException; 函数来实现,这样具体怎么读入数据,就要看集成这个抽象类的类来决定了。

        而GraphMLReader直接对这个函数进行了实现:

    public Graph readGraph(InputStream is) throws DataIOException {
            try {       
                SAXParserFactory factory   = SAXParserFactory.newInstance();
                SAXParser        saxParser = factory.newSAXParser();
                
                GraphMLHandler   handler   = new GraphMLHandler();
                System.out.println("here");
                saxParser.parse(is, handler);
                return handler.getGraph();
            } catch ( Exception e ) {
                if ( e instanceof DataIOException ) {
                    throw (DataIOException)e;
                } else {
                    throw new DataIOException(e);
                }
            }
        }

         其中SAXParserFactory,SAXParser是java提供的一个解析XML的库文件,输入的第一个参数为InputStream,第二个参数是DefaultHandler。这里的GraphMLHandler就是一个继承了DefaultHandler的静态类,见该文件中后边部分。

  • 相关阅读:
    背景qwq
    关于Oracle数据库空表无法导出问题
    Linux 备份 Oracle11g 数据库
    Linux Tomcat安装
    Linux JDK安装
    Oracle 监听与服务器
    Xftp强制更新
    Linux 安装 Oracle11g 数据库
    Vue 动态获取组件与动态路由获取组件
    Linux 防火墙
  • 原文地址:https://www.cnblogs.com/Joy06/p/3371794.html
Copyright © 2020-2023  润新知