List of usage examples for java.lang.reflect Proxy isProxyClass
public static boolean isProxyClass(Class<?> cl)
From source file:net.paoding.rose.web.impl.module.ModulesBuilderImpl.java
public List<Module> build(List<ModuleResource> moduleResources, WebApplicationContext rootContext) throws Exception { // ????????/*from w ww. ja v a2 s . co m*/ moduleResources = new ArrayList<ModuleResource>(moduleResources); Collections.sort(moduleResources); // ?? List<Module> modules = new ArrayList<Module>(moduleResources.size()); Map<ModuleResource, Module> modulesAsMap = new HashMap<ModuleResource, Module>(); // for (ModuleResource moduleResource : moduleResources) { final Module parentModule = (moduleResource.getParent() == null) ? null// : modulesAsMap.get(moduleResource.getParent()); final WebApplicationContext parentContext = (parentModule == null) ? rootContext// : parentModule.getApplicationContext(); final String namespace = "context@controllers" + moduleResource.getRelativePath().replace('/', '.'); // modulespring context final ServletContext servletContext = parentContext == null ? null // : parentContext.getServletContext(); final ModuleAppContext moduleContext = ModuleAppContext.createModuleContext(// parentContext, // moduleResource.getContextResources(), // moduleResource.getMessageBasenames(), // /*id*/moduleResource.getModuleUrl().toString(), // namespace// ); // ??...applicationContext registerBeanDefinitions(moduleContext, moduleResource.getModuleClasses()); // module final ModuleImpl module = new ModuleImpl(// parentModule, // moduleResource.getModuleUrl(), // moduleResource.getMappingPath(), // moduleResource.getRelativePath(), // moduleContext); // modulesAsMap.put(moduleResource, module); // servletContext if (servletContext != null) { String contextAttrKey = WebApplicationContext.class.getName() + "@" + moduleResource.getModuleUrl(); servletContext.setAttribute(contextAttrKey, moduleContext); } // Springweb??ParamValidatorParamResolver, ControllerInterceptor, ControllerErrorHandler List<ParamResolver> customerResolvers = findContextResolvers(moduleContext); // resolvers module.setCustomerResolvers(customerResolvers); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply resolvers " + customerResolvers); } // module List<InterceptorDelegate> interceptors = findInterceptors(moduleContext); for (Iterator<InterceptorDelegate> iter = interceptors.iterator(); iter.hasNext();) { InterceptorDelegate interceptor = iter.next(); ControllerInterceptor most = InterceptorDelegate.getMostInnerInterceptor(interceptor); if (!most.getClass().getName().startsWith("net.paoding.rose.web")) { // deny? if (moduleResource.getInterceptedDeny() != null) { if (RoseStringUtil.matches(moduleResource.getInterceptedDeny(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by rose.properties: " + most.getClass().getName()); } continue; } } // allow? if (moduleResource.getInterceptedAllow() != null) { if (!RoseStringUtil.matches(moduleResource.getInterceptedAllow(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by rose.properties: " + most.getClass().getName()); } continue; } } } } module.setControllerInterceptors(interceptors); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply intercetpors " + interceptors); } // validatormodule List<ParamValidator> validators = findContextValidators(moduleContext); module.setValidators(validators); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply global validators " + validators); } // errorhandler ControllerErrorHandler errorHandler = getContextErrorHandler(moduleContext); if (errorHandler != null) { if (Proxy.isProxyClass(errorHandler.getClass())) { module.setErrorHandler(errorHandler); } else { ErrorHandlerDispatcher dispatcher = new ErrorHandlerDispatcher(errorHandler); module.setErrorHandler(dispatcher); } if (logger.isInfoEnabled()) { logger.info("set errorHandler: " + module.getMappingPath() + " " + errorHandler); } } // controllers final ListableBeanFactory beanFactory = moduleContext.getBeanFactory(); for (String beanName : beanFactory.getBeanDefinitionNames()) { checkController(moduleContext, beanName, module); } // modules.add(module); } return modules; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
public List<Module> build(List<ModuleResource> moduleResources, WebApplicationContext rootContext) throws Exception { // ????????// www. ja v a 2 s . c om moduleResources = new ArrayList<ModuleResource>(moduleResources); Collections.sort(moduleResources); // ?? List<Module> modules = new ArrayList<Module>(moduleResources.size()); Map<ModuleResource, Module> modulesAsMap = new HashMap<ModuleResource, Module>(); // for (ModuleResource moduleResource : moduleResources) { final Module parentModule = (moduleResource.getParent() == null) ? null// : modulesAsMap.get(moduleResource.getParent()); final WebApplicationContext parentContext = (parentModule == null) ? rootContext// : parentModule.getApplicationContext(); final String namespace = "context@controllers" + moduleResource.getRelativePath().replace('/', '.'); // modulespring context final ServletContext servletContext = parentContext == null ? null // : parentContext.getServletContext(); final ModuleAppContext moduleContext = ModuleAppContext.createModuleContext(// parentContext, // moduleResource.getContextResources(), // moduleResource.getMessageBasenames(), // /*id*/moduleResource.getModuleUrl().toString(), // namespace// ); // ??...applicationContext registerBeanDefinitions(moduleContext, moduleResource.getModuleClasses()); // module final ModuleImpl module = new ModuleImpl(// parentModule, // moduleResource.getModuleUrl(), // moduleResource.getMappingPath(), // moduleResource.getRelativePath(), // moduleContext); // modulesAsMap.put(moduleResource, module); // servletContext if (servletContext != null) { String contextAttrKey = WebApplicationContext.class.getName() + "@" + moduleResource.getModuleUrl(); servletContext.setAttribute(contextAttrKey, moduleContext); } // Springweb??ParamValidatorParamResolver, ControllerInterceptor, ControllerErrorHandler List<ParamResolver> customerResolvers = findContextResolvers(moduleContext); // resolvers module.setCustomerResolvers(customerResolvers); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply resolvers " + customerResolvers); } // module List<InterceptorDelegate> interceptors = findInterceptors(moduleContext); for (Iterator<InterceptorDelegate> iter = interceptors.iterator(); iter.hasNext();) { InterceptorDelegate interceptor = iter.next(); ControllerInterceptor most = InterceptorDelegate.getMostInnerInterceptor(interceptor); if (!most.getClass().getName().startsWith("net.paoding.rose.web")) { // deny? if (moduleResource.getInterceptedDeny() != null) { if (BlitzStringUtil.matches(moduleResource.getInterceptedDeny(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by rose.properties: " + most.getClass().getName()); } continue; } } // allow? if (moduleResource.getInterceptedAllow() != null) { if (!BlitzStringUtil.matches(moduleResource.getInterceptedAllow(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by rose.properties: " + most.getClass().getName()); } continue; } } } } module.setControllerInterceptors(interceptors); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply intercetpors " + interceptors); } // validatormodule List<ParamValidator> validators = findContextValidators(moduleContext); module.setValidators(validators); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply global validators " + validators); } // errorhandler ControllerErrorHandler errorHandler = getContextErrorHandler(moduleContext); if (errorHandler != null) { if (Proxy.isProxyClass(errorHandler.getClass())) { module.setErrorHandler(errorHandler); } else { ErrorHandlerDispatcher dispatcher = new ErrorHandlerDispatcher(errorHandler); module.setErrorHandler(dispatcher); } if (logger.isInfoEnabled()) { logger.info("set errorHandler: " + module.getMappingPath() + " " + errorHandler); } } // controllers final ListableBeanFactory beanFactory = moduleContext.getBeanFactory(); for (String beanName : beanFactory.getBeanDefinitionNames()) { checkController(moduleContext, beanName, module); } // modules.add(module); } return modules; }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanImpl.java
/** * Dynamically implemented {@link Object#equals(Object)} method. * /*w w w. ja v a 2s .c om*/ * @param oOrigin The 'other' object * @return as equals specification * @see java.lang.Object#equals(java.lang.Object) */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public boolean equals(Object oOrigin) { T theOther; DynaBeanImpl theOtherDynaBean = null; Object o; // Check if 'other' is a null if (oOrigin == null) { return false; } if (Proxy.isProxyClass(oOrigin.getClass())) { o = Proxy.getInvocationHandler(oOrigin); } else { o = oOrigin; } // Check for self-equals... if (o == this) { return true; } // Check if 'the other' is a 'implementedType' type... if (descriptor.getImplementedType().isAssignableFrom(o.getClass()) == false) { // ...if not, can be a dynaBean?... if (DynaBeanImpl.class.isAssignableFrom(o.getClass())) { theOtherDynaBean = (DynaBeanImpl) o; // Yes, check if the implementedType is the same or derived if (getImplementedType().isAssignableFrom(theOtherDynaBean.getImplementedType()) == false) { return false; } } else { // Is not implemented type nor ProxyBeanImpl... return false; } } theOther = (T) o; for (DynaBeanPropertyDescriptor property : descriptor.getProperties()) { try { Object value; if (theOtherDynaBean != null) { value = theOtherDynaBean.values.get(property.propertyName); } else { value = property.getterMethod.invoke(theOther); } if (ObjectUtils.nullSafeEquals(values.get(property.propertyName), value) == false) { return false; } } catch (SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("On equals call!", e); } } return true; }
From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java
public List<Module> build(List<ModuleResource> moduleResources, WebApplicationContext rootContext) throws Exception { // ????????/*from w ww . ja va 2 s . c om*/ moduleResources = new ArrayList<ModuleResource>(moduleResources); Collections.sort(moduleResources); // ?? List<Module> modules = new ArrayList<Module>(moduleResources.size()); Map<ModuleResource, Module> modulesAsMap = new HashMap<ModuleResource, Module>(); /* * ModuleResource ?web??? * modelResourcesmodel * */ for (ModuleResource moduleResource : moduleResources) { final Module parentModule = (moduleResource.getParent() == null) ? null// : modulesAsMap.get(moduleResource.getParent()); final WebApplicationContext parentContext = (parentModule == null) ? rootContext// : parentModule.getApplicationContext(); final String namespace = "context@controllers" + moduleResource.getRelativePath().replace('/', '.'); // modulespring context final ServletContext servletContext = parentContext == null ? null // : parentContext.getServletContext(); final ModuleAppContext moduleContext = ModuleAppContext.createModuleContext(// parentContext, // moduleResource.getContextResources(), // moduleResource.getMessageBasenames(), // /*id*/moduleResource.getModuleUrl().toString(), // namespace// ); // ??...applicationContext registerBeanDefinitions(moduleContext, moduleResource.getModuleClasses()); // module final ModuleImpl module = new ModuleImpl(// parentModule, // moduleResource.getModuleUrl(), // moduleResource.getMappingPath(), // moduleResource.getRelativePath(), // moduleContext); // modulesAsMap.put(moduleResource, module); // servletContext if (servletContext != null) { String contextAttrKey = WebApplicationContext.class.getName() + "@" + moduleResource.getModuleUrl(); servletContext.setAttribute(contextAttrKey, moduleContext); } // Springweb??ParamValidatorParamResolver, ControllerInterceptor, ControllerErrorHandler List<ParamResolver> customerResolvers = findContextResolvers(moduleContext); // resolvers module.setCustomerResolvers(customerResolvers); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply resolvers " + customerResolvers); } // module List<InterceptorDelegate> interceptors = findInterceptors(moduleContext); for (Iterator<InterceptorDelegate> iter = interceptors.iterator(); iter.hasNext();) { InterceptorDelegate interceptor = iter.next(); ControllerInterceptor most = InterceptorDelegate.getMostInnerInterceptor(interceptor); if (!most.getClass().getName().startsWith("com.sinosoft.one.mvc.web")) { // deny? if (moduleResource.getInterceptedDeny() != null) { if (MvcStringUtil.matches(moduleResource.getInterceptedDeny(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by mvc.properties: " + most.getClass().getName()); } continue; } } // allow? if (moduleResource.getInterceptedAllow() != null) { if (!MvcStringUtil.matches(moduleResource.getInterceptedAllow(), interceptor.getName())) { iter.remove(); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': remove interceptor by mvc.properties: " + most.getClass().getName()); } continue; } } } } module.setControllerInterceptors(interceptors); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply intercetpors " + interceptors); } // validatormodule List<ParamValidator> validators = findContextValidators(moduleContext); module.setValidators(validators); if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': apply global validators " + validators); } // errorhandler ControllerErrorHandler errorHandler = getContextErrorHandler(moduleContext); if (errorHandler != null) { if (Proxy.isProxyClass(errorHandler.getClass())) { module.setErrorHandler(errorHandler); } else { ErrorHandlerDispatcher dispatcher = new ErrorHandlerDispatcher(errorHandler); module.setErrorHandler(dispatcher); } if (logger.isInfoEnabled()) { logger.info("set errorHandler: " + module.getMappingPath() + " " + errorHandler); } } // controllers final ListableBeanFactory beanFactory = moduleContext.getBeanFactory(); for (String beanName : beanFactory.getBeanDefinitionNames()) { checkController(moduleContext, beanName, module); } // modules.add(module); } return modules; }
From source file:org.unitils.core.util.ObjectFormatter.java
protected boolean formatProxy(Object object, Class<?> type, StringBuilder result) { if (Proxy.isProxyClass(type)) { result.append("Proxy<?>"); return true; }/*from ww w . j av a2 s . c om*/ String className = getShortClassName(object.getClass()); int index = className.indexOf("..EnhancerByCGLIB.."); if (index > 0) { result.append("Proxy<"); result.append(className.substring(0, index)); result.append(">"); return true; } return false; }
From source file:fr.ign.cogit.geoxygene.datatools.ojb.GeOxygeneBrokerHelper.java
/** * returns an Array with an Objects PK VALUES if convertToSql is true, any * associated java-to-sql conversions are applied. If the Object is a Proxy or * a VirtualProxy NO conversion is necessary. * /*from ww w. j av a 2s . c o m*/ * @param objectOrProxy * @param convertToSql * @return Object[] * @throws PersistenceBrokerException */ public ValueContainer[] getKeyValues(ClassDescriptor cld, Object objectOrProxy, boolean convertToSql, Connection conn) throws PersistenceBrokerException { /* * arminw Check it out. Because the isProxyClass method is costly and most * objects aren't proxies, I add a instanceof check before. Is every Proxy a * instance of Proxy? */ if ((objectOrProxy instanceof Proxy) && Proxy.isProxyClass(objectOrProxy.getClass())) { IndirectionHandler handler; handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy); return this.getKeyValues(cld, handler.getIdentity(), convertToSql); // BRJ: // convert // Identity } else if (objectOrProxy instanceof VirtualProxy) { IndirectionHandler handler; handler = VirtualProxy.getIndirectionHandler((VirtualProxy) objectOrProxy); return this.getKeyValues(cld, handler.getIdentity(), convertToSql); // BRJ: // convert // Identity } else { ClassDescriptor realCld = this.getRealClassDescriptor(cld, objectOrProxy); return this.getValuesForObject(realCld.getPkFields(), objectOrProxy, convertToSql, conn); } }
From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java
@Test public void wrappedClusterConnectionShouldUseWrappers() throws Exception { RedisClusterClient redisClusterClient = RedisClusterClient.create(TestClientResources.get(), RedisURI.create(TestSettings.host(), 7379)); GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(redisClusterClient::connect, new GenericObjectPoolConfig()); StatefulRedisClusterConnection<String, String> connection = pool.borrowObject(); RedisAdvancedClusterCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isTrue(); assertThat(sync).isInstanceOf(RedisAdvancedClusterCommands.class); assertThat(connection.async()).isInstanceOf(RedisAdvancedClusterAsyncCommands.class) .isNotInstanceOf(RedisAdvancedClusterAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisAdvancedClusterReactiveCommands.class) .isNotInstanceOf(RedisAdvancedClusterReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisClusterConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class).isSameAs(connection); connection.close();//from w w w . ja v a 2s . c om pool.close(); FastShutdown.shutdown(redisClusterClient); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
@Test public void plainConnectionShouldNotUseWrappers() throws Exception { GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport .createGenericObjectPool(() -> client.connect(), new GenericObjectPoolConfig(), false); StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); assertThat(connection).isInstanceOf(StatefulRedisConnection.class) .isNotInstanceOf(StatefulRedisClusterConnectionImpl.class); assertThat(Proxy.isProxyClass(connection.getClass())).isFalse(); assertThat(sync).isInstanceOf(RedisCommands.class); assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class) .isInstanceOf(RedisAsyncCommandsImpl.class); assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class) .isInstanceOf(RedisReactiveCommandsImpl.class); assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class) .isInstanceOf(StatefulRedisConnectionImpl.class); pool.returnObject(connection);/*from w ww . j a va2 s . c om*/ pool.close(); }
From source file:org.kuali.coeus.sys.impl.service.SpringBeanConfigurationTest.java
/** * Method searches out all prototype beans in all contexts. It then * makes sure that the bean exists in all contexts as a prototype. * This helps find issues with importing a prototype bean using the * GlobalResourceLoaderFactoryBean as a singleton. *//*from w ww. j ava 2 s . com*/ @Test public void test_beans_across_other_contexts_correct_scope() { final Set<String> prototypes = new HashSet<>(); final Set<String> nonPrototypes = new HashSet<>(); toEachSpringBean(new VoidFunction() { @Override public void r(ApplicationContext context, String name) { final Object o = context.getBean(name); final Object o2 = context.getBean(name); if (o != o2) { //skip checking if a proxy if (!Proxy.isProxyClass(o.getClass())) { prototypes.add(name); } } else { nonPrototypes.add(name); } } }, true); final Collection<String> misConfigured = CollectionUtils.retainAll(nonPrototypes, prototypes); Assert.assertTrue( "The following beans are prototypes in one spring context and non-prototypes in another spring context: " + misConfigured, misConfigured.isEmpty()); }