1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 22 import java.io.IOException ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.spi.project.support.ant.EditableProperties; 26 import org.openide.ErrorManager; 27 28 32 public final class PropertyHelper { 33 35 private Project project; 36 private UpdateHelper updateHelper; 37 38 39 public PropertyHelper(Project project, UpdateHelper updateHelper) { 40 this.project = project; 41 this.updateHelper = updateHelper; 42 } 43 44 50 public String getProperty(String path, String key) { 51 return getProperties(path).getProperty(key); 52 } 53 54 61 public void setProperty(String path, String key, String value) { 62 assert ProjectManager.mutex().isWriteAccess() : "You must have write access to ProjectManager.mutex(). You can also use @see #saveProperty if you only need to save one property"; 63 64 EditableProperties ep = getProperties(path); 65 ep.setProperty(key, value); 66 putProperties(path, ep); 67 } 68 69 76 public void saveProperty(final String path, final String key, final String value) { 77 ProjectManager.mutex().writeAccess(new Runnable () { 78 public void run() { 79 setProperty(path, key, value); 80 save(); 81 } 82 }); 83 } 84 85 88 public void save() { 89 assert ProjectManager.mutex().isWriteAccess() : "You must have write access to ProjectManager.mutex()."; 90 91 try { 92 ProjectManager.getDefault().saveProject(project); 93 } 94 catch (IOException e) { 95 ErrorManager.getDefault().notify(e); 96 } 97 } 98 99 private EditableProperties getProperties(String path) { 100 return updateHelper.getProperties(path); 101 } 102 103 private void putProperties(String path, EditableProperties ep) { 104 updateHelper.putProperties(path, ep); 105 } 106 } 107 | Popular Tags |