List of usage examples for org.apache.commons.jxpath JXPathIntrospector getBeanInfo
public static JXPathBeanInfo getBeanInfo(Class beanClass)
From source file:jp.terasoluna.fw.beans.jxpath.BeanPointerFactoryEx.java
/** * ???/* w ww. java2 s .c o m*/ * @param name QName * @param bean ??Bean * @param locale * @return Bean? */ @Override public NodePointer createNodePointer(QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointerEx(name, bean, bi, locale); }
From source file:jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryEx.java
/** * ???/*from ww w. ja va2s. c om*/ * @param name QName * @param bean ?Map * @param locale * @return Map? */ @Override public NodePointer createNodePointer(QName name, Object bean, Locale locale) { JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils .getDynamicPropertyHandler(bi.getDynamicPropertyHandlerClass()); return new DynamicPointerEx(name, bean, handler, locale); } return null; }
From source file:jp.terasoluna.fw.beans.jxpath.BeanPointerFactoryEx.java
/** * ???/* w w w. jav a 2s.c o m*/ * @param parent ?? * @param name QName * @param bean ??Bean * @return Bean? */ @Override public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); return new BeanPointerEx(parent, name, bean, bi); }
From source file:jp.terasoluna.fw.beans.jxpath.DynamicPointerFactoryEx.java
/** * ???//w w w . j av a 2 s .com * @param parent Map? * @param name QName * @param bean ?Map * @return Map? */ @Override public NodePointer createNodePointer(NodePointer parent, QName name, Object bean) { if (bean == null) { return new NullPointer(parent, name); } JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); if (bi.isDynamic()) { DynamicPropertyHandler handler = ValueUtils .getDynamicPropertyHandler(bi.getDynamicPropertyHandlerClass()); return new DynamicPointerEx(parent, name, bean, handler); } return null; }
From source file:org.apache.cocoon.components.modules.input.JXPathHelper.java
public static Iterator getAttributeNames(JXPathHelperConfiguration setup, Object contextObj) throws ConfigurationException { if (contextObj == null) { return null; }/*from w ww . ja va 2 s . c o m*/ try { JXPathBeanInfo info = JXPathIntrospector.getBeanInfo(contextObj.getClass()); java.beans.PropertyDescriptor[] properties = info.getPropertyDescriptors(); List names = new LinkedList(); for (int i = 0; i < properties.length; i++) { names.add(properties[i].getName()); } return names.listIterator(); } catch (Exception e) { throw new ConfigurationException("Error retrieving attribute names for class: " + contextObj.getClass(), e); } }
From source file:org.apache.cocoon.el.impl.objectmodel.ObjectModelImpl.java
public void fillContext() { // Hack: I use jxpath to populate the context object's properties // in the jexl context Object contextObject = get(CONTEXTBEAN); if (contextObject == null) { //nothing to do return;//from w ww . jav a2 s .c o m } // FIXME Exception Handling final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(contextObject.getClass()); if (bi.isDynamic()) { Class cl = bi.getDynamicPropertyHandlerClass(); try { DynamicPropertyHandler h = (DynamicPropertyHandler) cl.newInstance(); String[] result = h.getPropertyNames(contextObject); int len = result.length; for (int i = 0; i < len; i++) { try { put(result[i], h.getProperty(contextObject, result[i])); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } else { PropertyDescriptor[] props = bi.getPropertyDescriptors(); int len = props.length; for (int i = 0; i < len; i++) { try { Method read = props[i].getReadMethod(); if (read != null) { put(props[i].getName(), read.invoke(contextObject, null)); } } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.apache.cocoon.environment.TemplateObjectModelHelper.java
public static void fillContext(Object contextObject, Map map) { // Hack: I use jxpath to populate the context object's properties // in the jexl context final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(contextObject.getClass()); if (bi.isDynamic()) { Class cl = bi.getDynamicPropertyHandlerClass(); try {/*from w w w .java 2 s .co m*/ DynamicPropertyHandler h = (DynamicPropertyHandler) cl.newInstance(); String[] result = h.getPropertyNames(contextObject); int len = result.length; for (int i = 0; i < len; i++) { try { map.put(result[i], h.getProperty(contextObject, result[i])); } catch (Exception exc) { exc.printStackTrace(); } } } catch (Exception ignored) { ignored.printStackTrace(); } } else { PropertyDescriptor[] props = bi.getPropertyDescriptors(); int len = props.length; for (int i = 0; i < len; i++) { try { Method read = props[i].getReadMethod(); if (read != null) { map.put(props[i].getName(), read.invoke(contextObject, null)); } } catch (Exception ignored) { ignored.printStackTrace(); } } } }
From source file:org.apache.cocoon.generation.JXTemplateGenerator.java
private void fillContext(Object contextObject, Map map) { if (contextObject != null) { // Hack: I use jxpath to populate the context object's properties // in the jexl context final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(contextObject.getClass()); if (bi.isDynamic()) { Class cl = bi.getDynamicPropertyHandlerClass(); try { DynamicPropertyHandler h = (DynamicPropertyHandler) cl.newInstance(); String[] result = h.getPropertyNames(contextObject); int len = result.length; for (int i = 0; i < len; i++) { try { map.put(result[i], h.getProperty(contextObject, result[i])); } catch (Exception exc) { exc.printStackTrace(); }/*from ww w .j a v a 2 s . c om*/ } } catch (Exception ignored) { ignored.printStackTrace(); } } else { PropertyDescriptor[] props = bi.getPropertyDescriptors(); int len = props.length; for (int i = 0; i < len; i++) { try { Method read = props[i].getReadMethod(); if (read != null) { map.put(props[i].getName(), read.invoke(contextObject, null)); } } catch (Exception ignored) { ignored.printStackTrace(); } } } } }
From source file:org.apache.cocoon.generation.VelocityGenerator.java
/** * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(SourceResolver, Map, String, Parameters) *///from ww w . j av a 2 s .c om public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) throws ProcessingException, SAXException, IOException { if (activeFlag) { throw new IllegalStateException( "setup called on recyclable sitemap component before properly recycling previous state"); } super.setup(resolver, objectModel, src, params); // Pass along the SourceResolver to the Velocity resource loader this.resolverContext.put(CONTEXT_RESOLVER_KEY, resolver); this.resolverContext.put(CONTEXT_SOURCE_CACHE_KEY, new HashMap()); // FIXME: Initialize the Velocity context. Use objectModel to pass these final Object bean = FlowHelper.getContextObject(objectModel); if (bean != null) { final WebContinuation kont = FlowHelper.getWebContinuation(objectModel); // Hack? I use JXPath to determine the properties of the bean object final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); DynamicPropertyHandler h = null; final PropertyDescriptor[] props; if (bi.isDynamic()) { Class cl = bi.getDynamicPropertyHandlerClass(); try { h = (DynamicPropertyHandler) cl.newInstance(); } catch (Exception exc) { exc.printStackTrace(); h = null; } props = null; } else { h = null; props = bi.getPropertyDescriptors(); } final DynamicPropertyHandler handler = h; this.velocityContext = new Context() { public Object put(String key, Object value) { if (key.equals("flowContext") || key.equals("continuation")) { return value; } if (handler != null) { handler.setProperty(bean, key, value); return value; } else { for (int i = 0; i < props.length; i++) { if (props[i].getName().equals(key)) { try { return props[i].getWriteMethod().invoke(bean, new Object[] { value }); } catch (Exception ignored) { break; } } } return value; } } public boolean containsKey(Object key) { if (key.equals("flowContext") || key.equals("continuation")) { return true; } if (handler != null) { String[] result = handler.getPropertyNames(bean); for (int i = 0; i < result.length; i++) { if (key.equals(result[i])) { return true; } } } else { for (int i = 0; i < props.length; i++) { if (key.equals(props[i].getName())) { return true; } } } return false; } public Object[] getKeys() { Object[] result = null; if (handler != null) { result = handler.getPropertyNames(bean); } else { result = new Object[props.length]; for (int i = 0; i < props.length; i++) { result[i] = props[i].getName(); } } Set set = new HashSet(); for (int i = 0; i < result.length; i++) { set.add(result[i]); } set.add("flowContext"); set.add("continuation"); result = new Object[set.size()]; set.toArray(result); return result; } public Object get(String key) { if (key.equals("flowContext")) { return bean; } if (key.equals("continuation")) { return kont; } if (handler != null) { return handler.getProperty(bean, key); } else { for (int i = 0; i < props.length; i++) { if (props[i].getName().equals(key)) { try { return props[i].getReadMethod().invoke(bean, null); } catch (Exception ignored) { break; } } } return null; } } public Object remove(Object key) { // not implemented return key; } }; } this.velocityContext = new ChainedContext(this.velocityContext, ObjectModelHelper.getRequest(objectModel), ObjectModelHelper.getResponse(objectModel), ObjectModelHelper.getContext(objectModel), params); this.velocityContext.put("template", src); this.activeFlag = true; }
From source file:org.eclipse.e4.emf.internal.xpath.CollectionPointer.java
@Override public boolean isLeaf() { Object value = getNode(); return value == null || JXPathIntrospector.getBeanInfo(value.getClass()).isAtomic(); }