Exemplo n.º 1
0
 private void copyRendererAttributes(final RendererModel renderer, ComponentModel component) {
   for (PropertyBase property : renderer.getAttributes()) {
     PropertyBase attribute = component.getOrCreateAttribute(property.getName());
     attribute.merge(property);
     verifyAttribute(attribute, component);
   }
   renderer.setFamily(component.getFamily());
 }
  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;
  }
Exemplo n.º 3
0
 /**
  * @param library
  * @param component
  * @param verified
  */
 protected void verifyComponentAttributes(
     ComponentLibrary library,
     final ComponentModel component,
     Collection<ComponentModel> verified) {
   // There is potential StackOverflow, so we process only components which have not been
   // verified before.
   if (!verified.contains(component)) {
     // Propagate attributes from parent component, if any.
     verified.add(component);
     if (null != component.getBaseClass()) {
       try {
         // Step one, lookup for parent.
         ComponentModel parentComponent = findParent(library.getComponents(), component);
         component.setParent(parentComponent);
         if (null == component.getFamily()) {
           component.setFamily(parentComponent.getFamily());
         }
         // To be sure what all properties for parent component were propagated.
         verifyComponentAttributes(library, parentComponent, verified);
         for (PropertyBase parentAttribute : parentComponent.getAttributes()) {
           PropertyBase attribute = component.getOrCreateAttribute(parentAttribute.getName());
           attribute.merge(parentAttribute);
           // already exists in parent component.
           attribute.setGenerate(false);
         }
       } catch (NoSuchElementException e) {
         // No parent component in the library
       }
     } // Check attributes.
     for (PropertyBase attribute : component.getAttributes()) {
       verifyAttribute(attribute, component);
     }
     // compact(component.getAttributes());
     // Check renderers.
     // Check Tag
     for (TagModel tag : component.getTags()) {
       verifyTag(tag, component.getId(), DEFAULT_COMPONENT_HANDLER);
     }
     verifyDescription(component);
     for (FacetModel facet : component.getFacets()) {
       verifyDescription(facet);
     }
   }
 }