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

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


                Object object = collectionIterator.next();
        if (object != null)
        {
          ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(object.getClass());

          FieldDescriptor fieldDescriptor = classDescriptor.getUuidFieldDescriptor();
          if (fieldDescriptor == null)
          {
            throw new JcrMappingException("The bean doesn't have an uuid - classdescriptor : "
                                  + classDescriptor.getClassName());
          }

          String uuid = (String) ReflectionUtils.getNestedProperty(object, fieldDescriptor.getFieldName());
          values[i] = valueFactory.createValue(uuid, PropertyType.REFERENCE);
        }
            }

            parentNode.setProperty(jcrName, values);
View Full Code Here


                if (classDescriptor.getFieldDescriptors() != null)
                {
                    Iterator fieldIterator = classDescriptor.getFieldDescriptors().iterator();
                    while (fieldIterator.hasNext())
                    {
                        FieldDescriptor field = (FieldDescriptor) fieldIterator.next();
                        if (!field.isPath()) {
                            propDefs.add(getPropertyDefinition(field.getFieldName(), field, nodeTypeDef.getName()));
                        }
                    }
                }

                if (classDescriptor.getBeanDescriptors() != null) {
                    Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
                    while (beanIterator.hasNext()) {
                        BeanDescriptor field = (BeanDescriptor) beanIterator.next();
                        if (this.isPropertyType(field.getJcrType())) {
                            propDefs.add(getPropertyDefinition(field.getFieldName(), field, nodeTypeDef.getName()));
                        } else {
                            nodeDefs.add(getNodeDefinition(field.getFieldName(), field, nodeTypeDef.getName()));
                        }
                    }
                }
               
                if (classDescriptor.getCollectionDescriptors() != null) {
                    Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
                    while (collectionIterator.hasNext()) {
                        CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
                        if (this.isPropertyType(field.getJcrType())) {
                            propDefs.add(getPropertyDefinition(field.getFieldName(), field, nodeTypeDef.getName()));
                        } else {
                            nodeDefs.add(getNodeDefinition(field.getFieldName(), field, nodeTypeDef.getName()));
                        }
                    }
                }

                nodeTypeDef.setPropertyDefs((PropDef[]) propDefs.toArray(new PropDef[propDefs.size()]));
View Full Code Here

      if (object == null)
      {
        parentNode.setProperty(beanDescriptor.getJcrName(), (Value) null);
      }
     
      FieldDescriptor fieldDescriptor = beanClassDescriptor.getUuidFieldDescriptor();
      if (fieldDescriptor == null)
      {
        throw new JcrMappingException("The bean doesn't have an uuid - classdescriptor : " + beanClassDescriptor.getClassName());
      }
     
      String uuid = (String) ReflectionUtils.getNestedProperty(object, fieldDescriptor.getFieldName());
      parentNode.setProperty(beanDescriptor.getJcrName(), uuid, PropertyType.REFERENCE);
    } catch (Exception e) {
      throw new ObjectContentManagerException("Impossible to insert the bean attribute into the repository", e);
    }
  }
View Full Code Here

   * @throws JcrMappingException
   */
  public String getPath(Session session, Object object) {
    ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(object.getClass());

    final FieldDescriptor pathFieldDescriptor = classDescriptor.getPathFieldDescriptor();
    if (pathFieldDescriptor == null) {
      throw new JcrMappingException(
          "Class of type: "
              + object.getClass().getName()
              + " has no path mapping. Maybe attribute path=\"true\" for a field element of this class in mapping descriptor is missing " +
                " or maybe it is defined in an ancestor class which has no mapping descriptor.");
    }
    String pathField = pathFieldDescriptor.getFieldName();

    return (String) ReflectionUtils.getNestedProperty(object, pathField);
  }
View Full Code Here

              + classDescriptor.getClassName()
              + "' has not a discriminator property.");
        }
      }     
      while (fieldDescriptorIterator.hasNext()) {
        FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();

        String fieldName = fieldDescriptor.getFieldName();
        String propertyName = fieldDescriptor.getJcrName();

        if (fieldDescriptor.isPath()) {
          // HINT: lazy initialize target bean - The bean can be null
          // when it is inline
          if (null == initializedBean) {
            initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
          }

          ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getPath());

        } else {
          if (fieldDescriptor.isUuid()) {
            if (null == initializedBean) {
              initializedBean = ReflectionUtils.newInstance(classDescriptor.getClassName());
            }

            ReflectionUtils.setNestedProperty(initializedBean, fieldName, node.getUUID());
View Full Code Here

    try {
      ValueFactory valueFactory = session.getValueFactory();

      Iterator fieldDescriptorIterator = classDescriptor.getFieldDescriptors().iterator();
      while (fieldDescriptorIterator.hasNext()) {
        FieldDescriptor fieldDescriptor = (FieldDescriptor) fieldDescriptorIterator.next();

        String fieldName = fieldDescriptor.getFieldName();
        String jcrName = fieldDescriptor.getJcrName();

        // Of course, Path && UUID fields are not stored as property
        if (fieldDescriptor.isPath() || fieldDescriptor.isUuid()) {
          continue;
        }

        storeSimpleField(object, objectNode, valueFactory, fieldDescriptor, fieldName, jcrName);
      }
View Full Code Here


  private void addFieldDescriptor(ClassDescriptor classDescriptor, String fieldName, Field fieldAnnotation)
  {
       
    FieldDescriptor fieldDescriptor = new FieldDescriptor();       
    fieldDescriptor.setFieldName(fieldName);
    if ((fieldAnnotation.jcrName() != null) && (!fieldAnnotation.jcrName().equals("")))
    {
      fieldDescriptor.setJcrName(fieldAnnotation.jcrName())
    }
    else
    {
      fieldDescriptor.setJcrName(fieldName)
    }
    fieldDescriptor.setId(fieldAnnotation.id());       
    fieldDescriptor.setPath(fieldAnnotation.path());
    fieldDescriptor.setUuid(fieldAnnotation.uuid());
   
    // It is not possible to set a null value into an annotation attribute.
    // If the converter == Object.class, it should be considered as null
    if (! fieldAnnotation.converter().equals(Object.class))
    {
        fieldDescriptor.setConverter(fieldAnnotation.converter().getName());
    }
   
    // It is not possible to set a null value into an annotation attribute.
    // If the jcrDefaultValue value is an empty string => it should be considered as null
    if ((fieldAnnotation.jcrDefaultValue() != null) && (!fieldAnnotation.jcrDefaultValue().equals("")))
    {
         fieldDescriptor.setJcrDefaultValue(fieldAnnotation.jcrDefaultValue());
    }
   
    // It is not possible to set a null value into an annotation attribute.
    // If the jcrValueConstraints value is an empty string => it should be considered as null
    if ((fieldAnnotation.jcrValueConstraints() != null) && (!fieldAnnotation.jcrValueConstraints().equals("")))
    { 
         fieldDescriptor.setJcrValueConstraints(fieldAnnotation.jcrValueConstraints());
    }
   
    // It is not possible to set a null value into an annotation attribute.
    // If the jcrProperty value is an empty string => it should be considered as null
    if ((fieldAnnotation.jcrType() != null) && (!fieldAnnotation.jcrType().equals("")))
    {
        fieldDescriptor.setJcrType(fieldAnnotation.jcrType());
    }
   
    fieldDescriptor.setJcrAutoCreated(fieldAnnotation.jcrAutoCreated());
    fieldDescriptor.setJcrMandatory(fieldAnnotation.jcrMandatory());
    fieldDescriptor.setJcrOnParentVersion(fieldAnnotation.jcrOnParentVersion());
    fieldDescriptor.setJcrProtected(fieldAnnotation.jcrProtected());
    fieldDescriptor.setJcrMultiple(fieldAnnotation.jcrMultiple());
   
    //fieldDescriptor.setJcrType(value)
    classDescriptor.addFieldDescriptor(fieldDescriptor);
  }   
View Full Code Here

      assertNotNull("ClassDescriptor is null", classDescriptor);
      assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
      assertTrue("Invalid path field", classDescriptor.getPathFieldDescriptor().getFieldName().equals("path"));
      assertEquals("Invalid mixins", "mix:lockable", classDescriptor.getJcrMixinTypes()[0]);

      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());
View Full Code Here

      assertNotNull("ClassDescriptor is null", classDescriptor);
      assertTrue("Invalid classname", classDescriptor.getClassName()
          .equals(B.class.getName()));
      assertEquals(classDescriptor.getJcrSuperTypes(), "nt:base");

      FieldDescriptor b1Field = classDescriptor.getFieldDescriptor("b1");
      assertNotNull("FieldDescriptor is null", b1Field);
      assertEquals(b1Field.getFieldName(), "b1");
      assertEquals(b1Field.getJcrType(), "String");
      assertFalse(b1Field.isJcrAutoCreated());
      assertFalse(b1Field.isJcrMandatory());
      assertFalse(b1Field.isJcrProtected());
      assertFalse(b1Field.isJcrMultiple());
      assertEquals(b1Field.getJcrOnParentVersion(), "IGNORE");

      FieldDescriptor b2Field = classDescriptor.getFieldDescriptor("b2");
      assertNotNull("FieldDescriptor is null", b2Field);
      assertEquals(b2Field.getFieldName(), "b2");
      assertEquals(b2Field.getJcrType(), "String");
      assertFalse(b2Field.isJcrAutoCreated());
      assertFalse(b2Field.isJcrMandatory());
      assertFalse(b2Field.isJcrProtected());
      assertFalse(b2Field.isJcrMultiple());
      assertEquals(b2Field.getJcrOnParentVersion(), "IGNORE");

      ClassDescriptor classDescriptor2 = mapper
          .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(), "ocm:C");
      assertFalse(collectionDescriptor.isJcrAutoCreated());
      assertFalse(collectionDescriptor.isJcrMandatory());
      assertFalse(collectionDescriptor.isJcrProtected());
      assertFalse(collectionDescriptor.isJcrSameNameSiblings());
      assertEquals(collectionDescriptor.getJcrOnParentVersion(), "IGNORE");
     
      classDescriptor = mapper.getClassDescriptorByClass(PropertyTest.class);
      assertNotNull(classDescriptor);
      FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor("requiredWithConstraintsProp");
      assertNotNull(fieldDescriptor.getJcrValueConstraints());
      assertTrue("Invalid constaint", fieldDescriptor.getJcrValueConstraints()[0].equals("abc") );
      assertTrue("Invalid constaint", fieldDescriptor.getJcrValueConstraints()[1].equals("def") );
      assertTrue("Invalid constaint", fieldDescriptor.getJcrValueConstraints()[2].equals("ghi") );
     
      fieldDescriptor = classDescriptor.getFieldDescriptor("autoCreatedProp");
      assertNotNull(fieldDescriptor.getJcrDefaultValue());
      assertTrue("Invalid default value", fieldDescriptor.getJcrDefaultValue().equals("aaa") );
     
    } catch (JcrMappingException e) {
      e.printStackTrace();
      fail("Impossible to retrieve the converter " + e);
    }
View Full Code Here

      assertNotNull("ClassDescriptor is null", classDescriptor);
      assertTrue("Invalid classname", classDescriptor.getClassName().equals(A.class.getName()));
      assertTrue("Invalid path field", classDescriptor.getPathFieldDescriptor().getFieldName().equals("path"));
      assertEquals("Invalid mixins", "mixin:a", classDescriptor.getJcrMixinTypes()[0]);

      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());
View Full Code Here

TOP

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

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.