KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > refactoring > moveclass > EjbJarMoveClassRefactoring


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.moveclass;
21
22 import java.io.IOException JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.api.project.FileOwnerQuery;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.jmi.javamodel.JavaClass;
30 import org.netbeans.jmi.javamodel.Resource;
31 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
32 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb;
33 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
34 import org.netbeans.modules.j2ee.dd.api.ejb.Session;
35 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
36 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession;
37 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
38 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
39 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
40 import org.netbeans.modules.j2ee.dd.api.common.EjbRef;
41 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef;
42 import org.netbeans.modules.j2ee.refactoring.Utility;
43 import org.netbeans.modules.javacore.api.JavaModel;
44 import org.netbeans.modules.javacore.internalapi.ExternalChange;
45 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
46 import org.netbeans.modules.refactoring.api.MoveClassRefactoring;
47 import org.netbeans.modules.refactoring.api.Problem;
48 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
49 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
50 import org.openide.ErrorManager;
51 import org.openide.filesystems.FileObject;
52 import org.openide.util.NbBundle;
53
54 /**
55  *
56  * @author Martin Grebac
57  */

58 public final class EjbJarMoveClassRefactoring {
59     
60     private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename"); // NOI18N
61

62     public EjbJarMoveClassRefactoring() { }
63
64     public Problem fastCheckParameters(Collection JavaDoc resources, FileObject target) {
65         Problem problem = null;
66         Iterator JavaDoc it = resources.iterator();
67         while (it.hasNext()) {
68             Resource res = (Resource)it.next();
69             FileObject fo = JavaModel.getFileObject(res);
70             if (fo != null) {
71                 Project prj1 = FileOwnerQuery.getOwner(fo);
72                 Project prj2 = null;
73                 if (target != null ) {
74                     prj2 = FileOwnerQuery.getOwner(target);
75                 }
76                 if ((prj2 != null) && (!prj1.equals(prj2))) {
77                     if (isEjbMove(res)) {
78                         Problem newProblem = new Problem(true, NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarOtherProjectWarningMoveClass"));
79                         problem = Utility.addProblemsToEnd(problem, newProblem);
80                         break;
81                     }
82                 }
83             }
84         }
85         return problem;
86     }
87
88     private boolean isEjbMove(Resource res) {
89         JavaClass iface;
90         List JavaDoc l = res.getClassifiers();
91
92         if (l == null) {
93             return false;
94         }
95         
96         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_LOCAL_OBJECT);
97         for (int i=0; i < l.size(); i++) {
98             JavaClass jc = (JavaClass)l.get(i);
99             if (jc.isSubTypeOf(iface)) {
100                 return true;
101             }
102         }
103         
104         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_LOCAL_HOME);
105         for (int i=0; i < l.size(); i++) {
106             JavaClass jc = (JavaClass)l.get(i);
107             if (jc.isSubTypeOf(iface)) {
108                 return true;
109             }
110         }
111
112         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_HOME);
113         for (int i=0; i < l.size(); i++) {
114             JavaClass jc = (JavaClass)l.get(i);
115             if (jc.isSubTypeOf(iface)) {
116                 return true;
117             }
118         }
119
120         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.EJB_OBJECT);
121         for (int i=0; i < l.size(); i++) {
122             JavaClass jc = (JavaClass)l.get(i);
123             if (jc.isSubTypeOf(iface)) {
124                 return true;
125             }
126         }
127
128         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.ENTITY_BEAN);
129         for (int i=0; i < l.size(); i++) {
130             JavaClass jc = (JavaClass)l.get(i);
131             if (jc.isSubTypeOf(iface)) {
132                 return true;
133             }
134         }
135
136         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.SESSION_BEAN);
137         for (int i=0; i < l.size(); i++) {
138             JavaClass jc = (JavaClass)l.get(i);
139             if (jc.isSubTypeOf(iface)) {
140                 return true;
141             }
142         }
143
144         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.MESSAGE_DRIVEN_BEAN);
145         for (int i=0; i < l.size(); i++) {
146             JavaClass jc = (JavaClass)l.get(i);
147             if (jc.isSubTypeOf(iface)) {
148                 return true;
149             }
150         }
151
152         iface = (JavaClass)JavaModel.getDefaultExtent().getType().resolve(Utility.MESSAGE_LISTENER);
153         for (int i=0; i < l.size(); i++) {
154             JavaClass jc = (JavaClass)l.get(i);
155             if (jc.isSubTypeOf(iface)) {
156                 return true;
157             }
158         }
159
160         return false;
161     }
162     
163     public Problem checkParameters(Collection JavaDoc resources, FileObject target) {
164         return fastCheckParameters(resources, target);
165     }
166     
167     /** Find usages in web deployment descriptor: web.xml
168      */

169     public Problem prepare(MoveClassRefactoring moveClassRefactor, Collection JavaDoc resources, RefactoringElementsBag refactoringElements) {
170         Problem problem = null;
171         for (Iterator JavaDoc i = resources.iterator(); i.hasNext();) {
172             Resource resource = (Resource) i.next();
173             FileObject fo = JavaModel.getFileObject(resource);
174
175             err.log("resource package name: " + resource.getPackageName());
176             err.log("resource: name " + resource.getName());
177             Collection JavaDoc emodules = Utility.getRelevantEjbModules(fo);
178             Iterator JavaDoc emIter = null;
179
180             if (emodules != null) {
181                 emIter = emodules.iterator();
182             }
183             if (emIter != null) {
184                 while (emIter.hasNext()) {
185                     org.netbeans.modules.j2ee.api.ejbjar.EjbJar em = (org.netbeans.modules.j2ee.api.ejbjar.EjbJar)emIter.next();
186                     if (em != null) { // the class is in an ejb module
187
FileObject ejbJarFO = em.getDeploymentDescriptor();
188                         EjbJar ejbJarDD = null;
189                         try {
190                             ejbJarDD = DDProvider.getDefault().getMergedDDRoot(em.getMetadataUnit());
191                         } catch (IOException JavaDoc ioe) {
192                             //ignore
193
}
194                         if ((ejbJarDD != null) && (ejbJarDD.getStatus()!=EjbJar.STATE_INVALID_UNPARSABLE) && ejbJarFO != null) {
195                             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
196
197                             Session[] sessionBeans = eBeans != null ? eBeans.getSession() : null;
198                             err.log("Session Beans: " + sessionBeans);
199
200                             Entity [] entityBeans = eBeans != null ? eBeans.getEntity() : null;
201                             err.log("Entity Beans: " + entityBeans);
202
203                             MessageDriven [] messageBeans = eBeans != null ? eBeans.getMessageDriven() :null;
204                             err.log("MessageDriven Beans: " + messageBeans);
205
206                             List JavaDoc classes = resource.getClassifiers();
207                             err.log("Classes in resource: " + classes);
208
209                             for (int j=0; j < classes.size(); j++ ) {
210                                 JavaClass jClass = (JavaClass)classes.get(j);
211                                 err.log("javaclass: "+ jClass);
212
213                                 String JavaDoc name = jClass.getName();
214                                 err.log("name: " + name);
215
216                                 String JavaDoc targetPackage = moveClassRefactor.getTargetPackageName(resource);
217                                 err.log("targetPackage: " + targetPackage);
218
219                                 String JavaDoc newName = Utility.getClassName(targetPackage, jClass.getSimpleName());
220                                 err.log("newname: " + newName);
221
222                                 /* First check Session beans */
223                                 if ((sessionBeans != null) && (sessionBeans.length > 0)) {
224                                     for (int b=0; b < sessionBeans.length; b++) {
225                                         Session sBean = sessionBeans[b];
226                                         err.log("Session Bean: " + sBean);
227                                         String JavaDoc ejbClass = sBean.getEjbClass();
228                                         err.log("EJB Class: " + ejbClass);
229                                         if ((ejbClass != null) && (ejbClass.equals(name))) {
230                                             RefactoringElementImplementation elem = new EjbJarBeanClassMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
231                                             refactoringElements.add(moveClassRefactor, elem);
232                                         }
233                                         String JavaDoc ejbLocal = sBean.getLocal();
234                                         err.log("EJB Local: " + ejbLocal);
235                                         if ((ejbLocal != null) && (ejbLocal.equals(name))) {
236                                             RefactoringElementImplementation elem = new EjbJarLocalMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
237                                             refactoringElements.add(moveClassRefactor, elem);
238                                         }
239                                         String JavaDoc ejbLocalHome = sBean.getLocalHome();
240                                         err.log("EJB LocalHome: " + ejbLocalHome);
241                                         if ((ejbLocalHome != null) && (ejbLocalHome.equals(name))) {
242                                             RefactoringElementImplementation elem = new EjbJarLocalHomeMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
243                                             refactoringElements.add(moveClassRefactor, elem);
244                                         }
245                                         String JavaDoc ejbHome = sBean.getHome();
246                                         err.log("EJB Home: " + ejbHome);
247                                         if ((ejbHome != null) && (ejbHome.equals(name))) {
248                                             RefactoringElementImplementation elem = new EjbJarHomeMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
249                                             refactoringElements.add(moveClassRefactor, elem);
250                                         }
251                                         String JavaDoc ejbRemote = sBean.getRemote();
252                                         err.log("EJB Remote: " + ejbRemote);
253                                         if ((ejbRemote != null) && (ejbRemote.equals(name))) {
254                                             RefactoringElementImplementation elem = new EjbJarRemoteMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
255                                             refactoringElements.add(moveClassRefactor, elem);
256                                         }
257                                         
258                                         // service endpoint is related to ejb based web services
259
String JavaDoc serviceEndpoint = null;
260                                         try {
261                                             serviceEndpoint = sBean.getServiceEndpoint();
262                                             if (ErrorManager.getDefault().isLoggable(ErrorManager.INFORMATIONAL)) err.log("EJB Service Endpoint: " + serviceEndpoint);
263                                             if ((serviceEndpoint != null) && (serviceEndpoint.equals(name))) {
264                                                 RefactoringElementImplementation elem = new EjbJarServiceEndpointMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
265                                                 refactoringElements.add(moveClassRefactor, elem);
266                                             }
267                                         } catch (VersionNotSupportedException versionex) {
268                                             // No problem, just ignore
269
if (ErrorManager.getDefault().isLoggable(ErrorManager.INFORMATIONAL)) err.log("Service endpoint not supported in this version of dd.");
270                                         }
271                                         
272                                         //refs
273
EjbRef[] refs = sBean.getEjbRef();
274                                         if ((refs != null) && (refs.length > 0)) {
275                                             for (int l=0; l < refs.length; l++) {
276                                                 EjbRef ref = refs[l];
277                                                 err.log("EJB ref: " + ref);
278                                                 String JavaDoc refHome = ref.getHome();
279                                                 err.log("home ref: " + refHome);
280                                                 if ((refHome != null) && (refHome.equals(name))) {
281                                                     RefactoringElementImplementation elem =
282                                                             new EjbJarRefHomeMoveClassRefactoringElement(ejbJarDD, sBean, name, newName,
283                                                                 ejbJarFO
284                                                             );
285                                                     refactoringElements.add(moveClassRefactor, elem);
286                                                 }
287                                                 String JavaDoc refRemote = ref.getRemote();
288                                                 err.log("remote ref: " + refRemote);
289                                                 if ((refRemote != null) && (refRemote.equals(name))) {
290                                                     RefactoringElementImplementation elem =
291                                                             new EjbJarRefRemoteMoveClassRefactoringElement(ejbJarDD, sBean, name, newName,
292                                                                 ejbJarFO
293                                                             );
294                                                     refactoringElements.add(moveClassRefactor, elem);
295                                                 }
296                                             }
297                                         }
298                                         // local refs
299
EjbLocalRef[] localRefs = sBean.getEjbLocalRef();
300                                         if ((localRefs != null) && (localRefs.length > 0)) {
301                                             for (int l=0; l < localRefs.length; l++) {
302                                                 EjbLocalRef localRef = localRefs[l];
303                                                 err.log("EJB local ref: " + localRef);
304                                                 String JavaDoc refLocal = localRef.getLocal();
305                                                 err.log("local ref: " + refLocal);
306                                                 if ((refLocal != null) && (refLocal.equals(name))) {
307                                                     RefactoringElementImplementation elem =
308                                                             new EjbJarRefLocalMoveClassRefactoringElement(ejbJarDD, sBean, name, newName,
309                                                                 ejbJarFO
310                                                             );
311                                                     refactoringElements.add(moveClassRefactor, elem);
312                                                 }
313                                                 String JavaDoc refLocalHome = localRef.getLocalHome();
314                                                 err.log("localHome ref: " + refLocalHome);
315                                                 if ((refLocalHome != null) && (refLocalHome.equals(name))) {
316                                                     RefactoringElementImplementation elem =
317                                                             new EjbJarRefLocalHomeMoveClassRefactoringElement(ejbJarDD, sBean, name, newName,
318                                                                 ejbJarFO
319                                                             );
320                                                     refactoringElements.add(moveClassRefactor, elem);
321                                                 }
322                                             }
323                                         }
324                                     }
325                                 }
326
327                                 /* Then entity beans */
328                                 if ((entityBeans != null) && (entityBeans.length > 0)) {
329                                     for (int b=0; b < entityBeans.length; b++) {
330                                         Entity entBean = entityBeans[b];
331                                         err.log("Entity Bean: " + entBean);
332                                         String JavaDoc ejbClass = entBean.getEjbClass();
333                                         err.log("EJB Class: " + ejbClass);
334                                         if ((ejbClass != null) && (ejbClass.equals(name))) {
335                                             RefactoringElementImplementation elem = new EjbJarBeanClassMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
336                                             refactoringElements.add(moveClassRefactor, elem);
337                                         }
338                                         String JavaDoc ejbLocal = entBean.getLocal();
339                                         err.log("EJB Local: " + ejbLocal);
340                                         if ((ejbLocal != null) && (ejbLocal.equals(name))) {
341                                             RefactoringElementImplementation elem = new EjbJarLocalMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
342                                             refactoringElements.add(moveClassRefactor, elem);
343                                         }
344                                         String JavaDoc ejbLocalHome = entBean.getLocalHome();
345                                         err.log("EJB LocalHome: " + ejbLocalHome);
346                                         if ((ejbLocalHome != null) && (ejbLocalHome.equals(name))) {
347                                             RefactoringElementImplementation elem = new EjbJarLocalHomeMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
348                                             refactoringElements.add(moveClassRefactor, elem);
349                                         }
350                                         String JavaDoc ejbHome = entBean.getHome();
351                                         err.log("EJB Home: " + ejbHome);
352                                         if ((ejbHome != null) && (ejbHome.equals(name))) {
353                                             RefactoringElementImplementation elem = new EjbJarHomeMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
354                                             refactoringElements.add(moveClassRefactor, elem);
355                                         }
356                                         String JavaDoc ejbRemote = entBean.getRemote();
357                                         err.log("EJB Remote: " + ejbRemote);
358                                         if ((ejbRemote != null) && (ejbRemote.equals(name))) {
359                                             RefactoringElementImplementation elem = new EjbJarRemoteMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
360                                             refactoringElements.add(moveClassRefactor, elem);
361                                         }
362                                         //refs
363
EjbRef[] refs = entBean.getEjbRef();
364                                         if ((refs != null) && (refs.length > 0)) {
365                                             for (int l=0; l < refs.length; l++) {
366                                                 EjbRef ref = refs[l];
367                                                 err.log("EJB ref: " + ref);
368                                                 String JavaDoc refHome = ref.getHome();
369                                                 err.log("home ref: " + refHome);
370                                                 if ((refHome != null) && (refHome.equals(name))) {
371                                                     RefactoringElementImplementation elem =
372                                                             new EjbJarRefHomeMoveClassRefactoringElement(ejbJarDD, entBean, name, newName,
373                                                                 ejbJarFO
374                                                             );
375                                                     refactoringElements.add(moveClassRefactor, elem);
376                                                 }
377                                                 String JavaDoc refRemote = ref.getRemote();
378                                                 err.log("remote ref: " + refRemote);
379                                                 if ((refRemote != null) && (refRemote.equals(name))) {
380                                                     RefactoringElementImplementation elem =
381                                                             new EjbJarRefRemoteMoveClassRefactoringElement(ejbJarDD, entBean, name, newName,
382                                                                 ejbJarFO
383                                                             );
384                                                     refactoringElements.add(moveClassRefactor, elem);
385                                                 }
386                                             }
387                                         }
388                                         // local refs
389
EjbLocalRef[] localRefs = entBean.getEjbLocalRef();
390                                         if ((localRefs != null) && (localRefs.length > 0)) {
391                                             for (int l=0; l < localRefs.length; l++) {
392                                                 EjbLocalRef localRef = localRefs[l];
393                                                 err.log("EJB local ref: " + localRef);
394                                                 String JavaDoc refLocal = localRef.getLocal();
395                                                 err.log("local ref: " + refLocal);
396                                                 if ((refLocal != null) && (refLocal.equals(name))) {
397                                                     RefactoringElementImplementation elem =
398                                                             new EjbJarRefLocalMoveClassRefactoringElement(ejbJarDD, entBean, name, newName,
399                                                                 ejbJarFO
400                                                             );
401                                                     refactoringElements.add(moveClassRefactor, elem);
402                                                 }
403                                                 String JavaDoc refLocalHome = localRef.getLocalHome();
404                                                 err.log("localHome ref: " + refLocalHome);
405                                                 if ((refLocalHome != null) && (refLocalHome.equals(name))) {
406                                                     RefactoringElementImplementation elem =
407                                                             new EjbJarRefLocalHomeMoveClassRefactoringElement(ejbJarDD, entBean, name, newName,
408                                                                 ejbJarFO
409                                                             );
410                                                     refactoringElements.add(moveClassRefactor, elem);
411                                                 }
412                                             }
413                                         }
414                                     }
415                                 }
416
417                                 /* And finally message driven beans */
418                                 if ((messageBeans != null) && (messageBeans.length > 0)) {
419                                     for (int b=0; b < messageBeans.length; b++) {
420                                         MessageDriven msgBean = messageBeans[b];
421                                         err.log("MessageDriven Bean: " + msgBean);
422                                         String JavaDoc ejbClass = msgBean.getEjbClass();
423                                         err.log("EJB Class: " + ejbClass);
424                                         if ((ejbClass != null) && (ejbClass.equals(name))) {
425                                             RefactoringElementImplementation elem = new EjbJarBeanClassMoveClassRefactoringElement(ejbJarDD, name, newName, ejbJarFO);
426                                             refactoringElements.add(moveClassRefactor, elem);
427                                         }
428                                         //refs
429
EjbRef[] refs = msgBean.getEjbRef();
430                                         if ((refs != null) && (refs.length > 0)) {
431                                             for (int l=0; l < refs.length; l++) {
432                                                 EjbRef ref = refs[l];
433                                                 err.log("EJB ref: " + ref);
434                                                 String JavaDoc refHome = ref.getHome();
435                                                 err.log("home ref: " + refHome);
436                                                 if ((refHome != null) && (refHome.equals(name))) {
437                                                     RefactoringElementImplementation elem =
438                                                             new EjbJarRefHomeMoveClassRefactoringElement(ejbJarDD, msgBean, name, newName,
439                                                                 ejbJarFO
440                                                             );
441                                                     refactoringElements.add(moveClassRefactor, elem);
442                                                 }
443                                                 String JavaDoc refRemote = ref.getRemote();
444                                                 err.log("remote ref: " + refRemote);
445                                                 if ((refRemote != null) && (refRemote.equals(name))) {
446                                                     RefactoringElementImplementation elem =
447                                                             new EjbJarRefRemoteMoveClassRefactoringElement(ejbJarDD, msgBean, name, newName,
448                                                                 ejbJarFO
449                                                             );
450                                                     refactoringElements.add(moveClassRefactor, elem);
451                                                 }
452                                             }
453                                         }
454                                         // local refs
455
EjbLocalRef[] localRefs = msgBean.getEjbLocalRef();
456                                         if ((localRefs != null) && (localRefs.length > 0)) {
457                                             for (int l=0; l < localRefs.length; l++) {
458                                                 EjbLocalRef localRef = localRefs[l];
459                                                 err.log("EJB local ref: " + localRef);
460                                                 String JavaDoc refLocal = localRef.getLocal();
461                                                 err.log("local ref: " + refLocal);
462                                                 if ((refLocal != null) && (refLocal.equals(name))) {
463                                                     RefactoringElementImplementation elem =
464                                                             new EjbJarRefLocalMoveClassRefactoringElement(ejbJarDD, msgBean, name, newName,
465                                                                 ejbJarFO
466                                                             );
467                                                     refactoringElements.add(moveClassRefactor, elem);
468                                                 }
469                                                 String JavaDoc refLocalHome = localRef.getLocalHome();
470                                                 err.log("localHome ref: " + refLocalHome);
471                                                 if ((refLocalHome != null) && (refLocalHome.equals(name))) {
472                                                     RefactoringElementImplementation elem =
473                                                             new EjbJarRefLocalHomeMoveClassRefactoringElement(ejbJarDD, msgBean, name, newName,
474                                                                 ejbJarFO
475                                                             );
476                                                     refactoringElements.add(moveClassRefactor, elem);
477                                                 }
478                                             }
479                                         }
480                                     }
481                                 }
482                             } //for
483
} else if (ejbJarFO != null){
484                             Problem newProblem = new Problem(false, NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarMoveClassInvalidProblem"));
485                             problem = Utility.addProblemsToEnd(problem, newProblem);
486                         }
487                     }
488                 }
489             }
490         }
491         return problem;
492     }
493
494     public final class EjbJarBeanClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
495
496         protected EjbJar ejbJarDD;
497
498         /** Creates a new instance of EjbJarBeanClassMoveClassRefactoringElement */
499         public EjbJarBeanClassMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
500             this.ejbJarDD = ejbJarDD;
501             this.oldName = oldName;
502             this.newName = newName;
503             this.parentFile = parentFile;
504         }
505
506         /** Returns text describing the refactoring formatted for display (using HTML tags).
507          * @return Formatted text.
508          */

509         public String JavaDoc getDisplayText() {
510             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
511             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarBeanClassMoveClass"), args);
512         }
513
514         /** Performs the change represented by this refactoring element.
515          */

516         public void performChange() {
517             JavaMetamodel.getManager().registerExtChange(this);
518         }
519
520         public void performExternalChange() {
521             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
522             Ejb[] ejbs = eBeans.getEjbs();
523             Ejb ejb = null;
524             for (int i=0; i < ejbs.length; i++) {
525                 String JavaDoc ejbClass = ejbs[i].getEjbClass();
526                 if (oldName.equals(ejbClass)) {
527                     ejb = ejbs[i];
528                     break;
529                 }
530             }
531             if (ejb!=null) {
532                 ejb.setEjbClass(newName);
533                 try {
534                     ejbJarDD.write(parentFile);
535                 } catch (IOException JavaDoc ioe) {
536                     //TODO
537
}
538             }
539         }
540         
541         public void undoExternalChange() {
542             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
543             Ejb[] ejbs = eBeans.getEjbs();
544             Ejb ejb = null;
545             for (int i=0; i < ejbs.length; i++) {
546                 String JavaDoc ejbClass = ejbs[i].getEjbClass();
547                 if (newName.equals(ejbClass)) {
548                     ejb = ejbs[i];
549                     break;
550                 }
551             }
552             if (ejb!=null) {
553                 ejb.setEjbClass(oldName);
554                 try {
555                     ejbJarDD.write(parentFile);
556                 } catch (IOException JavaDoc ioe) {
557                     //TODO
558
}
559             }
560         }
561     }
562
563     public final class EjbJarLocalMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
564
565         protected EjbJar ejbJarDD;
566
567         /** Creates a new instance of EjbJarLocalMoveClassRefactoringElement */
568         public EjbJarLocalMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
569             this.ejbJarDD = ejbJarDD;
570             this.oldName = oldName;
571             this.newName = newName;
572             this.parentFile = parentFile;
573         }
574
575         /** Returns text describing the refactoring formatted for display (using HTML tags).
576          * @return Formatted text.
577          */

578         public String JavaDoc getDisplayText() {
579             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
580             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarLocalMoveClass"), args);
581         }
582
583         /** Performs the change represented by this refactoring element.
584          */

585         public void performChange() {
586             JavaMetamodel.getManager().registerExtChange(this);
587         }
588
589         public void performExternalChange() {
590             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
591             EntityAndSession ejb = null;
592             Session[] sEjbs = eBeans.getSession();
593             for (int i=0; i < sEjbs.length; i++) {
594                 String JavaDoc ejbLocal = sEjbs[i].getLocal();
595                 if (oldName.equals(ejbLocal)) {
596                     ejb = sEjbs[i];
597                     break;
598                 }
599             }
600             if (ejb == null) {
601                 Entity[] eEjbs = eBeans.getEntity();
602                 for (int i=0; i < eEjbs.length; i++) {
603                     String JavaDoc ejbLocal = eEjbs[i].getLocal();
604                     if (oldName.equals(ejbLocal)) {
605                         ejb = eEjbs[i];
606                         break;
607                     }
608                 }
609             }
610             if (ejb!=null) {
611                 ejb.setLocal(newName);
612                 try {
613                     ejbJarDD.write(parentFile);
614                 } catch (IOException JavaDoc ioe) {
615                     //TODO
616
}
617             }
618         }
619         
620         public void undoExternalChange() {
621             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
622             EntityAndSession ejb = null;
623             Session[] sEjbs = eBeans.getSession();
624             for (int i=0; i < sEjbs.length; i++) {
625                 String JavaDoc ejbLocal = sEjbs[i].getLocal();
626                 if (newName.equals(ejbLocal)) {
627                     ejb = sEjbs[i];
628                     break;
629                 }
630             }
631             if (ejb == null) {
632                 Entity[] eEjbs = eBeans.getEntity();
633                 for (int i=0; i < eEjbs.length; i++) {
634                     String JavaDoc ejbLocal = eEjbs[i].getLocal();
635                     if (newName.equals(ejbLocal)) {
636                         ejb = eEjbs[i];
637                         break;
638                     }
639                 }
640             }
641             if (ejb!=null) {
642                 ejb.setLocal(oldName);
643                 try {
644                     ejbJarDD.write(parentFile);
645                 } catch (IOException JavaDoc ioe) {
646                     //TODO
647
}
648             }
649         }
650     }
651     
652     public final class EjbJarLocalHomeMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
653
654         protected EjbJar ejbJarDD;
655
656         /** Creates a new instance of EjbJarLocalHomeMoveClassRefactoringElement */
657         public EjbJarLocalHomeMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
658             this.ejbJarDD = ejbJarDD;
659             this.oldName = oldName;
660             this.newName = newName;
661             this.parentFile = parentFile;
662         }
663
664         /** Returns text describing the refactoring formatted for display (using HTML tags).
665          * @return Formatted text.
666          */

667         public String JavaDoc getDisplayText() {
668             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
669             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarLocalHomeMoveClass"), args);
670         }
671
672         /** Performs the change represented by this refactoring element.
673          */

674         public void performChange() {
675             JavaMetamodel.getManager().registerExtChange(this);
676         }
677
678         public void performExternalChange() {
679             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
680             EntityAndSession ejb = null;
681             Session[] sEjbs = eBeans.getSession();
682             for (int i=0; i < sEjbs.length; i++) {
683                 String JavaDoc ejbLocalHome = sEjbs[i].getLocalHome();
684                 if (oldName.equals(ejbLocalHome)) {
685                     ejb = sEjbs[i];
686                     break;
687                 }
688             }
689             if (ejb == null) {
690                 Entity[] eEjbs = eBeans.getEntity();
691                 for (int i=0; i < eEjbs.length; i++) {
692                     String JavaDoc ejbLocalHome = eEjbs[i].getLocalHome();
693                     if (oldName.equals(ejbLocalHome)) {
694                         ejb = eEjbs[i];
695                         break;
696                     }
697                 }
698             }
699             if (ejb!=null) {
700                 ejb.setLocalHome(newName);
701                 try {
702                     ejbJarDD.write(parentFile);
703                 } catch (IOException JavaDoc ioe) {
704                     //TODO
705
}
706             }
707         }
708         
709         public void undoExternalChange() {
710             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
711             EntityAndSession ejb = null;
712             Session[] sEjbs = eBeans.getSession();
713             for (int i=0; i < sEjbs.length; i++) {
714                 String JavaDoc ejbLocalHome = sEjbs[i].getLocalHome();
715                 if (newName.equals(ejbLocalHome)) {
716                     ejb = sEjbs[i];
717                     break;
718                 }
719             }
720             if (ejb == null) {
721                 Entity[] eEjbs = eBeans.getEntity();
722                 for (int i=0; i < eEjbs.length; i++) {
723                     String JavaDoc ejbLocalHome = eEjbs[i].getLocalHome();
724                     if (newName.equals(ejbLocalHome)) {
725                         ejb = eEjbs[i];
726                         break;
727                     }
728                 }
729             }
730             if (ejb!=null) {
731                 ejb.setLocalHome(oldName);
732                 try {
733                     ejbJarDD.write(parentFile);
734                 } catch (IOException JavaDoc ioe) {
735                     //TODO
736
}
737             }
738         }
739     }
740     
741     public final class EjbJarHomeMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
742
743         protected EjbJar ejbJarDD;
744
745         /** Creates a new instance of EjbJarHomeMoveClassRefactoringElement */
746         public EjbJarHomeMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
747             this.ejbJarDD = ejbJarDD;
748             this.oldName = oldName;
749             this.newName = newName;
750             this.parentFile = parentFile;
751         }
752
753         /** Returns text describing the refactoring formatted for display (using HTML tags).
754          * @return Formatted text.
755          */

756         public String JavaDoc getDisplayText() {
757             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
758             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarHomeMoveClass"), args);
759         }
760
761         /** Performs the change represented by this refactoring element.
762          */

763         public void performChange() {
764             JavaMetamodel.getManager().registerExtChange(this);
765         }
766
767         public void performExternalChange() {
768             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
769             EntityAndSession ejb = null;
770             Session[] sEjbs = eBeans.getSession();
771             for (int i=0; i < sEjbs.length; i++) {
772                 String JavaDoc ejbHome = sEjbs[i].getHome();
773                 if (oldName.equals(ejbHome)) {
774                     ejb = sEjbs[i];
775                     break;
776                 }
777             }
778             if (ejb == null) {
779                 Entity[] eEjbs = eBeans.getEntity();
780                 for (int i=0; i < eEjbs.length; i++) {
781                     String JavaDoc ejbHome = eEjbs[i].getHome();
782                     if (oldName.equals(ejbHome)) {
783                         ejb = eEjbs[i];
784                         break;
785                     }
786                 }
787             }
788             if (ejb!=null) {
789                 ejb.setHome(newName);
790                 try {
791                     ejbJarDD.write(parentFile);
792                 } catch (IOException JavaDoc ioe) {
793                     //TODO
794
}
795             }
796         }
797         
798         public void undoExternalChange() {
799             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
800             EntityAndSession ejb = null;
801             Session[] sEjbs = eBeans.getSession();
802             for (int i=0; i < sEjbs.length; i++) {
803                 String JavaDoc ejbHome = sEjbs[i].getHome();
804                 if (newName.equals(ejbHome)) {
805                     ejb = sEjbs[i];
806                     break;
807                 }
808             }
809             if (ejb == null) {
810                 Entity[] eEjbs = eBeans.getEntity();
811                 for (int i=0; i < eEjbs.length; i++) {
812                     String JavaDoc ejbHome = eEjbs[i].getHome();
813                     if (newName.equals(ejbHome)) {
814                         ejb = eEjbs[i];
815                         break;
816                     }
817                 }
818             }
819             if (ejb!=null) {
820                 ejb.setHome(oldName);
821                 try {
822                     ejbJarDD.write(parentFile);
823                 } catch (IOException JavaDoc ioe) {
824                     //TODO
825
}
826             }
827         }
828     }
829
830     public final class EjbJarRemoteMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
831
832         protected EjbJar ejbJarDD;
833
834         /** Creates a new instance of EjbJarRemoteMoveClassRefactoringElement */
835         public EjbJarRemoteMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
836             this.ejbJarDD = ejbJarDD;
837             this.oldName = oldName;
838             this.newName = newName;
839             this.parentFile = parentFile;
840         }
841
842         /** Returns text describing the refactoring formatted for display (using HTML tags).
843          * @return Formatted text.
844          */

845         public String JavaDoc getDisplayText() {
846             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
847             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarRemoteMoveClass"), args);
848         }
849
850         /** Performs the change represented by this refactoring element.
851          */

852         public void performChange() {
853             JavaMetamodel.getManager().registerExtChange(this);
854         }
855
856         public void performExternalChange() {
857             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
858             EntityAndSession ejb = null;
859             Session[] sEjbs = eBeans.getSession();
860             for (int i=0; i < sEjbs.length; i++) {
861                 String JavaDoc ejbRemote = sEjbs[i].getRemote();
862                 if (oldName.equals(ejbRemote)) {
863                     ejb = sEjbs[i];
864                     break;
865                 }
866             }
867             if (ejb == null) {
868                 Entity[] eEjbs = eBeans.getEntity();
869                 for (int i=0; i < eEjbs.length; i++) {
870                     String JavaDoc ejbRemote = eEjbs[i].getRemote();
871                     if (oldName.equals(ejbRemote)) {
872                         ejb = eEjbs[i];
873                         break;
874                     }
875                 }
876             }
877             if (ejb!=null) {
878                 ejb.setRemote(newName);
879                 try {
880                     ejbJarDD.write(parentFile);
881                 } catch (IOException JavaDoc ioe) {
882                     //TODO
883
}
884             }
885         }
886         
887         public void undoExternalChange() {
888             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
889             EntityAndSession ejb = null;
890             Session[] sEjbs = eBeans.getSession();
891             for (int i=0; i < sEjbs.length; i++) {
892                 String JavaDoc ejbRemote = sEjbs[i].getRemote();
893                 if (newName.equals(ejbRemote)) {
894                     ejb = sEjbs[i];
895                     break;
896                 }
897             }
898             if (ejb == null) {
899                 Entity[] eEjbs = eBeans.getEntity();
900                 for (int i=0; i < eEjbs.length; i++) {
901                     String JavaDoc ejbRemote = eEjbs[i].getRemote();
902                     if (newName.equals(ejbRemote)) {
903                         ejb = eEjbs[i];
904                         break;
905                     }
906                 }
907             }
908             if (ejb!=null) {
909                 ejb.setRemote(oldName);
910                 try {
911                     ejbJarDD.write(parentFile);
912                 } catch (IOException JavaDoc ioe) {
913                     //TODO
914
}
915             }
916         }
917     }
918
919     public final class EjbJarServiceEndpointMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
920
921         protected EjbJar ejbJarDD;
922
923         /** Creates a new instance of EjbJarServiceEndpointMoveClassRefactoringElement */
924         public EjbJarServiceEndpointMoveClassRefactoringElement(EjbJar ejbJarDD, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
925             this.ejbJarDD = ejbJarDD;
926             this.oldName = oldName;
927             this.newName = newName;
928             this.parentFile = parentFile;
929         }
930
931         /** Returns text describing the refactoring formatted for display (using HTML tags).
932          * @return Formatted text.
933          */

934         public String JavaDoc getDisplayText() {
935             Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
936             return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarServiceEndpointMoveClass"), args);
937         }
938
939         /** Performs the change represented by this refactoring element.
940          */

941         public void performChange() {
942             JavaMetamodel.getManager().registerExtChange(this);
943         }
944
945         public void performExternalChange() {
946             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
947             Session ejb = null;
948             Session[] sEjbs = eBeans.getSession();
949             try {
950                 for (int i=0; i < sEjbs.length; i++) {
951                     String JavaDoc serviceEndpoint = sEjbs[i].getServiceEndpoint();
952                     if (oldName.equals(serviceEndpoint)) {
953                         ejb = sEjbs[i];
954                         break;
955                     }
956                 }
957                 if (ejb!=null) {
958                     ejb.setServiceEndpoint(newName);
959                     try {
960                         ejbJarDD.write(parentFile);
961                     } catch (IOException JavaDoc ioe) {
962                         //TODO
963
}
964                 }
965             } catch (VersionNotSupportedException ex) {
966                 // just ignore, this is checked sooner in prepare
967
}
968         }
969         
970         public void undoExternalChange() {
971             EnterpriseBeans eBeans = ejbJarDD.getEnterpriseBeans();
972             Session ejb = null;
973             Session[] sEjbs = eBeans.getSession();
974             try {
975                 for (int i=0; i < sEjbs.length; i++) {
976                     String JavaDoc serviceEndpoint = sEjbs[i].getServiceEndpoint();
977                     if (newName.equals(serviceEndpoint)) {
978                         ejb = sEjbs[i];
979                         break;
980                     }
981                 }
982                 if (ejb!=null) {
983                     ejb.setServiceEndpoint(oldName);
984                     try {
985                         ejbJarDD.write(parentFile);
986                     } catch (IOException JavaDoc ioe) {
987                         //TODO
988
}
989                 }
990             } catch (VersionNotSupportedException ex) {
991                 // just ignore, this is checked sooner in prepare
992
}
993         }
994     }
995
996     public final class EjbJarRefLocalMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
997
998         protected Ejb ejb;
999         protected EjbJar ejbJarDD;
1000        
1001        /** Creates a new instance of EjbJarRefLocalMoveClassRefactoringElement */
1002        public EjbJarRefLocalMoveClassRefactoringElement(EjbJar ejbJarDD, Ejb ejb, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
1003            this.ejb = ejb;
1004            this.oldName = oldName;
1005            this.newName = newName;
1006            this.ejbJarDD = ejbJarDD;
1007            this.parentFile = parentFile;
1008        }
1009
1010        /** Returns text describing the refactoring formatted for display (using HTML tags).
1011         * @return Formatted text.
1012         */

1013        public String JavaDoc getDisplayText() {
1014            Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
1015            return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarRefLocalMoveClass"), args);
1016        }
1017
1018        /** Performs the change represented by this refactoring element.
1019         */

1020        public void performChange() {
1021            JavaMetamodel.getManager().registerExtChange(this);
1022        }
1023
1024        public void performExternalChange() {
1025            EjbLocalRef[] refs = ejb.getEjbLocalRef();
1026            EjbLocalRef ref = null;
1027            for (int i=0; i < refs.length; i++) {
1028                String JavaDoc ejbLocal = refs[i].getLocal();
1029                if (oldName.equals(ejbLocal)) {
1030                    ref = refs[i];
1031                    break;
1032                }
1033            }
1034            if (ref!=null) {
1035                ref.setLocal(newName);
1036                try {
1037                    ejbJarDD.write(parentFile);
1038                } catch (IOException JavaDoc ioe) {
1039                    //TODO
1040
}
1041            }
1042        }
1043        
1044        public void undoExternalChange() {
1045            EjbLocalRef[] refs = ejb.getEjbLocalRef();
1046            EjbLocalRef ref = null;
1047            for (int i=0; i < refs.length; i++) {
1048                String JavaDoc ejbLocal = refs[i].getLocal();
1049                if (newName.equals(ejbLocal)) {
1050                    ref = refs[i];
1051                    break;
1052                }
1053            }
1054            if (ref!=null) {
1055                ref.setLocal(oldName);
1056                try {
1057                    ejbJarDD.write(parentFile);
1058                } catch (IOException JavaDoc ioe) {
1059                    //TODO
1060
}
1061            }
1062        }
1063    }
1064    
1065    public final class EjbJarRefLocalHomeMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
1066
1067        protected Ejb ejb;
1068        protected EjbJar ejbJarDD;
1069        
1070        /** Creates a new instance of EjbJarRefLocalHomeMoveClassRefactoringElement */
1071        public EjbJarRefLocalHomeMoveClassRefactoringElement(EjbJar ejbJarDD, Ejb ejb, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
1072            this.ejb = ejb;
1073            this.oldName = oldName;
1074            this.newName = newName;
1075            this.ejbJarDD = ejbJarDD;
1076            this.parentFile = parentFile;
1077        }
1078
1079        /** Returns text describing the refactoring formatted for display (using HTML tags).
1080         * @return Formatted text.
1081         */

1082        public String JavaDoc getDisplayText() {
1083            Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
1084            return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarRefLocalHomeMoveClass"), args);
1085        }
1086
1087        /** Performs the change represented by this refactoring element.
1088         */

1089        public void performChange() {
1090            JavaMetamodel.getManager().registerExtChange(this);
1091        }
1092
1093        public void performExternalChange() {
1094            EjbLocalRef[] refs = ejb.getEjbLocalRef();
1095            EjbLocalRef ref = null;
1096            for (int i=0; i < refs.length; i++) {
1097                String JavaDoc ejbLocalHome = refs[i].getLocalHome();
1098                if (oldName.equals(ejbLocalHome)) {
1099                    ref = refs[i];
1100                    break;
1101                }
1102            }
1103            if (ref!=null) {
1104                ref.setLocalHome(newName);
1105                try {
1106                    ejbJarDD.write(parentFile);
1107                } catch (IOException JavaDoc ioe) {
1108                    //TODO
1109
}
1110            }
1111        }
1112        
1113        public void undoExternalChange() {
1114            EjbLocalRef[] refs = ejb.getEjbLocalRef();
1115            EjbLocalRef ref = null;
1116            for (int i=0; i < refs.length; i++) {
1117                String JavaDoc ejbLocalHome = refs[i].getLocalHome();
1118                if (newName.equals(ejbLocalHome)) {
1119                    ref = refs[i];
1120                    break;
1121                }
1122            }
1123            if (ref!=null) {
1124                ref.setLocalHome(oldName);
1125                try {
1126                    ejbJarDD.write(parentFile);
1127                } catch (IOException JavaDoc ioe) {
1128                    //TODO
1129
}
1130            }
1131        }
1132    }
1133    
1134    public final class EjbJarRefHomeMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
1135
1136        protected Ejb ejb;
1137        protected EjbJar ejbJarDD;
1138        
1139        /** Creates a new instance of EjbJarRefLocalHomeMoveClassRefactoringElement */
1140        public EjbJarRefHomeMoveClassRefactoringElement(EjbJar ejbJarDD, Ejb ejb, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
1141            this.ejb = ejb;
1142            this.oldName = oldName;
1143            this.newName = newName;
1144            this.ejbJarDD = ejbJarDD;
1145            this.parentFile = parentFile;
1146        }
1147
1148        /** Returns text describing the refactoring formatted for display (using HTML tags).
1149         * @return Formatted text.
1150         */

1151        public String JavaDoc getDisplayText() {
1152            Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
1153            return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarRefHomeMoveClass"), args);
1154        }
1155
1156        /** Performs the change represented by this refactoring element.
1157         */

1158        public void performChange() {
1159            JavaMetamodel.getManager().registerExtChange(this);
1160        }
1161
1162        public void performExternalChange() {
1163            EjbRef[] refs = ejb.getEjbRef();
1164            EjbRef ref = null;
1165            for (int i=0; i < refs.length; i++) {
1166                String JavaDoc ejbHome = refs[i].getHome();
1167                if (oldName.equals(ejbHome)) {
1168                    ref = refs[i];
1169                    break;
1170                }
1171            }
1172            if (ref!=null) {
1173                ref.setHome(newName);
1174                try {
1175                    ejbJarDD.write(parentFile);
1176                } catch (IOException JavaDoc ioe) {
1177                    //TODO
1178
}
1179            }
1180        }
1181        
1182        public void undoExternalChange() {
1183            EjbRef[] refs = ejb.getEjbRef();
1184            EjbRef ref = null;
1185            for (int i=0; i < refs.length; i++) {
1186                String JavaDoc ejbHome = refs[i].getHome();
1187                if (newName.equals(ejbHome)) {
1188                    ref = refs[i];
1189                    break;
1190                }
1191            }
1192            if (ref!=null) {
1193                ref.setHome(oldName);
1194                try {
1195                    ejbJarDD.write(parentFile);
1196                } catch (IOException JavaDoc ioe) {
1197                    //TODO
1198
}
1199            }
1200        }
1201    }
1202    
1203    public final class EjbJarRefRemoteMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange {
1204
1205        protected Ejb ejb;
1206        protected EjbJar ejbJarDD;
1207        
1208        /** Creates a new instance of EjbJarRefRemoteMoveClassRefactoringElement */
1209        public EjbJarRefRemoteMoveClassRefactoringElement(EjbJar ejbJarDD, Ejb ejb, String JavaDoc oldName, String JavaDoc newName, FileObject parentFile) {
1210            this.ejb = ejb;
1211            this.oldName = oldName;
1212            this.newName = newName;
1213            this.ejbJarDD = ejbJarDD;
1214            this.parentFile = parentFile;
1215        }
1216
1217        /** Returns text describing the refactoring formatted for display (using HTML tags).
1218         * @return Formatted text.
1219         */

1220        public String JavaDoc getDisplayText() {
1221            Object JavaDoc[] args = new Object JavaDoc [] {parentFile.getNameExt(), oldName, newName};
1222            return MessageFormat.format(NbBundle.getMessage(EjbJarMoveClassRefactoring.class, "TXT_EjbJarRefRemoteMoveClass"), args);
1223        }
1224
1225        /** Performs the change represented by this refactoring element.
1226         */

1227        public void performChange() {
1228            JavaMetamodel.getManager().registerExtChange(this);
1229        }
1230
1231        public void performExternalChange() {
1232            EjbRef[] refs = ejb.getEjbRef();
1233            EjbRef ref = null;
1234            for (int i=0; i < refs.length; i++) {
1235                String JavaDoc ejbRemote = refs[i].getRemote();
1236                if (oldName.equals(ejbRemote)) {
1237                    ref = refs[i];
1238                    break;
1239                }
1240            }
1241            if (ref!=null) {
1242                ref.setRemote(newName);
1243                try {
1244                    ejbJarDD.write(parentFile);
1245                } catch (IOException JavaDoc ioe) {
1246                    //TODO
1247
}
1248            }
1249        }
1250        
1251        public void undoExternalChange() {
1252            EjbRef[] refs = ejb.getEjbRef();
1253            EjbRef ref = null;
1254            for (int i=0; i < refs.length; i++) {
1255                String JavaDoc ejbRemote = refs[i].getRemote();
1256                if (newName.equals(ejbRemote)) {
1257                    ref = refs[i];
1258                    break;
1259                }
1260            }
1261            if (ref!=null) {
1262                ref.setRemote(oldName);
1263                try {
1264                    ejbJarDD.write(parentFile);
1265                } catch (IOException JavaDoc ioe) {
1266                    //TODO
1267
}
1268            }
1269        }
1270    }
1271}
1272
Popular Tags