Home » openejb-3.1.2-src » org » superbiz » calculator » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.superbiz.calculator;
   18   
   19   import java.util.Date;
   20   
   21   import javax.ejb.Stateless;
   22   import javax.jws.HandlerChain;
   23   import javax.jws.WebService;
   24   import javax.xml.ws.Holder;
   25   
   26   /**
   27    * This is an EJB 3 style pojo stateless session bean
   28    * Every stateless session bean implementation must be annotated
   29    * using the annotation @Stateless
   30    * This EJB has a single interface: CalculatorWs a webservice interface.
   31    */
   32   //START SNIPPET: code
   33   @Stateless
   34   @WebService(
   35           portName = "CalculatorPort",
   36           serviceName = "CalculatorWsService",
   37           targetNamespace = "http://superbiz.org/wsdl",
   38           endpointInterface = "org.superbiz.calculator.CalculatorWs")
   39   @HandlerChain(file = "handler.xml")
   40   public class CalculatorImpl implements CalculatorWs, CalculatorLocal {
   41   
   42       public int sum(int add1, int add2) {
   43           return add1 + add2;
   44       }
   45   
   46       public int multiply(int mul1, int mul2) {
   47           return mul1 * mul2;
   48       }
   49   
   50       public int factorial(
   51   	    int number,
   52   	    Holder<String> userId, 
   53   	    Holder<String> returnCode,
   54   	    Holder<Date> datetime) {
   55   	
   56   	if (number == 0) {
   57   	    returnCode.value = "Can not calculate factorial for zero.";
   58   	    return -1;
   59   	}
   60   	
   61   	returnCode.value = userId.value;
   62   	datetime.value = new Date();
   63   	return (int) factorial(number);
   64       }
   65       
   66       // return n!
   67       // precondition: n >= 0 and n <= 20
   68       private static long factorial(long n) {
   69           if      (n <  0) throw new RuntimeException("Underflow error in factorial");
   70           else if (n > 20) throw new RuntimeException("Overflow error in factorial");
   71           else if (n == 0) return 1;
   72           else             return n * factorial(n-1);
   73       }
   74   }
   75   //END SNIPPET: code

Home » openejb-3.1.2-src » org » superbiz » calculator » [javadoc | source]