KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > ui > j > api > RefactoringSession


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.ui.j.api;
20
21 import java.util.AbstractCollection JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26
27 //import org.netbeans.api.mdr.MDRepository;
28
//import org.netbeans.modules.javacore.api.JavaModel;
29
//import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
30
//import org.netbeans.modules.refactoring.ProgressSupport;
31
//import org.netbeans.modules.refactoring.SPIAccessor;
32
//import org.netbeans.modules.refactoring.classpath.RefactoringClassPathImplementation;
33
//import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
34
//import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
35

36
37 /** Singleton class used to invoke refactorings.
38  *
39  * @author Martin Matula, Daniel Prusa
40  */

41 public final class RefactoringSession {
42 //public final class RefactoringSession {
43
private final LinkedList JavaDoc internalList;
44 // private final RefactoringElementsBag bag;
45
private final Collection JavaDoc refactoringElements;
46     private final String JavaDoc description;
47 // private ProgressSupport progressSupport;
48

49     private RefactoringSession(String JavaDoc description) {
50         internalList = new LinkedList JavaDoc();
51 // bag = SPIAccessor.DEFAULT.createBag(this, internalList);
52
this.description = description;
53         this.refactoringElements = new ElementsCollection();
54     }
55     
56     /** Creates a new refactoring session.
57      */

58     public static RefactoringSession create(String JavaDoc description) {
59         return new RefactoringSession(description);
60     }
61
62     public Problem doRefactoring(boolean saveAfterDone) {
63 // Iterator it = internalList.iterator();
64
// fireProgressListenerStart(0, internalList.size()+1);
65
// try {
66
// MDRepository repository = JavaModel.getJavaRepository();
67
// boolean fail = true;
68
// repository.beginTrans(true);
69
// JavaMetamodel.getUndoManager().setUndoDescription(description);
70
// try {
71
// JavaModel.setClassPath(RefactoringClassPathImplementation.getDefault());
72
// while (it.hasNext()) {
73
// fireProgressListenerStep();
74
// RefactoringElementImplementation element = (RefactoringElementImplementation) it.next();
75
// if (element.isEnabled() && !((element.getStatus() == RefactoringElement.GUARDED) || (element.getStatus() == RefactoringElement.READ_ONLY))) {
76
// element.performChange();
77
// }
78
// }
79
// fail = false;
80
// } finally {
81
// repository.endTrans(fail);
82
// }
83
// if (saveAfterDone) {
84
// JavaMetamodel.getUndoManager().saveAll();
85
// }
86
// fireProgressListenerStep();
87
// } finally {
88
// fireProgressListenerStop();
89
// }
90
return null;
91     }
92     
93     public Collection JavaDoc getRefactoringElements() {
94         return refactoringElements;
95     }
96     
97     public synchronized void addProgressListener(ProgressListener listener) {
98 // if (progressSupport == null ) {
99
// progressSupport = new ProgressSupport();
100
// }
101
// progressSupport.addProgressListener(listener);
102
}
103
104     public synchronized void removeProgressListener(ProgressListener listener) {
105 // if (progressSupport != null ) {
106
// progressSupport.removeProgressListener(listener);
107
// }
108
}
109
110 // RefactoringElementsBag getElementsBag() {
111
// return bag;
112
// }
113

114     private void fireProgressListenerStart(int type, int count) {
115 // if (progressSupport != null) {
116
// progressSupport.fireProgressListenerStart(this, type, count);
117
// }
118
}
119
120     private void fireProgressListenerStep() {
121 // if (progressSupport != null) {
122
// progressSupport.fireProgressListenerStep(this);
123
// }
124
}
125
126     private void fireProgressListenerStop() {
127 // if (progressSupport != null) {
128
// progressSupport.fireProgressListenerStop(this);
129
// }
130
}
131     
132     private class ElementsCollection extends AbstractCollection JavaDoc {
133         public Iterator JavaDoc iterator() {
134             return new Iterator JavaDoc() {
135                 private final Iterator JavaDoc inner = internalList.iterator();
136
137                 public void remove() {
138                     throw new UnsupportedOperationException JavaDoc();
139                 }
140                 
141                 public Object JavaDoc next() throws NoSuchElementException JavaDoc {
142 // return new RefactoringElement((RefactoringElementImplementation) inner.next());
143
return null;
144                 }
145                 
146                 public boolean hasNext() {
147                     return inner.hasNext();
148                 }
149             };
150         }
151
152         public int size() {
153             return internalList.size();
154         }
155     }
156 }
157
Popular Tags