]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-502 separated fillPart into a protected method so that it could be overridden.
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 5 Oct 2009 22:54:59 +0000 (22:54 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 5 Oct 2009 22:54:59 +0000 (22:54 +0000)
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java

index 5c2fb152c8f3a0ed2960bfc9226ebe440d648b16..aa3c1437005e94fcd72ed4fcf14cbb222b5a63e7 100644 (file)
@@ -58,9 +58,9 @@ public abstract class RemoteDocumentModelHandler<T, TL>
     public void setServiceContext(ServiceContext ctx) {
         if(ctx instanceof RemoteServiceContext){
             super.setServiceContext(ctx);
-        } else {
-        throw new IllegalArgumentException("setServiceContext requires instance of " +
-                RemoteServiceContext.class.getName());
+        }else{
+            throw new IllegalArgumentException("setServiceContext requires instance of " +
+                    RemoteServiceContext.class.getName());
         }
     }
 
@@ -122,22 +122,35 @@ public abstract class RemoteDocumentModelHandler<T, TL>
             if(!partsMetaMap.containsKey(partLabel)){
                 continue;
             }
-            InputStream payload = part.getBody(InputStream.class, null);
-
-            //check if this is an xml part
-            if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){
-                if(payload != null){
-                    Document document = DocumentUtils.parseDocument(payload);
-                    //TODO: callback to handler if registered to validate the
-                    //document
-                    Map<String, Object> objectProps = DocumentUtils.parseProperties(document);
-                    docModel.setProperties(partLabel, objectProps);
-                }
-            }
+            ObjectPartType partMeta = partsMetaMap.get(partLabel);
+            fillPart(part, docModel, partMeta);
         }//rof
 
     }
 
+    /**
+     * fillPart fills an XML part into given document model
+     * @param part to fill
+     * @param docModel for the given object
+     * @param partMeta metadata for the object to fill
+     * @throws Exception
+     */
+    protected void fillPart(InputPart part, DocumentModel docModel, ObjectPartType partMeta)
+            throws Exception {
+        InputStream payload = part.getBody(InputStream.class, null);
+
+        //check if this is an xml part
+        if(part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)){
+            if(payload != null){
+                Document document = DocumentUtils.parseDocument(payload);
+                //TODO: callback to handler if registered to validate the
+                //document
+                Map<String, Object> objectProps = DocumentUtils.parseProperties(document);
+                docModel.setProperties(partMeta.getLabel(), objectProps);
+            }
+        }
+    }
+
     /**
      * extractPart extracts an XML object from given DocumentModel
      * @param docModel