1 19 20 package org.apache.cayenne.project; 21 22 import java.io.PrintWriter ; 23 24 import org.apache.cayenne.access.DataNode; 25 import org.apache.cayenne.conf.ConfigSaver; 26 import org.apache.cayenne.conf.DriverDataSourceFactory; 27 28 34 public class DataNodeFile extends ProjectFile { 35 public static final String LOCATION_SUFFIX = ".driver.xml"; 36 37 protected DataNode nodeObj; 38 39 public DataNodeFile() {} 40 41 44 public DataNodeFile(Project project, DataNode node) { 45 super(project, node.getDataSourceLocation()); 46 this.nodeObj = node; 47 } 48 49 52 public Object getObject() { 53 return nodeObj; 54 } 55 56 59 public String getObjectName() { 60 return nodeObj.getName(); 61 } 62 63 public void save(PrintWriter out) throws Exception { 64 ProjectDataSource src = (ProjectDataSource) nodeObj.getDataSource(); 65 new ConfigSaver().storeDataNode(out, getProject(), src.getDataSourceInfo()); 66 } 67 68 71 public boolean canHandle(Object obj) { 72 if (obj instanceof DataNode) { 73 DataNode node = (DataNode) obj; 74 75 if (DriverDataSourceFactory 77 .class 78 .getName() 79 .equals(node.getDataSourceFactory())) { 80 return true; 81 } 82 } 83 84 return false; 85 } 86 87 90 public void willSave() { 91 super.willSave(); 92 93 if (nodeObj != null && canHandle(nodeObj)) { 94 nodeObj.setDataSourceLocation(getLocation()); 95 } 96 } 97 98 102 public String getLocationSuffix() { 103 return LOCATION_SUFFIX; 104 } 105 } 106 | Popular Tags |