List of usage examples for org.springframework.util StringUtils commaDelimitedListToStringArray
public static String[] commaDelimitedListToStringArray(@Nullable String str)
From source file:org.springframework.data.hadoop.cascading.HadoopFlowFactoryBean.java
@Override HadoopFlow createFlow() throws IOException { // copy flowDef FlowDef def = FlowDef.flowDef();//from w ww .j av a2s . co m if (flowDef != null) { def.addSinks(flowDef.getSinksCopy()).addSources(flowDef.getSourcesCopy()) .addTraps(flowDef.getTrapsCopy()).addTails(flowDef.getTailsArray()) .setAssertionLevel(flowDef.getAssertionLevel()).setDebugLevel(flowDef.getDebugLevel()) .addCheckpoints(flowDef.getCheckpointsCopy()) .addTags(StringUtils.commaDelimitedListToStringArray(flowDef.getTags())) .setName(flowDef.getName()); } Set<Pipe> heads = new LinkedHashSet<Pipe>(); if (tails != null) { for (Pipe pipe : tails) { Collections.addAll(heads, pipe.getHeads()); } } Pipe pipe = null; if (heads.size() == 1) { pipe = heads.iterator().next(); } if (sources != null && sources.size() == 1) { Tap tap = sources.remove(MARKER); if (tap != null) { sources.put(pipe.getName(), tap); } } if (sinks != null && sinks.size() == 1) { Tap tap = sinks.remove(MARKER); if (tap != null) { sinks.put(pipe.getName(), tap); } } def.addSources(sources).addSinks(sinks).addTraps(traps); if (tails != null) { def.addTails(tails); } if (StringUtils.hasText(beanName)) { def.addTag(beanName); if (!StringUtils.hasText(def.getName())) { def.setName(beanName); } } Configuration cfg = ConfigurationUtils.createFrom(configuration, properties); Properties props = ConfigurationUtils.asProperties(cfg); if (jar != null) { AppProps.setApplicationJarPath(props, ResourceUtils.decode(jar.getURI().toString())); } else if (jarClass != null) { AppProps.setApplicationJarClass(props, jarClass); } if (addCascadingJars) { if (FILE_SEPARATOR_WARNING && !":".equals(System.getProperty("path.separator"))) { log.warn( "System path separator is not ':' - this will likely cause invalid classpath entries within the DistributedCache. See the docs and HADOOP-9123 for more information."); // show the warning once per CL FILE_SEPARATOR_WARNING = false; } ClassLoader cascadingCL = Cascade.class.getClassLoader(); Resource cascadingCore = ResourceUtils.findContainingJar(Cascade.class); Resource cascadingHadoop = ResourceUtils.findContainingJar(cascadingCL, "cascading/flow/hadoop/HadoopFlow.class"); // find jgrapht Resource jgrapht = ResourceUtils.findContainingJar(cascadingCL, "org/jgrapht/Graph.class"); // find riffle Resource riffle = ResourceUtils.findContainingJar(cascadingCL, "riffle/process/Process.class"); // find janino Resource janino = ResourceUtils.findContainingJar(cascadingCL, "org/codehaus/janino/Java.class"); // find janino commons-compiler Resource commonsCompiler = ResourceUtils.findContainingJar(cascadingCL, "org/codehaus/commons/compiler/CompileException.class"); Assert.notNull(cascadingCore, "Cannot find cascading-core.jar"); Assert.notNull(cascadingHadoop, "Cannot find cascading-hadoop.jar"); Assert.notNull(jgrapht, "Cannot find jgraphts-jdk.jar"); Assert.notNull(riffle, "Cannot find riffle.jar"); Assert.notNull(janino, "Cannot find janino.jar"); Assert.notNull(commonsCompiler, "Cannot find commons-compiler.jar"); if (log.isDebugEnabled()) { log.debug("Auto-detecting Cascading Libs [" + Arrays.toString( new Resource[] { cascadingCore, cascadingHadoop, jgrapht, riffle, janino, commonsCompiler }) + "]"); } ConfigurationUtils.addLibs(cfg, cascadingCore, cascadingHadoop, jgrapht, riffle, janino, commonsCompiler); // config changed, reinit properties props = ConfigurationUtils.asProperties(cfg); } if (jobPoolingInterval != null) { FlowProps.setJobPollingInterval(props, jobPoolingInterval); } if (maxConcurrentSteps != null) { FlowProps.setMaxConcurrentSteps(props, maxConcurrentSteps); } HadoopFlow flow = (HadoopFlow) new HadoopFlowConnector(props).connect(def); return flow; }
From source file:org.springframework.data.mongodb.config.ServerAddressPropertyEditor.java
@Override public void setAsText(String replicaSetString) { String[] replicaSetStringArray = StringUtils.commaDelimitedListToStringArray(replicaSetString); Set<ServerAddress> serverAddresses = new HashSet<ServerAddress>(replicaSetStringArray.length); for (String element : replicaSetStringArray) { ServerAddress address = parseServerAddress(element); if (address != null) { serverAddresses.add(address); }/*from w ww . j av a 2 s. c om*/ } if (serverAddresses.isEmpty()) { throw new IllegalArgumentException( "Could not resolve at least one server of the replica set configuration! Validate your config!"); } setValue(serverAddresses.toArray(new ServerAddress[serverAddresses.size()])); }
From source file:org.springframework.flex.config.RemotingAnnotationPostProcessor.java
/** * //from w w w . j a v a 2 s .c o m * {@inheritDoc} */ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Set<RemotingDestinationMetadata> remoteBeans = findRemotingDestinations(beanFactory); if (remoteBeans.size() > 0) { Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, "In order for services to be exported via the @RemotingDestination annotation, the current BeanFactory must be a BeanDefinitionRegistry."); } BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (RemotingDestinationMetadata remotingDestinationConfig : remoteBeans) { BeanDefinitionBuilder exporterBuilder = BeanDefinitionBuilder .rootBeanDefinition(RemotingDestinationExporter.class); exporterBuilder.getRawBeanDefinition().setRole(BeanDefinition.ROLE_INFRASTRUCTURE); RemotingDestination remotingDestination = remotingDestinationConfig.getRemotingDestination(); String messageBrokerId = StringUtils.hasText(remotingDestination.messageBroker()) ? remotingDestination.messageBroker() : BeanIds.MESSAGE_BROKER; String destinationId = StringUtils.hasText(remotingDestination.value()) ? remotingDestination.value() : remotingDestinationConfig.getBeanName(); String[] channels = null; for (String channelValue : remotingDestination.channels()) { channelValue = beanFactory.resolveEmbeddedValue(channelValue); String[] parsedChannels = StringUtils .trimArrayElements(StringUtils.commaDelimitedListToStringArray(channelValue)); channels = StringUtils.mergeStringArrays(channels, parsedChannels); } exporterBuilder.addPropertyReference(MESSAGE_BROKER_PROPERTY, messageBrokerId); exporterBuilder.addPropertyValue(SERVICE_PROPERTY, remotingDestinationConfig.getBeanName()); exporterBuilder.addDependsOn(remotingDestinationConfig.getBeanName()); exporterBuilder.addPropertyValue(DESTINATION_ID_PROPERTY, destinationId); exporterBuilder.addPropertyValue(CHANNELS_PROPERTY, channels); exporterBuilder.addPropertyValue(INCLUDE_METHODS_PROPERTY, remotingDestinationConfig.getIncludeMethods()); exporterBuilder.addPropertyValue(EXCLUDE_METHODS_PROPERTY, remotingDestinationConfig.getExcludeMethods()); exporterBuilder.addPropertyValue(SERVICE_ADAPTER_PROPERTY, remotingDestination.serviceAdapter()); BeanDefinitionReaderUtils.registerWithGeneratedName(exporterBuilder.getBeanDefinition(), registry); } }
From source file:org.springframework.integration.http.support.DefaultHttpHeaderMapper.java
private void setHttpHeader(HttpHeaders target, String name, Object value) { if (ACCEPT.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (Object type : values) { if (type instanceof MediaType) { acceptableMediaTypes.add((MediaType) type); } else if (type instanceof String) { acceptableMediaTypes.addAll(MediaType.parseMediaTypes((String) type)); } else { Class<?> clazz = (type != null) ? type.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); }/*from www . jav a 2s.com*/ } target.setAccept(acceptableMediaTypes); } } else if (value instanceof MediaType) { target.setAccept(Collections.singletonList((MediaType) value)); } else if (value instanceof String[]) { List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>(); for (String next : (String[]) value) { acceptableMediaTypes.add(MediaType.parseMediaType(next)); } target.setAccept(acceptableMediaTypes); } else if (value instanceof String) { target.setAccept(MediaType.parseMediaTypes((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Accept' header value, but received: " + clazz); } } else if (ACCEPT_CHARSET.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } else { Class<?> clazz = (charset != null) ? charset.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } target.setAcceptCharset(acceptableCharsets); } } else if (value instanceof Charset[] || value instanceof String[]) { List<Charset> acceptableCharsets = new ArrayList<Charset>(); Object[] values = ObjectUtils.toObjectArray(value); for (Object charset : values) { if (charset instanceof Charset) { acceptableCharsets.add((Charset) charset); } else if (charset instanceof String) { acceptableCharsets.add(Charset.forName((String) charset)); } } target.setAcceptCharset(acceptableCharsets); } else if (value instanceof Charset) { target.setAcceptCharset(Collections.singletonList((Charset) value)); } else if (value instanceof String) { String[] charsets = StringUtils.commaDelimitedListToStringArray((String) value); List<Charset> acceptableCharsets = new ArrayList<Charset>(); for (String charset : charsets) { acceptableCharsets.add(Charset.forName(charset.trim())); } target.setAcceptCharset(acceptableCharsets); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Charset or String value for 'Accept-Charset' header value, but received: " + clazz); } } else if (ALLOW.equalsIgnoreCase(name)) { if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (Object method : values) { if (method instanceof HttpMethod) { allowedMethods.add((HttpMethod) method); } else if (method instanceof String) { allowedMethods.add(HttpMethod.valueOf((String) method)); } else { Class<?> clazz = (method != null) ? method.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } target.setAllow(allowedMethods); } } else { if (value instanceof HttpMethod) { target.setAllow(Collections.singleton((HttpMethod) value)); } else if (value instanceof HttpMethod[]) { Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (HttpMethod next : (HttpMethod[]) value) { allowedMethods.add(next); } target.setAllow(allowedMethods); } else if (value instanceof String || value instanceof String[]) { String[] values = (value instanceof String[]) ? (String[]) value : StringUtils.commaDelimitedListToStringArray((String) value); Set<HttpMethod> allowedMethods = new HashSet<HttpMethod>(); for (String next : values) { allowedMethods.add(HttpMethod.valueOf(next.trim())); } target.setAllow(allowedMethods); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected HttpMethod or String value for 'Allow' header value, but received: " + clazz); } } } else if (CACHE_CONTROL.equalsIgnoreCase(name)) { if (value instanceof String) { target.setCacheControl((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Cache-Control' header value, but received: " + clazz); } } else if (CONTENT_LENGTH.equalsIgnoreCase(name)) { if (value instanceof Number) { target.setContentLength(((Number) value).longValue()); } else if (value instanceof String) { target.setContentLength(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Number or String value for 'Content-Length' header value, but received: " + clazz); } } else if (CONTENT_TYPE.equalsIgnoreCase(name)) { if (value instanceof MediaType) { target.setContentType((MediaType) value); } else if (value instanceof String) { target.setContentType(MediaType.parseMediaType((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected MediaType or String value for 'Content-Type' header value, but received: " + clazz); } } else if (DATE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setDate(((Date) value).getTime()); } else if (value instanceof Number) { target.setDate(((Number) value).longValue()); } else if (value instanceof String) { target.setDate(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Date' header value, but received: " + clazz); } } else if (ETAG.equalsIgnoreCase(name)) { if (value instanceof String) { target.setETag((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'ETag' header value, but received: " + clazz); } } else if (EXPIRES.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setExpires(((Date) value).getTime()); } else if (value instanceof Number) { target.setExpires(((Number) value).longValue()); } else if (value instanceof String) { target.setExpires(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Expires' header value, but received: " + clazz); } } else if (IF_MODIFIED_SINCE.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setIfModifiedSince(((Date) value).getTime()); } else if (value instanceof Number) { target.setIfModifiedSince(((Number) value).longValue()); } else if (value instanceof String) { target.setIfModifiedSince(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'If-Modified-Since' header value, but received: " + clazz); } } else if (IF_NONE_MATCH.equalsIgnoreCase(name)) { if (value instanceof String) { target.setIfNoneMatch((String) value); } else if (value instanceof String[]) { String delmitedString = StringUtils.arrayToCommaDelimitedString((String[]) value); target.setIfNoneMatch(delmitedString); } else if (value instanceof Collection) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { List<String> ifNoneMatchList = new ArrayList<String>(); for (Object next : values) { if (next instanceof String) { ifNoneMatchList.add((String) next); } else { Class<?> clazz = (next != null) ? next.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'If-None-Match' header value, but received: " + clazz); } } target.setIfNoneMatch(ifNoneMatchList); } } } else if (LAST_MODIFIED.equalsIgnoreCase(name)) { if (value instanceof Date) { target.setLastModified(((Date) value).getTime()); } else if (value instanceof Number) { target.setLastModified(((Number) value).longValue()); } else if (value instanceof String) { target.setLastModified(Long.parseLong((String) value)); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected Date, Number, or String value for 'Last-Modified' header value, but received: " + clazz); } } else if (LOCATION.equalsIgnoreCase(name)) { if (value instanceof URI) { target.setLocation((URI) value); } else if (value instanceof String) { try { target.setLocation(new URI((String) value)); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected URI or String value for 'Location' header value, but received: " + clazz); } } else if (PRAGMA.equalsIgnoreCase(name)) { if (value instanceof String) { target.setPragma((String) value); } else { Class<?> clazz = (value != null) ? value.getClass() : null; throw new IllegalArgumentException( "Expected String value for 'Pragma' header value, but received: " + clazz); } } else if (value instanceof String) { target.set(name, (String) value); } else if (value instanceof String[]) { for (String next : (String[]) value) { target.add(name, next); } } else if (value instanceof Iterable<?>) { for (Object next : (Iterable<?>) value) { String convertedValue = null; if (next instanceof String) { convertedValue = (String) next; } else { convertedValue = this.convertToString(value); } if (StringUtils.hasText(convertedValue)) { target.add(name, (String) next); } else { logger.warn("Element of the header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter " + "is available. Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } } else { String convertedValue = this.convertToString(value); if (StringUtils.hasText(convertedValue)) { target.set(name, convertedValue); } else { logger.warn("Header '" + name + "' with value '" + value + "' will not be set since it is not a String and no Converter " + "is available. Consider registering a Converter with ConversionService (e.g., <int:converter>)"); } } }
From source file:org.springframework.ldap.config.ContextSourceParser.java
private void populatePoolValidationProperties(BeanDefinitionBuilder builder, Element element, boolean testOnBorrow, boolean testOnReturn, boolean testWhileIdle) { builder.addPropertyValue("testOnBorrow", testOnBorrow); builder.addPropertyValue("testOnReturn", testOnReturn); builder.addPropertyValue("testWhileIdle", testWhileIdle); BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder .rootBeanDefinition(DefaultDirContextValidator.class); validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, "")); validatorBuilder.addPropertyValue("filter", getString(element, ATT_VALIDATION_QUERY_FILTER, DefaultDirContextValidator.DEFAULT_FILTER)); String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF); if (StringUtils.hasText(searchControlsRef)) { validatorBuilder.addPropertyReference("searchControls", searchControlsRef); }/*from w w w . j a va 2 s. co m*/ builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition()); builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); builder.addPropertyValue("numTestsPerEvictionRun", getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN)); builder.addPropertyValue("minEvictableIdleTimeMillis", getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS, CommunicationException.class.getName()); String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions); Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>(); for (String className : strings) { try { nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e); } } builder.addPropertyValue("nonTransientExceptions", nonTransientExceptionClasses); }
From source file:org.springframework.ldap.config.ContextSourceParser.java
private void populatePoolValidationProperties(BeanDefinitionBuilder builder, Element element) { BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder .rootBeanDefinition(org.springframework.ldap.pool2.validation.DefaultDirContextValidator.class); validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, "")); validatorBuilder.addPropertyValue("filter", getString(element, ATT_VALIDATION_QUERY_FILTER, org.springframework.ldap.pool2.validation.DefaultDirContextValidator.DEFAULT_FILTER)); String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF); if (StringUtils.hasText(searchControlsRef)) { validatorBuilder.addPropertyReference("searchControls", searchControlsRef); }// w ww .j a v a2 s . c om builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition()); String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS, CommunicationException.class.getName()); String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions); Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>(); for (String className : strings) { try { nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e); } } builder.addPropertyValue("nonTransientExceptions", nonTransientExceptionClasses); }
From source file:org.springframework.orm.hibernate3.SessionFactoryBuilderSupport.java
/** * Populate the underlying {@code Configuration} instance with the various * properties of this builder. Customization may be performed through * {@code pre*} and {@code post*} methods. * @see #preBuildSessionFactory()//from ww w . ja v a2 s. c o m * @see #postProcessMappings() * @see #postBuildSessionFactory() * @see #postBuildSessionFactory() */ protected final SessionFactory doBuildSessionFactory() throws Exception { initializeConfigurationIfNecessary(); if (this.dataSource != null) { // Make given DataSource available for SessionFactory configuration. configTimeDataSourceHolder.set(this.dataSource); } if (this.jtaTransactionManager != null) { // Make Spring-provided JTA TransactionManager available. configTimeTransactionManagerHolder.set(this.jtaTransactionManager); } if (this.cacheRegionFactory != null) { // Make Spring-provided Hibernate RegionFactory available. configTimeRegionFactoryHolder.set(this.cacheRegionFactory); } if (this.lobHandler != null) { // Make given LobHandler available for SessionFactory configuration. // Do early because because mapping resource might refer to custom types. configTimeLobHandlerHolder.set(this.lobHandler); } try { if (isExposeTransactionAwareSessionFactory()) { // Set Hibernate 3.1+ CurrentSessionContext implementation, // providing the Spring-managed Session as current Session. // Can be overridden by a custom value for the corresponding Hibernate property. this.configuration.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, SpringSessionContext.class.getName()); } if (this.jtaTransactionManager != null) { // Set Spring-provided JTA TransactionManager as Hibernate property. this.configuration.setProperty(Environment.TRANSACTION_STRATEGY, JTATransactionFactory.class.getName()); this.configuration.setProperty(Environment.TRANSACTION_MANAGER_STRATEGY, LocalTransactionManagerLookup.class.getName()); } else { // Makes the Hibernate Session aware of the presence of a Spring-managed transaction. // Also sets connection release mode to ON_CLOSE by default. this.configuration.setProperty(Environment.TRANSACTION_STRATEGY, SpringTransactionFactory.class.getName()); } if (this.entityInterceptor != null) { // Set given entity interceptor at SessionFactory level. this.configuration.setInterceptor(this.entityInterceptor); } if (this.namingStrategy != null) { // Pass given naming strategy to Hibernate Configuration. this.configuration.setNamingStrategy(this.namingStrategy); } if (this.typeDefinitions != null) { // Register specified Hibernate type definitions. // Use reflection for compatibility with both Hibernate 3.3 and 3.5: // the returned Mappings object changed from a class to an interface. Method createMappings = Configuration.class.getMethod("createMappings"); Method addTypeDef = createMappings.getReturnType().getMethod("addTypeDef", String.class, String.class, Properties.class); Object mappings = ReflectionUtils.invokeMethod(createMappings, this.configuration); for (TypeDefinitionBean typeDef : this.typeDefinitions) { ReflectionUtils.invokeMethod(addTypeDef, mappings, typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters()); } } if (this.filterDefinitions != null) { // Register specified Hibernate FilterDefinitions. for (FilterDefinition filterDef : this.filterDefinitions) { this.configuration.addFilterDefinition(filterDef); } } if (this.configLocations != null) { for (Resource resource : this.configLocations) { // Load Hibernate configuration from given location. this.configuration.configure(resource.getURL()); } } if (this.hibernateProperties != null) { // Add given Hibernate properties to Configuration. this.configuration.addProperties(this.hibernateProperties); } if (dataSource != null) { Class<?> providerClass = LocalDataSourceConnectionProvider.class; if (isUseTransactionAwareDataSource() || dataSource instanceof TransactionAwareDataSourceProxy) { providerClass = TransactionAwareDataSourceConnectionProvider.class; } else if (this.configuration.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) { providerClass = LocalJtaDataSourceConnectionProvider.class; } // Set Spring-provided DataSource as Hibernate ConnectionProvider. this.configuration.setProperty(Environment.CONNECTION_PROVIDER, providerClass.getName()); } if (this.cacheRegionFactory != null) { // Expose Spring-provided Hibernate RegionFactory. this.configuration.setProperty(Environment.CACHE_REGION_FACTORY, "org.springframework.orm.hibernate3.LocalRegionFactoryProxy"); } if (this.mappingResources != null) { // Register given Hibernate mapping definitions, contained in resource files. for (String mapping : this.mappingResources) { Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader); this.configuration.addInputStream(resource.getInputStream()); } } if (this.mappingLocations != null) { // Register given Hibernate mapping definitions, contained in resource files. for (Resource resource : this.mappingLocations) { this.configuration.addInputStream(resource.getInputStream()); } } if (this.cacheableMappingLocations != null) { // Register given cacheable Hibernate mapping definitions, read from the file system. for (Resource resource : this.cacheableMappingLocations) { this.configuration.addCacheableFile(resource.getFile()); } } if (this.mappingJarLocations != null) { // Register given Hibernate mapping definitions, contained in jar files. for (Resource resource : this.mappingJarLocations) { this.configuration.addJar(resource.getFile()); } } if (this.mappingDirectoryLocations != null) { // Register all Hibernate mapping definitions in the given directories. for (Resource resource : this.mappingDirectoryLocations) { File file = resource.getFile(); if (!file.isDirectory()) { throw new IllegalArgumentException( "Mapping directory location [" + resource + "] does not denote a directory"); } this.configuration.addDirectory(file); } } // Tell Hibernate to eagerly compile the mappings that we registered, // for availability of the mapping information in further processing. postProcessMappings(); this.configuration.buildMappings(); if (this.entityCacheStrategies != null) { // Register cache strategies for mapped entities. for (Enumeration<?> classNames = this.entityCacheStrategies.propertyNames(); classNames .hasMoreElements();) { String className = (String) classNames.nextElement(); String[] strategyAndRegion = StringUtils .commaDelimitedListToStringArray(this.entityCacheStrategies.getProperty(className)); if (strategyAndRegion.length > 1) { // method signature declares return type as Configuration on Hibernate 3.6 // but as void on Hibernate 3.3 and 3.5 Method setCacheConcurrencyStrategy = Configuration.class .getMethod("setCacheConcurrencyStrategy", String.class, String.class, String.class); ReflectionUtils.invokeMethod(setCacheConcurrencyStrategy, this.configuration, className, strategyAndRegion[0], strategyAndRegion[1]); } else if (strategyAndRegion.length > 0) { this.configuration.setCacheConcurrencyStrategy(className, strategyAndRegion[0]); } } } if (this.collectionCacheStrategies != null) { // Register cache strategies for mapped collections. for (Enumeration<?> collRoles = this.collectionCacheStrategies.propertyNames(); collRoles .hasMoreElements();) { String collRole = (String) collRoles.nextElement(); String[] strategyAndRegion = StringUtils .commaDelimitedListToStringArray(this.collectionCacheStrategies.getProperty(collRole)); if (strategyAndRegion.length > 1) { this.configuration.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0], strategyAndRegion[1]); } else if (strategyAndRegion.length > 0) { this.configuration.setCollectionCacheConcurrencyStrategy(collRole, strategyAndRegion[0]); } } } if (this.eventListeners != null) { // Register specified Hibernate event listeners. for (Map.Entry<String, Object> entry : this.eventListeners.entrySet()) { String listenerType = entry.getKey(); Object listenerObject = entry.getValue(); if (listenerObject instanceof Collection) { Collection<?> listeners = (Collection<?>) listenerObject; EventListeners listenerRegistry = this.configuration.getEventListeners(); Object[] listenerArray = (Object[]) Array .newInstance(listenerRegistry.getListenerClassFor(listenerType), listeners.size()); listenerArray = listeners.toArray(listenerArray); this.configuration.setListeners(listenerType, listenerArray); } else { this.configuration.setListener(listenerType, listenerObject); } } } preBuildSessionFactory(); // Perform custom post-processing in subclasses. postProcessConfiguration(); // Build SessionFactory instance. logger.info("Building new Hibernate SessionFactory"); return this.sessionFactory = newSessionFactory(); } finally { if (dataSource != null) { SessionFactoryBuilderSupport.configTimeDataSourceHolder.remove(); } if (this.jtaTransactionManager != null) { SessionFactoryBuilderSupport.configTimeTransactionManagerHolder.remove(); } if (this.cacheRegionFactory != null) { SessionFactoryBuilderSupport.configTimeRegionFactoryHolder.remove(); } if (this.lobHandler != null) { SessionFactoryBuilderSupport.configTimeLobHandlerHolder.remove(); } postBuildSessionFactory(); } }
From source file:org.springframework.richclient.security.support.AbstractSecurityController.java
/** * Run all the requested post-processor actions. * @param controlledObject Object being controlled * @param authorized state that has been installed on controlledObject *//*from ww w . j a v a 2 s .co m*/ protected void runPostProcessorActions(Object controlledObject, boolean authorized) { String actions = getPostProcessorActionsToRun(); if (logger.isDebugEnabled()) { logger.debug("Run post-processors actions: " + actions); } String[] actionIds = StringUtils.commaDelimitedListToStringArray(actions); for (int i = 0; i < actionIds.length; i++) { doPostProcessorAction(actionIds[i], controlledObject, authorized); } }
From source file:org.springframework.richclient.security.support.AbstractSecurityController.java
/** * Validate our configuration./*from w ww .ja v a 2 s . co m*/ * @throws Exception */ public void afterPropertiesSet() throws Exception { // Ensure that all post-processors requested are registered String[] actions = StringUtils.commaDelimitedListToStringArray(getPostProcessorActionsToRun()); for (int i = 0; i < actions.length; i++) { if (!postProcessorActionIds.contains(actions[i])) { throw new IllegalArgumentException( "Requested post-processor action '" + actions[i] + "' is not registered."); } } }
From source file:org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.java
private Map<String, List<ConfigAttribute>> parseProtectPointcuts(ParserContext parserContext, List<Element> protectPointcutElts) { Map<String, List<ConfigAttribute>> pointcutMap = new LinkedHashMap<String, List<ConfigAttribute>>(); for (Element childElt : protectPointcutElts) { String accessConfig = childElt.getAttribute(ATT_ACCESS); String expression = childElt.getAttribute(ATT_EXPRESSION); if (!StringUtils.hasText(accessConfig)) { parserContext.getReaderContext().error("Access configuration required", parserContext.extractSource(childElt)); }/* w ww .j av a 2 s . c om*/ if (!StringUtils.hasText(expression)) { parserContext.getReaderContext().error("Pointcut expression required", parserContext.extractSource(childElt)); } String[] attributeTokens = StringUtils.commaDelimitedListToStringArray(accessConfig); List<ConfigAttribute> attributes = new ArrayList<>(attributeTokens.length); for (String token : attributeTokens) { attributes.add(new SecurityConfig(token)); } pointcutMap.put(expression, attributes); } return pointcutMap; }