1 package ch
.cyberduck
.core
;
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch
.cyberduck
.core
.preferences
.Preferences
;
21 import ch
.cyberduck
.core
.preferences
.PreferencesFactory
;
22 import ch
.cyberduck
.core
.transfer
.DisabledTransferErrorCallback
;
23 import ch
.cyberduck
.core
.transfer
.TransferErrorCallback
;
25 import org
.apache
.commons
.lang3
.reflect
.ConstructorUtils
;
26 import org
.apache
.log4j
.Logger
;
28 import java
.lang
.reflect
.Constructor
;
29 import java
.lang
.reflect
.InvocationTargetException
;
34 public class TransferErrorCallbackControllerFactory
extends Factory
<TransferErrorCallback
> {
35 private static final Logger log
= Logger
.getLogger(TransferErrorCallbackControllerFactory
.class);
37 private static final Preferences preferences
38 = PreferencesFactory
.get();
40 public TransferErrorCallback
create(final Controller c
) {
41 final String clazz
= preferences
.getProperty("factory.transfererrorcallback.class");
43 throw new FactoryException(String
.format("No implementation given for factory %s", this.getClass().getSimpleName()));
46 final Class
<TransferErrorCallback
> name
= (Class
<TransferErrorCallback
>) Class
.forName(clazz
);
47 final Constructor
<TransferErrorCallback
> constructor
= ConstructorUtils
.getMatchingAccessibleConstructor(name
, c
.getClass());
48 if(null == constructor
) {
49 log
.warn(String
.format("No matching constructor for parameter %s", c
.getClass()));
50 // Call default constructor for disabled implementations
51 return name
.newInstance();
53 return constructor
.newInstance(c
);
55 catch(InstantiationException
| InvocationTargetException
| ClassNotFoundException
| IllegalAccessException e
) {
56 log
.error(String
.format("Failure loading callback class %s. %s", clazz
, e
.getMessage()));
57 return new DisabledTransferErrorCallback();
62 * @param c Window controller
63 * @return Login controller instance for the current platform.
65 public static TransferErrorCallback
get(final Controller c
) {
66 return new TransferErrorCallbackControllerFactory().create(c
);