chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r1196599 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/...
Date Wed, 02 Nov 2011 14:20:39 GMT
Author: fguillaume
Date: Wed Nov  2 14:20:38 2011
New Revision: 1196599

URL: http://svn.apache.org/viewvc?rev=1196599&view=rev
Log:
CMIS-465: factor out PropertyData creation code

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/BindingsObjectFactory.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/BindingsObjectFactoryImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/BindingsObjectFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/BindingsObjectFactory.java?rev=1196599&r1=1196598&r2=1196599&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/BindingsObjectFactory.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/BindingsObjectFactory.java
Wed Nov  2 14:20:38 2011
@@ -37,12 +37,13 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.PropertyInteger;
 import org.apache.chemistry.opencmis.commons.data.PropertyString;
 import org.apache.chemistry.opencmis.commons.data.PropertyUri;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 
 /**
  * Factory for CMIS binding objects.
- * 
+ *
  * @author <a href="mailto:fmueller@opentext.com">Florian M&uuml;ller</a>
- * 
+ *
  */
 public interface BindingsObjectFactory {
 
@@ -50,6 +51,9 @@ public interface BindingsObjectFactory {
 
     Acl createAccessControlList(List<Ace> aces);
 
+    <T> PropertyData<T> createPropertyData(PropertyDefinition<T> pd,
+            Object value);
+
     PropertyBoolean createPropertyBooleanData(String id, List<Boolean> values);
 
     PropertyBoolean createPropertyBooleanData(String id, Boolean value);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/BindingsObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/BindingsObjectFactoryImpl.java?rev=1196599&r1=1196598&r2=1196599&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/BindingsObjectFactoryImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/BindingsObjectFactoryImpl.java
Wed Nov  2 14:20:38 2011
@@ -38,13 +38,24 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.PropertyInteger;
 import org.apache.chemistry.opencmis.commons.data.PropertyString;
 import org.apache.chemistry.opencmis.commons.data.PropertyUri;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyHtmlDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyIdDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
 
 /**
  * CMIS binding object factory implementation.
- * 
+ *
  * @author <a href="mailto:fmueller@opentext.com">Florian M&uuml;ller</a>
- * 
+ *
  */
 public class BindingsObjectFactoryImpl implements BindingsObjectFactory, Serializable {
 
@@ -69,6 +80,79 @@ public class BindingsObjectFactoryImpl i
         return new PropertiesImpl(properties);
     }
 
+    @SuppressWarnings("unchecked")
+    public <T> AbstractPropertyData<T> createPropertyData(
+            PropertyDefinition<T> pd, Object value) {
+        String id = pd.getId();
+        boolean single = pd.getCardinality() == Cardinality.SINGLE;
+        if (pd instanceof PropertyBooleanDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyBooleanData(id,
+                        (Boolean) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyBooleanData(id,
+                        (List<Boolean>) value);
+            }
+        } else if (pd instanceof PropertyDateTimeDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyDateTimeData(id,
+                        (GregorianCalendar) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyDateTimeData(id,
+                        (List<GregorianCalendar>) value);
+            }
+        } else if (pd instanceof PropertyDecimalDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyDecimalData(id,
+                        (BigDecimal) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyDecimalData(id,
+                        (List<BigDecimal>) value);
+            }
+        } else if (pd instanceof PropertyHtmlDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyHtmlData(id,
+                        (String) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyHtmlData(id,
+                        (List<String>) value);
+            }
+        } else if (pd instanceof PropertyIdDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyIdData(id,
+                        (String) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyIdData(id,
+                        (List<String>) value);
+            }
+        } else if (pd instanceof PropertyIntegerDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyIntegerData(id,
+                        (BigInteger) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyIntegerData(id,
+                        (List<BigInteger>) value);
+            }
+        } else if (pd instanceof PropertyStringDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyStringData(id,
+                        (String) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyStringData(id,
+                        (List<String>) value);
+            }
+        } else if (pd instanceof PropertyUriDefinition) {
+            if (single) {
+                return (AbstractPropertyData<T>) createPropertyUriData(id,
+                        (String) value);
+            } else {
+                return (AbstractPropertyData<T>) createPropertyUriData(id,
+                        (List<String>) value);
+            }
+        }
+        throw new CmisRuntimeException("Unknown property definition: " + pd);
+    }
+
     public PropertyBoolean createPropertyBooleanData(String id, List<Boolean> values)
{
         return new PropertyBooleanImpl(id, values);
     }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1196599&r1=1196598&r2=1196599&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Wed Nov  2 14:20:38 2011
@@ -988,7 +988,6 @@ public class InMemoryObjectServiceImpl e
         return csd;
     }
 
-    @SuppressWarnings("unchecked")
     private Map<String, PropertyData<?>> setDefaultProperties(TypeDefinition
typeDef, Map<String, PropertyData<?>> properties) {
         Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
         boolean hasCopied = false;
@@ -996,61 +995,15 @@ public class InMemoryObjectServiceImpl e
         for ( PropertyDefinition<?> propDef : propDefs.values()) {
             String propId = propDef.getId();
             List<?> defaultVal = propDef.getDefaultValue();
-            PropertyData<?> pd = null;
             if (defaultVal != null && null == properties.get(propId)) {
                 if (!hasCopied) {
                     properties = new HashMap<String, PropertyData<?>>(properties);
// copy because it is an unmodified collection
                     hasCopied = true;
                 }
-                if (propDef.getPropertyType() == PropertyType.BOOLEAN) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyBooleanData(propId,
(List<Boolean>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyBooleanData(propId,
(Boolean)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.DATETIME) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyDateTimeData(propId,
(List<GregorianCalendar>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyDateTimeData(propId,
(GregorianCalendar)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.DECIMAL) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyDecimalData(propId,
(List<BigDecimal>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyDecimalData(propId,
(BigDecimal)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.HTML) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyHtmlData(propId,
(List<String>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyHtmlData(propId,
(String)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.ID) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyIdData(propId,
(List<String>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyIdData(propId,
(String)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.INTEGER) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyIntegerData(propId,
(List<BigInteger>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyIntegerData(propId,
(BigInteger)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.STRING) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyStringData(propId,
(List<String>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyStringData(propId,
(String)defaultVal.get(0));
-                    }
-                } else if (propDef.getPropertyType() == PropertyType.URI) {
-                    if (propDef.getCardinality() == Cardinality.MULTI) {
-                        pd = fStoreManager.getObjectFactory().createPropertyUriData(propId,
(List<String>)defaultVal);
-                    } else {
-                        pd = fStoreManager.getObjectFactory().createPropertyUriData(propId,
(String)defaultVal.get(0));
-                    }
-                }
+                Object value = propDef.getCardinality() == Cardinality.SINGLE ? defaultVal.get(0)
+                        : defaultVal;
+                PropertyData<?> pd = fStoreManager.getObjectFactory().createPropertyData(
+                        propDef, value);
                 // set property:
                 properties.put(propId, pd);
             }



Mime
View raw message