package plugin11g;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import oracle.AWXML.AW;
import oracle.olap.awm.plugin.AWMPlugin;
import oracle.olapi.metadata.mdm.MdmBaseMeasure;
import oracle.olapi.metadata.mdm.MdmDerivedMeasure;
import oracle.olapi.metadata.mdm.MdmMetadataProvider;
import oracle.olapi.metadata.mdm.MdmObject;

/**
 * An implementation of the AWMPlugin interface that displays the XML
 * representation of an Oracle OLAP measure object.
 * Analytic Workspace Manager calls the methods of the plug-in and passes the
 * methods the following objects.
 *
 * - For the conn parameter, it passes a java.sql.Connection object that
 *   represents the current connection of the Analytic Workspace Manager
 *   to the Oracle Database instance.
 * - For the type parameter, it passes a String that is a type classification
 *   that Analytic Workspace Manager assigns to the metadata object.
 * - For the obj parameter, it passes An Oracle OLAP metadata object, a
 *   String, or null.
 * - For the aw parameter, in a 10.2.0.3 session, it passes an AWXML.AW
 *   object.
 *   In an 11g session, it passes null as the value of this parameter.
 * - For the params parameter, in a 10.2.0.3 session it passes null.
 *   In an 11g session, it passes a Map. The Map has two key/object pairs:
 *   o The String "DATASOURCE" is the key for a java.sql.DataSource object.
 *   o The String "DATAPROVIDER" is the key for an
 *     oracle.olapi.metadata.mdm.MdmMetadataProvider object.
 *
 * As the parent parameter of the handle method, Analytic Workspace Manager
 * passes a Frame that the plug-in can use as the parent Frame for graphical
 * user interface components.
 *
 * This example plug-in uses metadata objects from the Oracle OLAP Java API,
 * 11g Release (11.1).
 * It is compatible with the Analytic Workspace Manager in that release.
 *
 * For compatibility with the  10g release of Analytic Workspace Manager,
 * the AWMPlugin interface has an AW object from the Oracle OLAP Analytic
 * Workspace Java API.
 * To compile this plug-in, you must include the following JAR files in
 * your classpath:
 *
 * - olap_api.jar which contains the classes in the Oracle OLAP Java API.
 * - awxml.jar, which contains the classes in the Oracle OLAP Analytic
 *   Workspace Java API.
 * - awmplugin.jar, which contains the AWMPlugin interface.
 *
 * The olap_api.jar and awxml.jar files are located in the /olap/api/lib
 * directory under the ORACLE_HOME directory in an Oracle Database installation.
 *
 * The awmplugin.jar file is available from the Oracle Technology Network (OTN)
 * Web site at http://www.oracle.com/technology/products/bi/olap/index.html.
 */
public class ViewXMLPluginExample implements AWMPlugin
{
  /**
   * Creates a new ViewXMLPluginExample object.
   */
  public ViewXMLPluginExample()
  {
  }

  /**
   * Specifies the metadata objects that are supported by the plug-in.
   * This example supports MdmBaseMeasure and MdmDerivedMeasure objects,
   * which are owned by an MdmCube.
   * In Analytic Workspace Manager, an MdmDerivedMeasure is a calculated
   * measure.
   *
   * @param conn The Connection to an Oracle Database instance.
   * @param type A String that designates a type assigned by Analytic Workspace
   *             Manager.
   * @param obj An Oracle OLAP Java API metadata object, a String that Analytic
   *            Workspace Manager associates with the selected navigation tree
   *            object, or null.
   * @param aw For a 10g session, the current analytic workspace.
   *           For an 11g session, null.
   * @param params A Map that contains an MdmMetadataProvider and a
   *               DataSource.
   *
   * @return A boolean that is true if Analytic Workspace Manager should display
   *         the plug-in on the menu for the selected object or false if it
   *         should not.
   */
  public boolean isSupported(Connection conn, String type, Object obj, AW aw,
                             Map params)
  {
    // Support MdmBaseMeasure and MdmDerivedMeasure objects.
    if (obj instanceof MdmBaseMeasure || obj instanceof MdmDerivedMeasure)
    {
      return true;
    }
    return false;
  }

  /**
   * Gets the text to display for the plug-in on the right-click menu of the
   * selected object in the navigation tree.
   *
   * @param conn The Connection to an Oracle Database instance.
   * @param type A String that designates a type assigned by Analytic Workspace
   *             Manager.
   * @param obj An Oracle OLAP Java API metadata object, a String that Analytic
   *            Workspace Manager associates with the selected navigation tree
   *            object, or null.
   * @param aw For an 11g session, Analytic Workspace Manager passes null
   *           for this parameter.
   * @param params A Map that contains an MdmMetadataProvider and a
   *               DataSource.
   *
   * @return A String that contains text that Analytic Workspace Manager
   *         displays on the right-click menu for a metadata object.
   */
  public String getMenu(Connection conn, String type, Object obj, AW aw,
                        Map params)
  {
    // Text to display on the right-click menu.
    String menu = "View XML Example Plug-in";
    return menu;
  }

  /**
   * Performs the actions of the plug-in.
   * In this example, if the obj object is an OLAP metadata object,
   * this method gets the MdmMedataProvider for the session, gets the
   * the XML representation of the object, and then displays the XML.
   *
   * @param parent A Frame that the plug-in can use as the parent for a
   *               graphical user interface.
   * @param conn The Connection to an Oracle Database instance.
   * @param type A String that designates a type assigned by Analytic Workspace
   *             Manager.
   * @param obj An Oracle OLAP Java API metadata object, a String that Analytic
   *            Workspace Manager associates with the selected navigation tree
   *            object, or null.
   * @param aw For an 11g session, Analytic Workspace Manager passes null
   *           for this parameter.
   * @param params A Map that contains an MdmMetadataProvider and a
   *               DataSource.
   *
   */
  public void handle(Frame parent, Connection conn, String type, Object obj,
                     AW aw, Map params)
  {
    // Get the MdmMetadataProvider to use in exporting the XML.
    if (obj instanceof MdmObject)
    {
      Object objdp = params.get("DATAPROVIDER");
      if (objdp != null)
      {
        MdmObject mobj = (MdmObject)obj;
        MdmMetadataProvider mdp = (MdmMetadataProvider)objdp;

        // Get the XML representation of the MdmObject.
        List objects = new ArrayList();
        objects.add(mobj);
        Map renameMap = null;
        boolean includeOwnerString = true;
        String title = "XML for " + mobj.getName();
        try
        {
          String xml =
            mdp.exportFullXML(objects, renameMap, includeOwnerString);
          // Create a dialog box and display the XML.
          DisplayXMLDialog dxd = new DisplayXMLDialog(parent, title, true, xml);
          dxd.setVisible(true);
        }
        catch (IOException ie)
        {
          //Ignore error.
        }
      }
    }
  }

  /**
   * Specifies whether or not to refresh the navigation tree of Analytic
   * Workspace Manager.
   * If a plug-in creates new Oracle OLAP metadata objects, this method should
   * return true.
   *
   * @param conn The Connection to an Oracle Database instance.
   * @param type A String that designates a type assigned by Analytic Workspace
   *             Manager.
   * @param obj An Oracle OLAP Java API metadata object, a String that Analytic
   *            Workspace Manager associates with the selected navigation tree
   *            object, or null.
   * @param aw For an 11g session, Analytic Workspace Manager passes null
   *           for this parameter.
   * @param params A Map that contains an MdmMetadataProvider and a
   *               DataSource.
   *
   * @return A boolean that is true to have Analytic Workspace Manager refresh
   *         the navigation tree, or false otherwise.
   */
  public boolean refreshTree(Connection conn, String type, Object obj, AW aw,
                             Map params)
  {
    // This example does not create new metadata objects, so return false.
    return false;
  }


  /**
   * An inner class that creates a dialog box that displays the XML.
   */
  class DisplayXMLDialog extends JDialog implements ActionListener
  {
    /**
     * Creates a DisplayXMLDialog for displaying the contents of the xml
     * parameter.
     *
     * @param parent A Frame that is provided by Analytic Workspace Manager.
     * @param title A String that contains text to use as the title for the
     *              dialog box.
     * @param modal A boolean that specifies whether or not the dialog box is
     *              modal.
     * @param xml A String that contains the XML to display.
     */
    public DisplayXMLDialog(Frame parent, String title, boolean modal,
                            String xml)
    {
      setLocation(200, 200);
      setTitle(title);
      setModal(modal);

      try
      {
        displayXML(xml);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }

    /**
     * Creates a dialog box and displays the contents of a String.
     *
     * @param xml A String that contains the XML to display.
     */
    private void displayXML(String xml)
    {
      JTextArea ta = new JTextArea(xml);
      ta.setEditable(false);
      Font of = ta.getFont();
      Font f = new Font("Courier New", of.getStyle(), of.getSize());
      ta.setFont(f);

      JScrollPane p = new JScrollPane();
      p.getViewport().add(ta);

      JPanel buttonPane = new JPanel();
      JButton button = new JButton("Close");
      buttonPane.add(button);
      button.addActionListener(this);
      getContentPane().add(buttonPane, BorderLayout.SOUTH);

      getContentPane().add(p, BorderLayout.NORTH);
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      pack();
      setVisible(true);
    }

    /**
     * Performs an action for the Close button.
     *
     * @param e An ActionEvent for the Close button.
     */
    public void actionPerformed(ActionEvent e)
    {
      setVisible(false);
      dispose();
    }
  }
}
Left Curve
Popular Downloads
Right Curve
Untitled Document
Left Curve
More Database Downloads
Right Curve