View Javadoc

1   /*
2    * Copyright 2007 the original author or authors.
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 org.springframework.oxm.xstream;
18  
19  import com.thoughtworks.xstream.XStream;
20  import com.thoughtworks.xstream.annotations.Annotations;
21  import com.thoughtworks.xstream.annotations.XStreamAlias;
22  import org.springframework.util.Assert;
23  
24  /**
25   * Subclass of the {@link XStreamMarshaller} that supports JDK 1.5+ annotation metadata for aliases.
26   *
27   * @author Arjen Poutsma
28   * @see XStreamAlias
29   * @since 1.0.2
30   */
31  public class AnnotationXStreamMarshaller extends XStreamMarshaller {
32  
33      /**
34       * Sets the classes, for which mappings will be read from class-level JDK 1.5+ annotation metadata.
35       *
36       * @see Annotations#configureAliases(XStream, Class[])
37       */
38      public void setAnnotatedClass(Class<?> annotatedClass) {
39          Assert.notNull(annotatedClass, "'annotatedClass' must not be null");
40          Annotations.configureAliases(getXStream(), annotatedClass);
41      }
42  
43      /**
44       * Sets annotated classes, for which aliases will be read from class-level JDK 1.5+ annotation metadata.
45       *
46       * @see Annotations#configureAliases(XStream, Class[])
47       */
48      public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
49          Assert.notEmpty(annotatedClasses, "'annotatedClasses' must not be empty");
50          Annotations.configureAliases(getXStream(), annotatedClasses);
51      }
52  
53  }