Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2010-04-27 18:07:07 -0400
committercbateman2010-04-27 18:07:07 -0400
commit81ee32e5e0bc83a7c1b3d2feb394d9996371e015 (patch)
tree0a7a2a2366f77ba52f31d17a10705cfddef37ff9
parent0a44b2984ce3dad605b556d499e59034c6053f81 (diff)
downloadwebtools.jsf-81ee32e5e0bc83a7c1b3d2feb394d9996371e015.tar.gz
webtools.jsf-81ee32e5e0bc83a7c1b3d2feb394d9996371e015.tar.xz
webtools.jsf-81ee32e5e0bc83a7c1b3d2feb394d9996371e015.zip
Add support for detecting adds, changes and removes to individual composite component files in an existing workspace resource library folder.
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/AbstractJSFResourceLocator.java26
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/IJSFResourceLocator.java9
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResource.java28
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResourceChangeListener.java110
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JarBasedJSFResource.java75
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/ResourceIdentifier.java34
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResource.java6
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResourceLocator.java79
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceResourceManager.java238
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/CompositeComponentTaglibLocator.java109
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/ContextParamSpecifiedFaceletTaglibLocator.java4
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/FaceletTagIndex.java13
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/IFaceletTaglibLocator.java5
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/JSFResourceBasedTagRecord.java196
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibFileTracker.java85
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceManager.java43
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceTracker.java43
17 files changed, 847 insertions, 256 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/AbstractJSFResourceLocator.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/AbstractJSFResourceLocator.java
index 88bac5fdf..7c06a3844 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/AbstractJSFResourceLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/AbstractJSFResourceLocator.java
@@ -6,15 +6,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.resources.IProject;
import org.eclipse.jst.jsf.common.internal.locator.AbstractLocator;
import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener;
+import org.eclipse.jst.jsf.designtime.internal.resources.JSFResourceChangeListener.JSFResourceChangedEvent;
/**
* A locator that finds JSF resources.
*
* @author cbateman
- *
+ *
*/
public abstract class AbstractJSFResourceLocator extends
- AbstractLocator<List<JSFResource>, IProject, String> implements IJSFResourceLocator
+ AbstractLocator<List<JSFResource>, IProject, String> implements
+ IJSFResourceLocator
{
/**
@@ -32,4 +34,24 @@ public abstract class AbstractJSFResourceLocator extends
protected abstract List<JSFResource> doLocate(IProject context);
+ /**
+ * TODO: would be better to have a private interface to call fire.
+ *
+ * @param event
+ */
+ protected void fireChangeEvent(final JSFResourceChangedEvent event)
+ {
+ super.fireChangeEvent(event);
+ }
+
+ public void addListener(JSFResourceChangeListener listener)
+ {
+ super.addListener(listener);
+ }
+
+ public void removeListener(JSFResourceChangeListener listener)
+ {
+ super.removeListener(listener);
+ }
+
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/IJSFResourceLocator.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/IJSFResourceLocator.java
index 5d61f08a4..57faaea51 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/IJSFResourceLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/IJSFResourceLocator.java
@@ -13,5 +13,12 @@ import org.eclipse.jst.jsf.common.internal.locator.ILocator;
*/
public interface IJSFResourceLocator extends ILocator<List<JSFResource>, IProject, String>
{
- // nothing for now.
+ /**
+ * @param listener
+ */
+ public void addListener(final JSFResourceChangeListener listener);
+ /**
+ * @param listener
+ */
+ public void removeListener(final JSFResourceChangeListener listener);
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResource.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResource.java
index 81263d56b..e81c6bb62 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResource.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResource.java
@@ -6,7 +6,7 @@ import org.eclipse.jst.jsf.common.internal.resource.ContentTypeResolver;
* Represents a JSF loadable resource (spec 2.6).
*
* @author cbateman
- *
+ *
*/
public abstract class JSFResource
{
@@ -15,9 +15,10 @@ public abstract class JSFResource
/**
* @param id
- * @param contentTypeResolver
+ * @param contentTypeResolver
*/
- public JSFResource(final ResourceIdentifier id, final ContentTypeResolver contentTypeResolver)
+ public JSFResource(final ResourceIdentifier id,
+ final ContentTypeResolver contentTypeResolver)
{
_id = id;
_contentTypeResolver = contentTypeResolver;
@@ -38,11 +39,26 @@ public abstract class JSFResource
/**
* @param contentTypeName
- * @return true if the resources matches the content type indicated
- * by the contentTypeName.
+ * @return true if the resources matches the content type indicated by the
+ * contentTypeName.
*/
public boolean isContentType(final String contentTypeName)
{
- return _contentTypeResolver.matchesType(contentTypeName, _id.getResourceName());
+ return _contentTypeResolver.matchesType(contentTypeName, _id
+ .getResourceName());
+ }
+
+ /**
+ * @return a resource fragment is something which does not represent
+ * a JSF resource but which is a concrete object in the underlying design time system
+ * that maps to part or a "fragment" of a JSF resource. The most common instance
+ * is a workspace folder or jar entry that represents the library part of a resource id.
+ */
+ public abstract boolean isFragment();
+
+ @Override
+ public String toString()
+ {
+ return _id.toString();
}
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResourceChangeListener.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResourceChangeListener.java
new file mode 100644
index 000000000..70e048415
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JSFResourceChangeListener.java
@@ -0,0 +1,110 @@
+package org.eclipse.jst.jsf.designtime.internal.resources;
+
+import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener;
+
+/**
+ *
+ * @author cbateman
+ *
+ */
+public abstract class JSFResourceChangeListener implements ILocatorChangeListener
+{
+
+ /**
+ * Indicates that a tag library has changed
+ * @author cbateman
+ *
+ */
+ public static class JSFResourceChangedEvent extends LocatorChangeEvent
+ {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1546380081551499245L;
+
+ /**
+ * TODO: what happens if one locator has a namespace collision with
+ * another one?
+ */
+ public enum CHANGE_TYPE
+ {
+ /**
+ * Indicates that the resource is new
+ */
+ ADDED,
+
+ /**
+ * Indicates that the resource was removed.
+ */
+ REMOVED,
+
+ /**
+ * Indicates that the resource is not new, but it's content
+ * has changed
+ */
+ CHANGED
+ }
+
+ private final CHANGE_TYPE _changeType;
+ private final JSFResource _oldValue;
+ private final JSFResource _newValue;
+
+ /**
+ * @param source
+ * @param oldValue
+ * @param newValue
+ * @param changeType
+ */
+ public JSFResourceChangedEvent(
+ final AbstractJSFResourceLocator source,
+ final JSFResource oldValue,
+ final JSFResource newValue,
+ final CHANGE_TYPE changeType)
+ {
+ super(source);
+ _changeType = changeType;
+ _oldValue = oldValue;
+ _newValue = newValue;
+ }
+
+ @Override
+ public IJSFResourceLocator getSource()
+ {
+ return (IJSFResourceLocator) super.getSource();
+ }
+
+ /**
+ * @return the type of the change
+ */
+ public final CHANGE_TYPE getChangeType()
+ {
+ return _changeType;
+ }
+
+ /**
+ * @return the old value. This is null if the event is ADDED
+ */
+ public final JSFResource getOldValue()
+ {
+ return _oldValue;
+ }
+
+ /**
+ * @return the new value. This is null if the event is REMOVED
+ */
+ public final JSFResource getNewValue()
+ {
+ return _newValue;
+ }
+ }
+
+ public final void changed(final LocatorChangeEvent event)
+ {
+ changed((JSFResourceChangedEvent)event);
+ }
+
+ /**
+ * @param event
+ */
+ public abstract void changed(final JSFResourceChangedEvent event);
+}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JarBasedJSFResource.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JarBasedJSFResource.java
index ea2de3363..5dc72ca79 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JarBasedJSFResource.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/JarBasedJSFResource.java
@@ -25,9 +25,10 @@ public class JarBasedJSFResource extends JSFResource
/**
* @param id
* @param jarURL
- * @param contentTypeResolver
+ * @param contentTypeResolver
*/
- public JarBasedJSFResource(final ResourceIdentifier id, final URL jarURL, final ContentTypeResolver contentTypeResolver)
+ public JarBasedJSFResource(final ResourceIdentifier id, final URL jarURL,
+ final ContentTypeResolver contentTypeResolver)
{
super(id, contentTypeResolver);
_jarURL = jarURL;
@@ -49,26 +50,86 @@ public class JarBasedJSFResource extends JSFResource
return String.format("META-INF/resources/%s", getId().toString()); //$NON-NLS-1$
}
+ private ZipEntry getZipEntry(final JarFile jarFile)
+ {
+ return jarFile.getEntry(getJarEntryName());
+ }
+
/**
* @return true if is accessible.
*/
@Override
public final boolean isAccessible()
{
- URLConnection connection = null;
+ JarFile jarFile = null;
+ try
+ {
+ jarFile = getJarFile();
+ if (jarFile != null)
+ {
+ final ZipEntry entry = getZipEntry(jarFile);
+ return entry != null;
+ }
+ } finally
+ {
+ if (jarFile != null)
+ {
+// try
+// {
+// // TODO
+//// jarFile.close();
+// } /*catch (IOException e)
+// {
+// // fall-through.
+// }*/
+ }
+ }
+ return false;
+ }
+
+ private JarFile getJarFile()
+ {
+ URLConnection connection;
try
{
connection = _jarURL.openConnection();
connection.connect();
if (connection instanceof JarURLConnection)
{
- JarFile jarFile = ((JarURLConnection)connection).getJarFile();
- ZipEntry entry = jarFile.getEntry(getJarEntryName());
- return entry != null;
+ return ((JarURLConnection) connection).getJarFile();
}
} catch (IOException e)
{
- // fall-through
+ // fall through
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isFragment()
+ {
+ JarFile jarFile = null;
+ try
+ {
+ jarFile = getJarFile();
+ if (jarFile != null)
+ {
+ final ZipEntry entry = getZipEntry(jarFile);
+ return entry.isDirectory();
+ }
+ } finally
+ {
+ if (jarFile != null)
+ {
+ // TODO:
+// try
+// {
+// jarFile.close();
+// } catch (IOException e)
+// {
+// // fall-through.
+// }
+ }
}
return false;
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/ResourceIdentifier.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/ResourceIdentifier.java
index 0c0c4c7dd..986f1dc49 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/ResourceIdentifier.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/ResourceIdentifier.java
@@ -23,10 +23,10 @@ public class ResourceIdentifier
/**
* The namespace for validation diagnositics created by validate.
*/
- public static final String ResourceIdentifierValidationNamespace = JSFCorePlugin.PLUGIN_ID+"_JSFResourceIdentifier"; //$NON-NLS-1$
+ public static final String ResourceIdentifierValidationNamespace = JSFCorePlugin.PLUGIN_ID
+ + "_JSFResourceIdentifier"; //$NON-NLS-1$
private final String _resName;
-
/**
* @param resName
*/
@@ -88,7 +88,9 @@ public class ResourceIdentifier
if (getResourceName() == null)
{
- status.add(new Status(IStatus.ERROR, id, RESOURCE_NAME_MUST_NOT_BE_EMPTY, Messages.ResourceIdentifier_0, null));
+ status.add(new Status(IStatus.ERROR, id,
+ RESOURCE_NAME_MUST_NOT_BE_EMPTY,
+ Messages.ResourceIdentifier_0, null));
}
return status;
@@ -101,7 +103,7 @@ public class ResourceIdentifier
{
return validate().isOK();
}
-
+
@Override
public String toString()
{
@@ -130,4 +132,28 @@ public class ResourceIdentifier
}
return idString;
}
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (super.equals(obj))
+ {
+ return true;
+ }
+
+ if (obj instanceof ResourceIdentifier)
+ {
+ String meToString = toString();
+ String otherToString = obj.toString();
+ return meToString.equals(otherToString);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResource.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResource.java
index d082a28a2..20a12e76a 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResource.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResource.java
@@ -36,4 +36,10 @@ public class WorkspaceJSFResource extends JSFResource
{
return _res.isAccessible();
}
+
+ @Override
+ public boolean isFragment()
+ {
+ return _res.getType() != IResource.FILE;
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResourceLocator.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResourceLocator.java
index e38b19298..17f7a1cec 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResourceLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceJSFResourceLocator.java
@@ -1,25 +1,13 @@
package org.eclipse.jst.jsf.designtime.internal.resources;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.jst.jsf.common.internal.componentcore.AbstractVirtualComponentQuery;
-import org.eclipse.jst.jsf.common.internal.finder.AbstractMatcher.AlwaysMatcher;
-import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher;
-import org.eclipse.jst.jsf.common.internal.finder.acceptor.FileMatchingAcceptor;
import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener;
import org.eclipse.jst.jsf.common.internal.resource.ContentTypeResolver;
-import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
-import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
/**
* @author cbateman
@@ -29,14 +17,16 @@ public class WorkspaceJSFResourceLocator extends AbstractJSFResourceLocator
{
private final AbstractVirtualComponentQuery _vcQuery;
private final ContentTypeResolver _contentTypeResolver;
+ private WorkspaceResourceManager _workspaceResourceManager;
/**
* @param id
* @param displayName
* @param noResultValue
* @param mutableListenerList
- * @param vcQuery
- * @param contentTypeResolver
+ * @param vcQuery
+ * @param contentTypeResolver
+ * @param workspace
*/
public WorkspaceJSFResourceLocator(
final String id,
@@ -44,7 +34,8 @@ public class WorkspaceJSFResourceLocator extends AbstractJSFResourceLocator
final List<JSFResource> noResultValue,
final CopyOnWriteArrayList<ILocatorChangeListener> mutableListenerList,
final AbstractVirtualComponentQuery vcQuery,
- final ContentTypeResolver contentTypeResolver)
+ final ContentTypeResolver contentTypeResolver,
+ final IWorkspace workspace)
{
super(id, displayName, noResultValue, mutableListenerList);
_vcQuery = vcQuery;
@@ -55,57 +46,33 @@ public class WorkspaceJSFResourceLocator extends AbstractJSFResourceLocator
* @param noResultValue
* @param mutableListenerList
* @param vcQuery
- * @param contentTypeResolver
+ * @param contentTypeResolver
+ * @param workspace
*/
public WorkspaceJSFResourceLocator(
final List<JSFResource> noResultValue,
final CopyOnWriteArrayList<ILocatorChangeListener> mutableListenerList,
- final AbstractVirtualComponentQuery vcQuery, final ContentTypeResolver contentTypeResolver)
+ final AbstractVirtualComponentQuery vcQuery,
+ final ContentTypeResolver contentTypeResolver,
+ final IWorkspace workspace)
{
this(
- "", "", noResultValue, mutableListenerList, vcQuery, contentTypeResolver); //$NON-NLS-1$//$NON-NLS-2$
+ "", "", noResultValue, mutableListenerList, vcQuery, contentTypeResolver, workspace); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public void start(final IProject initialContext)
+ {
+ _workspaceResourceManager = new WorkspaceResourceManager(
+ initialContext, _vcQuery, this, _contentTypeResolver);
+ _workspaceResourceManager.initResources();
+ super.start(initialContext);
}
@Override
protected List<JSFResource> doLocate(final IProject project)
{
- final List<JSFResource> located = new ArrayList<JSFResource>();
- final IVirtualFolder webContentFolder = _vcQuery
- .getWebContentFolder(project);
- if (webContentFolder != null
- && webContentFolder.getUnderlyingFolder().isAccessible())
- {
- final IFolder folder = webContentFolder.getUnderlyingFolder()
- .getFolder(new Path("resources")); //$NON-NLS-1$
- if (folder != null && folder.isAccessible())
- {
- final VisitorMatcher<IContainer, IResource, String> matcher = new VisitorMatcher<IContainer, IResource, String>(
- "", "", //$NON-NLS-1$ //$NON-NLS-2$
- new FileMatchingAcceptor(), Collections
- .singletonList(new AlwaysMatcher()));
- try
- {
- final IPath containerPath = folder.getFullPath();
- final ResourceIdentifierFactory factory = new ResourceIdentifierFactory();
- final Collection<? extends IResource> foundResources = matcher
- .find(folder);
- for (final IResource res : foundResources)
- {
- final IPath fullPath = res.getFullPath()
- .makeRelativeTo(containerPath);
- located.add(new WorkspaceJSFResource(factory
- .createLibraryResource(fullPath.toString()),
- res, _contentTypeResolver));
- }
- } catch (final Exception e)
- {
- JSFCorePlugin
- .log(e,
- "While trying to locate JSF resources in the workspace"); //$NON-NLS-1$
- }
- }
- }
- return located;
+ return _workspaceResourceManager.getJSFResources();
}
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceResourceManager.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceResourceManager.java
new file mode 100644
index 000000000..709a38339
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/internal/resources/WorkspaceResourceManager.java
@@ -0,0 +1,238 @@
+package org.eclipse.jst.jsf.designtime.internal.resources;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.jsf.common.internal.componentcore.AbstractVirtualComponentQuery;
+import org.eclipse.jst.jsf.common.internal.finder.AbstractMatcher.AlwaysMatcher;
+import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher;
+import org.eclipse.jst.jsf.common.internal.finder.acceptor.FileMatchingAcceptor;
+import org.eclipse.jst.jsf.common.internal.resource.ContentTypeResolver;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceManager;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceTracker;
+import org.eclipse.jst.jsf.core.internal.JSFCorePlugin;
+import org.eclipse.jst.jsf.designtime.internal.resources.JSFResourceChangeListener.JSFResourceChangedEvent;
+import org.eclipse.jst.jsf.designtime.internal.resources.JSFResourceChangeListener.JSFResourceChangedEvent.CHANGE_TYPE;
+import org.eclipse.jst.jsf.designtime.internal.resources.ResourceIdentifierFactory.InvalidIdentifierException;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+
+/**
+ * Resource Manager that tracks JSF resources in a workspace.
+ *
+ * @author cbateman
+ *
+ */
+public class WorkspaceResourceManager extends ResourceManager<IResource>
+{
+ private final AbstractVirtualComponentQuery _vcQuery;
+ private final IProject _project;
+ private final AbstractJSFResourceLocator _locator;
+ private final ContentTypeResolver _contentTypeResolver;
+ private final ResourceIdentifierFactory _factory;
+
+ /**
+ * @param project
+ * @param vcQuery
+ * @param locator
+ * @param contentTypeResolver
+ */
+ public WorkspaceResourceManager(final IProject project,
+ final AbstractVirtualComponentQuery vcQuery,
+ final AbstractJSFResourceLocator locator,
+ final ContentTypeResolver contentTypeResolver)
+ {
+ super(project.getWorkspace());
+ _project = project;
+ _vcQuery = vcQuery;
+ _locator = locator;
+ _contentTypeResolver = contentTypeResolver;
+ _factory = new ResourceIdentifierFactory();
+ }
+
+ @Override
+ protected JSFResourceTracker createNewInstance(final IResource resource)
+ {
+ return new JSFResourceTracker(resource);
+ }
+
+ @Override
+ public void initResources()
+ {
+ final IFolder folder = getRootResourceFolder();
+
+ if (folder != null && folder.isAccessible())
+ {
+ try
+ {
+ track(folder.getParent(), folder);
+ } catch (final Exception e1)
+ {
+ JSFCorePlugin
+ .log(e1,
+ "While trying to locate JSF resources in the workspace"); //$NON-NLS-1$
+ }
+
+ final VisitorMatcher<IContainer, IResource, String> matcher = new VisitorMatcher<IContainer, IResource, String>(
+ "", "", //$NON-NLS-1$ //$NON-NLS-2$
+ new FileMatchingAcceptor(), Collections
+ .singletonList(new AlwaysMatcher()));
+ try
+ {
+ final Collection<? extends IResource> foundResources = matcher
+ .find(folder);
+ for (final IResource res : foundResources)
+ {
+ track(folder, res);
+ }
+ } catch (final Exception e)
+ {
+ JSFCorePlugin
+ .log(e,
+ "While trying to locate JSF resources in the workspace"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private WorkspaceJSFResource track(final IContainer containerFolder,
+ final IResource res) throws ManagedObjectException,
+ InvalidIdentifierException
+ {
+ final IPath containerPath = containerFolder.getFullPath();
+
+ final IPath fullPath = res.getFullPath().makeRelativeTo(containerPath);
+ // cause the resource to get tracked
+ final JSFResourceTracker tracker = (JSFResourceTracker) getInstance(res);
+ final WorkspaceJSFResource jsfRes = new WorkspaceJSFResource(_factory
+ .createLibraryResource(fullPath.toString()), res,
+ _contentTypeResolver);
+ tracker.setJsfResource(jsfRes);
+ addLifecycleEventListener(tracker);
+ return jsfRes;
+ }
+
+ /**
+ * @return the root folder for resources in the workspace.
+ */
+ public IFolder getRootResourceFolder()
+ {
+ final IVirtualFolder webContentFolder = _vcQuery
+ .getWebContentFolder(_project);
+ if (webContentFolder != null
+ && webContentFolder.getUnderlyingFolder().isAccessible())
+ {
+ return webContentFolder.getUnderlyingFolder().getFolder(
+ new Path("resources")); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ @Override
+ public List<IResource> getResources()
+ {
+ return new ArrayList(getManagedResources());
+ }
+
+ /**
+ * @return the jsf resource currently known. List is a copy but the
+ * contained JSFResource references are not.
+ */
+ public List<JSFResource> getJSFResources()
+ {
+ final List<JSFResource> jsfResources = new ArrayList<JSFResource>();
+ final Map<IResource, ManagedResourceObject<ResourceTracker<IResource>>> jsfResourceTrackers = getPerResourceObjects();
+
+ for (final Map.Entry<IResource, ManagedResourceObject<ResourceTracker<IResource>>> entry : jsfResourceTrackers
+ .entrySet())
+ {
+ jsfResources.add(((JSFResourceTracker) entry.getValue()
+ .getManagedObject()).getJsfResource());
+ }
+ return jsfResources;
+ }
+
+ private class JSFResourceTracker extends ResourceTracker<IResource>
+ {
+ private WorkspaceJSFResource _jsfResource;
+
+ public JSFResourceTracker(final IResource resource)
+ {
+ super(resource);
+ }
+
+ @Override
+ protected void fireResourceInAccessible(final ReasonType reasonType)
+ {
+ removeLifecycleEventListener(this);
+ _locator.fireChangeEvent(new JSFResourceChangedEvent(_locator,
+ _jsfResource, null, CHANGE_TYPE.REMOVED));
+ }
+
+ @Override
+ protected void fireResourceChanged(final ReasonType reasonType)
+ {
+ _locator.fireChangeEvent(new JSFResourceChangedEvent(_locator,
+ _jsfResource, _jsfResource, CHANGE_TYPE.CHANGED));
+ }
+
+ @Override
+ protected void fireResourceAdded(final IResource affectedResource,
+ final ReasonType reasonType)
+ {
+ final IFolder root = getRootResourceFolder();
+ if (root != null && root.isAccessible())
+ {
+ try
+ {
+ final WorkspaceJSFResource newJsfRes = track(root,
+ affectedResource);
+ final JSFResourceChangedEvent event = new JSFResourceChangedEvent(
+ _locator, null, newJsfRes, CHANGE_TYPE.ADDED);
+ _locator.fireChangeEvent(event);
+ } catch (final ManagedObjectException e)
+ {
+ JSFCorePlugin.log(e,
+ "While adding new resource " + affectedResource); //$NON-NLS-1$
+ } catch (final InvalidIdentifierException e)
+ {
+ JSFCorePlugin.log(e,
+ "While adding new resource " + affectedResource); //$NON-NLS-1$
+ }
+ }
+ }
+
+ @Override
+ protected boolean isInteresting(final ResourceLifecycleEvent event)
+ {
+ switch (event.getEventType())
+ {
+ case RESOURCE_ADDED:
+ return getResource() instanceof IContainer
+ && event.getAffectedResource().getParent().equals(
+ getResource());
+ default:
+ return super.isInteresting(event);
+ }
+ }
+
+ public final WorkspaceJSFResource getJsfResource()
+ {
+ return _jsfResource;
+ }
+
+ public final void setJsfResource(final WorkspaceJSFResource jsfResource)
+ {
+ _jsfResource = jsfResource;
+ }
+ }
+}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/CompositeComponentTaglibLocator.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/CompositeComponentTaglibLocator.java
index 06cd35fa4..ddc72b84a 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/CompositeComponentTaglibLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/CompositeComponentTaglibLocator.java
@@ -1,5 +1,6 @@
package org.eclipse.jst.jsf.facelet.core.internal.registry.taglib;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -7,7 +8,10 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.jst.jsf.common.internal.locator.ILocatorProvider;
import org.eclipse.jst.jsf.designtime.internal.resources.IJSFResourceLocator;
import org.eclipse.jst.jsf.designtime.internal.resources.JSFResource;
+import org.eclipse.jst.jsf.designtime.internal.resources.JSFResourceChangeListener;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.JSFResourceBasedTagRecord.Builder;
+import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.Listener.TaglibChangedEvent;
+import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.Listener.TaglibChangedEvent.CHANGE_TYPE;
/**
* A taglib locator that locates composite components, which a located as a type
@@ -19,15 +23,79 @@ import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.JSFResourceBase
public class CompositeComponentTaglibLocator extends
AbstractFaceletTaglibLocator
{
+ private final class ResourceLocatorChangeListener extends
+ JSFResourceChangeListener
+ {
+ @Override
+ public void changed(final JSFResourceChangedEvent event)
+ {
+ final Builder builder = new Builder();
+ switch (event.getChangeType())
+ {
+ case ADDED:
+ case CHANGED:
+ {
+ List<TaglibChangedEvent> events = Collections.EMPTY_LIST;
+
+ if (event.getNewValue().isFragment())
+ {
+ // if it's a fragment handle as a possible library add
+ events = handleFolderAddChange(event, builder);
+ } else
+ {
+ // otherwise, handle as a file add.
+ events = handleFileAddChange(event, builder);
+ }
+ _records = builder.merge(events, _records);
+ for (final TaglibChangedEvent fireEvent : events)
+ {
+ fireChangeEvent(fireEvent);
+ }
+ }
+ break;
+ case REMOVED:
+ {
+ final JSFResource oldValue = event.getOldValue();
+ builder.addTag(oldValue, CHANGE_TYPE.REMOVED);
+ final List<TaglibChangedEvent> events = builder.createRemove(
+ CompositeComponentTaglibLocator.this, _records);
+ _records = builder.merge(events, _records);
+ for (final TaglibChangedEvent fireEvent : events)
+ {
+ fireChangeEvent(fireEvent);
+ }
+ }
+ break;
+ }
+ }
+
+ private List<TaglibChangedEvent> handleFolderAddChange(
+ JSFResourceChangedEvent event, Builder builder)
+ {
+ final JSFResource newValue = event.getNewValue();
+ builder.addLibrary(newValue, CHANGE_TYPE.ADDED);
+ return builder.createMerge(CompositeComponentTaglibLocator.this, _records);
+ }
+
+ private List<TaglibChangedEvent> handleFileAddChange(
+ final JSFResourceChangedEvent event, final Builder builder)
+ {
+ final JSFResource newValue = event.getNewValue();
+ builder.addTag(newValue, CHANGE_TYPE.ADDED);
+ return builder.createMerge(CompositeComponentTaglibLocator.this,
+ _records);
+ }
+ }
+
/**
* the id of the locator strategy.
*/
public static final String ID = CompositeComponentTaglibLocator.class
.getCanonicalName();
private static final String DISPLAY_NAME = "Composite Composite Tag Lib Locator"; //$NON-NLS-1$
- private static final String FACELET_FILE_CONTENT_TYPE = "org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$
private final ILocatorProvider<IJSFResourceLocator> _locatorProvider;
- private Map<String, ? extends IFaceletTagRecord> _records;
+ private Map<String, JSFResourceBasedTagRecord> _records;
+ private final ResourceLocatorChangeListener _listener;
/**
* @param locatorProvider
@@ -38,22 +106,36 @@ public class CompositeComponentTaglibLocator extends
super(ID, DISPLAY_NAME);
_locatorProvider = locatorProvider;
_locatorProvider.initialize();
+ _listener = new ResourceLocatorChangeListener();
}
@Override
- public void start(IProject initialContext)
+ public void start(final IProject initialContext)
{
- for (IJSFResourceLocator locator : _locatorProvider.getLocators())
+ for (final IJSFResourceLocator locator : _locatorProvider.getLocators())
{
locator.start(initialContext);
+ locator.addListener(_listener);
+ }
+
+ final Builder builder = new Builder();
+ for (final IJSFResourceLocator locator : _locatorProvider.getLocators())
+ {
+ final List<JSFResource> resources = locator.locate(initialContext);
+ for (final JSFResource resource : resources)
+ {
+ builder.addTag(resource, CHANGE_TYPE.ADDED);
+ }
}
+ _records = builder.build();
+
super.start(initialContext);
}
@Override
public void stop()
{
- for (IJSFResourceLocator locator : _locatorProvider.getLocators())
+ for (final IJSFResourceLocator locator : _locatorProvider.getLocators())
{
locator.stop();
}
@@ -64,21 +146,6 @@ public class CompositeComponentTaglibLocator extends
protected Map<String, ? extends IFaceletTagRecord> doLocate(
final IProject context)
{
- final Builder builder = new Builder();
- for (final IJSFResourceLocator locator : _locatorProvider.getLocators())
- {
- List<JSFResource> resources = locator.locate(context);
- for (final JSFResource resource : resources)
- {
- if (resource.isAccessible()
- && resource.isContentType(FACELET_FILE_CONTENT_TYPE))
- {
- builder.addTag(resource);
- }
- }
- }
- _records = builder.build();
- return _records;
+ return Collections.unmodifiableMap(_records);
}
-
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/ContextParamSpecifiedFaceletTaglibLocator.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/ContextParamSpecifiedFaceletTaglibLocator.java
index f8e10c4f3..ed3b0c030 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/ContextParamSpecifiedFaceletTaglibLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/ContextParamSpecifiedFaceletTaglibLocator.java
@@ -78,7 +78,7 @@ public class ContextParamSpecifiedFaceletTaglibLocator extends
@Override
public void start(final IProject project)
{
- _fileManager.initFiles();
+ _fileManager.initResources();
super.start(project);
}
@@ -99,7 +99,7 @@ public class ContextParamSpecifiedFaceletTaglibLocator extends
protected Map<String, ? extends IFaceletTagRecord> doLocate(
final IProject context)
{
- final List<IFile> files = _fileManager.getFiles();
+ final List<IFile> files = _fileManager.getResources();
_records.clear();
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/FaceletTagIndex.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/FaceletTagIndex.java
index 6d55a8651..ebc84376f 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/FaceletTagIndex.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/FaceletTagIndex.java
@@ -39,7 +39,7 @@ import org.eclipse.jst.jsf.designtime.internal.resources.WorkspaceJSFResourceLoc
public class FaceletTagIndex extends
ResourceSingletonObjectManager<IProjectTaglibDescriptor, IProject>
{
- private IProjectTaglibDescriptorFactory _factory;
+ private final IProjectTaglibDescriptorFactory _factory;
/**
* @param ws
@@ -97,31 +97,32 @@ public class FaceletTagIndex extends
AbstractProjectTaglibDescriptorFactory
{
@Override
- public IProjectTaglibDescriptor create(IProject project,
- TagRecordFactory factory)
+ public IProjectTaglibDescriptor create(final IProject project,
+ final TagRecordFactory factory)
{
final List<AbstractFaceletTaglibLocator> locators = new ArrayList<AbstractFaceletTaglibLocator>();
locators.add(new JarFileFaceletTaglibLocator(factory));
locators.add(new ContextParamSpecifiedFaceletTaglibLocator(project,
factory, ModelProviderManager.getModelProvider(project),
new DefaultVirtualComponentQuery(), new WorkspaceMediator()));
- List<IJSFResourceLocator> resourceLocators = new ArrayList<IJSFResourceLocator>();
+ final List<IJSFResourceLocator> resourceLocators = new ArrayList<IJSFResourceLocator>();
resourceLocators.add(new JarBasedJSFResourceLocator(
Collections.EMPTY_LIST,
new CopyOnWriteArrayList<ILocatorChangeListener>(),
new DefaultJarProvider(Collections
.singletonList(new AlwaysMatcher())),
new ContentTypeResolver()));
+ final IWorkspace workspace = project.getWorkspace();
resourceLocators.add(new WorkspaceJSFResourceLocator(
Collections.EMPTY_LIST,
new CopyOnWriteArrayList<ILocatorChangeListener>(),
new DefaultVirtualComponentQuery(),
- new ContentTypeResolver()));
+ new ContentTypeResolver(), workspace));
final DefaultLocatorProvider<IJSFResourceLocator> resourceLocatorProvider = new DefaultLocatorProvider<IJSFResourceLocator>(
resourceLocators);
locators.add(new CompositeComponentTaglibLocator(
resourceLocatorProvider));
- LocatorProvider provider = new LocatorProvider(locators);
+ final LocatorProvider provider = new LocatorProvider(locators);
return new ProjectTaglibDescriptor(project, factory, provider);
}
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/IFaceletTaglibLocator.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/IFaceletTaglibLocator.java
index 23c8d3db2..6d0f76165 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/IFaceletTaglibLocator.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/IFaceletTaglibLocator.java
@@ -14,5 +14,8 @@ import org.eclipse.jst.jsf.common.internal.locator.ILocator;
*/
public interface IFaceletTaglibLocator extends ILocator<Map<String, ? extends IFaceletTagRecord>, IProject, String>
{
- // do nothing
+ /**
+ * @param listener
+ */
+ public abstract void addListener(final Listener listener);
} \ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/JSFResourceBasedTagRecord.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/JSFResourceBasedTagRecord.java
index 91b2280e7..1b23add35 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/JSFResourceBasedTagRecord.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/JSFResourceBasedTagRecord.java
@@ -10,6 +10,8 @@ import java.util.Map;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jst.jsf.designtime.internal.resources.JSFResource;
+import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.Listener.TaglibChangedEvent;
+import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.Listener.TaglibChangedEvent.CHANGE_TYPE;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibFactory;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.faceletTaglib.FaceletTaglibTag;
@@ -71,23 +73,70 @@ public class JSFResourceBasedTagRecord extends FaceletTagRecord
}
/**
+ * Merge my tags with 'withThese'. Tags in my list will be replaced with
+ * those in 'withThese' if their names match.
+ *
+ * @param withThese
+ */
+ /* package */JSFResourceBasedTagRecord mergeTags(
+ final List<FaceletTaglibTag> withThese)
+ {
+ final List<FaceletTaglibTag> tags = new ArrayList<FaceletTaglibTag>(
+ _tags);
+ for (final FaceletTaglibTag mergeTag : withThese)
+ {
+ final FaceletTaglibTag tag = getTag(mergeTag.getTagName());
+ if (tag != null)
+ {
+ tags.remove(tag);
+ }
+ tags.add(mergeTag);
+ }
+ return new JSFResourceBasedTagRecord(_uri, tags);
+ }
+
+ /* package */JSFResourceBasedTagRecord removeTags(
+ final List<FaceletTaglibTag> removeThese)
+ {
+ final List<FaceletTaglibTag> tags = new ArrayList<FaceletTaglibTag>(
+ _tags);
+ for (final FaceletTaglibTag mergeTag : removeThese)
+ {
+ final FaceletTaglibTag tag = getTag(mergeTag.getTagName());
+ if (tag != null)
+ {
+ tags.remove(tag);
+ }
+ }
+ return new JSFResourceBasedTagRecord(_uri, tags);
+ }
+
+ /**
* A builder for tag record.
*
* @author cbateman
- *
+ *
*/
public static class Builder
{
private final Map<String, List<FaceletTaglibTag>> _tags = new HashMap<String, List<FaceletTaglibTag>>();
+ private static final String FACELET_FILE_CONTENT_TYPE = "org.eclipse.wst.html.core.htmlsource"; //$NON-NLS-1$
/**
* @param jsfResource
+ * @param changeType
*/
- public void addTag(final JSFResource jsfResource)
+ public void addTag(final JSFResource jsfResource,
+ final CHANGE_TYPE changeType)
{
+ String libraryName = jsfResource.getId().getLibraryName();
+ if (libraryName == null)
+ {
+ return;
+ }
final String uri = String
.format(
- "http://java.sun.com/jsf/composite/%s", jsfResource.getId().getLibraryName()); //$NON-NLS-1$
+ "http://java.sun.com/jsf/composite/%s", libraryName); //$NON-NLS-1$
List<FaceletTaglibTag> tags = _tags.get(uri);
if (tags == null)
{
@@ -95,27 +144,160 @@ public class JSFResourceBasedTagRecord extends FaceletTagRecord
_tags.put(uri, tags);
}
final String resourceName = jsfResource.getId().getResourceName();
- final IPath resourceNamePath = new Path(resourceName).removeFileExtension();
+ final IPath resourceNamePath = new Path(resourceName)
+ .removeFileExtension();
final FaceletTaglibTag tag = FaceletTaglibFactory.eINSTANCE
.createFaceletTaglibTag();
tag.setTagName(resourceNamePath.toString());
- tags.add(tag);
+
+ switch (changeType)
+ {
+ case ADDED:
+ case CHANGED:
+ // only add to the list on a add/change if the resource exists
+ // and is the right type
+ if (jsfResource.isAccessible()
+ && jsfResource.isContentType(FACELET_FILE_CONTENT_TYPE))
+ {
+ tags.add(tag);
+ }
+ break;
+ case REMOVED:
+ // add all comers to the remove list. They will only be removal
+ // on merge if ADDED/CHANGED path decided they should be there.
+ tags.add(tag);
+ }
+ }
+
+ /**
+ * @param jsfResource
+ * @param added
+ */
+ public void addLibrary(JSFResource jsfResource, CHANGE_TYPE added)
+ {
+ String libraryName = jsfResource.getId().getLibraryName();
+ if (libraryName == null)
+ {
+ return;
+ }
+ final String uri = String
+ .format(
+ "http://java.sun.com/jsf/composite/%s", libraryName); //$NON-NLS-1$
+ List<FaceletTaglibTag> tags = _tags.get(uri);
+ if (tags == null)
+ {
+ tags = new ArrayList<FaceletTaglibTag>();
+ _tags.put(uri, tags);
+ }
}
/**
* @return the built list of tag records.
*/
- public Map<String, ? extends IFaceletTagRecord> build()
+ public Map<String, JSFResourceBasedTagRecord> build()
{
final Map<String, JSFResourceBasedTagRecord> records = new HashMap<String, JSFResourceBasedTagRecord>();
for (final Map.Entry<String, List<FaceletTaglibTag>> entry : _tags
.entrySet())
{
- JSFResourceBasedTagRecord newRecord = new JSFResourceBasedTagRecord(entry.getKey(), entry.getValue());
+ final JSFResourceBasedTagRecord newRecord = new JSFResourceBasedTagRecord(
+ entry.getKey(), entry.getValue());
records.put(entry.getKey(), newRecord);
}
return records;
}
+
+ /**
+ * @param locator
+ * @param records
+ * @return a list of taglib change events that reflect what will happen
+ * when my tags are merged into the map 'records'.
+ */
+ public List<TaglibChangedEvent> createMerge(
+ final AbstractFaceletTaglibLocator locator,
+ final Map<String, JSFResourceBasedTagRecord> records)
+ {
+ final Map<String, JSFResourceBasedTagRecord> newRecords = build();
+ final List<TaglibChangedEvent> mergeEvents = new ArrayList<TaglibChangedEvent>();
+ for (final Map.Entry<String, JSFResourceBasedTagRecord> entry : newRecords
+ .entrySet())
+ {
+ TaglibChangedEvent event = null;
+ if (!records.containsKey(entry.getKey()))
+ {
+ event = new TaglibChangedEvent(locator, null, entry
+ .getValue(), CHANGE_TYPE.ADDED);
+ } else
+ {
+ JSFResourceBasedTagRecord oldRecord = records.get(entry
+ .getKey());
+ JSFResourceBasedTagRecord newRecord = oldRecord
+ .mergeTags(entry.getValue()._tags);
+ event = new TaglibChangedEvent(locator, oldRecord,
+ newRecord, CHANGE_TYPE.CHANGED);
+ }
+ mergeEvents.add(event);
+ }
+ return mergeEvents;
+ }
+
+ /**
+ * @param locator
+ * @param records
+ * @return a list of change events that will result from removing my
+ * _tags from records.
+ */
+ public List<TaglibChangedEvent> createRemove(
+ AbstractFaceletTaglibLocator locator,
+ Map<String, JSFResourceBasedTagRecord> records)
+ {
+ final Map<String, JSFResourceBasedTagRecord> newRecords = build();
+ final List<TaglibChangedEvent> mergeEvents = new ArrayList<TaglibChangedEvent>();
+ for (final Map.Entry<String, JSFResourceBasedTagRecord> entry : newRecords
+ .entrySet())
+ {
+ TaglibChangedEvent event = null;
+ {
+ JSFResourceBasedTagRecord oldRecord = records.get(entry
+ .getKey());
+ if (oldRecord != null)
+ {
+ JSFResourceBasedTagRecord newRecord = oldRecord
+ .removeTags(entry.getValue()._tags);
+ event = new TaglibChangedEvent(locator, oldRecord,
+ newRecord, CHANGE_TYPE.CHANGED);
+ }
+ }
+ mergeEvents.add(event);
+ }
+ return mergeEvents;
+
+ }
+
+ /**
+ * @param events
+ * @param withThese
+ * @return a new merged map that contains withThese plus everything
+ * here.
+ */
+ public Map<String, JSFResourceBasedTagRecord> merge(
+ List<TaglibChangedEvent> events,
+ final Map<String, JSFResourceBasedTagRecord> withThese)
+ {
+ final Map<String, JSFResourceBasedTagRecord> newMap = new HashMap<String, JSFResourceBasedTagRecord>(
+ withThese);
+ for (final TaglibChangedEvent event : events)
+ {
+ IFaceletTagRecord newRecord = event.getNewValue();
+ // doubles as null check
+ if (newRecord instanceof JSFResourceBasedTagRecord)
+ {
+ newMap.put(newRecord.getURI(),
+ (JSFResourceBasedTagRecord) newRecord);
+ }
+ }
+ return newMap;
+ }
}
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibFileTracker.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibFileTracker.java
index 7d0c59325..26219c970 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibFileTracker.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibFileTracker.java
@@ -1,26 +1,22 @@
package org.eclipse.jst.jsf.facelet.core.internal.registry.taglib;
-import java.util.concurrent.atomic.AtomicLong;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent;
-import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.EventType;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceTracker;
-class TaglibFileTracker extends TaglibResourceTracker
+class TaglibFileTracker extends ResourceTracker<IFile>
{
- private final IFile _file;
private String _uri;
- private final AtomicLong _lastModifiedStamp = new AtomicLong();
private TaglibResourceManager _manager;
private final ILibraryChangeHandler _handler;
public TaglibFileTracker(final IFile file, final TaglibResourceManager manager,
final ILibraryChangeHandler handler)
{
+ super(file);
_manager = manager;
_manager.addListener(this);
- _file = file;
- _lastModifiedStamp.set(file.getModificationStamp());
_handler = handler;
}
@@ -42,64 +38,23 @@ class TaglibFileTracker extends TaglibResourceTracker
}
@Override
- public EventResult acceptEvent(final ResourceLifecycleEvent event)
+ protected void fireResourceInAccessible(final ReasonType reasonType)
{
- if (!_file.equals(event.getAffectedResource()))
- {
- return EventResult.getDefaultEventResult();
- }
-
- final EventType eventType = event.getEventType();
+ // removed resources kick a remove event
+ _handler.removed(_uri, getResource());
+ }
- switch (eventType)
- {
- case RESOURCE_ADDED:
- // added resources kick an add event.
- _handler.added(_file);
- break;
- case RESOURCE_CHANGED:
- // changed resources kick a change event
- _handler.changed(_uri, _file);
- break;
- case RESOURCE_INACCESSIBLE:
- // removed resources kick a remove event
- _handler.removed(_uri, _file);
- break;
- }
+ @Override
+ protected void fireResourceChanged(final ReasonType reasonType)
+ {
+ // changed resources kick a change event
+ _handler.changed(_uri, getResource());
+ }
- return EventResult.getDefaultEventResult();
+ @Override
+ protected void fireResourceAdded(final IResource affectedResource, final ReasonType reasonType)
+ {
+ // added resources kick an add event.
+ _handler.added(getResource());
}
-
-// private final static class HandleFileAddJob implements IWorkspaceRunnable
-// {
-// private final IResourceChangeEvent _event;
-// private List<IFile> _files;
-// private ILibraryChangeHandler _handler;
-//
-// private HandleFileAddJob(final IResourceChangeEvent event, final List<IFile> files,
-// final ILibraryChangeHandler handler)
-// {
-// _event = event;
-// _files = files;
-// _handler = handler;
-// }
-//
-// public void run(final IProgressMonitor monitor)
-// throws CoreException
-// {
-// for (final IFile file : _files)
-// {
-// final IResourceDelta delta = _event.getDelta()
-// .findMember(file.getFullPath());
-//
-// if (delta != null)
-// {
-// if (delta.getKind() == IResourceDelta.ADDED)
-// {
-// _handler.added(file);
-// }
-// }
-// }
-// }
-// }
} \ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceManager.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceManager.java
index 7195e2af9..ce7cce0a5 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceManager.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceManager.java
@@ -5,18 +5,16 @@ import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jst.jsf.common.internal.resource.IResourceLifecycleListener;
-import org.eclipse.jst.jsf.common.internal.resource.ResourceSingletonObjectManager;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceManager;
+import org.eclipse.jst.jsf.common.internal.resource.ResourceTracker;
import org.eclipse.jst.jsf.common.internal.resource.WorkspaceMediator;
import org.eclipse.jst.jsf.facelet.core.internal.FaceletCorePlugin;
import org.eclipse.jst.jsf.facelet.core.internal.registry.taglib.WebappConfiguration.WebappListener;
-class TaglibResourceManager extends
- ResourceSingletonObjectManager<TaglibResourceTracker, IResource>
+class TaglibResourceManager extends ResourceManager<IFile>
{
private ILibraryChangeHandler _handler;
private final WebappConfiguration _webAppConfiguration;
-// private final IResourceChangeListener _newFileListener;
public TaglibResourceManager(final IProject project,
final ILibraryChangeHandler handler,
@@ -26,30 +24,16 @@ class TaglibResourceManager extends
super(project.getWorkspace());
_handler = handler;
_webAppConfiguration = webAppConfiguration;
- // TODO: fold into LifecycleListener
-// _newFileListener = new IResourceChangeListener()
-// {
-// public void resourceChanged(final IResourceChangeEvent event)
-// {
-// // if the event is post change && has the same parent
-// // project
-// if (event.getType() == IResourceChangeEvent.POST_CHANGE
-// && event.getDelta().findMember(project.getFullPath()) != null)
-// {
-// wsMediator.runInWorkspaceJob(new HandleFileAddJob(event), "Context param update"); //$NON-NLS-1$
-// }
-// }
-// };
-
-// getWorkspace().addResourceChangeListener(_newFileListener);
}
- public List<IFile> getFiles()
+ @Override
+ public List<IFile> getResources()
{
return _webAppConfiguration.getFiles();
}
- public void initFiles()
+ @Override
+ public void initResources()
{
_webAppConfiguration.start();
_webAppConfiguration.addListener(new WebappListener()
@@ -90,7 +74,7 @@ class TaglibResourceManager extends
}
@Override
- protected TaglibResourceTracker createNewInstance(final IResource resource)
+ protected ResourceTracker createNewInstance(final IResource resource)
{
if (resource.getType() == IResource.FILE)
{
@@ -99,16 +83,6 @@ class TaglibResourceManager extends
throw new IllegalArgumentException();
}
- public void addListener(final IResourceLifecycleListener listener)
- {
- super.addLifecycleEventListener(listener);
- }
-
- public void removeListener(final IResourceLifecycleListener listener)
- {
- super.removeLifecycleEventListener(listener);
- }
-
/*
* (non-Javadoc)
*
@@ -120,7 +94,6 @@ class TaglibResourceManager extends
public void dispose()
{
_webAppConfiguration.dispose();
-// getWorkspace().removeResourceChangeListener(_newFileListener);
super.dispose();
}
} \ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceTracker.java b/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceTracker.java
deleted file mode 100644
index 2f43f2b2e..000000000
--- a/jsf/plugins/org.eclipse.jst.jsf.facelet.core/src/org/eclipse/jst/jsf/facelet/core/internal/registry/taglib/TaglibResourceTracker.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.eclipse.jst.jsf.facelet.core.internal.registry.taglib;
-
-import org.eclipse.jst.jsf.common.internal.managedobject.AbstractManagedObject;
-import org.eclipse.jst.jsf.common.internal.resource.IResourceLifecycleListener;
-import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent;
-
-/**
- * A managed object that tracks changes to a taglib resource.
- *
- * @author cbateman
- *
- */
-public class TaglibResourceTracker extends AbstractManagedObject implements
- IResourceLifecycleListener
-{
-
- public EventResult acceptEvent(ResourceLifecycleEvent event)
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void dispose()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void checkpoint()
- {
- // nothing currently persisted
-
- }
-
- @Override
- public void destroy()
- {
- // nothing currently persisted
- }
-
-}

Back to the top