chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r918057 - in /incubator/chemistry/trunk/opencmis/opencmis-client: opencmis-client-api/src/main/java/org/apache/opencmis/client/api/ opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ opencmis-client-impl/src/main/j...
Date Tue, 02 Mar 2010 14:44:36 GMT
Author: fmui
Date: Tue Mar  2 14:44:35 2010
New Revision: 918057

URL: http://svn.apache.org/viewvc?rev=918057&view=rev
Log:
improved PagingList
implemented getChildren

Modified:
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
Tue Mar  2 14:44:35 2010
@@ -62,7 +62,7 @@
 
   List<Container<FileableCmisObject>> getDescendants(int depth);
 
-  PagingList<CmisObject> getChildren(String orderby, int itemsPerPage);
+  PagingList<CmisObject> getChildren(String orderBy, int itemsPerPage);
 
   Folder getFolderParent();
 

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
Tue Mar  2 14:44:35 2010
@@ -25,6 +25,7 @@
 import org.apache.opencmis.client.api.Ace;
 import org.apache.opencmis.client.api.Acl;
 import org.apache.opencmis.client.api.AllowableActions;
+import org.apache.opencmis.client.api.CmisObject;
 import org.apache.opencmis.client.api.ContentStream;
 import org.apache.opencmis.client.api.Document;
 import org.apache.opencmis.client.api.Folder;
@@ -32,6 +33,7 @@
 import org.apache.opencmis.client.api.Property;
 import org.apache.opencmis.client.api.Relationship;
 import org.apache.opencmis.commons.enums.VersioningState;
+import org.apache.opencmis.commons.provider.ObjectData;
 
 /**
  * A factory to create CMIS objects.
@@ -40,38 +42,37 @@
  */
 public interface ObjectFactory {
 
-	// object factory
+  // object factory
 
   AllowableActions createAllowableAction(Map<String, Boolean> actions);
-  
-	Ace createAce(String principal, List<String> permissions, boolean isDirect);
 
-	Acl createAcl(List<Ace> aces, Boolean isExact);
+  Ace createAce(String principal, List<String> permissions, boolean isDirect);
 
-	ContentStream createContentStream(int length, String mimetype,
-			String filename, InputStream stream);
+  Acl createAcl(List<Ace> aces, Boolean isExact);
 
-	// object service
+  ContentStream createContentStream(int length, String mimetype, String filename, InputStream
stream);
 
-	// shortcut
-	Document createDocument(Folder parentfolder, String name);
+  // object service
 
-	Document createDocument(List<Property<?>> properties, Folder parentfolder,
-			ContentStream contentstream, VersioningState versioningState,
-			List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
+  // shortcut
+  Document createDocument(Folder parentfolder, String name);
 
-	Document createDocumentFromSource(Document source,
-			List<Property<?>> properties, Folder parentfolder,
-			VersioningState versioningState, List<Policy> policies,
-			List<Ace> addACEs, List<Ace> removeACEs);
+  Document createDocument(List<Property<?>> properties, Folder parentfolder,
+      ContentStream contentstream, VersioningState versioningState, List<Policy> policies,
+      List<Ace> addACEs, List<Ace> removeACEs);
 
-	Relationship createRelationship(List<Property<?>> properties,
-			List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
+  Document createDocumentFromSource(Document source, List<Property<?>> properties,
+      Folder parentfolder, VersioningState versioningState, List<Policy> policies,
+      List<Ace> addACEs, List<Ace> removeACEs);
 
-	Policy createPolicy(List<Property<?>> properties, Folder parentfolder,
-			List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
+  Relationship createRelationship(List<Property<?>> properties, List<Policy>
policies,
+      List<Ace> addACEs, List<Ace> removeACEs);
 
-	Folder createFolder(Folder parent, List<Property<?>> properties,
-			List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
+  Policy createPolicy(List<Property<?>> properties, Folder parentfolder, List<Policy>
policies,
+      List<Ace> addACEs, List<Ace> removeACEs);
 
+  Folder createFolder(Folder parent, List<Property<?>> properties, List<Policy>
policies,
+      List<Ace> addACEs, List<Ace> removeACEs);
+
+  CmisObject convertObject(ObjectData objectData);
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/AbstractPersistentCmisObject.java
Tue Mar  2 14:44:35 2010
@@ -47,8 +47,6 @@
 import org.apache.opencmis.commons.provider.Holder;
 import org.apache.opencmis.commons.provider.ObjectData;
 import org.apache.opencmis.commons.provider.ObjectList;
-import org.apache.opencmis.commons.provider.PropertyData;
-import org.apache.opencmis.commons.provider.PropertyIdData;
 import org.apache.opencmis.commons.provider.RelationshipService;
 
 /**
@@ -119,8 +117,8 @@
       if (objectData.getRelationships() != null) {
         relationships = new ArrayList<Relationship>();
         for (ObjectData rod : objectData.getRelationships()) {
-          relationships.add(new PersistentRelationshipImpl(getSession(),
-              getTypeFromObjectData(rod), rod));
+          relationships.add(new PersistentRelationshipImpl(getSession(), SessionUtil
+              .getTypeFromObjectData(getSession(), rod), rod));
         }
       }
     }
@@ -166,25 +164,6 @@
     return objectId;
   }
 
-  /**
-   * Extracts the type information from the given object data and returns the object type
or
-   * <code>null</code> if there is no type information.
-   */
-  private ObjectType getTypeFromObjectData(ObjectData objectData) {
-    if ((objectData == null) || (objectData.getProperties() == null)
-        || (objectData.getProperties().getProperties() == null)) {
-      return null;
-    }
-
-    PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(
-        PropertyIds.CMIS_OBJECT_TYPE_ID);
-    if (!(typeProperty instanceof PropertyIdData)) {
-      return null;
-    }
-
-    return getSession().getTypeDefinition((String) typeProperty.getFirstValue());
-  }
-
   // --- operations ---
 
   /*
@@ -633,7 +612,7 @@
     return new AbstractPagingList<Relationship>() {
 
       @Override
-      protected List<Relationship> fetchPage(int pageNumber) {
+      protected FetchResult fetchPage(int pageNumber) {
         int skipCount = pageNumber * getMaxItemsPerPage();
 
         // fetch the relationships
@@ -642,24 +621,16 @@
             includeAllowableActions, BigInteger.valueOf(getMaxItemsPerPage()), BigInteger
                 .valueOf(skipCount), null);
 
-        // set num items
-        if (relList.getNumItems() != null) {
-          setNumItems(relList.getNumItems().intValue());
-        }
-        else {
-          setNumItems(-1);
-        }
-
         // convert relationship objects
-        List<Relationship> result = new ArrayList<Relationship>();
+        List<Relationship> page = new ArrayList<Relationship>();
         if (relList.getObjects() != null) {
           for (ObjectData rod : relList.getObjects()) {
-            result
-                .add(new PersistentRelationshipImpl(getSession(), getTypeFromObjectData(rod),
rod));
+            page.add(new PersistentRelationshipImpl(getSession(), SessionUtil
+                .getTypeFromObjectData(getSession(), rod), rod));
           }
         }
 
-        return result;
+        return new FetchResult(page, relList.getNumItems(), relList.hasMoreItems());
       }
 
       @Override

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
Tue Mar  2 14:44:35 2010
@@ -32,9 +32,12 @@
 import org.apache.opencmis.client.api.Folder;
 import org.apache.opencmis.client.api.Policy;
 import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.SessionContext;
 import org.apache.opencmis.client.api.objecttype.ObjectType;
+import org.apache.opencmis.client.api.repository.ObjectFactory;
 import org.apache.opencmis.client.api.util.Container;
 import org.apache.opencmis.client.api.util.PagingList;
+import org.apache.opencmis.client.runtime.util.AbstractPagingList;
 import org.apache.opencmis.commons.PropertyIds;
 import org.apache.opencmis.commons.enums.IncludeRelationships;
 import org.apache.opencmis.commons.enums.UnfileObjects;
@@ -42,7 +45,10 @@
 import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.opencmis.commons.provider.AccessControlList;
 import org.apache.opencmis.commons.provider.FailedToDeleteData;
+import org.apache.opencmis.commons.provider.NavigationService;
 import org.apache.opencmis.commons.provider.ObjectData;
+import org.apache.opencmis.commons.provider.ObjectInFolderData;
+import org.apache.opencmis.commons.provider.ObjectInFolderList;
 import org.apache.opencmis.commons.provider.PropertiesData;
 import org.apache.opencmis.commons.provider.PropertyData;
 import org.apache.opencmis.commons.provider.ProviderObjectFactory;
@@ -113,8 +119,50 @@
     throw new CmisRuntimeException("not implemented");
   }
 
-  public PagingList<CmisObject> getChildren(String orderby, int itemsPerPage) {
-    throw new CmisRuntimeException("not implemented");
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.Folder#getChildren(java.lang.String, int)
+   */
+  public PagingList<CmisObject> getChildren(final String orderBy, final int itemsPerPage)
{
+    if (itemsPerPage < 1) {
+      throw new IllegalArgumentException("itemsPerPage must be > 0!");
+    }
+
+    final String objectId = getObjectId();
+    final SessionContext context = getSession().getContext();
+    final NavigationService navigationService = getProvider().getNavigationService();
+    final ObjectFactory objectFactory = getSession().getObjectFactory();
+
+    return new AbstractPagingList<CmisObject>() {
+
+      @Override
+      protected FetchResult fetchPage(int pageNumber) {
+        int skipCount = pageNumber * getMaxItemsPerPage();
+
+        // get the children
+        ObjectInFolderList children = navigationService.getChildren(getRepositoryId(), objectId,
+            context.getIncludeProperties(), orderBy, context.getIncludeAllowableActions(),
context
+                .getIncludeRelationships(), context.getIncludeRenditions(), context
+                .getIncludePathSegments(), BigInteger.valueOf(getMaxItemsPerPage()), BigInteger
+                .valueOf(skipCount), null);
+
+        // convert objects
+        List<CmisObject> page = new ArrayList<CmisObject>();
+        for (ObjectInFolderData objectData : children.getObjects()) {
+          if (objectData.getObject() != null) {
+            page.add(objectFactory.convertObject(objectData.getObject()));
+          }
+        }
+
+        return new FetchResult(page, children.getNumItems(), children.hasMoreItems());
+      }
+
+      @Override
+      public int getMaxItemsPerPage() {
+        return itemsPerPage;
+      }
+    };
   }
 
   public List<Container<FileableCmisObject>> getFolderTree(int depth) {
@@ -126,7 +174,13 @@
   }
 
   public Folder getFolderParent() {
-    throw new CmisRuntimeException("not implemented");
+    List<Folder> parents = getParents();
+
+    if ((parents == null) || (parents.isEmpty())) {
+      return null;
+    }
+
+    return parents.get(0);
   }
 
   public String getPath() {

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
Tue Mar  2 14:44:35 2010
@@ -67,8 +67,6 @@
 import org.apache.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
 import org.apache.opencmis.commons.provider.CmisProvider;
 import org.apache.opencmis.commons.provider.ObjectData;
-import org.apache.opencmis.commons.provider.PropertyData;
-import org.apache.opencmis.commons.provider.PropertyIdData;
 import org.apache.opencmis.commons.provider.RepositoryService;
 import org.apache.opencmis.util.repository.ObjectGenerator;
 
@@ -259,21 +257,7 @@
           includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds,
           includeAcl, extension);
 
-      /* determine type */
-      switch (od.getBaseTypeId()) {
-      case CMIS_DOCUMENT:
-        obj = new PersistentDocumentImpl(this, getType(od), od);
-        break;
-      case CMIS_FOLDER:
-        obj = new PersistentFolderImpl(this, getType(od), od);
-        break;
-      case CMIS_POLICY:
-        obj = new PersistentPolicyImpl(this, getType(od), od);
-      case CMIS_RELATIONSHIP:
-        obj = new PersistentRelationshipImpl(this, getType(od), od);
-      default:
-        throw new CmisRuntimeException("unsupported type: " + od.getBaseTypeId());
-      }
+      obj = getObjectFactory().convertObject(od);
 
       this.cache.put(obj);
     }
@@ -314,7 +298,8 @@
       ObjectData od = this.provider.getObjectService().getObject(repositoryId, rootFolderId,
null,
           false, IncludeRelationships.NONE, null, false, false, null);
 
-      rootFolder = new PersistentFolderImpl(this, getType(od), od);
+      ObjectType type = SessionUtil.getTypeFromObjectData(this, od);
+      rootFolder = new PersistentFolderImpl(this, type, od);
       this.cache.put(rootFolder);
     }
 
@@ -339,7 +324,7 @@
     return new AbstractPagingList<ObjectType>() {
 
       @Override
-      protected List<ObjectType> fetchPage(int pageNumber) {
+      protected FetchResult fetchPage(int pageNumber) {
         int skipCount = pageNumber * getMaxItemsPerPage();
 
         // fetch the data
@@ -347,21 +332,13 @@
             includePropertyDefinitions, BigInteger.valueOf(getMaxItemsPerPage()), BigInteger
                 .valueOf(skipCount), null);
 
-        // set num items
-        if (tdl.getNumItems() != null) {
-          setNumItems(tdl.getNumItems().intValue());
-        }
-        else {
-          setNumItems(-1);
-        }
-
         // convert type definitions
-        List<ObjectType> result = new ArrayList<ObjectType>(tdl.getList().size());
+        List<ObjectType> page = new ArrayList<ObjectType>(tdl.getList().size());
         for (TypeDefinition typeDefinition : tdl.getList()) {
-          result.add(SessionUtil.convertTypeDefinition(thisSession, typeDefinition));
+          page.add(SessionUtil.convertTypeDefinition(thisSession, typeDefinition));
         }
 
-        return result;
+        return new FetchResult(page, tdl.getNumItems(), tdl.hasMoreItems());
       }
 
       @Override
@@ -561,21 +538,4 @@
   public String getRepositoryId() {
     return this.getRepositoryInfo().getId();
   }
-
-  // --- internal ---
-
-  private ObjectType getType(ObjectData objectData) {
-    if ((objectData == null) || (objectData.getProperties() == null)
-        || (objectData.getProperties().getProperties() == null)) {
-      return null;
-    }
-
-    PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(
-        PropertyIds.CMIS_OBJECT_TYPE_ID);
-    if (!(typeProperty instanceof PropertyIdData)) {
-      return null;
-    }
-
-    return getTypeDefinition((String) typeProperty.getFirstValue());
-  }
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/SessionUtil.java
Tue Mar  2 14:44:35 2010
@@ -38,6 +38,7 @@
 import org.apache.opencmis.client.runtime.objecttype.FolderTypeImpl;
 import org.apache.opencmis.client.runtime.objecttype.PolicyTypeImpl;
 import org.apache.opencmis.client.runtime.objecttype.RelationshipTypeImpl;
+import org.apache.opencmis.commons.PropertyIds;
 import org.apache.opencmis.commons.api.DocumentTypeDefinition;
 import org.apache.opencmis.commons.api.FolderTypeDefinition;
 import org.apache.opencmis.commons.api.PolicyTypeDefinition;
@@ -56,8 +57,10 @@
 import org.apache.opencmis.commons.provider.AccessControlEntry;
 import org.apache.opencmis.commons.provider.AccessControlList;
 import org.apache.opencmis.commons.provider.AllowableActionsData;
+import org.apache.opencmis.commons.provider.ObjectData;
 import org.apache.opencmis.commons.provider.PropertiesData;
 import org.apache.opencmis.commons.provider.PropertyData;
+import org.apache.opencmis.commons.provider.PropertyIdData;
 import org.apache.opencmis.commons.provider.ProviderObjectFactory;
 
 /**
@@ -269,4 +272,23 @@
 
     return of.createAcl(aces, acl.isExact());
   }
+
+  /**
+   * Extracts the type information from the given object data and returns the object type
or
+   * <code>null</code> if there is no type information.
+   */
+  public static ObjectType getTypeFromObjectData(Session session, ObjectData objectData)
{
+    if ((objectData == null) || (objectData.getProperties() == null)
+        || (objectData.getProperties().getProperties() == null)) {
+      return null;
+    }
+
+    PropertyData<?> typeProperty = objectData.getProperties().getProperties().get(
+        PropertyIds.CMIS_OBJECT_TYPE_ID);
+    if (!(typeProperty instanceof PropertyIdData)) {
+      return null;
+    }
+
+    return session.getTypeDefinition((String) typeProperty.getFirstValue());
+  }
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
Tue Mar  2 14:44:35 2010
@@ -25,20 +25,27 @@
 import org.apache.opencmis.client.api.Ace;
 import org.apache.opencmis.client.api.Acl;
 import org.apache.opencmis.client.api.AllowableActions;
+import org.apache.opencmis.client.api.CmisObject;
 import org.apache.opencmis.client.api.ContentStream;
 import org.apache.opencmis.client.api.Document;
 import org.apache.opencmis.client.api.Folder;
 import org.apache.opencmis.client.api.Policy;
 import org.apache.opencmis.client.api.Property;
 import org.apache.opencmis.client.api.Relationship;
+import org.apache.opencmis.client.api.objecttype.ObjectType;
 import org.apache.opencmis.client.api.repository.ObjectFactory;
 import org.apache.opencmis.client.runtime.AceImpl;
 import org.apache.opencmis.client.runtime.AclImpl;
 import org.apache.opencmis.client.runtime.AllowableActionsImpl;
+import org.apache.opencmis.client.runtime.PersistentDocumentImpl;
 import org.apache.opencmis.client.runtime.PersistentFolderImpl;
+import org.apache.opencmis.client.runtime.PersistentPolicyImpl;
+import org.apache.opencmis.client.runtime.PersistentRelationshipImpl;
 import org.apache.opencmis.client.runtime.PersistentSessionImpl;
+import org.apache.opencmis.client.runtime.SessionUtil;
 import org.apache.opencmis.commons.enums.VersioningState;
 import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.opencmis.commons.provider.ObjectData;
 
 public class PersistentObjectFactoryImpl implements ObjectFactory {
 
@@ -106,4 +113,29 @@
       List<Ace> addACEs, List<Ace> removeACEs) {
     throw new CmisRuntimeException("not implemented");
   }
+
+  /**
+   * Converts object data into an API object.
+   */
+  public CmisObject convertObject(ObjectData objectData) {
+    if (objectData == null) {
+      throw new IllegalArgumentException("Object data is null!");
+    }
+
+    ObjectType type = SessionUtil.getTypeFromObjectData(this.session, objectData);
+
+    /* determine type */
+    switch (objectData.getBaseTypeId()) {
+    case CMIS_DOCUMENT:
+      return new PersistentDocumentImpl(this.session, type, objectData);
+    case CMIS_FOLDER:
+      return new PersistentFolderImpl(this.session, type, objectData);
+    case CMIS_POLICY:
+      return new PersistentPolicyImpl(this.session, type, objectData);
+    case CMIS_RELATIONSHIP:
+      return new PersistentRelationshipImpl(this.session, type, objectData);
+    default:
+      throw new CmisRuntimeException("unsupported type: " + objectData.getBaseTypeId());
+    }
+  }
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
Tue Mar  2 14:44:35 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.opencmis.client.runtime.util;
 
+import java.math.BigInteger;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -30,12 +31,12 @@
  */
 public abstract class AbstractPagingList<T> implements PagingList<T> {
 
-  // number of item is unknown before the fist fetch
+  // number of item is unknown before the first fetch
   private int numItems = -1;
 
   // cache is disabled by default
   private int cacheSize = 0;
-  private LinkedHashMap<Integer, List<T>> cache = null;
+  private LinkedHashMap<Integer, FetchResult> cache = null;
 
   /**
    * Initializes the cache.
@@ -47,11 +48,11 @@
     this.cacheSize = cacheSize;
 
     if (cacheSize > 0) {
-      cache = new LinkedHashMap<Integer, List<T>>(cacheSize + 1, 0.70f, true)
{
+      cache = new LinkedHashMap<Integer, FetchResult>(cacheSize + 1, 0.70f, true) {
         private static final long serialVersionUID = 1L;
 
         @Override
-        public boolean removeEldestEntry(Map.Entry<Integer, List<T>> eldest)
{
+        public boolean removeEldestEntry(Map.Entry<Integer, FetchResult> eldest) {
           return size() > cacheSize;
         }
       };
@@ -64,11 +65,19 @@
    * @see org.apache.opencmis.client.api.util.PagingList#get(int)
    */
   public List<T> get(int pageNumber) {
+    FetchResult fr = getInternal(pageNumber);
+    return (fr == null ? null : fr.getPage());
+  }
+
+  /**
+   * Retrieves a page or gets it from cache.
+   */
+  protected FetchResult getInternal(int pageNumber) {
     if (pageNumber < 0) {
       throw new IllegalArgumentException("pageNumber must be >= 0!");
     }
 
-    List<T> result = null;
+    FetchResult result = null;
 
     if (cacheSize > 0) {
       result = cache.get(pageNumber);
@@ -79,6 +88,16 @@
     }
     else {
       result = fetchPage(pageNumber);
+
+      // set number of items
+      if (result != null) {
+        if (result.getNumItems() != null) {
+          setNumItems(result.getNumItems().intValue());
+        }
+        else {
+          setNumItems(-1);
+        }
+      }
     }
 
     return result;
@@ -94,7 +113,7 @@
   }
 
   /**
-   * Sets the number of items. Should be updated by {@link #fetchPage(int)}.
+   * Sets the number of items.
    */
   protected void setNumItems(int numItems) {
     this.numItems = numItems;
@@ -139,7 +158,36 @@
    * @param pageNumber
    *          number of the page (>= 0).
    */
-  protected abstract List<T> fetchPage(int pageNumber);
+  protected abstract FetchResult fetchPage(int pageNumber);
+
+  // --- fetch result class ---
+
+  /**
+   * Fetch result.
+   */
+  protected class FetchResult {
+    private List<T> page;
+    private BigInteger numItems;
+    private Boolean hasMoreItems;
+
+    public FetchResult(List<T> page, BigInteger numItems, Boolean hasMoreItems) {
+      this.page = page;
+      this.numItems = numItems;
+      this.hasMoreItems = hasMoreItems;
+    }
+
+    public List<T> getPage() {
+      return page;
+    }
+
+    public BigInteger getNumItems() {
+      return numItems;
+    }
+
+    public Boolean getHasMoreItems() {
+      return hasMoreItems;
+    }
+  }
 
   // --- iterator class ---
 
@@ -149,11 +197,10 @@
   class PageIterator implements Iterator<List<T>> {
 
     private int currentPage = -1;
-    private boolean lastPageEmpty = false;
+    private boolean hasMoreItems = true;
 
     public boolean hasNext() {
-      if (lastPageEmpty) {
-        // the last page was empty, so we don't expect the next page will have items
+      if (!hasMoreItems) {
         return false;
       }
 
@@ -168,13 +215,22 @@
 
     public List<T> next() {
       currentPage++;
-      List<T> next = get(currentPage);
+      FetchResult next = getInternal(currentPage);
+
+      if (next == null) {
+        hasMoreItems = false;
+        return null;
+      }
+
+      if ((next.getPage() == null) || (next.getPage().isEmpty())) {
+        hasMoreItems = false;
+      }
 
-      if ((next == null) || (next.isEmpty())) {
-        lastPageEmpty = true;
+      if (next.getHasMoreItems() != null) {
+        hasMoreItems = next.getHasMoreItems().booleanValue();
       }
 
-      return next;
+      return (next == null ? null : next.getPage());
     }
 
     public void remove() {

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java?rev=918057&r1=918056&r2=918057&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java
Tue Mar  2 14:44:35 2010
@@ -23,6 +23,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.NoSuchElementException;
@@ -179,25 +180,24 @@
     }
 
     @Override
-    protected List<String> fetchPage(int pageNumber) {
+    protected FetchResult fetchPage(int pageNumber) {
       int skipCount = pageNumber * getMaxItemsPerPage();
       int lastIndex = skipCount + getMaxItemsPerPage() - 1;
       if (lastIndex >= sourceData.length) {
         lastIndex = sourceData.length - 1;
       }
 
-      setNumItems(sourceData.length);
-
       if (skipCount >= sourceData.length) {
         throw new NoSuchElementException();
       }
 
-      List<String> result = new ArrayList<String>();
+      List<String> page = new ArrayList<String>();
       for (int i = skipCount; i <= lastIndex; i++) {
-        result.add(sourceData[i]);
+        page.add(sourceData[i]);
       }
 
-      return result;
+      return new FetchResult(page, BigInteger.valueOf(sourceData.length), skipCount
+          + getMaxItemsPerPage() < sourceData.length);
     }
 
     @Override



Mime
View raw message