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