KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > ServiceConfigFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  * Responsible for creating ServiceConfig object per configuration in
30  * domain.xml
31  * @author mu125243
32  */

33 public class ServiceConfigFactory {
34     
35     /**
36      * Map between a config and it's diagnostic service configuration.
37      * Multiple instances may be using same configuration in which case
38      * there is only one ServiceConfig object for those instances.
39      */

40     private static Map JavaDoc diagnosticServiceConfigs;
41     
42     /**
43      * instance name to config name map
44      */

45     private static Map JavaDoc instanceConfigMap;
46     
47     /**
48      * Config with default values
49      */

50     private static ServiceConfig defaultConfig;
51     
52     private static ServiceConfigFactory configFactory;
53     
54     /** Creates a new instance of ServiceConfigFactory */
55     private ServiceConfigFactory() {
56         diagnosticServiceConfigs = new HashMap JavaDoc(5);
57         instanceConfigMap = new HashMap JavaDoc(5);
58     }
59     
60     /**
61      * Returns a ServiceConfgiFactory object
62      * @return ServiceConfigFactory
63      */

64     public static ServiceConfigFactory getInstance() {
65         if (configFactory == null)
66             configFactory = new ServiceConfigFactory();
67         
68         return configFactory;
69     }
70     
71     /**
72      * @return ServiceConfig with default values
73      */

74     public static ServiceConfig getDefaultServiceConfig() {
75             if( defaultConfig == null) {
76                 defaultConfig = new ServiceConfig(true,true, true,
77                     true,true, true, Defaults.MIN_LOG_LEVEL,
78                     Defaults.MAX_NO_OF_ENTRIES, Defaults.LOG_FILE, null, null);
79                 return defaultConfig;
80             }
81         return null;
82     }
83     
84     /**
85      * Gets service config for a instance.
86      * @param instanceName instance name
87      * @return diagnostic-service configuration
88      */

89     public ServiceConfig getServiceConfig(String JavaDoc instanceName) {
90         if (instanceName != null) {
91             String JavaDoc configName = (String JavaDoc)instanceConfigMap.get(instanceName);
92             return (ServiceConfig)diagnosticServiceConfigs.get(configName);
93         }
94         return null;
95     }
96     
97     /**
98      * Gets diagnostic-service configuration
99      * @param local flag which indicates whether command is run in local or remote
100      * @param repositoryRoot local/central repository root
101      * @param instanceName name of the instance
102      * @return diagnostic-service configuration for a instance
103      *
104      */

105     public ServiceConfig getServiceConfig(boolean local, String JavaDoc repositoryRoot,
106             String JavaDoc instanceName) {
107         if (repositoryRoot != null && instanceName != null) {
108             try {
109                 
110                 ServiceConfig config = new ServiceConfig(local,
111                         repositoryRoot, instanceName);
112                 return config;
113             }catch(Exception JavaDoc de) {
114                 // If for some reason diagnostic-service element in domain.xml
115
// is not readable, return diagnostic information with
116
// default values.
117
return getDefaultServiceConfig();
118             }
119         }
120         return null;
121     }
122 }
123
Popular Tags