--- /dev/null
+/** \r
+ * AbstractMultiPartCollectionSpaceResourceImpl.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+package org.collectionspace.services.common;\r
+\r
+import org.collectionspace.services.common.context.MultipartServiceContext;\r
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;\r
+import org.collectionspace.services.common.context.ServiceContext;\r
+import org.collectionspace.services.common.context.ServiceContextFactory;\r
+import org.collectionspace.services.common.document.DocumentHandler;\r
+\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+\r
+/**\r
+ * The Class AbstractMultiPartCollectionSpaceResourceImpl.\r
+ */\r
+public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends\r
+ AbstractCollectionSpaceResourceImpl<MultipartInput, MultipartOutput> {\r
+\r
+ @Override\r
+ public ServiceContextFactory<MultipartInput, MultipartOutput> getServiceContextFactory() {\r
+ return (ServiceContextFactory<MultipartInput, MultipartOutput>)MultipartServiceContextFactory.get();\r
+ }\r
+\r
+ @Override\r
+ public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {\r
+ DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getCommonPartLabel(),\r
+ getCommonPartClass());\r
+ return docHandler;\r
+ }\r
+ \r
+ /**\r
+ * Creates the document handler.\r
+ * \r
+ * @param serviceContext the service context\r
+ * @param schemaName the schema name\r
+ * @param commonClass the common class\r
+ * \r
+ * @return the document handler\r
+ * \r
+ * @throws Exception the exception\r
+ */\r
+ public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> serviceContext,\r
+ String schemaName, \r
+ Class<?> commonClass) throws Exception {\r
+ MultipartServiceContext ctx = (MultipartServiceContext)serviceContext;\r
+ Object commonPart = null;\r
+ if (ctx.getInput() != null) {\r
+ commonPart = ctx.getInputPart(schemaName, commonClass);\r
+ }\r
+ DocumentHandler docHandler = super.createDocumentHandler(ctx, commonPart);\r
+ \r
+ return docHandler;\r
+ }\r
+ \r
+ /**\r
+ * Creates the document handler.\r
+ * \r
+ * @param ctx the ctx\r
+ * @param commonClass the common class\r
+ * \r
+ * @return the document handler\r
+ * \r
+ * @throws Exception the exception\r
+ */\r
+ public DocumentHandler createDocumentHandler(\r
+ ServiceContext<MultipartInput, MultipartOutput> ctx,\r
+ Class<Object> commonClass) throws Exception {\r
+ return createDocumentHandler(ctx, ctx.getCommonPartLabel(), commonClass);\r
+ }\r
+ \r
+}\r
--- /dev/null
+/** \r
+ * RemoteServiceContextFactory.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+package org.collectionspace.services.common.context;\r
+\r
+import javax.ws.rs.core.MultivaluedMap;\r
+\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+\r
+/**\r
+ * A factory for creating RemoteServiceContext objects.\r
+ */\r
+public class RemoteServiceContextFactory<IT, OT>\r
+ implements ServiceContextFactory<IT, OT>{\r
+ \r
+ // create a Factory singleton\r
+ /** The Constant self. */\r
+ final private static RemoteServiceContextFactory self = new RemoteServiceContextFactory();\r
+ \r
+ /**\r
+ * Instantiates a new remote service context factory.\r
+ */\r
+ private RemoteServiceContextFactory() {} // private constructor\r
+ \r
+ /**\r
+ * Gets the.\r
+ * \r
+ * @return the remote service context factory\r
+ */\r
+ public static RemoteServiceContextFactory get() {\r
+ return self;\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String)\r
+ */\r
+ @Override\r
+ public ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {\r
+ RemoteServiceContext<IT, OT> ctx = new RemoteServiceContextImpl<IT, OT>(serviceName);\r
+ return ctx;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object)\r
+ */\r
+ @Override\r
+ public ServiceContext<IT, OT> createServiceContext(String serviceName,\r
+ IT theInput) throws Exception {\r
+ RemoteServiceContext<IT, OT> ctx = new RemoteServiceContextImpl<IT, OT>(serviceName, theInput);\r
+ return ctx;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object, javax.ws.rs.core.MultivaluedMap)\r
+ */\r
+ @Override\r
+ public ServiceContext<IT, OT> createServiceContext(\r
+ String serviceName,\r
+ IT theInput, \r
+ MultivaluedMap<String, String> queryParams) throws Exception {\r
+ ServiceContext<IT, OT> ctx = new RemoteServiceContextImpl<IT, OT>(serviceName,\r
+ theInput,\r
+ queryParams);\r
+ \r
+ return ctx;\r
+ }\r
+\r
+ @Override\r
+ public ServiceContext<IT, OT> createServiceContext(String serviceName,\r
+ IT input, \r
+ MultivaluedMap<String, String> queryParams,\r
+ String documentType,\r
+ String entityName) throws Exception {\r
+ ServiceContext<IT, OT> ctx = createServiceContext(\r
+ serviceName,\r
+ input,\r
+ queryParams);\r
+ ctx.setDocumentType(documentType); //persistence unit\r
+ ctx.setProperty("entity-name", entityName);\r
+ \r
+ return ctx;\r
+ }\r
+ \r
+}\r