1 2 Previous Next 15 Replies Latest reply on Aug 29, 2011 2:45 PM by kcbabo

    XML Validation in Eclipse

    rcernich

      Hey all,

       

      I've been able to put together an XML catalog to support validation of SwitchYard schema and configuration files within Eclipse.  In order to accomplish this, I needed to remove the "schemaLocation" attributes from all SwitchYard schema files.  (For whatever reason, Eclipse persisted in using these values, even though the use of "public" id's was preferred in the catalog.)  This  forced a minor change to Descriptor.java to so it could resolve schema resources when systemId was null.  (Note, Descriptor.getSchema() functionality is still driven by the information in the descriptor.properties files.)

       

      I've committed the changes to my repo's on github for review.

      https://github.com/rcernich/core/tree/xml_validation

      https://github.com/rcernich/components/tree/xml_validation

       

      Once you've got the updated source, you should be able to use the XML validation capabilities within Eclipse to validate schema and configuration files.  To do this, you will need:

      1. The catalog file (attached)
      2. Add the catalog file to Eclipse's XML catalog (preferences, XML->XML Catalog, Add..., Next Catalog).
      3. Disable "Honour all XML schema locations" (preferences, XML->XML Files->Validation).  (If you're getting weird validation errors, this setting is probably enabled.)
      4. Select a file or folder, right-click, Validate.

       

      The above assumes you have the projects containing the schema in your workspace (e.g. switchyard-config, switchyard-transform, switchyard-component-bean, etc.).  You don't need all the projects in your workspace, just the ones you want to use during validation (i.e. if you're just working with beans, you don't need the other component projects).

       

      There is also a forthcoming Eclipse plug-in which will contain all the schema and automatically register the catalog with Eclipse.  (Theoretically, you should be able to use the plug-in for everything, except when you are editing the schema, in which case you'll want to use the attached file to make sure you're pulling in the projects' schema.)

       

      Any and all feedback is welcome.

       

      Rob

       

      Message was edited by: Rob Cernich Updated attachment: switchyard_catalog.xml

        • 1. Re: XML Validation in Eclipse
          dward

          Rob,

           

          I agree that this is the Right Thing to do. I just looked over your code changes, and it looks good to me.  Please create a jira for this work, set the release target version to be 0.3, and reference this forum discussion in the jira as well (there's a field for it).

           

          Great work!

          David

          • 2. Re: XML Validation in Eclipse
            rcernich

            Per discussion with Dave on IRC, I'm going to:

            1. Create a JIRA.  I've chosen to simply reopen https://issues.jboss.org/browse/SWITCHYARD-350
            2. Fix as many outstanding XML validation errors that I can (most are in XML files used during testing).

             

            I'd like to find a place to store the catalog file, just so it will be easily accessible to developers.  (I was thinking someplace in core, maybe.)

             

            Dave, please let me know if I missed anything from our conversation.

            • 3. Re: XML Validation in Eclipse
              rcernich

              I've committed my final changes and issued pull requests for core and components.

               

              I've created additional JIRA for the few remaining validation errors:

              switchyard-config: https://issues.jboss.org/browse/SWITCHYARD-430

              switchyard-component-camel: https://issues.jboss.org/browse/SWITCHYARD-431

              switchyard-component-hornetq: https://issues.jboss.org/browse/SWITCHYARD-432

               

              I would have cleaned these up as well, but was not quite sure of the correct solution.

              • 4. Re: XML Validation in Eclipse
                rcernich

                Hey all,

                 

                If anybody has any recommendations as to where the catalog file should reside, please speak up.

                 

                For now, I've attached it to:  https://issues.jboss.org/browse/SWITCHYARD-212

                 

                Regards,

                Rob

                • 5. Re: XML Validation in Eclipse
                  dward

                  Typing this from my phone... Rob, you don't need separate jiras, one for each repo. One jira represents one issue, even if it spans components or even repos. Yes you need a separate pull request for each repo, but you can add them all to the same jira. The field supports newlines or commas to delimit.

                  • 6. Re: XML Validation in Eclipse
                    rcernich

                    Hey David,

                     

                    I understand.  The reason I created the separate issues is because they are related to the specific component problems, beyond the simple rejiggering of elements or attributes.  For example, should an error for an element with a missing delcaration be removed from the xml document or should a definition be added to the schema?  I figured those particular issues required a discussion in a more specific forum, so I created specific JIRA for each of those.

                     

                    Regards,

                    Rob

                    • 7. Re: XML Validation in Eclipse
                      kcbabo

                      If they are separate issues, then I think separate JIRAs is the right approach.

                      • 8. Re: XML Validation in Eclipse
                        rcernich

                        I've modified the way the camel-spring.xsd file was incorporated into the camel component and have updated the catalog file attached to the original post to accommodate it.

                        • 9. Re: XML Validation in Eclipse
                          tfennelly

                          Good work Rob.

                           

                          I was also looking at doing this some time ago but parked it: https://issues.jboss.org/browse/SWITCHYARD-353.  Maybe we should close that JIRA now, although it did represent something a bit different (an attempted solution that would work withough having to have all the switchyard src in your eclipse workspace) ?

                          • 10. Re: XML Validation in Eclipse
                            kcbabo

                            This requires a complete source checkout including all the schemas?  Definitely will still be useful for project developers, but I had raised my hopes that end users could take advantage of this as well. :-) 

                             

                            Perhaps what we need to do here is include all of our schema in the distribution so that users can simply point to a file system location and the catalog can resolve from there?

                            • 11. Re: XML Validation in Eclipse
                              rcernich

                              Hey Keith, Tom,

                               

                              There are two aspects to this:

                              1. Cleaning up the schemas so that validation is possible.
                              2. Providng an XML catalog so the schema can be resolved.

                               

                              The work I've done for https://issues.jboss.org/browse/SWITCHYARD-350 covers the first aspect (as well as cleaning up most of the validation errors).

                               

                              The catalog file attached to this discussion and https://issues.jboss.org/browse/SWITCHYARD-212 covers the second item for SwitchYard project development.  I've also created an Eclipse plugin for use by SwitchYard application developers (Tom's https://issues.jboss.org/browse/SWITCHYARD-353).

                               

                              The reason I created a standalone catalog file that could be used by SwitchYard project developers was that, by having the catalog resolve to files in the workspace, any changes made to project schema would be immediately available for validation, without having to wait for the Eclipse plugin to be rebuilt.  Of course, if new schema are added to SwitchYard, entries for the new schema would need to be added to both catalogs, as well as ensuring the new schema are included in the Eclipse plugin.

                               

                              Long story short, you do not need the source for validation to work.

                               

                              Rob

                              • 12. Re: XML Validation in Eclipse
                                rcernich

                                Keith has suggested the Eclipse plugin should resolve schema through a project's associated SwitchYard runtime.  This would allow SwitchYard projects to reference different versions of schema, based on the version of the runtime the project is associated with.  I've created a JIRA for this: https://issues.jboss.org/browse/SWITCHYARD-433

                                 

                                I can see how we could easily resolve the correct versions of schema, but I think it would be good if we could, somehow, automatically determine which schema are supported by the runtime.  I'm guessing we could use the current Descriptor functionality to resolve the defined schema along with their locations.  That said, I'm not sure of the best way to access that information (e.g. a management operation that provides a map <namespace, schema location>, a custom classloader, ???).

                                 

                                Thoughts?

                                • 13. Re: XML Validation in Eclipse
                                  jdoyle

                                  A long time ago I create a custom validator for the MetaMatrix product.  It basically enabled users who were not allowed to have an internet connection to add XSD and WSDL to their workspace and the standatd eclipse validator would find them.  Don't know that I understand your issue here but it might help.  There's really no doc, I went from this article and looked at the eclipse source to figure it out.

                                   

                                  ~jd

                                   

                                  http://wiki.eclipse.org/Using_the_WSDL_Validator_Outside_of_Eclipse#Registering_custom_WSDL_validators

                                  • 14. Re: XML Validation in Eclipse
                                    rcernich

                                    Hey John,

                                     

                                    Thanks for the link.

                                     

                                    Our main problem was getting the Eclipse XML validator to resolve the SwitchYard provided schema.  The problem was solved with some minor tweaks to the schema (removing schemaLocation attributes; why Eclipse wasn't using the overridden settings in the catalog is beyond me) and providing a static catalog (two catalogs actually, one that can be used by SwitchYard platform developers and one that can be used by SwitchYard application developers; the latter registered automatically through an Eclipse plugin).

                                     

                                    In the future, we plan to have a more sophisticated resolution mechanism, which would be tied in with the SwitchYard runtime.  Ideally, this would support multiple schema versions, as well as automatically pick up any user generated configuration schema (e.g. if a custom component is user supplied).

                                     

                                    Thanks again for the info.

                                     

                                    Rob

                                    1 2 Previous Next