Listing 1: faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>

<!--
  Copyright (c) 2004 Anatoly S. Krivitsky, PhD.
  All rights reserved.
  Conditional permission for free use of the code.
  As soon as above copyright notes are mentioned, the author grants a permission to any
  person or organization to use, distribute and publish this code for free.
  Questions and comments may be directed to the author at akrivitsky@yahoo.com and
  akrivitsky@usa.com.
  Disclaimer of Liability
  The user assumes all responsibility and risk for the use of this code "as is".
  There is no warranty of any kind associated with the code.
  Under no circumstances, including negligence, shall the author be liable for any DIRECT,
  INDIRECT, INCIDENTAL, SPECIAL or CONSEQUENTIAL DAMAGES, or LOST PROFITS that result from
  the use or inability to use the code.
  Nor shall the author be liable for any such damages including, but not limited to,
  reliance by any person on any information obtained with the code
-->

<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>

  <application>
    <locale-config>
      <default-locale>en</default-locale>
     </locale-config>
<message-bundle>
DwhetBeanMessages
</message-bundle>
  </application>

<managed-bean>
    <managed-bean-name>DwhetBean
</managed-bean-name>
    <managed-bean-class>
akrivitsky.DwhetBean
</managed-bean-class>
    <managed-bean-scope>
session
</managed-bean-scope>
</managed-bean>
<navigation-rule>
    <from-view-id>
/pages/input.jsp
</from-view-id>
    <navigation-case>
<from-outcome>sucess</from-outcome>
  <to-view-id>
/pages/response.jsp
</to-view-id>
    </navigation-case>
  </navigation-rule>
  </faces-config>

Listing 2. input.jsp


<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<HTML>
    <HEAD> <title>Whetstone in Servlets. Copyright (c) 2004 Anatoly S. Krivitsky,
	PhD.  All 	rights reserved.</title> </HEAD>
    <body bgcolor="white">
    <f:view>
    <h:form id="Form1" >
      <Font color=blue size=7>
      <B><Center>  To obtain DWhetstone results please fill out form below
	  </Center></B></font>
      <p><Center>
       Number of inner loops (from 300 to 400) :
      <br>
  	<h:inputText id="numberOFInner" value="#{DWhetBean.numberOFInnerLoops}" 
	required="true">
<f:validateLongRange minimum="300" maximum="400"/>
</h:inputText>
  
<h:message style="color: red; font-family: 'New Century Schoolbook', serif; font-style:
oblique; " id="errors1" for="numberOFInner"/>

        <br>
      Number of outer loops (from 150 to 200) :
      <br>
  	<h:inputText id="numberOFOuter" value="#{DWhetBean.numberOFOuterLoops}"
	required="true">
                 <f:validateLongRange minimum="150" maximum="200"/>
         </h:inputText>
  
<h:message style="color: red; font-family: 'New Century Schoolbook', serif; font-style:
oblique; " id="errors2" for="numberOFOuter"/>
        <br>
	 <h:commandButton id="submit" action="#{DWhetBean.processP}"  value="Submit"/>
         <p>
	 <br><br>

</Center>
<P><Font color=blue size=5><b> Wait about 2 minutes for results </B></font>
    </h:form>
    </f:view>
</HTML>

Listing 3. Response.jsp

 

<HTML>
    <HEAD> <title>Dwhet JSF results. Copyright  (c) 2004 Anatoly S. Krivitsky, PhD.
	All rights reserved.</title> </HEAD>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <body bgcolor="white">
    <f:view>
    <h:form id="responseForm" >
     <h:outputText  value="#{DWhetBean.responseIn}"></h:outputText> <br><br>
     <h:outputText  value="#{DWhetBean.responseOu}"> </h:outputText><br><br>
     <h:outputText   value="#{DWhetBean.path1}"></h:outputText><br><br>
      <h:outputText   value="#{DWhetBean.path11}"></h:outputText><br><br>
      <br> __________________________________<br>
      <h:outputText   value="#{DWhetBean.path2}"></h:outputText><br><br>
      <h:outputText   value="#{DWhetBean.path21}"></h:outputText><br><br>
      <br> __________________________________<br>
            <h:outputText id="result"  value="#{DWhetBean.response}"></h:outputText>

     <P>
    <A HREF=http://localhost:8080/DwhetSF><B>Click here to try again</B></A>
   <P><A href="http://www.mycgiserver.com/~akrivitsky/index.html\">
   <B>Click here to return to my home page</B></A>
    </h:form>
    </f:view>
 </HTML>

Listing 4. DwheatBean.java

 
/*
* Copyright (c) 2004 Anatoly S. Krivitsky, PhD. * All rights reserved.
* Conditional permission for free use of the * code.
* As soon as above copyright notes are * mentioned, 
* the author grants a permission to any person * or organization 
* to use, distribute and publish this code for * free.  * 
* Questions and comments may be directed to * the author at 
 * akrivitsky@yahoo.com and akrivitsky@usa.com. 
 * 
 * Disclaimer of Liability  
 * The user assumes all responsibility
 * and risk for the use of this code "as is".
 * There is no  warranty of any kind associated with the code.
 * Under no circumstances, including negligence, shall the author be liable
 * for any DIRECT, INDIRECT, INCIDENTAL, SPECIAL or CONSEQUENTIAL DAMAGES,
 * or LOST PROFITS that result from the use or inability to use the code.
 * Nor shall the author be liable for any such damages including,
 * but not limited to, reliance by any person on any
 * information obtained with the code
 */

package akrivitsky;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import javax.faces.application.FacesMessage;
import java.lang.Math;
import java.util.Date;
import java.io.*;
import java.text.*;
import java.util.*;
//import javax.faces.component.UIComponent;
//import javax.faces.context.FacesContext;
//import javax.faces.validator.LongRangeValidator;
//import javax.faces.validator.Validator;
//import javax.faces.validator.ValidatorException;

  
//           DWhetBean
public class DWhetBean {
  
  Integer numberOFInnerLoops;
  Integer numberOFOuterLoops;
  String response;
  String path1;
  String path11;
  String path2;
  String path21;
  String responseIn;
  String responseOu;
  
  static double t1, t2, t3;
  static int j, k, l;
  static double  e1[];

  public void setNumberOFInnerLoops(Integer Number_OFInnerLoops) {
    System.out.println("DWhet: setNumberOFInnerLoops started");
        this.numberOFInnerLoops = Number_OFInnerLoops;
    }

  public void setNumberOFOuterLoops (Integer Number_OuterLoops) {
    System.out.println("DWhet: setNumberOFOuterLoops started");
        this.numberOFOuterLoops = Number_OuterLoops;
  }

      public Integer getNumberOFInnerLoops() {
	    System.out.println("DWhet: getNumberOFInnerLoops started");
        return this.numberOFInnerLoops;
    }

       public Integer getNumberOFOuterLoops() {
	     System.out.println("DWhet: getNumberOFOuterLoops started");
        return this.numberOFOuterLoops;
    }


       public DWhetBean() {

        System.out.println("DWhet: started");

    }
  
  public String getResponseIn() {
  System.out.println
  ("getResponseIn started this.responseIn =" + this.responseIn);
      //processP();
      return this.responseIn;
  }
  public String getResponse() {

       return this.response;
  }
      public String processP()
   {
    int i, isave;
    int n2, n3, n4, n6, n7, n8, n9, n11;
    int inner_program, outer_program, kount, npass, max_pass, pass_print;

    double x, y, z;
    double whet_save, dif_save, kilowhet;
    double begin_time, end_time, dif_time;
    double error, whet_err, percent_err;

    System.out.println("DWhet: processP started");

    kilowhet = 0;

    begin_time = 0;

    end_time = 0;

    dif_time = 0;

    whet_save = 0;

    dif_save = 0;
    
    System.out.println("DWhet: getResponse started before inner_program");
    inner_program = numberOFInnerLoops.intValue();
    Date date = new Date();

    e1 = new double[5];

    npass = 0;
    max_pass = 2;

     outer_program = numberOFOuterLoops.intValue();

     responseIn = "Number of Inner Loops: " + inner_program;
     responseOu = "Number of Outer Loops: " + outer_program;
    while(npass < max_pass) {

        pass_print = npass + 1;
        if (pass_print == 1)
        {
      path1 = " Pass number: " + pass_print ;
        System.out.println("DWhet: path1 = " + path1);
        }
        else
      path2  = " Pass number: " + pass_print ;

      kount = 0;
      begin_time = secnds();
      while(kount < outer_program) {
	t1 = 0.499975;
	t2 = 0.50025;
	t3 = 2.0;

	isave = inner_program;
	n2    = 12  * inner_program;
	n3    = 14  * inner_program;
	n4    = 345 * inner_program;
	n6    = 210 * inner_program;
	n7    = 32  * inner_program;
	n8    = 899 * inner_program;
	n9    = 616 * inner_program;
	n11   = 93  * inner_program;

	e1[1] = 1.0;
	e1[2] = -1.0;
	e1[3] = 1.0;
	e1[4] = -1.0;

	// Loop 2
	for(i = 1; i <= n2; i++) {
	  e1[1] = ( e1[1] + e1[2] + e1[3] - e1[4]) * t1;
	  e1[2] = ( e1[1] + e1[2] - e1[3] + e1[4]) * t1;
	  e1[3] = ( e1[1] - e1[2] + e1[3] + e1[4]) * t1;
	  e1[4] = (-e1[1] + e1[2] + e1[3] + e1[4]) * t1;
	}

	// Loop 3
	for(i = 1; i <= n3; i++) {
	  sub1(e1);
	}

	// Loop 4
	j = 1;
	for (i = 1; i <= n4; i++) {
	  if(j - 1 != 0) {
	    j = 2;
	  } else {
	    j = 3;
	  }
	  if(j - 2 != 0) {
	    j = 1;
	  } else {
	    j = 0;
	  }
	  if(j - 1 != 0) {
	    j = 1;
	  } else {
	    j = 0;
	  }
	}

	// Loop 6
	j = 1;
	k = 2;
	l = 3;
	for(i = 1; i <= n6; i++) {
	  j = j * (k - j) * (l - k);
	  k = l * k - (l - j) * k;
	  l = (l - k) * (k + j);
	  e1[l - 1] = j + k + l;
	  e1[k - 1] = j * k * l;
	}

	// Loop 7
	x = 0.5;
	y = 0.5;
	for(i = 1; i <= n7; i++) {
	  x = t1 * Math.atan( t3 * Math.sin( x ) * Math.cos( x ) / (Math.cos( x + y ) +
	  Math.cos( x - y ) - 1.0) );
	  y = t1 * Math.atan( t3 * Math.sin( y ) * Math.cos( y ) / (Math.cos( x + y ) +
	  Math.cos( x - y ) - 1.0) );
	}

	// Loop 8
	x = 1.0;
	y = 1.0;
	z = 1.0;
	for(i = 1; i <= n8; i++) {
	  sub2(x,y,z);
	}

	// Loop 9
	j = 1;
	k = 2;
	l = 3;
	e1[1] = 1.0;
	e1[2] = 2.0;
	e1[3] = 3.0;
	for(i = 1; i <= n9; i++) {
	  sub3();
	}

	// Loop 11
	x = 0.75;
	for(i = 1; i <= n11; i++) {
	  x = Math.sqrt( Math.exp( Math.log( x ) / t2 ) );
	}

	inner_program = isave;
	kount = kount + 1;
      }
      end_time = secnds();
      dif_time = end_time - begin_time;
      kilowhet =  ((double)(100*inner_program*outer_program))/dif_time;
      if (pass_print == 1) 
      path11 = " Elapsed time = " + dif_time + " kilowhet = " +
      kilowhet;
        else
      path21 = " Elapsed time = " + dif_time + " kilowhet = " +
      kilowhet;
      npass = npass + 1;
      if(npass < max_pass) {
        dif_save = dif_time;
        whet_save =  kilowhet;
	inner_program = inner_program * max_pass;
      }
    }
    error = Math.abs(dif_time - (dif_save * max_pass));
    whet_err = Math.abs(whet_save - kilowhet);
    percent_err = Math.abs(whet_err * (double)100 / kilowhet);
    response = " time_error = " + error + " whet_err = " + whet_err
    + " percent_err = " + percent_err + "%";

    return "sucess";

  }

public void setPath1(String p1) {
           this.path1 = p1;
       }

       public String getPath1() {
           System.out.println("DWhet: getPath1 started path1 = " 
           + this.path1 );
       return this.path1;
       }
      public String getPath11() {
       return this.path11;
       }
       public String getPath2() {
       return this.path2;
       }
      public String getPath21() {
       return this.path21;
       }

       public String getResponseOu() {

       return this.responseOu;
       }


  public void sub1(double[] e) {

    for(int i = 1; i <= 6; i++) {
      e[1] = (e[1]  + e[2] + e[3] - e[4]) * t1;
      e[2] = (e[1]  + e[2] - e[3] + e[4]) * t1;
      e[3] = (e[1]  - e[2] + e[3] + e[4]) * t1;
      e[4] = (-e[1] + e[2] + e[3] + e[4]) / t3;
    }
  }

  public  void sub2(double x, double y, double z) {
    double x1, y1;

    x1 = x;
    y1 = y;
    x1 = (x1 + y1) * t1;
    y1 = (x1 + y1) * t1;
    z  = (x1 + y1) / t3;
  }

  public static void sub3() {
    e1[j] = e1[k];
    e1[k] = e1[l];
    e1[l] = e1[j];
  }

  public static double secnds() {
  Date date = new Date();
  double s1 = (double)(date.getHours()*3600) +
  (double)(date.getMinutes()*60) + (double)(date.getSeconds());
  return(s1);
   }
}