1 56 package org.objectstyle.cayenne.conf; 57 58 import java.io.File ; 59 60 import org.apache.log4j.Logger; 61 import org.objectstyle.cayenne.ConfigurationException; 62 import org.objectstyle.cayenne.util.ResourceLocator; 63 64 70 public class FileConfiguration extends DefaultConfiguration { 71 private static Logger logObj = Logger.getLogger(FileConfiguration.class); 72 73 76 protected File projectFile; 77 78 84 public FileConfiguration() { 85 this(Configuration.DEFAULT_DOMAIN_FILE); 86 } 87 88 97 public FileConfiguration(String domainConfigurationName) { 98 super(domainConfigurationName); 99 100 this.projectFile = new File (domainConfigurationName); 102 103 ResourceLocator locator = this.getResourceLocator(); 105 locator.setSkipAbsolutePath(false); 106 locator.setSkipClasspath(true); 107 locator.setSkipCurrentDirectory(false); 108 locator.setSkipHomeDirectory(true); 109 110 File projectDirectory = this.getProjectDirectory(); 112 if (projectDirectory != null) { 113 locator.addFilesystemPath(projectDirectory.getPath()); 114 } 115 } 116 117 124 public FileConfiguration(File domainConfigurationFile) { 125 super(); 126 127 logObj.debug("using domain file: " + domainConfigurationFile); 128 129 this.setProjectFile(domainConfigurationFile); 131 132 ResourceLocator locator = this.getResourceLocator(); 134 locator.setSkipAbsolutePath(false); 135 locator.setSkipClasspath(true); 136 locator.setSkipCurrentDirectory(false); 137 locator.setSkipHomeDirectory(true); 138 139 File projectDirectory = this.getProjectDirectory(); 141 if (projectDirectory != null) { 142 locator.addFilesystemPath(projectDirectory); 143 } 144 } 145 146 165 public void addFilesystemPath(String path) { 166 this.getResourceLocator().addFilesystemPath(path); 167 } 168 169 176 public void addFilesystemPath(File path) { 177 this.getResourceLocator().addFilesystemPath(path); 178 } 179 180 184 public boolean canInitialize() { 185 return (this.getProjectFile() != null); 187 } 188 189 192 public File getProjectFile() { 193 return projectFile; 194 } 195 196 201 protected void setProjectFile(File projectFile) { 202 if (projectFile != null) { 203 if (projectFile.isFile()) { 204 this.projectFile = projectFile; 205 this.setDomainConfigurationName(projectFile.getName()); 206 } 207 else { 208 throw new ConfigurationException("Project file: " 209 + projectFile 210 + " is a directory or not readable."); 211 } 212 } 213 else { 214 throw new ConfigurationException("Cannot use null as project file."); 215 } 216 } 217 218 222 public File getProjectDirectory() { 223 File pfile = this.getProjectFile(); 224 if (pfile != null) { 225 return pfile.getParentFile(); 226 } 227 else { 228 return null; 229 } 230 } 231 } 232 | Popular Tags |