blob: 74d0b5dffe5cbc14a7e19a61a52bab72fd1c008b [file] [log] [blame]
Francesco Furfariec7e1752006-10-02 13:37:04 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
Francesco Furfarid1072b52006-05-03 07:44:48 +00009 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Francesco Furfarid1072b52006-05-03 07:44:48 +000011 *
Francesco Furfariec7e1752006-10-02 13:37:04 +000012 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
Francesco Furfarid1072b52006-05-03 07:44:48 +000018 */
19
Francesco Furfarid1072b52006-05-03 07:44:48 +000020package org.apache.felix.upnp.sample.binaryLight;
21
22import java.util.HashMap;
23
24import org.osgi.service.upnp.UPnPAction;
25import org.osgi.service.upnp.UPnPService;
26import org.osgi.service.upnp.UPnPStateVariable;
27
28/*
Karl Paulsd312acc2007-06-18 20:38:33 +000029* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarid1072b52006-05-03 07:44:48 +000030*/
31
32public class PowerSwitchService implements UPnPService{
33
34 final private String SERVICE_ID = "urn:upnp-org:serviceId:SwitchPower:1";
35 final private String SERVICE_TYPE = "urn:schemas-upnp-org:service:SwitchPower:1";
36 final private String VERSION ="1";
37
38 private LightModel model;
39 private UPnPStateVariable status,target;
40 private UPnPStateVariable[] states;
41 private HashMap actions = new HashMap();
42
43
44 public PowerSwitchService(LightModel model){
45 this.model = model;
46 status = new StatusStateVariable();
47 target = new TargetStateVariable();
48 this.states = new UPnPStateVariable[]{status,target};
49
50 UPnPAction setTarget = new SetTargetAction(model,target);
51 UPnPAction getTarget = new GetTargetAction(model,target);
52 UPnPAction getStatus = new GetStatusAction(model,status);
53 actions.put(setTarget.getName(),setTarget);
54 actions.put(getTarget.getName(),getTarget);
55 actions.put(getStatus.getName(),getStatus);
56
57 }
58
59 /* (non-Javadoc)
60 * @see org.osgi.service.upnp.UPnPService#getId()
61 */
62 public String getId() {
63 return SERVICE_ID;
64 }
65
66 /* (non-Javadoc)
67 * @see org.osgi.service.upnp.UPnPService#getType()
68 */
69 public String getType() {
70 return SERVICE_TYPE;
71 }
72
73 /* (non-Javadoc)
74 * @see org.osgi.service.upnp.UPnPService#getVersion()
75 */
76 public String getVersion() {
77 return VERSION;
78 }
79
80 /* (non-Javadoc)
81 * @see org.osgi.service.upnp.UPnPService#getAction(java.lang.String)
82 */
83 public UPnPAction getAction(String name) {
84 return (UPnPAction)actions.get(name);
85 }
86
87 /* (non-Javadoc)
88 * @see org.osgi.service.upnp.UPnPService#getActions()
89 */
90 public UPnPAction[] getActions() {
91 return (UPnPAction[])(actions.values()).toArray(new UPnPAction[]{});
92 }
93
94 /* (non-Javadoc)
95 * @see org.osgi.service.upnp.UPnPService#getStateVariables()
96 */
97 public UPnPStateVariable[] getStateVariables() {
98 return states;
99 }
100
101 /* (non-Javadoc)
102 * @see org.osgi.service.upnp.UPnPService#getStateVariable(java.lang.String)
103 */
104 public UPnPStateVariable getStateVariable(String name) {
105 if (name.equals("Status"))
106 return status;
107 else if (name.equals("Target"))
108 return target;
109 else return null;
110 }
111}