Example usage for org.springframework.util StringUtils commaDelimitedListToStringArray

List of usage examples for org.springframework.util StringUtils commaDelimitedListToStringArray

Introduction

In this page you can find the example usage for org.springframework.util StringUtils commaDelimitedListToStringArray.

Prototype

public static String[] commaDelimitedListToStringArray(@Nullable String str) 

Source Link

Document

Convert a comma delimited list (e.g., a row from a CSV file) into an array of strings.

Usage

From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.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);
                    }// ww  w  .  ja v  a2  s  .  c  o m
                }
                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>();
                Collections.addAll(allowedMethods, (HttpMethod[]) value);
                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 (MessageHeaders.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) {
            try {
                target.setDate(Long.parseLong((String) value));
            } catch (NumberFormatException e) {
                target.setDate(this.getFirstDate((String) value, DATE));
            }
        } 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) {
            try {
                target.setExpires(Long.parseLong((String) value));
            } catch (NumberFormatException e) {
                target.setExpires(this.getFirstDate((String) value, EXPIRES));
            }
        } 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) {
            try {
                target.setIfModifiedSince(Long.parseLong((String) value));
            } catch (NumberFormatException e) {
                target.setIfModifiedSince(this.getFirstDate((String) value, IF_MODIFIED_SINCE));
            }
        } 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_UNMODIFIED_SINCE.equalsIgnoreCase(name)) {
        String ifUnmodifiedSinceValue = null;
        if (value instanceof Date) {
            ifUnmodifiedSinceValue = this.formatDate(((Date) value).getTime());
        } else if (value instanceof Number) {
            ifUnmodifiedSinceValue = this.formatDate(((Number) value).longValue());
        } else if (value instanceof String) {
            try {
                ifUnmodifiedSinceValue = this.formatDate(Long.parseLong((String) value));
            } catch (NumberFormatException e) {
                long longValue = this.getFirstDate((String) value, IF_UNMODIFIED_SINCE);
                ifUnmodifiedSinceValue = this.formatDate(longValue);
            }
        } else {
            Class<?> clazz = (value != null) ? value.getClass() : null;
            throw new IllegalArgumentException(
                    "Expected Date, Number, or String value for 'If-Unmodified-Since' header value, but received: "
                            + clazz);
        }
        target.set(IF_UNMODIFIED_SINCE, ifUnmodifiedSinceValue);
    } 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) {
            try {
                target.setLastModified(Long.parseLong((String) value));
            } catch (NumberFormatException e) {
                target.setLastModified(this.getFirstDate((String) value, LAST_MODIFIED));
            }
        } 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, convertedValue);
            } 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.cloud.stream.binder.kafka.streams.KafkaStreamsStreamListenerSetupMethodOrchestrator.java

private KStream<?, ?> getkStream(String inboundName, KafkaStreamsStateStoreProperties storeSpec,
        BindingProperties bindingProperties, StreamsBuilder streamsBuilder, Serde<?> keySerde,
        Serde<?> valueSerde, Topology.AutoOffsetReset autoOffsetReset) {
    if (storeSpec != null) {
        StoreBuilder storeBuilder = buildStateStore(storeSpec);
        streamsBuilder.addStateStore(storeBuilder);
        if (LOG.isInfoEnabled()) {
            LOG.info("state store " + storeBuilder.name() + " added to topology");
        }/*from ww  w .j  a v a 2 s. c om*/
    }
    String[] bindingTargets = StringUtils
            .commaDelimitedListToStringArray(this.bindingServiceProperties.getBindingDestination(inboundName));

    KStream<?, ?> stream = streamsBuilder.stream(Arrays.asList(bindingTargets),
            Consumed.with(keySerde, valueSerde).withOffsetResetPolicy(autoOffsetReset));
    final boolean nativeDecoding = this.bindingServiceProperties.getConsumerProperties(inboundName)
            .isUseNativeDecoding();
    if (nativeDecoding) {
        LOG.info("Native decoding is enabled for " + inboundName
                + ". Inbound deserialization done at the broker.");
    } else {
        LOG.info("Native decoding is disabled for " + inboundName
                + ". Inbound message conversion done by Spring Cloud Stream.");
    }

    stream = stream.mapValues((value) -> {
        Object returnValue;
        String contentType = bindingProperties.getContentType();
        if (value != null && !StringUtils.isEmpty(contentType) && !nativeDecoding) {
            returnValue = MessageBuilder.withPayload(value).setHeader(MessageHeaders.CONTENT_TYPE, contentType)
                    .build();
        } else {
            returnValue = value;
        }
        return returnValue;
    });
    return stream;
}

From source file:org.springframework.cloud.stream.binding.BindingService.java

@SuppressWarnings("unchecked")
public <T> Collection<Binding<T>> bindConsumer(T input, String inputName) {
    String bindingTarget = this.bindingServiceProperties.getBindingDestination(inputName);
    String[] bindingTargets = StringUtils.commaDelimitedListToStringArray(bindingTarget);
    Collection<Binding<T>> bindings = new ArrayList<>();
    Binder<T, ConsumerProperties, ?> binder = (Binder<T, ConsumerProperties, ?>) getBinder(inputName,
            input.getClass());/* w  w w .jav a  2 s  . c  o m*/
    ConsumerProperties consumerProperties = this.bindingServiceProperties.getConsumerProperties(inputName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedConsumerProperties(inputName);
        ExtendedConsumerProperties extendedConsumerProperties = new ExtendedConsumerProperties(extension);
        BeanUtils.copyProperties(consumerProperties, extendedConsumerProperties);
        consumerProperties = extendedConsumerProperties;
    }
    validate(consumerProperties);
    for (String target : bindingTargets) {
        Binding<T> binding = binder.bindConsumer(target, bindingServiceProperties.getGroup(inputName), input,
                consumerProperties);
        bindings.add(binding);
    }
    bindings = Collections.unmodifiableCollection(bindings);
    this.consumerBindings.put(inputName, new ArrayList<Binding<?>>(bindings));
    return bindings;
}

From source file:org.springframework.cloud.stream.binding.ChannelBindingService.java

@SuppressWarnings("unchecked")
public Collection<Binding<MessageChannel>> bindConsumer(MessageChannel inputChannel, String inputChannelName) {
    String channelBindingTarget = this.channelBindingServiceProperties.getBindingDestination(inputChannelName);
    String[] channelBindingTargets = StringUtils.commaDelimitedListToStringArray(channelBindingTarget);
    List<Binding<MessageChannel>> bindings = new ArrayList<>();
    Binder<MessageChannel, ConsumerProperties, ?> binder = (Binder<MessageChannel, ConsumerProperties, ?>) getBinderForChannel(
            inputChannelName);//w  w w  .  j  av  a  2 s  .  c o  m
    ConsumerProperties consumerProperties = this.channelBindingServiceProperties
            .getConsumerProperties(inputChannelName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedConsumerProperties(inputChannelName);
        ExtendedConsumerProperties extendedConsumerProperties = new ExtendedConsumerProperties(extension);
        BeanUtils.copyProperties(consumerProperties, extendedConsumerProperties);
        consumerProperties = extendedConsumerProperties;
    }
    validate(consumerProperties);
    for (String target : channelBindingTargets) {
        Binding<MessageChannel> binding = binder.bindConsumer(target,
                channelBindingServiceProperties.getGroup(inputChannelName), inputChannel, consumerProperties);
        bindings.add(binding);
    }
    this.consumerBindings.put(inputChannelName, bindings);
    return bindings;
}

From source file:org.springframework.cloud.stream.config.BinderFactoryConfiguration.java

static Collection<BinderType> parseBinderConfigurations(ClassLoader classLoader, Resource resource)
        throws IOException, ClassNotFoundException {
    Properties properties = PropertiesLoaderUtils.loadProperties(resource);
    Collection<BinderType> parsedBinderConfigurations = new ArrayList<>();
    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String binderType = (String) entry.getKey();
        String[] binderConfigurationClassNames = StringUtils
                .commaDelimitedListToStringArray((String) entry.getValue());
        Class<?>[] binderConfigurationClasses = new Class[binderConfigurationClassNames.length];
        int i = 0;
        for (String binderConfigurationClassName : binderConfigurationClassNames) {
            binderConfigurationClasses[i++] = ClassUtils.forName(binderConfigurationClassName, classLoader);
        }/*ww  w.j a v  a2  s .com*/
        parsedBinderConfigurations.add(new BinderType(binderType, binderConfigurationClasses));
    }
    return parsedBinderConfigurations;
}

From source file:org.springframework.core.env.AbstractEnvironment.java

/**
 * Return the set of active profiles as explicitly set through
 * {@link #setActiveProfiles} or if the current set of active profiles
 * is empty, check for the presence of the {@value #ACTIVE_PROFILES_PROPERTY_NAME}
 * property and assign its value to the set of active profiles.
 * @see #getActiveProfiles()//from  www .  ja  v a2  s. c  o m
 * @see #ACTIVE_PROFILES_PROPERTY_NAME
 */
protected Set<String> doGetActiveProfiles() {
    synchronized (this.activeProfiles) {
        if (this.activeProfiles.isEmpty()) {
            String profiles = getProperty(ACTIVE_PROFILES_PROPERTY_NAME);
            if (StringUtils.hasText(profiles)) {
                setActiveProfiles(
                        StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(profiles)));
            }
        }
        return this.activeProfiles;
    }
}

From source file:org.springframework.core.env.AbstractEnvironment.java

/**
 * Return the set of default profiles explicitly set via
 * {@link #setDefaultProfiles(String...)} or if the current set of default profiles
 * consists only of {@linkplain #getReservedDefaultProfiles() reserved default
 * profiles}, then check for the presence of the
 * {@value #DEFAULT_PROFILES_PROPERTY_NAME} property and assign its value (if any)
 * to the set of default profiles./*from w w w  . ja v  a 2  s. com*/
 * @see #AbstractEnvironment()
 * @see #getDefaultProfiles()
 * @see #DEFAULT_PROFILES_PROPERTY_NAME
 * @see #getReservedDefaultProfiles()
 */
protected Set<String> doGetDefaultProfiles() {
    synchronized (this.defaultProfiles) {
        if (this.defaultProfiles.equals(getReservedDefaultProfiles())) {
            String profiles = getProperty(DEFAULT_PROFILES_PROPERTY_NAME);
            if (StringUtils.hasText(profiles)) {
                setDefaultProfiles(
                        StringUtils.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(profiles)));
            }
        }
        return this.defaultProfiles;
    }
}

From source file:org.springframework.core.io.support.SpringFactoriesLoader.java

private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) {
    MultiValueMap<String, String> result = cache.get(classLoader);
    if (result != null)
        return result;
    try {//from   w w w.  j a  v a2 s . c o m
        Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION)
                : ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
        result = new LinkedMultiValueMap<>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            UrlResource resource = new UrlResource(url);
            Properties properties = PropertiesLoaderUtils.loadProperties(resource);
            for (Map.Entry<?, ?> entry : properties.entrySet()) {
                List<String> factoryClassNames = Arrays
                        .asList(StringUtils.commaDelimitedListToStringArray((String) entry.getValue()));
                result.addAll((String) entry.getKey(), factoryClassNames);
            }
        }
        cache.put(classLoader, result);
        return result;
    } catch (IOException ex) {
        throw new IllegalArgumentException(
                "Unable to load factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex);
    }
}

From source file:org.springframework.core.SpringFactoriesLoader.java

private static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader classLoader,
        String factoriesLocation) {

    String factoryClassName = factoryClass.getName();

    try {/*ww  w .j  a  va2 s .c  o m*/
        List<String> result = new ArrayList<String>();
        Enumeration<URL> urls = classLoader.getResources(factoriesLocation);
        while (urls.hasMoreElements()) {
            URL url = (URL) urls.nextElement();
            Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
            String factoryClassNames = properties.getProperty(factoryClassName);
            result.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(factoryClassNames)));
        }
        return result;
    } catch (IOException ex) {
        throw new IllegalArgumentException("Unable to load [" + factoryClass.getName()
                + "] factories from location [" + factoriesLocation + "]", ex);
    }

}

From source file:org.springframework.data.gemfire.config.ParsingUtils.java

@SuppressWarnings("unused")
static void parseMembershipAttributes(ParserContext parserContext, Element element,
        BeanDefinitionBuilder regionAttributesBuilder) {

    Element membershipAttributes = DomUtils.getChildElementByTagName(element, "membership-attributes");

    if (membershipAttributes != null) {
        String[] requiredRoles = StringUtils
                .commaDelimitedListToStringArray(membershipAttributes.getAttribute("required-roles"));

        String lossActionValue = membershipAttributes.getAttribute("loss-action");

        LossAction lossAction = (StringUtils.hasText(lossActionValue)
                ? LossAction.fromName(lossActionValue.toUpperCase().replace("-", "_"))
                : LossAction.NO_ACCESS);

        String resumptionActionValue = membershipAttributes.getAttribute("resumption-action");

        ResumptionAction resumptionAction = (StringUtils.hasText(resumptionActionValue)
                ? ResumptionAction.fromName(resumptionActionValue.toUpperCase().replace("-", "_"))
                : ResumptionAction.REINITIALIZE);

        regionAttributesBuilder.addPropertyValue("membershipAttributes",
                new MembershipAttributes(requiredRoles, lossAction, resumptionAction));
    }/*from   www  .j a  v a2  s .  co  m*/
}