KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.sun.logging.LogDomains;
25
26 import java.util.logging.Logger JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.io.File JavaDoc;
31 import java.util.Iterator JavaDoc;
32 /**
33  *
34  * @author mu125243
35  */

36 public abstract class TargetResolver {
37     
38     protected String JavaDoc target;
39     protected String JavaDoc repositoryName;
40     protected String JavaDoc repositoryDir;
41     protected boolean local;
42     protected TargetType type;
43     protected List JavaDoc<String JavaDoc> instances = new ArrayList JavaDoc(1);
44     protected ReportTarget reportTarget;
45     protected List JavaDoc<ServiceConfig> serviceConfigs = new ArrayList JavaDoc(1);
46     protected ExecutionContext context;
47     
48     protected static String JavaDoc DEFAULT_FEATURES_PROPERTY_CLASS =
49             "com.sun.enterprise.admin.pluggable.PEClientPluggableFeatureImpl";
50     
51     protected Logger JavaDoc logger =
52             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
53     /** Creates a new instance of TargetResolver */
54     public TargetResolver(String JavaDoc target, String JavaDoc repositoryDir, boolean local) {
55         this.target = target;
56         this.repositoryDir = repositoryDir;
57         this.local = local;
58     }
59     
60     public ReportTarget resolve() throws DiagnosticException {
61         if(validateTarget()) {
62             createTarget();
63             return reportTarget;
64         }
65         throw new InvalidTargetException(" Unable to resolve target : " + target);
66     }
67     
68     
69     public abstract boolean validateTarget() throws DiagnosticException;
70
71     
72     public ExecutionContext getExecutionContext() {
73         return context;
74     }
75     
76     
77      public List JavaDoc<ServiceConfig> getServiceConfigs() {
78         return serviceConfigs;
79      }
80      
81  
82    
83     protected void createTarget() throws DiagnosticException {
84         setExecutionContext();
85         initLogger();
86         determineTargetDetails();
87         createTargetObject();
88     }
89     
90     protected abstract void setExecutionContext();
91     
92     protected void determineTargetDetails() {
93         //determineTargetDir();
94
determineTargetType();
95         determineRepositoryDetails();
96         determineInstances();
97         determineServiceConfigs();
98         logger.log(Level.FINE,"diagnostic-service.target_details",
99                 new Object JavaDoc[] {target, repositoryDir, type, instances});
100     }
101     
102     protected abstract void determineRepositoryDetails() ;
103     protected abstract void determineTargetType() ;
104     protected abstract void determineInstances();
105     
106     protected void setTargetType(TargetType type) {
107         this.type = type;
108     }
109
110     protected void addInstance(String JavaDoc instanceName) {
111         instances.add(instanceName);
112     }
113     
114     protected void determineServiceConfigs() {
115         if(instances != null) {
116             Iterator JavaDoc<String JavaDoc> iterator = instances.iterator();
117             while(iterator.hasNext()) {
118                 addServiceConfig(iterator.next());
119             }
120         }
121     }
122     
123     protected void addServiceConfig(String JavaDoc instanceName) {
124         String JavaDoc instanceRepDir = repositoryDir + File.separator +
125                             repositoryName ;
126
127         if ((!(instanceName.equals(Constants.SERVER))) &&
128                 (!(type.equals(TargetType.INSTANCE)))){
129             // for example in case of node agent this value would be
130
//nodeagents/na1/instance1
131
instanceRepDir = instanceRepDir + File.separator + instanceName;
132         }
133                     
134                 
135         ServiceConfig instanceConfig = ServiceConfigFactory.getInstance().
136                         getServiceConfig(context.isLocal(), instanceRepDir,
137                         instanceName);
138         if(instanceConfig != null)
139             serviceConfigs.add(instanceConfig);
140     }
141     
142     
143     protected void createTargetObject() {
144         reportTarget = new ReportTarget(repositoryDir, repositoryName, target,
145         type, instances, local);
146     }
147     
148     private void initLogger() {
149         logger = context.getLogger();
150     }
151
152     private Logger JavaDoc getLogger() {
153         return logger;
154     }
155  
156 }
157
Popular Tags