//
// This file is part of the Prose Development Tools for Eclipse package.
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
//
// The Original Code is Prose Development Tools for Eclipse.
//
// The Initial Developer of the Original Code is Angela Nicoara. Portions
// created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
// All Rights Reserved.
//
// Contributor(s):
// $Id: AspectNode.java,v 1.1 2008/11/18 12:23:02 anicoara Exp $
// ==============================================================================
//
package ch.ethz.prose.eclipse.internal.run;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.graphics.Image;
import ch.ethz.prose.eclipse.internal.core.ProsePlugin;
import ch.ethz.prose.query.AspectSurrogate;
import ch.ethz.prose.query.CrosscutSurrogate;
import ch.ethz.prose.query.QueryManager;
import ch.ethz.prose.query.Tuple;
import ch.ethz.prose.tools.RemoteAspectManager;
/**
* @author Angela Nicoara
* @author Johann Gyger
* @version $Id: AspectNode.java,v 1.1 2008/11/18 12:23:02 anicoara Exp $
*/
public class AspectNode extends AbstractRunNode {
/**
* Aspect manager into which the aspect was inserted (parent).
*/
protected AspectManagerNode aspectManager;
/**
* Adaptee.
*/
protected AspectSurrogate aspect;
/**
* @param parent Parent node
* @param adaptee Adapted object
*/
public AspectNode(AspectManagerNode parent, AspectSurrogate adaptee) {
if (parent == null || adaptee == null) throw new IllegalArgumentException();
aspectManager = parent;
aspect = adaptee;
}
/**
* @return Aspect manager
*/
public AspectManagerNode getAspectManager() {
return aspectManager;
}
/**
* @return Aspect
*/
public AspectSurrogate getAspect() {
return aspect;
}
/**
* @return Crosscuts for a specific aspect
*/
public IRunNode[] getChildren() {
try {
ArrayList aspectList = new ArrayList(1);
aspectList.add(getAspect());
List tuples = getAspectManager().getAspectManager().queryAspects(aspectList,
QueryManager.SELECT_ASPECT | QueryManager.SELECT_CROSSCUT, QueryManager.GROUP_BY_CROSSCUT);
CrosscutNode[] result = new CrosscutNode[tuples.size()];
for (int i = 0; i < result.length; i++) {
CrosscutSurrogate crosscut = ((Tuple) tuples.get(i)).getCrosscutSurrogate();
result[i] = new CrosscutNode(this, crosscut);
}
return result;
} catch (UnreachableException e) {
return null;
} catch (RemoteException e) {
getAspectManager().getRun().setUnreachable();
return null;
}
}
/* (non-Javadoc)
* @see ch.ethz.prose.eclipse.internal.run.IRunNode#getParent()
*/
public IRunNode getParent() {
return aspectManager;
}
public Image getImage() {
return ASPECT_IMAGE;
}
public String toString() {
return aspect.toString();
}
/**
* Withdraw this aspect.
*
* @throws UnreachableException
*/
public void withdraw() throws UnreachableException {
AspectManagerNode manager = getAspectManager();
try {
RemoteAspectManager remote = getAspectManager().getAspectManager();
Object id = manager.getTransactionId();
if (id == null)
remote.withdraw(getAspect());
else
remote.withdraw(getAspect(), id);
ProsePlugin.getDefault().fireAspectWithdrawn(this);
} catch (ClassNotFoundException e) {
throw new Error(e);
} catch (RemoteException e) {
manager.getRun().setUnreachable();
throw new UnreachableException(e);
}
}
}