1 19 20 package org.netbeans.modules.j2ee.refactoring.safedelete; 21 22 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 23 import org.netbeans.modules.j2ee.refactoring.Utility; 24 import org.netbeans.modules.j2ee.refactoring.J2EERefactoring; 25 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 26 import org.netbeans.modules.refactoring.api.Problem; 27 import org.netbeans.modules.refactoring.api.RefactoringSession; 28 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 29 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 30 import org.netbeans.modules.web.taglib.TLDDataObject; 31 import org.netbeans.modules.web.taglib.model.Taglib; 32 import org.openide.filesystems.FileObject; 33 34 import java.util.Collection ; 35 import java.util.LinkedList ; 36 import java.util.Iterator ; 37 import java.io.IOException ; 38 import org.openide.loaders.DataObject; 39 40 43 public class BaseRefactoring implements J2EERefactoring { 44 final private Collection childRefactorings = new LinkedList (); 45 protected BaseRefactoringHelper helper; 46 47 public BaseRefactoring(BaseRefactoringHelper helper) { 48 this.helper = helper; 49 } 50 51 public void addChildRefactoring(AbstractRefactoring refactoring) { 52 childRefactorings.add(refactoring); 53 } 54 55 public Problem preCheck() { 56 Problem problem = preCheckThis(); 57 for (Iterator it = childRefactorings.iterator(); it.hasNext();) { 58 AbstractRefactoring refactoring = (AbstractRefactoring) it.next(); 59 problem = Utility.addProblemsToEnd(problem, refactoring.preCheck()); 60 } 61 return problem; 62 } 63 64 public Problem checkParameters() { 65 Problem problem = checkParametersThis(); 66 for (Iterator it = childRefactorings.iterator(); it.hasNext();) { 67 AbstractRefactoring refactoring = (AbstractRefactoring) it.next(); 68 problem = Utility.addProblemsToEnd(problem, refactoring.checkParameters()); 69 } 70 return problem; 71 } 72 73 74 public Problem fastCheckParameters() { 75 Problem problem = fastCheckParametersThis(); 76 for (Iterator it = childRefactorings.iterator(); it.hasNext();) { 77 AbstractRefactoring refactoring = (AbstractRefactoring) it.next(); 78 problem = Utility.addProblemsToEnd(problem, refactoring.fastCheckParameters()); 79 } 80 return problem; 81 } 82 83 public Problem prepare(RefactoringElementsBag refactoringElementsBag) { 84 Problem problem = prepareThis(refactoringElementsBag); 85 final RefactoringSession session = refactoringElementsBag.getSession(); 86 for (Iterator it = childRefactorings.iterator(); it.hasNext();) { 87 AbstractRefactoring refactoring = (AbstractRefactoring) it.next(); 88 problem = Utility.addProblemsToEnd(problem, refactoring.prepare(session)); 89 } 90 return problem; 91 } 92 93 protected Problem preCheckThis() { 94 return null; 95 } 96 97 protected Problem checkParametersThis() { 98 return null; 99 } 100 101 protected Problem fastCheckParametersThis() { 102 return null; 103 } 104 105 protected Problem prepareThis(RefactoringElementsBag refactoringElementsBag) { 106 return null; 107 } 108 109 110 public static class EjbHelper extends BaseRefactoringHelper { 111 private final EjbJar ejbJar; 112 113 public EjbHelper(AbstractRefactoring refactoring, FileObject fileObject, EjbJar ejbJar) { 114 super(refactoring, fileObject); 115 this.ejbJar = ejbJar; 116 } 117 118 public void writeDD() { 119 try { 120 ejbJar.write(getFileObject()); 121 } catch (IOException e) { 122 } 124 } 125 126 public EjbJar getEjbJar() { 127 return ejbJar; 128 } 129 130 } 131 132 public static class TldHelper extends BaseRefactoringHelper { 133 private final Taglib taglib; 134 135 public TldHelper(AbstractRefactoring refactoring, FileObject fileObject, Taglib taglib) { 136 super(refactoring, fileObject); 137 this.taglib = taglib; 138 } 139 140 public void writeDD() { 141 try { 142 TLDDataObject tdo =(TLDDataObject)DataObject.find(getFileObject()); 143 if (tdo != null) { 144 tdo.write(taglib); 145 } 146 } catch (IOException ioe) { 147 } 149 } 150 151 public Taglib getTaglib() { 152 return taglib; 153 } 154 } 155 156 } | Popular Tags |