1 56 package org.objectstyle.cayenne.project; 57 58 import java.io.PrintWriter ; 59 60 import org.objectstyle.cayenne.access.DataNode; 61 import org.objectstyle.cayenne.conf.ConfigSaver; 62 import org.objectstyle.cayenne.conf.DriverDataSourceFactory; 63 64 70 public class DataNodeFile extends ProjectFile { 71 public static final String LOCATION_SUFFIX = ".driver.xml"; 72 73 protected DataNode nodeObj; 74 75 public DataNodeFile() {} 76 77 80 public DataNodeFile(Project project, DataNode node) { 81 super(project, node.getDataSourceLocation()); 82 this.nodeObj = node; 83 } 84 85 88 public Object getObject() { 89 return nodeObj; 90 } 91 92 95 public String getObjectName() { 96 return nodeObj.getName(); 97 } 98 99 public void save(PrintWriter out) throws Exception { 100 ProjectDataSource src = (ProjectDataSource) nodeObj.getDataSource(); 101 new ConfigSaver().storeDataNode(out, src.getDataSourceInfo()); 102 } 103 104 107 public boolean canHandle(Object obj) { 108 if (obj instanceof DataNode) { 109 DataNode node = (DataNode) obj; 110 111 if (DriverDataSourceFactory 113 .class 114 .getName() 115 .equals(node.getDataSourceFactory())) { 116 return true; 117 } 118 } 119 120 return false; 121 } 122 123 126 public void willSave() { 127 super.willSave(); 128 129 if (nodeObj != null && canHandle(nodeObj)) { 130 nodeObj.setDataSourceLocation(getLocation()); 131 } 132 } 133 134 138 public String getLocationSuffix() { 139 return LOCATION_SUFFIX; 140 } 141 } 142 | Popular Tags |