summaryrefslogtreecommitdiff
path: root/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java
blob: b5d978e0e5d815266eac95b403c47ea754dd0543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.apache.qpid.management.wsdm.muse.engine;

import java.io.File;
import java.net.URI;

import javax.servlet.ServletContext;

import org.apache.muse.core.AbstractEnvironment;
import org.apache.muse.util.FileUtils;
import org.apache.muse.ws.addressing.EndpointReference;
import org.apache.qpid.management.Messages;
import org.apache.qpid.management.Names;
import org.apache.qpid.management.Protocol;
import org.apache.qpid.transport.util.Logger;

/**
 * QMan Adapter enviroment implementation.
 * 
 * @author Andrea Gazzarini
 */
public class WSDMAdapterEnvironment  extends AbstractEnvironment
{
	private final static Logger LOGGER = Logger.get(WSDMAdapterEnvironment.class);
	private final File _realDirectory;
    private final ServletContext _servletContext;
	
    /**
     * Builds a new qman environment with the given application context.
     *  
     * @param servletContext the application context. 
     */
    public WSDMAdapterEnvironment(ServletContext servletContext)
    {
    	this._servletContext = servletContext;
    	String realDirectoryPath = servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER);
        
        _realDirectory = (realDirectoryPath != null) 
        	? new File(realDirectoryPath) 
        	: FileUtils.CURRENT_DIR;
        	
        String defaultURI = getDefaultURIPrefix()+"adapter";
        setDefaultURI(defaultURI);
        
        LOGGER.info(Messages.QMAN_000029_DEFAULT_URI, defaultURI);
    }
    
    /**
     * Returns the endpoint created starting by this application default URI.
     * 
     * @return the endpoint created starting by this application default URI.
     */
    public EndpointReference getDeploymentEPR()
    {
        return new EndpointReference(URI.create(getDefaultURI()));
    }

    /**
     * Returns the application classes folder.
     * 
     * @return the application classes folder.
     */
    public File getRealDirectory()
    {
        return _realDirectory;
    }
    
    /**
     * Returns the default endpoint reference URI.
     * 
     * @return the default endpoint reference URI.
     */
    public String getDefaultURIPrefix()
    {
        return new StringBuilder()
    		.append("http://")
    		.append(System.getProperty(
    				Names.ADAPTER_HOST_PROPERTY_NAME,
    				Protocol.DEFAULT_QMAN_HOSTNAME))
    		.append(":")
    		.append(System.getProperty(
    				Names.ADAPTER_PORT_PROPERTY_NAME,
    				String.valueOf(Protocol.DEFAULT_QMAN_PORT_NUMBER)))
    		.append(_servletContext.getContextPath())
    		.append("/services/")
    		.toString();    	
    }
    
    /**
     * Returns the context path name of QMan application.
     * 
     * @return the context path name of QMan application.
     */
    public String getContextPath()
    {
    	return _servletContext.getContextPath();
    }
}