/** Applies the annotations defined in this helper to the specified * instance definition. * * @param compInfo the instance definition to update * @param propName the property name * @param clear whether to clear all definitions before returning * @see #clear * @since 8.0.0 */ public void applyAnnotations(ShadowInfo compInfo, String propName, boolean clear) { for (AnnotInfo info : _annots) { compInfo.addAnnotation(propName, info.name, info.attrs, info.loc); } if (clear) _annots.clear(); }
private static final LanguageDefinition getLanguageDefinition(NodeInfo node) { for (; node != null; node = node.getParent()) { if (node instanceof ComponentInfo) { LanguageDefinition langdef = ((ComponentInfo) node).getLanguageDefinition(); if (langdef != null) return langdef; } else if (node instanceof PageDefinition) { return ((PageDefinition) node).getLanguageDefinition(); } else if (node instanceof ShadowInfo) { return ((ShadowInfo) node).getLanguageDefinition(); } } return null; }
ComponentDefinition shadowDefinition = lookup.hasShadowDefinition(name) ? lookup.getShadowDefinition(name) : pgdef.getComponentDefinitionMap().get(name); final ShadowInfo compInfo = new ShadowInfo(parent, shadowDefinition, name, ConditionImpl.getInstance(ifc, unless)); boolean _annotationed = false; for (String annot : binderAnnotations) { if (attvaltrim.contains(annot)) { compInfo.enableBindingAnnotation(); _annotationed = true; break; compInfo.addProperty(attnm, attval, null); if (attrAnnHelper != null) attrAnnHelper.applyAnnotations(compInfo, attnm, true); compInfo.setCondition(ConditionImpl.getInstance(ifc, unless)); annHelper.applyAnnotations(compInfo, null, true); compInfo.setAnnotationNamespacedRoot(true);
} else if (curInfo instanceof ShadowInfo) { final ShadowInfo compInfo = (ShadowInfo) curInfo; _def = compInfo.getComponentDefinition(); addSharedAnnotationMap(_def.getAnnotationMap()); addSharedAnnotationMap(compInfo.getAnnotationMap()); if (compInfo.hasBindingAnnotation()) enableBindingAnnotation(); } else {
public Component newComponent(Page page, Component parent, ShadowInfo compInfo, Component insertBefore) { final Component comp = compInfo.newInstance(page, parent); Utils.setShadowInfo(comp, compInfo); Object currentInfo = ShadowElementsCtrl.getCurrentInfo(); if (currentInfo instanceof ShadowElement && ((ShadowElementCtrl) currentInfo).getShadowHostIfAny() == parent) { ((Component) currentInfo).insertBefore(comp, insertBefore); } else if (parent instanceof ShadowElement) { parent.insertBefore(comp, insertBefore); } else if (parent != null) { ((ShadowElementCtrl) comp).setShadowHost(parent, insertBefore); } else { //ZK-2955: Shadow element could be used in root element <zk> Component emptyRoot = null; String clsnm = Library.getProperty("org.zkoss.zk.ui.ShadowDefaultHost.class"); if (clsnm != null) { try { emptyRoot = (Component) Classes.newInstanceByThread(clsnm); emptyRoot.setPage(page); ((ShadowElementCtrl) comp).setShadowHost(emptyRoot, insertBefore); } catch (Throwable ex) { log.warn("Unable to load " + clsnm, ex); } } } if (comp instanceof BeforeCompose) ((BeforeCompose) comp).beforeCompose(); compInfo.applyProperties(comp); //include comp's definition Utils.setShadowInfo(comp, null); return comp; }
public Component newInstance(Class<? extends Component> cls) { final Object curInfo = ComponentsCtrl.getCurrentInfo(); boolean bSet = true; if (curInfo instanceof ComponentInfo) { bSet = ((ComponentInfo) curInfo).getComponentDefinition() != this; } else if (curInfo instanceof ShadowInfo) { bSet = ((ShadowInfo) curInfo).getComponentDefinition() != this; } if (bSet) ComponentsCtrl.setCurrentInfo(this); final Component comp; try { comp = cls.newInstance(); } catch (Exception ex) { throw UiException.Aide.wrap(ex); } finally { if (bSet) ComponentsCtrl.setCurrentInfo((ComponentDefinition) null); } return comp; }
private static Component[] execCreateChild(CreateInfo ci, Component parent, ShadowInfo childInfo, Component insertBefore) { Component child = null; final boolean bRoot = parent == null; try { // None composer support for shadow element child = ci.uf.newComponent(ci.page, parent, childInfo, insertBefore); childInfo.apply(child); // apply the property from ShadowInfo execCreate(ci, childInfo, child, null); //recursive (and appendChild) if (child instanceof AfterCompose) ((AfterCompose) child).afterCompose(); } catch (Throwable ex) { boolean ignore = ci.doCatch(ex, bRoot); if (!ignore) throw UiException.Aide.wrap(ex); } return child != null ? new Component[] { child } : new Component[0]; }