在官方网站上下载了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];
}
}
先到这里,下一篇继续~