1 27 package com.genimen.djeneric.repository; 28 29 import com.genimen.djeneric.language.Messages; 30 import com.genimen.djeneric.repository.exceptions.DjenericException; 31 import com.genimen.djeneric.structure.ExtentUsage; 32 import com.genimen.djeneric.structure.ResourceDefinition; 33 import com.genimen.djeneric.tools.io.DjenericDocumentHandler; 34 35 public abstract class DjModelView 36 { 37 final static long NOT_YET_PERSISTED = -1; 38 final static String UNTITLED = Messages.getString("DjModelView.Untitled"); 39 40 public abstract void delete(DjSession session) throws DjenericException; 42 43 public abstract void reload(DjSession session) throws DjenericException; 44 45 public abstract void persist(DjSession session) throws DjenericException; 46 47 public abstract void insert(DjSession session) throws DjenericException; 48 49 public abstract DjUser[] getUsers(DjSession session) throws DjenericException; 50 51 public abstract void removeUser(DjSession session, DjUser user) throws DjenericException; 52 53 public abstract boolean isModifiedExternally(DjSession session) throws DjenericException; 54 55 57 long _id; 58 String _code = UNTITLED; 59 String _definition = ""; 60 DjPersistenceManager _mgr; 61 62 protected DjModelView(DjPersistenceManager mgr) 63 64 { 65 _id = NOT_YET_PERSISTED; 66 _mgr = mgr; 67 } 68 69 protected DjModelView(DjPersistenceManager mgr, long id, String code, String definition) 70 { 71 _id = id; 72 _code = code; 73 _definition = definition; 74 _mgr = mgr; 75 } 76 77 public DjPersistenceManager getPersistenceManager() 78 { 79 return _mgr; 80 } 81 82 public boolean isUntitled() 83 { 84 return getCode() == null || getCode().equals(UNTITLED) || getCode().trim().length() == 0; 85 } 86 87 public long getId() 88 { 89 return _id; 90 } 91 92 protected void setId(long id) 93 { 94 _id = id; 95 } 96 97 public String getCode() 98 { 99 return _code; 100 } 101 102 public void setCode(String code) 103 { 104 _code = code; 105 } 106 107 public String getDefinition() 108 { 109 return _definition; 110 } 111 112 public void setDefinition(String definition) 113 { 114 _definition = definition; 115 } 116 117 public boolean equals(Object obj) 118 { 119 if (!(obj instanceof DjModelView)) return false; 120 DjModelView r = (DjModelView) obj; 121 122 return getId() == r.getId(); 123 } 124 125 public int hashCode() 126 { 127 return (int) getId(); 128 } 129 130 public String toString() 131 { 132 return getCode(); 133 } 134 135 public ExtentUsage[] getExtentUsages() throws DjenericException 136 { 137 DjenericDocumentHandler dh = new DjenericDocumentHandler(getDefinition()); 138 return dh.getTreeStructure(_mgr); 139 } 140 141 public ResourceDefinition[] getResources() throws DjenericException 142 { 143 DjenericDocumentHandler dh = new DjenericDocumentHandler(getDefinition()); 144 return dh.getResources(); 145 } 146 147 public DjenericDocumentHandler getDocumentHandler() throws DjenericException 148 { 149 return new DjenericDocumentHandler(getDefinition()); 150 } 151 152 } | Popular Tags |