jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1205375 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
Date Wed, 23 Nov 2011 11:53:10 GMT
Author: angela
Date: Wed Nov 23 11:53:10 2011
New Revision: 1205375

URL: http://svn.apache.org/viewvc?rev=1205375&view=rev
Log:
reformat code and add javadoc

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java?rev=1205375&r1=1205374&r2=1205375&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
Wed Nov 23 11:53:10 2011
@@ -135,7 +135,7 @@ class GroupImpl extends AuthorizableImpl
         } else {
             String thisID = getID();
             AuthorizableImpl impl = (AuthorizableImpl) authorizable;
-            for (Iterator<Group> it = impl.memberOf(); it.hasNext();) {
+            for (Iterator<Group> it = impl.memberOf(); it.hasNext(); ) {
                 if (thisID.equals(it.next().getID())) {
                     return true;
                 }
@@ -247,6 +247,14 @@ class GroupImpl extends AuthorizableImpl
         return false;
     }
 
+    private String safeGetID() {
+        try {
+            return getID();
+        } catch (RepositoryException e) {
+            return getNode().toString();
+        }
+    }
+
     static PropertySequence getPropertySequence(Node nMembers, UserManagerImpl userManager)
throws RepositoryException {
         Comparator<String> order = Rank.comparableComparator();
         int maxChildren = userManager.getGroupMembershipSplitSize();
@@ -297,7 +305,7 @@ class GroupImpl extends AuthorizableImpl
             } catch (RepositoryException e) {
                 // continue using regular membership evaluation
             }
-           
+
             Collection<Principal> members = getMembers();
             return members.contains(member);
         }
@@ -322,7 +330,6 @@ class GroupImpl extends AuthorizableImpl
         }
 
         //---------------------------------------------------< Serializable >---
-
         /**
          * implement the writeObject method to assert initialization of all members
          * before serialization.
@@ -336,12 +343,16 @@ class GroupImpl extends AuthorizableImpl
         }
 
         //----------------------------------------------------------------------
-
+        /**
+         * Collect the member of this group principal.
+         *
+         * @return the members of this group principal.
+         */
         private Collection<Principal> getMembers() {
             if (members == null) {
                 members = new HashSet<Principal>();
                 try {
-                    for (Iterator<Authorizable> it = GroupImpl.this.getMembers(); it.hasNext();)
{
+                    for (Iterator<Authorizable> it = GroupImpl.this.getMembers(); it.hasNext();
) {
                         members.add(it.next().getPrincipal());
                     }
                 } catch (RepositoryException e) {
@@ -353,21 +364,33 @@ class GroupImpl extends AuthorizableImpl
         }
     }
 
+    /**
+     * Inner MembershipProvider interface
+     */
     private interface MembershipProvider {
         boolean addMember(AuthorizableImpl authorizable) throws RepositoryException;
+
         boolean removeMember(AuthorizableImpl authorizable) throws RepositoryException;
+
         Iterator<Authorizable> getMembers(boolean includeIndirect, int type) throws
RepositoryException;
+
         boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException;
     }
 
+    /**
+     * PropertyBasedMembershipProvider
+     */
     private class PropertyBasedMembershipProvider implements MembershipProvider {
         private final NodeImpl node;
 
-        public PropertyBasedMembershipProvider(NodeImpl node) {
+        private PropertyBasedMembershipProvider(NodeImpl node) {
             super();
             this.node = node;
         }
 
+        /**
+         * @see MembershipProvider#addMember(AuthorizableImpl)
+         */
         public boolean addMember(AuthorizableImpl authorizable) throws RepositoryException
{
             Node memberNode = authorizable.getNode();
 
@@ -393,6 +416,9 @@ class GroupImpl extends AuthorizableImpl
             return true;
         }
 
+        /**
+         * @see MembershipProvider#removeMember(AuthorizableImpl)
+         */
         public boolean removeMember(AuthorizableImpl authorizable) throws RepositoryException
{
             if (!node.hasProperty(P_MEMBERS)) {
                 log.debug("Group has no members -> cannot remove member {}", authorizable.getID());
@@ -425,22 +451,26 @@ class GroupImpl extends AuthorizableImpl
             }
         }
 
+        /**
+         * @see MembershipProvider#getMembers(boolean, int)
+         */
         public Iterator<Authorizable> getMembers(boolean includeIndirect, int type)
throws RepositoryException {
             if (node.hasProperty(P_MEMBERS)) {
                 Value[] members = node.getProperty(P_MEMBERS).getValues();
 
                 if (includeIndirect) {
                     return includeIndirect(toAuthorizables(members, type), type);
-                }
-                else {
+                } else {
                     return toAuthorizables(members, type);
                 }
-            }
-            else {
+            } else {
                 return Iterators.empty();
             }
         }
 
+        /**
+         * @see MembershipProvider#hasMember(AuthorizableImpl)
+         */
         public boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException
{
             if (node.hasProperty(P_MEMBERS)) {
                 Value[] members = node.getProperty(P_MEMBERS).getValues();
@@ -450,22 +480,27 @@ class GroupImpl extends AuthorizableImpl
                     }
                 }
                 return false;
-            }
-            else {
+            } else {
                 return false;
             }
         }
 
     }
 
+    /**
+     * NodeBasedMembershipProvider
+     */
     private class NodeBasedMembershipProvider implements MembershipProvider {
         private final NodeImpl node;
 
-        public NodeBasedMembershipProvider(NodeImpl node) {
+        private NodeBasedMembershipProvider(NodeImpl node) {
             super();
             this.node = node;
         }
 
+        /**
+         * @see MembershipProvider#addMember(AuthorizableImpl)
+         */
         public boolean addMember(final AuthorizableImpl authorizable) throws RepositoryException
{
             return userManager.performProtectedOperation(getSession(), new SessionWriteOperation<Boolean>()
{
                 public Boolean perform(SessionContext context) throws RepositoryException
{
@@ -488,8 +523,7 @@ class GroupImpl extends AuthorizableImpl
                             node.save();
                         }
                         return true;
-                    }
-                    catch (RepositoryException e) {
+                    } catch (RepositoryException e) {
                         log.debug("addMember failed. Reverting changes", e);
                         if (nMembers.isNew()) {
                             node.refresh(false);
@@ -502,6 +536,9 @@ class GroupImpl extends AuthorizableImpl
             });
         }
 
+        /**
+         * @see MembershipProvider#removeMember(AuthorizableImpl)
+         */
         public boolean removeMember(final AuthorizableImpl authorizable) throws RepositoryException
{
             if (!node.hasNode(N_MEMBERS)) {
                 log.debug("Group has no members -> cannot remove member {}", authorizable.getID());
@@ -528,8 +565,7 @@ class GroupImpl extends AuthorizableImpl
                             node.save();
                         }
                         return true;
-                    }
-                    catch (RepositoryException e) {
+                    } catch (RepositoryException e) {
                         log.debug("removeMember failed. Reverting changes", e);
                         nMembers.refresh(false);
                         throw e;
@@ -538,35 +574,37 @@ class GroupImpl extends AuthorizableImpl
             });
         }
 
+        /**
+         * @see MembershipProvider#getMembers(boolean, int)
+         */
         public Iterator<Authorizable> getMembers(boolean includeIndirect, int type)
throws RepositoryException {
             if (node.hasNode(N_MEMBERS)) {
                 PropertySequence members = getPropertySequence(node.getNode(N_MEMBERS), userManager);
                 if (includeIndirect) {
                     return includeIndirect(toAuthorizables(members.iterator(), type), type);
-                }
-                else {
+                } else {
                     return toAuthorizables(members.iterator(), type);
                 }
-            }
-            else {
+            } else {
                 return Iterators.empty();
             }
         }
 
+        /**
+         * @see MembershipProvider#hasMember(AuthorizableImpl)
+         */
         public boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException
{
             if (node.hasNode(N_MEMBERS)) {
                 PropertySequence members = getPropertySequence(node.getNode(N_MEMBERS), userManager);
                 return members.hasItem(authorizable.getID());
-            }
-            else {
+            } else {
                 return false;
             }
         }
 
     }
 
-    // -----------------------------------------------------< utility >---
-
+    // -----------------------------------------------------------< utility >---
     /**
      * Returns an iterator of authorizables which includes all indirect members of the given
iterator
      * of authorizables.
@@ -592,7 +630,7 @@ class GroupImpl extends AuthorizableImpl
 
             /**
              * Returns the transitive closure over the members of this authorizable.
-             * 
+             *
              * @param authorizable
              * @return Iterator of Authorizable objects
              */
@@ -600,12 +638,10 @@ class GroupImpl extends AuthorizableImpl
                 if (authorizable.isGroup()) {
                     try {
                         return ((GroupImpl) authorizable).getMembers(true, type);
-                    }
-                    catch (RepositoryException e) {
+                    } catch (RepositoryException e) {
                         log.warn("Could not determine members of " + authorizable, e);
                     }
                 }
-
                 return Iterators.empty();
             }
         };
@@ -627,14 +663,15 @@ class GroupImpl extends AuthorizableImpl
             @Override
             protected String getNextMemberRef() throws RepositoryException {
                 return pos < members.length
-                    ? members[pos++].getString()
-                    : null;
+                        ? members[pos++].getString()
+                        : null;
             }
         };
     }
 
     /**
      * Map an iterator of properties to an iterator of authorizables.
+     *
      * @param members
      * @param type
      * @return Iterator of Authorizable objects
@@ -644,8 +681,8 @@ class GroupImpl extends AuthorizableImpl
             @Override
             protected String getNextMemberRef() throws RepositoryException {
                 return members.hasNext()
-                    ? members.next().getString()
-                    : null;
+                        ? members.next().getString()
+                        : null;
             }
         };
     }
@@ -687,7 +724,7 @@ class GroupImpl extends AuthorizableImpl
          * <code>null</code> if there there are no more.
          *
          * @return reference value of the next node representing the next authorizable or
-         * <code>null</code> if there there are no more.
+         *         <code>null</code> if there there are no more.
          * @throws javax.jcr.RepositoryException If an error occurs.
          */
         protected abstract String getNextMemberRef() throws RepositoryException;
@@ -703,34 +740,20 @@ class GroupImpl extends AuthorizableImpl
                     NodeImpl member = (NodeImpl) getSession().getNodeByIdentifier(memberRef);
                     if (type != UserManager.SEARCH_TYPE_USER && member.isNodeType(NT_REP_GROUP))
{
                         next = userManager.createGroup(member);
-                    }
-                    else if (type != UserManager.SEARCH_TYPE_GROUP && member.isNodeType(NT_REP_USER))
{
+                    } else if (type != UserManager.SEARCH_TYPE_GROUP && member.isNodeType(NT_REP_USER))
{
                         next = userManager.createUser(member);
-                    }
-                    else {
+                    } else {
                         log.debug("Group member entry with invalid node type {} -> " +
                                 "Not included in member set.", member.getPrimaryNodeType().getName());
                     }
-                }
-                catch (ItemNotFoundException e) {
+                } catch (ItemNotFoundException e) {
                     log.debug("Authorizable node referenced by {} doesn't exist any more
-> " +
                             "Ignored from member list.", safeGetID());
-                }
-                catch (RepositoryException e) {
+                } catch (RepositoryException e) {
                     log.debug("Error pre-fetching member for " + safeGetID(), e);
                 }
 
             }
         }
     }
-
-    private String safeGetID() {
-        try {
-            return getID();
-        }
-        catch (RepositoryException e) {
-            return getNode().toString();
-        }
-    }
-
 }



Mime
View raw message