KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > installer > UnpackerFactory


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2007 Dennis Reil
8  *
9  * 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 JavaDoc;
24
25 import com.izforge.izpack.util.AbstractUIProgressHandler;
26 import com.izforge.izpack.util.Debug;
27
28
29 /**
30  * A Factory for getting unpacker instances.
31  *
32  * @author Dennis Reil, <Dennis.Reil@reddot.de>
33  */

34 public abstract class UnpackerFactory
35 {
36     /**
37      * Returns an instance of the desired unpacker class
38      * @param unpackerclassname
39      * @param installdata
40      * @param listener
41      * @return
42      */

43     public static IUnpacker getUnpacker(String JavaDoc unpackerclassname, AutomatedInstallData installdata, AbstractUIProgressHandler listener){
44         IUnpacker unpackerobj = null;
45         try
46         {
47             Class JavaDoc unpackerclass = Class.forName(unpackerclassname);
48             Class JavaDoc[] parametertypes = {AutomatedInstallData.class, AbstractUIProgressHandler.class};
49             Constructor JavaDoc unpackerconstructor = unpackerclass.getConstructor(parametertypes);
50             Object JavaDoc[] parameter = {installdata,listener};
51             unpackerobj = (IUnpacker) unpackerconstructor.newInstance(parameter);
52         }
53         catch (NoSuchMethodException JavaDoc e)
54         {
55             Debug.trace("Can't load unpacker: " + unpackerclassname);
56             Debug.trace("Unpacker doesn't implement the desired method");
57             Debug.trace(e);
58         }
59         catch (Exception JavaDoc e)
60         {
61             Debug.trace("Can't load unpacker: " + unpackerclassname);
62             Debug.trace(e);
63         }
64         return unpackerobj;
65     }
66 }
67
Popular Tags