View Javadoc

1   /*
2   Copyright 2011-2014 AGH-UST, http://www.agh.edu.pl
3   Faculty of Computer Science, Electronics and Telecommunications
4   Department of Computer Science 
5   
6   See the NOTICE file distributed with this work for additional
7   information regarding copyright ownership
8   
9   Licensed under the Apache License, Version 2.0 (the "License");
10  you may not use this file except in compliance with the License.
11  You may obtain a copy of the License at
12  
13    http://www.apache.org/licenses/LICENSE-2.0
14  
15  Unless required by applicable law or agreed to in writing, software
16  distributed under the License is distributed on an "AS IS" BASIS,
17  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  See the License for the specific language governing permissions and
19  limitations under the License.
20  */
21  package org.universAAL.ri.gateway.eimanager.impl.exporting;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.universAAL.middleware.bus.model.AbstractBus;
28  import org.universAAL.middleware.container.ModuleContext;
29  import org.universAAL.middleware.service.DefaultServiceCaller;
30  import org.universAAL.middleware.service.ServiceBus;
31  import org.universAAL.middleware.service.ServiceBusFacade;
32  import org.universAAL.middleware.service.ServiceCall;
33  import org.universAAL.middleware.service.ServiceCallee;
34  import org.universAAL.middleware.service.ServiceResponse;
35  import org.universAAL.middleware.service.owls.profile.ServiceProfile;
36  import org.universAAL.ri.gateway.communicator.Activator;
37  import org.universAAL.ri.gateway.eimanager.impl.ProxyBusMember;
38  
39  public class ProxyServiceCaller extends ProxyBusMember {
40  
41  	private DefaultServiceCaller caller;
42  	private String serverNamespace;
43  	private String serviceType;
44  	private Map<String, List<ServiceProfile>> profiles;
45  	private ServiceBus bus;
46  
47  	public ProxyServiceCaller(final ExportedProxyManager manager,
48  			final String targetId, final ModuleContext mc,
49  			final String serverNamespace, final String serviceType,
50  			final Map<String, List<ServiceProfile>> profiles) {
51  		super(manager, targetId, "", mc);
52  		caller = new DefaultServiceCaller(mc);
53  		this.serverNamespace = serverNamespace;
54  		this.serviceType = serviceType;
55  		this.profiles = profiles;
56  		bus = ServiceBusFacade.fetchBus(Activator.mc);
57  	}
58  
59  	public ServiceResponse invoke(final ServiceCall call, final String memberId) {
60  		return ((ServiceCallee) ((AbstractBus) bus).getBusMember(memberId))
61  				.handleCall(call);
62  	}
63  
64  	/*
65  	 * DEPRECATED
66  	 * 
67  	 * private void prepareRequestedOutput(final List outputs) { if (outputs !=
68  	 * null && !outputs.isEmpty()) { for (int i = outputs.size() - 1; i > -1;
69  	 * i--) { ProcessOutput po = (ProcessOutput) outputs.remove(i);
70  	 * 
71  	 * Object val = po.getParameterValue(); if (val == null) continue;
72  	 * 
73  	 * String poSuffixUri = po.getURI().substring( po.getURI().indexOf("#") +
74  	 * 1);
75  	 * 
76  	 * ProcessOutput substitutedWithServerURI = new ProcessOutput(
77  	 * serverNamespace + poSuffixUri);
78  	 * substitutedWithServerURI.setParameterValue(val);
79  	 * outputs.add(substitutedWithServerURI); } } }
80  	 */
81  
82  	@Override
83  	public void removeProxy() {
84  		caller.close();
85  	}
86  
87  	@Override
88  	public String getId() {
89  		return caller.getMyID();
90  	}
91  
92  	public String getServiceType() {
93  		return serviceType;
94  	}
95  
96  	public ServiceProfile[] getProfiles() {
97  		List<ServiceProfile> profilesList = new ArrayList<ServiceProfile>();
98  		for (List<ServiceProfile> value : profiles.values()) {
99  			profilesList.addAll(value);
100 		}
101 		return profilesList.toArray(new ServiceProfile[0]);
102 	}
103 
104 	public void setProfiles(final Map<String, List<ServiceProfile>> profiles) {
105 		this.profiles = profiles;
106 	}
107 
108 }