KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.refactoring.safedelete;
21
22 import org.netbeans.modules.refactoring.api.Problem;
23 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
24 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
25 import org.netbeans.modules.j2ee.dd.api.ejb.Query;
26 import org.netbeans.modules.javacore.internalapi.ExternalChange;
27 import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
28 import org.openide.util.NbBundle;
29 import org.openide.ErrorManager;
30
31 /**
32  * @author pfiala
33  */

34 public class EjbQueryMethodSafeDeleteRefactoring extends BaseRefactoring {
35
36     private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.safedelete"); // NOI18N
37
private Entity entity;
38     private Query query;
39
40     public EjbQueryMethodSafeDeleteRefactoring(EjbHelper helper, Entity entity, Query query) {
41         super(helper);
42         this.entity = entity;
43         this.query = query;
44     }
45
46     protected Problem preCheckThis() {
47         return new Problem(false, NbBundle.getMessage(EjbQueryMethodSafeDeleteRefactoring.class,
48             "TXT_QueryMethodWarningSafeDelete", query.getQueryMethod().getMethodName()));
49     }
50
51     public Problem prepareThis(RefactoringElementsBag refactoringElementsBag) {
52         helper.addRefactoringElement(refactoringElementsBag, new EjbJarRefactoringElement());
53         return null;
54     }
55
56     public final class EjbJarRefactoringElement extends AbstractSafeDeleteRefactoringElement implements ExternalChange {
57
58         public EjbJarRefactoringElement() {
59             super(helper.getFileObject());
60         }
61
62         /** Returns text describing the refactoring formatted for display (using HTML tags).
63          * @return Formatted text.
64          */

65         public String JavaDoc getDisplayText() {
66             return NbBundle.getMessage(EjbQueryMethodSafeDeleteRefactoring.class,
67                     "TXT_EjbJarQueryMethodSafeDelete", query.getQueryMethod().getMethodName()); //NOI18N
68
}
69
70         /** Performs the change represented by this refactoring element.
71          */

72         public void performChange() {
73             JavaMetamodel.getManager().registerExtChange(this);
74         }
75
76         public void performExternalChange() {
77             entity.removeQuery(query);
78             helper.writeDD();
79         }
80
81         public void undoExternalChange() {
82             entity.addQuery(query);
83             helper.writeDD();
84         }
85     }
86 }
87
Popular Tags