1 19 20 package org.netbeans.modules.j2ee.refactoring.whereused; 21 22 import java.text.MessageFormat ; 23 import javax.jmi.reflect.RefObject; 24 import org.netbeans.jmi.javamodel.JavaClass; 25 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit; 26 import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil; 27 import org.netbeans.modules.j2ee.persistence.unit.PUDataObject; 28 import org.netbeans.modules.j2ee.refactoring.PersistenceRefactoringUtil; 29 import org.netbeans.modules.j2ee.refactoring.Utility; 30 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 31 import org.netbeans.modules.refactoring.api.Problem; 32 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 33 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 34 import org.openide.filesystems.FileObject; 35 import org.openide.util.NbBundle; 36 37 43 public class PersistenceXmlWhereUsedRefactoring { 44 45 48 public PersistenceXmlWhereUsedRefactoring() { 49 } 50 51 public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) { 52 53 Problem problem = null; 54 55 if (!(refObject instanceof JavaClass)) { 56 return null; 57 } 58 59 JavaClass javaClass = (JavaClass)refObject; 60 61 for (FileObject ddFile : PersistenceRefactoringUtil.getPersistence(javaClass)) { 62 63 PUDataObject dataObject = ProviderUtil.getPUDataObject(ddFile); 64 65 if (!ProviderUtil.isValid(dataObject)){ 66 Problem newProblem = 67 new Problem(false, NbBundle.getMessage(PersistenceXmlWhereUsedRefactoring.class, "TXT_PersistenceXmlInvalidProblem", ddFile.getPath())); 68 problem = Utility.addProblemsToEnd(problem, newProblem); 69 continue; 70 } 71 72 PersistenceUnit[] persistenceUnits = ProviderUtil.getPersistenceUnits(dataObject); 73 74 for (int i = 0; i < persistenceUnits.length; i++) { 75 PersistenceUnit unit = persistenceUnits[i]; 76 for (int j = 0; j < unit.getClass2().length; j++) { 77 if (unit.getClass2()[j].equals(javaClass.getName())){ 78 RefactoringElementImplementation refactoringElem = 79 new PersistenceXmlWhereUsedElement(javaClass.getName(), ddFile); 80 refactoringElements.add(refactoring, refactoringElem); 81 } 82 83 } 84 } 85 } 86 87 return problem; 88 89 } 90 91 private static class PersistenceXmlWhereUsedElement extends AbstractWhereUsedRefactoringElement { 92 93 public PersistenceXmlWhereUsedElement(String name, FileObject parentFile) { 94 this.name = name; 95 this.parentFile = parentFile; 96 } 97 98 public String getDisplayText() { 99 Object [] args = new Object [] {name}; 100 return MessageFormat.format(NbBundle.getMessage(PersistenceXmlWhereUsedRefactoring.class, "TXT_PersistenceXmlClassWhereUsed"), args); 101 } 102 } 103 104 } 105 | Popular Tags |