Alex:

Please help me understand your code for ObjectConvertImpl#insertBeanFields, posted below with an added comment.

It is confusing that on the 2nd branch you insert object but on the third branch you insert bean.

Why, when a bean has a converter, do you use that converter (apparently) to insert the *object* itself as the bean field?

If I change *your* code so that it inserts the bean using my bean converter, then I will get the behavior I want. Rf course, that does invoke *my* code. If I have this wrong, please post some code for a (default) BeanConverterImpl that I can put into my bean mapping. I want this beanConverter to give me the same result as I not named a beanConverter class at all for this bean. That is what I attempted to do in my TestBeanConverterImpl, but maybe I got it wrong.

        //**
         * Insert Bean fields
         *//
        *private* *void* insertBeanFields(Session session, Object object, 
ClassDescriptor classDescriptor, Node objectNode) {
                Iterator beanDescriptorIterator = 
classDescriptor.getBeanDescriptors().iterator();
                *while* (beanDescriptorIterator.hasNext()) {
                        BeanDescriptor beanDescriptor = (BeanDescriptor) 
beanDescriptorIterator.next();

                        *if* (!beanDescriptor.isAutoInsert()) {
                                *continue*;
                        }

                        String jcrName = beanDescriptor.getJcrName();
                        Object bean = ReflectionUtils.getNestedProperty(object, 
beanDescriptor.getFieldName());
                        *if* (bean != *null*) {
                                *if* (beanDescriptor.isInline()) {
                                        *this*.storeSimpleFields(session, bean, 
mapper.getClassDescriptorByClass(bean.getClass()), objectNode);
                                } *else* *if* (*null* != beanDescriptor.getConverter() && 
!*""*.equals(beanDescriptor.getConverter())) {
                                        String converterClassName = 
beanDescriptor.getConverter();
                                        Object[] param = {*this*};
                                        BeanConverter beanConverter = 
(BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
                                        beanConverter.insert(session, 
objectNode, beanDescriptor, object);  // confusing (?) appears to insert the 
object
                                } *else* {
                                        *this*.insert(session, objectNode, 
jcrName, bean);
                                }
                        }
                }
        }


      -- Dan


Alexandru Popescu wrote:

I may miss something but: your bean converter just delegates back to
the same default object converter with the initial object value so I
guess it is normal that when reaching again the

<bean-descriptor fieldName="author" jcrName="author" proxy="true"
converter="org.eclipse.emf.teneo.graffito.emf.TestBeanConverterImpl" />

than it will invoke yours again and so on. I would say that your code
is creating the infinite recursion. Probably you would like to invoke
the default converter with a property retreived from the object and
not once again with the full object.

./alex
--
.w( the_mindstorm )p.


On 9/8/06, Dan Connelly <[EMAIL PROTECTED]> wrote:

Alexandru Popescu wrote:

>
> Dan can you show us your code pls? It would be much easier to
> understand the issue.
>
> TIA,
>
> ./alex

Alex:

I believe that my code is irrelevant to this bug, but correct me if I am
wrong.

My TestBeanConverterImp source is attached.   Only the insert method is
being used for this test.

The significant metadata is here:

    <class-descriptor
        className="org.eclipse.example.library.impl.BookImpl"
            extend="org.eclipse.emf.ecore.EObject"
        jcrNodeType="graffito:eobject">
        <implement-descriptor
interfaceName="org.eclipse.example.library.Book"/>
        <field-descriptor fieldName="title"  jcrName="title" path="true"
id="true" />
        <field-descriptor fieldName="pages"  jcrName="pages" />
<bean-descriptor fieldName="author" jcrName="author" proxy="true"

converter="org.eclipse.emf.teneo.graffito.emf.TestBeanConverterImpl" />
        <bean-descriptor fieldName="category"  jcrName="category"
inline="true"
        />
    </class-descriptor>

  <nodeType name="graffito:eobject" isMixin="false">
    <supertypes>
      <supertype>mix:referenceable</supertype>
      <supertype>nt:unstructured</supertype>
    </supertypes>
  </nodeType>


A fragment of the console output is as follows:

Object Class = org.eclipse.example.library.impl.BookImpl object =
[EMAIL PROTECTED] (title: The Hobbit,
pages: 305, category: ScienceFiction)
Parent Node name = author
Parent Node path = /Library1/Books/The
Hobbit/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author/author
Interface name: org.eclipse.example.library.Book

       -- Dan


package org.eclipse.emf.teneo.graffito.emf;

import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.UnsupportedRepositoryOperationException;

import org.apache.portals.graffito.jcr.exception.JcrMappingException;
import org.apache.portals.graffito.jcr.exception.PersistenceException;
import org.apache.portals.graffito.jcr.exception.RepositoryException;
import org.apache.portals.graffito.jcr.mapper.model.BeanDescriptor;
import org.apache.portals.graffito.jcr.persistence.objectconverter.BeanConverter; import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter; import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.AbstractBeanConverterImpl; import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.ParentBeanConverterImpl; import org.apache.portals.graffito.jcr.persistence.objectconverter.impl.Reference;
import org.eclipse.emf.ecore.EObject;

public class TestBeanConverterImpl extends AbstractBeanConverterImpl implements BeanConverter {

        private ObjectConverter objectConverter;

        public TestBeanConverterImpl(ObjectConverter objectConverter)
        {
                super(objectConverter);
                this.objectConverter = objectConverter;
        }

        @Override
        public Object getObject(Session session, Node parentNode,
                        BeanDescriptor descriptor, Class beanClass)
throws PersistenceException, RepositoryException,
                        JcrMappingException {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public void insert(Session session, Node parentNode,
                        BeanDescriptor descriptor, Object object)
throws PersistenceException, RepositoryException,
                        JcrMappingException {

                Class objectClass = object.getClass();
System.out.println("Object Class = "+objectClass.getName() +" object = "+object.toString());
                try {
System.out.println("Parent Node name = "+parentNode.getName()); System.out.println("Parent Node path = "+parentNode.getPath());
                } catch (javax.jcr.RepositoryException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                }
objectConverter.insert(session, parentNode, descriptor.getJcrName(), object);

        }

        @Override
        public void remove(Session session, Node parentNode,
BeanDescriptor descriptor) throws PersistenceException,
                        RepositoryException, JcrMappingException {
                // TODO Auto-generated method stub

        }

        @Override
        public void update(Session session, Node parentNode,
                        BeanDescriptor descriptor, Object object)
throws PersistenceException, RepositoryException,
                        JcrMappingException {
                // TODO Auto-generated method stub
objectConverter.update(session, parentNode, descriptor.getJcrName(), object);
        }

}





Reply via email to