zoukankan      html  css  js  c++  java
  • 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的静态类,见该文件中后边部分。

  • 相关阅读:
    初次学习Vue,输出Hello Vue!
    js的let语句在安卓手机端的QQ浏览器出错的问题
    前端框架的对比
    Vue环境搭建及node安装过程整理
    快速排序与冒泡排序(面试题)
    判断一个字符串中出现次数最多的字符并统计其出现的次数(面试题)
    Go_18: Golang 中三种读取文件发放性能对比
    GO_05_2:Golang 中 panic、recover、defer 的用法
    Go_17:GoLang中如何使用多参数属性传参
    Go_16:GoLang中flag标签使用
  • 原文地址:https://www.cnblogs.com/Joy06/p/3371794.html
Copyright © 2011-2022 走看看