Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gateway/EditGateway.java


1   /*
2    * EditGateway.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:29 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gateway;
12  
13  import com.flexstor.common.data.ActionData;
14  import com.flexstor.common.exceptions.ejb.EjbException;
15  import com.flexstor.common.exceptions.ejb.edit.EditException;
16  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18  import com.flexstor.ejb.EjbObject;
19  import com.flexstor.ejb.edit.persist.EditPersist;
20  import com.flexstor.ejb.edit.persist.EditPersistHome;
21  
22  /**
23   * EditGateway provides functionality to send edits requests to the EJB server.
24   *
25   * @author  Jose Hernandez
26   * @version 3.0
27   */
28  public class EditGateway
29     extends Gateway
30  {
31     // MKS macro expander
32     public final static String IDENTIFIER = "$Id: EditGateway.java,v 1.2 2003/08/11 02:22:29 aleric Exp $";
33  
34     /** Bean reference. */
35     private EditPersist bean;
36     
37     /**
38      * Retrieves the Home interface name for this bean. 
39      */
40     protected String getHomeName()
41     {
42        return EDIT_PERSIST_HOME;
43     }
44      
45     /**
46      * Retrieves the bean object. 
47      */
48     protected EjbObject getBeanObject()
49     {
50        return bean;
51     }
52  
53     /**
54      * Stablishes the connection to the bean.
55      */
56     private void connect()
57        throws Exception
58     {
59        GatewayDebugOutput.println( 3, "Getting EditPersist object." );
60  
61        bean = ( (EditPersistHome)getHome() ).create();
62     }
63  
64     /**
65      * Applies specified edits.
66      */
67     public long applyEdits( ActionData data )
68        throws TransactionFailedException, EditException
69     {
70        try
71        {
72           GatewayDebugOutput.println( 3, "Applying edits." );
73  
74           connect();
75  
76           return bean.applyEdits( data );
77        }
78        // catch EJB processing exceptions
79        catch ( EjbException e )
80        {
81           // build a TransactionFailedException
82           throw buildException( e, "Applying Edits", IDENTIFIER );
83        }
84        // catch Edit validation exceptions
85        catch ( EditException e )
86        {
87           // re-throw exception
88           throw e;
89        }
90        // catch any other exception
91        catch ( Throwable e )
92        {
93           // build a TransactionFailedException
94           throw buildException( e, "Applying Edits", IDENTIFIER );
95        }
96        finally
97        {
98           dispose();
99        }
100    }
101 
102 } // end of class