Author: mduerig
Date: Wed Jan 27 14:08:38 2010
New Revision: 903648
URL: http://svn.apache.org/viewvc?rev=903648&view=rev
Log:
Fixed primarytype, mixin assignments for folders and documents
Modified:
jackrabbit/sandbox/jackrabbit-spi2cmis/src/main/java/org/apache/jackrabbit/spi2cmis/TypeTransformer.java
Modified: jackrabbit/sandbox/jackrabbit-spi2cmis/src/main/java/org/apache/jackrabbit/spi2cmis/TypeTransformer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-spi2cmis/src/main/java/org/apache/jackrabbit/spi2cmis/TypeTransformer.java?rev=903648&r1=903647&r2=903648&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-spi2cmis/src/main/java/org/apache/jackrabbit/spi2cmis/TypeTransformer.java
(original)
+++ jackrabbit/sandbox/jackrabbit-spi2cmis/src/main/java/org/apache/jackrabbit/spi2cmis/TypeTransformer.java
Wed Jan 27 14:08:38 2010
@@ -53,12 +53,13 @@
}
/**
- * Transform a CMIS {@link Type} to a JCR {@link QNodeTypeDefinition} with respect to
a
- * name space mapping and a CMIS {@link Repository}.
- * @param cmisRepository CMIS {@link Repository}
- * @param cmisType CMIS {@link Type}
- * @param namespaces name space mapping
- * @return JCR {@link QNodeTypeDefinition}
+ * Transform a CMIS {@link Type} to a JCR {@link QNodeTypeDefinition} with respect to
a name
+ * space mapping and a CMIS {@link Repository}.
+ *
+ * @param cmisRepository CMIS {@link Repository}
+ * @param cmisType CMIS {@link Type}
+ * @param namespaces name space mapping
+ * @return JCR {@link QNodeTypeDefinition}
* @throws RepositoryException
*/
public static QNodeTypeDefinition jcrNodeTypeDef(Repository cmisRepository, Type cmisType,
@@ -68,22 +69,12 @@
String parentId = cmisType.getParentId();
- Name[] supertypes;
- if (isFolder(cmisType)) {
- supertypes = new Name[] { NameConstants.NT_FOLDER };
- }
- else if (isDocument(cmisType)) {
- supertypes = new Name[] { NameConstants.NT_FILE };
- }
- else if (parentId == null) {
- supertypes = new Name[] { NameConstants.NT_BASE };
- }
- else {
- supertypes = new Name[] { NameTransformer.jcrName(parentId, namespaces) };
- }
+ Name[] supertypes = parentId == null
+ ? new Name[] { NameConstants.NT_BASE }
+ : new Name[] { NameTransformer.jcrName(parentId, namespaces) };
Name[] supportedMixins = null;
- boolean isMixin = isFolder(cmisType);
+ boolean isMixin = isHierarchyNode(cmisType);
boolean isAbstract = false;
boolean isQueryable = cmisType.isQueryable();
boolean hasOrderableChildNodes = false;
@@ -107,12 +98,13 @@
}
/**
- * Transform a CMIS {@link Type} to a JCR {@link QNodeDefinition} with respect to a
- * name space mapping and a declaring node type.
- * @param declaringNodeType {@link Name} of the declaring node type
- * @param cmisType CMIS {@link Type}
- * @param namespaces name space mapping
- * @return JCR {@link QNodeDefinition}
+ * Transform a CMIS {@link Type} to a JCR {@link QNodeDefinition} with respect to a name
space
+ * mapping and a declaring node type.
+ *
+ * @param declaringNodeType {@link Name} of the declaring node type
+ * @param cmisType CMIS {@link Type}
+ * @param namespaces name space mapping
+ * @return JCR {@link QNodeDefinition}
*/
public static QNodeDefinition jcrNodeDef(Name declaringNodeType, Type cmisType,
NamespaceMapping namespaces) {
@@ -133,11 +125,12 @@
/**
* Transform a CMIS {@link PropertyDefinition} to a JCR {@link QPropertyDefinition} with
respect
* to a name space mapping and declaring node type.
- * @param declaringNodeType {@link Name} of the declaring node type
- * @param declaringCmisType CMIS {@link Type} of the declaring node
- * @param cmisPropDef CMIS {@link PropertyDefinition}
- * @param namespaces name space mapping
- * @return JCR {@link QPropertyDefinition}
+ *
+ * @param declaringNodeType {@link Name} of the declaring node type
+ * @param declaringCmisType CMIS {@link Type} of the declaring node
+ * @param cmisPropDef CMIS {@link PropertyDefinition}
+ * @param namespaces name space mapping
+ * @return JCR {@link QPropertyDefinition}
* @throws RepositoryException
*/
public static QPropertyDefinition jcrPropDef(Name declaringNodeType, Type declaringCmisType,
@@ -150,9 +143,8 @@
boolean isProtected = false;
Serializable defaults = cmisPropDef.getDefaultValue();
- QValue[] defaultValues = defaults == null
- ? QValue.EMPTY_ARRAY
- : ValueTransformer.jcrValue(defaults, cmisPropDef.getType());
+ QValue[] defaultValues = defaults == null ? QValue.EMPTY_ARRAY : ValueTransformer.jcrValue(defaults,
+ cmisPropDef.getType());
boolean isMultiple = cmisPropDef.isMultiValued();
int requiredType = jcrPropertyType(cmisPropDef.getType());
@@ -168,8 +160,9 @@
/**
* Transform a CMIS {@link PropertyType} to a JCR {@link javax.jcr.PropertyType}
- * @param cmisPropertyType CMIS {@link PropertyType}
- * @return JCR {@link javax.jcr.PropertyType}
+ *
+ * @param cmisPropertyType CMIS {@link PropertyType}
+ * @return JCR {@link javax.jcr.PropertyType}
*/
public static int jcrPropertyType(org.apache.chemistry.PropertyType cmisPropertyType)
{
return ValueTransformer.getValueTransformer(cmisPropertyType).getJcrPropertyType();
@@ -177,15 +170,16 @@
/**
* Name of the JCR type for a CMIS type with respect to a name space mapping
+ *
* @param cmisType
* @param namespaces
- * @return JCR type Name
+ * @return JCR type Name
*/
public static Name jcrTypeName(Type cmisType, NamespaceMapping namespaces) {
- if (isFolder(cmisType)) {
+ if (isNtFolder(cmisType)) {
return NameConstants.NT_FOLDER;
}
- else if (isDocument(cmisType)) {
+ else if (isNtDocument(cmisType)) {
return NameConstants.NT_FILE;
}
else {
@@ -195,16 +189,14 @@
/**
* Names of the JCR mixins for a CMIS type with respect to a name space mapping
+ *
* @param cmisType
* @param namespaces
- * @return JCR mixin type names
+ * @return JCR mixin type names
*/
public static Name[] jcrMixinNames(Type cmisType, NamespaceMapping namespaces) {
- if (TypeTransformer.isFolder(cmisType)) {
- return new Name[] { NameTransformer.jcrName(BaseType.FOLDER.getId(), namespaces)
};
- }
- else if (TypeTransformer.isDocument(cmisType)) {
- return new Name[] { NameTransformer.jcrName(BaseType.DOCUMENT.getId(), namespaces)
};
+ if (isHierarchyNode(cmisType)) {
+ return new Name[] { NameTransformer.jcrName(cmisType.getId(), namespaces) };
}
else {
return Name.EMPTY_ARRAY;
@@ -212,42 +204,35 @@
}
/**
- * Determines whether a type is a cmis:folder
+ * Determines whether a CMIS type is mapped to a (sub) type of the JCR type nt:file
* @param cmisType
- * @return true iff <code>cmisType</code> is a cmis:folder and no other
sub type
- * of cmis:folder.
+ * @return
*/
- public static boolean isFolder(Type cmisType) {
- return BaseType.FOLDER.getId().equals(cmisType.getId());
+ private static boolean isNtDocument(Type cmisType) {
+ return BaseType.DOCUMENT == cmisType.getBaseType();
}
/**
- * Determines whether a type is a cmis:document
+ * Determines whether a CMIS type is mapped to a (sub) type of the JCR type nt:folder
* @param cmisType
- * @return true iff <code>cmisType</code> is a cmis:document no other sub
type
- * of cmis:document.
+ * @return
*/
- public static boolean isDocument(Type cmisType) {
- return BaseType.DOCUMENT.getId().equals(cmisType.getId());
+ private static boolean isNtFolder(Type cmisType) {
+ return BaseType.FOLDER == cmisType.getBaseType();
}
/**
- * Determines whether a type is a hierarchy type. A hierarchy type is a type whose
- * base type is wither cmis:document or cmis:folder.
+ * Determines whether a type is a hierarchy type. A hierarchy type is a type whose base
type is
+ * either cmis:document or cmis:folder.
+ *
* @param cmisType
- * @return true iff <code>cmisType</code> is a hierarchy type
+ * @return true iff <code>cmisType</code> is a hierarchy type
*/
public static boolean isHierarchyNode(Type cmisType) {
- switch (cmisType.getBaseType()) {
- case DOCUMENT:
- case FOLDER:
- return true;
- default:
- return false;
- }
+ return isNtFolder(cmisType) || isNtDocument(cmisType);
}
- // -----------------------------------------------------< >---
+ // -----------------------------------------------------< >---
private static Set<String> getSuperTypeProperties(Repository cmisRepository, Type
cmisType) {
Set<String> ids = new HashSet<String>();
|