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


Java Application.getClasses方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.Application.getClasses方法的典型用法代碼示例。如果您正苦於以下問題:Java Application.getClasses方法的具體用法?Java Application.getClasses怎麽用?Java Application.getClasses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.Application的用法示例。


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

示例1: SwaggerHandler

import javax.ws.rs.core.Application; //導入方法依賴的package包/類
public SwaggerHandler(
    final Class<? extends Application> applicationClass) {

    final ApplicationPath annotation = applicationClass.getAnnotation(ApplicationPath.class);
    if (annotation != null) {
        baseUri = URI.create(annotation.value()).normalize();
    } else {
        baseUri = URI.create("/");
    }

    Application application;
    try {
        application = applicationClass.newInstance();
    } catch (InstantiationException
        | IllegalAccessException e) {
        throw new ExceptionInInitializerError(e);
    }

    swagger = new ClonableSwagger();
    final Reader swaggerReader = new Reader(swagger);
    final Set<Class<?>> resourceClasses = application.getClasses();
    if (resourceClasses.isEmpty()) {
        final String packageName = applicationClass.getPackage().getName();
        final Reflections reflections = new Reflections(packageName);
        reflections.getTypesAnnotatedWith(Api.class).forEach(swaggerReader::read);
        reflections.getTypesAnnotatedWith(SwaggerDefinition.class).forEach(swaggerReader::read);
    } else {
        swaggerReader.read(applicationClass);
        resourceClasses.forEach(swaggerReader::read);
    }

}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:33,代碼來源:SwaggerHandler.java

示例2: index

import javax.ws.rs.core.Application; //導入方法依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
public ResourceIndex index(@Context Application application,
		@Context HttpServletRequest request) throws Exception {
	// String basePath = request.getRequestURL().toString();
	// String basePath = getBasePath(request);
	JsonObject rootNode = new JsonObject();
	JsonArray classesNode = new JsonArray();
	rootNode.addProperty(JS_TITLE_FIELD, Settings.getString(SettingCodes.API_TITLE, Bundle.SETTINGS, DefaultSettings.API_TITLE));
	rootNode.addProperty(JS_INSTANCE_FIELD, WebUtil.getInstanceName());
	rootNode.addProperty(JS_VERSION_FIELD, Settings.getString(SettingCodes.API_VERSION, Bundle.SETTINGS, DefaultSettings.API_VERSION));
	rootNode.addProperty(JS_JVM_FIELD, System.getProperty("java.version"));
	rootNode.addProperty(JS_REALM_FIELD, Settings.getString(SettingCodes.API_REALM, Bundle.SETTINGS, DefaultSettings.API_REALM));
	AnnouncementVO announcement = WebUtil.getServiceLocator().getToolsService().getAnnouncement();
	if (announcement != null) {
		rootNode.addProperty(JS_ANNOUNCEMENT_FIELD, announcement.getMessage());
	}
	rootNode.add(JS_CLASSES_FIELD, classesNode);
	ArrayList<Class> classes = new ArrayList<Class>(application.getClasses());
	Collections.sort(classes, RESOURCE_CLASS_COMPARATOR);
	Iterator<Class> classesIt = classes.iterator();
	while (classesIt.hasNext()) {
		Class resourceClass = classesIt.next();
		if (isAnnotatedResourceClass(resourceClass)) {
			classesNode.add(getResourceIndexNode(resourceClass, request)); // basePath));
		}
	}
	// return Response.ok().entity(rootNode).build();
	return new ResourceIndex(rootNode);
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:31,代碼來源:IndexResource.java


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