Carsten Ziegeler | 55c96d3 | 2012-06-13 12:03:35 +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 | */ |
| 19 | package org.apache.felix.scrplugin.description; |
| 20 | |
| 21 | /** |
| 22 | * Options for {@link ReferenceDescription#getCardinality()} |
| 23 | */ |
| 24 | public enum ReferenceCardinality { |
| 25 | |
| 26 | /** |
| 27 | * Optional, unary reference: No service required to be available for the |
| 28 | * refernce to be satisfied. Only a single service is available through this |
| 29 | * reference. |
| 30 | */ |
| 31 | OPTIONAL_UNARY("0..1"), |
| 32 | |
| 33 | /** |
| 34 | * Mandatory, unary reference: At least one service must be available for |
| 35 | * the reference to be satisfied. Only a single service is available through |
| 36 | * this reference. |
| 37 | */ |
| 38 | MANDATORY_UNARY("1..1"), |
| 39 | |
| 40 | /** |
| 41 | * Optional, multiple reference: No service required to be available for the |
| 42 | * refernce to be satisfied. All matching services are available through |
| 43 | * this reference. |
| 44 | */ |
| 45 | OPTIONAL_MULTIPLE("0..n"), |
| 46 | |
| 47 | /** |
| 48 | * Mandatory, multiple reference: At least one service must be available for |
| 49 | * the reference to be satisified. All matching services are available |
| 50 | * through this reference. |
| 51 | */ |
| 52 | MANDATORY_MULTIPLE("1..n"); |
| 53 | |
| 54 | private final String cardinalityString; |
| 55 | |
| 56 | private ReferenceCardinality(final String cardinalityString) { |
| 57 | this.cardinalityString = cardinalityString; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return String representation of cardinality |
| 62 | */ |
| 63 | public String getCardinalityString() { |
| 64 | return this.cardinalityString; |
| 65 | } |
| 66 | |
| 67 | public static ReferenceCardinality fromValue(final String value) { |
| 68 | for(final ReferenceCardinality rd : ReferenceCardinality.values() ) { |
| 69 | if ( rd.getCardinalityString().equals(value) ) { |
| 70 | return rd; |
| 71 | } |
| 72 | } |
| 73 | return null; |
| 74 | } |
| 75 | } |