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.Feature; 25 import org.netbeans.jmi.javamodel.Field; 26 import org.netbeans.jmi.javamodel.JavaClass; 27 import org.netbeans.jmi.javamodel.Method; 28 import org.netbeans.jmi.javamodel.Resource; 29 import org.netbeans.modules.j2ee.refactoring.EntityAnnotationReference; 30 import org.netbeans.modules.j2ee.refactoring.EntityAssociationResolver; 31 import org.netbeans.modules.j2ee.refactoring.PersistenceRefactoringUtil; 32 import org.netbeans.modules.j2ee.refactoring.jaxwssupport.JaxWsXmlRefactoringSupport; 33 import org.netbeans.modules.javacore.api.JavaModel; 34 import org.netbeans.modules.refactoring.api.AbstractRefactoring; 35 import org.netbeans.modules.refactoring.api.Problem; 36 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 37 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 38 import org.openide.filesystems.FileObject; 39 import org.openide.util.NbBundle; 40 41 46 public class EntityWhereUsedRefactoring extends JaxWsXmlRefactoringSupport { 47 48 51 public EntityWhereUsedRefactoring() { 52 } 53 54 57 public Problem prepare(AbstractRefactoring refactoring, RefObject refObject, RefactoringElementsBag refactoringElements) { 58 59 if (!(refObject instanceof Method || refObject instanceof Field)){ 60 return null; 61 } 62 63 Feature property = (Feature) refObject; 64 JavaClass javaClass = (JavaClass) property.getDeclaringClass(); 65 if (!PersistenceRefactoringUtil.isEntity(javaClass)){ 66 return null; 67 } 68 EntityAssociationResolver resolver 69 = new EntityAssociationResolver(javaClass, PersistenceRefactoringUtil.getEntitiesInProject(javaClass)); 70 71 for (EntityAnnotationReference reference : resolver.getMappedByReferences(property)) { 72 Resource res = reference.getReferring().getResource(); 73 FileObject fo = JavaModel.getFileObject(res); 74 RefactoringElementImplementation elem = new EntityWhereUsedElement(reference, fo); 75 refactoringElements.add(refactoring, elem); 76 77 } 78 79 return null; 80 } 81 82 private static class EntityWhereUsedElement extends AbstractWhereUsedRefactoringElement { 83 84 private EntityAnnotationReference reference; 85 86 public EntityWhereUsedElement(EntityAnnotationReference reference, FileObject parentFile) { 87 this.reference = reference; 88 this.parentFile = parentFile; 89 } 90 91 public String getDisplayText() { 92 Object [] args = new Object [] {reference.getAnnotation().getType().getName(), reference.getReferringProperty().getName()}; 93 return MessageFormat.format(NbBundle.getMessage(SunJaxWsXmlWhereUsedRefactoring.class, "TXT_EntityWhereUsed"), args); 94 } 95 } 96 } | Popular Tags |