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

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


  }

  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 = session.getNode(path);
      retrieveBeanFields(session, classDescriptor, node, object, true);
      retrieveCollectionFields(session, classDescriptor, node, object, true);
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 = session.getNode(path);
      BeanDescriptor beanDescriptor = classDescriptor.getBeanDescriptor(attributeName);
      if (beanDescriptor != null)
      {
        this.retrieveBeanField(session, beanDescriptor, node, 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

  /**
   * @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

    }

    public boolean isPersistent(final Class clazz) {

        try {
            ClassDescriptor classDescriptor = mapper.getClassDescriptorByClass(clazz);
            if (classDescriptor == null) {
              return false;
            }
            return true;
        } catch (IncorrectPersistentClassException e) {
View Full Code Here

        String jcrExpression = this.queryManager.buildJCRExpression(query);
        return getObjects(jcrExpression, javax.jcr.query.Query.XPATH);
    }

    public Collection getObjects(Class objectClass, String path) throws ObjectContentManagerException {
        final ClassDescriptor classDescriptorByClass = mapper.getClassDescriptorByClass(objectClass);
        if (classDescriptorByClass == null) {
            log.debug("Cannot get objects because no descriptor class exists for '{}'", objectClass.getClass().getName());
            return Collections.emptyList();
        }
        try {
            if (!session.nodeExists(path)) {
                log.debug("Cannot get objects '{}' because no node exists at '{}'", objectClass.getClass().getName(), path);
                return Collections.emptyList();
            }
            Node parentNode = session.getNode(path).getParent();
            String nodeName = NodeUtil.getNodeName(path);
            if (StringUtils.isBlank(nodeName)) {
                nodeName = null;
            }
            NodeIterator candidates = parentNode.getNodes();
            List<Node> validated = new ArrayList<Node>();
            while (candidates.hasNext()) {
                Node child = candidates.nextNode();
                if (nodeName != null && !child.getName().equals(nodeName)) {
                    continue;
                }
                if (child.hasProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY)) {
                    if (child.getProperty(ManagerConstant.DISCRIMINATOR_CLASS_NAME_PROPERTY).getString().equals(classDescriptorByClass.getClassName())) {
                        // the discriminator class name matches. This is an object we need
                        validated.add(child);
                    }
                } else {
                    if (child.getPrimaryNodeType().getName().equals(classDescriptorByClass.getJcrType())) {
                        // nodetype matches
                        validated.add(child);
                    }
                }
            }
View Full Code Here

            Iterator collectionIterator = objects.getIterator();
            for (int i = 0; i < objects.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 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;
    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

           
            for (int i = 0; i < manageableMap.getSize(); i++) {
                String key = (String) keyIterator.next();
                Object object = map.get(key);
                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(MapReferenceValueEncoder.encodeKeyAndReference(key, uuid), PropertyType.STRING);
                }
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

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.