Source code: com/virtuosotechnologies/asaph/modelutils/ModelUtilsPlugin.java
1 /*
2 ================================================================================
3
4 FILE: ModelUtilsPlugin.java
5
6 PROJECT:
7
8 Asaph
9
10 CONTENTS:
11
12 Plugin for model utilities
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.modelutils;
43
44
45 import java.util.logging.Logger;
46
47 import com.virtuosotechnologies.lib.plugin.PluginInitializer;
48 import com.virtuosotechnologies.lib.plugin.PluginInitializerException;
49 import com.virtuosotechnologies.lib.plugin.PluginLinker;
50
51 import com.virtuosotechnologies.asaph.notationmanager.NotationManager;
52
53
54 /**
55 * Plugin for model utilities
56 */
57 public class ModelUtilsPlugin
58 implements PluginInitializer
59 {
60 private Logger logger_;
61
62 private SongUtilsImpl songUtils_;
63 private DataTransferUtilsImpl dataTransferUtils_;
64
65
66 /**
67 * Constructor
68 */
69 public ModelUtilsPlugin()
70 {
71 logger_ = Logger.getLogger("com.virtuosotechnologies.asaph.modelutils");
72 logger_.fine("Starting ModelUtils");
73 }
74
75
76 /**
77 * Perform first initialization of the plugin. This is called after the plugin
78 * is instantiated, but before it is asked to provide any of its API implementations.
79 * Any APIs the plugin declared it needed for initialization will be available
80 * through the linker when this method is called.
81 * <p>
82 * Plugins should perform any time-consuming initialization in this method, rather
83 * than in the constructor or static initializers, and should use this method to
84 * report any fatal errors during initialization.
85 *
86 * @param linker the linker for this plugin.
87 * @exception PluginInitializerException thrown if the plugin could not
88 * initialize itself.
89 */
90 public void initialize(
91 PluginLinker linker)
92 throws
93 PluginInitializerException
94 {
95 NotationManager notationManager =
96 (NotationManager)linker.getAPI(NotationManager.API_NAME).getImplementation();
97 songUtils_ = new SongUtilsImpl(notationManager);
98 dataTransferUtils_ = new DataTransferUtilsImpl(notationManager);
99 songUtils_.setDataTransferUtils(dataTransferUtils_);
100 dataTransferUtils_.setSongUtils(songUtils_);
101 }
102
103
104 /**
105 * A plugin must implement this method to provide the implementations of the APIs
106 * that it provides. This method is called after the initialize() method.
107 * Any APIs the plugin declared it needed in to implement this API will be available
108 * through the linker when this method is called.
109 * <p>
110 * Plugins should perform any time-consuming initialization in this method, rather
111 * than in the constructor or static initializers, and should use this method to
112 * report any fatal errors during initialization.
113 *
114 * @param apiName the name of the API to implement
115 * @param linker the linker for this plugin.
116 * @return an object implementing the API.
117 * @exception PluginInitializerException thrown if the plugin could not implement the API.
118 */
119 public Object getAPIImplementation(
120 String apiName,
121 PluginLinker linker)
122 throws
123 PluginInitializerException
124 {
125 if (apiName.equals(SongUtils.API_NAME))
126 {
127 return songUtils_;
128 }
129 else if (apiName.equals(DataTransferUtils.API_NAME))
130 {
131 return dataTransferUtils_;
132 }
133 throw new PluginInitializerException("Unknown API: "+apiName);
134 }
135 }