ruper2/src/java/core/org/krysalis/ruper2/impl RepositoryObject.java,NONE,1.1 RepositoryResourceObject.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/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv28552/src/java/core/org/krysalis/ruper2/impl

Added Files:
	RepositoryObject.java RepositoryResourceObject.java 
Log Message:
Browser action

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

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

import org.krysalis.ruper2.RuperException;
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;
    
	// parent repository object
	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(Resource resource) {
		RepositoryResourceObject node = new RepositoryResourceObject(resource);
		addChild(node);													
	}
	
	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[] getCachedChildrenArray() throws RuperException {
		if(m_children == null){
			return null;
		}
		return (RepositoryObject[]) m_children.toArray(
			new RepositoryObject[m_children.size()]);
	}

	public RepositoryObject[] getChildrenArray() throws RuperException {
		if(null == m_children){ 
			 //	get the children from the repository
			syncChildren();
		}
		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
			syncChildren();
		}
		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
			syncChildren();
       }
	   return (m_children.size() > 0);
    }

	public void syncChildren() 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();){
						addChild( (Resource)iterator.next() );
					}
				}
				
			}
			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;
	}

}

--- NEW FILE: RepositoryResourceObject.java ---
/*
 * Created on Oct 27, 2003
  */
package org.krysalis.ruper2.impl;

import org.krysalis.ruper2.resource.Resource;

/**
 * @author anou_mana
 */
public class RepositoryResourceObject extends RepositoryObject {

	// the RepositoryObject.RESOURCE type - holds the resource
	private Resource m_resource; 

	/**
	 * @param name
	 * @param nodeType
	 */
	public RepositoryResourceObject(String name, int nodeType) {
		super(name, nodeType);
	}

	/**
	 * @param resource
	 */

	public RepositoryResourceObject(Resource resource) {
		super(resource.getFilename(),RESOURCE);
		m_resource = resource;
	}

	/**
	 * @param name
	 * @param nodeType
	 * @param repository
	 */
	public RepositoryResourceObject(
		String name,
		int nodeType,
		RepositoryWrapper repository) {
		super(name, nodeType, repository);
	}

	public RepositoryResourceObject(
		Resource resource,
		RepositoryWrapper repository) {
		super(resource.getFilename(),RESOURCE, repository);
		m_resource = resource;
	}

	/**
	 * @return
	 */
	public Resource getResource() {
		return m_resource;
	}

	/**
	 * @param resource
	 */
	public void setResource(Resource resource) {
		m_resource = resource;
	}

}




-------------------------------------------------------
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.