Example #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());
      }
    }
  }
Example #2
0
 protected void verifyTaglib(ComponentLibrary library) {
   Taglib taglib = library.getTaglib();
   if (null == taglib) {
     // Oops, create taglib model
     taglib = new Taglib();
     library.setTaglib(taglib);
   }
   // Verify URI
   String uri = taglib.getUri();
   if (null == uri) {
     // infer default value.
     uri = namingConventions.inferTaglibUri(library);
     taglib.setUri(uri);
     // log.error("No uri defined for taglib");
   }
   String shortName = taglib.getShortName();
   if (null == shortName) {
     shortName = namingConventions.inferTaglibName(uri);
     taglib.setShortName(shortName);
     // log.error("No short defined for taglib");
   }
   // Verify tags. If we have renderer-specific component, it should have a tag ?
   for (ComponentModel component : library.getComponents()) {
     if (null != component.getRendererType() && component.getTags().isEmpty()) {
       TagModel tag = new TagModel();
       verifyTag(tag, component.getId(), DEFAULT_COMPONENT_HANDLER);
       component.getTags().add(tag);
     }
   }
 }
Example #3
0
 protected void verifyEvents(ComponentLibrary library) {
   for (EventModel event : library.getEvents()) {
     ClassName listenerInterface = event.getListenerInterface();
     SourceUtils sourceUtils = sourceUtilsProvider.get();
     if (null != listenerInterface) {
       event.setGenerateListener(!sourceUtils.isClassExists(listenerInterface));
     }
     String methodName = event.getListenerMethod();
     if (null == methodName) {
       methodName = "process";
       event.setListenerMethod(methodName);
     }
     ClassName sourceInterface = event.getSourceInterface();
     if (null != sourceInterface) {
       event.setGenerateSource(!sourceUtils.isClassExists(sourceInterface));
     }
     // Propagate event to corresponding components.
     for (ComponentModel component : library.getComponents()) {
       for (EventModel componentEvent : component.getEvents()) {
         if (event.getType().equals(componentEvent.getType())) {
           componentEvent.merge(event);
         }
       }
     }
   }
 }
Example #4
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());
 }
Example #5
0
 protected void verifyComponents(ComponentLibrary library) throws CdkException {
   // Verify types and classes. Do it first to be sure what all all values are set before second
   // stage.
   for (ComponentModel component : library.getComponents()) {
     try {
       verifyComponentType(component);
     } catch (RuntimeException e) {
       throw new CdkException("Caught error when verifying component " + component, e);
     }
   }
   // Verify component attributes
   HashSet<ComponentModel> verified = Sets.newHashSet();
   for (ComponentModel component : library.getComponents()) {
     try {
       verifyComponentType(component);
       verifyComponentAttributes(library, component, verified);
       // generate component family if missing
       if (null == component.getFamily()) {
         component.setFamily(namingConventions.inferUIComponentFamily(component.getId()));
       }
       // add facelet tag if missing
       if (component.getTags().isEmpty()) {
         TagModel tag = new TagModel();
         component.getTags().add(tag);
         tag.setName(namingConventions.inferTagName(component.getId()));
         tag.setGenerate(false);
         tag.setType(TagType.Facelets);
       }
     } catch (RuntimeException e) {
       throw new CdkException("Caught error when verifying component " + component, e);
     }
   }
 }
Example #6
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");
 }
Example #7
0
  private boolean hasRendererSameBaseNameAsComponent(
      final RendererModel renderer, ComponentModel component) {
    String componentBaseName = component.getTargetClass().getSimpleName();
    String rendererBaseName = renderer.getTargetClass().getSimpleName();

    componentBaseName = componentBaseName.replaceFirst("^UI", "");
    rendererBaseName = rendererBaseName.replaceFirst("Renderer$", "");

    return componentBaseName.equals(rendererBaseName);
  }
Example #8
0
 private BeanProperty findBeanProperty(PropertyBase attribute, GeneratedFacesComponent component) {
   SourceUtils sourceUtils = sourceUtilsProvider.get();
   BeanProperty beanProperty =
       sourceUtils.getBeanProperty(component.getBaseClass(), attribute.getName());
   if (beanProperty instanceof DummyPropertyImpl && component instanceof ComponentModel) {
     ComponentModel model = (ComponentModel) component;
     if (null != model.getParent()) {
       beanProperty = findBeanProperty(attribute, model.getParent());
     }
   }
   if (beanProperty instanceof DummyPropertyImpl && component instanceof ModelElementBase) {
     ModelElementBase model = (ModelElementBase) component;
     for (ClassName interfaceName : model.getInterfaces()) {
       beanProperty = sourceUtils.getBeanProperty(interfaceName, attribute.getName());
       if (!(beanProperty instanceof DummyPropertyImpl)) {
         break;
       }
     }
   }
   return beanProperty;
 }
  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;
  }
Example #10
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);
     }
   }
 }