summaryrefslogtreecommitdiffstats
path: root/sandbox/SPI/implementation-crud/src/main/java/crud/CRUDImplementation.java
blob: 1a9e6096058f28ed4e4b3b0c3da9c4f3f5fd8a32 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * 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 crud;

import java.util.Collections;
import java.util.List;

import org.apache.tuscany.assembly.ConstrainingType;
import org.apache.tuscany.assembly.Implementation;
import org.apache.tuscany.assembly.Property;
import org.apache.tuscany.assembly.Reference;
import org.apache.tuscany.assembly.Service;
import org.apache.tuscany.assembly.impl.ServiceImpl;
import org.apache.tuscany.interfacedef.java.JavaInterface;
import org.apache.tuscany.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.interfacedef.java.impl.JavaInterfaceContractImpl;
import org.apache.tuscany.interfacedef.java.impl.JavaInterfaceImpl;
import org.apache.tuscany.policy.Intent;
import org.apache.tuscany.policy.PolicySet;

/**
 * The model representing a sample CRUD implementation in an SCA
 * assembly model.
 * 
 * The sample CRUD implementation is not a full blown implementation,
 * it only supports a subset of what a component implementation can
 * support:
 * - a single fixed service (as opposed to a list of services typed by different
 * interfaces)
 * - a directory attribute used to specify where a CRUD component is going
 * to persist resources 
 * - no references or properties
 * - no policy intents or policy sets
 * 
 * @version $$Rev$$ $$Date$$
 */
public class CRUDImplementation implements Implementation {
    private Service crudService;
    private String directory;

    /**
     * Constructs a new CRUD implementation.
     */
    public CRUDImplementation() {
        
        // CRUD implementation always provide a single service exposing
        // the CRUD interface, and have no references and properties
        crudService = new ServiceImpl();
        crudService.setName("CRUD");
        JavaInterface javaInterface = new JavaInterfaceImpl();
        javaInterface.setJavaClass(CRUD.class);
        JavaInterfaceContract interfaceContract = new JavaInterfaceContractImpl();
        interfaceContract.setInterface(javaInterface);
        crudService.setInterfaceContract(interfaceContract);
    }

    /**
     * Returns the directory used by CRUD implementations to persist
     * resources.
     * 
     * @return the directory used to persist resources
     */
    public String getDirectory() {
        return directory;
    }

    /**
     * Sets the directory used by CRUD implementations to persist
     * resources.
     * 
     * @param directory the directory used to persist resources
     */
    public void setDirectory(String directory) {
        this.directory = directory;
    }

    public ConstrainingType getConstrainingType() {
        // CRUD implementations do not support constrainingTypes
        return null;
    }

    public List<Property> getProperties() {
        // CRUD implementations do not support properties
        return Collections.emptyList();
    }

    public List<Reference> getReferences() {
        // CRUD implementations do not support properties
        return Collections.emptyList();
    }

    public List<Service> getServices() {
        // CRUD implementations provide a single fixed CRUD service 
        return Collections.singletonList(crudService);
    }

    public String getURI() {
        // CRUD implementations don't have a URI  
        return null;
    }

    public void setConstrainingType(ConstrainingType constrainingType) {
        // CRUD implementations do not support constrainingTypes 
    }

    public void setURI(String uri) {
        // CRUD implementations don't have a URI  
    }

    public List<PolicySet> getPolicySets() {
        // CRUD implementations do not support policy sets 
        return Collections.emptyList();
    }

    public List<Intent> getRequiredIntents() {
        // CRUD implementations do not support intents
        return Collections.emptyList();
    }

    public List<Object> getExtensions() {
        // CRUD implementations do not support extensions
        return Collections.emptyList();
    }

    public boolean isUnresolved() {
        // CRUD implementations are always resolved
        return false;
    }

    public void setUnresolved(boolean unresolved) {
        // CRUD implementations are always resolved
    }

}