List of usage examples for org.springframework.util ClassUtils getAllInterfaces
public static Class<?>[] getAllInterfaces(Object instance)
From source file:org.fcrepo.kernel.impl.LockReleasingSession.java
/** * Wrap a JCR session with this dynamic proxy *//* w w w. java2 s . co m*/ public static Session newInstance(final Session session) { LOGGER.trace("Wrapping session {} ({}).", session, session.getClass().getName()); return (Session) newProxyInstance(session.getClass().getClassLoader(), ClassUtils.getAllInterfaces(session), new LockReleasingSession(session)); }
From source file:org.LexGrid.LexBIG.caCore.applicationservice.resource.RemoteResourceManager.java
public Object replaceWithShell(Object result) { if (enableRemoteShell && !(result instanceof RemoteShell) && LexEVSCaCoreUtils.isLexBigClass(result.getClass()) && !result.getClass().isAnnotationPresent(LgClientSideSafe.class) && !doMethodsContainClientSideSafeAnnotation(result.getClass())) { Class<?>[] classes = ClassUtils.getAllInterfaces(result); if (classes.length > 0) { String resourceUuid = UUID.randomUUID().toString(); resourceMap.put(resourceUuid, result); RemoteShell shell = new RemoteShell(classes, result.getClass(), resourceUuid); result = shell;/*from w ww. j av a 2 s .c o m*/ } } return result; }
From source file:org.lightadmin.core.config.context.LightAdminRemoteConfiguration.java
private RmiServiceExporter createRmiServiceExporter(final Object service, final String serviceName) throws RemoteException { RmiServiceExporter rmiServiceExporter = new RmiServiceExporter(); rmiServiceExporter.setServiceName(serviceName); rmiServiceExporter.setService(service); rmiServiceExporter.setServiceInterface(ClassUtils.getAllInterfaces(service)[0]); rmiServiceExporter.setRegistryPort(1199); rmiServiceExporter.afterPropertiesSet(); return rmiServiceExporter; }
From source file:org.senro.metadata.aop.AOPMetadataFactory.java
/** * Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and * ApplicationContextAware). <p>This method allows the bean instance to perform initialization only possible when * all bean properties have been set and to throw an exception in the event of misconfiguration. * * @throws Exception in the event of misconfiguration (such as failure to set an essential property) or if * initialization fails. *//*w ww. j a va 2 s. c o m*/ public void afterPropertiesSet() throws Exception { // set up proxies classFactory = new AspectJProxyFactory(new MetadataClass()); for (MetadataProvider provider : metadataProviders) { Class clazz = provider.getClassClass(); classFactory.addAspect(clazz); for (Class aClass : ClassUtils.getAllInterfaces(clazz.newInstance())) { classFactory.addInterface(aClass); } } propertyFactory = new AspectJProxyFactory(new MetadataProperty()); for (MetadataProvider provider : metadataProviders) { propertyFactory.addAspect(provider.getPropertyClass()); } methodFactory = new AspectJProxyFactory(new MetadataMethod()); for (MetadataProvider provider : metadataProviders) { methodFactory.addAspect(provider.getMethodClass()); } packageFactory = new AspectJProxyFactory(new MetadataPackage()); for (MetadataProvider provider : metadataProviders) { packageFactory.addAspect(provider.getPackageClass()); } referenceFactory = new AspectJProxyFactory(new MetadataReference()); for (MetadataProvider provider : metadataProviders) { referenceFactory.addAspect(provider.getReferenceClass()); } }
From source file:org.focusns.common.dao.mybatis.MyBatisDaoSupport.java
private void inspectNamespace() { Class<?>[] interfaceClasses = ClassUtils.getAllInterfaces(this); for (Class<?> interfaceClass : interfaceClasses) { if (ClassUtils.isAssignable(BaseDao.class, interfaceClass) && interfaceClass != BaseDao.class) { this.NAMESPACE = interfaceClass.getName(); }// w w w .java 2 s. c om } // Assert.notNull(NAMESPACE, "Custom dao interface must implements BaseDao interface"); // this.NAMESPACE += "."; }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean.java
/** * Creates the proxy for target object. This method is invoked by a * BeanFactory after it has set all bean properties supplied. * /*from ww w . j a v a2 s .c o m*/ * @throws IllegalStateException * if target is <code>null</code>. * @throws AopConfigException * if the proxy interfaces or proxyTargetClass are not set and the * target type is <code>org.springframework.aop.TargetSource</code>. */ public void afterPropertiesSet() throws IllegalStateException, AopConfigException { cachingInterceptor.afterPropertiesSet(); flushingInterceptor.afterPropertiesSet(); if (target == null) { throw new IllegalStateException("Property 'target' is required"); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.addAdvisor(new CachingModelSourceAdvisor(cachingInterceptor)); if (hasFlushingModels) { proxyFactory.addAdvisor(new FlushingModelSourceAdvisor(flushingInterceptor)); } proxyFactory.copyFrom(this); TargetSource targetSource = createTargetSource(target); proxyFactory.setTargetSource(targetSource); if (proxyInterfaces != null) { proxyFactory.setInterfaces(proxyInterfaces); } else if (!isProxyTargetClass()) { if (target instanceof TargetSource) { throw new AopConfigException("Either 'proxyInterfaces' or 'proxyTargetClass' is required " + "when using a TargetSource as 'target'"); } // rely on AOP infrastructure to tell us what interfaces to proxy proxyFactory.setInterfaces(ClassUtils.getAllInterfaces(target)); } proxy = proxyFactory.getProxy(); }
From source file:org.senro.metadata.aop.AOPMetadataFactory.java
/** * Compose an implementation of Metadata for the Class object provided to this method. The Metadata object that is * returned is a proper composition of all the MetadataProviders that were registered in the startup configuration. * * @param element A Class object that we would like to recover Metadata for * @return A Metadata object// w w w . ja v a 2 s . c om */ public Metadata createClass(Class element) { classFactory = new AspectJProxyFactory(new MetadataClass()); for (MetadataProvider provider : metadataProviders) { Class clazz = provider.getClassClass(); classFactory.addAspect(clazz); Class[] allInterfaces; try { allInterfaces = ClassUtils.getAllInterfaces(clazz.newInstance()); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } for (Class aClass : allInterfaces) { classFactory.addInterface(aClass); } } return classFactory.getProxy(); }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBeanTests.java
/** * Verifies that the method//w ww .java 2s. com * <code>{@link CacheProxyFactoryBean#afterPropertiesSet()}</code> creates a * new proxy from on the given target object if the target object and the * specified proxy interfaces are not equal to <code>null</code>. */ public void testAfterPropertiesSetWithProxyInterfacesNotEqualToNull() throws Exception { expectAfterPropertiesSetOnInterceptors(); replay(); String[] proxyInterfaces = { Person.class.getName() }; factoryBean.setProxyInterfaces(proxyInterfaces); Person targetObject = new PersonImpl("Darth", "Vader"); factoryBean.setTarget(targetObject); factoryBean.afterPropertiesSet(); Object proxy = factoryBean.getProxy(); assertNotNull(proxy); Class[] targetObjectInterfaces = ClassUtils.getAllInterfaces(targetObject); int interfacesCount = targetObjectInterfaces.length; Class proxyClass = proxy.getClass(); for (int i = 0; i < interfacesCount; i++) { Class targetObjectInterface = targetObjectInterfaces[i]; assertTrue("The proxy should implement the interface <" + targetObjectInterface.getName() + ">", targetObjectInterface.isAssignableFrom(proxyClass)); } assertTrue("The proxy should implement the interface <" + Advised.class.getName() + ">", proxy instanceof Advised); verify(); }
From source file:edu.mayo.cts2.framework.core.plugin.FelixPluginManager.java
/** * Start./*from w w w.ja v a 2s.c o m*/ * * @throws OsgiContainerException the osgi container exception */ public void start() throws OsgiContainerException { if (isRunning()) { return; } boolean suppressOsgi = this.cts2GeneralConfig.getBooleanProperty(SUPPRESS_OSGI_CONFIG_PROP_NAME, DEFALUE_SUPPRESS_OSGI_CONFIG_VALUE); // Create a case-insensitive configuration property map. final StringMap configMap = new StringMap(false); if (!suppressOsgi) { try { this.autodeployBundles(this.configInitializer.getPluginsDirectory()); } catch (IOException e) { throw new RuntimeException(e); } PackageScannerConfiguration scannerConfig = new DefaultPackageScannerConfiguration(); scannerConfig.getPackageIncludes().add("edu.mayo.cts2.*"); scannerConfig.getPackageIncludes().add("org.jaxen*"); scannerConfig.getPackageIncludes().add("com.sun*"); scannerConfig.getPackageIncludes().add("org.json*"); scannerConfig.getPackageIncludes().add("org.springframework.oxm*"); scannerConfig.getPackageExcludes().add("com.atlassian.plugins*"); scannerConfig.getPackageExcludes().remove("org.apache.commons.logging*"); scannerConfig.getPackageVersions().put("org.apache.commons.collections*", "3.2.1"); String exports = exportsBuilder.getExports(scannerConfig); if (log.isDebugEnabled()) { log.debug("Exports: " + exports); } // Explicitly add the servlet exports; exports += ",javax.servlet;version=" + MIN_SERVLET_VERSION; exports += ",javax.servlet.http;version=" + MIN_SERVLET_VERSION; // Add the bundle provided service interface package and the core OSGi // packages to be exported from the class path via the system bundle. configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, exports); } // Explicitly specify the directory to use for caching bundles. File felixCache = ConfigUtils.createSubDirectory(this.configInitializer.getContextConfigDirectory(), ".osgi-felix-cache"); configMap.put(FelixConstants.FRAMEWORK_STORAGE, felixCache.getPath()); configMap.put(FelixConstants.LOG_LEVEL_PROP, String.valueOf(felixLogger.getLogLevel())); configMap.put(FelixConstants.LOG_LOGGER_PROP, felixLogger); configMap.put(FelixConstants.FRAGMENT_ATTACHMENT_RESOLVETIME, felixLogger); String bootDelegation = getAtlassianSpecificOsgiSystemProperty(OSGI_BOOTDELEGATION); if ((bootDelegation == null) || (bootDelegation.trim().length() == 0)) { // These exist to work around JAXP problems. Specifically, bundles that use static factories to create JAXP // instances will execute FactoryFinder with the CCL set to the bundle. These delegations ensure the appropriate // implementation is found and loaded. bootDelegation = "weblogic,weblogic.*," + "META-INF.services," + "com.yourkit,com.yourkit.*," + "com.chronon,com.chronon.*," + "com.jprofiler,com.jprofiler.*," + "org.apache.xerces,org.apache.xerces.*," + "org.apache.xalan,org.apache.xalan.*," + "org.apache.xpath.*," + "org.apache.xml.serializer," + "org.springframework.stereotype," + "org.springframework.web.bind.annotation," + "org.springframework.web.servlet," + "javax.*," + "org.osgi.*," + "org.apache.felix.*," + "sun.*," + "com.sun.*," + "com.sun.xml.bind.v2," + "com.icl.saxon"; } configMap.put(FelixConstants.FRAMEWORK_BOOTDELEGATION, bootDelegation); configMap.put(FelixConstants.IMPLICIT_BOOT_DELEGATION_PROP, "false"); configMap.put(FelixConstants.FRAMEWORK_BUNDLE_PARENT, FelixConstants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK); if (log.isDebugEnabled()) { log.debug("Felix configuration: " + configMap); } if (!suppressOsgi) { validateConfiguration(configMap); } try { final List<BundleActivator> hostServices = new ArrayList<BundleActivator>(); for (Entry<String, Object> bean : this.applicationContext.getBeansWithAnnotation(ExportedService.class) .entrySet()) { Object service = bean.getValue(); ExportedService annotation = service.getClass().getAnnotation(ExportedService.class); Class<?>[] interfaces = annotation.value(); if (interfaces.length == 1 && interfaces[0] == Void.class) { interfaces = ClassUtils.getAllInterfaces(service); } hostServices.add(new HostActivator(service, interfaces)); } configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, hostServices); // Now create an instance of the framework with // our configuration properties and activator. felix = new Felix(configMap); felixRunning = true; felix.init(); BundleContext context = felix.getBundleContext(); ServiceTracker tracker = new ServiceTracker(felix.getBundleContext(), ConfigurationAdmin.class.getName(), new ServiceTrackerCustomizer() { @Override public Object addingService(ServiceReference reference) { ConfigurationAdmin cm = (ConfigurationAdmin) felix.getBundleContext() .getService(reference); try { for (Entry<String, Properties> entrySet : supplementalPropetiesLoader .getOverriddenProperties().entrySet()) { Configuration config = cm.getConfiguration(entrySet.getKey()); config.update(entrySet.getValue()); } } catch (IOException e) { throw new RuntimeException(e); } return cm; } @Override public void modifiedService(ServiceReference reference, Object service) { // } @Override public void removedService(ServiceReference reference, Object service) { // } }); tracker.open(); this.trackers.add(tracker); if (suppressOsgi) { new ConfigurationManager().start(context); } else { FileFilter fileOnlyFilter = new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory(); } }; for (File bundle : this.configInitializer.getPluginsDirectory().listFiles(fileOnlyFilter)) { Bundle installedBundle = felix.getBundleContext().installBundle(bundle.toURI().toString()); try { if (installedBundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) { log.info("Not Auto-starting Fragment bundle: " + installedBundle.getSymbolicName()); } else { installedBundle.start(); log.info("Auto-starting system bundle: " + installedBundle.getSymbolicName()); } } catch (BundleException e) { log.warn("Bundle: " + installedBundle.getSymbolicName() + " failed to start.", e); } } } felix.start(); this.initializeNonOsgiPlugins(); for (String bean : this.applicationContext.getBeanNamesForType(ExtensionPoint.class)) { ExtensionPoint extensionPoint = this.applicationContext.getBean(bean, ExtensionPoint.class); this.registerExtensionPoint(extensionPoint); } servletContext.setAttribute(BundleContext.class.getName(), context); servletContext.setAttribute(PluginManager.class.getName(), this); } catch (final Exception ex) { throw new OsgiContainerException("Unable to start OSGi container", ex); } }
From source file:org.apache.cocoon.components.source.impl.BlockContextSource.java
private static Source adjustName(final TraversableSource source, final String blockName) { TraversableSource adjustedSource = (TraversableSource) Proxy.newProxyInstance( source.getClass().getClassLoader(), ClassUtils.getAllInterfaces(source), new InvocationHandler() { /* (non-Javadoc) * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) *//* w w w . j a v a2s. c o m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.equals(TraversableSource.class.getMethod("getName", new Class[] {}))) return blockName; else return method.invoke(source, args); } }); return adjustedSource; }