Skip to content

Method: XStreamContext1()

1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.thesefoolishthings.examples.dci.marshal.role;
28:
29: import com.thoughtworks.xstream.XStream;
30: import com.thoughtworks.xstream.io.xml.StaxDriver;
31: import com.thoughtworks.xstream.security.AnyTypePermission;
32: import it.tidalwave.dci.annotation.DciContext;
33: import it.tidalwave.thesefoolishthings.examples.dci.marshal.xstream.converter.IdXStreamConverter;
34: import it.tidalwave.thesefoolishthings.examples.dci.marshal.xstream.converter.PersonConverter;
35: import it.tidalwave.thesefoolishthings.examples.person.ListOfPersons;
36: import it.tidalwave.thesefoolishthings.examples.person.Person;
37: import lombok.Getter;
38:
39: /***********************************************************************************************************************
40: *
41: * A DCI local Context that provides an {@link XStream} for a few datum classes.
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: // START SNIPPET: xstreamcontext
47: @DciContext
48: public class XStreamContext1 implements XStreamContext
49: {
50: @Getter
51: private final XStream xStream = new XStream(new StaxDriver());
52:
53: public XStreamContext1()
54: {
55: // xStream.alias("person", PersonConverter.MutablePerson.class);
56: xStream.alias("person", Person.class);
57: xStream.aliasField("first-name", PersonConverter.MutablePerson.class, "firstName");
58: xStream.aliasField("last-name", PersonConverter.MutablePerson.class, "lastName");
59: xStream.useAttributeFor(PersonConverter.MutablePerson.class, "id");
60: xStream.registerConverter(new IdXStreamConverter());
61: xStream.registerConverter(new PersonConverter());
62:
63: xStream.alias("persons", ListOfPersons.class);
64: xStream.addImplicitCollection(ListOfPersons.class, "persons");
65:
66: xStream.addPermission(AnyTypePermission.ANY);
67: }
68: }
69: // END SNIPPET: xstreamcontext