1 56 package org.objectstyle.cayenne.project; 57 58 import java.io.File ; 59 import java.io.FileInputStream ; 60 import java.io.IOException ; 61 import java.io.InputStream ; 62 import java.util.ArrayList ; 63 import java.util.List ; 64 65 import org.apache.log4j.Logger; 66 import org.objectstyle.cayenne.conf.ConfigStatus; 67 import org.objectstyle.cayenne.map.DataMap; 68 import org.objectstyle.cayenne.map.DataMapException; 69 import org.objectstyle.cayenne.map.MapLoader; 70 import org.xml.sax.InputSource ; 71 72 77 public class DataMapProject extends Project { 78 private static Logger logObj = Logger.getLogger(DataMapProject.class); 79 80 protected DataMap map; 81 82 87 public DataMapProject(File projectFile) { 88 super(projectFile); 89 } 90 91 94 public void upgrade() throws ProjectException { 95 throw new ProjectException("'DataMapProject' does not support upgrades."); 97 } 98 99 102 public void checkForUpgrades() { 103 } 105 106 109 protected void postInitialize(File projectFile) { 110 if (projectFile != null) { 111 try { 112 InputStream in = new FileInputStream (projectFile.getCanonicalFile()); 113 map = new MapLoader().loadDataMap(new InputSource (in)); 114 115 String fileName = resolveSymbolicName(projectFile); 116 logObj.error("resolving: " + projectFile + " to " + fileName); 117 String mapName = 118 (fileName != null && fileName.endsWith(DataMapFile.LOCATION_SUFFIX)) 119 ? fileName.substring(0, fileName.length() - DataMapFile.LOCATION_SUFFIX.length()) 120 : "UntitledMap"; 121 122 map.setName(mapName); 123 } catch (IOException e) { 124 throw new ProjectException("Error creating " + this.getClass().getName(), e); 125 } catch (DataMapException dme) { 126 throw new ProjectException("Error creating " + this.getClass().getName(), dme); 127 } 128 } else { 129 map = (DataMap) NamedObjectFactory.createObject(DataMap.class, null); 130 } 131 132 super.postInitialize(projectFile); 133 } 134 135 136 139 public List getChildren() { 140 List entities = new ArrayList (); 141 entities.add(map); 142 return entities; 143 } 144 145 146 151 public ProjectFile projectFileForObject(Object obj) { 152 if(obj == this) { 153 return new DataMapFile(this, map); 154 } 155 156 return null; 157 } 158 159 163 public ConfigStatus getLoadStatus() { 164 return new ConfigStatus(); 165 } 166 } 167 | Popular Tags |