/**
  * Extract the id from a resource element and add to the resource map then recurse into any
  * contained resources. Also extract the ids from any contained method and its representation or
  * fault elements.
  *
  * @param file the URI of the current WADL file being processed
  * @param r the resource element
  * @throws javax.xml.bind.JAXBException if the WADL file is invalid or if the code generator
  *     encounters a problem.
  * @throws java.io.IOException if the specified WADL file cannot be read.
  */
 protected void extractResourceIds(Resource r, URI file) throws JAXBException, IOException {
   processIDHref(file, r.getId(), null, r);
   for (String type : r.getType()) {
     processIDHref(file, null, type, r);
   }
   for (Object child : r.getMethodOrResource()) {
     if (child instanceof Method) extractMethodIds((Method) child, file);
     else if (child instanceof Resource) extractResourceIds((Resource) child, file);
   }
 }
 /**
  * Add a resource and (recursively) its children to a tree starting at the parent. Follow
  * references to resources across WADL file boundaries
  *
  * @param parent the parent resource in the tree being built
  * @param resource the WADL resource to process
  * @param file the URI of the current WADL file being processed
  */
 protected void buildResourceTree(ResourceNode parent, Resource resource, URI file) {
   if (resource != null) {
     ResourceNode n = parent.addChild(resource);
     for (String type : resource.getType()) {
       addTypeToResource(n, type, file);
     }
     for (Object child : resource.getMethodOrResource()) {
       if (child instanceof Resource) {
         Resource childResource = (Resource) child;
         buildResourceTree(n, childResource, file);
       } else if (child instanceof Method) {
         Method m = (Method) child;
         addMethodToResource(n, m, file);
       }
     }
   }
 }
  /** Test of getTemplateParameters method, of class org.jvnet.ws.wadl2java.PathSegment. */
  public void testGetTemplateParameters() {
    System.out.println("getTemplateParameters");

    Resource r = new Resource();
    r.setPath("fred/{param1}/bob/{param2}");
    Param p = new Param();
    p.setName("param1");
    p.setRequired(true);
    r.getParam().add(p);

    PathSegment instance = new PathSegment(r);
    List<Param> result = instance.getTemplateParameters();

    assertEquals(result.get(0).getName(), "param1");
    assertTrue(result.get(0).isRequired());
    assertEquals(result.get(1).getName(), "param2");
    assertFalse(result.get(1).isRequired());
  }
  public void testEvaluate() {
    System.out.println("evaluate");
    Resource r = new Resource();
    r.setPath("fred/{param1}/bob/{param2}");
    Param p = new Param();
    p.setName("param1");
    p.setRequired(true);
    r.getParam().add(p);
    p = new Param();
    p.setName("param3");
    p.setStyle(ParamStyle.MATRIX);
    r.getParam().add(p);
    p = new Param();
    p.setName("param4");
    p.setStyle(ParamStyle.MATRIX);
    r.getParam().add(p);
    p = new Param();
    p.setName("param5");
    p.setStyle(ParamStyle.MATRIX);
    r.getParam().add(p);

    PathSegment instance = new PathSegment(r);
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("param1", "value1");
    params.put("param2", "value2");
    params.put("param3", "value3");
    params.put("param4", true);
    params.put("param5", false);
    String result = instance.evaluate(params);

    assertEquals(result, "fred/value1/bob/value2;param3=value3;param4");

    PathSegment instance2 = new PathSegment("fred/{xyzzy}/bob/");
    result = instance2.evaluate(null);
    assertEquals(result, "fred//bob/");
  }