1 19 20 package org.apache.cayenne.project; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.InputStream ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import org.apache.cayenne.conf.ConfigStatus; 29 import org.apache.cayenne.map.DataMap; 30 import org.apache.cayenne.map.MapLoader; 31 import org.xml.sax.InputSource ; 32 33 38 public class DataMapProject extends Project { 39 40 protected DataMap map; 41 42 47 public DataMapProject(File projectFile) { 48 super(projectFile); 49 } 50 51 54 public void upgrade() throws ProjectException { 55 throw new ProjectException("'DataMapProject' does not support upgrades."); 57 } 58 59 62 public void checkForUpgrades() { 63 } 65 66 69 protected void postInitialize(File projectFile) { 70 if (projectFile != null) { 71 try { 72 InputStream in = new FileInputStream (projectFile.getCanonicalFile()); 73 map = new MapLoader().loadDataMap(new InputSource (in)); 74 75 String fileName = resolveSymbolicName(projectFile); 76 String mapName = (fileName != null && fileName 77 .endsWith(DataMapFile.LOCATION_SUFFIX)) 78 ? fileName.substring(0, fileName.length() 79 - DataMapFile.LOCATION_SUFFIX.length()) 80 : "UntitledMap"; 81 82 map.setName(mapName); 83 } 84 catch (Exception dme) { 85 throw new ProjectException( 86 "Error creating " + this.getClass().getName(), 87 dme); 88 } 89 } 90 else { 91 map = (DataMap) NamedObjectFactory.createObject(DataMap.class, null); 92 } 93 94 super.postInitialize(projectFile); 95 } 96 97 100 public List getChildren() { 101 List entities = new ArrayList (); 102 entities.add(map); 103 return entities; 104 } 105 106 111 public ProjectFile projectFileForObject(Object obj) { 112 if (obj == this) { 113 return new DataMapFile(this, map); 114 } 115 116 return null; 117 } 118 119 122 public ConfigStatus getLoadStatus() { 123 return new ConfigStatus(); 124 } 125 } 126 | Popular Tags |