CMISScope enum now consistent with all other CMIS enums

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13811 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2009-04-02 14:20:13 +00:00
parent 440af3f96c
commit b19a68fa34
2 changed files with 24 additions and 32 deletions

View File

@@ -24,9 +24,6 @@
*/ */
package org.alfresco.cmis; package org.alfresco.cmis;
import java.util.HashMap;
import java.util.Map;
/** /**
* The scope for a CMIS name * The scope for a CMIS name
@@ -38,39 +35,34 @@ import java.util.Map;
* @author andyh * @author andyh
* *
*/ */
public enum CMISScope public enum CMISScope implements EnumLabel
{ {
OBJECT ('O'), OBJECT ("O"),
RELATIONSHIP ('R'), RELATIONSHIP ("R"),
DOCUMENT ('D'), DOCUMENT ("D"),
FOLDER ('F'), FOLDER ("F"),
POLICY ('P'), POLICY ("P"),
UNKNOWN ('U'); UNKNOWN ("U");
private static Map<Character, CMISScope> discriminatorMap = new HashMap<Character, CMISScope>(10); private String label;
static
/**
* Construct
*
* @param label
*/
CMISScope(String label)
{ {
for (CMISScope scope : CMISScope.values()) this.label = label;
{
discriminatorMap.put(scope.discriminator, scope);
}
}
private char discriminator;
CMISScope(char discriminator)
{
this.discriminator = discriminator;
} }
public char discriminator() /* (non-Javadoc)
* @see org.alfresco.cmis.EnumLabel#label()
*/
public String getLabel()
{ {
return discriminator; return label;
} }
public static CMISScope toScope(char discrimator) public static EnumFactory<CMISScope> FACTORY = new EnumFactory<CMISScope>(CMISScope.class);
{
return discriminatorMap.get(discrimator);
}
} }

View File

@@ -234,7 +234,7 @@ public class CMISMapping implements InitializingBean
} }
// Alfresco type id // Alfresco type id
CMISScope scope = CMISScope.toScope(typeId.charAt(0)); CMISScope scope = (CMISScope)CMISScope.FACTORY.fromLabel(typeId.substring(0, 1));
if (scope == null) if (scope == null)
{ {
throw new AlfrescoRuntimeException("Malformed type id '" + typeId + "'; discriminator " + typeId.charAt(0) + " unknown"); throw new AlfrescoRuntimeException("Malformed type id '" + typeId + "'; discriminator " + typeId.charAt(0) + " unknown");
@@ -257,7 +257,7 @@ public class CMISMapping implements InitializingBean
if (typeId == null) if (typeId == null)
{ {
StringBuilder builder = new StringBuilder(128); StringBuilder builder = new StringBuilder(128);
builder.append(scope.discriminator()); builder.append(scope.getLabel());
builder.append("/"); builder.append("/");
builder.append(buildPrefixEncodedString(typeQName, false)); builder.append(buildPrefixEncodedString(typeQName, false));
return new CMISTypeId(scope, builder.toString(), typeQName); return new CMISTypeId(scope, builder.toString(), typeQName);