chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r926534 [2/2] - in /incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src: main/java/org/apache/opencmis/inmemory/clientprovider/ main/java/org/apache/opencmis/inmemory/server/ test/java/org/apache/opencmis/inmemory/
Date Tue, 23 Mar 2010 12:23:29 GMT
Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
Tue Mar 23 12:23:29 2010
@@ -38,160 +38,186 @@ import org.apache.opencmis.inmemory.stor
 import org.apache.opencmis.server.spi.CallContext;
 import org.apache.opencmis.server.spi.CmisRepositoryService;
 
-public class InMemoryRepositoryServiceImpl extends AbstractServiceImpl implements CmisRepositoryService
{
-  
+public class InMemoryRepositoryServiceImpl extends AbstractServiceImpl implements
+    CmisRepositoryService {
+
   public InMemoryRepositoryServiceImpl(StoreManager storeManager) {
     super(storeManager);
   }
 
   public RepositoryInfoData getRepositoryInfo(CallContext context, String repositoryId,
       ExtensionsData extension) {
-    
+
     // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
-    
+    RuntimeContext.attachCfg(context);
+
     RepositoryInfoData repoInfo = getRepositoryInfoFromStoreManager(repositoryId);
 
     return repoInfo;
-   }
+  }
 
   public List<RepositoryInfoData> getRepositoryInfos(CallContext context, ExtensionsData
extension) {
-    
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
 
-    List<RepositoryInfoData> res = new ArrayList<RepositoryInfoData>();
-    List<String> repIds = fStoreManager.getAllRepositoryIds();
-    for (String repId : repIds) {
-      res.add(fStoreManager.getRepositoryInfo(repId));
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      List<RepositoryInfoData> res = new ArrayList<RepositoryInfoData>();
+      List<String> repIds = fStoreManager.getAllRepositoryIds();
+      for (String repId : repIds) {
+        res.add(fStoreManager.getRepositoryInfo(repId));
+      }
+      return res;
+    }
+    finally {
+      RuntimeContext.remove();
     }
-    return res;
   }
 
   public TypeDefinitionList getTypeChildren(CallContext context, String repositoryId,
       String typeId, Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger
skipCount,
       ExtensionsData extension) {
-    
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
 
-    getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
+
+      int skip = skipCount == null ? 0 : skipCount.intValue();
+      int max = maxItems == null ? -1 : maxItems.intValue();
+
+      TypeDefinitionListImpl result = new TypeDefinitionListImpl();
+      List<TypeDefinitionContainer> children;
+      if (typeId == null) {
+        // spec says that base types must be returned in this case
+        children = fStoreManager.getRootTypes(repositoryId);
+      }
+      else {
+        children = getTypeDescendants(context, repositoryId, typeId, BigInteger.valueOf(1),
+            includePropertyDefinitions, null);
+      }
+      result.setNumItems(BigInteger.valueOf(children.size()));
+      result.setHasMoreItems(children.size() > max - skip);
+      List<TypeDefinition> childrenTypes = new ArrayList<TypeDefinition>();
+      ListIterator<TypeDefinitionContainer> it = children.listIterator(skip);
+      if (max < 0)
+        max = children.size();
+      for (int i = skip; i < max + skip && it.hasNext(); i++)
+        childrenTypes.add(it.next().getTypeDefinition());
 
-    int skip = skipCount == null ? 0 : skipCount.intValue();
-    int max = maxItems == null ? -1 : maxItems.intValue();
-      
-    TypeDefinitionListImpl result = new TypeDefinitionListImpl();
-    List<TypeDefinitionContainer> children;
-    if (typeId == null) {
-      // spec says that base types must be returned in this case
-      children = fStoreManager.getRootTypes(repositoryId);
-    } else {    
-      children = getTypeDescendants(context, repositoryId, typeId, 
-        BigInteger.valueOf(1), includePropertyDefinitions, null);
-    }
-    result.setNumItems(BigInteger.valueOf(children.size()));
-    result.setHasMoreItems(children.size() > max - skip);
-    List<TypeDefinition> childrenTypes = new ArrayList<TypeDefinition>();
-    ListIterator<TypeDefinitionContainer> it = children.listIterator(skip);
-    if (max<0)
-      max = children.size();
-    for (int i=skip; i<max+skip && it.hasNext(); i++)
-      childrenTypes.add(it.next().getTypeDefinition());
-
-    result.setList(childrenTypes);      
-    return result;
-  }
-  
-  public TypeDefinition getTypeDefinition(CallContext context, String repositoryId,
-      String typeId, ExtensionsData extension) {
-    
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
+      result.setList(childrenTypes);
+      return result;
+    }
+    finally {
+      RuntimeContext.remove();
+    }
+  }
+
+  public TypeDefinition getTypeDefinition(CallContext context, String repositoryId, String
typeId,
+      ExtensionsData extension) {
+
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
 
-    getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
+      getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
 
-    TypeDefinitionContainer tc = fStoreManager.getTypeById(repositoryId, typeId);
-    if (tc != null) {
-      return tc.getTypeDefinition();
+      TypeDefinitionContainer tc = fStoreManager.getTypeById(repositoryId, typeId);
+      if (tc != null) {
+        return tc.getTypeDefinition();
+      }
+      else
+        throw new CmisObjectNotFoundException("unknown type id: " + typeId);
+    }
+    finally {
+      RuntimeContext.remove();
     }
-    else
-      throw new CmisObjectNotFoundException("unknown type id: " + typeId);        
   }
 
   public List<TypeDefinitionContainer> getTypeDescendants(CallContext context, String
repositoryId,
       String typeId, BigInteger depth, Boolean includePropertyDefinitions, ExtensionsData
extension) {
-    
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
-
-    getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
 
-    if (depth != null && depth.intValue() == 0)
-      throw new CmisInvalidArgumentException("depth == 0 is illegal in getTypeDescendants");
-    
-    List<TypeDefinitionContainer> result =  null;
-    if (typeId == null) {
-      // spec says that depth must be ignored in this case
-        Collection<TypeDefinitionContainer> typeColl = fStoreManager.getTypeDefinitionList(repositoryId);
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      getRepositoryInfoFromStoreManager(repositoryId); // just to check if repository exists
+
+      if (depth != null && depth.intValue() == 0)
+        throw new CmisInvalidArgumentException("depth == 0 is illegal in getTypeDescendants");
+
+      List<TypeDefinitionContainer> result = null;
+      if (typeId == null) {
+        // spec says that depth must be ignored in this case
+        Collection<TypeDefinitionContainer> typeColl = fStoreManager
+            .getTypeDefinitionList(repositoryId);
         result = new ArrayList<TypeDefinitionContainer>(typeColl);
         if (!includePropertyDefinitions) {
           // copy list and omit properties
           for (TypeDefinitionContainer c : result) {
-            AbstractTypeDefinition td = ((AbstractTypeDefinition)c.getTypeDefinition()).clone();
+            AbstractTypeDefinition td = ((AbstractTypeDefinition) c.getTypeDefinition()).clone();
             TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
             tdc.setChildren(c.getChildren());
             td.setPropertyDefinitions(null);
           }
         }
-    }
-    else {
-      TypeDefinitionContainer tc = fStoreManager.getTypeById(repositoryId, typeId);
-      if (tc != null) {
-        if (null==depth || depth.intValue() == -1) {
-          result = tc.getChildren();
-          if (!includePropertyDefinitions)
-            cloneTypeList(depth.intValue()-1, false, result);
-        } else if (depth.intValue() == 0 || depth.intValue() < -1)
-          throw new CmisInvalidArgumentException("illegal depth value: " + depth.intValue());
       
-        else {
-          result = tc.getChildren();
-          cloneTypeList(depth.intValue()-1, includePropertyDefinitions, result);
+      }
+      else {
+        TypeDefinitionContainer tc = fStoreManager.getTypeById(repositoryId, typeId);
+        if (tc != null) {
+          if (null == depth || depth.intValue() == -1) {
+            result = tc.getChildren();
+            if (!includePropertyDefinitions)
+              cloneTypeList(depth.intValue() - 1, false, result);
+          }
+          else if (depth.intValue() == 0 || depth.intValue() < -1)
+            throw new CmisInvalidArgumentException("illegal depth value: " + depth.intValue());
+          else {
+            result = tc.getChildren();
+            cloneTypeList(depth.intValue() - 1, includePropertyDefinitions, result);
+          }
         }
+        else
+          throw new CmisInvalidArgumentException("unknown type id: " + typeId);
       }
-      else
-        throw new CmisInvalidArgumentException("unknown type id: " + typeId);        
+
+      return result;
+    }
+    finally {
+      RuntimeContext.remove();
     }
-    
-    return result;
   }
 
   /**
-   * traverse tree and replace each need node with a clone. remove properties on 
-   * clone if requested, cut children of clone if depth is exceeded.
+   * traverse tree and replace each need node with a clone. remove properties on clone if
requested,
+   * cut children of clone if depth is exceeded.
+   * 
    * @param depth
    * @param types
    */
   private void cloneTypeList(int depth, boolean includePropertyDefinitions,
       List<TypeDefinitionContainer> types) {
-  
+
     ListIterator<TypeDefinitionContainer> it = types.listIterator();
     while (it.hasNext()) {
       TypeDefinitionContainer tdc = it.next();
-      AbstractTypeDefinition td = ((AbstractTypeDefinition)tdc.getTypeDefinition()).clone();
+      AbstractTypeDefinition td = ((AbstractTypeDefinition) tdc.getTypeDefinition()).clone();
       if (!includePropertyDefinitions)
         td.setPropertyDefinitions(null);
       TypeDefinitionContainerImpl tdcClone = new TypeDefinitionContainerImpl(td);
       if (depth > 0) {
-        ArrayList<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>(tdc.getChildren().size());
+        ArrayList<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>(tdc
+            .getChildren().size());
         children.addAll(tdc.getChildren());
         tdcClone.setChildren(children);
-        cloneTypeList(depth-1, includePropertyDefinitions, children);
+        cloneTypeList(depth - 1, includePropertyDefinitions, children);
       }
-      it.set(tdcClone);       
+      it.set(tdcClone);
     }
   }
 
-  private RepositoryInfoData getRepositoryInfoFromStoreManager(String repositoryId ) {
+  private RepositoryInfoData getRepositoryInfoFromStoreManager(String repositoryId) {
     RepositoryInfoData repoInfo = fStoreManager.getRepositoryInfo(repositoryId);
     if (null == repoInfo || !repoInfo.getRepositoryId().equals(repositoryId)) {
       throw new CmisInvalidArgumentException("Unknown repository: " + repositoryId);

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryVersioningServiceImpl.java
Tue Mar 23 12:23:29 2010
@@ -64,116 +64,138 @@ public class InMemoryVersioningServiceIm
   public void cancelCheckOut(CallContext context, String repositoryId, String objectId,
       ExtensionsData extension) {
 
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      StoredObject so = checkStandardParameters(repositoryId, objectId);
+      String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
+      VersionedDocument verDoc = testHasProperCheckedOutStatus(so, user);
 
-    StoredObject so = checkStandardParameters(repositoryId, objectId);
-    String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
-    VersionedDocument verDoc = testHasProperCheckedOutStatus(so, user);
-
-    verDoc.cancelCheckOut(user);
+      verDoc.cancelCheckOut(user);
+    }
+    finally {
+      RuntimeContext.remove();
+    }
   }
 
   public ObjectData checkIn(CallContext context, String repositoryId, Holder<String>
objectId,
       Boolean major, PropertiesData properties, ContentStreamData contentStream,
       String checkinComment, List<String> policies, AccessControlList addAces,
       AccessControlList removeAces, ExtensionsData extension, ObjectInfoHolder objectInfos)
{
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
 
-    StoredObject so = checkStandardParameters(repositoryId, objectId.getValue());
-    String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
-    VersionedDocument verDoc = testHasProperCheckedOutStatus(so, user);
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
 
-    DocumentVersion pwc = verDoc.getPwc();
+      StoredObject so = checkStandardParameters(repositoryId, objectId.getValue());
+      String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
+      VersionedDocument verDoc = testHasProperCheckedOutStatus(so, user);
 
-    if (null != contentStream)
-      pwc.setContent(contentStream, false);
+      DocumentVersion pwc = verDoc.getPwc();
 
-    if (null != properties && null != properties.getProperties())
-      pwc.setCustomProperties(properties.getProperties());
+      if (null != contentStream)
+        pwc.setContent(contentStream, false);
 
-    verDoc.checkIn(major, checkinComment, user);
+      if (null != properties && null != properties.getProperties())
+        pwc.setCustomProperties(properties.getProperties());
 
-    // To be able to provide all Atom links in the response we need additional information:
-    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
+      verDoc.checkIn(major, checkinComment, user);
 
-    ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so, null, false,
-        IncludeRelationships.NONE, null, false, false, extension);
+      // To be able to provide all Atom links in the response we need additional information:
+      fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
 
-    return od;
+      ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so, null, false,
+          IncludeRelationships.NONE, null, false, false, extension);
+
+      return od;
+    }
+    finally {
+      RuntimeContext.remove();
+    }
   }
 
   public ObjectData checkOut(CallContext context, String repositoryId, Holder<String>
objectId,
       ExtensionsData extension, Holder<Boolean> contentCopied, ObjectInfoHolder objectInfos)
{
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
 
-    StoredObject so = checkStandardParameters(repositoryId, objectId.getValue());
-    TypeDefinition typeDef = getTypeDefinition(repositoryId, so);
-    if (!typeDef.getBaseId().equals(BaseObjectTypeIds.CMIS_DOCUMENT))
-      throw new CmisNotSupportedException("Only documents can be checked-out.");
-    else if (!((DocumentTypeDefinition) typeDef).isVersionable())
-      throw new CmisNotSupportedException("Object can't be checked-out, type is not versionable.");
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
 
-    checkIsVersionableObject(so);
+      StoredObject so = checkStandardParameters(repositoryId, objectId.getValue());
+      TypeDefinition typeDef = getTypeDefinition(repositoryId, so);
+      if (!typeDef.getBaseId().equals(BaseObjectTypeIds.CMIS_DOCUMENT))
+        throw new CmisNotSupportedException("Only documents can be checked-out.");
+      else if (!((DocumentTypeDefinition) typeDef).isVersionable())
+        throw new CmisNotSupportedException("Object can't be checked-out, type is not versionable.");
 
-    VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
+      checkIsVersionableObject(so);
 
-    ContentStreamData content = null;
+      VersionedDocument verDoc = getVersionedDocumentOfObjectId(so);
 
-    if (so instanceof DocumentVersion) {
-      // get document the version is contained in to c
-      content = ((DocumentVersion) so).getContent(0, -1);
-    }
-    else {
-      content = ((VersionedDocument) so).getLatestVersion(false).getContent(0, -1);
-    }
+      ContentStreamData content = null;
+
+      if (so instanceof DocumentVersion) {
+        // get document the version is contained in to c
+        content = ((DocumentVersion) so).getContent(0, -1);
+      }
+      else {
+        content = ((VersionedDocument) so).getLatestVersion(false).getContent(0, -1);
+      }
 
-    if (verDoc.isCheckedOut())
-      throw new CmisUpdateConflictException("Document " + objectId.getValue()
-          + " is already checked out.");
+      if (verDoc.isCheckedOut())
+        throw new CmisUpdateConflictException("Document " + objectId.getValue()
+            + " is already checked out.");
 
-    String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
-    checkHasUser(user);
+      String user = RuntimeContext.getRuntimeConfigValue(CallContext.USERNAME);
+      checkHasUser(user);
 
-    DocumentVersion pwc = verDoc.checkOut(content, user);
-    objectId.setValue(pwc.getId()); // return the id of the created pwc
+      DocumentVersion pwc = verDoc.checkOut(content, user);
+      objectId.setValue(pwc.getId()); // return the id of the created pwc
 
-    // To be able to provide all Atom links in the response we need additional information:
-    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
+      // To be able to provide all Atom links in the response we need additional information:
+      fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
 
-    ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so, null, false,
-        IncludeRelationships.NONE, null, false, false, extension);
+      ObjectData od = PropertyCreationHelper.getObjectData(fStoreManager, so, null, false,
+          IncludeRelationships.NONE, null, false, false, extension);
 
-    return od;
+      return od;
+    }
+    finally {
+      RuntimeContext.remove();
+    }
   }
 
   public List<ObjectData> getAllVersions(CallContext context, String repositoryId,
       String versionSeriesId, String filter, Boolean includeAllowableActions,
       ExtensionsData extension, ObjectInfoHolder objectInfos) {
 
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
 
-    StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
+      StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
 
-    if (!(so instanceof VersionedDocument))
-      throw new RuntimeException("Object is not instance of a VersionedDocument (version
series)");
+      if (!(so instanceof VersionedDocument))
+        throw new RuntimeException("Object is not instance of a VersionedDocument (version
series)");
 
-    VersionedDocument verDoc = (VersionedDocument) so;
-    List<ObjectData> res = new ArrayList<ObjectData>();
-    List<DocumentVersion> versions = verDoc.getAllVersions();
-    for (DocumentVersion version : versions) {
-      ObjectData objData = getObject(context, repositoryId, version.getId(), filter,
-          includeAllowableActions, extension, objectInfos);
-      res.add(objData);
-    }
+      VersionedDocument verDoc = (VersionedDocument) so;
+      List<ObjectData> res = new ArrayList<ObjectData>();
+      List<DocumentVersion> versions = verDoc.getAllVersions();
+      for (DocumentVersion version : versions) {
+        ObjectData objData = getObject(context, repositoryId, version.getId(), filter,
+            includeAllowableActions, extension, objectInfos);
+        res.add(objData);
+      }
 
-    // provide information for Atom links for version series:
-    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
+      // provide information for Atom links for version series:
+      fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
 
-    return res;
+      return res;
+    }
+    finally {
+      RuntimeContext.remove();
+    }
   }
 
   public ObjectData getObjectOfLatestVersion(CallContext context, String repositoryId,
@@ -181,54 +203,65 @@ public class InMemoryVersioningServiceIm
       IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds,
       Boolean includeAcl, ExtensionsData extension, ObjectInfoHolder objectInfos) {
 
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
+      ObjectData objData = null;
+
+      if (so instanceof VersionedDocument) {
+        VersionedDocument verDoc = (VersionedDocument) so;
+        DocumentVersion latestVersion = verDoc.getLatestVersion(major);
+        objData = getObject(context, repositoryId, latestVersion.getId(), filter,
+            includeAllowableActions, extension, objectInfos);
+      }
+      else if (so instanceof Document) {
+        objData = getObject(context, repositoryId, so.getId(), filter, includeAllowableActions,
+            extension, objectInfos);
+      }
+      else
+        throw new RuntimeException("Object is not instance of a document (version series)");
 
-    StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
-    ObjectData objData = null;
+      // provide information for Atom links for version series:
+      fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
 
-    if (so instanceof VersionedDocument) {
-      VersionedDocument verDoc = (VersionedDocument) so;
-      DocumentVersion latestVersion = verDoc.getLatestVersion(major);
-      objData = getObject(context, repositoryId, latestVersion.getId(), filter,
-          includeAllowableActions, extension, objectInfos);
+      return objData;
     }
-    else if (so instanceof Document) {
-      objData = getObject(context, repositoryId, so.getId(), filter, includeAllowableActions,
-          extension, objectInfos);
+    finally {
+      RuntimeContext.remove();
     }
-    else
-      throw new RuntimeException("Object is not instance of a document (version series)");
-
-    // provide information for Atom links for version series:
-    fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfos);
-
-    return objData;
   }
 
   public PropertiesData getPropertiesOfLatestVersion(CallContext context, String repositoryId,
       String versionSeriesId, Boolean major, String filter, ExtensionsData extension) {
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(context);
 
-    StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
-    StoredObject latestVersionObject = null;
+    try {
+      // Attach the CallContext to a thread local context that can be accessed from everywhere
+      RuntimeContext.attachCfg(context);
+
+      StoredObject so = checkStandardParameters(repositoryId, versionSeriesId);
+      StoredObject latestVersionObject = null;
+
+      if (so instanceof VersionedDocument) {
+        VersionedDocument verDoc = (VersionedDocument) so;
+        latestVersionObject = verDoc.getLatestVersion(major);
+      }
+      else if (so instanceof Document) {
+        latestVersionObject = so;
+      }
+      else
+        throw new RuntimeException("Object is not instance of a document (version series)");
+
+      List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter);
+      PropertiesData props = PropertyCreationHelper.getPropertiesFromObject(repositoryId,
+          latestVersionObject, fStoreManager, requestedIds);
 
-    if (so instanceof VersionedDocument) {
-      VersionedDocument verDoc = (VersionedDocument) so;
-      latestVersionObject = verDoc.getLatestVersion(major);
+      return props;
     }
-    else if (so instanceof Document) {
-      latestVersionObject = so;
+    finally {
+      RuntimeContext.remove();
     }
-    else
-      throw new RuntimeException("Object is not instance of a document (version series)");
-
-    List<String> requestedIds = FilterParser.getRequestedIdsFromFilter(filter);
-    PropertiesData props = PropertyCreationHelper.getPropertiesFromObject(repositoryId,
-        latestVersionObject, fStoreManager, requestedIds);
-
-    return props;
   }
 
   private ObjectData getObject(CallContext context, String repositoryId, String objectId,

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/RuntimeContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/RuntimeContext.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/RuntimeContext.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/RuntimeContext.java
Tue Mar 23 12:23:29 2010
@@ -28,6 +28,8 @@ import org.apache.opencmis.server.spi.Ca
  * @author jens
  *
  */
+
+/*
 public class RuntimeContext {
   public static class ThreadLocalRuntimeConfig extends ThreadLocal<CallContext> { 
  
 
@@ -55,4 +57,34 @@ public class RuntimeContext {
     return CONN.getConfigValue(key);
   }
   
+  public static void remove() {
+    CONN.remove();
+  }
+}
+*/
+
+public class RuntimeContext {
+  
+  private static ThreadLocal<CallContext> CTX_TLS =  new ThreadLocal<CallContext>();

+
+  public static void attachCfg(CallContext ctx) {      
+    CTX_TLS.set(ctx);      
+  }
+
+  public static synchronized String getRuntimeConfigValue(String key) {
+    CallContext ctx = CTX_TLS.get();
+    if (null == ctx)
+      return null;
+    else      
+      return CTX_TLS.get().get(key) ;
+  }
+  
+  public static void remove() {
+    CTX_TLS.remove();
+  }
+
+  public static final CallContext getCurrentContext() {
+    return CTX_TLS.get();
+  }
+  
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/ServiceFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/ServiceFactory.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/ServiceFactory.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/ServiceFactory.java
Tue Mar 23 12:23:29 2010
@@ -254,7 +254,7 @@ public class ServiceFactory extends Abst
 
     // Simulate a runtime context with configuration parameters
     // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(new DummyCallContext());
+   RuntimeContext.attachCfg(new DummyCallContext());
 
     // Build the tree
     RepositoryInfoData rep = repSvc.getRepositoryInfo(repositoryId, null);

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/AbstractServiceTst.java
Tue Mar 23 12:23:29 2010
@@ -54,7 +54,7 @@ public class AbstractServiceTst /* exten
   protected RepositoryService fRepSvc;
   protected VersioningService fVerSvc;
   protected MultiFilingService fMultiSvc;
-  
+  protected DummyCallContext fTestCallContext;
   private String fTypeCreatorClassName;
   private boolean fUseClientProviderInterface;
   
@@ -92,6 +92,10 @@ public class AbstractServiceTst /* exten
     // give subclasses a chance to provide additional parameters for special tests
     addParameters(parameters);
     
+    fTestCallContext = new DummyCallContext();
+    // Attach a standatrd CallContext to a thread before the services are initialized.
+    RuntimeContext.attachCfg(fTestCallContext);
+
     if (fUseClientProviderInterface)
       initializeUsingClientProvider(parameters);
     else
@@ -106,10 +110,7 @@ public class AbstractServiceTst /* exten
     fRepositoryId = rep.getRepositoryId();
     
     assertNotNull(fRepositoryId);
-    assertNotNull(fRootFolderId);
-    
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(new DummyCallContext());
+    assertNotNull(fRootFolderId);    
   }
   
   // Override this method in subclasses if you want to provide additional configuration

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/VersioningTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/VersioningTest.java?rev=926534&r1=926533&r2=926534&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/VersioningTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/VersioningTest.java
Tue Mar 23 12:23:29 2010
@@ -55,11 +55,6 @@ import org.apache.opencmis.commons.provi
 import org.apache.opencmis.commons.provider.PropertyIdData;
 import org.apache.opencmis.commons.provider.PropertyStringData;
 import org.apache.opencmis.inmemory.clientprovider.DummyCallContext;
-import org.apache.opencmis.inmemory.clientprovider.MultiFilingServiceImpl;
-import org.apache.opencmis.inmemory.clientprovider.NavigationServiceImpl;
-import org.apache.opencmis.inmemory.clientprovider.ObjectServiceImpl;
-import org.apache.opencmis.inmemory.clientprovider.RepositoryServiceImpl;
-import org.apache.opencmis.inmemory.clientprovider.VersioningServiceImpl;
 import org.apache.opencmis.inmemory.server.RuntimeContext;
 import org.apache.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
 import org.apache.opencmis.inmemory.types.PropertyCreationHelper;
@@ -93,10 +88,13 @@ public class VersioningTest extends Abst
 
   private void setRuntimeContext(String user) {
 
+    /*
     DummyCallContext ctx = new DummyCallContext();
     ctx.put(CallContext.USERNAME, user);
     // Attach the CallContext to a thread local context that can be accessed from everywhere
-    RuntimeContext.getRuntimeConfig().attachCfg(ctx); 
+    RuntimeContext.attachCfg(ctx);
+    */
+    fTestCallContext.put(CallContext.USERNAME, user);
   }
     
   @Test



Mime
View raw message