1 56 package org.objectstyle.cayenne.project; 57 58 import java.io.File ; 59 60 import org.objectstyle.cayenne.ConfigurationException; 61 import org.objectstyle.cayenne.conf.Configuration; 62 import org.objectstyle.cayenne.conf.DataSourceFactory; 63 import org.objectstyle.cayenne.conf.FileConfiguration; 64 import org.objectstyle.cayenne.conf.RuntimeLoadDelegate; 65 import org.objectstyle.cayenne.util.ResourceLocator; 66 67 73 public class ProjectConfiguration extends FileConfiguration { 74 75 79 public ProjectConfiguration(File projectFile) { 80 super(projectFile); 81 82 this.setIgnoringLoadFailures(true); 84 85 ResourceLocator locator = this.getResourceLocator(); 87 locator.setSkipAbsolutePath(false); 88 locator.setSkipClasspath(true); 89 locator.setSkipCurrentDirectory(true); 90 locator.setSkipHomeDirectory(true); 91 92 setLoaderDelegate(new ProjectLoader()); 94 } 95 96 101 public boolean canInitialize() { 102 return (super.canInitialize() && this.getProjectFile().isFile()); 103 } 104 105 109 protected void setProjectFile(File projectFile) { 110 if ((projectFile != null) && (projectFile.exists())) { 111 super.setProjectFile(projectFile); 112 } 113 else { 114 super.projectFile = projectFile; 115 this.setDomainConfigurationName(Configuration.DEFAULT_DOMAIN_FILE); 116 } 117 } 118 119 124 public DataSourceFactory getDataSourceFactory() { 125 try { 126 return new ProjectDataSourceFactory(this.getProjectDirectory()); 127 } 128 catch (Exception e) { 129 throw new ProjectException("Error creating DataSourceFactory.", e); 130 } 131 } 132 133 final class ProjectLoader extends RuntimeLoadDelegate { 134 135 public ProjectLoader() { 136 super( 137 ProjectConfiguration.this, 138 ProjectConfiguration.this.getLoadStatus(), 139 ProjectConfiguration.getLoggingLevel()); 140 } 141 142 public void shouldLoadDataDomain(String domainName) { 143 super.shouldLoadDataDomain(domainName); 144 145 try { 146 findDomain(domainName).getEntityResolver().setIndexedByClass(false); 148 } 149 catch (Exception ex) { 150 throw new ConfigurationException("Domain is not loaded: " + domainName); 151 } 152 } 153 } 154 } 155 | Popular Tags |