diff options
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee.web/web/org')
14 files changed, 0 insertions, 2852 deletions
diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java deleted file mode 100644 index 27ab2ee71..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/ModuleAdapter.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Feb 8, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable; - -/** - * @author blancett - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class ModuleAdapter extends AdapterImpl { - - J2EEFlexProjDeployable delegate; - - public void setModuleDelegate(J2EEFlexProjDeployable moduleDelegate) { - delegate = moduleDelegate; - } - - public J2EEFlexProjDeployable getDelegate() { - return delegate; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java deleted file mode 100644 index f075703ec..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebDeployableArtifactUtil.java +++ /dev/null @@ -1,352 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.deployables; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.ITypeHierarchy; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.internal.web.jfaces.extension.FileURL; -import org.eclipse.jst.j2ee.internal.web.jfaces.extension.FileURLExtensionReader; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.j2ee.webapplication.JSPType; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.ServletMapping; -import org.eclipse.jst.j2ee.webapplication.ServletType; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.jst.j2ee.webapplication.WebType; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IModuleArtifact; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.util.WebResource; - -/** - * @version 1.0 - * @author - */ -public class WebDeployableArtifactUtil { - - private final static String GENERIC_SERVLET_CLASS_TYPE = "javax.servlet.GenericServlet"; //$NON-NLS-1$ - private final static String CACTUS_SERVLET_CLASS_TYPE = "org.apache.cactus.server.ServletTestRedirector"; //$NON-NLS-1$ - - public WebDeployableArtifactUtil() { - super(); - } - - public static IModuleArtifact getModuleObject(Object obj) { - IResource resource = null; - if (obj instanceof IResource) - resource = (IResource) obj; - if (obj instanceof IModuleArtifact) - resource = ((IModuleArtifact) obj).getModule().getProject(); - else if (obj instanceof IAdaptable) - resource = (IResource) ((IAdaptable) obj).getAdapter(IResource.class); - else if (obj instanceof EObject) { - resource = ProjectUtilities.getProject((EObject) obj); - if (obj instanceof Servlet) { - Servlet servlet = ((Servlet) obj); - Resource servResource = servlet.eResource(); - IVirtualResource[] resources = null; - try { - IResource eclipeServResoruce = WorkbenchResourceHelper.getFile(servResource); - resources = ComponentCore.createResources(eclipeServResoruce); - } catch (Exception e) { - e.printStackTrace(); - } - IVirtualComponent component = null; - if (resources[0] != null) - component = resources[0].getComponent(); - String mapping = null; - java.util.List mappings = ((Servlet) obj).getMappings(); - if (mappings != null && !mappings.isEmpty()) { - ServletMapping map = (ServletMapping) mappings.get(0); - mapping = map.getUrlPattern(); - } - if (mapping != null) { - return new WebResource(getModule(resource.getProject(), component), new Path(mapping)); - } - WebType webType = ((Servlet) obj).getWebType(); - if (webType.isJspType()) { - resource = ((IProject) resource).getFile(((JSPType) webType).getJspFile()); //$NON-NLS-1$ - } else if (webType.isServletType()) { - return new WebResource(getModule(resource.getProject(), component), new Path("servlet/" + ((ServletType) webType).getClassName())); //$NON-NLS-1$ - } - } - } - if (resource == null) - return null; - - if (resource instanceof IProject) { - IProject project = (IProject) resource; - if (hasInterestedComponents(project)) - return new WebResource(getModule(project, null), project.getProjectRelativePath()); - } - - if (!hasInterestedComponents(resource.getProject())) - return null; - if (isCactusJunitTest(resource)) - return null; - - IPath resourcePath = resource.getFullPath(); - IVirtualResource[] resources = ComponentCore.createResources(resource); - IVirtualComponent component = null; - if (resources[0] != null || resources.length <= 0) - component = resources[0].getComponent(); - String className = getServletClassName(resource); - if (className != null && component != null) { - String mapping = getServletMapping(resource, true, className, component.getName()); - if (mapping != null) { - return new WebResource(getModule(resource.getProject(), component), new Path(mapping)); - } - // if there is no servlet mapping, provide direct access to the servlet - // through the fully qualified class name - return new WebResource(getModule(resource.getProject(), component), new Path("servlet/" + className)); //$NON-NLS-1$ - - } - if (className == null) { - WebArtifactEdit webEdit = null; - try { - webEdit = WebArtifactEdit.getWebArtifactEditForRead(component); - List servlets = webEdit.getWebApp().getServlets(); - for (int i=0; i<servlets.size(); i++) { - Servlet servlet = (Servlet) servlets.get(i); - WebType type = servlet.getWebType(); - if (type.isJspType()) { - JSPType jsp = (JSPType)type; - String jspPath = resource.getProjectRelativePath().removeFirstSegments(1).toString(); - if (jsp.getJspFile().equals(jspPath)) { - List mappings = servlet.getMappings(); - String mapping = null; - if (mappings != null && !mappings.isEmpty()) { - ServletMapping map = (ServletMapping) mappings.get(0); - mapping = map.getUrlPattern(); - if (mapping != null) - return new WebResource(getModule(resource.getProject(), component), new Path(mapping)); - } - } - } - } - } finally { - if (webEdit != null) - webEdit.dispose(); - } - } - resourcePath = resources[0].getRuntimePath(); - - // Extension read to get the correct URL for Java Server Faces file if - // the jsp is of type jsfaces. - FileURL jspURL = FileURLExtensionReader.getInstance().getFilesURL(); - if (jspURL != null) { - IPath correctJSPPath = jspURL.getFileURL(resource, resourcePath); - if (correctJSPPath != null && correctJSPPath.toString().length() > 0) - return new WebResource(getModule(resource.getProject(), component), correctJSPPath); - } - // return Web resource type - - return new WebResource(getModule(resource.getProject(), component), resourcePath); - } - - protected static IModule getModule(IProject project, IVirtualComponent component) { - IModule deployable = null; - Iterator iterator = Arrays.asList(ServerUtil.getModules(J2EEProjectUtilities.DYNAMIC_WEB)).iterator(); //$NON-NLS-1$ - String componentName = null; - if (component != null) - componentName = component.getName(); - else - return getModuleProject(project, iterator); - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof IModule) { - deployable = (IModule) next; - if (deployable.getName().equals(componentName)) { - return deployable; - } - } - } - return null; - } - - protected static IModule getModuleProject(IProject project, Iterator iterator) { - IModule deployable = null; - while (iterator.hasNext()) { - Object next = iterator.next(); - if (next instanceof IModule) { - deployable = (IModule) next; - if (deployable.getProject().equals(project)) - return deployable; - } - } - return null; - } - - /** - * - * Very temporary api - TODO - rip this out by 1.0 - */ - private static boolean isCactusJunitTest(IResource resource) { - return getClassNameForType(resource, CACTUS_SERVLET_CLASS_TYPE) != null; - } - - - - private static IType[] getTypes(IJavaElement element) { - try { - if (element.getElementType() != IJavaElement.COMPILATION_UNIT) - return null; - - return ((ICompilationUnit) element).getAllTypes(); - } catch (Exception e) { - return null; - } - } - - public static String getServletClassName(IResource resource) { - return getClassNameForType(resource, GENERIC_SERVLET_CLASS_TYPE); - } - - public static String getClassNameForType(IResource resource, String superType) { - if (resource == null) - return null; - - try { - IProject project = resource.getProject(); - IPath path = resource.getFullPath(); - if (!project.hasNature(JavaCore.NATURE_ID) || path == null) - return null; - - IJavaProject javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); - if (!javaProject.isOpen()) - javaProject.open(new NullProgressMonitor()); - - // output location may not be on classpath - IPath outputPath = javaProject.getOutputLocation(); - if (outputPath != null && "class".equals(path.getFileExtension()) && outputPath.isPrefixOf(path)) { //$NON-NLS-1$ - int count = outputPath.segmentCount(); - path = path.removeFirstSegments(count); - } - - // remove initial part of classpath - IClasspathEntry[] classPathEntry = javaProject.getResolvedClasspath(true); - if (classPathEntry != null) { - int size = classPathEntry.length; - for (int i = 0; i < size; i++) { - IPath classPath = classPathEntry[i].getPath(); - if (classPath.isPrefixOf(path)) { - int count = classPath.segmentCount(); - path = path.removeFirstSegments(count); - i += size; - } - } - } - - // get java element - IJavaElement javaElement = javaProject.findElement(path); - - IType[] types = getTypes(javaElement); - if (types != null) { - int size2 = types.length; - for (int i = 0; i < size2; i++) { - if (hasSuperclass(types[i], superType)) - return types[i].getFullyQualifiedName(); - } - } - return null; - } catch (Exception e) { - return null; - } - } - - public static boolean hasSuperclass(IType type, String superClassName) { - try { - ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null); - IType[] superClasses = hierarchy.getAllSuperclasses(type); - - int size = superClasses.length; - for (int i = 0; i < size; i++) { - if (superClassName.equals(superClasses[i].getFullyQualifiedName())) //$NON-NLS-1$ - return true; - } - return false; - } catch (Exception e) { - return false; - } - } - - public static String getServletMapping(IResource resource, boolean isServlet, String typeName, String componentName) { - if (typeName == null || typeName.equals("")) //$NON-NLS-1$ - return null; - - IProject project = resource.getProject(); - WebArtifactEdit edit = null; - WebApp webApp = null; - try { - edit = WebArtifactEdit.getWebArtifactEditForRead(project); - edit.getDeploymentDescriptorRoot(); - webApp = edit.getWebApp(); - if (webApp == null) - return null; - Iterator iterator = webApp.getServlets().iterator(); - while (iterator.hasNext()) { - Servlet servlet = (Servlet) iterator.next(); - boolean valid = false; - - WebType webType = servlet.getWebType(); - if (webType.isServletType() && isServlet) { - ServletType type = (ServletType) webType; - if (typeName.equals(type.getClassName())) - valid = true; - } else if (webType.isJspType() && !isServlet) { - JSPType type = (JSPType) webType; - if (typeName.equals(type.getJspFile())) - valid = true; - } - if (valid) { - java.util.List mappings = servlet.getMappings(); - if (mappings != null && !mappings.isEmpty()) { - ServletMapping map = (ServletMapping) mappings.get(0); - return map.getUrlPattern(); - } - } - } - return null; - } finally { - if (edit != null) { - edit.dispose(); - } - } - } - - protected static boolean hasInterestedComponents(IProject project) { - return J2EEProjectUtilities.isDynamicWebProject(project); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java deleted file mode 100644 index 9f213a95d..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/deployables/WebModuleArtifact.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Feb 21, 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.deployables; - -/** - * Key Class for adapter manager - */ -public class WebModuleArtifact { - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java deleted file mode 100644 index 777e92514..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURL.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - - -/** - * @author vijayb - * - * TODO To change the template for this generated type comment go to Window - Preferences - Java - - * Code Style - Code Templates - */ -public interface FileURL { - public IPath getFileURL(IResource resource, IPath existingURL); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java deleted file mode 100644 index 53e2075da..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtension.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jem.util.logger.proxy.Logger; - -/** - * @author vijayb - * - * TODO To change the template for this generated type comment go to Window - Preferences - Java - - * Code Style - Code Templates - */ -public class FileURLExtension { - private String id = null; - private FileURL instance; - private boolean errorCondition = false; - private IConfigurationElement element; - public static final String FILE_URL_EXTENSION = "fileURL"; //$NON-NLS-1$ - public static final String RUN = "run"; //$NON-NLS-1$ - public static final String ATT_ID = "id"; //$NON-NLS-1$ - public static final String ATT_CLASS = "class"; //$NON-NLS-1$ - - - /** - * - */ - public FileURLExtension() { - super(); - } - - public FileURL getInstance() { - try { - if (this.instance == null && !this.errorCondition) - this.instance = (FileURL) this.element.createExecutableExtension("run"); //$NON-NLS-1$ - } catch (Throwable e) { - Logger.getLogger().logError(e); - this.errorCondition = true; - } - return this.instance; - } - - public FileURLExtension(IConfigurationElement element) { - if (!FILE_URL_EXTENSION.equals(element.getName())) - throw new IllegalArgumentException("Extensions must be of the type \"" + FILE_URL_EXTENSION + "\"."); //$NON-NLS-1$ //$NON-NLS-2$ - this.element = element; - init(); - } - - private void init() { - this.id = this.element.getAttribute(ATT_ID); - - } - - /** - * @return Returns the id. - */ - public String getId() { - return this.id; - } - - /** - * @param id - * The id to set. - */ - public void setId(String id) { - this.id = id; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java deleted file mode 100644 index c188cc3d2..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/jfaces/extension/FileURLExtensionReader.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jun 13, 2004 - */ -package org.eclipse.jst.j2ee.internal.web.jfaces.extension; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jem.util.RegistryReader; -import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin; - -/** - * @author vijayb - * - * This class loads all the extensions that define the correct URL string for the Java Server Faces - * file - * - */ -public class FileURLExtensionReader extends RegistryReader { - static FileURLExtensionReader instance = null; - protected List fileURLExtensions; - - /** - * @param registry - * @param pluginID - * @param extensionPoint - */ - public FileURLExtensionReader() { - super(WebPlugin.PLUGIN_ID, "fileURL"); //$NON-NLS-1$ - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) - */ - public boolean readElement(IConfigurationElement element) { - if (FileURLExtension.FILE_URL_EXTENSION.equals(element.getName())) { - addExtension(element); - return true; - } - return false; - } - - /** - * Sets the extension point. - * - * @param extensions - * The extensions to set - */ - protected void addExtension(IConfigurationElement newExtension) { - getFileURLExtensions().add(new FileURLExtension(newExtension)); - } - - /** - * Sets the extension point. - * - * @param extensions - * The extensions to set - */ - protected void addExtensionPoint(FileURLExtensionReader newExtension) { - if (this.fileURLExtensions == null) - this.fileURLExtensions = new ArrayList(); - this.fileURLExtensions.add(newExtension); - } - - /** - * @return the appropriate handler for the project based on priorities of those which are - * available and enabled - */ - public FileURL getFilesURL() { - FileURLExtension fileURLExt; - for (Iterator fileURLExtItr = getFileURLExtensions().iterator(); fileURLExtItr.hasNext();) { - fileURLExt = (FileURLExtension) fileURLExtItr.next(); - return fileURLExt.getInstance(); - } - return null; - } - - /** - * Gets the instance. - * - * @return Returns a FileURLExtensionReader - */ - public static FileURLExtensionReader getInstance() { - if (instance == null) { - instance = new FileURLExtensionReader(); - instance.readRegistry(); - } - return instance; - } - - /** - * @return Returns the handlerExtensions. - */ - protected List getFileURLExtensions() { - if (this.fileURLExtensions == null) - this.fileURLExtensions = new ArrayList(); - return this.fileURLExtensions; - } - - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java deleted file mode 100644 index a99465956..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/AddServletOperation.java +++ /dev/null @@ -1,307 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.common.CommonFactory; -import org.eclipse.jst.j2ee.common.Description; -import org.eclipse.jst.j2ee.common.ParamValue; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.webapplication.InitParam; -import org.eclipse.jst.j2ee.webapplication.JSPType; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.ServletMapping; -import org.eclipse.jst.j2ee.webapplication.ServletType; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.jst.j2ee.webapplication.WebapplicationFactory; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * This class, AddServlet Operation is a IDataModelOperation following the IDataModel wizard and - * operation framework. - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider - * - * This operation subclasses the ArtifactEditProviderOperation so the changes made to the deployment descriptor - * models are saved to the artifact edit model. - * @see org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation - * - * It is the operation which should be used when adding a new servlet to - * a web app, whether that be an annotated servlet or a non annotated servlet. This uses the - * NewServletClassDataModelProvider to retrieve properties set by the user in order to create the custom - * servet. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassDataModelProvider - * - * In the non annotated case, this operation will add the metadata necessary into the web deployment - * descriptor. In the annotated case, it will not, it will leave this up to the parsing of the - * annotations to build the deployment descriptor artifacts. To actually create the java class for - * the servlet, the operation uses the NewServletClassOperation. The NewServletClassOperation - * shares the same data model provider. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation - * - * Clients may subclass this operation to provide their own behaviour on servlet creation. The execute - * method can be extended to do so. Also, generateServletMetaData and creteServletClass are exposed. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class AddServletOperation extends ArtifactEditProviderOperation { - - /** - * This is the constructor which should be used when creating the operation. - * It will not accept null parameter. It will not return null. - * @see ArtifactEditProviderOperation#ArtifactEditProviderOperation(IDataModel) - * - * @param dataModel - * @return AddServletOperation - */ - public AddServletOperation(IDataModel dataModel) { - super(dataModel); - } - - /** - * Subclasses may extend this method to add their own actions during execution. - * The implementation of the execute method drives the running of the operation. This - * implementation will create the servlet class, and then if the servlet is not - * annotated, it will create the servlet metadata for the web deployment descriptor. - * This method will accept null as a parameter. - * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - * @see AddServletOperation#createServletClass() - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * - * @param monitor IProgressMonitor - * @param info IAdaptable - * @throws CoreException - * @throws InterruptedException - * @throws InvocationTargetException - */ - public IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - //Retrieve values set in the newservletclass data model - boolean isServletType = model.getBooleanProperty(INewServletClassDataModelProperties.IS_SERVLET_TYPE); - boolean useExisting = model.getBooleanProperty(INewServletClassDataModelProperties.USE_EXISTING_CLASS); - String qualifiedClassName = model.getStringProperty(INewJavaClassDataModelProperties.CLASS_NAME); - - // If it is servlet type, create the java class - if (isServletType && !useExisting) - qualifiedClassName = createServletClass(); - - // If the servlet is not annotated, generate the servlet metadata for the DD - if (!model.getBooleanProperty(IAnnotationsDataModel.USE_ANNOTATIONS)) - generateServletMetaData(model, qualifiedClassName, isServletType); - - return OK_STATUS; - } - - /** - * Subclasses may extend this method to add their own creation of the actual servlet java class. - * This implementation uses the NewServletClassOperation which is a subclass of the NewJavaClassOperation. - * The NewServletClassOperation will use the same NewServletClassDataModelProvider to retrieve the properties in - * order to create the java class accordingly. This method will not return null. - * @see NewServletClassOperation - * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassOperation - * @see NewServletClassDataModelProvider - * - * @return String qualified servlet classname - */ - protected String createServletClass() { - // Create servlet java class file using the NewServletClassOperation. The same data model is shared. - NewServletClassOperation op = new NewServletClassOperation(model); - try { - op.execute(new NullProgressMonitor(), null); - } catch (Exception e) { - Logger.getLogger().log(e); - } - // Return the qualified classname of the newly created java class for the servlet - return getQualifiedClassName(); - } - - /** - * This method will return the qualified java class name as specified by the class name - * and package name properties in the data model. - * This method should not return null. - * @see INewJavaClassDataModelProperties#CLASS_NAME - * @see INewJavaClassDataModelProperties#JAVA_PACKAGE - * - * @return String qualified java classname - */ - public final String getQualifiedClassName() { - // Use the java package name and unqualified class name to create a qualified java class name - String packageName = model.getStringProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE); - String className = model.getStringProperty(INewJavaClassDataModelProperties.CLASS_NAME); - //Ensure the class is not in the default package before adding package name to qualified name - if (packageName != null && packageName.trim().length() > 0) - return packageName + "." + className; //$NON-NLS-1$ - return className; - } - - /** - * Subclasses may extend this method to add their own generation steps for the creation of the - * metadata for the web deployment descriptor. This implementation uses the J2EE models to create - * the Servlet model instance, any init params specified, and any servlet mappings. It then adds - * these to the web application model. This will then be written out to the deployment descriptor - * file. This method does not accept null parameters. - * @see Servlet - * @see AddServletOperation#createServlet(String, boolean) - * @see AddServletOperation#setUpInitParams(List, Servlet) - * @see AddServletOperation#setUpURLMappings(List, Servlet) - * - * @param aModel - * @param qualifiedClassName - * @param isServletType - */ - protected void generateServletMetaData(IDataModel aModel, String qualifiedClassName, boolean isServletType) { - // Set up the servlet modelled object - Servlet servlet = createServlet(qualifiedClassName, isServletType); - - // Set up the InitParams if any - List initParamList = (List) aModel.getProperty(INewServletClassDataModelProperties.INIT_PARAM); - if (initParamList != null) - setUpInitParams(initParamList,servlet); - - // Set up the servlet URL mappings if any - List urlMappingList = (List) aModel.getProperty(INewServletClassDataModelProperties.URL_MAPPINGS); - if (urlMappingList != null) - setUpURLMappings(urlMappingList, servlet); - } - - /** - * This method is intended for private use only. This method is used to create the servlet - * modelled object, to set any parameters specified in the data model, and then to add the - * servlet instance to the web application model. This method does not accpet null parameters. - * It will not return null. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createServlet() - * @see Servlet - * - * @param qualifiedClassName - * @param isServletType - * @return Servlet instance - */ - private Servlet createServlet(String qualifiedClassName, boolean isServletType) { - // Get values from data model - String displayName = model.getStringProperty(INewServletClassDataModelProperties.DISPLAY_NAME); - String description = model.getStringProperty(INewServletClassDataModelProperties.DESCRIPTION); - - // Create the servlet instance and set up the parameters from data model - Servlet servlet = WebapplicationFactory.eINSTANCE.createServlet(); - servlet.setDisplayName(displayName); - servlet.setServletName(displayName); - servlet.setDescription(description); - // Handle servlet case - if (isServletType) { - ServletType servletType = WebapplicationFactory.eINSTANCE.createServletType(); - servletType.setClassName(qualifiedClassName); - servlet.setWebType(servletType); - } - // Handle JSP case - else { - JSPType jspType = WebapplicationFactory.eINSTANCE.createJSPType(); - jspType.setJspFile(qualifiedClassName); - servlet.setWebType(jspType); - } - // Add the servlet to the web application model - WebApp webApp = (WebApp) artifactEdit.getContentModelRoot(); - webApp.getServlets().add(servlet); - // Return the servlet instance - return servlet; - } - - /** - * This method is intended for internal use only. This is used to create any init params - * for the new servlet metadata. It will not accept null parameters. The init params are - * set on the servlet modelled object. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createInitParam() - * - * @param initParamList - * @param servlet - */ - private void setUpInitParams(List initParamList, Servlet servlet) { - // Get the web app instance from the data model - WebApp webApp = (WebApp) artifactEdit.getContentModelRoot(); - int nP = initParamList.size(); - // If J2EE 1.4, add the param value and description info instances to the servlet init params - if (webApp.getJ2EEVersionID() >= J2EEVersionConstants.J2EE_1_4_ID) { - for (int iP = 0; iP < nP; iP++) { - String[] stringArray = (String[]) initParamList.get(iP); - // Create 1.4 common param value - ParamValue param = CommonFactory.eINSTANCE.createParamValue(); - param.setName(stringArray[0]); - param.setValue(stringArray[1]); - // Create 1.4 common descripton value - Description descriptionObj = CommonFactory.eINSTANCE.createDescription(); - descriptionObj.setValue(stringArray[2]); - // Set the description on the param - param.getDescriptions().add(descriptionObj); - param.setDescription(stringArray[2]); - // Add the param to the servlet model list of init params - servlet.getInitParams().add(param); - } - } - // If J2EE 1.2 or 1.3, use the servlet specific init param instances - else { - for (int iP = 0; iP < nP; iP++) { - String[] stringArray = (String[]) initParamList.get(iP); - // Create the web init param - InitParam ip = WebapplicationFactory.eINSTANCE.createInitParam(); - // Set the param name - ip.setParamName(stringArray[0]); - // Set the param value - ip.setParamValue(stringArray[1]); - // Set the param description - ip.setDescription(stringArray[2]); - // Add the init param to the servlet model list of params - servlet.getParams().add(ip); - } - } - } - - /** - * This method is intended for internal use only. This method is used to create the servlet - * mapping modelled objects so the metadata for the servlet mappings is store in the web - * deployment descriptor. This method will not accept null parameters. The servlet mappings - * are added to the web application modelled object. - * @see AddServletOperation#generateServletMetaData(NewServletClassDataModel, String, boolean) - * @see WebapplicationFactory#createServletMapping() - * - * @param urlMappingList - * @param servlet - */ - private void setUpURLMappings(List urlMappingList, Servlet servlet) { - // Get the web app modelled object from the data model - WebApp webApp = (WebApp) artifactEdit.getContentModelRoot(); - int nM = urlMappingList.size(); - // Create the servlet mappings if any - for (int iM = 0; iM < nM; iM++) { - String[] stringArray = (String[]) urlMappingList.get(iM); - // Create the servlet mapping instance from the web factory - ServletMapping mapping = WebapplicationFactory.eINSTANCE.createServletMapping(); - // Set the servlet and servlet name - mapping.setServlet(servlet); - mapping.setName(servlet.getServletName()); - // Set the URL pattern to map the servlet to - mapping.setUrlPattern(stringArray[0]); - // Add the servlet mapping to the web application modelled list - webApp.getServletMappings().add(mapping); - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java deleted file mode 100644 index 75156c012..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/CreateServletTemplateModel.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Aug 6, 2004 - */ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.util.List; - -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - - -/** - * @author jlanuti - */ -public class CreateServletTemplateModel { - - IDataModel dataModel = null; - public static final String INIT = "init"; //$NON-NLS-1$ - public static final String TO_STRING = "toString"; //$NON-NLS-1$ - public static final String GET_SERVLET_INFO = "getServletInfo"; //$NON-NLS-1$ - public static final String DO_POST = "doPost"; //$NON-NLS-1$ - public static final String DO_PUT = "doPut"; //$NON-NLS-1$ - public static final String DO_DELETE = "doDelete"; //$NON-NLS-1$ - public static final String DESTROY = "destroy"; //$NON-NLS-1$ - public static final String DO_GET = "doGet"; //$NON-NLS-1$ - - public static final int NAME = 0; - public static final int VALUE = 1; - public static final int DESCRIPTION = 2; - - /** - * Constructor - */ - public CreateServletTemplateModel(IDataModel dataModel) { - super(); - this.dataModel = dataModel; - } - - public String getServletClassName() { - return getProperty(INewJavaClassDataModelProperties.CLASS_NAME); - } - - public String getJavaPackageName() { - return getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE); - } - - public String getQualifiedJavaClassName() { - return getJavaPackageName() + "." + getServletClassName(); //$NON-NLS-1$ - } - - public String getSuperclassName() { - return getProperty(INewJavaClassDataModelProperties.SUPERCLASS); - } - - public String getServletName() { - return getProperty(INewJavaClassDataModelProperties.CLASS_NAME); - } - - public boolean isPublic() { - return dataModel.getBooleanProperty(INewJavaClassDataModelProperties.MODIFIER_PUBLIC); - } - - public boolean isFinal() { - return dataModel.getBooleanProperty(INewJavaClassDataModelProperties.MODIFIER_FINAL); - } - - public boolean isAbstract() { - return dataModel.getBooleanProperty(INewJavaClassDataModelProperties.MODIFIER_ABSTRACT); - } - - protected String getProperty(String propertyName) { - return dataModel.getStringProperty(propertyName); - } - - public boolean shouldGenInit() { - return implementImplementedMethod(INIT); - } - - public boolean shouldGenToString() { - return implementImplementedMethod(TO_STRING); - } - - public boolean shouldGenGetServletInfo() { - return implementImplementedMethod(GET_SERVLET_INFO); - } - - public boolean shouldGenDoPost() { - return implementImplementedMethod(DO_POST); - } - - public boolean shouldGenDoPut() { - return implementImplementedMethod(DO_PUT); - } - - public boolean shouldGenDoDelete() { - return implementImplementedMethod(DO_DELETE); - } - - public boolean shouldGenDestroy() { - return implementImplementedMethod(DESTROY); - } - - public boolean shouldGenDoGet() { - return implementImplementedMethod(DO_GET); - } - - public List getInitParams() { - return (List) dataModel.getProperty(INewServletClassDataModelProperties.INIT_PARAM); - } - - public String getInitParam(int index, int type) { - List params = getInitParams(); - if (index < params.size()) { - String[] stringArray = (String[]) params.get(index); - return stringArray[type]; - } - return null; - } - - public List getServletMappings() { - return (List) dataModel.getProperty(INewServletClassDataModelProperties.URL_MAPPINGS); - } - - public String getServletMapping(int index) { - List mappings = getServletMappings(); - if (index < mappings.size()) { - String[] map = (String[]) mappings.get(index); - return map[0]; - } - return null; - } - - public String getServletDescription() { - return dataModel.getStringProperty(INewServletClassDataModelProperties.DESCRIPTION); - } - - public List getInterfaces() { - return (List) this.dataModel.getProperty(INewJavaClassDataModelProperties.INTERFACES); - } - - protected boolean implementImplementedMethod(String methodName) { - if (dataModel.getBooleanProperty(INewJavaClassDataModelProperties.ABSTRACT_METHODS)) { - if (methodName.equals(INIT)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.INIT); - else if (methodName.equals(TO_STRING)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.TO_STRING); - else if (methodName.equals(GET_SERVLET_INFO)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.GET_SERVLET_INFO); - else if (methodName.equals(DO_POST)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.DO_POST); - else if (methodName.equals(DO_PUT)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.DO_PUT); - else if (methodName.equals(DO_DELETE)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.DO_DELETE); - else if (methodName.equals(DESTROY)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.DESTROY); - else if (methodName.equals(DO_GET)) - return dataModel.getBooleanProperty(INewServletClassDataModelProperties.DO_GET); - } - return false; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/INewServletClassDataModelProperties.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/INewServletClassDataModelProperties.java deleted file mode 100644 index cd739b1b7..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/INewServletClassDataModelProperties.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.operations; - -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; - -public interface INewServletClassDataModelProperties extends INewJavaClassDataModelProperties, IAnnotationsDataModel { - /** - * Optional, boolean property used to specify whether to generate the init method. - * The default is false. - */ - public static final String INIT = "NewServletClassDataModel.INIT"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doPost method. - * The default is true. - */ - public static final String DO_POST = "NewServletClassDataModel.DO_POST"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the destroy method. - * The default is false. - */ - public static final String DESTROY = "NewServletClassDataModel.DESTROY"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the toString method. - * The default is false. - */ - public static final String TO_STRING = "NewServletClassDataModel.TO_STRING"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doPut method. - * The default is false. - */ - public static final String DO_PUT = "NewServletClassDataModel.DO_PUT"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doGet method. - * The default is true. - */ - public static final String DO_GET = "NewServletClassDataModel.DO_GET"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the getServletInfo method. - * The default is false. - */ - public static final String GET_SERVLET_INFO = "NewServletClassDataModel.GET_SERVLET_INFO"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether to generate the doDelete method. - * The default is false. - */ - public static final String DO_DELETE = "NewServletClassDataModel.DO_DELETE"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to determine if building JSP or servlet. - * The default is true. - */ - public static final String IS_SERVLET_TYPE = "NewServletClassDataModel.IS_SERVLET_TYPE"; //$NON-NLS-1$ - - /** - * Optional, List property used to cache all the init params defined on the servlet. - */ - public static final String INIT_PARAM = "NewServletClassDataModel.INIT_PARAM"; //$NON-NLS-1$ - - /** - * Optional, List propety used to cache all the servlet mappings for this servlet on the web application. - */ - public static final String URL_MAPPINGS = "NewServletClassDataModel.URL_MAPPINGS"; //$NON-NLS-1$ - - /** - * Required, String property of the display name for the servlet - */ - public static final String DISPLAY_NAME = "NewServletClassDataModel.DISPLAY_NAME"; //$NON-NLS-1$ - - /** - * Optional, String property of the description info for the servlet - */ - public static final String DESCRIPTION = "NewServletClassDataModel.DESCRIPTION"; //$NON-NLS-1$ - - /** - * Optional, boolean property used to specify whether or not to gen a new java class. - * The default is false. - */ - public static final String USE_EXISTING_CLASS = "NewServletClassDataModel.USE_EXISTING_CLASS"; //$NON-NLS-1$ - - /** - * Do not set! The javajet template file used in creating the annotated servlet template class - */ - public static final String TEMPLATE_FILE = "NewServletClassDataModel.TEMPLATE_FILE"; //$NON-NLS-1$ - - /** - * Do not set! The javajet template file used in creating the non-annotated servlet template class - */ - public static final String NON_ANNOTATED_TEMPLATE_FILE = "NewServletClassDataModel.NON_ANNOTATED_TEMPLATE_FILE"; //$NON-NLS-1$ - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java deleted file mode 100644 index 4304b1fdd..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassDataModelProvider.java +++ /dev/null @@ -1,598 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.jst.j2ee.webapplication.Servlet; -import org.eclipse.jst.j2ee.webapplication.WebApp; -import org.eclipse.wst.common.componentcore.ArtifactEdit; -import org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; - -/** - * The NewServletClassDataModelProvider is a subclass of ArtifactEditOperationDataModelProvider and - * follows the IDataModel Operation and Wizard frameworks. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation - * - * This data model provider is a subclass of the NewJavaClassDataModelProvider, which stores base - * properties necessary in the creation of a default java class. - * @see org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider - * - * The NewServletClassDataModelProvider provides more specific properties for java class creation - * that are required in creating a servlet java class. The data model provider is used to store - * these values for the NewServletClassOperation. - * @see org.eclipse.jst.j2ee.internal.web.operations.INewServletClassDataModelProperties That - * operation will create the servlet java class based on the settings defined here in the data - * model. - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation - * - * This data model properties implements the IAnnotationsDataModel to get the USE_ANNOTATIONS - * property for determining whether or not to generate an annotated java class. - * @see org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel - * - * Clients can subclass this data model provider to cache and provide their own specific attributes. - * They should also provide their own validation methods, properties interface, and default values - * for the properties they add. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class NewServletClassDataModelProvider extends NewJavaClassDataModelProvider implements INewServletClassDataModelProperties { - - /** - * The fully qualified default servlet superclass: HttpServlet. - */ - private final static String SERVLET_SUPERCLASS = "javax.servlet.http.HttpServlet"; //$NON-NLS-1$ - /** - * String array of the default, minimum required fully qualified Servlet interfaces - */ - private final static String[] SERVLET_INTERFACES = {"javax.servlet.Servlet"}; //$NON-NLS-1$ - - private final static String ANNOTATED_TEMPLATE_DEFAULT = "servletXDoclet.javajet"; //$NON-NLS-1$ - - private final static String NON_ANNOTATED_TEMPLATE_DEFAULT = "servletXDocletNonAnnotated.javajet"; //$NON-NLS-1$ - - /** - * The cache of all the interfaces the servlet java class will implement. - */ - private List interfaceList; - - private static boolean useAnnotations = false; - - /** - * Subclasses may extend this method to provide their own default operation for this data model - * provider. This implementation uses the AddServletOperation to drive the servlet creation. It - * will not return null. - * - * @see IDataModel#getDefaultOperation() - * - * @return IDataModelOperation AddServletOperation - */ - public IDataModelOperation getDefaultOperation() { - return new AddServletOperation(getDataModel()); - } - - /** - * Subclasses may extend this method to provide their own determination of whether or not - * certain properties should be disabled or enabled. This method does not accept null parameter. - * It will not return null. This implementation makes sure annotation support is only allowed on - * web projects of J2EE version 1.3 or higher. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#isPropertyEnabled(String) - * @see IAnnotationsDataModel#USE_ANNOTATIONS - * - * @param propertyName - * @return boolean should property be enabled? - */ - public boolean isPropertyEnabled(String propertyName) { - // Annotations should only be enabled on a valid j2ee project of version 1.3 or higher - if (USE_ANNOTATIONS.equals(propertyName)) { - if (getBooleanProperty(USE_EXISTING_CLASS) || !isAnnotationsSupported()) - return false; - return true; - } - // Otherwise return super implementation - return super.isPropertyEnabled(propertyName); - } - - /** - * Subclasses may extend this method to add their own data model's properties as valid base - * properties. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - public Set getPropertyNames() { - // Add servlet specific properties defined in this data model - Set propertyNames = super.getPropertyNames(); - propertyNames.add(INIT); - propertyNames.add(DO_POST); - propertyNames.add(DESTROY); - propertyNames.add(TO_STRING); - propertyNames.add(DO_PUT); - propertyNames.add(DO_GET); - propertyNames.add(GET_SERVLET_INFO); - propertyNames.add(DO_DELETE); - propertyNames.add(IS_SERVLET_TYPE); - propertyNames.add(INIT_PARAM); - propertyNames.add(URL_MAPPINGS); - propertyNames.add(USE_ANNOTATIONS); - propertyNames.add(DISPLAY_NAME); - propertyNames.add(DESCRIPTION); - propertyNames.add(NON_ANNOTATED_TEMPLATE_FILE); - propertyNames.add(TEMPLATE_FILE); - propertyNames.add(USE_EXISTING_CLASS); - return propertyNames; - } - - /** - * Subclasses may extend this method to provide their own default values for any of the - * properties in the data model hierarchy. This method does not accept a null parameter. It may - * return null. This implementation sets annotation use to be true, and to generate a servlet - * with doGet and doPost. - * - * @see NewJavaClassDataModelProvider#getDefaultProperty(String) - * @see IDataModelProvider#getDefaultProperty(String) - * - * @param propertyName - * @return Object default value of property - */ - public Object getDefaultProperty(String propertyName) { - // Generate a doPost method by default - if (propertyName.equals(DO_POST)) - return Boolean.TRUE; - // Generate a doGet method by default - else if (propertyName.equals(DO_GET)) - return Boolean.TRUE; - // Use servlet by default - else if (propertyName.equals(IS_SERVLET_TYPE)) - return Boolean.TRUE; - // Create an annotated servlet java class by default - else if (propertyName.equals(USE_ANNOTATIONS)) - return shouldDefaultAnnotations(); - else if (propertyName.equals(DISPLAY_NAME)) { - String className = getStringProperty(CLASS_NAME); - if (className.endsWith(".jsp")) { //$NON-NLS-1$ - int index = className.lastIndexOf("/"); //$NON-NLS-1$ - className = className.substring(index+1,className.length()-4); - } else { - int index = className.lastIndexOf("."); //$NON-NLS-1$ - className = className.substring(index+1); - } - return className; - } - else if (propertyName.equals(URL_MAPPINGS)) - return getDefaultUrlMapping(); - else if (propertyName.equals(INTERFACES)) - return getServletInterfaces(); - else if (propertyName.equals(SUPERCLASS)) - return SERVLET_SUPERCLASS; - else if (propertyName.equals(TEMPLATE_FILE)) - return ANNOTATED_TEMPLATE_DEFAULT; - else if (propertyName.equals(NON_ANNOTATED_TEMPLATE_FILE)) - return NON_ANNOTATED_TEMPLATE_DEFAULT; - else if (propertyName.equals(USE_EXISTING_CLASS)) - return Boolean.FALSE; - // Otherwise check super for default value for property - return super.getDefaultProperty(propertyName); - } - - /** - * Returns the default Url Mapping depending upon the display name of the Servlet - * - * @return List containting the default Url Mapping - */ - private Object getDefaultUrlMapping() { - List urlMappings = null; - String text = (String) getProperty(DISPLAY_NAME); - if (text != null) { - urlMappings = new ArrayList(); - urlMappings.add(new String[]{"/" + text}); //$NON-NLS-1$ - } - return urlMappings; - } - - /** - * Subclasses may extend this method to add their own specific behaviour when a certain property - * in the data model heirarchy is set. This method does not accept null for the property name, - * but it will for propertyValue. It will not return null. It will return false if the set - * fails. This implementation verifies the display name is set to the classname, that the - * annotations is disabled/enabled properly, and that the target project name is determined from - * the source folder setting. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#propertySet(String, - * Object) - * - * @param propertyName - * @param propertyValue - * @return boolean was property set? - */ - public boolean propertySet(String propertyName, Object propertyValue) { - - // If annotations is changed, notify an enablement change - if (propertyName.equals(USE_ANNOTATIONS)) { - useAnnotations = ((Boolean) propertyValue).booleanValue(); - if (useAnnotations && !isAnnotationsSupported()) - return true; - getDataModel().notifyPropertyChange(USE_ANNOTATIONS, IDataModel.ENABLE_CHG); - } - // If the source folder is changed, ensure we have the correct project name - if (propertyName.equals(SOURCE_FOLDER)) { - // Get the project name from the source folder name - String sourceFolder = (String) propertyValue; - int index = sourceFolder.indexOf(File.separator); - String projectName = sourceFolder; - if (index == 0) - projectName = sourceFolder.substring(1); - index = projectName.indexOf(File.separator); - if (index != -1) { - projectName = projectName.substring(0, index); - setProperty(PROJECT_NAME, projectName); - } - } - // Call super to set the property on the data model - boolean result = super.propertySet(propertyName, propertyValue); - // If class name is changed, update the display name to be the same - if (propertyName.equals(CLASS_NAME) && !getDataModel().isPropertySet(DISPLAY_NAME)) { - getDataModel().notifyPropertyChange(DISPLAY_NAME, IDataModel.DEFAULT_CHG); - } - // After the property is set, if project changed, update the nature and the annotations - // enablement - if (propertyName.equals(COMPONENT_NAME)) { - getDataModel().notifyPropertyChange(USE_ANNOTATIONS, IDataModel.ENABLE_CHG); - } - // After property is set, if annotations is set to true, update its value based on the new - // level of the project - if (getBooleanProperty(USE_ANNOTATIONS)) { - if (!isAnnotationsSupported()) - setBooleanProperty(USE_ANNOTATIONS, false); - } - if (propertyName.equals(USE_EXISTING_CLASS)) { - getDataModel().notifyPropertyChange(USE_ANNOTATIONS, IDataModel.ENABLE_CHG); - if (((Boolean)propertyValue).booleanValue()) - setProperty(USE_ANNOTATIONS,Boolean.FALSE); - setProperty(JAVA_PACKAGE, null); - setProperty(CLASS_NAME, null); - } - // Return whether property was set - return result; - } - - /** - * This method is used to determine if annotations should try to enable based on workspace settings - * @return does any valid annotation provider or xdoclet handler exist - */ - //TODO add this method back in for defect 146696 -// protected boolean isAnnotationProviderDefined() { -// boolean isControllerEnabled = AnnotationsControllerManager.INSTANCE.isAnyAnnotationsSupported(); -// final String preferred = AnnotationPreferenceStore.getProperty(AnnotationPreferenceStore.ANNOTATIONPROVIDER); -// IAnnotationProvider annotationProvider = null; -// boolean isProviderEnabled = false; -// if (preferred != null) { -// try { -// annotationProvider = AnnotationUtilities.findAnnotationProviderByName(preferred); -// } catch (Exception ex) { -// //Default -// } -// if (annotationProvider != null && annotationProvider.isValid()) -// isProviderEnabled = true; -// } -// return isControllerEnabled || isProviderEnabled; -// } - - /** - * This method checks to see if valid annotation providers exist and if valid project version levels exist. - * @return should annotations be supported for this project in this workspace - */ - protected boolean isAnnotationsSupported() { - //TODO add this check back in for defect 146696 -// if (!isAnnotationProviderDefined()) -// return false; - if (!getDataModel().isPropertySet(IArtifactEditOperationDataModelProperties.PROJECT_NAME)) - return true; - if (getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME).equals("")) //$NON-NLS-1$ - return true; - IProject project = ProjectUtilities.getProject(getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME)); - String moduleName = getStringProperty(IArtifactEditOperationDataModelProperties.COMPONENT_NAME); - if (project == null || moduleName == null || moduleName.equals(""))return true; //$NON-NLS-1$ - WebArtifactEdit webEdit = null; - try { - webEdit = WebArtifactEdit.getWebArtifactEditForRead(project); - if (webEdit == null) - return true; - return webEdit.getJ2EEVersion() > J2EEVersionConstants.VERSION_1_2; - } catch (Exception e) { - e.printStackTrace(); - return false; - } finally { - if (webEdit != null) - webEdit.dispose(); - } - } - - /** - * Subclasses may extend this method to provide their own validation on any of the valid data - * model properties in the hierarchy. This implementation adds validation for the init params, - * servlet mappings, display name, and existing class fields specific to the servlet java class - * creation. It does not accept a null parameter. This method will not return null. - * - * @see NewJavaClassDataModelProvider#validate(String) - * - * @param propertyName - * @return IStatus is property value valid? - */ - public IStatus validate(String propertyName) { - IStatus result = Status.OK_STATUS; - // If our default is the superclass, we know it is ok - if (propertyName.equals(SUPERCLASS) && getStringProperty(propertyName).equals(SERVLET_SUPERCLASS)) - return WTPCommonPlugin.OK_STATUS; - // Validate init params - if (propertyName.equals(INIT_PARAM)) - return validateInitParamList((List) getProperty(propertyName)); - // Validate servlet mappings - if (propertyName.equals(URL_MAPPINGS)) - return validateURLMappingList((List) getProperty(propertyName)); - // Validate the servlet name in DD - if (propertyName.equals(DISPLAY_NAME)) - return validateDisplayName(getStringProperty(propertyName)); - if (propertyName.equals(CLASS_NAME)) { - if (getStringProperty(propertyName).length()!=0 && getBooleanProperty(USE_EXISTING_CLASS)) - return WTPCommonPlugin.OK_STATUS; - result = super.validateJavaClassName(getStringProperty(propertyName)); - if (result.isOK()) { - result = validateJavaClassName(getStringProperty(propertyName)); - if (result.isOK()&&!getBooleanProperty(USE_EXISTING_CLASS)) - result = canCreateTypeInClasspath(getStringProperty(CLASS_NAME)); - } - return result; - } - // Otherwise defer to super to validate the property - return super.validate(propertyName); - } - - /** - * Subclasses may extend this method to provide their own validation of the specified java - * classname. This implementation will ensure the class name is not set to Servlet and then will - * forward on to the NewJavaClassDataModel to validate the class name as valid java. This method - * does not accept null as a parameter. It will not return null. - * - * @see NewServletClassDataModelProvider#validateExistingClass(boolean) - * @see NewJavaClassDataModelProvider#validateJavaClassName(String) - * - * @param className - * @return IStatus is java classname valid? - */ - protected IStatus validateJavaClassName(String className) { - if (getBooleanProperty(USE_EXISTING_CLASS)) - return WTPCommonPlugin.OK_STATUS; - // First use the NewJavaClassDataModel to validate the classname as proper java syntax - IStatus status = super.validateJavaClassName(className); - if (status.isOK()) { - // Do not allow the name to be "Servlet" - if (className.equals("Servlet")) { //$NON-NLS-1$ - String msg = WebMessages.ERR_SERVLET_JAVA_CLASS_NAME_INVALID; - return WTPCommonPlugin.createErrorStatus(msg); - } - return WTPCommonPlugin.OK_STATUS; - } - // Return the status - return status; - } - - /** - * This method is intended for internal use only. It will be used to validate the init params - * list to ensure there are not any duplicates. This method will accept a null paramter. It will - * not return null. - * - * @see NewServletClassDataModelProvider#validate(String) - * - * @param prop - * @return IStatus is init params list valid? - */ - private IStatus validateInitParamList(List prop) { - if (prop != null && !prop.isEmpty()) { - // Ensure there are not duplicate entries in the list - boolean dup = hasDuplicatesInStringArrayList(prop); - if (dup) { - String msg = WebMessages.ERR_DUPLICATED_INIT_PARAMETER; - return WTPCommonPlugin.createErrorStatus(msg); - } - } - // Return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * This method is intended for internal use only. This will validate the servlet mappings list - * and ensure there are not duplicate entries. It will accept a null parameter. It will not - * return null. - * - * @see NewServletClassDataModelProvider#validate(String) - * - * @param prop - * @return IStatus is servlet mapping list valid? - */ - private IStatus validateURLMappingList(List prop) { - if (prop != null && !prop.isEmpty()) { - // Ensure there are not duplicates in the mapping list - boolean dup = hasDuplicatesInStringArrayList(prop); - if (dup) { - String msg = WebMessages.ERR_DUPLICATED_URL_MAPPING; - return WTPCommonPlugin.createErrorStatus(msg); - } - } else { - String msg = WebMessages.ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY; - return WTPCommonPlugin.createErrorStatus(msg); - } - // Return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * This method is intended for internal use only. It provides a simple algorithm for detecting - * if there are duplicate entries in a list. It will accept a null paramter. It will not return - * null. - * - * @see NewServletClassDataModelProvider#validateInitParamList(List) - * @see NewServletClassDataModelProvider#validateURLMappingList(List) - * - * @param input - * @return boolean are there dups in the list? - */ - private boolean hasDuplicatesInStringArrayList(List input) { - // If list is null or empty return false - if (input == null) - return false; - int n = input.size(); - boolean dup = false; - // nested for loops to check each element to see if other elements are the same - for (int i = 0; i < n; i++) { - String[] sArray1 = (String[]) input.get(i); - for (int j = i + 1; j < n; j++) { - String[] sArray2 = (String[]) input.get(j); - if (isTwoStringArraysEqual(sArray1, sArray2)) { - dup = true; - break; - } - } - if (dup) - break; - } - // Return boolean status for duplicates - return dup; - } - - /** - * This method is intended for internal use only. This checks to see if the two string arrays - * are equal. If either of the arrays are null or empty, it returns false. - * - * @see NewServletClassDataModelProvider#hasDuplicatesInStringArrayList(List) - * - * @param sArray1 - * @param sArray2 - * @return boolean are Arrays equal? - */ - private boolean isTwoStringArraysEqual(String[] sArray1, String[] sArray2) { - // If either array is null, return false - if (sArray1 == null || sArray2 == null) - return false; - int n1 = sArray1.length; - int n2 = sArray1.length; - // If either array is empty, return false - if (n1 == 0 || n2 == 0) - return false; - // If they don't have the same length, return false - if (n1 != n2) - return false; - // If their first elements do not match, return false - if (!sArray1[0].equals(sArray2[0])) - return false; - // Otherwise return true - return true; - } - - /** - * This method will return the list of servlet interfaces to be implemented for the new servlet - * java class. It will intialize the list using lazy initialization to the minimum interfaces - * required by the data model SERVLET_INTERFACES. This method will not return null. - * - * @see INewServletClassDataModelProperties#SERVLET_INTERFACES - * - * @return List of servlet interfaces to be implemented - */ - private List getServletInterfaces() { - if (interfaceList == null) { - interfaceList = new ArrayList(); - // Add minimum required list of servlet interfaces to be implemented - for (int i = 0; i < SERVLET_INTERFACES.length; i++) { - interfaceList.add(SERVLET_INTERFACES[i]); - } - } - // Return interface list - return interfaceList; - } - - /** - * This method is intended for internal use only. This will validate whether the display name - * selected is a valid display name for the servlet in the specified web application. It will - * make sure the name is not empty and that it doesn't already exist in the web app. This method - * will accept null as a parameter. It will not return null. - * - * @see NewServletClassDataModelProvider#validate(String) - * - * @param prop - * @return IStatus is servlet display name valid? - */ - private IStatus validateDisplayName(String prop) { - // Ensure the servlet display name is not null or empty - if (prop == null || prop.trim().length() == 0) { - String msg = WebMessages.ERR_DISPLAY_NAME_EMPTY; - return WTPCommonPlugin.createErrorStatus(msg); - } - if (getTargetProject() == null || getTargetComponent() == null) - return WTPCommonPlugin.OK_STATUS; - ArtifactEdit edit = null; - try { - edit = getArtifactEditForRead(); - if (edit == null) - return WTPCommonPlugin.OK_STATUS; - WebApp webApp = (WebApp) edit.getContentModelRoot(); - if (webApp == null) - return WTPCommonPlugin.OK_STATUS; - List servlets = webApp.getServlets(); - boolean exists = false; - // Ensure the display does not already exist in the web application - if (servlets != null && !servlets.isEmpty()) { - for (int i = 0; i < servlets.size(); i++) { - String name = ((Servlet) servlets.get(i)).getServletName(); - if (prop.equals(name)) - exists = true; - } - } - // If the servlet name already exists, throw an error - if (exists) { - String msg = WebMessages.getResourceString(WebMessages.ERR_SERVLET_DISPLAY_NAME_EXIST, new String[]{prop}); - return WTPCommonPlugin.createErrorStatus(msg); - } - } finally { - if (edit != null) - edit.dispose(); - } - - // Otherwise, return OK - return WTPCommonPlugin.OK_STATUS; - } - - /** - * @return boolean should the default annotations be true? - */ - private static Boolean shouldDefaultAnnotations() { - if (useAnnotations) - return Boolean.TRUE; - return Boolean.FALSE; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java deleted file mode 100644 index 7aeef25c6..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/NewServletClassOperation.java +++ /dev/null @@ -1,420 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.operations; - -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.codegen.jet.JETEmitter; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaModelMarker; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsController; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager; -import org.eclipse.jst.common.internal.annotations.controller.AnnotationsControllerManager.Descriptor; -import org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel; -import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties; -import org.eclipse.jst.j2ee.internal.project.WTPJETEmitter; -import org.eclipse.jst.j2ee.internal.web.plugin.WebPlugin; -import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider; -import org.eclipse.wst.common.componentcore.datamodel.FacetProjectCreationDataModelProvider; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties.FacetDataModelMap; -import org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.enablement.nonui.WFTWrappedException; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -/** - * The NewServletClassOperation is an IDataModelOperation following the - * IDataModel wizard and operation framework. - * - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider - * - * It extends ArtifactEditProviderOperation to provide servlet specific java - * class generation. - * @see org.eclipse.wst.common.componentcore.internal.operation.ArtifactEditProviderOperation - * - * This operation is used by the AddServletOperation to generate either an - * annotated or non annotated java class for an added servlet. It shares the - * NewServletClassDataModelProvider with the AddServletOperation to store the - * appropriate properties required to generate the new servlet. - * @see org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation - * @see org.eclipse.jst.j2ee.internal.web.operations.NewServletClassDataModelProvider - * - * In the annotated case, a WTPJetEmitter servlet template is created and used - * to generate the servlet java class with the embedded annotated tags. - * @see org.eclipse.jst.j2ee.internal.project.WTPJETEmitter - * @see org.eclipse.jst.j2ee.internal.web.operations.CreateServletTemplateModel - * - * In the non annotated case, the same emitter is used to create the class with - * the non annotated servlet template so the annotated tags are omitted. - * - * Subclasses may extend this operation to provide their own specific servlet - * java class generation. The execute method may be extended to do so. Also, - * generateUsingTemplates is exposed. - * - * The use of this class is EXPERIMENTAL and is subject to substantial changes. - */ -public class NewServletClassOperation extends ArtifactEditProviderOperation { - - /** - * XDoclet facet constants - */ - private static final String JST_WEB_XDOCLET_VERSION = "1.2.3"; //$NON-NLS-1$ - private static final String JST_WEB_XDOCLET = "jst.web.xdoclet"; //$NON-NLS-1$ - - /** - * The extension name for a java class - */ - private static final String DOT_JAVA = ".java"; //$NON-NLS-1$ - - /** - * platform plugin beginning for URI string - */ - // private static final String PLATFORM_PLUGIN = "platform:/plugin/"; - // //$NON-NLS-1$ - /** - * variable for the web plugin - */ - protected static final String WEB_PLUGIN = "WEB_PLUGIN"; //$NON-NLS-1$ - - /** - * folder location of the servlet creation templates diretory - */ - protected static final String TEMPLATE_DIR = "/templates/"; //$NON-NLS-1$ - - /** - * name of the template emitter to be used to generate the deployment - * descriptor from the tags - */ - protected static final String TEMPLATE_EMITTER = "org.eclipse.jst.j2ee.ejb.annotations.emitter.template"; //$NON-NLS-1$ - - /** - * id of the builder used to kick off generation of web metadata based on - * parsing of annotations - */ - protected static final String BUILDER_ID = "builderId"; //$NON-NLS-1$ - - /** - * This is the constructor which should be used when creating a - * NewServletClassOperation. An instance of the NewServletClassDataModel - * should be passed in. This does not accept null parameter. It will not - * return null. - * - * @see ArtifactEditProviderOperation#ArtifactEditProviderOperation(IDataModel) - * @see NewServletClassDataModel - * - * @param dataModel - * @return NewServletClassOperation - */ - public NewServletClassOperation(IDataModel dataModel) { - super(dataModel); - } - - /** - * Subclasses may extend this method to add their own actions during - * execution. The implementation of the execute method drives the running of - * the operation. This implemenatation will create the java source folder, - * create the java package, and then if using annotations, will use - * templates to generate an annotated servlet java class, or if it is not - * annotated, the servlet java class file will be created without the - * annotated tags using templates. Optionally, subclasses may extend the - * generateUsingTemplates or createJavaFile method rather than extend the - * execute method. This method will accept a null paramter. - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperation#execute(org.eclipse.core.runtime.IProgressMonitor) - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * - * @param monitor - * @throws CoreException - * @throws InterruptedException - * @throws InvocationTargetException - */ - public IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // Create source folder if it does not exist - createJavaSourceFolder(); - // Create java package if it does not exist - IPackageFragment pack = createJavaPackage(); - // Generate using templates - try { - generateUsingTemplates(monitor, pack); - } catch (Exception e) { - return WTPCommonPlugin.createErrorStatus(e.toString()); - } - return OK_STATUS; - } - - /** - * This method will return the java package as specified by the new java - * class data model. If the package does not exist, it will create the - * package. This method should not return null. - * - * @see INewJavaClassDataModelProperties#JAVA_PACKAGE - * @see IPackageFragmentRoot#createPackageFragment(java.lang.String, - * boolean, org.eclipse.core.runtime.IProgressMonitor) - * - * @return IPackageFragment the java package - */ - protected final IPackageFragment createJavaPackage() { - // Retrieve the package name from the java class data model - String packageName = model.getStringProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE); - IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model - .getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT); - IPackageFragment pack = packRoot.getPackageFragment(packageName); - // Handle default package - if (pack == null) { - pack = packRoot.getPackageFragment(""); //$NON-NLS-1$ - } - // Create the package fragment if it does not exist - if (!pack.exists()) { - String packName = pack.getElementName(); - try { - pack = packRoot.createPackageFragment(packName, true, null); - } catch (JavaModelException e) { - Logger.getLogger().log(e); - } - } - // Return the package - return pack; - } - - /** - * Subclasses may extend this method to provide their own template based - * creation of an annotated servlet java class file. This implementation - * uses the creation of a CreateServletTemplateModel and the WTPJetEmitter - * to create the java class with the annotated tags. This method accepts - * null for monitor, it does not accept null for fragment. If annotations - * are not being used the tags will be omitted from the class. - * - * @see CreateServletTemplateModel - * @see NewServletClassOperation#generateTemplateSource(CreateServletTemplateModel, - * IProgressMonitor) - * - * @param monitor - * @param fragment - * @throws CoreException - * @throws WFTWrappedException - */ - protected void generateUsingTemplates(IProgressMonitor monitor, IPackageFragment fragment) throws WFTWrappedException, CoreException { - // Create the servlet template model - CreateServletTemplateModel tempModel = createTemplateModel(); - IProject project = getTargetProject(); - String source; - // Using the WTPJetEmitter, generate the java source based on the servlet template model - try { - source = generateTemplateSource(tempModel, monitor); - } catch (Exception e) { - throw new WFTWrappedException(e); - } - if (fragment != null) { - // Create the java file - String javaFileName = tempModel.getServletClassName() + DOT_JAVA; - ICompilationUnit cu = fragment.getCompilationUnit(javaFileName); - // Add the compilation unit to the java file - if (cu == null || !cu.exists()) - cu = fragment.createCompilationUnit(javaFileName, source, true, monitor); - IFile aFile = (IFile) cu.getResource(); - // Let the annotations controller process the annotated resource - AnnotationsController controller = AnnotationsControllerManager.INSTANCE.getAnnotationsController(project); - if (controller != null) - controller.process(aFile); - } - - // Add the xdoclet facet, if necessary, for xdoclet servlet creation - try { - installXDocletFacetIfNecessary(monitor, project); - } catch (Exception e) { - throw new WFTWrappedException(e); - } - } - - /** - * This method is intended for internal use only. This will add an webdoclet facet to the project. - * - * @throws CoreException - * @throws ExecutionException - */ - private void installXDocletFacet(IProgressMonitor monitor, IProject project) throws CoreException, ExecutionException { - IFacetedProject facetedProject = ProjectFacetsManager.create(project); - Set fixedFacets = facetedProject.getFixedProjectFacets(); - IDataModel dm = DataModelFactory.createDataModel(new FacetInstallDataModelProvider()); - dm.setProperty(IFacetDataModelProperties.FACET_ID, JST_WEB_XDOCLET); - dm.setProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, project.getName()); - dm.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JST_WEB_XDOCLET_VERSION); - IDataModel fdm = DataModelFactory.createDataModel(new FacetProjectCreationDataModelProvider()); - fdm.setProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME, project.getName()); - - FacetDataModelMap map = (FacetDataModelMap) fdm.getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP); - map.add(dm); - - fdm.getDefaultOperation().execute(monitor, null); - facetedProject.setFixedProjectFacets(fixedFacets); - } - - /** - * This method is intended for internal use only. This will check to see if it needs to add an - * webdoclet facet to the project. - * - * @throws CoreException - * @throws ExecutionException - */ - private void installXDocletFacetIfNecessary(IProgressMonitor monitor, IProject project) throws CoreException, ExecutionException { - - // If not using annotations, ignore the xdoclet facet - if (!model.getBooleanProperty(IAnnotationsDataModel.USE_ANNOTATIONS)) - return; - - // If an extended annotations processor is added, ignore the default xdoclet one - Descriptor descriptor = AnnotationsControllerManager.INSTANCE.getDescriptor(getTargetComponent().getProject()); - if (descriptor != null) - return; - - // Otherwise check and see if the xdoclet facet is on the project yet - IFacetedProject facetedProject = ProjectFacetsManager.create(project); - Set facets = facetedProject.getProjectFacets(); - for (Iterator iter = facets.iterator(); iter.hasNext();) { - IProjectFacetVersion facetVersion = (IProjectFacetVersion) iter.next(); - String facetID = facetVersion.getProjectFacet().getId(); - if (JST_WEB_XDOCLET.equals(facetID)) - return; - } - // Install xdoclet facet - installXDocletFacet(monitor, project); - } - - /** - * This method is intended for internal use only. This will use the - * WTPJETEmitter to create an annotated java file based on the passed in - * servlet class template model. This method does not accept null - * parameters. It will not return null. If annotations are not used, it will - * use the non annotated template to omit the annotated tags. - * - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * @see JETEmitter#generate(org.eclipse.core.runtime.IProgressMonitor, - * java.lang.Object[]) - * @see CreateServletTemplateModel - * - * @param tempModel - * @param monitor - * @return String the source for the java file - * @throws JETException - */ - private String generateTemplateSource(CreateServletTemplateModel tempModel, IProgressMonitor monitor) throws JETException { - URL templateURL = null; - // If annotated, use annotated template - if (model.getBooleanProperty(IAnnotationsDataModel.USE_ANNOTATIONS)) - templateURL = WebPlugin.getDefault().find( - new Path(TEMPLATE_DIR + getDataModel().getStringProperty(INewServletClassDataModelProperties.TEMPLATE_FILE))); - // Otherwise use non annotated template - else - templateURL = WebPlugin.getDefault().find( - new Path(TEMPLATE_DIR - + getDataModel().getStringProperty(INewServletClassDataModelProperties.NON_ANNOTATED_TEMPLATE_FILE))); - cleanUpOldEmitterProject(); - WTPJETEmitter emitter = new WTPJETEmitter(templateURL.toString(), this.getClass().getClassLoader()); - emitter.setIntelligentLinkingEnabled(true); - emitter.addVariable(WEB_PLUGIN, WebPlugin.PLUGIN_ID); - return emitter.generate(monitor, new Object[] { tempModel }); - } - - private void cleanUpOldEmitterProject() { - IProject project = ProjectUtilities.getProject(WTPJETEmitter.PROJECT_NAME); - if (project == null || !project.exists()) - return; - try { - IMarker[] markers = project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); - for (int i = 0, l = markers.length; i < l; i++) { - if (((Integer) markers[i].getAttribute(IMarker.SEVERITY)).intValue() == IMarker.SEVERITY_ERROR) { - project.delete(true, new NullProgressMonitor()); - break; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * This method is intended for internal use only. This method will create an - * instance of the CreateServletTemplate model to be used in conjunction - * with the WTPJETEmitter. This method will not return null. - * - * @see CreateServletTemplateModel - * @see NewServletClassOperation#generateUsingTemplates(IProgressMonitor, - * IPackageFragment) - * - * @return CreateServletTemplateModel - */ - private CreateServletTemplateModel createTemplateModel() { - // Create the CreateServletTemplateModel instance with the new servlet - // class data model - CreateServletTemplateModel templateModel = new CreateServletTemplateModel(model); - return templateModel; - } - - /** - * This method will return the java source folder as specified in the java - * class data model. It will create the java source folder if it does not - * exist. This method may return null. - * - * @see INewJavaClassDataModelProperties#SOURCE_FOLDER - * @see IFolder#create(boolean, boolean, - * org.eclipse.core.runtime.IProgressMonitor) - * - * @return IFolder the java source folder - */ - protected final IFolder createJavaSourceFolder() { - // Get the source folder name from the data model - String folderFullPath = model.getStringProperty(INewJavaClassDataModelProperties.SOURCE_FOLDER); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFolder folder = root.getFolder(new Path(folderFullPath)); - // If folder does not exist, create the folder with the specified path - if (!folder.exists()) { - try { - folder.create(true, true, null); - } catch (CoreException e) { - Logger.getLogger().log(e); - } - } - // Return the source folder - return folder; - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java deleted file mode 100644 index 3f3721c80..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/operations/WebMessages.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jan 13, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.j2ee.internal.web.operations; - -import org.eclipse.osgi.util.NLS; - - -/** - * @author jialin - * - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public class WebMessages extends NLS { - private static final String BUNDLE_NAME = "web";//$NON-NLS-1$ - - private WebMessages() { - // Do not instantiate - } - - public static String ERR_JAR_NAME_EMPTY; - public static String ERR_JAR_NAME_EXIST; - public static String ERR_JAVA_PROJECT_NAME_EMPTY; - public static String ERR_JAVA_PROJECT_NAME_EXIST; - public static String ERR_DUPLICATED_INIT_PARAMETER; - public static String ERR_DUPLICATED_URL_MAPPING; - - public static String ERR_SERVLET_MAPPING_URL_PATTERN_EMPTY; - public static String ERR_SERVLET_MAPPING_URL_PATTERN_EXIST; - public static String KEY_3; - public static String KEY_4; - public static String KEY_5; - public static String KEY_6; - public static String ERR_FILTER_PARAMETER_NAME_EXIST; - public static String ERR_FILTER_MAPPING_SERVLET_EXIST; - public static String ERR_FILTER_MAPPING_SERVLET_DISPATCHER_TYPES_EMPTY; - public static String ERR_DISPLAY_NAME_EMPTY; - public static String ERR_SERVLET_NAME_EXIST; - public static String ERR_SERVLET_DISPLAY_NAME_EXIST; - public static String ERR_SERVLET_CLASS_NAME_USED; - public static String ERR_SERVLET_JAVA_CLASS_NAME_INVALID; - public static String ERR_SERVLET_MAPPING_SERVLET_NOT_EXIST; - public static String ERR_SERVLET_PARAMETER_NAME_EMPTY; - public static String ERR_SERVLET_PARAMETER_NAME_EXIST; - public static String ERR_SERVLET_PARAMETER_VALUE_EMPTY; - public static String ERR_SERVLET_PARAMETER_VALUE_EXIST; - public static String ERR_SERVLET_ROLE_REF_NAME_EMPTY; - public static String ERR_SERVLET_ROLE_REF_NAME_EXIST; - public static String ERR_SERVLET_ROLE_LINK_EMPTY; - - public static String ERR_FILTER_DISPLAY_NAME_EXIST; - public static String ERR_FILTER_CLASS_NAME_USED; - public static String ERR_FILTER_CLASS_NAME_INVALID; - public static String ERR_LISTENER_DISPLAY_NAME_EXIST; - public static String ERR_LISTENER_CLASS_NAME_USED; - public static String ERR_LISTENER_CLASS_NAME_INVALID; - - public static String ERR_PAGE_ENCODING_EMPTY; - public static String ERR_PAGE_ENCODING_EXIST; - public static String ERR_URL_PATTERN_EXIST; - public static String ERR_INCLUDE_PRELUDES_EXIST; - public static String ERR_INCLUDE_CODAS_EXIST; - public static String ERR_SECURITY_CONSTRAINT_NAME_EMPTY; - public static String ERR_SECURITY_CONSTRAINT_NAME_EXIST; - public static String ERR_CONTEXT_PARAMETER_NAME_EMPTY; - public static String ERR_CONTEXT_PARAMETER_NAME_EXIST; - public static String ERR_RESOURCE_NAME_EMPTY; - public static String ERR_RESOURCE_NAME_EXIST; - public static String ERR_URL_PATTERNS_EMPTY; - public static String ERR_MIME_MAPPING_EXTENSION_EMPTY; - public static String ERR_MIME_MAPPING_EXTENSION_EXIST; - public static String ERR_WELCOME_PAGE_EMPTY; - public static String ERR_WELCOME_PAGE_EXIST; - public static String ERR_ENV_ENTRY_NAME_EMPTY; - public static String ERR_ENV_ENTRY_NAME_EXIST; - public static String ERR_ERROR_CODE_EMPTY; - public static String ERR_ERROR_CODE_MUST_BE_3_DIGITS; - public static String ERR_ERROR_PAGE_LOCATION_EMPTY; - public static String ERR_ERROR_PAGE_LOCATION_EXIST; - public static String ERR_ERROR_PAGE_LOCATION_MUST_START_WITH_SLASH; - public static String ERR_EXCEPTION_TYPE_EMPTY; - public static String ERR_EXCEPTION_SECURITY_ID_NO_BEANS; - public static String ERR_EXCEPTION_ROLE_NAME_EMPTY; - public static String ERR_LOCALE_NAME_EMPTY; - public static String ERR_LOCALE_NAME_EXIST; - public static String ERR_TAGLIBREF_URL_EMPTY; - public static String ERR_TAGLIBREF_URL_EXIST; - public static String ERR_MESSAGE_DESTINATION_NAME_EMPTY; - public static String ERR_MESSAGE_DESTINATION_NAME_EXIST; - public static String ERR_EXCEPTION_METHOD_ELEMENT_EMPTY; - public static String ERR_EXCEPTION_METHOD_TRANSACTION_ATTRIBUTES_EMPTY; - public static String ERR_SERVLET_LIST_EMPTY; - public static String ERR_FILTER_LIST_EMPTY; - public static String ERR_LISTENER_LIST_EMPTY; - - static { - NLS.initializeMessages(BUNDLE_NAME, WebMessages.class); - } - - public static String getResourceString(String key, Object[] args) { - return NLS.bind(key, args); - } -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java deleted file mode 100644 index 52d3f91de..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebModuleExtensionImpl.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Sep 29, 2003 - * - * To change the template for this generated file go to Window>Preferences>Java>Code - * Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.web.plugin; - -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.j2ee.application.Module; -import org.eclipse.jst.j2ee.application.WebModule; -import org.eclipse.jst.j2ee.internal.moduleextension.EarModuleExtensionImpl; -import org.eclipse.jst.j2ee.internal.moduleextension.WebModuleExtension; -import org.eclipse.jst.j2ee.internal.project.J2EEJavaProjectInfo; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentImportDataModelProvider; -import org.eclipse.jst.j2ee.internal.web.archive.operations.WebFacetProjectCreationDataModelProvider; -import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - - - -public class WebModuleExtensionImpl extends EarModuleExtensionImpl implements WebModuleExtension { - - /** - * - */ - public WebModuleExtensionImpl() { - super(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#createProjectInfo() - */ - public J2EEJavaProjectInfo createProjectInfo() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#addWLPProjects(org.eclipse.core.resources.IProject, - * java.util.Set) - */ - public void addWLPProjects(IProject aProject, Set projectsToBuild) { - // J2EEWebNatureRuntime nature = J2EEWebNatureRuntime.getRuntime(aProject); - // if (nature == null) - // return; - // ILibModule[] libModules = nature.getLibModules(); - // for (int i = 0; i < libModules.length; i++) { - // IProject p = libModules[i].getProject(); - // if (p.isAccessible()) - // projectsToBuild.add(libModules[i].getProject()); - // } - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#setContextRootForModuleMapping(org.eclipse.jst.j2ee.internal.internal.application.WebModule, - * org.eclipse.core.resources.IProject) - */ - public void setContextRootForModuleMapping(WebModule webModule, IProject nestedProject) throws CoreException { - WebArtifactEdit webEdit = null; - try { - // TODO migrate to flex project - // webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead( nestedProject - // ); - if (webEdit != null) { - webEdit.setServerContextRoot(webModule.getContextRoot()); - } - } finally { - if (webEdit != null) - webEdit.dispose(); - } - // if (wnr != null) { - // wnr.setContextRoot(webModule.getContextRoot()); - // } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#hasRuntime(org.eclipse.core.resources.IProject) - */ - public boolean hasRuntime(IProject project) { - // return J2EEWebNatureRuntimeUtilities.hasJ2EERuntime(project); - // To do: work based on module - return false; - } - - // public J2EEImportOperationOLD createImportOperation(IProject - // nestedProject, WARFile warFile, EARImportConfiguration importConfig){ - // WarImportOperation op = new WarImportOperation(nestedProject, warFile); - // //op.setServerTarget(info.getServerTarget()); - // HashMap opMap = importConfig.createProjectOption; - // if(opMap != null && !opMap.isEmpty()) - // op.createWLProjectOptions = opMap; - // return op; - // } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#getContentFolder(org.eclipse.core.resources.IProject, - * org.eclipse.jst.j2ee.internal.internal.commonarchivecore.File) - */ - - public String getContentFolder(IProject project, IFile webSettingsFile) { - String contentFolder = null; - - // WebSettings webSettings = new WebSettings(project, webSettingsFile); - // if (webSettings != null) { - // contentFolder = webSettings.getWebContentName(); - // } - // To do: Needs work here, no content folder exists now - WebArtifactEdit webEdit = null; - try { - // TODO migrate to flex project - // webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead(project); - if (webEdit != null) { - - } - } finally { - if (webEdit != null) - webEdit.dispose(); - } - - return contentFolder; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.WebModuleExtension#compareWebContextRoot(org.eclipse.jst.j2ee.internal.internal.application.Module, - * org.eclipse.core.resources.IProject) - */ - public boolean compareWebContextRoot(Module module, IProject project) throws CoreException { - String contextRoot = ((WebModule) module).getContextRoot(); - if (contextRoot != null) - return ((contextRoot).equals(getServerContextRoot(project))); - return false; - } - - protected String getServerContextRoot(IProject project) { - WebArtifactEdit webEdit = null; - try { - // TODO migrate to flex project - // webEdit = (WebArtifactEdit) StructureEdit.getFirstArtifactEditForRead(project); - if (webEdit != null) { - return webEdit.getServerContextRoot(); - } - } finally { - if (webEdit != null) - webEdit.dispose(); - } - return ""; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.EarModuleExtension#createProjectDataModel() - */ - public IDataModel createProjectDataModel() { - return DataModelFactory.createDataModel(new WebFacetProjectCreationDataModelProvider()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jst.j2ee.internal.internal.moduleextension.EarModuleExtension#createImportDataModel() - */ - public IDataModel createImportDataModel() { - return DataModelFactory.createDataModel(new WebComponentImportDataModelProvider()); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java b/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java deleted file mode 100644 index 06c086621..000000000 --- a/plugins/org.eclipse.jst.j2ee.web/web/org/eclipse/jst/j2ee/internal/web/plugin/WebPlugin.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.internal.web.plugin; - -import java.io.IOException; -import java.net.URL; -import java.text.MessageFormat; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.ResourceLocator; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.web.util.WebEditAdapterFactory; -import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel; -import org.eclipse.wst.common.frameworks.internal.WTPPlugin; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - - -/** - * This is a top-level class of the j2ee plugin. - * - */ - -public class WebPlugin extends WTPPlugin implements ResourceLocator { - // Default instance of the receiver - private static WebPlugin inst; - protected final IPath iconsFolder = new Path(Platform.getBundle(PLUGIN_ID).getEntry("icons").getPath()); //$NON-NLS-1$ - // Links View part of the plugin - //public static final String LINKS_BUILDER_ID = - // "com.ibm.etools.links.management.linksbuilder";//$NON-NLS-1$ - public static final String LINKS_BUILDER_ID = "com.ibm.etools.webtools.additions.linksbuilder"; //$NON-NLS-1$ - // LibDir Change Listener - public static final String LIBDIRCHANGE_BUILDER_ID = "com.ibm.etools.webtools.LibDirBuilder"; //$NON-NLS-1$ - public static final String PLUGIN_ID = "org.eclipse.jst.j2ee.web"; //$NON-NLS-1$ - // LibCopy builder ID - public static final String LIBCOPY_BUILDER_ID = "org.eclipse.jst.j2ee.LibCopyBuilder"; //$NON-NLS-1$ - // Validation part of the plugin - //Global ResourceSet (somewhat global) - private static IPath location; - public static final String[] ICON_DIRS = new String[]{"icons/full/obj16", //$NON-NLS-1$ - "icons/full/cview16", //$NON-NLS-1$ - "icons/full/ctool16", //$NON-NLS-1$ - "icons/full/clcl16", //$NON-NLS-1$ - "icons/full/ovr16", //$NON-NLS-1$ - "icons/full/extra", //$NON-NLS-1$ - "icons/full/wizban", //$NON-NLS-1$ - "icons", //$NON-NLS-1$ - ""}; //$NON-NLS-1$ - - /** - * Create the J2EE plugin and cache its default instance - */ - public WebPlugin() { - super(); - if (inst == null) - inst = this; - } - - /** - * Get the plugin singleton. - */ - static public WebPlugin getDefault() { - return inst; - } - - /* - * Javadoc copied from interface. - */ - public URL getBaseURL() { - return getBundle().getEntry("/"); //$NON-NLS-1$ - } - - public Object[] getJ2EEWebProjectMigrationExtensions() { - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint pct = registry.getExtensionPoint(getBundle().getSymbolicName(), "J2EEWebProjectMigrationExtension"); //$NON-NLS-1$ - - IExtension[] extension = pct.getExtensions(); - List ret = new Vector(); - for (int l = 0; l < extension.length; ++l) { - IExtension config = extension[l]; - - IConfigurationElement[] cElems = config.getConfigurationElements(); - for (int i = 0; i < cElems.length; i++) { - IConfigurationElement d = cElems[i]; - if (d.getName().equals("migration")) { //$NON-NLS-1$ - try { - Object me = d.createExecutableExtension("run"); //$NON-NLS-1$ - - ret.add(me); - } catch (Exception ex) { - // ignore this extension, keep going - } - } - } - } - - return ret.toArray(); - } - - /** - * This gets a .gif from the icons folder. - */ - public Object getImage(String key) { - return J2EEPlugin.getImageURL(key, getBundle()); - } - - // ISSUE: this method is never used in WTP. Seems no need to be API - public static IPath getInstallLocation() { - if (location == null) { - String installLocation = getDefault().getBundle().getLocation(); - location = new Path(installLocation); - } - return location; - } - - public static URL getInstallURL() { - return getDefault().getBundle().getEntry("/"); //$NON-NLS-1$ - } - - /** - * Get the singleton instance. - */ - public static WebPlugin getPlugin() { - return inst; - } - - /** - * Return the plugin directory location- the directory that all the plugins are located in (i.e. - * d:\installdir\plugin) - */ - public static IPath getPluginLocation(String pluginId) { - Bundle bundle = Platform.getBundle(pluginId); - if (bundle != null) { - try { - IPath installPath = new Path(bundle.getEntry("/").toExternalForm()).removeTrailingSeparator(); //$NON-NLS-1$ - String installStr = Platform.asLocalURL(new URL(installPath.toString())).getFile(); - return new Path(installStr); - } catch (IOException e) { - //Do nothing - } - } - return null; - } - - /** - * Return the Servlets Jar file path preference. - * - * @return String the file path to the servlets jar, or null if never specified. - * @deprecated - the preference store is no longer on this plugin because of the UI dependency. - */ - public String getPreferenceServletsJar() { - // return getPreferenceStore().getString(IWebToolingCoreConstants.PROP_SERVLET_JAR); - return "THIS IS THE WRONG PATH - NEED TO CHANGE IMPLEMENTATION!!!!!"; //$NON-NLS-1$ - } - - /** - * Return the Servlets Jar file path preference. - * - * @return String the file path to the servlets jar, or null if never specified. - * @deprecated - the preference store is no longer on this plugin because of the UI dependency. - */ - public String getPreferenceWebASJar() { - //return getPreferenceStore().getString(IWebToolingCoreConstants.PROP_WEBAS_JAR); - return "THIS IS THE WRONG PATH - NEED TO CHANGE IMPLEMENTATION!!!!!"; //$NON-NLS-1$ - } - - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation, - * or to throw a core exception in a context other than executing an operation - * - * Create a new IStatus of type ERROR using the J2EEPlugin ID. aCode is just an internal code. - */ - public static IStatus newErrorStatus(int aCode, String aMessage, Throwable exception) { - return newStatus(IStatus.ERROR, aCode, aMessage, exception); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation, - * or to throw a core exception in a context other than executing an operation - * - * Create a new IStatus of type ERROR, code OPERATION_FAILED, using the J2EEPlugin ID - */ - public static IStatus newErrorStatus(String aMessage, Throwable exception) { - return newErrorStatus(0, aMessage, exception); - } - - /** - * If this is called from an operation, in response to some other exception that was caught, - * then the client code should throw {@link com.ibm.etools.wft.util.WFTWrappedException}; - * otherwise this can still be used to signal some other error condition within the operation. - * - * Create a new IStatus of type ERROR, code OPERATION_FAILED, using the J2EEPlugin ID - */ - public static IStatus newOperationFailedStatus(String aMessage, Throwable exception) { - return newStatus(IStatus.ERROR, IResourceStatus.OPERATION_FAILED, aMessage, exception); - } - - /** - * Create a new IStatus with a severity using the J2EEPlugin ID. aCode is just an internal code. - */ - public static IStatus newStatus(int severity, int aCode, String aMessage, Throwable exception) { - return new Status(severity, PLUGIN_ID, aCode, aMessage, exception); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key) { - return Platform.getResourceString(getBundle(), key); - } - - /* - * Javadoc copied from interface. - */ - public String getString(String key, Object[] substitutions) { - return MessageFormat.format(getString(key), substitutions); - } - - public void stop(BundleContext context) throws Exception { - super.stop(context); - } - - public void start(BundleContext context) throws Exception { - super.start(context); - //WebAppResourceFactory.register(WTPResourceFactoryRegistry.INSTANCE); - IAdapterManager manager = Platform.getAdapterManager(); - manager.registerAdapters(new WebEditAdapterFactory(), ArtifactEditModel.class); - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.WTPPlugin#getPluginID() - */ - public String getPluginID() { - return PLUGIN_ID; - } - - public static void log( final Exception e ) - { - final ILog log = WebPlugin.getDefault().getLog(); - final String msg = "Encountered an unexpected exception."; - - log.log( new Status( IStatus.ERROR, PLUGIN_ID, IStatus.OK, msg, e ) ); - } - public String getString(String key, boolean translate) { - // TODO For now... translate not supported - return getString(key); - } - - public String getString(String key, Object[] substitutions, boolean translate) { - // TODO For now... translate not supported - return getString(key,substitutions); - } - -} |