ruper2/src/java/core/org/krysalis/ruper2/repository RepositoryObject.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/repository
In directory sc8-pr-cvs1:/tmp/cvs-serv15861/src/java/core/org/krysalis/ruper2/repository

Added Files:
	RepositoryObject.java 
Log Message:
browser - still testing

--- NEW FILE: RepositoryObject.java ---
package org.krysalis.ruper2.repository;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.impl.RepositoryWrapper;
import org.krysalis.ruper2.resource.Resource;
import org.krysalis.ruper2.resource.ResourceGroup;
import org.krysalis.ruper2.util.select.AllSelector;

public class RepositoryObject {
	
	public static final int REPOSITORY_ROOT 	= 1;
	public static final int RESOURCE_GROUP 		= 2;
	public static final int RESOURCE 			= 3;
	
	public static final int NOT_REPOSITORY 		= 4;
	
	// Repository
	private RepositoryWrapper m_repositoryWrapper;
	
    private String m_name;
    private int m_type;
    private ArrayList m_children;

    private RepositoryObject m_parent;

	public RepositoryObject(String name, int nodeType) {
		m_name = name;
		m_type = nodeType;
	}

	public RepositoryObject(String name, int nodeType, RepositoryWrapper repository) {
		m_name = name;
		m_type = nodeType;
		m_repositoryWrapper = repository;
	}

    public String getName() {
        return m_name;
    }

    public void setParent(RepositoryObject parent) {
        m_parent = parent;
    }

    public RepositoryObject getParent() {
        return m_parent;
    }

    public String toString() {
        return getName();
    }

	public void addChild(String name, int type) {
		
		RepositoryObject node = new RepositoryObject(name, type);
		addChild(node);													
	}
	
    public void addChild(RepositoryObject child) {
    	if(m_children == null)
    		m_children = new ArrayList();
    		
        m_children.add(child);
        child.setParent(this);
        
        if(this.m_repositoryWrapper != null)
        	child.setRepositoryWrapper(this.m_repositoryWrapper);
    }

    public void removeChild(RepositoryObject child) {
    	if(m_children != null){
	        m_children.remove(child);
	        child.setParent(null);
    	}
    }

	public RepositoryObject[] getChildrenArray() throws RuperException {
		if(null == m_children){ 
			 //	get the children from the repository
			 refreshChildren();
		}
		return (RepositoryObject[]) m_children.toArray(
			new RepositoryObject[m_children.size()]);
	}
  
	public List getChildren() throws RuperException {
		if(null == m_children){ 
			 //	get the children from the repository
			 refreshChildren();
		}
		return m_children;
	}
  
	public void setChildrenArray(RepositoryObject[] children) throws RuperException {
		
		m_children = new ArrayList();
		
		for(int i = 0; i < children.length; i++){
			addChild((RepositoryObject)children[i]);
		}
	}
    
	public void setChildren(List children) throws RuperException {

		m_children = new ArrayList();
		
		if(children != null){
			for(Iterator iterator = children.iterator(); iterator.hasNext();){
				addChild((RepositoryObject)iterator.next());													
			}
		}
	}
    

    public boolean hasChildren() throws RuperException {
       if(null == m_children){ 
			//	get the children from the repository
			refreshChildren();
       }
	   return (m_children.size() > 0);
    }

	public void refreshChildren() throws RuperException {
		
		// not null children means it has read from the repository
		m_children = new ArrayList();
		
		switch(m_type){
			case REPOSITORY_ROOT :
			{
				List list = this.m_repositoryWrapper.listGroups(AllSelector.getInstance());

				if(list != null){
					for(Iterator iterator = list.iterator(); iterator.hasNext();){
						String name = ( (ResourceGroup)iterator.next() ).getGroup();
						addChild(name, RESOURCE_GROUP);													
					}
				}
					
			}
			break;
			case RESOURCE_GROUP :
			{
				List list = this.m_repositoryWrapper.listResources( new ResourceGroup(m_name),
				AllSelector.getInstance());

				if(list != null){
					for(Iterator iterator = list.iterator(); iterator.hasNext();){
						String name = ( (Resource)iterator.next() ).getFilename();
						addChild(name, RESOURCE);
					}
				}
				
			}
			break;
		}
		
	}
	/**
	 * @return
	 */
	public RepositoryWrapper getRepositoryWrapper() {
		return m_repositoryWrapper;
	}

	/**
	 * @return
	 */
	public int getType() {
		return m_type;
	}

	/**
	 * @param list
	 */
	public void setChildren(ArrayList list) {
		m_children = list;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		m_name = string;
	}

	/**
	 * @param wrapper
	 */
	public void setRepositoryWrapper(RepositoryWrapper wrapper) {
		m_repositoryWrapper = wrapper;
	}

	/**
	 * @param i
	 */
	public void setType(int i) {
		m_type = i;
	}

}




-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.