View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: XMLRemover.java
13   * Created: 2007-09-20
14   * Author: entrop
15   * $Id: XMLRemover.java 2335 2009-01-13 16:40:16Z entrop $
16   */
17  
18  package pl.edu.agh.cast.model.mapper.internal;
19  
20  import java.io.File;
21  
22  import org.eclipse.core.resources.IProject;
23  
24  import pl.edu.agh.cast.model.base.IDataSet;
25  import pl.edu.agh.cast.model.mapper.Mappable;
26  
27  /**
28   * The XML implementation of the {@link Remover} interface.
29   *
30   * @author AGH CAST Team
31   *
32   */
33  public class XMLRemover extends AbstractRemover {
34  	private IProject project;
35  
36  	/**
37  	 * The parameterized constructor.
38  	 * @param object The object to remove.
39  	 * @param project The project the object belongs to.
40  	 */
41  	public XMLRemover(Mappable object, IProject project) {
42  		super(object);
43  		this.project = project;
44  	}
45  
46  	/**
47  	 * {@inheritDoc}
48  	 * @see pl.edu.agh.cast.model.mapper.Remover#remove()
49  	 */
50  	public boolean remove() {
51  		try {
52  			if (primaryObject instanceof IDataSet) {
53  				IDataSet dataSet = (IDataSet)primaryObject;
54  
55  				String dsFilePath = XMLSaver.fileFor(project, dataSet.getId());
56  				File dsFile = new File(dsFilePath);
57  				boolean removed = dsFile.delete();
58  				if (removed) {
59  					removeDataSetFromModel(dataSet);
60  					log.info("Removed DataSet: " + dataSet.getId()); //$NON-NLS-1$
61  				} else {
62  					log.error("Cannot remove DataSet: '" + dataSet.getId() //$NON-NLS-1$
63  					        + "' [" + dsFilePath + "]"); //$NON-NLS-1$ //$NON-NLS-2$
64  				}
65  				return removed;
66  			}
67  		} catch (Exception ex) {
68  			log.error("Cannot remove object: " + primaryObject, ex); //$NON-NLS-1$
69  		}
70  		return false;
71  	}
72  }