KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > AntLogAdapter


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 package org.eclipse.pde.internal.build;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15 import org.eclipse.core.runtime.*;
16 import org.osgi.framework.Bundle;
17
18 public class AntLogAdapter implements ILog {
19     private Object JavaDoc antLog;
20     private Method JavaDoc log;
21     
22     public AntLogAdapter(Object JavaDoc antLog) throws NoSuchMethodException JavaDoc{
23         this.antLog = antLog;
24         try {
25             log = antLog.getClass().getMethod("log", new Class JavaDoc[] { String JavaDoc.class, int.class }); //$NON-NLS-1$
26
} catch (SecurityException JavaDoc e) {
27             // TODO Auto-generated catch block
28
e.printStackTrace();
29         }
30     }
31     
32     public void addLogListener(ILogListener listener) {
33         throw new UnsupportedOperationException JavaDoc();
34     }
35
36     public Bundle getBundle() {
37         return BundleHelper.getDefault().getBundle();
38     }
39
40     public void log(IStatus status) {
41         try {
42             log.invoke(antLog, new Object JavaDoc[] { status.getMessage(), new Integer JavaDoc(mapLogLevels(status.getSeverity()))} );
43             IStatus[] nestedStatus = status.getChildren();
44             if (nestedStatus != null) {
45                 for (int i = 0; i < nestedStatus.length; i++) {
46                     log(nestedStatus[i]);
47                 }
48             }
49         } catch (IllegalArgumentException JavaDoc e) {
50             // TODO Auto-generated catch block
51
e.printStackTrace();
52         } catch (IllegalAccessException JavaDoc e) {
53             // TODO Auto-generated catch block
54
e.printStackTrace();
55         } catch (InvocationTargetException JavaDoc e) {
56             // TODO Auto-generated catch block
57
e.printStackTrace();
58         }
59     }
60
61     private int mapLogLevels(int iStatusLevel) {
62         switch (iStatusLevel) {
63             case IStatus.ERROR :
64                 return 0;
65             case IStatus.OK:
66                 return 2;
67             case IStatus.INFO:
68                 return 2;
69             case IStatus.WARNING:
70                 return 1;
71             default:
72                 return 1;
73         }
74     }
75     
76     public void removeLogListener(ILogListener listener) {
77         throw new UnsupportedOperationException JavaDoc();
78     }
79
80 }
81
Popular Tags