jxta学习笔记5~开始研究myJXTA~

在官方网站上下载了2.5版本的myJXTA,配置好窗体后跑了一遍,感觉这个示例程序的功能还是蛮强大的,但是这个程序的API写得比较简单,所以决定自己仔细研究研究~

 

先从main( )入手:

 

public final class Main {

    /**
     * 这个类的对象只能初始化为一个单例
     */
    private Main() {
        super();
    }

    /**
     * 本应用的驱动方法.  建立主线程.
     */
    public static void main(final String[] args) {
        Thread.currentThread().setName(Main.class.getName() + ".main()");
        System.setProperty("net.jxta.myjxta", Level.WARNING.getName());
        MyJXTA.startMyJxta();
    }

}

 

MyJXTA.startMyJxta();这个语句调用了MyJXTA的类方法:

   

public static MyJXTA startMyJxta() {
        if (g_theInstance == null) {
            g_theInstance = new MyJXTA();
        }
        return g_theInstance;
    }

这样初始化了一个MyJXTA的对象,执行了构造方法(构造方法私有):

 

private MyJXTA() {

  // 在同一项工作中,只能有一个活动的MyJxta实例,所以在这里做一次检查,如果存在了就销毁
  // directory
  if (!MultipleInstanceUtil.isOnlyInstance(this)) {
   destroy();
   return;
  }

  //将实例初始化为当前对象

  g_theInstance = this;

  // 仅仅用于NetBean集成技术,注册了一个mbean,用到了jmx技术?
  registerBeanStuff();

  // // 初始化插件 / 模块容器

  m_pluginContainer = new DefaultMyJxtaPluginContainer(this);

  // ViewFactory.setViewerClass(net.jxta.myjxta.ui.MyJXTALiteViewer.class);
  // initiate the view (right now only a single swing view is
  // implememented)

  //获得视图
  this.view = ViewFactory.getView(this);

  // call the init methods of the plugins

  //初始化插件
  m_pluginContainer.init();

  //使视图可见

  this.view.setVisible(true);

  // boolean isConfigured = configureMyJxta();

  //

  try {

  //初始化配置平台

   MyJXTAConfigurator c = new NetworkManagerConfigurator(this.view);
   // MyJXTAConfigurator c = new JxtaExtConfigurator(this.view);
   c.configurePlatform();
   initialize();
  } catch (IOException e) {
   e.printStackTrace(); // To change body of catch statement use
         // File | Settings | File Templates.
   view.showMessageDialog(e.getLocalizedMessage());
  }
 }

 

上面出现的代码就不在其中作注释了,另起一段一句一句分析,— —!发觉原版注释中有很多错字~

 m_pluginContainer = new DefaultMyJxtaPluginContainer(this);

   

    public DefaultMyJxtaPluginContainer(MyJXTA p_myJxta) {
        m_myJxta = p_myJxta;//定义一个MyJXTA对象
        try {

       /*

        *设置安全策略为空,这一部比较重要API中是这样说的:

        * Sets the System security.

        *If there is a security manager already installed, this method first calls the security manager's checkPermission method with   

    *a RuntimePermission("setSecurityManager") permission to ensure it's ok to replace the existing security manager

        *.This may result in throwing a SecurityException. Otherwise, the argument is established as the current security manager. 

        *If the argument is null and no security manager has been established, then no action is taken and the method simply returns.
        */ 

        System.setSecurityManager(null);
        } catch (Exception e) {
            e.printStackTrace();
        }


        PluginFetcher.PluginJar[] externalPluginsJars = PluginFetcher.getExternalPluginJars();

        PluginFetcher.PluginJar[] internalPluginsJars = PluginFetcher.getInternalPlugins();

        Plugin[] plugins = PluginFetcher.getValidPluginInstances(externalPluginsJars);
        Plugin[] internalPlugins = PluginFetcher.getValidPluginInstances(internalPluginsJars);
        m_plugins = new Plugin[plugins.length + internalPlugins.length];

        for (int i = 0; i < m_plugins.length; i++) {
            m_plugins[i] = (i < internalPlugins.length) ? internalPlugins[i] : plugins[i - internalPlugins.length];
        }
   }

 

   先到这里,下一篇继续~

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值