Extending the Validation Framework to create validators
The Validation Framework offers a set of APIs to create and manage validators easily in IBM® Rational® Application Developer. The Validation Framework is an open source project, and it is controlled by the Eclipse community (Web Tools Platform). The resource to be validated can be an Eclipse Resource (IResource), an Eclipse Modeling Framework, or an EMF Resource (EObject).
The framework puts out problems found during validation as problem markers in the Problems View or Markers View of the Rational Application Developer user interface providing you the ability to identify problems during development phase and avoiding defects in later test stages, therefore helping you to save time and money for your team.
You must create an extension in your plug-in to extend the validator extension point from the framework in order to create a new validator. The example in Listing 1 shows how an extension would look.
Listing 1. Plug-in extension example
<extension id="test1" name="Test1 Validator" point="org.eclipse.wst.validation.validatorV2"> <validator class="org.eclipse.wst.validation.tests.TestValidator" build="false" manual="false" > <include> <rules> <fileext ext="test1"></fileext> <pattern regex=".*/secondx/third/.*"></pattern> <facet id="java" version="1.6" /> </rules> </include> <exclude> <rules> <targetRuntime id="JBoss v5.0"/> <file caseSensitive="true" name=".project" type="file"> </file> </rules> </exclude> </validator> </extension>
All validators must extend org.eclipse.wst.validation.validatorV2. In addition, they must define an ID, a name, a class where the validator implementation is defined, and some includes and excludes where filter rules are defined.
Filter rules are stored in groups. There are two types of groups: Include and Exclude. You can have as many Include groups as you like. Filters inside of an Include group cause resources to be validated. If any rule matches, the entire group matches. Inside of a group the filter rules are ORed together. However, individual Include groups are ANDed together. You can have one Exclude group. If any of its filter rules match, then the resource is excluded. Exclusion takes precedence over inclusion.
After the validator has been added into your plug-in and Rational Application Developer has been restarted, the new validator will be shown ( Windows > Preferences > Validation).
Figure 1. Test Validator option in validation preferences
The framework offers four validation options, which the subsections that follow explain:
- Allow projects to override these preferences settings.
- Suspend all validators.
- Save all modified resources automatically before validating.
- Show confirmation dialog when performing manual validation.:
Figure 2. Selecting validation options
1. Allow projects to override these preferences settings
Projects can override the options in Window > Preferences > Validation. By doing this, individual projects will be validated depending on the current selected option. It can be Manual, Build, and the selectable Settings.
2. Suspend all validators
If you select this option, all validators will be suspended, which means that the projects and resources in your workspace will not be validated.
3. Save all modified resources automatically before validating
By selecting this option, if a resource has not been saved and Manual validation is performed, a pop-up dialog window confirms that the resource must be saved to be validated.
You can avoid showing this dialog by checking Always save all modified resources automatically prior to validating in the dialog window.
Figure 3. Save modified resources
4. Show confirmation dialog when performing manual validation
By selecting this option, if Manual validation is performed, a pop-up dialog window confirms that there were or were not errors or a warning during the validation.
Figure 4. Showing no errors after running validation
Figure 5. Showing errors after running validation
Calling the Manual or Build validators
If the build operation takes a long time, you might want to disable some of the validators. When a validator is disabled, errors, warnings, and information messages are not shown in the Markers nor Problems views.
All of the validators can be called by two different options in Rational Application Developer:
Manual validation lets resources to be validated by selecting the project that contains the resource, right-clicking on it, and then selecting Validation context menu option. You can enable or disable Manual validation:
- Select the resource or its parent project.
- Right-click and select the Validate menu option.
Build lets you select resources to be validated by selecting Project > Clean menu options. You can enable or disable Build validation, too:
- Select Window > Preferences > Validation
- Pick the validator you may want to change its behavior.
- On the Manual column of the validator, check or uncheck the option.
In both cases, the resources will be validated or not, depending on your selection.
It is important to notice that not all of the validators must be enabled in order to validate your application. Depending on what kind of application you are working on, you can enable a specific validator.
Validating a very large workspace can take time, so you might enable only the validators that you need in your application to reduce the amount of validation.
Figure 6. Enabling and disabling Manual and Build validation
Table 1. Validators in Rational Application Developer
|Application Client Validator||Validates the following Application Client project resources:||Yes|
|Application Manifest Validator||Performs validations on the APPLICATION.MF file in OSGi application projects.||Yes|
|Blueprint File Validator||Performs validations on blueprint XML files in OSGi bundle projects.||Yes|
|Bundle Manifest Validator|
Performs validations on the MANIFEST.MF file in OSGi bundle projects.
|Classpath Dependency Validator||Verifies potential runtime classpath errors. These are classpath issues where even though everything is compiling fine in the Eclipse environment, when the applications are deployed to a Java EE server, there could be classpath errors.||No (Eclipse)|
|Composite Bundle Manifest Validator||Performs validations on the COMPOSITEBUNDLE.MF file in OSGi composite bundle projects.||Yes|
|Connector (1.0,1.5) Validator||Checks for invalid J2EE specification levels in connector projects.||No (Eclipse)|
|DTD Validator||Determines whether the current state of a DTD is semantically valid. XML files are validated according to the XML specification Extensible Markup Language (XML) 1.0 from the W3C Web site. As well, the DTD validator checks for errors such as references to entities and elements that do not exist.||No (Eclipse)|
|Deployment Manifest Validator||Performs validations on the DEPLOYMENT.MF file in OSGi application projects.||Yes|
|EJB Validator||Verifies that enterprise beans contained in an EJB project comply with the Oracle Enterprise JavaBeans Specifications, depending on the level of the bean. Specifically, the EJB Validator validates the following resources:||Yes|
|Enterprise Application Validator||Validates the following:||Yes|
|Fragment Manifest Validator|
Performs validations on the MANIFEST.MF file in OSGi fragment projects.
|HTML Syntax Validator||Validates HTML basic syntax and HTML DTD compliance in the following Web project resources:||No (Eclipse)|
|J2EE Classpath Validator||Validates that the classpath container dependencies exist.||Yes|
|JSP Content Validator||Reports if the library referred to by a Tag Library Directive cannot be found, as well as any problems it finds regarding the prefix value in the JSP file content.||No (Eclipse)|
|JSP Syntax Validator||Validates JSP files in a project by translating them into the corresponding Java code and then checking the Java code for compile errors.||No (Eclipse)|
|Map Validator||Verifies that the fields in the database and the members of the EJBs are mapped and synchronized correctly.||Yes|
|Project Structure Validator||Validates whether any component resources point to a non-existing source folder and whether there are unnecessary resource mappings in the project structure.||Yes|
|SCA 1.0 Composite Validator||Validates the OSOA files *.composite.||Yes|
|SCA 1.0 Contribution Validator||Validates the OSOA file META-INF/sca-contribution-xml.||Yes|
|SCA 1.1 Composite Validator||Validates the OASIS files *.composite.||Yes|
|SCA 1.1 Contribution Validator||Validates the OASIS file META-INF/sca-contribution-xml.||Yes|
|SIP 1.0 Converged Project Validator||Verifies that the sip.xml and the web.xml are merged correctly.||Yes|
|SIP 1.1 Converged Project Validator||Verifies that the sip.xml and the web.xml are merged correctly.||Yes|
|SIP 1.1 Deployment Descriptor Validator||Verifies the SIP project is correct and valid.||Yes|
|SIP 1.1 Semantic Validator||Verifies the SIP rules Y maps||Yes|
|SIP 1.1 Servlet Selection Validator||Verifies the servlet is valid and there is one servlet selected.||Yes|
|SIP 1.1 Servlet Validator||Verifies the servlet is valid and has a main entry.||Yes|
|Struts Configuration File Validator||Checks the semantic errors that are not caught by the XML syntax checker. These are semantic as defined in the files : struts-config _1_1.dtd and for Struts 1.0, struts-config_1_0.dtd. Note: Only the configured configuration files are validated. That means if it’s not defined within web.xml (or portal.xml), it is not validated.||Yes|
|Struts Configuration File Validator - Portlet||Checks the semantic errors that are not caught by the XML syntax checker. These are semantic as defined in the files: struts-config _1_1.dtd and for Struts 1.0, struts-config_1_0.dtd. Note: Only the configured configuration files are validated. That means if it’s not defined within web.xml (or portal.xml), it is not validated.||Yes|
|Tag Library Descriptor Validator||A tag library descriptor is an XML document that contains information about a library as a whole and about each tag contained in the library. TLDs are used by a web container to validate the tags and by JSP page development tools. This validator can be used to validate the conformance of any JSP page importing this tag library to its requirements.||No (Eclipse)|
|WS-I Message Validator||Checks SOAP messages against WS-I Profiles. A user can capture and verify SOAP messages using the TCP/IP Monitor. The validator checks a message log that is saved as a project resource (.wsimsg). The log conforms to a format as specified by WS-I.||No (Eclipse)|
|WSDL Validator||The WSDL validator checks the following in WSDL files:|
The validator also includes an extension point to allow other validators to be plugged into the WSDL validation to provide additional verification of the WSDL file. Through this mechanism, interoperability is checked by validating a WSDL file against WS-I profiles.
|Web Service Annotation Validator||Validates JAX-WS Web services annotations and ensures the application is properly configured for the target runtime.||Yes|
|Web Service Project Validator||Validates WebSphere based EJB Web services to ensure that all necessary modules are configured.||Yes|
|Web Validator||Validates the following web project resources:||Yes|
|WebSphere Application Manifest Validator||Performs IBM® WebSphere®-specific validations on the APPLICATION.MF file in OSGi application projects.||Yes|
|WebSphere Composite Bundle Manifest Validator||Performs WebSphere-specific validations on the COMPOSITEBUNDLE.MF file in OSGi composite bundle projects.||Yes|
|WebSphere EJB 3.0 Deployment Descriptor Validator||Validates the ejb-jar.xml file with respect to WebSphere bindings and extensions related meta-data.||Yes|
|WebSphere EJB Bindings Validator||Validates the ibm-ejb-jar-bnd.xml file where WebSphere EJB bindings meta-data is defined (i.e. such as bindings to data sources, etc).||Yes|
|WebSphere EJB Extensions Validator||Validates the ibm-ejb-jar-ext.xml file where WebSphere EJB extensions meta-data is defined.||Yes|
|WebSphere EJB Programming Model Extensions Validator||Validates the ibm-ejb-jar-ext-pme.xml file where WebSphere EJB programming model extensions meta-data is defined.||Yes|
|WebSphere JPA Validator||Validates the JPA persistence.xml file of any WebSphere/OpenJPA specific meta-data.||Yes|
|WebSphere Legacy EJB Extensions Validator||Validates the ibm-ejb-jar-ext.xmi file where WebSphere EJB extensions meta-data is defined.||Yes|
|WebSphere Legacy Web Extensions Validator||Validates the ibm-web-jar-ext.xmi file where WebSphere Web extensions meta-data is defined.||Yes|
|WebSphere Web Bindings Validator||Validates the ibm-web-jar-bnd.xml file where WebSphere Web bindings meta-data is defined.||Yes|
|WebSphere Web Extensions Validator||Validates the ibm-web-jar-ext.xml file where WebSphere Web extensions meta-data is defined.||Yes|
|WebSphere Web Programming Model Extensions Validator||Validates the ibm-web-ext-pme.xml file where WebSphere Web programming model extensions meta-data is defined.||Yes|
|XML Schema Validator||Determines whether the current state of an XML schema file is semantically valid. XML schemas are validated according to the XML Schema specification XML Schema.||No (Eclipse)|
|XML Validator||The XML validator ensures that an XML file is well-formed. It also verifies if an XML file is valid - that is, it follows the constraints established in the DTD or XML schema the XML file is associated with.||No (Eclipse)|
|XSL Validator||Ensures that the XSL file is well-formed. It tries to detect any static errors, that is, an error that can be detected in a style sheet before execution starts.||No (Eclipse)|
|iWidget Validator||Ensures that an iWidget must have at least one content element in View mode, the content element mode has to be unique within the XML document and the mode of any content element that you add should synchronize with the Supported Modes field.||No (Eclipse)|
|xJCL Batch Validator||Verifies that the XML Job Control Language (xJCL) file is well-formed.||No (Eclipse)|
- For more information related to this article:
- Find out more about Rational Application Developer:
- Browse the Rational Application Developer for WebSphere Software page on developerWorks for links to technical articles and many related resources.
- Explore the Information Center.
- Explore the Rational software area on developerWorks for technical resources, best practices, and information about Rational collaborative and integrated solutions for software and systems delivery.
- Subscribe to the developerWorks weekly email newsletter, and choose the topics to follow. Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Improve your skills. Check the Rational training and certification catalog, which includes many types of courses on a wide range of topics. You can take some of them anywhere, any time, and many of the “Getting Started" ones are free.
Get products and technologies
- Try Rational Application Developer for WebSphere Software, free.
- Evaluate IBM software in the way that suits you best: Download it for a trial, try it online, use it in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement service-oriented architecture efficiently.
- Check Rational Application Developer wiki to keep up with news and to contribute.
- Join the Development Tools forum to ask questions and participate in discussions.
- Rate or review Rational software. It’s quick and easy.
- Share your knowledge and help others who use Rational software by writing a developerWorks article. Find out what makes a good developerWorks article and how to proceed.
- Follow Rational software on Facebook, Twitter (@ibmrational), and YouTube, and add your comments and requests.
- Ask and answer questions and increase your expertise when you get involved in the Rational forums, cafés, and wikis.
Dig deeper into Rational software on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.