Hi John, Thanks for your example! Have you ever tried the validation framework? Seems that it do nearly the same...
Regards, Henner > -----Urspr�ngliche Nachricht----- > Von: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Im > Auftrag von John Gagon > Gesendet: Freitag, 28. Februar 2003 23:25 > An: [EMAIL PROTECTED] > Betreff: [dbforms] EJB Example. > > > > > I have some actual source code to share for the EJB Example: > Thanks someone for putting my EJB tip in the document ;o> > > Here is some actual sample code though. : > > > public class BasicTestInterceptor extends DbEventInterceptorSupport { > > static Category log = > Category.getInstance(BasicTestInterceptor.class.getName()); > > /** > * Checks to see if a number is in range inclusively > given three Strings. > * @param check String representing a number. > * @param low String representing the low number of the range. > * @param high String representing the high number of the range > * @param inclusive set to true if you want the low <= > check and check <= high . > * @param digits the number in digits to the left of > the decimal to round. positive, non-zero int > * @return value converted to a string. > * @throws ValidationException when encountering other > exceptions like NumberFormatException. > * > */ > public static boolean inRange(String check, String low, > String high, boolean inclusive) > throws ValidationException > { > try > { > NumericValidationLocal numericValidation = > EjbUtil.getNumericValdiationBean(); > if(numericValidation==null) > { > System.out.println("Null numericValidation"); > return false; > } > return > numericValidation.inRange(check,low,high,inclusive); > } > catch(MathException me) > { > throw new ValidationException(me.getMessage()); > } > catch(Exception e) > { > throw new ValidationException(""); > } > > }//inRange(...) > > ... > }//BasicTestInterceptor > > package com.atser.sejb.math; > > > > public interface NumericValidationLocal > extends javax.ejb.EJBLocalObject > { > > /** > * Checks to see if a number is in range. > * Range is inclusive given three Strings. > * @param check String representing a number. > * @param low String representing the low number of the range. > * @param high String representing the high number of the range > * @param inclusive set to true > if you want the low <= check and check <= high . > * @param digits the number in digits to the > left of the decimal to round. positive, > non-zero integer only. For example: 1438 with 1 passed in > will give us 1440. > * @return value converted to a string. > * @throws ValidationException for any number format problems. > */ > public boolean inRange( > String check, > String low, > String high, > boolean inclusive > ) > throws MathException; > > > }//NumericValidationLocal > > package com.atser.sejb.math; > > > public interface NumericValidationLocalHome > extends javax.ejb.EJBLocalHome > { > > NumericValidationLocal create() throws > javax.ejb.CreateException; > > }//NumericValidationLocal > > > import javax.ejb.*;//SessionContext > import org.apache.log4j.*;//Category > > > public class NumericValidationStatelessBean > implements javax.ejb.SessionBean > { > > private static Category log = > > Category.getInstance("NumericValidationStatefulBean"); > > > private javax.ejb.SessionContext ctx; > > /** > * Provides generic range checking. > * Checks to see if a number is in range. > * Range is inclusive given three Strings. > * and returns true if in range or false if out of > * specified range. > */ > public static boolean inRange(String check, > String low, String high, boolean inclusive) > throws MathException > { > try > { > double c = Double.parseDouble(check); > double l = Double.parseDouble(low); > double h = Double.parseDouble(high); > if(inclusive) > return (l<=c && c<=h); > else > return (l<c && c<h); > } > catch(NumberFormatException nfe) > { > throw new MathException("Invalid > arguements to method: inRange(String check, String low, > String high, boolean > inclusive):"+check+","+low+","+high+","+inclusive); > } > > > }//inRange(...) > > > public void ejbCreate() > { > log.debug("ejbCreate()"); > }//ejbCreate() > > > public void ejbRemove() > { > log.debug("ejbRemove()"); > }//ejbRemove() > > > public void ejbActivate() > { > log.debug("ejbActivate()"); > }//ejbActivate() > > > public void ejbPassivate() > { > log.debug("ejbPassivate()"); > }//ejbPassivate() > > > public void setSessionContext(javax.ejb.SessionContext ctx) > { > this.ctx = ctx; > log.debug("setSessionContext(..)"); > return; > }//setSessionContext(..) > > > }//NumericValidationStatefulBean > > jboss.xml > <?xml version="1.0" encoding="UTF-8"?> > <jboss> > <enterprise-beans> > <session> > <ejb-name>com/atser/sejb/math/NumericValidation</ejb-name> > <jndi-name>com/atser/sejb/math/NumericValidation</jndi-name> > </session> > </enterprise-beans> > </jboss> > > ejb-jar.xml > <!DOCTYPE ejb-jar > PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' > 'http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd'> > <ejb-jar> > <enterprise-beans> > <session> > <!-- The JNDI name of the bean. --> > <ejb-name>com/atser/sejb/math/NumericValidation</ejb-name> > > <!-- Class configuration for the bean --> > > <local-home>com.atser.sejb.math.NumericValidationLocalHome</lo > cal-home> > <local>com.atser.sejb.math.NumericValidationLocal</local> > > <ejb-class>com.atser.sejb.math.NumericValidationStatelessBean< > /ejb-class> > <session-type>Stateless</session-type> > <transaction-type>Container</transaction-type> > </session> > </enterprise-beans> > </ejb-jar> > > > web.xml > > <ejb-local-ref> > <ejb-ref-name>ejb/NumericValidation</ejb-ref-name> > <ejb-ref-type>Session</ejb-ref-type> > > <local-home>com.atser.sejb.math.NumericValidationLocalHome</lo > cal-home> > <local>com.atser.sejb.math.NumericValidationLocal</local> > <ejb-link>com/atser/sejb/math/NumericValidation</ejb-link> > </ejb-local-ref> > > making sure you have > <!DOCTYPE web-app > PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" > "http://java.sun.com/dtd/web-app_2_3.dtd"> > > > in application.xml, make sure you have the jar you compiled > do not play with jndi.properties. > don't need jboss-web.xml > > tested on JBoss 3.0.0-Tomcat 4.0.6 > > > > > > > > > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > DbForms Mailing List > http://www.wap-force.net/dbforms ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ DbForms Mailing List http://www.wap-force.net/dbforms
