コード例 #1
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
 private static UserOperation getOperationFromElement(Element e) {
   UserOperation op = new UserOperation();
   op.setName(e.getAttribute("name"));
   op.setVerb(e.getAttribute("verb"));
   op.setPath(e.getAttribute("path"));
   op.setOneway(Boolean.parseBoolean(e.getAttribute("oneway")));
   op.setConsumes(e.getAttribute("consumes"));
   op.setProduces(e.getAttribute("produces"));
   List<Element> paramEls =
       DOMUtils.findAllElementsByTagNameNS(e, "http://cxf.apache.org/jaxrs", "param");
   List<Parameter> params = new ArrayList<Parameter>(paramEls.size());
   for (int i = 0; i < paramEls.size(); i++) {
     Element paramEl = paramEls.get(i);
     Parameter p = new Parameter(paramEl.getAttribute("type"), i, paramEl.getAttribute("name"));
     p.setEncoded(Boolean.valueOf(paramEl.getAttribute("encoded")));
     p.setDefaultValue(paramEl.getAttribute("defaultValue"));
     String pClass = paramEl.getAttribute("class");
     if (!StringUtils.isEmpty(pClass)) {
       try {
         p.setJavaType(ClassLoaderUtils.loadClass(pClass, ResourceUtils.class));
       } catch (Exception ex) {
         throw new RuntimeException(ex);
       }
     }
     params.add(p);
   }
   op.setParameters(params);
   return op;
 }
コード例 #2
0
ファイル: ResourceUtils.java プロジェクト: jboss/cxf
  public static ClassResourceInfo createServiceClassResourceInfo(
      Map<String, UserResource> resources,
      UserResource model,
      Class<?> sClass,
      boolean isRoot,
      boolean enableStatic,
      Bus bus) {
    if (model == null) {
      throw new RuntimeException("Resource class " + sClass.getName() + " has no model info");
    }
    ClassResourceInfo cri =
        new ClassResourceInfo(
            sClass,
            sClass,
            isRoot,
            enableStatic,
            true,
            model.getConsumes(),
            model.getProduces(),
            bus);
    URITemplate t = URITemplate.createTemplate(model.getPath());
    cri.setURITemplate(t);

    MethodDispatcher md = new MethodDispatcher();
    Map<String, UserOperation> ops = model.getOperationsAsMap();

    Method defaultMethod = null;
    Map<String, Method> methodNames = new HashMap<String, Method>();
    for (Method m : cri.getServiceClass().getMethods()) {
      if (m.getAnnotation(DefaultMethod.class) != null) {
        // if needed we can also support multiple default methods
        defaultMethod = m;
      }
      methodNames.put(m.getName(), m);
    }

    for (Map.Entry<String, UserOperation> entry : ops.entrySet()) {
      UserOperation op = entry.getValue();
      Method actualMethod = methodNames.get(op.getName());
      if (actualMethod == null) {
        actualMethod = defaultMethod;
      }
      if (actualMethod == null) {
        continue;
      }
      OperationResourceInfo ori =
          new OperationResourceInfo(
              actualMethod,
              cri,
              URITemplate.createTemplate(op.getPath()),
              op.getVerb(),
              op.getConsumes(),
              op.getProduces(),
              op.getParameters(),
              op.isOneway());
      String rClassName = actualMethod.getReturnType().getName();
      if (op.getVerb() == null) {
        if (resources.containsKey(rClassName)) {
          ClassResourceInfo subCri =
              rClassName.equals(model.getName())
                  ? cri
                  : createServiceClassResourceInfo(
                      resources,
                      resources.get(rClassName),
                      actualMethod.getReturnType(),
                      false,
                      enableStatic,
                      bus);
          if (subCri != null) {
            cri.addSubClassResourceInfo(subCri);
            md.bind(ori, actualMethod);
          }
        }
      } else {
        md.bind(ori, actualMethod);
      }
    }

    cri.setMethodDispatcher(md);
    return checkMethodDispatcher(cri) ? cri : null;
  }