[jdom-interest] Document getter/setter not the same (collection vs List)

Jason Hunter jhunter at servlets.com
Wed Sep 19 11:08:44 PDT 2007


Well, here's the source of the complaint:

In Document.java:

   public List getContent() { }
   public Document setContent(Collection newContent) { }

The JDOM programming contract is you can pass in any old Collection type 
as content but JDOM promises on access to return a specific type of 
Collection, a List.  NetBeans seems to have a problem with this.  It 
must be making some wrong assumptions that Content is a property, 
probably in the hidden magic it performs on the method since it's marked 
@WebMethod.

-jh-

IL Bretone wrote:
> Hello,
> 
> I'm trying to compile a class which will become a web service, I'm using
> Netbeans 5.5 and when i try to compile the following code:
> 
> "
>     @WebMethod
>     public Document getUserTrainingPlan(@WebParam(name="userId") String
> userId) {
>         
>        UserPlan[] availableUserPlans =
> AngelSelectQuery.doGetAvailbleUserPlans(userId);
>             
>        Document doc = new Document();
>        Element plans = new Element("plans");
>                        
>        for  ( int i = 0; i < availableUserPlans.length; i++) {
>           Element plan = new Element("plan").setAttribute("id",
> availableUserPlans[i].getPlan().getPlanId());
>           plan.addContent(new
> Element("creationDate").setText(angel.webapp.utils.Date4Jsp.getDate(availableUserPlans[i].getPlan().getCreationDate())));
>           plan.addContent(new
> Element("name").setText(availableUserPlans[i].getPlan().getPlanName()));
>           plan.addContent(new
> Element("creator").setText(availableUserPlans[i].getPlan().getCreator().getGeneralInfo()));
>           plan.addContent(new
> Element("duration").setText(availableUserPlans[i].getPlan().getDuration()));
>                 plan.addContent(new
> Element("avgSpeed").setText(availableUserPlans[i].getPlan().getAverageSpeed()));
>                 
>           plans.addContent(plan);
>             }
>   
>           doc.addContent(plans);
>             
>             // Debug
>             try {
>                 XMLOutputter outp = new XMLOutputter();
>                 outp.output(doc, System.out);
>             } catch (Exception e){
>                 System.out.println("Erreur xml: " + e.toString());
>             }
>         
>         return doc;
>         
>     }
> "
> 
> it gives me the following error:
> 
> "error: The type of the getter is java.util.List but that of the setter is
> java.util.Collection. They have to be the same.
>         this problem is related to the following location:
>                 at org.jdom.Document.getContent (Unknown Source)
>                 at org.jdom.Document (Unknown Source)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse._return(GetUserTrainingPlanResponse.java:17)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse(GetUserTrainingPlanResponse.java:14)
>         this problem is related to the following location:
>                 at org.jdom.Document.setContent (Unknown Source)
>                 at org.jdom.Document (Unknown Source)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse._return(GetUserTrainingPlanResponse.java:17)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse(GetUserTrainingPlanResponse.java:14)
> error: The type of the getter is java.util.List but that of the setter is
> java.util.Collection. They have to be the same.
>         this problem is related to the following location:
>                 at org.jdom.Element.getContent (Unknown Source)
>                 at org.jdom.Element (Unknown Source)
>                 at org.jdom.Document.getRootElement (Unknown Source)
>                 at org.jdom.Document (Unknown Source)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse._return(GetUserTrainingPlanResponse.java:17)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse(GetUserTrainingPlanResponse.java:14)
>         this problem is related to the following location:
>                 at org.jdom.Element.setContent (Unknown Source)
>                 at org.jdom.Element (Unknown Source)
>                 at org.jdom.Document.getRootElement (Unknown Source)
>                 at org.jdom.Document (Unknown Source)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse._return(GetUserTrainingPlanResponse.java:17)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse(GetUserTrainingPlanResponse.java:14)
> error: org.jdom.Namespace does not have a no-arg default constructor.
>         this problem is related to the following location:
>                 at org.jdom.Namespace (Unknown Source)
>                 at org.jdom.Element.getNamespace (Unknown Source)
>                 at org.jdom.Element (Unknown Source)
>                 at org.jdom.Document.getRootElement (Unknown Source)
>                 at org.jdom.Document (Unknown Source)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse._return(GetUserTrainingPlanResponse.java:17)
>                 at
> angel.ws.jaxws.GetUserTrainingPlanResponse(GetUserTrainingPlanResponse.java:14)
> 3 errors
> error: compilation failed, errors should have been reported
> "
> 
> What should I do ? I wouldn't like to rewrite jdom ;)
> 
> Cheers,
> Joel


More information about the jdom-interest mailing list