| /******************************************************************************* |
| * Copyright (c) 2007 Cisco Systems, Inc. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * E. Dillon (Cisco Systems, Inc.) - reformat for Code Open-Sourcing |
| *******************************************************************************/ |
| package org.eclipse.tigerstripe.workbench.internal.api.impl; |
| |
| import java.io.File; |
| import java.net.URI; |
| |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.tigerstripe.workbench.internal.WorkingCopyManager; |
| import org.eclipse.tigerstripe.workbench.project.IAbstractTigerstripeProject; |
| |
| public abstract class AbstractTigerstripeProjectHandle |
| extends WorkingCopyManager |
| implements IAbstractTigerstripeProject { |
| |
| @Override |
| public String getName() { |
| String path = projectContainerURI.getPath(); |
| return new File(path).getName(); |
| } |
| |
| // we keep track of a TStamp on the hanlde when we create it to know |
| // when the handle is invalid because the underlying URI actually changed |
| private long handleTStamp; |
| |
| private URI projectContainerURI; |
| |
| public AbstractTigerstripeProjectHandle(URI projectContainerURI) { |
| this.projectContainerURI = projectContainerURI; |
| |
| if (projectContainerURI == null)// Read-only tigerstripe project from |
| // module |
| return; |
| |
| File file = new File(projectContainerURI); |
| if (file.exists()) { |
| handleTStamp = file.lastModified(); |
| } |
| } |
| |
| public File getBaseDir() { |
| if (getProjectContainerURI() != null) |
| return new File(getProjectContainerURI()); |
| return null; |
| } |
| |
| public URI getProjectContainerURI() { |
| return this.projectContainerURI; |
| } |
| |
| |
| public URI getURI() { |
| return getProjectContainerURI(); |
| } |
| |
| public IPath getLocation() { |
| return getURI() == null ? null : new Path(new File(getURI()).getAbsolutePath()); |
| } |
| |
| /** |
| * Tries and locate the project descriptor for this project |
| * |
| * @return |
| */ |
| protected abstract boolean findProjectDescriptor(); |
| |
| |
| @Override |
| public boolean equals(Object arg0) { |
| if (this == arg0) { |
| return true; |
| } |
| if (arg0 == null) |
| return false; |
| |
| if (arg0.getClass() == this.getClass()) { |
| if (getURI() != null) { |
| return getURI().equals( |
| ((AbstractTigerstripeProjectHandle) arg0).getURI()); |
| } |
| } |
| return false; |
| } |
| |
| @Override |
| public int hashCode() { |
| if (getURI() != null) { |
| return getURI().hashCode(); |
| } |
| return super.hashCode(); |
| } |
| |
| public long handleTStamp() { |
| return this.handleTStamp; |
| } |
| } |