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

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


    /**
    *
    * @see org.apache.jackrabbit.ocm.mapper.Mapper#getClassDescriptorByClass(java.lang.Class)
    */
   public ClassDescriptor getClassDescriptorByClass(Class clazz) {
     ClassDescriptor descriptor = mappingDescriptor.getClassDescriptorByName(clazz.getName());
     if (descriptor==null) {
      throw new IncorrectPersistentClassException("Class of type: " + clazz.getName() + " has no descriptor.");
     }
       return descriptor ;
   }
View Full Code Here


   /**
   * @see org.apache.jackrabbit.ocm.mapper.Mapper#getClassDescriptorByNodeType(String)
   */
  public ClassDescriptor getClassDescriptorByNodeType(String jcrNodeType) {
    ClassDescriptor descriptor = mappingDescriptor.getClassDescriptorByNodeType(jcrNodeType);
     if (descriptor==null) {
      throw new IncorrectPersistentClassException("Node type: " + jcrNodeType + " has no descriptor.");
     }
      return descriptor ;
  }
View Full Code Here

    public MappingDescriptor loadClassDescriptors()
  {
    MappingDescriptor mappingDescriptor = new MappingDescriptor();
    for (Class clazz : annotatedClassNames) {

      ClassDescriptor classDescriptor = buildClassDescriptor(mappingDescriptor, clazz);
      mappingDescriptor.addClassDescriptor(classDescriptor);
    }
    return mappingDescriptor;

  }
View Full Code Here

  }

  private ClassDescriptor buildClassDescriptor(MappingDescriptor mappingDescriptor, Class clazz)
  {
    ClassDescriptor classDescriptor = null;

    Node nodeAnnotation =  (Node) clazz.getAnnotation(Node.class);
    if (nodeAnnotation != null)
    {
      classDescriptor = createClassDescriptor(clazz, nodeAnnotation);
View Full Code Here

  }

  private ClassDescriptor createClassDescriptor(Class clazz, Node nodeAnnotation)
  {
    ClassDescriptor classDescriptor = new ClassDescriptor();
    classDescriptor.setClassName(clazz.getName());
    classDescriptor.setJcrType(nodeAnnotation.jcrType());
    classDescriptor.setDiscriminator(nodeAnnotation.discriminator());
    if (nodeAnnotation.jcrSuperTypes() != null && ! nodeAnnotation.jcrSuperTypes().equals(""))
    {
         classDescriptor.setJcrSuperTypes(nodeAnnotation.jcrSuperTypes());
    }

    if (nodeAnnotation.jcrMixinTypes() != null && ! nodeAnnotation.jcrMixinTypes().equals(""))
    {
         classDescriptor.setJcrMixinTypes(nodeAnnotation.jcrMixinTypes());
    }

    Class ancestorClass = ReflectionUtils.getAncestorClass(clazz);
    if (ancestorClass != null)
    {
      classDescriptor.setExtend(ancestorClass.getName());
    }
     
    // TODO : Can we still support the extend param in the annotation @Node if we are using
    //        the reflection to get the ancestor class ? (see the previous if)
    if (nodeAnnotation.extend() != null && ! nodeAnnotation.extend().equals(Object.class))
    {
         classDescriptor.setExtend(nodeAnnotation.extend().getName());
    }

   
    classDescriptor.setAbstract(nodeAnnotation.isAbstract()||ReflectionUtils.isAbstractClass(clazz) );
    classDescriptor.setInterface(clazz.isInterface());
    return classDescriptor;
  }
View Full Code Here

    }
  }

  public void update(Session session, String uuId, Object object) {
    try {
      ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
      Node objectNode = session.getNodeByIdentifier(uuId);
      update(session, objectNode, object);
    } catch (PathNotFoundException pnfe) {
      throw new ObjectContentManagerException("Impossible to update the object with UUID: " + uuId , pnfe);
    } catch (RepositoryException re) {
View Full Code Here

      throw new org.apache.jackrabbit.ocm.exception.RepositoryException("Impossible to update the object with UUID: " + uuId, re);
    }
  }

  public void update(Session session, Node objectNode, Object object) {
      ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));

      checkNodeType(session, classDescriptor);

      checkCompatiblePrimaryNodeTypes(session, objectNode, classDescriptor, false);
View Full Code Here

      simpleFieldsHelp.refreshUuidPath(session, classDescriptor, objectNode, object);
  }

  public void update(Session session, Node parentNode, String nodeName, Object object) {
    try {
      ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
      Node objectNode = getNode(parentNode,classDescriptor,nodeName,object);
      update(session, objectNode, object);
    } catch (PathNotFoundException pnfe) {
      throw new ObjectContentManagerException("Impossible to update the object: " + nodeName + " at node : " + parentNode, pnfe);
    } catch (RepositoryException re) {
View Full Code Here

      if (requestObjectCache.isCached(path))
        {
            return requestObjectCache.getObject(path);
        }

      ClassDescriptor classDescriptor;
      Node node = session.getNode(path);
      if (node.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY)) {
        String className = node.getProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY).getValue().getString();
        classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.forName(className));
      } else {
        String nodeType = node.getPrimaryNodeType().getName();
        if (nodeType.equals(ManagerConstant.FROZEN_NODE_TYPE)) {
          nodeType = node.getProperty(ManagerConstant.FROZEN_PRIMARY_TYPE_PROPERTY).getString();
        }
        classDescriptor = mapper.getClassDescriptorByNodeType(nodeType);
      }

      if (null == classDescriptor) {
        throw new JcrMappingException("Impossible to find the classdescriptor for " + path
            + ". There is no discriminator and associated  JCR node type");
      }

      Object object = ReflectionUtils.newInstance(classDescriptor.getClassName());

            if (! requestObjectCache.isCached(path))
            {
        requestObjectCache.cache(path, object);
            }
View Full Code Here

      if (requestObjectCache.isCached(path))
        {
            return requestObjectCache.getObject(path);
        }

      ClassDescriptor classDescriptor = getClassDescriptor(clazz);

      checkNodeType(session, classDescriptor);

      Node node = session.getNode(path);
      if (!classDescriptor.isInterface()) {
        node = getActualNode(session,node);
        checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
      }

      ClassDescriptor alternativeDescriptor = null;
      if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
        if (node.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY)) {
                  String className = node.getProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY).getValue().getString();
                  alternativeDescriptor = getClassDescriptor(ReflectionUtils.forName(className));
        }
      } else {
        if (classDescriptor.usesNodeTypePerConcreteClassStrategy()) {
          String nodeType = node.getPrimaryNodeType().getName();
          if (!nodeType.equals(classDescriptor.getJcrType())) {
              alternativeDescriptor = classDescriptor.getDescendantClassDescriptor(nodeType);

              // in case we an alternative could not be found by walking
              // the class descriptor hierarchy, check whether we would
              // have a descriptor for the node type directly (which
              // may the case if the class descriptor hierarchy is
              // incomplete due to missing configuration. See JCR-1145
              // for details.
              if (alternativeDescriptor == null) {
                  alternativeDescriptor = mapper.getClassDescriptorByNodeType(nodeType);
              }
          }
        }
      }

      // if we have an alternative class descriptor, check whether its
      // extends (or is the same) as the requested class.
      if (alternativeDescriptor != null) {
          Class alternativeClazz = ReflectionUtils.forName(alternativeDescriptor.getClassName());
          if (clazz.isAssignableFrom(alternativeClazz)) {
              clazz = alternativeClazz;
              classDescriptor = alternativeDescriptor;
          }
      }
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.