當前位置: 首頁>>代碼示例>>Java>>正文


Java EJB類代碼示例

本文整理匯總了Java中javax.ejb.EJB的典型用法代碼示例。如果您正苦於以下問題:Java EJB類的具體用法?Java EJB怎麽用?Java EJB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EJB類屬於javax.ejb包,在下文中一共展示了EJB類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerEjbInjectionPoint

import javax.ejb.EJB; //導入依賴的package包/類
@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);
}
 
開發者ID:dajudge,項目名稱:testee.fi,代碼行數:20,代碼來源:EjbInjectionServicesImpl.java

示例2: invokeInterceptor

import javax.ejb.EJB; //導入依賴的package包/類
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;
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:24,代碼來源:DeployedSessionBean.java

示例3: EjbRefElement

import javax.ejb.EJB; //導入依賴的package包/類
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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:CommonAnnotationBeanPostProcessor.java

示例4: EjbRefElement

import javax.ejb.EJB; //導入依賴的package包/類
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();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:CommonAnnotationBeanPostProcessor.java

示例5: cacheInjectFields

import javax.ejb.EJB; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:levants,項目名稱:lightmare,代碼行數:30,代碼來源:BeanDeployer.java

示例6: retriveConnection

import javax.ejb.EJB; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:levants,項目名稱:lightmare,代碼行數:28,代碼來源:BeanDeployer.java

示例7: testCreateForEJBField1

import javax.ejb.EJB; //導入依賴的package包/類
@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());
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:13,代碼來源:ReferenceTest.java

示例8: testCreateForEJBField2

import javax.ejb.EJB; //導入依賴的package包/類
@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());
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:13,代碼來源:ReferenceTest.java

示例9: createFor

import javax.ejb.EJB; //導入依賴的package包/類
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);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,代碼來源:Reference.java

示例10: mockEJBs

import javax.ejb.EJB; //導入依賴的package包/類
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));
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:11,代碼來源:SubscriptionServiceMockBase.java

示例11: setTestBean4

import javax.ejb.EJB; //導入依賴的package包/類
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
	if (this.testBean4 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean4 = testBean4;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:8,代碼來源:CommonAnnotationBeanPostProcessorTests.java

示例12: setTestBean6

import javax.ejb.EJB; //導入依賴的package包/類
@EJB
public void setTestBean6(INestedTestBean testBean6) {
	if (this.testBean6 != null) {
		throw new IllegalStateException("Already called");
	}
	this.testBean6 = testBean6;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:8,代碼來源:CommonAnnotationBeanPostProcessorTests.java

示例13: createJavaEEAnnotationSet

import javax.ejb.EJB; //導入依賴的package包/類
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);
}
 
開發者ID:NovaTecConsulting,項目名稱:BeanTest,代碼行數:8,代碼來源:InjectionHelper.java

示例14: resolveComponentName

import javax.ejb.EJB; //導入依賴的package包/類
/**
 * フィールドからコンポーネントの名前を解決します.
 *
 * @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());
}
 
開發者ID:e-taka,項目名稱:junit-seasar2,代碼行數:21,代碼來源:FieldsBindingStatement.java

示例15: getLookupName

import javax.ejb.EJB; //導入依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:13,代碼來源:AnnotationDeployer.java


注:本文中的javax.ejb.EJB類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。