In a pure CMIS way, the following code snippet would accomplish the goal:
// For how to get a Session see:
// http://chemistry.apache.org/java/opencmis-client-api.html#sessions
Session session = getSession();
CmisObject object = session.getObjectByPath("/path/to/object");
ObjectType type = object.getType();
Boolean isVersionable = type instanceOf DocumentType && ((DocumentType)type).isVersionable();
In facts, cmis:document
nodes are always marked as versionable in Alfresco, while in reality Alfresco uses the cm:versionable
aspect to mark a node to be subdue to versioning. This is incompatible with the standard CMIS domain model where versionability is statically derived from the object type definition.
I believe that the cm:versionable
aspect is automatically added by Alfresco when issuing versioning CMIS calls to nodes that miss it, so that the above incompatibility shouldn't result in any real issue.
Another, more Alfresco specific solution would require you to use the Alfresco OpenCMIS Extension:
CmisObject object = session.getObjectByPath("/path/to/object");
Boolean isVersionable = object instanceof AlfrescoDocument && ((AlfrescoDocument)object).hasAspect("cm:versionable");