KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > jaxwssupport > SunJaxWsXmlElementSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.refactoring.jaxwssupport;
21
22 import java.io.IOException JavaDoc;
23 import java.io.OutputStream JavaDoc;
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 /**
34  * Base class for sun jax ws refactoring elements.
35  *
36  * @author Erno Mononen
37  */

38 public abstract class SunJaxWsXmlElementSupport extends AbstractRenameRefactoringElement implements ExternalChange {
39     
40     private Endpoint endpoint;
41     private Endpoints model;
42     
43     /**
44      * Creates a new instance of JaxWsXmlRefactoringElementSupport
45      * @param oldName the fully qualified old name of the implementation class.
46      * @param newName the fully qualified new name of the implementation class.
47      * @model the model representing <code>sun-jaxws.xml</code>.
48      * @endpoint the endpoint whose implementation class is to be renamed.
49      * @parentFile the file object representing jax-ws.xml.
50      */

51     public SunJaxWsXmlElementSupport(String JavaDoc oldName, String JavaDoc 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     /**
72      * Writes the model.
73      */

74     protected void writeModel(){
75         FileLock lock = null;
76         try {
77             lock = parentFile.lock();
78             OutputStream JavaDoc os = parentFile.getOutputStream(lock);
79             try{
80                 model.write(os);
81             } finally {
82                 os.close();
83             }
84         } catch (IOException JavaDoc 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