public boolean required() { return core.required(); }
protected boolean isMandatory(Object bean, String propertyName) { // lets look at the setter method and see if its got a @Required // annotation if (bean instanceof AbstractNode) { AbstractNode node = (AbstractNode) bean; Class<?> camelClass = node.getCamelDefinitionClass(); if (camelClass != null) { XmlAccessorType accessorType = camelClass.getAnnotation(XmlAccessorType.class); boolean useMethods = true; if (accessorType != null) { if (accessorType.value().equals(XmlAccessType.FIELD)) { useMethods = false; } } try { BeanInfo beanInfo = Introspector.getBeanInfo(camelClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); if (propertyDescriptors != null) { for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { if (propertyName.equals(propertyDescriptor.getName())) { Method writeMethod = propertyDescriptor.getWriteMethod(); if (writeMethod != null) { Required annotation = writeMethod.getAnnotation(Required.class); if (annotation != null) { return true; } if (useMethods) { XmlElement element = writeMethod.getAnnotation(XmlElement.class); if (element != null && element.required()) { return true; } XmlAttribute attribute = writeMethod.getAnnotation(XmlAttribute.class); if (attribute != null && attribute.required()) { return true; } } } break; } } } if (!useMethods) { Field[] fields = camelClass.getDeclaredFields(); for (Field field : fields) { if (propertyName.equals(field.getName())) { Required annotation = field.getAnnotation(Required.class); if (annotation != null) { return true; } XmlElement element = field.getAnnotation(XmlElement.class); if (element != null && element.required()) { return true; } XmlAttribute attribute = field.getAnnotation(XmlAttribute.class); if (attribute != null && attribute.required()) { return true; } } } } } catch (IntrospectionException e) { // ignore } } } // expression is mandatory on resequence if (node instanceof Resequence && "expression".equals(propertyName)) { return true; } // lets make all URI properties mandatory by default to avoid complex // validation with ref v uri boolean answer = ("uri".equals(propertyName) || propertyName.endsWith("Uri")) || (bean instanceof Aggregate && "strategyRef".equals(propertyName)) || (bean instanceof ConvertBody && "type".equals(propertyName)) || (bean instanceof ExpressionDefinition && isMandatoryExpression()) || (bean instanceof Log && "message".equals(propertyName)) || (bean instanceof Process && "ref".equals(propertyName)) || (bean instanceof RemoveHeader && "headerName".equals(propertyName)) || (bean instanceof RemoveProperty && "propertyName".equals(propertyName)) || (bean instanceof SetHeader && "headerName".equals(propertyName)) || (bean instanceof SetOutHeader && "headerName".equals(propertyName)) || (bean instanceof SetProperty && "propertyName".equals(propertyName)); return answer; }
public String namespace() { return core.namespace(); }
private void processFieldRelatedAnnotations( Annotation annots[], String fieldName, Type defaultGenericType) { WrappedElementInfo wrappedInfo = null; for (Annotation annot : annots) { if (annot instanceof XmlElementWrapper) { XmlElementWrapper wrapper = (XmlElementWrapper) annot; wrappedInfo = new WrappedElementInfo(wrapper, fieldName); jaxbElemNodeInfo.add(wrappedInfo); break; } } for (Annotation annot : annots) { if (annot instanceof XmlValue) { elementValue = new JaxbValueInfo((XmlValue) annot, fieldName, defaultGenericType); } else if (annot instanceof XmlAttribute) { XmlAttribute attr = (XmlAttribute) annot; String attrName = attr.name(); if ((attrName == null) || DEFAULT_MARKER.equals(attrName)) { attrName = fieldName; } this.setXmlAttributeInfo(attr, fieldName, defaultGenericType); this.attributeNames.add(attrName); } else if (annot instanceof XmlElement) { XmlElement xmlElem = (XmlElement) annot; if (wrappedInfo == null) { setXmlElementInfo(xmlElem, fieldName, defaultGenericType); } else { wrappedInfo.add(xmlElem, fieldName, defaultGenericType); } } else if (annot instanceof XmlElementRef) { XmlElementRef xmlElemR = (XmlElementRef) annot; if (wrappedInfo == null) { setXmlElementInfo(xmlElemR, null, null); } else { wrappedInfo.add(xmlElemR, null, null); } } else if (annot instanceof XmlElements) { JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType); if (wrappedInfo == null) { jaxbElemNodeInfo.add(choiceNode); } else { wrappedInfo.add(choiceNode); } XmlElements xmlElemsAnnot = (XmlElements) annot; for (XmlElement xmlE : xmlElemsAnnot.value()) { choiceNode.add(xmlE); } } else if (annot instanceof XmlElementRefs) { JaxbPseudoNodeChoiceInfo choiceNode = new JaxbPseudoNodeChoiceInfo(fieldName, defaultGenericType); if (wrappedInfo == null) { jaxbElemNodeInfo.add(choiceNode); } else { wrappedInfo.add(choiceNode); } XmlElementRefs elemRefs = (XmlElementRefs) annot; for (XmlElementRef xmlE : elemRefs.value()) { choiceNode.add(xmlE); } } } }