1 19 20 package org.netbeans.modules.j2ee.ejbcore.api.methodcontroller; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import org.netbeans.modules.j2ee.common.method.MethodModel; 26 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 27 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 28 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 29 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 30 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 31 import org.netbeans.modules.j2ee.dd.api.ejb.Session; 32 import org.openide.ErrorManager; 33 import org.openide.filesystems.FileObject; 34 35 40 public abstract class EjbMethodController { 41 42 public static EjbMethodController createFromClass(FileObject ejbClassFO, String className) { 43 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(ejbClassFO); 44 if (ejbModule == null) { 45 return null; 46 } 47 DDProvider provider = DDProvider.getDefault(); 48 EjbJar ejbJar = null; 49 EjbMethodController controller = null; 50 try { 51 ejbJar = provider.getMergedDDRoot(ejbModule.getMetadataUnit()); 52 if (ejbJar != null) { 53 EnterpriseBeans beans = ejbJar.getEnterpriseBeans(); 54 if (beans != null) { 55 Session session = (Session) beans.findBeanByName(EnterpriseBeans.SESSION, Ejb.EJB_CLASS, className); 56 if (session != null) { 57 controller = new SessionMethodController(ejbClassFO, session); 58 if (!controller.hasLocal() && !controller.hasRemote()) { 60 controller = null; 62 } 63 } else { 64 Entity entity = (Entity) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_CLASS, className); 65 if (entity != null) { 66 controller = new EntityMethodController(ejbClassFO, entity, ejbJar); 67 } 68 } 69 } 70 } 71 } catch (IOException ioe) { 72 ErrorManager.getDefault().notify(ioe); 73 } 74 return controller; 75 } 76 77 81 public abstract List getImplementation(MethodModel intfView); 82 public abstract MethodModel getPrimaryImplementation(MethodModel intfView); 83 86 public abstract boolean hasJavaImplementation(MethodModel intfView); 87 public abstract boolean hasJavaImplementation(MethodType methodType); 88 89 94 public abstract ClassMethodPair getInterface(MethodModel beanImpl, boolean local); 95 96 103 public abstract boolean hasMethodInInterface(MethodModel method, MethodType methodType, boolean local); 104 105 108 public abstract MethodType getMethodTypeFromInterface(MethodModel clientView); 109 public abstract MethodType getMethodTypeFromImpl(MethodModel implView); 110 111 public abstract String getBeanClass(); 112 public abstract String getLocal(); 113 public abstract String getRemote(); 114 public abstract Collection <String > getLocalInterfaces(); 115 public abstract Collection <String > getRemoteInterfaces(); 116 public abstract boolean hasLocal(); 117 public abstract boolean hasRemote(); 118 public void addEjbQl(MethodModel clientView, String ejbql, FileObject ddFileObject) throws IOException { 119 assert false: "ejbql not supported for this bean type"; 120 } 121 122 public String createDefaultQL(MethodModel methodModel) { 123 return null; 124 } 125 126 129 public abstract void createAndAddInterface(MethodModel beanImpl, boolean local); 130 131 137 public abstract void createAndAddImpl(MethodModel clientView); 138 139 public abstract void delete(MethodModel interfaceMethod, boolean local); 140 141 144 public abstract boolean supportsMethodType(MethodType.Kind type); 145 public abstract MethodModel createAndAdd(MethodModel clientView, boolean local, boolean component); 146 147 148 149 protected static final class ClassMethodPair { 150 151 private final String className; 152 private final MethodModel methodModel; 153 154 public ClassMethodPair(String className, MethodModel methodModel) { 155 this.className = className; 156 this.methodModel = methodModel; 157 } 158 159 public String getClassName() { 160 return className; 161 } 162 163 public MethodModel getMethodModel() { 164 return methodModel; 165 } 166 167 } 168 } 169 | Popular Tags |