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的静态类,见该文件中后边部分。

  • 相关阅读:
    Oracle 添加主键和索引
    Oracle中查询主键、外键、sequence、表基本信息等
    Spring工作原理
    Ehcache 缓存使用
    socket编程-java
    oracle触发器详解
    单例模式的几种写法
    [LeetCode] 412. Fizz Buzz 嘶嘶嗡嗡
    LeetCode Top Interview Questions
    [LeetCode] 131. Palindrome Partitioning 回文分割
  • 原文地址:https://www.cnblogs.com/Joy06/p/3371794.html
Copyright © 2011-2022 走看看