summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-final/java/sca/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java
blob: a5795d076ed7a5a9df54a00ac34feb726f295ca0 (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
/**
 *
 *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.tuscany.binding.axis2.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.deployment.AxisConfigBuilder;
import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisConfigurator;
import org.apache.tuscany.common.resource.ResourceLoader;
import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl;
import org.osoa.sca.ServiceRuntimeException;

/**
 * Helps configure Axis2 from a resource in binding.axis2 instead of Axis2.xml
 * 
 * TODO: Review: should there be a single global Axis ConfigurationContext
 */
public class TuscanyAxisConfigurator implements AxisConfigurator {

    protected AxisConfiguration axisConfiguration;

    protected final ResourceLoader resourceLoader;

    /**
     * @param resourceLoader
     *            desired resource loader if null use thread context.
     * @param axisConfiguration
     *            Starting axis configuration, null then use uninitialized configuration.
     */
    public TuscanyAxisConfigurator(ResourceLoader resourceLoader, AxisConfiguration axisConfiguration) {
        this.resourceLoader = resourceLoader != null ? resourceLoader : new ResourceLoaderImpl(getClass().getClassLoader());
        this.axisConfiguration = axisConfiguration == null ? new AxisConfiguration() : axisConfiguration;
    }

    public AxisConfiguration getAxisConfiguration() {

        return axisConfiguration;
    }

    public ConfigurationContext getConfigurationContext() throws ServiceRuntimeException {

        try {
            URL url = resourceLoader.getResource("org/apache/tuscany/binding/axis2/engine/config/axis2.xml");

            InputStream serviceInputStream = url.openStream();
            AxisConfigBuilder axisConfigBuilder = new AxisConfigBuilder(serviceInputStream, new DeploymentEngine(), axisConfiguration);
            axisConfigBuilder.populateConfig();
            serviceInputStream.close();
            return ConfigurationContextFactory.createConfigurationContext(this);
        } catch (IOException e) {

            throw new ServiceRuntimeException(e);
        }

    }

    public void loadServices() {
        // TODO Auto-generated method stub
        
    }

    public void engageGlobalModules() throws AxisFault {
        // TODO Auto-generated method stub
        
    }

}