Java 类javax.ejb.EJB 实例源码

项目:testee.fi    文件:EjbInjectionServicesImpl.java   
@Override
@SuppressWarnings("unchecked")
public ResourceReferenceFactory<Object> registerEjbInjectionPoint(
        final InjectionPoint injectionPoint
) {
    if (injectionPoint.getAnnotated().getAnnotation(EJB.class) == null) {
        throw new IllegalStateException("Unhandled injection point: " + injectionPoint);
    }
    final Type type = injectionPoint.getType();
    final ResourceReferenceFactory<Object> alternative = alternatives.alternativeFor(type);
    if (alternative != null) {
        return alternative;
    }
    final EjbDescriptor<Object> descriptor = (EjbDescriptor<Object>) lookup.lookup(type);
    if (descriptor == null) {
        throw new IllegalStateException("No EJB descriptor found for EJB injection point: " + injectionPoint);
    }
    return factory.createInstance(descriptor);
}
项目:oscm    文件: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;
        }
    }
}
项目:lams    文件:CommonAnnotationBeanPostProcessor.java   
public EjbRefElement(Member member, PropertyDescriptor pd) {
    super(member, pd);
    AnnotatedElement ae = (AnnotatedElement) member;
    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.equals(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();
}
项目:spring4-understanding    文件: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();
}
项目:my-spring-cache-redis    文件:CommonAnnotationBeanPostProcessor.java   
public EjbRefElement(Member member, PropertyDescriptor pd) {
    super(member, pd);
    AnnotatedElement ae = (AnnotatedElement) member;
    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.equals(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();
}
项目:spring    文件: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();
}
项目: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;
        }
    }
}
项目:class-guard    文件:CommonAnnotationBeanPostProcessor.java   
public EjbRefElement(Member member, PropertyDescriptor pd) {
    super(member, pd);
    AnnotatedElement ae = (AnnotatedElement) member;
    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.equals(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();
}
项目:lightmare    文件:BeanDeployer.java   
/**
 * Caches {@link EJB} annotated fields
 *
 * @param beanClass
 */
private void cacheInjectFields(Field field) {

    EJB ejb = field.getAnnotation(EJB.class);
    Class<?> interfaceClass = ejb.beanInterface();
    if (interfaceClass == null || interfaceClass.equals(Object.class)) {
        interfaceClass = field.getType();
    }

    String name = ejb.beanName();
    if (name == null || name.isEmpty()) {
        name = BeanUtils.nameFromInterface(interfaceClass);
    }

    String description = ejb.description();
    String mappedName = ejb.mappedName();
    Class<?>[] interfaceClasses = { interfaceClass };
    InjectionData injectionData = new InjectionData();
    injectionData.setField(field);
    injectionData.setInterfaceClasses(interfaceClasses);
    injectionData.setName(name);
    injectionData.setDescription(description);
    injectionData.setMappedName(mappedName);
    metaData.addInject(injectionData);
}
项目:lightmare    文件:BeanDeployer.java   
/**
 * Retrieves and caches {@link Field}s with injection
 *
 * @param field
 * @throws IOException
 */
private void retriveConnection(Field field) throws IOException {

    PersistenceContext context = field.getAnnotation(PersistenceContext.class);
    Resource resource = field.getAnnotation(Resource.class);
    PersistenceUnit unit = field.getAnnotation(PersistenceUnit.class);
    EJB ejbAnnot = field.getAnnotation(EJB.class);
    if (ObjectUtils.notNull(context)) {
        identifyConnections(context, field);
        addAccessibleField(field);
    } else if (ObjectUtils.notNull(resource)) {
        metaData.setTransactionField(field);
        addAccessibleField(field);
    } else if (ObjectUtils.notNull(unit)) {
        addUnitField(field);
        addAccessibleField(field);
    } else if (ObjectUtils.notNull(ejbAnnot)) {
        // caches EJB annotated fields
        cacheInjectFields(field);
        addAccessibleField(field);
    }
}
项目:oscm    文件: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());
}
项目:oscm    文件: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());
}
项目:oscm    文件: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);
}
项目:oscm    文件: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));
        }
    }
}
项目:oscm    文件: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());
}
项目:oscm    文件: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());
}
项目:spring4-understanding    文件:CommonAnnotationBeanPostProcessorTests.java   
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
    if (this.testBean4 != null) {
        throw new IllegalStateException("Already called");
    }
    this.testBean4 = testBean4;
}
项目:spring4-understanding    文件:CommonAnnotationBeanPostProcessorTests.java   
@EJB
public void setTestBean6(INestedTestBean testBean6) {
    if (this.testBean6 != null) {
        throw new IllegalStateException("Already called");
    }
    this.testBean6 = testBean6;
}
项目: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());
}
项目: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());
}
项目: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);
}
项目: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));
        }
    }
}
项目: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());
}
项目: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());
}
项目: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);
}
项目:junit-seasar2    文件:FieldsBindingStatement.java   
/**
 * フィールドからコンポーネントの名前を解決します.
 *
 * @param filed
 *            フィールド
 * @return コンポーネント名
 */
private String resolveComponentName(final Field filed) {
    if (_testContext.isEjb3Enabled()) {
        final EJB ejb = filed.getAnnotation(EJB.class);
        if (ejb != null) {
            if (!StringUtil.isEmpty(ejb.beanName())) {
                return ejb.beanName();
            } else if (!StringUtil.isEmpty(ejb.name())) {
                return ejb.name();
            }
        }
    }
    return normalizeName(filed.getName());
}
项目:tomee    文件:AnnotationDeployer.java   
private static String getLookupName(final EJB ejb) {
    String value = "";
    final Method lookupMethod = getLookupMethod(EJB.class);
    if (lookupMethod != null) {
        try {
            value = (String) lookupMethod.invoke(ejb, null);
        } catch (final Exception e) {
            // ignore
        }
    }
    return value;
}
项目:oscm    文件:SubscriptionServiceMockBase.java   
private static boolean isMockable(Field f) {
    return ((f.getAnnotation(Inject.class) != null)
            || (f.getAnnotation(Resource.class) != null) || f
                .getAnnotation(EJB.class) != null);

}
项目:oscm    文件:PaymentTypeConverter.java   
@EJB
public void setAccountingService(AccountService accountingService) {
    this.accountingService = accountingService;
}
项目:oscm    文件:MySubscriptionsCtrl.java   
@EJB
public void setSubscriptionsService(
        SubscriptionsService subscriptionsService) {
    this.subscriptionsService = subscriptionsService;
}
项目:oscm    文件:MySubscriptionsCtrl.java   
@EJB
public void setSubscriptionService(
        SubscriptionService subscriptionService) {
    this.subscriptionService = subscriptionService;
}
项目:oscm    文件:OperationRecordCtrl.java   
@EJB
public void setOperationRecordService(final OperationRecordService opr) {
    this.operationRecordService = opr;
}
项目:oscm    文件:CreateUserCtrl.java   
@EJB
public void setUserService(UserService userService) {
    this.userService = userService;
}
项目:oscm    文件:CreateUserCtrl.java   
@EJB
public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
}
项目:oscm    文件:UserGroupListCtrl.java   
@EJB
public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
}
项目:oscm    文件:AddGroupCtrl.java   
@EJB
public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
}
项目:oscm    文件:UserGroupBaseCtrl.java   
@EJB
public void setSearchServiceInternal(
        SearchServiceInternal searchServiceInternal) {
    this.searchServiceInternal = searchServiceInternal;
}
项目:oscm    文件:ManageGroupCtrl.java   
@EJB
public void setUserGroupService(UserGroupService userGroupService) {
    this.userGroupService = userGroupService;
}
项目:oscm    文件:ManageGroupCtrl.java   
@EJB
public void setIdService(IdentityService idService) {
    this.idService = idService;
}
项目:oscm    文件:SelectGroupCtrl.java   
@EJB
public void setService(UserGroupService service) {
    this.service = service;
}