KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > safedelete > TldClassSafeDeleteRefactoring


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.safedelete;
21
22 import org.netbeans.modules.refactoring.api.Problem;
23 import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
24 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
25 import org.netbeans.modules.j2ee.refactoring.Utility;
26 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
27 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession;
28 import org.netbeans.modules.javacore.internalapi.ExternalChange;
29 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
30 import org.netbeans.jmi.javamodel.JavaClass;
31 import org.netbeans.jmi.javamodel.UnresolvedClass;
32 import org.netbeans.jmi.javamodel.Element;
33 import org.netbeans.modules.web.taglib.model.FunctionType;
34 import org.netbeans.modules.web.taglib.model.TagType;
35 import org.netbeans.modules.web.taglib.model.Taglib;
36 import org.netbeans.modules.web.taglib.model.Taglib;
37 import org.netbeans.modules.web.taglib.model.ValidatorType;
38 import org.openide.util.NbBundle;
39
40 import java.util.List JavaDoc;
41 import java.util.LinkedList JavaDoc;
42
43 /**
44  * @author Martin Grebac
45  */

46 public class TldClassSafeDeleteRefactoring extends BaseRefactoring {
47     private final Taglib taglib;
48     private JavaClass javaClass;
49
50     public TldClassSafeDeleteRefactoring(TldHelper helper, Taglib taglib, JavaClass javaClass) {
51         super(helper);
52         this.taglib = taglib;
53         this.javaClass = javaClass;
54     }
55
56     protected Problem preCheckThis() {
57         return null;
58     }
59
60     protected Problem prepareThis(RefactoringElementsBag refactoringElementsBag) {
61         String JavaDoc name = javaClass.getName();
62         // tag element
63
TagType[] tagTypes = taglib.getTag();
64         if ((tagTypes != null) && (tagTypes.length > 0)) {
65             for (int tt = 0; tt < tagTypes.length; tt++) {
66                 TagType tagT = tagTypes[tt];
67                 String JavaDoc tagClass = tagT.getTagClass();
68                 if ((tagClass != null) && (tagClass.equals(name))) {
69                     helper.addRefactoringElement(refactoringElementsBag, new TaglibTagClassSafeDeleteRefactoringElement(taglib, tagT/*, tld*/));
70                 }
71                 String JavaDoc teiClass = tagT.getTeiClass();
72                 if ((teiClass != null) && (teiClass.equals(name))) {
73 // helper.addRefactoringElement(refactoringElementsBag, TaglibTeiClassSafeDeleteRefactoringElement(taglib, name, tagT, tld));
74
}
75             }
76         }
77
78         FunctionType[] functionTypes = taglib.getFunction();
79         if ((functionTypes != null) && (functionTypes.length > 0)) {
80             for (int tt = 0; tt < functionTypes.length; tt++) {
81                 FunctionType functionT = functionTypes[tt];
82                 String JavaDoc functionClass = functionT.getFunctionClass();
83                 if ((functionClass != null) && (functionClass.equals(name))) {
84 // helper.addRefactoringElement(refactoringElementsBag, TaglibFunctionClassSafeDeleteRefactoringElement(taglib, name, tagT/*, tld*/));
85
}
86             }
87         }
88
89         // validator element
90
ValidatorType validatorType = taglib.getValidator();
91         if (validatorType != null) {
92             String JavaDoc validatorClass = validatorType.getValidatorClass();
93             if ((validatorClass != null) && (validatorClass.equals(name))) {
94 // helper.addRefactoringElement(refactoringElementsBag, TaglibValidatorClassSafeDeleteRefactoringElement(taglib, name, tagT/*, tld*/));
95
}
96         }
97
98         // listener element
99
org.netbeans.modules.web.taglib.model.ListenerType[] listenerTypes = taglib.getListener();
100         if ((listenerTypes != null) && (listenerTypes.length > 0)) {
101             for (int tt = 0; tt < listenerTypes.length; tt++) {
102                 org.netbeans.modules.web.taglib.model.ListenerType listenerT = listenerTypes[tt];
103                 String JavaDoc listenerClass = listenerT.getListenerClass();
104                 if ((listenerClass != null) && (listenerClass.equals(name))) {
105 // helper.addRefactoringElement(refactoringElementsBag, TaglibTagClassSafeDeleteRefactoringElement(taglib, name, tagT/*, tld*/));
106
}
107             }
108         }
109         return null;
110     }
111
112     public final class TaglibTagClassSafeDeleteRefactoringElement extends AbstractSafeDeleteRefactoringElement implements ExternalChange {
113
114         private TagType tagType = null;
115
116         public TaglibTagClassSafeDeleteRefactoringElement(Taglib taglib, TagType tagType) {
117             super(helper.getFileObject());
118             this.tagType = tagType;
119         }
120
121         /**
122          * Returns text describing the refactoring formatted for display (using HTML tags).
123          *
124          * @return Formatted text.
125          */

126         public String JavaDoc getDisplayText() {
127             return NbBundle.getMessage(TaglibTagClassSafeDeleteRefactoringElement.class, "TXT_TaglibTagClassSafeDelete", tagType.getName());
128         }
129
130         /**
131          * Performs the change represented by this refactoring element.
132          */

133         public void performChange() {
134             JavaMetamodel.getManager().registerExtChange(this);
135         }
136
137         public void performExternalChange() {
138             taglib.removeTag(tagType);
139             helper.writeDD();
140         }
141
142         public void undoExternalChange() {
143             taglib.addTag(tagType);
144             helper.writeDD();
145         }
146     }
147 }
148
Popular Tags