01: /*
02: * $Id: AbstractLoader.java 881 2007-02-12 07:54:31Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.controller;
15:
16: import org.concern.LoaderException;
17: import org.concern.SubjectNotFoundException;
18:
19: import java.util.*;
20: import java.lang.reflect.Array;
21:
22: public abstract class AbstractLoader<S> extends AbstractNode implements
23: Loader<S> {
24: public String getName() {
25: return (String) environment.get("loader.name");
26: }
27:
28: /**
29: * The subjects are loaded one by one.
30: * Please override this method with a more efficient implementation!
31: * @param ids
32: * @return subjects
33: */
34: public S[] load(String[] ids) throws SubjectNotFoundException,
35: LoaderException {
36: if (ids.length == 0)
37: return null;
38:
39: Object[] subjects = new Object[ids.length];
40: for (int i = 0; i < ids.length; i++) {
41: String id = ids[i];
42: subjects[i] = load(id);
43: }
44: S[] ss = (S[]) Array.newInstance(subjects[0].getClass(),
45: subjects.length);
46: System.arraycopy(subjects, 0, ss, 0, subjects.length);
47: return ss;
48: }
49:
50: public Map<String, String> formatSubjectLines(S subject)
51: throws LoaderException {
52: return Collections.singletonMap("*", subject.toString());
53: }
54:
55: public String getOriginator(S o) throws LoaderException {
56: return null;
57: }
58: }
|