类javax.ejb.EJB源码实例Demo

下面列出了怎么用javax.ejb.EJB的API类实例代码及写法,或者点击链接到github查看源代码。

public EjbRefElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) {
	super(member, pd);
	EJB resource = ae.getAnnotation(EJB.class);
	String resourceBeanName = resource.beanName();
	String resourceName = resource.name();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	Class<?> resourceType = resource.beanInterface();
	if (Object.class != resourceType) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.beanName = resourceBeanName;
	this.name = resourceName;
	this.lookupType = resourceType;
	this.mappedName = resource.mappedName();
}
 
public EjbRefElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) {
	super(member, pd);
	EJB resource = ae.getAnnotation(EJB.class);
	String resourceBeanName = resource.beanName();
	String resourceName = resource.name();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	Class<?> resourceType = resource.beanInterface();
	if (Object.class != resourceType) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.beanName = resourceBeanName;
	this.name = resourceName;
	this.lookupType = resourceType;
	this.mappedName = resource.mappedName();
}
 
源代码3 项目: lams   文件: CommonAnnotationBeanPostProcessor.java
public EjbRefElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
	super(member, pd);
	EJB resource = ae.getAnnotation(EJB.class);
	String resourceBeanName = resource.beanName();
	String resourceName = resource.name();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	Class<?> resourceType = resource.beanInterface();
	if (resourceType != null && Object.class != resourceType) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.beanName = resourceBeanName;
	this.name = resourceName;
	this.lookupType = resourceType;
	this.mappedName = resource.mappedName();
}
 
public EjbRefElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
	super(member, pd);
	EJB resource = ae.getAnnotation(EJB.class);
	String resourceBeanName = resource.beanName();
	String resourceName = resource.name();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	Class<?> resourceType = resource.beanInterface();
	if (resourceType != null && Object.class != resourceType) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.beanName = resourceBeanName;
	this.name = resourceName;
	this.lookupType = resourceType;
	this.mappedName = resource.mappedName();
}
 
源代码5 项目: development   文件: DeployedSessionBean.java
private void invokeInterceptor(Method method, Class<?> clazz)
        throws InstantiationException, IllegalAccessException,
        InvocationTargetException {
    for (Method interceptorMethod : clazz.getMethods()) {
        if (interceptorMethod.getAnnotation(AroundInvoke.class) != null) {

            Object instance = clazz.newInstance();

            for (Field field : instance.getClass().getDeclaredFields()) {
                EJB ejb = field.getAnnotation(EJB.class);
                Inject inject = field.getAnnotation(Inject.class);
                if (ejb != null || inject != null) {
                    field.setAccessible(true);
                    field.set(instance, Mockito.mock(field.getType()));
                }
            }

            InvocationContext ic = createInvocationContext(method);
            interceptorMethod.invoke(instance, ic);
            break;
        }
    }
}
 
源代码6 项目: tomee   文件: TestClient.java
protected final void processFieldInjections() {
    Object home = null;
    ClassFinder finder = null;
    List<Field> fieldList = null;

    finder = new ClassFinder(getClassPath());
    fieldList = finder.findAnnotatedFields(EJB.class);
    for (final Iterator fields = fieldList.iterator(); fields.hasNext(); ) {
        final Field field = (Field) fields.next();
        final EJB ejbAnnotation = field.getAnnotation(EJB.class);
        if ((ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) {
            try {
                home = initialContext.lookup(ejbAnnotation.name());
                // home = ejbAnnotation.beanInterface().cast(home;
                home = cast(home, ejbAnnotation.beanInterface());
                field.setAccessible(true);
                field.set(this, home);
            } catch (final Exception ex) {
                // TODO - MNour : Needs better exception handling
                ex.printStackTrace();
            }
        }
    }
}
 
源代码7 项目: tomee   文件: TestClient.java
protected final void processSetterInjections() {
    Object home = null;
    ClassFinder finder = null;
    List<Method> methodList = null;

    finder = new ClassFinder(getClassPath());
    methodList = finder.findAnnotatedMethods(EJB.class);
    for (final Iterator methods = methodList.iterator(); methods.hasNext(); ) {
        final Method method = (Method) methods.next();
        final EJB ejbAnnotation = method.getAnnotation(EJB.class);
        if ((ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) {
            try {
                home = initialContext.lookup(ejbAnnotation.name());
                // home = ejbAnnotation.beanInterface().cast(home;
                home = cast(home, ejbAnnotation.beanInterface());
                method.setAccessible(true);
                method.invoke(this, new Object[]{home});
            } catch (final Exception ex) {
                // TODO - MNour : Needs better exception handling
                ex.printStackTrace();
            }
        }
    }
}
 
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
	if (this.testBean4 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean4 = testBean4;
}
 
@EJB
public void setTestBean6(INestedTestBean testBean6) {
	if (this.testBean6 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean6 = testBean6;
}
 
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
	if (this.testBean4 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean4 = testBean4;
}
 
@EJB
public void setTestBean6(INestedTestBean testBean6) {
	if (this.testBean6 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean6 = testBean6;
}
 
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
	if (this.testBean4 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean4 = testBean4;
}
 
@EJB
public void setTestBean6(INestedTestBean testBean6) {
	if (this.testBean6 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean6 = testBean6;
}
 
源代码14 项目: development   文件: ReferenceTest.java
@Test
public void testCreateForEJBField1() throws Exception {
    class Bean {
        @EJB
        private Object foo;
    }
    Field field = Bean.class.getDeclaredField("foo");
    EJB ejb = field.getAnnotation(EJB.class);
    Reference r = Reference.createFor(ejb, field);
    assertEquals(Object.class, r.getInterfaceOrClass());
    assertEquals(Bean.class.getName() + "/foo", r.getName());
}
 
源代码15 项目: development   文件: ReferenceTest.java
@Test
public void testCreateForEJBField2() throws Exception {
    class Bean {
        @EJB(name = "other", beanInterface = Runnable.class)
        private Object foo;
    }
    Field field = Bean.class.getDeclaredField("foo");
    EJB ejb = field.getAnnotation(EJB.class);
    Reference r = Reference.createFor(ejb, field);
    assertEquals(Runnable.class, r.getInterfaceOrClass());
    assertEquals("other", r.getName());
}
 
源代码16 项目: development   文件: Reference.java
public static Reference createFor(EJB ejb, Field field) {
    final Class<?> type;
    if (!Object.class.equals(ejb.beanInterface())) {
        type = ejb.beanInterface();
    } else {
        type = field.getType();
    }
    final String name;
    if (ejb.name().length() > 0) {
        name = ejb.name();
    } else {
        name = field.getDeclaringClass().getName() + "/" + field.getName();
    }
    return new Reference(type, name, field);
}
 
源代码17 项目: development   文件: SubscriptionServiceMockBase.java
static void mockEJBs(Object instance) throws Exception {
    for (Field f : instance.getClass().getDeclaredFields()) {
        EJB ejb = f.getAnnotation(EJB.class);
        if (ejb != null) {
            Class<?> t = f.getType();
            f.setAccessible(true);
            f.set(instance, mock(t));
        }
    }
}
 
源代码18 项目: development   文件: ReferenceTest.java
@Test
public void testCreateForEJBField1() throws Exception {
    class Bean {
        @EJB
        private Object foo;
    }
    Field field = Bean.class.getDeclaredField("foo");
    EJB ejb = field.getAnnotation(EJB.class);
    Reference r = Reference.createFor(ejb, field);
    assertEquals(Object.class, r.getInterfaceOrClass());
    assertEquals(Bean.class.getName() + "/foo", r.getName());
}
 
源代码19 项目: development   文件: ReferenceTest.java
@Test
public void testCreateForEJBField2() throws Exception {
    class Bean {
        @EJB(name = "other", beanInterface = Runnable.class)
        private Object foo;
    }
    Field field = Bean.class.getDeclaredField("foo");
    EJB ejb = field.getAnnotation(EJB.class);
    Reference r = Reference.createFor(ejb, field);
    assertEquals(Runnable.class, r.getInterfaceOrClass());
    assertEquals("other", r.getName());
}
 
源代码20 项目: BeanTest   文件: InjectionHelper.java
private static Set<Class<? extends Annotation>> createJavaEEAnnotationSet() {
    Set<Class<? extends Annotation>> javaEEAnnotations = new HashSet<Class<? extends Annotation>>();
    javaEEAnnotations.add(Resource.class);
    javaEEAnnotations.add(EJB.class);
    javaEEAnnotations.add(PersistenceContext.class);
    return Collections.unmodifiableSet(javaEEAnnotations);
}
 
@Override
@EJB
public void setTestBean2(TestBean testBean2) {
	super.setTestBean2(testBean2);
}
 
@Override
@EJB
public void setTestBean2(TestBean testBean2) {
	super.setTestBean2(testBean2);
}
 
@Override
@EJB
public void setTestBean2(TestBean testBean2) {
	super.setTestBean2(testBean2);
}
 
源代码24 项目: development   文件: SubscriptionServiceMockBase.java
private static boolean isMockable(Field f) {
    return ((f.getAnnotation(Inject.class) != null)
            || (f.getAnnotation(Resource.class) != null) || f
                .getAnnotation(EJB.class) != null);

}
 
源代码25 项目: development   文件: PaymentTypeConverter.java
@EJB
public void setAccountingService(AccountService accountingService) {
    this.accountingService = accountingService;
}
 
源代码26 项目: development   文件: MySubscriptionsCtrl.java
@EJB
public void setSubscriptionsService(
        SubscriptionsService subscriptionsService) {
    this.subscriptionsService = subscriptionsService;
}
 
源代码27 项目: development   文件: MySubscriptionsCtrl.java
@EJB
public void setSubscriptionService(
        SubscriptionService subscriptionService) {
    this.subscriptionService = subscriptionService;
}
 
源代码28 项目: development   文件: OperationRecordCtrl.java
@EJB
public void setOperationRecordService(final OperationRecordService opr) {
    this.operationRecordService = opr;
}
 
源代码29 项目: development   文件: CreateUserCtrl.java
@EJB
public void setUserService(UserService userService) {
    this.userService = userService;
}
 
源代码30 项目: development   文件: CreateUserCtrl.java
@EJB
public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
}