GrxPluginLoader.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 /*
00011  *  GrxPluginLoader.java
00012  *
00013  *  Copyright (C) 2007 GeneralRobotix, Inc.
00014  *  All Rights Reserved
00015  *
00016  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00017  */
00018 
00019 package com.generalrobotix.ui.util;
00020 
00021 import java.io.File;
00022 import java.io.FilenameFilter;
00023 import java.lang.reflect.Constructor;
00024 import java.net.MalformedURLException;
00025 import java.net.URL;
00026 import java.net.URLClassLoader;
00027 
00028 import com.generalrobotix.ui.GrxBasePlugin;
00029 import com.generalrobotix.ui.GrxBaseView;
00030 import com.generalrobotix.ui.GrxPluginManager;
00031 
00036 public class GrxPluginLoader extends URLClassLoader {
00037         public GrxPluginLoader(String pluginDir, ClassLoader parent) {
00038                 super(new URL[0], parent);
00039         }
00040         
00041         public GrxPluginLoader(String pluginDir) {
00042                 this(pluginDir, null);
00043         }
00044 
00048         @SuppressWarnings("deprecation")
00049         public void addURL(String path) {
00050                 File f = new File(path);
00051                 if ( f.isDirectory() || (path.endsWith(".jar")&&f.exists())){
00052                         URL[] urls=getURLs();
00053                         for(URL url : urls){
00054                                 if(url.equals(path))
00055                                         return;
00056                         }       
00057                         try{
00058                                 super.addURL(f.toURL());
00059                                         System.out.println("classpath added: "+f.toString());
00060                         } catch (MalformedURLException e) {
00061                                 e.printStackTrace();
00062                         }
00063                 }else
00064                         return;
00065         }
00066 
00067         public Class<?> loadClass(String cname){
00068                 try {
00069                         return super.loadClass(cname, true);
00070                 } catch (ClassNotFoundException e) {
00071                         GrxDebugUtil.println("ClassNotFound "+cname);
00072                 }
00073                 return null;
00074         }
00075         
00076         public boolean existClass(String cname) {
00077                 try{
00078                         super.loadClass(cname, true);
00079                         return true;
00080                 }catch(ClassNotFoundException e){
00081                         return false;
00082                 }
00083         }
00084 
00085         // ビューの作成。クラスの作成はGrxUIでは行わず、パースペクティブに任せることにしたので消した。
00086         /*
00087         public GrxBaseView createView( Class<? extends GrxBaseView> cls ) {
00088                 String viewId = cls.getName();
00089 
00090                 IWorkbench workbench = PlatformUI.getWorkbench();
00091         IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
00092         IWorkbenchPage page = window.getActivePage();
00093         IViewPart view = page.findView(viewId);
00094         // はじめて使われるビューの場合
00095         if(view==null) {
00096                 System.out.println("[PERSPECTIVE] "+viewId+" is not Existence");
00097                 try {
00098                         // これやると現在の(これから作るのではない)パースペクティブに表示されてしまうよ。だめじゃん。
00099                         view = page.showView(viewId);
00100                 }catch( PartInitException e ) {
00101                         e.printStackTrace();
00102                 }
00103         }
00104 
00105         if( view instanceof GrxBaseView  ) {
00106                 System.out.println("[PERSPECTIVE] create "+viewId);
00107                 return (GrxBaseView)view;
00108         }
00109         System.out.println("[PERSPECTIVE] create "+cls.getName()+" fault.");
00110         return null;
00111         }
00112         */
00113 
00114         // 指定されたプラグインのコンストラクタを実行、インスタンスを返す
00115         public GrxBasePlugin createPlugin(Class cls, String name, GrxPluginManager manager) {
00116                 try {
00117                         // TODO: ビューの管理はEclipseにやらせている。以下は実際には不要
00118                         if( GrxBaseView.class.isAssignableFrom(cls) ) {
00119                                 //GrxDebugUtil.println("[PM] "+cls+" is view");
00120                                 //GrxBaseView vPlugin = createView( (Class<? extends GrxBaseView>) cls );
00121                                 //vPlugin.setName(name);
00122                                 //vPlugin.setManager(manager);
00123                                 return null;//vPlugin;
00124                         }else{
00125                                 //GrxDebugUtil.println("[PM] "+cls+" is item");
00126                                 Constructor c = cls.getConstructor(new Class[] { String.class, GrxPluginManager.class });
00127                                 return (GrxBasePlugin) c.newInstance(new Object[] { name, manager});
00128                         }
00129                 } catch (Exception e) {
00130                         e.printStackTrace();
00131                 }
00132                 return null;
00133         }
00134 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:54