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


                String key = (String) keyIterator.next();
                Object object = map.get(key);
                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(MapReferenceValueEncoder.encodeKeyAndReference(key, uuid), PropertyType.STRING);
                }
            }

            parentNode.setProperty(jcrName, values);
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

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test5Class");
        classDescriptor.setJcrType("ocm:test5");
        classDescriptor.setJcrSuperTypes("ocm:test2");

        FieldDescriptor field1 = new FieldDescriptor();
        field1.setFieldName("abc");
        classDescriptor.addFieldDescriptor(field1);

        nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor);

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

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test6Class");
        classDescriptor.setJcrType("nt:test3");
        classDescriptor.setJcrSuperTypes("nt:base");

        FieldDescriptor field1 = new FieldDescriptor();
        field1.setFieldName("a");
        field1.setJcrName("a");
        field1.setJcrType("String");
        classDescriptor.addFieldDescriptor(field1);

        boolean failed = false;

        try
View Full Code Here

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

        FieldDescriptor field1 = new FieldDescriptor();
        field1.setFieldName("a");
        field1.setJcrName("ocm:a");
        field1.setJcrType("String");
        classDescriptor.addFieldDescriptor(field1);

        FieldDescriptor field2 = new FieldDescriptor();
        field2.setFieldName("b");
        field2.setJcrName("ocm:b");
        field2.setJcrType("Long");
        classDescriptor.addFieldDescriptor(field2);

        ClassDescriptor classDescriptor2 = new ClassDescriptor();
        classDescriptor2.setClassName("test.Test7Class");
        classDescriptor2.setJcrType("ocm:test7");
        classDescriptor2.setJcrSuperTypes("nt:base");

        FieldDescriptor field3 = new FieldDescriptor();
        field3.setFieldName("a");
        field3.setJcrName("ocm:a");
        field3.setJcrType("String");
        classDescriptor2.addFieldDescriptor(field3);

        FieldDescriptor field4 = new FieldDescriptor();
        field4.setFieldName("b");
        field4.setJcrName("ocm:b");
        field4.setJcrType("Long");
        classDescriptor2.addFieldDescriptor(field4);

        ClassDescriptor[] classDescriptorArray = new ClassDescriptor[2];
        classDescriptorArray[0] = classDescriptor;
        classDescriptorArray[1] = classDescriptor2;
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

      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(), "nt:unstructured");
      assertFalse(collectionDescriptor.isJcrAutoCreated());
      assertFalse(collectionDescriptor.isJcrMandatory());
      assertFalse(collectionDescriptor.isJcrProtected());
      assertFalse(collectionDescriptor.isJcrSameNameSiblings());
      assertEquals(collectionDescriptor.getJcrOnParentVersion(), "IGNORE");
     
      classDescriptor = mapper.getClassDescriptorByClass(OcmTestProperty.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

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

        FieldDescriptor field1 = new FieldDescriptor();
        field1.setFieldName("a");
        field1.setJcrName("ocm:a");
        field1.setJcrType("String");
        field1.setJcrAutoCreated(true);
        field1.setJcrMandatory(true);
        field1.setJcrMultiple(true);
        classDescriptor.addFieldDescriptor(field1);

        FieldDescriptor field2 = new FieldDescriptor();
        field2.setFieldName("b");
        field2.setJcrName("ocm:b");
        field2.setJcrType("Long");
        field1.setJcrAutoCreated(false);
        field1.setJcrMandatory(true);
        field1.setJcrMultiple(false);
        classDescriptor.addFieldDescriptor(field2);
View Full Code Here

        ClassDescriptor classDescriptor = new ClassDescriptor();
        classDescriptor.setClassName("test.Test3Class");
        classDescriptor.setJcrType("test3");
        classDescriptor.setJcrSuperTypes("nt:base");

        FieldDescriptor field1 = new FieldDescriptor();
        field1.setFieldName("a");
        field1.setJcrName("a");
        field1.setJcrType("String");
        classDescriptor.addFieldDescriptor(field1);

        nodeTypeManagerImpl.createSingleNodeType(getSession(), classDescriptor);

        NodeType test3 = getSession().getWorkspace().getNodeTypeManager().getNodeType("test3");
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.