public static MoodleGroup[] getGroupsFromCourseId(long id) throws MoodleRestGroupException, UnsupportedEncodingException, MoodleRestException {
        Vector v=new Vector();
        MoodleGroup group=null;
        StringBuilder data=new StringBuilder();
        String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_GROUP_GET_COURSE_GROUPS:MoodleServices.CORE_GROUP_GET_COURSE_GROUPS;
        if (MoodleCallRestWebService.getAuth()==null)
            throw new MoodleRestGroupException();
        else
            data.append(MoodleCallRestWebService.getAuth());
        data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING));
        if (id<1) throw new MoodleRestGroupException(); else  data.append("&").append(URLEncoder.encode("courseid", MoodleServices.ENCODING)).append("=").append(id);
        NodeList elements=MoodleCallRestWebService.call(data.toString());
        for (int j=0;j<elements.getLength();j++) {
            String content=elements.item(j).getTextContent();
            String nodeName=elements.item(j).getParentNode().getAttributes().getNamedItem("name").getNodeValue();
            if (nodeName.equals("id")) {
                if (group==null)
                    group=new MoodleGroup(Long.parseLong(content));
                else  {
                    v.add(group);
                    group=new MoodleGroup(Long.parseLong(content));
                }
            }
            group.setMoodleGroupField(nodeName, content);
        }
        if (group!=null)
            v.add(group);
        MoodleGroup[] groups=new MoodleGroup[v.size()];
        for (int i=0;i<v.size();i++) {
            groups[i]=(MoodleGroup)v.get(i);
        }
        v.removeAllElements();
        return groups;
    }