public Iterator getChildren()

in src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java [295:350]


    public Iterator<Resource> getChildren(final String parentPath, final String subPath) {
        final Map<String, Object> childStructure = this.convertData();
        if ( childStructure != null ) {
            Map<String, Object> current = childStructure;
            if ( subPath != null ) {
                final String[] segments = subPath.split("/");
                for(final String path : segments) {
                    final Object child = current.get(path);
                    if ( child == null ) {
                        return null;
                    }
                    if ( !(child instanceof Map) ) {
                        return null;
                    }
                    current = (Map<String, Object>)child;
                }
            }
            if ( current.size() == 0 ) {
                return null;
            }
            final Iterator<Map.Entry<String, Object>> childIter = current.entrySet().iterator();

            return new Iterator<Resource>() {

                private Map.Entry<String, Object> next = this.seek();

                private Map.Entry<String, Object> seek() {
                    while ( childIter.hasNext() ) {
                        final Map.Entry<String, Object> c = childIter.next();
                        if ( c.getValue() instanceof Map ) {
                            return c;
                        }
                    }
                    return null;
                }

                public void remove() {
                    throw new UnsupportedOperationException("remove");
                }

                public Resource next() {
                    final Map.Entry<String, Object> props = next;
                    if ( props == null ) {
                        throw new NoSuchElementException();
                    }
                    next = seek();
                    return new MapResource(getResourceResolver(), parentPath + '/' + props.getKey(), (Map)props.getValue(), AttributeResource.this);
                }

                public boolean hasNext() {
                    return next != null;
                }
            };
        }
        return null;
    }