KickJava   Java API By Example, From Geeks To Geeks.

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


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.j2ee.dd.api.ejb.EjbJar;
23 import org.netbeans.modules.j2ee.refactoring.Utility;
24 import org.netbeans.modules.j2ee.refactoring.J2EERefactoring;
25 import org.netbeans.modules.refactoring.api.AbstractRefactoring;
26 import org.netbeans.modules.refactoring.api.Problem;
27 import org.netbeans.modules.refactoring.api.RefactoringSession;
28 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
29 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
30 import org.netbeans.modules.web.taglib.TLDDataObject;
31 import org.netbeans.modules.web.taglib.model.Taglib;
32 import org.openide.filesystems.FileObject;
33
34 import java.util.Collection JavaDoc;
35 import java.util.LinkedList JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.io.IOException JavaDoc;
38 import org.openide.loaders.DataObject;
39
40 /**
41  * @author pfiala
42  */

43 public class BaseRefactoring implements J2EERefactoring {
44     final private Collection JavaDoc childRefactorings = new LinkedList JavaDoc();
45     protected BaseRefactoringHelper helper;
46
47     public BaseRefactoring(BaseRefactoringHelper helper) {
48         this.helper = helper;
49     }
50
51     public void addChildRefactoring(AbstractRefactoring refactoring) {
52         childRefactorings.add(refactoring);
53     }
54
55     public Problem preCheck() {
56         Problem problem = preCheckThis();
57         for (Iterator JavaDoc it = childRefactorings.iterator(); it.hasNext();) {
58             AbstractRefactoring refactoring = (AbstractRefactoring) it.next();
59             problem = Utility.addProblemsToEnd(problem, refactoring.preCheck());
60         }
61         return problem;
62     }
63
64     public Problem checkParameters() {
65         Problem problem = checkParametersThis();
66         for (Iterator JavaDoc it = childRefactorings.iterator(); it.hasNext();) {
67             AbstractRefactoring refactoring = (AbstractRefactoring) it.next();
68             problem = Utility.addProblemsToEnd(problem, refactoring.checkParameters());
69         }
70         return problem;
71     }
72
73
74     public Problem fastCheckParameters() {
75         Problem problem = fastCheckParametersThis();
76         for (Iterator JavaDoc it = childRefactorings.iterator(); it.hasNext();) {
77             AbstractRefactoring refactoring = (AbstractRefactoring) it.next();
78             problem = Utility.addProblemsToEnd(problem, refactoring.fastCheckParameters());
79         }
80         return problem;
81     }
82
83     public Problem prepare(RefactoringElementsBag refactoringElementsBag) {
84         Problem problem = prepareThis(refactoringElementsBag);
85         final RefactoringSession session = refactoringElementsBag.getSession();
86         for (Iterator JavaDoc it = childRefactorings.iterator(); it.hasNext();) {
87             AbstractRefactoring refactoring = (AbstractRefactoring) it.next();
88             problem = Utility.addProblemsToEnd(problem, refactoring.prepare(session));
89         }
90         return problem;
91     }
92
93     protected Problem preCheckThis() {
94         return null;
95     }
96
97     protected Problem checkParametersThis() {
98         return null;
99     }
100
101     protected Problem fastCheckParametersThis() {
102         return null;
103     }
104
105     protected Problem prepareThis(RefactoringElementsBag refactoringElementsBag) {
106         return null;
107     }
108
109
110     public static class EjbHelper extends BaseRefactoringHelper {
111         private final EjbJar ejbJar;
112
113         public EjbHelper(AbstractRefactoring refactoring, FileObject fileObject, EjbJar ejbJar) {
114             super(refactoring, fileObject);
115             this.ejbJar = ejbJar;
116         }
117
118         public void writeDD() {
119             try {
120                 ejbJar.write(getFileObject());
121             } catch (IOException JavaDoc e) {
122                 //todo
123
}
124         }
125
126         public EjbJar getEjbJar() {
127             return ejbJar;
128         }
129
130     }
131
132     public static class TldHelper extends BaseRefactoringHelper {
133         private final Taglib taglib;
134
135         public TldHelper(AbstractRefactoring refactoring, FileObject fileObject, Taglib taglib) {
136             super(refactoring, fileObject);
137             this.taglib = taglib;
138         }
139
140         public void writeDD() {
141             try {
142                 TLDDataObject tdo =(TLDDataObject)DataObject.find(getFileObject());
143                 if (tdo != null) {
144                     tdo.write(taglib);
145                 }
146             } catch (IOException JavaDoc ioe) {
147                 //TODO
148
}
149         }
150
151         public Taglib getTaglib() {
152             return taglib;
153         }
154     }
155     
156 }
Popular Tags