FolderInternal.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.model;
  2. import net.javacoding.jspider.api.model.*;
  3. import net.javacoding.jspider.core.storage.spi.StorageSPI;
  4. /**
  5.  * $Id: FolderInternal.java,v 1.2 2003/04/11 16:37:04 vanrogu Exp $
  6.  */
  7. public class FolderInternal implements Folder {
  8.     protected StorageSPI storage;
  9.     protected int id;
  10.     protected int parent;
  11.     protected String name;
  12.     protected int site;
  13.     public FolderInternal ( StorageSPI storage, int id, int parent, String name, int site ) {
  14.         this.storage = storage;
  15.         this.id = id;
  16.         this.parent= parent;
  17.         this.name = name;
  18.         this.site = site;
  19.     }
  20.     public int getId() {
  21.         return id;
  22.     }
  23.     public int getSiteId ( ) {
  24.         return site;
  25.     }
  26.     public void setId(int id) {
  27.         this.id = id;
  28.     }
  29.     public Site getSite() {
  30.         return storage.getSiteDAO().find(site);
  31.     }
  32.     public String getName() {
  33.         return name;
  34.     }
  35.     public Folder getParent() {
  36.         if ( parent == 0 ) {
  37.             return null;
  38.         } else {
  39.           return storage.getFolderDAO().findById(parent);
  40.         }
  41.     }
  42.     public Resource[] getResources() {
  43.         return storage.getResourceDAO().findByFolder(this);
  44.     }
  45.     public Folder[] getFolders() {
  46.         return storage.getFolderDAO().findSubFolders(this);
  47.     }
  48.     public Folder getFolder(String name) {
  49.         Folder[] folders = getFolders();
  50.         for (int i = 0; i < folders.length; i++) {
  51.             Folder folder = folders[i];
  52.             if ( folder.getName().equals( name ) ){
  53.                 return folder;
  54.             }
  55.         }
  56.         return null;
  57.     }
  58.     public String toString ( ) {
  59.         return "[FOLDER id: " + id + " name:" + name + "]";
  60.     }
  61.     public int hashCode () {
  62.         return id;
  63.     }
  64.     public boolean equals ( Object other ) {
  65.         if ( other instanceof FolderInternal ) {
  66.           FolderInternal otherFolder = (FolderInternal)other;
  67.             if (otherFolder.id == id ) {
  68.                 return true;
  69.             }
  70.         }
  71.         return false;
  72.     }
  73. }