class DomainSchemaHelper {

    public static String getDataIslandPathFromGroup(PresentationGroupElement group, List<ResourceElement> clientResources,
            List<String> constantGroupNames){
        // Data island ID is taken from resource path, but PresentationGroupElement doesn't have resourcePath.
        // Let's iterate over elements tree to find any PresentationSingleElement and take data island ID from it.
        String result = null;
        if(group != null){
            final List<PresentationElement> elements = group.getElements();
            for (PresentationElement element : elements) {
                if(element instanceof PresentationGroupElement){
                    // it's group. Proceed with recursive call
                    result = getDataIslandPathFromGroup((PresentationGroupElement) element, clientResources,
                            constantGroupNames);
                } else if(element instanceof PresentationSingleElement){
                    // it's single element. Try to take data island ID from it
                    final String dataIslandPathCandidate =
                            getDataIslandPathFromElement((PresentationSingleElement) element, clientResources);
                    // if current element points to constant, then we have to ignore it, because constants may
                    // participate in multiple data islands without being joined
                    if(!constantGroupNames.contains(dataIslandPathCandidate)) {
                        // it's not constant, let's use it as a result
                        result = dataIslandPathCandidate;
                    }
                }
                if(result != null){
                    // data island ID is found. Stop iterating.
                    break;
                }
            }
        }
        if(result == null && !constantGroupNames.isEmpty()){
            // it may be a data island with constants only. Let's try to find it's path by calling same method,
            // but without constant groups collection. In this case reference to constants groups
            // will not be ignored
            result = getDataIslandPathFromGroup(group, clientResources, new ArrayList<String>());
        }
        return result;
    }

}