1 23 24 29 30 package com.sun.jdo.spi.persistence.support.ejb.ejbc; 31 32 import java.util.ResourceBundle ; 33 34 import com.sun.ejb.codegen.GeneratorException; 35 36 import com.sun.enterprise.deployment.Application; 37 import com.sun.enterprise.deployment.EjbBundleDescriptor; 38 39 import com.sun.jdo.spi.persistence.utility.I18NHelper; 40 41 45 public class JDOCodeGeneratorHelper { 46 47 50 private final static ResourceBundle messages = I18NHelper.loadBundle( 51 JDOCodeGeneratorHelper.class); 52 53 56 public static String getModuleName(EjbBundleDescriptor bundle) { 57 String moduleName = null; 58 Application application = bundle.getApplication(); 59 if (application.isVirtual()) { 60 moduleName = application.getRegistrationName(); 62 63 } else { 64 String jarName = bundle.getModuleDescriptor().getArchiveUri(); 66 int l = jarName.length(); 67 68 moduleName = jarName.substring(0, l - 4); 70 71 } 72 73 return moduleName; 74 } 75 76 82 public static GeneratorException createGeneratorException( 83 String key, EjbBundleDescriptor bundle) { 84 return new GeneratorException(I18NHelper.getMessage( 85 messages, key, 86 bundle.getApplication().getRegistrationName(), 87 getModuleName(bundle))); 88 } 89 90 97 public static GeneratorException createGeneratorException( 98 String key, EjbBundleDescriptor bundle, Exception e) { 99 100 return new GeneratorException(I18NHelper.getMessage( 101 messages, key, 102 bundle.getApplication().getRegistrationName(), 103 getModuleName(bundle), 104 e.getMessage())); 105 } 106 107 113 public static GeneratorException createGeneratorException( 114 String key, String beanName, EjbBundleDescriptor bundle) { 115 116 return new GeneratorException(I18NHelper.getMessage( 117 messages, key, beanName, 118 bundle.getApplication().getRegistrationName(), 119 getModuleName(bundle))); 120 } 121 122 130 public static GeneratorException createGeneratorException( 131 String key, String beanName, EjbBundleDescriptor bundle, 132 Exception e) { 133 134 return createGeneratorException(key, beanName, bundle, e.getMessage()); 135 } 136 137 147 public static GeneratorException createGeneratorException( 148 String key, String beanName, EjbBundleDescriptor bundle, 149 Exception e, StringBuffer buf) { 150 151 String msg = (buf == null) ? 152 e.getMessage() : 153 buf.append(e.getMessage()).append('\n').toString(); 154 return createGeneratorException(key, beanName, bundle, msg); 155 } 156 157 165 public static GeneratorException createGeneratorException( 166 String key, String beanName, EjbBundleDescriptor bundle, 167 String msg) { 168 169 return new GeneratorException(I18NHelper.getMessage( 170 messages, key, 171 new Object [] { 172 beanName, 173 bundle.getApplication().getRegistrationName(), 174 getModuleName(bundle), 175 msg} 176 )); 177 } 178 } 179 | Popular Tags |