public OtpErlangObject newInstance(final int objectId, final OtpErlangPid pid)
      throws InstantiationException, IllegalAccessException {

    MethodHandler mh = new ProxyHandler(root, objectId, pid, mths);
    Object obj = cl.newInstance();
    ((Proxy) obj).setHandler(mh);
    return root.makeErlangTuple(root.map_to_erlang(obj), root.map_to_erlang(mh));
  }
  <T> T createHandler(
      final Object framedElement,
      final FramedGraph<?> graph,
      final Element element,
      Class<?> frameClass,
      final Method method) {

    try {
      Class<T> implClass = (Class<T>) classCache.get(frameClass);
      T handler = factory.create(implClass);
      ((Proxy) handler)
          .setHandler(
              new MethodHandler() {
                private JavaHandlerContextImpl<Element> defaultJavahandlerImpl =
                    new JavaHandlerContextImpl<Element>(graph, method, element);

                @Override
                public Object invoke(Object o, Method m, Method proceed, Object[] args)
                    throws Throwable {
                  if (!Modifier.isAbstract(m.getModifiers())) {
                    return proceed.invoke(o, args);
                  } else {
                    if (m.getAnnotation(JavaHandler.class) != null) {
                      throw new JavaHandlerException(
                          "Method " + m + " is marked with @JavaHandler but is not implemented");
                    }
                    if (m.getDeclaringClass() == JavaHandlerContext.class) {
                      return m.invoke(defaultJavahandlerImpl, args);
                    }

                    return m.invoke(framedElement, args);
                  }
                }
              });
      return handler;
    } catch (ExecutionException e) {
      Throwable cause = e.getCause();
      if (cause instanceof ClassNotFoundException) {
        throw new JavaHandlerException("Problem locating handler class for " + frameClass, e);
      } else {
        throw new JavaHandlerException("Cannot create class for handling framed method", cause);
      }
    } catch (InstantiationException e) {
      throw new JavaHandlerException("Problem instantiating handler class", e);
    } catch (IllegalAccessException e) {
      throw new JavaHandlerException("Problem instantiating handler class", e);
    }
  }
Esempio n. 3
0
  public OutlineImpl(T members, boolean camelCased) {
    this.members = members;
    ((Proxy) members).setHandler(new OutlineMethodHandler());

    this.camelCased = camelCased;
  }