public void doTag(XMLOutput output) throws JellyTagException { Map attributes = getAttributes(); String var = (String) attributes.get( "var" ); Object classObject = attributes.get( "class" ); addIgnoreProperty("class"); addIgnoreProperty("var"); try { // this method could return null in derived classes Class theClass = convertToClass(classObject); bean = newInstance(theClass, attributes, output); setBeanProperties(bean, attributes); // invoke body which could result in other properties being set invokeBody(output); processBean(var, bean); } catch (ClassNotFoundException e) { throw new JellyTagException(e); } }
public Class getAttributeType(String name) throws JellyTagException { if (name.equals("items")) { return Expression.class; } return super.getAttributeType(name); }
/** * Adds a name to the Set of property names that will be skipped when setting * bean properties. In other words, names added here won't be set into the bean * if they're present in the attribute Map. * @param name */ protected void addIgnoreProperty(String name) { getIgnorePropertySet().add(name); }
/** * Sets the properties on the bean. Derived tags could implement some custom * type conversion etc. * <p/> * This method ignores all property names in the Set returned by {@link #getIgnorePropertySet()}. */ protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { Map attrsToUse = new HashMap(attributes); attrsToUse.keySet().removeAll(getIgnorePropertySet()); validateBeanProperties(bean, attrsToUse); try { BeanUtils.populate(bean, attrsToUse); } catch (IllegalAccessException e) { throw new JellyTagException("could not set the properties of the bean",e); } catch (InvocationTargetException e) { throw new JellyTagException("could not set the properties of the bean",e); } }
/** * Attempts to convert the given object to a Class instance. * If the classObject is already a Class it will be returned * otherwise it will be converted to a String and loaded * using the default class loading mechanism. */ protected Class convertToClass(Object classObject) throws MissingAttributeException, ClassNotFoundException { if (classObject instanceof Class) { return (Class) classObject; } else if ( classObject == null ) { Class theClass = getDefaultClass(); if (theClass == null) { throw new MissingAttributeException("class"); } return theClass; } else { String className = classObject.toString(); return loadClass(className); } }
protected void processBean(String var, Object bean) throws JellyTagException { super.processBean(var, bean); List list = getList(); // if the items variable is specified lets append all the items if (items != null) { Iterator iter = items.evaluateAsIterator(context); while (iter.hasNext()) { list.add( iter.next() ); } } }
/** * By default this will export the bean using the given variable if it is defined. * This Strategy method allows derived tags to process the beans in different ways * such as to register this bean with its parent tag etc. */ protected void processBean(String var, Object bean) throws JellyTagException { if (var != null) { context.setVariable(var, bean); } else { ArgTag parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class)); if(null != parentArg) { parentArg.setValue(bean); } } }
/** * If {@link #isIgnoreUnknownProperties()} returns true, make sure that * every non-ignored ({@see #addIgnoreProperty(String)}) property * matches a writable property on the target bean. * @param bean the bean to validate * @param attributes the list of properties to validate * @throws JellyTagException when a property is not writeable */ protected void validateBeanProperties(Object bean, Map attributes) throws JellyTagException { if (!isIgnoreUnknownProperties()) { for (Iterator i=attributes.keySet().iterator();i.hasNext();) { String attrName = (String)i.next(); if (! PropertyUtils.isWriteable(bean, attrName)) { throw new JellyTagException("No bean property found: " + attrName); } } } }
/** * Sets the properties on the bean. Derived tags could implement some custom * type conversion etc. * <p/> * This method ignores all property names in the Set returned by {@link #getIgnorePropertySet()}. */ protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { Map attrsToUse = new HashMap(attributes); attrsToUse.keySet().removeAll(getIgnorePropertySet()); validateBeanProperties(bean, attrsToUse); try { BeanUtils.populate(bean, attrsToUse); } catch (IllegalAccessException e) { throw new JellyTagException("could not set the properties of the bean",e); } catch (InvocationTargetException e) { throw new JellyTagException("could not set the properties of the bean",e); } }
/** * Attempts to convert the given object to a Class instance. * If the classObject is already a Class it will be returned * otherwise it will be converted to a String and loaded * using the default class loading mechanism. */ protected Class convertToClass(Object classObject) throws MissingAttributeException, ClassNotFoundException { if (classObject instanceof Class) { return (Class) classObject; } else if ( classObject == null ) { Class theClass = getDefaultClass(); if (theClass == null) { throw new MissingAttributeException("class"); } return theClass; } else { String className = classObject.toString(); return loadClass(className); } }
protected void processBean(String var, Object bean) throws JellyTagException { super.processBean(var, bean); List list = getList(); // if the items variable is specified lets append all the items if (items != null) { Iterator iter = items.evaluateAsIterator(context); while (iter.hasNext()) { list.add( iter.next() ); } } }
/** * By default this will export the bean using the given variable if it is defined. * This Strategy method allows derived tags to process the beans in different ways * such as to register this bean with its parent tag etc. */ protected void processBean(String var, Object bean) throws JellyTagException { if (var != null) { context.setVariable(var, bean); } else { ArgTag parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class)); if(null != parentArg) { parentArg.setValue(bean); } } }
/** * If {@link #isIgnoreUnknownProperties()} returns true, make sure that * every non-ignored ({@see #addIgnoreProperty(String)}) property * matches a writable property on the target bean. * @param bean the bean to validate * @param attributes the list of properties to validate * @throws JellyTagException when a property is not writeable */ protected void validateBeanProperties(Object bean, Map attributes) throws JellyTagException { if (!isIgnoreUnknownProperties()) { for (Iterator i=attributes.keySet().iterator();i.hasNext();) { String attrName = (String)i.next(); if (! PropertyUtils.isWriteable(bean, attrName)) { throw new JellyTagException("No bean property found: " + attrName); } } } }
public void doTag(XMLOutput output) throws JellyTagException { Map attributes = getAttributes(); String var = (String) attributes.get( "var" ); Object classObject = attributes.get( "class" ); addIgnoreProperty("class"); addIgnoreProperty("var"); try { // this method could return null in derived classes Class theClass = convertToClass(classObject); bean = newInstance(theClass, attributes, output); setBeanProperties(bean, attributes); // invoke body which could result in other properties being set invokeBody(output); processBean(var, bean); } catch (ClassNotFoundException e) { throw new JellyTagException(e); } }
/** * Sets the properties on the bean. Derived tags could implement some custom * type conversion etc. * <p/> * This method ignores all property names in the Set returned by {@link #getIgnorePropertySet()}. */ protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { Map attrsToUse = new HashMap(attributes); attrsToUse.keySet().removeAll(getIgnorePropertySet()); validateBeanProperties(bean, attrsToUse); try { BeanUtils.populate(bean, attrsToUse); } catch (IllegalAccessException e) { throw new JellyTagException("could not set the properties of the bean",e); } catch (InvocationTargetException e) { throw new JellyTagException("could not set the properties of the bean",e); } }
/** * Attempts to convert the given object to a Class instance. * If the classObject is already a Class it will be returned * otherwise it will be converted to a String and loaded * using the default class loading mechanism. */ protected Class convertToClass(Object classObject) throws MissingAttributeException, ClassNotFoundException { if (classObject instanceof Class) { return (Class) classObject; } else if ( classObject == null ) { Class theClass = getDefaultClass(); if (theClass == null) { throw new MissingAttributeException("class"); } return theClass; } else { String className = classObject.toString(); return loadClass(className); } }
protected void processBean(String var, Object bean) throws JellyTagException { super.processBean(var, bean); List list = getList(); // if the items variable is specified lets append all the items if (items != null) { Iterator iter = items.evaluateAsIterator(context); while (iter.hasNext()) { list.add( iter.next() ); } } }
/** * Adds a name to the Set of property names that will be skipped when setting * bean properties. In other words, names added here won't be set into the bean * if they're present in the attribute Map. * @param name */ protected void addIgnoreProperty(String name) { getIgnorePropertySet().add(name); }
public Class getAttributeType(String name) throws JellyTagException { if (name.equals("items")) { return Expression.class; } return super.getAttributeType(name); }
/** * By default this will export the bean using the given variable if it is defined. * This Strategy method allows derived tags to process the beans in different ways * such as to register this bean with its parent tag etc. */ protected void processBean(String var, Object bean) throws JellyTagException { if (var != null) { context.setVariable(var, bean); } else { ArgTag parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class)); if(null != parentArg) { parentArg.setValue(bean); } } }