summaryrefslogtreecommitdiffstats
path: root/sandbox/implementation-spring2/src/main/java/org/apache/tuscany/implementation/spring/SpringImplementation.java
blob: 5107bc859934a2709a81f8c72d3a1b5fd061f9fd (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.implementation.spring;

import java.util.List;
import java.util.Hashtable;

import org.apache.tuscany.sca.assembly.ComponentType;
import org.apache.tuscany.sca.assembly.Implementation;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.Service;
import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl;

import org.springframework.core.io.Resource;

import org.apache.tuscany.implementation.spring.xml.SpringBeanElement;

/**
 * Represents a Spring implementation.
 * 
 * TBD: Incomplete and needs substantial work...   MJE, 4th May 2007
 */
public class SpringImplementation  extends ComponentTypeImpl implements Implementation {

	// The location attribute which points to the Spring application-context XML file
    private String springLocation;
    // The application-context file as a Spring Resource
    private Resource resource;
    private ComponentType componentType;
    // Mapping of Services to Beans
    private Hashtable<String,SpringBeanElement> serviceMap;

    protected SpringImplementation() {
        this.springLocation = null;
        this.resource = null;
        setUnresolved(true);
        serviceMap = new Hashtable<String,SpringBeanElement>();
    }

    /* Returns the location attribute for this Spring implementation */
    public String getSpringLocation() {
        return springLocation;
    }
    
    /**
     * Sets the location attribute for this Spring implementation
     * location - a URI to the Spring application-context file
     */
    public void setSpringLocation(String location) {
    	this.springLocation = location;
        return;
    }
    
    public void setResource( Resource resource ) {
    	this.resource = resource;
    }
    
    public Resource getResource() {
    	return resource;
    }

    /* 
     * Returns the componentType for this Spring implementation 
     */
    public ComponentType getComponentType() {
        return componentType;
    }

    /*
     * Sets the componentType for this Spring implementation
     */
    public void setComponentType(ComponentType componentType) {
        this.componentType = componentType;
    }

    public List<Service> getServices() {
        return componentType.getServices();
    }

    public List<Reference> getReferences() {
        return componentType.getReferences();
    }
    
    /**
     * Returns the Spring Bean which implements a particular service
     * @param service the service
     * @return the bean which implements the service, as a SpringBeanElement
     */
    public SpringBeanElement getBeanFromService( Service service ) {
    	SpringBeanElement theBean = serviceMap.get( service.getName() );
    	return theBean;
    }
    
    /**
     * Sets the mapping from a service to the Spring Bean that implements the service
     * @param service the service
     * @param theBean a SpringBeanElement for the Bean implementing the service
     */
    public void setBeanForService( Service service, SpringBeanElement theBean ) {
    	serviceMap.put( service.getName(), theBean );
    }
}