code: public void linkMembership(User user, Group group, MembershipType m, boolean broadcast) throws Exception
     {
        if (user == null)
        {
           throw new InvalidNameException("Can not create membership record because user is null");
        }
  
        if (group == null)
        {
           throw new InvalidNameException("Can not create membership record because group is null");
        }
  
        if (m == null)
        {
           throw new InvalidNameException("Can not create membership record because membership type is null");
        }
        Session session = service.getStorageSession();
        try
        {
           MembershipImpl membership = new MembershipImpl();
           membership.setMembershipType(m.getName());
           membership.setGroupId(group.getId());
           membership.setUserName(user.getUserName());
  
           createMembership(session, membership, broadcast);
        }
        finally
        {
           session.logout();
        }
     }
docs: {@inheritDoc}