1 // ======================================================================== 2 // Copyright (c) Webtide LLC 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // 8 // The Eclipse Public License is available at 9 // http://www.eclipse.org/legal/epl-v10.html 10 // 11 // The Apache License v2.0 is available at 12 // http://www.apache.org/licenses/LICENSE-2.0.txt 13 // 14 // You may elect to redistribute this code under either of these licenses. 15 // ======================================================================== 16 package org.eclipse.jetty.deploy; 17 18 import org.eclipse.jetty.server.handler.ContextHandler; 19 import org.eclipse.jetty.util.AttributesMap; 20 21 /** 22 * The information about an App that is managed by the {@link DeploymentManager} 23 */ 24 public class App 25 { 26 private final DeploymentManager _manager; 27 private final AppProvider _provider; 28 private final String _originId; 29 private ContextHandler _context; 30 31 /** 32 * Create an App with specified Origin ID and archivePath 33 * 34 * @param originId 35 * the origin ID (The ID that the {@link AppProvider} knows 36 * about) 37 * @see App#getOriginId() 38 * @see App#getContextPath() 39 */ 40 public App(DeploymentManager manager, AppProvider provider, String originId) 41 { 42 _manager = manager; 43 _provider = provider; 44 _originId = originId; 45 } 46 47 /** 48 * Create an App with specified Origin ID and archivePath 49 * 50 * @param originId 51 * the origin ID (The ID that the {@link AppProvider} knows 52 * about) 53 * @see App#getOriginId() 54 * @see App#getContextPath() 55 * @param context 56 * Some implementations of AppProvider might have to use an 57 * already created ContextHandler. 58 */ 59 public App(DeploymentManager manager, AppProvider provider, String originId, ContextHandler context) 60 { 61 this(manager,provider,originId); 62 _context = context; 63 } 64 65 /* ------------------------------------------------------------ */ 66 /** 67 * @return The deployment manager 68 */ 69 public DeploymentManager getDeploymentManager() 70 { 71 return _manager; 72 } 73 74 /* ------------------------------------------------------------ */ 75 /** 76 * @return The AppProvider 77 */ 78 public AppProvider getAppProvider() 79 { 80 return _provider; 81 } 82 83 /** 84 * Get ContextHandler for the App. 85 * 86 * Create it if needed. 87 * 88 * @return the {@link ContextHandler} to use for the App when fully started. 89 * (Portions of which might be ignored when App is not yet 90 * {@link AppLifeCycle#DEPLOYED} or {@link AppLifeCycle#STARTED}) 91 * @throws Exception 92 */ 93 public ContextHandler getContextHandler() throws Exception 94 { 95 if (_context == null) 96 { 97 _context = getAppProvider().createContextHandler(this); 98 99 AttributesMap attributes = _manager.getContextAttributes(); 100 if (attributes!=null && attributes.size()>0) 101 { 102 // Merge the manager attributes under the existing attributes 103 attributes = new AttributesMap(attributes); 104 attributes.addAll(_context.getAttributes()); 105 _context.setAttributes(attributes); 106 } 107 } 108 return _context; 109 } 110 111 112 /** 113 * The context path {@link App} relating to how it is installed on the 114 * jetty server side. 115 * 116 * NOTE that although the method name indicates that this is a unique 117 * identifier, it is not, as many contexts may have the same contextPath, 118 * yet different virtual hosts. 119 * 120 * @deprecated Use getContextPath instead. 121 * @return the context path for the App 122 */ 123 public String getContextId() 124 { 125 return getContextPath(); 126 } 127 128 129 /** 130 * The context path {@link App} relating to how it is installed on the 131 * jetty server side. 132 * 133 * @return the contextPath for the App 134 */ 135 public String getContextPath() 136 { 137 if (this._context == null) 138 { 139 return null; 140 } 141 return this._context.getContextPath(); 142 } 143 144 145 /** 146 * The origin of this {@link App} as specified by the {@link AppProvider} 147 * 148 * @return String representing the origin of this app. 149 */ 150 public String getOriginId() 151 { 152 return this._originId; 153 } 154 155 @Override 156 public String toString() 157 { 158 return "App[" + _context + "," + _originId + "]"; 159 } 160 }