KickJava   Java API By Example, From Geeks To Geeks.

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


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.Model;
25
26 /**
27  *
28  * @author Nam Nguyen
29  */

30 public class FileRenameRequest extends RefactorRequest {
31     private String JavaDoc oldFileName;
32     private String JavaDoc newFileName;
33     private Model target;
34
35     /** Creates a new instance of FileRenameRequest */
36     public FileRenameRequest(Model target) {
37         this(target, (Set JavaDoc<Component>)null);
38     }
39     
40     public FileRenameRequest(Model target, Set JavaDoc<Component> scope) {
41         super(scope);
42         if (! (target instanceof Model)) {
43             throw new IllegalArgumentException JavaDoc("Expect refactor target is a Model instance");
44         }
45         this.target = target;
46         oldFileName = getTargetName();
47     }
48     
49     public FileRenameRequest(Model target, String JavaDoc newFileName) {
50         this(target, (Set JavaDoc<Component>)null);
51         this.newFileName = newFileName;
52     }
53     
54     public Class JavaDoc<FileRenameRequest> getType() {
55         return FileRenameRequest.class;
56     }
57     
58     public boolean confirmChangePerformed() {
59         return getFileObject().getName().equals(newFileName);
60     }
61     
62     public Model getTarget() {
63         return target;
64     }
65
66     public String JavaDoc getOldFileName() {
67         return oldFileName;
68     }
69     
70     public String JavaDoc getNewFileName() {
71         return newFileName;
72     }
73
74     public void setNewFileName(String JavaDoc v) {
75         newFileName = v;
76     }
77     
78     public String JavaDoc getTargetName() {
79         return this.getFileObject().getName();
80     }
81     
82     public String JavaDoc calculateNewLocationString(String JavaDoc currentLocationString) {
83         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
84         int i = currentLocationString.lastIndexOf('/');
85         if (i > -1) {
86             sb.append(currentLocationString.substring(0, i+1));
87         }
88         sb.append(getNewFileName());
89         sb.append("."); //NOI18N
90
sb.append(getFileObject().getExt());
91         return sb.toString();
92     }
93
94     public void precheckChange() {
95         super.precheckChange();
96         ErrorItem error = RefactoringUtil.precheck(this);
97         if (error != null) {
98             addError(error);
99         }
100     }
101
102 }
103
Popular Tags