KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > RenameRequest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.refactoring;
20
21 import java.util.Set JavaDoc;
22 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil;
23 import org.netbeans.modules.xml.xam.Component;
24 import org.netbeans.modules.xml.xam.Nameable;
25 import org.netbeans.modules.xml.xam.NamedReferenceable;
26 import org.openide.ErrorManager;
27
28 /**
29  *
30  * @author Nam Nguyen
31  */

32 public class RenameRequest extends RefactorRequest {
33     private Nameable target;
34     private String JavaDoc oldName;
35     private String JavaDoc newName;
36     private Nameable renamed;
37
38     /** Creates a new instance of RenameRequest */
39     public RenameRequest(Nameable target, String JavaDoc newName) {
40         this(target, newName, null);
41     }
42     
43     public RenameRequest(Nameable target, String JavaDoc newName, Set JavaDoc<Component> scope) {
44         super(scope);
45         assert target instanceof NamedReferenceable;
46         this.target = target;
47         this.oldName = target.getName();
48         this.newName = newName;
49     }
50     
51     public Class JavaDoc<RenameRequest> getType() {
52         return RenameRequest.class;
53     }
54     
55     public boolean confirmChangePerformed() {
56         String JavaDoc name = getTarget().getName();
57         if (getRenamedTarget() == null) {
58             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
59                     "Failed to rename target " + name); //NOI18N
60
}
61         return (getRenamedTarget() != null);
62     }
63     
64     public NamedReferenceable getTarget() {
65         return (NamedReferenceable) target;
66     }
67
68     public Nameable getNameableTarget() {
69         return target;
70     }
71     
72     public String JavaDoc getTargetName() {
73         return getOldName();
74     }
75     
76     public Nameable getRenamedTarget() {
77         return renamed;
78     }
79     
80     public void setRenamedTarget(Nameable renamed) {
81         this.renamed = renamed;
82     }
83
84     public String JavaDoc getNewName() {
85         return newName;
86     }
87     
88     public void setNewName(String JavaDoc v) {
89         newName = v;
90     }
91     
92     public String JavaDoc getOldName() {
93         return oldName;
94     }
95
96     public void precheckChange() {
97         super.precheckChange();
98         ErrorItem error = RefactoringUtil.precheck(this);
99         if (error != null) {
100             addError(error);
101         }
102     }
103 }
104
Popular Tags