KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > calculator > RealCalculatorImpl


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package calculator;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9
10 import ve.luz.ica.jackass.component.ApplicationContext;
11 import ve.luz.ica.jackass.component.StatelessContext;
12 import ve.luz.ica.jackass.component.StatelessHook;
13
14 /**
15  * Servant class of calculator::ICalculator CORBA Interface.
16  * Is a example servant of a Stateless Component of Jackass.
17  * This class, been a CORBA Servant of calculator::ICalculator,
18  * should implement {@link StatelessHook} in order to be a
19  * Stateless Component of Jackass.
20  * @author Carlos Arévalo, Nelson Arapé
21  */

22 public class RealCalculatorImpl extends RealCalculatorPOA implements StatelessHook
23 {
24     private static final Log LOG = LogFactory.getLog(RealCalculatorImpl.class);
25
26     private ApplicationContext appContext = null;
27     private StatelessContext compContext = null;
28
29     /**
30      * Adds op1 to op2 and returns the result.
31      * A example implementation of
32      * {@link calculator.ICalculatorOperations#add(double, double)}
33      * @param op1 the first operand
34      * @param op2 the second operand
35      * @return op1 + op2
36      */

37     public double add(double op1, double op2)
38     {
39         if (LOG.isDebugEnabled())
40         {
41             LOG.debug("Parameters: " + op1 + "," + op2 +
42                       ". Result:" + (op1 + op2));
43         }
44         return op1 + op2;
45     }
46
47     /**
48      * Divide op1 to op2 and returns the result.
49      * A example implementation of
50      * {@link calculator.ICalculatorOperations#div(double, double)}
51      * @param op1 the first operand
52      * @param op2 the second operand
53      * @return op1 / op2
54      * @throws DivByZero if op2 == 0
55      */

56     public double div(double op1, double op2) throws DivByZero
57     {
58         if (LOG.isDebugEnabled()) LOG.debug("Parameters: " + op1 + "," + op2);
59
60         if (op2 == 0)
61         {
62             if (LOG.isWarnEnabled()) LOG.warn("DivByZero will be throw.");
63             throw new DivByZero();
64         }
65
66         if (LOG.isDebugEnabled()) LOG.debug("Result:" + (op1 / op2));
67         return op1 / op2;
68     }
69
70     /**
71      * @see ve.luz.ica.jackass.component.StatelessHook#jackassSetContext(ve.luz.ica.jackass.component.JackassContext)
72      */

73     public void jackassSetContexts(ApplicationContext appCtx, StatelessContext compCtx)
74     {
75         this.appContext = appCtx;
76         this.compContext = compCtx;
77     }
78
79     /**
80      * @see ve.luz.ica.jackass.component.StatelessHook#jackassCreate()
81      */

82     public void jackassCreate()
83     {
84         // Nothing to do in this sample component
85
}
86
87     /**
88      * @see ve.luz.ica.jackass.component.StatelessHook#jackassRemove()
89      */

90     public void jackassRemove()
91     {
92         // Nothing to do in this sample component
93
}
94 }
95
Popular Tags