Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 250042 - [ds tooling] Validate <service> element
Summary: [ds tooling] Validate <service> element
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Chris Aniszczyk CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-07 22:49 EDT by Simon Archer CLA
Modified: 2008-10-24 16:33 EDT (History)
1 user (show)

See Also:


Attachments
DSErrorReporter updates (6.80 KB, text/plain)
2008-10-24 12:58 EDT, Rafael Oliveira Nóbrega CLA
no flags Details
New Messages (7.22 KB, text/plain)
2008-10-24 13:49 EDT, Rafael Oliveira Nóbrega CLA
caniszczyk: iplog+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2008-10-07 22:49:39 EDT
Using Eclipse 3.5M2 from HEAD

Section 112.4.6 of the OSGi spec discusses the <service> element. The <service> element has an optional servicefactory attribute, which has the following constraint:

"The servicefactory attribute MUST NOT be true if the component is a factory
component or an immediate component."

The spec goes on, rather redundantly to say:

"A component description is ILL-FORMED if it specifies that the component is a
factory component or an immediate component and servicefactory is set to
true."

In cases where a component is ill-formed it seems appropriate to issue an error rather than a warning. Here are two examples of an ill-formed component.

1. The <component> element's immediate attribute is set to "true" and its <service> element's servicefactory attribute set to "true":

  <?xml version="1.0" encoding="UTF-8"?>
  <component immediate="true" name="com.ibm.foo">
     <implementation class="com.ibm.foo.internal.Component"/>
     <service servicefactory="true">
       <provide interface="com.ibm.foo.IBar"/>
     </service>
  </component>

2. The <component> element's factory attribute set and its <service> element's servicefactory attribute set to "true":

  <?xml version="1.0" encoding="UTF-8"?>
  <component name="com.ibm.foo" factory="bar.factory">
     <implementation class="com.ibm.foo.internal.Component"/>
     <service servicefactory="true">
       <provide interface="com.ibm.foo.IBar"/>
     </service>
  </component>


Finally, the spec goes on to say this about the body of the <service> element:

"The service element MUST have one or more provide elements that define the service interfaces."

A couple of examples:

1. There is nothing between <service> and </service>:

  <?xml version="1.0" encoding="UTF-8"?>
  <component name="com.ibm.foo">
     <implementation class="com.ibm.foo.internal.Component"/>
     <service>
     </service>
  </component>

2. There is simply a <service/> element:

  <?xml version="1.0" encoding="UTF-8"?>
  <component name="com.ibm.foo">
     <implementation class="com.ibm.foo.internal.Component"/>
     <service/>
  </component>

I think it is appropriate to issue an error when the <service> element does not contain any <provide> elements.
Comment 1 Rafael Oliveira Nóbrega CLA 2008-10-24 12:58:01 EDT
Created attachment 116076 [details]
DSErrorReporter updates

1-validating ServiceFactory attribute against immedite and factory attributes
2-validating service elements with no children.
Comment 2 Simon Archer CLA 2008-10-24 13:35:52 EDT
Having looked at the patch I have some comments regarding the messages. I'm using the terms "Wrong" and "Right" rather loosly here, for which I apologize. The theme here being "simpler is better". 

* DSErrorReporter_illegalServiceFactory:

  Wrong: The 'servicefactory' attribute MUST NOT be true if the
         component is a factory or an immediate component.

  Right: The 'servicefactory' attribute must not be true for a
         factory component or an immediate component.

Both versions of this message are rather XML-centric for my liking, maybe two problem-centric message would be better, but clearly this would require smarter logic:

  - A factory component cannot be a service factory.

  - An immediate component cannot be a service factory.


* DSErrorReporter_illegalEmptyService:

  Wrong: The 'service' element MUST have one or more provide elements
         that define the service interfaces.

  Right: The 'service' element must contain at least one 'provide'
         element.


This message is also rather XML-centric, but this will only ever be issued when the user has hand-edited the XML, so it seems appropriate.
Comment 3 Rafael Oliveira Nóbrega CLA 2008-10-24 13:49:46 EDT
Created attachment 116080 [details]
New Messages

thanks simon. :)

(how can I set an old patch as obsolete using Mylyn?)
Comment 4 Chris Aniszczyk CLA 2008-10-24 16:30:25 EDT
done.

Thanks Rafael!
Comment 5 Chris Aniszczyk CLA 2008-10-24 16:33:24 EDT
Rafael, Mylyn doesn't support making attachments obselete yet. However, I think they are working on that for the next release.