List of usage examples for org.springframework.util ObjectUtils addObjectToArray
public static <A, O extends A> A[] addObjectToArray(@Nullable A[] array, @Nullable O obj)
From source file:io.pivotal.receptor.commands.DesiredLRPCreateRequest.java
public void addRoute(int port, String... hostnames) { this.routes.put("cf-router", ObjectUtils.addObjectToArray(this.routes.get("cf-router"), new Route(port, hostnames))); }
From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java
/** * Prepare the script beans in the internal BeanFactory that this * post-processor uses. Each original bean definition will be split * into a ScriptFactory definition and a scripted object definition. * @param bd the original bean definition in the main BeanFactory * @param scriptFactoryBeanName the name of the internal ScriptFactory bean * @param scriptedObjectBeanName the name of the internal scripted object bean *//*from w ww . j ava 2 s .co m*/ protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) { // Avoid recreation of the script bean definition in case of a prototype. synchronized (this.scriptBeanFactory) { if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) { this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd)); ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class); ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator()); Class<?>[] interfaces = scriptFactory.getScriptInterfaces(); Class<?>[] scriptedInterfaces = interfaces; if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) { Class<?> configInterface = createConfigInterface(bd, interfaces); scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface); } BeanDefinition objectBd = createScriptedObjectBeanDefinition(bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces); long refreshCheckDelay = resolveRefreshCheckDelay(bd); if (refreshCheckDelay >= 0) { objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE); } this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd); } } }
From source file:org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor.java
private void addSyntheticDependsOn(BeanDefinition definition, String beanName) { if (StringUtils.hasText(beanName)) { String[] dependsOn = definition.getDependsOn(); if (dependsOn != null && dependsOn.length > 0) { for (String dependOn : dependsOn) { if (beanName.equals(dependOn)) { return; }// w w w . j a v a 2 s .c o m } } // add depends on dependsOn = (String[]) ObjectUtils.addObjectToArray(dependsOn, beanName); definition.setDependsOn(dependsOn); Collection<String> markers = (Collection<String>) definition.getAttribute(SYNTHETIC_DEPENDS_ON); if (markers == null) { markers = new ArrayList<String>(2); definition.setAttribute(SYNTHETIC_DEPENDS_ON, markers); } markers.add(beanName); } }
From source file:org.eclipse.gemini.blueprint.service.importer.support.OsgiServiceProxyFactoryBean.java
Object createProxy(boolean lazyProxy) { if (log.isDebugEnabled()) log.debug("Creating a single service proxy ..."); // first create the TCCL interceptor to register its listener with the // dynamic interceptor boolean serviceTccl = ImportContextClassLoaderEnum.SERVICE_PROVIDER.equals(getImportContextClassLoader()); final ServiceProviderTCCLInterceptor tcclAdvice = (serviceTccl ? new ServiceProviderTCCLInterceptor() : null);//w ww . j av a 2s . c om final OsgiServiceLifecycleListener tcclListener = (serviceTccl ? tcclAdvice.new ServiceProviderTCCLListener() : null); Class<?> filterClass = ClassUtils.getParticularClass(getInterfaces()); String filterClassName = (filterClass != null ? filterClass.getName() : null); final ServiceDynamicInterceptor lookupAdvice = new ServiceDynamicInterceptor(getBundleContext(), filterClassName, getUnifiedFilter(), getAopClassLoader()); lookupAdvice.setMandatoryService(Availability.MANDATORY.equals(getAvailability())); lookupAdvice.setUseBlueprintExceptions(isUseBlueprintExceptions()); lookupAdvice.setSticky(sticky); OsgiServiceLifecycleListener[] listeners = (serviceTccl ? ObjectUtils.addObjectToArray(getListeners(), tcclListener) : getListeners()); lookupAdvice.setListeners(listeners); synchronized (monitor) { lookupAdvice.setRetryTimeout(retryTimeout); retryTemplate = lookupAdvice.getRetryTemplate(); } lookupAdvice.setApplicationEventPublisher(applicationEventPublisher); // add the listeners as a list since it might be updated after the proxy // has been created lookupAdvice.setStateListeners(stateListeners); lookupAdvice.setServiceImporter(this); lookupAdvice.setServiceImporterName(getBeanName()); // create a proxy creator using the existing context ServiceProxyCreator creator = new AbstractServiceProxyCreator(getInterfaces(), getAopClassLoader(), getBeanClassLoader(), getBundleContext(), getImportContextClassLoader()) { ServiceInvoker createDispatcherInterceptor(ServiceReference reference) { return lookupAdvice; } Advice createServiceProviderTCCLAdvice(ServiceReference reference) { return tcclAdvice; } }; ProxyPlusCallback proxyPlusCallback = creator.createServiceProxy(lookupAdvice.getServiceReference()); synchronized (monitor) { proxy = proxyPlusCallback.proxy; destructionCallback = new DisposableBeanRunnableAdapter(proxyPlusCallback.destructionCallback); } lookupAdvice.setProxy(proxy); // start the lookup only after the proxy has been assembled if (!lazyProxy) { lookupAdvice.afterPropertiesSet(); } else { initializationCallback = new Runnable() { public void run() { lookupAdvice.afterPropertiesSet(); } }; } return proxy; }
From source file:org.rill.bpm.api.finder.support.RoleTagRelationManFinderInterceptorAdapter.java
public Object invoke(MethodInvocation arg0) throws Throwable { boolean firstMatch = false; try {/* w w w . j a v a 2s . co m*/ // Check the return value is empty or not String[] foundMans = null; for (RoleTagRelationalManFinder f : this.finder) { // Set finder component boolean internalFirstMatch = setMatchFinderComponent(f); if (!firstMatch && internalFirstMatch) { firstMatch = true; } String[] fm = f.findTaskExemans((String) arg0.getArguments()[0], (String) arg0.getArguments()[1], (String) arg0.getArguments()[2], (Long) arg0.getArguments()[3]); if (!ObjectUtils.isEmpty(fm)) { for (String s : fm) { foundMans = (String[]) ObjectUtils.addObjectToArray(foundMans, s); } } } if (!ObjectUtils.isEmpty(foundMans)) { if (log.isDebugEnabled()) log.debug("Found result " + ObjectUtils.getDisplayString(foundMans) + " by " + this.finder.getClass().getName()); List<String> list = Arrays.asList(foundMans); Set<String> afterFilter = new LinkedHashSet<String>(list); return afterFilter.toArray(new String[afterFilter.size()]); } // Let next intercepter do it. return arg0.proceed(); } finally { if (firstMatch) { clearFirstMatchFinderComponent(); } } }
From source file:org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.java
@Override public void visit(String attributeName, Object attributeValue) { Object newValue = attributeValue; Object existingValue = this.attributes.get(this.attributeName); if (existingValue != null) { newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue); } else {/*from w w w. j ava 2s.c om*/ Object[] newArray = (Object[]) Array.newInstance(newValue.getClass(), 1); newArray[0] = newValue; newValue = newArray; } this.attributes.put(this.attributeName, newValue); }
From source file:org.springframework.data.gemfire.GemfireBeanFactoryLocator.java
public void afterPropertiesSet() { // add the factory as default if possible (if it's the only one) synchronized (GemfireBeanFactoryLocator.class) { canUseDefaultBeanFactory = beanFactories.isEmpty(); if (canUseDefaultBeanFactory) { if (defaultFactory == null) { defaultFactory = beanFactory; if (log.isDebugEnabled()) log.debug("default beanFactoryReference=" + defaultFactory); } else { if (log.isDebugEnabled()) log.debug("more then one beanFactory - default not possible to determine"); canUseDefaultBeanFactory = false; defaultFactory = null;// w w w . j av a 2 s . co m } } } // add aliases if (StringUtils.hasText(factoryName)) { String[] aliases = beanFactory.getAliases(factoryName); names = (String[]) ObjectUtils.addObjectToArray(aliases, factoryName); for (String name : names) { if (log.isDebugEnabled()) log.debug("adding key=" + name + " w/ reference=" + beanFactory); if (beanFactories.containsKey(name) && !beanFactory.equals(beanFactories.get(name)) || beanFactories.putIfAbsent(name, beanFactory) != null) { throw new IllegalArgumentException( "a beanFactoryReference already exists for key " + factoryName); } } } }
From source file:org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean.java
Object createProxy(boolean lazyProxy) { if (log.isDebugEnabled()) log.debug("Creating a single service proxy ..."); // first create the TCCL interceptor to register its listener with the // dynamic interceptor boolean serviceTccl = ImportContextClassLoaderEnum.SERVICE_PROVIDER.equals(getImportContextClassLoader()); final ServiceProviderTCCLInterceptor tcclAdvice = (serviceTccl ? new ServiceProviderTCCLInterceptor() : null);/*from ww w .j av a2 s. co m*/ final OsgiServiceLifecycleListener tcclListener = (serviceTccl ? tcclAdvice.new ServiceProviderTCCLListener() : null); Class<?> filterClass = ClassUtils.getParticularClass(getInterfaces()); String filterClassName = (filterClass != null ? filterClass.getName() : null); final ServiceDynamicInterceptor lookupAdvice = new ServiceDynamicInterceptor(getBundleContext(), filterClassName, getUnifiedFilter(), getAopClassLoader()); lookupAdvice.setMandatoryService(Availability.MANDATORY.equals(getAvailability())); lookupAdvice.setUseBlueprintExceptions(isUseBlueprintExceptions()); lookupAdvice.setSticky(sticky); OsgiServiceLifecycleListener[] listeners = (serviceTccl ? (OsgiServiceLifecycleListener[]) ObjectUtils.addObjectToArray(getListeners(), tcclListener) : getListeners()); lookupAdvice.setListeners(listeners); synchronized (monitor) { lookupAdvice.setRetryTimeout(retryTimeout); retryTemplate = lookupAdvice.getRetryTemplate(); } lookupAdvice.setApplicationEventPublisher(applicationEventPublisher); // add the listeners as a list since it might be updated after the proxy // has been created lookupAdvice.setStateListeners(stateListeners); lookupAdvice.setServiceImporter(this); lookupAdvice.setServiceImporterName(getBeanName()); // create a proxy creator using the existing context ServiceProxyCreator creator = new AbstractServiceProxyCreator(getInterfaces(), getAopClassLoader(), getBeanClassLoader(), getBundleContext(), getImportContextClassLoader()) { ServiceInvoker createDispatcherInterceptor(ServiceReference reference) { return lookupAdvice; } Advice createServiceProviderTCCLAdvice(ServiceReference reference) { return tcclAdvice; } }; ProxyPlusCallback proxyPlusCallback = creator.createServiceProxy(lookupAdvice.getServiceReference()); synchronized (monitor) { proxy = proxyPlusCallback.proxy; destructionCallback = new DisposableBeanRunnableAdapter(proxyPlusCallback.destructionCallback); } lookupAdvice.setProxy(proxy); // start the lookup only after the proxy has been assembled if (!lazyProxy) { lookupAdvice.afterPropertiesSet(); } else { initializationCallback = new Runnable() { public void run() { lookupAdvice.afterPropertiesSet(); } }; } return proxy; }
From source file:org.springframework.scripting.support.ScriptFactoryPostProcessor.java
/** * Prepare the script beans in the internal BeanFactory that this * post-processor uses. Each original bean definition will be split * into a ScriptFactory definition and a scripted object definition. * @param bd the original bean definition in the main BeanFactory * @param scriptFactoryBeanName the name of the internal ScriptFactory bean * @param scriptedObjectBeanName the name of the internal scripted object bean *//*from www .j a v a 2s . c o m*/ protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) { // Avoid recreation of the script bean definition in case of a prototype. synchronized (this.scriptBeanFactory) { if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) { this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd)); ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class); ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator()); Class<?>[] interfaces = scriptFactory.getScriptInterfaces(); Class<?>[] scriptedInterfaces = interfaces; if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) { Class<?> configInterface = createConfigInterface(bd, interfaces); scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface); } BeanDefinition objectBd = createScriptedObjectBeanDefinition(bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces); long refreshCheckDelay = resolveRefreshCheckDelay(bd); if (refreshCheckDelay >= 0) { objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE); } this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd); } } }