1 56 package org.objectstyle.cayenne.project; 57 58 import java.io.File ; 59 import java.util.ArrayList ; 60 import java.util.List ; 61 62 import org.apache.log4j.Logger; 63 import org.objectstyle.cayenne.access.DataNode; 64 import org.objectstyle.cayenne.conf.ConfigStatus; 65 import org.objectstyle.cayenne.conf.Configuration; 66 import org.objectstyle.cayenne.conf.DriverDataSourceFactory; 67 import org.objectstyle.cayenne.map.DataMap; 68 69 74 public class ApplicationProject extends Project { 75 private static Logger logObj = Logger.getLogger(ApplicationProject.class); 76 77 protected ProjectConfiguration configuration; 78 79 84 public ApplicationProject(File projectFile) { 85 super(projectFile); 86 } 87 88 91 public void upgrade() throws ProjectException { 92 ApplicationUpgradeHandler.sharedHandler().performUpgrade(this); 93 } 94 95 98 protected void postInitialize(File projectFile) { 99 logObj.debug("postInitialize: " + projectFile); 100 101 try { 102 if (projectFile != null) { 104 if (projectFile.isDirectory()) { 106 projectFile = 108 new File ( 109 projectFile.getPath() 110 + File.separator 111 + Configuration.DEFAULT_DOMAIN_FILE); 112 } 113 114 projectFile = projectFile.getCanonicalFile(); 115 } 116 117 loadProject(projectFile); 118 } 119 catch (Exception e) { 120 throw new ProjectException("Error creating ApplicationProject.", e); 121 } 122 123 super.postInitialize(projectFile); 124 } 125 126 129 protected void loadProject(File projectFile) throws Exception { 130 ProjectConfiguration conf = new ProjectConfiguration(projectFile); 131 132 if (conf.canInitialize()) { 134 conf.initialize(); 135 conf.didInitialize(); 136 } 137 138 if (conf.getProjectVersion() == null) { 140 conf.setProjectVersion( 141 ApplicationUpgradeHandler.sharedHandler().supportedVersion()); 142 } 143 144 this.configuration = conf; 145 } 146 147 150 public Configuration getConfiguration() { 151 return configuration; 152 } 153 154 157 public void setConfiguration(ProjectConfiguration config) { 158 this.configuration = config; 159 } 160 161 public void checkForUpgrades() { 162 ApplicationUpgradeHandler.sharedHandler().checkForUpgrades( 163 configuration, 164 upgradeMessages); 165 } 166 167 170 public List getChildren() { 171 return new ArrayList (this.getConfiguration().getDomains()); 172 } 173 174 180 public ProjectFile projectFileForObject(Object obj) { 181 if (requiresProjectFile(obj)) { 182 String domainFileName = this.getConfiguration().getDomainConfigurationName(); 183 return new ApplicationProjectFile(this, domainFileName); 184 } 185 else if (requiresMapFile(obj)) { 186 return new DataMapFile(this, (DataMap) obj); 187 } 188 else if (requiresNodeFile(obj)) { 189 return new DataNodeFile(this, (DataNode) obj); 190 } 191 192 return null; 193 } 194 195 protected boolean requiresProjectFile(Object obj) { 196 return obj == this; 197 } 198 199 protected boolean requiresMapFile(Object obj) { 200 return obj instanceof DataMap; 201 } 202 203 protected boolean requiresNodeFile(Object obj) { 204 if (obj instanceof DataNode) { 205 DataNode node = (DataNode) obj; 206 207 if (DriverDataSourceFactory 209 .class 210 .getName() 211 .equals(node.getDataSourceFactory())) { 212 return true; 213 } 214 } 215 216 return false; 217 } 218 219 public ConfigStatus getLoadStatus() { 220 return (configuration != null) 221 ? configuration.getLoadStatus() 222 : new ConfigStatus(); 223 } 224 } 225 | Popular Tags |