1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 import com.sun.enterprise.loader.EJBClassLoader; 32 import java.io.*; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Properties ; 36 import javax.enterprise.deploy.spi.Target ; 37 import com.sun.enterprise.util.io.*; 38 import com.sun.enterprise.util.StringUtils; 39 import com.sun.enterprise.instance.InstanceEnvironment; 40 import com.sun.enterprise.instance.ApplicationEnvironment; 41 import com.sun.enterprise.instance.ModuleEnvironment; 42 import com.sun.enterprise.deployment.Application; 43 import com.sun.enterprise.util.diagnostics.ObjectAnalyzer; 44 import com.sun.enterprise.instance.AppsManager; 45 import com.sun.enterprise.util.i18n.StringManager; 46 import com.sun.enterprise.server.Constants; 47 import com.sun.enterprise.management.deploy.DeploymentCallback; 48 49 54 55 public class DeploymentRequest 56 { 57 private boolean isDone = false; 58 59 63 70 public DeploymentRequest( 71 InstanceEnvironment iEnv, 72 DeployableObjectType theType, 73 DeploymentCommand theCommand) 74 throws IASDeploymentException 77 { 78 instanceEnv = iEnv; 80 setType(theType); 81 setCommand(theCommand); 82 } 83 84 86 90 public void verify() throws IASDeploymentException 91 { 92 if(isVerified) 93 return; 94 95 if(isFileSourceRequired() && fileSource == null) { 96 String msg = localStrings.getString( 97 "enterprise.deployment.backend.file_source_required" ); 98 throw new IASDeploymentException( msg ); 99 } 100 101 if(isNameRequired() && name == null) { 102 String msg = localStrings.getString( 103 "enterprise.deployment.backend.name_required" ); 104 throw new IASDeploymentException( msg ); 105 } 106 107 if(isContextRootRequired() && contextRoot == null && 108 defaultContextRoot == null) { 109 110 String msg = localStrings.getString( 111 "enterprise.deployment.backend.context_root_required" ); 112 throw new IASDeploymentException( msg ); 113 } 114 115 if(name == null) createName(); 117 118 123 if(!FileUtils.isLegalFilename(name)) 124 { 125 128 String msg = localStrings.getString( 130 "enterprise.deployment.backend.illegal_characters_in_component_name", 131 FileUtils.getIllegalFilenameCharacters() ); 132 throw new IASDeploymentException( msg ); 133 } 136 137 setEnv(); 138 checkForRedeploy(); 139 isVerified = true; 140 } 141 142 149 public void setName(String theName) throws IASDeploymentException 150 { 151 if(StringUtils.ok(theName)) 152 name = theName; 153 154 else if(isNameRequired()) { 155 String msg = localStrings.getString( 156 "enterprise.deployment.backend.null_setname" ); 157 throw new IASDeploymentException( msg ); 158 } 159 } 160 161 168 public void setFileSource(String src) throws IASDeploymentException 169 { 170 setFileSource(new File(src)); 171 } 172 173 180 public void setFileSource(File src) throws IASDeploymentException 181 { 182 fileSource = null; 183 184 if(src == null && !isFileSourceRequired()) 185 return; 187 try 188 { 189 fileSource = new FileSource(src); 190 } 191 catch(Exception e) 192 { 193 if(isFileSourceRequired()) 194 throw new IASDeploymentException("DeploymentRequest.setFileSource()" + e); 195 } 196 } 197 198 199 public void setDeploymentPlan(File plan) { 200 deploymentPlan = plan; 201 } 202 203 public File getDeploymentPlan() { 204 return deploymentPlan; 205 } 206 207 public void setDeploymentCallback(DeploymentCallback callback) { 208 deploymentCallback = callback; 209 } 210 211 public DeploymentCallback getDeploymentCallback() { 212 return deploymentCallback; 213 } 214 215 public void setAbort(boolean isAborted) { 216 this.isAborted = isAborted; 217 } 218 219 public boolean isAborted() { 220 return isAborted; 221 } 222 223 public void setReload(boolean isReload) { 224 this.isReload = isReload; 225 } 226 227 public boolean isReload() { 228 return isReload; 229 } 230 231 public void setTargetName(String name) 232 { 233 targetName = name; 234 } 235 236 public String getTargetName() 237 { 238 return targetName; 239 } 240 241 243 246 public void setShared(boolean newShared) throws IASDeploymentException 247 { 248 if(!isEjbModule()) { 249 String msg = localStrings.getString( 250 "enterprise.deployment.backend.cannot_set_shared_flag" ); 251 throw new IASDeploymentException( msg ); 252 } 253 254 shared = newShared; 255 } 256 262 public void setForced(boolean newForced) 263 { 264 forced = newForced; 265 } 266 275 public void addOptionalArguments(Properties props) 276 { 277 282 optionalArguments.putAll(props); 283 } 284 285 public void addOptionalArguments(Map map) 286 { 287 optionalArguments.putAll(map); 288 } 289 290 294 public void addOptionalArgument(String key, String value) 295 { 296 optionalArguments.put(key, value); 297 } 298 299 301 307 public void setPrecompileJSP(boolean newPrecompileJSP) 308 { 309 precompileJSP = newPrecompileJSP; 310 } 311 312 315 public boolean getPrecompileJSP() 316 { 317 return precompileJSP; 318 } 319 320 324 public void setGenerateRMIStubs(boolean newGenerateRMIStubs) 325 { 326 generateRMIStubs = newGenerateRMIStubs; 327 } 328 329 332 public boolean getGenerateRMIStubs() 333 { 334 return generateRMIStubs; 335 } 336 337 341 public void setAvailabilityEnabled(boolean newAvailabilityEnabled) 342 { 343 availabilityEnabled = newAvailabilityEnabled; 344 } 345 346 349 public boolean isAvailabilityEnabled() 350 { 351 return availabilityEnabled; 352 } 353 354 358 public void setJavaWebStartEnabled(boolean newJavaWebStartEnabled) 359 { 360 javaWebStartEnabled = newJavaWebStartEnabled; 361 } 362 363 366 public boolean isJavaWebStartEnabled() 367 { 368 return javaWebStartEnabled; 369 } 370 371 375 public void setLibraries(String newLibraries) 376 { 377 libraries = newLibraries; 378 } 379 380 383 public String getLibraries() 384 { 385 return libraries; 386 } 387 388 391 public String getResourceAction() 392 { 393 return resourceAction; 394 } 395 396 400 public void setResourceAction (String newResourceAction) 401 { 402 resourceAction = newResourceAction; 403 } 404 405 409 public void setResourceTargetList (String newTargetList) 410 { 411 resourceTargetList = newTargetList; 412 } 413 414 417 public String getResourceTargetList() 418 { 419 return resourceTargetList; 420 } 421 422 424 427 public boolean isForced() 428 { 429 return forced; 430 } 431 432 434 public File getClientJar() 435 { 436 return clientJar; 437 } 438 439 441 public boolean isApplication() 442 { 443 return DeployableObjectType.APP.equals(type); 444 } 445 446 448 public void setContextRoot(String s) 449 { 450 contextRoot = s; 451 } 452 453 455 public String getContextRoot() 456 { 457 return contextRoot; 458 } 459 460 462 public void setDefaultContextRoot(String s) 463 { 464 defaultContextRoot = s; 465 } 466 467 public String getDefaultContextRoot() 468 { 469 return defaultContextRoot; 470 } 471 472 473 475 public boolean isModule() 476 { 477 return isWebModule() || isEjbModule() || isConnectorModule() || isAppClientModule(); 478 } 479 480 482 public boolean isSharedModule() 483 { 484 return isModule() && shared; 485 } 486 487 489 public boolean isStandAloneModule() 490 { 491 return isModule() && !shared; 492 } 493 494 496 public boolean isWebModule() 497 { 498 return DeployableObjectType.WEB.equals(type); 499 } 500 501 503 public boolean isEjbModule() 504 { 505 return DeployableObjectType.EJB.equals(type); 506 } 507 508 510 public boolean isConnectorModule() 511 { 512 return DeployableObjectType.CONN.equals(type); 513 } 514 515 517 public boolean isAppClientModule() 518 { 519 return DeployableObjectType.CAR.equals(type); 520 } 521 522 523 525 public boolean isDeploy() throws IASDeploymentException 526 { 527 if(command == null) 528 { 529 String msg =localStrings.getString( "enterprise.deployment.backend.no_command"); 530 throw new IASDeploymentException( msg ); 531 } 532 537 541 return command.equals(DeploymentCommand.DEPLOY); 542 } 543 544 546 public boolean isReDeploy() throws IASDeploymentException 547 { 548 if(command == null) 549 { 550 String msg =localStrings.getString( "enterprise.deployment.backend.no_command"); 551 throw new IASDeploymentException( msg ); 552 } 553 554 559 563 return command.equals(DeploymentCommand.REDEPLOY); 564 } 565 566 568 public boolean isUnDeploy() throws IASDeploymentException 569 { 570 if(command == null) 571 { 572 String msg =localStrings.getString( "enterprise.deployment.backend.no_command"); 573 throw new IASDeploymentException( msg ); 574 } 575 576 581 585 return command.equals(DeploymentCommand.UNDEPLOY); 586 } 587 588 590 public boolean isArchive() throws IASDeploymentException 591 { 592 if(isUnDeploy()) { 593 String msg = localStrings.getString( 594 "enterprise.deployment.backend.invalid_isarchive_call" ); 595 throw new IASDeploymentException( msg ); 596 } 597 598 return getFileSource().isArchive(); 599 } 600 601 603 public boolean isDirectory() throws IASDeploymentException 604 { 605 if(isUnDeploy()) 606 return false; 608 609 return getFileSource().isDirectory(); 610 } 611 612 614 public String getName() 615 { 616 return name; 617 } 618 619 621 public String toString() 622 { 623 return ObjectAnalyzer.toString(this); 624 } 625 626 628 public void setDebug(boolean what) 629 { 630 debug = true; 631 } 632 633 635 public boolean getDebug() 636 { 637 return debug; 638 } 639 640 642 public void setNoEJBC() 643 { 644 noEJBC = true; 645 } 646 647 649 650 public boolean getNoEJBC() 651 { 652 return noEJBC; 653 } 654 655 657 662 public void setVerifying(boolean what) 663 { 664 isVerifying = what; 665 } 666 672 public boolean isVerifying() 673 { 674 return isVerifying; 675 } 676 680 public File getDeployedDirectory() 681 { 682 if(!FileUtils.safeIsDirectory(deployedDirectory)) 683 deployedDirectory = null; 684 685 return deployedDirectory; 686 } 687 691 public File getStubsDirectory() 692 { 693 if(!FileUtils.safeIsDirectory(stubsDirectory)) 694 stubsDirectory = null; 695 696 return stubsDirectory; 697 } 698 702 public File getJSPDirectory() 703 { 704 if(!FileUtils.safeIsDirectory(jspDirectory)) 705 jspDirectory = null; 706 707 return jspDirectory; 708 } 709 710 711 715 public File getGeneratedXMLDirectory() 716 { 717 if(!FileUtils.safeIsDirectory(generatedXMLDirectory)) 718 generatedXMLDirectory = null; 719 720 return generatedXMLDirectory; 721 } 722 723 727 void setClientJar(File f) { 729 736 clientJar = f; 737 } 738 739 741 public FileSource getFileSource() 742 { 743 return fileSource; 744 } 745 746 748 public DeployableObjectType getType() 749 { 750 return type; 751 } 752 753 755 DeploymentCommand getCommand() 756 { 757 return command; 758 } 759 760 767 769 public InstanceEnvironment getInstanceEnv() 770 { 771 return instanceEnv; 772 } 773 774 776 ApplicationEnvironment getAppEnv() throws IASDeploymentException 777 { 778 if(!isApplication()) { 779 String msg = localStrings.getString( 780 "enterprise.deployment.backend.illegal_getapplicationenv_call"); 781 throw new IASDeploymentException( msg ); 782 } 783 784 return appEnv; 785 } 786 787 789 ModuleEnvironment getModuleEnv() throws IASDeploymentException 790 { 791 if(!isModule()) { 792 String msg = localStrings.getString( 793 "enterprise.deployment.backend.illegal_getmoduleenv_call"); 794 throw new IASDeploymentException( msg ); 795 } 796 797 return moduleEnv; 798 } 799 800 802 boolean isEar() 803 { 804 return isApplication() && fileSource.isArchive(); 807 } 808 809 811 boolean isWar() 812 { 813 return isWebModule() && fileSource.isArchive(); 816 } 817 819 boolean isEjbJar() 820 { 821 return isEjbModule() && fileSource.isArchive(); 824 } 825 826 831 void setParentClassLoader(ClassLoader cl) 832 { 833 this.parentClassLoader = cl; 834 } 835 836 841 ClassLoader getParentClassLoader() 842 { 843 return this.parentClassLoader; 844 } 845 846 849 void setParentClasspath(List classpaths) 850 { 851 this.parentClasspath = classpaths; 852 } 853 854 859 List getParentClasspath() 860 { 861 return this.parentClasspath; 862 } 863 864 867 public void setOptionalAttributes(Properties optionalAttributes) 868 { 869 this.optionalAttributes = optionalAttributes; 870 } 871 872 877 public Properties getOptionalAttributes() 878 { 879 return this.optionalAttributes; 880 } 881 882 883 888 void setEjbClassLoader(ClassLoader cl) 889 { 890 this.ejbClassLoader = cl; 891 } 892 893 898 ClassLoader getEjbClassLoader() 899 { 900 return this.ejbClassLoader; 901 } 902 903 906 void setCompleteClasspath(List classpaths) 907 { 908 this.completeClasspath = classpaths; 909 } 910 911 916 List getCompleteClasspath() 917 { 918 return this.completeClasspath; 919 } 920 921 926 void setModuleClasspath(List classpath) { 927 moduleClasspath = classpath; 928 } 929 930 933 List getModuleClasspath() { 934 935 return moduleClasspath; 936 } 937 938 943 public Properties getOptionalArguments() 944 { 945 return optionalArguments; 946 } 947 948 951 public void setDeployedDirectory(File d) 952 { 953 deployedDirectory = d; 954 } 955 958 public void setStubsDirectory(File d) 959 { 960 stubsDirectory = d; 961 } 962 965 public void setJSPDirectory(File d) 966 { 967 jspDirectory = d; 968 } 969 970 973 public void setGeneratedXMLDirectory(File d) 974 { 975 generatedXMLDirectory = d; 976 } 977 978 979 981 boolean isMaybeCMPDropTables() 982 { 983 String s = getOptionalArguments().getProperty(Constants.CMP_DROP_TABLES); 984 985 if(s != null && s.equalsIgnoreCase(Constants.FALSE)) 986 return false; 987 988 return true; 989 } 990 991 992 public String getHttpHostName() 993 { 994 return httpHostName; 995 } 996 997 public void setHttpHostName(String hostName) 998 { 999 httpHostName = hostName; 1000 } 1001 1002 public int getHttpPort() 1003 { 1004 return httpPort; 1005 } 1006 1007 public void setHttpPort(int port) 1008 { 1009 httpPort = port; 1010 } 1011 1012 public String getHttpsHostName() 1013 { 1014 return httpsHostName; 1015 } 1016 1017 public void setHttpsHostName(String hostName) 1018 { 1019 httpsHostName = hostName; 1020 } 1021 1022 public int getHttpsPort() 1023 { 1024 return httpsPort; 1025 } 1026 1027 public void setHttpsPort(int port) 1028 { 1029 httpsPort = port; 1030 } 1031 1032 1036 private boolean isFileSourceRequired() throws IASDeploymentException 1037 { 1038 if(isUnDeploy()) 1039 return false; 1040 else 1041 return true; 1042 } 1043 1044 1046 private boolean isNameRequired() throws IASDeploymentException 1047 { 1048 if(isDeploy()) 1049 return false; 1050 else 1051 return true; 1052 } 1053 1054 1056 private boolean isContextRootRequired() throws IASDeploymentException 1057 { 1058 return isWebModule() && ( isDeploy() || isReDeploy()); 1060 } 1061 1062 1064 private void setType(DeployableObjectType theType) throws IASDeploymentException 1065 { 1066 type = theType; 1067 1068 if(isConnectorModule()) 1069 shared = true; 1070 else 1071 shared = false; 1072 } 1073 1074 1076 void setCommand(DeploymentCommand theCommand) throws IASDeploymentException 1077 { 1078 command = theCommand; 1079 1080 if(command == null) { 1081 String msg = localStrings.getString( 1082 "enterprise.deployment.backend.null_command_type" ); 1083 throw new IASDeploymentException( msg ); 1084 } 1085 } 1086 1087 1089 private void setEnv() throws IASDeploymentException 1090 { 1091 if(instanceEnv == null) { 1092 String msg = localStrings.getString( 1093 "enterprise.deployment.backend.null_instanceenvironment" ); 1094 throw new IASDeploymentException( msg ); 1095 } 1096 1097 if(isApplication()) 1098 appEnv = new ApplicationEnvironment(instanceEnv, name); 1099 else if(isWebModule()) 1100 moduleEnv = new ModuleEnvironment(instanceEnv, name, DeployableObjectType.WEB); 1101 else if(isEjbModule()) 1102 moduleEnv = new ModuleEnvironment(instanceEnv, name, DeployableObjectType.EJB); 1103 else if(isConnectorModule()) 1104 moduleEnv = new ModuleEnvironment(instanceEnv, name, DeployableObjectType.CONN); 1105 else if (isAppClientModule()) 1106 moduleEnv = new ModuleEnvironment(instanceEnv, name ,DeployableObjectType.CAR); 1107 else { 1108 String msg = localStrings.getString( 1109 "enterprise.deployment.backend.unknown_deployable_object", 1110 getClass().getName() ); 1111 throw new IASDeploymentException( msg ); 1112 } 1113 } 1114 1115 1117 private void createName() 1118 { 1119 String aname = fileSource.getSource().getName(); 1120 1121 if(isEar()) 1123 name = FileUtils.makeFriendlyFilenameNoExtension(aname); 1124 else 1125 name = FileUtils.makeFriendlyFilename(aname); 1126 } 1127 1128 1131 private void checkForRedeploy() throws IASDeploymentException 1132 { 1133 if(isUnDeploy()) 1134 return; 1136 assert (appEnv != null && moduleEnv == null)|| (appEnv == null && moduleEnv != null); 1137 assert !isVerified; 1138 assert StringUtils.ok(name); 1139 assert instanceEnv != null; 1140 1141 if(moduleEnv != null) 1142 { 1143 return; 1145 } 1146 1147 try 1148 { 1149 AppsManager appMgr = new AppsManager(instanceEnv); 1150 boolean isReg = appMgr.isRegistered(name); 1151 1152 if(forced && isReg && isDeploy()) 1153 command = DeploymentCommand.REDEPLOY; 1154 } 1155 catch(Exception e) 1156 { 1157 throw new IASDeploymentException(e); 1158 } 1159 } 1160 1161 1165 public void setTarget(Target target) { 1166 this.target = target; 1167 } 1168 1169 1173 public Target getTarget() { 1174 return target; 1175 } 1176 1177 1181 public void setCurrentDeploymentStatus(DeploymentStatus status) { 1182 currentDeploymentStatus = status; 1183 } 1184 1185 1189 public DeploymentStatus getCurrentDeploymentStatus() { 1190 return currentDeploymentStatus; 1191 } 1192 1193 1198 public void setStartOnDeploy(boolean startOnDeploy) { 1199 this.startOnDeploy = startOnDeploy; 1200 } 1201 1202 1206 public boolean isStartOnDeploy() { 1207 return this.startOnDeploy; 1208 } 1209 1210 1214 public void setActionCode(int actionCode){ 1215 this.actionCode = actionCode; 1216 } 1217 1218 1222 public int getActionCode() { 1223 return actionCode; 1224 } 1225 1226 1231 public void setCascade(boolean cascade) { 1232 this.cascade = cascade; 1233 } 1234 1235 1239 public boolean getCascade() { 1240 return this.cascade; 1241 } 1242 1243 1246 public void setDescriptor(Application app) { 1247 this.application = app; 1248 } 1249 1250 1253 public Application getDescriptor() { 1254 return application; 1255 } 1256 1257 1260 public void setDescription(String description) { 1261 this.description = description; 1262 } 1263 1264 1267 public String getDescription() { 1268 return description; 1269 } 1270 1271 1276 public boolean getReRegisterOnFailure() 1277 { 1278 return reregisterOnFailure; 1279 } 1280 1281 void setReRegisterOnFailure(boolean b) 1282 { 1283 reregisterOnFailure = b; 1284 } 1285 1286 1290 public void done() { 1291 if ( ! isDone) { 1292 isDone = true; 1293 if (ejbClassLoader != null && ejbClassLoader instanceof EJBClassLoader) { 1294 ((EJBClassLoader) ejbClassLoader).done(); 1295 } 1296 } 1297 } 1298 1299 1301 private FileSource fileSource = null; 1302 private File deploymentPlan = null; 1303 private DeploymentCallback deploymentCallback = null; 1304 private boolean isAborted = false; 1305 private boolean isReload = false; 1306 private String targetName = null; 1307 private DeployableObjectType type = null; 1308 private DeploymentCommand command = null; 1309 private String name = null; 1310 private String contextRoot = null; 1311 private String defaultContextRoot 1312 = null; 1313 private InstanceEnvironment instanceEnv = null; 1314 private ApplicationEnvironment appEnv = null; 1315 private ModuleEnvironment moduleEnv = null; 1316 private File clientJar = null; 1317 private File deployedDirectory = null; 1318 private File jspDirectory = null; 1319 private File stubsDirectory = null; 1320 private File generatedXMLDirectory = null; 1321 private boolean shared = false; 1322 private boolean forced = true; 1323 private boolean isVerified = false; 1324 private boolean isVerifying = false; 1325 private boolean debug = false; 1326 private boolean noEJBC = false; 1327 private boolean precompileJSP = false; 1328 private boolean generateRMIStubs = false; 1329 private boolean availabilityEnabled = false; 1330 private boolean javaWebStartEnabled = true; 1331 private String libraries = null; 1332 private String resourceAction = null; 1333 private String resourceTargetList = null; 1334 private boolean directoryDeployed = false; 1335 private List parentClasspath = null; 1336 private ClassLoader parentClassLoader = null; 1337 private List completeClasspath = null; 1338 private List moduleClasspath = null; 1339 private ClassLoader ejbClassLoader = null; 1340 private Properties optionalAttributes = null; 1341 private Properties optionalArguments = new Properties (); 1342 private String httpHostName = null; 1343 private int httpPort; 1344 private String httpsHostName = null; 1345 private int httpsPort; 1346 private Application application=null; 1347 private static StringManager localStrings = 1348 StringManager.getManager( DeploymentRequest.class ); 1349 1350 1351 private Target target = null; 1352 1353 1354 private boolean startOnDeploy = true; 1355 1356 1357 private int actionCode = 0; 1358 1359 1360 private boolean cascade = false; 1361 1362 1363 private DeploymentStatus currentDeploymentStatus = null; 1364 1365 private String description = null; 1366 1367 1368 1369 private boolean reregisterOnFailure = true; 1370 1371} 1372 | Popular Tags |