KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > config > KernelConfigFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.kernel.plugins.config;
23
24 import org.jboss.kernel.spi.config.KernelConfig;
25 import org.jboss.kernel.plugins.config.property.PropertyKernelConfig;
26
27 import java.util.Properties JavaDoc;
28
29 /**
30  * Implementation of the Factory design pattern used in constructing new
31  * instances of {@link KernelConfig KernelConfig} objects based on various
32  * configuration sources.
33  *
34  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
35  * @version <tt>$Revision: 57307 $</tt>
36  */

37 public class KernelConfigFactory {
38
39    /**
40     * Constructs a new KernelConfig instance based on the System properties.
41     * <p>If any necessary KernelConfig properties are not found in the System
42     * properties, sensible default implementations for the missing
43     * properties will be used.
44     * @return a new <tt>KernelConfig</tt> instance based on the
45     * System properties.
46     * @see System#getProperties()
47     * @see #newInstance(Properties)
48     */

49    public static KernelConfig newInstance() {
50       //for the values not found in the System properties, default values
51
//used are from the KernelConstants interface. See
52
//the PropertyKernelConfig class implementation for more details.
53
return newInstance( System.getProperties() );
54    }
55
56    /**
57     * Constructs a new <tt>KernelConfig</tt> instance based on the specified
58     * <tt>Properties</tt>.
59     * <p>If any necessary KernelConfig properties are not found in the given
60     * properties, sensible default implementations for the missing
61     * properties will be used.
62     * @param props the properties to use when creating a new
63     * <tt>KernelConfig</tt> instance.
64     * @return a new <tt>KernelConfig</tt> instance based on the specified
65     * <tt>Properties</tt>
66     * @see PropertyKernelConfig
67     */

68    public static KernelConfig newInstance( Properties JavaDoc props ) {
69       KernelConfig cfg;
70       try
71       {
72          //for the values not found in the given props, default values
73
//used are from the KernelConstants interface. See
74
//the PropertyKernelConfig class implementation for more details.
75
cfg = new PropertyKernelConfig( props );
76       }
77       catch ( Throwable JavaDoc t )
78       {
79          String JavaDoc msg = "Unable to construct a " +
80             PropertyKernelConfig.class.getName() +
81             " instance based on the specified properties.";
82          throw new RuntimeException JavaDoc( msg, t );
83       }
84
85       return cfg;
86    }
87 }
88
Popular Tags