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

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


        return discriminatorFilter;
    }

    private String getNodeType(Filter filter) {
        ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(filter.getFilterClass());

        String jcrNodeType = classDescriptor.getJcrType();
        if (jcrNodeType == null || jcrNodeType.equals(""))
          {
           return ManagerConstant.NT_UNSTRUCTURED; 
          }
        else
View Full Code Here


                                      ManageableObjects objects) {
        if (objects == null) {
            return;
        }

        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

        Iterator collectionIterator = objects.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 = collectionDescriptor.getJcrElementName();
                if (elementJcrName == null) { // use PathFormat.checkFormat() here?
View Full Code Here

    protected void doUpdateCollection(Session session,
                                      Node parentNode,
                                      CollectionDescriptor collectionDescriptor,
                                      ManageableObjects objects) throws RepositoryException {

        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass(
                ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

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

        if (objects == null) {
            return;
        }

        Iterator collectionIterator = objects.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 = collectionDescriptor.getJcrElementName();
                if (elementJcrName == null) { // use PathFormat.checkFormat() here?
                    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

     */
    protected ManageableObjects doGetCollection(Session session,
                                                   Node parentNode,
                                                   CollectionDescriptor collectionDescriptor,
                                                   Class collectionFieldClass) throws RepositoryException {
      ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
        ManageableObjects objects = ManageableObjectsUtil.getManageableObjects(collectionFieldClass);

        NodeIterator nodes = this.getCollectionNodes(session, parentNode, elementClassDescriptor.getJcrType());

        if (nodes == null || nodes.getSize() == 0)
        {
          return null;
        }

        while (nodes.hasNext()) {
            Node itemNode = (Node) nodes.next();
            log.debug("Collection node found : " + itemNode.getPath());
            Object item = objectConverter.getObject(session,  itemNode.getPath());
            mapper.getClassDescriptorByClass(item.getClass());
            if ( objects instanceof ManageableCollection)
              ((ManageableCollection)objects).addObject(item);
            else {
              if (!elementClassDescriptor.hasIdField())
              {
                throw new JcrMappingException("Impossible to use a map for the field : "
                                          + collectionDescriptor.getFieldName()
                                          + "in the class : " + collectionDescriptor.getCollectionClassName()
                                          + ". The element objects have no id field (check their OCM mapping)");
              }
              Object elementId = ReflectionUtils.getNestedProperty(item,
                                             elementClassDescriptor.getIdFieldDescriptor().getFieldName());
                ((ManageableMap) objects).addObject(elementId, item);
            }

        }

View Full Code Here

                                              Node parentNode,
                                              CollectionDescriptor collectionDescriptor,
                                              Class collectionFieldClass) throws RepositoryException {

        String elementClassName = collectionDescriptor.getElementClassName();
        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.forName(elementClassName));
    QueryResult queryResult = getQuery(session, parentNode, elementClassDescriptor.getJcrType());
      return queryResult.getNodes().getSize() == 0;
    }
View Full Code Here

            collectionNode = parentNode.addNode(jcrName, collectionDescriptor.getJcrType());
        } else {
            collectionNode = parentNode.addNode(jcrName);
        }

        ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));

        if (objects instanceof ManageableCollection)
           insertManageableCollection(session, objects, collectionNode, elementClassDescriptor, collectionDescriptor);
        else
           insertManageableMap(session, objects, collectionNode);
View Full Code Here

      CollectionDescriptor collectionDescriptor,
      ManageableObjects objects, String jcrName)
      throws PathNotFoundException, RepositoryException,
      VersionException, LockException, ConstraintViolationException,
      ItemExistsException {
    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() && !elementClassDescriptor.hasUUIdField()) {
            String primaryNodeTypeName = collectionNode.getPrimaryNodeType().getName();
            collectionNode.remove();
            collectionNode = parentNode.addNode(jcrName, primaryNodeTypeName);
        }

        Iterator collectionIterator = objects.getIterator();

        Map updatedItems = new HashMap();
        List<String> validUuidsForTheNode = new ArrayList<String>();
        while (collectionIterator.hasNext()) {
            Object item = collectionIterator.next();
            String elementJcrName = null;
           
            if (elementClassDescriptor.hasUUIdField()){
              elementJcrName = collectionDescriptor.getJcrElementName();
              elementJcrName = (elementJcrName == null)? COLLECTION_ELEMENT_NAME : elementJcrName;
                String uuidFieldName = elementClassDescriptor.getUuidFieldDescriptor().getFieldName();
                Object objUuid = ReflectionUtils.getNestedProperty(item, uuidFieldName);
              String currentItemUuid = (objUuid == null) ? null : objUuid.toString();
              if (currentItemUuid != null){
                //The Node already exists so we need to update the existing node
                //rather than to replace it.
                Node nodeToUpdate = collectionNode.getSession().getNodeByIdentifier(currentItemUuid);
                objectConverter.update(session, currentItemUuid, item);
                validUuidsForTheNode.add(currentItemUuid);
              }
              else{
                objectConverter.insert(session, collectionNode, elementJcrName, item);
                validUuidsForTheNode.add(ReflectionUtils.getNestedProperty(item, uuidFieldName).toString());
              }
             
            }
            else 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 = collectionDescriptor.getJcrElementName();
                if (elementJcrName == null) { // use PathFormat.checkFormat() here?
                    elementJcrName = COLLECTION_ELEMENT_NAME;
                }
                objectConverter.insert(session, collectionNode, elementJcrName, item);
            }
        }

        // Delete JCR nodes that are not present in the collection
        if (elementClassDescriptor.hasUUIdField()) {
            NodeIterator nodeIterator = collectionNode.getNodes();
            List<Node> removeNodes = new ArrayList<Node>();
            while (nodeIterator.hasNext()) {
              Node currentNode = nodeIterator.nextNode();
              if (!validUuidsForTheNode.contains(currentNode.getIdentifier())) {
                    removeNodes.add(currentNode);
                }
            }
            for (Node aNode : removeNodes){
              aNode.remove();
            }
            return;
        }
       
        // 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

                  throws PathNotFoundException, RepositoryException,
                  VersionException, LockException, ConstraintViolationException,
                  ItemExistsException {
   
   
    ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
        Node collectionNode = parentNode.getNode(jcrName);

        Map map = (Map) objects.getObjects();
        Map updatedItems = new HashMap();
    for (Object key : map.keySet())
View Full Code Here

     * @return
     */
    protected List solveReferences(List errors) {
        for(Iterator it = this.mappingDescriptor.getClassDescriptorsByClassName().entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            ClassDescriptor cd = (ClassDescriptor) entry.getValue();
           
            // Check if the ancestor is a persistent class
            if (null != cd.getExtend() && !"".equals(cd.getExtend()))
            {
                ClassDescriptor superClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(cd.getExtend());

                if (null == superClassDescriptor)
                {
                  // Just a debug info because we can have a non persisted ancestor class
                  log.debug("Cannot find mapping for class "
                            + cd.getExtend()
                            + " referenced as extends from "
                            + cd.getClassName());
                 
                  // This is not necessary to keep a non persisted ancestor class
                  cd.setExtend(null);

                }
                else
                {
                  log.debug("Class " +cd.getClassName() " extends " + cd.getExtend());
                    cd.setSuperClassDescriptor(superClassDescriptor);
                }
            }
            else
            {
                   rootClassDescriptors.add(cd);
            }

            // Check if the implemented interfaces are persistent classes
            Set interfaces = cd.getImplements();
            Set mappedInterfaces  = new HashSet();
           
            if (interfaces.size() > 0)
            { 
                    for (Iterator iterator = interfaces.iterator(); iterator.hasNext();)
                    {
                      String interfaceName= (String) iterator.next();
                          ClassDescriptor interfaceClassDescriptor = this.mappingDescriptor.getClassDescriptorByName(interfaceName);

                          if (null == interfaceClassDescriptor)
                          {
                            // Just a debug info because we can have a non persisted interface reference
                            log.debug("Cannot find mapping for interface "
                                      + interfaceName
                                      + " referenced as implements from "
                                      + cd.getClassName());
                           
                          }
                          else
                          {
                              log.debug("Class " +cd.getClassName() " implements " + interfaceName);
                              interfaceClassDescriptor.addDescendantClassDescriptor(cd);
                              mappedInterfaces.add(interfaceName);
                          }
                   
                    }
                   
View Full Code Here

     * @param classDescriptors the ancestor classdescriptors
     * @return
     */
    protected List  validateDescriptors(List errors, Collection classDescriptors ) {
        for(Iterator it = classDescriptors.iterator(); it.hasNext(); ) {
            ClassDescriptor classDescriptor = (ClassDescriptor) it.next();
            try {
                classDescriptor.afterPropertiesSet();
                if (classDescriptor.hasDescendants()) {
                    errors = validateDescriptors(errors, classDescriptor.getDescendantClassDescriptors());
                }
            }
            catch(JcrMappingException jme) {
                log.warn("Mapping of class " + classDescriptor.getClassName() + " is invalid", jme);
                errors.add(jme.getMessage());
            }
        }
        return errors;
    }
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.