KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ant > taskdefs > EMFTask


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2004-2005 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: EMFTask.java,v 1.3 2005/06/08 06:17:17 nickb Exp $
16  */

17 package org.eclipse.emf.ant.taskdefs;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Task;
21
22 import org.eclipse.ant.core.AntCorePlugin;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.core.runtime.NullProgressMonitor;
25
26
27 /**
28  * Base class for the tasks that are defined in this plugin. Provides common behavior
29  * and facilities.
30  *
31  * @since 2.1.0
32  */

33 public abstract class EMFTask extends Task
34 {
35   /**
36    * Throws a <tt>BuildException</tt> if <tt>expression</tt> is false.
37    * @param message
38    * @param expression
39    * @throws BuildException
40    */

41   public static void assertTrue(String JavaDoc message, boolean expression) throws BuildException
42   {
43     if (!expression)
44     {
45       throw new BuildException(message);
46     }
47   }
48
49   protected IProgressMonitor getProgressMonitor()
50   {
51     try
52     {
53       IProgressMonitor progressMonitor = (IProgressMonitor)getProject().getReferences().get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
54       if (progressMonitor != null)
55       {
56         return progressMonitor;
57       }
58     }
59     catch (Exception JavaDoc e)
60     {
61     }
62     return new NullProgressMonitor();
63   }
64
65   public final void execute() throws BuildException
66   {
67     checkAttributes();
68
69     try
70     {
71       doExecute();
72     }
73     catch (Exception JavaDoc e)
74     {
75       if (e instanceof BuildException)
76       {
77         throw (BuildException)e;
78       }
79       else
80       {
81         throw new BuildException(e);
82       }
83     }
84   }
85
86   /**
87    * All the attribute checks should be performed in this method.
88    * @throws BuildException
89    */

90   protected void checkAttributes() throws BuildException
91   {
92   }
93
94   /**
95    * Performs the task specific code.
96    * @throws Exception
97    */

98   abstract protected void doExecute() throws Exception JavaDoc;
99 }
Popular Tags