org.simpleframework.xml.transform.Transformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-xml Show documentation
Show all versions of simple-xml Show documentation
Simple is a high performance XML serialization and configuration framework for Java
The newest version!
/*
* Transformer.java May 2007
*
* Copyright (C) 2007, Niall Gallagher
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.simpleframework.xml.transform;
import java.util.Map;
import org.simpleframework.xml.util.Cache;
import org.simpleframework.xml.util.ConcurrentCache;
/**
* The Transformer
object is used to convert strings to
* and from object instances. This is used during the serialization
* and deserialization process to transform types from the Java class
* libraries, as well as other types which do not contain XML schema
* annotations. Typically this will be used to transform primitive
* types to and from strings, such as int
values.
*
*
* @Element
* private String[] value;
*
*
* For example taking the above value the array of strings needs to
* be converted in to a single string value that can be inserted in
* to the element in such a way that in can be read later. In this
* case the serialized value of the string array would be as follows.
*
*
* <value>one, two, three</value>
*
*
* Here each non-null string is inserted in to a comma separated
* list of values, which can later be deserialized. Just to note the
* above array could be annotated with ElementList
just
* as easily, in which case each entry would have its own element.
* The choice of which annotation to use is up to the developer. A
* more obvious benefit to transformations like this can be seen for
* values annotated with the Attribute
annotation.
*
* @author Niall Gallagher
*/
public class Transformer {
/**
* This is used to cache all transforms matched to a given type.
*/
private final Cache cache;
/**
* This is used to cache the types that to not have a transform.
*/
private final Cache