1 23 package com.sun.enterprise.diagnostics; 24 import com.sun.logging.LogDomains; 25 26 import java.util.logging.Logger ; 27 import java.util.logging.Level ; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.io.File ; 31 import java.util.Iterator ; 32 36 public abstract class TargetResolver { 37 38 protected String target; 39 protected String repositoryName; 40 protected String repositoryDir; 41 protected boolean local; 42 protected TargetType type; 43 protected List <String > instances = new ArrayList (1); 44 protected ReportTarget reportTarget; 45 protected List <ServiceConfig> serviceConfigs = new ArrayList (1); 46 protected ExecutionContext context; 47 48 protected static String DEFAULT_FEATURES_PROPERTY_CLASS = 49 "com.sun.enterprise.admin.pluggable.PEClientPluggableFeatureImpl"; 50 51 protected Logger logger = 52 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 53 54 public TargetResolver(String target, String 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 <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 determineTargetType(); 95 determineRepositoryDetails(); 96 determineInstances(); 97 determineServiceConfigs(); 98 logger.log(Level.FINE,"diagnostic-service.target_details", 99 new Object [] {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 instanceName) { 111 instances.add(instanceName); 112 } 113 114 protected void determineServiceConfigs() { 115 if(instances != null) { 116 Iterator <String > iterator = instances.iterator(); 117 while(iterator.hasNext()) { 118 addServiceConfig(iterator.next()); 119 } 120 } 121 } 122 123 protected void addServiceConfig(String instanceName) { 124 String instanceRepDir = repositoryDir + File.separator + 125 repositoryName ; 126 127 if ((!(instanceName.equals(Constants.SERVER))) && 128 (!(type.equals(TargetType.INSTANCE)))){ 129 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 getLogger() { 153 return logger; 154 } 155 156 } 157 | Popular Tags |