View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: AbstractModelDataLoader.java
13   * Created: 2007-11-16
14   * Author: apohllo, entrop, bmilos
15   * $Id: BasePlugin.java 2232 2009-01-04 22:59:53Z apohllo $
16   */
17  
18  package pl.edu.agh.cast.model.base;
19  
20  import org.apache.log4j.ConsoleAppender;
21  import org.apache.log4j.Level;
22  import org.apache.log4j.Logger;
23  import org.apache.log4j.PatternLayout;
24  import org.eclipse.core.runtime.IConfigurationElement;
25  import org.eclipse.core.runtime.Platform;
26  import org.eclipse.ui.plugin.AbstractUIPlugin;
27  import org.osgi.framework.BundleContext;
28  
29  /**
30   *
31   * The activator class controls the plug-in life cycle.
32   *
33   * @author AGH CAST Team
34   */
35  public class BasePlugin extends AbstractUIPlugin {
36  
37  	/**
38  	 * The plug-in ID.
39  	 */
40  	public static final String PLUGIN_ID = "pl.edu.agh.cast.base"; //$NON-NLS-1$
41  
42  	/**
43  	 * Model extension point id.
44  	 */
45  	public static final String MODEL_EXTENSION_ID = "pl.edu.agh.cast.model"; //$NON-NLS-1$
46  
47  	/**
48  	 * Abstract model extension id.
49  	 */
50  	public static final String ABSTRACT_MODEL_ID = "pl.edu.agh.cast.model.base"; //$NON-NLS-1$
51  
52  	/**
53  	 * Column node in the model exsd (extension point definition file).
54  	 */
55  	public static final String COLUMN = "column"; //$NON-NLS-1$
56  
57  	/**
58  	 * Column default value attribute in the model exsd.
59  	 */
60  	public static final String COLUMN_DEFAULTVALUE = "defaultvalue"; //$NON-NLS-1$
61  
62  	/**
63  	 * Column model index attribute in the model exsd.
64  	 */
65  	public static final String COLUMN_MODEL_INDEX = "modelIndex"; //$NON-NLS-1$
66  
67  	/**
68  	 * Column name attribute in the model exsd.
69  	 */
70  	public static final String COLUMN_NAME = "name"; //$NON-NLS-1$
71  
72  	/**
73  	 * Column use attribute in the model exsd.
74  	 */
75  	public static final String COLUMN_USE = "use"; //$NON-NLS-1$
76  
77  	/**
78  	 * Column id attribute in the model exsd.
79  	 */
80  	public static final String COLUMN_ID = "id"; //$NON-NLS-1$
81  
82  	/**
83  	 * Column type attribute in the model exsd.
84  	 */
85  	public static final String COLUMN_TYPE = "type"; //$NON-NLS-1$
86  
87  	/**
88  	 * Parameter node in the model exsd.
89  	 */
90  	public static final String PARAMETER = "parameter"; //$NON-NLS-1$
91  
92  	/**
93  	 * Parameter id attribute in the model exsd.
94  	 */
95  	public static final String PARAMETER_ID = "id"; //$NON-NLS-1$
96  
97  	/**
98  	 * Parameter name attribute in the model exsd.
99  	 */
100 	public static final String PARAMETER_NAME = "name"; //$NON-NLS-1$
101 
102 	/**
103 	 * Loader node in the model exsd.
104 	 */
105 	public static final String LOADER = "loader"; //$NON-NLS-1$
106 
107 	/**
108 	 * Model name attribute in the model exsd.
109 	 */
110 	public static final String MODEL_NAME = "name"; //$NON-NLS-1$
111 
112 	/**
113 	 * Model id attribute in the model exsd.
114 	 */
115 	public static final String MODEL_ID = "id"; //$NON-NLS-1$
116 
117 	/**
118 	 * Column required value in the model exsd.
119 	 */
120 	public static final String COLUMN_REQUIRED = "required"; //$NON-NLS-1$
121 
122 	/**
123 	 * Column optional value in the model exsd.
124 	 */
125 	public static final String COLUMN_OPTIONAL = "optional"; //$NON-NLS-1$
126 
127 	/**
128 	 * Column type string value in the model exsd.
129 	 */
130 	public static final String COLUMN_TYPE_STRING = "String"; //$NON-NLS-1$
131 
132 	/**
133 	 * Column type long value in the model exsd.
134 	 */
135 	public static final String COLUMN_TYPE_LONG = "Long"; //$NON-NLS-1$
136 
137 	/**
138 	 * Column type double value in the model exsd.
139 	 */
140 	public static final String COLUMN_TYPE_DOUBLE = "Double"; //$NON-NLS-1$
141 
142 	/**
143 	 * Column type date value in the model exsd.
144 	 */
145 	public static final String COLUMN_TYPE_DATE = "Date"; //$NON-NLS-1$
146 
147 	/**
148 	 * Column type boolean value in the model exsd.
149 	 */
150 	public static final String COLUMN_TYPE_BOOLEAN = "Boolean"; //$NON-NLS-1$
151 
152 	/**
153 	 * Type node in the model exsd.
154 	 */
155 	public static final String TYPE = "type"; //$NON-NLS-1$
156 
157 	/**
158 	 * Type id attribute in the model exsd.
159 	 */
160 	public static final String TYPE_ID = "id"; //$NON-NLS-1$
161 
162 	/**
163 	 * Attribute node in the model exsd.
164 	 */
165 	public static final String ATTRIBUTE = "attribute"; //$NON-NLS-1$
166 
167 	/**
168 	 * Attribute id attribute in the model exsd.
169 	 */
170 	public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
171 
172 	/**
173 	 * Attribute name attribute in the model exsd.
174 	 */
175 	public static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
176 
177 	/**
178 	 * Source attribute name for Relation and TimedRelation in the model exsd.
179 	 */
180 	public static final String SOURCE_ATTRIBUTE_NAME = "Source"; //$NON-NLS-1$
181 
182 	/**
183 	 * Target attribute name for Relation and TimedRelation in the model exsd.
184 	 */
185 	public static final String TARGET_ATTRIBUTE_NAME = "Target"; //$NON-NLS-1$
186 
187 	/**
188 	 * Date attribute name for Relation and TimedRelation in the model exsd.
189 	 */
190 	public static final String DATE_ATTRIBUTE_NAME = "Date"; //$NON-NLS-1$
191 
192 	// The shared instance
193 	private static BasePlugin plugin;
194 
195 	// Plug-in logger
196 	private static volatile Logger log;
197 
198 	private static Object lock = new Object();
199 
200 	/**
201 	 * The default constructor.
202 	 */
203 	public BasePlugin() {
204 	}
205 
206 	/**
207 	 *
208 	 * {@inheritDoc}
209 	 *
210 	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
211 	 */
212 	@Override
213 	public void start(BundleContext context) throws Exception {
214 		super.start(context);
215 		plugin = this;
216 	}
217 
218 	/**
219 	 *
220 	 * {@inheritDoc}
221 	 *
222 	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
223 	 */
224 	@Override
225 	public void stop(BundleContext context) throws Exception {
226 		plugin = null;
227 		super.stop(context);
228 	}
229 
230 	/**
231 	 * Returns the shared instance.
232 	 *
233 	 * @return the shared instance
234 	 */
235 	public static BasePlugin getDefault() {
236 		return plugin;
237 	}
238 
239 	/**
240 	 * The default logger of the plug-in.
241 	 *
242 	 * @return The plug-in logger.
243 	 */
244 	public static Logger getLogger() {
245 		if (log == null) {
246 			synchronized (lock) {
247 				log = Logger.getLogger(BasePlugin.class);
248 				if (!log.getAllAppenders().hasMoreElements()) {
249 					// add default console appender
250 					log.addAppender(new ConsoleAppender(new PatternLayout("%c: %5p [%t] (%F:%L) - %m%n "))); //$NON-NLS-1$
251 					log.setLevel(Level.INFO);
252 				}
253 			}
254 		}
255 		return log;
256 	}
257 
258 	/**
259 	 * Returns configurations (extensions description) for all models - extension point pl.edu.agh.cast.model .
260 	 *
261 	 * @return Array of configurations.
262 	 */
263 	public static IConfigurationElement[] getModelConfigurations() {
264 		return Platform.getExtensionRegistry().getConfigurationElementsFor(MODEL_EXTENSION_ID);
265 	}
266 
267 }