2 Replies Latest reply on Apr 1, 2013 5:57 AM by 1000102

    Need help about reflexivity bidirectionnal

      I try to make an application that could use plugin (with thread and sockets)
      For this moment I could instantiate my jar at runtime and call method from mother class.

      here is the part where I instantiate the jar

      public static void load_Jars (){

                <blockquote>Server _server = new Server();
                JarFile jarFile = null;
           File file = new File("C:/Chemin d'accès du jar.jar");
      URLClassLoader clazzLoader = null;
                <blockquote>try {
                     clazzLoader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()});
                } catch (MalformedURLException e2) {
                }</blockquote>           <blockquote>try {
                     jarFile = new JarFile(file);
                } catch (IOException e1) {
                     // TODO Auto-generated catch block
                }</blockquote> Enumeration<JarEntry> entries = jarFile.entries();

      while (entries.hasMoreElements()) {<blockquote>JarEntry element = entries.nextElement();
      if (element.getName().endsWith(".class")) {
      try {
      Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", "."));

           Constructor constr = c.getConstructor(String.class);      
      Server.o = constr.newInstance(_message, event);
      Server.method = c.getMethod("Item_Action",String.class); </blockquote> }
      } catch (Exception e) {
      }</blockquote>      }

      and there the class in the jar

      public class FM_Automate{

           <blockquote>static String socketPort, message;
           private static ServerSocket socketserverB;
      private static Socket socketB;
      static Boolean etatsocket;
      public static Class _server;</blockquote>   
      public String getMessage () {
           <blockquote>return message;</blockquote> }
      public FM_Automate (String _message){

           <blockquote>message = _message;     

                try {
                          <blockquote>socketB = new Socket("",2010);
                          new ReceptionSrvFMAuto (socketB, this);
                          etatsocket = socketB.isConnected();</blockquote>               } catch (UnknownHostException e) {
                          <blockquote>// TODO Auto-generated catch block
                          e.printStackTrace();</blockquote>               } catch (IOException e) {
                          <blockquote>// TODO Auto-generated catch block
                          e.printStackTrace();</blockquote>               }</blockquote> }

           public void Item_Action (String _message){
           <blockquote>message = _message;
           try {

                     <blockquote>PrintWriter out = new PrintWriter(
      new BufferedWriter(
      new OutputStreamWriter(socketB.getOutputStream())),
                } catch (UnknownHostException e) {
                     <blockquote>// TODO Auto-generated catch block
                     e.printStackTrace();</blockquote>          } catch (IOException e) {
                     <blockquote>// TODO Auto-generated catch block
                     e.printStackTrace();</blockquote>          }</blockquote>     }
      synchronized public static void getReceivedData (String message){
           <blockquote>System.out.println("message: "+message);</blockquote> }

      I would like to return value for the thread that receive data from socket to the mother class.
      I try many thing like pass mother class inside the constructor etc but nothing work

      Hope someone could help me

      Thanks a lot