当前位置: 首页>>代码示例>>Java>>正文


Java Service类代码示例

本文整理汇总了Java中org.jvnet.hk2.annotations.Service的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Service类属于org.jvnet.hk2.annotations包,在下文中一共展示了Service类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processClass

import org.jvnet.hk2.annotations.Service; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> T processClass(Class<?> classType) throws InstantiationException, IllegalAccessException
{
    if(!discoveredClasses.contains(classType))
    {
        discoveredClasses.add(classType);

        if (classType.isAnnotationPresent(Singleton.class) || classType.isAnnotationPresent(Service.class))
        {
            // Singletons are a special case as we allow interception

            // Do we have an intercept?
            Object o = config.getAsInstance(classType.getName(), Object.class);
            if (o == null)
            {
                o = getServiceLocator().create(classType);
            }

            discoveredServices.add(o);

            ServiceLocatorUtilities.addOneConstant(getServiceLocator(), o);

            return (T) o;
        }

        final Class<?>[] childClasses = classType.getClasses();
        for(Class childClass : childClasses)
        {
            processClass(childClass);
        }
    }
    return null;
}
 
开发者ID:orbit,项目名称:orbit-hk2,代码行数:34,代码来源:Container.java

示例2: init

import org.jvnet.hk2.annotations.Service; //导入依赖的package包/类
/**
 * Scan the requested packages on the classpath for HK2 'Service' and 'Contract' annotated classes.
 * Load the metadata for those classes into the HK2 Service Locator.
 * 
 * This implementation should support all Annotations that are supported by HK2 - however - if you are using 
 * HK2 older than 2.3.0 - note that it is impacted by this bug:  https://java.net/jira/browse/HK2-187
 * 
 * For an implementation that is not impacted by that bug, see {@link HK2RuntimeInitializerCustom}
 * 
 * @see org.glassfish.hk2.api.ServiceLocatorFactory#create(String)
 * @see ServiceLocatorUtilities#createAndPopulateServiceLocator(String)
 * 
 * @param serviceLocatorName - The name of the ServiceLocator to find (or create if it doesn't yet exist)  
 * @param readInhabitantFiles - Read and process inhabitant files before doing the classpath scan.  Annotated items
 * found during the scan will override items found in the inhabitant files, if they collide.  
 * @param packageNames -- The set of package names to scan recursively - for example - new String[]{"org.foo", "com.bar"}
 * If not provided, the entire classpath is scanned 
 * @return - The created ServiceLocator (but in practice, you can lookup this ServiceLocator by doing:
 * <pre>
 * {@code
 * ServiceLocatorFactory.getInstance().create("SomeName");
 * }
 * </pre>
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static ServiceLocator init(String serviceLocatorName, boolean readInhabitantFiles, String ... packageNames) throws IOException, ClassNotFoundException 
{
	AnnotatedClasses ac = new AnnotatedClasses();
	
	@SuppressWarnings("unchecked")
	AnnotationDetector cf = new AnnotationDetector(new AnnotationReporter(ac, new Class[]{Service.class}));
	if (packageNames == null || packageNames.length == 0)
	{
		cf.detect();
	}
	else
	{
		cf.detect(packageNames);
	}
	
	ServiceLocator locator = null;
	
	if (readInhabitantFiles)
	{
		locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(serviceLocatorName);
	}
	else
	{
		ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
		locator = factory.create(serviceLocatorName);
	}

	for (ActiveDescriptor<?> ad : ServiceLocatorUtilities.addClasses(locator, ac.getAnnotatedClasses()))
	{
		log.debug("Added " + ad.toString());
	}
	
	return locator;
}
 
开发者ID:darmbrust,项目名称:HK2Utilities,代码行数:61,代码来源:HK2RuntimeInitializer.java

示例3: setup

import org.jvnet.hk2.annotations.Service; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setup(final Application application) {

    final Set<ClassInfo> classInfoSet = Sets.newLinkedHashSet();
    subscribeSystemEvent(ClassFoundEvent.class, event -> event.accept(info -> {
        if (info.containsAnnotations(Service.class)) {
            classInfoSet.add(info);
            return true;
        }
        return false;
    }));

    final Feature localResource = new Feature() {

        @Inject
        private ServiceLocator locator;

        @Override
        public boolean configure(FeatureContext context) {
            for (ClassInfo classInfo : classInfoSet) {
                ServiceLocatorUtilities.addClasses(locator, classInfo.toClass());
            }
            classInfoSet.clear();
            return true;
        }
    };

    application.register(localResource);
}
 
开发者ID:icode,项目名称:ameba,代码行数:33,代码来源:LocalResourceAddon.java

示例4: isService

import org.jvnet.hk2.annotations.Service; //导入依赖的package包/类
public boolean isService()
{
	return hasAnnotation(Service.class.getName());
}
 
开发者ID:darmbrust,项目名称:HK2Utilities,代码行数:5,代码来源:ClassInfo.java


注:本文中的org.jvnet.hk2.annotations.Service类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。