On Tue, Nov 17, 2009 at 1:10 PM, Rakesh Vidyadharan <[email protected]> wrote: > > On 17 Nov 2009, at 5:32:13 AM, Ard Schrijvers wrote: >> I do not agree, and fortunately, mapping jcr nodes to simple java >> objects which again can be accessed from jsp / freemarker / velocity >> scripts feels much more natural to me, is quite easy: I do not want to >> burden other developers with handling all the jcr stuff, catching all >> the exceptions, handling defaults, writing complex queries (do you >> really like to write search queries? It is part of the JCR API, but I >> am glad I went through all that once, and made a simple java interface >> for it (similar to jr-ocm, only targeted for large repositories >> avoiding slow queries, and supporting more website convenient >> searches, like multiple scoped kind of queries). > > I am using > http://kenai.com/projects/jcrcms/sources/svn/content/trunk/src/app/com/sptci/cms/site/model/NodeBean.java?rev=17 > - a simple generic map wrapper around a node that can be used for tempting > systems easily. Not final yet, but it works.
I would recommend to add some ObjectConverter capable of mapping primary nodetypes to certain beans. Then, your NodeBean could be something like the base fallback bean. With generics you can then add methods to your base bean like below. You could take a look at [1]. Regards Ard [1] http://svn.hippocms.org/repos/hippo/ecm/site-toolkit/trunk/content-beans/src/main/java/org/hippoecm/hst/content/beans/ public <T> T getBean(String relPath, Class<T> beanMappingClass) { try { Object o = this.objectConverter.getObject(node, relPath); if(o == null) { log.debug("Cannot get bean for relpath {} for current bean {}.", relPath, this.getPath()); return null; } if(!beanMappingClass.isAssignableFrom(o.getClass())) { log.debug("Expected bean of type '{}' but found of type '{}'. Return null.", beanMappingClass.getName(), o.getClass().getName()); return null; } return (T)o; } catch (ObjectBeanManagerException e) { log.warn("Cannot get Object at relPath '{}' for '{}'", relPath, this.getPath()); } return null; } > > Rakesh
