Exemplo n.º 1
0
  protected void vefifyRenderer(final ComponentLibrary library, final RendererModel renderer) {

    String baseName = renderer.getBaseClass().getSimpleName().replaceFirst("Base$", "");

    // Check renderer-type
    if (null == renderer.getId()) {
      if (null == renderer.getTemplate().getTemplatePath()) {
        throw new IllegalArgumentException("templatePath must not be null");
      }
      renderer.setId(
          namingConventions.inferRendererTypeByTemplatePath(
              renderer.getTemplate().getTemplatePath()));
    }
    // Check family.
    if (null == renderer.getFamily()) {
      renderer.setFamily(namingConventions.inferRendererFamily(renderer.getId()));
    }
    // Check type.
    verifyTypes(renderer, new RendererTypeCallback(library, renderer));
    // Check component type.
    for (ComponentModel component : library.getComponents()) {
      if (renderer.getId().equals(component.getRendererType())) {
        copyRendererAttributes(renderer, component);
      } else if (hasRendererSameBaseNameAsComponent(renderer, component)) {
        copyRendererAttributes(renderer, component);
        component.setRendererType(renderer.getId());
      }
    }
    // Check template
    if (renderer.getTemplate() != null && renderer.getTemplate().getInterface() != null) {
      if (null == renderer.getTemplate().getInterface().getJavaClass()) {
        renderer.getTemplate().getInterface().setJavaClass(renderer.getTargetClass());
      }
    }
  }
Exemplo n.º 2
0
 @Override
 public FacesId inferType() throws CallbackException {
   // For renderers with template - try to determine type by template file.
   if (null != this.renderer.getTemplate()) {
     for (ComponentModel component : this.library.getComponents()) {
       if (null != component.getRendererTemplate()
           && this.renderer
               .getTemplate()
               .getTemplatePath()
               .endsWith(component.getRendererTemplate())) {
         if (null != component.getRendererType()) {
           return component.getRendererType();
         } else {
           FacesId rendererType = namingConventions.inferRendererType(component.getId());
           component.setRendererType(rendererType);
           return rendererType;
         }
       }
     }
     // No component found, try to infer from template path.
     return namingConventions.inferRendererTypeByTemplatePath(
         this.renderer.getTemplate().getTemplatePath());
   }
   // If previvious attempt fall, try to infer renderer type from family.
   if (null != this.renderer.getFamily()) {
     return namingConventions.inferRendererType(this.renderer.getFamily());
   }
   throw new CallbackException("Cannot determine renderer type");
 }
  public static ComponentModel createComponent() {
    ComponentModel component = new ComponentModel(FacesId.parseId("foo.bar"));
    component.setGenerate(true);
    component.setTargetClass(
        ClassName.parseName("org.richfaces.cdk.generate.java.GeneratedComponent"));
    component.setBaseClass(ClassName.parseName(UIOutput.class.getName()));
    component.setRendererType(FacesId.parseId("foo.barRenderer"));

    PropertyBase attribute = component.getOrCreateAttribute("testValue");
    attribute.setType(new ClassName(Object.class));
    attribute.setGenerate(true);

    attribute = component.getOrCreateAttribute("testFlag");
    attribute.setType(new ClassName(Boolean.TYPE));
    attribute.setRequired(true);
    attribute.setGenerate(true);

    attribute = component.getOrCreateAttribute("testBinding");
    attribute.setType(new ClassName(MethodBinding.class));
    attribute.setGenerate(true);
    attribute.setBinding(true);
    attribute.setBindingAttribute(true);

    attribute = component.getOrCreateAttribute("testExpr");
    attribute.setType(new ClassName(MethodExpression.class));
    attribute.setGenerate(true);
    attribute.setBindingAttribute(true);
    MethodSignature signature = new MethodSignature();
    signature.setParameters(
        Arrays.asList(new ClassName(String.class), new ClassName(Integer.class)));
    attribute.setSignature(signature);

    attribute = component.getOrCreateAttribute("id");
    attribute.setType(new ClassName(String.class));
    attribute.setGenerate(false);

    attribute = component.getOrCreateAttribute("listStrings");
    attribute.setType(new ClassName(new ArrayList<String>().getClass()));
    attribute.setGenerate(true);

    attribute = component.getOrCreateAttribute("listInteger");
    attribute.setType(new ClassName(new ArrayList<Integer>().getClass()));
    attribute.setGenerate(true);

    attribute = component.getOrCreateAttribute("list");
    attribute.setType(new ClassName(ArrayList.class));
    attribute.setGenerate(true);

    Set<EventName> eventNames = attribute.getEventNames();
    eventNames.add(getEvent("id", false));
    eventNames.add(getEvent("action", true));

    return component;
  }