Example #1
0
  /**
   * Register several interfaces in same time.<br>
   * Remember to declare all shared linked interfaces in same time
   *
   * @param interfacesIDL Interfaces to register
   * @throws IOException On registering issue
   */
  public static void declareIDLs(final Class<?>... interfacesIDL) throws IOException {
    final ArrayList<NameCode> codes = new ArrayList<NameCode>();

    for (final Class<?> interfaceIDL : interfacesIDL) {
      codes.addAll(JHelpIDL.createClassesForInterface(interfaceIDL));
    }

    Compiler.compil(JHelpIDL.COMPILE_DIRECTORY_BIN, codes.toArray(new NameCode[codes.size()]));

    for (final NameCode nameCode : codes) {
      JHelpIDL.CLASS_LOADER.add(
          new File(
              JHelpIDL.COMPILE_DIRECTORY_BIN,
              nameCode.getName().replace('.', File.separatorChar) + JHelpIDL.CLASS));
    }
  }
Example #2
0
  /**
   * Link a receiver to an interface.<br>
   * It a way to say what to answer when receiver message.<br>
   * For one interface, only one receiver is allowed, have to call {@link #stopReceiver(Class)} for
   * be able change the registered object
   *
   * @param <TYPE> Interface type
   * @param interfaceIDLImplementation Given implementation
   * @param interfaceIDL Interface class
   * @throws ClassNotFoundException If interface not registered
   * @throws NoSuchMethodException If registeration had previously issue
   * @throws SecurityException If the interface targetted is protected by security form refelection
   * @throws InstantiationException If registeration had previously issue
   * @throws IllegalAccessException If the interface targetted is protected by security form
   *     refelection
   * @throws IllegalArgumentException If the implementation given is wrong type
   * @throws InvocationTargetException If the interface targetted is protected by security form
   *     refelection or registeration had previously issue
   */
  @SuppressWarnings("unchecked")
  public static <TYPE> void registerReceiver(
      final TYPE interfaceIDLImplementation, final Class<TYPE> interfaceIDL)
      throws ClassNotFoundException, NoSuchMethodException, SecurityException,
          InstantiationException, IllegalAccessException, IllegalArgumentException,
          InvocationTargetException {
    if (interfaceIDLImplementation == null) {
      throw new NullPointerException("interfaceIDLImplementation musn't be null");
    }

    final String className = interfaceIDL.getName() + JHelpIDL.TARGET;
    TYPE receiver = (TYPE) JHelpIDL.INSTANCES.get(className);

    if (receiver != null) {
      throw new IllegalStateException("A receiver is already registered !");
    }

    final Class<?> claz = JHelpIDL.CLASS_LOADER.loadClass(className);
    final Constructor<?> constructor = claz.getConstructor(interfaceIDL);
    receiver = (TYPE) constructor.newInstance(interfaceIDLImplementation);

    JHelpIDL.INSTANCES.put(className, receiver);
  }