Exemplo n.º 1
0
 private void verifyGeneratedClasses(
     GeneratedFacesComponent component, NamingConventionsCallback callback)
     throws CallbackException {
   if (null == component.getBaseClass()) {
     component.setBaseClass(callback.getDefaultBaseClass());
     // return;
   }
   if (null == component.getTargetClass()) {
     component.setTargetClass(callback.inferClass(component.getId()));
   }
 }
Exemplo n.º 2
0
 protected void verifyAttribute(PropertyBase attribute, GeneratedFacesComponent component) {
   // Check name.
   if (Strings.isEmpty(attribute.getName())) {
     log.error("No name for attribute " + attribute);
     return;
   }
   if (attribute.getName().contains(".")
       || Character.isDigit(attribute.getName().charAt(0))
       || attribute.getName().contains(" ")) {
     log.error("Invalid attribute name [" + attribute.getName() + "]");
     return;
   }
   // Check type
   BeanProperty beanProperty = findBeanProperty(attribute, component);
   if (null == attribute.getType()) {
     log.warn("Unknown type of attribute [" + attribute.getName() + "]");
     attribute.setType(beanProperty.getType());
   }
   if (attribute.getType().isPrimitive() && null == attribute.getDefaultValue()) {
     // Set default value for primitive
     attribute.setDefaultValue(attribute.getType().getDefaultValue());
   }
   // Check binding properties.
   if ("javax.faces.el.MethodBinding".equals(attribute.getType().getName())) {
     attribute.setBinding(true);
     attribute.setBindingAttribute(true);
   } else if ("javax.el.MethodExpression".equals(attribute.getType().getName())) {
     attribute.setBindingAttribute(true);
   }
   // if(attribute.isBindingAttribute() && attribute.getSignature().isEmpty() &&
   // !attribute.isHidden()) {
   // log.error("Signature for method expression attribute "+attribute.getName()+" has not been
   // set");
   // }
   // Check "generate" flag.
   if (Boolean.TRUE.equals(component.getGenerate())) {
     // TODO Attribute should be only generated if it does not exist or abstract in the base class.
     // Step one - check base class
     if (SPECIAL_PROPERTIES.contains(attribute.getName())) {
       attribute.setGenerate(false);
     } else if (null == attribute.getGenerate()) {
       attribute.setGenerate(!beanProperty.isExists());
     }
   } else {
     attribute.setGenerate(false);
   }
   verifyDescription(attribute);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * This method virifies type/family attributes for JSF objects ( components, renderers,
  * validators, converters, behaviors )
  *
  * @param component object to verify.
  * @param callback callback to corresponding naming conventions.
  * @return
  */
 protected boolean verifyTypes(
     GeneratedFacesComponent component, NamingConventionsCallback callback) {
   // Check JsfComponent type.
   try {
     if (null == component.getId()) {
       if (null != component.getTargetClass()) {
         component.setId(callback.inferType(component.getTargetClass()));
       } else if (null != component.getBaseClass()) {
         component.setId(callback.inferType(component.getBaseClass()));
       } else {
         component.setId(callback.inferType());
       }
     }
     // Check classes.
     if (null == component.getGenerate()) {
       if (null == component.getTargetClass()) {
         component.setTargetClass(callback.inferClass(component.getId()));
       }
       component.setGenerate(!sourceUtilsProvider.get().isClassExists(component.getTargetClass()));
     }
     if (component.getGenerate()) {
       verifyGeneratedClasses(component, callback);
     } else if (null == component.getTargetClass()) {
       if (null == component.getBaseClass()) {
         component.setBaseClass(callback.getDefaultClass());
       }
       component.setTargetClass(component.getBaseClass());
     }
   } catch (CallbackException e) {
     log.error(e.getMessage());
     return false;
   }
   return true;
 }