1 19 20 package org.netbeans.modules.j2ee.refactoring.jaxwssupport; 21 22 import java.io.IOException ; 23 import java.io.OutputStream ; 24 import org.netbeans.modules.j2ee.refactoring.rename.AbstractRenameRefactoringElement; 25 import org.netbeans.modules.javacore.internalapi.ExternalChange; 26 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 27 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoint; 28 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoints; 29 import org.openide.ErrorManager; 30 import org.openide.filesystems.FileLock; 31 import org.openide.filesystems.FileObject; 32 33 38 public abstract class SunJaxWsXmlElementSupport extends AbstractRenameRefactoringElement implements ExternalChange { 39 40 private Endpoint endpoint; 41 private Endpoints model; 42 43 51 public SunJaxWsXmlElementSupport(String oldName, String newName, 52 Endpoints model, Endpoint endpoint, FileObject parentFile) { 53 54 this.oldName = oldName; 55 this.newName = newName; 56 this.endpoint = endpoint; 57 this.model = model; 58 this.parentFile = parentFile; 59 } 60 61 public void undoExternalChange() { 62 model.findEndpointByName(endpoint.getEndpointName()).setImplementation(oldName); 63 writeModel(); 64 } 65 66 public void performExternalChange() { 67 model.findEndpointByName(endpoint.getEndpointName()).setImplementation(newName); 68 writeModel(); 69 } 70 71 74 protected void writeModel(){ 75 FileLock lock = null; 76 try { 77 lock = parentFile.lock(); 78 OutputStream os = parentFile.getOutputStream(lock); 79 try{ 80 model.write(os); 81 } finally { 82 os.close(); 83 } 84 } catch (IOException ex) { 85 ErrorManager.getDefault().notify(ex); 86 } finally { 87 lock.releaseLock(); 88 } 89 } 90 public void performChange() { 91 JavaMetamodel.getManager().registerExtChange(this); 92 } 93 94 95 } 96 | Popular Tags |