summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-05-24 12:22:25 (EDT)
committerpelder2006-05-24 12:22:25 (EDT)
commit3bcb52ae4b7111db586f930fa067e61b7f2a342c (patch)
treef02073313b391f2dc97b97b58bdaa2b9830b07da
parent2757f3942bfbbeb67b721523e032d99c7f162097 (diff)
downloadorg.eclipse.jet-3bcb52ae4b7111db586f930fa067e61b7f2a342c.zip
org.eclipse.jet-3bcb52ae4b7111db586f930fa067e61b7f2a342c.tar.gz
org.eclipse.jet-3bcb52ae4b7111db586f930fa067e61b7f2a342c.tar.bz2
[143509] provide model loader and inspector to allow JET to naviate the Eclipse workspace.
-rw-r--r--plugins/org.eclipse.jet/plugin.properties1
-rw-r--r--plugins/org.eclipse.jet/plugin.xml14
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/ResourceLoader.java74
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractResourceAttribute.java43
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractWrappedAttribute.java59
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/IWrappedAttribute.java37
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/PropertiesInspector.java195
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceAttributeFactory.java314
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceInspector.java211
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/WrappedAttributeInspector.java93
10 files changed, 1041 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jet/plugin.properties b/plugins/org.eclipse.jet/plugin.properties
index ae974a2..f9fba78 100644
--- a/plugins/org.eclipse.jet/plugin.properties
+++ b/plugins/org.eclipse.jet/plugin.properties
@@ -42,3 +42,4 @@ extpoint.modelInspectors.name = Model Inspectors
extensions.modelLoaders.emf.name = EMF Model Loader
extensions.modelLoaders.emfxml.name = EMF-based loader for XML documents
+extensions.modelLoaders.resource.name = Eclipse Resource Loader
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 632ff69..36c62b2 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1274,6 +1274,11 @@ if 'length' is specified, convert only the specified number of characters, other
<defaultTypeLoader
fileType="xml"
id="org.eclipse.jet.emfxml"/>
+ <loader
+ class="org.eclipse.jet.internal.runtime.model.ResourceLoader"
+ dynamicTypes="false"
+ id="resource"
+ name="%extensions.modelLoaders.resource.name"/>
</extension>
<extension
point="org.eclipse.jet.modelInspectors">
@@ -1295,6 +1300,15 @@ if 'length' is specified, convert only the specified number of characters, other
<inspector class="org.eclipse.jet.internal.xpath.inspectors.EMFXMLNodeWrapperInspector">
<inspects class="org.eclipse.jet.internal.xpath.inspectors.EMFXMLNodeWrapper"/>
</inspector>
+ <inspector class="org.eclipse.jet.internal.xpath.inspectors.ResourceInspector">
+ <inspects class="org.eclipse.core.resources.IResource"/>
+ </inspector>
+ <inspector class="org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector">
+ <inspects class="org.eclipse.jet.internal.xpath.inspectors.IWrappedAttribute"/>
+ </inspector>
+ <inspector class="org.eclipse.jet.internal.xpath.inspectors.PropertiesInspector">
+ <inspects class="java.util.Properties"/>
+ </inspector>
</extension>
<extension
id="taskmarker"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/ResourceLoader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/ResourceLoader.java
new file mode 100644
index 0000000..437effb
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/ResourceLoader.java
@@ -0,0 +1,74 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.runtime.model;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jet.runtime.model.IModelLoader;
+
+/**
+ * Model loader that provides IResource information for the loaded URL.
+ *
+ */
+public class ResourceLoader implements IModelLoader {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.runtime.model.IModelLoader#canLoad(java.lang.String)
+ */
+ public boolean canLoad(String kind) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.runtime.model.IModelLoader#load(java.net.URL)
+ */
+ public Object load(URL modelUrl) throws IOException {
+ if(!"platform".equals(modelUrl.getProtocol()) || !modelUrl.getPath().startsWith("/resource/")) { //$NON-NLS-1$ //$NON-NLS-2$
+ throw new IOException("Resource loader requires platform:/resource/ URL format"); //$NON-NLS-1$
+ }
+ IPath path = new Path(modelUrl.getPath());
+ path = path.removeFirstSegments(1);
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if(resource == null) {
+ throw new FileNotFoundException(path.toString());
+ }
+ return resource;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.runtime.model.IModelLoader#load(java.net.URL, java.lang.String)
+ */
+ public Object load(URL modelUrl, String kind) throws IOException {
+ return load(modelUrl);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.runtime.model.IModelLoader#loadFromString(java.lang.String, java.lang.String)
+ */
+ public Object loadFromString(String serializedModel, String kind)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractResourceAttribute.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractResourceAttribute.java
new file mode 100644
index 0000000..c6d7f84
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractResourceAttribute.java
@@ -0,0 +1,43 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.xpath.inspectors;
+
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Abstract implementation of {@link IWrappedAttribute} for resource Attributes.
+ *
+ */
+public abstract class AbstractResourceAttribute extends AbstractWrappedAttribute implements IWrappedAttribute {
+
+ public AbstractResourceAttribute(IResource parent, String name) {
+ super(parent, name);
+
+ }
+ public final IResource getResource() {
+ return (IResource)getParent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.experiments.IResourceAttribute#getDocumentRoot()
+ */
+ public final Object getDocumentRoot() {
+ return getResource().getWorkspace().getRoot();
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractWrappedAttribute.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractWrappedAttribute.java
new file mode 100644
index 0000000..d196d85
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/AbstractWrappedAttribute.java
@@ -0,0 +1,59 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.xpath.inspectors;
+
+
+/**
+ * Abstract implementatino of {@link IWrappedAttribute}.
+ */
+public abstract class AbstractWrappedAttribute implements IWrappedAttribute
+{
+
+ private final Object parent;
+ private final String name;
+
+ /**
+ * Construct a wrapped attribute whose parent in the given object, and whose
+ * name is as specified.
+ * @param parent
+ * @param name
+ */
+ public AbstractWrappedAttribute(Object parent, String name)
+ {
+ this.parent = parent;
+ this.name = name;
+ }
+
+ public final String getName()
+ {
+ return name;
+ }
+
+ public final Object getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Provide a default implementation of {@link IWrappedAttribute#getDocumentRoot()} that returns
+ * <code>null</code>.
+ */
+ public Object getDocumentRoot()
+ {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/IWrappedAttribute.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/IWrappedAttribute.java
new file mode 100644
index 0000000..edec9ff
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/IWrappedAttribute.java
@@ -0,0 +1,37 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.xpath.inspectors;
+
+/**
+ * Interface defining common behavior of object attributes exposed to an XPath inspector.
+ * @see WrappedAttributeInspector
+ * @see ResourceAttributeFactory
+ * @see AbstractResourceAttribute
+ *
+ */
+public interface IWrappedAttribute {
+
+ public abstract String getStringValue();
+
+ public abstract Object getDocumentRoot();
+
+ public abstract String getName();
+
+ public abstract Object getParent();
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/PropertiesInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/PropertiesInspector.java
new file mode 100644
index 0000000..29429a3
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/PropertiesInspector.java
@@ -0,0 +1,195 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.xpath.inspectors;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.jet.xpath.inspector.AddElementException;
+import org.eclipse.jet.xpath.inspector.CopyElementException;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.IElementInspector;
+import org.eclipse.jet.xpath.inspector.INodeInspector;
+import org.eclipse.jet.xpath.inspector.InvalidChildException;
+import org.eclipse.jet.xpath.inspector.SimpleElementRequiresValueException;
+
+/**
+ * @author pelder
+ */
+public class PropertiesInspector implements INodeInspector, IElementInspector
+{
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#expandedNameOf(java.lang.Object)
+ */
+ public ExpandedName expandedNameOf(Object node)
+ {
+ return new ExpandedName(""); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren(Object node)
+ {
+ return new Object[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getDocumentRoot(java.lang.Object)
+ */
+ public Object getDocumentRoot(Object node)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getNodeKind(java.lang.Object)
+ */
+ public NodeKind getNodeKind(Object obj)
+ {
+ return NodeKind.ELEMENT;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getParent(java.lang.Object)
+ */
+ public Object getParent(Object obj)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#nameOf(java.lang.Object)
+ */
+ public String nameOf(Object node)
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#stringValueOf(java.lang.Object)
+ */
+ public String stringValueOf(Object node)
+ {
+ return ""; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)
+ */
+ public boolean testExpandedName(Object node, ExpandedName testName)
+ {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#addElement(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName, java.lang.Object)
+ */
+ public Object addElement(Object node, ExpandedName elementName, Object addBeforeThisSibling) throws SimpleElementRequiresValueException,
+ InvalidChildException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#addTextElement(java.lang.Object, java.lang.String, java.lang.String, boolean)
+ */
+ public Object addTextElement(Object parentElement, String name, String bodyContent, boolean asCData) throws AddElementException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#copyElement(java.lang.Object, java.lang.Object, java.lang.String, boolean)
+ */
+ public Object copyElement(Object tgtParent, Object srcElement, String name, boolean recursive) throws CopyElementException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#createAttribute(java.lang.Object, java.lang.String, java.lang.String)
+ */
+ public boolean createAttribute(Object node, String attributeName, String value)
+ {
+ Properties props = (Properties)node;
+ props.setProperty(attributeName, value);
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#getAttributes(java.lang.Object)
+ */
+ public Object[] getAttributes(Object node)
+ {
+ Properties props = (Properties)node;
+ Set keySet = props.keySet();
+
+ Object[] result = new Object[keySet.size()];
+ int index = 0;
+ for (Iterator i = keySet.iterator(); i.hasNext(); index++)
+ {
+ String key = (String)i.next();
+
+ result[index] = new AbstractWrappedAttribute(props, key) {
+
+ public String getStringValue()
+ {
+ return ((Properties)getParent()).getProperty(getName());
+ }};
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)
+ */
+ public Object getNamedAttribute(Object node, ExpandedName nameTestExpandedName)
+ {
+ Properties props = (Properties)node;
+ String name = nameTestExpandedName.getLocalPart();
+ if(props.containsKey(name)) {
+ return new AbstractWrappedAttribute(props, name) {
+
+ public String getStringValue()
+ {
+ return ((Properties)getParent()).getProperty(getName());
+ }};
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#removeAttribute(java.lang.Object, java.lang.String)
+ */
+ public void removeAttribute(Object node, String name)
+ {
+ Properties props = (Properties)node;
+ props.remove(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#removeElement(java.lang.Object)
+ */
+ public void removeElement(Object node)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceAttributeFactory.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceAttributeFactory.java
new file mode 100644
index 0000000..272e75a
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceAttributeFactory.java
@@ -0,0 +1,314 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.xpath.inspectors;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Factory for XPath wrappers on attributes of IResource.
+ *
+ */
+public class ResourceAttributeFactory {
+
+ private static final class TeamPrivateMemberAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "teamPrivateMember"; //$NON-NLS-1$
+
+ private TeamPrivateMemberAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().isTeamPrivateMember());
+ }
+ }
+
+ private static final class ReadOnlyAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "readOnly"; //$NON-NLS-1$
+
+ private ReadOnlyAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().isPhantom());
+ }
+ }
+
+ private static final class PhantomAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "phantom"; //$NON-NLS-1$
+
+ private PhantomAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().isPhantom());
+ }
+ }
+
+ private static final class LinkedAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "linked"; //$NON-NLS-1$
+
+ private LinkedAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().isLinked());
+ }
+ }
+
+ private static final class DerivedAttributed extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "derived"; //$NON-NLS-1$
+
+ private DerivedAttributed(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().isDerived());
+ }
+ }
+
+ private static final class RawLocationURIAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "rawLocationURI"; //$NON-NLS-1$
+
+ private RawLocationURIAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getRawLocationURI() == null ? getResource()
+ .getLocationURI().toString()
+ : getResource().getRawLocationURI().toString();
+ }
+ }
+
+ private static final class RawLocationAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "rawLocation"; //$NON-NLS-1$
+
+ private RawLocationAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getRawLocation() == null ? getResource()
+ .getLocation().toString() : getResource()
+ .getRawLocation().toString();
+ }
+ }
+
+ private static final class ProjectRelativePathAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "projectRelativePath"; //$NON-NLS-1$
+
+ private ProjectRelativePathAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getProjectRelativePath().toString();
+ }
+ }
+
+ private static final class ProjectAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "project"; //$NON-NLS-1$
+
+ private ProjectAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ IProject containingProject = getResource().getProject();
+ return containingProject != null ? containingProject.getName() : ""; //$NON-NLS-1$
+ }
+ }
+
+ private static final class NameAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+
+ private NameAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getName();
+ }
+ }
+
+ private static final class ModificationStampAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "modificationStamp"; //$NON-NLS-1$
+
+ private ModificationStampAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().getModificationStamp());
+ }
+ }
+
+ private static final class LocationURIAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "locationURI"; //$NON-NLS-1$
+
+ private LocationURIAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getLocationURI().toString();
+ }
+ }
+
+ private static final class LocationAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "location"; //$NON-NLS-1$
+
+ private LocationAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getLocation().toString();
+ }
+ }
+
+ private static final class LocalTimeStampAttribute extends AbstractResourceAttribute {
+ private static final String ATTRIBUTE_NAME = "localTimeStamp"; //$NON-NLS-1$
+
+ private LocalTimeStampAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getResource().getLocalTimeStamp());
+ }
+ }
+
+ private static final class FullPathAttribute extends AbstractResourceAttribute {
+ public static final String ATTRIBUTE_NAME = "fullPath"; //$NON-NLS-1$
+
+ private FullPathAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ return getResource().getFullPath().toString();
+ }
+ }
+
+ private static final class FileExtensionAttribute extends AbstractResourceAttribute {
+
+ public static final String ATTRIBUTE_NAME = "fileExtension"; //$NON-NLS-1$
+
+ private FileExtensionAttribute(IResource parent) {
+ super(parent, ATTRIBUTE_NAME);
+ }
+
+ public String getStringValue() {
+ String fileExtension = getResource().getFileExtension();
+ return fileExtension == null ? "" : fileExtension; //$NON-NLS-1$
+ }
+ }
+
+ public static final int FILE_EXTENSION = 1;
+ public static final int FULL_PATH = 2;
+ public static final int LOCAL_TIMESTAMP = 3;
+ public static final int LOCATION = 4;
+ public static final int LOCATION_URI = 5;
+ public static final int MODIFICATION_STAMP = 6;
+ public static final int NAME = 7;
+ public static final int PROJECT = 8;
+ public static final int PROJECT_RELATIVE_PATH = 9;
+ public static final int RAW_LOCATION = 10;
+ public static final int RAW_LOCATION_URI = 11;
+ public static final int DERIVED = 12;
+ public static final int LINKED = 13;
+ public static final int PHANTOM = 14;
+ public static final int READ_ONLY = 15;
+ public static final int TEAM_PRIVATE_MEMBER = 16;
+
+ private static final Map attributeKindByName = new HashMap();
+ static {
+ attributeKindByName.put(FileExtensionAttribute.ATTRIBUTE_NAME, new Integer(FILE_EXTENSION));
+ attributeKindByName.put(FullPathAttribute.ATTRIBUTE_NAME, new Integer(FULL_PATH));
+ attributeKindByName.put(LocalTimeStampAttribute.ATTRIBUTE_NAME, new Integer(LOCAL_TIMESTAMP));
+ attributeKindByName.put(LocationAttribute.ATTRIBUTE_NAME, new Integer(LOCATION));
+ attributeKindByName.put(LocationURIAttribute.ATTRIBUTE_NAME, new Integer(LOCATION_URI));
+ attributeKindByName.put(ModificationStampAttribute.ATTRIBUTE_NAME, new Integer(MODIFICATION_STAMP));
+ attributeKindByName.put(NameAttribute.ATTRIBUTE_NAME, new Integer(NAME));
+ attributeKindByName.put(ProjectAttribute.ATTRIBUTE_NAME, new Integer(PROJECT));
+ attributeKindByName.put(ProjectRelativePathAttribute.ATTRIBUTE_NAME, new Integer(PROJECT_RELATIVE_PATH));
+ attributeKindByName.put(RawLocationAttribute.ATTRIBUTE_NAME, new Integer(RAW_LOCATION));
+ attributeKindByName.put(RawLocationURIAttribute.ATTRIBUTE_NAME, new Integer(RAW_LOCATION_URI));
+ attributeKindByName.put(DerivedAttributed.ATTRIBUTE_NAME, new Integer(DERIVED));
+ attributeKindByName.put(LinkedAttribute.ATTRIBUTE_NAME, new Integer(LINKED));
+ attributeKindByName.put(PhantomAttribute.ATTRIBUTE_NAME, new Integer(PHANTOM));
+ attributeKindByName.put(ReadOnlyAttribute.ATTRIBUTE_NAME, new Integer(READ_ONLY));
+ attributeKindByName.put(TeamPrivateMemberAttribute.ATTRIBUTE_NAME, new Integer(TEAM_PRIVATE_MEMBER));
+ }
+
+ public IWrappedAttribute create(int kind, IResource parent) {
+ switch(kind) {
+ case FILE_EXTENSION:
+ return new FileExtensionAttribute(parent);
+ case FULL_PATH:
+ return new FullPathAttribute(parent);
+ case LOCAL_TIMESTAMP:
+ return new LocalTimeStampAttribute(parent);
+ case LOCATION:
+ return new LocationAttribute(parent);
+ case LOCATION_URI:
+ return new LocationURIAttribute(parent);
+ case MODIFICATION_STAMP:
+ return new ModificationStampAttribute(parent);
+ case NAME:
+ return new NameAttribute(parent);
+ case PROJECT:
+ return new ProjectAttribute(parent);
+ case PROJECT_RELATIVE_PATH:
+ return new ProjectRelativePathAttribute(parent);
+ case RAW_LOCATION:
+ return new RawLocationAttribute(parent);
+ case RAW_LOCATION_URI:
+ return new RawLocationURIAttribute(parent);
+ case DERIVED:
+ return new DerivedAttributed(parent);
+ case LINKED:
+ return new LinkedAttribute(parent);
+ case PHANTOM:
+ return new PhantomAttribute(parent);
+ case READ_ONLY:
+ return new ReadOnlyAttribute(parent);
+ case TEAM_PRIVATE_MEMBER:
+ return new TeamPrivateMemberAttribute(parent);
+ }
+ return null;
+ }
+
+ public IWrappedAttribute create(String name, IResource resource) {
+ Integer kind = (Integer) attributeKindByName.get(name);
+ if(kind != null) {
+ return create(kind.intValue(), resource);
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceInspector.java
new file mode 100644
index 0000000..d5b02c9
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/ResourceInspector.java
@@ -0,0 +1,211 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.xpath.inspectors;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jet.xpath.inspector.AddElementException;
+import org.eclipse.jet.xpath.inspector.CopyElementException;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.IElementInspector;
+import org.eclipse.jet.xpath.inspector.INodeInspector;
+import org.eclipse.jet.xpath.inspector.InvalidChildException;
+import org.eclipse.jet.xpath.inspector.SimpleElementRequiresValueException;
+
+/**
+ * Inspector for IResource objects.
+ *
+ */
+public class ResourceInspector implements INodeInspector, IElementInspector {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#expandedNameOf(java.lang.Object)
+ */
+ public ExpandedName expandedNameOf(Object node) {
+ IResource resource = (IResource) node;
+ ExpandedName result = null;
+ switch(resource.getType()) {
+ case IResource.FILE:
+ result = new ExpandedName("file"); //$NON-NLS-1$
+ break;
+ case IResource.FOLDER:
+ result = new ExpandedName("folder"); //$NON-NLS-1$
+ break;
+ case IResource.PROJECT:
+ result = new ExpandedName("project"); //$NON-NLS-1$
+ break;
+ case IResource.ROOT:
+ result = new ExpandedName("root"); //$NON-NLS-1$
+ break;
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren(Object node) {
+ IResource resource = (IResource) node;
+
+ if(resource instanceof IContainer) {
+ IContainer container = (IContainer) resource;
+ try {
+ return container.members();
+ } catch (CoreException e) {
+ return new Object[0];
+ }
+ } else {
+ return new Object[0];
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getDocumentRoot(java.lang.Object)
+ */
+ public Object getDocumentRoot(Object node) {
+ IResource resource = (IResource) node;
+ return resource.getWorkspace().getRoot();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getNodeKind(java.lang.Object)
+ */
+ public NodeKind getNodeKind(Object obj) {
+ return NodeKind.ELEMENT;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getParent(java.lang.Object)
+ */
+ public Object getParent(Object node) {
+ IResource resource = (IResource) node;
+ return resource.getParent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#nameOf(java.lang.Object)
+ */
+ public String nameOf(Object node) {
+ ExpandedName expandedName = expandedNameOf(node);
+ return expandedName.getLocalPart();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#stringValueOf(java.lang.Object)
+ */
+ public String stringValueOf(Object node) {
+ return ""; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)
+ */
+ public boolean testExpandedName(Object node, ExpandedName testName) {
+ return expandedNameOf(node).equals(testName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#addElement(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName, java.lang.Object)
+ */
+ public Object addElement(Object node, ExpandedName elementName,
+ Object addBeforeThisSibling)
+ throws SimpleElementRequiresValueException, InvalidChildException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#addTextElement(java.lang.Object, java.lang.String, java.lang.String, boolean)
+ */
+ public Object addTextElement(Object parentElement, String name,
+ String bodyContent, boolean asCData) throws AddElementException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#copyElement(java.lang.Object, java.lang.Object, java.lang.String, boolean)
+ */
+ public Object copyElement(Object tgtParent, Object srcElement, String name,
+ boolean recursive) throws CopyElementException {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#createAttribute(java.lang.Object, java.lang.String, java.lang.String)
+ */
+ public boolean createAttribute(Object node, String attributeName,
+ String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#getAttributes(java.lang.Object)
+ */
+ public Object[] getAttributes(Object node) {
+ IResource resource = (IResource) node;
+ ResourceAttributeFactory factory = new ResourceAttributeFactory();
+
+ return new Object[] {
+ factory.create(ResourceAttributeFactory.FILE_EXTENSION,
+ resource),
+ factory.create(ResourceAttributeFactory.FULL_PATH, resource),
+ factory.create(ResourceAttributeFactory.LOCAL_TIMESTAMP,
+ resource),
+ factory.create(ResourceAttributeFactory.LOCATION, resource),
+ factory.create(ResourceAttributeFactory.LOCATION_URI, resource),
+ factory.create(ResourceAttributeFactory.MODIFICATION_STAMP,
+ resource),
+ factory.create(ResourceAttributeFactory.NAME, resource),
+ factory.create(ResourceAttributeFactory.PROJECT, resource),
+ factory.create(ResourceAttributeFactory.PROJECT_RELATIVE_PATH,
+ resource),
+ factory.create(ResourceAttributeFactory.RAW_LOCATION, resource),
+ factory.create(ResourceAttributeFactory.RAW_LOCATION_URI,
+ resource),
+ factory.create(ResourceAttributeFactory.DERIVED, resource),
+ factory.create(ResourceAttributeFactory.LINKED, resource),
+ factory.create(ResourceAttributeFactory.PHANTOM, resource),
+ factory.create(ResourceAttributeFactory.READ_ONLY, resource),
+ factory.create(ResourceAttributeFactory.TEAM_PRIVATE_MEMBER,
+ resource), };
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)
+ */
+ public Object getNamedAttribute(Object node,
+ ExpandedName nameTestExpandedName) {
+ IResource resource = (IResource) node;
+ return new ResourceAttributeFactory().create(nameTestExpandedName.getLocalPart(), resource);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#removeAttribute(java.lang.Object, java.lang.String)
+ */
+ public void removeAttribute(Object node, String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.IElementInspector#removeElement(java.lang.Object)
+ */
+ public void removeElement(Object node) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/WrappedAttributeInspector.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/WrappedAttributeInspector.java
new file mode 100644
index 0000000..33da5b7
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/inspectors/WrappedAttributeInspector.java
@@ -0,0 +1,93 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.internal.xpath.inspectors;
+
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector;
+
+/**
+ * XPath inspector for simple object attributes wrapped {@link IWrappedAttribute}.
+ * @see ResourceInspector
+ * @see IWrappedAttribute
+ *
+ */
+public class WrappedAttributeInspector implements INodeInspector {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#expandedNameOf(java.lang.Object)
+ */
+ public ExpandedName expandedNameOf(Object node) {
+ IWrappedAttribute attr = (IWrappedAttribute) node;
+ return new ExpandedName(attr.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren(Object node) {
+ return new Object[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getDocumentRoot(java.lang.Object)
+ */
+ public Object getDocumentRoot(Object node) {
+ IWrappedAttribute attr = (IWrappedAttribute) node;
+ return attr.getDocumentRoot();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getNodeKind(java.lang.Object)
+ */
+ public NodeKind getNodeKind(Object obj) {
+ return NodeKind.ATTRIBUTE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#getParent(java.lang.Object)
+ */
+ public Object getParent(Object node) {
+ IWrappedAttribute attr = (IWrappedAttribute) node;
+ return attr.getParent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#nameOf(java.lang.Object)
+ */
+ public String nameOf(Object node) {
+ IWrappedAttribute attr = (IWrappedAttribute) node;
+ return attr.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#stringValueOf(java.lang.Object)
+ */
+ public String stringValueOf(Object node) {
+ IWrappedAttribute attr = (IWrappedAttribute) node;
+ String stringValue = attr.getStringValue();
+ return stringValue == null ? "" : stringValue; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.inspector.INodeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)
+ */
+ public boolean testExpandedName(Object node, ExpandedName testName) {
+ return expandedNameOf(node).equals(testName);
+ }
+
+}