/** Get converted value and original value of this Binding. */ private Object[] getAttributeValues(Component comp) { if (!isSavable() || _attr.startsWith("_") || DataBinder.isTemplate(comp) || comp.getPage() == null) { return null; // cannot save, a control attribute, or a detached component, skip! } Object rawval = null; try { rawval = Fields.get(comp, _attr); } catch (NoSuchMethodException ex) { // Bug #1813278, Annotations do not work with xhtml tags if (comp instanceof DynamicPropertied) { final DynamicPropertied dpcomp = (DynamicPropertied) comp; if (dpcomp.hasDynamicProperty(_attr)) { rawval = dpcomp.getDynamicProperty(_attr); } else { throw UiException.Aide.wrap(ex); } } else if (comp.getAttributes() .containsKey( _attr)) { // Feature #2855116. Get value from component custom-attribute(also a // variable in ZK5). rawval = comp.getAttribute(_attr); } else { throw UiException.Aide.wrap(ex); } } try { final Object val = (_converter == null) ? rawval : _converter.coerceToBean(rawval, comp); return val == TypeConverter.IGNORE ? null : new Object[] {val, rawval}; } catch (ClassCastException ex) { throw UiException.Aide.wrap(ex); } }
/** * Initializes the context for the given page before rendering this page definition. * * <p>It is called before {@link Initiator#doInit} and {@link #init}. * * @param page the page to initialize the context. It cannot be null. */ public void preInit(Page page) { page.addClassResolver(_clsresolver); page.addFunctionMapper(getTaglibMapper()); if (_mapperdefs != null) for (Iterator it = _mapperdefs.iterator(); it.hasNext(); ) { final FunctionMapperInfo def = (FunctionMapperInfo) it.next(); try { FunctionMapper mapper = def.newFunctionMapper(this, page); if (mapper != null) page.addFunctionMapper(mapper); } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } } if (_resolvdefs != null) for (Iterator it = _resolvdefs.iterator(); it.hasNext(); ) { final VariableResolverInfo def = (VariableResolverInfo) it.next(); try { VariableResolver resolver = def.newVariableResolver(this, page); if (resolver != null) page.addVariableResolver(resolver); } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } } }
/** * Invokes {@link Initiator#doInit}, if any, and returns an instance of{@link Initiators}. * * @param sysinits the system-level initiators */ @SuppressWarnings("unchecked") public static final Initiators doInit(PageDefinition pagedef, Page page, Initiator[] sysinits) { if (sysinits != null) try { for (int j = 0; j < sysinits.length; ++j) sysinits[j].doInit(page, Collections.EMPTY_MAP); } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } final List<Initiator> inits = pagedef != null ? pagedef.doInit(page) : null; boolean sysinitEx = false; if (sysinits != null) for (int j = 0; j < sysinits.length; ++j) if (sysinits[j] instanceof InitiatorExt) { sysinitEx = true; break; } boolean initEx = false; if (inits != null) for (Initiator init : inits) if (init instanceof InitiatorExt) { initEx = true; break; } if (!sysinitEx && !initEx) return new Initiators(); return new RealInits(sysinits, inits, sysinitEx, initEx); }
/** Invokes {@link Initiator#doFinally}. */ public void doFinally() { Throwable t = null; if (_sysinitEx) for (int j = 0; j < _sysinits.length; ++j) { final Initiator init = _sysinits[j]; if (init instanceof InitiatorExt) { try { ((InitiatorExt) init).doFinally(); } catch (Throwable ex) { Initiators.log.error("", ex); if (t == null) t = ex; } } } if (_initEx) for (Initiator init : _inits) { if (init instanceof InitiatorExt) { try { ((InitiatorExt) init).doFinally(); } catch (Throwable ex) { Initiators.log.error("", ex); if (t == null) t = ex; } } } if (t != null) throw UiException.Aide.wrap(t); }
private BookCtrl getBookCtrl() { BookCtrl ctrl = _bookCtrl; if (ctrl == null) synchronized (this) { ctrl = _bookCtrl; if (ctrl == null) { String clsnm = Library.getProperty(BookCtrl.CLASS); if (clsnm != null) try { final Object o = Classes.newInstanceByThread(clsnm); if (!(o instanceof BookCtrl)) throw new UiException( o.getClass().getName() + " must implement " + BookCtrl.class.getName()); ctrl = (BookCtrl) o; } catch (UiException ex) { throw ex; } catch (Throwable ex) { throw UiException.Aide.wrap(ex, "Unable to load " + clsnm); } if (ctrl == null) ctrl = new BookCtrlImpl(); _bookCtrl = ctrl; } } return ctrl; }
public void call(Object base, Method method) { Class<?>[] paramTypes = method.getParameterTypes(); java.lang.annotation.Annotation[][] parmAnnos = method.getParameterAnnotations(); Object[] params = new Object[paramTypes.length]; try { for (int i = 0; i < paramTypes.length; i++) { params[i] = resolveParameter(parmAnnos[i], paramTypes[i]); } method.invoke(base, params); } catch (InvocationTargetException invokEx) { // Ian YT Tsai (2012.06.20), while InvocationTargetException, // using original exception is much meaningful. Throwable c = invokEx.getCause(); if (c == null) c = invokEx; _log.error(c); throw UiException.Aide.wrap(c); } catch (Exception e) { _log.error(e); throw UiException.Aide.wrap(e); } }
/** * Returns a list of all {@link Initiator} and invokes its {@link Initiator#doInit} before * returning. It never returns null. */ public List<Initiator> doInit(Page page) { if (_initdefs == null) return Collections.emptyList(); final List<Initiator> inits = new LinkedList<Initiator>(); try { for (InitiatorInfo ii : _initdefs) { final Initiator init = ii.newInitiator(getEvaluator(), page); if (init != null) inits.add(init); } } catch (Throwable ex) { throw UiException.Aide.wrap(ex); } return inits; }
/** * Set the {@link TypeConverter}. * * @param cvtClsName the converter class name. */ /*package*/ void setConverter(String cvtClsName) { if (cvtClsName != null) { // bug #2129992 Class cls = null; if (_comp == null || _comp.getPage() == null) { try { cls = Classes.forNameByThread(cvtClsName); } catch (ClassNotFoundException ex) { throw UiException.Aide.wrap(ex); } } else { try { cls = _comp.getPage().resolveClass(cvtClsName); } catch (ClassNotFoundException ex) { throw UiException.Aide.wrap(ex); } } try { _converter = (TypeConverter) cls.newInstance(); } catch (Exception ex) { throw UiException.Aide.wrap(ex); } } }
@SuppressWarnings("unchecked") private void setThreadLocals() { if (_threadLocals != null) { try { Class cls = Classes.forNameByThread( "org.springframework.transaction.support.TransactionSynchronizationManager"); getThreadLocal(cls, "resources").set(_threadLocals[0]); getThreadLocal(cls, "synchronizations").set(_threadLocals[1]); getThreadLocal(cls, "currentTransactionName").set(_threadLocals[2]); getThreadLocal(cls, "currentTransactionReadOnly").set(_threadLocals[3]); getThreadLocal(cls, "actualTransactionActive").set(_threadLocals[4]); // 20070907, Henri Chen: bug 1785457, hibernate3 might not used try { cls = Classes.forNameByThread("org.springframework.orm.hibernate3.SessionFactoryUtils"); getThreadLocal(cls, "deferredCloseHolder").set(_threadLocals[5]); } catch (ClassNotFoundException ex) { // ignore if hibernate 3 is not used. } cls = Classes.forNameByThread( "org.springframework.transaction.interceptor.TransactionAspectSupport"); // Spring 1.2.8 and Spring 2.0.x, the ThreadLocal field name has changed, default use 2.0.x // 2.0.x transactionInfoHolder // 1.2.8 currentTransactionInfo try { getThreadLocal(cls, "transactionInfoHolder").set(_threadLocals[6]); } catch (SystemException ex) { if (ex.getCause() instanceof NoSuchFieldException) { getThreadLocal(cls, "currentTransactionInfo").set(_threadLocals[6]); } else { throw ex; } } _threadLocals = null; } catch (ClassNotFoundException ex) { throw UiException.Aide.wrap(ex); } } }
@Override public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Exception { final String mname = method.getName(); Class<?> declaringClass = method.getDeclaringClass(); if (declaringClass.equals(FormFieldCleaner.class)) { return super.invoke(self, method, proceed, args); } else { if ("setFormOwner".equals(mname) || "getFormStatus".equals(mname)) { return super.invoke(self, method, proceed, args); } try { if (!method.getDeclaringClass().isAssignableFrom(FormProxyObject.class)) { if (mname.startsWith("get")) { if (_origin == null) return null; final String attr = toAttrName(method); if (_cache != null) { if (_cache.containsKey(attr)) { return _cache.get(attr); } } Object value = method.invoke(_origin, args); if (value != null) { // ZK-2736 Form proxy with Immutable values value = ProxyHelper.createProxyIfAny(value, method.getAnnotations()); addCache(attr, value); if (value instanceof FormProxyObject) { addDirtyField(attr); // it may be changed. } } return value; } } } catch (Exception e) { throw UiException.Aide.wrap(e); } } return super.invoke(self, method, proceed, args); }
/** * Sets the type of the sorter. You might specify either "auto", "auto(FIELD_NAME1[,FIELD_NAME2] * ...)"(since 3.5.3), "auto(<i>number</i>)" (since 5.0.6) or "none". * * <p>If "client" or "client(number)" is specified, the sort functionality will be done by * Javascript at client without notifying to server, that is, the order of the component in the * row is out of sync. * * <ul> * <li>"client" : it is treated by a string * <li>"client(number)" : it is treated by a number * </ul> * * <p>Note: client sorting cannot work in model case. (since 5.0.0) * * <p>If "auto" is specified, {@link #setSortAscending} and/or {@link #setSortDescending} are * called with {@link ListitemComparator}, if {@link #getSortDescending} and/or {@link * #getSortAscending} are null. If you assigned a comparator to them, it won't be affected. The * auto created comparator is case-insensitive. * * <p>If "auto(FIELD_NAME1, FIELD_NAME2, ...)" is specified, {@link #setSortAscending} and/or * {@link #setSortDescending} are called with {@link FieldComparator}, if {@link * #getSortDescending} and/or {@link #getSortAscending} are null. If you assigned a comparator to * them, it won't be affected. The auto created comparator is case-sensitive. * * <p>If "auto(LOWER(FIELD_NAME))" or "auto(UPPER(FIELD_NAME))" is specified, {@link * #setSortAscending} and/or {@link #setSortDescending} are called with {@link FieldComparator}, * if {@link #getSortDescending} and/or {@link #getSortAscending} are null. If you assigned a * comparator to them, it won't be affected. The auto created comparator is case-insensitive. * * <p>If "auto(<i>number</i>)" is specified, {@link #setSortAscending} and/or {@link * #setSortDescending} are called with {@link ArrayComparator}. Notice that the data must be an * array and the number-th element must be comparable ({@link Comparable}). * * <p>If "none" is specified, both {@link #setSortAscending} and {@link #setSortDescending} are * called with null. Therefore, no more sorting is available to users for this column. */ public void setSort(String type) { if (type == null) return; if (type.startsWith("client")) { try { setSortAscending(type); setSortDescending(type); } catch (Throwable ex) { throw UiException.Aide.wrap(ex); // not possible to throw ClassNotFoundException... } } else if ("auto".equals(type)) { if (getSortAscending() == null) setSortAscending(new ListitemComparator(this, true, true)); if (getSortDescending() == null) setSortDescending(new ListitemComparator(this, false, true)); } else if (!Strings.isBlank(type) && type.startsWith("auto")) { final int j = type.indexOf('('); final int k = type.lastIndexOf(')'); if (j >= 0 && k >= 0) { final String name = type.substring(j + 1, k); char cc; int index = -1; if (name.length() > 0 && (cc = name.charAt(0)) >= '0' && cc <= '9') if ((index = Integer.parseInt(name)) < 0) throw new IllegalArgumentException("Nonnegative number is required: " + name); if (getSortAscending() == null || !_isCustomAscComparator) { if (index < 0) setSortAscending(new FieldComparator(name, true)); else setSortAscending(new ArrayComparator(index, true)); _isCustomAscComparator = false; } if (getSortDescending() == null || !_isCustomDscComparator) { if (index < 0) setSortDescending(new FieldComparator(name, false)); else setSortDescending(new ArrayComparator(index, false)); _isCustomDscComparator = false; } } else { throw new UiException("Unknown sort type: " + type); } } else if ("none".equals(type)) { setSortAscending((Comparator) null); setSortDescending((Comparator) null); } }
public void run() { try { _inf.listener.onEvent(_event); if (_inf.callback != null || _pendingEvents != null) { Executions.activate(_desktop); try { if (_pendingEvents != null) for (T evt : _pendingEvents) _que.publish(evt); if (_inf.callback != null) _inf.callback.onEvent(_event); } finally { Executions.deactivate(_desktop); } } } catch (DesktopUnavailableException ex) { log.warn("", ex); // ignore } catch (Throwable ex) { log.error("", ex); throw UiException.Aide.wrap(ex); } }
private void myLoadAttribute(Component comp, Object bean) { try { // since 3.1, 20080416, support bindingArgs for non-supported tag // bug #2803575, merge bindingArgs together since a component can have // multiple bindings on different attributes. Map<Object, Object> bindArgs = cast((Map) comp.getAttribute(DataBinder.ARGS)); if (bindArgs == null) { bindArgs = new HashMap<Object, Object>(); comp.setAttribute(DataBinder.ARGS, bindArgs); } if (_args != null) { bindArgs.putAll(_args); comp.setAttribute(_attr + "_" + DataBinder.ARGS, _args); } if (_converter != null) { bean = _converter.coerceToUi(bean, comp); if (bean == TypeConverter.IGNORE) return; // ignore, so don't do Fields.set() } // Bug #1876198 Error msg appears when load page (databind+CustomConstraint) // catching WrongValueException no longer works, check special case and // use setRowValue() method directly if ((comp instanceof InputElement) && "value".equals(_attr)) { Object value = bean; Object oldv = null; try { // Bug 1879389 final Method m = comp.getClass().getMethod("getValue"); oldv = ((InputElement) comp).getRawValue(); value = Classes.coerce(m.getReturnType(), bean); } catch (NoSuchMethodException ex) { // ignore it } // See both Bug 3000305 and 2874098 Fields.set(comp, "rawValue", value, _converter == null); } else { Fields.set(comp, _attr, bean, _converter == null); } } catch (ClassCastException ex) { throw UiException.Aide.wrap(ex); } catch (NoSuchMethodException ex) { // Bug #1813278, Annotations do not work with xhtml tags if (comp instanceof DynamicPropertied) { final DynamicPropertied dpcomp = (DynamicPropertied) comp; if (dpcomp.hasDynamicProperty(_attr)) { // no way to know destination type of the property, use bean as is dpcomp.setDynamicProperty(_attr, bean); } else { throw UiException.Aide.wrap(ex); } } else { // Feature# 2855116. Save into component custom-attribute(also a variable in ZK5). comp.setAttribute(_attr, bean); } // Bug #1876198 Error msg appears when load page (databind+CustomConstraint) // catching WrongValueException no longer works, so mark it out /*} catch (WrongValueException ex) { //Bug #1615371, try to use setRawValue() if ("value".equals(_attr)) { try { Fields.set(comp, "rawValue", bean, _converter == null); } catch (Exception ex1) { //exception throw ex; } } else { throw ex; } */ } }
private static void load0() throws java.io.IOException { final XMLResourcesLocator locator = Utils.getXMLResourcesLocator(); // 1. parse config.xml final ConfigParser parser = new ConfigParser(); parser.parseConfigXml(null); // only system default configs // 2. process lang.xml (no particular dependency) for (Enumeration en = locator.getResources("metainfo/zk/lang.xml"); en.hasMoreElements(); ) { final URL url = (URL) en.nextElement(); if (log.isDebugEnabled()) log.debug("Loading " + url); try { final Document doc = new SAXBuilder(true, false, true).build(url); if (ConfigParser.checkVersion(url, doc, true)) parseLang(doc, locator, url, false); } catch (Exception ex) { log.error("Failed to load " + url, ex); throw UiException.Aide.wrap(ex, "Failed to load " + url); // abort since it is hardly to work then } } // 5. process other language (from addLanguage) if (_langs != null) { for (Iterator<Object[]> it = _langs.iterator(); it.hasNext(); ) { final Object[] p = it.next(); loadLang((Locator) p[0], (URL) p[1], false); } _langs = null; // free memory } // 4. process lang-addon.xml (with dependency) final List<XMLResourcesLocator.Resource> xmls = locator.getDependentXMLResources("metainfo/zk/lang-addon.xml", "addon-name", "depends"); for (XMLResourcesLocator.Resource res : xmls) { try { if (ConfigParser.checkVersion(res.url, res.document, true)) parseLang(res.document, locator, res.url, true); } catch (Exception ex) { log.error("Failed to load " + res.url, ex); // keep running } } // 5. process other addon (from addAddon) if (_addons != null) { for (Iterator<Object[]> it = _addons.iterator(); it.hasNext(); ) { final Object[] p = it.next(); loadLang((Locator) p[0], (URL) p[1], true); // addon } _addons = null; // free memory } // 6. process the extension if (_exts != null) { for (Map.Entry<String, String> me : _exts.entrySet()) { final String ext = me.getKey(); final String lang = me.getValue(); try { LanguageDefinition.addExtension(ext, lang); } catch (DefinitionNotFoundException ex) { log.warn("Extension " + ext + " ignored since language " + lang + " not found"); } } _exts = null; } }