1 19 20 package org.apache.cayenne.project; 21 22 import java.io.File ; 23 24 import org.apache.cayenne.conf.Configuration; 25 import org.apache.cayenne.conf.DataSourceFactory; 26 import org.apache.cayenne.conf.FileConfiguration; 27 import org.apache.cayenne.util.ResourceLocator; 28 29 35 public class ProjectConfiguration extends FileConfiguration { 36 37 42 public ProjectConfiguration(File projectFile) { 43 super(projectFile); 44 45 this.setIgnoringLoadFailures(true); 47 48 ResourceLocator locator = this.getResourceLocator(); 50 locator.setSkipAbsolutePath(false); 51 locator.setSkipClasspath(true); 52 locator.setSkipCurrentDirectory(true); 53 locator.setSkipHomeDirectory(true); 54 } 55 56 61 public boolean canInitialize() { 62 return (super.canInitialize() && this.getProjectFile().isFile()); 63 } 64 65 70 protected void setProjectFile(File projectFile) { 71 if ((projectFile != null) && (projectFile.exists())) { 72 super.setProjectFile(projectFile); 73 } 74 else { 75 super.projectFile = projectFile; 76 this.setDomainConfigurationName(Configuration.DEFAULT_DOMAIN_FILE); 77 } 78 } 79 80 85 public DataSourceFactory getDataSourceFactory() { 86 try { 87 return new ProjectDataSourceFactory(this.getProjectDirectory()); 88 } 89 catch (Exception e) { 90 throw new ProjectException("Error creating DataSourceFactory.", e); 91 } 92 } 93 } 94 | Popular Tags |