diff options
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal')
86 files changed, 0 insertions, 9282 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/ITestTracker.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/ITestTracker.java deleted file mode 100644 index 259d90921..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/ITestTracker.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal; - -/** - * An injection interface that allows classes to selectively report test progress. - * - * @author cbateman - * - */ -public interface ITestTracker -{ - /** - * Event types - * - */ - public enum Event - { - /** - * Signals that tracking should begin on the eventLabel - * The seqId must be repeated on the STOP_TRACKING event - * for the same event. - */ - START_TRACKING, - /** - * Signals that tracking should stop on the named event - * for the seqId that was passed first in the START_TRACKING. - * - */ - STOP_TRACKING - } - - /** - * Fires the event of type event, a unique instance tracking seqId - * and a label called eventLabel. - * - * @param event - * @param seqId - * @param eventLabel - */ - void fireEvent(Event event, long seqId, String eventLabel); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/JSPUtil.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/JSPUtil.java deleted file mode 100644 index 37e7a9999..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/JSPUtil.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; - -/** - * Utility JSP methods - * @author cbateman - * - */ -public final class JSPUtil -{ - private final static String CTYPE_JSPSOURCE = - "org.eclipse.jst.jsp.core.jspsource"; //$NON-NLS-1$ - private final static String CTYPE_JSPFRAGMENTSOURCE = - "org.eclipse.jst.jsp.core.jspfragmentsource"; //$NON-NLS-1$ - /** - * @param contentType - * @return true if contentType is one of the content types registered - * for JSP files - */ - public static boolean isJSPContentType(final String contentType) - { - return CTYPE_JSPSOURCE.equals(contentType) - || CTYPE_JSPFRAGMENTSOURCE.equals(contentType); - } - - /** - * @param file - * @return true if file is associated with a JSP or JSP fragment content type - */ - public static boolean isJSPContentType(final IFile file) - { - final boolean isJSPSource = isJSPSource(file); - if (isJSPSource) - { - return true; - } - - final boolean isJSPFragment = isJSPFragment(file); - - if (isJSPFragment) - { - return true; - } - - return false; - } - - private JSPUtil() - { - // no instantiation - } - - /** - * @param file - * @return true if file is associated with the JSP source content type - * (returns if JSP fragment) - */ - public static boolean isJSPSource(IFile file) { - return isAssociatedWithContentType(file, CTYPE_JSPSOURCE); - } - - /** - * @param file - * @return true if the file is associated with the JSP fragment content type - */ - public static boolean isJSPFragment(IFile file) { - return isAssociatedWithContentType(file, CTYPE_JSPFRAGMENTSOURCE); - } - - private static boolean isAssociatedWithContentType(final IFile file, final String contentType) - { - final IContentTypeManager typeManager = Platform.getContentTypeManager(); - IContentType jspContentType = - typeManager.getContentType(contentType); - if (jspContentType != null - && jspContentType.isAssociatedWith(file.getName())) - { - return true; - } - - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/RunOnCompletionPattern.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/RunOnCompletionPattern.java deleted file mode 100644 index 6ae5a195a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/RunOnCompletionPattern.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * A pattern that runs a Job and either joins on the job's completion - * or runs some completion behaviour. - * - * @author cbateman - * - */ -public class RunOnCompletionPattern implements Runnable -{ - private final Job _job; - private final Runnable _runAfter; - - /** - * @param job - * @param runAfter - */ - public RunOnCompletionPattern(Job job, Runnable runAfter) - { - _job = job; - _runAfter = runAfter; - } - - public void run() - { - if (_runAfter != null) - { - _job.addJobChangeListener(new JobChangeAdapter() - { - - @Override - public void done(IJobChangeEvent event) - { - if (event.getResult().getSeverity() != IStatus.ERROR) - { - _runAfter.run(); - } - } - - }); - } - - _job.schedule(); - - if (_runAfter == null) - { - try - { - _job.join(); - } - catch (InterruptedException e) - { - JSFCommonPlugin.log(e, "Joining on job"); //$NON-NLS-1$ - } - } - } - - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/componentcore/AbstractVirtualComponentQuery.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/componentcore/AbstractVirtualComponentQuery.java deleted file mode 100644 index ae797b30f..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/componentcore/AbstractVirtualComponentQuery.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.componentcore; - -import org.eclipse.core.resources.IProject; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; - -/** - * Wraps parts of the component core in a way that always PDE-free injection - * during test. - * - * @author cbateman - * - */ -public abstract class AbstractVirtualComponentQuery -{ - /** - * TODO: reconcile with duplicate. This was taken from JSFAppConfigUtils. - * - * Gets an IVirtualFolder instance which represents the root context's web - * content folder. - * - * @param project - * IProject instance for which to get the folder. - * @return IVirtualFolder instance which represents the root context's web - * content folder. - */ - public abstract IVirtualFolder getWebContentFolder(IProject project); - - /** - * The default implementation that makes static calls to ComponentCore. - * @author cbateman - * - */ - public static class DefaultVirtualComponentQuery extends - AbstractVirtualComponentQuery - { - @Override - public IVirtualFolder getWebContentFolder(IProject project) - { - IVirtualFolder folder = null; - IVirtualComponent component = ComponentCore - .createComponent(project); - if (component != null) - { - folder = component.getRootFolder(); - } - return folder; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractFinder.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractFinder.java deleted file mode 100644 index 17411f4c9..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractFinder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder; - -import org.eclipse.jst.jsf.common.internal.strategy.AbstractIdentifiableStrategy; - - -/** - * An abstract strategy that finds it's OUTPUT value in a container designated - * by it's INPUT value. - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <IDTYPE> - */ -public abstract class AbstractFinder<INPUT, OUTPUT, IDTYPE> extends AbstractIdentifiableStrategy<INPUT, OUTPUT, IDTYPE> -{ - - /** - * @param id - * @param displayName - * @param noResultValue - */ - public AbstractFinder(IDTYPE id, String displayName, OUTPUT noResultValue) - { - super(id, displayName, noResultValue); - } - - /** - * @param input - * @return the output found in input or getNoResult() if not found. - * @throws Exception - */ - public final OUTPUT find(INPUT input) throws Exception - { - return perform(input); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractMatcher.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractMatcher.java deleted file mode 100644 index 4cd661b05..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/AbstractMatcher.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder; - -import java.util.Collections; -import java.util.List; - -/** - * A finder that finds it's OUTPUT in INPUT by using a matching strategy. - * @author cbateman - * @param <INPUT> - * @param <OUTPUT> - * @param <IDTYPE> - * - */ -public abstract class AbstractMatcher<INPUT, OUTPUT, IDTYPE> extends AbstractFinder<INPUT, OUTPUT, IDTYPE> -{ - private final List<? extends IMatcher> _matchers; - - /** - * An interface that defines a match. - * - */ - public interface IMatcher - { - /** - * @param matchThis - * @return true if T matches the expected critieria - */ - boolean matches(Object matchThis); - } - - /** - * A matcher that matches always. - * @author cbateman - * - */ - public static final class AlwaysMatcher implements IMatcher - { - public boolean matches(Object matchThis) - { - return true; - } - } - - /** - * @param id - * @param displayName - * @param noResultValue - * @param matchers - */ - public AbstractMatcher(final IDTYPE id, final String displayName, final OUTPUT noResultValue, final List<? extends IMatcher> matchers) - { - super(id, displayName, noResultValue); - _matchers = matchers; - } - - @Override - public abstract OUTPUT perform(INPUT input) throws Exception; - - /** - * @return the matchers - */ - protected final List<IMatcher> getMatchers() - { - return Collections.unmodifiableList(_matchers); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/VisitorMatcher.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/VisitorMatcher.java deleted file mode 100644 index 9182e7ee8..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/VisitorMatcher.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * A matcher finder that uses a visitor to traverse its INPUT and match values - * using its matchers. An optional value resolver can be used to get the - * matching value used. - * - * INPUT need not implement it's own visitation interface. Rather, an instance - * of MatchingVisitor must be provided to handle this. - * - * @author cbateman - * @param <INPUT> - * @param <VISITTYPE> - * @param <IDTYPE> - * - */ -public class VisitorMatcher<INPUT, VISITTYPE, IDTYPE> extends - AbstractMatcher<INPUT, Collection<? extends VISITTYPE>, IDTYPE> -{ - private final MatchingAcceptor _acceptor; - - /** - * @param id - * @param displayName - * @param acceptor - * @param matchers - */ - public VisitorMatcher(IDTYPE id, String displayName, - final MatchingAcceptor<INPUT, VISITTYPE> acceptor, - final List<? extends IMatcher> matchers) - { - super(id, displayName, Collections.EMPTY_LIST, matchers); - _acceptor = acceptor; - } - - @Override - public Collection<? extends VISITTYPE> perform(final INPUT input) throws Exception - { - MatchingVisitor visitor = new MatchingVisitor(getMatchers()); - _acceptor.accept(input, visitor); - return visitor.getFoundMatches(); - } - - /** - * Call visit on each VISITTYPE. Sub-classes must provide implementations of - * getInputChildren and getVisitableChildren to control what gets visited - * from the INPUT root. - * - * @param <INPUT> - * @param <VISITTYPE> - */ - public abstract static class MatchingAcceptor<INPUT, VISITTYPE> - { - private void accept(final INPUT input, - final MatchingVisitor<VISITTYPE> visitor) - { - final Collection<? extends VISITTYPE> inputChildren = getInputChildren(input); - accept(visitor, inputChildren); - } - - private void accept(final MatchingVisitor<VISITTYPE> visitor, - final Collection<? extends VISITTYPE> inputChildren) - { - for (final VISITTYPE visitable : inputChildren) - { - visitor.visit(visitable); - accept(visitor, getVisitableChildren(visitable)); - } - } - - /** - * @param inputType - * @return the first level children of INPUT to be visited. - */ - protected abstract Collection<? extends VISITTYPE> getInputChildren( - INPUT inputType); - - /** - * @param visitType - * @return the visitable children of visitType. - */ - protected abstract Collection<? extends VISITTYPE> getVisitableChildren( - VISITTYPE visitType); - } - - private static final class MatchingVisitor<VISITTYPE> - { - private final List<IMatcher> _matchers; - private final List<VISITTYPE> _foundMatches = new ArrayList<VISITTYPE>(); - public MatchingVisitor(final List<IMatcher> matcher) - { - _matchers = matcher; - } - - public void visit(final VISITTYPE visitable) - { - MATCH_LOOP: for (final IMatcher matcher : _matchers) - { - if (matcher.matches(visitable)) - { - _foundMatches.add(visitable); - break MATCH_LOOP; - } - } - } - - protected final List<VISITTYPE> getFoundMatches() - { - return _foundMatches; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/ClasspathEntryJarMatchingAcceptor.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/ClasspathEntryJarMatchingAcceptor.java deleted file mode 100644 index 855e4c78a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/ClasspathEntryJarMatchingAcceptor.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.acceptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher.MatchingAcceptor; -import org.eclipse.jst.jsf.common.internal.resource.ClasspathJarFile; - -/** - * Accepts all the jars underlying a classpath entry. - * - * @author cbateman - * - */ -public class ClasspathEntryJarMatchingAcceptor extends - MatchingAcceptor<IPackageFragmentRoot, ClasspathJarFile> -{ - private final IProject project; - - /** - * @param project - */ - public ClasspathEntryJarMatchingAcceptor(final IProject project) - { - super(); - this.project = project; - } - - @Override - protected Collection<? extends ClasspathJarFile> getInputChildren( - final IPackageFragmentRoot inputType) - { - final List<ClasspathJarFile> jarFiles = new ArrayList<ClasspathJarFile>(); - if (inputType.isArchive()) - { - jarFiles.add(new ClasspathJarFile(project, inputType.getPath())); - } - // if (inputType.exists()) - // { - // List<ClasspathJarFile> jarFiles = new ArrayList<ClasspathJarFile>(); - // switch (inputType.getEntryKind()) - // { - // // this entry describes a source root in its project - // case IClasspathEntry.CPE_SOURCE: - // break; - // // - this entry describes a folder or JAR containing - // // binaries - // case IClasspathEntry.CPE_LIBRARY: - // { - // jarFiles.add(new ClasspathJarFile(project, inputType)); - // } - // break; - // // - this entry describes another project - // case IClasspathEntry.CPE_PROJECT: - // // { - // // final IPath pathToProject = entry.getPath(); - // // IWorkspace wkspace = ResourcesPlugin.getWorkspace(); - // // IResource res = - // // wkspace.getRoot().findMember(pathToProject); - // // if (res instanceof IProject) - // // { - // // tagLibsFound.addAll(); - // // } - // // } - // break; - // // - this entry describes a project or library indirectly - // // via a - // // classpath variable in the first segment of the path * - // case IClasspathEntry.CPE_VARIABLE: - // break; - // // - this entry describes set of entries referenced - // // indirectly - // // via a classpath container - // case IClasspathEntry.CPE_CONTAINER: - // break; - // } - // } - return jarFiles; - } - - @Override - protected Collection<? extends ClasspathJarFile> getVisitableChildren( - final ClasspathJarFile visitType) - { - return Collections.EMPTY_LIST; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/FileMatchingAcceptor.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/FileMatchingAcceptor.java deleted file mode 100644 index 650e1748a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/FileMatchingAcceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.acceptor; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher.MatchingAcceptor; - -/** - * A matching acceptor that traverses all of the children of an IContainer. - * - * @author cbateman - * - */ -public class FileMatchingAcceptor extends MatchingAcceptor<IContainer, IResource> -{ - @Override - protected Collection<? extends IResource> getInputChildren( - final IContainer container) - { - IResource[] members = new IResource[0]; - try - { - members = container.members(); - } catch (CoreException e) - { - JSFCommonPlugin.log(e); - } - return Arrays.asList(members); - } - - @Override - protected Collection<? extends IResource> getVisitableChildren( - IResource visitType) - { - if (visitType instanceof IContainer) - { - return getInputChildren((IContainer)visitType); - } - return Collections.emptyList(); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarEntryMatchingAcceptor.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarEntryMatchingAcceptor.java deleted file mode 100644 index 79d03937a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarEntryMatchingAcceptor.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.acceptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher.MatchingAcceptor; - -/** - * An acceptor that gets the jar entries from a jar file. - * - * @author cbateman - * - */ -public class JarEntryMatchingAcceptor extends - MatchingAcceptor<JarFile, JarEntry> -{ - - @Override - protected Collection<? extends JarEntry> getInputChildren(JarFile inputType) - { - final List<JarEntry> children = new ArrayList<JarEntry>(); - Enumeration<JarEntry> entries = inputType.entries(); - while (entries.hasMoreElements()) - { - children.add(entries.nextElement()); - } - return children; - } - - @Override - protected Collection<? extends JarEntry> getVisitableChildren( - JarEntry visitType) - { - return Collections.EMPTY_LIST; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarMatchingAcceptor.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarMatchingAcceptor.java deleted file mode 100644 index 7742d75f7..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/acceptor/JarMatchingAcceptor.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.acceptor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -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.VisitorMatcher.MatchingAcceptor; -import org.eclipse.jst.jsf.common.internal.resource.ClasspathJarFile; -import org.eclipse.jst.jsf.common.internal.resource.JavaCoreMediator; - -/** - * A matching acceptor that provides the jars referenced by a project. - * - * @author cbateman - * - */ -public class JarMatchingAcceptor extends - MatchingAcceptor<IProject, ClasspathJarFile> -{ - private final JavaCoreMediator _javaCoreMediator; - - /** - * @param javaCoreMediator - */ - public JarMatchingAcceptor(final JavaCoreMediator javaCoreMediator) - { - _javaCoreMediator = javaCoreMediator; - } - - @Override - protected Collection<ClasspathJarFile> getInputChildren( - final IProject project) - { - final IJavaProject javaProject = _javaCoreMediator.create(project); - IPackageFragmentRoot[] roots = null; - try - { - roots = javaProject.getPackageFragmentRoots(); - } catch (final JavaModelException e1) - { - JSFCommonPlugin.log(e1); - } - if (roots == null || roots.length == 0) - { - return Collections.EMPTY_LIST; - } - final List<ClasspathJarFile> jars = new ArrayList<ClasspathJarFile>(); - VisitorMatcher<IPackageFragmentRoot, ClasspathJarFile, String> entryMatcher = new VisitorMatcher<IPackageFragmentRoot, ClasspathJarFile, String>( - "", "", new ClasspathEntryJarMatchingAcceptor(project), //$NON-NLS-1$ //$NON-NLS-2$ - Collections.singletonList(new AlwaysMatcher())); - for (final IPackageFragmentRoot root : roots) - { - try - { - jars.addAll(entryMatcher.perform(root)); - } catch (Exception e) - { - JSFCommonPlugin.log(e); - } - } - return jars; - } - - @Override - protected Collection<ClasspathJarFile> getVisitableChildren( - final ClasspathJarFile visitType) - { - return Collections.EMPTY_LIST; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibFinder.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibFinder.java deleted file mode 100644 index 0febe25b6..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibFinder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.matcher; - -import org.eclipse.jst.jsf.common.internal.strategy.AbstractIdentifiableStrategy; - - -/** - * A finder strategy for Facelet tag libraries. - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - */ -public abstract class TaglibFinder<INPUT, OUTPUT> extends AbstractIdentifiableStrategy<INPUT, OUTPUT, String> -{ - /** - * @param id - * @param displayName - * @param noResultValue - */ - public TaglibFinder(String id, String displayName, - OUTPUT noResultValue) - { - super(id, displayName, noResultValue); - } - - @Override - public abstract OUTPUT perform(INPUT input) throws Exception; -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibJarEntryFinder.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibJarEntryFinder.java deleted file mode 100644 index fb5c9616a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/finder/matcher/TaglibJarEntryFinder.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.finder.matcher; - -import java.util.jar.JarEntry; -import java.util.regex.Pattern; - -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.common.internal.finder.AbstractMatcher.IMatcher; - - -/** - * @author cbateman - * - */ -public class TaglibJarEntryFinder extends TaglibFinder<JarEntry, JarEntry> implements IMatcher -{ - /** - * Unique id of this strategy. - */ - public static final String ID = TaglibJarEntryFinder.class.getCanonicalName(); - private static final String DISPLAY_NAME = "Display Name"; //$NON-NLS-1$ - private final Pattern _pattern; - - /** - * @param pattern - */ - public TaglibJarEntryFinder(final Pattern pattern) - { - super(ID, DISPLAY_NAME, null); - _pattern = pattern; - } - - @Override - public JarEntry perform(JarEntry input) throws Exception - { - if (_pattern.matcher(input.getName()).matches()) - { - return input; - } - return getNoResult(); - } - - public boolean matches(Object matchThis) - { - if (matchThis instanceof JarEntry) - { - try - { - return perform((JarEntry) matchThis) != getNoResult(); - } catch (Exception e) - { - JSFCommonPlugin.log(e, "While matching jar entry: "+matchThis); //$NON-NLS-1$ - } - } - return false; - } -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocator.java deleted file mode 100644 index 409c744dd..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocator.java +++ /dev/null @@ -1,177 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.concurrent.CopyOnWriteArrayList; - -import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener.LocatorChangeEvent; - -/** - * The abstract base class of all ILocator implementations. - * - * @author cbateman - * - * @param <LOCATORTYPE> - * @param <CONTEXTTYPE> - * @param <IDTYPE> - */ -public abstract class AbstractLocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> - implements ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> -{ - /** - * The default value used for "no result". - */ - protected static final Object DEFAULT_NO_RESULT_VALUE = null; - - private final CopyOnWriteArrayList<ILocatorChangeListener> _listeners; - private final LOCATORTYPE _noResultValue; - private final IDTYPE _id; - private final String _displayName; - private boolean _isStarted; - - private Exception _startTrace; - - /** - * Available for sub-classes that want to use reasonable defaults and only provide - * mandatory data. - * - * No result value is null. - * A new instance of CopyOnWriteArrayList is used and held private. - * - * @param id - * @param displayName - * - */ - public AbstractLocator(final IDTYPE id, final String displayName) - { - this(id, - displayName, - null, - new CopyOnWriteArrayList<ILocatorChangeListener>()); - } - - /** - * Available for sub-classes to manually inject dependencies. - * - * @param id - * @param displayName - * @param noResultValue - * @param mutableListenerList - */ - protected AbstractLocator( - final IDTYPE id, - final String displayName, - final LOCATORTYPE noResultValue, - final CopyOnWriteArrayList<ILocatorChangeListener> mutableListenerList) - { - _id = id; - _displayName = displayName; - _listeners = mutableListenerList; - _noResultValue = noResultValue; - } - - public final LOCATORTYPE perform(final CONTEXTTYPE context) - throws Exception - { - return locate(context); - } - - public LOCATORTYPE getNoResult() - { - return _noResultValue; - } - - public IDTYPE getId() - { - return _id; - } - - public String getDisplayName() - { - return _displayName; - } - - public LOCATORTYPE locate(final CONTEXTTYPE context) - { - if (isStarted()) - { - return doLocate(context); - } - throw new IllegalStateException("Locator not started"); //$NON-NLS-1$ - } - - - /** - * @param context - * @return the located type. - */ - protected abstract LOCATORTYPE doLocate(CONTEXTTYPE context); - - public void start(final CONTEXTTYPE initialContext) - { - if (isStarted()) - { - throw new IllegalStateException("Locator was already started", _startTrace); //$NON-NLS-1$ - } - - // set the started flag - setStarted(true); - _startTrace = new Exception("Locator was started on this trace"); //$NON-NLS-1$ - } - - public void stop() - { - // set the started flag - // clear all listeners - _listeners.clear(); - setStarted(false); - _startTrace = null; - } - - /** - * @param listener - */ - public void addListener(final ILocatorChangeListener listener) - { - _listeners.addIfAbsent(listener); - } - - /** - * @param listener - */ - public void removeListener(final ILocatorChangeListener listener) - { - _listeners.remove(listener); - } - - /** - * @param event - */ - protected void fireChangeEvent(final LocatorChangeEvent event) - { - for (final ILocatorChangeListener listener : _listeners) - { - listener.changed(event); - } - } - - public final boolean isStarted() - { - return _isStarted; - } - - public boolean canStart() - { - if (isStarted()) - { - return false; - } - return true; - } - - /** - * @param newValue - */ - protected final void setStarted(final boolean newValue) - { - _isStarted = newValue; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocatorProvider.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocatorProvider.java deleted file mode 100644 index edd77dc23..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/AbstractLocatorProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.Collections; -import java.util.List; - -/** - * The super-class of all ILocatorProvider's. - * - * @author cbateman - * @param <LOCATORTYPE> - * - */ -public abstract class AbstractLocatorProvider<LOCATORTYPE> implements ILocatorProvider<LOCATORTYPE> -{ - private boolean _isInit = false; - - public void initialize() - { - doInitialize(); - _isInit = true; - } - - /** - * Overrride to do the init. You can override initialize if you want to - */ - protected abstract void doInitialize(); - - public List<? extends LOCATORTYPE> getLocators() - { - if (!_isInit) - { - throw new IllegalStateException( - "initialize must be called before getLocators"); //$NON-NLS-1$ - } - return doGetLocators(); - } - - /** - * @return the locators. - */ - protected abstract List<? extends LOCATORTYPE> doGetLocators(); - - /** - * A default implementation of the provider that simply sits on a list - * of a locators. - * - * @param <LOCATORTYPE> - */ - public static class DefaultLocatorProvider<LOCATORTYPE> extends AbstractLocatorProvider<LOCATORTYPE> - { - private final List<LOCATORTYPE> _locators; - - /** - * @param locators - */ - public DefaultLocatorProvider(List<LOCATORTYPE> locators) - { - _locators = locators; - } - @Override - protected void doInitialize() - { - // nothing to do. - } - - @Override - protected List<? extends LOCATORTYPE> doGetLocators() - { - return Collections.unmodifiableList(_locators); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/CompositeLocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/CompositeLocator.java deleted file mode 100644 index 65658e89d..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/CompositeLocator.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.Iterator; - -import org.eclipse.jst.jsf.common.internal.policy.IIteratorPolicy; -import org.eclipse.jst.jsf.common.internal.strategy.IteratorPolicyBasedStrategyComposite; - -/** - * @author cbateman - * - * @param <LOCATORTYPE> - * @param <COMPOSITETYPE> - * @param <CONTEXTTYPE> - * @param <IDTYPE> - */ -public abstract class CompositeLocator<LOCATORTYPE, COMPOSITETYPE, CONTEXTTYPE, IDTYPE> extends -IteratorPolicyBasedStrategyComposite<CONTEXTTYPE, LOCATORTYPE, COMPOSITETYPE, IDTYPE, ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE>> -implements ILocator<COMPOSITETYPE, CONTEXTTYPE, IDTYPE>, ILocatorChangeListener -{ - private DefaultComposingLocatorDelegate<LOCATORTYPE, COMPOSITETYPE, CONTEXTTYPE, IDTYPE> _delegate; - private final COMPOSITETYPE _noResultValue; - - /** - * @param id - * @param displayName - * @param policy - * @param noResultValue - * @param compositionStrategy - */ - public CompositeLocator( - final IDTYPE id, - final String displayName, - final IIteratorPolicy<IDTYPE> policy, - final COMPOSITETYPE noResultValue, - final DefaultCompositionStrategy<CONTEXTTYPE, LOCATORTYPE, COMPOSITETYPE, ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE>> compositionStrategy) - { - super(policy, compositionStrategy); - _delegate = new DefaultComposingLocatorDelegate<LOCATORTYPE, COMPOSITETYPE, CONTEXTTYPE, IDTYPE>(id, displayName) - { - @Override - protected COMPOSITETYPE doLocate(final CONTEXTTYPE context) - { - return CompositeLocator.this.doLocate(context); - } - }; - _noResultValue = noResultValue; - } - - /** - * @param context - * @return the located value. - */ - protected abstract COMPOSITETYPE doLocate(CONTEXTTYPE context); - - public final IDTYPE getId() - { - return _delegate.getId(); - } - - public String getDisplayName() - { - return _delegate.getDisplayName(); - } - - public void start(final CONTEXTTYPE initialContext) - { - if (canStart()) - { - final Iterator<ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE>> iterator = getIterator(); - while (iterator.hasNext()) - { - - final ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> next = iterator.next(); - next.addListener(this); - next.start(initialContext); - } - _delegate.start(initialContext); - } - throw new IllegalStateException("canStart must be called before calling start"); //$NON-NLS-1$ - } - - public boolean canStart() - { - boolean canStart = true; - final Iterator<ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE>> iterator = getIterator(); - while (canStart && iterator.hasNext()) - { - canStart &= iterator.next().canStart(); - } - - return canStart && _delegate.canStart(); - } - - public boolean isStarted() - { - return _delegate.isStarted(); - } - - public void stop() - { - if (!isStarted()) - { - final Iterator<ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE>> iterator = getIterator(); - while (iterator.hasNext()) - { - final ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> next = iterator.next(); - next.removeListener(this); - next.stop(); - } - - _delegate.stop(); - } - } - - public COMPOSITETYPE locate(final CONTEXTTYPE context) - { - return _delegate.locate(context); - } - - @Override - public COMPOSITETYPE getNoResult() - { - return _noResultValue; - } - - - public void changed(final LocatorChangeEvent event) - { - _delegate.fireChangeEvent(event); - } - - - public void addListener(final ILocatorChangeListener listener) - { - _delegate.addListener(listener); - } - - - public void removeListener(final ILocatorChangeListener listener) - { - _delegate.removeListener(listener); - } - - /** - * Re-fire events from composed strategies. - * - * @param event - */ - protected void fireChangeEvent(final LocatorChangeEvent event) - { - _delegate.fireChangeEvent(event); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultComposingLocatorDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultComposingLocatorDelegate.java deleted file mode 100644 index ac698d342..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultComposingLocatorDelegate.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * Default delegatable locator for composing locators. - * - * @author cbateman - * - * @param <LOCATORTYPE> - * @param <COMPOSITETYPE> - * @param <CONTEXTTYPE> - * @param <IDTYPE> - */ -public class DefaultComposingLocatorDelegate<LOCATORTYPE, COMPOSITETYPE, CONTEXTTYPE, IDTYPE> extends - AbstractLocator<COMPOSITETYPE, CONTEXTTYPE, IDTYPE> -{ - - /** - * @param id - * @param displayName - */ - public DefaultComposingLocatorDelegate(IDTYPE id, String displayName) - { - super(id, displayName); - } - - - /** - * @param id - * @param displayName - * @param noResultValue - * @param mutableListenerList - */ - public DefaultComposingLocatorDelegate( - IDTYPE id, - String displayName, - COMPOSITETYPE noResultValue, - CopyOnWriteArrayList<ILocatorChangeListener> mutableListenerList) - { - super(id, displayName, noResultValue, mutableListenerList); - } - - - @Override - protected COMPOSITETYPE doLocate(CONTEXTTYPE context) - { - throw new UnsupportedOperationException("This method is abstract and should not be called"); //$NON-NLS-1$ - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultLocatorDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultLocatorDelegate.java deleted file mode 100644 index 04d8fdb90..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/DefaultLocatorDelegate.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * Implements the bare minimum of AbstractLocator needed to treat it as a - * sub-class by composition (delegation). - * - * @author cbateman - * @param <LOCATORTYPE> - * @param <CONTEXTTYPE> - * @param <IDTYPE> - * - */ -public class DefaultLocatorDelegate<LOCATORTYPE, CONTEXTTYPE, IDTYPE> extends - AbstractLocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> -{ - - /** - * @param id - * @param displayName - */ - public DefaultLocatorDelegate(IDTYPE id, String displayName) - { - super(id, displayName); - } - - - /** - * @param id - * @param displayName - * @param noResultValue - * @param mutableListenerList - */ - public DefaultLocatorDelegate( - IDTYPE id, - String displayName, - LOCATORTYPE noResultValue, - CopyOnWriteArrayList<ILocatorChangeListener> mutableListenerList) - { - super(id, displayName, noResultValue, mutableListenerList); - } - - - @Override - protected LOCATORTYPE doLocate(CONTEXTTYPE context) - { - throw new UnsupportedOperationException("This method is abstract and should not be called"); //$NON-NLS-1$ - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocator.java deleted file mode 100644 index abf6bade9..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocator.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import org.eclipse.jst.jsf.common.internal.strategy.IIdentifiableStrategy; - -/** - * A generic location strategy object. - * - * @author cbateman - * - * @param <LOCATORTYPE> - * the type of object being returned by the locator - * @param <CONTEXTTYPE> - * the type of the context object passed for starting and locating - * @param <IDTYPE> - * the type of the id used to identify a locator - * @noimplement extend AbstractLocator instead - */ -public interface ILocator<LOCATORTYPE, CONTEXTTYPE, IDTYPE> extends - IIdentifiableStrategy<CONTEXTTYPE, LOCATORTYPE, IDTYPE> -{ - /** - * Initialize the locator optionally using initialContext. - * - * Must be called before any other methods. Implementations should throw - * IllegalStateException if this has not been called before anything else. - * - * @param initialContext - */ - void start(CONTEXTTYPE initialContext); - - /** - * Implementations should return false if the system prevents them from - * starting. It must also be checked before a client attempts to restart a - * stopped locator. Must return false if isStarted is true. - * - * @return true if the locator can be started - */ - boolean canStart(); - - /** - * @return true if the start() has been called but stop has not yet been - * called. - */ - boolean isStarted(); - - /** - * Stop the locator. - */ - void stop(); - - /** - * @param listener - */ - void addListener( final ILocatorChangeListener listener); - - /** - * @param listener - */ - void removeListener(final ILocatorChangeListener listener); - - /** - * perform must call this method in any concrete implementation. - * - * @param context - * @return the located type. - */ - LOCATORTYPE locate(CONTEXTTYPE context); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorChangeListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorChangeListener.java deleted file mode 100644 index 0b996dffa..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorChangeListener.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.EventListener; -import java.util.EventObject; - -/** - * @author cbateman - * - */ -public interface ILocatorChangeListener extends EventListener -{ - /** - * @param event - */ - public void changed(final LocatorChangeEvent event); - - /** - * @author cbateman - * - */ - public static class LocatorChangeEvent extends EventObject - { - /** - * @param source - */ - public LocatorChangeEvent(ILocator source) { - super(source); - } - - @Override - public ILocator getSource() { - return (ILocator) super.getSource(); - } - - /** - * - */ - private static final long serialVersionUID = -7930804700395142768L; - - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorProvider.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorProvider.java deleted file mode 100644 index 57472ad8e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/locator/ILocatorProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.locator; - -import java.util.List; - -/** - * An object that provides zero or more locators to a client. - * - * @author cbateman - * @param <LOCATORTYPE> - * - */ -public interface ILocatorProvider<LOCATORTYPE> -{ - /** - * Must be called before getLocators is called. Implementations MUST - * support multiple calls to initialize on the same instance but need not - * do anything on any of them. - */ - void initialize(); - - /** - * @return the list of locators. - */ - List<? extends LOCATORTYPE> getLocators(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/AbstractManagedObject.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/AbstractManagedObject.java deleted file mode 100644 index 9138f0e35..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/AbstractManagedObject.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.managedobject; - -import java.util.concurrent.atomic.AtomicBoolean; - - -/** - * Sub-class for managed objects. - * - */ -/** - * @author cbateman - * - */ -public abstract class AbstractManagedObject implements IManagedObject -{ - /** - * Flag for checking disposal. - */ - protected final AtomicBoolean _isDisposed = new AtomicBoolean(false); - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jst.jsf.common.internal.managedobject.IManagedObject#dispose - * () - */ - public void dispose() - { - _isDisposed.set(true); - } - - public boolean isDisposed() - { - return _isDisposed.get(); - } - - /** - * Checks if this object is disposed and throws IllegalStateException if it - * is. - */ - protected final void assertNotDisposed() - { - if (isDisposed()) - { - throw new IllegalStateException(this.toString() + " is disposed"); //$NON-NLS-1$ - } - } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jst.jsf.common.internal.managedobject.IManagedObject#checkpoint - * () - */ - public abstract void checkpoint(); - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jst.jsf.common.internal.managedobject.IManagedObject#destroy - * () - */ - public abstract void destroy(); - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/IManagedObject.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/IManagedObject.java deleted file mode 100644 index 2c43679c9..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/IManagedObject.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.managedobject; - -/** - * Represents an object that wishes to be managed by the framework. - * - * Clients should not implement: sub-class AbstractManagedObject instead. - * - */ -public interface IManagedObject -{ - /** - * Called by the object client to indicate is finished with the object. The - * object should save any data it may want between sessions, perhaps by - * calling its checkpoint, before cleaning held resources and clearing - * memory references. - */ - void dispose(); - - /** - * @return true if dispose has been successfully called on the object. - */ - boolean isDisposed(); - - /** - * Called to indicate that the object should remove all its data from both - * memory and persistent storage. This differentiates it from dispose in - * that it signals that this object and its associated state will never - * again be loaded for associated objects. - */ - void destroy(); - - /** - * Indicates that an object should flush cached data and make durable any - * data it might want between sessions. It does not indicate a disposal of - * the object. - */ - void checkpoint(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/ObjectManager.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/ObjectManager.java deleted file mode 100644 index 569517099..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/managedobject/ObjectManager.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.managedobject; - - -/** - * An abstraction for a manager that manages managed objects based on a KEYTYPE - * - * @author cbateman - * - * @param <T> - * @param <KEYTYPE> - */ -public abstract class ObjectManager<T extends IManagedObject, KEYTYPE> extends - AbstractManagedObject -{ - - /** - * A valid instance of T for the key. The instance of T may be unique on a - * per-key basis or may not. - * - * @param key - * @return an instance of the managed object associated with key - * @throws ManagedObjectException - * if an error occurs during construction - */ - public abstract T getInstance(KEYTYPE key) throws ManagedObjectException; - - @Override - public abstract void destroy(); - - @Override - public abstract void checkpoint(); - - @Override - public abstract void dispose(); - - /** - * Indicates a problem that occurred during a managed object operation - * - * @author cbateman - * - */ - public static class ManagedObjectException extends Exception - { - /** - * - */ - private static final long serialVersionUID = -8723548990029368844L; - - /** - * - */ - public ManagedObjectException() - { - super(); - } - - /** - * @param message - * @param cause - */ - public ManagedObjectException(final String message, final Throwable cause) - { - super(message, cause); - } - - /** - * @param message - */ - public ManagedObjectException(final String message) - { - super(message); - } - - /** - * @param cause - */ - public ManagedObjectException(final Throwable cause) - { - super(cause); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java deleted file mode 100644 index 64677fe62..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractRegistryReader.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.pde; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * A utility base class that simplifies the reading and caching of extension - * point information. - * - * @author cbateman - * @param <T> - * - */ -public abstract class AbstractRegistryReader<T> -{ - private final String _extPtNamespace; - private final String _extPtId; - private List<T> _extensions; - private final AtomicBoolean _isInitialized = new AtomicBoolean(false); - - /** - * @param extPtNamespace - * @param extPtId - */ - protected AbstractRegistryReader(final String extPtNamespace, - final String extPtId) - { - _extPtNamespace = extPtNamespace; - _extPtId = extPtId; - } - - /** - * @return the extensions - */ - public final List<T> getExtensions() - { - synchronized (_isInitialized) - { - if (_isInitialized.compareAndSet(false, true)) - { - SafeRunner.run(new ISafeRunnable() - { - public void run() throws Exception - { - initialize(); - } - - public void handleException(Throwable exception) - { - // This is expected during testing if there running as JUnit test (non-plugin) - JSFCommonPlugin.log(exception, "Loading extension point"); //$NON-NLS-1$ - } - }); - } - return _extensions; - } - } - - /** - * @param extensions - */ - protected final void internalSetExtensions(List<T> extensions) - { - if (_extensions != null) - { - throw new IllegalStateException( - "internalSetExtensions should be called exactly once"); //$NON-NLS-1$ - } - _extensions = Collections.unmodifiableList(extensions); - } - - /** - * Called exactly once to initialize the registry. - */ - protected abstract void initialize(); - - /** - * @return the extension point id. see IConfigurationElement.getName - */ - protected final String getExtPtId() - { - return _extPtId; - } - - /** - * @return the namespace of the extension point. see Bundle.getSymbolicName - */ - protected final String getExtPtNamespace() - { - return _extPtNamespace; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java deleted file mode 100644 index 288d1d2e0..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/pde/AbstractSimpleClassExtensionRegistryReader.java +++ /dev/null @@ -1,265 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.pde; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * @author cbateman - * @param <T> - * - */ -public abstract class AbstractSimpleClassExtensionRegistryReader<T> extends - AbstractRegistryReader<T> -{ - /** - * Indicates no sorting of extension. - */ - protected final static Comparator NO_SORT = null; - - private final String _attributeName; - private final String _configElementName; - private final Comparator<SortableExecutableExtension<T>> _comparator; - - private boolean _logWarnings = false; - - /** - * @param extPtNamespace - * @param extPtId - * @param configElementName - * @param attributeName - * @param listComparator - * May be null if no sorting of the extensions list is required. - */ - protected AbstractSimpleClassExtensionRegistryReader( - final String extPtNamespace, final String extPtId, - final String configElementName, final String attributeName, - final Comparator<SortableExecutableExtension<T>> listComparator) - { - super(extPtNamespace, extPtId); - _configElementName = configElementName; - _attributeName = attributeName; - _comparator = listComparator; - } - - @Override - protected final void initialize() - { - final List<SortableExecutableExtension<T>> result = new ArrayList<SortableExecutableExtension<T>>(); - final IExtensionPoint extensionPoint = Platform.getExtensionRegistry() - .getExtensionPoint(getExtPtNamespace(), getExtPtId()); - if (extensionPoint == null) - { - return; - } - IExtension[] extensions = extensionPoint.getExtensions(); - for (int i = 0; i < extensions.length; i++) - { - IExtension ext = extensions[i]; - IConfigurationElement[] tagConverter = ext - .getConfigurationElements(); - - for (int j = 0; j < tagConverter.length; j++) - { - final IConfigurationElement element = tagConverter[j]; - - if (element.getName().equals(_configElementName)) - { - element.getAttribute(_attributeName); - try - { - final T obj = (T) element - .createExecutableExtension(_attributeName); - result.add(new SortableExecutableExtension<T>( - _comparator, element.getContributor().getName(), - obj)); - } catch (ClassCastException ce) - { - handleLoadFailure(new CoreException(new Status( - IStatus.ERROR, JSFCommonPlugin.PLUGIN_ID, - "Extension class is not the expected type", ce))); //$NON-NLS-1$ - } catch (CoreException e) - { - handleLoadFailure(e); - } - } - } - } - - if (result.size() > 0) - { - if (_comparator != NO_SORT) - { - Collections.sort(result, _comparator); - } - } else if (_logWarnings) - { - JSFCommonPlugin.log(IStatus.WARNING, String.format( - "No extensions found for: %s.%s", //$NON-NLS-1$ - getExtPtNamespace(), getExtPtId())); - } - final List<T> finalExtensions = new ArrayList<T>(); - for (final SortableExecutableExtension<T> sortable : result) - { - finalExtensions.add(sortable.getExtensionObject()); - } - internalSetExtensions(finalExtensions); - } - - /** - * Called by initialize when an error occurs trying to load a class from an - * extension point. Sub-class should implement to handle the failure, - * typically to log it using their bundle id. - * - * @param ce - */ - protected abstract void handleLoadFailure(final CoreException ce); - - /** - * @param doLogWarnings - */ - protected void logWarnings(final boolean doLogWarnings) { - _logWarnings = doLogWarnings; - } - - /** - * A comparator that sorts canonically by extension namespace and id, but - * can make exceptions for certain prefices. - * - * @param <T> - * - */ - protected abstract static class CanonicalComparatorWithPrefixExceptions<T> - implements Comparator<SortableExecutableExtension<T>> - { - - public int compare(SortableExecutableExtension<T> o1, - SortableExecutableExtension<T> o2) - { - int result = prefixSort(o1, o2); - - // if the prefix sort doesn't distinguish a sort order, then - // compare it canonically - if (result == 0) - { - result = o1.getContributorId().compareTo(o2.getContributorId()); - } - - return result; - } - - /** - * @param o1 - * @param o2 - * @return -1 if o1 should sort before o2 based on prefix. 1 if o2 - * should sort before o1 or 0 if there is sort preference based - * on prefix. - */ - protected abstract int prefixSort(SortableExecutableExtension<T> o1, - SortableExecutableExtension<T> o2); - } - - /** - * Ensures that contributions from "org.eclipse.jst" plugins are sorted last - * - * @param <T> - */ - public static class CompareOrgEclipseJstContributorsLastComparator<T> extends CanonicalComparatorWithPrefixExceptions<T> { - @Override - protected int prefixSort( - SortableExecutableExtension<T> o1, - SortableExecutableExtension<T> o2) - { - // if o1 is contributed by open source, sort it - // after - if (o1.getContributorId().startsWith("org.eclipse.jst")) //$NON-NLS-1$ - { - return 1; - } - // if o2 is contributed by open source, sort o1 first - else if (o2.getContributorId().startsWith("org.eclipse.jst")) //$NON-NLS-1$ - { - return -1; - } - // otherwise, we don't care - return 0; - } - - } - /** - * Used to sort extensions before locking down the list. - * - * @param <T> - */ - protected final static class SortableExecutableExtension<T> implements - Comparable<SortableExecutableExtension> - { - private final Comparator _comparator; - private final String _contributorId; - private final T _extensionObject; - - private SortableExecutableExtension(final Comparator comparator, - final String contributorId, final T extensionObject) - { - if (comparator == null) - { - _comparator = new Comparator<T>() - { - public int compare(T o1, T o2) - { - // always return equal. - return 0; - } - }; - } else - { - _comparator = comparator; - } - _contributorId = contributorId; - _extensionObject = extensionObject; - } - - public int compareTo(SortableExecutableExtension o) - { - return _comparator.compare(this, o); - } - - @Override - public boolean equals(Object obj) - { - return _comparator.compare(this, obj) == 0; - } - - @Override - public int hashCode() - { - return _contributorId.hashCode() ^ _extensionObject.hashCode(); - } - - /** - * @return the id of the bundle that contributed this extension - */ - public String getContributorId() - { - return _contributorId; - } - - /** - * @return the extension object - */ - public T getExtensionObject() - { - return _extensionObject; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/CanonicallyOrderedIteratorPolicy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/CanonicallyOrderedIteratorPolicy.java deleted file mode 100644 index 24ba27d82..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/CanonicallyOrderedIteratorPolicy.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.policy; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * An iterator policy that sorts a comparable iterator type canonically. This - * policy takes a private copy of the collectin passed in getIterator. The - * cost of the sort is incurred when getIterator() is called under the - * assumption that the iterator will normally be used immediately after - * construction, so there is little value in deferring. - * - * @author cbateman - * - * @param <ITERATORTYPE> - */ -public class CanonicallyOrderedIteratorPolicy<ITERATORTYPE extends Comparable<ITERATORTYPE>> - implements IIteratorPolicy<ITERATORTYPE> -{ - - public Iterator<ITERATORTYPE> getIterator( - Collection<ITERATORTYPE> forCollection) - { - return new CanonicalIterator<ITERATORTYPE>(forCollection); - } - - private final static class CanonicalIterator<ITERATORTYPE extends Comparable> implements Iterator<ITERATORTYPE> - { - private final Iterator<ITERATORTYPE> _sortedIterator; - private CanonicalIterator(final Collection<ITERATORTYPE> source) - { - List<ITERATORTYPE> sortable = new ArrayList<ITERATORTYPE>(source); - Collections.sort(sortable); - _sortedIterator = sortable.iterator(); - } - - public boolean hasNext() - { - return _sortedIterator.hasNext(); - } - - public ITERATORTYPE next() - { - return _sortedIterator.next(); - } - public void remove() - { - throw new UnsupportedOperationException(); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIdentifiable.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIdentifiable.java deleted file mode 100644 index 6e6368def..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIdentifiable.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.policy; - -/** - * An object with an unique identity - * @author cbateman - * @param <IDTYPE> - * - */ -public interface IIdentifiable<IDTYPE> -{ - /** - * @return the unique identifier - */ - IDTYPE getId(); - - /** - * @return a human-readable name for this identifier. - */ - String getDisplayName(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIteratorPolicy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIteratorPolicy.java deleted file mode 100644 index 6b567f368..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IIteratorPolicy.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.policy; - -import java.util.Collection; -import java.util.Iterator; - -/** - * A policy that allows a strategy composite to change the order in which - * it queries it's list of strategies. - * - * @author cbateman - * @param <ITERATORTYPE> - * - */ -public interface IIteratorPolicy<ITERATORTYPE> -{ - /** - * @param forCollection - * @return an iterator that controls the ordering through forCollection - * in a policy directed way. The policy may take a copy of the collection - * or may choose to iterate in place. - */ - Iterator<ITERATORTYPE> getIterator(Collection<ITERATORTYPE> forCollection); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IdentifierOrderedIteratorPolicy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IdentifierOrderedIteratorPolicy.java deleted file mode 100644 index a566af0c7..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/IdentifierOrderedIteratorPolicy.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.policy; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -/** - * An iterator policy that creates Iterators that traverse a target collection - * by returning items in the order they are in the policyOrder object pased at - * construction. The target collection passed to getIterator is copied, so the - * iterator will not be effected by subsequent changes to the target. - * - * NOTE: the policyOrder iterable collection should not be modified after it is - * passed to the constructor. - * - * The class is thread-safe, however the iterators are not. That is, more than - * one thread can safely call any of the public methods, however each Iterator - * returned by getIterator can only be used safely by a single thread. - * - * @author cbateman - * - * @param <ITERATORTYPE> - */ -public class IdentifierOrderedIteratorPolicy<ITERATORTYPE> implements - IIteratorPolicy<ITERATORTYPE> -{ - private final Iterable<ITERATORTYPE> _policyOrder; - // controls whether the policy iterator will return items that are - // not explicitly listed in policyOrder. - private volatile boolean _excludeNonExplicitValues = false; - - /** - * @param policyOrder - */ - public IdentifierOrderedIteratorPolicy(final Iterable<ITERATORTYPE> policyOrder) - { - _policyOrder = policyOrder; - } - - /** - * Default value is <b>false</b>. - * - * @return if true, the iterator will not return values in the forCollection - * passed to getIterator whose identifier are not explicitly listed in - * the policyOrder, If false, these values will be return after all - * the policyOrder values have been returned. - */ - public boolean isExcludeNonExplicitValues() - { - return _excludeNonExplicitValues; - } - - /** - * @param excludeNonExplicitValues - */ - public void setExcludeNonExplicitValues(boolean excludeNonExplicitValues) - { - _excludeNonExplicitValues = excludeNonExplicitValues; - } - - public Iterator<ITERATORTYPE> getIterator( - final Collection<ITERATORTYPE> forCollection) - { - final boolean excludeNonExplicitValues = _excludeNonExplicitValues; - return new MyIterator<ITERATORTYPE>(forCollection, excludeNonExplicitValues, _policyOrder); - } - - private static class MyIterator<ITERATORTYPE> implements Iterator<ITERATORTYPE> - { - private final List<ITERATORTYPE> _items; - private final Iterator<ITERATORTYPE> _policyIterator; - private ITERATORTYPE _next; - - MyIterator(final Collection<ITERATORTYPE> collection, - final boolean excludeNonExplicitValues, - final Iterable<ITERATORTYPE> policyOrder) - { - _items = new ArrayList(); - _items.addAll(collection); - - _policyIterator = policyOrder.iterator(); - _next = findNext(); - } - - public boolean hasNext() - { - return _next != null; - } - - public ITERATORTYPE next() - { - if (_next != null) - { - ITERATORTYPE next = _next; - //calculate next one before returning - _next = findNext(); - return next; - } - - throw new NoSuchElementException("No more elements"); //$NON-NLS-1$ - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - - private ITERATORTYPE findNext() - { - while (_policyIterator.hasNext()) - { - ITERATORTYPE next = _policyIterator.next(); - if (_items.contains(next)) - { - _items.remove(next); - return next; - } - } - - // we have exhausted the _items that are in the policy iterator - // now return any further _items in the order they are in the list - if (_items.size() > 0) - { - return _items.remove(0); - } - - return null; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/OrderedListProvider.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/OrderedListProvider.java deleted file mode 100644 index 75407553e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/policy/OrderedListProvider.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.policy; - -import java.util.List; - -/** - * Provides a list of order, enablement-modifiable objects. - * - * @author cbateman - * - */ -public abstract class OrderedListProvider -{ - private List<OrderableObject> _orderableObjects; - - /** - * - * @return the list of ordered objects - */ - public final List<OrderableObject> getOrderedObjects() - { - if (_orderableObjects == null) - { - _orderableObjects = createAndPopulateOrderedObjects(); - } - return _orderableObjects; - } - - /** - * <p>Clears the orderableObjects collection so that the next call - * of getOrderedObjects() </p> - */ - public final void resetOrderedObjects() - { - _orderableObjects = null; - } - - /** - * Move the object one toward the front of the list - * - * @param object - */ - public final void moveUp(final OrderableObject object) - { - final List<OrderableObject> list = getOrderedObjects(); - final int index = list.indexOf(object); - if (index > 0) - { - OrderableObject item = list.remove(index); - list.add(index - 1, item); - } - } - - /** - * Move the object one toward the end - * @param object - */ - public final void moveDown(final OrderableObject object) - { - final List<OrderableObject> list = getOrderedObjects(); - int index = list.indexOf(object); - if (index < list.size() - 1) - { - OrderableObject item = list.remove(index); - list.add(index + 1, item); - } - } - - /** - * @return a new list orderable objects populate in their initial order - * The list must be modifiable. - */ - protected abstract List<OrderableObject> createAndPopulateOrderedObjects(); - - /** - * Proxy object for ordering in list - * - * @author cbateman - * - */ - public static class OrderableObject implements Cloneable - { - private boolean _enabled; - private Object _object; - - /** - * @param object - * @param enabled - */ - public OrderableObject(final Object object, final boolean enabled) - { - _object = object; - _enabled = enabled; - } - - private OrderableObject(final OrderableObject copyMe) - { - _object = copyMe._object; - _enabled = copyMe._enabled; - } - - /** - * @return true if this object is enabled - */ - public boolean isEnabled() - { - return _enabled; - } - - /** - * @param enabled - */ - public void setEnabled(boolean enabled) - { - _enabled = enabled; - } - - /** - * @return the object in the ordered list - */ - public Object getObject() - { - return _object; - } - - /** - * @param object - */ - public void setObject(Object object) - { - _object = object; - } - - @Override - public OrderableObject clone() - { - return new OrderableObject(this); - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof OrderableObject) - { - if (_enabled == ((OrderableObject)obj)._enabled) - { - Object other = ((OrderableObject)obj)._object; - if (other != null) - { - return other.equals(_object); - } - return _object == null; - } - } - return false; - } - - @Override - public int hashCode() - { - int enabledCode = _enabled ? 0xcccccccc : 0x33333333; - if (_object == null) - { - return enabledCode; - } - return _object.hashCode() ^ enabledCode; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractJarLocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractJarLocator.java deleted file mode 100644 index ba1a51edb..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractJarLocator.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.Collection; -import java.util.Collections; -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; - -/** - * An abstract implementation of the JarLocator. - * - * @author cbateman - * - */ -public abstract class AbstractJarLocator extends - AbstractLocator<Collection<? extends ClasspathJarFile>, IProject, String> - implements IJarLocator -{ - /** - * @param id - * @param displayName - */ - public AbstractJarLocator(final String id, final String displayName) - { - super(id, displayName, Collections.EMPTY_LIST, - new CopyOnWriteArrayList<ILocatorChangeListener>()); - } - - private final CopyOnWriteArrayList<JarChangeListener> _listeners = new CopyOnWriteArrayList<JarChangeListener>(); - - public final Collection<? extends ClasspathJarFile> getJars(final IProject project) - { - return locate(project); - } - - @Override - protected abstract Collection<? extends ClasspathJarFile> doLocate(IProject context); - - public void addListener(final JarChangeListener listener) - { - _listeners.addIfAbsent(listener); - } - - public void removeListener(final JarChangeListener listener) - { - _listeners.remove(listener); - } - - /** - * @param event - */ - protected void fireChangeEvent(final JarChangeEvent event) - { - for (final JarChangeListener listener : _listeners) - { - listener.changed(event); - } - } - - public void dispose() - { - _listeners.clear(); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractLifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractLifecycleListener.java deleted file mode 100644 index 3bafecd91..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/AbstractLifecycleListener.java +++ /dev/null @@ -1,221 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.Collection; -import java.util.Collections; -import java.util.EventObject; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * - * @author cbateman - * @param <EVENTTYPE> - * @param <LISTENERTYPE> - * @param <LIFECYCLEOBJECT> - * - */ -public abstract class AbstractLifecycleListener<EVENTTYPE extends EventObject, LISTENERTYPE extends ILifecycleListener<EVENTTYPE>, LIFECYCLEOBJECT> - extends ImmutableLifecycleListener<LISTENERTYPE> -{ - /** - * Exception (non-localized) error message thrown when a null object is - * added. - */ - protected static final String CANNOT_ADD_NULL_RESOURCE = "Cannot add null object"; //$NON-NLS-1$ - static final boolean TRACE_EVENTS; - static - { - TRACE_EVENTS = Boolean.valueOf( - Platform.getDebugOption(JSFCommonPlugin.PLUGIN_ID - + "/debug/lifecyclelistener")).booleanValue() //$NON-NLS-1$ - || Boolean.valueOf(System.getProperty("org.eclipse.jst.jsf.common/debug/lifecyclelistener")).booleanValue(); //$NON-NLS-1$ - } - - private final CopyOnWriteArrayList<LISTENERTYPE> _listeners = new CopyOnWriteArrayList<LISTENERTYPE>(); - private final CopyOnWriteArrayList<LIFECYCLEOBJECT> _lifecycleObjects = new CopyOnWriteArrayList<LIFECYCLEOBJECT>(); - private final AtomicBoolean _isDisposed = new AtomicBoolean(false); - - /** - * Adds listener to the list of objects registered to receive lifecycle - * events for this resource. Only adds the listener if it is not already in - * the list. - * - * Method is thread-safe and may block the caller - * - * Throws {@link IllegalStateException} if isDisposed() == true Throws - * {@link NullPointerException} if listener == null - * - * @param listener - */ - @Override - public void addListener(final LISTENERTYPE listener) - { - if (isDisposed()) - { - throw new IllegalStateException(); - } - if (listener == null) - { - throw new NullPointerException("Cannot pass null listener"); //$NON-NLS-1$ - } - _listeners.addIfAbsent(listener); - } - - /** - * Removes listener from the list of registered listeners - * - * Method is thread-safe and may block the caller - * - * Throws {@link IllegalStateException} if isDisposed() == true - * - * @param listener - */ - @Override - public void removeListener(final LISTENERTYPE listener) - { - if (isDisposed()) - { - throw new IllegalStateException(); - } - _listeners.remove(listener); - } - - /** - * @param event - */ - protected void fireLifecycleEvent(final EVENTTYPE event) - { - boolean disposeAfter = false; - if (TRACE_EVENTS) - { - System.err.println(event); - } - // NOTE: must use iterator through _listeners so that - // CopyOnWriteArrayList protects us from concurrent modification - for (final LISTENERTYPE listener : _listeners) - { - final EventResult result = listener.acceptEvent(event); - disposeAfter |= result.getDisposeAfterEvent(); - } - if (disposeAfter) - { - dispose(); - } - } - - /** - * @return true if the listener has been disposed - */ - public boolean isDisposed() - { - return _isDisposed.get(); - } - - /** - * Release the resource change listener - */ - public final void dispose() - { - if (_isDisposed.compareAndSet(false, true)) - { - // ensure that add/removeResource don't cause races to add or - // remove the resource listener - synchronized (_lifecycleObjects) - { - // remove first to minimize the chance that the listener will - // be triggered during the remainder of dispose - removeSystemChangeListener(); - _lifecycleObjects.clear(); - doDispose(); - } - } - } - - /** - * Sub-class disposal specialization. - */ - protected void doDispose() - { - // do nothing by default; sub-classes should override to provide their - // own disposal. - } - - /** - * @param object - */ - protected void addLifecycleObject(final LIFECYCLEOBJECT object) - { - if (object == null) - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - synchronized (_lifecycleObjects) - { - // don't add any resources if we've disposed before acquiring the - // lock - if (isDisposed()) - { - return; - } - final int preSize = _lifecycleObjects.size(); - if (!_lifecycleObjects.contains(object)) - { - _lifecycleObjects.add(object); - } - // if the size of the array was 0 - // and is now greater, make sure the listener is added - if (preSize == 0 && _lifecycleObjects.size() > 0) - { - addSystemChangeListener(); - } - } - } - - /** - * If there are no longer resources being targeted, the resource change - * listener will be removed. - * - * @param res - */ - public void removeResource(final IResource res) - { - synchronized (_lifecycleObjects) - { - // don't bother with this stuff if we're disposed. - if (isDisposed()) - { - return; - } - _lifecycleObjects.remove(res); - // if there are no longer target resources, - // remove the workspace listener - if (_lifecycleObjects.size() == 0) - { - removeSystemChangeListener(); - } - } - } - - /** - * @return an iterable of the lifecycle objects being tracked. - */ - protected Collection<LIFECYCLEOBJECT> getLifecycleObjects() - { - return Collections.unmodifiableCollection(_lifecycleObjects); - } - - /** - * Add the system change listener that is used to collect events that will - * be processed into lifecycle change events. - */ - protected abstract void addSystemChangeListener(); - - /** - * Remove a system change listener added using addSystemChangeListener - */ - protected abstract void removeSystemChangeListener(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathEntryLifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathEntryLifecycleListener.java deleted file mode 100644 index 80e8c9a90..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathEntryLifecycleListener.java +++ /dev/null @@ -1,213 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.common.internal.resource.IClasspathLifecycleListener.ClasspathLifecycleEvent; - -/** - * @author cbateman - */ -public class ClasspathEntryLifecycleListener - extends - AbstractLifecycleListener<IClasspathLifecycleListener.ClasspathLifecycleEvent, IClasspathLifecycleListener, IProject> - implements IElementChangedListener -{ - private final JavaCoreMediator _mediator; - - /** - * Initialize an inactive lifecycle listener. A classpath listener will not - * be installed by this constructor. The object created using this - * constructor will not fire any events until addClasspathEntry is called at - * least once to add a target resource - * - * @param mediator - * the mediator to use to access JavaCore operations - * @throws NullPointerException - * if mediator is null. - */ - public ClasspathEntryLifecycleListener(final JavaCoreMediator mediator) - { - if (mediator == null) - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - _mediator = mediator; - } - - /** - * Create a new lifecycle listener for the res - * - * @param entry - * @param mediator - * the workspace to listen to for changes. - * @throws NullPointerException - * if res or workspace is null. - */ - public ClasspathEntryLifecycleListener(final IProject entry, - final JavaCoreMediator mediator) - { - this(mediator); - if (entry == null) - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - addLifecycleObject(entry); - } - - public void elementChanged(final ElementChangedEvent event) - { - // we are only interested in package fragment roots that are listening - // for - if (event.getType() == ElementChangedEvent.POST_CHANGE) - { - handlePostChangeEvent(event); - } - } - - private void handlePostChangeEvent(final ElementChangedEvent event) - { - final IJavaElementDelta delta = event.getDelta(); - new DeltaAcceptor().accept(new DeltaAcceptor.DeltaVisitor() - { - public void visit(final IJavaElementDelta visitDelta) - { - // we are only interested in package_fragment_root's - final IJavaElement element = visitDelta.getElement(); - // only interested if a project in our entries list owns the - // element. - final IJavaProject javaProject = element.getJavaProject(); - if (javaProject == null - || !getLifecycleObjects().contains( - javaProject.getProject())) - { - return; - } - if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) - { - handlePackageFragmentRoot(visitDelta); - } else if (element.getElementType() == IJavaElement.JAVA_PROJECT - && visitDelta.getResourceDeltas() != null) - { - handleProject(visitDelta); - } - // need to test the flags only for package fragment roots - } - - private void handleProject(final IJavaElementDelta visitDelta) - { - for (final IResourceDelta resDelta : visitDelta - .getResourceDeltas()) - { - try - { - resDelta.accept(new IResourceDeltaVisitor() - { - public boolean visit(final IResourceDelta resDelta2) - throws CoreException - { - if (resDelta2.getKind() == IResourceDelta.REMOVED - && resDelta2.getResource().getType() == IResource.FILE - && "jar".equals(resDelta2.getResource().getFileExtension())) //$NON-NLS-1$ - { - fireLifecycleEvent(new ClasspathLifecycleEvent( - ClasspathEntryLifecycleListener.this, - visitDelta.getElement(), - ClasspathLifecycleEvent.Type.REMOVED_DELTA, - resDelta2.getResource())); - } - return true; - } - }); - } catch (final CoreException e) - { - JSFCommonPlugin.log(e); - } - } - } - - private void handlePackageFragmentRoot( - final IJavaElementDelta visitDelta) - { - final int flags = visitDelta.getFlags(); - switch (visitDelta.getKind()) - { - case IJavaElementDelta.ADDED: - { - fireLifecycleEvent(new ClasspathLifecycleEvent( - ClasspathEntryLifecycleListener.this, - visitDelta.getElement(), - ClasspathLifecycleEvent.Type.ADDED)); - } - break; - case IJavaElementDelta.REMOVED: - { - fireLifecycleEvent(new ClasspathLifecycleEvent( - ClasspathEntryLifecycleListener.this, - visitDelta.getElement(), - ClasspathLifecycleEvent.Type.REMOVED)); - } - break; - case IJavaElementDelta.CHANGED: - if ((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) != 0) - { - fireLifecycleEvent(new ClasspathLifecycleEvent( - ClasspathEntryLifecycleListener.this, - visitDelta.getElement(), - ClasspathLifecycleEvent.Type.ADDED)); - } else if ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) != 0) - { - fireLifecycleEvent(new ClasspathLifecycleEvent( - ClasspathEntryLifecycleListener.this, - visitDelta.getElement(), - ClasspathLifecycleEvent.Type.REMOVED)); - } else if ((flags & IJavaElementDelta.F_REORDER) != 0) - { - // TODO: how important is the case of a classpath - // reordering? - } - break; - } - } - }, delta); - } - - @Override - protected void addSystemChangeListener() - { - _mediator.addElementChangedListener(this); - } - - @Override - protected void removeSystemChangeListener() - { - _mediator.removeElementChangeListener(this); - } - - private static class DeltaAcceptor - { - public interface DeltaVisitor - { - public void visit(final IJavaElementDelta delta); - } - - public void accept(final DeltaVisitor visitor, - final IJavaElementDelta delta) - { - visitor.visit(delta); - for (final IJavaElementDelta childDelta : delta - .getAffectedChildren()) - { - accept(visitor, childDelta); - } - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathJarFile.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathJarFile.java deleted file mode 100644 index 0c4bba176..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ClasspathJarFile.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.io.File; -import java.io.IOException; -import java.util.jar.JarFile; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * Represents a jar that is available on the classpath. Encapsulates the jar - * as well as information about where it is provided from. - * - * The jar itself may have been deleted in which case, exists() will return false. - * - * @author cbateman - * - */ -public class ClasspathJarFile -{ - private final IProject _project; - private final IPath _iPath; - - /** - * @param project - * @param iPath - */ - public ClasspathJarFile(final IProject project, final IPath iPath) - { - _project = project; - _iPath = iPath; - } - - /** - * @return the project that this jar file is being referenced from. Note that this - * is not necessarily the same as the project that owns it (if it is in the - * workspace) and a jar file may be referenced by more than one project. - */ - public IProject getProject() - { - return _project; - } - - /** - * @return the class path entry - */ - public IPath getPath() - { - return _iPath; - } - - /** - * @return a new JarFile for the underlying jar. Caller MUST close the jar when - * done. - */ - public JarFile getJarFile() - { - JarFile jarFileFromCPE = null; - try - { - jarFileFromCPE = getJarFileFromCPE(_iPath, _project.getWorkspace()); - } catch (final IOException e) - { - JSFCommonPlugin.log(e); - } - return jarFileFromCPE; - } - - /** - * TODO: Merge into JSFAppConfigUtils. - * - * @param entry - * @param workspace - * @return - */ - private JarFile getJarFileFromCPE(final IPath entry, final IWorkspace workspace) - throws IOException - { - IPath path = _iPath; - if (path.getFileExtension() != null - && path.getFileExtension().length() > 0) - { - final IWorkspaceRoot workspaceRoot = workspace.getRoot(); - if (path.getDevice() == null - && workspaceRoot.getProject(path.segment(0)) - .exists()) - { - path = workspaceRoot.getFile(path) - .getLocation(); - } - final String libraryPathString = path.toString(); - final File file = new File(libraryPathString); - if (file.exists()) - { - return new JarFile(file); - } - } - return null; - } - - @Override - public boolean equals(Object obj) - { - if (obj == this) - { - return true; - } - - if (! (obj instanceof ClasspathJarFile)) - { - return false; - } - - ClasspathJarFile other = (ClasspathJarFile) obj; - return _project.equals(other._project) && _iPath.equals(other._iPath); - } - - @Override - public int hashCode() - { - return _project.hashCode() ^ _iPath.hashCode(); - } - - @Override - public String toString() - { - return String.format("ClasspathJarFile for project=%s, entry=%s", _project, _iPath); //$NON-NLS-1$ - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ContentTypeResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ContentTypeResolver.java deleted file mode 100644 index c4cd6da06..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ContentTypeResolver.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; - -/** - * Tools for resolving content types of resources or other object linked from - * the workspace (i.e. "files" in classpath entries). - * - * @author cbateman - * - */ -public class ContentTypeResolver -{ - private final IContentTypeManager _typeManager; - - /** - * Equivalent to Platform.getContentTypeManager(). - */ - public ContentTypeResolver() - { - this(Platform.getContentTypeManager()); - } - - /** - * @param typeManager - */ - public ContentTypeResolver(final IContentTypeManager typeManager) - { - _typeManager = typeManager; - } - - /** - * @param contentTypeId - * @param fileName - * @return true if the fileName matches the content type provided. May also return - * false if the fileName alone is not enough to determine type. - */ - public boolean matchesType(final String contentTypeId, final String fileName) - { - IContentType jspContentType = _typeManager.getContentType(contentTypeId); - if (jspContentType != null - && jspContentType.isAssociatedWith(fileName)) - { - return true; - } - - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/DefaultJarLocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/DefaultJarLocator.java deleted file mode 100644 index 4f31cc178..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/DefaultJarLocator.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.common.internal.finder.AbstractMatcher.AlwaysMatcher; -import org.eclipse.jst.jsf.common.internal.finder.AbstractMatcher.IMatcher; -import org.eclipse.jst.jsf.common.internal.finder.VisitorMatcher; -import org.eclipse.jst.jsf.common.internal.finder.acceptor.ClasspathEntryJarMatchingAcceptor; -import org.eclipse.jst.jsf.common.internal.finder.acceptor.JarMatchingAcceptor; -import org.eclipse.jst.jsf.common.internal.resource.IClasspathLifecycleListener.ClasspathLifecycleEvent; -import org.eclipse.jst.jsf.common.internal.resource.IJarLocator.JarChangeEvent.Type; - -/** - * A default jar provider that traverses a project and returns all found jars on - * the classpath that a list of matcher criteria. - * - * @author cbateman - * - */ -public class DefaultJarLocator extends AbstractJarLocator -{ - private static final String DISPLAY_NAME = "Default Jar Provider"; //$NON-NLS-1$ - private static final String ID = DefaultJarLocator.class.getCanonicalName(); - private final VisitorMatcher<IProject, ClasspathJarFile, String> _matcher; - private ClasspathEntryLifecycleListener _classpathEntryListener; - private final JavaCoreMediator _javaCoreMediator; - - /** - * @param javaCoreMediator - */ - public DefaultJarLocator(final JavaCoreMediator javaCoreMediator) - { - this(Collections.singletonList(new AlwaysMatcher()), javaCoreMediator); - } - - /** - * @param matchers - * @param javaCoreMediator - */ - public DefaultJarLocator(final List<? extends IMatcher> matchers, - final JavaCoreMediator javaCoreMediator) - { - super(ID, DISPLAY_NAME); - _matcher = new VisitorMatcher<IProject, ClasspathJarFile, String>(ID, - DISPLAY_NAME, new JarMatchingAcceptor(javaCoreMediator), - matchers); - _javaCoreMediator = javaCoreMediator; - _classpathEntryListener = new ClasspathEntryLifecycleListener( - _javaCoreMediator); - } - - @Override - public void start(final IProject project) - { - _classpathEntryListener.addLifecycleObject(project); - _classpathEntryListener.addListener(new IClasspathLifecycleListener() - { - public EventResult acceptEvent(final ClasspathLifecycleEvent event) - { - final IJavaElement affectedElement = event.getAffectedElement(); - final List<ClasspathJarFile> affectedJarFiles = new ArrayList<ClasspathJarFile>(); - if (isInteresting(project, affectedElement, event)) - { - Type jarEventType = null; - switch (event.getType()) - { - case ADDED: - jarEventType = Type.JAR_ADDED; - affectedJarFiles.addAll(getChangedJars((IPackageFragmentRoot) affectedElement)); - break; - case REMOVED: - jarEventType = Type.JAR_REMOVED; - affectedJarFiles.addAll(getChangedJars((IPackageFragmentRoot) affectedElement)); - break; - case REMOVED_DELTA: - jarEventType = Type.JAR_REMOVED; - IResource res = event.getAffectedResource(); - if (res.getType() == IResource.FILE && - "jar".equals(res.getFileExtension())) //$NON-NLS-1$ - { - IPath path = res.getLocation(); - if (path != null) - { - affectedJarFiles.add(new ClasspathJarFile(project, path)); - } - } - break; - } - - if (jarEventType != null && !affectedJarFiles.isEmpty()) - { - for (final ClasspathJarFile changedJar : affectedJarFiles) - { - fireChangeEvent(new JarChangeEvent( - DefaultJarLocator.this, jarEventType, - changedJar)); - } - } - } - return EventResult.getDefaultEventResult(); - } - - private Collection<? extends ClasspathJarFile> getChangedJars( - final IPackageFragmentRoot affectedElement) - { - try - { - return new VisitorMatcher<IPackageFragmentRoot, ClasspathJarFile, String>( - "", "", new ClasspathEntryJarMatchingAcceptor(project), //$NON-NLS-1$ //$NON-NLS-2$ - Collections.singletonList(new AlwaysMatcher())) - .find(affectedElement); - } catch (final JavaModelException e) - { - return Collections.EMPTY_LIST; - } catch (final Exception e) - { - return Collections.EMPTY_LIST; - } - } - }); - super.start(project); - } - - private boolean isInteresting(final IProject project, - final IJavaElement affectedElement, final ClasspathLifecycleEvent event) - { - return - // first filter out events that aren't related to the project we care about. - (affectedElement != null - && affectedElement.getJavaProject() != null - && project - .equals(affectedElement.getJavaProject().getProject())) - // then filter down to only events impacting frag roots - // or jar file deletions - && (affectedElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT - || (affectedElement.getElementType() == IJavaElement.JAVA_PROJECT - && event.getAffectedResource() != null - && event.getType() == ClasspathLifecycleEvent.Type.REMOVED_DELTA)); - } - - @Override - public void stop() - { - _classpathEntryListener.dispose(); - super.stop(); - } - - @Override - protected Collection<? extends ClasspathJarFile> doLocate( - final IProject project) - { - try - { - return _matcher.find(project); - } catch (final Exception e) - { - JSFCommonPlugin - .log(e, "While getting jars for project: " + project); //$NON-NLS-1$ - return getNoResult(); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/EventResult.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/EventResult.java deleted file mode 100644 index 68aae9538..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/EventResult.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -/** - * @author cbateman - * - */ -public class EventResult -{ - private static EventResult DEFAULT; - - /** - * @return an event result with defaults initialized - */ - public synchronized static EventResult getDefaultEventResult() - { - if (DEFAULT == null) - { - DEFAULT = new EventResult() - { - @Override - protected void setDisposeAfterEvent(final boolean disposeAfterEvent) - { - throw new UnsupportedOperationException(); - } - }; - } - return DEFAULT; - } - - private static EventResult DISPOSE_AFTER_EVENT; - - /** - * @return an event result with default except dispose after - * is set - */ - public synchronized static EventResult getDisposeAfterEventResult() - { - if (DISPOSE_AFTER_EVENT == null) - { - DISPOSE_AFTER_EVENT = new EventResult() - { - /** - * @return the remove listener flag - */ - @Override - public boolean getDisposeAfterEvent() - { - return true; - } - - /** - * @param disposeAfterEvent - */ - @Override - protected void setDisposeAfterEvent(final boolean disposeAfterEvent) { - _disposeAfterEvent = disposeAfterEvent; - } - - }; - } - return DISPOSE_AFTER_EVENT; - } - - /** - * set to true if after the current event is finished firing, the source - * should be disposed. If self-disposal is not applicable, the flag is ignored - */ - protected boolean _disposeAfterEvent; - - /** - * @return the remove listener flag - */ - public boolean getDisposeAfterEvent() - { - return _disposeAfterEvent; - } - - /** - * @param disposeAfterEvent - */ - protected void setDisposeAfterEvent(final boolean disposeAfterEvent) { - _disposeAfterEvent = disposeAfterEvent; - } -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IClasspathLifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IClasspathLifecycleListener.java deleted file mode 100644 index e2fcfccac..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IClasspathLifecycleListener.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.EventObject; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jst.jsf.common.internal.resource.IClasspathLifecycleListener.ClasspathLifecycleEvent; - -/** - * Listener can register for events ona particular LifecycleListener - * - * @author cbateman - * - */ -public interface IClasspathLifecycleListener extends - ILifecycleListener<ClasspathLifecycleEvent> -{ - /** - * Listener accepts the classpath lifecycle event - * - * @param event - */ - EventResult acceptEvent(ClasspathLifecycleEvent event); - - /** - * An event indicating a change on the classpath - * - */ - public static class ClasspathLifecycleEvent extends EventObject - { - /** - * Indicates the type of change. - * - */ - public enum Type - { - /** - * The affected element was added to the classpath - */ - ADDED, - /** - * The affected element was removed from the classpath - */ - REMOVED, - /** - * A classpath object has been deleted from the workspace. The - * affected element is the owning IJavaProject. The actual deleted - * object can be obtained by query getAffectedResource. Note that - * this is a post change event, so the underlying resources most - * likely don't exist any more. - * - */ - REMOVED_DELTA - } - - private final IJavaElement _affectedElement; - private final IResource _affectedResource; - private final Type _type; - - /** - * @param source - * @param affectedElement - * @param type - */ - public ClasspathLifecycleEvent( - final ClasspathEntryLifecycleListener source, - final IJavaElement affectedElement, final Type type) - { - this(source, affectedElement, type, null); - } - - /** - * @param source - * @param affectedElement - * @param type - * @param affectedResource - * @throws IllegalArgumentException - * if affectedResource is non-null but type doesn't match - * one that has affectedResources (see - * isAffectResourceEvent) - */ - public ClasspathLifecycleEvent( - final ClasspathEntryLifecycleListener source, - final IJavaElement affectedElement, final Type type, - final IResource affectedResource) - { - super(source); - _affectedElement = affectedElement; - _type = type; - _affectedResource = affectedResource; - if (affectedResource != null && !isAffectResourceEvent(type)) - { - throw new IllegalArgumentException(); - } - } - - @Override - public ClasspathEntryLifecycleListener getSource() - { - return (ClasspathEntryLifecycleListener) super.getSource(); - } - - /** - * @return the type of event. - */ - public Type getType() - { - return _type; - } - - /** - * @return the affected resource or null if none. - */ - public IResource getAffectedResource() - { - return _affectedResource; - } - - /** - * - */ - private static final long serialVersionUID = -2510218872082581659L; - - /** - * @return the element that changed. - */ - public IJavaElement getAffectedElement() - { - return _affectedElement; - } - - /** - * @param type - * @return true if the type instance matches one for which - * affectedResource's are valid in the change event. - */ - public boolean isAffectResourceEvent(final Type type) - { - return type == Type.REMOVED_DELTA; - } - - @Override - public String toString() - { - return String.format( - "ClasspathLifecycleEvent: IJavaElement=%s, Res = %s, Event=%s", //$NON-NLS-1$ - getAffectedElement(), getAffectedResource(), getType()); - } - - - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IJarLocator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IJarLocator.java deleted file mode 100644 index 34629f990..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IJarLocator.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.Collection; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jst.jsf.common.internal.locator.ILocator; -import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener; -import org.eclipse.jst.jsf.common.internal.locator.ILocatorChangeListener.LocatorChangeEvent; - -/** - * Provider of jars for use by the locator. Exists to abstract the locator from - * JDT for test purposes. - * - */ -public interface IJarLocator extends - ILocator<Collection<? extends ClasspathJarFile>, IProject, String> -{ - /** - * @param project - * @return a list of valid jar files. - */ - Collection<? extends ClasspathJarFile> getJars(final IProject project); - - /** - * @param listener - */ - void addListener(final JarChangeListener listener); - - /** - * @param listener - */ - void removeListener(final JarChangeListener listener); - - /** - * Disposes the provider. - */ - void dispose(); - - /** - * Implemented by classes that want receive events signalling a change on - * the classpath. - * - */ - public abstract class JarChangeListener implements ILocatorChangeListener - { - /** - * @param event - */ - public abstract void changed(JarChangeEvent event); - - public final void changed(final LocatorChangeEvent event) - { - changed((JarChangeEvent) event); - } - } - - /** - * Indicates a change on the class path. - * - */ - public class JarChangeEvent extends LocatorChangeEvent - { - /** - * Indicates the type of event - * - */ - public enum Type - { - /** - * Indicates a jar has been added. - */ - JAR_ADDED, - /** - * Indicates a jar has been removed. - */ - JAR_REMOVED; - } - - private final Type _type; - private final ClasspathJarFile _jar; - - /** - * @param source - * @param type - * @param jar - */ - public JarChangeEvent(final ILocator source, final Type type, - final ClasspathJarFile jar) - { - super(source); - _type = type; - _jar = jar; - } - - /** - * @return the type of the event - */ - public Type getType() - { - return _type; - } - - /** - * @return the affected jar. - */ - public ClasspathJarFile getJar() - { - return _jar; - } - - /** - * - */ - private static final long serialVersionUID = 8163703453414731319L; - } -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ILifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ILifecycleListener.java deleted file mode 100644 index 93acba85c..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ILifecycleListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.EventObject; - -/** - * @author cbateman - * - * @param <EVENTTYPE> - */ -public interface ILifecycleListener<EVENTTYPE extends EventObject> -{ - /** - * Listener accepts the resource lifecycle event - * - * @param event - * @return the result of accepting the event - */ - EventResult acceptEvent(EVENTTYPE event); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IResourceLifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IResourceLifecycleListener.java deleted file mode 100644 index 2306d598c..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/IResourceLifecycleListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - - -/** - * Listener can register for events ona particular LifecycleListener - * - * @author cbateman - * - */ -public interface IResourceLifecycleListener extends ILifecycleListener<ResourceLifecycleEvent> -{ - /** - * Listener accepts the classpath lifecycle event - * - * @param event - */ - EventResult acceptEvent(ResourceLifecycleEvent event); - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ImmutableLifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ImmutableLifecycleListener.java deleted file mode 100644 index f54421613..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ImmutableLifecycleListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - - -/** - * A lifecycle listener abstraction that cannot have its resources modified. - * Clients may only register and deregister for events. - * - * @author cbateman - * @param <LISTENERTYPE> - * - */ -public abstract class ImmutableLifecycleListener<LISTENERTYPE extends ILifecycleListener> -{ - - /** - * Adds listener to the list of objects registered to receive - * lifecycle events for this resource. Only adds the listener - * if it is not already in the list. - * - * Method is thread-safe and may block the caller - * - * Throws {@link IllegalStateException} if isDisposed() == true - * - * @param listener - */ - public abstract void addListener(final LISTENERTYPE listener); - - /** - * Removes listener from the list of registered listeners - * - * Method is thread-safe and may block the caller - * - * Throws {@link IllegalStateException} if isDisposed() == true - * - * @param listener - */ - public abstract void removeListener(final LISTENERTYPE listener); -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/JavaCoreMediator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/JavaCoreMediator.java deleted file mode 100644 index 7f84c3fec..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/JavaCoreMediator.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; - -/** - * Implements pass-through methods to the static JavaCore class. This allows us - * to decouple from JavaCore for testing and other dep-injection purposes. - * - * @author cbateman - * - */ -public class JavaCoreMediator -{ - /** - * @param project - * @return a java project for project. Return null if project is null. - */ - public IJavaProject create(final IProject project) - { - return JavaCore.create(project); - } - - /** - * @param listener - */ - public void addElementChangedListener(final IElementChangedListener listener) - { - JavaCore.addElementChangedListener(listener); - } - - /** - * @param listener - */ - public void removeElementChangeListener( - final ClasspathEntryLifecycleListener listener) - { - JavaCore.removeElementChangedListener(listener); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/LifecycleListener.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/LifecycleListener.java deleted file mode 100644 index 3aee0decd..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/LifecycleListener.java +++ /dev/null @@ -1,381 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.jst.jsf.common.internal.ITestTracker; -import org.eclipse.jst.jsf.common.internal.ITestTracker.Event; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.EventType; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType; - -/** - * Listens to resource changes and fires lifecycle events - * - * @author cbateman - * - */ -public class LifecycleListener extends - AbstractLifecycleListener<ResourceLifecycleEvent, IResourceLifecycleListener, IResource> - implements IResourceChangeListener -{ - private static boolean ENABLE_TEST_TRACKING = false; - private static long _seqId; - private ITestTracker _testTracker; // == - final IWorkspace _workspace; - - // null; - // initialized - // by - // setter - // injection - /** - * Initialize an inactive lifecycle listener. A workspace listener will not - * be installed by this constructor. The object created using this - * constructor will not fire any events until addResource is called at least - * once to add a target resource - * - * @param workspace - * the workspace to listen to for changes. - * @throws NullPointerException - * if workspace is null. - */ - public LifecycleListener(final IWorkspace workspace) - { - super(); - if (workspace == null) - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - _workspace = workspace; - } - - /** - * Create a new lifecycle listener for the res - * - * @param res - * @param workspace - * the workspace to listen to for changes. - * @throws NullPointerException - * if res or workspace is null. - */ - public LifecycleListener(final IResource res, final IWorkspace workspace) - { - this(workspace); - if (res == null) - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - addResource(res); - } - - /** - * @param resources - * @param workspace - * the workspace to listen to for changes. - * @throws NullPointerException - * if resources, a member of resources or workspace is null. - */ - public LifecycleListener(final List<IResource> resources, - final IWorkspace workspace) - { - this(workspace); - for (final IResource resource : resources) - { - if (resource != null) - { - addResource(resource); - } else - { - throw new NullPointerException(CANNOT_ADD_NULL_RESOURCE); - } - } - } - - @Override - protected void addSystemChangeListener() - { - _workspace.addResourceChangeListener(this); - } - - @Override - protected void removeSystemChangeListener() - { - _workspace.removeResourceChangeListener(this); - } - - /** - * @param testTracker - */ - public final void setTestTracker(final ITestTracker testTracker) - { - _testTracker = testTracker; - } - - /** - * @param newValue - */ - protected final void setEnableTracing(final boolean newValue) - { - ENABLE_TEST_TRACKING = newValue; - } - - /** - * @param res - * a resource you want to receive events for. MUST NOT BE NULL. - * @throw {@link NullPointerException} if res is null - */ - public void addResource(final IResource res) - { - addLifecycleObject(res); - } - - public void resourceChanged(final IResourceChangeEvent event) - { - final long seqId = _seqId++; - if (_testTracker != null && ENABLE_TEST_TRACKING) - { - _testTracker.fireEvent(Event.START_TRACKING, seqId, - "trackMethod_resourceChanged"); //$NON-NLS-1$ - } - assert (!isDisposed()); - switch (event.getType()) - { - case IResourceChangeEvent.PRE_CLOSE: - { - final IProject proj = (IProject) event.getResource(); - // must use iterator to ensure copy on write behaviour - for (final IResource res : getLifecycleObjects()) - { - if (proj == res || proj == res.getProject()) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, - res, EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_PROJECT_CLOSED)); - } - } - } - break; - case IResourceChangeEvent.PRE_DELETE: - { - final IProject proj = (IProject) event.getResource(); - // must use iterator to ensure copy on write behaviour - for (final IResource res : getLifecycleObjects()) - { - // if the resource being tracked is the resource being - // deleted, - // then fire a resource delete event - if (proj == res) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, - res, EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_DELETED)); - } - // if the resource being tracked is a resource in the - // project being - // deleted, then fire a project deleted event - else if (proj == res.getProject()) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, - res, EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_PROJECT_DELETED)); - } - } - } - break; - case IResourceChangeEvent.POST_CHANGE: - { - for (final IResource res : getLifecycleObjects()) - { - IResourceDelta delta = event.getDelta(); - // only care about post change events to resources - // that we are tracking - if (delta != null) - { - delta = delta.findMember(res.getFullPath()); - if (delta != null) - { - visit(delta); - } - } - } - } - break; - default: - // do nothing - // we only handle these three - } - if (ENABLE_TEST_TRACKING && _testTracker != null) - { - _testTracker.fireEvent(Event.STOP_TRACKING, seqId, - "trackMethod_resourceChanged"); //$NON-NLS-1$ - } - } - - private void visit(final IResourceDelta delta) - { - assert (!isDisposed()); - final IResource res = delta.getResource(); - // the wkspace root is a special case since even though - // it is registered as the target resource, we are interested - // in new projects created in the root - if (res.getType() == IResource.ROOT) - { - handleWorkspaceRoot(delta); - } else if (res instanceof IContainer) - { - handleContainer(delta, res); - } else - { - handleFile(delta, res); - } - } - - private void handleContainer(final IResourceDelta delta, IResource container) - { - handleChange(delta, container, container); - for (final IResourceDelta childDelta : delta.getAffectedChildren()) - { - if (childDelta.getResource().getType() == IResource.FILE - || childDelta.getResource().getType() == IResource.FOLDER) - { - handleChange(childDelta, childDelta.getResource(), container); - } - } - } - - private void handleFile(final IResourceDelta delta, final IResource res) - { - switch (delta.getKind()) - { - case IResourceDelta.ADDED: - case IResourceDelta.REMOVED: - { - handleChange(delta, res, res); - } - break; - case IResourceDelta.CHANGED: - { - // the contents of the file have changed - if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_CHANGED, - ReasonType.RESOURCE_CHANGED_CONTENTS)); - } - } - break; - } - } - - private void handleChange(final IResourceDelta delta, final IResource res, - final IResource interestedResource) - { - switch (delta.getKind()) - { - case IResourceDelta.ADDED: - { - handleAdd(delta, res, interestedResource); - } - break; - case IResourceDelta.REMOVED: - { - handleRemove(delta, res, interestedResource); - } - break; - } - } - - private void handleRemove(final IResourceDelta delta, final IResource res, - final IResource interestedResource) - { - if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) - { - if (res.equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_MOVED)); - } else if (res.getParent().equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_MOVED_CONTAINER)); - } - } else - { - if (res.equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_DELETED)); - } else if (res.getParent().equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_INACCESSIBLE, - ReasonType.RESOURCE_DELETED_FROM_CONTAINER)); - } - } - } - - private void handleAdd(final IResourceDelta delta, final IResource res, - final IResource interestedResource) - { - if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) - { - if (res.equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_ADDED, ReasonType.RESOURCE_MOVED)); - } else if (res.getParent().equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_ADDED, - ReasonType.RESOURCE_MOVED_CONTAINER)); - } - } else - { - if (res.equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_ADDED, ReasonType.RESOURCE_ADDED)); - } else if (res.getParent().equals(interestedResource)) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_ADDED, - ReasonType.RESOURCE_ADDED_TO_CONTAINER)); - } - } - } - - private void handleWorkspaceRoot(final IResourceDelta delta) - { - for (final IResourceDelta childDelta : delta - .getAffectedChildren(IResourceDelta.ADDED|IResourceDelta.CHANGED)) - { - final IResource res = childDelta.getResource(); - if ((childDelta.getFlags() & IResourceDelta.OPEN) != 0 && - // project was just opened - res.getType() == IResource.PROJECT) - { - fireLifecycleEvent(new ResourceLifecycleEvent(this, res, - EventType.RESOURCE_ADDED, ReasonType.PROJECT_OPENED)); - } - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceLifecycleEvent.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceLifecycleEvent.java deleted file mode 100644 index 15ac306aa..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceLifecycleEvent.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.EventObject; - -import org.eclipse.core.resources.IResource; - -/** - * @author cbateman - * - */ -public class ResourceLifecycleEvent extends EventObject -{ - /** - * - */ - private static final long serialVersionUID = -8692801944833729L; - - /** - * the type of lifecycle event this enum is not closed and may add new - * fields in the future - */ - public enum EventType - { - /** - * Indicates that the resource is no longer accessible (as testable with - * IResource.isAccessible). The reasonType will indicate why. - */ - RESOURCE_INACCESSIBLE, - - /** - * Indicates that the resource being tracked has changed in some way, - * use ReasonType to determine specifics - */ - RESOURCE_CHANGED, - - /** - * Indicates that the resource being tracked hass been added. Use - * ReasonType to determine specifics. - */ - RESOURCE_ADDED; - } - - /** - * encodes the cause of the event if the event type provides one this enum - * is not closed and may add new fields in the future - */ - public enum ReasonType - { - /** - * The resource was deleted from the workspace, this event is pre change - * if the event is project and post change otherwise - */ - RESOURCE_DELETED, - /** - * The resource was delete from it's container. This fired when the - * PARENT of the resource being deleted is registered for lifecycle - * events (i.e. _affectedResource.getParent() == registeredResource) - */ - RESOURCE_DELETED_FROM_CONTAINER, - /** - * The resource's project was deleted. This event is pre-change. Note - * that if the tracked resource is a project, RESOURCE_DELETED will be - * fired, not this event. - */ - RESOURCE_PROJECT_DELETED, - /** - * The resource's project was closed. This event is pre-change - */ - RESOURCE_PROJECT_CLOSED, - /** - * Occurs when the contents of a non-project resource has changed - */ - RESOURCE_CHANGED_CONTENTS, - /** - * Occurs when a project resource is added - */ - PROJECT_OPENED, - /** - * Occurs when a non-project resource is added to a container. This is - * fired if the resource being added was in the list of resources - * registered for lifecycle events (i.e. _affectedResource == - * registeredResource). - */ - RESOURCE_ADDED, - /** - * Occurs when a non-project resource is added to a container. This is - * fired if the PARENT of the resource being added was in the resources - * registered for lifecycle events (i.e. _affectedResource.getParent() = - * registeredResource) - */ - RESOURCE_ADDED_TO_CONTAINER, - /** - * Occurs when a resource has becomes added or inaccessible due to a - * move operation. This event is fired when the resource being moved is - * the one of interest. - */ - RESOURCE_MOVED, - /** - * Occurs when a resource has becomes added or inaccessible due to a - * move operation. This event is fired when the PARENT of resource being - * moved is the one of interest. - */ - RESOURCE_MOVED_CONTAINER - } - - private final IResource _affectedResource; - private final EventType _eventType; - private final ReasonType _reasonType; - - /** - * @param source - * @param affectedResource - * @param eventType - * @param reasonType - */ - public ResourceLifecycleEvent(final LifecycleListener source, - final IResource affectedResource, - final EventType eventType, final ReasonType reasonType) - { - super(source); - _affectedResource = affectedResource; - _eventType = eventType; - _reasonType = reasonType; - } - - /** - * @return the affected resource - */ - public IResource getAffectedResource() - { - return _affectedResource; - } - - /** - * @return the event that has occurred - */ - public EventType getEventType() - { - return _eventType; - } - - /** - * @return the cause of the event - */ - public ReasonType getReasonType() - { - return _reasonType; - } - - @Override - public String toString() - { - return String.format( - "ResourceLifecycleEvent: Res = %s, Event=%s, Reason=%s", //$NON-NLS-1$ - getAffectedResource(), getEventType(), getReasonType()); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceManager.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceManager.java deleted file mode 100644 index 2ecedd469..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; - -/** - * A resource singleton object manager that manages singletons that are aware - * of the the resources they are singletons for. - * - * @author cbateman - * @param <RESTYPE> - * - */ -public abstract class ResourceManager<RESTYPE extends IResource> extends - ResourceSingletonObjectManager<ResourceTracker<RESTYPE>, IResource> -{ - /** - * @param workspace - */ - public ResourceManager(IWorkspace workspace) - { - super(workspace); - } - - public void dispose() - { - super.dispose(); - } - - /** - * @param listener - */ - public void addListener(final IResourceLifecycleListener listener) - { - super.addLifecycleEventListener(listener); - } - - /** - * @param listener - */ - public void removeListener(final IResourceLifecycleListener listener) - { - super.removeLifecycleEventListener(listener); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.common.internal.resource.ResourceSingletonObjectManager#createNewInstance(org.eclipse.core.resources.IResource) - */ - protected abstract ResourceTracker<RESTYPE> createNewInstance(final IResource resource); - - /** - * Initialize any state about the current resources we are managing. - */ - public abstract void initResources(); - - /** - * @return the current list of resources being managed. - */ - public abstract List<RESTYPE> getResources(); - -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceSingletonObjectManager.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceSingletonObjectManager.java deleted file mode 100644 index d2b98f466..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceSingletonObjectManager.java +++ /dev/null @@ -1,419 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jst.jsf.common.internal.managedobject.IManagedObject; -import org.eclipse.jst.jsf.common.internal.managedobject.ObjectManager; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.EventType; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType; - -/** - * An object manager that manages a single instanceof an IManagedObject per - * resource. The manager takes care of ensuring that a managed object is - * properly disposed when a resource lifecycle event renders it inaccessible - * (i.e file is deleted, project is closed or delete). - * - * @author cbateman - * - * @param <RESOURCE> - * @param <MANAGEDOBJECT> - */ -public abstract class ResourceSingletonObjectManager<MANAGEDOBJECT extends IManagedObject, RESOURCE extends IResource> - extends ObjectManager<MANAGEDOBJECT, RESOURCE> -{ - // lazily initialized - private LifecycleListener _lifecycleListener; - final Map<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>> _perResourceObjects; - private final IWorkspace _workspace; - - /** - * Default constructor - * @param workspace - */ - protected ResourceSingletonObjectManager(final IWorkspace workspace) - { - _workspace = workspace; - _perResourceObjects = new HashMap<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>>(); - } - - /** - * @return the workspace - */ - protected final IWorkspace getWorkspace() - { - return _workspace; - } - - - /** - * @return an unmodifiable view on the map of currently managed objects keyed - * by the resource they are mapped to. - */ - protected final Map<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>> getPerResourceObjects() - { - return Collections.unmodifiableMap(_perResourceObjects); - } - - @Override - public final MANAGEDOBJECT getInstance(final RESOURCE key) - throws ManagedObjectException - { - assertNotDisposed(); - IAdaptable stateObject = null; - try - { - stateObject = unsafeRunBeforeGetInstance(key); - synchronized(this) - { - runBeforeGetInstance(key); - ManagedResourceObject managedResObject = _perResourceObjects.get(key); - - if (managedResObject == null) - { - final MANAGEDOBJECT managedObject = createNewInstance(key); - - if (managedObject == null) - { - throw new ManagedObjectException( - "No object available for resource"); //$NON-NLS-1$ - } - managedResObject = manageResource(key, managedObject); - } - - runAfterGetInstance(key); - return (MANAGEDOBJECT) managedResObject.getManagedObject(); - } - } - finally - { - unsafeRunAfterGetInstance(key, stateObject); - } - } - - /** - * @param resource - * @return a new instance of T associated with S. This operation must not - * cache T: a brand new instance is always required. getInstance - * will perform caching and resource listening. - */ - protected abstract MANAGEDOBJECT createNewInstance(RESOURCE resource); - - /** - * @param resource - */ - protected void runBeforeGetInstance(final RESOURCE resource) - { - // do nothing by default - } - - /** - * @param resource - */ - protected void runAfterGetInstance(final RESOURCE resource) - { - // do nothing by default - } - - /** - * Callback run outside of synchronized code block in getInstance - * @param resource - * @return A state object to be passed to unsafeRunAfterGetInstance, or null. - */ - protected IAdaptable unsafeRunBeforeGetInstance(final RESOURCE resource) - { - // do nothing by default - return null; - } - - /** - * Callback run outside of synchronized code block in getInstance - * @param resource - * @param adaptable State object returned from unsafeRunBeforeGetInstance call, may be null. - */ - protected void unsafeRunAfterGetInstance(final RESOURCE resource, final IAdaptable adaptable) - { - // do nothing by default - } - - /** - * @param resource - * @return true if there already exists a managed object associated with - * the resource - */ - public synchronized boolean isInstance(RESOURCE resource) - { - assertNotDisposed(); - return _perResourceObjects.containsKey(resource); - } - - /** - * @return a copy of the current set of RESOURCE object keys that we - * are managing singletons for. Collection is mutable, but as a copy, - * changes to it do not effect thie object manager. - */ - public synchronized Collection<RESOURCE> getManagedResources() - { - assertNotDisposed(); - return new HashSet(_perResourceObjects.keySet()); - } - /** - * Should be called by concrete classes to indicate they have created a new - * managed object for resource, for which they want to track lifecycle - * changes. - * - * @param resource - * @param managedObject - */ - private synchronized ManagedResourceObject manageResource(final RESOURCE resource, - final MANAGEDOBJECT managedObject) - { - final LifecycleListener listener = lazilyGetLifecycleListener(); - listener.addResource(resource); - final MyLifecycleEventListener<RESOURCE, MANAGEDOBJECT> eventListener = - new MyLifecycleEventListener<RESOURCE, MANAGEDOBJECT>( - this, managedObject, resource); - listener.addListener(eventListener); - - final ManagedResourceObject<MANAGEDOBJECT> managedResourceObject = new ManagedResourceObject<MANAGEDOBJECT>( - managedObject, eventListener); - _perResourceObjects.put(resource, managedResourceObject); - return managedResourceObject; - } - - /** - * Stop managing the resource. If resource is the last one, the resource - * change listener will be removed (it will be added again when next - * manageResource is called). - * - * @param resource - * @return the managed object that has just be disassociated from the resource. - * The object is not disposed, destroyed or checkpointed before being returned. - */ - protected final synchronized MANAGEDOBJECT unmanageResource(final RESOURCE resource) - { - final ManagedResourceObject managedResourceObject = - _perResourceObjects.remove(resource); - final LifecycleListener listener = lazilyGetLifecycleListener(); - - if (managedResourceObject != null) - { - listener.removeListener(managedResourceObject.getEventListener()); - } - - listener.removeResource(resource); - return (MANAGEDOBJECT) managedResourceObject.getManagedObject(); - } - - /** - * Call to register a listener - * - * @param listener - */ - protected final void addLifecycleEventListener( - final IResourceLifecycleListener listener) - { - assertNotDisposed(); - final LifecycleListener lifecycleListener = lazilyGetLifecycleListener(); - lifecycleListener.addListener(listener); - } - - /** - * Call to remove a listener - * - * @param listener - */ - protected final void removeLifecycleEventListener( - final IResourceLifecycleListener listener) - { - final LifecycleListener lifecycleListener = lazilyGetLifecycleListener(); - lifecycleListener.removeListener(listener); - } - - /** - * Add additional resources to the set to listen to. - * - * @param res - */ - protected final void addResource(final IResource res) - { - final LifecycleListener lifecycleListener = lazilyGetLifecycleListener(); - lifecycleListener.addResource(res); - } - - /** - * Remove a resource that is being listened to. Must not be used to remove - * internally added resources (i.e. only use this if you called addResource(res). - * - * @param res - */ - protected final void removeResource(final IResource res) - { - synchronized(this) - { - if (_perResourceObjects.keySet().contains(res)) - { - throw new IllegalArgumentException("Can't remove managed resources with this method"); //$NON-NLS-1$ - } - } - final LifecycleListener lifecycleListener = lazilyGetLifecycleListener(); - lifecycleListener.removeResource(res); - } - - private synchronized LifecycleListener lazilyGetLifecycleListener() - { - if (_lifecycleListener == null) - { - _lifecycleListener = new LifecycleListener(_workspace); - } - return _lifecycleListener; - } - - /** - * @author cbateman - * - * @param <MANAGEDOBJECT> - */ - protected final static class ManagedResourceObject<MANAGEDOBJECT extends IManagedObject> - { - private final MANAGEDOBJECT _managedObject; - private final MyLifecycleEventListener _eventListener; - - private ManagedResourceObject(final MANAGEDOBJECT managedObject, - final MyLifecycleEventListener eventListener) - { - _managedObject = managedObject; - _eventListener = eventListener; - } - - /** - * @return the managed object - */ - public MANAGEDOBJECT getManagedObject() - { - return _managedObject; - } - - /** - * @return the event listener - */ - public MyLifecycleEventListener getEventListener() - { - return _eventListener; - } - } - - private static class MyLifecycleEventListener<RESOURCE extends IResource, MANAGEDOBJECT extends IManagedObject> implements - IResourceLifecycleListener - { - private final RESOURCE _resource; - private final MANAGEDOBJECT _managedObject; - private final ResourceSingletonObjectManager<MANAGEDOBJECT, RESOURCE> _target; - - private MyLifecycleEventListener(final ResourceSingletonObjectManager<MANAGEDOBJECT, RESOURCE> target, - final MANAGEDOBJECT managedObject, - final RESOURCE resource) - { - _resource = resource; - _managedObject = managedObject; - _target = target; - } - - public EventResult acceptEvent(final ResourceLifecycleEvent event) - { - final EventResult result = EventResult.getDefaultEventResult(); - - // not interested - if (!_resource.equals(event.getAffectedResource())) - { - return EventResult.getDefaultEventResult(); - } - - if (event.getEventType() == EventType.RESOURCE_INACCESSIBLE) - { - try - { - if (event.getReasonType() == ReasonType.RESOURCE_DELETED - || event.getReasonType() == ReasonType.RESOURCE_PROJECT_DELETED) - { - _managedObject.destroy(); - } - else - { - _managedObject.dispose(); - } - } - // dispose/destroy is external code out our control, so make sure - // unmanage gets called if it blows up. - finally - { - _target.unmanageResource(_resource); - } - } - return result; - } - } - - - /** - * Unmanages all resources and calls checkpoint and dispose on all managed - * objects. After this call, other methods my throw exception is called. - * - * Sub-class may override, but should always call dispose after disposing - * their own specialized state. - */ - @Override - public void dispose() - { - if (_isDisposed.compareAndSet(false, true)) - { - // TODO: implement a better lock strategy on resource manager - synchronized (this) - { - Map<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>> copy = new HashMap<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>>( - getPerResourceObjects()); - - for (Map.Entry<RESOURCE, ManagedResourceObject<MANAGEDOBJECT>> entry : copy.entrySet()) - { - RESOURCE res = entry.getKey(); - MANAGEDOBJECT unmanagedResource = unmanageResource(res); - unmanagedResource.checkpoint(); - unmanagedResource.dispose(); - } - _perResourceObjects.clear(); - if (_lifecycleListener != null) - { - _lifecycleListener.dispose(); - } - } - } - } - - @Override - public void destroy() - { - // do nothing by default - } - - @Override - public void checkpoint() - { - // do nothing by default - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceTracker.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceTracker.java deleted file mode 100644 index 8f431ddbc..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/ResourceTracker.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import java.util.concurrent.atomic.AtomicLong; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jst.jsf.common.internal.managedobject.AbstractManagedObject; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.EventType; -import org.eclipse.jst.jsf.common.internal.resource.ResourceLifecycleEvent.ReasonType; - -/** - * A managed object that tracks changes to a resource. - * - * @author cbateman - * @param <RESTYPE> - * - */ -public abstract class ResourceTracker<RESTYPE extends IResource> extends - AbstractManagedObject implements IResourceLifecycleListener -{ - private final RESTYPE _resource; - private final AtomicLong _lastModifiedStamp = new AtomicLong(); - - /** - * @param resource - */ - public ResourceTracker(final RESTYPE resource) - { - super(); - _resource = resource; - _lastModifiedStamp.set(resource.getModificationStamp()); - } - - /** - * @return the resource that is being tracked - */ - public final RESTYPE getResource() - { - return _resource; - } - - /** - * @return the last modificatino stamp stored for the resource. - */ - public final long getLastModifiedStamp() - { - return _lastModifiedStamp.get(); - } - - public EventResult acceptEvent(final ResourceLifecycleEvent event) - { - if (!isInteresting(event)) - { - return EventResult.getDefaultEventResult(); - } - - final EventType eventType = event.getEventType(); - - final ReasonType reasonType = event.getReasonType(); - switch (eventType) - { - case RESOURCE_ADDED: - // added resources kick an add event. - fireResourceAdded(event.getAffectedResource(), reasonType); - break; - case RESOURCE_CHANGED: - // changed resources kick a change event - fireResourceChanged(event.getAffectedResource(), reasonType); - break; - case RESOURCE_INACCESSIBLE: - // removed resources kick a remove event - fireResourceInAccessible(event.getAffectedResource(), reasonType); - break; - } - - return EventResult.getDefaultEventResult(); - } - - /** - * @param event - * @return true if this event is interesting - */ - protected boolean isInteresting(final ResourceLifecycleEvent event) - { - return _resource.equals(event.getAffectedResource()); - } - - /** - * @param affectedResource - * @param reasonType - */ - protected abstract void fireResourceInAccessible(IResource affectedResource, ReasonType reasonType); - - /** - * @param affectedResource - * @param reasonType - */ - protected abstract void fireResourceChanged(IResource affectedResource, ReasonType reasonType); - - /** - * Note that this may fire for both the new resource and it's parent - * container if both are registered by the lifecycle event. Check reasonType - * to ensure you getting the event you want: i.e. RESOURCE_ADDED vs. - * RESOURCE_ADDED_TO_CONTAINER - * - * @param affectedResource - * @param reasonType - */ - protected abstract void fireResourceAdded(IResource affectedResource, - ReasonType reasonType); - - @Override - public void dispose() - { - super.dispose(); - } - - @Override - public void checkpoint() - { - // nothing currently persisted - } - - @Override - public void destroy() - { - // nothing currently persisted - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/WorkspaceMediator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/WorkspaceMediator.java deleted file mode 100644 index 7e870478d..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/resource/WorkspaceMediator.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.resource; - -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * Mediates between a client and certain workspace interface. This is allows - * us to decouple from the IWorkspace interface, especially for testing. - * - * @author cbateman - * - */ -public class WorkspaceMediator -{ - /** - * @param runnable - * @param name - */ - public void runInWorkspaceJob(final IWorkspaceRunnable runnable, final String name) - { - new WorkspaceJob(name) - { - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) - throws CoreException - { - runnable.run(monitor); - return Status.OK_STATUS; - } - - }.schedule(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractIdentifiableStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractIdentifiableStrategy.java deleted file mode 100644 index 0de9778f4..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractIdentifiableStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -/** - * Abstract base implementation for identifiable strategies. - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <IDTYPE> - */ -public abstract class AbstractIdentifiableStrategy<INPUT, OUTPUT, IDTYPE> implements - IIdentifiableStrategy<INPUT, OUTPUT, IDTYPE> -{ - private final IDTYPE _id; - private final OUTPUT _noResultValue; - private final String _displayName; - - /** - * @param id - * @param displayName - * @param noResultValue - */ - public AbstractIdentifiableStrategy(final IDTYPE id, final String displayName, - final OUTPUT noResultValue) - { - _id = id; - _noResultValue = noResultValue; - _displayName = displayName; - } - - public abstract OUTPUT perform(INPUT input) throws Exception; - - public OUTPUT getNoResult() - { - return _noResultValue; - } - - public IDTYPE getId() - { - return _id; - } - - public String getDisplayName() - { - return _displayName; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractTestableExtensibleDefaultProviderSelectionStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractTestableExtensibleDefaultProviderSelectionStrategy.java deleted file mode 100644 index 028da9766..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/AbstractTestableExtensibleDefaultProviderSelectionStrategy.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jst.jsf.common.internal.policy.IdentifierOrderedIteratorPolicy; - -/** - * Will select in order the testable, then extension-point, then default strategies. - * <p> - * Users should use addTestableStrategy(), addExtensionStrategy(), and addDefaultStrategy() and <b>NOT</b> addStrategy() - * <p> - * Users must supply a defaultStrategy at minimum; - * <p> - * @param <INPUT> - * @param <OUTPUT> - */ -public abstract class AbstractTestableExtensibleDefaultProviderSelectionStrategy<INPUT, OUTPUT> - extends - IteratorPolicyBasedStrategyComposite<INPUT, OUTPUT, OUTPUT, String, IIdentifiableStrategy<INPUT, OUTPUT, String>> { - - private static final String TEST_STRATEGY_ID = "testInjection"; //$NON-NLS-1$ - /** - * LocatorProviderStrategy id for extension-pt - */ - private static final String EXT_PT_STRATEGY_ID = "extensionPointInjection"; //$NON-NLS-1$ - /** - * LocatorProviderStrategy id for platform default - */ - private static final String DEFAULT_STRATEGY_ID = "platformDefault"; //$NON-NLS-1$ - - /** - * Contructor - */ - protected AbstractTestableExtensibleDefaultProviderSelectionStrategy() { - super(new MyIteratorPolicy()); - } - - @Override - public OUTPUT getNoResult() { - return null; - } - - /** - * @param testStrategy - */ - public void addTestableStrategy(final ISimpleStrategy<INPUT, OUTPUT> testStrategy) { - super.addStrategy(new IdententifiableStrategyWrapper(testStrategy, TEST_STRATEGY_ID)); - } - - /** - * @param extensionStrategy - */ - public void addExtensionStrategy(final ISimpleStrategy<INPUT, OUTPUT> extensionStrategy) { - super.addStrategy(new IdententifiableStrategyWrapper(extensionStrategy, EXT_PT_STRATEGY_ID)); - } - - /** - * @param defaultStrategy - */ - public void addDefaultStrategy(final ISimpleStrategy<INPUT, OUTPUT> defaultStrategy) { - super.addStrategy(new IdententifiableStrategyWrapper(defaultStrategy, DEFAULT_STRATEGY_ID)); - } - - private class IdententifiableStrategyWrapper<INPUT, OUTPUT, String> implements IIdentifiableStrategy<INPUT, OUTPUT, String> { - - private ISimpleStrategy<INPUT, OUTPUT> _innerStrategy; - private String _id; - - IdententifiableStrategyWrapper(final ISimpleStrategy<INPUT, OUTPUT> innerStrategy, final String id) { - _innerStrategy = innerStrategy; - _id = id; - } - - public OUTPUT perform(INPUT input) throws Exception { - return _innerStrategy.perform(input); - } - - public OUTPUT getNoResult() { - return null; - } - - public String getId() { - return _id; - } - - public java.lang.String getDisplayName() { - return null; - } - - } - private static class MyIteratorPolicy extends - IdentifierOrderedIteratorPolicy<String> { - - private static List<String> _selectionOrder; - - static { - _selectionOrder = new ArrayList<String>(); - _selectionOrder - .add(TEST_STRATEGY_ID); - _selectionOrder - .add(EXT_PT_STRATEGY_ID); - _selectionOrder - .add(DEFAULT_STRATEGY_ID); - } - - public MyIteratorPolicy() { - super(_selectionOrder); - setExcludeNonExplicitValues(true); - } - - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IIdentifiableStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IIdentifiableStrategy.java deleted file mode 100644 index 94cf53d92..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IIdentifiableStrategy.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.strategy; - -import org.eclipse.jst.jsf.common.internal.policy.IIdentifiable; - - -/** - * A simple strategy that is identifiable - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <IDTYPE> - */ -public interface IIdentifiableStrategy<INPUT, OUTPUT, IDTYPE> - extends ISimpleStrategy<INPUT, OUTPUT>, IIdentifiable<IDTYPE> -{ - // nothing added. -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/ISimpleStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/ISimpleStrategy.java deleted file mode 100644 index 787a31090..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/ISimpleStrategy.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.strategy; - -/** - * A strategy that takes an INPUT, performs a calculation on it, and returns - * an OUTPUT - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - */ -public interface ISimpleStrategy<INPUT, OUTPUT> -{ - /** - * Perform the algorithm on input and return OUTPUT. This type of - * operation should avoid side-effects, but may throw exceptions. - * - * @param input - * @return the result of the strategy algorithm - * @throws Exception implementers should narrow what exceptions are thrown. - */ - public OUTPUT perform(INPUT input) throws Exception; - - /** - * @return the single value that perform will return if it cannot calculate - * a meaningful result for an input. The value must be unique, the same - * for all inputs and must be testable using the '==' operator. - */ - public OUTPUT getNoResult(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IteratorPolicyBasedStrategyComposite.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IteratorPolicyBasedStrategyComposite.java deleted file mode 100644 index ff59abbfd..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/IteratorPolicyBasedStrategyComposite.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.strategy; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.common.internal.policy.IIteratorPolicy; - -/** - * A strategy composite that uses an iterator policy to provide the iterator - * used to decide what order to execute the strategy in. - * - * This composite represents a grouping of strategies which represent N ways - * to perform a particular calculation and which any number for those N ways - * may be applicable to any particular situation given the policy in place. - * - * By default, the first such strategy in policy order to provide the calculation - * wins and it's result is returned. You can modify the way the result is composed - * by providing your own composition strategy using the two-arg constructor. - * - * - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <RESULTTYPE> - * @param <IDTYPE> - * @param <STRATEGYTYPE> - */ -public abstract class IteratorPolicyBasedStrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE extends IIdentifiableStrategy<INPUT, OUTPUT, IDTYPE>> - extends StrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE> -{ - private final Map<IDTYPE, STRATEGYTYPE> _strategies; - private IIteratorPolicy<IDTYPE> _policy; - private final Object _changeLock = new Object(); - - /** - * @param policy - */ - protected IteratorPolicyBasedStrategyComposite(final IIteratorPolicy<IDTYPE> policy) - { - super(); - _policy = policy; - _strategies = new LinkedHashMap<IDTYPE, STRATEGYTYPE>(); - } - - /** - * @param policy - * @param compositionStrategy - */ - protected IteratorPolicyBasedStrategyComposite(final IIteratorPolicy<IDTYPE> policy, AbstractCompositionStrategy<INPUT, OUTPUT, RESULTTYPE, STRATEGYTYPE> compositionStrategy) - { - super(compositionStrategy); - _policy = policy; - _strategies = new LinkedHashMap<IDTYPE, STRATEGYTYPE>(); - } - - /** - * Add strategy if not already present. - * - * @param strategy - */ - public final void addStrategy(final STRATEGYTYPE strategy) - { - synchronized(_changeLock) - { - _strategies.put(strategy.getId(), strategy); - } - } - - /** - * @param strategy - */ - public final void removeStrategy(final STRATEGYTYPE strategy) - { - synchronized(_changeLock) - { - _strategies.remove(strategy.getId()); - } - } - - /** - * Change the active policy used to select the order in which the composite - * calls it's child strategies. - * - * If the policy is not set, then strategies are called in - * - * @param policy - */ - public final void setPolicy(final IIteratorPolicy<IDTYPE> policy) - { - // policy may not be null - if (policy == null) - { - JSFCommonPlugin.log(new Exception("stack trace only"), "Policy can't be null"); //$NON-NLS-1$ //$NON-NLS-2$ - return; - } - - // protect access in case getIterator is being called simulataneously - synchronized(_changeLock) - { - _policy = policy; - } - } - - @Override - public final Iterator<STRATEGYTYPE> getIterator() - { - IIteratorPolicy<IDTYPE> policy = null; - Map<IDTYPE, STRATEGYTYPE> strategies = Collections.emptyMap(); - - synchronized(_changeLock) - { - policy = _policy; - strategies = Collections.unmodifiableMap(new HashMap<IDTYPE, STRATEGYTYPE>(_strategies)); - } - - final Iterator<IDTYPE> iterator = policy.getIterator(strategies.keySet()); - return new StrategyIterator<IDTYPE, STRATEGYTYPE>(strategies, iterator); - } - - @Override - public abstract RESULTTYPE getNoResult(); - - private static class StrategyIterator<IDTYPE, STRATEGYTYPE> implements - Iterator<STRATEGYTYPE> - { - private final Map<IDTYPE, STRATEGYTYPE> _map; - private final Iterator<IDTYPE> _policyIterator; - - private StrategyIterator(final Map<IDTYPE, STRATEGYTYPE> map, - final Iterator<IDTYPE> policyIterator) - { - _map = map; - _policyIterator = policyIterator; - } - - public boolean hasNext() - { - return _policyIterator.hasNext(); - } - - public STRATEGYTYPE next() - { - IDTYPE id = _policyIterator.next(); - return _map.get(id); - } - - public void remove() - { - throw new UnsupportedOperationException(); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/MergingCompositionStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/MergingCompositionStrategy.java deleted file mode 100644 index 4e8cb428b..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/MergingCompositionStrategy.java +++ /dev/null @@ -1,213 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jst.jsf.common.internal.strategy.StrategyComposite.AbstractCompositionStrategy; -import org.eclipse.jst.jsf.common.internal.strategy.StrategyComposite.CompositionArguments; - -/** - * A composition strategy that merges the result of all composed strategies. The - * merge policy is left to concrete implementations. Three concrete impls are - * provided: one that uses compose all (List) and one that uses compose unique - * (Set) and a third that uses Map. - * - * @author cbateman - * - * @param <INPUT> - * @param <MERGETYPE> - * @param <STRATEGY> - */ -/** - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <MERGETYPE> - * @param <STRATEGY> - */ -public abstract class MergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> -extends AbstractCompositionStrategy<INPUT, OUTPUT, MERGETYPE, STRATEGY> -{ - /** - * The result of the merge. - */ - protected final MERGETYPE _composedResult; - - /** - * @param composedResult - * @param noResultValue - */ - public MergingCompositionStrategy(final MERGETYPE composedResult, - final MERGETYPE noResultValue) - { - super(); - _composedResult = composedResult; - } - - @Override - public boolean compose(final CompositionArguments<INPUT, OUTPUT, STRATEGY> args) - throws Exception - { - final OUTPUT result = args.getStrategy().perform(args.getInput()); - if (result != args.getStrategy().getNoResult()) - { - doCompose(result); - } - // never stop composing early - return false; - } - - /** - * Sub-classes must implement to do the detail composition for their result - * type. - * - * @param result - */ - protected abstract void doCompose(OUTPUT result); - - @Override - public MERGETYPE getComposedResult() - { - return _composedResult; - } - - @Override - public abstract void reset(); - - /** - * An implementation that uses a List to implement the list policy. The - * result is to add all results from all composed strategies to a single - * list. Duplicates may occur. - * - * @param <INPUT> - * @param <OUTPUT> - * @param <MERGETYPE> - * @param <STRATEGY> - * ` - */ - public static class ListMergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE extends List, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - extends - MergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE, STRATEGY> - { - /** - * @param composedResult - * @param noResultValue - */ - public ListMergingCompositionStrategy(final MERGETYPE composedResult, - final MERGETYPE noResultValue) - { - super(composedResult, noResultValue); - } - - @Override - protected void doCompose(final OUTPUT result) - { - if (result instanceof Collection) - { - _composedResult.addAll((Collection) result); - } else - { - _composedResult.add(result); - } - } - - @Override - public void reset() - { - _composedResult.clear(); - } - } - - /** - * An implementation that uses a List to implement the list policy. The - * result is to add all results from all composed strategies to a single - * list. Duplicates will not occur. - * - * @param <INPUT> - * @param <OUTPUT> - * @param <MERGETYPE> - * @param <STRATEGY> - */ - public static class SetMergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE extends Set, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - extends - MergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE, STRATEGY> - { - /** - * @param composedResult - * @param noResultValue - */ - public SetMergingCompositionStrategy(final MERGETYPE composedResult, - final MERGETYPE noResultValue) - { - super(composedResult, noResultValue); - } - - @Override - protected void doCompose(final OUTPUT result) - { - if (result instanceof Collection) - { - _composedResult.addAll((Collection) result); - } else - { - _composedResult.add(result); - } - } - - @Override - public void reset() - { - _composedResult.clear(); - } - } - - /** - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <MERGETYPE> - * @param <STRATEGY> - */ - public abstract static class MapMergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE extends Map, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - extends - MergingCompositionStrategy<INPUT, OUTPUT, MERGETYPE, STRATEGY> - { - /** - * @param composedResult - * @param noResultValue - */ - public MapMergingCompositionStrategy(final MERGETYPE composedResult, - final MERGETYPE noResultValue) - { - super(composedResult, noResultValue); - } - - @Override - protected void doCompose(final OUTPUT result) - { - if (result instanceof Map) - { - _composedResult.putAll((Map) result); - } else - { - _composedResult.put(calculateKey(result), result); - } - } - - /** - * @param result - * @return the key to be used for result in any composed map. - */ - protected abstract Object calculateKey(final OUTPUT result); - - @Override - public void reset() - { - _composedResult.clear(); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/SimpleStrategyComposite.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/SimpleStrategyComposite.java deleted file mode 100644 index 25c567af7..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/SimpleStrategyComposite.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -/** - * A simple concrete implementation that uses a constructor provided values - * to implement abstract methods. - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <RESULTTYPE> - * @param <IDTYPE> - * @param <STRATEGYTYPE> - */ -public class SimpleStrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE extends IIdentifiableStrategy<INPUT,OUTPUT,IDTYPE>> extends -StrategyComposite<INPUT, OUTPUT, RESULTTYPE, IDTYPE, STRATEGYTYPE> -{ - - private final RESULTTYPE _noResultValue; - private final Collection<STRATEGYTYPE> _strategies; - - /** - * Use the list of strategies and null as the no result value. - * @param strategies - */ - public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies) - { - this(strategies, (RESULTTYPE) null); - } - /** - * Use the list of strategies and the provided no result value. - * @param strategies - * @param noResultValue - */ - public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies, final RESULTTYPE noResultValue) - { - super(); - _strategies = strategies; - _noResultValue = noResultValue; - } - - /** - * Use the provided strategies, composition strategy and null for the no result value - * @param strategies - * @param compositionStrategy - */ - public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies, - final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTTYPE, STRATEGYTYPE> compositionStrategy) - { - this(strategies, null, compositionStrategy); - } - - /** - * Use the provided strategies, composition strategy and null for the no result value - * @param strategies - * @param noResultValue - * @param compositionStrategy - */ - public SimpleStrategyComposite(final Collection<STRATEGYTYPE> strategies, final RESULTTYPE noResultValue, - final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTTYPE, STRATEGYTYPE> compositionStrategy) - { - super(compositionStrategy); - _strategies = strategies; - _noResultValue = noResultValue; - } - - @Override - public RESULTTYPE getNoResult() - { - return _noResultValue; - } - - @Override - public Iterator<STRATEGYTYPE> getIterator() - { - return Collections.unmodifiableCollection(_strategies).iterator(); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/StrategyComposite.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/StrategyComposite.java deleted file mode 100644 index c7842c038..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/StrategyComposite.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.strategy; - -import java.util.Iterator; - -import org.eclipse.jst.jsf.common.JSFCommonPlugin; - -/** - * A composite strategy whos role is to iterate through a number of child - * stategies until one returns a valid value for an input. - * - * @author cbateman - * - * @param <INPUT> - * @param <OUTPUT> - * @param <RESULTOUTPUT> - * @param <IDTYPE> - * @param <STRATEGYTYPE> - */ -public abstract class StrategyComposite<INPUT, OUTPUT, RESULTOUTPUT, IDTYPE, STRATEGYTYPE extends IIdentifiableStrategy<INPUT, OUTPUT, IDTYPE>> -implements ISimpleStrategy<INPUT, RESULTOUTPUT> -{ - private final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGYTYPE> _compositionStrategy; - - /** - * @param compositionStrategy - */ - protected StrategyComposite( - final AbstractCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGYTYPE> compositionStrategy) - { - _compositionStrategy = compositionStrategy; - } - - /** - * Default constructor: composite returns the first value found. - */ - protected StrategyComposite() - { - // by default, the composition strategy selects the first value - this( - new DefaultCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGYTYPE>()); - } - - public final RESULTOUTPUT perform(final INPUT input) - { - final Iterator<STRATEGYTYPE> sIt = getIterator(); - - RESULTOUTPUT result = getNoResult(); - boolean finishedComposing = false; - - EXECUTE_LOOP: while (sIt.hasNext()) - { - final STRATEGYTYPE strategy = sIt.next(); - try - { - finishedComposing = _compositionStrategy - .compose(new CompositionArguments<INPUT, OUTPUT, STRATEGYTYPE>( - strategy, input)); - // returns true if we are done composing - if (finishedComposing) - { - result = _compositionStrategy.getComposedResult(); - break EXECUTE_LOOP; - } - } catch (final Exception e) - { - JSFCommonPlugin.log(e); - } - } - - if (finishedComposing) - { - return result; - } - return getNoResult(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jst.jsf.common.internal.strategy.ISimpleStrategy#getNoResult - * () - */ - public abstract RESULTOUTPUT getNoResult(); - - /** - * @return an iterator that will return the next strategy to be executed - */ - public abstract Iterator<STRATEGYTYPE> getIterator(); - - /** - * @author cbateman - * @param <INPUT> - * @param <OUTPUT> - * @param <RESULTOUTPUT> - * @param <STRATEGY> - */ - public abstract static class AbstractCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - implements ISimpleStrategy<CompositionArguments<INPUT, OUTPUT, STRATEGY>, Boolean> - { - private final Boolean _noResultValue; - - /** - * - */ - protected AbstractCompositionStrategy() - { - _noResultValue = null; - reset(); - } - - /** - * @param input - * @return true if composing is finished based on the input, false - * otherwise - * @throws Exception - */ - public abstract boolean compose(CompositionArguments<INPUT, OUTPUT, STRATEGY> input) throws Exception; - - @SuppressWarnings("boxing") - public final Boolean perform(final CompositionArguments<INPUT, OUTPUT, STRATEGY> input) throws Exception - { - return compose(input); - } - - /** - * @return the result of composing. - */ - public abstract RESULTOUTPUT getComposedResult(); - - public Boolean getNoResult() - { - return _noResultValue; - } - - /** - * Clear any composed result and make strategy reusable as if it were - * newly constructed. This method is only called automatically at construction. - * - * Owners should call to control the contents of their result list. - */ - public abstract void reset(); - } - - /** - * The default composition strategy. This causes the first strategy that returns - * a non-NoResult value to have it's value returned. - * - * @param <INPUT> - * @param <OUTPUT> - * @param <RESULTOUTPUT> - * @param <STRATEGY> - */ - public final static class DefaultCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - extends AbstractCompositionStrategy<INPUT, OUTPUT, RESULTOUTPUT, STRATEGY> - { - private RESULTOUTPUT _result; - - /** - * - */ - public DefaultCompositionStrategy() - { - super(); - } - - @Override - public boolean compose(final CompositionArguments<INPUT, OUTPUT, STRATEGY> arg) throws Exception - { - final OUTPUT result = arg.getStrategy().perform(arg.getInput()); - if (result != arg.getStrategy().getNoResult()) - { - _result = (RESULTOUTPUT)result; - return true; - } - return false; - } - - @Override - public RESULTOUTPUT getComposedResult() - { - return _result; - } - - @Override - public void reset() - { - _result = null; - } - } - - /** - * Bundle values needed by the composing strategies into a single arg object. - * - * @param <INPUT> - * @param <OUTPUT> - * @param <STRATEGY> - */ - public final static class CompositionArguments<INPUT, OUTPUT, STRATEGY extends ISimpleStrategy<INPUT, OUTPUT>> - { - private final STRATEGY _strategy; - private final INPUT _input; - - /** - * @param strategy - * @param input - */ - public CompositionArguments(final STRATEGY strategy, final INPUT input) - { - _strategy = strategy; - _input = input; - } - - /** - * @return the strategy - */ - public STRATEGY getStrategy() - { - return _strategy; - } - - /** - * @return the input - */ - public INPUT getInput() - { - return _input; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableProjectFactoryStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableProjectFactoryStrategy.java deleted file mode 100644 index 7028bf74d..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableProjectFactoryStrategy.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.QualifiedName; - - -/** - * Abstract class that, when given a project session key, - * will provide the instance of OUTPUT to use, or no result - * <p> - * Users need only set the project session property with the key and OUTPUT instance - * @param <OUTPUT> - */ -public abstract class TestableProjectFactoryStrategy<OUTPUT> implements ISimpleStrategy<IProject, OUTPUT> { - private QualifiedName _key; - - /** - * @param testableFactorySessionKey - project property session key for property value holding testable instance - */ - public TestableProjectFactoryStrategy(final QualifiedName testableFactorySessionKey) { - _key = testableFactorySessionKey; - } - - public OUTPUT perform(final IProject project) throws Exception { - if (_key != null && project != null) { - final Object factory = project.getSessionProperties().get(_key); - if (factory != null) - return (OUTPUT)factory; - } - return getNoResult(); - } - - public OUTPUT getNoResult() { - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableResourceFactoryStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableResourceFactoryStrategy.java deleted file mode 100644 index c935e011a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/strategy/TestableResourceFactoryStrategy.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.strategy; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.QualifiedName; - - -/** - * Copy of {@link TestableProjectFactoryStrategy} except that this can accept IResources - * - * An abstract class that, when given a project resource and a project session key, - * will provide the instance of OUTPUT to use, or, - * no result will be returned if the resource is not a project. - * <p> - * Users need only set the project session property with the key and OUTPUT instance - * @param <OUTPUT> - */ -public abstract class TestableResourceFactoryStrategy<OUTPUT> implements ISimpleStrategy<IResource, OUTPUT> { - private QualifiedName _key; - - /** - * @param testableFactorySessionKey - project property session key for property value holding testable instance - */ - public TestableResourceFactoryStrategy(final QualifiedName testableFactorySessionKey) { - _key = testableFactorySessionKey; - } - - public OUTPUT perform(final IResource resource) throws Exception { - if (_key != null && resource != null) { - if (resource instanceof IProject) { - final Object factory = ((IProject)resource).getSessionProperties().get(_key); - if (factory != null) - return (OUTPUT)factory; - } - } - return getNoResult(); - } - - public OUTPUT getNoResult() { - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/BooleanLiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/BooleanLiteralType.java deleted file mode 100644 index 6055e5f50..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/BooleanLiteralType.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.Signature; - -/** - * Represents a BooleanLiteral as defined by JSP.2.9 - * - * @author cbateman - * - */ -public class BooleanLiteralType extends LiteralType -{ - /** - * The literal FALSE singleton - */ - public final static BooleanLiteralType FALSE = new BooleanLiteralType(false); - /** - * The literal TRUE singleton - */ - public final static BooleanLiteralType TRUE = new BooleanLiteralType(true); - - private final boolean _literalValue; - - - /** - * @param value - * @return a constant boolean literal type corresponding to value - */ - public static BooleanLiteralType valueOf(boolean value) - { - return value ? TRUE : FALSE; - } - - /** - * @param literalValue - */ - /*package*/BooleanLiteralType(boolean literalValue) - { - super(Signature.SIG_BOOLEAN); - _literalValue = literalValue; - } - - public Number coerceToNumber(Class T) throws TypeCoercionException - { - // illegal to coerce boolean to number per JSP.2.8.3 step 3 - throw new TypeCoercionException("Cannot coerce boolean to number"); //$NON-NLS-1$ - } - - public String getLiteralValue() - { - return Boolean.toString(_literalValue); - } - - public Object getLiteralValueRaw() - { - return Boolean.valueOf(_literalValue); - } - - public Boolean coerceToBoolean() throws TypeCoercionException - { - return Boolean.valueOf(_literalValue); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeType.java deleted file mode 100644 index 9069f056d..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeType.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.Signature; - - -/** - * Encapsulates the runtime type or types of a JSF entity in a - * way that can be compared to other entities - * - * @author cbateman - * - */ -public class CompositeType -{ - private final String[] _signatures; - private final int _assignmentType; - - private boolean[] _isTypeSignature; // = null lazily derived from signatures - // on first access - /** - * @param signatureStrings - * @param assignmentType - */ - public CompositeType(String[] signatureStrings, int assignmentType) - { - if (signatureStrings == null - || signatureStrings.length < 1) - { - throw new AssertionError("Must specify at least one signature string"); //$NON-NLS-1$ - } - - _signatures = new String[signatureStrings.length]; - System.arraycopy(signatureStrings, 0, _signatures, 0, _signatures.length); - _assignmentType = assignmentType; - } - - /** - * Convenience constructor for most common case where composite only - * consistes of a single type signature - * - * @param signatureString - * @param assignmentType - */ - public CompositeType(String signatureString, int assignmentType) - { - this(new String[]{signatureString}, assignmentType); - } - /** - * @return the assignment type mask - */ - public int getAssignmentTypeMask() - { - return _assignmentType; - } - - /** - * @return true if the composite type supports being on the LHS of an - * assignment - */ - public boolean isLHS() - { - return TypeUtil.matchesLHS(_assignmentType); - } - - /** - * @return true if the composite type supports being on the RHS of an - * assignment - */ - public boolean isRHS() - { - return TypeUtil.matchesRHS(_assignmentType); - } - - /** - * @return an array of booleans. The value in each index of the array - * is true if the corresponding position _signatures corresponds to a type - * signature and false if it's a method signature - */ - public boolean[] getIsTypeSignature() - { - return getTypeSignatureFlags(); - } - - /** - * @return the type signatures. Changes to the returned form do not - * affect the internal values - */ - public String[] getSignatures() - { - final String[] copy = new String[_signatures.length]; - System.arraycopy(_signatures, 0, copy, 0, _signatures.length); - return copy; - } - - public String toString() - { - final StringBuffer stringBuffer = new StringBuffer(); - - for (int i = 0; i < _signatures.length; i++) - { - stringBuffer.append(_signatures[i]); - stringBuffer.append(" | "); //$NON-NLS-1$ - } - - return stringBuffer.toString(); - } - - /** - * @return a version of to string with of the type signatures replaced - * with their more Javaeseque names - */ - public String toUserReadableString() - { - final StringBuffer stringBuffer = new StringBuffer(); - - for (int i = 0; i < _signatures.length; i++) - { - final String signature = _signatures[i]; - - if (getTypeSignatureFlags()[i]) - { - stringBuffer.append(Signature.getSignatureSimpleName(signature)); - } - - if (i < _signatures.length -1) - { - stringBuffer.append(", "); //$NON-NLS-1$ - } - } - return stringBuffer.toString(); - } - - private boolean[] getTypeSignatureFlags() - { - if (_isTypeSignature == null) - { - _isTypeSignature = new boolean[_signatures.length]; - - for (int i = 0; i < _signatures.length; i++) - { - try - { - Signature.getTypeSignatureKind(_signatures[i]); - - // if an exception wasn't thrown above, then it - // is some sort of type signature - _isTypeSignature[i] = true; - } - catch (IllegalArgumentException ae) - { - // getTypeSignatureKind threw an exception, so - // this signature is a method - _isTypeSignature[i] = false; - } - } - } - - return _isTypeSignature; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeTypeCoercer.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeTypeCoercer.java deleted file mode 100644 index 5f2aff492..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/CompositeTypeCoercer.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - - -/** - * Follows type coercion rules codified in section JSP.2.8 of the - * JSP 2.0 Specification. - * - * This class operates on CompositeType's and returns raw - * Java signatures for the single resulting type coercion. - * - * The rules are stretched a little bit since JSP.2.8 defines how to - * coerce an *instance* A to a type T. But since we have no runtime instances, - * only their types, we approximate by taking what we know about the type of A - * and coercing it T as best we can. - * - * Also, whereas the spec says to throw errors when coercion is not possible, - * we have two cases: - * - * 1) We can determine definitively that there is no coercion - * 2) We cannot determine whether there is or isn't a coercion - * - * In case 1, we always throw an exception. In case 2, we return null to indicate - * "indeterminate" result, rather than error. - * - * @author cbateman - * - */ -public class CompositeTypeCoercer -{ - /** - * This method follows JSP.2.8.3 except that rather than returning a specific - * type that has been coerced to, it determines the most exact possible type - * that typeOfA can be coerced to, to be number compatible. The caller must - * decide what do with the return value compared to the type (N in the spec) - * that they want to coerce to. - * - * @param typeOfA - * @return a new signature for the type of A after being coerced to a Number - * @throws TypeCoercionException if A can definitively not be coerced to - * a number - */ - public static String coerceToNumber(final CompositeType typeOfA) - throws TypeCoercionException - { - String coercedType = null; - boolean errorDetected = true; // assume error: only false if we - // find a member of typeOfA that - // coerces to number - - // JSP.2.8.1 -- auto-box primitives - final CompositeType boxedTypeOfA = - TypeTransformer.transformBoxPrimitives(typeOfA); - final boolean[] typesigs = boxedTypeOfA.getIsTypeSignature(); - - // iterate through all of the signatures that represent types - // and find at least one that can be coerced to a number - for (int i = 0; i < typesigs.length; i++) - { - if (typesigs[i]) - { - try - { - final String testType = - TypeCoercer.coerceToNumber(boxedTypeOfA.getSignatures()[i]); - - if (testType != null) - { - // if we have already found a coercible type, then - // we need to return null, since we have a conflict that - // we don't know how to resolve to a type?????? - if (coercedType != null) - { - return null; - } - - coercedType = testType; - } - errorDetected = false; // we have found a number coercion or indeterminate - } - catch (TypeCoercionException tce) - { - // do nothing: so far error still detected - } - } - } - - // we have three choices: - // 1: if errorDetected was never cleared, we definitely never found - // a coerceable type, so throw exception - if (errorDetected) - { - throw new TypeCoercionException(); - } - - // otherwise the flag was cleared return what we found - if (coercedType != null) - { - // need to unbox per JSP.2.8.1 - coercedType = - TypeTransformer.transformUnboxPrimitives(coercedType); - } - - return coercedType; - } - - -// public static String coerceToBoolean(CompositeType compositeType) -// { -// -// } - -}
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/FloatLiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/FloatLiteralType.java deleted file mode 100644 index 5631b8700..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/FloatLiteralType.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.eclipse.jdt.core.Signature; - -/** - * Represents an FloatLiteral as defined by JSP.2.9 - * @author cbateman - * - */ -public class FloatLiteralType extends NumericTypeLiteral -{ - private final double _literalValue; - - /** - * @param literalValue - */ - public FloatLiteralType(double literalValue) - { - // according to the notes to JSP.2.9, bullet 5, float literals are doubles - super(Signature.SIG_DOUBLE); - _literalValue = literalValue; - } - - protected Number getBoxedValue() - { - return new Double(_literalValue); - } - - public Number coerceToNumber(Class T) throws TypeCoercionException - { - if (T == BigInteger.class) - { - return new BigDecimal(_literalValue).toBigInteger(); - } - else if (T == BigDecimal.class) - { - return new BigDecimal(_literalValue); - } - - Number commonCoercion = super.coerceToNumber(T); - - if (commonCoercion == null) - { - throw new IllegalArgumentException("Not a target numeric type: "+T); //$NON-NLS-1$ - } - - return commonCoercion; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IAssignable.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IAssignable.java deleted file mode 100644 index 8b74dfd85..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IAssignable.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -/** - * Defines the lhs/rhs rules for a type - * @author cbateman - * - */ -public interface IAssignable -{ - /** - * Type is none: it cannot be assigned to. method binding. - */ - public static int ASSIGNMENT_TYPE_NONE = 0x0; - /** - * Type is lhs: it can be assigned to - */ - public static int ASSIGNMENT_TYPE_LHS = 0x1; - - /** - * Type is rhs: it can be assigned from - */ - public static int ASSIGNMENT_TYPE_RHS = 0x2; - - /** - * @return the assigment mask - */ - public int getAssignability(); - - /** - * @return true if ASSIGNMENT_TYPE_LHS is set in getAssignability - */ - public boolean isLHS(); - /** - * @return true if ASSIGNMENT_TYPE_RHS is set in getAssignability - */ - public boolean isRHS(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IntegerLiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IntegerLiteralType.java deleted file mode 100644 index d7a3be803..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/IntegerLiteralType.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.eclipse.jdt.core.Signature; - -/** - * Represents a IntegerLiteral as defined by JSP.2.9 - * @author cbateman - * - */ -public class IntegerLiteralType extends NumericTypeLiteral -{ - /** - * A singleton for zero literals - */ - public final static IntegerLiteralType ZERO = new IntegerLiteralType(0); - - private final long _literalValue; - - /** - * @param literalValue - */ - public IntegerLiteralType(long literalValue) - { - // according to the notes to JSP.2.9, bullet 4, integer literals are longs - super(Signature.SIG_LONG); - _literalValue = literalValue; - } - - protected Number getBoxedValue() - { - return Long.valueOf(_literalValue); - } - - /** - * Per JSP.2.8.3, step 5 - * @see org.eclipse.jst.jsf.common.internal.types.LiteralType#coerceToNumber(java.lang.Class) - */ - public Number coerceToNumber(Class T) throws TypeCoercionException - { - if (T == BigInteger.class) - { - return BigInteger.valueOf(_literalValue); - } - else if (T == BigDecimal.class) - { - return BigDecimal.valueOf(_literalValue); - } - - Number commonCoercion = super.coerceToNumber(T); - - if (commonCoercion == null) - { - throw new IllegalArgumentException("Not a target numeric type: "+T); //$NON-NLS-1$ - } - - return commonCoercion; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/LiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/LiteralType.java deleted file mode 100644 index 3ea6de53c..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/LiteralType.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - - -/** - * Encodes a type signature and a string that has some literal value based on - * the type signature. The class represents only a value object -- no attempt - * is made to assert that the literalValue is really of the type specified. - * - * @author cbateman - * - */ -public abstract class LiteralType extends ValueType -{ - - /** - * Consider a new literal type - * - * @param signature - */ - protected LiteralType(final String signature) - { - super(signature, IAssignable.ASSIGNMENT_TYPE_RHS); - } - - /** - * @return the literal value string (unparsed) - */ - public abstract String getLiteralValue(); - - /** - * @return the actual untranslated literal value as an object - */ - public abstract Object getLiteralValueRaw(); - - /** - * @return the type signature - */ - public final String getSignature() { - return super.getSignature(); - } - - /** - * @return a type signature for the kind of number this literal will coerce - * into when asked to become a number or null if this cannot be determined - * @throws TypeCoercionException if this literal has no legal coercion into - * a number - */ - public String getNumberCoercion() throws TypeCoercionException - { - // always box before coercion - return - TypeCoercer.coerceToNumber( - TypeTransformer.transformBoxPrimitives(getSignature())); - } - - /** - * @param T - * @return a Number coercion of the literal's value, null if indeterminate - * @throws TypeCoercionException if the coercion is illegal - */ - public abstract Number coerceToNumber(Class T) throws TypeCoercionException; - - /** - * @return a Boolean coercion of the literal's value, null if indeterminate - * @throws TypeCoercionException if the coercion is illegal - */ - public abstract Boolean coerceToBoolean() throws TypeCoercionException; -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/Messages.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/Messages.java deleted file mode 100644 index b3db7a5e6..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/Messages.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ -package org.eclipse.jst.jsf.common.internal.types; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * Message bundle - * - */ -public class Messages { - private static final String BUNDLE_NAME = "org.eclipse.jst.jsf.common.internal.types.messages"; //$NON-NLS-1$ - - private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle - .getBundle(BUNDLE_NAME); - - private Messages() { - // no external construction - } - - /** - * @param key - * @return the string for key or !key! if not found - */ - public static String getString(String key) { - try { - return RESOURCE_BUNDLE.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/MethodType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/MethodType.java deleted file mode 100644 index 38e47b0c6..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/MethodType.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -/** - * Signature type for method bindings in an EL expression - * - * @author cbateman - * - */ -public class MethodType implements SignatureBasedType -{ - private final String _methodName; - private final String _signature; - - /** - * @param methodName - * @param signature - */ - public MethodType(final String methodName, final String signature) - { - _methodName = methodName; - _signature = signature; - } - - /** - * @see org.eclipse.jst.jsf.common.internal.types.SignatureBasedType#getSignature() - */ - public String getSignature() - { - return _signature; - } - - /** - * @return the method name signature - */ - public String getMethodName() - { - return _methodName; - } - - public CompositeType toCompositeType() - { - return new CompositeType(_signature, IAssignable.ASSIGNMENT_TYPE_NONE); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NullLiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NullLiteralType.java deleted file mode 100644 index eeb43e69d..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NullLiteralType.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * Represents a NullLiteralType per JSP.2.9 - * - * @author cbateman - * - */ -public class NullLiteralType extends LiteralType -{ - /** - * The singleton null literal - */ - public final static NullLiteralType SINGLETON = new NullLiteralType(); - - /** - * Construct a new null - */ - private NullLiteralType() - { - super(TypeConstants.TYPE_NULL); // use void to indicate null in this situation - } - - /** - * Per JSP.2.8.5 null is always false - * - * @see org.eclipse.jst.jsf.common.internal.types.LiteralType#coerceToBoolean() - */ - public Boolean coerceToBoolean() throws TypeCoercionException - { - return Boolean.FALSE; - } - - /** - * Per JSP.2.8.3, null is always 0 - * - * @see org.eclipse.jst.jsf.common.internal.types.LiteralType#coerceToNumber(java.lang.Class) - */ - public Number coerceToNumber(Class T) throws TypeCoercionException { - if (T == BigInteger.class) - { - return BigInteger.ZERO; - } - else if (T == BigDecimal.class) - { - return new BigDecimal(0.0); - } - else if (T == Double.class || T == Double.TYPE) - { - return new Double(0.0); - } - else if (T == Float.class || T == Float.TYPE) - { - return new Float(0.0); - } - else if (T == Long.class || T == Long.TYPE) - { - return Long.valueOf(0L); - } - else if (T == Integer.class || T == Integer.TYPE) - { - return Integer.valueOf(0); - } - else if (T == Short.class || T == Short.TYPE) - { - return Short.valueOf((short)0); - } - else if (T == Byte.class || T == Byte.TYPE) - { - return Byte.valueOf((byte)0); - } - else - { - throw new IllegalArgumentException("Not a target numeric type: "+T); //$NON-NLS-1$ - } - } - - /** - * Per JSP.2.8.2 null is always an empty string - * @see org.eclipse.jst.jsf.common.internal.types.LiteralType#getLiteralValue() - */ - public String getLiteralValue() - { - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.core.internal.types.LiteralType#getLiteralValueRaw() - */ - public Object getLiteralValueRaw() - { - return null; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NumericTypeLiteral.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NumericTypeLiteral.java deleted file mode 100644 index 8b6acbe05..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/NumericTypeLiteral.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - - -/** - * Common super-type for Float and Integer literals - * @author cbateman - * - */ -public abstract class NumericTypeLiteral extends LiteralType -{ - /** - * @param signature - */ - protected NumericTypeLiteral(String signature) - { - super(signature); - } - - /** - * @return the boxed form of the numeric literal value - */ - protected abstract Number getBoxedValue(); - - public Number coerceToNumber(Class T) throws TypeCoercionException - { - Number boxedLiteralValue = getBoxedValue(); - - if (T == Double.class || T == Double.TYPE) - { - return new Double(boxedLiteralValue.doubleValue()); - } - else if (T == Float.class || T == Float.TYPE) - { - return new Float(boxedLiteralValue.floatValue()); - } - else if (T == Long.class || T == Long.TYPE) - { - return boxedLiteralValue; - } - else if (T == Integer.class || T == Integer.TYPE) - { - return Integer.valueOf(boxedLiteralValue.intValue()); - } - else if (T == Short.class || T == Short.TYPE) - { - return Short.valueOf(boxedLiteralValue.shortValue()); - } - else if (T == Byte.class || T == Byte.TYPE) - { - return Byte.valueOf(boxedLiteralValue.byteValue()); - } - else - { - return null; - } - } - - public String getLiteralValue() - { - return getBoxedValue().toString(); - } - - public Object getLiteralValueRaw() - { - return getBoxedValue(); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.core.internal.types.LiteralType#coerceToBoolean() - */ - public Boolean coerceToBoolean() throws TypeCoercionException { - // JSP.2.8.5 does not provide for number -> boolean coercion - throw new TypeCoercionException("Cannot coerce number to boolean"); //$NON-NLS-1$ - } - - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/SignatureBasedType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/SignatureBasedType.java deleted file mode 100644 index 41e2bb482..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/SignatureBasedType.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -/** - * Defines a signature-based type. Signatures must conform to the JVM - * type signature format as defined in the JVM specs and in the JDT Signature - * class - * - * @author cbateman - * - */ -public interface SignatureBasedType -{ - /** - * @return the signature string - */ - public String getSignature(); - - /** - * @return a version of the this type in CompositeType form - */ - public CompositeType toCompositeType(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/StringLiteralType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/StringLiteralType.java deleted file mode 100644 index 2e887fde9..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/StringLiteralType.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.math.BigDecimal; -import java.math.BigInteger; - -/** - * Represents a StringLiteral as defined by JSP.2.9 - * - * @author cbateman - */ -public class StringLiteralType extends LiteralType -{ - private final String _literalValue; - - /** - * @param value - */ - public StringLiteralType(String value) - { - super(TypeConstants.TYPE_STRING); - _literalValue = value; - } - - public Number coerceToNumber(Class T) throws TypeCoercionException - { - try - { - if (T == BigInteger.class) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return BigInteger.ZERO; - } - return new BigInteger(_literalValue); - } - else if (T == BigDecimal.class) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return new BigDecimal(0.0); - } - return new BigDecimal(_literalValue); - } - else if (T == Double.class || T == Double.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return new Double(0.0); - } - - return Double.valueOf(_literalValue); - } - else if (T == Float.class || T == Float.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return new Float(0.0); - } - return Float.valueOf(_literalValue); - } - else if (T == Long.class || T == Long.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return Long.valueOf(0L); - } - return Long.valueOf(_literalValue); - } - else if (T == Integer.class || T == Integer.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return Integer.valueOf(0); - } - return Integer.valueOf(_literalValue); - } - else if (T == Short.class || T == Short.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return Short.valueOf((short)0); - } - return Short.valueOf(_literalValue); - } - else if (T == Byte.class || T == Byte.TYPE) - { - if ("".equals(_literalValue)) //$NON-NLS-1$ - { - return Byte.valueOf((byte)0); - } - return Byte.valueOf(_literalValue); - } - else - { - throw new IllegalArgumentException("Not a target numeric type: "+T); //$NON-NLS-1$ - } - } - catch (NumberFormatException nfe) - { - throw new TypeCoercionException(nfe); - } - } - - public String getLiteralValue() - { - return _literalValue; - } - - public Object getLiteralValueRaw() - { - return _literalValue; - } - - public Boolean coerceToBoolean() throws TypeCoercionException - { - // JSP.2.8.5 - return Boolean.valueOf(_literalValue); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercer.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercer.java deleted file mode 100644 index fa75a12f9..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercer.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.Signature; - -/** - * Coercer for simple type signatures - * - * @author cbateman - * - */ -public class TypeCoercer -{ - - /** - * Based on JSP.2.8.3 in JSP 2.0 specification - * - * @param boxedTypeSignature -- an auto-boxed type signature - * @return the coerced type or null if cannot be resolved. No unboxing - * is performed on the return. - * @throws TypeCoercionException if boxedTypeSignature is - */ - public static String coerceToNumber(final String boxedTypeSignature) - throws TypeCoercionException - { - String boxedTypeSignature_ = boxedTypeSignature; - - // can't coerce arrays to numbers - if (Signature.getTypeSignatureKind(boxedTypeSignature_) - == Signature.ARRAY_TYPE_SIGNATURE) - { - throw new TypeCoercionException("Cannot coerce arrays to numbers"); //$NON-NLS-1$ - } - // if it's character, pre-coerce to short per step 2 - if (TypeConstants.SIGNATURE_BOXED_CHARACTER.equals(boxedTypeSignature)) - { - boxedTypeSignature_ = TypeConstants.TYPE_BOXED_SHORT; - } - - if (TypeCoercer.typeIsNumeric(boxedTypeSignature_) - || TypeCoercer.typeIsNull(boxedTypeSignature_)) - { - return boxedTypeSignature_; - } - else if (typeIsString(boxedTypeSignature_)) - { - // undetermined a string may or not resolve to a number - // depending on its runtime value - return null; - } - else - { - throw new TypeCoercionException(); - } - } - - /** - * @param boxedTypeSignature - * @return true if type can be coerced to boolean; null if indeterminate - */ - public static boolean canCoerceToBoolean(String boxedTypeSignature) - { - // JSP.2.8.5 -- boolean is always boolean; string is converted by Boolean.valueOf(String) - if (typeIsBoolean(boxedTypeSignature) - || typeIsString(boxedTypeSignature) - || typeIsNull(boxedTypeSignature)) - { - return true; - } - // nothing else really convertible besides null - return false; - } - - /** - * @param typeSignature -- boxed type signature - * @return true if the typeSignature is numeric - */ - public static boolean typeIsNumeric(final String typeSignature) - { - return (TypeConstants.TYPE_BOXED_BYTE.equals(typeSignature) || - TypeConstants.TYPE_BOXED_SHORT.equals(typeSignature) || - TypeConstants.TYPE_BOXED_INTEGER.equals(typeSignature) || - TypeConstants.TYPE_BOXED_LONG.equals(typeSignature) || - TypeConstants.TYPE_BOXED_FLOAT.equals(typeSignature) || - TypeConstants.TYPE_BOXED_DOUBLE.equals(typeSignature) || - TypeConstants.TYPE_BIG_INTEGER.equals(typeSignature) || - TypeConstants.TYPE_BIG_DOUBLE.equals(typeSignature)); - } - - /** - * @param typeSignature - * @return true if the typeSignature represents a String - */ - public static boolean typeIsString(final String typeSignature) - { - return (TypeConstants.TYPE_STRING.equals(typeSignature)); - } - - /** - * @param typeSignature -- boxed type signature - * @return true if the typeSignature represents a boxed boolean - */ - public static boolean typeIsBoolean(final String typeSignature) - { - return (TypeConstants.TYPE_BOXED_BOOLEAN.equals(typeSignature)); - } - - /** - * @param typeSignature - * @return true if type is the EL null type - */ - public static boolean typeIsNull(final String typeSignature) - { - return (TypeConstants.TYPE_NULL.equals(typeSignature)); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercionException.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercionException.java deleted file mode 100644 index aa18bbd12..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeCoercionException.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -/** - * @author cbateman - * - */ -public class TypeCoercionException extends Exception -{ - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * @see java.lang.Exception - */ - public TypeCoercionException() { - super(); - } - - /** - * @param message - * @param cause - * @see java.lang.Exception - */ - public TypeCoercionException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param message - * @see java.lang.Exception - */ - public TypeCoercionException(String message) { - super(message); - } - - /** - * @param cause - * @see java.lang.Exception - */ - public TypeCoercionException(Throwable cause) { - super(cause); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparator.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparator.java deleted file mode 100644 index a57a94bed..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparator.java +++ /dev/null @@ -1,292 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.jdt.core.Signature; - -/** - * Static utility class used to compare two CompositeTypes for compatability - * - * @author cbateman - * - */ -public final class TypeComparator { - private static class SignatureTestResult { - /** - * the diagnostic - */ - private final Diagnostic diagnostic; - /** - * Measure of the probability that the tested signatures were meant to - * match. Larger value means higher probability. - */ - private final int matchQuality; - - /** - * @param diagnostic - * @param matchQuality - - * Measure of the probability that the tested signatures were - * meant to match. Larger value means higher probability. - */ - public SignatureTestResult(final Diagnostic diagnostic, - final int matchQuality) { - super(); - this.diagnostic = diagnostic; - this.matchQuality = matchQuality; - } - } - - private final TypeComparatorDiagnosticFactory _factory; - - /** - * Default Constructor - * @param factory - */ - public TypeComparator(final TypeComparatorDiagnosticFactory factory) - { - _factory = factory; - } - - /** - * @param firstType - * @param secondType - * @return true if firstType is assignable to secondType or vice-versa, - * depending on their assignment and runtime types - */ - public Diagnostic calculateTypeCompatibility( - final CompositeType firstType, final CompositeType secondType) { - // first, box all primitives - final CompositeType boxedFirstType = TypeTransformer - .transformBoxPrimitives(firstType); - final CompositeType boxedSecondType = TypeTransformer - .transformBoxPrimitives(secondType); - - final String[] mustBeSatisfied = boxedFirstType.getSignatures(); - final String[] testSignatures = boxedSecondType.getSignatures(); - List<String> mustbeMethods = Collections.emptyList(); - List<String> mustbeTypes = Collections.emptyList(); - for (final String mustbeSignature : mustBeSatisfied) { - if (TypeUtil.isMethodSignature(mustbeSignature)) { - if (mustbeMethods.isEmpty()) { - mustbeMethods = new ArrayList<String>(mustbeSignature - .length()); - } - mustbeMethods.add(mustbeSignature); - } else { - if (mustbeTypes.isEmpty()) { - mustbeTypes = new ArrayList<String>(mustbeSignature - .length()); - } - mustbeTypes.add(mustbeSignature); - } - } - final boolean mustbeWriteable = firstType.isLHS(); - SignatureTestResult bestResult = null; - for (final String isSignature : testSignatures) { - SignatureTestResult testResult; - if (TypeUtil.isMethodSignature(isSignature)) { - testResult = checkMethodSignature(isSignature, mustbeTypes, - mustbeMethods); - if (testResult.diagnostic.getSeverity() == Diagnostic.OK) { - return testResult.diagnostic; - } - } else { - testResult = checkTypeSignature(isSignature, mustbeTypes, - mustbeMethods, mustbeWriteable); - if (testResult.diagnostic.getSeverity() == Diagnostic.OK) { - return checkAssignability(firstType, secondType); - } - } - if (bestResult == null - || bestResult.matchQuality < testResult.matchQuality) { - bestResult = testResult; - } - } - // TODO: bestResult empty? (should not happen, but who knows... - return bestResult.diagnostic; - } - - private SignatureTestResult checkTypeSignature( - final String isSignature, final List<String> mustbeTypes, - final List<String> mustbeMethods, final boolean mustbeWriteable) { - if (mustbeTypes.isEmpty()) { - final Diagnostic diag = _factory.create_METHOD_EXPRESSION_EXPECTED(); - return new SignatureTestResult(diag, 0); - } - for (final String mustbeSignature : mustbeTypes) { - if (mustbeSignature.equals(isSignature) - || canCoerce(isSignature, mustbeSignature, mustbeWriteable)) { - final Diagnostic diag = Diagnostic.OK_INSTANCE; - return new SignatureTestResult(diag, 5); - } - } - final String[] params = new String[2]; - params[0] = readableSignatures(mustbeTypes); - params[1] = Signature.toString(isSignature); - final Diagnostic diag = _factory.create_INCOMPATIBLE_TYPES(params); - return new SignatureTestResult(diag, 1); - } - - private SignatureTestResult checkMethodSignature( - final String isSignature, final List<String> mustbeTypes, - final List<String> mustbeMethods) { - if (mustbeMethods.isEmpty()) { - final Diagnostic diag = _factory.create_VALUE_EXPRESSION_EXPECTED(); - return new SignatureTestResult(diag, 0); - } - for (final String mustbeSignature : mustbeMethods) { - if (methodSignaturesMatch(mustbeSignature, isSignature)) { - final Diagnostic diag = Diagnostic.OK_INSTANCE; - return new SignatureTestResult(diag, 5); - } - } - final String[] params = new String[2]; - params[0] = readableSignatures(mustbeMethods); - params[1] = Signature - .toString(isSignature, "method", null, false, true); //$NON-NLS-1$ - final Diagnostic diag = _factory.create_INCOMPATIBLE_METHOD_TYPES(params); - return new SignatureTestResult(diag, 1); - } - - private static String readableSignatures(final List<String> signatures) { - StringBuilder res = null; - for (final String sig : signatures) { - String sigText; - if (TypeUtil.isMethodSignature(sig)) { - sigText = Signature.toString(sig, "method", null, false, true); //$NON-NLS-1$ - } else { - sigText = Signature.toString(sig); - } - if (res == null) { - res = new StringBuilder(sigText); - } else { - res.append(", ").append(sigText); //$NON-NLS-1$ - } - } - return res != null ? res.toString() : "[no signature]"; //$NON-NLS-1$ - } - - private static boolean canCoerce(final String testType, - final String checkType, final boolean checkTypeIsWritable) { - boolean canCoerce = canCoerce(testType, checkType); - - // if the check type is writable, we need to be sure that the - // coercion can work in both directions - if (canCoerce && checkTypeIsWritable) { - // reverse roles: can checkType assign back to test type? - canCoerce &= canCoerce(checkType, testType); - } - - return canCoerce; - } - - private static boolean canCoerce(final String testType, - final String checkType) { - // can always to coerce to string or object - if (TypeCoercer.typeIsString(checkType)/* - || TypeConstants.TYPE_JAVAOBJECT.equals(checkType)*/) - { - return true; - } else if (TypeCoercer.typeIsNumeric(checkType)) { - return canCoerceNumeric(testType); - } else if (TypeCoercer.typeIsBoolean(checkType)) { - return TypeCoercer.canCoerceToBoolean(testType); - } - - // otherwise, no type coercion available - return false; - } - - private static boolean canCoerceNumeric(final String testType) { - try { - TypeCoercer.coerceToNumber(testType); - // TODO: there is a case when coerceToNumber returns - // null meaning "not sure", that we may want to handle - // differently, with a warning - return true; - } catch (final TypeCoercionException tce) { - // outright failure -- can't coerce - return false; - } - } - - private static boolean methodSignaturesMatch(final String firstMethodSig, - final String secondMethodSig) { - // TODO: need to account for primitive type coercions - if (firstMethodSig.equals(secondMethodSig)) { - return true; - } - final String[] firstMethodParams = Signature - .getParameterTypes(firstMethodSig); - final String[] secondMethodParams = Signature - .getParameterTypes(secondMethodSig); - - // fail fast if param count doesn't match - if (firstMethodParams.length != secondMethodParams.length) { - return false; - } - - // now check each parameter - for (int i = 0; i < firstMethodParams.length; i++) { - // need to box primitives before comparing - final String firstMethodParam = TypeTransformer - .transformBoxPrimitives(firstMethodParams[i]); - final String secondMethodParam = TypeTransformer - .transformBoxPrimitives(secondMethodParams[i]); - - if (!firstMethodParam.equals(secondMethodParam)) { - return false; - } - } - - // if we get to here then we need only check the return type - final String firstReturn = TypeTransformer - .transformBoxPrimitives(Signature.getReturnType(firstMethodSig)); - final String secondReturn = TypeTransformer - .transformBoxPrimitives(Signature - .getReturnType(secondMethodSig)); - - if (!firstReturn.equals(secondReturn)) { - return false; - } - - // if we get to here, then everything checks out - return true; - } - - /** - * Precond: both firstType and secondType must represent value bindings. - * - * @param firstType - * @param secondType - * @return a diagnostic validating that the two composite have compatible - * assignability - */ - private Diagnostic checkAssignability(final CompositeType firstType, - final CompositeType secondType) { - if (firstType.isRHS() && !secondType.isRHS()) { - return _factory.create_PROPERTY_NOT_READABLE(); - } - - if (firstType.isLHS() && !secondType.isLHS()) { - return _factory.create_PROPERTY_NOT_WRITABLE(); - } - - return Diagnostic.OK_INSTANCE; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorDiagnosticFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorDiagnosticFactory.java deleted file mode 100644 index 23d2cccc0..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorDiagnosticFactory.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.emf.common.util.BasicDiagnostic; -import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.osgi.util.NLS; - -/** - * Diagnostic Factory for type comparator diagnostics. - * - * @author cbateman - * - */ -public final class TypeComparatorDiagnosticFactory -{ - /** - * The id used in the source field of all Diagnostic's created by this - * factory to uniquely identify TypeComparator validation as their source - * type. - */ - public final static String SOURCE_IDENTIFIER = "org.eclipse.jst.jsf.common.types.TypeComparator"; //$NON-NLS-1$ - - /** - * A method expression was expected, but something else (i.e. a value - * expression) was provided. - */ - public final static int METHOD_EXPRESSION_EXPECTED_ID = 0; - - /** - * Value expression type was incompatible with the expected type. - */ - public static final int INCOMPATIBLE_TYPES_ID = 1; - - /** - * A value expression was expected, but something else (i.e. a method - * expression) was provided. - */ - public static final int VALUE_EXPRESSION_EXPECTED_ID = 2; - - /** - * Method expression signature did not match what was expected. - */ - public static final int INCOMPATIBLE_METHOD_TYPES_ID = 3; - - /** - * A property was expected to be readable but no getter was found. - */ - public static final int PROPERTY_NOT_READABLE_ID = 4; - - /** - * A property was expected to be writable but no setter was found - */ - public static final int PROPERTY_NOT_WRITABLE_ID = 5; - - /** - * the number of diagnostic ids - */ - public static final int NUM_IDS = 6; - - private final TypeComparatorPreferences _prefs; - - /** - * @param prefs - */ - public TypeComparatorDiagnosticFactory(final TypeComparatorPreferences prefs) - { - _prefs = prefs; - } - // A method expression was supplied as expected, but its signature did - // * not match the expected. - /** - * @return a diagnostic - */ - public Diagnostic create_METHOD_EXPRESSION_EXPECTED() - { - return create(METHOD_EXPRESSION_EXPECTED_ID, Messages - .getString("TypeComparator.Expression.No_Method")); //$NON-NLS-1$ - } - - /** - * @param params - * @return a diagnostic - */ - public Diagnostic create_INCOMPATIBLE_TYPES(final Object[] params) - { - return create( - INCOMPATIBLE_TYPES_ID, - NLS - .bind( - Messages - .getString("TypeComparator.Expression.Incompatible_Value"), params)); //$NON-NLS-1$ - } - - /** - * @return a diagnostic - */ - public Diagnostic create_VALUE_EXPRESSION_EXPECTED() - { - return create(VALUE_EXPRESSION_EXPECTED_ID, Messages - .getString("TypeComparator.Expression.No_Value")); //$NON-NLS-1$ - } - - /** - * @param params - * @return a diagnostic - */ - public Diagnostic create_INCOMPATIBLE_METHOD_TYPES(final Object[] params) - { - return create(INCOMPATIBLE_METHOD_TYPES_ID, NLS.bind(Messages - .getString("TypeComparator.Expression.Incompatible_Method"), //$NON-NLS-1$ - params)); - } - - /** - * @return a diagnostic - */ - public Diagnostic create_PROPERTY_NOT_READABLE() - { - return create(PROPERTY_NOT_READABLE_ID, Messages - .getString("TypeComparator.Expression.Not.Gettable")); //$NON-NLS-1$ - } - - /** - * @return a diagnostic - */ - public Diagnostic create_PROPERTY_NOT_WRITABLE() - { - return create(PROPERTY_NOT_WRITABLE_ID, Messages - .getString("TypeComparator.Expression.Expected.Settable")); //$NON-NLS-1$ - } - - private BasicDiagnostic create(int diagnosticId, String message) - { - final int severity = _prefs.getDefaultSeverity(diagnosticId); - return new BasicDiagnostic(severity, SOURCE_IDENTIFIER, diagnosticId, message, - null); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorPreferences.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorPreferences.java deleted file mode 100644 index 49f63bc6a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeComparatorPreferences.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.emf.common.util.Diagnostic; - -/** - * Preference info for type comparator diagnostics - * - * @author cbateman - * - */ -public class TypeComparatorPreferences -{ - - /** - * @param diagnosticId - * @return the default severity of a diagnostic - */ - public int getDefaultSeverity(final int diagnosticId) - { - switch (diagnosticId) - { - case TypeComparatorDiagnosticFactory.METHOD_EXPRESSION_EXPECTED_ID: - return Diagnostic.ERROR; - case TypeComparatorDiagnosticFactory.INCOMPATIBLE_TYPES_ID: - return Diagnostic.INFO; - case TypeComparatorDiagnosticFactory.VALUE_EXPRESSION_EXPECTED_ID: - return Diagnostic.ERROR; - case TypeComparatorDiagnosticFactory.INCOMPATIBLE_METHOD_TYPES_ID: - return Diagnostic.ERROR; - case TypeComparatorDiagnosticFactory.PROPERTY_NOT_READABLE_ID: - return Diagnostic.WARNING; - case TypeComparatorDiagnosticFactory.PROPERTY_NOT_WRITABLE_ID: - return Diagnostic.WARNING; - default: - throw new IllegalArgumentException("Diagnostic Id: "+ diagnosticId +" is out of range"); //$NON-NLS-1$ //$NON-NLS-2$ - - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeConstants.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeConstants.java deleted file mode 100644 index 4561f6d3c..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeConstants.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -/** - * @author cbateman - * - */ -public class TypeConstants -{ - /** - * we overload "void" to represent null - */ - public final static String TYPE_NULL = "V"; //$NON-NLS-1$ - /** - * unboxed boolean - */ - public final static String TYPE_BOOLEAN = "Z"; //$NON-NLS-1$ - /** - * string type - */ - public final static String TYPE_STRING = "Ljava.lang.String;"; //$NON-NLS-1$ - /** - * big integer - */ - public final static String TYPE_BIG_INTEGER = "Ljava.math.BigInteger;"; //$NON-NLS-1$ - - /** - * big double - */ - public final static String TYPE_BIG_DOUBLE = "Ljava.math.BigDecimal;"; //$NON-NLS-1$ - - /* boxed types */ - /** - * Boxed byte - */ - public final static String TYPE_BOXED_BYTE = "Ljava.lang.Byte;"; //$NON-NLS-1$ - /** - * Boxed short - */ - public final static String TYPE_BOXED_SHORT = "Ljava.lang.Short;"; //$NON-NLS-1$ - /** - * Boxed int - */ - public final static String TYPE_BOXED_INTEGER = "Ljava.lang.Integer;"; //$NON-NLS-1$ - /** - * Boxed long - */ - public final static String TYPE_BOXED_LONG = "Ljava.lang.Long;"; //$NON-NLS-1$ - /** - * Boxed float - */ - public final static String TYPE_BOXED_FLOAT = "Ljava.lang.Float;"; //$NON-NLS-1$ - /** - * Boxed double - */ - public final static String TYPE_BOXED_DOUBLE = "Ljava.lang.Double;"; //$NON-NLS-1$ - /** - * Boxed boolean - */ - public final static String TYPE_BOXED_BOOLEAN = "Ljava.lang.Boolean;"; //$NON-NLS-1$ - /** - * Boxed char - */ - public final static String SIGNATURE_BOXED_CHARACTER = "Ljava.lang.Character"; //$NON-NLS-1$ - /** - * Map type - */ - public final static String TYPE_MAP = "Ljava.util.Map;"; //$NON-NLS-1$ - /** - * Collection type - */ - public final static String TYPE_COLLECTION = "Ljava.util.Collection;"; //$NON-NLS-1$ - /** - * Comparable type - */ - public final static String TYPE_COMPARABLE = "Ljava.lang.Comparable;"; //$NON-NLS-1$ - - /** - * List type - */ - public final static String TYPE_LIST = "Ljava.util.List;"; //$NON-NLS-1$ - - /** - * java.lang.Object type signature - */ - public static final String TYPE_JAVAOBJECT = "Ljava.lang.Object;"; //$NON-NLS-1$ - /** - * Type signature for the JSF Data Model type - */ - public static final String TYPE_DATA_MODEL = "Ljavax.faces.model.DataModel;"; //$NON-NLS-1$ - /** - * Type signature for the Result Set type - */ - public static final String TYPE_RESULT_SET = "Ljava.sql.ResultSet;"; //$NON-NLS-1$ - /** - * Type signature for the JSTL ResultSet type - */ - public static final String TYPE_JAVAX_SERVLET_JSP_JSTL_SQL_RESULT = "Ljavax.servlet.jsp.jstl.sql.Result;"; //$NON-NLS-1$ - /** - * Type signature of the base type of all enum types - */ - public static final String TYPE_ENUM_BASE = "Ljava.lang.Enum;"; //$NON-NLS-1$ -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfo.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfo.java deleted file mode 100644 index d514f4236..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfo.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.IType; -import org.eclipse.jst.jsf.context.symbol.IBeanMethodSymbol; -import org.eclipse.jst.jsf.context.symbol.IBeanPropertySymbol; - -/**This class contains all info that is cached for a given IType. - * @see org.eclipse.jst.jsf.common.internal.types.TypeInfoCache - * - * @author Matthias - */ -class TypeInfo { - - /**Empty String array. Used for the (usual) case when a type has no missing supertypes. - */ - public static String[] NO_NAMES = new String[0]; - - private IBeanMethodSymbol[] methods = null; - private IBeanPropertySymbol[] properties = null; - private IType[] supertypes = null; - private IType[] interfaceTypes = null; - private String[] missingSupertypeNames = null; - - /**Creates an empty TypeInfo object - */ - public TypeInfo() { - super(); - } - - /**Returns the method symbols. Returns <code>null</code> if none have been cached. - * @return the method symbols. May be null. - */ - public IBeanMethodSymbol[] getMethodSymbols() { - return methods; - } - - /**Returns the property symbols. Returns <code>null</code> if none have been cached. - * @return the property symbols. May be null. - */ - public IBeanPropertySymbol[] getPropertySymbols() { - return properties; - } - - /**Sets the methods symbols to be cached. - * @param methods - the method symbols - */ - public void setMethodSymbols(IBeanMethodSymbol[] methods) { - this.methods = methods; - } - - /**Sets the property symbols to be cached. - * @param properties - the property symbols - */ - public void setPropertySymbols(IBeanPropertySymbol[] properties) { - this.properties = properties; - } - - /**Returns the supertypes. Returns <code>null</code> if none have been cached. - * @return the supertypes. May be null. - */ - public IType[] getSupertypes() { - return supertypes; - } - - /**Sets the supertypes to be cached. - * @param superTypes - the property symbols - */ - public void setSupertypes(IType[] superTypes) { - this.supertypes = superTypes; - } - - /**Returns the interface types. Returns <code>null</code> if none have been cached. - * @return the interface types. May be null. - */ - public IType[] getInterfaceTypes() { - return interfaceTypes; - } - - /**Sets the interface types to be cached. - * @param interfaceTypes - the property symbols - */ - public void setInterfaceTypes(IType[] interfaceTypes) { - this.interfaceTypes = interfaceTypes; - } - - /**Returns the names of the missing supertypes. Returns <code>null</code> if none have been cached. - * @return the names of the missing supertypes. May be null. - */ - public String[] getMissingSupertypeNames() { - return missingSupertypeNames; - } - - /**Sets the supertypes to be cached. - * @param missingSupertypeNames - the names of the missing supertypes - */ - public void setMissingSupertypeNames(String[] missingSupertypeNames) { - this.missingSupertypeNames = missingSupertypeNames; - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfoCache.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfoCache.java deleted file mode 100644 index c58f31ce1..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeInfoCache.java +++ /dev/null @@ -1,603 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.common.internal.types; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.ITypeHierarchy; -import org.eclipse.jdt.core.ITypeRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsf.common.JSFCommonPlugin; -import org.eclipse.jst.jsf.context.symbol.IBeanMethodSymbol; -import org.eclipse.jst.jsf.context.symbol.IBeanPropertySymbol; - -/**Provides a cache for java IType properties. It can cache bean property symbols, method symbols, - * supertypes and implemented interfaces per IType. The cache listens to changes in the java model - * and invalidates affected properties, but does not update them. - * - * @author Matthias - */ -public class TypeInfoCache implements IElementChangedListener { - - private static TypeInfoCache instance = null; - - /**Returns the TypeInfoCache instance. This instance is considered - * protected and must not be disposded with disposeInstance. - * - * @return the TypeInfoCache instance - */ - public static synchronized TypeInfoCache getInstance() { - if (instance == null) { - instance = createNewInstance(); - } - return instance; - } - - /** - * Create a new instance of the type cache. - * - * @return a new instance of the type info cache. - */ - public static TypeInfoCache createNewInstance() - { - final TypeInfoCache newCache = new TypeInfoCache(); - JavaCore.addElementChangedListener(newCache, ElementChangedEvent.POST_CHANGE); - return newCache; - } - - /** - * If cache is not the singleton instance acquired with {@link #getInstance()} - * then the cache will be disposed and should not be used. If cache is - * protected instance, then nothing will happen (the singleton instance - * cannot be disposed). - * - * @param cache - */ - public static void disposeInstance(final TypeInfoCache cache) - { - if (cache != null - && cache != instance) - { - JavaCore.removeElementChangedListener(cache); - - synchronized(cache) - { - if (cache.cachedInfo != null) - { - cache.cachedInfo.clear(); - } - - if (cache.cachedTypesByAffectingTypeRoot != null) - { - cache.cachedTypesByAffectingTypeRoot.clear(); - } - - if (cache.cachedTypesByMissingSupertypename != null) - { - cache.cachedTypesByMissingSupertypename.clear(); - } - } - } - } - - private final Map<IType, TypeInfo> cachedInfo; - private final Map<ITypeRoot, Set<IType>> cachedTypesByAffectingTypeRoot; - private final Map<String, Set<IType>> cachedTypesByMissingSupertypename; - - private TypeInfoCache() { - cachedInfo = new HashMap<IType, TypeInfo>(); - cachedTypesByAffectingTypeRoot = new HashMap(); - cachedTypesByMissingSupertypename = new HashMap(10); - } - - public void elementChanged(ElementChangedEvent event) { - updateChangedJavaElement(event.getDelta()); - } - - /**Returns the cached info({@link TypeInfo}) for a given type. Will - * return <code>null</code> if no info has been cached or the the type/something it depends on - * has changed since then. - * - * @param type - the type in question - * @return a TypeInfo instance that contains all cached info for the given type. May be null. - */ - protected TypeInfo getTypeInfo(IType type) { - TypeInfo info = null; - if (type != null) - { - info = cachedInfo.get(type); - } - return info; - } - - /**Returns the cached bean property symbols for a given type. Will return null if no - * bean property symbols have been cached or the type/something it depends on has changed since - * then. - * @param beanType - the bean type in question - * @return the bean property symbols for the given type. May be null. - * @see TypeInfoCache#cachePropertySymbols(IType, IBeanPropertySymbol[]) - */ - public synchronized IBeanPropertySymbol[] getCachedPropertySymbols(IType beanType) { - IBeanPropertySymbol[] props = null; - - if (beanType != null) - { - TypeInfo typeInfo = getTypeInfo(beanType); - if (typeInfo != null) - { - props = typeInfo.getPropertySymbols(); - } - } - return props; - } - - /**Returns the cached method symbols for a given type. Will return null if no - * method symbols have been cached or the type/something it depends on has changed since - * then. - * @param beanType - the bean type in question - * @return the method symbols for the given type. May be null. - * @see TypeInfoCache#cacheMethodSymbols(IType, IBeanMethodSymbol[]) - */ - public synchronized IBeanMethodSymbol[] getCachedMethodSymbols(IType beanType) { - IBeanMethodSymbol[] methods = null; - - if (beanType != null) - { - TypeInfo typeInfo = getTypeInfo(beanType); - if (typeInfo != null) - { - methods = typeInfo.getMethodSymbols(); - } - } - - return methods; - } - - /**Returns the cached supertypes for a given type. Will return null if no supertypes - * have been cached for this type or if the type/something it depends on has changed since - * then. - * @param type - the bean type in question - * @return the supertypes for the given type. May be null. - * @see TypeInfoCache#cacheSupertypesFor(IType) - */ - public synchronized IType[] getCachedSupertypes(IType type) { - IType[] types = null; - - if (type != null) - { - TypeInfo typeInfo = getTypeInfo(type); - if (typeInfo != null) - { - types = typeInfo.getSupertypes(); - } - } - - return types; - } - - /**Returns the cached implemented interfaces for a given type. Will return null if no interfaces - * have been cached for this type or if the type/something it depends on has changed since - * then. - * @param type - the bean type in question - * @return the interface types implemented by the given type. May be null. - * @see TypeInfoCache#cacheInterfaceTypesFor(IType) - */ - public synchronized IType[] getCachedInterfaceTypes(IType type) - { - IType[] types = null; - - if (type != null) - { - TypeInfo typeInfo = getTypeInfo(type); - if (typeInfo != null) - { - types = typeInfo.getInterfaceTypes(); - } - } - - return types; - } - - /**Caches the given method symbols for the given type. - * @param beanType - the type - * @param methods - the method symbols to cache - */ - public synchronized void cacheMethodSymbols(IType beanType, IBeanMethodSymbol[] methods) { - if (beanType != null) - { - TypeInfo typeInfo = getOrCreateTypeInfo(beanType); - if (typeInfo != null) { - typeInfo.setMethodSymbols(methods); - } - } - } - - /**Caches the given property symbols for the given type. - * @param beanType - the type - * @param properties - the property symbols to cache - */ - public synchronized void cachePropertySymbols(IType beanType, IBeanPropertySymbol[] properties) { - if (beanType != null) - { - TypeInfo typeInfo = getOrCreateTypeInfo(beanType); - if (typeInfo != null) { - typeInfo.setPropertySymbols(properties); - } - } - } - - /**Caches the supertypes for the given type. The supertypes will be calculated (and also returned) - * by this method. - * @param type - the type to cache supertypes for - * @return the supertypes of the given type. - */ - public synchronized IType[] cacheSupertypesFor(IType type) - { - IType[] types = null; - - if (type != null) - { - TypeInfo typeInfo = getOrCreateTypeInfo(type); - - if (typeInfo != null) - { - types = typeInfo.getSupertypes(); - } - } - return types; - } - - /**Caches the interface types for the given type. The interface types will be calculated (and also - * returned) by this method. - * @param type - the type to cache interface types for - * @return the interface types implemented by the given type. - */ - public synchronized IType[] cacheInterfaceTypesFor(IType type) - { - IType[] types = null; - - if (type != null) - { - TypeInfo typeInfo = getOrCreateTypeInfo(type); - if (typeInfo != null) - { - types = typeInfo.getInterfaceTypes(); - } - } - return types; - } - - /**Returns the TypeInfo for the given type. If no TypeInfo exists for this type, an empty TypeInfo - * will be created and cached. - * @param type - the type in question - * @return the (modifyable) TypeInfo for the given type - */ - protected TypeInfo getOrCreateTypeInfo(IType type) { - TypeInfo typeInfo = getTypeInfo(type); - if (typeInfo == null) { - try { - final ITypeHierarchy hierarchy = - type.newSupertypeHierarchy(new NullProgressMonitor()); - final IType[] supertypes = hierarchy.getAllSuperclasses(type); - final IType[] interfaceTypes = hierarchy.getAllInterfaces(); - final IType[] rootClasses = hierarchy.getRootClasses(); - List missingSupertypesList = null; - for (int i = 0; i < rootClasses.length; i++) { - String superclassName = rootClasses[i].getSuperclassName(); - if (superclassName != null) { - if (missingSupertypesList == null) { - missingSupertypesList = new ArrayList(1); - } - superclassName = shortTypename(superclassName); - missingSupertypesList.add(superclassName); - } - } - String[] missingSupertypes = null; - if (missingSupertypesList != null) { - missingSupertypes = (String[]) missingSupertypesList.toArray(new String[missingSupertypesList.size()]); - } else { - missingSupertypes = TypeInfo.NO_NAMES; - } - typeInfo = new TypeInfo(); - typeInfo.setSupertypes(supertypes); - typeInfo.setInterfaceTypes(interfaceTypes); - typeInfo.setMissingSupertypeNames(missingSupertypes); - cachedInfo.put(type, typeInfo); - registerCachedType(type, typeInfo); - } catch (JavaModelException e) { - JSFCommonPlugin.log(e); - } - } - return typeInfo; - } - - /**Returns the typename fragment after the last "." (which in most cases is identical to the - * unqualified typename). - * Used only to make sure that if n1 and n2 are names of the same type - * shortname(n1) equals shortname(2) even if one name is qualified and one not. - * @param typename - * @return the typename fragment after the last "." - */ - private String shortTypename(String typename) { - int pos = typename.lastIndexOf('.'); - if (pos >= 0) { - typename = typename.substring(pos + 1); - } - return typename; - } - - /** - * Registers the given type for all ITypeRoot's it depends on, so that it can be uncached if - * one of this ITypeRoot's has changed. The type must be unregistered when it should not be watched - * anymore. - * @param type - the type - * @param typeInfo - TypeInfo of the given type - * @see TypeInfoCache#unregisterCachedType(IType, TypeInfo) - */ - protected void registerCachedType(IType type, TypeInfo typeInfo) { - registerTypeForTypeRoot(type, type.getTypeRoot()); - IType[] supertypes = typeInfo.getSupertypes(); - for (int i = 0; i < supertypes.length; i++) { - registerTypeForTypeRoot(type, supertypes[i].getTypeRoot()); - } - String[] missingSupertypeNames = typeInfo.getMissingSupertypeNames(); - if (missingSupertypeNames != null) { - for (int i = 0; i < missingSupertypeNames.length; i++) { - registerTypeForMissingSupertype(type, missingSupertypeNames[i]); - } - } - } - - private void registerTypeForTypeRoot(IType type, ITypeRoot typeRoot) { - Set dependentTypes = cachedTypesByAffectingTypeRoot.get(typeRoot); - if (dependentTypes == null) { - dependentTypes = new HashSet(5); - cachedTypesByAffectingTypeRoot.put(typeRoot, dependentTypes); - } - dependentTypes.add(type); - } - - private void registerTypeForMissingSupertype(IType type, String supertype) { - Set dependentTypes = cachedTypesByMissingSupertypename.get(supertype); - if (dependentTypes == null) { - dependentTypes = new HashSet(5); - cachedTypesByMissingSupertypename.put(supertype, dependentTypes); - } - dependentTypes.add(type); - } - - /**Unregisters the given type for all ITypeRoot's it depended on. - * @param type - the type - * @param typeInfo - TypeInfo of the given type - */ - protected void unregisterCachedType(IType type, TypeInfo typeInfo) { - unregisterTypeForTypeRoot(type, type.getTypeRoot()); - IType[] supertypes = typeInfo.getSupertypes(); - for (int i = 0; i < supertypes.length; i++) { - unregisterTypeForTypeRoot(type, supertypes[i].getTypeRoot()); - } - String[] missingSupertypeNames = typeInfo.getMissingSupertypeNames(); - if (missingSupertypeNames != null) { - for (int i = 0; i < missingSupertypeNames.length; i++) { - unregisterTypeForMissingSupertype(type, missingSupertypeNames[i]); - } - } - } - - private void unregisterTypeForTypeRoot(IType type, ITypeRoot typeRoot) { - Set dependentTypes = cachedTypesByAffectingTypeRoot.get(typeRoot); - if (dependentTypes != null) { - dependentTypes.remove(type); - if (dependentTypes.isEmpty()) { - cachedTypesByAffectingTypeRoot.remove(typeRoot); - } - } - } - - private void unregisterTypeForMissingSupertype(IType type, String supertype) { - Set dependentTypes = cachedTypesByMissingSupertypename.get(supertype); - if (dependentTypes != null) { - dependentTypes.remove(type); - if (dependentTypes.isEmpty()) { - cachedTypesByMissingSupertypename.remove(supertype); - } - } - } - - /**This will remove all cached info for all types. - */ - protected synchronized void uncacheAllTypes() { - cachedInfo.clear(); - cachedTypesByAffectingTypeRoot.clear(); - cachedTypesByMissingSupertypename.clear(); - } - - /**Removes all cached info for all types that are subtypes of a type of the given ITypeRoot. - * @param typeRoot - */ - protected synchronized void uncacheAffectedTypes(ITypeRoot typeRoot) { - Collection affectedTypes = cachedTypesByAffectingTypeRoot.get(typeRoot); - if (affectedTypes != null && !affectedTypes.isEmpty()) { - List affectedTypesCopy = new ArrayList(affectedTypes); - for (Iterator it = affectedTypesCopy.iterator(); it.hasNext(); ) { - IType cachedType = (IType) it.next(); - TypeInfo typeInfo = cachedInfo.remove(cachedType); - unregisterCachedType(cachedType, typeInfo); - } - } - } - - /**Removes all cached info for all types (or subtypes of types) that specify a supertype - * that has a name similar to the given name. - * @param supertypename - the missing supertype name. May be qualified or not - */ - protected synchronized void uncacheTypesWithMissingSupertype(String supertypename) { - Collection affectedTypes = cachedTypesByMissingSupertypename.get(shortTypename(supertypename)); - if (affectedTypes != null && !affectedTypes.isEmpty()) { - List affectedTypesCopy = new ArrayList(affectedTypes); - for (Iterator it = affectedTypesCopy.iterator(); it.hasNext(); ) { - IType cachedType = (IType) it.next(); - TypeInfo typeInfo = cachedInfo.remove(cachedType); - unregisterCachedType(cachedType, typeInfo); - } - } - } - - /**Removes all cached info that may be affected by the given change. - * @param delta - the change in the java model - */ - protected void updateChangedJavaElement(IJavaElementDelta delta) { - IJavaElement element= delta.getElement(); - switch (element.getElementType()) { - case IJavaElement.JAVA_MODEL: - updateChangedJavaModel(delta, element); - break; - case IJavaElement.JAVA_PROJECT: - updateChangedJavaProject(delta, element); - break; - case IJavaElement.PACKAGE_FRAGMENT_ROOT: - updateChangedPackageFragmentRoot(delta, element); - break; - case IJavaElement.PACKAGE_FRAGMENT: - updateChangedPackageFragment(delta, (IPackageFragment) element); - break; - case IJavaElement.CLASS_FILE: - case IJavaElement.COMPILATION_UNIT: - updateChangedOpenable(delta, element); - break; - } - } - - private void updateChangedChildren(IJavaElementDelta delta) { - if ((delta.getFlags() & IJavaElementDelta.F_CHILDREN) > 0) { - IJavaElementDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - updateChangedJavaElement(children[i]); - } - } - } - - private void updateChangedJavaModel(IJavaElementDelta delta, IJavaElement element) { - switch (delta.getKind()) { - case IJavaElementDelta.ADDED : - case IJavaElementDelta.REMOVED : - uncacheAllTypes(); - break; - case IJavaElementDelta.CHANGED : - updateChangedChildren(delta); - break; - } - } - - private void updateChangedJavaProject(IJavaElementDelta delta, IJavaElement element) { - int kind = delta.getKind(); - int flags = delta.getFlags(); - if ((flags & IJavaElementDelta.F_OPENED) != 0) { - kind = IJavaElementDelta.ADDED; // affected in the same way - } - if ((flags & IJavaElementDelta.F_CLOSED) != 0) { - kind = IJavaElementDelta.REMOVED; // affected in the same way - } - switch (kind) { - case IJavaElementDelta.ADDED : - case IJavaElementDelta.REMOVED : - uncacheAllTypes(); - break; - case IJavaElementDelta.CHANGED : - updateChangedChildren(delta); - break; - } - } - - private void updateChangedPackageFragment(IJavaElementDelta delta, IPackageFragment element) { - switch (delta.getKind()) { - case IJavaElementDelta.ADDED : - // if the package fragment is in the projects being considered, this could - // introduce new types, changing the hierarchy - case IJavaElementDelta.REMOVED : - // is a change if the package fragment contains supertypes? - uncacheAllTypes(); - break; - case IJavaElementDelta.CHANGED : - // look at the files in the package fragment - updateChangedChildren(delta); - } - } - - private void updateChangedPackageFragmentRoot(IJavaElementDelta delta, IJavaElement element) { - switch (delta.getKind()) { - case IJavaElementDelta.ADDED : - case IJavaElementDelta.REMOVED : - uncacheAllTypes(); - break; - case IJavaElementDelta.CHANGED : - int flags = delta.getFlags(); - if (((flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0)||(flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) { - uncacheAllTypes(); - } else { - updateChangedChildren(delta); - } - break; - } - } - - /**Removes all cached info that may be affected by the change in this IOpenable - * @param delta - the change in the java model - * @param element - the (changed) IOpenable considered - */ - protected void updateChangedOpenable(IJavaElementDelta delta, IJavaElement element) { - if (element instanceof ITypeRoot) { - ITypeRoot typeRoot = (ITypeRoot) element; - uncacheAffectedTypes(typeRoot); - // Creates missing superclass for any cached type? - if (delta.getKind() == IJavaElementDelta.ADDED) { - if (typeRoot instanceof ICompilationUnit) { - ICompilationUnit cu = (ICompilationUnit) typeRoot; - try { - IType[] types = cu.getAllTypes(); - for (int i = 0; i < types.length; i++) { - uncacheTypesWithMissingSupertype(types[i].getElementName()); - } - } catch (JavaModelException e) { - if (!e.isDoesNotExist()) - { - JSFCommonPlugin.log(IStatus.INFO, "Unable to get types for compilation unit " + cu, e); //$NON-NLS-1$ - } - uncacheAllTypes(); - } - } else if (typeRoot instanceof IClassFile) { - IClassFile cf = (IClassFile) typeRoot; - IType type = cf.getType(); - uncacheTypesWithMissingSupertype(type.getElementName()); - } - } - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeTransformer.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeTransformer.java deleted file mode 100644 index 4c5718f89..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeTransformer.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.jdt.core.Signature; - -/** - * Transforms one CompositeType to another according to particular - * transform rules. - * - * In general, every transformation should be of the form: - * - * CompositeType transform(CompositeType original, other inputs...); - * - * @author cbateman - * - */ -public class TypeTransformer -{ - private final static Map boxConversions = new HashMap(); - private final static Map unBoxConversions = new HashMap(); - - static - { - // see jdt.core.Signature or JVM link spec for more details - boxConversions.put("B", "Ljava.lang.Byte;"); //$NON-NLS-1$//$NON-NLS-2$ - boxConversions.put("C", "Ljava.lang.Character;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("D", "Ljava.lang.Double;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("F", "Ljava.lang.Float;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("I", "Ljava.lang.Integer;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("J", "Ljava.lang.Long;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("S", "Ljava.lang.Short;"); //$NON-NLS-1$ //$NON-NLS-2$ - boxConversions.put("Z", "Ljava.lang.Boolean;"); //$NON-NLS-1$ //$NON-NLS-2$ - // don't box V - boxConversions.put("V", "V"); //$NON-NLS-1$ //$NON-NLS-2$ - - // invert hte box conversions - for (final Iterator it = boxConversions.keySet().iterator(); it.hasNext();) - { - final String newValue = (String) it.next(); - final String newKey = (String) boxConversions.get(newValue); - if (unBoxConversions.put(newKey, newValue) != null) - { - // if put returns non-null then we have replaced a key - // added on a previous iteration. This implies - // that box mappings are no longer one-to-one - throw new AssertionError("Duplicated boxing value"); //$NON-NLS-1$ - } - } - } - - /** - * @param compositeType - * @return an equivilent form of compositeType with all primitive type - * signatures converted to their fully qualified boxed equivilent but - * otherwise unchanged. - * - * Example: J -> Ljava.lang.Long; - */ - public static CompositeType transformBoxPrimitives(CompositeType compositeType) - { - String[] signatures = compositeType.getSignatures(); - String[] newsignatures = new String[signatures.length]; - - for (int i = 0; i < signatures.length; i++) - { - newsignatures[i] = transformBoxPrimitives(signatures[i]); - } - - return new CompositeType(newsignatures, compositeType.getAssignmentTypeMask()); - } - - /** - * Performs boxing for a single typeSignature string - * @param curSignature - * @return the boxed signature - */ - public static String transformBoxPrimitives(final String curSignature) - { - String newSignature = curSignature; - - // first determine if we have a type or method signature - try - { - int kind = Signature.getTypeSignatureKind(curSignature); - - // interested in base types, since these need boxing - if (kind == Signature.BASE_TYPE_SIGNATURE) - { - // grab the box for the primitive - newSignature = (String) boxConversions.get(curSignature); - } - else if (kind == Signature.ARRAY_TYPE_SIGNATURE) - { - // check if it's array of primitives - final String baseType = Signature.getElementType(curSignature); - - if (Signature.getTypeSignatureKind(baseType) == Signature.BASE_TYPE_SIGNATURE) - { - // it is, so box it - final String newBaseType = (String) boxConversions.get(baseType); - final int numBraces = Signature.getArrayCount(curSignature); - newSignature = ""; //$NON-NLS-1$ - for (int j = 0; j < numBraces; j++) - { - newSignature += "["; //$NON-NLS-1$ - } - - newSignature += newBaseType; - } - } - } - catch (IllegalArgumentException e) - { - // signature was not a type signature, so must be a method sig - // do nothing: don't box method types - } - - return newSignature; - } - - /** - * Performs the exact inverse of transformBoxPrimitives -- takes all - * boxing type signatures and replaces them with their primitive equivilent - * @param compositeType - * @return a new composite with all boxed primitives unboxed - */ - public static CompositeType transformUnboxPrimitives(CompositeType compositeType) - { - String[] signatures = compositeType.getSignatures(); - String[] newsignatures = new String[signatures.length]; - - for (int i = 0; i < signatures.length; i++) - { - newsignatures[i] = transformUnboxPrimitives(signatures[i]); - } - - return new CompositeType(newsignatures, compositeType.getAssignmentTypeMask()); - } - - /** - * Performs unboxing for a single typeSignature string - * - * @param typeSignature - * @return the transformed signature - */ - public static String transformUnboxPrimitives(final String typeSignature) - { - String newSignature = typeSignature; - - // first determine if we have a type or method signature - try - { - int kind = Signature.getTypeSignatureKind(typeSignature); - - // interested in class types, since these need boxing - if (kind == Signature.CLASS_TYPE_SIGNATURE) - { - // grab the box for the primitive - String checkForUnbox = (String) unBoxConversions.get(typeSignature); - - if (checkForUnbox != null) - { - newSignature = checkForUnbox; - } - } - else if (kind == Signature.ARRAY_TYPE_SIGNATURE) - { - // check if it's array of objects - final String baseType = Signature.getElementType(typeSignature); - - if (Signature.getTypeSignatureKind(baseType) == Signature.CLASS_TYPE_SIGNATURE) - { - // it is, so unbox it - final String newBaseTypeCandidate = (String) unBoxConversions.get(baseType); - - if (newBaseTypeCandidate != null) - { - final int numBraces = Signature.getArrayCount(typeSignature); - newSignature = ""; //$NON-NLS-1$ - for (int j = 0; j < numBraces; j++) - { - newSignature += "["; //$NON-NLS-1$ - } - - newSignature += newBaseTypeCandidate; - } - } - } - } - catch (IllegalArgumentException e) - { - // signature was not a type signature, so must be a method sig - // do nothing: don't box method types - } - - return newSignature; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeUtil.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeUtil.java deleted file mode 100644 index a302fc4d6..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/TypeUtil.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.Signature; - -/** - * Package utility class - * @author cbateman - * - */ -/*package*/final class TypeUtil -{ - /** - * @param assignmentType - * @return true if assignmentType has lhs flag set - */ - public static boolean matchesLHS(int assignmentType) - { - return (assignmentType & IAssignable.ASSIGNMENT_TYPE_LHS) != 0; - } - - /** - * @param assignmentType - * @return true if assignmentType has rhs flag set - */ - public static boolean matchesRHS(int assignmentType) - { - return (assignmentType & IAssignable.ASSIGNMENT_TYPE_RHS) != 0; - } - - /** - * @param signature - * @return true if the signature is a method signature - */ - public static boolean isMethodSignature(final String signature) - { - // method signature must start with a "(" - return signature.charAt(0) == Signature.C_PARAM_START; - } - private TypeUtil() {/*not instantiable*/} -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/ValueType.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/ValueType.java deleted file mode 100644 index 2d1282586..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/ValueType.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.common.internal.types; - -import org.eclipse.jdt.core.Signature; - -/** - * Value object representing a value binding type by it's type and assignability - * information - * - * @author cbateman - * - */ -public class ValueType implements SignatureBasedType, IAssignable -{ - /** - * A default empty string array - */ - protected final static String[] EMPTY_STRING_ARRAY = new String[0]; - - private final String _signature; - private final String[] _typeArgs; - private final int _assignmentMask; - private final String[] _superTypes; - private final String[] _interfaceTypes; - - private final boolean _isEnumType; - - private String[] _allTypes; // lazy creation on getAllTypes - - /** - * Construct a new ValueType object with the given - * signature - * - * @param signature - * @param typeArgs generic type arguments for signature or empty if none - * @param superTypes - * @param interfaceTypes - * @param isEnumType - * @param assignmentMask - */ - public ValueType(final String signature, - final String[] typeArgs, - final String[] superTypes, - final String[] interfaceTypes, - final boolean isEnumType, - final int assignmentMask) - { - if (signature == null) - { - throw new AssertionError("signature can never be null"); //$NON-NLS-1$ - } - - _signature = signature; - _typeArgs = typeArgs; - _assignmentMask = assignmentMask; - _superTypes = superTypes != null ? superTypes : EMPTY_STRING_ARRAY; - _interfaceTypes = interfaceTypes != null ? interfaceTypes : EMPTY_STRING_ARRAY; - _isEnumType = isEnumType; - } - - /** - * Copy constructor equivilent to - * ValueType(template.getSignature(), template.getSuperTypes(), template.getInterfaceTypes(),assingmentMask, template._isEnumType) - * - * @param template - * @param assignmentMask - */ - public ValueType(final ValueType template, final int assignmentMask) - { - this(template._signature, template._typeArgs, template._superTypes, - template._interfaceTypes, template._isEnumType, assignmentMask); - } - - /** - * Convienence constructor for creating ValueType's with no supertype, type argument - * or interface info. Equivilent to: - * ValueType(signature, new String[0], new String[0], new String[0], false, assignmentMask) - * - * @param signature - * @param assignmentMask - */ - public ValueType(final String signature, final int assignmentMask) - { - this(signature, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY, false, assignmentMask); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.core.internal.types.SignatureBasedType#getSignature() - */ - public String getSignature() - { - return _signature; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.common.internal.types.IAssignable#getAssignability() - */ - public int getAssignability() { - return _assignmentMask; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.common.internal.types.IAssignable#isLHS() - */ - public boolean isLHS() { - return TypeUtil.matchesLHS(_assignmentMask); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.common.internal.types.IAssignable#isRHS() - */ - public boolean isRHS() { - return TypeUtil.matchesRHS(_assignmentMask); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() - { - return Signature.getSignatureSimpleName - (TypeTransformer.transformBoxPrimitives(_signature)); - } - - /** - * @return an array of all signatures of all super types or empty - * array if there are no super types for this type - * - * Note: if isArray() == true, then these are the super types of - * the base element - */ - public String[] getSuperTypes() - { - return _superTypes; - } - - /** - * @return an array of all interfaces implemented or empty array - * if none - * - * Note: if isArray() == true, then these are the interfacess of - * the base element - */ - public String[] getInterfaceTypes() - { - return _interfaceTypes; - } - - /** - * @return all types including the base type, super types and interface - * types. - * - * Note: if isArray() == true, then these are the super types of - * the base element - - */ - public String[] getAllTypes() - { - if (_allTypes == null) - { - int numberOfTypes = 1 + _superTypes.length + _interfaceTypes.length; - _allTypes = new String[numberOfTypes]; - _allTypes[0] = _signature; - System.arraycopy(_superTypes, 0, _allTypes, 1, _superTypes.length); - System.arraycopy(_interfaceTypes, 0, _allTypes, 1+_superTypes.length, _interfaceTypes.length); - } - return _allTypes; - } - - /** - * @return the type arguments for getSignature() if any or empty array if none - */ - public String[] getTypeArguments() - { - return _typeArgs; - } - - /** - * - */ - public CompositeType toCompositeType() - { - return new CompositeType(getAllTypes(), getAssignability()); - } - - /** - * @param signature - * @return true if an instance of this type would satisfy instanceof signature - * - */ - public boolean isInstanceOf(final String signature) - { - // if this is an array, then the super types are for the base - // type and we can't be an instance of anything but signature - if (isArray()) - { - return getSignature().equals(signature); - } - - final String[] allTypes = getAllTypes(); - - for (int i = 0; i < allTypes.length; i++) - { - if (allTypes[i].equals(signature)) - { - return true; - } - } - - return false; - } - - /** - * @return true if this is an array type - */ - public boolean isArray() - { - return Signature.getArrayCount(getSignature()) > 0; - } - - /** - * @return true if the value type represents a (>=Java5) enum type - */ - public boolean isEnumType() { - return _isEnumType; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/messages.properties b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/messages.properties deleted file mode 100644 index 3df119baf..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/types/messages.properties +++ /dev/null @@ -1,18 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2007 Oracle 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: -# Oracle Corporation - initial API and implementation -############################################################################### -TypeComparator.Expression.Doesnt.Match.Expected.Types=EL expression does not evaluate to expected types for this attribute -TypeComparator.Expression.Not.Gettable=Expression is not gettable -TypeComparator.Expression.Expected.Settable=Attribute expects settable value, but expression is not settable - -TypeComparator.Expression.No_Method=Expression must be a method expression but is a value expression -TypeComparator.Expression.No_Value=Expression must be a value expression but is a method expression -TypeComparator.Expression.Incompatible_Method=Method must have signature "{0}" but has signature "{1}" -TypeComparator.Expression.Incompatible_Value=Cannot coerce type {1} to {0} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/util/JarUtilities.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/util/JarUtilities.java deleted file mode 100644 index 76c609ea3..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/internal/util/JarUtilities.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.eclipse.jst.jsf.common.internal.util; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -/** - * @author cbateman - * - */ -public class JarUtilities -{ - private static final String JAR_PREFIX = "jar:"; //$NON-NLS-1$ - private static final String JAR_FILE_PREFIX = JAR_PREFIX + "file:"; //$NON-NLS-1$ - /** - * A common instance. - */ - public static final JarUtilities INSTANCE = new JarUtilities(); - /** - * @param jarFile - * @return the URL for the jarFile - * @throws MalformedURLException - */ - public URL createJarUrl(final JarFile jarFile) throws MalformedURLException - { - return createJarUrl(jarFile, ""); //$NON-NLS-1$ - } - - /** - * @param jarFile - * @param jarEntry - * @return the URL for the jarEntry inside jarFile. - * @throws MalformedURLException - */ - public URL createJarUrl(final JarFile jarFile, final JarEntry jarEntry) throws MalformedURLException - { - return createJarUrl(jarFile, jarEntry != null ? jarEntry.getName() : ""); //$NON-NLS-1$ - } - - /** - * @param jarFile - * @param jarEntryName - * @return the URL for the jarEntryName inside jarFile. - * @throws MalformedURLException - */ - public URL createJarUrl(final JarFile jarFile, final String jarEntryName) throws MalformedURLException - { - final String fixedJarFileName = jarFile.getName().replace("\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$ - return createJarUrl(fixedJarFileName, jarEntryName != null ? jarEntryName : ""); //$NON-NLS-1$ - } - - /** - * @param filePath - * @param jarEntryName - * @return the URL for the jarEntryName in the file at filePath - * @throws MalformedURLException - */ - public URL createJarUrl(final String filePath, final String jarEntryName) throws MalformedURLException - { - final String urlString = String.format("jar:file:///%s!/%s", //$NON-NLS-1$ - filePath, jarEntryName); - return new URL(urlString); - } - - /** - * @param url - * @return a file for the URL if url is in the local file system (must conform to jar:file:// uri). - * or null. - */ - public File getFile(final URL url) - { - String string = url.toString(); - if (string != null && string.startsWith(JAR_FILE_PREFIX)) - { - string = string.substring(JAR_PREFIX.length()); - try - { - return new File(URI.create(string)); - } catch (IllegalArgumentException e) - { - // fallthorough and return null if the file can't do anything - // with the string. - } - } - return null; - } -} |