1 5 package calculator; 6 7 import java.net.URL ; 8 import java.net.URLClassLoader ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.omg.CORBA.INTERNAL ; 13 import org.omg.CosNaming.NamingContextExt ; 14 import org.omg.CosNaming.NamingContextPackage.CannotProceed ; 15 import org.omg.CosNaming.NamingContextPackage.InvalidName ; 16 import org.omg.CosNaming.NamingContextPackage.NotFound ; 17 18 import ve.luz.ica.jackass.component.ApplicationContext; 19 import ve.luz.ica.jackass.component.StatelessContext; 20 import ve.luz.ica.jackass.component.StatelessHook; 21 22 23 33 public class ComplexCalculatorImpl extends ComplexCalculatorPOA implements StatelessHook 34 { 35 private static final Log LOG = LogFactory.getLog(ComplexCalculatorImpl.class); 36 37 private StatelessContext compContext = null; 38 private ApplicationContext appContext = null; 39 40 47 public Complex add(Complex op1, Complex op2) 48 { 49 if (LOG.isDebugEnabled()) LOG.debug("Parameters:" + op1 + ", " + op2); 50 51 try 52 { 53 URLClassLoader loader = (URLClassLoader ) this.getClass().getClassLoader(); 54 URL [] urls = loader.getURLs(); 55 for (int i = 0; i<urls.length; ++i) 56 { 57 LOG.info(urls[i].getPath()); 58 } 59 60 61 NamingContextExt rootContext = compContext.getRootNamingContext(); 62 String calcContext = compContext.getProperty("real_calculator_context"); 63 64 org.omg.CORBA.Object obj = rootContext.resolve_str(calcContext); 65 RealCalculator calc = RealCalculatorHelper.narrow(obj); 66 if (LOG.isDebugEnabled()) LOG.debug("Resolved RealCalculator component:" + calc); 67 68 double real = calc.add(op1.r, op2.r); 69 double imag = calc.add(op1.i, op2.i); 70 Complex c = new Complex(real, imag); 71 72 if (LOG.isDebugEnabled()) LOG.debug("Result:" + c.r + " " + c.i + "i"); 73 return c; 74 } 75 catch (NotFound e) 76 { 77 String errMsg = "RealCalculator component not found."; 78 79 if (LOG.isErrorEnabled()) 80 { 81 errMsg += "Why:" + e.why + ". Rest of the name:" + e.rest_of_name; 82 LOG.error(errMsg, e); 83 } 84 85 throw new INTERNAL (errMsg); 86 } 87 catch (CannotProceed e) 88 { 89 String errMsg = "System gave up when it was looking for a RealCalculator component."; 90 91 if (LOG.isErrorEnabled()) 92 { 93 errMsg += "Rest of the name:" + e.rest_of_name; 94 LOG.error(errMsg, e); 95 } 96 97 throw new INTERNAL (errMsg); 98 } 99 catch (InvalidName e) 100 { 101 String errMsg = "Cannot find RealCalculator, Invalid name"; 102 if (LOG.isErrorEnabled()) 103 { 104 LOG.error(errMsg, e); 105 } 106 107 throw new INTERNAL (errMsg); 108 } 109 } 110 111 114 public void jackassSetContexts(ApplicationContext appCtx, StatelessContext compCtx) 115 { 116 this.appContext = appCtx; 117 this.compContext = compCtx; 118 } 119 120 123 public void jackassCreate() 124 { 125 } 127 128 131 public void jackassRemove() 132 { 133 } 135 } 136
| Popular Tags
|