javax.ejb.EJB Java Examples
The following examples show how to use
javax.ejb.EJB.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestClient.java From tomee with Apache License 2.0 | 6 votes |
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(); } } } }
Example #2
Source File: TestClient.java From tomee with Apache License 2.0 | 6 votes |
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(); } } } }
Example #3
Source File: CommonAnnotationBeanPostProcessor.java From java-technology-stack with MIT License | 6 votes |
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(); }
Example #4
Source File: CommonAnnotationBeanPostProcessor.java From spring-analysis-note with MIT License | 6 votes |
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(); }
Example #5
Source File: CommonAnnotationBeanPostProcessor.java From lams with GNU General Public License v2.0 | 6 votes |
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(); }
Example #6
Source File: CommonAnnotationBeanPostProcessor.java From spring4-understanding with Apache License 2.0 | 6 votes |
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(); }
Example #7
Source File: DeployedSessionBean.java From development with Apache License 2.0 | 6 votes |
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; } } }
Example #8
Source File: CommonAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@EJB(beanName="testBean3", beanInterface=ITestBean.class) private void setTestBean4(ITestBean testBean4) { if (this.testBean4 != null) { throw new IllegalStateException("Already called"); } this.testBean4 = testBean4; }
Example #9
Source File: ReferenceTest.java From development with Apache License 2.0 | 5 votes |
@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()); }
Example #10
Source File: ReferenceTest.java From development with Apache License 2.0 | 5 votes |
@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()); }
Example #11
Source File: SubscriptionServiceMockBase.java From development with Apache License 2.0 | 5 votes |
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)); } } }
Example #12
Source File: Reference.java From development with Apache License 2.0 | 5 votes |
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); }
Example #13
Source File: ReferenceTest.java From development with Apache License 2.0 | 5 votes |
@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()); }
Example #14
Source File: ReferenceTest.java From development with Apache License 2.0 | 5 votes |
@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()); }
Example #15
Source File: CommonAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@EJB public void setTestBean6(INestedTestBean testBean6) { if (this.testBean6 != null) { throw new IllegalStateException("Already called"); } this.testBean6 = testBean6; }
Example #16
Source File: CommonAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@EJB public void setTestBean6(INestedTestBean testBean6) { if (this.testBean6 != null) { throw new IllegalStateException("Already called"); } this.testBean6 = testBean6; }
Example #17
Source File: CommonAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 5 votes |
@EJB(beanName="testBean3", beanInterface=ITestBean.class) private void setTestBean4(ITestBean testBean4) { if (this.testBean4 != null) { throw new IllegalStateException("Already called"); } this.testBean4 = testBean4; }
Example #18
Source File: InjectionHelper.java From BeanTest with Apache License 2.0 | 5 votes |
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); }
Example #19
Source File: CommonAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@EJB public void setTestBean6(INestedTestBean testBean6) { if (this.testBean6 != null) { throw new IllegalStateException("Already called"); } this.testBean6 = testBean6; }
Example #20
Source File: CommonAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 5 votes |
@EJB(beanName="testBean3", beanInterface=ITestBean.class) private void setTestBean4(ITestBean testBean4) { if (this.testBean4 != null) { throw new IllegalStateException("Already called"); } this.testBean4 = testBean4; }
Example #21
Source File: SubscriptionWizardConversation.java From development with Apache License 2.0 | 4 votes |
@EJB public void setUserGroupService(UserGroupService userGroupService) { this.userGroupService = userGroupService; }
Example #22
Source File: BillingContactBean.java From development with Apache License 2.0 | 4 votes |
@EJB public void setAccountService(AccountService accountService) { this.accountService = accountService; }
Example #23
Source File: UserImportBean.java From development with Apache License 2.0 | 4 votes |
@EJB public void setConfigurationService(ConfigurationService configurationService) { this.configurationService = configurationService; }
Example #24
Source File: UserImportBean.java From development with Apache License 2.0 | 4 votes |
@EJB public void setIdentityService(IdentityService identityService) { this.identityService = identityService; }
Example #25
Source File: PaymentInfoBean.java From development with Apache License 2.0 | 4 votes |
@EJB public void setPaymentService(PaymentService paymentService) { this.paymentService = paymentService; }
Example #26
Source File: SubscriptionWizardConversation.java From development with Apache License 2.0 | 4 votes |
@EJB public void setSubscriptionService( SubscriptionService subscriptionService) { this.subscriptionService = subscriptionService; }
Example #27
Source File: UpdateUserCtrl.java From development with Apache License 2.0 | 4 votes |
@EJB public void setUserService(UserService userService) { this.userService = userService; }
Example #28
Source File: SubscriptionWizardConversation.java From development with Apache License 2.0 | 4 votes |
@EJB public void setAccountingService(AccountService accountingService) { this.accountingService = accountingService; }
Example #29
Source File: BillingContactEditBean.java From development with Apache License 2.0 | 4 votes |
@EJB public void setAccountService(AccountService accountService) { this.accountService = accountService; }
Example #30
Source File: SubscriptionWizardConversation.java From development with Apache License 2.0 | 4 votes |
@EJB public void setSubscriptionServiceInternal( SubscriptionServiceInternal subscriptionServiceInternal) { this.subscriptionServiceInternal = subscriptionServiceInternal; }