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

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


        assertTrue(containsPropertyDefintion(test1.getPropertyDefinitions(), "ocm:testProperty"));
    }
   
    public void testCreateSingleNodeType() throws Exception
    {
        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);       

        getJackrabbitNodeTypeManagerImpl().createSingleNodeType(session, classDescriptor);
       
        NodeType testNodeType = session.getWorkspace().getNodeTypeManager().getNodeType("ocm:test2");
        assertNotNull(testNodeType);
View Full Code Here


        // TODO test all properties
    }
   
    public void testCreateSingleNodeTypeNoNamespace() throws Exception
    {
        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);

        getJackrabbitNodeTypeManagerImpl().createSingleNodeType(session, classDescriptor);
       
        NodeType test3 = session.getWorkspace().getNodeTypeManager().getNodeType("test3");
        assertNotNull(test3);
View Full Code Here

            Iterator collectionIterator = collection.getIterator();
            for (int i = 0; i < collection.getSize(); i++) {
                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);
        }
View Full Code Here

    }
  }

  public void retrieveMappedAttribute(Session session, Object object, String attributeName) {
    String path = null;
    ClassDescriptor classDescriptor = null;
    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
      else
      {
        CollectionDescriptor collectionDescriptor = classDescriptor.getCollectionDescriptor(attributeName);
        if (collectionDescriptor != null)
        {
          this.retrieveCollectionField(session, collectionDescriptor, node, object, true);
        }
        else
        {
          throw new ObjectContentManagerException("Impossible to retrieve the mapped attribute. The attribute '" +
                                                                       attributeName + "'  is not a bean or a collection for the class : " + classDescriptor.getClassName());
        }
      }

    } catch (PathNotFoundException pnfe) {
View Full Code Here

   * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#getPath(javax.jcr.Session,
   *      java.lang.Object)
   * @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 " +
View Full Code Here

    }

  }

  private ClassDescriptor getClassDescriptor(Class beanClass) {
    ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(beanClass);
    if (null == classDescriptor) {
      throw new JcrMappingException("Class of type: " + beanClass.getName()
          + " is not JCR persistable. Maybe element 'class-descriptor' for this type in mapping file is missing");
    }
View Full Code Here

                    + collectionDescriptor.getFieldName() + " for the classdescriptor : " + collectionDescriptor.getClassDescriptor().getClassName());
        }

        Node collectionNode = parentNode.addNode(jcrName);
       
        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

        Iterator collectionIterator = collection.getIterator();       
        while (collectionIterator.hasNext()) {
            Object item = collectionIterator.next();
            String elementJcrName = null;

            // If the element object has a unique id => the element jcr node name = the id value
            if (elementClassDescriptor.hasIdField()) {
                String idFieldName = elementClassDescriptor.getIdFieldDescriptor()
                                                           .getFieldName();
                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
            }
            else {               
                elementJcrName = COLLECTION_ELEMENT_NAME;
View Full Code Here

        return;
      }
       
      // update process
     
        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));        
        Node collectionNode = parentNode.getNode(jcrName);
        //  If the collection elements have not an id, it is not possible to find the matching JCR nodes => delete the complete collection
        if (!elementClassDescriptor.hasIdField()) {
            collectionNode.remove();
            collectionNode = parentNode.addNode(jcrName);
        }

        Iterator collectionIterator = collection.getIterator();

        Map updatedItems = new HashMap();
        while (collectionIterator.hasNext()) {
            Object item = collectionIterator.next();

            String elementJcrName = null;

            if (elementClassDescriptor.hasIdField()) {

                String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();

                // Update existing JCR Nodes
                if (collectionNode.hasNode(elementJcrName)) {
                    objectConverter.update(session, collectionNode, elementJcrName, item);
                }
                else {
                    // Add new collection elements
                    objectConverter.insert(session, collectionNode, elementJcrName, item);
                }

                updatedItems.put(elementJcrName, item);
            }
            else {
                elementJcrName = COLLECTION_ELEMENT_NAME ;
                objectConverter.insert(session, collectionNode, elementJcrName, item);
            }
        }

        // Delete JCR nodes that are not present in the collection
        if (elementClassDescriptor.hasIdField()) {
            NodeIterator nodeIterator = collectionNode.getNodes();
            List removeNodes = new ArrayList();
            while (nodeIterator.hasNext()) {
                Node child = nodeIterator.nextNode();
                if (!updatedItems.containsKey(child.getName())) {
View Full Code Here

                                      ManageableCollection collection) {
        if (collection == null) {
            return;
        }
       
        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

        Iterator collectionIterator = collection.getIterator();       
        while (collectionIterator.hasNext()) {
            Object item = collectionIterator.next();
            String elementJcrName = null;

            // If the element object has a unique id => the element jcr node name = the id value
            if (elementClassDescriptor.hasIdField()) {
                String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();
            }
            else {               
                elementJcrName = COLLECTION_ELEMENT_NAME;
            }
View Full Code Here

    protected void doUpdateCollection(Session session,
                                      Node parentNode,
                                      CollectionDescriptor collectionDescriptor,
                                      ManageableCollection collection) throws RepositoryException {
       
        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass(
                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

        if (collection == null || !elementClassDescriptor.hasIdField()) {
            this.deleteCollectionItems(session,
                                       parentNode,
                                       elementClassDescriptor.getJcrType());
        }

        if (collection == null) {
            return;
        }

        Iterator collectionIterator = collection.getIterator();
        Map updatedItems = new HashMap();
        while (collectionIterator.hasNext()) {
            Object item = collectionIterator.next();
       
            String elementJcrName = null;

            if (elementClassDescriptor.hasIdField()) {
                String idFieldName = elementClassDescriptor.getIdFieldDescriptor().getFieldName();
                elementJcrName = ReflectionUtils.getNestedProperty(item, idFieldName).toString();

                // Update existing JCR Nodes
                if (parentNode.hasNode(elementJcrName)) {
                    objectConverter.update(session, parentNode, elementJcrName, item);
                }
                else {
                    // Add new collection elements
                    objectConverter.insert(session, parentNode, elementJcrName, item);
                }

                updatedItems.put(elementJcrName, item);
            }
            else {
                elementJcrName = COLLECTION_ELEMENT_NAME;
                objectConverter.insert(session, parentNode, elementJcrName, item);
            }
        }

        // Delete JCR nodes that are not present in the collection
         NodeIterator nodes = this.getCollectionNodes(session, parentNode,
                                                          elementClassDescriptor.getJcrType());
         if (nodes != null && elementClassDescriptor.hasIdField()) {
           

            while (nodes.hasNext()) {
                Node child = (Node) nodes.next();
               
View Full Code Here

TOP

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

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.