View Javadoc

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  import org.omg.CORBA.portable.ApplicationException;
21  
22  /**
23   * The information about an App that is managed by the {@link DeploymentManager}
24   */
25  public class App
26  {
27      private final DeploymentManager _manager;
28      private final AppProvider _provider;
29      private final String _originId;
30      private ContextHandler _context;
31  
32      /**
33       * Create an App with specified Origin ID and archivePath
34       * 
35       * @param originId
36       *            the origin ID (The ID that the {@link AppProvider} knows
37       *            about)
38       * @see App#getOriginId()
39       * @see App#getContextId()
40       */
41      public App(DeploymentManager manager, AppProvider provider, String originId)
42      {
43          _manager = manager;
44          _provider = provider;
45          _originId = originId;
46      }
47  
48      /**
49       * Create an App with specified Origin ID and archivePath
50       * 
51       * @param originId
52       *            the origin ID (The ID that the {@link AppProvider} knows
53       *            about)
54       * @see App#getOriginId()
55       * @see App#getContextId()
56       * @param context
57       *            Some implementations of AppProvider might have to use an
58       *            already created ContextHandler.
59       */
60      public App(DeploymentManager manager, AppProvider provider, String originId, ContextHandler context)
61      {
62          this(manager,provider,originId);
63          _context = context;
64      }
65  
66      /* ------------------------------------------------------------ */
67      /**
68       * @return The deployment manager
69       */
70      public DeploymentManager getDeploymentManager()
71      {
72          return _manager;
73      }
74  
75      /* ------------------------------------------------------------ */
76      /**
77       * @return The AppProvider
78       */
79      public AppProvider getAppProvider()
80      {
81          return _provider;
82      }
83  
84      /**
85       * Get ContextHandler for the App.
86       * 
87       * Create it if needed.
88       * 
89       * @return the {@link ContextHandler} to use for the App when fully started.
90       *         (Portions of which might be ignored when App is not yet 
91       *         {@link AppLifeCycle#DEPLOYED} or {@link AppLifeCycle#STARTED})
92       * @throws Exception
93       */
94      public ContextHandler getContextHandler() throws Exception
95      {
96          if (_context == null)
97          {
98              _context = getAppProvider().createContextHandler(this);
99              this._context.setAttributes(new AttributesMap(_manager.getContextAttributes()));
100         }
101         return _context;
102     }
103 
104     /**
105      * The unique id of the {@link App} relating to how it is installed on the
106      * jetty server side.
107      * 
108      * @return the generated Id for the App.
109      */
110     public String getContextId()
111     {
112         if (this._context == null)
113         {
114             return null;
115         }
116         return this._context.getContextPath();
117     }
118 
119     /**
120      * The origin of this {@link App} as specified by the {@link AppProvider}
121      * 
122      * @return String representing the origin of this app.
123      */
124     public String getOriginId()
125     {
126         return this._originId;
127     }
128 
129     @Override
130     public String toString()
131     {
132         return "App[" + _context + "," + _originId + "]";
133     }
134 }