blob: 9719aa2707b8cc066192043bbd81f3bb1a84de71 [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 */
Francesco Furfariec7e1752006-10-02 13:37:04 +000019
Francesco Furfarid1072b52006-05-03 07:44:48 +000020package org.apache.felix.upnp.sample.clock;
21
22import java.util.Dictionary;
23
24import org.osgi.service.upnp.UPnPAction;
25import org.osgi.service.upnp.UPnPStateVariable;
26
27/*
Karl Paulsd312acc2007-06-18 20:38:33 +000028* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
Francesco Furfarid1072b52006-05-03 07:44:48 +000029*/
30
31public class SetTimeAction implements UPnPAction {
32
33 final private String NAME = "SetTime";
34 final private String NEW_TIME_VALUE = "NewTime";
35 final private String NEW_RESULT_VALUE = "Result";
36 final private String[] IN_ARG_NAMES = new String[]{NEW_TIME_VALUE};
37 final private String[] OUT_ARG_NAMES = new String[]{NEW_RESULT_VALUE};
38 private UPnPStateVariable time,result;
39
40
41 public SetTimeAction(UPnPStateVariable time,UPnPStateVariable result){
42 this.time = time;
43 this.result=result;
44 }
45
46 /* (non-Javadoc)
47 * @see org.osgi.service.upnp.UPnPAction#getName()
48 */
49 public String getName() {
50 return NAME;
51 }
52
53 /* (non-Javadoc)
54 * @see org.osgi.service.upnp.UPnPAction#getReturnArgumentName()
55 */
56 public String getReturnArgumentName() {
57 return "Result";
58 }
59
60 /* (non-Javadoc)
61 * @see org.osgi.service.upnp.UPnPAction#getInputArgumentNames()
62 */
63 public String[] getInputArgumentNames() {
64 return IN_ARG_NAMES;
65 }
66
67 /* (non-Javadoc)
68 * @see org.osgi.service.upnp.UPnPAction#getOutputArgumentNames()
69 */
70 public String[] getOutputArgumentNames() {
71 return OUT_ARG_NAMES;
72 }
73
74 /* (non-Javadoc)
75 * @see org.osgi.service.upnp.UPnPAction#getStateVariable(java.lang.String)
76 */
77 public UPnPStateVariable getStateVariable(String argumentName) {
78 if (argumentName.equals("NewTime")) return time;
79 else if (argumentName.equals("Result")) return result;
80 else return null;
81 }
82
83 /* (non-Javadoc)
84 *
85 * @see org.osgi.service.upnp.UPnPAction#invoke(java.util.Dictionary)
86 */
87 public Dictionary invoke(Dictionary args) throws Exception {
88 //Date value = (Date) args.get(NEW_TIME_VALUE);
89 long l = ((Long) args.get(NEW_TIME_VALUE)).longValue();
90 ((TimeStateVariable) time).setCurrentTime(l);
91 args.remove(NEW_TIME_VALUE);
92 args.put(NEW_RESULT_VALUE,((TimeStateVariable) time).getCurrentTime());
93 return args;
94 }
95}