Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 208728 | Differences between
and this patch

Collapse All | Expand All

(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/GLAHelper.java (-501 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005,2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.internal.importer;
14
15
import java.io.File;
16
import java.lang.reflect.Constructor;
17
import java.lang.reflect.InvocationTargetException;
18
import java.lang.reflect.Method;
19
import java.net.MalformedURLException;
20
import java.net.URL;
21
import java.util.Locale;
22
import java.util.Map;
23
import java.util.StringTokenizer;
24
25
import org.eclipse.hyades.logging.adapter.impl.AdapterXMLConstants;
26
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
27
import org.eclipse.hyades.logging.adapter.util.Messages;
28
import org.eclipse.hyades.logging.parsers.LogParserException;
29
import org.eclipse.hyades.logging.parsers.ParserConstants;
30
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
31
32
/**
33
 * Helper class for finding the GLA adapter configuration file.
34
 * 
35
 * @author apnan
36
 *
37
 */
38
public class GLAHelper {
39
40
	protected static short platform = -1;//flag indicating whether the code runs in the workbench or outside the workbench
41
										// the values that this flag can have are:
42
										// -1: GLAHelper wasn't initialized
43
										// 0: GLAHelper runs outside the workbench
44
										// 1: GLAHelper runs in the workbench
45
	
46
	/**
47
	 * Get the adapter configuration file path.
48
	 * @param table the parser parameters hash stable
49
	 * @param nameSpace the plugin name if running in the workbench, null otherwise
50
	 * @param useOriginalAdapter boolean to indicate to use the original adapter file specification
51
	 * stored in the hash table with key originalAdapter
52
	 * @return the adapter file path. 
53
	 * @throws LogParserException
54
	 */
55
	public static synchronized String getAdapterPath(Map table, String nameSpace, boolean useOriginalAdapter) throws LogParserException{
56
		
57
		String key; 
58
		
59
		if (useOriginalAdapter) {
60
			key = LogParserConstants.ORIGINAL_ADAPTER_KEY;
61
		}
62
		else {
63
			key = getAdapterPathKey(table);
64
			if(key==null){
65
				String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)null); 
66
				throw new LogParserException(message);
67
			}
68
			if(GLADebug.INSTANCE.debug){
69
				GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: adapter key="+key);			
70
			}
71
		}
72
		
73
		String config_file = (String)table.get(key);
74
75
		//get the adapter config file path
76
		String adapterFilePath = "";
77
		
78
		if(config_file.indexOf("./")>-1){
79
			config_file = config_file.substring(2);			
80
		}
81
		
82
		/* If running in an eclipse workbench environment then try to get the adapter file
83
		 * path based on the plugin bundle.
84
		 */
85
		if(isWorkbenchMode()){
86
			try {
87
				// Bundle bundle = Platform.getBundle(nameSpace);
88
				Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
89
	            Method getBundle = platformClass.getMethod("getBundle", new Class[]{String.class});
90
	            Object bundle = getBundle.invoke(null, new String[]{nameSpace});
91
	            Class pathClass = Class.forName("org.eclipse.core.runtime.IPath");
92
	            Class bundleClass = Class.forName("org.osgi.framework.Bundle");
93
	            Method find = platformClass.getMethod("find", new Class[]{bundleClass, pathClass});
94
				
95
				if(bundle!=null){
96
					//verify if the adapter is NL enabled
97
					if(config_file.indexOf("/nl/")>-1){
98
						config_file = getNLAdapterPath(table, config_file, find, bundle);
99
						if(config_file==null){
100
							String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)table.get(key)); 
101
							throw new Exception(message);
102
						}
103
						adapterFilePath = config_file; 
104
					}else{				
105
						URL fileURL = find(find, bundle, config_file);
106
						if(fileURL==null){
107
							//config_file = "config/"+config_file;
108
							fileURL = find(find, bundle, "config/"+config_file);
109
						}
110
						if(fileURL!=null){
111
							adapterFilePath = fileURL.toString();
112
						}else{
113
							/* Try using the config file root from the hash table if Log Import Wizard modified the
114
							 * adapter with a filter. */
115
							adapterFilePath = (String) table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) + "/" + config_file;			
116
							File test = new File(adapterFilePath);
117
							if(!test.exists()){
118
								// Couldn't find adapter file so throw an exception
119
								throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file));
120
							}
121
						}
122
					}
123
				}else{
124
					adapterFilePath = config_file; 
125
				}
126
			}
127
			catch (Throwable e) {
128
				// Capture the exception in a LogParserException
129
				throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file),e);
130
			}
131
			
132
		}
133
		/* Else find the adapter file path based on path variables in the hash table */
134
		else{
135
			
136
			//verify if the adapter is NL enabled
137
			if(config_file.indexOf("/nl/")>-1){
138
				if(GLADebug.INSTANCE.debug){
139
					GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: trying to get the nl adapter file using base file "+config_file);			
140
				}
141
				config_file = getNLAdapterPath(table, config_file, null, null);
142
				if(config_file==null){
143
					String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)table.get(key)); 
144
					throw new LogParserException(message);
145
				}
146
				adapterFilePath = config_file; 
147
			}else{
148
				String adapterPath = (String)table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) ;
149
				
150
//				//check to see if the global properties are set
151
//				if (adapterPath == null){
152
//					adapterPath = CBEConfigurationProperties.instance().getProperties().getProperty(CBEConfigurationProperties.ADAPTER_LOCATION);
153
//				}
154
				adapterFilePath = adapterPath + "/" + config_file;
155
				if(GLADebug.INSTANCE.debug){
156
					GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file using ConfigFileRoot path eg. "+adapterFilePath);			
157
				}
158
				File test = new File(adapterFilePath);
159
				if(!test.exists()){
160
					adapterFilePath = adapterPath + "config/"+config_file;
161
					if(GLADebug.INSTANCE.debug){
162
						GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file using ConfigFileRoot path plus config eg. "+adapterFilePath);			
163
					}
164
					test = new File(adapterFilePath);
165
					if(!test.exists()){
166
						// last attempt 
167
						//
168
						// Bug 62317
169
						// Try to resolve the config file using the command line list of directories
170
						//
171
						String config_paths = (String)table.get(LogParserConstants.CONFIG_PATH_KEY); // get the paths containing the adapter files
172
173
						// Check to ensure config_path was set in the input table
174
						// If it is not then throw an appropriate exception.
175
						if (config_paths != null && config_paths.length() != 0) {
176
							StringTokenizer strtok = new StringTokenizer(config_paths, File.pathSeparator, false); // tokenize the path
177
							while(strtok.hasMoreTokens()) {
178
								String config_path = strtok.nextToken();
179
180
								if(GLADebug.INSTANCE.debug){
181
									GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file " + config_file + " using config_path "+config_path);			
182
								}
183
								File f = new File(config_path, config_file); // look for the adapter file using the path
184
								if(f.exists()) {									
185
//									table.remove(LogParserConstants.CONFIG_PATH_KEY); // This is no longer required									
186
									adapterFilePath = f.getAbsolutePath();
187
									return adapterFilePath;
188
								}
189
							}
190
						}
191
						// Bug 62317 ends
192
193
						if(GLADebug.INSTANCE.debug){
194
							GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: could not find the adapter file!  Throwing an exception.");			
195
						}
196
						throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file));
197
						
198
					}
199
				}			
200
			}
201
		}		
202
		return adapterFilePath;		
203
	}
204
	/**
205
	 * Initializes the context in which this class is running.
206
	 * Determines whether the code runs in a workbench context or outside. 
207
	 * Calling this method is required before using the adapter path helper method.
208
	 *
209
	 */
210
	protected static synchronized void initialize(){
211
		try {
212
            Class resourcePlugin = Class.forName("org.eclipse.core.resources.ResourcesPlugin");
213
            Method getWorkspace = resourcePlugin.getMethod("getWorkspace", null);
214
            Object workspace = getWorkspace.invoke(null, null);
215
            Method getRoot = workspace.getClass().getMethod("getRoot", null);
216
            Object root = getRoot.invoke(workspace, null);
217
218
            platform =(short)((root != null) ? 1 : 0);
219
        } catch (ClassNotFoundException e) {
220
        	platform = 0;
221
        } catch (SecurityException e) {
222
        	platform = 0;
223
        } catch (NoSuchMethodException e) {
224
        	platform = 0;
225
        } catch (IllegalArgumentException e) {
226
        	platform = 0;
227
        } catch (IllegalAccessException e) {
228
        	platform = 0;
229
        } catch (InvocationTargetException e) {
230
        	platform = 0;
231
        } catch (NullPointerException e) {
232
        	platform = 0;
233
        }
234
	}
235
236
	/**
237
	 * Get the absolute path of the adapter configuration file.
238
	 * @param table the parser parameters hash stable
239
	 * @param nameSpace the plugin name if running in the workbench, null otherwise
240
	 * @param useOriginalAdapter boolean to indicate to use the original adapter file specification
241
	 * stored in the hash table with key originalAdapter
242
	 * @return the absolute path of the adapter file. 
243
	 * @throws LogParserException
244
	 */
245
	public static synchronized String getAbsoluteAdapterPath(Map table, String nameSpace, boolean useOriginalAdapter) throws LogParserException{
246
		String adapterPath = getAdapterPath(table, nameSpace, useOriginalAdapter);
247
		
248
		/* If running in eclipse workbench environment Then the adapter path returned by getAdapterPath may
249
		 * be a URL based on the plugin bundle.  In that case it needs to be converted to an
250
		 * absolute file path.
251
		 */
252
		if(isWorkbenchMode()){
253
			try{
254
				Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
255
	            Method asLocalURL = platformClass.getMethod("asLocalURL", new Class[]{URL.class});
256
	            URL adapterURL = new URL(adapterPath);
257
	            URL absoluteURL = (URL)asLocalURL.invoke(null, new Object[]{adapterURL});
258
	            return absoluteURL.getFile();
259
			}catch (MalformedURLException ue) {
260
				/* Assume that the path returned by getAdapterPath is not a URL but is already an absolute path for
261
				 * the adapter file.  Iit will be returned.
262
				 */
263
			}catch (Throwable e) {
264
				// Capture the exception in a LogParserException
265
				throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", adapterPath),e);
266
			}
267
268
			
269
		}
270
		return adapterPath;
271
	}
272
	/**
273
	 * Get the key that is used to find the adapter configuration file name in the hash table.
274
	 * @param table the parser parameters hash table
275
	 * @return the hash table key corresponding to the adapter file path, null if no adapter
276
	 * file path found.
277
	 */
278
	public static synchronized String getAdapterPathKey(Map table){
279
		String key = null;
280
		String version = (String) (table.get(ParserConstants.APPLICATION_VERSION_KEY));
281
		String config_file = null;
282
		
283
		// If no version attribute given, use default
284
		if(version == null)
285
		{
286
			version = LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY;
287
		}
288
289
		// Get the config file defined for this version
290
		config_file =  (String) (table.get(version));
291
		
292
		if(config_file == null && version != LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY)
293
		{
294
			// Cannot find the corresponding config file, use default
295
			config_file = (String) (table.get(LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY));
296
			
297
			// If the default file is the desired adapter file then set the key to return 
298
			if(config_file != null) { 
299
				key = LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY;
300
			}			
301
		}
302
		else if (config_file != null) {
303
			key = version;
304
		}
305
306
		return key;
307
	
308
	}
309
	
310
	/**
311
	 * 
312
	 * @return boolean whether object is executing in an Eclipse workbench environment
313
	 */
314
	public static synchronized boolean isWorkbenchMode(){
315
		if(platform==-1){
316
			initialize();
317
		}
318
		if(GLADebug.INSTANCE.debug){
319
			GLADebug.INSTANCE.log("workbench="+platform);			
320
		}
321
		
322
		return platform ==1;
323
	}
324
	
325
	/**
326
	 * Get the adapter configuration file path based on locale and encoding.
327
	 * @param table Hash table of input parameters
328
	 * @param configFilePath The adapter configuration file to find.
329
	 * @param find The method to find the file
330
	 * @param bundle - plugin bundle
331
	 * @return the adapter configuration file path
332
	 */
333
	protected static synchronized String getNLAdapterPath(Map table,
334
			String configFilePath, Method find, Object bundle){
335
336
		String characterEncoding = (String) table
337
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_CHARACTER_ENCODING);
338
		String countryCode = (String) table
339
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_ISO_COUNTRY_CODE);
340
		String languageCode = (String) table
341
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_ISO_LANGUAGE_CODE);
342
343
		String locale = null;
344
		/*
345
		 * bugzilla 135799
346
		 * Get the default system locale and character encoding if the default string is 
347
		 * passed in.
348
		 */
349
		if (languageCode != null && languageCode.equals(AdapterConstants.AttributeValue_Default)) {
350
			languageCode = Locale.getDefault().getLanguage();
351
		}
352
		if (countryCode != null && countryCode.equals(AdapterConstants.AttributeValue_Default)) {
353
			countryCode = Locale.getDefault().getCountry();
354
		}
355
356
		if (characterEncoding != null && characterEncoding.equals(AdapterConstants.AttributeValue_Default)) {
357
			try {
358
				characterEncoding = System.getProperty("file.encoding");
359
			}
360
			catch (SecurityException e) {
361
				/* null file encoding will be handled below */
362
			}
363
		}
364
		if(countryCode!=null && countryCode.length() == 0){
365
			locale = languageCode;
366
		}else if(countryCode!=null && languageCode!=null){
367
			locale = languageCode + "_" + countryCode;
368
		}
369
370
		int i = configFilePath.indexOf("/nl/");
371
		if(GLADebug.INSTANCE.debug){
372
			GLADebug.INSTANCE.log("characterEncoding="+characterEncoding);
373
			GLADebug.INSTANCE.log("countryCode="+countryCode);
374
			GLADebug.INSTANCE.log("languageCode="+languageCode);
375
		}
376
		
377
		// try to find the adapter in the following order
378
		// <root>/nl/<ISOLanguageCode>_<ISOCountryCode>/<characterEncoding>
379
		// <root>/nl/<ISOLanguageCode>_<ISOCountryCode>
380
		// <root>/nl/<characterEncoding>
381
		// <root>/nl/
382
		
383
		String[][] searchPath = new String[][]{{locale, characterEncoding}, {locale}, {characterEncoding}, {"/"}};
384
		if (i < 0) {
385
			return configFilePath;
386
		}
387
		int j = configFilePath.lastIndexOf('/');
388
		String dir = configFilePath.substring(0, i + 3);
389
		String fileName = configFilePath.substring(j);
390
		
391
		StringBuffer path = new StringBuffer();
392
		String[] currentPath = null;
393
		int l = 0;
394
395
		String fullPath = null;
396
		String lastPathAppended = null;
397
		for(int idx=0;idx<4 && fullPath==null;idx++){
398
			currentPath = searchPath[idx];
399
			l = currentPath.length;
400
			path.append(dir);
401
			for(int jdx=0;jdx<l;jdx++){				
402
				if(currentPath[jdx]==null){
403
					continue;
404
				}
405
				if(!currentPath[jdx].equals("/")){
406
					path.append('/');
407
				}
408
				path.append(currentPath[jdx]);
409
				lastPathAppended = currentPath[jdx];
410
			}
411
			if(lastPathAppended!=null && lastPathAppended.equals("/")){
412
				path.append(fileName.substring(1));
413
			}else{
414
				path.append(fileName);
415
			}
416
			fullPath = getPath(table, find, bundle, path.toString());
417
			path.setLength(0);
418
		}
419
420
		return fullPath;
421
	}
422
	
423
	/**
424
	 * Get the full path of the adapter configuration file
425
	 * @param table Hash table of input parameters
426
	 * @param find The method to use to find the URL
427
	 * @param bundle The plugin bundle
428
	 * @param configFilePath
429
	 * @return the full path of the adapter file
430
	 */
431
	protected static synchronized String getPath(Map table, Method find, Object bundle, String configFilePath){
432
		String filePath = null;
433
		if(bundle!=null){
434
			// workbench context mode: local import
435
			URL fileURL = find(find, bundle, configFilePath);
436
			if(fileURL==null){
437
				fileURL = find(find, bundle, "config/"+configFilePath);
438
			}
439
			if (fileURL != null) {
440
				filePath = fileURL.toString();
441
			}
442
		}else{
443
			// outside workbench context: remote import or web client
444
			String adapterPath = (String)table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) ;
445
			
446
//			//check to see if the global properties are set
447
//			if (adapterPath == null){
448
//				adapterPath = CBEConfigurationProperties.instance().getProperties().getProperty(CBEConfigurationProperties.ADAPTER_LOCATION);
449
//			}
450
			
451
			String adapterFilePath = adapterPath + "/" + configFilePath;
452
			File file = new File(adapterFilePath);
453
			if(file.exists()){
454
				filePath = adapterFilePath;
455
			}else {
456
				String config_paths = (String)table.get(LogParserConstants.CONFIG_PATH_KEY); // get the paths containing the adapter files
457
				if (config_paths != null && config_paths.length() != 0) {
458
					StringTokenizer strtok = new StringTokenizer(config_paths, File.pathSeparator, false); // tokenize the path
459
					while(strtok.hasMoreTokens()) {
460
						String config_path = strtok.nextToken();
461
462
						File f = new File(config_path, configFilePath); // look for the adapter file using the path
463
						if(f.exists()) {
464
							filePath = f.getAbsolutePath();
465
						}
466
					}
467
				}	
468
			}		
469
		}
470
		if(GLADebug.INSTANCE.debug){
471
			GLADebug.INSTANCE.log("GLAHelper.getPath: Attempted to get adapter at path "+configFilePath +" result: file=" +filePath);
472
		}
473
474
		return filePath;
475
	}
476
	
477
	/**
478
	 * Find the URL of the adapter configuration file
479
	 * @param find The method to find the adapter file
480
	 * @param bundle - The plugin bundle
481
	 * @param config_file - the adapter configuration file to find
482
	 * @return the URL of the adapter configuration file
483
	 */
484
	protected static URL find(Method find, Object bundle, String config_file){
485
		URL fileURL = null;
486
		Class pathClass;
487
		try {
488
			pathClass = Class.forName("org.eclipse.core.runtime.Path");
489
			Constructor pathConstructor = pathClass.getConstructor(new Class[] {config_file.getClass()});
490
			Object path = pathConstructor.newInstance(new Object[] {config_file});
491
			fileURL = (URL)find.invoke(null, new Object[]{bundle, path});
492
			
493
		} catch (Exception e) {			
494
			if(GLADebug.INSTANCE.debug)
495
				e.printStackTrace();
496
		}
497
		return fileURL;
498
		
499
	}
500
	
501
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/GLALoggerFactory.java (-88 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: GLALoggerFactory.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.internal.importer;
14
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogConfigurationException;
17
import org.eclipse.hyades.logging.commons.LoggerFactory;
18
19
/**
20
 * This class extends org.eclipse.hyades.logging.commons.LoggerFactory
21
 * to instantiate the org.eclpise.hyades.logging.parsers.GLALogger class.
22
 * 
23
 * @see org.apache.commons.logging.LogFactory
24
 * @see org.eclipse.hyades.logging.commons.Logger
25
 * @see org.eclipse.hyades.logging.commons.LoggerFactory
26
 * @see org.eclipse.hyades.logging.parsers.internal.importer.GLALogger
27
 */
28
public class GLALoggerFactory extends LoggerFactory {
29
30
    /**
31
     * No-argument constructor.
32
     */
33
    public GLALoggerFactory() {
34
        super();
35
    }
36
37
    /**
38
     * Returns an instance of a non-null named
39
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code> based on the
40
     * parameter name.
41
     * <p>
42
     * Passing a <code>null</code> logger name results in a <code>null</code>
43
     * return value.
44
     * <p>
45
     * An instance of a named
46
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code> is created if no
47
     * named instance current exists or all instances have been released.
48
     * <p>
49
     * Once a named <code>org.eclipse.hyades.logging.parsers.GLALogger</code> is
50
     * created, the instance is cached for future calls to retrieve the same
51
     * named <code>org.eclipse.hyades.logging.parsers.GLALogger</code>.
52
     * <p>
53
     * The name of the <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
54
     * uniquely identifies an instance of an
55
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code>. All subsequent
56
     * calls will return the same instance of the named
57
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code>.
58
     * <p>
59
     * 
60
     * @param loggerName
61
     *            The non-null name of the returned
62
     *            <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
63
     *            instance.
64
     * @return A named <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
65
     *         instance, otherwise <code>null</code> if the parameter logger
66
     *         name is <code>null</code>.
67
     * @exception LogConfigurationException
68
     *                if the named
69
     *                <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
70
     *                instance could not be created.
71
     * @see org.apache.commons.logging.LogFactory#getInstance(java.lang.String)
72
     */
73
    public Log getInstance(String loggerName) throws LogConfigurationException {
74
75
        if (loggerName != null) {
76
77
            if (loggers.containsKey(loggerName)) { return (((Log) (loggers.get(loggerName)))); }
78
79
            GLALogger logger = new GLALogger(loggerName);
80
81
            loggers.put(loggerName, logger);
82
83
            return logger;
84
        }
85
86
        return null;
87
    }
88
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/LocalLogParserLoader.java (-246 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalLogParserLoader.java,v 1.1 2006/08/23 21:17:51 sleeloy Exp $
8
 *
9
 * Contributors:
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.logging.parsers.internal.importer;
13
14
import java.io.UnsupportedEncodingException;
15
import java.util.Hashtable;
16
17
import org.apache.commons.logging.Log;
18
import org.eclipse.hyades.internal.logging.core.Constants;
19
import org.eclipse.hyades.logging.events.cbe.util.EventFormatter;
20
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
21
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
22
23
public class LocalLogParserLoader extends LocalLogImportLoader{
24
25
    //~ Constructors -------------------------------------------------------------------------------
26
27
    public LocalLogParserLoader(ILogParser parser, Hashtable parserParameters, boolean traceXML) {
28
    	super(parser, parserParameters, traceXML);
29
    	loggingLevel=0;
30
    }
31
32
    //~ Methods ------------------------------------------------------------------------------------
33
34
    
35
    public Log getParserLogger(){
36
    	return logParser;
37
    }
38
39
    //NOTE: Temporary API to propagate logged raw objects to the model as XML strings:
40
    private void logXMLToModel(String xml) {
41
        // Note:  L0DocumentEventHandler (perftrace.loader.XMLLoader) XML scanner MUST be passed UTF8 encoded byte array data:
42
        byte[] xmlLogEntryBytes = null;
43
44
        try {
45
            xmlLogEntryBytes = xml.getBytes("UTF8");
46
        }
47
        catch (UnsupportedEncodingException u) {
48
            xmlLogEntryBytes = xml.getBytes();
49
        }
50
51
        //		System.err.println(xml);
52
        xmlLoader.loadEvent(xmlLogEntryBytes, xmlLogEntryBytes.length);
53
    }
54
    
55
	/**
56
	 * Logs the parameter <code>java.lang.Object</code> log record to the Logging Agent 
57
	 * with the same name as the logger if TRACE logging is currently enabled.  
58
	 * 
59
	 * The log record is first converted to XML and then sent to the Logging Agent.
60
	 * 
61
	 * @param record The log record to be logged to the Logging Agent.
62
	 */
63
64
	public void trace(Object record) {
65
//		try {
66
			if (isTraceEnabled()) {
67
				if(!traceXML){
68
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
69
				}else{
70
					logXMLToModel((String)record);
71
				}
72
			}
73
//		}
74
//		catch (Throwable t) {
75
//		}
76
77
	}
78
79
	public void trace(Object record, Throwable throwable) {
80
//		try {
81
			if (isTraceEnabled()) {
82
				if(!traceXML){
83
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
84
				}else{
85
					logXMLToModel((String)record);
86
				}
87
			}
88
//		}
89
//		catch (Throwable t) {
90
//		}
91
92
	}
93
94
	public void debug(Object record) {
95
//		try {
96
			if (isDebugEnabled()) {
97
				if(!traceXML){
98
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
99
				}else{
100
					logXMLToModel((String)record);
101
				}
102
			}
103
//		}
104
//		catch (Throwable t) {
105
//		}
106
107
	}
108
109
	public void debug(Object record, Throwable throwable) {
110
//		try {
111
			if (isDebugEnabled()) {
112
				if(!traceXML){
113
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
114
				}else{
115
					logXMLToModel((String)record);
116
				}
117
			}
118
//		}
119
//		catch (Throwable t) {
120
//		}
121
122
	}
123
124
	public void info(Object record) {
125
//		try {
126
			if (isInfoEnabled()) {
127
				if(!traceXML){
128
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
129
				}else{
130
					logXMLToModel((String)record);
131
				}
132
			}
133
//		}
134
//		catch (Throwable t) {
135
//		}
136
137
	}
138
139
	public void info(Object record, Throwable throwable) {
140
141
//		try {
142
			if (isInfoEnabled()) {
143
				if(!traceXML){
144
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
145
				}else{
146
					logXMLToModel((String)record);
147
				}
148
			}
149
//		}
150
//		catch (Throwable t) {
151
//		}
152
	}
153
154
155
	public void warn(Object record) {
156
//		try {
157
			if (isWarnEnabled()) {
158
                if(!traceXML){	
159
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
160
                }else{
161
                	logXMLToModel((String)record);
162
                }
163
			}
164
//		}
165
//		catch (Throwable t) {
166
//		}
167
	}
168
169
	public void warn(Object record, Throwable throwable) {
170
//		try {
171
			if (isWarnEnabled()) {
172
				if(!traceXML){
173
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
174
				}else{
175
					logXMLToModel((String)record);
176
				}
177
			}
178
//		}
179
//		catch (Throwable t) {
180
//		}
181
	}
182
183
	public void error(Object record) {
184
//		try {
185
			if (isErrorEnabled()) {
186
				if(!traceXML){
187
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
188
				}else{
189
					logXMLToModel((String)record);
190
				}
191
			}
192
//		}
193
//		catch (Throwable t) {
194
//		}
195
	}
196
197
	public void error(Object record, Throwable throwable) {
198
199
//		try {
200
			if (isErrorEnabled()) {
201
				if(!traceXML){
202
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
203
				}else{
204
					logXMLToModel((String)record);
205
				}
206
			}
207
//		}
208
//		catch (Throwable t) {
209
//		}
210
	}
211
212
213
	public void fatal(Object record) {
214
//		try {
215
			if (isFatalEnabled()) {
216
				if(!traceXML){
217
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
218
				}else{
219
					logXMLToModel((String)record);
220
				}
221
			}
222
//		}
223
//		catch (Throwable t) {
224
//		}
225
	}
226
227
228
	public void fatal(Object record, Throwable throwable) {
229
230
//		try {
231
			if (isFatalEnabled()) {
232
				if(!traceXML){
233
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
234
				}else{
235
					logXMLToModel((String)record);
236
				}
237
			}
238
//		}
239
//		catch (Throwable t) {
240
//		}
241
	}
242
243
244
}
245
   
246
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/GLADebug.java (-123 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others. All rights reserved. This program and the
3
 * accompanying materials are made available under the terms of the Eclipse
4
 * Public License v1.0 which accompanies this distribution, and is available at
5
 * http://www.eclipse.org/legal/epl-v10.html
6
 * $Id
7
 * 
8
 * Contributors: IBM - Initial API and implementation
9
 ******************************************************************************/
10
11
package org.eclipse.hyades.logging.parsers.internal.importer;
12
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.lang.reflect.Method;
17
import java.util.Date;
18
19
/**
20
 * This class provides debugging facilities for the Log Import code.
21
 * 
22
 * @author apnan
23
 *
24
 */
25
public class GLADebug {
26
27
	public boolean debug = false;
28
	public boolean logToFile = false;
29
	
30
	protected String plugin_name; 
31
	protected String value;
32
	protected final String NL = System.getProperties().getProperty("line.separator");
33
	private FileOutputStream log = null;
34
35
	public static GLADebug INSTANCE = new GLADebug("org.eclipse.hyades.logging.parsers");
36
37
	public GLADebug(String plugin_name) {
38
		this.plugin_name = plugin_name;
39
		init();
40
	}
41
42
	/**
43
	 * Initialize the debugging code.
44
	 *
45
	 */
46
	protected void init() {
47
		try {
48
			// Get the debugging options from the options file.		
49
			Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
50
            Method getDebugOption = platformClass.getMethod("getDebugOption", new Class[]{String.class});
51
            value = (String)getDebugOption.invoke(null, new String[]{plugin_name+"/debug"});
52
			
53
			if (value != null) {
54
				debug = value.equalsIgnoreCase("true");
55
			} else if(System.getProperty("GLADebug.debug")!=null)
56
			{
57
					debug = Boolean.valueOf(System.getProperty("GLADebug.debug")).booleanValue();
58
			}
59
			value = (String)getDebugOption.invoke(null, new String[]{plugin_name+"/logToFile"});
60
			if (value != null) {
61
				logToFile = value.equalsIgnoreCase("true");
62
			} else if(System.getProperty("GLADebug.logToFile")!=null)
63
			{
64
				logToFile = Boolean.valueOf(System.getProperty("GLADebug.logToFile")).booleanValue();
65
			}
66
			
67
			
68
		} catch (Exception e) {
69
			//	The platform is not available, read the environment variables
70
			debug = Boolean.valueOf(System.getProperty("GLADebug.debug")).booleanValue();
71
			logToFile = Boolean.valueOf(System.getProperty("GLADebug.logToFile")).booleanValue();
72
		}		
73
	}
74
	
75
	/**
76
	 * Get the debug log file output stream.
77
	 * 
78
	 * @return the FileOutputStream for the debug file
79
	 */
80
	public FileOutputStream getLog(){
81
		if(log==null){
82
			try {
83
				log = new FileOutputStream("./GLADebug-"+(new Date()).getTime());
84
			} catch (FileNotFoundException e) {
85
				if(debug)
86
					e.printStackTrace();
87
			}
88
		}else{
89
			if(!log.getChannel().isOpen())
90
			{
91
				try {
92
					log = new FileOutputStream("./GLADebug-"+(new Date()).getTime());					
93
				} catch (FileNotFoundException e) {
94
					if(debug)
95
						e.printStackTrace();
96
				}
97
			}
98
			
99
		}
100
		return log;
101
	}
102
	
103
	/**
104
	 * Log a debug message
105
	 * @param message
106
	 */
107
	public void log(String message){
108
		if(logToFile){
109
			// Log the message to the log file.
110
			try {
111
				getLog().write(message.getBytes());
112
				getLog().write(NL.getBytes());
113
			} catch (IOException e) {			
114
				if(debug)	
115
					e.printStackTrace();
116
			}
117
		}else{
118
			// Log the message to System.out
119
			System.out.println(message);
120
		}
121
	}
122
	
123
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/GLALogger.java (-97 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: GLALogger.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.internal.importer;
14
15
import org.eclipse.hyades.logging.commons.Logger;
16
import org.eclipse.hyades.logging.events.cbe.CommonBaseEvent;
17
18
/**
19
 * This class extends org.eclipse.hyades.logging.commons.Logger
20
 * so that it only logs the Common Base Event message instead of the
21
 * whole Common Base Event.  This class is used to log GLA messages.
22
 * 
23
 * @see org.apache.commons.logging.Log
24
 * @see org.apache.commons.logging.LogFactory
25
 * @see org.eclipse.hyades.logging.core.LoggingAgent
26
 * @see org.eclipse.hyades.logging.commons.Logger
27
 * @see org.eclipse.hyades.logging.commons.LoggerFactory
28
 */
29
public class GLALogger extends Logger {
30
31
    /**
32
     * Constructor to create a logger instance with a Logging Agent using the
33
     * parameter name.
34
     * 
35
     * NOTE: The default logging level is set to WARN until explicitly set.
36
     * 
37
     * @param name
38
     *            The name of the newly created logger.
39
     */
40
    public GLALogger(String name) {
41
42
        super(name);
43
 
44
    }
45
46
    /**
47
     * Logs the parameter <code>java.lang.Object</code> log record to the
48
     * Logging Agent with the same name as the logger if TRACE logging is
49
     * currently enabled.
50
     * 
51
     * If the log record is a CommonBaseEvent only the CommonBaseEvent message will be 
52
     * sent to the Logging Agent.  Otherwise it is assumed the record is a String.
53
     * 
54
     * @param record
55
     *            The log record to be logged to the Logging Agent.
56
     */
57
    public void trace(Object record) {
58
59
        if (isTraceEnabled()) {
60
        	if (record instanceof CommonBaseEvent) {
61
        		loggingAgent.write("glalog=" + ((CommonBaseEvent)record).getMsg());
62
        	}
63
        	else if (record instanceof String) {
64
        		loggingAgent.write((String)record);
65
        	}
66
        }
67
    }
68
69
    /**
70
     * Logs the parameter <code>java.lang.Object</code> log record and
71
     * <code>java.lang.Throwable</code> exception to the Logging Agent with
72
     * the same name as the logger if TRACE logging is currently enabled.
73
     * 
74
     * If the log record is a CommonBaseEvent only the CommonBaseEvent message will be 
75
     * sent to the Logging Agent.  Otherwise it is assumed the record is a String.
76
     * 
77
     * Only the parameter <code>java.lang.Object</code> log record is logged.
78
     * The <code>java.lang.Throwable</code> exception is ignored.
79
     * 
80
     * @param record
81
     *            The log record to be logged to the Logging Agent.
82
     * @param throwable
83
     *            The exception will be ignored
84
     */
85
    public void trace(Object record, Throwable throwable) {
86
87
        if (isTraceEnabled()) {
88
           	if (record instanceof CommonBaseEvent) {
89
        		loggingAgent.write("glalog=" + ((CommonBaseEvent)record).getMsg());
90
        	}
91
        	else if (record instanceof String) {
92
        		loggingAgent.write((String)record);
93
        	}
94
        }
95
    }
96
97
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/StatusMonitor.java (-87 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: StatusMonitor.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.logging.parsers.internal.importer;
13
14
import org.apache.commons.logging.Log;
15
16
/**
17
 * This class is a runnable that checks the status of a log parser
18
 * at regular intervals and sends the status to a logging agent.
19
 */
20
public class StatusMonitor implements Runnable {
21
22
	// Class of the parser object
23
	private Class parserClass = null;
24
	
25
	// The parser object
26
	private Object parser = null;
27
	
28
	// The logging agent to write the status to.
29
	private Log statusLogger = null;
30
	
31
	/**
32
	 * Constructor with required parameters
33
	 * @param parser object that is doing the log parsing
34
	 * @param parserClass class of the parser object
35
	 * @param statusLogger logging agent to write the status to
36
	 */
37
	public StatusMonitor(Object parser, Class parserClass, Log statusLogger) {
38
		super();
39
		
40
		this.parser = parser;
41
		this.parserClass = parserClass;
42
		this.statusLogger = statusLogger;
43
	}
44
45
	/**
46
	 * Run this StatusMonitor thread.
47
	 * @see java.lang.Runnable#run()
48
	 */
49
	public void run() {
50
		String status = null;
51
		
52
		// Status checking loop.
53
		while (true) {
54
			try {
55
				// Get the status of the parsing object.
56
				status = (String)parserClass.getMethod("getStatus",null).invoke(parser, null);
57
			}
58
			catch (Exception e) {
59
				System.err.println("Exception occured when getting status: " + e.getMessage());
60
				status = null;
61
			}
62
			// write status string to status agent
63
			if (status != null) {
64
				statusLogger.trace(status);
65
			}
66
			
67
			// If this thread has been interrupted then quit the monitoring loop.
68
			if (Thread.interrupted()) {
69
				break;
70
			}
71
			
72
	   		/* Sleep for 2 seconds before checking the status again.
73
    		 * The parsing thread may interrupt this thread to indicate it is done so break
74
    		 * from the monitoring loop.
75
    		 */
76
            try {
77
            	Thread.sleep(2000);
78
            }
79
            catch (InterruptedException e) {
80
            	// Quit the monitoring loop if this thread has been interrupted
81
            	break;
82
            }
83
		}
84
85
	}
86
87
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/LocalLogImportLoader.java (-179 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors: 
9
 * IBM - Initial API and implementation
10
 * 
11
 * Change History:
12
 **********************************************************************/
13
package org.eclipse.hyades.logging.parsers.internal.importer;
14
15
import java.util.Hashtable;
16
17
import org.apache.commons.logging.Log;
18
import org.eclipse.hyades.loaders.util.XMLLoader;
19
import org.eclipse.hyades.logging.parsers.LogParserException;
20
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
21
22
/**
23
 * 
24
 * This is a specialized logger to be used by GLA for local log imports.  It is
25
 * instantiated by clients and passed to GLA via ParserWrapper.parse(Log) method.
26
 * Currently it is available internally only for use by the Log Import Wizard in
27
 * org.eclipse.tptp.monitoring.logui
28
 * 
29
 * @author Cindy Jin
30
 *
31
 */
32
public class LocalLogImportLoader  implements Log {
33
34
35
    protected Hashtable parserParameters = null;
36
    protected ILogParser parser = null;
37
    protected XMLLoader xmlLoader = null;
38
    protected Log logParser = null;
39
    protected boolean traceXML = false;
40
41
    /**
42
	 * Trace logging level value.
43
	 */
44
	public static final int TRACE_LEVEL = 0;
45
46
	/**
47
	 * Debug logging level value.
48
	 */
49
	public static final int DEBUG_LEVEL = 1;
50
51
	/**
52
	 * Information logging level value.
53
	 */
54
	public static final int INFO_LEVEL = 2;
55
56
	/**
57
	 * Warning logging level value.
58
	 */
59
	public static final int WARN_LEVEL = 3;
60
61
	/**
62
	 * Error logging level value.
63
	 */
64
	public static final int ERROR_LEVEL = 4;
65
66
	/**
67
	 * Fatal logging level value.
68
	 */
69
	public static final int FATAL_LEVEL = 5;
70
71
	/**
72
	 * The logger's current logging level value.
73
	 */
74
	protected int loggingLevel;
75
	public LocalLogImportLoader()
76
	{
77
		parser           = null;
78
		parserParameters = null;
79
	}
80
81
    public LocalLogImportLoader(ILogParser parser, Hashtable parserParameters, boolean traceXML) {
82
        this.parser = parser;
83
        this.parserParameters = parserParameters;
84
        this.traceXML = traceXML;
85
    }
86
87
    public void setXMLLoader(XMLLoader xmlLoader) {
88
    	 parserParameters.put("xmlLoader", xmlLoader);
89
        this.xmlLoader = xmlLoader;
90
    }
91
    
92
     
93
    public void startParsing() throws LogParserException {
94
        parser.setUserInput(parserParameters);
95
        parser.parse(this);
96
    }
97
    public void setParserLogger(Log logParser){
98
    	this.logParser = logParser;
99
    	parser.setParserLogger(logParser); 
100
    }
101
    
102
    public Log getParserLogger(){
103
    	return logParser;
104
    }
105
106
    public XMLLoader getXMLLoader()
107
    {
108
    	return xmlLoader;
109
    }
110
    
111
	public boolean isTraceEnabled() {
112
		return (loggingLevel<=TRACE_LEVEL);
113
	}
114
115
	public boolean isDebugEnabled() {
116
		return (loggingLevel<=DEBUG_LEVEL);
117
	}
118
119
120
	public boolean isInfoEnabled() {
121
		return (loggingLevel<=INFO_LEVEL);
122
	}
123
124
	public boolean isWarnEnabled() {
125
		return (loggingLevel<=WARN_LEVEL);
126
	}
127
128
	public boolean isErrorEnabled() {
129
		return (loggingLevel<=ERROR_LEVEL);
130
	}
131
132
	public boolean isFatalEnabled() {
133
		return (loggingLevel<=FATAL_LEVEL);
134
	}
135
136
	 
137
	public void trace(Object record) {
138
	}
139
140
	public void trace(Object record, Throwable throwable) {
141
	}
142
143
	public void debug(Object record) {
144
	}
145
146
	public void debug(Object record, Throwable throwable) {
147
	}
148
149
	public void info(Object record) {
150
	}
151
152
	public void info(Object record, Throwable throwable) {
153
	}
154
155
156
	public void warn(Object record) {
157
	}
158
159
	public void warn(Object record, Throwable throwable) {
160
	}
161
162
	public void error(Object record) {
163
	}
164
165
	public void error(Object record, Throwable throwable) {
166
	}
167
168
169
	public void fatal(Object record) {
170
171
	}
172
173
174
	public void fatal(Object record, Throwable throwable) {
175
176
	}
177
	
178
	
179
}
(-)src.import/org/eclipse/hyades/logging/parsers/internal/importer/LocalGLALogger.java (-203 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalGLALogger.java,v 1.2 2006/09/20 19:20:23 dnsmith Exp $
8
 *
9
 * Contributors:
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.internal.importer;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.apache.commons.logging.Log;
19
import org.eclipse.hyades.logging.events.cbe.CommonBaseEvent;
20
21
public class LocalGLALogger implements Log {
22
23
	//private XmlGenerator xmlGenerator = new XmlGenerator();
24
	private List events = new ArrayList();
25
	private  final String NL = System.getProperties().getProperty("line.separator");
26
	
27
	private String detailMessage = null;
28
29
	/**
30
	 * Trace logging level value.
31
	 */
32
	public static final int TRACE_LEVEL = 0;
33
34
	/**
35
	 * Debug logging level value.
36
	 */
37
	public static final int DEBUG_LEVEL = 1;
38
39
	/**
40
	 * Information logging level value.
41
	 */
42
	public static final int INFO_LEVEL = 2;
43
44
	/**
45
	 * Warning logging level value.
46
	 */
47
	public static final int WARN_LEVEL = 3;
48
49
	/**
50
	 * Error logging level value.
51
	 */
52
	public static final int ERROR_LEVEL = 4;
53
54
	/**
55
	 * Fatal logging level value.
56
	 */
57
	public static final int FATAL_LEVEL = 5;
58
59
	/**
60
	 * The logger's current logging level value.
61
	 */
62
	private int loggingLevel;
63
64
	public LocalGLALogger() {
65
		//xmlGenerator.reset(null, true, 8);
66
		loggingLevel = 0;
67
	}
68
69
	public String getLogDetails() {
70
		StringBuffer buffer = new StringBuffer();
71
		synchronized(events){
72
			int s = events.size();
73
			String msg = null;
74
			if(s>0){
75
				for(int i=0;i<s-1;i++){
76
					msg = (String)events.get(i);
77
					if(msg!=null){
78
						buffer.append(msg);				
79
						buffer.append(NL);
80
					}			
81
				}
82
				msg = (String)events.get(s-1);
83
				if(msg!=null){
84
					buffer.append(msg);
85
				}
86
			}
87
		}
88
		detailMessage = buffer.toString();
89
		return detailMessage;
90
	}
91
92
	public boolean isDebugEnabled() {
93
		return (loggingLevel <= DEBUG_LEVEL);
94
	}
95
96
	public boolean isErrorEnabled() {
97
		return (loggingLevel <= ERROR_LEVEL);
98
	}
99
100
	public boolean isFatalEnabled() {
101
		return (loggingLevel <= FATAL_LEVEL);
102
	}
103
104
	public boolean isInfoEnabled() {
105
		return (loggingLevel <= INFO_LEVEL);
106
	}
107
108
	public boolean isTraceEnabled() {
109
		return (loggingLevel <= TRACE_LEVEL);
110
	}
111
112
	public boolean isWarnEnabled() {
113
		return (loggingLevel <= WARN_LEVEL);
114
	}
115
116
	public void trace(Object record) {
117
		if (isTraceEnabled()) {
118
			synchronized(events){
119
				if(record!=null && record instanceof CommonBaseEvent)
120
				if(((CommonBaseEvent)record).getMsg()!=null && !events.contains(((CommonBaseEvent)record).getMsg())){
121
					events.add(((CommonBaseEvent)record).getMsg());
122
				}
123
			}
124
//			this.detailMessage = xmlGenerator.objectToXML(record);
125
//			logXMLToModel(xmlGenerator.objectToXML(record));
126
		}
127
128
	}
129
130
	public void trace(Object record, Throwable arg1) {
131
		if (isTraceEnabled()) {
132
			trace(record);
133
//			logXMLToModel(xmlGenerator.objectToXML(record));
134
		}
135
136
	}
137
138
	public void debug(Object record) {
139
		if (isDebugEnabled()) {
140
			trace(record);
141
//			logXMLToModel(xmlGenerator.objectToXML(record));
142
		}
143
	}
144
145
	public void debug(Object record, Throwable arg1) {
146
		if (isDebugEnabled()) {
147
//			logXMLToModel(xmlGenerator.objectToXML(record));
148
		}
149
150
	}
151
152
	public void info(Object record) {
153
		if (isInfoEnabled()) {
154
//			logXMLToModel(xmlGenerator.objectToXML(record));
155
		}
156
157
	}
158
159
	public void info(Object record, Throwable arg1) {
160
		if (isInfoEnabled()) {
161
//			logXMLToModel(xmlGenerator.objectToXML(record));
162
		}
163
164
	}
165
166
	public void warn(Object record) {
167
		if (isWarnEnabled()) {
168
//			logXMLToModel(xmlGenerator.objectToXML(record));
169
		}
170
171
	}
172
173
	public void warn(Object record, Throwable arg1) {
174
		if (isWarnEnabled()) {
175
//			logXMLToModel(xmlGenerator.objectToXML(record));
176
		}
177
	}
178
179
	public void error(Object record) {
180
		if (isErrorEnabled()) {
181
//			logXMLToModel(xmlGenerator.objectToXML(record));
182
		}
183
	}
184
185
	public void error(Object record, Throwable arg1) {
186
		if (isErrorEnabled()) {
187
//			logXMLToModel(xmlGenerator.objectToXML(record));
188
		}
189
	}
190
191
	public void fatal(Object record) {
192
		if (isFatalEnabled()) {
193
//			logXMLToModel(xmlGenerator.objectToXML(record));
194
		}
195
	}
196
197
	public void fatal(Object record, Throwable arg1) {
198
		if (isFatalEnabled()) {
199
//			logXMLToModel(xmlGenerator.objectToXML(record));
200
		}
201
	}
202
203
}
(-)schema/logParser.exsd (-16 / +14 lines)
Lines 110-115 Link Here
110
               </documentation>
110
               </documentation>
111
            </annotation>
111
            </annotation>
112
         </attribute>
112
         </attribute>
113
         <attribute name="override_id" type="string">
114
            <annotation>
115
               <documentation>
116
                  ID of logParser extension that this extension will override. Note, only those attributes included in this extension will be overridden.
117
               </documentation>
118
            </annotation>
119
         </attribute>
120
         <attribute name="override_priority" type="string">
121
            <annotation>
122
               <documentation>
123
                  Numeric priority value used to evaluate the priority of this override extension in relation to other override extensions. A value of -1 indicates that the extension that is specified in override_id should be disabled and not available for use as a log parser. Note, this attribute is required if override_id is specified.  This attribute is ignored if override_id is not specified.
124
               </documentation>
125
            </annotation>
126
         </attribute>
113
      </complexType>
127
      </complexType>
114
   </element>
128
   </element>
115
129
Lines 546-568 Link Here
546
      </documentation>
560
      </documentation>
547
   </annotation>
561
   </annotation>
548
562
549
   <annotation>
550
      <appInfo>
551
         <meta.section type="apiInfo"/>
552
      </appInfo>
553
      <documentation>
554
         
555
      </documentation>
556
   </annotation>
557
563
558
   <annotation>
559
      <appInfo>
560
         <meta.section type="implementation"/>
561
      </appInfo>
562
      <documentation>
563
         
564
      </documentation>
565
   </annotation>
566
564
567
   <annotation>
565
   <annotation>
568
      <appInfo>
566
      <appInfo>
(-)src.import/org/eclipse/hyades/logging/parsers/internal/adapter/formatters/LocalLogImportCBEFormatter.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-38 Link Here
32
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
32
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
33
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
33
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
34
import org.eclipse.hyades.logging.parsers.importer.ParserWrapper;
34
import org.eclipse.hyades.logging.parsers.importer.ParserWrapper;
35
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogImportLoader;
35
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogImportLoader;
36
36
37
/**
37
/**
38
 * 
38
 * 
(-)src/org/eclipse/hyades/logging/parsers/adapter/sensors/StaticParserSensor.java (-27 / +44 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005,2006 IBM Corporation and others.
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 91-108 Link Here
91
	}
91
	}
92
92
93
	/**
93
	/**
94
	 * Update the configuration based on the configuration Element
94
	 * Read the sensor configuration from the configuration element
95
	 * @throws AdapterInvalidConfig if the configuration processing failed.
95
	 * @param parserParameters Hashtable to put the sensor parameters in
96
	 * @see org.eclipse.hyades.logging.adapter.IComponent#update()
97
	 */
96
	 */
98
	public void update() throws AdapterInvalidConfig
97
	protected void readConfiguration(Hashtable parserParameters) {
99
	{
98
		// maximumBlocking is set by the sensor configuration
100
		// first get the basic configuration set
101
		super.update();
102
		// maximumBlocking is set by the sensor config
103
		String directory = null;
104
		String fileName = null;
105
		String className = null;
106
99
107
		String propertyName = null;
100
		String propertyName = null;
108
		String propertyValue = null;
101
		String propertyValue = null;
Lines 114-125 Link Here
114
		
107
		
115
		// Make a copy of the sensor properties to use as the parserParameters
108
		// Make a copy of the sensor properties to use as the parserParameters
116
		Hashtable sensorParameters = getProperties();
109
		Hashtable sensorParameters = getProperties();
117
		Hashtable parserParameters = new Hashtable();
118
		
110
		
119
		// This sensor may be configured with a sub element of the config
111
		// This sensor may be configured with a sub element of the config
120
		// or the sensor may be configured with sensor properties only.
112
		// or the sensor may be configured with sensor properties only.
121
113
122
		boolean propertiesPresent = false;
123
		// Get the sensor parameters from the sensor properties
114
		// Get the sensor parameters from the sensor properties
124
		if (sensorParameters != null && !sensorParameters.isEmpty()) {
115
		if (sensorParameters != null && !sensorParameters.isEmpty()) {
125
			// bugzilla 160528 - copy the sensor properties into the parserParamenters hash table because
116
			// bugzilla 160528 - copy the sensor properties into the parserParamenters hash table because
Lines 131-138 Link Here
131
122
132
			fileName = (String)parserParameters.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);
123
			fileName = (String)parserParameters.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);
133
			
124
			
134
			className = (String)parserParameters.get(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName);									
125
			parserClassName = (String)parserParameters.get(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName);									
135
			propertiesPresent = true;
126
			
136
		}	
127
		}	
137
		else if (element != null) {
128
		else if (element != null) {
138
			/**
129
			/**
Lines 158-164 Link Here
158
								fileName = file;
149
								fileName = file;
159
						}	
150
						}	
160
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName))
151
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName))
161
							className = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName);
152
							parserClassName = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAstaticParserClassAttributeName);
162
					
153
					
163
					    // Get the parameters from the sensor type instance properties
154
					    // Get the parameters from the sensor type instance properties
164
						sensorNodes = sensorNode.getChildNodes();
155
						sensorNodes = sensorNode.getChildNodes();
Lines 184-198 Link Here
184
				}
175
				}
185
			}
176
			}
186
		}
177
		}
187
		
178
	}
179
180
	/**
181
	 * Process the values read from the configuration and update the hash table of
182
	 * parameters if necessary.
183
	 * @param parserParameters Hashtable of sensor parameters
184
	 * @throws AdapterInvalidConfig
185
	 */
186
	protected void processConfiguration(Hashtable parserParameters) throws AdapterInvalidConfig {
188
		// We must have a directory and fileName
187
		// We must have a directory and fileName
189
		if (directory == null || directory.length() == 0 || fileName == null || fileName.length() == 0 || className == null || className.length() == 0) {
188
		if (directory == null || directory.length() == 0 || fileName == null || fileName.length() == 0 || parserClassName == null || parserClassName.length() == 0) {
190
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_StaticParserSensor_Invalid_Config_File_ERROR_"));
189
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_StaticParserSensor_Invalid_Config_File_ERROR_"));
191
		}
190
		}
192
		
191
		
193
		setDirectory(directory);
192
		setDirectory(directory);
194
		setFileName(fileName);
193
		setFileName(fileName);
195
		setParserClassName(className);
194
		setParserClassName(parserClassName);
196
		
195
		
197
		// Construct the full input log file name
196
		// Construct the full input log file name
198
		if (getDirectory().endsWith(PATH_SEPARATOR)) {
197
		if (getDirectory().endsWith(PATH_SEPARATOR)) {
Lines 265-278 Link Here
265
		
264
		
266
		parserParameters.put(ParserConstants.CONTINUOUS_KEY, new Boolean(continuousContext));
265
		parserParameters.put(ParserConstants.CONTINUOUS_KEY, new Boolean(continuousContext));
267
266
268
		/* bugzilla 91489 - if the directory and file name values are not already in the hash
267
		/* bugzilla 91489 - reset the directory and file name values in the hash
269
		 * table then add them so the parser class can use them instead of file_path to handle
268
		 * table so the parser class can use them instead of file_path to handle
270
		 * regular expression values better.
269
		 * regular expression values better.  The directory and file name values 
270
		 * may have been changed before getting to this point so they should be
271
		 * reset in the hash table.
271
		 */
272
		 */
272
		if (!propertiesPresent) {
273
		
273
			parserParameters.put(ParserConstants.DIRECTORY_KEY, directory);
274
		parserParameters.put(ParserConstants.DIRECTORY_KEY, directory);
274
			parserParameters.put(ParserConstants.FILE_NAME_KEY, fileName);
275
		parserParameters.put(ParserConstants.FILE_NAME_KEY, fileName);
275
		}
276
		
276
		
277
		// Get the static parser class instance
277
		// Get the static parser class instance
278
		try {
278
		try {
Lines 296-301 Link Here
296
	}
296
	}
297
	
297
	
298
	/**
298
	/**
299
	 * Update the configuration based on the configuration Element
300
	 * @throws AdapterInvalidConfig if the configuration processing failed.
301
	 * @see org.eclipse.hyades.logging.adapter.IComponent#update()
302
	 */
303
	public void update() throws AdapterInvalidConfig
304
	{
305
		// first get the basic configuration set
306
		super.update();
307
		
308
		Hashtable parserParameters = new Hashtable();
309
		
310
		readConfiguration(parserParameters);
311
		
312
		processConfiguration(parserParameters);
313
	}
314
	
315
	/**
299
	 * 	simulates a getNext
316
	 * 	simulates a getNext
300
	 * @see org.eclipse.hyades.logging.adapter.ISensor#testGetNext()
317
	 * @see org.eclipse.hyades.logging.adapter.ISensor#testGetNext()
301
	 */
318
	 */
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 17-23 Link Here
17
 org.eclipse.hyades.logging.parsers.importer,
17
 org.eclipse.hyades.logging.parsers.importer,
18
 org.eclipse.hyades.logging.parsers.internal.adapter.formatters,
18
 org.eclipse.hyades.logging.parsers.internal.adapter.formatters,
19
 org.eclipse.hyades.logging.parsers.internal.adapter.outputters,
19
 org.eclipse.hyades.logging.parsers.internal.adapter.outputters,
20
 org.eclipse.hyades.logging.parsers.internal.importer
20
 org.eclipse.hyades.logging.parsers.provisional.importer
21
Require-Bundle: org.eclipse.hyades.logging.core;bundle-version="[4.2.0,5.0.0)";visibility:=reexport,
21
Require-Bundle: org.eclipse.hyades.logging.core;bundle-version="[4.2.0,5.0.0)";visibility:=reexport,
22
 org.eclipse.hyades.logging.adapter;bundle-version="[4.2.0,5.0.0)";visibility:=reexport,
22
 org.eclipse.hyades.logging.adapter;bundle-version="[4.2.0,5.0.0)";visibility:=reexport,
23
 org.eclipse.swt;bundle-version="[3.2.0,4.0.0)",
23
 org.eclipse.swt;bundle-version="[3.2.0,4.0.0)",
(-)src.import/org/eclipse/hyades/logging/parsers/importer/RemoteLogParserLoader.java (-5 / +5 lines)
Lines 1-7 Link Here
1
package org.eclipse.hyades.logging.parsers.importer;
1
package org.eclipse.hyades.logging.parsers.importer;
2
2
3
/**********************************************************************
3
/**********************************************************************
4
 * Copyright (c) 2005,2006 IBM Corporation and others.
4
 * Copyright (c) 2005,2008 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 28-37 Link Here
28
import org.eclipse.hyades.logging.core.LoggingAgent;
28
import org.eclipse.hyades.logging.core.LoggingAgent;
29
import org.eclipse.hyades.logging.parsers.LogParserException;
29
import org.eclipse.hyades.logging.parsers.LogParserException;
30
import org.eclipse.hyades.logging.parsers.ParserUtilities;
30
import org.eclipse.hyades.logging.parsers.ParserUtilities;
31
import org.eclipse.hyades.logging.parsers.internal.importer.GLADebug;
31
import org.eclipse.hyades.logging.parsers.provisional.importer.GLADebug;
32
import org.eclipse.hyades.logging.parsers.internal.importer.GLALogger;
32
import org.eclipse.hyades.logging.parsers.provisional.importer.GLALogger;
33
import org.eclipse.hyades.logging.parsers.internal.importer.GLALoggerFactory;
33
import org.eclipse.hyades.logging.parsers.provisional.importer.GLALoggerFactory;
34
import org.eclipse.hyades.logging.parsers.internal.importer.StatusMonitor;
34
import org.eclipse.hyades.logging.parsers.provisional.importer.StatusMonitor;
35
/**
35
/**
36
 * This class handles initialization (e.g. calling the setUserInput() API)
36
 * This class handles initialization (e.g. calling the setUserInput() API)
37
 * and invocation (e.g. calling the parse() API) of a remote log
37
 * and invocation (e.g. calling the parse() API) of a remote log
(-)src.import/org/eclipse/hyades/logging/parsers/importer/ParserWrapper.java (-159 / +184 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 36-43 Link Here
36
import org.eclipse.hyades.logging.parsers.ParserConstants;
36
import org.eclipse.hyades.logging.parsers.ParserConstants;
37
import org.eclipse.hyades.logging.parsers.ParserUtilities;
37
import org.eclipse.hyades.logging.parsers.ParserUtilities;
38
import org.eclipse.hyades.logging.parsers.adapter.outputters.AdapterLogOutputter;
38
import org.eclipse.hyades.logging.parsers.adapter.outputters.AdapterLogOutputter;
39
import org.eclipse.hyades.logging.parsers.internal.importer.GLADebug;
39
import org.eclipse.hyades.logging.parsers.provisional.importer.GLADebug;
40
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
40
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
41
import org.w3c.dom.Document;
41
import org.w3c.dom.Document;
42
import org.w3c.dom.Element;
42
import org.w3c.dom.Element;
43
import org.w3c.dom.NamedNodeMap;
43
import org.w3c.dom.NamedNodeMap;
Lines 216-222 Link Here
216
	 * @return String - name of new config file
216
	 * @return String - name of new config file
217
	 * @throws LogParserException 
217
	 * @throws LogParserException 
218
	 */		
218
	 */		
219
	private String getNewConfigFile(Hashtable table) throws LogParserException
219
	protected String getNewConfigFile(Hashtable table) throws LogParserException
220
	{
220
	{
221
		Document doc = null;
221
		Document doc = null;
222
222
Lines 430-620 Link Here
430
		if(GLADebug.INSTANCE.debug){
430
		if(GLADebug.INSTANCE.debug){
431
			GLADebug.INSTANCE.log("ParserWrapper.getNewConfigFile: setting sensor properties.");			
431
			GLADebug.INSTANCE.log("ParserWrapper.getNewConfigFile: setting sensor properties.");			
432
		}
432
		}
433
		/**
433
434
		 * Get the sensor config - there should only be one sensor - and fill in
434
		/* Iterate through the components in the context instance and set any component
435
		 * the properties and attributes with the values from the input hash table
435
		 * properties with their corresponding values in the input hash table.
436
		 */
436
		 */ 
437
		NodeList sensorList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_SENSOR);
437
		NodeList contextInstanceList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
438
		int sensorCount = sensorList.getLength();
438
		
439
		for (int i = 0; i < sensorCount; ++i)
439
		Element cIElement = (Element) contextInstanceList.item(0);
440
		{
440
		NodeList componentList = cIElement.getChildNodes();
441
			Element sensorElement = (Element) sensorList.item(i);
441
		int compCount = componentList.getLength();
442
			
442
		
443
			// We should always have a sensor instance but check in case an invalid
443
		for (int i = 0; i<compCount; ++i) {
444
			// config file is used.
444
			if (componentList.item(i) instanceof Element) {
445
			if (sensorElement != null) {
445
				Element compElement = (Element) componentList.item(i);
446
				Element sensorNode;
446
				String tagName = compElement.getTagName();
447
				Element sensorPropertyElement;
447
				System.out.println(tagName);
448
				Element sensorTypeInstance = null;
449
				String propValue;
448
				String propValue;
450
				String propName;
449
				String propName;
451
				String newConverterCmd = null;
450
				Element propertyElement;
452
451
453
				Element directoryPropertyElement = null;
452
				// If the component is a sensor Then set the appropriate sensor attributes and properties
454
				Element fileNamePropertyElement = null;
453
				if (compElement.getTagName().equals(AdapterXMLConstants.ELEMENT_TAG_NAME_SENSOR)) {
455
				
454
					Element sensorElement = compElement;
456
				// Get the sensor children (properties or sensor type instances)
455
					
457
				NodeList sensorNodes = sensorElement.getChildNodes();
456
					Element sensorNode;
458
				for (int k = 0; k < sensorNodes.getLength(); k++) {
457
					Element sensorPropertyElement;
459
					if (sensorNodes.item(k).getNodeType() == Node.ELEMENT_NODE) {
458
					Element sensorTypeInstance = null;
460
						sensorNode = (Element) sensorNodes.item(k);
459
					String newConverterCmd = null;
461
						// Process the sensor property
460
462
						if (sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGAPropertyElementTagName)) {
461
					Element directoryPropertyElement = null;
463
							sensorPropertyElement = sensorNode;
462
					Element fileNamePropertyElement = null;
464
463
					
465
							propName = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName);
464
					// Get the sensor children (properties or sensor type instances)
466
							propValue = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName);
465
					NodeList sensorNodes = sensorElement.getChildNodes();
467
							
466
					for (int k = 0; k < sensorNodes.getLength(); k++) {
468
							if (propName.equals(AdapterXMLConstants.HyadesGAdirectoryAttributeName)) {
467
						if (sensorNodes.item(k).getNodeType() == Node.ELEMENT_NODE) {
469
								// save property element so it can be set after converter processing
468
							sensorNode = (Element) sensorNodes.item(k);
470
								directoryPropertyElement = sensorPropertyElement;
469
							// Process the sensor property
471
								/* There might not be a log file if the converter command generates a file.
470
							if (sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGAPropertyElementTagName)) {
472
								 * If there is a log file then set the directory property
471
								sensorPropertyElement = sensorNode;
473
								 */
474
								if (logFileDir != null) {
475
									sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, logFileDir);
476
								}									
477
							}
478
							else if (propName.equals(AdapterXMLConstants.HyadesGAfileNameAttributeName)) {
479
								// save property element so it can be set after converter processing
480
								fileNamePropertyElement = sensorPropertyElement;
481
								/* There might not be a log file if the converter command generates a file.
482
								 * If there is a log file then set the fileName property
483
								 */
484
								if (logFileName != null) {
485
									sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, logFileName);
486
								}									
487
							}
488
							else if (propName.equals(AdapterXMLConstants.HyadesGAconverterCmdAttributeName)) {
489
								if (propValue != null && propValue.length() > 0) {
490
									if (newConverterCmd == null) {
491
										newConverterCmd = modifyConverter(propValue, configFileDirectory, table, logFile);
492
										// ensure the new converter command is not null
493
										if (newConverterCmd == null) {
494
											newConverterCmd = "";
495
										}
496
									}
497
									sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, newConverterCmd);
498
								}
499
							}
500
							else {
501
								propValue = (String)table.get(propName);
502
								if(propValue != null)
503
								{
504
									sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, propValue.trim());
505
								}
506
							}
507
						}
508
						// Process the sensor type instance
509
						else if (sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGAStaticParserSensorTagName) ||
510
								 sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGASingleFileSensorTagName)) {
511
							sensorTypeInstance = sensorNode;
512
							// Get the sensor properties for this sensor type instance
513
							NodeList sensorPropertyList = sensorTypeInstance.getElementsByTagName(AdapterXMLConstants.HyadesGASensorPropertyElementTagName);
514
							int sensorPropertyCount = sensorPropertyList.getLength();
515
							for(int j = 0; j < sensorPropertyCount; ++j)
516
							{
517
								sensorPropertyElement = (Element) sensorPropertyList.item(j);
518
								propName = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGASensorPropertyNameAttributeName);
519
								propValue = (String)table.get(propName);
520
								if(propValue != null)
521
								{
522
									sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, propValue.trim());
523
								}
524
							}
525
472
526
							// Get the sensor type attributes
473
								propName = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName);
527
							NamedNodeMap sensorTypeAttributeList = sensorTypeInstance.getAttributes();
474
								propValue = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName);
528
							int sensorTypeAttributeCount = sensorTypeAttributeList.getLength();
475
								
529
				
476
								if (propName.equals(AdapterXMLConstants.HyadesGAdirectoryAttributeName)) {
530
							for(int j = 0; j < sensorTypeAttributeCount; ++j)
477
									// save property element so it can be set after converter processing
531
							{
478
									directoryPropertyElement = sensorPropertyElement;
532
								Node sensorTypeAttribute = sensorTypeAttributeList.item(j);
533
								String attrName = sensorTypeAttribute.getNodeName();
534
								// Modify the attribute based on user input
535
								if(attrName.equals(AdapterXMLConstants.HyadesGAdirectoryAttributeName))
536
								{
537
									/* There might not be a log file if the converter command generates a file.
479
									/* There might not be a log file if the converter command generates a file.
538
									 * If there is a log file then set the directory attribute
480
									 * If there is a log file then set the directory property
539
									 */
481
									 */
540
									if (logFileDir != null) {
482
									if (logFileDir != null) {
541
										sensorTypeAttribute.setNodeValue(logFileDir);
483
										sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, logFileDir);
542
									}									
484
									}									
543
								}
485
								}
544
								else if(attrName.equals(AdapterXMLConstants.HyadesGAfileNameAttributeName))
486
								else if (propName.equals(AdapterXMLConstants.HyadesGAfileNameAttributeName)) {
545
								{
487
									// save property element so it can be set after converter processing
488
									fileNamePropertyElement = sensorPropertyElement;
546
									/* There might not be a log file if the converter command generates a file.
489
									/* There might not be a log file if the converter command generates a file.
547
									 * If there is a log file then set the fileName attribute
490
									 * If there is a log file then set the fileName property
548
									 */
491
									 */
549
									if (logFileName != null) {
492
									if (logFileName != null) {
550
										sensorTypeAttribute.setNodeValue(logFileName);
493
										sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, logFileName);
494
									}									
495
								}
496
								else if (propName.equals(AdapterXMLConstants.HyadesGAconverterCmdAttributeName)) {
497
									if (propValue != null && propValue.length() > 0) {
498
										if (newConverterCmd == null) {
499
											newConverterCmd = modifyConverter(propValue, configFileDirectory, table, logFile);
500
											// ensure the new converter command is not null
501
											if (newConverterCmd == null) {
502
												newConverterCmd = "";
503
											}
504
										}
505
										sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, newConverterCmd);
551
									}
506
									}
552
								}
507
								}
553
								else if(attrName.equals(AdapterXMLConstants.HyadesGAconverterCmdAttributeName))
508
								else {
554
								{
509
									propValue = (String)table.get(propName);
555
									if (newConverterCmd == null) {
510
									if(propValue != null)
556
									   newConverterCmd = modifyConverter(sensorTypeAttribute.getNodeValue(), configFileDirectory, table, logFile);
511
									{
557
									   // ensure the new converter command is not null
512
										sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, propValue.trim());
558
									   if (newConverterCmd == null) {
559
									   		newConverterCmd = "";
560
									   }
561
									}
513
									}
562
									sensorTypeAttribute.setNodeValue(newConverterCmd);
563
								}
514
								}
564
								else
515
							}
516
							// Process the sensor type instance
517
							else if (sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGAStaticParserSensorTagName) ||
518
									 sensorNode.getTagName().equals(AdapterXMLConstants.HyadesGASingleFileSensorTagName)) {
519
								sensorTypeInstance = sensorNode;
520
								// Get the sensor properties for this sensor type instance
521
								NodeList sensorPropertyList = sensorTypeInstance.getElementsByTagName(AdapterXMLConstants.HyadesGASensorPropertyElementTagName);
522
								int sensorPropertyCount = sensorPropertyList.getLength();
523
								for(int j = 0; j < sensorPropertyCount; ++j)
565
								{
524
								{
566
									propValue = (String)table.get(attrName);
525
									sensorPropertyElement = (Element) sensorPropertyList.item(j);
526
									propName = sensorPropertyElement.getAttribute(AdapterXMLConstants.HyadesGASensorPropertyNameAttributeName);
527
									propValue = (String)table.get(propName);
567
									if(propValue != null)
528
									if(propValue != null)
568
									{
529
									{
569
										sensorTypeAttribute.setNodeValue(propValue.trim());
530
										sensorPropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, propValue.trim());
531
									}
532
								}
533
534
								// Get the sensor type attributes
535
								NamedNodeMap sensorTypeAttributeList = sensorTypeInstance.getAttributes();
536
								int sensorTypeAttributeCount = sensorTypeAttributeList.getLength();
537
					
538
								for(int j = 0; j < sensorTypeAttributeCount; ++j)
539
								{
540
									Node sensorTypeAttribute = sensorTypeAttributeList.item(j);
541
									String attrName = sensorTypeAttribute.getNodeName();
542
									// Modify the attribute based on user input
543
									if(attrName.equals(AdapterXMLConstants.HyadesGAdirectoryAttributeName))
544
									{
545
										/* There might not be a log file if the converter command generates a file.
546
										 * If there is a log file then set the directory attribute
547
										 */
548
										if (logFileDir != null) {
549
											sensorTypeAttribute.setNodeValue(logFileDir);
550
										}									
551
									}
552
									else if(attrName.equals(AdapterXMLConstants.HyadesGAfileNameAttributeName))
553
									{
554
										/* There might not be a log file if the converter command generates a file.
555
										 * If there is a log file then set the fileName attribute
556
										 */
557
										if (logFileName != null) {
558
											sensorTypeAttribute.setNodeValue(logFileName);
559
										}
560
									}
561
									else if(attrName.equals(AdapterXMLConstants.HyadesGAconverterCmdAttributeName))
562
									{
563
										if (newConverterCmd == null) {
564
										   newConverterCmd = modifyConverter(sensorTypeAttribute.getNodeValue(), configFileDirectory, table, logFile);
565
										   // ensure the new converter command is not null
566
										   if (newConverterCmd == null) {
567
										   		newConverterCmd = "";
568
										   }
569
										}
570
										sensorTypeAttribute.setNodeValue(newConverterCmd);
571
									}
572
									else
573
									{
574
										propValue = (String)table.get(attrName);
575
										if(propValue != null)
576
										{
577
											sensorTypeAttribute.setNodeValue(propValue.trim());
578
										}
570
									}
579
									}
571
								}
580
								}
572
							}
581
							}
573
						}
582
						}
574
					}
583
					}
575
				}
576
584
577
				// Get the sensor attributes
585
					// Get the sensor attributes
578
				NamedNodeMap sensorAttributeList = sensorElement.getAttributes();
586
					NamedNodeMap sensorAttributeList = sensorElement.getAttributes();
579
				int sensorTypeAttributeCount = sensorAttributeList.getLength();
587
					int sensorTypeAttributeCount = sensorAttributeList.getLength();
580
				
588
					
581
				for(int k = 0; k < sensorTypeAttributeCount; ++k)
589
					for(int k = 0; k < sensorTypeAttributeCount; ++k)
582
				{
583
					Node sensorTypeAttribute = sensorAttributeList.item(k);
584
					String attrName = sensorTypeAttribute.getNodeName();
585
					
586
					// Modify the attribute based on user input
587
					propValue = (String)table.get(attrName);
588
					if(propValue != null && propValue.length() > 0)
589
					{
590
					{
590
						sensorTypeAttribute.setNodeValue(propValue.trim());
591
						Node sensorTypeAttribute = sensorAttributeList.item(k);
592
						String attrName = sensorTypeAttribute.getNodeName();
593
						
594
						// Modify the attribute based on user input
595
						propValue = (String)table.get(attrName);
596
						if(propValue != null && propValue.length() > 0)
597
						{
598
							sensorTypeAttribute.setNodeValue(propValue.trim());
599
						}
591
					}
600
					}
592
				}
593
601
594
				// Check if the directory of the log file to be parsed was updated by modifyConverter 				
602
					// Check if the directory of the log file to be parsed was updated by modifyConverter 				
595
				if (newDirectory != null) {
603
					if (newDirectory != null) {
596
					// If so update it in the config file
604
						// If so update it in the config file
597
					if (directoryPropertyElement != null) {
605
						if (directoryPropertyElement != null) {
598
						directoryPropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, newDirectory);
606
							directoryPropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, newDirectory);
599
					}
607
						}
600
					if (sensorTypeInstance != null) {
608
						if (sensorTypeInstance != null) {
601
						// Set the attribute
609
							// Set the attribute
602
						Node sensorAttribute = sensorTypeInstance.getAttributeNode(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
610
							Node sensorAttribute = sensorTypeInstance.getAttributeNode(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
603
						sensorAttribute.setNodeValue(newDirectory);					
611
							sensorAttribute.setNodeValue(newDirectory);					
612
						}
604
					}
613
					}
614
					
615
					// Check if the name of the log file to be parsed was updated by modifyConverter 				
616
					if (newFileName != null) {
617
						// If so update it in the config file
618
						if (fileNamePropertyElement != null) {
619
							fileNamePropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, newFileName);
620
						}
621
						if (sensorTypeInstance != null) {
622
							// Set the attribute
623
							Node sensorAttribute = sensorTypeInstance.getAttributeNode(AdapterXMLConstants.HyadesGAfileNameAttributeName);
624
							sensorAttribute.setNodeValue(newFileName);					
625
						}	
626
					}					
605
				}
627
				}
606
				
628
				// Else set the properties of the non-sensor components
607
				// Check if the name of the log file to be parsed was updated by modifyConverter 				
629
				else {
608
				if (newFileName != null) {
630
					// Get the property children of the component
609
					// If so update it in the config file
631
					NodeList compProperties = compElement.getElementsByTagName(AdapterXMLConstants.HyadesGAPropertyElementTagName);
610
					if (fileNamePropertyElement != null) {
632
					for (int k = 0; k < compProperties.getLength(); k++) {
611
						fileNamePropertyElement.setAttribute(AdapterXMLConstants.HyadesGASensorPropertyValueAttributeName, newFileName);
633
						propertyElement = (Element) compProperties.item(k);
612
					}
634
						// Set the property's value to the value of the corresponding parameter in the input hash table						
613
					if (sensorTypeInstance != null) {
635
						propName = propertyElement.getAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName);
614
						// Set the attribute
636
						propValue = (String)table.get(propName);
615
						Node sensorAttribute = sensorTypeInstance.getAttributeNode(AdapterXMLConstants.HyadesGAfileNameAttributeName);
637
						if(propValue != null)
616
						sensorAttribute.setNodeValue(newFileName);					
638
						{
617
					}	
639
							System.out.println("Set property " + propName + " with value " + propValue);
640
							propertyElement.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, propValue.trim());
641
						}
642
					}
618
				}
643
				}
619
			}
644
			}
620
		}
645
		}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/GLALoggerFactory.java (+88 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: GLALoggerFactory.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.provisional.importer;
14
15
import org.apache.commons.logging.Log;
16
import org.apache.commons.logging.LogConfigurationException;
17
import org.eclipse.hyades.logging.commons.LoggerFactory;
18
19
/**
20
 * This class extends org.eclipse.hyades.logging.commons.LoggerFactory
21
 * to instantiate the org.eclpise.hyades.logging.parsers.GLALogger class.
22
 * 
23
 * @see org.apache.commons.logging.LogFactory
24
 * @see org.eclipse.hyades.logging.commons.Logger
25
 * @see org.eclipse.hyades.logging.commons.LoggerFactory
26
 * @see org.eclipse.hyades.logging.parsers.provisional.importer.GLALogger
27
 */
28
public class GLALoggerFactory extends LoggerFactory {
29
30
    /**
31
     * No-argument constructor.
32
     */
33
    public GLALoggerFactory() {
34
        super();
35
    }
36
37
    /**
38
     * Returns an instance of a non-null named
39
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code> based on the
40
     * parameter name.
41
     * <p>
42
     * Passing a <code>null</code> logger name results in a <code>null</code>
43
     * return value.
44
     * <p>
45
     * An instance of a named
46
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code> is created if no
47
     * named instance current exists or all instances have been released.
48
     * <p>
49
     * Once a named <code>org.eclipse.hyades.logging.parsers.GLALogger</code> is
50
     * created, the instance is cached for future calls to retrieve the same
51
     * named <code>org.eclipse.hyades.logging.parsers.GLALogger</code>.
52
     * <p>
53
     * The name of the <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
54
     * uniquely identifies an instance of an
55
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code>. All subsequent
56
     * calls will return the same instance of the named
57
     * <code>org.eclipse.hyades.logging.parsers.GLALogger</code>.
58
     * <p>
59
     * 
60
     * @param loggerName
61
     *            The non-null name of the returned
62
     *            <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
63
     *            instance.
64
     * @return A named <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
65
     *         instance, otherwise <code>null</code> if the parameter logger
66
     *         name is <code>null</code>.
67
     * @exception LogConfigurationException
68
     *                if the named
69
     *                <code>org.eclipse.hyades.logging.parsers.GLALogger</code>
70
     *                instance could not be created.
71
     * @see org.apache.commons.logging.LogFactory#getInstance(java.lang.String)
72
     */
73
    public Log getInstance(String loggerName) throws LogConfigurationException {
74
75
        if (loggerName != null) {
76
77
            if (loggers.containsKey(loggerName)) { return (((Log) (loggers.get(loggerName)))); }
78
79
            GLALogger logger = new GLALogger(loggerName);
80
81
            loggers.put(loggerName, logger);
82
83
            return logger;
84
        }
85
86
        return null;
87
    }
88
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/LocalLogImportLoader.java (+179 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors: 
9
 * IBM - Initial API and implementation
10
 * 
11
 * Change History:
12
 **********************************************************************/
13
package org.eclipse.hyades.logging.parsers.provisional.importer;
14
15
import java.util.Hashtable;
16
17
import org.apache.commons.logging.Log;
18
import org.eclipse.hyades.loaders.util.XMLLoader;
19
import org.eclipse.hyades.logging.parsers.LogParserException;
20
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
21
22
/**
23
 * 
24
 * This is a specialized logger to be used by GLA for local log imports.  It is
25
 * instantiated by clients and passed to GLA via ParserWrapper.parse(Log) method.
26
 * Currently it is available internally only for use by the Log Import Wizard in
27
 * org.eclipse.tptp.monitoring.logui
28
 * 
29
 * @author Cindy Jin
30
 *
31
 */
32
public class LocalLogImportLoader  implements Log {
33
34
35
    protected Hashtable parserParameters = null;
36
    protected ILogParser parser = null;
37
    protected XMLLoader xmlLoader = null;
38
    protected Log logParser = null;
39
    protected boolean traceXML = false;
40
41
    /**
42
	 * Trace logging level value.
43
	 */
44
	public static final int TRACE_LEVEL = 0;
45
46
	/**
47
	 * Debug logging level value.
48
	 */
49
	public static final int DEBUG_LEVEL = 1;
50
51
	/**
52
	 * Information logging level value.
53
	 */
54
	public static final int INFO_LEVEL = 2;
55
56
	/**
57
	 * Warning logging level value.
58
	 */
59
	public static final int WARN_LEVEL = 3;
60
61
	/**
62
	 * Error logging level value.
63
	 */
64
	public static final int ERROR_LEVEL = 4;
65
66
	/**
67
	 * Fatal logging level value.
68
	 */
69
	public static final int FATAL_LEVEL = 5;
70
71
	/**
72
	 * The logger's current logging level value.
73
	 */
74
	protected int loggingLevel;
75
	public LocalLogImportLoader()
76
	{
77
		parser           = null;
78
		parserParameters = null;
79
	}
80
81
    public LocalLogImportLoader(ILogParser parser, Hashtable parserParameters, boolean traceXML) {
82
        this.parser = parser;
83
        this.parserParameters = parserParameters;
84
        this.traceXML = traceXML;
85
    }
86
87
    public void setXMLLoader(XMLLoader xmlLoader) {
88
    	 parserParameters.put("xmlLoader", xmlLoader);
89
        this.xmlLoader = xmlLoader;
90
    }
91
    
92
     
93
    public void startParsing() throws LogParserException {
94
        parser.setUserInput(parserParameters);
95
        parser.parse(this);
96
    }
97
    public void setParserLogger(Log logParser){
98
    	this.logParser = logParser;
99
    	parser.setParserLogger(logParser); 
100
    }
101
    
102
    public Log getParserLogger(){
103
    	return logParser;
104
    }
105
106
    public XMLLoader getXMLLoader()
107
    {
108
    	return xmlLoader;
109
    }
110
    
111
	public boolean isTraceEnabled() {
112
		return (loggingLevel<=TRACE_LEVEL);
113
	}
114
115
	public boolean isDebugEnabled() {
116
		return (loggingLevel<=DEBUG_LEVEL);
117
	}
118
119
120
	public boolean isInfoEnabled() {
121
		return (loggingLevel<=INFO_LEVEL);
122
	}
123
124
	public boolean isWarnEnabled() {
125
		return (loggingLevel<=WARN_LEVEL);
126
	}
127
128
	public boolean isErrorEnabled() {
129
		return (loggingLevel<=ERROR_LEVEL);
130
	}
131
132
	public boolean isFatalEnabled() {
133
		return (loggingLevel<=FATAL_LEVEL);
134
	}
135
136
	 
137
	public void trace(Object record) {
138
	}
139
140
	public void trace(Object record, Throwable throwable) {
141
	}
142
143
	public void debug(Object record) {
144
	}
145
146
	public void debug(Object record, Throwable throwable) {
147
	}
148
149
	public void info(Object record) {
150
	}
151
152
	public void info(Object record, Throwable throwable) {
153
	}
154
155
156
	public void warn(Object record) {
157
	}
158
159
	public void warn(Object record, Throwable throwable) {
160
	}
161
162
	public void error(Object record) {
163
	}
164
165
	public void error(Object record, Throwable throwable) {
166
	}
167
168
169
	public void fatal(Object record) {
170
171
	}
172
173
174
	public void fatal(Object record, Throwable throwable) {
175
176
	}
177
	
178
	
179
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/LocalGLALogger.java (+203 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2006,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalGLALogger.java,v 1.2 2006/09/20 19:20:23 dnsmith Exp $
8
 *
9
 * Contributors:
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.provisional.importer;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.apache.commons.logging.Log;
19
import org.eclipse.hyades.logging.events.cbe.CommonBaseEvent;
20
21
public class LocalGLALogger implements Log {
22
23
	//private XmlGenerator xmlGenerator = new XmlGenerator();
24
	private List events = new ArrayList();
25
	private  final String NL = System.getProperties().getProperty("line.separator");
26
	
27
	private String detailMessage = null;
28
29
	/**
30
	 * Trace logging level value.
31
	 */
32
	public static final int TRACE_LEVEL = 0;
33
34
	/**
35
	 * Debug logging level value.
36
	 */
37
	public static final int DEBUG_LEVEL = 1;
38
39
	/**
40
	 * Information logging level value.
41
	 */
42
	public static final int INFO_LEVEL = 2;
43
44
	/**
45
	 * Warning logging level value.
46
	 */
47
	public static final int WARN_LEVEL = 3;
48
49
	/**
50
	 * Error logging level value.
51
	 */
52
	public static final int ERROR_LEVEL = 4;
53
54
	/**
55
	 * Fatal logging level value.
56
	 */
57
	public static final int FATAL_LEVEL = 5;
58
59
	/**
60
	 * The logger's current logging level value.
61
	 */
62
	private int loggingLevel;
63
64
	public LocalGLALogger() {
65
		//xmlGenerator.reset(null, true, 8);
66
		loggingLevel = 0;
67
	}
68
69
	public String getLogDetails() {
70
		StringBuffer buffer = new StringBuffer();
71
		synchronized(events){
72
			int s = events.size();
73
			String msg = null;
74
			if(s>0){
75
				for(int i=0;i<s-1;i++){
76
					msg = (String)events.get(i);
77
					if(msg!=null){
78
						buffer.append(msg);				
79
						buffer.append(NL);
80
					}			
81
				}
82
				msg = (String)events.get(s-1);
83
				if(msg!=null){
84
					buffer.append(msg);
85
				}
86
			}
87
		}
88
		detailMessage = buffer.toString();
89
		return detailMessage;
90
	}
91
92
	public boolean isDebugEnabled() {
93
		return (loggingLevel <= DEBUG_LEVEL);
94
	}
95
96
	public boolean isErrorEnabled() {
97
		return (loggingLevel <= ERROR_LEVEL);
98
	}
99
100
	public boolean isFatalEnabled() {
101
		return (loggingLevel <= FATAL_LEVEL);
102
	}
103
104
	public boolean isInfoEnabled() {
105
		return (loggingLevel <= INFO_LEVEL);
106
	}
107
108
	public boolean isTraceEnabled() {
109
		return (loggingLevel <= TRACE_LEVEL);
110
	}
111
112
	public boolean isWarnEnabled() {
113
		return (loggingLevel <= WARN_LEVEL);
114
	}
115
116
	public void trace(Object record) {
117
		if (isTraceEnabled()) {
118
			synchronized(events){
119
				if(record!=null && record instanceof CommonBaseEvent)
120
				if(((CommonBaseEvent)record).getMsg()!=null && !events.contains(((CommonBaseEvent)record).getMsg())){
121
					events.add(((CommonBaseEvent)record).getMsg());
122
				}
123
			}
124
//			this.detailMessage = xmlGenerator.objectToXML(record);
125
//			logXMLToModel(xmlGenerator.objectToXML(record));
126
		}
127
128
	}
129
130
	public void trace(Object record, Throwable arg1) {
131
		if (isTraceEnabled()) {
132
			trace(record);
133
//			logXMLToModel(xmlGenerator.objectToXML(record));
134
		}
135
136
	}
137
138
	public void debug(Object record) {
139
		if (isDebugEnabled()) {
140
			trace(record);
141
//			logXMLToModel(xmlGenerator.objectToXML(record));
142
		}
143
	}
144
145
	public void debug(Object record, Throwable arg1) {
146
		if (isDebugEnabled()) {
147
//			logXMLToModel(xmlGenerator.objectToXML(record));
148
		}
149
150
	}
151
152
	public void info(Object record) {
153
		if (isInfoEnabled()) {
154
//			logXMLToModel(xmlGenerator.objectToXML(record));
155
		}
156
157
	}
158
159
	public void info(Object record, Throwable arg1) {
160
		if (isInfoEnabled()) {
161
//			logXMLToModel(xmlGenerator.objectToXML(record));
162
		}
163
164
	}
165
166
	public void warn(Object record) {
167
		if (isWarnEnabled()) {
168
//			logXMLToModel(xmlGenerator.objectToXML(record));
169
		}
170
171
	}
172
173
	public void warn(Object record, Throwable arg1) {
174
		if (isWarnEnabled()) {
175
//			logXMLToModel(xmlGenerator.objectToXML(record));
176
		}
177
	}
178
179
	public void error(Object record) {
180
		if (isErrorEnabled()) {
181
//			logXMLToModel(xmlGenerator.objectToXML(record));
182
		}
183
	}
184
185
	public void error(Object record, Throwable arg1) {
186
		if (isErrorEnabled()) {
187
//			logXMLToModel(xmlGenerator.objectToXML(record));
188
		}
189
	}
190
191
	public void fatal(Object record) {
192
		if (isFatalEnabled()) {
193
//			logXMLToModel(xmlGenerator.objectToXML(record));
194
		}
195
	}
196
197
	public void fatal(Object record, Throwable arg1) {
198
		if (isFatalEnabled()) {
199
//			logXMLToModel(xmlGenerator.objectToXML(record));
200
		}
201
	}
202
203
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/StatusMonitor.java (+87 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: StatusMonitor.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.logging.parsers.provisional.importer;
13
14
import org.apache.commons.logging.Log;
15
16
/**
17
 * This class is a runnable that checks the status of a log parser
18
 * at regular intervals and sends the status to a logging agent.
19
 */
20
public class StatusMonitor implements Runnable {
21
22
	// Class of the parser object
23
	private Class parserClass = null;
24
	
25
	// The parser object
26
	private Object parser = null;
27
	
28
	// The logging agent to write the status to.
29
	private Log statusLogger = null;
30
	
31
	/**
32
	 * Constructor with required parameters
33
	 * @param parser object that is doing the log parsing
34
	 * @param parserClass class of the parser object
35
	 * @param statusLogger logging agent to write the status to
36
	 */
37
	public StatusMonitor(Object parser, Class parserClass, Log statusLogger) {
38
		super();
39
		
40
		this.parser = parser;
41
		this.parserClass = parserClass;
42
		this.statusLogger = statusLogger;
43
	}
44
45
	/**
46
	 * Run this StatusMonitor thread.
47
	 * @see java.lang.Runnable#run()
48
	 */
49
	public void run() {
50
		String status = null;
51
		
52
		// Status checking loop.
53
		while (true) {
54
			try {
55
				// Get the status of the parsing object.
56
				status = (String)parserClass.getMethod("getStatus",null).invoke(parser, null);
57
			}
58
			catch (Exception e) {
59
				System.err.println("Exception occured when getting status: " + e.getMessage());
60
				status = null;
61
			}
62
			// write status string to status agent
63
			if (status != null) {
64
				statusLogger.trace(status);
65
			}
66
			
67
			// If this thread has been interrupted then quit the monitoring loop.
68
			if (Thread.interrupted()) {
69
				break;
70
			}
71
			
72
	   		/* Sleep for 2 seconds before checking the status again.
73
    		 * The parsing thread may interrupt this thread to indicate it is done so break
74
    		 * from the monitoring loop.
75
    		 */
76
            try {
77
            	Thread.sleep(2000);
78
            }
79
            catch (InterruptedException e) {
80
            	// Quit the monitoring loop if this thread has been interrupted
81
            	break;
82
            }
83
		}
84
85
	}
86
87
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/GLAHelper.java (+501 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.provisional.importer;
14
15
import java.io.File;
16
import java.lang.reflect.Constructor;
17
import java.lang.reflect.InvocationTargetException;
18
import java.lang.reflect.Method;
19
import java.net.MalformedURLException;
20
import java.net.URL;
21
import java.util.Locale;
22
import java.util.Map;
23
import java.util.StringTokenizer;
24
25
import org.eclipse.hyades.logging.adapter.impl.AdapterXMLConstants;
26
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
27
import org.eclipse.hyades.logging.adapter.util.Messages;
28
import org.eclipse.hyades.logging.parsers.LogParserException;
29
import org.eclipse.hyades.logging.parsers.ParserConstants;
30
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
31
32
/**
33
 * Helper class for finding the GLA adapter configuration file.
34
 * 
35
 * @author apnan
36
 *
37
 */
38
public class GLAHelper {
39
40
	protected static short platform = -1;//flag indicating whether the code runs in the workbench or outside the workbench
41
										// the values that this flag can have are:
42
										// -1: GLAHelper wasn't initialized
43
										// 0: GLAHelper runs outside the workbench
44
										// 1: GLAHelper runs in the workbench
45
	
46
	/**
47
	 * Get the adapter configuration file path.
48
	 * @param table the parser parameters hash stable
49
	 * @param nameSpace the plugin name if running in the workbench, null otherwise
50
	 * @param useOriginalAdapter boolean to indicate to use the original adapter file specification
51
	 * stored in the hash table with key originalAdapter
52
	 * @return the adapter file path. 
53
	 * @throws LogParserException
54
	 */
55
	public static synchronized String getAdapterPath(Map table, String nameSpace, boolean useOriginalAdapter) throws LogParserException{
56
		
57
		String key; 
58
		
59
		if (useOriginalAdapter) {
60
			key = LogParserConstants.ORIGINAL_ADAPTER_KEY;
61
		}
62
		else {
63
			key = getAdapterPathKey(table);
64
			if(key==null){
65
				String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)null); 
66
				throw new LogParserException(message);
67
			}
68
			if(GLADebug.INSTANCE.debug){
69
				GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: adapter key="+key);			
70
			}
71
		}
72
		
73
		String config_file = (String)table.get(key);
74
75
		//get the adapter config file path
76
		String adapterFilePath = "";
77
		
78
		if(config_file.indexOf("./")>-1){
79
			config_file = config_file.substring(2);			
80
		}
81
		
82
		/* If running in an eclipse workbench environment then try to get the adapter file
83
		 * path based on the plugin bundle.
84
		 */
85
		if(isWorkbenchMode()){
86
			try {
87
				// Bundle bundle = Platform.getBundle(nameSpace);
88
				Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
89
	            Method getBundle = platformClass.getMethod("getBundle", new Class[]{String.class});
90
	            Object bundle = getBundle.invoke(null, new String[]{nameSpace});
91
	            Class pathClass = Class.forName("org.eclipse.core.runtime.IPath");
92
	            Class bundleClass = Class.forName("org.osgi.framework.Bundle");
93
	            Method find = platformClass.getMethod("find", new Class[]{bundleClass, pathClass});
94
				
95
				if(bundle!=null){
96
					//verify if the adapter is NL enabled
97
					if(config_file.indexOf("/nl/")>-1){
98
						config_file = getNLAdapterPath(table, config_file, find, bundle);
99
						if(config_file==null){
100
							String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)table.get(key)); 
101
							throw new Exception(message);
102
						}
103
						adapterFilePath = config_file; 
104
					}else{				
105
						URL fileURL = find(find, bundle, config_file);
106
						if(fileURL==null){
107
							//config_file = "config/"+config_file;
108
							fileURL = find(find, bundle, "config/"+config_file);
109
						}
110
						if(fileURL!=null){
111
							adapterFilePath = fileURL.toString();
112
						}else{
113
							/* Try using the config file root from the hash table if Log Import Wizard modified the
114
							 * adapter with a filter. */
115
							adapterFilePath = (String) table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) + "/" + config_file;			
116
							File test = new File(adapterFilePath);
117
							if(!test.exists()){
118
								// Couldn't find adapter file so throw an exception
119
								throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file));
120
							}
121
						}
122
					}
123
				}else{
124
					adapterFilePath = config_file; 
125
				}
126
			}
127
			catch (Throwable e) {
128
				// Capture the exception in a LogParserException
129
				throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file),e);
130
			}
131
			
132
		}
133
		/* Else find the adapter file path based on path variables in the hash table */
134
		else{
135
			
136
			//verify if the adapter is NL enabled
137
			if(config_file.indexOf("/nl/")>-1){
138
				if(GLADebug.INSTANCE.debug){
139
					GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: trying to get the nl adapter file using base file "+config_file);			
140
				}
141
				config_file = getNLAdapterPath(table, config_file, null, null);
142
				if(config_file==null){
143
					String message = Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", (String)table.get(key)); 
144
					throw new LogParserException(message);
145
				}
146
				adapterFilePath = config_file; 
147
			}else{
148
				String adapterPath = (String)table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) ;
149
				
150
//				//check to see if the global properties are set
151
//				if (adapterPath == null){
152
//					adapterPath = CBEConfigurationProperties.instance().getProperties().getProperty(CBEConfigurationProperties.ADAPTER_LOCATION);
153
//				}
154
				adapterFilePath = adapterPath + "/" + config_file;
155
				if(GLADebug.INSTANCE.debug){
156
					GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file using ConfigFileRoot path eg. "+adapterFilePath);			
157
				}
158
				File test = new File(adapterFilePath);
159
				if(!test.exists()){
160
					adapterFilePath = adapterPath + "config/"+config_file;
161
					if(GLADebug.INSTANCE.debug){
162
						GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file using ConfigFileRoot path plus config eg. "+adapterFilePath);			
163
					}
164
					test = new File(adapterFilePath);
165
					if(!test.exists()){
166
						// last attempt 
167
						//
168
						// Bug 62317
169
						// Try to resolve the config file using the command line list of directories
170
						//
171
						String config_paths = (String)table.get(LogParserConstants.CONFIG_PATH_KEY); // get the paths containing the adapter files
172
173
						// Check to ensure config_path was set in the input table
174
						// If it is not then throw an appropriate exception.
175
						if (config_paths != null && config_paths.length() != 0) {
176
							StringTokenizer strtok = new StringTokenizer(config_paths, File.pathSeparator, false); // tokenize the path
177
							while(strtok.hasMoreTokens()) {
178
								String config_path = strtok.nextToken();
179
180
								if(GLADebug.INSTANCE.debug){
181
									GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: try to find the adapter file " + config_file + " using config_path "+config_path);			
182
								}
183
								File f = new File(config_path, config_file); // look for the adapter file using the path
184
								if(f.exists()) {									
185
//									table.remove(LogParserConstants.CONFIG_PATH_KEY); // This is no longer required									
186
									adapterFilePath = f.getAbsolutePath();
187
									return adapterFilePath;
188
								}
189
							}
190
						}
191
						// Bug 62317 ends
192
193
						if(GLADebug.INSTANCE.debug){
194
							GLADebug.INSTANCE.log("GLAHelper.getAdapterPath: could not find the adapter file!  Throwing an exception.");			
195
						}
196
						throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", config_file));
197
						
198
					}
199
				}			
200
			}
201
		}		
202
		return adapterFilePath;		
203
	}
204
	/**
205
	 * Initializes the context in which this class is running.
206
	 * Determines whether the code runs in a workbench context or outside. 
207
	 * Calling this method is required before using the adapter path helper method.
208
	 *
209
	 */
210
	protected static synchronized void initialize(){
211
		try {
212
            Class resourcePlugin = Class.forName("org.eclipse.core.resources.ResourcesPlugin");
213
            Method getWorkspace = resourcePlugin.getMethod("getWorkspace", null);
214
            Object workspace = getWorkspace.invoke(null, null);
215
            Method getRoot = workspace.getClass().getMethod("getRoot", null);
216
            Object root = getRoot.invoke(workspace, null);
217
218
            platform =(short)((root != null) ? 1 : 0);
219
        } catch (ClassNotFoundException e) {
220
        	platform = 0;
221
        } catch (SecurityException e) {
222
        	platform = 0;
223
        } catch (NoSuchMethodException e) {
224
        	platform = 0;
225
        } catch (IllegalArgumentException e) {
226
        	platform = 0;
227
        } catch (IllegalAccessException e) {
228
        	platform = 0;
229
        } catch (InvocationTargetException e) {
230
        	platform = 0;
231
        } catch (NullPointerException e) {
232
        	platform = 0;
233
        }
234
	}
235
236
	/**
237
	 * Get the absolute path of the adapter configuration file.
238
	 * @param table the parser parameters hash stable
239
	 * @param nameSpace the plugin name if running in the workbench, null otherwise
240
	 * @param useOriginalAdapter boolean to indicate to use the original adapter file specification
241
	 * stored in the hash table with key originalAdapter
242
	 * @return the absolute path of the adapter file. 
243
	 * @throws LogParserException
244
	 */
245
	public static synchronized String getAbsoluteAdapterPath(Map table, String nameSpace, boolean useOriginalAdapter) throws LogParserException{
246
		String adapterPath = getAdapterPath(table, nameSpace, useOriginalAdapter);
247
		
248
		/* If running in eclipse workbench environment Then the adapter path returned by getAdapterPath may
249
		 * be a URL based on the plugin bundle.  In that case it needs to be converted to an
250
		 * absolute file path.
251
		 */
252
		if(isWorkbenchMode()){
253
			try{
254
				Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
255
	            Method asLocalURL = platformClass.getMethod("asLocalURL", new Class[]{URL.class});
256
	            URL adapterURL = new URL(adapterPath);
257
	            URL absoluteURL = (URL)asLocalURL.invoke(null, new Object[]{adapterURL});
258
	            return absoluteURL.getFile();
259
			}catch (MalformedURLException ue) {
260
				/* Assume that the path returned by getAdapterPath is not a URL but is already an absolute path for
261
				 * the adapter file.  Iit will be returned.
262
				 */
263
			}catch (Throwable e) {
264
				// Capture the exception in a LogParserException
265
				throw new LogParserException(Messages.getString("HyadesGA_CBE_Adapter_No_Config_File_ERROR_", adapterPath),e);
266
			}
267
268
			
269
		}
270
		return adapterPath;
271
	}
272
	/**
273
	 * Get the key that is used to find the adapter configuration file name in the hash table.
274
	 * @param table the parser parameters hash table
275
	 * @return the hash table key corresponding to the adapter file path, null if no adapter
276
	 * file path found.
277
	 */
278
	public static synchronized String getAdapterPathKey(Map table){
279
		String key = null;
280
		String version = (String) (table.get(ParserConstants.APPLICATION_VERSION_KEY));
281
		String config_file = null;
282
		
283
		// If no version attribute given, use default
284
		if(version == null)
285
		{
286
			version = LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY;
287
		}
288
289
		// Get the config file defined for this version
290
		config_file =  (String) (table.get(version));
291
		
292
		if(config_file == null && version != LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY)
293
		{
294
			// Cannot find the corresponding config file, use default
295
			config_file = (String) (table.get(LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY));
296
			
297
			// If the default file is the desired adapter file then set the key to return 
298
			if(config_file != null) { 
299
				key = LogParserConstants.DEFAULT_APPLICATION_VERSION_KEY;
300
			}			
301
		}
302
		else if (config_file != null) {
303
			key = version;
304
		}
305
306
		return key;
307
	
308
	}
309
	
310
	/**
311
	 * 
312
	 * @return boolean whether object is executing in an Eclipse workbench environment
313
	 */
314
	public static synchronized boolean isWorkbenchMode(){
315
		if(platform==-1){
316
			initialize();
317
		}
318
		if(GLADebug.INSTANCE.debug){
319
			GLADebug.INSTANCE.log("workbench="+platform);			
320
		}
321
		
322
		return platform ==1;
323
	}
324
	
325
	/**
326
	 * Get the adapter configuration file path based on locale and encoding.
327
	 * @param table Hash table of input parameters
328
	 * @param configFilePath The adapter configuration file to find.
329
	 * @param find The method to find the file
330
	 * @param bundle - plugin bundle
331
	 * @return the adapter configuration file path
332
	 */
333
	protected static synchronized String getNLAdapterPath(Map table,
334
			String configFilePath, Method find, Object bundle){
335
336
		String characterEncoding = (String) table
337
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_CHARACTER_ENCODING);
338
		String countryCode = (String) table
339
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_ISO_COUNTRY_CODE);
340
		String languageCode = (String) table
341
				.get(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_ISO_LANGUAGE_CODE);
342
343
		String locale = null;
344
		/*
345
		 * bugzilla 135799
346
		 * Get the default system locale and character encoding if the default string is 
347
		 * passed in.
348
		 */
349
		if (languageCode != null && languageCode.equals(AdapterConstants.AttributeValue_Default)) {
350
			languageCode = Locale.getDefault().getLanguage();
351
		}
352
		if (countryCode != null && countryCode.equals(AdapterConstants.AttributeValue_Default)) {
353
			countryCode = Locale.getDefault().getCountry();
354
		}
355
356
		if (characterEncoding != null && characterEncoding.equals(AdapterConstants.AttributeValue_Default)) {
357
			try {
358
				characterEncoding = System.getProperty("file.encoding");
359
			}
360
			catch (SecurityException e) {
361
				/* null file encoding will be handled below */
362
			}
363
		}
364
		if(countryCode!=null && countryCode.length() == 0){
365
			locale = languageCode;
366
		}else if(countryCode!=null && languageCode!=null){
367
			locale = languageCode + "_" + countryCode;
368
		}
369
370
		int i = configFilePath.indexOf("/nl/");
371
		if(GLADebug.INSTANCE.debug){
372
			GLADebug.INSTANCE.log("characterEncoding="+characterEncoding);
373
			GLADebug.INSTANCE.log("countryCode="+countryCode);
374
			GLADebug.INSTANCE.log("languageCode="+languageCode);
375
		}
376
		
377
		// try to find the adapter in the following order
378
		// <root>/nl/<ISOLanguageCode>_<ISOCountryCode>/<characterEncoding>
379
		// <root>/nl/<ISOLanguageCode>_<ISOCountryCode>
380
		// <root>/nl/<characterEncoding>
381
		// <root>/nl/
382
		
383
		String[][] searchPath = new String[][]{{locale, characterEncoding}, {locale}, {characterEncoding}, {"/"}};
384
		if (i < 0) {
385
			return configFilePath;
386
		}
387
		int j = configFilePath.lastIndexOf('/');
388
		String dir = configFilePath.substring(0, i + 3);
389
		String fileName = configFilePath.substring(j);
390
		
391
		StringBuffer path = new StringBuffer();
392
		String[] currentPath = null;
393
		int l = 0;
394
395
		String fullPath = null;
396
		String lastPathAppended = null;
397
		for(int idx=0;idx<4 && fullPath==null;idx++){
398
			currentPath = searchPath[idx];
399
			l = currentPath.length;
400
			path.append(dir);
401
			for(int jdx=0;jdx<l;jdx++){				
402
				if(currentPath[jdx]==null){
403
					continue;
404
				}
405
				if(!currentPath[jdx].equals("/")){
406
					path.append('/');
407
				}
408
				path.append(currentPath[jdx]);
409
				lastPathAppended = currentPath[jdx];
410
			}
411
			if(lastPathAppended!=null && lastPathAppended.equals("/")){
412
				path.append(fileName.substring(1));
413
			}else{
414
				path.append(fileName);
415
			}
416
			fullPath = getPath(table, find, bundle, path.toString());
417
			path.setLength(0);
418
		}
419
420
		return fullPath;
421
	}
422
	
423
	/**
424
	 * Get the full path of the adapter configuration file
425
	 * @param table Hash table of input parameters
426
	 * @param find The method to use to find the URL
427
	 * @param bundle The plugin bundle
428
	 * @param configFilePath
429
	 * @return the full path of the adapter file
430
	 */
431
	protected static synchronized String getPath(Map table, Method find, Object bundle, String configFilePath){
432
		String filePath = null;
433
		if(bundle!=null){
434
			// workbench context mode: local import
435
			URL fileURL = find(find, bundle, configFilePath);
436
			if(fileURL==null){
437
				fileURL = find(find, bundle, "config/"+configFilePath);
438
			}
439
			if (fileURL != null) {
440
				filePath = fileURL.toString();
441
			}
442
		}else{
443
			// outside workbench context: remote import or web client
444
			String adapterPath = (String)table.get(LogParserConstants.CONFIG_FILE_ROOT_KEY) ;
445
			
446
//			//check to see if the global properties are set
447
//			if (adapterPath == null){
448
//				adapterPath = CBEConfigurationProperties.instance().getProperties().getProperty(CBEConfigurationProperties.ADAPTER_LOCATION);
449
//			}
450
			
451
			String adapterFilePath = adapterPath + "/" + configFilePath;
452
			File file = new File(adapterFilePath);
453
			if(file.exists()){
454
				filePath = adapterFilePath;
455
			}else {
456
				String config_paths = (String)table.get(LogParserConstants.CONFIG_PATH_KEY); // get the paths containing the adapter files
457
				if (config_paths != null && config_paths.length() != 0) {
458
					StringTokenizer strtok = new StringTokenizer(config_paths, File.pathSeparator, false); // tokenize the path
459
					while(strtok.hasMoreTokens()) {
460
						String config_path = strtok.nextToken();
461
462
						File f = new File(config_path, configFilePath); // look for the adapter file using the path
463
						if(f.exists()) {
464
							filePath = f.getAbsolutePath();
465
						}
466
					}
467
				}	
468
			}		
469
		}
470
		if(GLADebug.INSTANCE.debug){
471
			GLADebug.INSTANCE.log("GLAHelper.getPath: Attempted to get adapter at path "+configFilePath +" result: file=" +filePath);
472
		}
473
474
		return filePath;
475
	}
476
	
477
	/**
478
	 * Find the URL of the adapter configuration file
479
	 * @param find The method to find the adapter file
480
	 * @param bundle - The plugin bundle
481
	 * @param config_file - the adapter configuration file to find
482
	 * @return the URL of the adapter configuration file
483
	 */
484
	protected static URL find(Method find, Object bundle, String config_file){
485
		URL fileURL = null;
486
		Class pathClass;
487
		try {
488
			pathClass = Class.forName("org.eclipse.core.runtime.Path");
489
			Constructor pathConstructor = pathClass.getConstructor(new Class[] {config_file.getClass()});
490
			Object path = pathConstructor.newInstance(new Object[] {config_file});
491
			fileURL = (URL)find.invoke(null, new Object[]{bundle, path});
492
			
493
		} catch (Exception e) {			
494
			if(GLADebug.INSTANCE.debug)
495
				e.printStackTrace();
496
		}
497
		return fileURL;
498
		
499
	}
500
	
501
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/GLALogger.java (+97 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: GLALogger.java,v 1.1 2005/06/28 19:33:31 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
13
package org.eclipse.hyades.logging.parsers.provisional.importer;
14
15
import org.eclipse.hyades.logging.commons.Logger;
16
import org.eclipse.hyades.logging.events.cbe.CommonBaseEvent;
17
18
/**
19
 * This class extends org.eclipse.hyades.logging.commons.Logger
20
 * so that it only logs the Common Base Event message instead of the
21
 * whole Common Base Event.  This class is used to log GLA messages.
22
 * 
23
 * @see org.apache.commons.logging.Log
24
 * @see org.apache.commons.logging.LogFactory
25
 * @see org.eclipse.hyades.logging.core.LoggingAgent
26
 * @see org.eclipse.hyades.logging.commons.Logger
27
 * @see org.eclipse.hyades.logging.commons.LoggerFactory
28
 */
29
public class GLALogger extends Logger {
30
31
    /**
32
     * Constructor to create a logger instance with a Logging Agent using the
33
     * parameter name.
34
     * 
35
     * NOTE: The default logging level is set to WARN until explicitly set.
36
     * 
37
     * @param name
38
     *            The name of the newly created logger.
39
     */
40
    public GLALogger(String name) {
41
42
        super(name);
43
 
44
    }
45
46
    /**
47
     * Logs the parameter <code>java.lang.Object</code> log record to the
48
     * Logging Agent with the same name as the logger if TRACE logging is
49
     * currently enabled.
50
     * 
51
     * If the log record is a CommonBaseEvent only the CommonBaseEvent message will be 
52
     * sent to the Logging Agent.  Otherwise it is assumed the record is a String.
53
     * 
54
     * @param record
55
     *            The log record to be logged to the Logging Agent.
56
     */
57
    public void trace(Object record) {
58
59
        if (isTraceEnabled()) {
60
        	if (record instanceof CommonBaseEvent) {
61
        		loggingAgent.write("glalog=" + ((CommonBaseEvent)record).getMsg());
62
        	}
63
        	else if (record instanceof String) {
64
        		loggingAgent.write((String)record);
65
        	}
66
        }
67
    }
68
69
    /**
70
     * Logs the parameter <code>java.lang.Object</code> log record and
71
     * <code>java.lang.Throwable</code> exception to the Logging Agent with
72
     * the same name as the logger if TRACE logging is currently enabled.
73
     * 
74
     * If the log record is a CommonBaseEvent only the CommonBaseEvent message will be 
75
     * sent to the Logging Agent.  Otherwise it is assumed the record is a String.
76
     * 
77
     * Only the parameter <code>java.lang.Object</code> log record is logged.
78
     * The <code>java.lang.Throwable</code> exception is ignored.
79
     * 
80
     * @param record
81
     *            The log record to be logged to the Logging Agent.
82
     * @param throwable
83
     *            The exception will be ignored
84
     */
85
    public void trace(Object record, Throwable throwable) {
86
87
        if (isTraceEnabled()) {
88
           	if (record instanceof CommonBaseEvent) {
89
        		loggingAgent.write("glalog=" + ((CommonBaseEvent)record).getMsg());
90
        	}
91
        	else if (record instanceof String) {
92
        		loggingAgent.write((String)record);
93
        	}
94
        }
95
    }
96
97
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/GLADebug.java (+123 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005,2008 IBM Corporation and others. All rights reserved. This program and the
3
 * accompanying materials are made available under the terms of the Eclipse
4
 * Public License v1.0 which accompanies this distribution, and is available at
5
 * http://www.eclipse.org/legal/epl-v10.html
6
 * $Id
7
 * 
8
 * Contributors: IBM - Initial API and implementation
9
 ******************************************************************************/
10
11
package org.eclipse.hyades.logging.parsers.provisional.importer;
12
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.lang.reflect.Method;
17
import java.util.Date;
18
19
/**
20
 * This class provides debugging facilities for the Log Import code.
21
 * 
22
 * @author apnan
23
 *
24
 */
25
public class GLADebug {
26
27
	public boolean debug = false;
28
	public boolean logToFile = false;
29
	
30
	protected String plugin_name; 
31
	protected String value;
32
	protected final String NL = System.getProperties().getProperty("line.separator");
33
	private FileOutputStream log = null;
34
35
	public static GLADebug INSTANCE = new GLADebug("org.eclipse.hyades.logging.parsers");
36
37
	public GLADebug(String plugin_name) {
38
		this.plugin_name = plugin_name;
39
		init();
40
	}
41
42
	/**
43
	 * Initialize the debugging code.
44
	 *
45
	 */
46
	protected void init() {
47
		try {
48
			// Get the debugging options from the options file.		
49
			Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
50
            Method getDebugOption = platformClass.getMethod("getDebugOption", new Class[]{String.class});
51
            value = (String)getDebugOption.invoke(null, new String[]{plugin_name+"/debug"});
52
			
53
			if (value != null) {
54
				debug = value.equalsIgnoreCase("true");
55
			} else if(System.getProperty("GLADebug.debug")!=null)
56
			{
57
					debug = Boolean.valueOf(System.getProperty("GLADebug.debug")).booleanValue();
58
			}
59
			value = (String)getDebugOption.invoke(null, new String[]{plugin_name+"/logToFile"});
60
			if (value != null) {
61
				logToFile = value.equalsIgnoreCase("true");
62
			} else if(System.getProperty("GLADebug.logToFile")!=null)
63
			{
64
				logToFile = Boolean.valueOf(System.getProperty("GLADebug.logToFile")).booleanValue();
65
			}
66
			
67
			
68
		} catch (Exception e) {
69
			//	The platform is not available, read the environment variables
70
			debug = Boolean.valueOf(System.getProperty("GLADebug.debug")).booleanValue();
71
			logToFile = Boolean.valueOf(System.getProperty("GLADebug.logToFile")).booleanValue();
72
		}		
73
	}
74
	
75
	/**
76
	 * Get the debug log file output stream.
77
	 * 
78
	 * @return the FileOutputStream for the debug file
79
	 */
80
	public FileOutputStream getLog(){
81
		if(log==null){
82
			try {
83
				log = new FileOutputStream("./GLADebug-"+(new Date()).getTime());
84
			} catch (FileNotFoundException e) {
85
				if(debug)
86
					e.printStackTrace();
87
			}
88
		}else{
89
			if(!log.getChannel().isOpen())
90
			{
91
				try {
92
					log = new FileOutputStream("./GLADebug-"+(new Date()).getTime());					
93
				} catch (FileNotFoundException e) {
94
					if(debug)
95
						e.printStackTrace();
96
				}
97
			}
98
			
99
		}
100
		return log;
101
	}
102
	
103
	/**
104
	 * Log a debug message
105
	 * @param message
106
	 */
107
	public void log(String message){
108
		if(logToFile){
109
			// Log the message to the log file.
110
			try {
111
				getLog().write(message.getBytes());
112
				getLog().write(NL.getBytes());
113
			} catch (IOException e) {			
114
				if(debug)	
115
					e.printStackTrace();
116
			}
117
		}else{
118
			// Log the message to System.out
119
			System.out.println(message);
120
		}
121
	}
122
	
123
}
(-)src.import/org/eclipse/hyades/logging/parsers/provisional/importer/LocalLogParserLoader.java (+246 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: LocalLogParserLoader.java,v 1.1 2006/08/23 21:17:51 sleeloy Exp $
8
 *
9
 * Contributors:
10
 * IBM - Initial API and implementation
11
 **********************************************************************/
12
package org.eclipse.hyades.logging.parsers.provisional.importer;
13
14
import java.io.UnsupportedEncodingException;
15
import java.util.Hashtable;
16
17
import org.apache.commons.logging.Log;
18
import org.eclipse.hyades.internal.logging.core.Constants;
19
import org.eclipse.hyades.logging.events.cbe.util.EventFormatter;
20
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
21
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
22
23
public class LocalLogParserLoader extends LocalLogImportLoader{
24
25
    //~ Constructors -------------------------------------------------------------------------------
26
27
    public LocalLogParserLoader(ILogParser parser, Hashtable parserParameters, boolean traceXML) {
28
    	super(parser, parserParameters, traceXML);
29
    	loggingLevel=0;
30
    }
31
32
    //~ Methods ------------------------------------------------------------------------------------
33
34
    
35
    public Log getParserLogger(){
36
    	return logParser;
37
    }
38
39
    //NOTE: Temporary API to propagate logged raw objects to the model as XML strings:
40
    private void logXMLToModel(String xml) {
41
        // Note:  L0DocumentEventHandler (perftrace.loader.XMLLoader) XML scanner MUST be passed UTF8 encoded byte array data:
42
        byte[] xmlLogEntryBytes = null;
43
44
        try {
45
            xmlLogEntryBytes = xml.getBytes("UTF8");
46
        }
47
        catch (UnsupportedEncodingException u) {
48
            xmlLogEntryBytes = xml.getBytes();
49
        }
50
51
        //		System.err.println(xml);
52
        xmlLoader.loadEvent(xmlLogEntryBytes, xmlLogEntryBytes.length);
53
    }
54
    
55
	/**
56
	 * Logs the parameter <code>java.lang.Object</code> log record to the Logging Agent 
57
	 * with the same name as the logger if TRACE logging is currently enabled.  
58
	 * 
59
	 * The log record is first converted to XML and then sent to the Logging Agent.
60
	 * 
61
	 * @param record The log record to be logged to the Logging Agent.
62
	 */
63
64
	public void trace(Object record) {
65
//		try {
66
			if (isTraceEnabled()) {
67
				if(!traceXML){
68
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
69
				}else{
70
					logXMLToModel((String)record);
71
				}
72
			}
73
//		}
74
//		catch (Throwable t) {
75
//		}
76
77
	}
78
79
	public void trace(Object record, Throwable throwable) {
80
//		try {
81
			if (isTraceEnabled()) {
82
				if(!traceXML){
83
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
84
				}else{
85
					logXMLToModel((String)record);
86
				}
87
			}
88
//		}
89
//		catch (Throwable t) {
90
//		}
91
92
	}
93
94
	public void debug(Object record) {
95
//		try {
96
			if (isDebugEnabled()) {
97
				if(!traceXML){
98
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
99
				}else{
100
					logXMLToModel((String)record);
101
				}
102
			}
103
//		}
104
//		catch (Throwable t) {
105
//		}
106
107
	}
108
109
	public void debug(Object record, Throwable throwable) {
110
//		try {
111
			if (isDebugEnabled()) {
112
				if(!traceXML){
113
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
114
				}else{
115
					logXMLToModel((String)record);
116
				}
117
			}
118
//		}
119
//		catch (Throwable t) {
120
//		}
121
122
	}
123
124
	public void info(Object record) {
125
//		try {
126
			if (isInfoEnabled()) {
127
				if(!traceXML){
128
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
129
				}else{
130
					logXMLToModel((String)record);
131
				}
132
			}
133
//		}
134
//		catch (Throwable t) {
135
//		}
136
137
	}
138
139
	public void info(Object record, Throwable throwable) {
140
141
//		try {
142
			if (isInfoEnabled()) {
143
				if(!traceXML){
144
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
145
				}else{
146
					logXMLToModel((String)record);
147
				}
148
			}
149
//		}
150
//		catch (Throwable t) {
151
//		}
152
	}
153
154
155
	public void warn(Object record) {
156
//		try {
157
			if (isWarnEnabled()) {
158
                if(!traceXML){	
159
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
160
                }else{
161
                	logXMLToModel((String)record);
162
                }
163
			}
164
//		}
165
//		catch (Throwable t) {
166
//		}
167
	}
168
169
	public void warn(Object record, Throwable throwable) {
170
//		try {
171
			if (isWarnEnabled()) {
172
				if(!traceXML){
173
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
174
				}else{
175
					logXMLToModel((String)record);
176
				}
177
			}
178
//		}
179
//		catch (Throwable t) {
180
//		}
181
	}
182
183
	public void error(Object record) {
184
//		try {
185
			if (isErrorEnabled()) {
186
				if(!traceXML){
187
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
188
				}else{
189
					logXMLToModel((String)record);
190
				}
191
			}
192
//		}
193
//		catch (Throwable t) {
194
//		}
195
	}
196
197
	public void error(Object record, Throwable throwable) {
198
199
//		try {
200
			if (isErrorEnabled()) {
201
				if(!traceXML){
202
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
203
				}else{
204
					logXMLToModel((String)record);
205
				}
206
			}
207
//		}
208
//		catch (Throwable t) {
209
//		}
210
	}
211
212
213
	public void fatal(Object record) {
214
//		try {
215
			if (isFatalEnabled()) {
216
				if(!traceXML){
217
                	logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
218
				}else{
219
					logXMLToModel((String)record);
220
				}
221
			}
222
//		}
223
//		catch (Throwable t) {
224
//		}
225
	}
226
227
228
	public void fatal(Object record, Throwable throwable) {
229
230
//		try {
231
			if (isFatalEnabled()) {
232
				if(!traceXML){
233
					logXMLToModel(EventFormatter.toCanonicalXMLString(EventHelpers.convertObjectToCommonBaseEvent(record,4), true).concat(Constants.LINE_SEPARATOR));
234
				}else{
235
					logXMLToModel((String)record);
236
				}
237
			}
238
//		}
239
//		catch (Throwable t) {
240
//		}
241
	}
242
243
244
}
245
   
246
(-)src/org/eclipse/hyades/logging/adapter/internal/util/Controller.java (-1184 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Controller.java,v 1.9 2007/03/22 05:29:24 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 * 
12
 * Change History:
13
 * Bugzilla  Description
14
 * 79014     Improved error handling and message logging
15
 * 
16
 **********************************************************************/
17
package org.eclipse.hyades.logging.adapter.internal.util;
18
19
import java.io.FileInputStream;
20
import java.io.FileNotFoundException;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.util.Iterator;
24
import java.util.List;
25
26
import javax.xml.parsers.DocumentBuilderFactory;
27
import javax.xml.parsers.ParserConfigurationException;
28
29
import org.eclipse.hyades.logging.adapter.AdapterException;
30
import org.eclipse.hyades.logging.adapter.AdapterInvalidConfig;
31
import org.eclipse.hyades.logging.adapter.AdapterPlugin;
32
import org.eclipse.hyades.logging.adapter.IComponent;
33
import org.eclipse.hyades.logging.adapter.IContext;
34
import org.eclipse.hyades.logging.adapter.IContextListener;
35
import org.eclipse.hyades.logging.adapter.IOutputter;
36
import org.eclipse.hyades.logging.adapter.IProcessUnit;
37
import org.eclipse.hyades.logging.adapter.impl.AdapterContext;
38
import org.eclipse.hyades.logging.adapter.impl.AdapterXMLConstants;
39
import org.eclipse.hyades.logging.adapter.impl.Component;
40
import org.eclipse.hyades.logging.adapter.impl.Context;
41
import org.eclipse.hyades.logging.adapter.impl.Status;
42
import org.eclipse.hyades.logging.adapter.parsers.PreparationException;
43
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
44
import org.eclipse.hyades.logging.adapter.util.AdapterUtilities;
45
import org.eclipse.hyades.logging.adapter.util.Messages;
46
import org.w3c.dom.Document;
47
import org.w3c.dom.Element;
48
import org.w3c.dom.Node;
49
import org.w3c.dom.NodeList;
50
import org.xml.sax.SAXException;
51
/**
52
 * Controller manages a set of Context objects by setting the configurations and then starting each context.
53
 * 
54
 */
55
public class Controller implements Runnable {
56
   
57
    private boolean singleFileInputMode = false;
58
    
59
    /* Keep our contexts and thier associated threads within a list. It is imperative that the index
60
     *  of each list be kept consistant.  That is, the thread running context at index n must be in the
61
     *  thread list at index n
62
     */
63
    private Context[] contexts;
64
    private Thread[]   contextThreads;
65
    
66
  	// Adapter log outputter component
67
    private IOutputter logOutputter = null;
68
    
69
    private String contextConfigurationFile = AdapterConstants.HyadesGADefaultContextConfigurationFile;
70
    private String componentConfigurationFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile;
71
    private DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
72
    private InputStream inContextParams = null;
73
    private InputStream inAppParams = null;
74
    private boolean running = false;
75
    private long sleepTime = 500;
76
77
    // Overall logging level for the Adapter
78
    private short loggingLevel = -1;
79
    /**
80
     * Constructor for Controller.
81
     */
82
    public Controller() {
83
        super();
84
    }
85
    
86
    /**
87
     * Returns whether the Controller is running.
88
     * @return true if Controller is running, false otherwise
89
     */
90
    public boolean isRunning() {
91
        return running;
92
    }
93
    
94
    /**
95
     * Start running the controller which means starting up each of the contexts.
96
     */
97
    public void start() {
98
    	/* RKD:  We will run all of the contexts except the first one 
99
    	 * (our internal logging context), each in its own thread.
100
    	 * The internal logging context was already started
101
    	 * when we went through the prepare stage.
102
         */
103
    	synchronized(contexts) {
104
	        for (int i = 1; i < contextThreads.length; ++i) {
105
	            if (contexts[i] != null && !contexts[i].isDisabled()) {
106
	            	contextThreads[i]=new Thread(contexts[i]);
107
	            	contextThreads[i].setName(contexts[i].getName() + AdapterConstants.HyadesGA + contexts[i].getUniqueID());
108
	            	contextThreads[i].setDaemon(true);
109
	            	contextThreads[i].start();
110
	            }
111
	        }
112
    	}
113
        running = true;
114
    }
115
    
116
    /**
117
     * Stop the controller which means stopping all of the contexts if they
118
     * are still running.
119
     */
120
    public void stop() {
121
122
	    if (contexts != null && contextThreads != null) {
123
	       	synchronized(contexts) {
124
	       	    int contextStopCount = 0;
125
	       	    /* stop them in reverse order so that the logging context gets stopped last */        	
126
	            for (int i=contexts.length-1; i>0; i--) {
127
	 				/* bugzilla 74713 - set stopping flag instead of calling Context.stop() because
128
					 * we're running in a different thread than the context.  Also, only stop the
129
					 * context if the context thread is still alive
130
					 */
131
	                if (contexts[i] != null && contextThreads.length > i && contextThreads[i] != null  && contextThreads[i].isAlive()) {
132
	                    contexts[i].setStopping(true);
133
	                    contextStopCount++;
134
	                }
135
	            }
136
		        /* If other contexts are stopping Then sleep before stopping 
137
		         * the logging context to allow the other contexts
138
	    	     * to log messages and end.
139
	             * bugzilla 91218 - only sleep if there are contexts in the
140
	             * process of stopping.
141
	    		 */
142
	            if (contextStopCount > 0) {
143
	            	try {
144
	            		Thread.sleep(1500);
145
	            	}
146
	            	catch (InterruptedException e) {
147
	            	
148
	            	}
149
	            }
150
	            // Stop the logging context.
151
	            if (contexts[0] != null && contextThreads.length > 0 && contextThreads[0] != null  && contextThreads[0].isAlive()) {
152
	                contexts[0].setStopping(true);
153
	                // Wait until logging context is finished
154
	                while (contextThreads[0] != null  && contextThreads[0].isAlive()) {
155
	                	try {
156
		            		Thread.sleep(200);
157
		            		// System.out.println("Waited a fifth of a second for logging context to end");
158
		            	}
159
		            	catch (InterruptedException e) {
160
		            	
161
		            	}
162
	                }
163
	            }
164
	    	}
165
    	}
166
        running = false;
167
    }
168
    
169
	/**
170
	 * This stop method will still cause the contexts to be stopped but will
171
	 * not call the context listener methods when flushing the components.
172
	 */    
173
	public void hardStop() {
174
		synchronized(contexts) {
175
			if (contexts != null && contextThreads != null)
176
				/* stop them in reverse order so that the logging context gets stopped last */
177
				for (int i=contexts.length-1; i>=0; i--) {
178
					/* bugzilla 74713 - set hard stop flag instead of calling Context.stop() because
179
					 * we're running in a different thread than the context.  Also, only stop the
180
					 * context if the context thread is still alive
181
					 */
182
					if (contexts[i] != null && contextThreads.length > i && contextThreads[i] != null && contextThreads[i].isAlive()) {
183
						// Set hardStop flag to stop the context
184
						contexts[i].setHardStop();
185
					}
186
				}
187
		}
188
		running = false;
189
	}
190
    
191
	/**
192
	 * Get the set of Context objects
193
	 * @return the set of Context objects
194
	 */
195
    public IContext[] getContexts() {
196
    	synchronized(contexts) {
197
	    	// Ensure the contexts have been created
198
	    	if (contexts == null || contexts.length <= 1) {
199
	    		return null;
200
	    	}
201
			// Exclude the internal logging context
202
			IContext newContextSet[] = new IContext[contexts.length-1];
203
			for (int i=1; i < contexts.length; i++) {
204
				newContextSet[i-1] = contexts[i];
205
			}
206
			return newContextSet;
207
    	}
208
    }
209
    
210
    /**
211
     * Set the name of the file containing the configurations for the
212
     * contexts.
213
     * @param config - name of the context configuation file
214
     */
215
    public void setContextConfigPath(String config) {
216
        contextConfigurationFile = config;
217
    }
218
    
219
	/**
220
	 * Get the name of the file containing the configurations for the contexts
221
	 * @return the contextConfigurationFile
222
	 */
223
	public String getContextConfigPath() {
224
		return contextConfigurationFile;
225
	}
226
227
	/**
228
     * Set the name of the file containing the configurations for the
229
     * components of the contexts.
230
     * @param config - name of the component configuation file
231
     */
232
    public void setComponentConfigPath(String config) {
233
        componentConfigurationFile = config;
234
    }
235
236
    /**
237
     * Get the name of the file containing the configurations for the components of the contexts.
238
	 * @return the componentConfigurationFile
239
	 */
240
	public String getComponentConfigPath() {
241
		return componentConfigurationFile;
242
	}
243
244
    /*
245
     * Validates an adapter file against the schema files.
246
     */
247
    private void validateAdapterConfigurations(InputStream inAppStream, IProcessUnit logger) throws AdapterInvalidConfig {
248
    	AdapterConfigValidator validator = new AdapterConfigValidator(logger);
249
    	try{
250
    		validator.validate(inAppStream);
251
    	}catch(AdapterException e){    		
252
    		log(e.toString());
253
    	}    	
254
    }
255
    
256
    /**
257
     * Prepare the adapter for execution.  This involves reading and validating the adapter 
258
     * configuration file(s), getting the context listeners from eclipse, starting the internal
259
     * logging context, and initializing the contexts.
260
     * @param validating  boolean flag to indicate this method is called as part of adapter validation
261
     */
262
    public void prepareAdapter(boolean validating) throws AdapterException {
263
    	/* Open the context and configuration files */
264
        try {
265
    		inContextParams = new FileInputStream(contextConfigurationFile);
266
    		if (singleFileInputMode) {
267
    			inAppParams = new FileInputStream(contextConfigurationFile);
268
    		}
269
    		else {
270
    			inAppParams = new FileInputStream(componentConfigurationFile);
271
    		}
272
    	}
273
    	catch(FileNotFoundException e) {
274
    		String filename=null;
275
    		if(inContextParams==null) {
276
    			filename=contextConfigurationFile;
277
    		}
278
    		else {
279
    			filename=componentConfigurationFile;
280
    			try {
281
    				inContextParams.close();
282
    			}
283
    			catch(IOException eprime) {
284
    				/* We will ignore if this fails.  It should be successful as we just opened the file */
285
    			}	
286
    		}
287
        	/* We cannot open the adapter file */
288
        	throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Open_ERROR_", filename));
289
    	}
290
    	catch (Throwable e) {
291
     		String filename=null;
292
    		if(inContextParams==null) {
293
    			filename=contextConfigurationFile;
294
    		}
295
    		else {
296
    			filename=componentConfigurationFile;
297
    			try {
298
    				inContextParams.close();
299
    			}
300
    			catch(IOException eprime) {
301
    				/* We will ignore if this fails.  It should be successful as we just opened the file */
302
    			}	
303
    		}
304
        	/* We cannot open the adapter file */
305
        	throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Open_ERROR_", filename),e);
306
    	}
307
        
308
        // build the contexts based on configurations     	
309
        try {
310
        	contexts = createContextsAndComponents(inContextParams);
311
        	synchronized(contexts) {
312
        		setComponentConfigurations(inAppParams);
313
        	}
314
	        
315
	        /* We are done with the files.  Lets close them */
316
	        try {
317
	        	inContextParams.close();
318
	        	if(!singleFileInputMode) {
319
	        		inAppParams.close();
320
	        	}	
321
	        }
322
	        catch(IOException e) {
323
	        	/* We just had the file open. We are now closing it */
324
	        }
325
326
            /* Before we start the contexts locate any IContextListeners that
327
             * are registered with the plugin.  This only works when we are running
328
             * as a plugin inside of Eclipse.  Outside of Eclipse there is no notion
329
             * of IContextListeners.
330
             */
331
	        if (AdapterUtilities.isWorkbench()) {
332
	            try {
333
	                List contextListeners = AdapterPlugin.getContextListeners();
334
	
335
	                /* If this context has a listener then set it */
336
	                if (contextListeners != null) {
337
	                    Iterator listenerIterator = contextListeners.iterator();
338
	                    while (listenerIterator.hasNext()) {
339
	                        IContextListener listener = (IContextListener) listenerIterator.next();
340
	                        String[] targetContexts = listener.getTargetContextUniqueIds();
341
	                        for (int j = 0; j < targetContexts.length; j++) {
342
	                            for (int k = 0; k < contexts.length; k++) {
343
	                                if (contexts[k].getUniqueID().equals(targetContexts[j])) {
344
	                                    contexts[k].setContextListener(listener);
345
	                                }
346
	                            }
347
	                        }
348
	                    }
349
	                }
350
	            }
351
	            catch (AdapterException e) {
352
	            	throw e;
353
	            }
354
	            catch (Throwable e) {
355
	                throw new AdapterException(Messages.getString("HyadesGAInitialization_GetContextListeners_Failure_ERROR_"), e);
356
	            }
357
	        }
358
            
359
            /* Start the logging context in its entirty before we continue with anything else */
360
            IProcessUnit logger=startInternalLoggingContext();
361
362
            /* Validate the adapter configuration file against the schema files before starting the rest of the contexts.  
363
             * It would have been good to have done this above, however, we want our internal logging context running so that we 
364
             * can report any errors during validation
365
             */            
366
            inAppParams = new FileInputStream(contextConfigurationFile);
367
            validateAdapterConfigurations(inAppParams, logger);
368
 
369
            if (!singleFileInputMode) {
370
                inAppParams = new FileInputStream(componentConfigurationFile);
371
                validateAdapterConfigurations(inAppParams, logger);
372
            }
373
            
374
            // Count the number of contexts that are initialized and ready to execute
375
            int contextsReadyCount = 0;
376
            AdapterException initException = null;
377
            
378
            synchronized(contexts) {
379
	            for (int i = 1; i < contexts.length; ++i) {
380
	                if (contexts[i] != null) {
381
	                	
382
	                	/* Set the logger for this context to be the internal logging sensor */
383
	                	contexts[i].setLogger(logger);
384
	                	
385
	                	/* Set the validating status for the context */
386
	                	contexts[i].setValidating(validating);
387
	                	
388
	                	/* bugzilla 96433
389
	                	 * Set logging level of context and components if it needs to be globally set
390
	                	 * and it is not being validated.
391
	                	 */ 
392
	                	if (!validating && loggingLevel > -1) {
393
	                		contexts[i].setLoggingLevel(loggingLevel);
394
	                		IComponent comp[] = contexts[i].getComponents();
395
	                		for (int j=0; j<comp.length; j++) {
396
	                			comp[j].setLoggingLevel(loggingLevel);
397
	                		}
398
	                	}
399
	                	
400
	                    // set all the context config info
401
	                    if (!(contexts[i].init())) {
402
	                    	contexts[i]=null;
403
	                    	/* Make sure we log that this context will not be started */
404
	                    	log(Messages.getString("HyadesGAContextFatal_ERROR_"));
405
	                    	continue;
406
	                    }
407
	                    // set all the component config info
408
	                    
409
	                    /* Setup the configuration information for this context.  At this point in time the context
410
	                     * may fail to initialize itself properly.  If that is the case then this context should be 
411
	                     * disabled.
412
	                     */
413
	                    try {
414
	                    	contexts[i].update();
415
	                    	// Only increment context ready count if context is not disabled
416
	                    	if (!contexts[i].isDisabled()) {
417
	                    		contextsReadyCount++;
418
	                    	}
419
	                    }
420
	                    catch(AdapterException e) {
421
	                    	if (!validating) {
422
	                    		contexts[i]=null;
423
	                    		/* Make sure we log that this context will not be started */
424
	                    		log(Messages.getString("HyadesGAContextFatal_ERROR_"));
425
	                    	}
426
	                    	initException = e;
427
	                    }
428
	                }
429
	            }
430
            }
431
            // If there are no contexts ready to execute then quit! 
432
            if (contextsReadyCount == 0) {
433
            	if (initException != null) {
434
            		throw initException;
435
            	}
436
            	else {
437
            		throw new AdapterException(Messages.getString("HyadesGAContextFatal_ERROR_"));
438
            	}
439
            }
440
        }   
441
        catch(Throwable e) {
442
        	/* RKD:  Our caller will need to use our exception information for now to handle the error.*/
443
			/* Don't log anything here.  Assume the caller handles the exception and 
444
			 * logs a message if necessary.
445
             * log(Messages.getString("HyadesGAAdapterFatal_ERROR_"));
446
          	 * log(e.toString());
447
			 */
448
        	if (e instanceof AdapterException) {
449
        		throw (AdapterException)e;
450
        	}
451
        	
452
        	// Wrap non-AdapterException in an AdapterException
453
        	String errorMsg = e.getMessage();
454
        	if (errorMsg == null) {
455
        	 	errorMsg = e.toString();
456
        	}
457
            throw new AdapterException(errorMsg);
458
        }
459
        finally {
460
        	
461
        	/* Close our configuration file */
462
            try {
463
                if (inAppParams != null) {
464
                	inAppParams.close();
465
                }
466
                if (inContextParams != null) {
467
                	inContextParams.close();
468
                }
469
            }
470
            catch (IOException e) {
471
            	/* We couldn't close the configuration files.  This should only occur if we failed to 
472
            	 * open the file in the first place.
473
            	 */
474
                log(e.toString());
475
            }
476
        }
477
    }
478
 
479
    /**
480
     * Prepare the adapter configuration for execution.  This involves 
481
     * starting the internal logging context, and initializing the contexts.
482
     * @param validating  boolean flag to indicate this method is called as part of adapter validation
483
     */
484
    public void prepareConfiguration(boolean validating) throws AdapterException {
485
  	
486
        try {            
487
            /* Start the logging context in its entirty before we continue with anything else */
488
            IProcessUnit logger=startInternalLoggingContext();
489
490
            // Count the number of contexts that are initialized and ready to execute
491
            int contextsReadyCount = 0;
492
            AdapterException initException = null;
493
            
494
            synchronized(contexts) {
495
	            for (int i = 1; i < contexts.length; ++i) {
496
	                if (contexts[i] != null) {
497
	                	
498
	                	/* Set the logger for this context to be the internal logging sensor */
499
	                	contexts[i].setLogger(logger);
500
	                	
501
	                	/* Set the validating status for the context */
502
	                	contexts[i].setValidating(validating);
503
	                	
504
	                	/* bugzilla 96433
505
	                	 * Set logging level of context and components if it needs to be globally set
506
	                	 * and it is not being validated.
507
	                	 */ 
508
	                	if (!validating && loggingLevel > -1) {
509
	                		contexts[i].setLoggingLevel(loggingLevel);
510
	                		IComponent comp[] = contexts[i].getComponents();
511
	                		for (int j=0; j<comp.length; j++) {
512
	                			comp[j].setLoggingLevel(loggingLevel);
513
	                		}
514
	                	}
515
	                	
516
	                    // set all the context config info
517
	                    if (!(contexts[i].init())) {
518
	                    	contexts[i]=null;
519
	                    	/* Make sure we log that this context will not be started */
520
	                    	log(Messages.getString("HyadesGAContextFatal_ERROR_"));
521
	                    	continue;
522
	                    }
523
	                    // set all the component config info
524
	                    
525
	                    /* Setup the configuration information for this context.  At this point in time the context
526
	                     * may fail to initialize itself properly.  If that is the case then this context should be 
527
	                     * disabled.
528
	                     */
529
	                    try {
530
	                    	contexts[i].update();
531
	                    	// Only increment context ready count if context is not disabled
532
	                    	if (!contexts[i].isDisabled()) {
533
	                    		contextsReadyCount++;
534
	                    	}
535
	                    }
536
	                    catch(AdapterException e) {
537
	                    	if (!validating) {
538
	                    		contexts[i]=null;
539
	                    		/* Make sure we log that this context will not be started */
540
	                    		log(Messages.getString("HyadesGAContextFatal_ERROR_"));
541
	                    	}
542
	                    	initException = e;
543
	                    }
544
	                }
545
	            }
546
            }
547
            // If there are no contexts ready to execute then quit! 
548
            if (contextsReadyCount == 0) {
549
            	if (initException != null) {
550
            		throw initException;
551
            	}
552
            	else {
553
            		throw new AdapterException(Messages.getString("HyadesGAContextFatal_ERROR_"));
554
            	}
555
            }
556
        }   
557
        catch(Throwable e) {
558
        	/* RKD:  Our caller will need to use our exception information for now to handle the error.*/
559
			/* Don't log anything here.  Assume the caller handles the exception and 
560
			 * logs a message if necessary.
561
             * log(Messages.getString("HyadesGAAdapterFatal_ERROR_"));
562
          	 * log(e.toString());
563
			 */
564
        	if (e instanceof AdapterException) {
565
        		throw (AdapterException)e;
566
        	}
567
        	
568
        	// Wrap non-AdapterException in an AdapterException
569
        	String errorMsg = e.getMessage();
570
        	if (errorMsg == null) {
571
        	 	errorMsg = e.toString();
572
        	}
573
            throw new AdapterException(errorMsg);
574
        }
575
576
    }
577
    
578
    /**
579
     * parses Context configurations and build the Context objects
580
     * as well as set teh context config for each component
581
     */
582
    private Context[] createContextsAndComponents(InputStream inContextStream) throws PreparationException {
583
584
        Document doc = null;
585
        Context[] contexts = null;
586
        try {
587
            doc = docFactory.newDocumentBuilder().parse(inContextStream);
588
589
            //Add the adapter logging context as default:
590
            Element loggingContext = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXT);
591
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Context instance for the current component");
592
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.impl.AdapterContext");
593
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
594
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "60");
595
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, AdapterXMLConstants.HyadesGAAdapterContextName);
596
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "context");
597
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
598
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NB1F4ED002DA11D8A519FBE7C98C2F53");
599
600
            Element loggingSensor = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
601
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter logging sensor");
602
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterSensor");
603
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
604
            // bugzilla 84698 - If there is an outputter Then let WARNING or higher messages be logged.
605
            if (logOutputter != null) {
606
            	loggingSensor.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
607
            }
608
            // Otherwise let all messages be logged
609
            else {
610
            	loggingSensor.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "0");
611
            }
612
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogSensor");
613
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "sensor");
614
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
615
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NF991E0004FF11D8930381B6A308BEB5");
616
617
            loggingContext.appendChild(loggingSensor);
618
619
            Element loggingOutputter = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
620
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter logging outputter");
621
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
622
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionAttributeName, "");
623
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionDescriptionAttributeName, "");
624
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "outputter");
625
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
626
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
627
628
            // Add the outputter specified by the user (eg. set by StaticParserWrapper in the log import case)
629
            if (logOutputter != null) {
630
            	//Set the logging level so we get Warning, Critical and Fatal error messages
631
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
632
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, logOutputter.getClass().getName());
633
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogOutputter");
634
                
635
                /*************************************************************************************************                
636
                 * bugzilla 79014 
637
                 * Comment this out because we should not need to log to a file in the log import
638
                 * case.  GLA messages will be handled by the outputter set by the user.
639
                 * However, we'll keep the code here in case we find it necessar to log to a file as well.              
640
                 *                  
641
                 * loggingContext.appendChild(loggingOutputter);
642
                 *               
643
                 * // Create a file outputter too
644
                 * loggingOutputter = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
645
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter File logging outputter");
646
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
647
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionAttributeName, "");
648
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionDescriptionAttributeName, "");
649
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "outputter");
650
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
651
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "AdapterFileLoggerId");
652
                 * //Set the logging level so we get Warning, Critical and Fatal error messages
653
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
654
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterLogFileOutputter");
655
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogFileOutputter");
656
                 *
657
                 **************************************************************************************************/
658
            }
659
	        //Add the Eclipse Problems View outputter if in Eclipse mode. This is used when the context runs in the GLA editor.
660
	        else if (AdapterUtilities.isWorkbench()) {
661
            	//Set the logging level so we get any messages that are at least informational
662
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "10");
663
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.GlaTaskOutputter");
664
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "CBEEclipseProblemsViewOutputter");
665
            }
666
            //Add the log file outputter if in standalone mode:
667
            else {
668
            	//Set the logging level so we get Warning, Critical and Fatal error messages
669
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
670
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterLogFileOutputter");
671
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogFileOutputter");                
672
            }      
673
674
            loggingContext.appendChild(loggingOutputter);
675
676
            NodeList contextsNodeList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTS);
677
678
            if (contextsNodeList.getLength() == 0) {
679
680
                //Create a contexts element:	
681
                Element contextsElement = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTS);
682
                
683
                /* Insert the logging context at the first of the child list of elements */
684
                NodeList children=contextsElement.getChildNodes();
685
                for(int i=0; i<children.getLength(); i++) {
686
                	if(children.item(i).getNodeType()==Node.ELEMENT_NODE) {
687
                		contextsElement.insertBefore(loggingContext, children.item(i));
688
                		break;
689
                	}	
690
                }
691
692
                doc.getDocumentElement().appendChild(contextsElement);
693
            }
694
            else {
695
696
                //ASSUMPTION:  Only one contexts element permitted.	
697
698
                //Retrieve the contexts element:	
699
                Node contextsElement = contextsNodeList.item(0);
700
                /* Insert the logging context at the first of the child list of elements */
701
                NodeList children=contextsElement.getChildNodes();
702
                for(int i=0; i<children.getLength(); i++) {
703
                	if(children.item(i).getNodeType()==Node.ELEMENT_NODE) {
704
                		contextsElement.insertBefore(loggingContext, children.item(i));
705
                		break;
706
                	}	
707
                }
708
709
                doc.getDocumentElement().appendChild(contextsElement);
710
            }
711
712
            try {
713
                NodeList contextList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXT);
714
                // check to see if this file contains everything or just the context config
715
                NodeList tempInstanceList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
716
                if (tempInstanceList.getLength() > 0)
717
                    singleFileInputMode = true;
718
                else
719
                    singleFileInputMode = false;
720
                int count = contextList.getLength();
721
                contexts = new Context[count];
722
                int j = 0;
723
                Element element = null;
724
                Context context = null;
725
                Component component = null;
726
                
727
                for (int i = 0; i < count; ++i) {
728
                    //TODO: HS need to support imbedded/nested contexts/components
729
                    // Extract each root context and copy the expected attributes
730
                    element = (Element) contextList.item(i);
731
                	/* try and build the context.  A number of things can go wrong here as we use relection to build the instance. */
732
                	context = ContextFactory.buildContext(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));	
733
                	context.setContextConfiguration(element);
734
735
                    //
736
                    // get a list of all sub elements and assume they are components
737
                    NodeList componentList = element.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
738
                    IComponent[] compArray = null;
739
                    int componentCount = componentList.getLength();
740
                    compArray = new IComponent[componentCount];
741
                    for (int k = 0, l = 0; k < componentCount; k++) {
742
                        // Extract each component config
743
                        element = (Element) componentList.item(k);
744
745
                        // Check if we have a log outputter object already and if so then use that
746
                        if (i == 0 && k ==1 && logOutputter != null) {
747
                        	component = (Component)logOutputter;
748
                        	component.setName(element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));
749
                        	component.setUniqueID(element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName));
750
                        	component.setExecutableClassName(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName));
751
                        }
752
                        else {
753
                        	component = ComponentFactory.buildComponent(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));
754
                        }
755
                        component.setContextConfiguration(element);
756
                        compArray[l++] = component;
757
                    }
758
                    // put the components in the context
759
                    context.setComponents(compArray);
760
                    // put this context in the controller's array
761
                    contexts[j++] = context;
762
                }
763
            }
764
            catch (PreparationException e) {
765
                throw e;
766
            }
767
            catch (Exception e) {
768
                throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextConfiguration_Failure_ERROR_", contextConfigurationFile), e);
769
            }
770
        }
771
        catch (SAXException e) {
772
        	/* We have a problem parsing the configuration file ABORT */
773
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
774
        }
775
        catch (ParserConfigurationException e) {
776
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
777
        }
778
        catch (IOException e) {
779
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
780
        }
781
        return contexts;
782
    }
783
784
    /**
785
     * CreateContextsConfig takes in an entire component configurations file and
786
     * separates out the context instances and gives each context the sub tree for itself and
787
     * it's components.
788
     */
789
    private void setComponentConfigurations(InputStream inAppStream) throws AdapterInvalidConfig, PreparationException {
790
791
        Document doc = null;
792
793
        try {
794
795
            doc = docFactory.newDocumentBuilder().parse(inAppStream);
796
797
            //Add the adapter internal logging context instance as default:
798
            Element loggingSensorInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_SENSOR);
799
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "An adapter CBE sensor");
800
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGAmaximumBlockingAttributeName, "5");
801
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NF991E0004FF11D8930381B6A308BEB5");
802
803
            Element loggerContextInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
804
            loggerContextInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Context instance for the current component");
805
            /* Configure the internal logging context to run forever or until the adatper is explicitly stopped */ 
806
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_CONTINUOUS_OPERATION, "true");
807
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_MAXIMUM_IDLE_TIME, "0");
808
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_PAUSE_INTERVAL, "10");
809
            loggerContextInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NB1F4ED002DA11D8A519FBE7C98C2F53");
810
811
            loggerContextInstance.appendChild(loggingSensorInstance);
812
813
            // Configure the log outputter for the log import case
814
            if (logOutputter != null) {
815
				Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
816
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter log outputter");
817
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
818
				
819
				/* This outputter is created and configured by the user so there will not be any configuration properties for it. */
820
				
821
                loggerContextInstance.appendChild(loggingOutputterInstance);
822
                
823
                /*************************************************************************************************                
824
                 *              bugzilla 79014 
825
                 *              Comment this out because we should not need to log to a file in the log import
826
                 *              case.  GLA messages will be handled by the outputter set by the user.
827
                 *              However, we'll keep the code here in case we find it necessary to log to a file as well.              
828
                 *   
829
                 *              // Get the directory for the GLA log file
830
                 *              String glaLogDirectory = ".";
831
                 *       		try {
832
                 *       			
833
                 *       			// Try to get the plugin's workspace directory (e.g. <workspace>/.metadata/plugins/org.eclipse.hyades.logging.adapter) 
834
                 *
835
                 *       			Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
836
                 *       			
837
                 *       			Method getPluginStateLocationMethod = platformClass.getMethod("getPluginStateLocation",new Class[]{Class.forName("org.eclipse.core.runtime.Plugin")});
838
                 *       			
839
                 *       			Object iPathObject =  getPluginStateLocationMethod.invoke(null,new Object[]{AdapterPlugin.getPlugin()});
840
                 *       			
841
                 *       			Class iPathClass = iPathObject.getClass();
842
                 *       			
843
                 *       			Method toOSStringMethod = iPathClass.getMethod("toOSString",null);
844
                 *       			
845
                 *       			glaLogDirectory = (String)(toOSStringMethod.invoke(iPathObject,null));
846
                 *       		}
847
                 *       		catch (Exception e) {
848
                 *       			// Ignore this and use the current directory for the GLA log file
849
                 *       		}
850
                 *       		
851
                 *               // Add the file logger component configuration
852
                 *               loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
853
                 *               loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Single file outputter");
854
                 *               loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "AdapterFileLoggerId");
855
                 *
856
                 *				 Element outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
857
                 *               outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, glaLogDirectory);
858
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAdirectoryAttributeName);
859
                 *               loggingOutputterInstance.appendChild(outputterProperty);
860
                 *               
861
                 *				 outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
862
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, "hgla.log");
863
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAfileNameAttributeName);
864
                 *				 loggingOutputterInstance.appendChild(outputterProperty);                
865
                 *				
866
                 *               loggerContextInstance.appendChild(loggingOutputterInstance);
867
                 * 
868
                 ************************************************************************************/	
869
            }
870
            // Configure the Problems View outputter for the GLA editor case
871
            else if (AdapterUtilities.isWorkbench()) {
872
            	
873
				Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
874
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Eclipse error dialog outputter");
875
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
876
				
877
				/* RKD:  We need to inform the outputter of the configuration path so it can create markers for the resource */
878
		        Element resourcePathProperty=doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
879
	            resourcePathProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName, "resourceName");
880
	            resourcePathProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, contextConfigurationFile);
881
	                
882
	            loggingOutputterInstance.appendChild(resourcePathProperty);
883
                loggerContextInstance.appendChild(loggingOutputterInstance);			
884
            }
885
            else{
886
887
                Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
888
                loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Single file outputter");
889
                loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
890
891
				Element outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
892
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, ".");
893
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAdirectoryAttributeName);
894
                loggingOutputterInstance.appendChild(outputterProperty);
895
                
896
				outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
897
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, "hgla.log");
898
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAfileNameAttributeName);
899
				loggingOutputterInstance.appendChild(outputterProperty);                
900
				
901
                loggerContextInstance.appendChild(loggingOutputterInstance);
902
            }
903
904
            NodeList configurationNodeList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONFIGURATION);
905
906
            if (configurationNodeList.getLength() == 0) {
907
908
                //Create a configuration element:	
909
                Element loggerConfigurationInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONFIGURATION);
910
                loggerConfigurationInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "The component level configurations for this adapter");
911
                loggerConfigurationInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N06FBD3004FF11D8BCF4CFA9EA8F31E7");
912
913
                loggerConfigurationInstance.appendChild(loggerContextInstance);
914
915
                doc.getDocumentElement().appendChild(loggerConfigurationInstance);
916
            }
917
            else {
918
919
                //ASSUMPTION:  Only one configuration element permitted.	
920
921
                //Retrieve the configuration element:	
922
                Node loggerConfigurationInstance = configurationNodeList.item(0);
923
                loggerConfigurationInstance.appendChild(loggerContextInstance);
924
925
                doc.getDocumentElement().appendChild(loggerConfigurationInstance);
926
            }
927
928
            try {
929
                // get a list of all the context instances and associates each with a context
930
                NodeList contextInstanceList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
931
932
                int contextInstanceCount = contextInstanceList.getLength();
933
                for (int i = 0; i < contextInstanceCount; ++i) {
934
                    try {
935
                        //find the matching Context and Context Instance
936
                        Element contextElement = (Element) contextInstanceList.item(i);
937
                        String contextInstanceID = contextElement.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName);
938
939
                        int contextCount = contexts.length;
940
						/* Throw an exception if we have a mismatch in the number of Context's and
941
						 * the number of ContextInstance's.
942
						 */
943
						if (contextInstanceCount != contextCount) {
944
							throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextConfigurationErrorContextCountMismatchFatal_ERROR_"));
945
						}                       
946
                        
947
                        boolean contextFound = false;
948
                        for (int j = 0; j < contextCount; j++) {
949
                            if (contexts[j].getUniqueID().equals(contextInstanceID)) {
950
                                contexts[j].setConfiguration(contextElement);
951
                                contextFound = true;
952
                                // so now we have a good context which may or may not have components
953
                                //assume each child of the contextInstance is a component
954
                                NodeList componentInstanceList = contextElement.getChildNodes();
955
                                int numberOfComponentInstances = componentInstanceList.getLength();
956
                                // get the components from the context
957
								IComponent components[] = contexts[j].getComponents();
958
								int componentCount = components.length;
959
960
								int componentInstanceCount = 0;
961
                                for (int k = 0; k < numberOfComponentInstances; k++) {
962
                                    if (componentInstanceList.item(k).getNodeType() == Node.ELEMENT_NODE) {
963
                                        Element componentElement = (Element) componentInstanceList.item(k);
964
                                        String componentInstanceID = componentElement.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName);
965
                                        boolean componentFound = false;
966
                                        componentInstanceCount++;
967
                                        // walk through the components of the context and set the config
968
                                        for (int l = 0; l < componentCount; l++) {
969
                                            if (components[l].getUniqueID().equals(componentInstanceID)) {
970
                                                components[l].setConfiguration(componentElement);
971
                                                componentFound = true;
972
                                                /* bugzilla 82193
973
                                                 * If this is a formatter and we are running in the GLA editor
974
                                                 */
975
                                                if (componentElement.getNodeName().equals(AdapterXMLConstants.ELEMENT_TAG_NAME_FORMATTER) && 
976
                                                		logOutputter == null &&	AdapterUtilities.isWorkbench()) {
977
                                                	/* Add the test attribute to the formatter element to indicate we are running
978
                                                	 * in the GLA editor environment.  
979
                                                	 */
980
                                                	componentElement.setAttribute(AdapterConstants.AttrubuteName_Test,AdapterConstants.AttrubuteValue_Test_True);
981
                                                }
982
                                                break;
983
                                            }
984
                                        }
985
                                        if (!componentFound) {
986
											throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorComponentIdNotFoundFatal_ERROR_",componentInstanceID , contexts[j].getUniqueID()));
987
                                        }
988
                                    }
989
                                }
990
								/* Throw an exception if we have a mismatch in number of components between
991
								 * the context and the contextInstance.
992
								 */
993
								if (componentInstanceCount != componentCount) {
994
									throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorComponentMismatchFatal_ERROR_",contexts[j].getUniqueID()));
995
								}
996
                                break;
997
                            }
998
                        }
999
						if (!contextFound) {
1000
							throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorContextIdNotFoundFatal_ERROR_", contextInstanceID));
1001
						}
1002
                    }
1003
                    catch (AdapterInvalidConfig e) {
1004
                    	throw e;
1005
                    }
1006
                    catch (Exception e) {
1007
                        throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextInstanceConfiguration_Failure_ERROR_", componentConfigurationFile), e);
1008
                    }
1009
                }
1010
            }
1011
            catch (AdapterInvalidConfig e) {
1012
            	throw e;
1013
            }
1014
            catch (Exception e) {
1015
                throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextInstanceConfiguration_Failure_ERROR_", componentConfigurationFile), e);
1016
            }
1017
        }
1018
        catch (SAXException e) {
1019
        	/* We have a problem parsing the configuration file ABORT */
1020
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1021
        }
1022
        catch (ParserConfigurationException e) {
1023
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1024
        }
1025
        catch (IOException e) {
1026
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1027
        }
1028
    }
1029
    /**
1030
     * run provides the basic loop for a Controller thread.  It starts the Controller thread and
1031
     * then monitors it.
1032
     */
1033
    public void run() {
1034
        start();
1035
        while (isRunning()) {
1036
            synchronized (this) {
1037
                try {
1038
                    wait(sleepTime);
1039
                }
1040
                catch (Exception e) {
1041
                    log(e.toString());
1042
                }
1043
                if (areContextsDone()) {
1044
               	    // Stop the Adapter logging context
1045
                    stop();
1046
                }
1047
            }
1048
        }
1049
    }
1050
    /**
1051
     * return false if any context is still alive, otherwise return true 
1052
     */
1053
    private boolean areContextsDone() {
1054
        if (contextThreads != null) {
1055
        	/* Ignore the internal logging context.  hense we start at index 1 */
1056
            for (int i = 1; i < contextThreads.length; i++) {
1057
                if (contextThreads[i] != null) {
1058
                    if (contextThreads[i].isAlive() && !(contexts[i] instanceof AdapterContext))
1059
                        return false;
1060
                }
1061
            }
1062
        }
1063
        return true;
1064
    }
1065
    
1066
    /**
1067
     * clean a controller by nulling out everything
1068
     */
1069
    private void clean() {
1070
        if (contexts != null) {
1071
            for (int i = 0; i < contexts.length; i++) {
1072
                contexts[i] = null;
1073
            }
1074
        }
1075
        contexts = null;
1076
        //		hashContextConfig.clear();
1077
    }
1078
    
1079
    /**
1080
     * Starts the internal logging context.
1081
     *
1082
     */
1083
    private IProcessUnit startInternalLoggingContext() {
1084
    	contexts[0].init();
1085
    	contextThreads=new Thread[contexts.length];
1086
        try {
1087
        	contexts[0].update();
1088
        	// bugzilla 96433 - Reset the logging context status
1089
        	contexts[0].setStopping(false);
1090
        	contextThreads[0]=new Thread(contexts[0]);
1091
        	contextThreads[0].setName(contexts[0].getName() + AdapterConstants.HyadesGA + contexts[0].getUniqueID());
1092
        	contextThreads[0].setDaemon(true);
1093
        	contextThreads[0].start();
1094
        	return (IProcessUnit)contexts[0].getComponents()[0];
1095
        	
1096
        }
1097
        catch(AdapterException e) {
1098
        	/* Since we are generating the context content we should not have configuration problems */
1099
        	/* However, we may get an exception here if the GLA logging cannot be initialized. */
1100
			log(Messages.getString("HyadesGAInitialization_Internal_Logging_Not_Started_WARN_", e.getLocalizedMessage()));
1101
        }
1102
        catch(Exception e) {
1103
        	/* Catch any other kind of exception and log a message */
1104
        	log(Messages.getString("HyadesGAInitialization_Internal_Logging_Not_Started_WARN_", e.toString()));
1105
        }
1106
        return null;
1107
    }
1108
    
1109
    /**
1110
     * Log the string message to standard error since the logging outputter(s)
1111
     * associated with the <code>AdapterSensor</code> logger will never be
1112
     * started.
1113
     * 
1114
     * @param logRecord The string message to be logged to standard error.
1115
     */
1116
    public void log(String logRecord) {
1117
    	if(!AdapterUtilities.isWorkbench()) {
1118
    		System.err.println(logRecord);
1119
    	}
1120
       
1121
    }
1122
    
1123
    /**
1124
     * Get the status of the contexts
1125
     * @return the array of Status objects representing the status of the contexts
1126
     */
1127
    public Status [] getStatus() {
1128
    	Status [] statuses = null; 
1129
    	
1130
    	/* If there are context then get their status */
1131
	    if (contexts != null) {
1132
	    	synchronized(contexts) {
1133
	        	statuses = new Status[contexts.length];
1134
	        	/* get the status for each context */        	
1135
	            for (int i=0; i < contexts.length; i++) {
1136
	            	if (contexts[i] != null) {
1137
	            		statuses[i] = contexts[i].getContextStatus();
1138
	            	}
1139
	            	else {
1140
	            		statuses[i] = null;
1141
	            	}
1142
	            }
1143
	        }
1144
    	}
1145
    	
1146
    	return statuses;
1147
    }
1148
	
1149
	/**
1150
	 * Get the custom Outputter that the internal logging context is using.
1151
	 * @return Returns the custom Outputter that the internal logging context is using.
1152
	 */
1153
	public IOutputter getLogOutputter() {
1154
		return logOutputter;
1155
	}
1156
	/**
1157
	 * Sets the custom Outputter for the internal logging context to use.
1158
	 * @param logOutputter The custom Outputter for the internal logging context.
1159
	 */
1160
	public void setLogOutputter(IOutputter logOutputter) {
1161
		this.logOutputter = logOutputter;
1162
	}
1163
	
1164
    /**
1165
     * Sets the loggingLevel of the Adapter object.  This value will override 
1166
     * all values in the adapter configuration. The logging level value specified will
1167
     * take effect the next time the Adapter is started. If this method is 
1168
     * not called or is called with a value of -1, the logging levels specified in the
1169
     * adapter configuration will be used.
1170
     * @param newLevel The level of logging that the Adapter will use during execution
1171
     */
1172
	public void setLoggingLevel(short newLevel)
1173
	{
1174
		loggingLevel = newLevel;
1175
	}
1176
1177
	/**
1178
	 * Get the logging level of the Adapter object.
1179
	 * @return the level of logging the Adapter is currently using
1180
	 */
1181
	public short getLoggingLevel() {
1182
		return loggingLevel;
1183
	}
1184
}
(-)src/org/eclipse/hyades/logging/adapter/outputters/CBEFileOutputter.java (-26 / +43 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005,2006 IBM Corporation and others.
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 47-52 Link Here
47
	private String fileName = null;
47
	private String fileName = null;
48
	protected String rawLogFileName = null;
48
	protected String rawLogFileName = null;
49
	protected  FileWriter fw = null;
49
	protected  FileWriter fw = null;
50
	protected String tmpFileName = null;
51
	protected String tmpDirectory = null;
50
		
52
		
51
	/**
53
	/**
52
	 * This implementation processes messages represented by an array of CommonBaseEvent objects
54
	 * This implementation processes messages represented by an array of CommonBaseEvent objects
Lines 188-211 Link Here
188
		this.fileName = fileName;
190
		this.fileName = fileName;
189
		updateConfigurationPropertyChild(AdapterXMLConstants.HyadesGAfileNameAttributeName, fileName);
191
		updateConfigurationPropertyChild(AdapterXMLConstants.HyadesGAfileNameAttributeName, fileName);
190
	}
192
	}
191
	
193
192
	/**
194
	/**
193
	 * update the configuration based on the configuration Element
195
	 * Read the outputter configuration from the configuration element
194
	 */
196
	 */
195
	public void update() throws AdapterInvalidConfig
197
	protected void readConfiguration() {
196
	{
197
		// first get the basic configuration set
198
		super.update();
199
200
		/* The directory and fileName may be set already if the 
201
		 * outputter is passed to the adapter as the GLA Adapter Log 
202
		 * Outputter so intialize the local variables with those values.
203
		 * Note, they will be overwritten below by the values in the 
204
		 * configuration if they are present.
205
		 */
206
		String directory = getDirectory();
207
		String fileName = getFileName();
208
		
209
//		Get configuration
198
//		Get configuration
210
199
211
		Element element = getConfiguration();
200
		Element element = getConfiguration();
Lines 216-224 Link Here
216
		// Get the outputter parameters from the outputter properties
205
		// Get the outputter parameters from the outputter properties
217
		Hashtable outputterProperties = getProperties();		
206
		Hashtable outputterProperties = getProperties();		
218
		if (outputterProperties != null && !outputterProperties.isEmpty()) {
207
		if (outputterProperties != null && !outputterProperties.isEmpty()) {
219
			directory = (String)outputterProperties.get(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
208
			tmpDirectory = (String)outputterProperties.get(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
220
209
221
			fileName = (String)outputterProperties.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);				
210
			tmpFileName = (String)outputterProperties.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);				
222
		}
211
		}
223
		else if (element != null) {
212
		else if (element != null) {
224
			/**
213
			/**
Lines 234-260 Link Here
234
						outputterTypeInstance = outputterNode;
223
						outputterTypeInstance = outputterNode;
235
						// Get attributes				
224
						// Get attributes				
236
						if (outputterTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName))
225
						if (outputterTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName))
237
							directory = outputterTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
226
							tmpDirectory = outputterTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
238
						if (outputterTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName))
227
						if (outputterTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName))
239
							fileName = outputterTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName);
228
							tmpFileName = outputterTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName);
240
					}
229
					}
241
				}
230
				}
242
			}
231
			}
243
		}
232
		}
244
			
233
	}
234
235
	/**
236
	 * Process the values read from the configuration and perform other initialization
237
	 * @throws AdapterInvalidConfig
238
	 */
239
	protected void processConfiguration() throws AdapterInvalidConfig {
245
		// We must have a directory and fileName
240
		// We must have a directory and fileName
246
		if (directory == null || directory.length() == 0 || fileName == null || fileName.length() == 0) {
241
		if (tmpDirectory == null || tmpDirectory.length() == 0 || tmpFileName == null || tmpFileName.length() == 0) {
247
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileOutputter_Invalid_Config_File_ERROR_"));
242
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileOutputter_Invalid_Config_File_ERROR_"));
248
		}
243
		}
249
		
244
		
250
		// Check if the directory is actually a directory
245
		// Check if the directory is actually a directory
251
		File dir = new File(directory);
246
		File dir = new File(tmpDirectory);
252
		if (!dir.isDirectory()) {
247
		if (!dir.isDirectory()) {
253
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileOutputter_Invalid_Config_File_ERROR_"));
248
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileOutputter_Invalid_Config_File_ERROR_"));
254
		}
249
		}
255
		
250
		
256
		setDirectory(directory);
251
		setDirectory(tmpDirectory);
257
		setFileName(fileName);
252
		setFileName(tmpFileName);
258
253
259
		// Get the parent context so we can get the validating flag
254
		// Get the parent context so we can get the validating flag
260
		boolean validating = false;
255
		boolean validating = false;
Lines 274-279 Link Here
274
	}
269
	}
275
	
270
	
276
	/**
271
	/**
272
	 * update the configuration based on the configuration Element
273
	 */
274
	public void update() throws AdapterInvalidConfig
275
	{
276
		// first get the basic configuration set
277
		super.update();
278
279
		/* The directory and fileName may be set already if the 
280
		 * outputter is passed to the adapter as the GLA Adapter Log 
281
		 * Outputter so intialize the local variables with those values.
282
		 * Note, they will be overwritten below by the values in the 
283
		 * configuration if they are present.
284
		 */
285
		tmpDirectory = getDirectory();
286
		tmpFileName = getFileName();
287
		
288
		readConfiguration();
289
			
290
		processConfiguration();
291
	}
292
	
293
	/**
277
	 * Prepare the file for the log CBE output
294
	 * Prepare the file for the log CBE output
278
	 */
295
	 */
279
	protected void prepareFile() throws AdapterInvalidConfig 
296
	protected void prepareFile() throws AdapterInvalidConfig 
(-)src/org/eclipse/hyades/logging/adapter/sensors/SingleOSFileSensor.java (-37 / +55 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005,2006 IBM Corporation and others.
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 97-102 Link Here
97
	private File tmpFile = null;
97
	private File tmpFile = null;
98
	private static String prefix = "hgla";
98
	private static String prefix = "hgla";
99
99
100
	protected String tmpFileName = null;
101
	protected String tmpDirectory = null;
102
	protected String tmpConverterCmd = null;
100
	/**
103
	/**
101
	 * No-arguement constructor to create a SingleOSFileSensor.
104
	 * No-arguement constructor to create a SingleOSFileSensor.
102
	 */
105
	 */
Lines 122-144 Link Here
122
		super.stop();
125
		super.stop();
123
		clean();
126
		clean();
124
	}
127
	}
128
	
125
	/**
129
	/**
126
	 * Update the configuration based on the configuration Element.
130
	 * Read the sensor configuration from the configuration element
127
	 *
128
	 * @see org.eclipse.hyades.logging.adapter.IComponent#update()
129
	 */
131
	 */
130
	/* (non-Javadoc)
132
	protected void readConfiguration() {
131
	 * @see org.eclipse.hyades.logging.adapter.impl.Sensor#update()
132
	 */
133
	public void update() throws AdapterInvalidConfig
134
	{
135
		// first get the basic configuration set
136
		super.update();
137
		// maximumBlocking is set by the sensor config
138
		lastLine = new String[maximumBlocking];
139
		String directory = null;
140
		String fileName = null;
141
		String converterCmdAttribute = null;
142
133
143
		Element sensorTypeInstance = null;
134
		Element sensorTypeInstance = null;
144
		Element sensorNode;
135
		Element sensorNode;
Lines 147-157 Link Here
147
		// Get the sensor parameters from the sensor properties
138
		// Get the sensor parameters from the sensor properties
148
		Hashtable sensorProperties = getProperties();		
139
		Hashtable sensorProperties = getProperties();		
149
		if (sensorProperties != null && !sensorProperties.isEmpty()) {
140
		if (sensorProperties != null && !sensorProperties.isEmpty()) {
150
			directory = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
141
			tmpDirectory = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
151
142
152
			fileName = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);
143
			tmpFileName = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAfileNameAttributeName);
153
			
144
			
154
			converterCmdAttribute = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAconverterCmdAttributeName);
145
			tmpConverterCmd = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAconverterCmdAttributeName);
155
			
146
			
156
			converterShell = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAconverterShellAttributeName);
147
			converterShell = (String)sensorProperties.get(AdapterXMLConstants.HyadesGAconverterShellAttributeName);
157
			
148
			
Lines 169-182 Link Here
169
						// Get the sensor parameters from the sensor type instance attributes
160
						// Get the sensor parameters from the sensor type instance attributes
170
						sensorTypeInstance = sensorNode;
161
						sensorTypeInstance = sensorNode;
171
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName)) {
162
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName)) {
172
							directory = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
163
							tmpDirectory = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAdirectoryAttributeName);
173
						}
164
						}
174
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName)) {
165
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName)) {
175
							fileName = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName);
166
							tmpFileName = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAfileNameAttributeName);
176
						}
167
						}
177
	
168
	
178
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAconverterCmdAttributeName)) {
169
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAconverterCmdAttributeName)) {
179
							converterCmdAttribute = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAconverterCmdAttributeName);
170
							tmpConverterCmd = sensorTypeInstance.getAttribute(AdapterXMLConstants.HyadesGAconverterCmdAttributeName);
180
						}
171
						}
181
	
172
	
182
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAconverterShellAttributeName)) {
173
						if (sensorTypeInstance.hasAttribute(AdapterXMLConstants.HyadesGAconverterShellAttributeName)) {
Lines 187-196 Link Here
187
			}
178
			}
188
		}
179
		}
189
		
180
		
190
		if (converterCmdAttribute != null) {
181
		if (tmpConverterCmd != null) {
191
			converterCmdAttribute = converterCmdAttribute.trim();
182
			tmpConverterCmd = tmpConverterCmd.trim();
192
			if (converterCmdAttribute.length() == 0) {
183
			if (tmpConverterCmd.length() == 0) {
193
				converterCmdAttribute = null;
184
				tmpConverterCmd = null;
194
			}
185
			}
195
		}
186
		}
196
		
187
		
Lines 200-208 Link Here
200
				converterShell = null;
191
				converterShell = null;
201
			}
192
			}
202
		}
193
		}
203
		
204
		filterExitClassInstance = getFilterExitClassInstance();
205
		
206
194
207
		// Get the parent context so we can get the charset and
195
		// Get the parent context so we can get the charset and
208
		// continuous operation flag
196
		// continuous operation flag
Lines 217-233 Link Here
217
				break;
205
				break;
218
			}
206
			}
219
		}
207
		}
208
	}
209
210
	/**
211
	 * Process the values read from the configuration and perform other initialization
212
	 * @throws AdapterInvalidConfig
213
	 */
214
	protected void processConfiguration() throws AdapterInvalidConfig {
220
		// Check if the directory and fileName properties are non null
215
		// Check if the directory and fileName properties are non null
221
		if (directory == null || directory.trim().length() == 0 ||
216
		if (tmpDirectory == null || tmpDirectory.trim().length() == 0 ||
222
				fileName == null || fileName.trim().length() == 0) {
217
				tmpFileName == null || tmpFileName.trim().length() == 0) {
223
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
218
			throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
224
		}
219
		}
220
221
		filterExitClassInstance = getFilterExitClassInstance();
225
		
222
		
223
		// maximumBlocking is set by the sensor config
224
		lastLine = new String[maximumBlocking];
226
		 
225
		 
227
		/* Assume the fileName specified is a regular expression and try to
226
		/* Assume the fileName specified is a regular expression and try to
228
		 * use the MultipleFilesReader class.
227
		 * use the MultipleFilesReader class.
229
		 */
228
		 */
230
		mfr = new MultipleFilesReader(directory, fileName, tmpLog);
229
		mfr = new MultipleFilesReader(tmpDirectory, tmpFileName, tmpLog);
231
		mfr.init();
230
		mfr.init();
232
231
233
		// If only one file matches the regex, use the original SingleOSFileSensor
232
		// If only one file matches the regex, use the original SingleOSFileSensor
Lines 246-264 Link Here
246
				String fn = mfr.getNext();
245
				String fn = mfr.getNext();
247
				//We must have a vaild directory and fileName that exists on the local file system:
246
				//We must have a vaild directory and fileName that exists on the local file system:
248
				if (fn == null || fn.trim().length() == 0 ||
247
				if (fn == null || fn.trim().length() == 0 ||
249
					(converterCmdAttribute == null && !(new File(fn).canRead()))) {
248
					(tmpConverterCmd == null && !(new File(fn).canRead()))) {
250
					throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
249
					throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
251
				}
250
				}
252
				setFileName(new File(fn).getName()); // Because the name is fully-qualified			
251
				setFileName(new File(fn).getName()); // Because the name is fully-qualified			
253
			}
252
			}
254
			else { // no match at all
253
			else { // no match at all
255
				// If there was no converter command to generate the log file and the sensor is not running in a continuous context then throw an exception
254
				// If there was no converter command to generate the log file and the sensor is not running in a continuous context then throw an exception
256
				if (converterCmdAttribute == null && !continuousContext) {
255
				if (tmpConverterCmd == null && !continuousContext) {
257
					throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
256
					throw new AdapterInvalidConfig(Messages.getString("HyadesGA_CBE_SingleFileSensor_Invalid_Config_File_ERROR_"));
258
				}
257
				}
259
				else {
258
				else {
260
					// use the original file name, assuming the converter command will generate the file
259
					// use the original file name, assuming the converter command will generate the file
261
					setFileName(fileName.trim());
260
					setFileName(tmpFileName.trim());
262
				}
261
				}
263
			}
262
			}
264
		}
263
		}
Lines 282-289 Link Here
282
			}
281
			}
283
		}
282
		}
284
		
283
		
285
		setDirectory(directory.trim());
284
		setDirectory(tmpDirectory.trim());
286
		setConverterCommand(converterCmdAttribute);
285
		setConverterCommand(tmpConverterCmd);
287
		
286
		
288
	    CommonBaseEvent event = getEventFactory().createCommonBaseEvent();
287
	    CommonBaseEvent event = getEventFactory().createCommonBaseEvent();
289
	    event.setMsg(Messages.getString("HyadesGASensor_SingleOSFileSensor_Configuration_INFO_",getFileName(), getDirectory(), getConverterCommand()));
288
	    event.setMsg(Messages.getString("HyadesGASensor_SingleOSFileSensor_Configuration_INFO_",getFileName(), getDirectory(), getConverterCommand()));
Lines 301-306 Link Here
301
			}
300
			}
302
		}
301
		}
303
	}
302
	}
303
	
304
	/**
305
	 * Update the configuration based on the configuration Element.
306
	 *
307
	 * @see org.eclipse.hyades.logging.adapter.IComponent#update()
308
	 */
309
	/* (non-Javadoc)
310
	 * @see org.eclipse.hyades.logging.adapter.impl.Sensor#update()
311
	 */
312
	public void update() throws AdapterInvalidConfig
313
	{
314
		// first get the basic configuration set
315
		super.update();
316
		
317
		readConfiguration();
318
		
319
		processConfiguration();
320
321
	}
304
322
305
	/**
323
	/**
306
	 * 	simulates a getNext
324
	 * 	simulates a getNext
(-)src/org/eclipse/hyades/logging/adapter/Adapter.java (-9 / +22 lines)
Lines 1-7 Link Here
1
package org.eclipse.hyades.logging.adapter;
2
3
/**********************************************************************
1
/**********************************************************************
4
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
5
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-25 Link Here
17
 * 
15
 * 
18
 **********************************************************************/
16
 **********************************************************************/
19
17
18
package org.eclipse.hyades.logging.adapter;
19
20
import org.eclipse.hyades.logging.adapter.impl.Status;
20
import org.eclipse.hyades.logging.adapter.impl.Status;
21
import org.eclipse.hyades.logging.adapter.internal.util.Controller;
22
import org.eclipse.hyades.logging.adapter.parsers.PreparationException;
21
import org.eclipse.hyades.logging.adapter.parsers.PreparationException;
22
import org.eclipse.hyades.logging.adapter.provisional.util.ControllerFactory;
23
import org.eclipse.hyades.logging.adapter.provisional.util.IController;
24
import org.eclipse.hyades.logging.adapter.provisional.util.IControllerFactory;
23
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
25
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
24
import org.eclipse.hyades.logging.adapter.util.Messages;
26
import org.eclipse.hyades.logging.adapter.util.Messages;
25
27
Lines 54-60 Link Here
54
 */
56
 */
55
public class Adapter {
57
public class Adapter {
56
58
57
    private Controller rootController = null;
59
60
	private IControllerFactory controllerFactory;
61
	private IController rootController = null;
58
    private String contextFile = null;
62
    private String contextFile = null;
59
    private String componentFile = null;
63
    private String componentFile = null;
60
    // Adapter internal log outputter
64
    // Adapter internal log outputter
Lines 66-72 Link Here
66
     * Status object representing the status of this adapter instance.
70
     * Status object representing the status of this adapter instance.
67
     */
71
     */
68
    private Status status = new Status();
72
    private Status status = new Status();
69
    
73
74
    /**
75
	 * Adapter constructor
76
	 */
77
	public Adapter() {
78
		super();
79
		// Create a controller factory
80
		controllerFactory = new ControllerFactory();
81
		
82
	}
70
    /**
83
    /**
71
     * Sets the path of the file containing the context configuration portion of the 
84
     * Sets the path of the file containing the context configuration portion of the 
72
     * adapter configuration. This method must be called before the validate and start
85
     * adapter configuration. This method must be called before the validate and start
Lines 138-144 Link Here
138
        	}
151
        	}
139
        	// Otherwise create a new controller and load the configuration from the adapter file to validate it.
152
        	// Otherwise create a new controller and load the configuration from the adapter file to validate it.
140
        	else {
153
        	else {
141
		    	rootController = new Controller();
154
		    	rootController = controllerFactory.getController();
142
		
155
		
143
		        if (componentFile == null) {
156
		        if (componentFile == null) {
144
		            componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
157
		            componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
Lines 206-212 Link Here
206
    	// Otherwise create a new controller and load the configuration from the adapter file.
219
    	// Otherwise create a new controller and load the configuration from the adapter file.
207
    	else {
220
    	else {
208
	    	/* Get a new controller to run the adapter */
221
	    	/* Get a new controller to run the adapter */
209
	        rootController = new Controller();
222
	        rootController = controllerFactory.getController();
210
	
223
	
211
	        if (componentFile == null) {
224
	        if (componentFile == null) {
212
	            componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
225
	            componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
Lines 381-387 Link Here
381
	    		}
394
	    		}
382
	    	}
395
	    	}
383
	    	else {
396
	    	else {
384
	    		rootController = new Controller();
397
	    		rootController = controllerFactory.getController();
385
	
398
	
386
	            if (componentFile == null) {
399
	            if (componentFile == null) {
387
	                componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
400
	                componentFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile; //$NON-NLS-1$
(-)src/org/eclipse/hyades/logging/adapter/provisional/util/ControllerFactory.java (+32 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Controller.java,v 1.9 2007/03/22 05:29:24 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 * 
12
 **********************************************************************/
13
14
package org.eclipse.hyades.logging.adapter.provisional.util;
15
16
/**
17
 * Implementation of an IControllerFactory that generates Controller instances
18
 * 
19
 * @author smith
20
 *
21
 */
22
public class ControllerFactory implements IControllerFactory {
23
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.hyades.logging.adapter.provisional.util.IControllerFactory#getController()
26
	 */
27
	public IController getController() {
28
		// TODO Auto-generated method stub
29
		return new Controller();
30
	}
31
32
}
(-)src/org/eclipse/hyades/logging/adapter/provisional/util/Controller.java (+1158 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Controller.java,v 1.9 2007/03/22 05:29:24 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 * 
12
 * Change History:
13
 * Bugzilla  Description
14
 * 79014     Improved error handling and message logging
15
 * 
16
 **********************************************************************/
17
package org.eclipse.hyades.logging.adapter.provisional.util;
18
19
import java.io.FileInputStream;
20
import java.io.FileNotFoundException;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.util.Iterator;
24
import java.util.List;
25
26
import javax.xml.parsers.DocumentBuilderFactory;
27
import javax.xml.parsers.ParserConfigurationException;
28
29
import org.eclipse.hyades.logging.adapter.AdapterException;
30
import org.eclipse.hyades.logging.adapter.AdapterInvalidConfig;
31
import org.eclipse.hyades.logging.adapter.AdapterPlugin;
32
import org.eclipse.hyades.logging.adapter.IComponent;
33
import org.eclipse.hyades.logging.adapter.IContext;
34
import org.eclipse.hyades.logging.adapter.IContextListener;
35
import org.eclipse.hyades.logging.adapter.IOutputter;
36
import org.eclipse.hyades.logging.adapter.IProcessUnit;
37
import org.eclipse.hyades.logging.adapter.impl.AdapterContext;
38
import org.eclipse.hyades.logging.adapter.impl.AdapterXMLConstants;
39
import org.eclipse.hyades.logging.adapter.impl.Component;
40
import org.eclipse.hyades.logging.adapter.impl.Context;
41
import org.eclipse.hyades.logging.adapter.impl.Status;
42
import org.eclipse.hyades.logging.adapter.internal.util.AdapterConfigValidator;
43
import org.eclipse.hyades.logging.adapter.internal.util.ComponentFactory;
44
import org.eclipse.hyades.logging.adapter.internal.util.ContextFactory;
45
import org.eclipse.hyades.logging.adapter.parsers.PreparationException;
46
import org.eclipse.hyades.logging.adapter.util.AdapterConstants;
47
import org.eclipse.hyades.logging.adapter.util.AdapterUtilities;
48
import org.eclipse.hyades.logging.adapter.util.Messages;
49
import org.w3c.dom.Document;
50
import org.w3c.dom.Element;
51
import org.w3c.dom.Node;
52
import org.w3c.dom.NodeList;
53
import org.xml.sax.SAXException;
54
/**
55
 * The TPTP implementation of the IController interface.
56
 * 
57
 */
58
public class Controller implements IController {
59
   
60
    private boolean singleFileInputMode = false;
61
    
62
    /* Keep our contexts and their associated threads within a list. It is imperative that the index
63
     *  of each list be kept consistent.  That is, the thread running context at index n must be in the
64
     *  thread list at index n
65
     */
66
    private Context[] contexts;
67
    private Thread[]   contextThreads;
68
    
69
  	// Adapter log outputter component
70
    private IOutputter logOutputter = null;
71
    
72
    private String contextConfigurationFile = AdapterConstants.HyadesGADefaultContextConfigurationFile;
73
    private String componentConfigurationFile = AdapterConstants.HyadesGADefaultComponentConfigurationsFile;
74
    private DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
75
    private InputStream inContextParams = null;
76
    private InputStream inAppParams = null;
77
    private boolean running = false;
78
    private long sleepTime = 500;
79
80
    // Overall logging level for the Adapter
81
    private short loggingLevel = -1;
82
    /**
83
     * Constructor for Controller.
84
     */
85
    public Controller() {
86
        super();
87
    }
88
    
89
    /* (non-Javadoc)
90
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#isRunning()
91
	 */
92
    public boolean isRunning() {
93
        return running;
94
    }
95
    
96
    /* (non-Javadoc)
97
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#start()
98
	 */
99
    public void start() {
100
    	/* RKD:  We will run all of the contexts except the first one 
101
    	 * (our internal logging context), each in its own thread.
102
    	 * The internal logging context was already started
103
    	 * when we went through the prepare stage.
104
         */
105
    	synchronized(contexts) {
106
	        for (int i = 1; i < contextThreads.length; ++i) {
107
	            if (contexts[i] != null && !contexts[i].isDisabled()) {
108
	            	contextThreads[i]=new Thread(contexts[i]);
109
	            	contextThreads[i].setName(contexts[i].getName() + AdapterConstants.HyadesGA + contexts[i].getUniqueID());
110
	            	contextThreads[i].setDaemon(true);
111
	            	contextThreads[i].start();
112
	            }
113
	        }
114
    	}
115
        running = true;
116
    }
117
    
118
    /* (non-Javadoc)
119
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#stop()
120
	 */
121
    public void stop() {
122
123
	    if (contexts != null && contextThreads != null) {
124
	       	synchronized(contexts) {
125
	       	    int contextStopCount = 0;
126
	       	    /* stop them in reverse order so that the logging context gets stopped last */        	
127
	            for (int i=contexts.length-1; i>0; i--) {
128
	 				/* bugzilla 74713 - set stopping flag instead of calling Context.stop() because
129
					 * we're running in a different thread than the context.  Also, only stop the
130
					 * context if the context thread is still alive
131
					 */
132
	                if (contexts[i] != null && contextThreads.length > i && contextThreads[i] != null  && contextThreads[i].isAlive()) {
133
	                    contexts[i].setStopping(true);
134
	                    contextStopCount++;
135
	                }
136
	            }
137
		        /* If other contexts are stopping Then sleep before stopping 
138
		         * the logging context to allow the other contexts
139
	    	     * to log messages and end.
140
	             * bugzilla 91218 - only sleep if there are contexts in the
141
	             * process of stopping.
142
	    		 */
143
	            if (contextStopCount > 0) {
144
	            	try {
145
	            		Thread.sleep(1500);
146
	            	}
147
	            	catch (InterruptedException e) {
148
	            	
149
	            	}
150
	            }
151
	            // Stop the logging context.
152
	            if (contexts[0] != null && contextThreads.length > 0 && contextThreads[0] != null  && contextThreads[0].isAlive()) {
153
	                contexts[0].setStopping(true);
154
	                // Wait until logging context is finished
155
	                while (contextThreads[0] != null  && contextThreads[0].isAlive()) {
156
	                	try {
157
		            		Thread.sleep(200);
158
		            		// System.out.println("Waited a fifth of a second for logging context to end");
159
		            	}
160
		            	catch (InterruptedException e) {
161
		            	
162
		            	}
163
	                }
164
	            }
165
	    	}
166
    	}
167
        running = false;
168
    }
169
    
170
	/* (non-Javadoc)
171
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#hardStop()
172
	 */    
173
	public void hardStop() {
174
		synchronized(contexts) {
175
			if (contexts != null && contextThreads != null)
176
				/* stop them in reverse order so that the logging context gets stopped last */
177
				for (int i=contexts.length-1; i>=0; i--) {
178
					/* bugzilla 74713 - set hard stop flag instead of calling Context.stop() because
179
					 * we're running in a different thread than the context.  Also, only stop the
180
					 * context if the context thread is still alive
181
					 */
182
					if (contexts[i] != null && contextThreads.length > i && contextThreads[i] != null && contextThreads[i].isAlive()) {
183
						// Set hardStop flag to stop the context
184
						contexts[i].setHardStop();
185
					}
186
				}
187
		}
188
		running = false;
189
	}
190
    
191
	/* (non-Javadoc)
192
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getContexts()
193
	 */
194
    public IContext[] getContexts() {
195
    	synchronized(contexts) {
196
	    	// Ensure the contexts have been created
197
	    	if (contexts == null || contexts.length <= 1) {
198
	    		return null;
199
	    	}
200
			// Exclude the internal logging context
201
			IContext newContextSet[] = new IContext[contexts.length-1];
202
			for (int i=1; i < contexts.length; i++) {
203
				newContextSet[i-1] = contexts[i];
204
			}
205
			return newContextSet;
206
    	}
207
    }
208
    
209
    /* (non-Javadoc)
210
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#setContextConfigPath(java.lang.String)
211
	 */
212
    public void setContextConfigPath(String config) {
213
        contextConfigurationFile = config;
214
    }
215
    
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getContextConfigPath()
218
	 */
219
	public String getContextConfigPath() {
220
		return contextConfigurationFile;
221
	}
222
223
	/* (non-Javadoc)
224
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#setComponentConfigPath(java.lang.String)
225
	 */
226
    public void setComponentConfigPath(String config) {
227
        componentConfigurationFile = config;
228
    }
229
230
    /* (non-Javadoc)
231
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getComponentConfigPath()
232
	 */
233
	public String getComponentConfigPath() {
234
		return componentConfigurationFile;
235
	}
236
237
    /*
238
     * Validates an adapter file against the schema files.
239
     */
240
    private void validateAdapterConfigurations(InputStream inAppStream, IProcessUnit logger) throws AdapterInvalidConfig {
241
    	AdapterConfigValidator validator = new AdapterConfigValidator(logger);
242
    	try{
243
    		validator.validate(inAppStream);
244
    	}catch(AdapterException e){    		
245
    		log(e.toString());
246
    	}    	
247
    }
248
    
249
    /* (non-Javadoc)
250
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#prepareAdapter(boolean)
251
	 */
252
    public void prepareAdapter(boolean validating) throws AdapterException {
253
    	/* Open the context and configuration files */
254
        try {
255
    		inContextParams = new FileInputStream(contextConfigurationFile);
256
    		if (singleFileInputMode) {
257
    			inAppParams = new FileInputStream(contextConfigurationFile);
258
    		}
259
    		else {
260
    			inAppParams = new FileInputStream(componentConfigurationFile);
261
    		}
262
    	}
263
    	catch(FileNotFoundException e) {
264
    		String filename=null;
265
    		if(inContextParams==null) {
266
    			filename=contextConfigurationFile;
267
    		}
268
    		else {
269
    			filename=componentConfigurationFile;
270
    			try {
271
    				inContextParams.close();
272
    			}
273
    			catch(IOException eprime) {
274
    				/* We will ignore if this fails.  It should be successful as we just opened the file */
275
    			}	
276
    		}
277
        	/* We cannot open the adapter file */
278
        	throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Open_ERROR_", filename));
279
    	}
280
    	catch (Throwable e) {
281
     		String filename=null;
282
    		if(inContextParams==null) {
283
    			filename=contextConfigurationFile;
284
    		}
285
    		else {
286
    			filename=componentConfigurationFile;
287
    			try {
288
    				inContextParams.close();
289
    			}
290
    			catch(IOException eprime) {
291
    				/* We will ignore if this fails.  It should be successful as we just opened the file */
292
    			}	
293
    		}
294
        	/* We cannot open the adapter file */
295
        	throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Open_ERROR_", filename),e);
296
    	}
297
        
298
        // build the contexts based on configurations     	
299
        try {
300
        	contexts = createContextsAndComponents(inContextParams);
301
        	synchronized(contexts) {
302
        		setComponentConfigurations(inAppParams);
303
        	}
304
	        
305
	        /* We are done with the files.  Lets close them */
306
	        try {
307
	        	inContextParams.close();
308
	        	if(!singleFileInputMode) {
309
	        		inAppParams.close();
310
	        	}	
311
	        }
312
	        catch(IOException e) {
313
	        	/* We just had the file open. We are now closing it */
314
	        }
315
316
            /* Before we start the contexts locate any IContextListeners that
317
             * are registered with the plugin.  This only works when we are running
318
             * as a plugin inside of Eclipse.  Outside of Eclipse there is no notion
319
             * of IContextListeners.
320
             */
321
	        if (AdapterUtilities.isWorkbench()) {
322
	            try {
323
	                List contextListeners = AdapterPlugin.getContextListeners();
324
	
325
	                /* If this context has a listener then set it */
326
	                if (contextListeners != null) {
327
	                    Iterator listenerIterator = contextListeners.iterator();
328
	                    while (listenerIterator.hasNext()) {
329
	                        IContextListener listener = (IContextListener) listenerIterator.next();
330
	                        String[] targetContexts = listener.getTargetContextUniqueIds();
331
	                        for (int j = 0; j < targetContexts.length; j++) {
332
	                            for (int k = 0; k < contexts.length; k++) {
333
	                                if (contexts[k].getUniqueID().equals(targetContexts[j])) {
334
	                                    contexts[k].setContextListener(listener);
335
	                                }
336
	                            }
337
	                        }
338
	                    }
339
	                }
340
	            }
341
	            catch (AdapterException e) {
342
	            	throw e;
343
	            }
344
	            catch (Throwable e) {
345
	                throw new AdapterException(Messages.getString("HyadesGAInitialization_GetContextListeners_Failure_ERROR_"), e);
346
	            }
347
	        }
348
            
349
            /* Start the logging context in its entirty before we continue with anything else */
350
            IProcessUnit logger=startInternalLoggingContext();
351
352
            /* Validate the adapter configuration file against the schema files before starting the rest of the contexts.  
353
             * It would have been good to have done this above, however, we want our internal logging context running so that we 
354
             * can report any errors during validation
355
             */            
356
            inAppParams = new FileInputStream(contextConfigurationFile);
357
            validateAdapterConfigurations(inAppParams, logger);
358
 
359
            if (!singleFileInputMode) {
360
                inAppParams = new FileInputStream(componentConfigurationFile);
361
                validateAdapterConfigurations(inAppParams, logger);
362
            }
363
            
364
            // Count the number of contexts that are initialized and ready to execute
365
            int contextsReadyCount = 0;
366
            AdapterException initException = null;
367
            
368
            synchronized(contexts) {
369
	            for (int i = 1; i < contexts.length; ++i) {
370
	                if (contexts[i] != null) {
371
	                	
372
	                	/* Set the logger for this context to be the internal logging sensor */
373
	                	contexts[i].setLogger(logger);
374
	                	
375
	                	/* Set the validating status for the context */
376
	                	contexts[i].setValidating(validating);
377
	                	
378
	                	/* bugzilla 96433
379
	                	 * Set logging level of context and components if it needs to be globally set
380
	                	 * and it is not being validated.
381
	                	 */ 
382
	                	if (!validating && loggingLevel > -1) {
383
	                		contexts[i].setLoggingLevel(loggingLevel);
384
	                		IComponent comp[] = contexts[i].getComponents();
385
	                		for (int j=0; j<comp.length; j++) {
386
	                			comp[j].setLoggingLevel(loggingLevel);
387
	                		}
388
	                	}
389
	                	
390
	                    // set all the context config info
391
	                    if (!(contexts[i].init())) {
392
	                    	contexts[i]=null;
393
	                    	/* Make sure we log that this context will not be started */
394
	                    	log(Messages.getString("HyadesGAContextFatal_ERROR_"));
395
	                    	continue;
396
	                    }
397
	                    // set all the component config info
398
	                    
399
	                    /* Setup the configuration information for this context.  At this point in time the context
400
	                     * may fail to initialize itself properly.  If that is the case then this context should be 
401
	                     * disabled.
402
	                     */
403
	                    try {
404
	                    	contexts[i].update();
405
	                    	// Only increment context ready count if context is not disabled
406
	                    	if (!contexts[i].isDisabled()) {
407
	                    		contextsReadyCount++;
408
	                    	}
409
	                    }
410
	                    catch(AdapterException e) {
411
	                    	if (!validating) {
412
	                    		contexts[i]=null;
413
	                    		/* Make sure we log that this context will not be started */
414
	                    		log(Messages.getString("HyadesGAContextFatal_ERROR_"));
415
	                    	}
416
	                    	initException = e;
417
	                    }
418
	                }
419
	            }
420
            }
421
            // If there are no contexts ready to execute then quit! 
422
            if (contextsReadyCount == 0) {
423
            	if (initException != null) {
424
            		throw initException;
425
            	}
426
            	else {
427
            		throw new AdapterException(Messages.getString("HyadesGAContextFatal_ERROR_"));
428
            	}
429
            }
430
        }   
431
        catch(Throwable e) {
432
        	/* RKD:  Our caller will need to use our exception information for now to handle the error.*/
433
			/* Don't log anything here.  Assume the caller handles the exception and 
434
			 * logs a message if necessary.
435
             * log(Messages.getString("HyadesGAAdapterFatal_ERROR_"));
436
          	 * log(e.toString());
437
			 */
438
        	if (e instanceof AdapterException) {
439
        		throw (AdapterException)e;
440
        	}
441
        	
442
        	// Wrap non-AdapterException in an AdapterException
443
        	String errorMsg = e.getMessage();
444
        	if (errorMsg == null) {
445
        	 	errorMsg = e.toString();
446
        	}
447
            throw new AdapterException(errorMsg);
448
        }
449
        finally {
450
        	
451
        	/* Close our configuration file */
452
            try {
453
                if (inAppParams != null) {
454
                	inAppParams.close();
455
                }
456
                if (inContextParams != null) {
457
                	inContextParams.close();
458
                }
459
            }
460
            catch (IOException e) {
461
            	/* We couldn't close the configuration files.  This should only occur if we failed to 
462
            	 * open the file in the first place.
463
            	 */
464
                log(e.toString());
465
            }
466
        }
467
    }
468
 
469
    /* (non-Javadoc)
470
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#prepareConfiguration(boolean)
471
	 */
472
    public void prepareConfiguration(boolean validating) throws AdapterException {
473
  	
474
        try {            
475
            /* Start the logging context in its entirty before we continue with anything else */
476
            IProcessUnit logger=startInternalLoggingContext();
477
478
            // Count the number of contexts that are initialized and ready to execute
479
            int contextsReadyCount = 0;
480
            AdapterException initException = null;
481
            
482
            synchronized(contexts) {
483
	            for (int i = 1; i < contexts.length; ++i) {
484
	                if (contexts[i] != null) {
485
	                	
486
	                	/* Set the logger for this context to be the internal logging sensor */
487
	                	contexts[i].setLogger(logger);
488
	                	
489
	                	/* Set the validating status for the context */
490
	                	contexts[i].setValidating(validating);
491
	                	
492
	                	/* bugzilla 96433
493
	                	 * Set logging level of context and components if it needs to be globally set
494
	                	 * and it is not being validated.
495
	                	 */ 
496
	                	if (!validating && loggingLevel > -1) {
497
	                		contexts[i].setLoggingLevel(loggingLevel);
498
	                		IComponent comp[] = contexts[i].getComponents();
499
	                		for (int j=0; j<comp.length; j++) {
500
	                			comp[j].setLoggingLevel(loggingLevel);
501
	                		}
502
	                	}
503
	                	
504
	                    // set all the context config info
505
	                    if (!(contexts[i].init())) {
506
	                    	contexts[i]=null;
507
	                    	/* Make sure we log that this context will not be started */
508
	                    	log(Messages.getString("HyadesGAContextFatal_ERROR_"));
509
	                    	continue;
510
	                    }
511
	                    // set all the component config info
512
	                    
513
	                    /* Setup the configuration information for this context.  At this point in time the context
514
	                     * may fail to initialize itself properly.  If that is the case then this context should be 
515
	                     * disabled.
516
	                     */
517
	                    try {
518
	                    	contexts[i].update();
519
	                    	// Only increment context ready count if context is not disabled
520
	                    	if (!contexts[i].isDisabled()) {
521
	                    		contextsReadyCount++;
522
	                    	}
523
	                    }
524
	                    catch(AdapterException e) {
525
	                    	if (!validating) {
526
	                    		contexts[i]=null;
527
	                    		/* Make sure we log that this context will not be started */
528
	                    		log(Messages.getString("HyadesGAContextFatal_ERROR_"));
529
	                    	}
530
	                    	initException = e;
531
	                    }
532
	                }
533
	            }
534
            }
535
            // If there are no contexts ready to execute then quit! 
536
            if (contextsReadyCount == 0) {
537
            	if (initException != null) {
538
            		throw initException;
539
            	}
540
            	else {
541
            		throw new AdapterException(Messages.getString("HyadesGAContextFatal_ERROR_"));
542
            	}
543
            }
544
        }   
545
        catch(Throwable e) {
546
        	/* RKD:  Our caller will need to use our exception information for now to handle the error.*/
547
			/* Don't log anything here.  Assume the caller handles the exception and 
548
			 * logs a message if necessary.
549
             * log(Messages.getString("HyadesGAAdapterFatal_ERROR_"));
550
          	 * log(e.toString());
551
			 */
552
        	if (e instanceof AdapterException) {
553
        		throw (AdapterException)e;
554
        	}
555
        	
556
        	// Wrap non-AdapterException in an AdapterException
557
        	String errorMsg = e.getMessage();
558
        	if (errorMsg == null) {
559
        	 	errorMsg = e.toString();
560
        	}
561
            throw new AdapterException(errorMsg);
562
        }
563
564
    }
565
    
566
    /**
567
     * parses Context configurations and build the Context objects
568
     * as well as set teh context config for each component
569
     */
570
    private Context[] createContextsAndComponents(InputStream inContextStream) throws PreparationException {
571
572
        Document doc = null;
573
        Context[] contexts = null;
574
        try {
575
            doc = docFactory.newDocumentBuilder().parse(inContextStream);
576
577
            //Add the adapter logging context as default:
578
            Element loggingContext = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXT);
579
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Context instance for the current component");
580
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.impl.AdapterContext");
581
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
582
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "60");
583
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, AdapterXMLConstants.HyadesGAAdapterContextName);
584
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "context");
585
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
586
            loggingContext.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NB1F4ED002DA11D8A519FBE7C98C2F53");
587
588
            Element loggingSensor = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
589
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter logging sensor");
590
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterSensor");
591
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
592
            // bugzilla 84698 - If there is an outputter Then let WARNING or higher messages be logged.
593
            if (logOutputter != null) {
594
            	loggingSensor.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
595
            }
596
            // Otherwise let all messages be logged
597
            else {
598
            	loggingSensor.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "0");
599
            }
600
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogSensor");
601
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "sensor");
602
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
603
            loggingSensor.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NF991E0004FF11D8930381B6A308BEB5");
604
605
            loggingContext.appendChild(loggingSensor);
606
607
            Element loggingOutputter = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
608
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter logging outputter");
609
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
610
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionAttributeName, "");
611
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionDescriptionAttributeName, "");
612
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "outputter");
613
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
614
            loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
615
616
            // Add the outputter specified by the user (eg. set by StaticParserWrapper in the log import case)
617
            if (logOutputter != null) {
618
            	//Set the logging level so we get Warning, Critical and Fatal error messages
619
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
620
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, logOutputter.getClass().getName());
621
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogOutputter");
622
                
623
                /*************************************************************************************************                
624
                 * bugzilla 79014 
625
                 * Comment this out because we should not need to log to a file in the log import
626
                 * case.  GLA messages will be handled by the outputter set by the user.
627
                 * However, we'll keep the code here in case we find it necessar to log to a file as well.              
628
                 *                  
629
                 * loggingContext.appendChild(loggingOutputter);
630
                 *               
631
                 * // Create a file outputter too
632
                 * loggingOutputter = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
633
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter File logging outputter");
634
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
635
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionAttributeName, "");
636
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAImplementationVersionDescriptionAttributeName, "");
637
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleAttributeName, "outputter");
638
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGARoleCreationDateAttributeName, "Fri Jan 09 15:27:17 EST 2004");
639
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "AdapterFileLoggerId");
640
                 * //Set the logging level so we get Warning, Critical and Fatal error messages
641
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
642
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterLogFileOutputter");
643
                 * loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogFileOutputter");
644
                 *
645
                 **************************************************************************************************/
646
            }
647
	        //Add the Eclipse Problems View outputter if in Eclipse mode. This is used when the context runs in the GLA editor.
648
	        else if (AdapterUtilities.isWorkbench()) {
649
            	//Set the logging level so we get any messages that are at least informational
650
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "10");
651
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.GlaTaskOutputter");
652
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "CBEEclipseProblemsViewOutputter");
653
            }
654
            //Add the log file outputter if in standalone mode:
655
            else {
656
            	//Set the logging level so we get Warning, Critical and Fatal error messages
657
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGALoggingLevelAttributeName, "30");
658
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName, "org.eclipse.hyades.logging.adapter.internal.util.AdapterLogFileOutputter");
659
                loggingOutputter.setAttribute(AdapterXMLConstants.HyadesGANameAttributeName, "AdapterLogFileOutputter");                
660
            }      
661
662
            loggingContext.appendChild(loggingOutputter);
663
664
            NodeList contextsNodeList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTS);
665
666
            if (contextsNodeList.getLength() == 0) {
667
668
                //Create a contexts element:	
669
                Element contextsElement = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTS);
670
                
671
                /* Insert the logging context at the first of the child list of elements */
672
                NodeList children=contextsElement.getChildNodes();
673
                for(int i=0; i<children.getLength(); i++) {
674
                	if(children.item(i).getNodeType()==Node.ELEMENT_NODE) {
675
                		contextsElement.insertBefore(loggingContext, children.item(i));
676
                		break;
677
                	}	
678
                }
679
680
                doc.getDocumentElement().appendChild(contextsElement);
681
            }
682
            else {
683
684
                //ASSUMPTION:  Only one contexts element permitted.	
685
686
                //Retrieve the contexts element:	
687
                Node contextsElement = contextsNodeList.item(0);
688
                /* Insert the logging context at the first of the child list of elements */
689
                NodeList children=contextsElement.getChildNodes();
690
                for(int i=0; i<children.getLength(); i++) {
691
                	if(children.item(i).getNodeType()==Node.ELEMENT_NODE) {
692
                		contextsElement.insertBefore(loggingContext, children.item(i));
693
                		break;
694
                	}	
695
                }
696
697
                doc.getDocumentElement().appendChild(contextsElement);
698
            }
699
700
            try {
701
                NodeList contextList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXT);
702
                // check to see if this file contains everything or just the context config
703
                NodeList tempInstanceList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
704
                if (tempInstanceList.getLength() > 0)
705
                    singleFileInputMode = true;
706
                else
707
                    singleFileInputMode = false;
708
                int count = contextList.getLength();
709
                contexts = new Context[count];
710
                int j = 0;
711
                Element element = null;
712
                Context context = null;
713
                Component component = null;
714
                
715
                for (int i = 0; i < count; ++i) {
716
                    //TODO: HS need to support imbedded/nested contexts/components
717
                    // Extract each root context and copy the expected attributes
718
                    element = (Element) contextList.item(i);
719
                	/* try and build the context.  A number of things can go wrong here as we use relection to build the instance. */
720
                	context = ContextFactory.buildContext(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));	
721
                	context.setContextConfiguration(element);
722
723
                    //
724
                    // get a list of all sub elements and assume they are components
725
                    NodeList componentList = element.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_COMPONENT);
726
                    IComponent[] compArray = null;
727
                    int componentCount = componentList.getLength();
728
                    compArray = new IComponent[componentCount];
729
                    for (int k = 0, l = 0; k < componentCount; k++) {
730
                        // Extract each component config
731
                        element = (Element) componentList.item(k);
732
733
                        // Check if we have a log outputter object already and if so then use that
734
                        if (i == 0 && k ==1 && logOutputter != null) {
735
                        	component = (Component)logOutputter;
736
                        	component.setName(element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));
737
                        	component.setUniqueID(element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName));
738
                        	component.setExecutableClassName(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName));
739
                        }
740
                        else {
741
                        	component = ComponentFactory.buildComponent(element.getAttribute(AdapterXMLConstants.HyadesGAExecutableClassAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName), element.getAttribute(AdapterXMLConstants.HyadesGANameAttributeName));
742
                        }
743
                        component.setContextConfiguration(element);
744
                        compArray[l++] = component;
745
                    }
746
                    // put the components in the context
747
                    context.setComponents(compArray);
748
                    // put this context in the controller's array
749
                    contexts[j++] = context;
750
                }
751
            }
752
            catch (PreparationException e) {
753
                throw e;
754
            }
755
            catch (Exception e) {
756
                throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextConfiguration_Failure_ERROR_", contextConfigurationFile), e);
757
            }
758
        }
759
        catch (SAXException e) {
760
        	/* We have a problem parsing the configuration file ABORT */
761
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
762
        }
763
        catch (ParserConfigurationException e) {
764
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
765
        }
766
        catch (IOException e) {
767
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", contextConfigurationFile), e);
768
        }
769
        return contexts;
770
    }
771
772
    /**
773
     * CreateContextsConfig takes in an entire component configurations file and
774
     * separates out the context instances and gives each context the sub tree for itself and
775
     * it's components.
776
     */
777
    private void setComponentConfigurations(InputStream inAppStream) throws AdapterInvalidConfig, PreparationException {
778
779
        Document doc = null;
780
781
        try {
782
783
            doc = docFactory.newDocumentBuilder().parse(inAppStream);
784
785
            //Add the adapter internal logging context instance as default:
786
            Element loggingSensorInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_SENSOR);
787
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "An adapter CBE sensor");
788
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGAmaximumBlockingAttributeName, "5");
789
            loggingSensorInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NF991E0004FF11D8930381B6A308BEB5");
790
791
            Element loggerContextInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
792
            loggerContextInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Context instance for the current component");
793
            /* Configure the internal logging context to run forever or until the adatper is explicitly stopped */ 
794
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_CONTINUOUS_OPERATION, "true");
795
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_MAXIMUM_IDLE_TIME, "0");
796
            loggerContextInstance.setAttribute(AdapterXMLConstants.CONTEXTINSTANCE_ATTR_NAME_PAUSE_INTERVAL, "10");
797
            loggerContextInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "NB1F4ED002DA11D8A519FBE7C98C2F53");
798
799
            loggerContextInstance.appendChild(loggingSensorInstance);
800
801
            // Configure the log outputter for the log import case
802
            if (logOutputter != null) {
803
				Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
804
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Adapter log outputter");
805
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
806
				
807
				/* This outputter is created and configured by the user so there will not be any configuration properties for it. */
808
				
809
                loggerContextInstance.appendChild(loggingOutputterInstance);
810
                
811
                /*************************************************************************************************                
812
                 *              bugzilla 79014 
813
                 *              Comment this out because we should not need to log to a file in the log import
814
                 *              case.  GLA messages will be handled by the outputter set by the user.
815
                 *              However, we'll keep the code here in case we find it necessary to log to a file as well.              
816
                 *   
817
                 *              // Get the directory for the GLA log file
818
                 *              String glaLogDirectory = ".";
819
                 *       		try {
820
                 *       			
821
                 *       			// Try to get the plugin's workspace directory (e.g. <workspace>/.metadata/plugins/org.eclipse.hyades.logging.adapter) 
822
                 *
823
                 *       			Class platformClass = Class.forName("org.eclipse.core.runtime.Platform");
824
                 *       			
825
                 *       			Method getPluginStateLocationMethod = platformClass.getMethod("getPluginStateLocation",new Class[]{Class.forName("org.eclipse.core.runtime.Plugin")});
826
                 *       			
827
                 *       			Object iPathObject =  getPluginStateLocationMethod.invoke(null,new Object[]{AdapterPlugin.getPlugin()});
828
                 *       			
829
                 *       			Class iPathClass = iPathObject.getClass();
830
                 *       			
831
                 *       			Method toOSStringMethod = iPathClass.getMethod("toOSString",null);
832
                 *       			
833
                 *       			glaLogDirectory = (String)(toOSStringMethod.invoke(iPathObject,null));
834
                 *       		}
835
                 *       		catch (Exception e) {
836
                 *       			// Ignore this and use the current directory for the GLA log file
837
                 *       		}
838
                 *       		
839
                 *               // Add the file logger component configuration
840
                 *               loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
841
                 *               loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Single file outputter");
842
                 *               loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "AdapterFileLoggerId");
843
                 *
844
                 *				 Element outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
845
                 *               outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, glaLogDirectory);
846
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAdirectoryAttributeName);
847
                 *               loggingOutputterInstance.appendChild(outputterProperty);
848
                 *               
849
                 *				 outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
850
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, "hgla.log");
851
                 *				 outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAfileNameAttributeName);
852
                 *				 loggingOutputterInstance.appendChild(outputterProperty);                
853
                 *				
854
                 *               loggerContextInstance.appendChild(loggingOutputterInstance);
855
                 * 
856
                 ************************************************************************************/	
857
            }
858
            // Configure the Problems View outputter for the GLA editor case
859
            else if (AdapterUtilities.isWorkbench()) {
860
            	
861
				Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
862
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Eclipse error dialog outputter");
863
				loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
864
				
865
				/* RKD:  We need to inform the outputter of the configuration path so it can create markers for the resource */
866
		        Element resourcePathProperty=doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
867
	            resourcePathProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName, "resourceName");
868
	            resourcePathProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, contextConfigurationFile);
869
	                
870
	            loggingOutputterInstance.appendChild(resourcePathProperty);
871
                loggerContextInstance.appendChild(loggingOutputterInstance);			
872
            }
873
            else{
874
875
                Element loggingOutputterInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_OUTPUTTER);
876
                loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "Single file outputter");
877
                loggingOutputterInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N5F286A002DA11D8BC799C6AF4352915");
878
879
				Element outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
880
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, ".");
881
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAdirectoryAttributeName);
882
                loggingOutputterInstance.appendChild(outputterProperty);
883
                
884
				outputterProperty = doc.createElement(AdapterXMLConstants.HyadesGAPropertyElementTagName);
885
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyValueAttributeName, "hgla.log");
886
				outputterProperty.setAttribute(AdapterXMLConstants.HyadesGAPropertyNameAttributeName,AdapterXMLConstants.HyadesGAfileNameAttributeName);
887
				loggingOutputterInstance.appendChild(outputterProperty);                
888
				
889
                loggerContextInstance.appendChild(loggingOutputterInstance);
890
            }
891
892
            NodeList configurationNodeList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONFIGURATION);
893
894
            if (configurationNodeList.getLength() == 0) {
895
896
                //Create a configuration element:	
897
                Element loggerConfigurationInstance = doc.createElement(AdapterXMLConstants.ELEMENT_TAG_NAME_CONFIGURATION);
898
                loggerConfigurationInstance.setAttribute(AdapterXMLConstants.HyadesGADescriptionAttributeName, "The component level configurations for this adapter");
899
                loggerConfigurationInstance.setAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName, "N06FBD3004FF11D8BCF4CFA9EA8F31E7");
900
901
                loggerConfigurationInstance.appendChild(loggerContextInstance);
902
903
                doc.getDocumentElement().appendChild(loggerConfigurationInstance);
904
            }
905
            else {
906
907
                //ASSUMPTION:  Only one configuration element permitted.	
908
909
                //Retrieve the configuration element:	
910
                Node loggerConfigurationInstance = configurationNodeList.item(0);
911
                loggerConfigurationInstance.appendChild(loggerContextInstance);
912
913
                doc.getDocumentElement().appendChild(loggerConfigurationInstance);
914
            }
915
916
            try {
917
                // get a list of all the context instances and associates each with a context
918
                NodeList contextInstanceList = doc.getElementsByTagName(AdapterXMLConstants.ELEMENT_TAG_NAME_CONTEXTINSTANCE);
919
920
                int contextInstanceCount = contextInstanceList.getLength();
921
                for (int i = 0; i < contextInstanceCount; ++i) {
922
                    try {
923
                        //find the matching Context and Context Instance
924
                        Element contextElement = (Element) contextInstanceList.item(i);
925
                        String contextInstanceID = contextElement.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName);
926
927
                        int contextCount = contexts.length;
928
						/* Throw an exception if we have a mismatch in the number of Context's and
929
						 * the number of ContextInstance's.
930
						 */
931
						if (contextInstanceCount != contextCount) {
932
							throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextConfigurationErrorContextCountMismatchFatal_ERROR_"));
933
						}                       
934
                        
935
                        boolean contextFound = false;
936
                        for (int j = 0; j < contextCount; j++) {
937
                            if (contexts[j].getUniqueID().equals(contextInstanceID)) {
938
                                contexts[j].setConfiguration(contextElement);
939
                                contextFound = true;
940
                                // so now we have a good context which may or may not have components
941
                                //assume each child of the contextInstance is a component
942
                                NodeList componentInstanceList = contextElement.getChildNodes();
943
                                int numberOfComponentInstances = componentInstanceList.getLength();
944
                                // get the components from the context
945
								IComponent components[] = contexts[j].getComponents();
946
								int componentCount = components.length;
947
948
								int componentInstanceCount = 0;
949
                                for (int k = 0; k < numberOfComponentInstances; k++) {
950
                                    if (componentInstanceList.item(k).getNodeType() == Node.ELEMENT_NODE) {
951
                                        Element componentElement = (Element) componentInstanceList.item(k);
952
                                        String componentInstanceID = componentElement.getAttribute(AdapterXMLConstants.HyadesGAUniqueIDAttributeName);
953
                                        boolean componentFound = false;
954
                                        componentInstanceCount++;
955
                                        // walk through the components of the context and set the config
956
                                        for (int l = 0; l < componentCount; l++) {
957
                                            if (components[l].getUniqueID().equals(componentInstanceID)) {
958
                                                components[l].setConfiguration(componentElement);
959
                                                componentFound = true;
960
                                                /* bugzilla 82193
961
                                                 * If this is a formatter and we are running in the GLA editor
962
                                                 */
963
                                                if (componentElement.getNodeName().equals(AdapterXMLConstants.ELEMENT_TAG_NAME_FORMATTER) && 
964
                                                		logOutputter == null &&	AdapterUtilities.isWorkbench()) {
965
                                                	/* Add the test attribute to the formatter element to indicate we are running
966
                                                	 * in the GLA editor environment.  
967
                                                	 */
968
                                                	componentElement.setAttribute(AdapterConstants.AttrubuteName_Test,AdapterConstants.AttrubuteValue_Test_True);
969
                                                }
970
                                                break;
971
                                            }
972
                                        }
973
                                        if (!componentFound) {
974
											throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorComponentIdNotFoundFatal_ERROR_",componentInstanceID , contexts[j].getUniqueID()));
975
                                        }
976
                                    }
977
                                }
978
								/* Throw an exception if we have a mismatch in number of components between
979
								 * the context and the contextInstance.
980
								 */
981
								if (componentInstanceCount != componentCount) {
982
									throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorComponentMismatchFatal_ERROR_",contexts[j].getUniqueID()));
983
								}
984
                                break;
985
                            }
986
                        }
987
						if (!contextFound) {
988
							throw new AdapterInvalidConfig(Messages.getString("HyadesGAContextInstanceConfigurationErrorContextIdNotFoundFatal_ERROR_", contextInstanceID));
989
						}
990
                    }
991
                    catch (AdapterInvalidConfig e) {
992
                    	throw e;
993
                    }
994
                    catch (Exception e) {
995
                        throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextInstanceConfiguration_Failure_ERROR_", componentConfigurationFile), e);
996
                    }
997
                }
998
            }
999
            catch (AdapterInvalidConfig e) {
1000
            	throw e;
1001
            }
1002
            catch (Exception e) {
1003
                throw new PreparationException(Messages.getString("HyadesGAInitialization_ContextInstanceConfiguration_Failure_ERROR_", componentConfigurationFile), e);
1004
            }
1005
        }
1006
        catch (SAXException e) {
1007
        	/* We have a problem parsing the configuration file ABORT */
1008
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1009
        }
1010
        catch (ParserConfigurationException e) {
1011
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1012
        }
1013
        catch (IOException e) {
1014
            throw new PreparationException(Messages.getString("HyadesGA_CBE_Adapter_Config_File_Parse_ERROR_", componentConfigurationFile), e);
1015
        }
1016
    }
1017
    /* (non-Javadoc)
1018
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#run()
1019
	 */
1020
    public void run() {
1021
        start();
1022
        while (isRunning()) {
1023
            synchronized (this) {
1024
                try {
1025
                    wait(sleepTime);
1026
                }
1027
                catch (Exception e) {
1028
                    log(e.toString());
1029
                }
1030
                if (areContextsDone()) {
1031
               	    // Stop the Adapter logging context
1032
                    stop();
1033
                }
1034
            }
1035
        }
1036
    }
1037
    /**
1038
     * return false if any context is still alive, otherwise return true 
1039
     */
1040
    private boolean areContextsDone() {
1041
        if (contextThreads != null) {
1042
        	/* Ignore the internal logging context.  hense we start at index 1 */
1043
            for (int i = 1; i < contextThreads.length; i++) {
1044
                if (contextThreads[i] != null) {
1045
                    if (contextThreads[i].isAlive() && !(contexts[i] instanceof AdapterContext))
1046
                        return false;
1047
                }
1048
            }
1049
        }
1050
        return true;
1051
    }
1052
    
1053
    /**
1054
     * clean a controller by nulling out everything
1055
     */
1056
    private void clean() {
1057
        if (contexts != null) {
1058
            for (int i = 0; i < contexts.length; i++) {
1059
                contexts[i] = null;
1060
            }
1061
        }
1062
        contexts = null;
1063
        //		hashContextConfig.clear();
1064
    }
1065
    
1066
    /**
1067
     * Starts the internal logging context.
1068
     *
1069
     */
1070
    private IProcessUnit startInternalLoggingContext() {
1071
    	contexts[0].init();
1072
    	contextThreads=new Thread[contexts.length];
1073
        try {
1074
        	contexts[0].update();
1075
        	// bugzilla 96433 - Reset the logging context status
1076
        	contexts[0].setStopping(false);
1077
        	contextThreads[0]=new Thread(contexts[0]);
1078
        	contextThreads[0].setName(contexts[0].getName() + AdapterConstants.HyadesGA + contexts[0].getUniqueID());
1079
        	contextThreads[0].setDaemon(true);
1080
        	contextThreads[0].start();
1081
        	return (IProcessUnit)contexts[0].getComponents()[0];
1082
        	
1083
        }
1084
        catch(AdapterException e) {
1085
        	/* Since we are generating the context content we should not have configuration problems */
1086
        	/* However, we may get an exception here if the GLA logging cannot be initialized. */
1087
			log(Messages.getString("HyadesGAInitialization_Internal_Logging_Not_Started_WARN_", e.getLocalizedMessage()));
1088
        }
1089
        catch(Exception e) {
1090
        	/* Catch any other kind of exception and log a message */
1091
        	log(Messages.getString("HyadesGAInitialization_Internal_Logging_Not_Started_WARN_", e.toString()));
1092
        }
1093
        return null;
1094
    }
1095
    
1096
    /* (non-Javadoc)
1097
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#log(java.lang.String)
1098
	 */
1099
    public void log(String logRecord) {
1100
    	if(!AdapterUtilities.isWorkbench()) {
1101
    		System.err.println(logRecord);
1102
    	}
1103
       
1104
    }
1105
    
1106
    /* (non-Javadoc)
1107
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getStatus()
1108
	 */
1109
    public Status [] getStatus() {
1110
    	Status [] statuses = null; 
1111
    	
1112
    	/* If there are context then get their status */
1113
	    if (contexts != null) {
1114
	    	synchronized(contexts) {
1115
	        	statuses = new Status[contexts.length];
1116
	        	/* get the status for each context */        	
1117
	            for (int i=0; i < contexts.length; i++) {
1118
	            	if (contexts[i] != null) {
1119
	            		statuses[i] = contexts[i].getContextStatus();
1120
	            	}
1121
	            	else {
1122
	            		statuses[i] = null;
1123
	            	}
1124
	            }
1125
	        }
1126
    	}
1127
    	
1128
    	return statuses;
1129
    }
1130
	
1131
	/* (non-Javadoc)
1132
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getLogOutputter()
1133
	 */
1134
	public IOutputter getLogOutputter() {
1135
		return logOutputter;
1136
	}
1137
	/* (non-Javadoc)
1138
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#setLogOutputter(org.eclipse.hyades.logging.adapter.IOutputter)
1139
	 */
1140
	public void setLogOutputter(IOutputter logOutputter) {
1141
		this.logOutputter = logOutputter;
1142
	}
1143
	
1144
    /* (non-Javadoc)
1145
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#setLoggingLevel(short)
1146
	 */
1147
	public void setLoggingLevel(short newLevel)
1148
	{
1149
		loggingLevel = newLevel;
1150
	}
1151
1152
	/* (non-Javadoc)
1153
	 * @see org.eclipse.hyades.logging.adapter.internal.util.IController#getLoggingLevel()
1154
	 */
1155
	public short getLoggingLevel() {
1156
		return loggingLevel;
1157
	}
1158
}
(-)src/org/eclipse/hyades/logging/adapter/provisional/util/IController.java (+150 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Controller.java,v 1.9 2007/03/22 05:29:24 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 * 
12
 **********************************************************************/
13
14
package org.eclipse.hyades.logging.adapter.provisional.util;
15
16
import org.eclipse.hyades.logging.adapter.AdapterException;
17
import org.eclipse.hyades.logging.adapter.IContext;
18
import org.eclipse.hyades.logging.adapter.IOutputter;
19
import org.eclipse.hyades.logging.adapter.impl.Status;
20
21
/**
22
 * This interface represents a Controller that manages a set of Context 
23
 * objects by setting the configurations and then starting each context.
24
 * 
25
 * @author dnsmith
26
 */
27
28
public interface IController extends Runnable {
29
30
	/**
31
	 * Returns whether the Controller is running.
32
	 * @return true if Controller is running, false otherwise
33
	 */
34
	public boolean isRunning();
35
36
	/**
37
	 * Start running the controller which means starting up each of the contexts.
38
	 */
39
	public void start();
40
41
	/**
42
	 * Stop the controller which means stopping all of the contexts if they
43
	 * are still running.
44
	 */
45
	public void stop();
46
47
	/**
48
	 * This stop method will still cause the contexts to be stopped but will
49
	 * not call the context listener methods when flushing the components.
50
	 */
51
	public void hardStop();
52
53
	/**
54
	 * Get the set of Context objects
55
	 * @return the set of Context objects
56
	 */
57
	public IContext[] getContexts();
58
59
	/**
60
	 * Set the name of the file containing the configurations for the
61
	 * contexts.
62
	 * @param config - name of the context configuation file
63
	 */
64
	public void setContextConfigPath(String config);
65
66
	/**
67
	 * Get the name of the file containing the configurations for the contexts
68
	 * @return the contextConfigurationFile
69
	 */
70
	public String getContextConfigPath();
71
72
	/**
73
	 * Set the name of the file containing the configurations for the
74
	 * components of the contexts.
75
	 * @param config - name of the component configuation file
76
	 */
77
	public void setComponentConfigPath(String config);
78
79
	/**
80
	 * Get the name of the file containing the configurations for the components of the contexts.
81
	 * @return the componentConfigurationFile
82
	 */
83
	public String getComponentConfigPath();
84
85
	/**
86
	 * Prepare the adapter for execution.  This involves reading and validating the adapter 
87
	 * configuration file(s), getting the context listeners from eclipse, starting the internal
88
	 * logging context, and initializing the contexts.
89
	 * @param validating  boolean flag to indicate this method is called as part of adapter validation
90
	 */
91
	public void prepareAdapter(boolean validating) throws AdapterException;
92
93
	/**
94
	 * Prepare the adapter configuration for execution.  This involves 
95
	 * starting the internal logging context, and initializing the contexts.
96
	 * @param validating  boolean flag to indicate this method is called as part of adapter validation
97
	 */
98
	public void prepareConfiguration(boolean validating)
99
			throws AdapterException;
100
101
	/**
102
	 * run provides the basic loop for a Controller thread.  It starts the Controller thread and
103
	 * then monitors it.
104
105
	public void run();
106
	 */
107
	/**
108
	 * Log the string message to standard error since the logging outputter(s)
109
	 * associated with the <code>AdapterSensor</code> logger will never be
110
	 * started.
111
	 * 
112
	 * @param logRecord The string message to be logged to standard error.
113
	 */
114
	public void log(String logRecord);
115
116
	/**
117
	 * Get the status of the contexts
118
	 * @return the array of Status objects representing the status of the contexts
119
	 */
120
	public Status[] getStatus();
121
122
	/**
123
	 * Get the custom Outputter that the internal logging context is using.
124
	 * @return Returns the custom Outputter that the internal logging context is using.
125
	 */
126
	public IOutputter getLogOutputter();
127
128
	/**
129
	 * Sets the custom Outputter for the internal logging context to use.
130
	 * @param logOutputter The custom Outputter for the internal logging context.
131
	 */
132
	public void setLogOutputter(IOutputter logOutputter);
133
134
	/**
135
	 * Sets the loggingLevel of the Adapter object.  This value will override 
136
	 * all values in the adapter configuration. The logging level value specified will
137
	 * take effect the next time the Adapter is started. If this method is 
138
	 * not called or is called with a value of -1, the logging levels specified in the
139
	 * adapter configuration will be used.
140
	 * @param newLevel The level of logging that the Adapter will use during execution
141
	 */
142
	public void setLoggingLevel(short newLevel);
143
144
	/**
145
	 * Get the logging level of the Adapter object.
146
	 * @return the level of logging the Adapter is currently using
147
	 */
148
	public short getLoggingLevel();
149
150
}
(-)src/org/eclipse/hyades/logging/adapter/provisional/util/IControllerFactory.java (+30 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: Controller.java,v 1.9 2007/03/22 05:29:24 dnsmith Exp $
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation
11
 * 
12
 **********************************************************************/
13
14
package org.eclipse.hyades.logging.adapter.provisional.util;
15
16
/**
17
 * This interface represents a factory to create IController instances.
18
 * 
19
 * @author dnsmith
20
 *
21
 */
22
public interface IControllerFactory {
23
24
	/**
25
	 * Gets an instance of an IController class
26
	 * @return IController instance
27
	 */
28
	public IController getController();
29
	
30
}
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/RemoteImportHandler.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 44-50 Link Here
44
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
44
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
45
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
45
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
46
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
46
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
47
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogImportLoader;
47
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogImportLoader;
48
import org.eclipse.hyades.models.hierarchy.TRCAgent;
48
import org.eclipse.hyades.models.hierarchy.TRCAgent;
49
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
49
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
50
import org.eclipse.hyades.models.hierarchy.TRCProcessProxy;
50
import org.eclipse.hyades.models.hierarchy.TRCProcessProxy;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/ImportLogHelper.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005,2007 IBM Corporation and others.
2
 * Copyright (c) 2005,2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 46-52 Link Here
46
import org.eclipse.hyades.logging.parsers.adapter.sensors.StaticParserSensor;
46
import org.eclipse.hyades.logging.parsers.adapter.sensors.StaticParserSensor;
47
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
47
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
48
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
48
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
49
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
49
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
50
import org.eclipse.hyades.models.hierarchy.TRCAgent;
50
import org.eclipse.hyades.models.hierarchy.TRCAgent;
51
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
51
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
52
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
52
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/AbstractImportHandler.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-23 Link Here
17
import java.util.Map;
17
import java.util.Map;
18
18
19
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogImportLoader;
20
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogImportLoader;
21
import org.eclipse.hyades.models.hierarchy.util.ISessionManager;
21
import org.eclipse.hyades.models.hierarchy.util.ISessionManager;
22
import org.eclipse.hyades.models.hierarchy.util.internal.SessionManagerWrapper;
22
import org.eclipse.hyades.models.hierarchy.util.internal.SessionManagerWrapper;
23
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.IErrorHandler;
23
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.IErrorHandler;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/AbstractLocalImportHandler.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 29-36 Link Here
29
import org.eclipse.hyades.logging.parsers.internal.adapter.formatters.LocalLogImportCBEFormatter;
29
import org.eclipse.hyades.logging.parsers.internal.adapter.formatters.LocalLogImportCBEFormatter;
30
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
30
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
31
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoMemoryOutputter;
31
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoMemoryOutputter;
32
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogImportLoader;
32
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogImportLoader;
33
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogParserLoader;
33
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogParserLoader;
34
import org.eclipse.hyades.models.hierarchy.TRCAgent;
34
import org.eclipse.hyades.models.hierarchy.TRCAgent;
35
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
35
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
36
import org.eclipse.hyades.models.hierarchy.util.ISessionManager;
36
import org.eclipse.hyades.models.hierarchy.util.ISessionManager;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/GLAFilterHelper.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 69-75 Link Here
69
import org.eclipse.hyades.logging.events.cbe.EventPackage;
69
import org.eclipse.hyades.logging.events.cbe.EventPackage;
70
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
70
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
71
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
71
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
72
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
72
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
73
import org.eclipse.hyades.models.cbe.CBEPackage;
73
import org.eclipse.hyades.models.cbe.CBEPackage;
74
import org.eclipse.hyades.models.hierarchy.TRCAgent;
74
import org.eclipse.hyades.models.hierarchy.TRCAgent;
75
import org.eclipse.hyades.models.hierarchy.extensions.BinaryExpression;
75
import org.eclipse.hyades.models.hierarchy.extensions.BinaryExpression;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/LocalDownloadImportHandler.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 31-37 Link Here
31
import org.eclipse.core.runtime.Status;
31
import org.eclipse.core.runtime.Status;
32
import org.eclipse.hyades.execution.local.CommunicationDebug;
32
import org.eclipse.hyades.execution.local.CommunicationDebug;
33
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
33
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
34
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
34
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
35
import org.eclipse.hyades.ui.internal.util.StringUtil;
35
import org.eclipse.hyades.ui.internal.util.StringUtil;
36
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.IImportHandler;
36
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.IImportHandler;
37
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.ILogFileElement;
37
import org.eclipse.tptp.monitoring.log.provisional.cbeimport.ILogFileElement;
(-)cbe.import/org/eclipse/tptp/monitoring/log/internal/core/LocalImportHandler.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 25-31 Link Here
25
import org.eclipse.core.runtime.Status;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.hyades.loaders.util.LoadersUtils;
26
import org.eclipse.hyades.loaders.util.LoadersUtils;
27
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
27
import org.eclipse.hyades.logging.parsers.LoggingParsersPlugin;
28
import org.eclipse.hyades.logging.parsers.internal.importer.LocalGLALogger;
28
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalGLALogger;
29
import org.eclipse.hyades.models.hierarchy.util.MonitoredInputStream;
29
import org.eclipse.hyades.models.hierarchy.util.MonitoredInputStream;
30
import org.eclipse.hyades.models.util.ModelDebugger;
30
import org.eclipse.hyades.models.util.ModelDebugger;
31
import org.eclipse.osgi.util.NLS;
31
import org.eclipse.osgi.util.NLS;
(-)src/org/eclipse/tptp/monitoring/logui/internal/wizards/LogSetManager.java (-1 / +1 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
(-)src/org/eclipse/tptp/monitoring/logui/internal/wizards/LocalLogParserLoader.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 19-29 Link Here
19
import org.eclipse.hyades.logging.events.cbe.util.EventFormatter;
19
import org.eclipse.hyades.logging.events.cbe.util.EventFormatter;
20
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
20
import org.eclipse.hyades.logging.events.cbe.util.EventHelpers;
21
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
21
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
22
import org.eclipse.hyades.logging.parsers.internal.importer.LocalLogImportLoader;
22
import org.eclipse.hyades.logging.parsers.provisional.importer.LocalLogImportLoader;
23
23
24
/**
24
/**
25
 * 
25
 * 
26
 * @deprecated since TPTP 4.4 - this class was moved to org.eclipse.hyades.logging.parsers.internal.importer
26
 * @deprecated since TPTP 4.4 - this class was moved to org.eclipse.hyades.logging.parsers.provisional.importer
27
 * package in TPTP 4.3.
27
 * package in TPTP 4.3.
28
 *
28
 *
29
 */
29
 */
(-)src/org/eclipse/tptp/monitoring/logui/internal/wizards/LocalGLALogger.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 20-26 Link Here
20
20
21
/**
21
/**
22
 * 
22
 * 
23
 * @deprecated since TPTP 4.4 - this class was moved to org.eclipse.hyades.logging.parsers.internal.importer
23
 * @deprecated since TPTP 4.4 - this class was moved to org.eclipse.hyades.logging.parsers.provisional.importer
24
 * package in TPTP 4.3.
24
 * package in TPTP 4.3.
25
 *
25
 *
26
 */
26
 */
(-)src/org/eclipse/tptp/monitoring/logui/internal/wizards/ImportLogWizard.java (-1 / +1 lines)
Lines 54-60 Link Here
54
import org.eclipse.hyades.loaders.util.LoadersUtils;
54
import org.eclipse.hyades.loaders.util.LoadersUtils;
55
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
55
import org.eclipse.hyades.logging.parsers.importer.ILogParser;
56
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
56
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
57
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
57
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
58
import org.eclipse.hyades.models.hierarchy.CorrelationContainerProxy;
58
import org.eclipse.hyades.models.hierarchy.CorrelationContainerProxy;
59
import org.eclipse.hyades.models.hierarchy.TRCAgent;
59
import org.eclipse.hyades.models.hierarchy.TRCAgent;
60
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
60
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
(-)src/org/eclipse/tptp/monitoring/logui/internal/util/ImportLogHelper.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 43-49 Link Here
43
import org.eclipse.hyades.logging.parsers.adapter.sensors.StaticParserSensor;
43
import org.eclipse.hyades.logging.parsers.adapter.sensors.StaticParserSensor;
44
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
44
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
45
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
45
import org.eclipse.hyades.logging.parsers.internal.adapter.outputters.CBEtoCSVOutputter;
46
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
46
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
47
import org.eclipse.hyades.models.hierarchy.TRCAgent;
47
import org.eclipse.hyades.models.hierarchy.TRCAgent;
48
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
48
import org.eclipse.hyades.models.hierarchy.TRCAgentProxy;
49
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
49
import org.eclipse.hyades.models.hierarchy.util.IHyadesResourceExtension;
(-)src/org/eclipse/tptp/monitoring/logui/internal/util/GLAFilterHelper.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 67-73 Link Here
67
import org.eclipse.hyades.logging.adapter.model.internal.outputter.OutputterFactory;
67
import org.eclipse.hyades.logging.adapter.model.internal.outputter.OutputterFactory;
68
import org.eclipse.hyades.logging.events.cbe.EventPackage;
68
import org.eclipse.hyades.logging.events.cbe.EventPackage;
69
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
69
import org.eclipse.hyades.logging.parsers.importer.LogParserConstants;
70
import org.eclipse.hyades.logging.parsers.internal.importer.GLAHelper;
70
import org.eclipse.hyades.logging.parsers.provisional.importer.GLAHelper;
71
import org.eclipse.hyades.models.cbe.CBEPackage;
71
import org.eclipse.hyades.models.cbe.CBEPackage;
72
import org.eclipse.hyades.models.hierarchy.TRCAgent;
72
import org.eclipse.hyades.models.hierarchy.TRCAgent;
73
import org.eclipse.hyades.models.hierarchy.extensions.BinaryExpression;
73
import org.eclipse.hyades.models.hierarchy.extensions.BinaryExpression;

Return to bug 208728