Package org.apache.jackrabbit.ocm.mapper.model

Examples of org.apache.jackrabbit.ocm.mapper.model.BeanDescriptor


    try {
      classDescriptor = getClassDescriptor(object.getClass());
      String pathFieldName = classDescriptor.getPathFieldDescriptor().getFieldName();
      path = (String) ReflectionUtils.getNestedProperty(object, pathFieldName);
      Node node = (Node) session.getItem(path);
      BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor(attributeName);
      if (beanDescriptor != null)
      {
        this.retrieveBeanField(session, beanDescriptor, node, path, object, true);
      }
      // Check if the attribute is a collection
View Full Code Here


   */
  private void retrieveBeanFields(Session session, ClassDescriptor classDescriptor, Node node, String path, Object object,
      boolean forceToRetrieve) {
    Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
    while (beanDescriptorIterator.hasNext()) {
      BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
      this.retrieveBeanField(session, beanDescriptor, node, path, object, forceToRetrieve);
    }
  }
View Full Code Here

   * 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)
      {
        String converterClassName = null;

        if (null == beanDescriptor.getConverter() || "".equals(beanDescriptor.getConverter()))
        {
          converterClassName = DEFAULT_BEAN_CONVERTER;
        }
        else
        {
          converterClassName = beanDescriptor.getConverter();
        }

        Object[] param = {this.mapper, this, this.atomicTypeConverterProvider};
        BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
        beanConverter.insert(session, objectNode, beanDescriptor, mapper.getClassDescriptorByClass(bean.getClass()), bean, classDescriptor, object);
View Full Code Here

  private void updateBeanFields(Session session, Object object, ClassDescriptor classDescriptor, Node objectNode) {
    String jcrName = null;
    Iterator beanDescriptorIterator = classDescriptor.getBeanDescriptors().iterator();
    while (beanDescriptorIterator.hasNext())
    {
      BeanDescriptor beanDescriptor = (BeanDescriptor) beanDescriptorIterator.next();
      if (!beanDescriptor.isAutoUpdate()) {
        continue;
      }

      jcrName = beanDescriptor.getJcrName();
      Object bean = ReflectionUtils.getNestedProperty(object, beanDescriptor.getFieldName());

      String converterClassName = null;
      if (null == beanDescriptor.getConverter() || "".equals(beanDescriptor.getConverter()))
      {
        converterClassName = DEFAULT_BEAN_CONVERTER;
      }
      else
      {
        converterClassName = beanDescriptor.getConverter();
      }

      Object[] param = {this.mapper, this, this.atomicTypeConverterProvider };
      BeanConverter beanConverter = (BeanConverter) ReflectionUtils.invokeConstructor(converterClassName, param);
      Class beanClass = ReflectionUtils.getPropertyType(object, beanDescriptor.getFieldName());
      // if the bean is null, remove existing node
      if ((bean == null))
      {

        beanConverter.remove(session, objectNode, beanDescriptor, mapper.getClassDescriptorByClass(beanClass), bean, classDescriptor, object);
View Full Code Here

            }
    }
  }

  private void addBeanDescriptor(ClassDescriptor classDescriptor, String fieldName, Bean beanAnnotation) {
    BeanDescriptor beanDescriptor = new BeanDescriptor();
    beanDescriptor.setFieldName(fieldName);
    if (beanAnnotation.jcrName() != null && ! beanAnnotation.jcrName().equals(""))
    {
       beanDescriptor.setJcrName(beanAnnotation.jcrName());
    }
    else
    {
      beanDescriptor.setJcrName(fieldName);
    }

    beanDescriptor.setProxy(beanAnnotation.proxy());
    beanDescriptor.setConverter(beanAnnotation.converter().getName());
    beanDescriptor.setAutoInsert(beanAnnotation.autoInsert());
    beanDescriptor.setAutoRetrieve(beanAnnotation.autoRetrieve());
    beanDescriptor.setAutoUpdate(beanAnnotation.autoUpdate());
    beanDescriptor.setJcrType(beanAnnotation.jcrType());
    beanDescriptor.setJcrAutoCreated(beanAnnotation.jcrAutoCreated());
    beanDescriptor.setJcrMandatory(beanAnnotation.jcrMandatory());
    beanDescriptor.setJcrOnParentVersion(beanAnnotation.jcrOnParentVersion());
    beanDescriptor.setJcrProtected(beanAnnotation.jcrProtected());
    beanDescriptor.setJcrSameNameSiblings(beanAnnotation.jcrSameNameSiblings());

    classDescriptor.addBeanDescriptor(beanDescriptor);
  }
View Full Code Here

      FieldDescriptor fieldDescriptor = classDescriptor  .getFieldDescriptor("a1");
      assertNotNull("FieldDescriptor is null", fieldDescriptor);
      assertTrue("Invalid jcrName for field a1", fieldDescriptor.getJcrName().equals("a1"));

      BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor("b");
      assertNotNull("BeanDescriptor is null", beanDescriptor);
      assertTrue("Invalid jcrName for field b", beanDescriptor  .getJcrName().equals("b"));     
      assertNotNull("Invalid bean default converter", beanDescriptor.getConverter());
     

      CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor("collection");
      assertNotNull("CollectionDescriptor is null", collectionDescriptor);
      assertTrue("Invalid jcrName for field collection",collectionDescriptor.getJcrName().equals("collection"));
View Full Code Here

          .getClassDescriptorByClass(A.class);
      assertNotNull("ClassDescriptor is null", classDescriptor2);
      assertTrue("Invalid classname", classDescriptor2.getClassName()
          .equals(A.class.getName()));

      BeanDescriptor beanDescriptor = classDescriptor2
          .getBeanDescriptor("b");
      assertNotNull(beanDescriptor);
      assertEquals(beanDescriptor.getFieldName(), "b");
      assertEquals(beanDescriptor.getJcrType(), "nt:unstructured");
      assertFalse(beanDescriptor.isJcrAutoCreated());
      assertFalse(beanDescriptor.isJcrMandatory());
      assertFalse(beanDescriptor.isJcrProtected());
      assertFalse(beanDescriptor.isJcrSameNameSiblings());
      assertEquals(beanDescriptor.getJcrOnParentVersion(), "IGNORE");

      CollectionDescriptor collectionDescriptor = classDescriptor2
          .getCollectionDescriptor("collection");
      assertNotNull(collectionDescriptor);
      assertEquals(collectionDescriptor.getJcrType(), "nt:unstructured");
View Full Code Here

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test10Class");
        classDescriptor.setJcrType("ocm:test10");
        classDescriptor.setJcrSuperTypes("nt:base");

        BeanDescriptor bean1 = new BeanDescriptor();
        bean1.setFieldName("a");
        bean1.setJcrName("a");
        bean1.setJcrType("String");
        classDescriptor.addBeanDescriptor(bean1);

        nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor);

        NodeType test10 = getSession().getWorkspace().getNodeTypeManager().getNodeType("ocm:test10");
View Full Code Here

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test14Class");
        classDescriptor.setJcrType("ocm:test14");
        classDescriptor.setJcrSuperTypes("nt:base");

        BeanDescriptor bean1 = new BeanDescriptor();
        bean1.setFieldName("a");
        bean1.setJcrName("a");
        bean1.setJcrType("String");
        classDescriptor.addBeanDescriptor(bean1);

        nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor);

        NodeType test14 = getSession().getWorkspace().getNodeTypeManager().getNodeType("ocm:test14");
View Full Code Here

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test12Class");
        classDescriptor.setJcrType("ocm:test12");
        classDescriptor.setJcrSuperTypes("nt:base");

        BeanDescriptor bean1 = new BeanDescriptor();
        bean1.setFieldName("a");
        bean1.setJcrName("b");
        bean1.setJcrType("nt:unstructured");
        classDescriptor.addBeanDescriptor(bean1);

        nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor);

        NodeType test12 = getSession().getWorkspace().getNodeTypeManager().getNodeType("ocm:test12");
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.ocm.mapper.model.BeanDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.