Example usage for org.springframework.util StringUtils delimitedListToStringArray

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

Introduction

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

Prototype

public static String[] delimitedListToStringArray(@Nullable String str, @Nullable String delimiter) 

Source Link

Document

Take a String that is a delimited list and convert it into a String array.

Usage

From source file:ch.sdi.plugins.oxwall.job.OxFtpJob.java

/**
 * @see ch.sdi.core.intf.TargetJob#init()
 *//*  w  w  w . j  av a 2  s  .  c  o  m*/
@Override
public void init() throws SdiException {
    myDryRun = ConfigUtils.getBooleanProperty(myEnv, SdiMainProperties.KEY_DRYRUN, false);

    myTargetDir = ConfigUtils.getStringProperty(myEnv, SdiMainProperties.KEY_FTP_DEST_DIR);
    if (!StringUtils.hasText(myTargetDir)) {
        throw new SdiException("Property " + SdiMainProperties.KEY_FTP_DEST_DIR + " not configured",
                SdiException.EXIT_CODE_CONFIG_ERROR);
    } // if !StringUtils.hasText( targetDir )
    myTargetDir = myTargetDir.trim();

    String commandLine = ConfigUtils.getStringProperty(myEnv, SdiMainProperties.KEY_FTP_CMD_LINE);
    if (!StringUtils.hasText(commandLine)) {
        throw new SdiException("Property " + SdiMainProperties.KEY_FTP_CMD_LINE + " not configured",
                SdiException.EXIT_CODE_CONFIG_ERROR);
    } // if !StringUtils.hasText( commandLine )
    myCmdLineArgs = StringUtils.delimitedListToStringArray(commandLine, " ");

    if (!myDryRun) {
        myFtpExecutor.init(myCmdLineArgs);
        try {
            myFtpExecutor.connectAndLogin();
        } catch (IOException t) {
            throw new SdiException("Problems connecting to FTP server", SdiException.EXIT_CODE_FTP_ERROR);
        }

        mySshExecutor.init();
    } // if !myDryRun
}

From source file:org.cloudfoundry.identity.uaa.config.YamlBindingTests.java

private BindingResult bind(Object target, String values) {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource[] { new ByteArrayResource(values.getBytes()) });
    Map<Object, Object> map = factory.getObject();
    DataBinder binder = new DataBinder(target) {

        @Override/*from   ww w.  ja va  2s  .com*/
        protected void doBind(MutablePropertyValues mpvs) {
            modifyProperties(mpvs, getTarget());
            super.doBind(mpvs);
        }

        private void modifyProperties(MutablePropertyValues mpvs, Object target) {

            List<PropertyValue> list = mpvs.getPropertyValueList();
            BeanWrapperImpl bw = new BeanWrapperImpl(target);

            for (int i = 0; i < list.size(); i++) {
                PropertyValue pv = list.get(i);

                String name = pv.getName();
                StringBuilder builder = new StringBuilder();

                for (String key : StringUtils.delimitedListToStringArray(name, ".")) {
                    if (builder.length() != 0) {
                        builder.append(".");
                    }
                    builder.append(key);
                    String base = builder.toString();
                    Class<?> type = bw.getPropertyType(base);
                    if (type != null && Map.class.isAssignableFrom(type)) {
                        String suffix = name.substring(base.length());
                        Map<String, Object> nested = new LinkedHashMap<String, Object>();
                        if (bw.getPropertyValue(base) != null) {
                            @SuppressWarnings("unchecked")
                            Map<String, Object> existing = (Map<String, Object>) bw.getPropertyValue(base);
                            nested = existing;
                        } else {
                            bw.setPropertyValue(base, nested);
                        }
                        Map<String, Object> value = nested;
                        String[] tree = StringUtils.delimitedListToStringArray(suffix, ".");
                        for (int j = 1; j < tree.length - 1; j++) {
                            String subtree = tree[j];
                            value.put(subtree, nested);
                            value = nested;
                        }
                        String refName = base + suffix.replaceAll("\\.([a-zA-Z0-9]*)", "[$1]");
                        mpvs.setPropertyValueAt(new PropertyValue(refName, pv.getValue()), i);
                        break;
                    }
                }

            }

        }

    };
    binder.setIgnoreUnknownFields(false);
    LocalValidatorFactoryBean validatorFactoryBean = new LocalValidatorFactoryBean();
    validatorFactoryBean.afterPropertiesSet();
    binder.setValidator(validatorFactoryBean);
    binder.bind(new MutablePropertyValues(map));
    binder.validate();

    return binder.getBindingResult();
}

From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtilTest.java

@Before
public void setUp() throws FileNotFoundException, java.io.FileNotFoundException, NotSupportedException,
        SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {

    // Source/*from   w  w  w . ja  v a 2s . c om*/
    String[] parts = StringUtils.delimitedListToStringArray(validSourcePath, "/");
    for (String part : parts) {
        validSourcePathList.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(invalidSourcePath, "/");
    for (String part : parts) {
        invalidSourcePathList.add(part);
    }
    // Destination
    parts = StringUtils.delimitedListToStringArray(validDestinationPath, "/");
    for (String part : parts) {
        validDestinationPathList.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(invalidDestinationPath, "/");
    for (String part : parts) {
        invalidDestinationPathList.add(part);
    }
    // Logs
    parts = StringUtils.delimitedListToStringArray(validLogsPath, "/");
    for (String part : parts) {
        validLogsPathList.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(invalidLogsPath, "/");
    for (String part : parts) {
        invalidLogsPathList.add(part);
    }

    // Files
    parts = StringUtils.delimitedListToStringArray(validSourcePath + "/" + validMetaFileName, "/");
    for (String part : parts) {
        validFilePathList.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(validSourcePath + "/" + invalidMetaFileName, "/");
    for (String part : parts) {
        invalidFilePathList.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(validSourcePath + "/" + validFileName, "/");
    for (String part : parts) {
        validFilePathList2.add(part);
    }

    parts = StringUtils.delimitedListToStringArray(validDestinationPath + "/A/A/1-1 A/" + validFileName, "/");
    for (String part : parts) {
        validFilePathList3.add(part);
    }

    contentData = new ContentData("file", "text/plain", 0, "UTF-8");

    validInputStream = new FileInputStream(validSourcePath + "/" + validMetaFileName);

    context.checking(new Expectations() {
        {
            allowing(siteService).getSite("test");
            will(returnValue(siteInfo));

            allowing(siteService).getSite("fail");
            will(returnValue(null));

            allowing(siteInfo).getNodeRef();
            will(returnValue(dummyNodeRef));

            allowing(fileFolderService).searchSimple(dummyNodeRef, SiteService.DOCUMENT_LIBRARY);
            will(returnValue(dummyNodeRef));
            // Source
            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validSourcePathList, false);
            will(returnValue(fileInfo));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, invalidSourcePathList, false);
            will(returnValue(null));
            // Destination
            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validDestinationPathList, false);
            will(returnValue(fileInfo));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, invalidDestinationPathList, false);
            will(returnValue(null));
            // Logs
            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validLogsPathList, false);
            will(returnValue(fileInfo));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, invalidLogsPathList, false);
            will(returnValue(null));

            // Files
            allowing(contentService).getRawReader(contentData.getContentUrl());
            will(returnValue(contentReader));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validFilePathList, false);
            will(returnValue(fileInfo));
            allowing(fileFolderService).resolveNamePath(dummyNodeRef, invalidFilePathList, false);
            will(returnValue(null));

            allowing(fileInfo).getContentData();
            will(returnValue(contentData));

            allowing(fileInfo).getNodeRef();
            will(returnValue(dummyNodeRef));

            allowing(contentReader).getContentInputStream();
            will(returnValue(validInputStream));

            //Import documents
            allowing(fileFolderService).searchSimple(with(equal(dummyNodeRef)), with(any(String.class)));
            will(returnValue(dummyNodeRef));

            allowing(fileFolderService).create(with(equal(dummyNodeRef)), with(any(String.class)),
                    with(equal(AkDmModel.TYPE_AKDM_BYGGREDA_DOC)));
            will(returnValue(fileInfo));

            allowing(fileFolderService).create(with(equal(dummyNodeRef)), with(any(String.class)),
                    with(equal(AkDmModel.TYPE_AKDM_DOCUMENT)));
            will(returnValue(fileInfo));

            allowing(nodeService).addProperties(with(equal(dummyNodeRef)), with(any(HashMap.class)));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validFilePathList2, false);
            will(returnValue(fileInfo));

            allowing(fileFolderService).resolveNamePath(dummyNodeRef, validFilePathList3, false);
            will(returnValue(null));

            allowing(contentService).getWriter(dummyNodeRef, ContentModel.PROP_CONTENT, true);
            will(returnValue(contentWriter));

            allowing(contentWriter).setMimetype(with(any(String.class)));

            allowing(contentWriter).putContent(with(any(InputStream.class)));

            allowing(versionService).getVersionHistory(dummyNodeRef);
            will(returnValue(null));

            allowing(versionService).createVersion(with(equal(dummyNodeRef)), with(any(Map.class)));

            allowing(contentReader).exists();
            will(returnValue(true));

            allowing(sysAdminParams).getShareContext();
            will(returnValue("share"));
            allowing(sysAdminParams).getShareHost();
            will(returnValue("localhost"));
            allowing(sysAdminParams).getSharePort();
            will(returnValue(8081));
            allowing(sysAdminParams).getShareProtocol();
            will(returnValue("http"));

            allowing(transactionService).getNonPropagatingUserTransaction();
            will(returnValue(userTransaction));

            allowing(userTransaction).begin();
            allowing(userTransaction).commit();
            allowing(userTransaction).rollback();

        }
    });
}

From source file:fr.mby.portal.coreimpl.context.PropertiesAppConfigFactory.java

/**
 * Process ACL permissions map from OPA config.
 * /*from   w  w w . ja v a  2  s.c  om*/
 * @param bundleApp
 * @param appConfig
 * @param opaConfig
 * 
 * @return the map of all configured permissions.
 * @throws AppConfigNotFoundException
 */
protected Map<String, IPermission> processAclPermissions(final Bundle bundleApp, final BasicAppConfig appConfig,
        final Properties opaConfig) {
    final Map<String, IPermission> permissionsByAclName = new HashMap<String, IPermission>(4);

    // Special Permissions
    final Map<SpecialPermission, IPermission> specialPermissions = new HashMap<SpecialPermission, IPermission>(
            SpecialPermission.values().length);
    for (final SpecialPermission spEnum : SpecialPermission.values()) {
        final String finalPermissionName = this.buildFinalPermissionName(bundleApp, spEnum.name());
        final IPermission specialPerm = this.permissionFactory.build(finalPermissionName);
        specialPermissions.put(spEnum, specialPerm);
        permissionsByAclName.put(spEnum.name(), specialPerm);
    }
    appConfig.setSpecialPermissions(Collections.unmodifiableMap(specialPermissions));

    // Declared Permissions
    final String aclPermissionsVal = this.getOptionalValue(opaConfig, OpaConfigKeys.ACL_PERMISSIONS.getKey());
    final String[] aclPermissionsArray = StringUtils.delimitedListToStringArray(aclPermissionsVal,
            IAppConfigFactory.OPA_CONFIG_LIST_SPLITER);
    if (aclPermissionsArray != null) {
        for (final String aclPermissionName : aclPermissionsArray) {
            if (StringUtils.hasText(aclPermissionName)) {
                final String finalPermissionName = this.buildFinalPermissionName(bundleApp, aclPermissionName);
                final IPermission permission = this.permissionFactory.build(finalPermissionName);
                permissionsByAclName.put(aclPermissionName, permission);
            }
        }
    }
    final Set<IPermission> permissionsSet = new HashSet<IPermission>(permissionsByAclName.values());
    appConfig.setDeclaredPermissions(Collections.unmodifiableSet(permissionsSet));

    return permissionsByAclName;
}

From source file:org.eclipse.virgo.ide.runtime.internal.core.ServerPublishOperation.java

/**
 * Check if resource delta only contains static resources
 *//*from   w w  w. j a  va2s.  c o  m*/
private boolean onlyStaticResources(IModuleResourceDelta delta, Set<IModuleFile> files) {
    if (delta.getModuleResource() instanceof IModuleFolder) {
        for (IModuleResourceDelta child : delta.getAffectedChildren()) {
            if (!onlyStaticResources(child, files)) {
                return false;
            }
        }
        return true;
    } else {
        if (delta.getModuleResource() instanceof IModuleFile) {
            files.add((IModuleFile) delta.getModuleResource());
        }
        String name = delta.getModuleResource().getName();

        // make that configurable
        if (name.endsWith(".xml")) {
            IFile file = (IFile) delta.getModuleResource().getAdapter(IFile.class);
            // check for spring context xml files first but exclude
            if (!checkIfSpringConfigurationFile(file)) {
                return false;
            }
        }
        boolean isStatic = false;
        // Check the configuration options for static resources
        AntPathMatcher matcher = new AntPathMatcher();
        for (String pattern : StringUtils
                .delimitedListToStringArray(ServerUtils.getServer(server).getStaticFilenamePatterns(), ",")) {
            if (pattern.startsWith("!") && matcher.match(pattern.substring(1), name)) {
                isStatic = false;
            } else if (matcher.match(pattern, name)) {
                isStatic = true;
            }
        }
        return isStatic;
    }
}

From source file:org.web4thejob.orm.DataReaderServiceImpl.java

private DetachedCriteria toDetachedCriteria(Query query, String alias) {
    boolean hasOneToManyAssociation = false;
    DetachedCriteria detachedCriteria;/* ww w . j av a 2s .  c o  m*/
    if (alias != null) {
        detachedCriteria = DetachedCriteria.forClass(query.getTargetType(), alias);
    } else {
        detachedCriteria = DetachedCriteria.forClass(query.getTargetType());
    }

    final Map<String, String> aliases = new HashMap<String, String>();
    for (final Criterion w4tjCriterion : query.getCriteria()) {
        if (w4tjCriterion.getCondition() != null
                && (w4tjCriterion.getCondition().getOperandsNo() == 0 || (w4tjCriterion.getValue() != null
                        && StringUtils.hasText(w4tjCriterion.getValue().toString())))) {
            if (!hasOneToManyAssociation) {
                hasOneToManyAssociation = w4tjCriterion.getPropertyPath().hasOneToManySteps();
            }

            org.hibernate.criterion.Criterion hibCriterion;

            if (w4tjCriterion.isLocal()) {
                hibCriterion = toHibernateCriterion(w4tjCriterion, detachedCriteria.getAlias());
            } else {
                String aliasPath = null;
                for (final PropertyMetadata propertyMetadata : w4tjCriterion.getPropertyPath().getSteps()) {
                    if (propertyMetadata.equals(w4tjCriterion.getPropertyPath().getLastStep())) {
                        break;
                    } else if (propertyMetadata.equals(w4tjCriterion.getPropertyPath().getFirstStep())) {
                        aliasPath = propertyMetadata.getName();
                    } else {
                        aliasPath += "." + propertyMetadata.getName();
                    }

                    buildAlias(detachedCriteria, aliases, aliasPath);
                }

                hibCriterion = toHibernateCriterion(w4tjCriterion, aliases.get(aliasPath));
            }

            detachedCriteria = detachedCriteria.add(hibCriterion);
        }
    }

    if (!query.getSubqueries().isEmpty()) {
        String masterId = detachedCriteria.getAlias() + "."
                + ContextUtil.getMRS().getEntityMetadata(query.getTargetType()).getIdentifierName();
        int subqindex = 0;
        for (Subquery subquery : query.getSubqueries()) {
            subqindex += 1;
            detachedCriteria = detachedCriteria
                    .add(toHibernateSubcriterion(masterId, String.valueOf(subqindex), subquery));
        }
    }

    for (final OrderBy orderBy : query.getOrderings()) {
        PathMetadata pathMetadata = ContextUtil.getMRS().getPropertyPath(query.getTargetType(),
                StringUtils.delimitedListToStringArray(orderBy.getProperty(), Path.DELIMITER));

        String property;
        if (pathMetadata.isMultiStep()) {
            String aliasPath = null;

            if (!hasOneToManyAssociation) {
                hasOneToManyAssociation = pathMetadata.hasOneToManySteps();
            }

            for (PropertyMetadata propertyMetadata : pathMetadata.getSteps()) {
                if (propertyMetadata.equals(pathMetadata.getLastStep())) {
                    break;
                } else if (propertyMetadata.equals(pathMetadata.getFirstStep())) {
                    aliasPath = propertyMetadata.getName();
                } else {
                    aliasPath += "." + propertyMetadata.getName();
                }

                buildAlias(detachedCriteria, aliases, aliasPath);
            }
            property = aliases.get(aliasPath) + "." + pathMetadata.getLastStep().getName();
        } else {
            property = orderBy.getProperty();
        }

        if (orderBy.isDescending()) {
            detachedCriteria = detachedCriteria.addOrder(Order.desc(property));
        } else {
            detachedCriteria = detachedCriteria.addOrder(Order.asc(property));
        }
    }

    if (hasOneToManyAssociation) {
        detachedCriteria = detachedCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    }

    return detachedCriteria;
}

From source file:org.web4thejob.web.panel.base.AbstractMutablePanel.java

@Override
public Set<ConstraintViolation<Entity>> validate() {
    if (hasTargetEntity()) {

        for (Binding binding : dataBinder.getAllBindings()) {
            if (binding.getComponent() != null) {
                Clients.clearWrongValue(binding.getComponent());
            }//from  ww  w.j  a va2 s  .  c om
        }

        dataBinder.saveAll();
        Set<ConstraintViolation<Entity>> violations = getTargetEntity().validate();
        for (final ConstraintViolation<Entity> violation : violations) {
            final PathMetadata pathMetadata = ContextUtil.getMRS().getPropertyPath(getTargetType(),
                    StringUtils.delimitedListToStringArray(violation.getPropertyPath().toString(), "."));

            final Component comp = getBoundComponent(pathMetadata);
            if (comp != null) {
                ensureVisible(comp);
                Clients.wrongValue(comp, violation.getMessage());
            }
        }
        dataBinder.loadAll();
        return violations;
    }

    return Collections.emptySet();
}

From source file:com.ei.itop.common.tag.MessageTag.java

/**
 * Resolve the given arguments Object into an arguments array.
 * @param arguments the specified arguments Object
 * @return the resolved arguments as array
 * @throws JspException if argument conversion failed
 * @see #setArguments/*from   ww w. j  a v a  2 s .  c  o  m*/
 */
protected Object[] resolveArguments(Object arguments) throws JspException {
    if (arguments instanceof String) {
        String[] stringArray = StringUtils.delimitedListToStringArray((String) arguments,
                this.argumentSeparator);
        if (stringArray.length == 1) {
            Object argument = ExpressionEvaluationUtils.evaluate("argument", stringArray[0], pageContext);
            if (argument != null && argument.getClass().isArray()) {
                return ObjectUtils.toObjectArray(argument);
            } else {
                return new Object[] { argument };
            }
        } else {
            Object[] argumentsArray = new Object[stringArray.length];
            for (int i = 0; i < stringArray.length; i++) {
                argumentsArray[i] = ExpressionEvaluationUtils.evaluate("argument[" + i + "]", stringArray[i],
                        pageContext);
            }
            return argumentsArray;
        }
    } else if (arguments instanceof Object[]) {
        return (Object[]) arguments;
    } else if (arguments instanceof Collection) {
        return ((Collection) arguments).toArray();
    } else if (arguments != null) {
        // Assume a single argument object.
        return new Object[] { arguments };
    } else {
        return null;
    }
}

From source file:fr.mby.portal.coreimpl.context.PropertiesAppConfigFactory.java

/**
 * Process ACL roles map from OPA config.
 * /*ww w. j  av  a 2s. c o m*/
 * @param bundleApp
 * @param appConfig
 * @param opaConfig
 * @param permissionsMap
 * 
 * @return the map of all configured roles.
 * @throws AppConfigNotFoundException
 * @throws BadAppConfigException
 */
protected Map<String, IRole> processAclRoles(final Bundle bundleApp, final BasicAppConfig appConfig,
        final Properties opaConfig, final Map<String, IPermission> permissionsMap)
        throws BadAppConfigException {
    final Map<String, IRole> rolesByAclName = new HashMap<String, IRole>(4);

    // Special Roles
    final Set<String> specialRolesNames = new HashSet<String>(SpecialRole.values().length);
    final Map<SpecialRole, IRole> specialRoles = new HashMap<SpecialRole, IRole>(SpecialRole.values().length);
    for (final SpecialRole srEnum : SpecialRole.values()) {
        specialRolesNames.add(srEnum.name());
    }

    // Declared Roles
    final Set<String> aclRolesNames = new HashSet<String>();
    aclRolesNames.addAll(specialRolesNames);
    final String aclRolesVal = this.getOptionalValue(opaConfig, OpaConfigKeys.ACL_ROLES.getKey());
    final String[] aclRolesArray = StringUtils.delimitedListToStringArray(aclRolesVal,
            IAppConfigFactory.OPA_CONFIG_LIST_SPLITER);
    if (aclRolesArray != null) {
        for (final String aclRoleName : aclRolesArray) {
            if (StringUtils.hasText(aclRoleName)) {
                aclRolesNames.add(aclRoleName);
            }
        }
    }

    // Search permissions assignment
    final Map<String, Set<IPermission>> permissionsAssignment = new HashMap<String, Set<IPermission>>(4);
    for (final String aclRoleName : aclRolesNames) {
        // For each role search perm assignment
        final Set<IPermission> rolePermissionSet;
        final String permKey = OpaConfigKeys.ACL_ROLES.getKey().concat(".").concat(aclRoleName)
                .concat(OpaConfigKeys.ACL_PERMISSIONS_ASSIGNMENT_SUFFIX.getKey());
        final String rolePermissionsVal = this.getOptionalValue(opaConfig, permKey);
        final String[] rolePermissionsArray = StringUtils.delimitedListToStringArray(rolePermissionsVal,
                IAppConfigFactory.OPA_CONFIG_LIST_SPLITER);
        if (rolePermissionsArray != null) {
            // We found a perm assignment
            rolePermissionSet = new HashSet<IPermission>();
            for (final String rolePermissionName : rolePermissionsArray) {
                if (StringUtils.hasText(rolePermissionName)) {
                    final IPermission perm = permissionsMap.get(rolePermissionName);
                    if (perm != null) {
                        rolePermissionSet.add(perm);
                    } else {
                        final String message = String.format(
                                "Try to assign undeclared permission: [%1$s] to role: [%2$s] in OPA: [%3$s] !",
                                rolePermissionName, aclRoleName, bundleApp.getSymbolicName());
                        throw new BadAppConfigException(message);
                    }
                }
            }
        } else {
            rolePermissionSet = Collections.emptySet();
        }

        permissionsAssignment.put(aclRoleName, rolePermissionSet);
    }

    // Search sub-roles assignment
    final Map<String, Set<String>> subRolesAssignment = new HashMap<String, Set<String>>(4);
    for (final String aclRoleName : aclRolesNames) {
        final Set<String> subRolesSet;
        final String key = OpaConfigKeys.ACL_ROLES.getKey().concat(".").concat(aclRoleName)
                .concat(OpaConfigKeys.ACL_SUBROLES_ASSIGNMENT_SUFFIX.getKey());
        final String subRolesVal = this.getOptionalValue(opaConfig, key);
        final String[] subRolesArray = StringUtils.delimitedListToStringArray(subRolesVal,
                IAppConfigFactory.OPA_CONFIG_LIST_SPLITER);
        if (subRolesArray != null) {
            subRolesSet = new HashSet<String>();
            for (final String subRoleName : subRolesArray) {
                if (StringUtils.hasText(subRoleName) && aclRolesNames.contains(subRoleName)) {
                    subRolesSet.add(subRoleName);
                } else {
                    final String message = String.format(
                            "Try to assign undeclared sub-role: [%1$s] to role: [%2$s] in OPA: [%3$s] !",
                            subRoleName, aclRoleName, bundleApp.getSymbolicName());
                    throw new BadAppConfigException(message);
                }
            }
        } else {
            subRolesSet = Collections.emptySet();
        }

        subRolesAssignment.put(aclRoleName, subRolesSet);
    }

    // Build roles : begin with the sub-roles
    final Set<String> rolesToBuild = new HashSet<String>(aclRolesNames);
    final Set<String> builtRoles = new HashSet<String>(rolesToBuild.size());
    while (!rolesToBuild.isEmpty()) {
        // Loop while some roles are not built yet
        final Iterator<String> rolesToBuildIt = rolesToBuild.iterator();
        while (rolesToBuildIt.hasNext()) {
            // Loop on all roles not built yet to find one candidate to build
            final String aclRoleName = rolesToBuildIt.next();
            final Set<String> subRolesNames = subRolesAssignment.get(aclRoleName);
            if (builtRoles.containsAll(subRolesNames)) {
                // If all sub-roles are already built we can build the role
                final String finalRoleName = this.buildFinalRoleName(bundleApp, aclRoleName);
                final Set<IPermission> permissions = permissionsAssignment.get(aclRoleName);
                final Set<IRole> subRoles = new HashSet<IRole>(subRolesNames.size());
                for (final String subRoleName : subRolesNames) {
                    subRoles.add(rolesByAclName.get(subRoleName));
                }

                final IRole newRole = this.roleFactory.initializeRole(finalRoleName, permissions, subRoles);
                rolesByAclName.put(aclRoleName, newRole);
                builtRoles.add(aclRoleName);
                rolesToBuildIt.remove();

                if (specialRolesNames.contains(aclRoleName)) {
                    // Current role is special
                    specialRoles.put(Enum.valueOf(SpecialRole.class, aclRoleName), newRole);
                }
            }
        }
    }

    appConfig.setSpecialRoles(Collections.unmodifiableMap(specialRoles));
    final Set<IRole> rolesSet = new HashSet<IRole>(rolesByAclName.values());
    appConfig.setDeclaredRoles(Collections.unmodifiableSet(rolesSet));

    return rolesByAclName;
}