1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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.geronimo.st.v11.core; 18 19 import javax.xml.bind.JAXBElement; 20 21 import org.apache.geronimo.st.core.GeronimoUtils; 22 import org.apache.geronimo.st.core.internal.Trace; 23 import org.apache.geronimo.st.core.jaxb.JAXBUtils; 24 import org.apache.geronimo.xml.ns.deployment_1.ArtifactType; 25 import org.apache.geronimo.xml.ns.deployment_1.EnvironmentType; 26 import org.apache.geronimo.xml.ns.j2ee.application_1.ApplicationType; 27 import org.apache.geronimo.xml.ns.j2ee.connector_1.ConnectorType; 28 import org.apache.geronimo.xml.ns.j2ee.web_1.WebAppType; 29 import org.eclipse.core.resources.IFile; 30 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; 31 import org.eclipse.wst.server.core.IModule; 32 import org.openejb.xml.ns.openejb_jar_2.OpenejbJarType; 33 34 /** 35 * @version $Rev: 471551 $ $Date: 2006-11-05 17:47:11 -0500 (Sun, 05 Nov 2006) $ 36 */ 37 public class GeronimoV11Utils extends GeronimoUtils { 38 39 public static JAXBElement getDeploymentPlan(IFile file) throws Exception { 40 Trace.tracePoint("ENTRY", "GeronimoV11Utils.getDeploymentPlan", file); 41 42 if (!file.exists()) { 43 return null; 44 } 45 46 if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME)) 47 return getApplicationDeploymentPlan(file); 48 else if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME)) 49 return getOpenEjbDeploymentPlan(file); 50 else if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME)) 51 return getWebDeploymentPlan(file); 52 else if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME)) 53 return getConnectorDeploymentPlan(file); 54 else if (file.getName().equals(GeronimoUtils.APP_CLIENT_PLAN_NAME)) 55 return getApplicationClientDeploymentPlan(file); 56 57 Trace.tracePoint("EXIT", "GeronimoV11Utils.getDeploymentPlan", null); 58 return null; 59 } 60 61 // public static String getConfigId2(IModule module) { 62 // 63 // IFile planFile = null; 64 // IVirtualComponent comp = 65 // ComponentCore.createComponent(module.getProject()); 66 // if (isWebModule(module)) { 67 // planFile = GeronimoUtils.getWebDeploymentPlanFile(comp); 68 // } else if (isEjbJarModule(module)) { 69 // planFile = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp); 70 // } else if (isEarModule(module)) { 71 // planFile = GeronimoUtils.getApplicationDeploymentPlanFile(comp); 72 // } else if (isRARModule(module)) { 73 // planFile = GeronimoUtils.getConnectorDeploymentPlanFile(comp); 74 // } 75 // 76 // if(planFile != null) { 77 // try { 78 // XmlObject xmlObject = 79 // XmlBeansUtil.parse(planFile.getLocation().toFile()); 80 // XmlCursor cursor = xmlObject.newCursor(); 81 // cursor.toFirstChild(); 82 // xmlObject = cursor.getObject(); 83 // XmlObject result[] = 84 // xmlObject.selectChildren(QNameSet.singleton(EnvironmentDocument.type.getDocumentElementName())); 85 // if(result != null && result.length > 0) { 86 // org.apache.geronimo.deployment.xbeans.EnvironmentType env = 87 // (org.apache.geronimo.deployment.xbeans.EnvironmentType) 88 // result[0].changeType(org.apache.geronimo.deployment.xbeans.EnvironmentType.type); 89 // org.apache.geronimo.deployment.xbeans.ArtifactType moduleId = 90 // env.getModuleId(); 91 // return getQualifiedConfigID(moduleId); 92 // } 93 // } catch (IOException e) { 94 // e.printStackTrace(); 95 // } catch (XmlException e) { 96 // e.printStackTrace(); 97 // } 98 // } 99 // 100 // return null; 101 // } 102 103 public static String getConfigId(IModule module) throws Exception { 104 105 EnvironmentType environment = null; 106 if (isWebModule(module)) { 107 JAXBElement<WebAppType> webapptype=getWebDeploymentPlan(module); 108 WebAppType plan = webapptype.getValue(); 109 if (plan != null) 110 environment = plan.getEnvironment(); 111 } else if (isEjbJarModule(module)) { 112 OpenejbJarType plan = getOpenEjbDeploymentPlan(module).getValue(); 113 // if (plan != null) 114 // environment = plan.getEnvironment(); 115 } else if (isEarModule(module)) { 116 ApplicationType plan = getApplicationDeploymentPlan(module).getValue(); 117 if (plan != null) 118 environment = plan.getEnvironment(); 119 } else if (isRARModule(module)) { 120 ConnectorType plan = getConnectorDeploymentPlan(module).getValue(); 121 if (plan != null) 122 environment = plan.getEnvironment(); 123 } 124 if (environment != null 125 && environment.getModuleId() != null) { 126 Trace.tracePoint("EXIT", "GeronimoV11Utils.getConfigId", getQualifiedConfigID(environment.getModuleId())); 127 return getQualifiedConfigID(environment.getModuleId()); 128 } 129 130 return getId(module); 131 } 132 133 // public static String getQualifiedConfigID(ArtifactType artifact) { 134 // return getQualifiedConfigID(artifact.getGroupId(), artifact 135 // .getArtifactId(), artifact.getVersion(), artifact.getType()); 136 // } 137 138 public static String getQualifiedConfigID( 139 ArtifactType artifact) { 140 return getQualifiedConfigID(artifact.getGroupId(), artifact 141 .getArtifactId(), artifact.getVersion(), artifact.getType()); 142 } 143 144 public static String getQualifiedConfigID(String groupId, 145 String artifactId, String version, String type) { 146 return groupId + "/" + artifactId + "/" + version + "/" + type; 147 } 148 149 public static String getContextRoot(IModule module) throws Exception { 150 String contextRoot = null; 151 152 WebAppType deploymentPlan = getWebDeploymentPlan(module).getValue(); 153 if (deploymentPlan != null) 154 contextRoot = deploymentPlan.getContextRoot(); 155 156 if (contextRoot == null) 157 contextRoot = GeronimoUtils.getContextRoot(module); 158 159 return contextRoot; 160 } 161 162 public static JAXBElement<WebAppType> getWebDeploymentPlan(IModule module) 163 throws Exception { 164 return getWebDeploymentPlan(getVirtualComponent(module)); 165 } 166 167 public static JAXBElement<ApplicationType> getApplicationDeploymentPlan( 168 IModule module) throws Exception { 169 return getApplicationDeploymentPlan(getVirtualComponent(module)); 170 } 171 172 public static JAXBElement<OpenejbJarType> getOpenEjbDeploymentPlan( 173 IModule module) throws Exception { 174 return getOpenEjbDeploymentPlan(getVirtualComponent(module)); 175 } 176 177 public static JAXBElement<ConnectorType> getConnectorDeploymentPlan( 178 IModule module) throws Exception { 179 return getConnectorDeploymentPlan(getVirtualComponent(module)); 180 } 181 182 public static JAXBElement getApplicationDeploymentPlan( 183 IVirtualComponent comp) throws Exception { 184 return getApplicationDeploymentPlan(getApplicationDeploymentPlanFile(comp)); 185 } 186 187 public static JAXBElement getApplicationClientDeploymentPlan(IFile file) 188 throws Exception { 189 Trace.tracePoint("ENTRY", 190 "GeronimoV11Utils.getApplicationClientDeploymentPlan", file); 191 192 if (file.getName().equals(APP_CLIENT_PLAN_NAME) && file.exists()) { 193 return JAXBUtils.unmarshalFilterDeploymentPlan(file); 194 } 195 196 Trace.tracePoint("EXIT", 197 "GeronimoV11Utils.getApplicationClientDeploymentPlan", null); 198 return null; 199 } 200 201 public static JAXBElement getWebDeploymentPlan(IVirtualComponent comp) 202 throws Exception { 203 return getWebDeploymentPlan(getWebDeploymentPlanFile(comp)); 204 } 205 206 public static JAXBElement getOpenEjbDeploymentPlan(IVirtualComponent comp) 207 throws Exception { 208 return getOpenEjbDeploymentPlan(getOpenEjbDeploymentPlanFile(comp)); 209 } 210 211 public static JAXBElement getConnectorDeploymentPlan(IVirtualComponent comp) 212 throws Exception { 213 return getConnectorDeploymentPlan(getConnectorDeploymentPlanFile(comp)); 214 } 215 216 public static JAXBElement getApplicationDeploymentPlan(IFile file) throws Exception { 217 Trace.tracePoint("ENTRY", 218 "GeronimoV11Utils.getApplicationClientDeploymentPlan", file); 219 220 if (file.getName().equals(APP_PLAN_NAME) && file.exists()) { 221 return JAXBUtils.unmarshalFilterDeploymentPlan(file); 222 } 223 224 Trace.tracePoint("EXIT", 225 "GeronimoV11Utils.getApplicationClientDeploymentPlan", null); 226 return null; 227 } 228 229 public static JAXBElement getWebDeploymentPlan(IFile file) throws Exception { 230 Trace 231 .tracePoint("ENTRY", "GeronimoV11Utils.getWebDeploymentPlan", 232 file); 233 234 if (file.getName().equals(WEB_PLAN_NAME) && file.exists()) { 235 return JAXBUtils.unmarshalFilterDeploymentPlan(file); 236 } 237 238 Trace.tracePoint("EXIT", "GeronimoV11Utils.getWebDeploymentPlan", null); 239 return null; 240 } 241 242 public static JAXBElement getOpenEjbDeploymentPlan(IFile file) 243 throws Exception { 244 Trace.tracePoint("ENTRY", "GeronimoV11Utils.getOpenEjbDeploymentPlan", 245 file); 246 247 if (file.getName().equals(OPENEJB_PLAN_NAME) && file.exists()) { 248 return JAXBUtils.unmarshalFilterDeploymentPlan(file); 249 } 250 251 Trace.tracePoint("EXIT", "GeronimoV11Utils.getOpenEjbDeploymentPlan", 252 null); 253 return null; 254 } 255 256 public static JAXBElement getConnectorDeploymentPlan(IFile file) 257 throws Exception { 258 Trace.tracePoint("ENTRY", 259 "GeronimoV11Utils.getConnectorDeploymentPlan", file); 260 261 if (file.getName().equals(CONNECTOR_PLAN_NAME) && file.exists()) { 262 return JAXBUtils.unmarshalFilterDeploymentPlan(file); 263 } 264 265 Trace.tracePoint("EXIT", "GeronimoV11Utils.getConnectorDeploymentPlan", 266 null); 267 return null; 268 } 269 270 }