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

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


   *
   * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#insert(javax.jcr.Session,
   *      javax.jcr.Node, java.lang.String, java.lang.Object)
   */
  public void insert(Session session, Node parentNode, String nodeName, Object object) {
    ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(object.getClass());

    String jcrType = classDescriptor.getJcrType();
    if ((jcrType == null) || jcrType.equals("")) {
      jcrType = ManagerConstant.NT_UNSTRUCTURED;
    }

    Node objectNode = null;
    try {
      objectNode = parentNode.addNode(nodeName, jcrType);

    } catch (NoSuchNodeTypeException nsnte) {
      throw new JcrMappingException("Unknown node type " + jcrType + " for mapped class " + object.getClass(), nsnte);
    } catch (RepositoryException re) {
      throw new ObjectContentManagerException("Cannot create new node of type " + jcrType + " from mapped class "
          + object.getClass(), re);
    }

    String[] mixinTypes = classDescriptor.getJcrMixinTypes();
    String mixinTypeName = null;
    try {

      // Add mixin types
      if (null != classDescriptor.getJcrMixinTypes()) {
        for (int i = 0; i < mixinTypes.length; i++) {
          mixinTypeName = mixinTypes[i].trim();
          objectNode.addMixin(mixinTypeName);
        }
      }

      // Add mixin types defined in the associated interfaces
      if (!classDescriptor.hasDiscriminator() && classDescriptor.hasInterfaces()) {
        Iterator interfacesIterator = classDescriptor.getImplements().iterator();
        while (interfacesIterator.hasNext()) {
          String interfaceName = (String) interfacesIterator.next();
          ClassDescriptor interfaceDescriptor = mapper
              .getClassDescriptorByClass(ReflectionUtils.forName(interfaceName));
          objectNode.addMixin(interfaceDescriptor.getJcrType().trim());
        }
      }

      // If required, add the discriminator node type
      if (classDescriptor.hasDiscriminator()) {
View Full Code Here


     */
    protected ManageableCollection doGetCollection(Session session,
                                                   Node parentNode,
                                                   CollectionDescriptor collectionDescriptor,
                                                   Class collectionFieldClass) throws RepositoryException {
      ClassDescriptor elementClassDescriptor = mapper.getClassDescriptorByClass( ReflectionUtils.forName(collectionDescriptor.getElementClassName()));
        ManageableCollection collection = ManageableCollectionUtil.getManageableCollection(collectionFieldClass);

        NodeIterator nodes = this.getCollectionNodes(session, parentNode, elementClassDescriptor.getJcrType());
       
        if (nodes == null || nodes.getSize() == 0)
        {
          return null;
        }
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

   * @see org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter#update(javax.jcr.Session,
   *      javax.jcr.Node, java.lang.String, java.lang.Object)
   */
  public void update(Session session, Node parentNode, String nodeName, Object object) {
    try {
      ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(ReflectionUtils.getBeanClass(object));
      Node objectNode = parentNode.getNode(nodeName);

      checkNodeType(session, classDescriptor);

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

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

      ClassDescriptor classDescriptor = null;
      Node node = (Node) session.getItem(path);
      if (node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
        String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).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 = (Node) session.getItem(path);
      if (!classDescriptor.isInterface()) {
        checkCompatiblePrimaryNodeTypes(session, node, classDescriptor, true);
      }

      ClassDescriptor alternativeDescriptor = null;
      if (classDescriptor.usesNodeTypePerHierarchyStrategy()) {
        if (node.hasProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME)) {
                  String className = node.getProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME).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

  }

  public void retrieveAllMappedAttributes(Session session, Object object) {
    String path = null;
    try {
      ClassDescriptor classDescriptor = getClassDescriptor(object.getClass());
      String pathFieldName = classDescriptor.getPathFieldDescriptor().getFieldName();
      path = (String) ReflectionUtils.getNestedProperty(object, pathFieldName);
      Node node = (Node) session.getItem(path);
      retrieveBeanFields(session, classDescriptor, node, path, object, true);
      retrieveCollectionFields(session, classDescriptor, node, object, true);
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());
    }
   
    if (nodeAnnotation.extend() != null && ! nodeAnnotation.extend().equals(Object.class))
    {
         classDescriptor.setExtend(nodeAnnotation.extend().getName());
    }
   
    classDescriptor.setAbstract(nodeAnnotation.isAbstract());
    classDescriptor.setInterface(clazz.isInterface());
    return classDescriptor;
  }
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.