1 5 package xdoclet.modules.ejb.entity; 6 7 import java.text.MessageFormat ; 8 import java.util.*; 9 10 import xjavadoc.*; 11 import xdoclet.DocletContext; 12 13 import xdoclet.DocletTask; 14 import xdoclet.XDocletException; 15 import xdoclet.XDocletTagSupport; 16 import xdoclet.modules.ejb.EjbTagsHandler; 17 import xdoclet.modules.ejb.entity.EntityFacadeSubTask; 18 import xdoclet.modules.ejb.session.RemoteFacadeSubTask; 19 20 26 public class FacadeTagsHandler extends EntityTagsHandler 27 { 28 29 public static String getEntityFacadeClassFor(XClass clazz) 30 { 31 String fileName = clazz.getContainingPackage().getName(); 32 String entityName = MessageFormat.format(getEntityFacadeClassPattern(), new Object []{EjbTagsHandler.getShortEjbNameFor(clazz)}); 33 34 35 fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(EntityFacadeSubTask.class)); 37 if (fileName.length() > 0) { 38 fileName += "."; 39 } 40 41 fileName += entityName; 42 43 return fileName; 44 } 45 46 public static String getRemoteFacadeClassFor(XClass clazz) 47 { 48 String fileName = clazz.getContainingPackage().getName(); 49 String entityName = MessageFormat.format(getRemoteFacadeClassPattern(), new Object []{EjbTagsHandler.getShortEjbNameFor(clazz)}); 50 51 52 fileName = choosePackage(fileName, null, DocletTask.getSubTaskName(RemoteFacadeSubTask.class)); 54 if (fileName.length() > 0) { 55 fileName += "."; 56 } 57 58 fileName += entityName; 59 60 return fileName; 61 } 62 63 68 protected static String getRemoteFacadeClassPattern() 69 { 70 RemoteFacadeSubTask remoteFacadeSubtask = ((RemoteFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(RemoteFacadeSubTask.class))); 71 72 if (remoteFacadeSubtask != null) { 73 return remoteFacadeSubtask.getRemoteFacadeClassPattern(); 74 } 75 else { 76 return RemoteFacadeSubTask.DEFAULT_REMOTE_FACADE_CLASS_PATTERN; 77 } 78 } 79 80 81 protected static String getEntityFacadeClassPattern() 82 { 83 EntityFacadeSubTask entityFacadeSubtask = ((EntityFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(EntityFacadeSubTask.class))); 84 85 if (entityFacadeSubtask != null) { 86 return entityFacadeSubtask.getEntityFacadeClassPattern(); 87 } 88 else { 89 return EntityFacadeSubTask.DEFAULT_ENTITY_FACADE_CLASS_PATTERN; 90 } 91 } 92 93 94 99 protected static String getEntityFacadeEjbNamePattern() 100 { 101 EntityFacadeSubTask entityFacadeSubtask = ((EntityFacadeSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(EntityFacadeSubTask.class))); 102 103 if (entityFacadeSubtask != null) { 104 return entityFacadeSubtask.getEntityFacadeEjbNamePattern(); 105 } 106 else { 107 return EntityFacadeSubTask.DEFAULT_FACADE_EJB_NAME_PATTERN; 108 } 109 } 110 111 public String getFacadeEjbNameFor(XClass clazz) throws XDocletException 112 { 113 String name = clazz.getDoc().getTagAttributeValue("ejb.facade", "name", false); 115 116 if (name != null && !"".equals(name)) { 117 return name; 118 } 119 else { 120 return MessageFormat.format(getEntityFacadeEjbNamePattern(), new Object []{EjbTagsHandler.getShortEjbNameFor(clazz)}); 121 } 122 123 } 124 125 132 public String entityFacadeClass() throws XDocletException 133 { 134 return getEntityFacadeClassFor(XDocletTagSupport.getCurrentClass()); 135 } 136 137 142 public String remoteFacadeClass() throws XDocletException 143 { 144 return getRemoteFacadeClassFor(XDocletTagSupport.getCurrentClass()); 145 } 146 147 148 155 public String facadeEjbName() throws XDocletException 156 { 157 return getFacadeEjbNameFor(XDocletTagSupport.getCurrentClass()); 158 } 159 160 public boolean canUseLocal() throws XDocletException 161 { 162 XClass clazz = XDocletTagSupport.getCurrentClass(); 163 164 return !EjbTagsHandler.isOnlyRemoteEjb(clazz); 165 } 166 167 175 public void ifUseLocalInterface(String template, Properties attributes) throws XDocletException 176 { 177 if (canUseLocal()) { 178 generate(template); 179 } 180 } 181 182 190 public void ifUseRemoteInterface(String template, Properties attributes) throws XDocletException 191 { 192 if (!canUseLocal()) { 193 generate(template); 194 } 195 } 196 197 204 public String sessionType() throws XDocletException 205 { 206 XClass clazz = XDocletTagSupport.getCurrentClass(); 207 String type = clazz.getDoc().getTagAttributeValue("ejb.facade", "type", false); 208 209 if ("Statefull".equals(type)) { 210 return "Statefull"; 211 } 212 else { 213 return "Stateless"; 214 } 215 } 216 217 224 public String viewType() throws XDocletException 225 { 226 XClass clazz = XDocletTagSupport.getCurrentClass(); 227 String type = clazz.getDoc().getTagAttributeValue("ejb.bean", "view-type", false); 228 String facadeType = clazz.getDoc().getTagAttributeValue("ejb.facade", "view-type", false); 229 230 if (facadeType != null) { 231 return facadeType; 232 } 233 234 if (type != null) { 235 return type; 236 } 237 238 return "remote"; 239 } 240 241 248 public String localJndiName() throws XDocletException 249 { 250 XClass clazz = XDocletTagSupport.getCurrentClass(); 251 String jndi = clazz.getDoc().getTagAttributeValue("ejb.facade", "local-jndi-name", false); 252 253 if (jndi != null) { 254 return jndi; 255 } 256 257 return facadeEjbName() + "Local"; 258 } 259 260 267 public String jndiName() throws XDocletException 268 { 269 XClass clazz = XDocletTagSupport.getCurrentClass(); 270 String jndi = clazz.getDoc().getTagAttributeValue("ejb.facade", "jndi-name", false); 271 272 if (jndi != null) { 273 return jndi; 274 } 275 276 return "ejb/" + facadeEjbName(); 277 } 278 279 286 287 public String beanPermission() throws XDocletException 288 { 289 XClass clazz = XDocletTagSupport.getCurrentClass(); 290 291 String permission = clazz.getDoc().getTagAttributeValue("ejb.facade", "permission", false); 292 293 if (permission != null) { 294 return "* @ejb.permission role-name=\"" + permission + "\""; 296 } 297 298 String unchecked = clazz.getDoc().getTagAttributeValue("ejb.facade", "unchecked", false); 299 300 if (unchecked != null) { 301 return "* @ejb.permission unchecked=\"true\""; 303 } 304 305 permission = clazz.getDoc().getTagAttributeValue("ejb.permission", "role-name", true); 307 308 if (permission != null) { 309 return "* @ejb.permission role-name=\"" + permission + "\""; 311 } 312 313 unchecked = clazz.getDoc().getTagAttributeValue("ejb.permission", "unchecked", true); 314 315 if (unchecked != null) { 316 return "* @ejb.permission unchecked=\"true\""; 318 } 319 320 return "*"; 321 } 322 323 330 331 public String beanRef() throws XDocletException 332 { 333 XClass clazz = XDocletTagSupport.getCurrentClass(); 334 335 if (canUseLocal()) { 336 return "* @ejb.ejb-ref ejb-name=\"" + EjbTagsHandler.getEjbNameFor(clazz) + "\" view-type=\"local\""; 337 } 338 else { 339 return "* @ejb.ejb-ref ejb-name=\"" + EjbTagsHandler.getEjbNameFor(clazz) + "\"view-type=\"remote\""; 340 } 341 } 342 } 343 | Popular Tags |