Package com.zaranux.os.client.access

Source Code of com.zaranux.os.client.access.Group

package com.zaranux.os.client.access;

import com.zaranux.client.api.AsyncCallback;
import com.zaranux.client.java.io.File;
import com.zaranux.client.java.io.FileInputStream;
import java.util.Vector;

import com.zaranux.client.java.util.Properties;
import com.zaranux.os.client.util.Log;

public class Group {
  private static File groupFile = new File("/.zaranux/.groups.zconfig");
  private static Vector<Group> groups;
 
  public static void getGroups(final AsyncCallback<Vector<Group>> callback)
  {
    if(groups != null ) {callback.onSuccess(groups); return;}
   
    groups = new Vector<Group>();
    FileInputStream fis = new FileInputStream(groupFile);
   
    final Properties groupProperties = new Properties();
    groupProperties.load(fis, new AsyncCallback<Boolean>()
        {
        public void onSuccess(Boolean b)
        {
          for(Object o : groupProperties.keySet())
          {
            Group g = new Group((String) o);
            String groupRecord = (String) groupProperties.get(o);
            // Display Name : memeber1,memeber2,...
            String[] fields = groupRecord.split(":",2);
            if(fields.length != 2) continue; // incorrect format
            g.setDisplayName(fields[0]);
            String[] members = fields[1].split(",");
            for(String member : members)
            {
              g.addMember(member);
            }
            groups.add(g);
          }
          callback.onSuccess(groups);
        }
        public void onFailure(Throwable t)
        {
          callback.onFailure(t);
        }
        });
  }

  private final String groupName;
  private String displayName;
  private Vector<String> members = new Vector<String>();
 
  private Group(String groupName)
  {
    this.groupName = groupName;
  }
  public String getGroupName()
  {
    return groupName;
  }
  public String getGroupDisplayName()
  {
    return displayName;
  }
  public Vector<String> getMembers()
  {
    return members;
  }
  public void setDisplayName(String displayName)
  {
    this.displayName = displayName;
  }
  public void addMember(String member){
    members.add(member);
  }
 
  public boolean removeMember(String memeber)
  {
    return members.remove(memeber);
  }
}
TOP

Related Classes of com.zaranux.os.client.access.Group

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.