01: /*
02: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
03: *
04: * http://izpack.org/
05: * http://izpack.codehaus.org/
06: *
07: * Copyright 2007 Dennis Reil
08: *
09: * Licensed under the Apache License, Version 2.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.apache.org/licenses/LICENSE-2.0
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: */
21: package com.izforge.izpack.installer;
22:
23: import java.lang.reflect.Constructor;
24:
25: import com.izforge.izpack.util.AbstractUIProgressHandler;
26: import com.izforge.izpack.util.Debug;
27:
28: /**
29: * A Factory for getting unpacker instances.
30: *
31: * @author Dennis Reil, <Dennis.Reil@reddot.de>
32: */
33: public abstract class UnpackerFactory {
34: /**
35: * Returns an instance of the desired unpacker class
36: * @param unpackerclassname
37: * @param installdata
38: * @param listener
39: * @return the unpacker
40: */
41: public static IUnpacker getUnpacker(String unpackerclassname,
42: AutomatedInstallData installdata,
43: AbstractUIProgressHandler listener) {
44: IUnpacker unpackerobj = null;
45: try {
46: Class<IUnpacker> unpackerclass = (Class<IUnpacker>) Class
47: .forName(unpackerclassname);
48: Class[] parametertypes = { AutomatedInstallData.class,
49: AbstractUIProgressHandler.class };
50: Constructor<IUnpacker> unpackerconstructor = unpackerclass
51: .getConstructor(parametertypes);
52: Object[] parameter = { installdata, listener };
53: unpackerobj = unpackerconstructor.newInstance(parameter);
54: } catch (NoSuchMethodException e) {
55: Debug.trace("Can't load unpacker: " + unpackerclassname);
56: Debug
57: .trace("Unpacker doesn't implement the desired method");
58: Debug.trace(e);
59: } catch (Exception e) {
60: Debug.trace("Can't load unpacker: " + unpackerclassname);
61: Debug.trace(e);
62: }
63: return unpackerobj;
64: }
65: }
|