Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 1 | /* |
| 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 Rop | 30ff986 | 2013-10-15 16:57:40 +0000 | [diff] [blame] | 19 | package org.apache.felix.dm.test.components; |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 20 | |
| 21 | import java.util.HashMap; |
| 22 | import java.util.Map; |
| 23 | |
Pierre De Rop | ee1c807 | 2010-09-08 19:40:35 +0000 | [diff] [blame] | 24 | import org.apache.felix.dm.annotation.api.Component; |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 25 | import org.apache.felix.dm.annotation.api.Property; |
| 26 | import org.apache.felix.dm.annotation.api.ServiceDependency; |
| 27 | import org.apache.felix.dm.annotation.api.Start; |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * This test validates that a basic Service may specify some extra service properties |
| 31 | * from it's start callback |
| 32 | */ |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 33 | public class ExtraServiceProperties { |
Pierre De Rop | 428a9f1 | 2013-10-14 19:35:03 +0000 | [diff] [blame] | 34 | public final static String ENSURE = "ExtraServiceProperties"; |
| 35 | |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 36 | public interface Provider { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 39 | @Component(properties = {@Property(name = "foo", value = "bar")}) |
| 40 | public static class ProviderImpl implements Provider { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 41 | @Start |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 42 | Map<String, String> start() { |
| 43 | return new HashMap<String, String>() { |
| 44 | { |
| 45 | put("foo2", "bar2"); |
| 46 | } |
| 47 | }; |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 50 | |
Pierre De Rop | ee1c807 | 2010-09-08 19:40:35 +0000 | [diff] [blame] | 51 | @Component |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 52 | public static class Consumer { |
Pierre De Rop | 428a9f1 | 2013-10-14 19:35:03 +0000 | [diff] [blame] | 53 | @ServiceDependency(filter = "(name=" + ENSURE + ")") |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 54 | volatile Ensure m_sequencer; |
| 55 | |
| 56 | private volatile Map m_properties; |
| 57 | |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 58 | @ServiceDependency |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 59 | void bindProvider(Map properties, Provider m_provider) { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 60 | m_properties = properties; |
| 61 | } |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 62 | |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 63 | @Start |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 64 | void start() { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 65 | System.out.println("provider service properties: " + m_properties); |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 66 | if ("bar".equals(m_properties.get("foo"))) { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 67 | m_sequencer.step(1); |
| 68 | } |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 69 | |
| 70 | if ("bar2".equals(m_properties.get("foo2"))) { |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 71 | m_sequencer.step(2); |
Pierre De Rop | 3abce08 | 2013-10-13 21:05:35 +0000 | [diff] [blame] | 72 | } |
Pierre De Rop | 92ca37e | 2010-08-10 21:19:44 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |