• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, SnakeYAML
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package examples.spring;
15 
16 import org.yaml.snakeyaml.TypeDescription;
17 import org.yaml.snakeyaml.nodes.Node;
18 
19 /**
20  * This description is supposed to work like this:
21  *
22  * 1) Counter is retrieved from dataRegistry and is set before deserializing data from YAML; 2) Id
23  * is deserialized from YAML, using standard SnakeYAML logic for Strings and is impacted by Counter
24  * that was set before; 3) Data is being retrieved from injected DataRegistry bean using the id;
25  *
26  */
27 public class TestEntityDescription extends TypeDescription {
28 
29   private DataRegistry dataRegistry;
30 
TestEntityDescription()31   public TestEntityDescription() {
32     super(TestEntity.class, TestEntity.class);
33   }
34 
35   @Override
newInstance(Node node)36   public Object newInstance(Node node) {
37     TestEntity entity = (TestEntity) super.newInstance(node);
38     entity.setCounter(dataRegistry.getNextCounterValue());
39     return entity;
40   }
41 
42   @Override
finalizeConstruction(Object obj)43   public Object finalizeConstruction(Object obj) {
44     TestEntity entity = (TestEntity) super.finalizeConstruction(obj);
45     entity.setData(dataRegistry.getDataForId(entity.getId()));
46     return entity;
47   }
48 
setDataRegistry(DataRegistry dataRegistry)49   public void setDataRegistry(DataRegistry dataRegistry) {
50     this.dataRegistry = dataRegistry;
51   }
52 }
53