1 /*
2 * Copyright 2022 Búraló Technologies
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 package com.buralotech.oss.identifier.spring;
18
19 import com.buralotech.oss.identifier.api.Identifier;
20 import com.buralotech.oss.identifier.api.IdentifierService;
21 import org.springframework.core.convert.converter.Converter;
22
23 /**
24 * Used to bind/inject identifiers in their text representation as identifiers objects.
25 */
26 public class IdentifierConverter implements Converter<String, Identifier> {
27
28 /**
29 * The identifier service.
30 */
31 private final IdentifierService identifierService;
32
33 /**
34 * Initialise the converter.
35 *
36 * @param identifierService The identifier service.
37 */
38 public IdentifierConverter(final IdentifierService identifierService) {
39 this.identifierService = identifierService;
40 }
41
42 /**
43 * Perform the conversion by delegating to the identifier service.
44 *
45 * @param source The textual representation of the identifier.
46 * @return The identifier object.
47 */
48 @Override
49 public Identifier convert(final String source) {
50 return identifierService.fromText(source);
51 }
52 }