User: user57  
  Date: 01/10/02 14:34:56

  Added:       src/main/org/jboss/survey/command SurveyHandler.java
  Log:
   o moved jboss-website/website/survey to jboss-website/survey (it's own
     module)
  
  Revision  Changes    Path
  1.1                  
website-survey/src/main/org/jboss/survey/command/SurveyHandler.java
  
  Index: SurveyHandler.java
  ===================================================================
  // ----------------------------------------------------------------------------
  // File: SurveyHandler.java
  // Copyright ( c ) 2001 eBuilt, Inc.  All rights reserved.
  // Version: $Revision: 1.1 $
  // Last Checked In: $Date: 2001/10/02 21:34:56 $
  // Last Checked In By: $Author: user57 $
  // ----------------------------------------------------------------------------
  
  package org.jboss.survey.command;
  
  import org.jboss.survey.ejb.entity.SurveyData;
  import org.jboss.survey.ejb.entity.UserData;
  import org.jboss.survey.exception.ServiceUnavailableException;
  import org.jboss.survey.exception.InvalidValueException;
  import org.jboss.survey.ejb.session.SurveyManagement;
  import org.jboss.survey.ejb.session.SurveyManagementHome;
  
  import java.util.Collection;
  import java.rmi.RemoteException;
  
  import javax.ejb.CreateException;
  import javax.ejb.FinderException;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  
  /**
   * Is the glue between the client/JSP and the business rules managing
   * EJBs. It also delivers the rights Value Objects on requests.
   *
   * @author Andreas Schaefer ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   **/
  public class SurveyHandler {
  
     // -------------------------------------------------------------------------
     // Static
     // -------------------------------------------------------------------------
  
     // -------------------------------------------------------------------------
     // Members 
     // -------------------------------------------------------------------------  
  
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
         
     /**
      * Default (no-args) constructor
      **/
     public SurveyHandler() {
     }
  
     // -------------------------------------------------------------------------
     // Methods
     // -------------------------------------------------------------------------  
  
     /**
      * Returns the requested Survey
      *
      * @param pSurveyId Id of the requested Survey
      *
      * @return Survey Value Object
      *
      * @throws InvalidValueException If the requested Survey could not be found
      * @throws ServiceUnavailable If the service is unaccessible or unusable
      **/
     public SurveyData getSurvey( int pSurveyId )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.getSurvey( pSurveyId );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
  
     /**
     * Returns the all the available Surveys
     *
     * @return Survey Value Object List
     *
     * @throws ServiceUnavailable If the service is unaccessible or unusable
     **/
     public Collection getSurveys()
        throws
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.getSurveys();
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
     
     /**
      * Saves the given Survey (either create or edit the existing one)
      *
      * @param pSurvey Survey Value Object containing the Survey Information
      *
      * @return Updated Survey Data
      *
      * @throws InvalidValueException If the given Survey content is invalid
      * @throws ServiceUnavailable If the service is unaccessible or unusable
      **/
     public SurveyData saveSurvey( SurveyData pSurvey )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.saveSurvey( pSurvey );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
  
     /**
      * Removes the given Survey
      *
      * @param pSurveyId Survey ID of the Survey to be delete
      *
      * @throws InvalidValueException If the given Survey ID is not valid or Survey 
not found
      * @throws ServiceUnavailable If the service is unaccessible or unusable
      **/
     public void removeSurvey( int pSurveyId )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           aBean.removeSurvey( pSurveyId );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
  
     /**
      * Returns the requested User
      *
      * @param pUserId Id of the requested User
      *
      * @return User Value Object
      *
      * @throws InvalidValueException If the requested User could not be found
      * @throws ServiceUnavailable If the service is unaccessible or unusable
      **/
     public UserData getUser( int pUserId )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.getUser( pUserId );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
     
     /**
     * Returns the requested User
     *
     * @param pEmail Email address of the user
     * @param pPassword Password of the user
     *
     * @return User Value Object
     *
     * @throws InvalidValueException If the requested User could not be found
     * @throws ServiceUnavailable If the service is unaccessible or unusable
     **/
     public UserData getUser( String pEmail, String pPassword )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.getUser( pEmail, pPassword );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
     
     /**
     * Returns a list of Users according to the given Search Criteria
     *
     * @param pSupportCriteria
     * @param pSizeCriteria
     * @param pTypeCriteria
     *
     * @return List of found users which can be empty but never null
     *
     * @throws InvalidValueException If the requested User could not be found
     * @throws ServiceUnavailable If the service is unaccessible or unusable
     **/
     public Collection getUsers( int pSupportCriteria, int pSizeCriteria, int 
pTypeCriteria )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.getUsers( pSupportCriteria, pSizeCriteria, pTypeCriteria );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
     
     /**
     * Saves the given User (either create or edit the existing one)
     *
     * @param pUser User Value Object containing the User Information
     *
     * @return Updated User Data
     *
     * @throws InvalidValueException If the given User content is invalid
     * @throws ServiceUnavailable If the service is unaccessible or unusable
     **/
     public UserData saveUser( UserData pUser )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           return aBean.saveUser( pUser );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
  
     /**
      * Removes the given User
      *
      * @param pUserId User ID of the User to be delete
      *
      * @throws InvalidValueException If the given User ID is not valid or User not 
found
      * @throws ServiceUnavailable If the service is unaccessible or unusable
      **/
     public void removeUser( int pUserId )
        throws
           InvalidValueException,
           ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           aBean.removeUser( pUserId );
        }
        catch ( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
     }
     
     /**
     * Sends an email to the given User
     **/
     public void sendEmail(
        String pFromAddress,
        String pFromName,
        String pToAddress,
        String pSubject,
        String pEmail
     ) throws
        ServiceUnavailableException
     {
        try {
           SurveyManagement aBean = getSurveyManagementBean();
           aBean.sendEmail( pFromAddress, pFromName, pToAddress, pSubject, pEmail );
        }
        catch( RemoteException re ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + re.getMessage()
           );
        }
     }
  
     /**
      * Describes the instance and its content for debugging purpose
      *
      * @return Debugging information about the instance and its content
      **/
     public String toString() {
        return "SurveyHandler [ " + " ]";
     }
  
     /**
      * Checks if the given instance is the same (same address) as
      * this instance.
      *
      * @return The result from the super class equals() method
      **/
     public boolean equals( Object pTest ) {
        return super.equals( pTest );
     }
  
     /**
      * Returns the hashcode of this instance
      *
      * @return Hashcode of its super class
      **/
     public int hashCode() {
        return super.hashCode();
     }
  
     /**
      * Creates a SurveyManagement bean.
      *
      * @return Returns a SurveyManagement bean for use by the Survey handler.
      **/
     private SurveyManagement getSurveyManagementBean()
        throws ServiceUnavailableException
     {
        try {
           Context aJNDIContext = new InitialContext();
           Object aEJBRef = aJNDIContext.lookup( "ejb/jboss/survey/SurveyManagement" );
           SurveyManagementHome aHome = (SurveyManagementHome) 
              PortableRemoteObject.narrow( aEJBRef, SurveyManagementHome.class );
  
           return aHome.create();
        }
        catch( NamingException pNE ) {
           pNE.printStackTrace();
           throw new ServiceUnavailableException( 
              "JNDI lookup failed: " + pNE.getMessage() 
           );
        }
        catch( RemoteException pRE ) {
           throw new ServiceUnavailableException(
              "Remote communication error: " + pRE.getMessage()
           );
        }
        catch( CreateException pCE ) {
           throw new ServiceUnavailableException(
              "Problem creating content management session bean: " + pCE.getMessage()
           );
        }
     }
  }
  
  // ----------------------------------------------------------------------------
  // EOF
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to