private void resolveInsertComponents(Collection<Component> comps, Map<String, Component> map) { for (Component comp : comps) { final Annotation annt = ((ComponentCtrl) comp).getAnnotation(null, "insert"); if (annt != null) { final String insertName = annt.getAttribute("value"); if (map.containsKey(insertName)) { throw new UiException("Duplicate insert name: " + insertName + " at Component " + comp); } map.put(insertName, comp); } resolveInsertComponents(comp.getChildren(), map); //recursive } } }
private void processReferenceBinding(Component comp, String propName, Annotation ann) { String loadExpr = null; Map<String, String[]> args = null; for (final Iterator<Entry<String, String[]>> it = ann.getAttributes().entrySet().iterator(); it.hasNext();) { final Entry<String, String[]> entry = it.next(); final String tag = entry.getKey(); final String[] tagExpr = entry.getValue(); if ("value".equals(tag)) { loadExpr = AnnotationUtil.testString(tagExpr, ann); } else { //other unknown tag, keep as arguments if (args == null) { args = new HashMap<String, String[]>(); } args.put(tag, tagExpr); } } final Map<String, Object> parsedArgs = args == null ? null : BindEvaluatorXUtil.parseArgs(_binder.getEvaluatorX(), args); try { BinderUtil.pushContext().setCurrentLocation(ann.getLocation()); _binder.addReferenceBinding(comp, propName, loadExpr, parsedArgs); } finally { BinderUtil.popContext(); } }
public void checkBinder(Component comp) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; for (Annotation anno : compCtrl.getAnnotations(BINDER_ATTR)) { String nm = anno.getName(); if (ID_ANNO.equals(nm) || INIT_ANNO.equals(nm)) { continue; } try { BinderUtil.pushContext().setCurrentLocation(anno.getLocation()); _collector.addInfo(new AnnoWarnInfo(comp, BINDER_ATTR, nm, "Unknow binder annotation")); } finally { BinderUtil.popContext(); } } }
private String getSystemConverter(Component comp, String attr) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; final Annotation ann = AnnotationUtil.getSystemAnnotation(compCtrl, attr); if (ann != null) { final Map<String, String[]> attrs = ann.getAttributes(); //(tag, tagExpr) return AnnotationUtil.testString(attrs.get(Binder.CONVERTER), ann); //system converter if exists } return null; }
for (String propName : annotationMap.getAnnotatedProperties()) { for (Annotation anno : annotationMap.getAnnotations(propName)) { compInfo.addAnnotation(propName, anno.getName(), anno.getAttributes(), anno.getLocation());
final String idExpr = idanno.getAttribute("value"); if (anno.getName().equals(LOAD_ANNO)) { processFormLoadBindings(comp, formId, anno); } else if (anno.getName().equals(SAVE_ANNO)) { processFormSaveBindings(comp, formId, anno, validatorInfo);
public static String formatLocationMessage(String message, Annotation anno) { if (anno == null) return message; return formatLocationMessage(message, anno.getLocation(), true); }
/** * Returns whether the property name contains with a dynamic value. */ protected boolean isDynamicValue(String propName) { final ComponentCtrl compCtrl = this; Collection<Annotation> annos = compCtrl.getAnnotations(propName); if (!annos.isEmpty()) { for (Annotation anno : annos) { final String annoName = anno.getName(); if (annoName.equals(BIND_ANNO) || annoName.equals(LOAD_ANNO) || annoName.equals(SAVE_ANNO) || annoName.equals(REFERENCE_ANNO) || annoName.equals(INIT_ANNO)) { return true; } } } return false; }
AnnotationUtil.testString(idanno.getAttributeValues(VALUE_ANNO_ATTR), idanno), String.class); if (Strings.isEmpty(vname)) { throw new UiException(MiscUtil.formatLocationMessage("name of ValidationMessages is empty", idanno)); AnnotationUtil.testString(initanno.getAttributeValues(VALUE_ANNO_ATTR), initanno), Object.class); try { if (vmessages instanceof String) {
private String getSystemValidator(Component comp, String attr) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; final Annotation ann = AnnotationUtil.getSystemAnnotation(compCtrl, attr); if (ann != null) { final Map<String, String[]> attrs = ann.getAttributes(); //(tag, tagExpr) return AnnotationUtil.testString(attrs.get(Binder.VALIDATOR), ann); //system validator if exists } return null; }
private static Location toComponentLocation(Component comp) { if (comp instanceof AbstractComponent) { Annotation anno = ((AbstractComponent) comp).getAnnotation(null, "ZKLOC"); return anno == null ? null : anno.getLocation(); } return null; }
public static String testString(String[] string, Annotation anno) { if (string == null || string.length == 0) { return null; } else if (string.length == 1) { return string[0]; } else { throw new IllegalSyntaxException(MiscUtil.formatLocationMessage( "only allow one string of @" + anno.getName() + ",but contains " + Arrays.toString(string), anno)); } } }
AnnotationUtil.testString(idanno.getAttributeValues(VALUE_ANNO_ATTR), idanno), String.class); if (Strings.isEmpty(bname)) { throw new UiException(MiscUtil.formatLocationMessage("name of binder is empty", idanno)); binder = AnnotationUtil.testString(initanno.getAttributeValues(VALUE_ANNO_ATTR), initanno); String name = AnnotationUtil.testString(initanno.getAttributeValues(QUEUE_NAME_ANNO_ATTR), initanno); String scope = AnnotationUtil.testString(initanno.getAttributeValues(QUEUE_SCOPE_ANNO_ATTR), initanno);
private void processFormInit(Component comp, String formId, Annotation ann) { String initExpr = null; Map<String, String[]> args = null; for (final Iterator<Entry<String, String[]>> it = ann.getAttributes().entrySet().iterator(); it.hasNext();) { final Entry<String, String[]> entry = it.next(); final String tag = entry.getKey(); final String[] tagExpr = entry.getValue(); if ("value".equals(tag)) { initExpr = AnnotationUtil.testString(tagExpr, ann); } else { //other unknown tag, keep as arguments if (args == null) { args = new HashMap<String, String[]>(); } args.put(tag, tagExpr); } } final Map<String, Object> parsedArgs = args == null ? null : BindEvaluatorXUtil.parseArgs(_binder.getEvaluatorX(), args); try { BinderUtil.pushContext().setCurrentLocation(ann.getLocation()); _binder.addFormInitBinding(comp, formId, initExpr, parsedArgs); } finally { BinderUtil.popContext(); } }
private Map<String, Object> getViewModelInitArgs(BindEvaluatorX evalx, Component comp) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; final Collection<Annotation> anncol = compCtrl.getAnnotations(VIEW_MODEL_ATTR, INIT_ANNO); if (anncol.size() == 0) return null; final Annotation ann = anncol.iterator().next(); final Map<String, String[]> attrs = ann.getAttributes(); //(tag, tagExpr) Map<String, String[]> args = null; for (final Iterator<Entry<String, String[]>> it = attrs.entrySet().iterator(); it.hasNext();) { final Entry<String, String[]> entry = it.next(); final String tag = entry.getKey(); final String[] tagExpr = entry.getValue(); if ("value".equals(tag)) { //ignore } else { //other unknown tag, keep as arguments if (args == null) { args = new HashMap<String, String[]>(); } args.put(tag, tagExpr); } } return args == null ? null : BindEvaluatorXUtil.parseArgs(_binder.getEvaluatorX(), args); }
public void checkViewModel(Component comp) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; for (Annotation anno : compCtrl.getAnnotations(VIEW_MODEL_ATTR)) { String nm = anno.getName(); if (ID_ANNO.equals(nm) || INIT_ANNO.equals(nm)) { continue; } try { BinderUtil.pushContext().setCurrentLocation(anno.getLocation()); _collector.addInfo(new AnnoWarnInfo(comp, VIEW_MODEL_ATTR, nm, "Unknow viewmodel annotation")); } finally { BinderUtil.popContext(); } } }
String pattern = null; if (annot != null) { pattern = annot.getAttribute("value");
/** Returns the annotation associated with the specified * property, or null if not available. * * @param annotName the annotation name * @param propName the property name, e.g., "value". * If null, this method returns the annotation(s) associated with the * component (rather than a particular property). */ public Annotation getAnnotation(String propName, String annotName) { if (_annots != null) { final Map<String, List<Annotation>> anmap = _annots.get(propName); if (anmap != null) { List<Annotation> ans = anmap.get(annotName); if (ans != null) { if (ans.size() == 1) return ans.get(0); //merge annotations into a single annotation final AnnotImpl ai = new AnnotImpl(annotName, null); for (Annotation an : ans) { if (ai._loc == null) ai._loc = an.getLocation(); ai.addAttributes(an); } return ai; } } } return null; }
private void processChildrenBindings(Component comp) { final ComponentCtrl compCtrl = (ComponentCtrl) comp; ExpressionAnnoInfo converterInfo = parseConverter(comp, CHILDREN_ATTR); //scan init first Collection<Annotation> initannos = compCtrl.getAnnotations(CHILDREN_ATTR, INIT_ANNO); if (initannos.size() > 1) { throw new IllegalSyntaxException(MiscUtil.formatLocationMessage( "Allow only one @init for " + CHILDREN_ATTR + " of " + comp, initannos.iterator().next())); } else if (initannos.size() == 1) { processChildrenInit(comp, initannos.iterator().next(), converterInfo); } Collection<Annotation> annos = compCtrl.getAnnotations(CHILDREN_ATTR); //get all annotation in the children with the order. for (Annotation anno : annos) { if (anno.getName().equals(BIND_ANNO)) { processChildrenPromptBindings(comp, anno, converterInfo); } else if (anno.getName().equals(LOAD_ANNO)) { processChildrenLoadBindings(comp, anno, converterInfo); } } ExpressionAnnoInfo templateInfo = parseTemplate(comp, CHILDREN_ATTR); if (templateInfo != null) { //use special CHILDREN_KEY to avoid conflict _binder.setTemplate(comp, CHILDREN_KEY, templateInfo.expr, templateInfo.args); } }
AnnotationUtil.testString(idanno.getAttributeValues(VALUE_ANNO_ATTR), idanno), String.class); vm = BindEvaluatorXUtil.eval(evalx, comp, AnnotationUtil.testString(initanno.getAttributeValues(VALUE_ANNO_ATTR), initanno), Object.class);