01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.util.install;
18:
19: import java.io.File;
20: import java.util.ArrayList;
21: import java.util.Iterator;
22:
23: import org.apache.pluto.util.install.file.jetty.Jetty5FileSystemInstaller;
24: import org.apache.pluto.util.install.file.tomcat5.Tomcat5FileSystemInstaller;
25: import org.apache.pluto.util.install.file.tomcat6.Tomcat6FileSystemInstaller;
26:
27: /**
28: *
29: *
30: */
31: public abstract class PortalInstallerFactory {
32:
33: private static final ArrayList HANDLERS = new ArrayList();
34:
35: static {
36: HANDLERS.add(new Tomcat6FileSystemInstaller());
37: HANDLERS.add(new Tomcat5FileSystemInstaller());
38: HANDLERS.add(new Jetty5FileSystemInstaller());
39: }
40:
41: public static PortalInstaller getAppServerHandler(File installDir) {
42: String className = System
43: .getProperty(PortalInstallerFactory.class.getName());
44: PortalInstaller installer = null;
45: if (className != null) {
46: installer = getHandler(className, installDir);
47: } else {
48: installer = findHandler(installDir);
49: }
50: return installer;
51: }
52:
53: private static PortalInstaller getHandler(String className,
54: File installDir) {
55: PortalInstaller ash;
56: try {
57: Class cl = Class.forName(className);
58: ash = (PortalInstaller) cl.newInstance();
59: if (ash.isValidInstallationDirectory(installDir)) {
60: return ash;
61: } else {
62: throw new Exception(
63: "Invalid installation directory for handler: "
64: + className);
65: }
66: } catch (Exception e) {
67: throw new RuntimeException("Unable to instantiate class: "
68: + className, e);
69: }
70: }
71:
72: private static PortalInstaller findHandler(File installDir) {
73: Iterator it = HANDLERS.iterator();
74: while (it.hasNext()) {
75: PortalInstaller ash = (PortalInstaller) it.next();
76: if (ash.isValidInstallationDirectory(installDir)) {
77: return ash;
78: }
79: }
80: throw new RuntimeException(
81: "Unable to locate appropriate app server handler for: "
82: + installDir.getAbsolutePath());
83: }
84:
85: }
|