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

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/xmldatabase/XMLDatabasePlugin.java


1   /*
2   ================================================================================
3   
4     FILE:  XMLDatabasePlugin.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      Plugin that provides the XML database implementations
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.xmldatabase;
43  
44  
45  import java.io.IOException;
46  
47  import com.virtuosotechnologies.lib.plugin.PluginInitializer;
48  import com.virtuosotechnologies.lib.plugin.PluginLinker;
49  import com.virtuosotechnologies.lib.plugin.PluginInitializerException;
50  import com.virtuosotechnologies.lib.plugin.APIProvider;
51  
52  import com.virtuosotechnologies.asaph.maingui.CommandManager;
53  import com.virtuosotechnologies.asaph.maingui.DatabaseManager;
54  import com.virtuosotechnologies.asaph.maingui.GuiEnvironmentManager;
55  import com.virtuosotechnologies.asaph.maingui.PaneManager;
56  import com.virtuosotechnologies.asaph.maingui.SelectionManager;
57  import com.virtuosotechnologies.asaph.maingui.DuplicateConnectorException;
58  import com.virtuosotechnologies.asaph.modelutils.SongUtils;
59  import com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory;
60  
61  
62  /**
63   * Plugin that provides the XML database implementations
64   */
65  public class XMLDatabasePlugin
66  implements PluginInitializer
67  {
68    private IndexedDatabaseFactoryImpl indexedDatabaseFactory_;
69    private XMLDatabaseGui xmlDatabaseGui_;
70    
71    
72    /**
73     * Perform first initialization of the plugin. This is called after the plugin
74     * is instantiated, but before it is asked to provide any of its API implementations.
75     * Any APIs the plugin declared it needed for initialization will be available
76     * through the linker when this method is called.
77     * <p>
78     * Plugins should perform any time-consuming initialization in this method, rather
79     * than in the constructor or static initializers, and should use this method to
80     * report any fatal errors during initialization.
81     *
82     * @param linker the linker for this plugin.
83     * @exception PluginInitializerException thrown if the plugin could not
84     *    initialize itself.
85     */
86    public void initialize(
87      PluginLinker linker)
88    throws
89      PluginInitializerException
90    {
91      CommandManager commandManager = null;
92      DatabaseManager databaseManager = null;
93      GuiEnvironmentManager guiEnvironmentManager = null;
94      PaneManager paneManager = null;
95      SelectionManager selectionManager = null;
96      APIProvider api;
97      if ((api = linker.getAPI(CommandManager.API_NAME)) != null)
98      {
99        commandManager = (CommandManager)api.getImplementation();
100     }
101     if ((api = linker.getAPI(DatabaseManager.API_NAME)) != null)
102     {
103       databaseManager = (DatabaseManager)api.getImplementation();
104     }
105     if ((api = linker.getAPI(GuiEnvironmentManager.API_NAME)) != null)
106     {
107       guiEnvironmentManager = (GuiEnvironmentManager)api.getImplementation();
108     }
109     if ((api = linker.getAPI(PaneManager.API_NAME)) != null)
110     {
111       paneManager = (PaneManager)api.getImplementation();
112     }
113     if ((api = linker.getAPI(SelectionManager.API_NAME)) != null)
114     {
115       selectionManager = (SelectionManager)api.getImplementation();
116     }
117     SongUtils songUtils = (SongUtils)
118       linker.getAPI(SongUtils.API_NAME).getImplementation();
119     StandardModelFactory modelFactory = (StandardModelFactory)
120       linker.getAPI(StandardModelFactory.API_NAME).getImplementation();
121     
122     try
123     {
124       indexedDatabaseFactory_ = new IndexedDatabaseFactoryImpl(
125         songUtils, modelFactory);
126       if (commandManager != null && databaseManager != null &&
127         guiEnvironmentManager != null && paneManager != null &&
128         selectionManager != null)
129       {
130         xmlDatabaseGui_ = new XMLDatabaseGui(commandManager, databaseManager,
131           guiEnvironmentManager, paneManager, selectionManager, modelFactory,
132           indexedDatabaseFactory_);
133       }
134     }
135     catch (IOException ex)
136     {
137       throw new PluginInitializerException(ex);
138     }
139     catch (DuplicateConnectorException ex)
140     {
141       throw new PluginInitializerException(ex);
142     }
143   }
144   
145   
146   /**
147    * A plugin must implement this method to provide the implementations of the APIs
148    * that it provides. This method is called after the initialize() method.
149    * Any APIs the plugin declared it needed in to implement this API will be available
150    * through the linker when this method is called.
151    * <p>
152    * Plugins should perform any time-consuming initialization in this method, rather
153    * than in the constructor or static initializers, and should use this method to
154    * report any fatal errors during initialization.
155    *
156    * @param apiName the name of the API to implement
157    * @param linker the linker for this plugin.
158    * @return an object implementing the API.
159    * @exception PluginInitializerException thrown if the plugin could not implement the API.
160    */
161   public Object getAPIImplementation(
162     String apiName,
163     PluginLinker linker)
164   throws
165     PluginInitializerException
166   {
167     if (apiName.equals(IndexedDatabaseFactory.API_NAME))
168     {
169       return indexedDatabaseFactory_;
170     }
171     else
172     {
173       throw new PluginInitializerException();
174     }
175   }
176 }