List of usage examples for org.springframework.web.context.support XmlWebApplicationContext getBean
@Override
public Object getBean(String name) throws BeansException
From source file:org.parancoe.web.ContextListener.java
/** * Populate the "daoMap" bean with the DAOs defined in the context. *//* w w w .ja v a2 s. com*/ @SuppressWarnings("unchecked") protected void populateDaoMap(XmlWebApplicationContext ctx) { Map daoMap = (Map) ctx.getBean("daoMap"); Map daos = DaoUtils.getDaos(ctx); daoMap.putAll(daos); }
From source file:gov.nih.nci.clinicalconnector.service.globus.ClinicalConnectorProviderImpl.java
public ClinicalConnectorProviderImpl() throws RemoteException { XmlWebApplicationContext c = new XmlWebApplicationContext(); c.setConfigLocation("classpath:applicationContext.xml"); c.refresh();/*from ww w . ja v a 2 s .c om*/ impl = (ClinicalConnectorImpl) c.getBean("clinicalConnectorService"); }
From source file:gov.nih.nci.cdmsconnector.c3d.service.globus.C3DGridServiceProviderImpl.java
public C3DGridServiceProviderImpl() throws RemoteException { XmlWebApplicationContext c = new XmlWebApplicationContext(); c.setConfigLocation("classpath:applicationContext.xml"); c.refresh();//from w w w.j a v a 2 s . co m impl = (C3DGridServiceImpl) c.getBean("c3DGridService"); }
From source file:org.guanxi.idp.persistence.AttributePersistenceTest.java
@Test public void test() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(persistenceConfigFiles); ctx.setServletContext(servletContext); ctx.refresh();//from w ww . j a v a 2s . c om PersistenceEngine engine = (PersistenceEngine) ctx.getBean("idpPersistenceEngine"); assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertTrue( engine.persistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME, TEST_ATTRIBUTE_VALUE)); assertTrue(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertEquals(engine.getAttributeValue(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME), TEST_ATTRIBUTE_VALUE); assertTrue(engine.unpersistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); }
From source file:sct.ApplicationContextNamespaceTestServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); ctx.setClassLoader(loader);//from w w w. j a va2 s .c o m ctx.setConfigLocation("classpath:sct/namespace.xml"); ctx.refresh(); Object bean = ctx.getBean("someBean"); if (bean != null) { PrintWriter writer = resp.getWriter(); writer.write("OK"); writer.flush(); } }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
/** ??? */ private ControllerErrorHandler getContextErrorHandler(XmlWebApplicationContext context) { ControllerErrorHandler errorHandler = null; String[] names = context.getBeanNamesForType(ControllerErrorHandler.class); for (int i = 0; errorHandler == null && i < names.length; i++) { errorHandler = (ControllerErrorHandler) context.getBean(names[i]); Class<?> userClass = ClassUtils.getUserClass(errorHandler); if (userClass.isAnnotationPresent(Ignored.class)) { logger.debug("Ignored controllerErrorHandler: " + errorHandler); errorHandler = null;// w ww .j a v a 2 s .c o m continue; } } return errorHandler; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private List<ParamResolver> findContextResolvers(XmlWebApplicationContext context) { String[] resolverNames = SpringUtils.getBeanNames(context.getBeanFactory(), ParamResolver.class); ArrayList<ParamResolver> resolvers = new ArrayList<ParamResolver>(resolverNames.length); for (String beanName : resolverNames) { ParamResolver resolver = (ParamResolver) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(resolver); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored context resolver:" + resolver); }// w ww. j ava 2s .c o m continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && context.getBeanFactory().getBeanDefinition(beanName) == null) { if (logger.isDebugEnabled()) { logger.debug("Ignored context resolver (NotForSubModules):" + resolver); } continue; } resolvers.add(resolver); if (logger.isDebugEnabled()) { logger.debug("context resolver[" + resolver.getClass().getName()); } } return resolvers; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private List<ParamValidator> findContextValidators(XmlWebApplicationContext context) { String[] validatorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ParamValidator.class); ArrayList<ParamValidator> globalValidators = new ArrayList<ParamValidator>(validatorNames.length); for (String beanName : validatorNames) { ParamValidator validator = (ParamValidator) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(validator); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored context validator:" + validator); }//from www . j av a 2 s . c om continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && context.getBeanFactory().getBeanDefinition(beanName) == null) { if (logger.isDebugEnabled()) { logger.debug("Ignored context validator (NotForSubModules):" + validator); } continue; } globalValidators.add(validator); if (logger.isDebugEnabled()) { logger.debug("add context validator: " + userClass.getName()); } } return globalValidators; }
From source file:net.paoding.rose.web.impl.module.ModulesBuilderImpl.java
private List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context) { String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class); ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length); for (String beanName : interceptorNames) { ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(interceptor); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (Ignored):" + interceptor); }/*from w w w. j a v a2 s . c om*/ continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && !context.getBeanFactory().containsBeanDefinition(beanName)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (NotForSubModules):" + interceptor); } continue; } if (!userClass.getSimpleName().endsWith(RoseConstants.INTERCEPTOR_SUFFIX)) { logger.error("", new IllegalArgumentException("Interceptor must be end with '" + RoseConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName())); continue; } InterceptorBuilder builder = new InterceptorBuilder(interceptor); Interceptor annotation = userClass.getAnnotation(Interceptor.class); if (annotation != null) { builder.oncePerRequest(annotation.oncePerRequest()); } String interceporName; if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) { interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()), RoseConstants.INTERCEPTOR_SUFFIX); } else { interceporName = StringUtils.removeEnd(beanName, RoseConstants.INTERCEPTOR_SUFFIX); } final String rose = "rose"; if (interceporName.startsWith(rose) && (interceporName.length() == rose.length() || Character.isUpperCase(interceporName.charAt(rose.length()))) && !userClass.getName().startsWith("net.paoding.rose.")) { throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for " + userClass.getName() + ": don't starts with 'rose', it's reserved"); } builder.name(interceporName); InterceptorDelegate wrapper = builder.build(); interceptors.add(wrapper); if (logger.isDebugEnabled()) { int priority = 0; if (interceptor instanceof Ordered) { priority = ((Ordered) interceptor).getPriority(); } logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n + wrapper.getName() + "=" + userClass.getName()); } } Collections.sort(interceptors); throwExceptionIfDuplicatedNames(interceptors); return interceptors; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context) { String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class); ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length); for (String beanName : interceptorNames) { ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(interceptor); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (Ignored):" + interceptor); }//from w ww .j a va 2s .c om continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && !context.getBeanFactory().containsBeanDefinition(beanName)) { if (logger.isDebugEnabled()) { logger.debug("Ignored interceptor (NotForSubModules):" + interceptor); } continue; } if (!userClass.getSimpleName().endsWith(BlitzConstants.INTERCEPTOR_SUFFIX)) { logger.error("", new IllegalArgumentException("Interceptor must be end with '" + BlitzConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName())); continue; } InterceptorBuilder builder = new InterceptorBuilder(interceptor); Interceptor annotation = userClass.getAnnotation(Interceptor.class); if (annotation != null) { builder.oncePerRequest(annotation.oncePerRequest()); } String interceporName; if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) { interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()), BlitzConstants.INTERCEPTOR_SUFFIX); } else { interceporName = StringUtils.removeEnd(beanName, BlitzConstants.INTERCEPTOR_SUFFIX); } final String rose = "rose"; if (interceporName.startsWith(rose) && (interceporName.length() == rose.length() || Character.isUpperCase(interceporName.charAt(rose.length()))) && !userClass.getName().startsWith("net.paoding.rose.")) { throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for " + userClass.getName() + ": don't starts with 'rose', it's reserved"); } builder.name(interceporName); InterceptorDelegate wrapper = builder.build(); interceptors.add(wrapper); if (logger.isDebugEnabled()) { int priority = 0; if (interceptor instanceof Ordered) { priority = ((Ordered) interceptor).getPriority(); } logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n + wrapper.getName() + "=" + userClass.getName()); } } Collections.sort(interceptors); throwExceptionIfDuplicatedNames(interceptors); return interceptors; }