blob: 54f19162aa4bc172229dbbd9325f847c0cc983fe [file] [log] [blame]
Pierre De Rop92ca37e2010-08-10 21:19:44 +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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * 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.
18 */
Pierre De Rop30ff9862013-10-15 16:57:40 +000019package org.apache.felix.dm.test.components;
Pierre De Rop92ca37e2010-08-10 21:19:44 +000020
21import java.util.HashMap;
22import java.util.Map;
23
Pierre De Ropee1c8072010-09-08 19:40:35 +000024import org.apache.felix.dm.annotation.api.Component;
Pierre De Rop92ca37e2010-08-10 21:19:44 +000025import org.apache.felix.dm.annotation.api.Property;
26import org.apache.felix.dm.annotation.api.ServiceDependency;
27import org.apache.felix.dm.annotation.api.Start;
Pierre De Rop92ca37e2010-08-10 21:19:44 +000028
29/**
30 * This test validates that a basic Service may specify some extra service properties
31 * from it's start callback
32 */
Pierre De Rop3abce082013-10-13 21:05:35 +000033public class ExtraServiceProperties {
Pierre De Rop428a9f12013-10-14 19:35:03 +000034 public final static String ENSURE = "ExtraServiceProperties";
35
Pierre De Rop3abce082013-10-13 21:05:35 +000036 public interface Provider {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000037 }
38
Pierre De Rop3abce082013-10-13 21:05:35 +000039 @Component(properties = {@Property(name = "foo", value = "bar")})
40 public static class ProviderImpl implements Provider {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000041 @Start
Pierre De Rop3abce082013-10-13 21:05:35 +000042 Map<String, String> start() {
43 return new HashMap<String, String>() {
44 {
45 put("foo2", "bar2");
46 }
47 };
Pierre De Rop92ca37e2010-08-10 21:19:44 +000048 }
49 }
Pierre De Rop3abce082013-10-13 21:05:35 +000050
Pierre De Ropee1c8072010-09-08 19:40:35 +000051 @Component
Pierre De Rop3abce082013-10-13 21:05:35 +000052 public static class Consumer {
Pierre De Rop428a9f12013-10-14 19:35:03 +000053 @ServiceDependency(filter = "(name=" + ENSURE + ")")
Pierre De Rop3abce082013-10-13 21:05:35 +000054 volatile Ensure m_sequencer;
55
56 private volatile Map m_properties;
57
Pierre De Rop92ca37e2010-08-10 21:19:44 +000058 @ServiceDependency
Pierre De Rop3abce082013-10-13 21:05:35 +000059 void bindProvider(Map properties, Provider m_provider) {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000060 m_properties = properties;
61 }
Pierre De Rop3abce082013-10-13 21:05:35 +000062
Pierre De Rop92ca37e2010-08-10 21:19:44 +000063 @Start
Pierre De Rop3abce082013-10-13 21:05:35 +000064 void start() {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000065 System.out.println("provider service properties: " + m_properties);
Pierre De Rop3abce082013-10-13 21:05:35 +000066 if ("bar".equals(m_properties.get("foo"))) {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000067 m_sequencer.step(1);
68 }
Pierre De Rop3abce082013-10-13 21:05:35 +000069
70 if ("bar2".equals(m_properties.get("foo2"))) {
Pierre De Rop92ca37e2010-08-10 21:19:44 +000071 m_sequencer.step(2);
Pierre De Rop3abce082013-10-13 21:05:35 +000072 }
Pierre De Rop92ca37e2010-08-10 21:19:44 +000073 }
74 }
75}