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

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


      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


        return jcrFieldName;

    }

    private String getStringValue(String fieldName, Object value) {
      FieldDescriptor fieldDescriptor = classDescriptor.getFieldDescriptor(fieldName);
      AtomicTypeConverter atomicTypeConverter = null ;
      // if the attribute is a simple field (primitive data type or wrapper class)
      if (fieldDescriptor != null)
      {
        String fieldConverterName = fieldDescriptor.getConverter();

        // if a field converter is set in the mapping, use this one
        if ( fieldConverterName != null )
        {
          atomicTypeConverter = (AtomicTypeConverter) ReflectionUtils.newInstance(fieldConverterName);
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


  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

   * @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.getIdentifier());
View Full Code Here

      if (initializedBean == null)
      {
        return null;
      }
     
      FieldDescriptor pathField = classDescriptor.getPathFieldDescriptor();
      if (pathField != null)
      {
          ReflectionUtils.setNestedProperty(initializedBean, pathField.getFieldName(), node.getPath());
      }
     
      FieldDescriptor uuidField = classDescriptor.getUuidFieldDescriptor();
      if (uuidField != null)
      {
        ReflectionUtils.setNestedProperty(initializedBean, uuidField.getFieldName(), node.getIdentifier());
      }
     
    } catch (ValueFormatException vfe) {
      throw new ObjectContentManagerException(
          "Cannot retrieve properties of object " + object + " from node " + node, vfe);
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

                final List propertyDefinitionTemplates = ntt.getPropertyDefinitionTemplates();

                if (classDescriptor.getFieldDescriptors() != null) {
                    Iterator fieldIterator = classDescriptor.getFieldDescriptors().iterator();
                    while (fieldIterator.hasNext()) {
                        FieldDescriptor field = (FieldDescriptor) fieldIterator.next();
                        if (!field.isPath()) {
                            final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                            // add the just created pdt to the nodetypetemplate
                            propertyDefinitionTemplates.add(pdt);
                        }
                    }

                    if (classDescriptor.getBeanDescriptors() != null) {
                        Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
                        while (beanIterator.hasNext()) {
                            BeanDescriptor field = (BeanDescriptor) beanIterator.next();
                            if (this.isPropertyType(field.getJcrType())) {
                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                propertyDefinitionTemplates.add(pdt);
                            } else {
                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                nodeDefinitionTemplates.add(ndt);
                            }
                        }
                    }

                    if (classDescriptor.getCollectionDescriptors() != null) {
                        Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
                        while (collectionIterator.hasNext()) {
                            CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
                            if (this.isPropertyType(field.getJcrType())) {
                                final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
                                // add the just created pdt to the nodetypetemplate
                                propertyDefinitionTemplates.add(pdt);
                            } else {
                                final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
View Full Code Here

        pdt.setOnParentVersion(onParentVersion);
        pdt.setProtected(field.isJcrProtected());
        pdt.setQueryOrderable(true);

        if (field instanceof  FieldDescriptor) {
            FieldDescriptor f = (FieldDescriptor) field;
            if (f.getJcrDefaultValue() != null) {
                if (pdt.getRequiredType() == PropertyType.STRING) {
                    Value[] vals = {valueFactory.createValue(f.getJcrDefaultValue())};
                    pdt.setDefaultValues(vals);
                } else {
                    log.warn("Can only set default value for String properties. Skip for field '{}'", field.getJcrName());
                }
            }
            pdt.setValueConstraints(f.getJcrValueConstraints());
        }

        return pdt;
    }
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.