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