Exemplo n.º 1
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);
     }
   }
 }
Exemplo n.º 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);
     }
   }
 }
Exemplo n.º 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);
         }
       }
     }
   }
 }
Exemplo n.º 4
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.º 5
0
 /**
  * Verify all behaviors in the library.
  *
  * @param library
  */
 protected void verifyBehaviors(ComponentLibrary library) {
   for (final BehaviorModel behavior : library.getBehaviors()) {
     verifyTypes(behavior, new BehaviorTypeCallback(behavior));
     for (TagModel tag : behavior.getTags()) {
       verifyTag(tag, behavior.getId(), DEFAULT_BEHAVIOR_HANDLER);
     }
   }
 }
Exemplo n.º 6
0
 protected void verifyRenderers(ComponentLibrary library) {
   for (RenderKitModel renderKit : library.getRenderKits()) {
     // Check render kit name and class.
     for (RendererModel renderer : renderKit.getRenderers()) {
       try {
         vefifyRenderer(library, renderer);
       } catch (RuntimeException e) {
         throw new IllegalStateException("Caught error when verifying renderer " + renderer, e);
       }
     }
   }
 }
Exemplo n.º 7
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);
     }
   }
 }
Exemplo n.º 8
0
 protected void verifyConverters(ComponentLibrary library) {
   for (ConverterModel converter : library.getConverters()) {
     verifyTypes(converter, new ConverterTypeCallback(converter));
   }
 }
Exemplo n.º 9
0
 private void verifyValidators(ComponentLibrary library) {
   for (ValidatorModel validator : library.getValidators()) {
     verifyTypes(validator, new ValidatorTypeCallback(validator));
   }
 }