Author: scabanovich
Date: 2012-01-20 20:41:08 -0500 (Fri, 20 Jan 2012)
New Revision: 38012
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
Log:
JBIDE-10645
https://issues.joss.org/browse/JBIDE-10645
Supported JAX-RS in validation of servlet-mapping/servlet-name.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java 2012-01-21
01:33:10 UTC (rev 38011)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckClass.java 2012-01-21
01:41:08 UTC (rev 38012)
@@ -87,30 +87,41 @@
}
if(type != null) {
- String mustImpl = null;
- try { mustImpl = checkImplements(object, type); } catch (Exception e) {
+ try {
+ check(object, value, type);
+ } catch (Exception e) {
LogHelper.logError("org.jboss.tools.jst.web.verification", e);
//$NON-NLS-1$
}
- if(mustImpl != null) {
- fireImplements(object, preference, value, mustImpl);
- }
- String mustExtend = null;
- try { mustExtend = checkExtends(object, type); } catch (Exception e) {
- LogHelper.logError("org.jboss.tools.jst.web.verification", e);
//$NON-NLS-1$
- }
- if(mustExtend != null) {
- fireExtends(object, preference, value, mustExtend);
- }
return;
}
fireNotExist(object, preference, value);
}
+
+ protected void check(XModelObject object, String value, IType type) throws
JavaModelException {
+ String mustImpl = checkImplements(object, type);
+ if(mustImpl != null) {
+ fireImplements(object, preference, value, mustImpl);
+ }
+ String mustExtend = checkExtends(object, type);
+ if(mustExtend != null) {
+ fireExtends(object, preference, value, mustExtend);
+ }
+ }
private boolean checkQualifiedName(String value) {
return constraint.accepts(value);
}
-
- private String checkImplements(XModelObject object, IType type) throws Exception {
+
+ /**
+ * Returns name of interface that should be implemented by type but is not.
+ * Returns null if no restriction on type is set.
+ *
+ * @param object
+ * @param type
+ * @return
+ * @throws JavaModelException
+ */
+ protected String checkImplements(XModelObject object, IType type) throws
JavaModelException {
if("java.lang.Class".equals(type.getFullyQualifiedName())) return null;
//$NON-NLS-1$
String impl = implementsType;
if(impl == null || impl.length() == 0) return null;
@@ -129,7 +140,16 @@
return checkImplements(object, type);
}
- private String checkExtends(XModelObject object, IType type) throws Exception {
+ /**
+ * Returns name of class that should be extended by type but is not.
+ * Returns null if no restriction on type is set or if type is interface.
+ *
+ * @param object
+ * @param type
+ * @return
+ * @throws JavaModelException
+ */
+ protected String checkExtends(XModelObject object, IType type) throws JavaModelException
{
if(type.isInterface()) return null;
if("java.lang.Class".equals(type.getFullyQualifiedName())) return null;
//$NON-NLS-1$
String ext = extendsType;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java 2012-01-21
01:33:10 UTC (rev 38011)
+++
trunk/jst/plugins/org.jboss.tools.jst.web/src/org/jboss/tools/jst/web/validation/CheckServletMappingName.java 2012-01-21
01:41:08 UTC (rev 38012)
@@ -10,15 +10,19 @@
******************************************************************************/
package org.jboss.tools.jst.web.validation;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.model.*;
import org.jboss.tools.common.validation.ValidationErrorManager;
+import org.jboss.tools.jst.web.WebModelPlugin;
import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
/**
* @author Viacheslav Kabanovich
*/
public class CheckServletMappingName extends Check {
+ public static String JAX_RS_APPLICATION = "javax.ws.rs.core.Application";
//$NON-NLS-1$
static String ATTR = "servlet-name"; //$NON-NLS-1$
boolean acceptEmpty = false;
@@ -34,7 +38,20 @@
if(acceptEmpty) return;
fireMessage(object, NLS.bind(WebXMLValidatorMessages.EMPTY, attr));
} else if(findServlet(object, servletName) == null) {
- fireMessage(object, NLS.bind(WebXMLValidatorMessages.SERVLET_NOT_EXISTS, attr,
servletName));
+ //JAX-RS
+ if(servletName.equals(JAX_RS_APPLICATION)) {
+ return;
+ }
+ IType type = CheckClass.getValidType(servletName, object);
+ if(type != null) {
+ try {
+ new CheckServletClass(manager).check(object, servletName, type);
+ } catch (JavaModelException e) {
+ WebModelPlugin.getDefault().logError(e);
+ }
+ } else {
+ fireMessage(object, NLS.bind(WebXMLValidatorMessages.SERVLET_NOT_EXISTS, attr,
servletName));
+ }
}
}
@@ -48,3 +65,18 @@
}
}
+
+class CheckServletClass extends CheckClass {
+
+ public CheckServletClass(ValidationErrorManager manager) {
+ super(manager, WebXMLPreferences.INVALID_SERVLET_REF, CheckServletMappingName.ATTR,
false, null, CheckServletMappingName.JAX_RS_APPLICATION);
+ }
+
+ protected void check(XModelObject object, String value, IType type) throws
JavaModelException {
+ String mustExtend = checkExtends(object, type);
+ if(mustExtend == null) {
+ return;
+ }
+ fireExtends(object, preference, value, mustExtend);
+ }
+}