1 19 20 package org.netbeans.modules.j2ee.oc4j.ide; 21 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.logging.ErrorManager ; 27 import javax.swing.JOptionPane ; 28 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 29 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager; 30 import org.netbeans.modules.j2ee.oc4j.util.OC4JDebug; 31 import org.netbeans.modules.j2ee.oc4j.util.OC4JPluginUtils; 32 import org.openide.util.NbBundle; 33 34 39 public class OC4JErrorManager extends ErrorManager { 40 41 44 private static Map <OC4JDeploymentManager, OC4JErrorManager> instances = new HashMap <OC4JDeploymentManager, OC4JErrorManager>(); 45 46 private OC4JDeploymentManager dm; 47 48 49 private OC4JErrorManager(OC4JDeploymentManager dm) { 50 this.dm = dm; 51 } 52 53 59 public static OC4JErrorManager getInstance(OC4JDeploymentManager dm) { 60 if (!instances.containsKey(dm)) 61 instances.put(dm, new OC4JErrorManager(dm)); 62 63 return instances.get(dm); 64 } 65 66 private void write(String s) { 67 OC4JLogger.getInstance(dm.getUri()).write(s); 68 } 69 70 private Throwable getDepestCause(Throwable t) { 71 return (null != t.getCause()) ? (getDepestCause(t.getCause())):(t); 72 } 73 74 80 public synchronized boolean reaction(String clazz) { 81 ClassReaction c = ClassReaction.lookup(clazz); 82 83 if (null != c) { 84 c.react(dm); 85 return true; 86 } 87 88 return false; 89 } 90 91 98 @Override 99 public synchronized void error(String s, Exception e, int code) { 100 List <String > buffer = new ArrayList <String >(); 101 102 if (OC4JDebug.isEnabled()) 103 write(s); 104 105 Throwable t = e; 106 107 if (null != e.getCause()) { 108 t = getDepestCause(e.getCause()); 109 } 110 111 for (final StackTraceElement st : t.getStackTrace()) { 112 if (OC4JDebug.isEnabled()) 113 write(st.toString()); 114 115 if(!buffer.contains(st.getClassName())) 117 if (reaction(st.getClassName())) 118 buffer.add(st.getClassName()); 119 } 120 } 121 122 static { 124 new AuthenticateReaction(); 125 new MissingDriverReaction(); 126 new MissingJSFReaction(); 127 } 128 129 private static class AuthenticateReaction extends ClassReaction { 130 131 public AuthenticateReaction() { 132 super("oracle.oc4j.rmi.ClientRmiTransport"); 133 } 134 135 public void react(OC4JDeploymentManager manager) { 136 InstanceProperties ip = manager.getInstanceProperties(); 137 138 String username = ip.getProperty(InstanceProperties.USERNAME_ATTR); 139 String password = OC4JPluginUtils.requestPassword(username); 140 141 if(password != null) 142 ip.setProperty(InstanceProperties.PASSWORD_ATTR, password); 143 } 144 } 145 146 private static class MissingDriverReaction extends ClassReaction { 147 148 public MissingDriverReaction() { 149 super("java.net.URLClassLoader"); 150 } 151 152 public void react(OC4JDeploymentManager manager) { 153 JOptionPane.showMessageDialog(null, NbBundle.getMessage(OC4JErrorManager.class, "MSG_MissingDriver"), 154 NbBundle.getMessage(OC4JErrorManager.class, "MSG_MissingDriverTitle"), JOptionPane.INFORMATION_MESSAGE); 155 } 156 } 157 158 private static class MissingJSFReaction extends ClassReaction { 159 160 public MissingJSFReaction() { 161 super("com.evermind.server.http.deployment.WARAnnotationParser"); 162 } 163 164 public void react(OC4JDeploymentManager manager) { 165 JOptionPane.showMessageDialog(null, NbBundle.getMessage(OC4JErrorManager.class, "MSG_MissingJSF"), 166 NbBundle.getMessage(OC4JErrorManager.class, "MSG_MissingJSFTitle"), JOptionPane.INFORMATION_MESSAGE); 167 } 168 } 169 170 private abstract static class ClassReaction { 171 172 private static Map <String , ClassReaction> reactions = new HashMap <String , ClassReaction>(); 173 174 private String clazz; 175 176 private ClassReaction(String clazz) { 177 this.clazz = clazz; 178 179 reactions.put(clazz, this); 180 } 181 182 private String getClazz() { 183 return clazz; 184 } 185 186 public abstract void react(OC4JDeploymentManager manager); 187 188 public static ClassReaction lookup(String clazz) { 189 return reactions.get(clazz); 190 } 191 } 192 } 193 | Popular Tags |