コード例 #1
0
  @PostConstruct
  public void postConstruct(InvocationContext ctx) throws Exception {
    log.debug("postConstruct " + ctx);

    Class<?> businessInterfaces[];
    InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
    Local local = container.getAnnotation(Local.class);
    if (local != null) businessInterfaces = local.value();
    else if (container.getBeanClass().getInterfaces().length == 1)
      businessInterfaces = new Class<?>[] {container.getBeanClass().getInterfaces()[0]};
    else throw new IllegalArgumentException("TODO");

    // TODO: determine JNDI name
    String jndiName = container.getBeanClass().getSimpleName() + "/local";
    log.debug("jndiName = " + jndiName);

    Object proxy =
        Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(),
            businessInterfaces,
            new LocalProxy(container));

    Util.createSubcontext(new InitialContext(), container.getBeanClass().getSimpleName());
    NonSerializableFactory.rebind(new InitialContext(), jndiName, proxy);

    ctx.proceed();
  }
コード例 #2
0
  private MockEjbDescriptor(final Class<T> type) {
    this.beanClass = type;
    this.ejbName = type.getSimpleName();

    this.localInterfaces = new ArrayList<BusinessInterfaceDescriptor<?>>();
    Local localAnnotation = type.getAnnotation(Local.class);
    if (localAnnotation != null) {
      for (final Class<?> clazz : localAnnotation.value()) {
        localInterfaces.add(createBusinessInterfaceDescriptor(clazz));
      }
    }

    for (final Class<?> clazz : type.getInterfaces()) {
      if (clazz.isAnnotationPresent(Local.class)) {
        localInterfaces.add(createBusinessInterfaceDescriptor(clazz));
      }
    }

    this.remoteInterfaces = new ArrayList<BusinessInterfaceDescriptor<?>>();
    Remote remoteAnnotation = type.getAnnotation(Remote.class);
    if (remoteAnnotation != null) {
      for (final Class<?> clazz : remoteAnnotation.value()) {
        remoteInterfaces.add(createBusinessInterfaceDescriptor(clazz));
      }
    }

    for (final Class<?> clazz : type.getInterfaces()) {
      if (clazz.isAnnotationPresent(Remote.class)) {
        remoteInterfaces.add(createBusinessInterfaceDescriptor(clazz));
      }
    }

    // cope with EJB 3.1 style no-interface views
    if (localInterfaces.size() == 0) {
      localInterfaces.add(createBusinessInterfaceDescriptor(type));
    }
    this.removeMethods = new HashSet<Method>();
    for (final Method method : type.getMethods()) {
      if (method.isAnnotationPresent(Remove.class)) {
        removeMethods.add(method);
      }
    }
  }