01 package org.apache.qpid.management.wsdm.muse.engine;
02
03 import java.io.File;
04 import java.net.URI;
05
06 import javax.servlet.ServletContext;
07
08 import org.apache.muse.core.AbstractEnvironment;
09 import org.apache.muse.util.FileUtils;
10 import org.apache.muse.ws.addressing.EndpointReference;
11 import org.apache.qpid.management.Messages;
12 import org.apache.qpid.management.Names;
13 import org.apache.qpid.management.Protocol;
14 import org.apache.qpid.transport.util.Logger;
15
16 /**
17 * QMan Adapter enviroment implementation.
18 *
19 * @author Andrea Gazzarini
20 */
21 public class WSDMAdapterEnvironment extends AbstractEnvironment
22 {
23 private final static Logger LOGGER = Logger.get(WSDMAdapterEnvironment.class);
24 private final File _realDirectory;
25 private final ServletContext _servletContext;
26
27 /**
28 * Builds a new qman environment with the given application context.
29 *
30 * @param servletContext the application context.
31 */
32 public WSDMAdapterEnvironment(ServletContext servletContext)
33 {
34 this._servletContext = servletContext;
35 String realDirectoryPath = servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER);
36
37 _realDirectory = (realDirectoryPath != null)
38 ? new File(realDirectoryPath)
39 : FileUtils.CURRENT_DIR;
40
41 String defaultURI = getDefaultURIPrefix()+"adapter";
42 setDefaultURI(defaultURI);
43
44 LOGGER.info(Messages.QMAN_000029_DEFAULT_URI, defaultURI);
45 }
46
47 /**
48 * Returns the endpoint created starting by this application default URI.
49 *
50 * @return the endpoint created starting by this application default URI.
51 */
52 public EndpointReference getDeploymentEPR()
53 {
54 return new EndpointReference(URI.create(getDefaultURI()));
55 }
56
57 /**
58 * Returns the application classes folder.
59 *
60 * @return the application classes folder.
61 */
62 public File getRealDirectory()
63 {
64 return _realDirectory;
65 }
66
67 public String getDefaultURIPrefix()
68 {
69 return new StringBuilder()
70 .append("http://")
71 .append(System.getProperty(
72 Names.ADAPTER_HOST_PROPERTY_NAME,
73 Protocol.DEFAULT_QMAN_HOSTNAME))
74 .append(":")
75 .append(System.getProperty(
76 Names.ADAPTER_PORT_PROPERTY_NAME,
77 String.valueOf(Protocol.DEFAULT_QMAN_PORT_NUMBER)))
78 .append(_servletContext.getContextPath())
79 .append("/services/")
80 .toString();
81 }
82 }
|