org.springframework.web.context.WebApplicationContext.getBeanNamesForType()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(16.4k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.springframework.web.context.WebApplicationContext.getBeanNamesForType()方法的一些代码示例,展示了WebApplicationContext.getBeanNamesForType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebApplicationContext.getBeanNamesForType()方法的具体详情如下:
包路径:org.springframework.web.context.WebApplicationContext
类名称:WebApplicationContext
方法名:getBeanNamesForType

WebApplicationContext.getBeanNamesForType介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) {
  String wacId = wac.getId();
  Map<Class<?>, String> beanNamesByType = cache.get(wacId);
  if (beanNamesByType == null) {
    beanNamesByType = new ConcurrentHashMap<>();
    cache.put(wacId, beanNamesByType);
  }
  if (!beanNamesByType.containsKey(endpointClass)) {
    String[] names = wac.getBeanNamesForType(endpointClass);
    if (names.length == 1) {
      beanNamesByType.put(endpointClass, names[0]);
    }
    else {
      beanNamesByType.put(endpointClass, NO_VALUE);
      if (names.length > 1) {
        throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" +
            endpointClass.getName() + "]: bean names " + Arrays.asList(names));
      }
    }
  }
  String beanName = beanNamesByType.get(endpointClass);
  return (NO_VALUE.equals(beanName) ? null : beanName);
}

代码示例来源:origin: org.springframework/spring-websocket

@Nullable
private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) {
  String wacId = wac.getId();
  Map<Class<?>, String> beanNamesByType = cache.get(wacId);
  if (beanNamesByType == null) {
    beanNamesByType = new ConcurrentHashMap<>();
    cache.put(wacId, beanNamesByType);
  }
  if (!beanNamesByType.containsKey(endpointClass)) {
    String[] names = wac.getBeanNamesForType(endpointClass);
    if (names.length == 1) {
      beanNamesByType.put(endpointClass, names[0]);
    }
    else {
      beanNamesByType.put(endpointClass, NO_VALUE);
      if (names.length > 1) {
        throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" +
            endpointClass.getName() + "]: bean names " + Arrays.asList(names));
      }
    }
  }
  String beanName = beanNamesByType.get(endpointClass);
  return (NO_VALUE.equals(beanName) ? null : beanName);
}

代码示例来源:origin: entando/entando-core

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
  _logger.debug("Request: {}", request.getRequestURI());
  try {
    ServletContext svCtx = request.getSession().getServletContext();
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(svCtx);
    String[] resourceProviderNames = wac.getBeanNamesForType(IProtectedResourceProvider.class);
    for (int i = 0; i < resourceProviderNames.length; i++) {
      String resourceProviderName = resourceProviderNames[i];
      IProtectedResourceProvider provider = (IProtectedResourceProvider) wac.getBean(resourceProviderName);
      boolean responseCommitted = provider.provideProtectedResource(request, response);
      if (responseCommitted) {
        return;
      }
    }
  } catch (Throwable t) {
    _logger.error("Error providing protected resource", t);
    throw new ServletException("Error providing protected resource", t);
  }
}

代码示例来源:origin: micromata/projectforge

public static <T> T getBean(final Class<T> clazz)
 {
  final String[] beanNamesForType = getWebApplicationContext().getBeanNamesForType(clazz);
  return getWebApplicationContext().getBean(beanNamesForType[0], clazz);
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Nullable
private String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) {
  String wacId = wac.getId();
  Map<Class<?>, String> beanNamesByType = cache.get(wacId);
  if (beanNamesByType == null) {
    beanNamesByType = new ConcurrentHashMap<>();
    cache.put(wacId, beanNamesByType);
  }
  if (!beanNamesByType.containsKey(endpointClass)) {
    String[] names = wac.getBeanNamesForType(endpointClass);
    if (names.length == 1) {
      beanNamesByType.put(endpointClass, names[0]);
    }
    else {
      beanNamesByType.put(endpointClass, NO_VALUE);
      if (names.length > 1) {
        throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" +
            endpointClass.getName() + "]: bean names " + Arrays.asList(names));
      }
    }
  }
  String beanName = beanNamesByType.get(endpointClass);
  return (NO_VALUE.equals(beanName) ? null : beanName);
}

代码示例来源:origin: Putnami/putnami-web-toolkit

@Override
protected void initFilterBean() throws ServletException {
  findWebApplicationContext();
  for (String beanName : webApplicationContext.getBeanNamesForType(Filter.class)) {
    scanBean(webApplicationContext.getBean(beanName), beanName);
  }
}

代码示例来源:origin: entando/entando-core

private static void executeSystemRefresh(WebApplicationContext wac) throws Throwable {
  RefreshableBean configManager = (RefreshableBean) wac.getBean(SystemConstants.BASE_CONFIG_MANAGER);
  configManager.refresh();
  String[] defNames = wac.getBeanNamesForType(RefreshableBean.class);
  for (int i=0; i<defNames.length; i++) {
    Object bean = null;
    try {
      bean = wac.getBean(defNames[i]);
    } catch (Throwable t) {
      logger.error("error in executeSystemRefresh", t);
      bean = null;
    }
    if (bean != null) {
      ((RefreshableBean) bean).refresh();
    }
  }
}

代码示例来源:origin: org.entando.entando/entando-core-engine

private List<HookPointElementContainer> extractElements(HttpServletRequest request) {
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  String[] beanNames =  wac.getBeanNamesForType(HookPointElementContainer.class);
  List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>();
  for (int i=0; i<beanNames.length; i++) {
    HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]);
    if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) {
      containers.add(container);
    }
  }
  BeanComparator comparator = new BeanComparator("priority");
  Collections.sort(containers, comparator);
  return containers;
}

代码示例来源:origin: entando/entando-core

private List<HookPointElementContainer> extractElements(HttpServletRequest request) {
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  String[] beanNames =  wac.getBeanNamesForType(HookPointElementContainer.class);
  List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>();
  for (int i=0; i<beanNames.length; i++) {
    HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]);
    if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) {
      containers.add(container);
    }
  }
  BeanComparator comparator = new BeanComparator("priority");
  Collections.sort(containers, comparator);
  return containers;
}

代码示例来源:origin: org.entando.entando/entando-admin-console

private List<HookPointElementContainer> extractElements(HttpServletRequest request) {
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  String[] beanNames =  wac.getBeanNamesForType(HookPointElementContainer.class);
  List<HookPointElementContainer> containers = new ArrayList<HookPointElementContainer>();
  for (int i=0; i<beanNames.length; i++) {
    HookPointElementContainer container = (HookPointElementContainer) wac.getBean(beanNames[i]);
    if (null != container && null != container.getHookPointKey() && container.getHookPointKey().equals(this.getKey())) {
      containers.add(container);
    }
  }
  BeanComparator comparator = new BeanComparator("priority");
  Collections.sort(containers, comparator);
  return containers;
}

代码示例来源:origin: org.entando.entando/entando-core-engine

protected List<IFrameDecoratorContainer> extractDecorators() throws ApsSystemException {
  HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  List<IFrameDecoratorContainer> containters = new ArrayList<IFrameDecoratorContainer>();
  try {
    String[] beanNames = wac.getBeanNamesForType(IFrameDecoratorContainer.class);
    for (int i = 0; i < beanNames.length; i++) {
      IFrameDecoratorContainer container = (IFrameDecoratorContainer) wac.getBean(beanNames[i]);
      containters.add(container);
    }
    BeanComparator comparator = new BeanComparator("order");
    Collections.sort(containters, comparator);
  } catch (Throwable t) {
    ApsSystemUtils.logThrowable(t, this, "extractDecorators", "Error extracting widget decorators");
    throw new ApsSystemException("Error extracting widget decorators", t);
  }
  return containters;
}

代码示例来源:origin: org.entando.entando/entando-core-engine

private static void executeSystemRefresh(WebApplicationContext wac) throws Throwable {
  RefreshableBean configManager = (RefreshableBean) wac.getBean(SystemConstants.BASE_CONFIG_MANAGER);
  configManager.refresh();
  String[] defNames = wac.getBeanNamesForType(RefreshableBean.class);
  for (int i=0; i<defNames.length; i++) {
    Object bean = null;
    try {
      bean = wac.getBean(defNames[i]);
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, ApsWebApplicationUtils.class, "executeSystemRefresh");
      bean = null;
    }
    if (bean != null) {
      ((RefreshableBean) bean).refresh();
    }
  }
}

代码示例来源:origin: org.entando.entando/entando-core-engine

@Override
public int doStartTag() throws JspException {
  HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>();
  ValueStack stack = this.getStack();
  try {
    String[] beanNames =  wac.getBeanNamesForType(PluginSubMenuContainer.class);
    for (int i=0; i<beanNames.length; i++) {
      PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]);
      containters.add(container);
    }
    if (containters.size()>0) {
      stack.getContext().put(this.getObjectName(), containters);
      stack.setValue("#attr['" + this.getObjectName() + "']", containters, false);
      return EVAL_BODY_INCLUDE;
    }
  } catch (Throwable t) {
    throw new JspException("Error creating the plugins menu list", t);
  }
  return super.doStartTag();
}

代码示例来源:origin: entando/entando-core

@Override
public int doStartTag() throws JspException {
  HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>();
  ValueStack stack = this.getStack();
  try {
    String[] beanNames =  wac.getBeanNamesForType(PluginSubMenuContainer.class);
    for (int i=0; i<beanNames.length; i++) {
      PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]);
      containters.add(container);
    }
    if (containters.size()>0) {
      stack.getContext().put(this.getObjectName(), containters);
      stack.setValue("#attr['" + this.getObjectName() + "']", containters, false);
      return EVAL_BODY_INCLUDE;
    }
  } catch (Throwable t) {
    throw new JspException("Error creating the plugins menu list", t);
  }
  return super.doStartTag();
}

代码示例来源:origin: org.entando.entando/entando-admin-console

@Override
public int doStartTag() throws JspException {
  HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
  WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
  List<PluginSubMenuContainer> containters = new ArrayList<PluginSubMenuContainer>();
  ValueStack stack = this.getStack();
  try {
    String[] beanNames =  wac.getBeanNamesForType(PluginSubMenuContainer.class);
    for (int i=0; i<beanNames.length; i++) {
      PluginSubMenuContainer container = (PluginSubMenuContainer) wac.getBean(beanNames[i]);
      containters.add(container);
    }
    if (containters.size()>0) {
      stack.getContext().put(this.getObjectName(), containters);
      stack.setValue("#attr['" + this.getObjectName() + "']", containters, false);
      return EVAL_BODY_INCLUDE;
    }
  } catch (Throwable t) {
    throw new JspException("Error creating the plugins menu list", t);
  }
  return super.doStartTag();
}

代码示例来源:origin: org.entando.entando/entando-admin-console

@Override
public Map getReferencingObjects(IPage page, HttpServletRequest request) throws ApsSystemException {
  Map<String, List> references = new HashMap<String, List>();
  try {
    String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageUtilizer.class);
    for (int i = 0; i < defNames.length; i++) {
      Object service = null;
      try {
        service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
      } catch (Throwable t) {
        _logger.error("error in hasReferencingObjects", t);
        service = null;
      }
      if (service != null) {
        PageUtilizer pageUtilizer = (PageUtilizer) service;
        List utilizers = pageUtilizer.getPageUtilizers(page.getCode());
        if (utilizers != null && !utilizers.isEmpty()) {
          references.put(pageUtilizer.getName() + "Utilizers", utilizers);
        }
      }
    }
  } catch (Throwable t) {
    throw new ApsSystemException("Error extracting Referencing Objects", t);
  }
  return references;
}

代码示例来源:origin: org.entando.entando/entando-admin-console

@Override
public Map getReferencingObjects(Category category, HttpServletRequest request) throws ApsSystemException {
  Map<String, List> references = new HashMap<String, List>();
  try {
    String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(CategoryUtilizer.class);
    for (int i=0; i<defNames.length; i++) {
      Object service = null;
      try {
        service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
      } catch (Throwable t) {
        _logger.error("error checking Referencing Objects", t);
        service = null;
      }
      if (service != null) {
        CategoryUtilizer categoryUtilizer = (CategoryUtilizer) service;
        List utilizers = categoryUtilizer.getCategoryUtilizers(category.getCode());
        if (utilizers != null && !utilizers.isEmpty()) {
          references.put(categoryUtilizer.getName()+"Utilizers", utilizers);
        }
      }
    }
  } catch (Throwable t) {
    throw new ApsSystemException("Errore in hasReferencingObjects", t);
  }
  return references;
}

代码示例来源:origin: org.entando.entando/entando-admin-console

@Override
public Map<String, List<Object>> getReferencingObjects(PageModel pageModel, HttpServletRequest request) throws ApsSystemException {
  Map<String, List<Object>> references = new HashMap<String, List<Object>>();
  try {
    String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageModelUtilizer.class);
    for (int i=0; i<defNames.length; i++) {
      Object service = null;
      try {
        service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
      } catch (Throwable t) {
        _logger.error("error in hasReferencingObjects", t);
        service = null;
      }
      if (service != null) {
        PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service;
        List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(pageModel.getCode());
        if (utilizers != null && !utilizers.isEmpty()) {
          references.put(pageModelUtilizer.getName()+"Utilizers", utilizers);
        }
      }
    }
  } catch (Throwable t) {
    throw new ApsSystemException("Error on getReferencingObjects methods", t);
  }
  return references;
}

代码示例来源:origin: org.entando.entando/entando-admin-console

@Override
public Map getReferencingObjectsForMove(Category category, HttpServletRequest request) throws ApsSystemException {
  Map<String, List> references = new HashMap<String, List>();
  try {
    String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(CategoryUtilizer.class);
    for (int i=0; i<defNames.length; i++) {
      Object service = null;
      try {
        service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
      } catch (Throwable t) {
        _logger.error("error checking Referencing Objects", t);
        service = null;
      }
      if (service != null) {
        CategoryUtilizer categoryUtilizer = (CategoryUtilizer) service;
        List utilizers = categoryUtilizer.getCategoryUtilizersForReloadReferences(category.getCode());
        if (utilizers != null && !utilizers.isEmpty()) {
          references.put(categoryUtilizer.getName()+"Utilizers", utilizers);
        }
      }
    }
  } catch (Throwable t) {
    throw new ApsSystemException("Error in getReferencingObjectsForMove", t);
  }
  return references;
}

代码示例来源:origin: org.entando.entando/entando-core-engine

@Override
public Map getReferencingObjects(Content content, HttpServletRequest request) throws ApsSystemException {
  Map<String, List> references = new HashMap<String, List>();
  try {
    String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(ContentUtilizer.class);
    for (int i=0; i<defNames.length; i++) {
      Object service = null;
      try {
        service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
      } catch (Throwable t) {
        ApsSystemUtils.logThrowable(t, this, "hasReferencingObject");
        service = null;
      }
      if (service != null) {
        ContentUtilizer contentUtilizer = (ContentUtilizer) service;
        List utilizers = contentUtilizer.getContentUtilizers(content.getId());
        if (utilizers != null && !utilizers.isEmpty()) {
          references.put(contentUtilizer.getName()+"Utilizers", utilizers);
        }
      }
    }
  } catch (Throwable t) {
    throw new ApsSystemException("Error in hasReferencingObject method", t);
  }
  return references;
}

相关文章