~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to j2ee/refactoring/src/org/netbeans/modules/j2ee/refactoring/moveclass/TldMoveClassRefactoring.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.j2ee.refactoring.moveclass;
 
43
 
 
44
import java.io.File;
 
45
import java.io.IOException;
 
46
import java.text.MessageFormat;
 
47
import java.util.Collection;
 
48
import java.util.Enumeration;
 
49
import java.util.Iterator;
 
50
import java.util.List;
 
51
import javax.jmi.reflect.RefObject;
 
52
import org.netbeans.modules.j2ee.dd.api.web.WebApp;
 
53
import org.netbeans.jmi.javamodel.JavaClass;
 
54
import org.netbeans.jmi.javamodel.Resource;
 
55
import org.netbeans.modules.j2ee.refactoring.Utility;
 
56
import org.netbeans.modules.javacore.api.JavaModel;
 
57
import org.netbeans.modules.javacore.internalapi.ExternalChange;
 
58
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
 
59
import org.netbeans.modules.refactoring.api.MoveClassRefactoring;
 
60
import org.netbeans.modules.refactoring.api.Problem;
 
61
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
 
62
import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
 
63
import org.netbeans.modules.web.api.webmodule.WebModule;
 
64
import org.netbeans.modules.web.taglib.TLDDataObject;
 
65
import org.netbeans.modules.web.taglib.TLDLoader;
 
66
import org.netbeans.modules.web.taglib.model.FunctionType;
 
67
import org.netbeans.modules.web.taglib.model.ListenerType;
 
68
import org.netbeans.modules.web.taglib.model.TagType;
 
69
import org.netbeans.modules.web.taglib.model.Taglib;
 
70
import org.netbeans.modules.web.taglib.model.ValidatorType;
 
71
import org.openide.ErrorManager;
 
72
import org.openide.cookies.EditorCookie;
 
73
import org.openide.cookies.OpenCookie;
 
74
import org.openide.filesystems.FileObject;
 
75
import org.openide.filesystems.FileUtil;
 
76
import org.openide.loaders.DataObject;
 
77
import org.openide.loaders.DataObjectNotFoundException;
 
78
import org.openide.util.NbBundle;
 
79
 
 
80
/**
 
81
 *
 
82
 * @author Martin Grebac
 
83
 */
 
84
public final class TldMoveClassRefactoring {
 
85
    
 
86
    private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename");   // NOI18N
 
87
 
 
88
    public TldMoveClassRefactoring() { }
 
89
 
 
90
    /** Find usages in web deployment descriptor: web.xml 
 
91
     */
 
92
    public Problem prepare(MoveClassRefactoring moveClassRefactor, Collection resources, RefactoringElementsBag refactoringElements) {
 
93
        Problem problem = null;
 
94
            
 
95
        for (Iterator i = resources.iterator(); i.hasNext();) {
 
96
            Resource resource = (Resource) i.next();
 
97
            FileObject fo = JavaModel.getFileObject(resource);
 
98
 
 
99
            err.log("resource package name:  " + resource.getPackageName());
 
100
            err.log("resource: name " + resource.getName());
 
101
 
 
102
            WebModule wm = WebModule.getWebModule(fo);
 
103
            
 
104
            FileObject target = moveClassRefactor.getTargetClassPathRoot();
 
105
            WebModule wmNew = null;
 
106
            if  (target != null) {
 
107
                wmNew = WebModule.getWebModule(moveClassRefactor.getTargetClassPathRoot());
 
108
            }
 
109
            
 
110
            if (wm != null) {              // the class is in a web module, therefore tld makes sense
 
111
                boolean moveToAnotherProject = false; 
 
112
                
 
113
                if (wmNew != null) {
 
114
                    moveToAnotherProject = !wm.equals(wmNew);
 
115
                }
 
116
    
 
117
                FileObject webInf = wm.getWebInf();
 
118
                Enumeration e = null;
 
119
                if (webInf != null) {
 
120
                    e = webInf.getChildren(true);
 
121
                }
 
122
                if (e != null) {
 
123
                    while (e.hasMoreElements()) {
 
124
                        FileObject tld = (FileObject)e.nextElement();
 
125
                        FileObject tldNew = null;
 
126
                        
 
127
                        if (isTld(tld)) {
 
128
 
 
129
                            DataObject tldData = null;
 
130
                            DataObject newTldData = null;
 
131
                            
 
132
                            try {
 
133
                                tldData = DataObject.find(tld);
 
134
                            } catch (DataObjectNotFoundException dne) {
 
135
                                // ignore
 
136
                            }
 
137
                            
 
138
                            if (moveToAnotherProject) {
 
139
                                FileObject webInfNew = wmNew.getWebInf();
 
140
                                Enumeration e2 = null;
 
141
                                if (webInfNew != null) {
 
142
                                    e2 = webInfNew.getChildren(true);
 
143
                                }
 
144
                                while (e2.hasMoreElements()) {
 
145
                                    tldNew = (FileObject)e2.nextElement();
 
146
                                    if (isTld(tldNew)) {
 
147
                                        try {
 
148
                                            newTldData = DataObject.find(tldNew);
 
149
                                            break;
 
150
                                        } catch (DataObjectNotFoundException dne) {
 
151
                                            // ignore
 
152
                                        }
 
153
                                    }
 
154
                                }
 
155
                                if (newTldData == null) {
 
156
                                    Problem newProblem = new Problem(false, NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibNotExistMoveClassOtherProjectInvalidProblem"));
 
157
                                    problem = Utility.addProblemsToEnd(problem, newProblem);
 
158
                                }
 
159
                            }
 
160
                            
 
161
                            
 
162
                            if ((tldData != null) && (tldData instanceof TLDDataObject)) {
 
163
                                Taglib taglib = null;
 
164
                                try {
 
165
                                    taglib = ((TLDDataObject)tldData).getTaglib();
 
166
                                } catch (IOException ioe) {}
 
167
                                if (taglib != null) {
 
168
                                    List classes = resource.getClassifiers();
 
169
                                    err.log("Classes in resource: " + classes);
 
170
 
 
171
                                    for (int j=0; j < classes.size(); j++ ) {
 
172
                                        JavaClass jClass = (JavaClass)classes.get(j);
 
173
                                        err.log("javaclass: "+ jClass);
 
174
 
 
175
                                        String name = jClass.getName();
 
176
                                        err.log("name: " + name);
 
177
 
 
178
                                        String targetPackage = moveClassRefactor.getTargetPackageName(resource);
 
179
                                        err.log("targetPackage: " + targetPackage);
 
180
 
 
181
                                        String newName = targetPackage + "." + jClass.getSimpleName();
 
182
                                        err.log("newname: " + newName);
 
183
 
 
184
                                        // tag element
 
185
                                        TagType[] tagTypes = taglib.getTag();
 
186
                                        if ((tagTypes != null) && (tagTypes.length > 0)) {
 
187
                                            for (int tt = 0; tt < tagTypes.length; tt++) {
 
188
                                                TagType tagT = tagTypes[tt];
 
189
                                                String tagClass = tagT.getTagClass();
 
190
                                                String teiClass = tagT.getTeiClass();
 
191
                                                if (!moveToAnotherProject) {
 
192
                                                    if ((tagClass != null) && (tagClass.equals(name))) {
 
193
                                                        RefactoringElementImplementation elem = new TaglibTagClassMoveClassRefactoringElement(tldData, name, newName);
 
194
                                                        refactoringElements.add(moveClassRefactor, elem);
 
195
                                                    }
 
196
                                                    if ((teiClass != null) && (teiClass.equals(name))) {
 
197
                                                        RefactoringElementImplementation elem = new TaglibTeiClassMoveClassRefactoringElement(tldData, name, newName);
 
198
                                                        refactoringElements.add(moveClassRefactor, elem);
 
199
                                                    }
 
200
                                                } else {
 
201
                                                    if (newTldData != null) {
 
202
                                                        if ((tagClass != null) && (tagClass.equals(name))) {
 
203
                                                            RefactoringElementImplementation elem = new TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement(tldData, newTldData, name, newName);
 
204
                                                            refactoringElements.add(moveClassRefactor, elem);
 
205
                                                        }
 
206
                                                        if ((teiClass != null) && (teiClass.equals(name))) {
 
207
                                                            RefactoringElementImplementation elem = new TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement(tldData, newTldData, name, newName);
 
208
                                                            refactoringElements.add(moveClassRefactor, elem);
 
209
                                                        }
 
210
                                                    }
 
211
                                                }
 
212
                                            }
 
213
                                        }
 
214
 
 
215
                                        FunctionType[] functionTypes = taglib.getFunction();
 
216
                                        if ((functionTypes != null) && (functionTypes.length > 0)) {
 
217
                                            for (int tt = 0; tt < functionTypes.length; tt++) {
 
218
                                                FunctionType functionT = functionTypes[tt];
 
219
                                                String functionClass = functionT.getFunctionClass();
 
220
                                                if ((functionClass != null) && (functionClass.equals(name))) {
 
221
                                                    RefactoringElementImplementation elem = new TaglibFunctionClassMoveClassRefactoringElement(tldData, name, newName);
 
222
                                                    refactoringElements.add(moveClassRefactor, elem);
 
223
                                                }
 
224
                                            }
 
225
                                        }
 
226
 
 
227
                                        // validator element
 
228
                                        ValidatorType validatorType = taglib.getValidator();
 
229
                                        if (validatorType != null) {
 
230
                                            String validatorClass = validatorType.getValidatorClass();
 
231
                                            if ((validatorClass != null) && (validatorClass.equals(name))) {
 
232
                                                RefactoringElementImplementation elem = new TaglibValidatorClassMoveClassRefactoringElement(tldData, name, newName);
 
233
                                                refactoringElements.add(moveClassRefactor, elem);
 
234
                                            }
 
235
                                        }
 
236
 
 
237
                                        // listener element
 
238
                                        org.netbeans.modules.web.taglib.model.ListenerType[] listenerTypes = taglib.getListener();
 
239
                                        if ((listenerTypes != null) && (listenerTypes.length > 0)) {
 
240
                                            for (int tt = 0; tt < listenerTypes.length; tt++) {
 
241
                                                org.netbeans.modules.web.taglib.model.ListenerType listenerT = listenerTypes[tt];
 
242
                                                String listenerClass = listenerT.getListenerClass();
 
243
                                                if ((listenerClass != null) && (listenerClass.equals(name))) {
 
244
                                                    RefactoringElementImplementation elem = new TaglibListenerClassMoveClassRefactoringElement(tldData, name, newName);
 
245
                                                    refactoringElements.add(moveClassRefactor, elem);
 
246
                                                }
 
247
                                            }
 
248
                                        }
 
249
 
 
250
 
 
251
                                    }
 
252
 
 
253
                                } else {
 
254
                                    Object[] args = new Object [] {tld.getNameExt()};
 
255
                                    String msg = MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibMoveClassInvalidProblem"), args);
 
256
                                    Problem newProblem = new Problem(false, msg);
 
257
                                    problem = Utility.addProblemsToEnd(problem, newProblem);
 
258
                                }
 
259
                            }
 
260
                        }
 
261
                    }
 
262
                }
 
263
            }
 
264
        }
 
265
        return problem;
 
266
    }
 
267
 
 
268
    private boolean isTld(FileObject fo) {
 
269
        boolean isTld = false;
 
270
        if (fo != null) {
 
271
            String ext = fo.getExt();
 
272
            if (TLDLoader.tldExt.equalsIgnoreCase(ext)) {
 
273
                isTld = true;
 
274
            }
 
275
        }
 
276
        return isTld;
 
277
    }
 
278
        
 
279
    public final class TaglibTagClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
280
 
 
281
        protected DataObject data = null;
 
282
 
 
283
        /** Creates a new instance of TaglibTagClassMoveClassRefactoringElement */
 
284
        public TaglibTagClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 
 
285
            this.data = data;
 
286
            this.oldName = oldName;
 
287
            this.newName = newName;
 
288
        }
 
289
 
 
290
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
291
         * @return Formatted text.
 
292
         */
 
293
        public String getDisplayText() {
 
294
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
295
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTagClassMoveClass"), args);
 
296
        }
 
297
 
 
298
        /** Returns file that the element affects (relates to)
 
299
         * @return File
 
300
         */
 
301
        public FileObject getParentFile() {
 
302
            if (data != null) {
 
303
                return data.getPrimaryFile();                
 
304
            }
 
305
            return null;
 
306
        }        
 
307
 
 
308
        /** Performs the change represented by this refactoring element.
 
309
         */
 
310
        public void performChange() {
 
311
            JavaMetamodel.getManager().registerExtChange(this);
 
312
        }
 
313
 
 
314
        public void performExternalChange() {
 
315
            if (data != null) {
 
316
                FileObject tldFO = data.getPrimaryFile();
 
317
                TLDDataObject tdo = ((TLDDataObject)data);
 
318
                Taglib taglib = null;
 
319
                try {
 
320
                    taglib = tdo.getTaglib();
 
321
                } catch (IOException ioe) { 
 
322
                    //ignore 
 
323
                }
 
324
                if (taglib != null) /* TODO check validity */ {
 
325
                    err.log("perform external change: TaglibTagClassMoveClassRefactoringElement");
 
326
                    TagType tag = null;
 
327
                    TagType[] tags = taglib.getTag();
 
328
                    for (int i=0; i < tags.length; i++) {
 
329
                        String tagClass = tags[i].getTagClass();
 
330
                        if (oldName.equals(tagClass)) {
 
331
                            tag = tags[i];
 
332
                            break;
 
333
                        }
 
334
                    }
 
335
                    if (tag!=null) {
 
336
                        tag.setTagClass(newName);
 
337
                        try {
 
338
                            if (tdo != null) {
 
339
                                tdo.write(taglib);
 
340
                            }
 
341
                        } catch (IOException ioe) {
 
342
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
343
                        }
 
344
                    }
 
345
                }
 
346
            }
 
347
        }
 
348
        
 
349
        public void undoExternalChange() {
 
350
            if (data != null) {
 
351
                FileObject tldFO = data.getPrimaryFile();
 
352
                TLDDataObject tdo = ((TLDDataObject)data);
 
353
                Taglib taglib = null;
 
354
                try {
 
355
                    taglib = tdo.getTaglib();
 
356
                } catch (IOException ioe) { 
 
357
                    //ignore 
 
358
                }
 
359
                if (taglib != null) /* TODO check validity */ {
 
360
                    err.log("undo external change: TaglibTagClassMoveClassRefactoringElement");
 
361
                    TagType tag = null;
 
362
                    TagType[] tags = taglib.getTag();
 
363
                    for (int i=0; i < tags.length; i++) {
 
364
                        String tagClass = tags[i].getTagClass();
 
365
                        if (newName.equals(tagClass)) {
 
366
                            tag = tags[i];
 
367
                            break;
 
368
                        }
 
369
                    }
 
370
                    if (tag!=null) {
 
371
                        tag.setTagClass(oldName);
 
372
                        try {
 
373
                            if (tdo != null) {
 
374
                                tdo.write(taglib);
 
375
                            }
 
376
                        } catch (IOException ioe) {
 
377
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
378
                        }
 
379
                    }
 
380
                }
 
381
            }
 
382
        }
 
383
    }    
 
384
    
 
385
    
 
386
    public final class TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
387
 
 
388
        protected DataObject data = null;
 
389
        protected DataObject newData = null;
 
390
 
 
391
        /** Creates a new instance of TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement */
 
392
        public TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 
 
393
            this.data = data;
 
394
            this.newData = newData;
 
395
            this.oldName = oldName;
 
396
            this.newName = newName;
 
397
        }
 
398
 
 
399
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
400
         * @return Formatted text.
 
401
         */
 
402
        public String getDisplayText() {
 
403
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), data.getPrimaryFile().getNameExt(), newData.getPrimaryFile().getNameExt()};
 
404
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTagClassReferenceMoveClassOtherProject"), args);
 
405
        }
 
406
 
 
407
        /** Returns file that the element affects (relates to)
 
408
         * @return File
 
409
         */
 
410
        public FileObject getParentFile() {
 
411
            if (data != null) {
 
412
                return data.getPrimaryFile();                
 
413
            }
 
414
            return null;
 
415
        }
 
416
 
 
417
        /** Performs the change represented by this refactoring element.
 
418
         */
 
419
        public void performChange() {
 
420
            JavaMetamodel.getManager().registerExtChange(this);
 
421
        }
 
422
 
 
423
        public void performExternalChange() {
 
424
            if (data != null) {
 
425
                FileObject tldFO = data.getPrimaryFile();
 
426
                TLDDataObject tdo = ((TLDDataObject)data);
 
427
 
 
428
                FileObject newTldFO = newData.getPrimaryFile();
 
429
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
430
                
 
431
                Taglib taglib = null;
 
432
                Taglib newTaglib = null;
 
433
                try {
 
434
                    taglib = tdo.getTaglib();
 
435
                    newTaglib = newTdo.getTaglib();
 
436
                } catch (IOException ioe) { 
 
437
                    //ignore 
 
438
                }
 
439
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
440
                    err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject");
 
441
                    TagType tag = null;
 
442
                    TagType[] tags = taglib.getTag();
 
443
                    for (int i=0; i < tags.length; i++) {
 
444
                        String tagClass = tags[i].getTagClass();
 
445
                        if (oldName.equals(tagClass)) {
 
446
                            tag = tags[i];
 
447
                            break;
 
448
                        }
 
449
                    }
 
450
                    if (tag != null) {
 
451
                        taglib.removeTag(tag);
 
452
                        tag.setTagClass(newName);
 
453
                        newTaglib.addTag(tag);
 
454
                        try {
 
455
                            if (tdo != null) {
 
456
                                tdo.write(taglib);
 
457
                            }
 
458
                            if (newTdo != null) {
 
459
                                newTdo.write(newTaglib);
 
460
                            }
 
461
                        } catch (IOException ioe) {
 
462
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
463
                        }
 
464
                    }
 
465
                }
 
466
            }
 
467
        }
 
468
        
 
469
        public void undoExternalChange() {
 
470
            if (data != null) {
 
471
                FileObject tldFO = data.getPrimaryFile();
 
472
                TLDDataObject tdo = ((TLDDataObject)data);
 
473
 
 
474
                FileObject newTldFO = newData.getPrimaryFile();
 
475
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
476
                
 
477
                Taglib taglib = null;
 
478
                Taglib newTaglib = null;
 
479
                try {
 
480
                    taglib = tdo.getTaglib();
 
481
                    newTaglib = newTdo.getTaglib();
 
482
                } catch (IOException ioe) { 
 
483
                    //ignore 
 
484
                }
 
485
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
486
                    err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject");
 
487
                    TagType tag = null;
 
488
                    TagType[] tags = newTaglib.getTag();
 
489
                    for (int i=0; i < tags.length; i++) {
 
490
                        String tagClass = tags[i].getTagClass();
 
491
                        if (newName.equals(tagClass)) {
 
492
                            tag = tags[i];
 
493
                            break;
 
494
                        }
 
495
                    }
 
496
                    if (tag != null) {
 
497
                        newTaglib.removeTag(tag);
 
498
                        tag.setTagClass(oldName);
 
499
                        taglib.addTag(tag);
 
500
                        try {
 
501
                            if (tdo != null) {
 
502
                                tdo.write(taglib);
 
503
                            }
 
504
                            if (newTdo != null) {
 
505
                                newTdo.write(newTaglib);
 
506
                            }
 
507
                        } catch (IOException ioe) {
 
508
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
509
                        }
 
510
                    }
 
511
                }
 
512
            }
 
513
        }
 
514
    }    
 
515
    
 
516
    
 
517
    public final class TaglibTeiClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
518
 
 
519
        protected DataObject data = null;
 
520
 
 
521
        /** Creates a new instance of TaglibTeiClassMoveClassRefactoringElement */
 
522
        public TaglibTeiClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 
 
523
            this.data = data;
 
524
            this.oldName = oldName;
 
525
            this.newName = newName;
 
526
        }
 
527
 
 
528
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
529
         * @return Formatted text.
 
530
         */
 
531
        public String getDisplayText() {
 
532
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
533
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTeiClassMoveClass"), args);
 
534
        }
 
535
 
 
536
        /** Returns file that the element affects (relates to)
 
537
         * @return File
 
538
         */
 
539
        public FileObject getParentFile() {
 
540
            if (data != null) {
 
541
                return data.getPrimaryFile();                
 
542
            }
 
543
            return null;
 
544
        }        
 
545
 
 
546
        /** Performs the change represented by this refactoring element.
 
547
         */
 
548
        public void performChange() {
 
549
            JavaMetamodel.getManager().registerExtChange(this);
 
550
        }
 
551
 
 
552
        public void performExternalChange() {
 
553
            if (data != null) {
 
554
                FileObject tldFO = data.getPrimaryFile();
 
555
                TLDDataObject tdo = ((TLDDataObject)data);
 
556
                Taglib taglib = null;
 
557
                try {
 
558
                    taglib = tdo.getTaglib();
 
559
                } catch (IOException ioe) { 
 
560
                    //ignore 
 
561
                }
 
562
                if (taglib != null) /* TODO check validity */ {
 
563
                    TagType tag = null;
 
564
                    TagType[] tags = taglib.getTag();
 
565
                    for (int i=0; i < tags.length; i++) {
 
566
                        String teiClass = tags[i].getTagClass();
 
567
                        if (oldName.equals(teiClass)) {
 
568
                            tag = tags[i];
 
569
                            break;
 
570
                        }
 
571
                    }
 
572
                    if (tag!=null) {
 
573
                        tag.setTeiClass(newName);
 
574
                        try {
 
575
                            if (tdo != null) {
 
576
                                tdo.write(taglib);
 
577
                            }
 
578
                        } catch (IOException ioe) {
 
579
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
580
                        }
 
581
                    }
 
582
                }
 
583
            }
 
584
        }
 
585
        
 
586
        public void undoExternalChange() {
 
587
            if (data != null) {
 
588
                FileObject tldFO = data.getPrimaryFile();
 
589
                TLDDataObject tdo = ((TLDDataObject)data);
 
590
                Taglib taglib = null;
 
591
                try {
 
592
                    taglib = tdo.getTaglib();
 
593
                } catch (IOException ioe) { 
 
594
                    //ignore 
 
595
                }
 
596
                if (taglib != null) /* TODO check validity */ {
 
597
                    TagType tag = null;
 
598
                    TagType[] tags = taglib.getTag();
 
599
                    for (int i=0; i < tags.length; i++) {
 
600
                        String teiClass = tags[i].getTagClass();
 
601
                        if (newName.equals(teiClass)) {
 
602
                            tag = tags[i];
 
603
                            break;
 
604
                        }
 
605
                    }
 
606
                    if (tag!=null) {
 
607
                        tag.setTeiClass(oldName);
 
608
                        try {
 
609
                            if (tdo != null) {
 
610
                                tdo.write(taglib);
 
611
                            }
 
612
                        } catch (IOException ioe) {
 
613
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
614
                        }
 
615
                    }
 
616
                }
 
617
            }
 
618
        }
 
619
    }        
 
620
 
 
621
    
 
622
    public final class TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
623
 
 
624
        protected DataObject data = null;
 
625
        protected DataObject newData = null;
 
626
 
 
627
        /** Creates a new instance of TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement */
 
628
        public TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 
 
629
            this.data = data;
 
630
            this.newData = newData;
 
631
            this.oldName = oldName;
 
632
            this.newName = newName;
 
633
        }
 
634
 
 
635
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
636
         * @return Formatted text.
 
637
         */
 
638
        public String getDisplayText() {
 
639
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
640
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTeiClassReferenceMoveClassOtherProject"), args);
 
641
        }
 
642
 
 
643
        /** Returns file that the element affects (relates to)
 
644
         * @return File
 
645
         */
 
646
        public FileObject getParentFile() {
 
647
            if (data != null) {
 
648
                return data.getPrimaryFile();                
 
649
            }
 
650
            return null;
 
651
        }        
 
652
 
 
653
        /** Performs the change represented by this refactoring element.
 
654
         */
 
655
        public void performChange() {
 
656
            JavaMetamodel.getManager().registerExtChange(this);
 
657
        }
 
658
 
 
659
        public void performExternalChange() {
 
660
            if (data != null) {
 
661
                FileObject tldFO = data.getPrimaryFile();
 
662
                TLDDataObject tdo = ((TLDDataObject)data);
 
663
 
 
664
                FileObject newTldFO = newData.getPrimaryFile();
 
665
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
666
                
 
667
                Taglib taglib = null;
 
668
                Taglib newTaglib = null;
 
669
                try {
 
670
                    taglib = tdo.getTaglib();
 
671
                    newTaglib = newTdo.getTaglib();
 
672
                } catch (IOException ioe) { 
 
673
                    //ignore 
 
674
                }
 
675
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
676
                    err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject");
 
677
                    TagType tag = null;
 
678
                    TagType[] tags = taglib.getTag();
 
679
                    for (int i=0; i < tags.length; i++) {
 
680
                        String teiClass = tags[i].getTeiClass();
 
681
                        if (oldName.equals(teiClass)) {
 
682
                            tag = tags[i];
 
683
                            break;
 
684
                        }
 
685
                    }
 
686
                    if (tag != null) {
 
687
                        taglib.removeTag(tag);
 
688
                        tag.setTeiClass(newName);
 
689
                        newTaglib.addTag(tag);
 
690
                        try {
 
691
                            if (tdo != null) {
 
692
                                tdo.write(taglib);
 
693
                            }
 
694
                            if (newTdo != null) {
 
695
                                newTdo.write(newTaglib);
 
696
                            }
 
697
                        } catch (IOException ioe) {
 
698
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
699
                        }
 
700
                    }
 
701
                }
 
702
            }
 
703
        }
 
704
        
 
705
        public void undoExternalChange() {
 
706
            if (data != null) {
 
707
                FileObject tldFO = data.getPrimaryFile();
 
708
                TLDDataObject tdo = ((TLDDataObject)data);
 
709
 
 
710
                FileObject newTldFO = newData.getPrimaryFile();
 
711
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
712
                
 
713
                Taglib taglib = null;
 
714
                Taglib newTaglib = null;
 
715
                try {
 
716
                    taglib = tdo.getTaglib();
 
717
                    newTaglib = newTdo.getTaglib();
 
718
                } catch (IOException ioe) { 
 
719
                    //ignore 
 
720
                }
 
721
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
722
                    err.log("undo external change: TaglibTagClassReferenceMoveClassOtherProject");
 
723
                    TagType tag = null;
 
724
                    TagType[] tags = newTaglib.getTag();
 
725
                    for (int i=0; i < tags.length; i++) {
 
726
                        String teiClass = tags[i].getTeiClass();
 
727
                        if (newName.equals(teiClass)) {
 
728
                            tag = tags[i];
 
729
                            break;
 
730
                        }
 
731
                    }
 
732
                    if (tag != null) {
 
733
                        newTaglib.removeTag(tag);
 
734
                        tag.setTeiClass(oldName);
 
735
                        taglib.addTag(tag);
 
736
                        try {
 
737
                            if (tdo != null) {
 
738
                                tdo.write(taglib);
 
739
                            }
 
740
                            if (newTdo != null) {
 
741
                                newTdo.write(newTaglib);
 
742
                            }
 
743
                        } catch (IOException ioe) {
 
744
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
745
                        }
 
746
                    }
 
747
                }
 
748
            }
 
749
        }
 
750
    }    
 
751
    
 
752
    
 
753
    public final class TaglibFunctionClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
754
 
 
755
        protected DataObject data;
 
756
 
 
757
        /** Creates a new instance of TaglibFunctionClassMoveClassRefactoringElement */
 
758
        public TaglibFunctionClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 
 
759
            this.data = data;
 
760
            this.oldName = oldName;
 
761
            this.newName = newName;
 
762
        }
 
763
 
 
764
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
765
         * @return Formatted text.
 
766
         */
 
767
        public String getDisplayText() {
 
768
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
769
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibFunctionClassMoveClass"), args);
 
770
        }
 
771
 
 
772
        /** Performs the change represented by this refactoring element.
 
773
         */
 
774
        public void performChange() {
 
775
            JavaMetamodel.getManager().registerExtChange(this);
 
776
        }
 
777
 
 
778
        /** Returns file that the element affects (relates to)
 
779
         * @return File
 
780
         */
 
781
        public FileObject getParentFile() {
 
782
            if (data != null) {
 
783
                return data.getPrimaryFile();                
 
784
            }
 
785
            return null;
 
786
        }        
 
787
 
 
788
        public void performExternalChange() {
 
789
            if (data != null) {
 
790
                FileObject tldFO = data.getPrimaryFile();
 
791
                TLDDataObject tdo = ((TLDDataObject)data);
 
792
                Taglib taglib = null;
 
793
                try {
 
794
                    taglib = tdo.getTaglib();
 
795
                } catch (IOException ioe) { 
 
796
                    //ignore 
 
797
                }
 
798
                if (taglib != null) /* TODO check validity */ {            
 
799
                    FunctionType function = null;
 
800
                    FunctionType[] functions = taglib.getFunction();
 
801
                    for (int i=0; i < functions.length; i++) {
 
802
                        String functionClass = functions[i].getFunctionClass();
 
803
                        if (oldName.equals(functionClass)) {
 
804
                            function = functions[i];
 
805
                            break;
 
806
                        }
 
807
                    }
 
808
                    if (function!=null) {
 
809
                        function.setFunctionClass(newName);
 
810
                        try {
 
811
                            if (tdo != null) {
 
812
                                tdo.write(taglib);
 
813
                            }
 
814
                        } catch (IOException ioe) {
 
815
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
816
                        }
 
817
                    }
 
818
                }
 
819
            }
 
820
        }
 
821
        
 
822
        public void undoExternalChange() {
 
823
            if (data != null) {
 
824
                FileObject tldFO = data.getPrimaryFile();
 
825
                TLDDataObject tdo = ((TLDDataObject)data);
 
826
                Taglib taglib = null;
 
827
                try {
 
828
                    taglib = tdo.getTaglib();
 
829
                } catch (IOException ioe) { 
 
830
                    //ignore 
 
831
                }
 
832
                if (taglib != null) /* TODO check validity */ {
 
833
                    FunctionType function = null;
 
834
                    FunctionType[] functions = taglib.getFunction();
 
835
                    for (int i=0; i < functions.length; i++) {
 
836
                        String functionClass = functions[i].getFunctionClass();
 
837
                        if (newName.equals(functionClass)) {
 
838
                            function = functions[i];
 
839
                            break;
 
840
                        }
 
841
                    }
 
842
                    if (function!=null) {
 
843
                        function.setFunctionClass(oldName);
 
844
                        try {
 
845
                            if (tdo != null) {
 
846
                                tdo.write(taglib);
 
847
                            }
 
848
                        } catch (IOException ioe) {
 
849
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
850
                        }
 
851
                    }
 
852
                }
 
853
            }
 
854
        }
 
855
    }
 
856
    
 
857
    
 
858
    public final class TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
859
 
 
860
        protected DataObject data = null;
 
861
        protected DataObject newData = null;
 
862
 
 
863
        /** Creates a new instance of TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement */
 
864
        public TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 
 
865
            this.data = data;
 
866
            this.newData = newData;
 
867
            this.oldName = oldName;
 
868
            this.newName = newName;
 
869
        }
 
870
 
 
871
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
872
         * @return Formatted text.
 
873
         */
 
874
        public String getDisplayText() {
 
875
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
876
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibFunctionClassReferenceMoveClassOtherProject"), args);
 
877
        }
 
878
 
 
879
        /** Returns file that the element affects (relates to)
 
880
         * @return File
 
881
         */
 
882
        public FileObject getParentFile() {
 
883
            if (data != null) {
 
884
                return data.getPrimaryFile();                
 
885
            }
 
886
            return null;
 
887
        }        
 
888
 
 
889
        /** Performs the change represented by this refactoring element.
 
890
         */
 
891
        public void performChange() {
 
892
            JavaMetamodel.getManager().registerExtChange(this);
 
893
        }
 
894
 
 
895
        public void performExternalChange() {
 
896
            if (data != null) {
 
897
                FileObject tldFO = data.getPrimaryFile();
 
898
                TLDDataObject tdo = ((TLDDataObject)data);
 
899
 
 
900
                FileObject newTldFO = newData.getPrimaryFile();
 
901
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
902
                
 
903
                Taglib taglib = null;
 
904
                Taglib newTaglib = null;
 
905
                try {
 
906
                    taglib = tdo.getTaglib();
 
907
                    newTaglib = newTdo.getTaglib();
 
908
                } catch (IOException ioe) { 
 
909
                    //ignore 
 
910
                }
 
911
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
912
                    err.log("perform external change: TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement");
 
913
                    FunctionType function = null;
 
914
                    FunctionType[] functions = taglib.getFunction();
 
915
                    for (int i=0; i < functions.length; i++) {
 
916
                        String functionClass = functions[i].getFunctionClass();
 
917
                        if (oldName.equals(functionClass)) {
 
918
                            function = functions[i];
 
919
                            break;
 
920
                        }
 
921
                    }
 
922
                    if (function != null) {
 
923
                        taglib.removeFunction(function);
 
924
                        function.setFunctionClass(newName);
 
925
                        newTaglib.addFunction(function);
 
926
                        try {
 
927
                            if (tdo != null) {
 
928
                                tdo.write(taglib);
 
929
                            }
 
930
                            if (newTdo != null) {
 
931
                                newTdo.write(newTaglib);
 
932
                            }
 
933
                        } catch (IOException ioe) {
 
934
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
935
                        }
 
936
                    }
 
937
                }
 
938
            }
 
939
        }
 
940
        
 
941
        public void undoExternalChange() {
 
942
            if (data != null) {
 
943
                FileObject tldFO = data.getPrimaryFile();
 
944
                TLDDataObject tdo = ((TLDDataObject)data);
 
945
 
 
946
                FileObject newTldFO = newData.getPrimaryFile();
 
947
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
948
                
 
949
                Taglib taglib = null;
 
950
                Taglib newTaglib = null;
 
951
                try {
 
952
                    taglib = tdo.getTaglib();
 
953
                    newTaglib = newTdo.getTaglib();
 
954
                } catch (IOException ioe) { 
 
955
                    //ignore 
 
956
                }
 
957
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
958
                    err.log("undo external change: TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement");
 
959
                    FunctionType function = null;
 
960
                    FunctionType[] functions = newTaglib.getFunction();
 
961
                    for (int i=0; i < functions.length; i++) {
 
962
                        String functionClass = functions[i].getFunctionClass();
 
963
                        if (newName.equals(functionClass)) {
 
964
                            function = functions[i];
 
965
                            break;
 
966
                        }
 
967
                    }
 
968
                    if (function != null) {
 
969
                        newTaglib.removeFunction(function);
 
970
                        function.setFunctionClass(oldName);
 
971
                        taglib.addFunction(function);
 
972
                        try {
 
973
                            if (tdo != null) {
 
974
                                tdo.write(taglib);
 
975
                            }
 
976
                            if (newTdo != null) {
 
977
                                newTdo.write(newTaglib);
 
978
                            }
 
979
                        } catch (IOException ioe) {
 
980
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
981
                        }
 
982
                    }
 
983
                }
 
984
            }
 
985
        }
 
986
    }        
 
987
    
 
988
    public final class TaglibValidatorClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
989
 
 
990
        protected DataObject data;
 
991
 
 
992
        /** Creates a new instance of TaglibValidatorClassMoveClassRefactoringElement */
 
993
        public TaglibValidatorClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 
 
994
            this.data = data;
 
995
            this.oldName = oldName;
 
996
            this.newName = newName;
 
997
        }
 
998
 
 
999
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
1000
         * @return Formatted text.
 
1001
         */
 
1002
        public String getDisplayText() {
 
1003
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
1004
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibValidatorClassMoveClass"), args);
 
1005
        }
 
1006
 
 
1007
        /** Returns file that the element affects (relates to)
 
1008
         * @return File
 
1009
         */
 
1010
        public FileObject getParentFile() {
 
1011
            if (data != null) {
 
1012
                return data.getPrimaryFile();                
 
1013
            }
 
1014
            return null;
 
1015
        }        
 
1016
 
 
1017
        /** Performs the change represented by this refactoring element.
 
1018
         */
 
1019
        public void performChange() {
 
1020
            JavaMetamodel.getManager().registerExtChange(this);
 
1021
        }
 
1022
 
 
1023
        public void performExternalChange() {
 
1024
            if (data != null) {
 
1025
                FileObject tldFO = data.getPrimaryFile();
 
1026
                TLDDataObject tdo = ((TLDDataObject)data);
 
1027
                Taglib taglib = null;
 
1028
                try {
 
1029
                    taglib = tdo.getTaglib();
 
1030
                } catch (IOException ioe) { 
 
1031
                    //ignore 
 
1032
                }
 
1033
                if (taglib != null) /* TODO check validity */ {            
 
1034
                    ValidatorType validator = taglib.getValidator();
 
1035
                    if (validator!=null) {
 
1036
                        validator.setValidatorClass(newName);
 
1037
                        try {
 
1038
                            if (tdo != null) {
 
1039
                                tdo.write(taglib);
 
1040
                            }
 
1041
                        } catch (IOException ioe) {
 
1042
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1043
                        }
 
1044
                    }
 
1045
                }
 
1046
            }
 
1047
        }
 
1048
        
 
1049
        public void undoExternalChange() {
 
1050
            if (data != null) {
 
1051
                FileObject tldFO = data.getPrimaryFile();
 
1052
                Taglib taglib = null;
 
1053
                TLDDataObject tdo = ((TLDDataObject)data);                
 
1054
                try {
 
1055
                    taglib = tdo.getTaglib();
 
1056
                } catch (IOException ioe) { 
 
1057
                    //ignore 
 
1058
                }
 
1059
                if (taglib != null) /* TODO check validity */ {
 
1060
                    ValidatorType validator = taglib.getValidator();
 
1061
                    if (validator!=null) {
 
1062
                        validator.setValidatorClass(oldName);
 
1063
                        try {
 
1064
                            if (tdo != null) {
 
1065
                                tdo.write(taglib);
 
1066
                            }
 
1067
                        } catch (IOException ioe) {
 
1068
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1069
                        }
 
1070
                    }
 
1071
                }
 
1072
            }
 
1073
        }
 
1074
    }
 
1075
 
 
1076
    public final class TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
1077
 
 
1078
        protected DataObject data = null;
 
1079
        protected DataObject newData = null;
 
1080
 
 
1081
        /** Creates a new instance of TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement */
 
1082
        public TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 
 
1083
            this.data = data;
 
1084
            this.newData = newData;
 
1085
            this.oldName = oldName;
 
1086
            this.newName = newName;
 
1087
        }
 
1088
 
 
1089
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
1090
         * @return Formatted text.
 
1091
         */
 
1092
        public String getDisplayText() {
 
1093
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
1094
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibValidatorClassReferenceMoveClassOtherProject"), args);
 
1095
        }
 
1096
 
 
1097
        /** Returns file that the element affects (relates to)
 
1098
         * @return File
 
1099
         */
 
1100
        public FileObject getParentFile() {
 
1101
            if (data != null) {
 
1102
                return data.getPrimaryFile();                
 
1103
            }
 
1104
            return null;
 
1105
        }        
 
1106
 
 
1107
        /** Performs the change represented by this refactoring element.
 
1108
         */
 
1109
        public void performChange() {
 
1110
            JavaMetamodel.getManager().registerExtChange(this);
 
1111
        }
 
1112
 
 
1113
        public void performExternalChange() {
 
1114
            if (data != null) {
 
1115
                FileObject tldFO = data.getPrimaryFile();
 
1116
                TLDDataObject tdo = ((TLDDataObject)data);
 
1117
 
 
1118
                FileObject newTldFO = newData.getPrimaryFile();
 
1119
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
1120
                
 
1121
                Taglib taglib = null;
 
1122
                Taglib newTaglib = null;
 
1123
                try {
 
1124
                    taglib = tdo.getTaglib();
 
1125
                    newTaglib = newTdo.getTaglib();
 
1126
                } catch (IOException ioe) { 
 
1127
                    //ignore 
 
1128
                }
 
1129
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
1130
                    err.log("perform external change: TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement");
 
1131
                    ValidatorType validator = taglib.getValidator();
 
1132
                    if (validator != null) {
 
1133
                        String validatorClass = validator.getValidatorClass();
 
1134
                        if (oldName.equals(validatorClass)) {
 
1135
                            
 
1136
                            // TODO - this is missing in the TLD api, why?
 
1137
//                            taglib.removeValidator(validator);
 
1138
//                            validator.setValidatorClass(newName);
 
1139
//                            newTaglib.addValidator(validator);
 
1140
                            try {
 
1141
                                if (tdo != null) {
 
1142
                                    tdo.write(taglib);
 
1143
                                }
 
1144
                                if (newTdo != null) {
 
1145
                                    newTdo.write(newTaglib);
 
1146
                                }
 
1147
                            } catch (IOException ioe) {
 
1148
                                ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1149
                            }
 
1150
                        }
 
1151
                    }
 
1152
                }
 
1153
            }
 
1154
        }
 
1155
        
 
1156
        public void undoExternalChange() {
 
1157
            if (data != null) {
 
1158
                FileObject tldFO = data.getPrimaryFile();
 
1159
                TLDDataObject tdo = ((TLDDataObject)data);
 
1160
 
 
1161
                FileObject newTldFO = newData.getPrimaryFile();
 
1162
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
1163
                
 
1164
                Taglib taglib = null;
 
1165
                Taglib newTaglib = null;
 
1166
                try {
 
1167
                    taglib = tdo.getTaglib();
 
1168
                    newTaglib = newTdo.getTaglib();
 
1169
                } catch (IOException ioe) { 
 
1170
                    //ignore 
 
1171
                }
 
1172
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
1173
                    err.log("undo external change: TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement");
 
1174
                    ValidatorType validator = newTaglib.getValidator();
 
1175
                    if (validator != null) {
 
1176
                        String validatorClass = validator.getValidatorClass();
 
1177
                        if (newName.equals(validatorClass)) {
 
1178
                                // TODO - this is missing in the TLD api, why?
 
1179
    //                        newTaglib.removeValidator(validator);
 
1180
    //                        function.setValidatorClass(oldName);
 
1181
    //                        taglib.addValidator(validator);
 
1182
                            try {
 
1183
                                if (tdo != null) {
 
1184
                                    tdo.write(taglib);
 
1185
                                }
 
1186
                                if (newTdo != null) {
 
1187
                                    newTdo.write(newTaglib);
 
1188
                                }
 
1189
                            } catch (IOException ioe) {
 
1190
                                ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1191
                            }
 
1192
                        }
 
1193
                    }
 
1194
                }
 
1195
            }
 
1196
        }
 
1197
    }        
 
1198
    
 
1199
    public final class TaglibListenerClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
1200
 
 
1201
        protected DataObject data;
 
1202
 
 
1203
        /** Creates a new instance of TaglibListenerClassMoveClassRefactoringElement */
 
1204
        public TaglibListenerClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 
 
1205
            this.data = data;
 
1206
            this.oldName = oldName;
 
1207
            this.newName = newName;
 
1208
        }
 
1209
 
 
1210
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
1211
         * @return Formatted text.
 
1212
         */
 
1213
        public String getDisplayText() {
 
1214
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
1215
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibListenerClassMoveClass"), args);
 
1216
        }
 
1217
 
 
1218
        /** Returns file that the element affects (relates to)
 
1219
         * @return File
 
1220
         */
 
1221
        public FileObject getParentFile() {
 
1222
            if (data != null) {
 
1223
                return data.getPrimaryFile();                
 
1224
            }
 
1225
            return null;
 
1226
        }        
 
1227
 
 
1228
        /** Performs the change represented by this refactoring element.
 
1229
         */
 
1230
        public void performChange() {
 
1231
            JavaMetamodel.getManager().registerExtChange(this);
 
1232
        }
 
1233
 
 
1234
        public void performExternalChange() {
 
1235
            if (data != null) {
 
1236
                FileObject tldFO = data.getPrimaryFile();
 
1237
                TLDDataObject tdo = ((TLDDataObject)data);
 
1238
                Taglib taglib = null;
 
1239
                try {
 
1240
                    taglib = tdo.getTaglib();
 
1241
                } catch (IOException ioe) { 
 
1242
                    //ignore 
 
1243
                }
 
1244
                if (taglib != null) /* TODO check validity */ {            
 
1245
                    org.netbeans.modules.web.taglib.model.ListenerType listener = null;
 
1246
                    org.netbeans.modules.web.taglib.model.ListenerType[] listeners = taglib.getListener();
 
1247
                    for (int i=0; i < listeners.length; i++) {
 
1248
                        String listenerClass = listeners[i].getListenerClass();
 
1249
                        if (oldName.equals(listenerClass)) {
 
1250
                            listener = listeners[i];
 
1251
                            break;
 
1252
                        }
 
1253
                    }
 
1254
                    if (listener!=null) {
 
1255
                        listener.setListenerClass(newName);
 
1256
                        try {
 
1257
                            if (tdo != null) {
 
1258
                                tdo.write(taglib);
 
1259
                            }
 
1260
                        } catch (IOException ioe) {
 
1261
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1262
                        }
 
1263
                    }
 
1264
                }
 
1265
            }
 
1266
        }
 
1267
        
 
1268
        public void undoExternalChange() {
 
1269
            if (data != null) {
 
1270
                FileObject tldFO = data.getPrimaryFile();
 
1271
                TLDDataObject tdo = ((TLDDataObject)data);
 
1272
                Taglib taglib = null;
 
1273
                try {
 
1274
                    taglib = tdo.getTaglib();
 
1275
                } catch (IOException ioe) { 
 
1276
                    //ignore 
 
1277
                }
 
1278
                if (taglib != null) /* TODO check validity */ {
 
1279
                    org.netbeans.modules.web.taglib.model.ListenerType listener = null;
 
1280
                    org.netbeans.modules.web.taglib.model.ListenerType[] listeners = taglib.getListener();
 
1281
                    for (int i=0; i < listeners.length; i++) {
 
1282
                        String listenerClass = listeners[i].getListenerClass();
 
1283
                        if (newName.equals(listenerClass)) {
 
1284
                            listener = listeners[i];
 
1285
                            break;
 
1286
                        }
 
1287
                    }
 
1288
                    if (listener!=null) {
 
1289
                        listener.setListenerClass(oldName);
 
1290
                        try {
 
1291
                            if (tdo != null) {
 
1292
                                tdo.write(taglib);
 
1293
                            }
 
1294
                        } catch (IOException ioe) {
 
1295
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1296
                        }
 
1297
                    }
 
1298
                }
 
1299
            }
 
1300
        }
 
1301
    }
 
1302
    
 
1303
    
 
1304
    public final class TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
 
1305
 
 
1306
        protected DataObject data = null;
 
1307
        protected DataObject newData = null;
 
1308
 
 
1309
        /** Creates a new instance of TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement */
 
1310
        public TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 
 
1311
            this.data = data;
 
1312
            this.newData = newData;
 
1313
            this.oldName = oldName;
 
1314
            this.newName = newName;
 
1315
        }
 
1316
 
 
1317
        /** Returns text describing the refactoring formatted for display (using HTML tags).
 
1318
         * @return Formatted text.
 
1319
         */
 
1320
        public String getDisplayText() {
 
1321
            Object[] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName};
 
1322
            return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibListenerClassReferenceMoveClassOtherProject"), args);
 
1323
        }
 
1324
 
 
1325
        /** Returns file that the element affects (relates to)
 
1326
         * @return File
 
1327
         */
 
1328
        public FileObject getParentFile() {
 
1329
            if (data != null) {
 
1330
                return data.getPrimaryFile();                
 
1331
            }
 
1332
            return null;
 
1333
        }        
 
1334
 
 
1335
        /** Performs the change represented by this refactoring element.
 
1336
         */
 
1337
        public void performChange() {
 
1338
            JavaMetamodel.getManager().registerExtChange(this);
 
1339
        }
 
1340
 
 
1341
        public void performExternalChange() {
 
1342
            if (data != null) {
 
1343
                FileObject tldFO = data.getPrimaryFile();
 
1344
                TLDDataObject tdo = ((TLDDataObject)data);
 
1345
 
 
1346
                FileObject newTldFO = newData.getPrimaryFile();
 
1347
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
1348
                
 
1349
                Taglib taglib = null;
 
1350
                Taglib newTaglib = null;
 
1351
                try {
 
1352
                    taglib = tdo.getTaglib();
 
1353
                    newTaglib = newTdo.getTaglib();
 
1354
                } catch (IOException ioe) { 
 
1355
                    //ignore 
 
1356
                }
 
1357
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
1358
                    err.log("perform external change: TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement");
 
1359
                    ListenerType listener = null;
 
1360
                    ListenerType[] listeners = taglib.getListener();
 
1361
                    for (int i=0; i < listeners.length; i++) {
 
1362
                        String listenerClass = listeners[i].getListenerClass();
 
1363
                        if (oldName.equals(listenerClass)) {
 
1364
                            listener = listeners[i];
 
1365
                            break;
 
1366
                        }
 
1367
                    }
 
1368
                    if (listener != null) {
 
1369
                        taglib.removeListener(listener);
 
1370
                        listener.setListenerClass(newName);
 
1371
                        newTaglib.addListener(listener);
 
1372
                        try {
 
1373
                            if (tdo != null) {
 
1374
                                tdo.write(taglib);
 
1375
                            }
 
1376
                            if (newTdo != null) {
 
1377
                                newTdo.write(newTaglib);
 
1378
                            }
 
1379
                        } catch (IOException ioe) {
 
1380
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1381
                        }
 
1382
                    }
 
1383
                }
 
1384
            }
 
1385
        }
 
1386
        
 
1387
        public void undoExternalChange() {
 
1388
            if (data != null) {
 
1389
                FileObject tldFO = data.getPrimaryFile();
 
1390
                TLDDataObject tdo = ((TLDDataObject)data);
 
1391
 
 
1392
                FileObject newTldFO = newData.getPrimaryFile();
 
1393
                TLDDataObject newTdo = ((TLDDataObject)newData);
 
1394
                
 
1395
                Taglib taglib = null;
 
1396
                Taglib newTaglib = null;
 
1397
                try {
 
1398
                    taglib = tdo.getTaglib();
 
1399
                    newTaglib = newTdo.getTaglib();
 
1400
                } catch (IOException ioe) { 
 
1401
                    //ignore 
 
1402
                }
 
1403
                if ((taglib != null) && (newTaglib != null)) /* TODO check validity */ {
 
1404
                    err.log("undo external change: TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement");
 
1405
                    ListenerType listener = null;
 
1406
                    ListenerType[] listeners = newTaglib.getListener();
 
1407
                    for (int i=0; i < listeners.length; i++) {
 
1408
                        String listenerClass = listeners[i].getListenerClass();
 
1409
                        if (newName.equals(listenerClass)) {
 
1410
                            listener = listeners[i];
 
1411
                            break;
 
1412
                        }
 
1413
                    }
 
1414
                    if (listener != null) {
 
1415
                        newTaglib.removeListener(listener);
 
1416
                        listener.setListenerClass(oldName);
 
1417
                        taglib.addListener(listener);
 
1418
                        try {
 
1419
                            if (tdo != null) {
 
1420
                                tdo.write(taglib);
 
1421
                            }
 
1422
                            if (newTdo != null) {
 
1423
                                newTdo.write(newTaglib);
 
1424
                            }
 
1425
                        } catch (IOException ioe) {
 
1426
                            ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage());
 
1427
                        }
 
1428
                    }
 
1429
                }
 
1430
            }
 
1431
        }
 
1432
    }    
 
1433
    
 
1434
}