1 34 package org.dspace.checker; 35 36 import java.sql.SQLException ; 37 import java.util.ArrayList ; 38 import java.util.List ; 39 40 import org.apache.log4j.Logger; 41 import org.dspace.content.DSpaceObject; 42 import org.dspace.core.Constants; 43 import org.dspace.core.Context; 44 import org.dspace.handle.HandleManager; 45 46 55 public class HandleDispatcher implements BitstreamDispatcher 56 { 57 58 59 private static final Logger LOG = Logger.getLogger(HandleDispatcher.class); 60 61 62 String handle = null; 63 64 65 Boolean init = Boolean.FALSE; 66 67 68 ListDispatcher delegate = null; 69 70 73 BitstreamInfoDAO bitstreamInfoDAO; 74 75 78 private HandleDispatcher() 79 { 80 ; 81 } 82 83 89 public HandleDispatcher(BitstreamInfoDAO bitInfoDAO, String hdl) 90 { 91 bitstreamInfoDAO = bitInfoDAO; 92 handle = hdl; 93 } 94 95 101 private void init() 102 { 103 Context context = null; 104 int dsoType = -1; 105 106 int id = -1; 107 try 108 { 109 context = new Context(); 110 DSpaceObject dso = HandleManager.resolveToObject(context, handle); 111 id = dso.getID(); 112 dsoType = dso.getType(); 113 context.abort(); 114 115 } 116 catch (SQLException e) 117 { 118 LOG.error("init error " + e.getMessage(), e); 119 throw new RuntimeException ("init error" + e.getMessage(), e); 120 121 } 122 finally 123 { 124 if ((context != null) && context.isValid()) 126 { 127 context.abort(); 128 } 129 } 130 131 List ids = new ArrayList (); 132 133 switch (dsoType) 134 { 135 case Constants.BITSTREAM: 136 ids.add(new Integer (id)); 137 break; 138 139 case Constants.ITEM: 140 ids = bitstreamInfoDAO.getItemBitstreams(id); 141 break; 142 143 case Constants.COLLECTION: 144 ids = bitstreamInfoDAO.getCollectionBitstreams(id); 145 break; 146 147 case Constants.COMMUNITY: 148 ids = bitstreamInfoDAO.getCommunityBitstreams(id); 149 break; 150 } 151 152 delegate = new ListDispatcher(ids); 153 init = Boolean.TRUE; 154 } 155 156 161 public int next() 162 { 163 synchronized (init) 164 { 165 if (init == Boolean.FALSE) 166 { 167 init(); 168 } 169 } 170 171 return delegate.next(); 172 } 173 } 174 | Popular Tags |