Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

BackendObject.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.objects;
00026 
00027 import java.awt.Color;
00028 import java.awt.datatransfer.DataFlavor;
00029 import java.awt.datatransfer.Transferable;
00030 import java.awt.datatransfer.UnsupportedFlavorException;
00031 import java.awt.dnd.DnDConstants;
00032 import java.awt.dnd.DragSource;
00033 import java.io.IOException;
00034 
00035 import javax.management.InstanceNotFoundException;
00036 import javax.swing.SwingConstants;
00037 
00038 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean;
00039 import org.objectweb.cjdbc.console.gui.CjdbcGui;
00040 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00041 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
00042 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener;
00043 import org.objectweb.cjdbc.console.gui.popups.BackendPopUpMenu;
00044 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00045 
00046 /**
00047  * This class defines a BackendObject
00048  * 
00049  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00050  * @version 1.0
00051  */
00052 public class BackendObject extends AbstractGuiObject
00053     implements
00054       Transferable,
00055       Cloneable
00056 
00057 {
00058   private String               backendState;
00059   private String               database;
00060   private String               controllerName;
00061   private DatabaseBackendMBean mbean;
00062   private String               user;
00063   private String               password;
00064   private CjdbcGui             gui;
00065   private RmiJmxClient         jmxClient;
00066   private BackendPopUpMenu menu;
00067 
00068   /**
00069    * Access the mbean from this bob object
00070    * 
00071    * @return <code>DatabaseBackendMBean</code> instance
00072    * @throws InstanceNotFoundException if fails
00073    * @throws IOException if fails
00074    */
00075   public DatabaseBackendMBean getMbean() throws InstanceNotFoundException,
00076       IOException
00077   {
00078     jmxClient = (RmiJmxClient) gui.getJmxClients().get(controllerName);
00079     user = gui.getGuiSession().getAuthenticatedDatabaseLogin(database);
00080     password = gui.getGuiSession().getAuthenticatedDatabasePassword(database);
00081     mbean = jmxClient.getDatabaseBackendProxy(database, getName(), user,
00082         password);
00083     return mbean;
00084   }
00085 
00086   /**
00087    * Creates a new <code>BackendObject.java</code> object
00088    * 
00089    * @param gui we are attached to
00090    * @param database the virtual database this backends belongs to
00091    * @param name the name of the backend of this backend object
00092    * @param listener backend transfer listener for DnD
00093    * @param controllerName the owner of this backend
00094    * @throws IOException if cannot access MBean
00095    * @throws InstanceNotFoundException if cannot locate MBean
00096    */
00097   public BackendObject(CjdbcGui gui, BackendTransferListener listener,
00098       String database, String name, String controllerName)
00099       throws InstanceNotFoundException, IOException
00100   {
00101     super();
00102     this.database = database;
00103     this.controllerName = controllerName;
00104     this.gui = gui;
00105     setText(name);
00106     setName(name);
00107     this.menu = new BackendPopUpMenu(gui, this);
00108     setBackground(Color.white);
00109     setVerticalTextPosition(SwingConstants.BOTTOM);
00110 
00111     getMbean();
00112 
00113     addMouseMotionListener(listener);
00114     addMouseListener(listener);
00115     addMouseListener(menu);
00116 
00117     DragSource dragSource = DragSource.getDefaultDragSource();
00118     dragSource.createDefaultDragGestureRecognizer(this, // What component
00119         DnDConstants.ACTION_COPY_OR_MOVE, // What drag types?
00120         listener);// the listener
00121   }
00122 
00123   /**
00124    * Get the state of the backend
00125    * 
00126    * @return state of backend as defined in gui constants , null if unknown
00127    */
00128   public String getState()
00129   {
00130     return backendState;
00131   }
00132 
00133   /**
00134    * Set state of backend
00135    * 
00136    * @param state string description of the state
00137    */
00138   public void setState(String state)
00139   {
00140     this.backendState = state;
00141     if (state.equals(GuiConstants.BACKEND_STATE_ENABLED))
00142     {
00143       setIcon(GuiIcons.BACKEND_ENABLED_ICON);
00144       menu.setEnabled(true);
00145       menu.getBackendCheckpoint().setEnabled(false);
00146       menu.getBackendCreate().setEnabled(true);
00147       menu.getBackendRemove().setEnabled(false);
00148       
00149       menu.getBackendEnable().setEnabled(false);
00150       menu.getBackendDisable().setEnabled(true);
00151       menu.getBackendBackup().setEnabled(true);
00152       menu.getBackendRestore().setEnabled(false);
00153     }
00154     else if (state.equals(GuiConstants.BACKEND_STATE_DISABLED))
00155     {
00156       setIcon(GuiIcons.BACKEND_DISABLED_ICON);
00157       menu.getBackendCheckpoint().setEnabled(true);
00158       menu.getBackendCreate().setEnabled(true);
00159       menu.getBackendRemove().setEnabled(true);
00160       
00161       menu.getBackendEnable().setEnabled(true);
00162       menu.getBackendDisable().setEnabled(false);
00163       menu.getBackendBackup().setEnabled(true);
00164       menu.getBackendRestore().setEnabled(true);
00165     }
00166     else if (state.equals(GuiConstants.BACKEND_STATE_DISABLING))
00167     {
00168       setIcon(GuiIcons.BACKEND_DISABLING_ICON);
00169       menu.setEnabled(false);
00170     }
00171     else if (state.equals(GuiConstants.BACKEND_STATE_BACKUP))
00172     {
00173       setIcon(GuiIcons.BACKEND_BACKUP_ICON);
00174       menu.setEnabled(false);
00175     }
00176     else if (state.equals(GuiConstants.BACKEND_STATE_RESTORE))
00177     {
00178       setIcon(GuiIcons.BACKEND_RESTORE_ICON);
00179       menu.setEnabled(false);
00180     }
00181     else if (state.equals(GuiConstants.BACKEND_STATE_RECOVERY))
00182     {
00183       setIcon(GuiIcons.BACKEND_STATE_RECOVERY);
00184       menu.setEnabled(false);
00185     }
00186   }
00187 
00188   /**
00189    * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
00190    */
00191   public DataFlavor[] getTransferDataFlavors()
00192   {
00193     return new DataFlavor[]{DataFlavor.stringFlavor, DataFlavor.plainTextFlavor};
00194   }
00195 
00196   /**
00197    * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
00198    */
00199   public boolean isDataFlavorSupported(DataFlavor flavor)
00200   {
00201     if (flavor.equals(DataFlavor.stringFlavor)
00202         || flavor.equals(DataFlavor.plainTextFlavor))
00203       return true;
00204     else
00205       return false;
00206   }
00207 
00208   /**
00209    * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
00210    */
00211   public Object getTransferData(DataFlavor flavor)
00212       throws UnsupportedFlavorException, IOException
00213   {
00214     return this.getText();
00215   }
00216 
00217   /**
00218    * Returns the database value.
00219    * 
00220    * @return Returns the database.
00221    */
00222   public String getDatabase()
00223   {
00224     return database;
00225   }
00226 
00227   /**
00228    * Returns the controllerName value.
00229    * 
00230    * @return Returns the controllerName.
00231    */
00232   public String getControllerName()
00233   {
00234     return controllerName;
00235   }
00236 
00237   /**
00238    * Sets the controllerName value.
00239    * 
00240    * @param controllerName The controllerName to set.
00241    */
00242   public void setControllerName(String controllerName)
00243   {
00244     this.controllerName = controllerName;
00245   }
00246 
00247   /**
00248    * @see java.awt.Component#setName(java.lang.String)
00249    */
00250   public void setName(String name)
00251   {
00252     super.setName(name);
00253     setText(name);
00254   }
00255   /**
00256    * Returns the jmxClient value.
00257    * 
00258    * @return Returns the jmxClient.
00259    */
00260   public RmiJmxClient getJmxClient()
00261   {
00262     return jmxClient;
00263   }
00264 }

Generated on Mon Apr 11 22:01:29 2005 for C-JDBC by  doxygen 1.3.9.1