View Javadoc
1   package org.kuali.ole.docstore.document.jcr;
2   
3   import org.kuali.ole.docstore.document.DocumentManager;
4   import org.kuali.ole.docstore.model.enums.DocCategory;
5   import org.kuali.ole.docstore.model.enums.DocFormat;
6   import org.kuali.ole.docstore.model.enums.DocType;
7   import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
8   
9   import java.util.HashMap;
10  import java.util.Map;
11  
12  /**
13   * Creates the suitable implementation of DocumentManager for the given document category, type and format.
14   *
15   * @author tirumalesh.b
16   * @version %I%, %G%
17   *          Date: 28/8/12 Time: 12:52 PM
18   */
19  public class JcrDocumentManagerFactory {
20      private static JcrDocumentManagerFactory jcrDocumentManagerFactory = new JcrDocumentManagerFactory();
21      private Map<String, DocumentManager> documentManagerMap = new HashMap<String, DocumentManager>();
22  
23      public static JcrDocumentManagerFactory getInstance() {
24          return jcrDocumentManagerFactory;
25      }
26  
27      private JcrDocumentManagerFactory() {
28          initDocumentManagerMap();
29      }
30  
31      private void initDocumentManagerMap() {
32          String key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.MARC.getCode();
33          documentManagerMap.put(key, JcrWorkBibMarcDocumentManager.getInstance());
34  
35          key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.DUBLIN_CORE.getCode();
36          documentManagerMap.put(key, JcrWorkBibDocumentManager.getInstance());
37  
38          key = DocCategory.WORK.getCode() + DocType.BIB.getDescription() + DocFormat.DUBLIN_UNQUALIFIED.getCode();
39          documentManagerMap.put(key, JcrWorkBibDocumentManager.getInstance());
40  
41          key = DocCategory.WORK.getCode() + DocType.INSTANCE.getCode() + DocFormat.OLEML.getCode();
42          documentManagerMap.put(key, JcrWorkInstanceDocumentManager.getInstance());
43  
44          key = DocCategory.WORK.getCode() + DocType.HOLDINGS.getCode() + DocFormat.OLEML.getCode();
45          documentManagerMap.put(key, JcrJcrWorkHoldingsDocumentManager.getInstance());
46  
47          key = DocCategory.WORK.getCode() + DocType.ITEM.getCode() + DocFormat.OLEML.getCode();
48          documentManagerMap.put(key, JcrWorkItemDocumentManager.getInstance());
49  
50          key = DocCategory.WORK.getCode() + DocType.SOURCEHOLDINGS.getCode() + DocFormat.OLEML.getCode();
51          documentManagerMap.put(key, JcrWorkInstanceDocumentManager.getInstance());
52  
53          key = DocCategory.WORK.getCode() + DocType.LICENSE.getCode() + DocFormat.ONIXPL.getCode();
54          documentManagerMap.put(key, JcrWorkLicenseDocumentManager.getInstance());
55  
56          key = DocCategory.WORK.getCode() + DocType.LICENSE.getCode() + DocFormat.PDF.getCode();
57          documentManagerMap.put(key, JcrWorkLicenseDocumentManager.getInstance());
58  
59          key = DocCategory.WORK.getCode() + DocType.LICENSE.getCode() + DocFormat.DOC.getCode();
60          documentManagerMap.put(key, JcrWorkLicenseDocumentManager.getInstance());
61  
62          key = DocCategory.WORK.getCode() + DocType.LICENSE.getCode() + DocFormat.XSLT.getCode();
63          documentManagerMap.put(key, JcrWorkLicenseDocumentManager.getInstance());
64  
65      }
66  
67      public DocumentManager getDocumentManager(String docCategory, String docType, String docFormat) {
68          return documentManagerMap.get(docCategory + docType + docFormat);
69      }
70  
71      public DocumentManager getDocumentManager(RequestDocument requestDocument) {
72          return documentManagerMap
73                  .get(requestDocument.getCategory() + requestDocument.getType() + requestDocument.getFormat());
74      }
75  }