Package list libxstream-java / 950f48b
Imported Upstream version 1.4.9 Emmanuel Bourg 5 years ago
211 changed file(s) with 6253 addition(s) and 1656 deletion(s). Raw diff Collapse all Expand all
0 * text=auto
1
2 *.css text
3 *.diff text
4 *.htm* text
5 *.java text
6 *.js text
7 *.md text
8 *.patch text
9 *.txt text
10 *.xml text
11
12 *.gif binary
13 *.jpg binary
14 *.png binary
15 *.psp binary
16 *.vsd binary
0 .*
1 target
2 *.iml
0 language: java
1 jdk:
2 - oraclejdk8
3 - oraclejdk7
4 - openjdk6
5 install: true
6 script: "mvn -V -B -e clean package"
7 cache:
8 directories:
9 - $HOME/.m2
0 For Java 5 or higher build with Maven 2.2 or 3
0 For Java 6 or higher build with Maven 3.2.5 or higher
1 For Java 5 build with Maven 3.0.5
12 For Java 1.4 build with Maven 2.0.11
23
34 Before building:
89
910 Before deploying:
1011
11 copy settings-template.xml to ~/.m2/settings.xml adding your Codehaus DAV username and passwords.
12 copy settings-template.xml to ~/.m2/settings.xml adding your Sonatype OSSRH
13 username and passwords.
1214
1315 To deploy (optionally adding sources and javadoc jars):
1416 mvn deploy
00 (BSD Style License)
11
22 Copyright (c) 2003-2006, Joe Walnes
3 Copyright (c) 2006-2011, XStream Committers
3 Copyright (c) 2006-2015, XStream Committers
44 All rights reserved.
55
66 Redistribution and use in source and binary forms, with or without
0 [![Build Status](https://travis-ci.org/x-stream/xstream.svg?branch=v-1.4.x)](https://travis-ci.org/x-stream/xstream)
1 ----
2 # XStream
3 _Java to XML Serialization, and back again_
4
5 ## Binaries
6 All binary artifacts are bundled in the -bin archive. It includes
7 the XStream jars and any other library used at build time, or
8 optional runtime extras. Xpp3 is recommend for use as it will
9 greatly improve the performance of XStream.
10
11 ## Documentation
12 Documentation can be found at [GitHub](http://x-stream.github.io). This
13 includes:
14 * Introduction and tutorial
15 * JavaDoc
16 * Change log
17 * Frequently asked questions
18
19 ## Source
20 The complete source for XStream is bundled in the -src archive. This includes:
21 * Main API [xstream/src/java]
22 * Unit tests [xstream/src/test]
23 * Maven build files [pom.xml]
24 * Hibernate module [xstream-hibernate]
25 * Web site [xstream-distribution]
26
77
88 --[ Binaries ]-----------------------------------------------
99
10 All binary artifacts are in the 'lib' directory. These include the
11 xstream jars and any other library used at build time,
12 or optional runtime extras. kXML2 is recommend for use as it will
10 All binary artifacts are bundled in the -bin archive. It includes
11 the XStream jars and any other library used at build time, or
12 optional runtime extras. Xpp3 is recommend for use as it will
1313 greatly improve the performance of XStream.
1414
1515 --[ Documentation ]------------------------------------------
1616
17 Documentation can be found in docs/index.html. This includes:
17 Documentation can be found at http://x-stream.github.io. This
18 includes:
1819 * Introduction and tutorial
1920 * JavaDoc
2021 * Change log
2223
2324 --[ Source ]-------------------------------------------------
2425
25 The complete source for XStream is bundled. This includes:
26 * Main API [src/java]
27 * Unit tests [src/test]
26 The complete source for XStream is bundled in the -src archive.
27 This includes:
28 * Main API [xstream/src/java]
29 * Unit tests [xstream/src/test]
2830 * Maven build files [pom.xml]
29 * Dependencies [lib]
31 * Hibernate module [xstream-hibernate]
32 * Web site [xstream-distribution]
3033
3134 -------------------------------------------------------------
3235
33 -XStream Ccommitters
36 - XStream Committers
3437
35 http://xstream.codehaus.org/
38 http://x-stream.github.io/
3639
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1010 Created on 29. July 2006 by Mauro Talevi
1111 -->
1212 <modelVersion>4.0.0</modelVersion>
13 <parent>
14 <groupId>org.codehaus</groupId>
15 <artifactId>codehaus-parent</artifactId>
16 <version>3</version><!-- 4 required Java 5 -->
17 <relativePath />
18 </parent>
1913 <groupId>com.thoughtworks.xstream</groupId>
2014 <artifactId>xstream-parent</artifactId>
2115 <packaging>pom</packaging>
22 <version>1.4.8</version>
16 <version>1.4.9</version>
2317 <name>XStream Parent</name>
18 <url>http://x-stream.github.io</url>
2419 <description>
2520 XStream is a serialization library from Java objects to XML and back.
2621 </description>
2823 <inceptionYear>2004</inceptionYear>
2924 <organization>
3025 <name>XStream</name>
31 <url>http://xstream.codehaus.org</url>
26 <url>http://x-stream.github.io</url>
3227 </organization>
28
29 <developers>
30 <developer>
31 <id>xstream</id>
32 <name>XStream Committers</name>
33 <url>http://x-stream.github.io/team.html</url>
34 </developer>
35 </developers>
3336
3437 <profiles>
3538 <profile>
5255 </properties>
5356 </profile>
5457 <profile>
55 <id>jdk15-ge</id>
58 <!-- build with Maven 3.2.5 !!! -->
59 <id>jdk16-ge</id>
5660 <activation>
57 <jdk>[1.5,)</jdk>
61 <jdk>[1.6,)</jdk>
5862 </activation>
59 <build>
60 <plugins>
61 <plugin>
62 <groupId>org.apache.felix</groupId>
63 <artifactId>maven-bundle-plugin</artifactId>
64 <executions>
65 <execution>
66 <id>bundle-manifest</id>
67 <phase>process-classes</phase>
68 <goals>
69 <goal>manifest</goal>
70 </goals>
71 </execution>
72 </executions>
73 </plugin>
74 </plugins>
75 </build>
7663 <modules>
77 <!--module>xstream-builder</module-->
64 <module>xstream-jmh</module>
65 <module>xstream-distribution</module>
7866 </modules>
7967 </profile>
8068 <profile>
69 <!-- build with Maven 3.0.5 !!! -->
8170 <id>jdk15</id>
8271 <activation>
8372 <jdk>1.5</jdk>
9685 <properties>
9786 <version.java.source>1.3</version.java.source>
9887 <version.java.target>1.3</version.java.target>
88 <version.plugin.maven.enforcer>1.0-beta-1</version.plugin.maven.enforcer>
9989 <link.javadoc.javase>http://docs.oracle.com/javase/1.4.2/docs/api/</link.javadoc.javase>
10090 <!-- repeat Hibernate version dependencies, JDK intervals in activation is not supported with M2.0.x -->
10191 <version.hsqldb>1.8.0.10</version.hsqldb>
112102 </activation>
113103 <build>
114104 <plugins>
105 <plugin>
106 <groupId>org.apache.maven.plugins</groupId>
107 <artifactId>maven-source-plugin</artifactId>
108 </plugin>
115109 <plugin>
116110 <groupId>org.apache.maven.plugins</groupId>
117111 <artifactId>maven-enforcer-plugin</artifactId>
137131 </build>
138132 </profile>
139133 <profile>
134 <id>osgi</id>
135 <activation>
136 <jdk>[1.6,)</jdk>
137 <file>
138 <exists>profiles/osgi</exists>
139 </file>
140 </activation>
141 <build>
142 <plugins>
143 <plugin>
144 <groupId>org.apache.felix</groupId>
145 <artifactId>maven-bundle-plugin</artifactId>
146 <executions>
147 <execution>
148 <id>bundle-manifest</id>
149 <phase>process-classes</phase>
150 <goals>
151 <goal>manifest</goal>
152 </goals>
153 </execution>
154 </executions>
155 <configuration>
156 <instructions combine.children="append">
157 <Export-Package>${bundle.export.package}</Export-Package>
158 </instructions>
159 </configuration>
160 </plugin>
161 <plugin>
162 <groupId>org.apache.maven.plugins</groupId>
163 <artifactId>maven-jar-plugin</artifactId>
164 <executions>
165 <execution>
166 <id>default-jar</id>
167 <goals>
168 <goal>jar</goal>
169 </goals>
170 <configuration>
171 <archive combine.children="append">
172 <manifestFile>${project.build.directory}/OSGi/MANIFEST.MF</manifestFile>
173 </archive>
174 </configuration>
175 </execution>
176 </executions>
177 </plugin>
178 </plugins>
179 </build>
180 <properties>
181 <bundle.export.package>${project.groupId}.*;-noimport:=true</bundle.export.package>
182 </properties>
183 </profile>
184 <profile>
140185 <id>xstream-release</id>
141186 <properties>
142187 <version.java.enforced>[1.8,1.9)</version.java.enforced>
165210 <module>xstream</module>
166211 <module>xstream-hibernate</module>
167212 <module>xstream-benchmark</module>
168 <module>xstream-distribution</module>
169213 </modules>
170214
171215 <licenses>
172216 <license>
173217 <name>BSD style</name>
174 <url>http://xstream.codehaus.org/license.html</url>
218 <url>http://x-stream.github.io/license.html</url>
175219 <distribution>repo</distribution>
176220 </license>
177221 </licenses>
178222
223 <issueManagement>
224 <system>github</system>
225 <url>https://github.com/x-stream/xstream/issues/</url>
226 </issueManagement>
227 <ciManagement>
228 <system>Travis</system>
229 <url>https://travis-ci.org/x-stream/xstream</url>
230 </ciManagement>
231 <mailingLists>
232 <mailingList>
233 <name>XStream Users List</name>
234 <subscribe>xstream-user+subscribe@googlegroups.com</subscribe>
235 <unsubscribe>xstream-user+unsubscribe@googlegroups.com</unsubscribe>
236 <post>xstream-user@googlegroups.com</post>
237 <archive>https://groups.google.com/forum/#!forum/xstream-user</archive>
238 <otherArchives>
239 <otherArchive>http://news.gmane.org/gmane.comp.java.xstream.user</otherArchive>
240 <otherArchive>http://markmail.org/search/list:org.codehaus.xstream.user</otherArchive>
241 </otherArchives>
242 </mailingList>
243 <mailingList>
244 <name>XStream Notifications List</name>
245 <subscribe>xstream-notifications+subscribe@googlegroups.com</subscribe>
246 <unsubscribe>xstream-notifications+unsubscribe@googlegroups.com</unsubscribe>
247 <post>xstream-notifications@googlegroups.com</post>
248 <archive>https://groups.google.com/forum/#!forum/xstream-notifications</archive>
249 <otherArchives>
250 <otherArchive>http://news.gmane.org/gmane.comp.java.xstream.scm</otherArchive>
251 </otherArchives>
252 </mailingList>
253 <mailingList>
254 <name>Former (pre-2015-06) Development List</name>
255 <archive>http://news.gmane.org/gmane.comp.java.xstream.dev</archive>
256 <otherArchives>
257 <otherArchive>http://markmail.org/search/list:org.codehaus.xstream.dev</otherArchive>
258 </otherArchives>
259 </mailingList>
260 <mailingList>
261 <name>Former (pre-2015-06) Announcements List</name>
262 <archive>http://markmail.org/search/list:org.codehaus.xstream.announce</archive>
263 </mailingList>
264 </mailingLists>
265
179266 <dependencyManagement>
180267 <dependencies>
181268 <dependency>
182269 <groupId>com.thoughtworks.xstream</groupId>
183270 <artifactId>xstream</artifactId>
184 <version>1.4.8</version>
271 <version>1.4.9</version>
185272 </dependency>
186273 <dependency>
187274 <groupId>com.thoughtworks.xstream</groupId>
188275 <artifactId>xstream</artifactId>
189 <version>1.4.8</version>
276 <version>1.4.9</version>
190277 <classifier>tests</classifier>
191278 <type>test-jar</type>
192279 <scope>test</scope>
194281 <dependency>
195282 <groupId>com.thoughtworks.xstream</groupId>
196283 <artifactId>xstream</artifactId>
197 <version>1.4.8</version>
284 <version>1.4.9</version>
198285 <classifier>javadoc</classifier>
199286 <scope>provided</scope>
200287 </dependency>
201288 <dependency>
202289 <groupId>com.thoughtworks.xstream</groupId>
203290 <artifactId>xstream-hibernate</artifactId>
204 <version>1.4.8</version>
291 <version>1.4.9</version>
205292 </dependency>
206293 <dependency>
207294 <groupId>com.thoughtworks.xstream</groupId>
208295 <artifactId>xstream-hibernate</artifactId>
209 <version>1.4.8</version>
296 <version>1.4.9</version>
210297 <classifier>javadoc</classifier>
211298 <scope>provided</scope>
212299 </dependency>
213300 <dependency>
214301 <groupId>com.thoughtworks.xstream</groupId>
215 <artifactId>xstream-benchmark</artifactId>
216 <version>1.4.8</version>
302 <artifactId>xstream-jmh</artifactId>
303 <version>1.4.9</version>
304 </dependency>
305 <dependency>
306 <groupId>com.thoughtworks.xstream</groupId>
307 <artifactId>xstream-jmh</artifactId>
308 <version>1.4.9</version>
309 <classifier>javadoc</classifier>
310 <scope>provided</scope>
217311 </dependency>
218312 <dependency>
219313 <groupId>com.thoughtworks.xstream</groupId>
220314 <artifactId>xstream-benchmark</artifactId>
221 <version>1.4.8</version>
315 <version>1.4.9</version>
316 </dependency>
317 <dependency>
318 <groupId>com.thoughtworks.xstream</groupId>
319 <artifactId>xstream-benchmark</artifactId>
320 <version>1.4.9</version>
222321 <classifier>javadoc</classifier>
223322 <scope>provided</scope>
224323 </dependency>
386485 </dependency>
387486
388487 <dependency>
488 <groupId>javax.activation</groupId>
489 <artifactId>activation</artifactId>
490 <version>${version.javax.activation}</version>
491 <scope>provided</scope>
492 </dependency>
493
494 <dependency>
389495 <groupId>org.hibernate</groupId>
390496 <artifactId>hibernate-core</artifactId>
391497 <version>${version.org.hibernate.core}</version>
419525 <scope>runtime</scope>
420526 </dependency>
421527
528 <dependency>
529 <groupId>org.openjdk.jmh</groupId>
530 <artifactId>jmh-core</artifactId>
531 <version>${version.org.openjdk.jmh}</version>
532 </dependency>
533 <dependency>
534 <groupId>org.openjdk.jmh</groupId>
535 <artifactId>jmh-generator-annprocess</artifactId>
536 <version>${version.org.openjdk.jmh}</version>
537 <scope>provided</scope>
538 </dependency>
539
422540 <!-- always test-scoped -->
423541 <dependency>
424542 <groupId>junit</groupId>
426544 <version>${version.junit}</version>
427545 <scope>test</scope>
428546 </dependency>
429
430547 <dependency>
431548 <groupId>jmock</groupId>
432549 <artifactId>jmock</artifactId>
574691 <artifactId>maven-release-plugin</artifactId>
575692 <version>${version.plugin.maven.release}</version>
576693 <configuration>
694 <mavenExecutorId>forked-path</mavenExecutorId>
577695 <goals>deploy</goals>
578696 <autoVersionSubmodules>true</autoVersionSubmodules>
579 <!-- overwrite codehaus-parent -->
697 <useReleaseProfile>false</useReleaseProfile>
580698 <arguments>-Pxstream-release</arguments>
581699 </configuration>
582700 </plugin>
738856 </build>
739857
740858 <distributionManagement>
741 <!--
742 The server id codehaus-nexus-snapshots, codehaus-nexus-staging, and
743 codehaus.org must appear ~/.m2/settings.xml cf. settings-template.xml.
744 http://hausmates.codehaus.org/Codehaus+Maven+Repository+Usage+Guide
745 -->
746 <site>
747 <id>codehaus.org</id>
748 <name>Codehaus XStream Site</name>
749 <url>dav:https://dav.codehaus.org/xstream</url>
750 </site>
859 <repository>
860 <id>ossrh-staging</id>
861 <url>http://oss.sonatype.org/service/local/staging/deploy/maven2</url>
862 </repository>
863 <snapshotRepository>
864 <id>ossrh-snapshots</id>
865 <url>http://oss.sonatype.org/content/repositories/snapshots</url>
866 </snapshotRepository>
867 <!--site>
868 <id>github</id>
869 <url>scm:git:ssh://git@github.com/x-stream/x-stream.github.io.git</url>
870 </site-->
751871 </distributionManagement>
752872
753873 <scm>
754 <connection>scm:svn:http://svn.codehaus.org/xstream/tags/XSTREAM_1_4_8</connection>
755 <developerConnection>scm:svn:https://svn.codehaus.org/xstream/tags/XSTREAM_1_4_8</developerConnection>
756 <url>http://fisheye.codehaus.org/browse/xstream/tags/XSTREAM_1_4_8</url>
874 <url>http://github.com/x-stream/xstream</url>
875 <developerConnection>scm:git:https://github.com/x-stream/xstream.git</developerConnection>
876 <connection>scm:git:https://github.com/x-stream/xstream.git</connection>
877 <tag>v-1.4.x</tag>
757878 </scm>
758879
759880 <properties>
881 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
882
760883 <version.java.source>1.5</version.java.source>
761884 <version.java.target>1.5</version.java.target>
762885 <version.java.enforced>[1.4,)</version.java.enforced>
793916 <version.dom4j>1.6.1</version.dom4j>
794917 <version.hsqldb>2.2.8</version.hsqldb>
795918 <version.javaassist>3.12.1.GA</version.javaassist>
919 <version.javax.activation>1.1.1</version.javax.activation>
796920 <version.jmock>1.0.1</version.jmock>
797921 <version.joda-time>1.6</version.joda-time>
798922 <version.junit>3.8.1</version.junit>
804928 <version.org.jdom>1.1.3</version.org.jdom>
805929 <version.org.jdom2>2.0.5</version.org.jdom2>
806930 <version.org.json>20080701</version.org.json>
931 <version.org.openjdk.jmh>1.11.1</version.org.openjdk.jmh>
807932 <version.org.slf4j>1.6.1</version.org.slf4j>
808933 <version.oro>2.0.8</version.oro>
809934 <version.stax>1.2.0</version.stax>
00 <?xml version="1.0" encoding="UTF-8"?>
11 <!--
2 Copyright (C) 2006, 2007, 2010 XStream committers.
2 Copyright (C) 2006, 2007, 2010, 2015, 2016 XStream committers.
33 All rights reserved.
44
55 The software in this package is published under the terms of the BSD
1111 <settings>
1212 <servers>
1313 <server>
14 <id>codehaus-nexus-snapshots</id>
15 <username>your-xircles-id</username>
16 <password>your-xircles-pwd</password>
14 <id>ossrh-snapshots</id>
15 <username>your-sonatype.org-id</username>
16 <password>your-sonatype.org-pwd</password>
1717 </server>
1818 <server>
19 <id>codehaus-nexus-staging</id>
20 <username>your-xircles-id</username>
21 <password>your-xircles-pwd</password>
19 <id>ossrh-staging</id>
20 <username>your-sonatype.org-id</username>
21 <password>your-sonatype.org-pwd</password>
2222 </server>
23 <server>
24 <id>codehaus.org</id>
25 <username></username>
26 <password></password>
27 </server>
2823 </servers>
2924 </settings>
+0
-84
svn-autoprops.config less more
0 [auto-props]
1 *.apt = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
2 *.c = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
3 *.c++ = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
4 *.cpp = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
5 *.cs = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
6 *.css = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
7 *.dtd = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
8 *.ent = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
9 *.fml = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
10 *.groovy = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
11 *.h = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
12 *.h++ = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
13 *.hpp = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
14 *.html = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
15 *.idl = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
16 *.include = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
17 *.java = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
18 *.js = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
19 *.jsp = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
20 *.ldf = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
21 *.ldif = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
22 *.mak = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
23 *.mdo = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
24 *.php = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
25 *.rb = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
26 *.rtf = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
27 *.sql = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
28 *.svg = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
29 *.t2t = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
30 *.vm = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
31 *.xhtml = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
32 *.xml = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
33 *.xsd = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
34 *.xsl = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
35 *.xslt = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
36 Makefile = svn:eol-style=native;svn:keywords=Author Date Id HeadURL Revision
37
38 *.launch = svn:eol-style=native
39 *.MF = svn:eol-style=native
40 *.properties = svn:eol-style=native
41 *.script = svn:eol-style=native
42 *.txt = svn:eol-style=native
43
44 *.dsp = svn:eol-style=CRLF
45 *.dsw = svn:eol-style=CRLF
46
47 *.iml = svn:eol-style=LF
48
49 *.bat = svn:eol-style=CRLF;svn:executable;svn:keywords=Author Date Id HeadURL Revision
50 *.cmd = svn:eol-style=CRLF;svn:executable;svn:keywords=Author Date Id HeadURL Revision
51
52 *.ksh = svn:eol-style=LF;svn:executable;svn:keywords=Author Date Id HeadURL Revision
53 *.sh = svn:eol-style=LF;svn:executable;svn:keywords=Author Date Id HeadURL Revision
54
55 *.pl = svn:eol-style=native;svn:executable;svn:keywords=Author Date Id HeadURL Revision
56 *.py = svn:eol-style=native;svn:executable;svn:keywords=Author Date Id HeadURL Revision
57
58 *.bmp = svn:mime-type=image/bmp;svn:needs-lock=*
59 *.gif = svn:mime-type=image/gif;svn:needs-lock=*
60 *.ico = svn:mime-type=image/x-icon;svn:needs-lock=*
61 *.jpeg = svn:mime-type=image/jpeg;svn:needs-lock=*
62 *.jpg = svn:mime-type=image/jpeg;svn:needs-lock=*
63 *.png = svn:mime-type=image/png;svn:needs-lock=*
64 *.tif = svn:mime-type=image/tiff;svn:needs-lock=*
65 *.tiff = svn:mime-type=image/tiff;svn:needs-lock=*
66
67 *.doc = svn:mime-type=application/msword;svn:needs-lock=*
68 *.jar = svn:mime-type=application/octet-stream;svn:needs-lock=*
69 *.odc = svn:mime-type=application/vnd.oasis.opendocument.chart;svn:needs-lock=*
70 *.odf = svn:mime-type=application/vnd.oasis.opendocument.formula;svn:needs-lock=*
71 *.odg = svn:mime-type=application/vnd.oasis.opendocument.graphics;svn:needs-lock=*
72 *.odi = svn:mime-type=application/vnd.oasis.opendocument.image;svn:needs-lock=*
73 *.odp = svn:mime-type=application/vnd.oasis.opendocument.presentation;svn:needs-lock=*
74 *.ods = svn:mime-type=application/vnd.oasis.opendocument.spreadsheet;svn:needs-lock=*
75 *.odt = svn:mime-type=application/vnd.oasis.opendocument.text;svn:needs-lock=*
76 *.pdf = svn:mime-type=application/pdf;svn:needs-lock=*
77 *.ppt = svn:mime-type=application/vnd.ms-powerpoint;svn:needs-lock=*
78 *.ser = svn:mime-type=application/octet-stream;svn:needs-lock=*
79 *.swf = svn:mime-type=application/x-shockwave-flash;svn:needs-lock=*
80 *.vsd = svn:mime-type=application/x-visio;svn:needs-lock=*
81 *.xls = svn:mime-type=application/vnd.ms-excel;svn:needs-lock=*
82 *.zip = svn:mime-type=application/zip;svn:needs-lock=*
83
00 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
11 <!--
22 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream committers.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream committers.
44 All rights reserved.
55
66 The software in this package is published under the terms of the BSD
1313 <parent>
1414 <groupId>com.thoughtworks.xstream</groupId>
1515 <artifactId>xstream-parent</artifactId>
16 <version>1.4.8</version>
16 <version>1.4.9</version>
1717 </parent>
1818 <artifactId>xstream</artifactId>
1919 <packaging>jar</packaging>
9999 <groupId>org.codehaus.jettison</groupId>
100100 <artifactId>jettison</artifactId>
101101 <optional>true</optional>
102 </dependency>
103
104 <dependency>
105 <groupId>javax.activation</groupId>
106 <artifactId>activation</artifactId>
102107 </dependency>
103108
104109 <!-- test-scoped -->
309314 </compilerArgs>
310315 <excludes>
311316 <exclude>**/Lambda**</exclude>
317 <exclude>**/extended/PathConverter*</exclude>
312318 </excludes>
313319 <testExcludes>
314320 <exclude>**/Lambda**</exclude>
321 <exclude>**/acceptance/Extended17TypesTest*</exclude>
315322 <exclude>**/extended/*17Test*</exclude>
316323 </testExcludes>
317324 </configuration>
380387 <exclude>**/basic/UUID*</exclude>
381388 <exclude>**/core/util/Types*</exclude>
382389 <exclude>**/extended/*15*</exclude>
390 <exclude>**/extended/PathConverter*</exclude>
383391 <exclude>**/io/xml/JDom2*</exclude>
384392 </excludes>
385393 <testExcludes>
392400 <exclude>**/io/xml/JDom2*Test*</exclude>
393401 <exclude>**/acceptance/Basic15TypesTest*</exclude>
394402 <exclude>**/acceptance/Concurrent15TypesTest*</exclude>
403 <exclude>**/acceptance/Extended17TypesTest*</exclude>
395404 </testExcludes>
396405 </configuration>
397406 </plugin>
428437 </plugins>
429438 </reporting>
430439
440 <properties>
441 <bundle.export.package>!com.thoughtworks.xstream.core.util,com.thoughtworks.xstream.*;-noimport:=true</bundle.export.package>
442 </properties>
443
431444 </project>
(New empty file)
00 /*
11 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
66 * style license a copy of which has been included with this distribution in
77 * the LICENSE.txt file.
8 *
8 *
99 * Created on 26. September 2003 by Joe Walnes
1010 */
1111 package com.thoughtworks.xstream;
342342 * The instance will use the {@link XppDriver} as default and tries to determine the best
343343 * match for the {@link ReflectionProvider} on its own.
344344 * </p>
345 *
345 *
346346 * @throws InitializationException in case of an initialization problem
347347 */
348348 public XStream() {
369369 * The instance will tries to determine the best match for the {@link ReflectionProvider} on
370370 * its own.
371371 * </p>
372 *
372 *
373373 * @param hierarchicalStreamDriver the driver instance
374374 * @throws InitializationException in case of an initialization problem
375375 */
599599 mapper = new LocalConversionMapper(mapper);
600600 mapper = new ImmutableTypesMapper(mapper);
601601 if (JVM.is18()) {
602 mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
603 new Object[]{mapper});
602 mapper =
603 buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
604 new Object[]{mapper});
604605 }
605606 mapper = new SecurityMapper(mapper);
606607 if (JVM.is15()) {
733734 alias("awt-color", JVM.loadClassForName("java.awt.Color", false));
734735 alias("awt-font", JVM.loadClassForName("java.awt.Font", false));
735736 alias("awt-text-attribute", JVM.loadClassForName("java.awt.font.TextAttribute"));
737
738 // only available in Java 5 when javax.activation:activation is available on CP
739 Class type = JVM.loadClassForName("javax.activation.ActivationDataFlavor");
740 if (type != null) {
741 alias("activation-data-flavor", type);
742 }
736743 }
737744
738745 if (JVM.isSQLAvailable()) {
762769 alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder"));
763770 alias("uuid", JVM.loadClassForName("java.util.UUID"));
764771 }
772
773 if (JVM.is17()) {
774 aliasType("path", JVM.loadClassForName("java.nio.file.Path"));
775 }
776
765777 if (JVM.loadClassForName("java.lang.invoke.SerializedLambda") != null) {
766778 aliasDynamically("serialized-lambda", "java.lang.invoke.SerializedLambda");
767779 }
892904 "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
893905 null, null);
894906 }
907 if (JVM.loadClassForName("javax.activation.ActivationDataFlavor") != null) {
908 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.ActivationDataFlavorConverter",
909 PRIORITY_NORMAL, null, null);
910 }
911 if (JVM.is17()) {
912 registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter",
913 PRIORITY_NORMAL, null, null);
914 }
895915 if (JVM.is18()) {
896916 registerConverterDynamically("com.thoughtworks.xstream.converters.reflection.LambdaConverter",
897917 PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class, ClassLoaderReference.class},
928948 }
929949
930950 // primitives are always immutable
931 addImmutableType(boolean.class);
932 addImmutableType(Boolean.class);
933 addImmutableType(byte.class);
934 addImmutableType(Byte.class);
935 addImmutableType(char.class);
936 addImmutableType(Character.class);
937 addImmutableType(double.class);
938 addImmutableType(Double.class);
939 addImmutableType(float.class);
940 addImmutableType(Float.class);
941 addImmutableType(int.class);
942 addImmutableType(Integer.class);
943 addImmutableType(long.class);
944 addImmutableType(Long.class);
945 addImmutableType(short.class);
946 addImmutableType(Short.class);
951 addImmutableType(boolean.class, false);
952 addImmutableType(Boolean.class, false);
953 addImmutableType(byte.class, false);
954 addImmutableType(Byte.class, false);
955 addImmutableType(char.class, false);
956 addImmutableType(Character.class, false);
957 addImmutableType(double.class, false);
958 addImmutableType(Double.class, false);
959 addImmutableType(float.class, false);
960 addImmutableType(Float.class, false);
961 addImmutableType(int.class, false);
962 addImmutableType(Integer.class, false);
963 addImmutableType(long.class, false);
964 addImmutableType(Long.class, false);
965 addImmutableType(short.class, false);
966 addImmutableType(Short.class, false);
947967
948968 // additional types
949 addImmutableType(Mapper.Null.class);
950 addImmutableType(BigDecimal.class);
951 addImmutableType(BigInteger.class);
952 addImmutableType(String.class);
953 addImmutableType(URI.class);
954 addImmutableType(URL.class);
955 addImmutableType(File.class);
956 addImmutableType(Class.class);
957
958 addImmutableType(Collections.EMPTY_LIST.getClass());
959 addImmutableType(Collections.EMPTY_SET.getClass());
960 addImmutableType(Collections.EMPTY_MAP.getClass());
969 addImmutableType(Mapper.Null.class, false);
970 addImmutableType(BigDecimal.class, false);
971 addImmutableType(BigInteger.class, false);
972 addImmutableType(String.class, false);
973 addImmutableType(URL.class, false);
974 addImmutableType(File.class, false);
975 addImmutableType(Class.class, false);
961976
962977 if (JVM.isAWTAvailable()) {
963 addImmutableTypeDynamically("java.awt.font.TextAttribute");
978 addImmutableTypeDynamically("java.awt.font.TextAttribute", false);
964979 }
965980
966981 if (JVM.is14()) {
967982 // late bound types - allows XStream to be compiled on earlier JDKs
968 addImmutableTypeDynamically("java.nio.charset.Charset");
969 addImmutableTypeDynamically("java.util.Currency");
970 }
971 }
972
973 private void addImmutableTypeDynamically(String className) {
983 addImmutableTypeDynamically("java.nio.charset.Charset", true);
984 addImmutableTypeDynamically("java.util.Currency", true);
985 }
986
987 if (JVM.is15()) {
988 addImmutableTypeDynamically("java.util.UUID", true);
989 }
990
991 addImmutableType(URI.class, true);
992 addImmutableType(Collections.EMPTY_LIST.getClass(), true);
993 addImmutableType(Collections.EMPTY_SET.getClass(), true);
994 addImmutableType(Collections.EMPTY_MAP.getClass(), true);
995 }
996
997 private void addImmutableTypeDynamically(String className, boolean isReferenceable) {
974998 Class type = JVM.loadClassForName(className);
975999 if (type != null) {
976 addImmutableType(type);
1000 addImmutableType(type, isReferenceable);
9771001 }
9781002 }
9791003
9831007
9841008 /**
9851009 * Serialize an object to a pretty-printed XML String.
986 *
1010 *
9871011 * @throws XStreamException if the object cannot be serialized
9881012 */
9891013 public String toXML(Object obj) {
10241048
10251049 /**
10261050 * Serialize and object to a hierarchical data structure (such as XML).
1027 *
1051 *
10281052 * @throws XStreamException if the object cannot be serialized
10291053 */
10301054 public void marshal(Object obj, HierarchicalStreamWriter writer) {
10441068
10451069 /**
10461070 * Deserialize an object from an XML String.
1047 *
1071 *
10481072 * @throws XStreamException if the object cannot be deserialized
10491073 */
10501074 public Object fromXML(String xml) {
10531077
10541078 /**
10551079 * Deserialize an object from an XML Reader.
1056 *
1080 *
10571081 * @throws XStreamException if the object cannot be deserialized
10581082 */
10591083 public Object fromXML(Reader reader) {
10621086
10631087 /**
10641088 * Deserialize an object from an XML InputStream.
1065 *
1089 *
10661090 * @throws XStreamException if the object cannot be deserialized
10671091 */
10681092 public Object fromXML(InputStream input) {
11701194
11711195 /**
11721196 * Deserialize an object from a hierarchical data structure (such as XML).
1173 *
1197 *
11741198 * @throws XStreamException if the object cannot be deserialized
11751199 */
11761200 public Object unmarshal(HierarchicalStreamReader reader) {
12151239
12161240 /**
12171241 * Alias a Class to a shorter name to be used in XML elements.
1218 *
1242 *
12191243 * @param name Short name
12201244 * @param type Type to be aliased
12211245 * @throws InitializationException if no {@link ClassAliasingMapper} is available
12491273
12501274 /**
12511275 * Alias a Class to a shorter name to be used in XML elements.
1252 *
1276 *
12531277 * @param name Short name
12541278 * @param type Type to be aliased
12551279 * @param defaultImplementation Default implementation of type to use if no other specified.
12631287
12641288 /**
12651289 * Alias a package to a shorter name to be used in XML elements.
1266 *
1290 *
12671291 * @param name Short name
12681292 * @param pkgName package to be aliased
12691293 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
12811305
12821306 /**
12831307 * Create an alias for a field name.
1284 *
1308 *
12851309 * @param alias the alias itself
12861310 * @param definedIn the type that declares the field
12871311 * @param fieldName the name of the field
12981322
12991323 /**
13001324 * Create an alias for an attribute
1301 *
1325 *
13021326 * @param alias the alias itself
13031327 * @param attributeName the name of the attribute
13041328 * @throws InitializationException if no {@link AttributeAliasingMapper} is available
13341358
13351359 /**
13361360 * Create an alias for an attribute.
1337 *
1361 *
13381362 * @param definedIn the type where the attribute is defined
13391363 * @param attributeName the name of the attribute
13401364 * @param alias the alias itself
13481372
13491373 /**
13501374 * Use an attribute for a field or a specific type.
1351 *
1375 *
13521376 * @param fieldName the name of the field
13531377 * @param type the Class of the type to be rendered as XML attribute
13541378 * @throws InitializationException if no {@link AttributeMapper} is available
13651389
13661390 /**
13671391 * Use an attribute for a field declared in a specific type.
1368 *
1392 *
13691393 * @param fieldName the name of the field
13701394 * @param definedIn the Class containing such field
13711395 * @throws InitializationException if no {@link AttributeMapper} is available
13821406
13831407 /**
13841408 * Use an attribute for an arbitrary type.
1385 *
1409 *
13861410 * @param type the Class of the type to be rendered as XML attribute
13871411 * @throws InitializationException if no {@link AttributeMapper} is available
13881412 * @since 1.2
14151439 }
14161440
14171441 /**
1418 * Add immutable types. The value of the instances of these types will always be written
1419 * into the stream even if they appear multiple times.
1420 *
1442 * Add immutable types. The value of the instances of these types will always be written into the stream even if
1443 * they appear multiple times. However, references are still supported at deserialization time.
1444 *
14211445 * @throws InitializationException if no {@link ImmutableTypesMapper} is available
1446 * @deprecated As of 1.4.9 use {@link #addImmutableType(Class, boolean)}
14221447 */
14231448 public void addImmutableType(Class type) {
1449 addImmutableType(type, true);
1450 }
1451
1452 /**
1453 * Add immutable types. The value of the instances of these types will always be written into the stream even if
1454 * they appear multiple times.
1455 * <p>
1456 * Note, while a reference-keeping marshaller will not write references for immutable types into the stream, a
1457 * reference-keeping unmarshaller can still support such references in the stream for compatibility reasons at the
1458 * expense of memory consumption. Therefore declare these types only as referenceable if your already persisted
1459 * streams do contain such references. Otherwise you may waste a lot of memory during deserialization.
1460 * </p>
1461 *
1462 * @param isReferenceable <code>true</code> if support at deserialization time is required for compatibility at the
1463 * cost of a higher memory footprint, <code>false</code> otherwise
1464 * @throws InitializationException if no {@link ImmutableTypesMapper} is available
1465 * @since 1.4.9
1466 */
1467 public void addImmutableType(final Class type, final boolean isReferenceable) {
14241468 if (immutableTypesMapper == null) {
14251469 throw new com.thoughtworks.xstream.InitializationException("No "
14261470 + ImmutableTypesMapper.class.getName()
14271471 + " available");
14281472 }
1429 immutableTypesMapper.addImmutableType(type);
1473 immutableTypesMapper.addImmutableType(type, isReferenceable);
14301474 }
14311475
14321476 public void registerConverter(Converter converter) {
14521496
14531497 /**
14541498 * Register a local {@link Converter} for a field.
1455 *
1499 *
14561500 * @param definedIn the class type the field is defined in
14571501 * @param fieldName the field name
14581502 * @param converter the converter to use
14691513
14701514 /**
14711515 * Register a local {@link SingleValueConverter} for a field.
1472 *
1516 *
14731517 * @param definedIn the class type the field is defined in
14741518 * @param fieldName the field name
14751519 * @param converter the converter to use
14941538
14951539 /**
14961540 * Retrieve the {@link ReflectionProvider} in use.
1497 *
1541 *
14981542 * @return the mapper
14991543 * @since 1.2.1
15001544 */
15501594
15511595 /**
15521596 * Adds a default implicit collection which is used for any unmapped XML tag.
1553 *
1597 *
15541598 * @param ownerType class owning the implicit collection
15551599 * @param fieldName name of the field in the ownerType. This field must be a concrete
15561600 * collection type or matching the default implementation type of the collection
15621606
15631607 /**
15641608 * Adds implicit collection which is used for all items of the given itemType.
1565 *
1609 *
15661610 * @param ownerType class owning the implicit collection
15671611 * @param fieldName name of the field in the ownerType. This field must be a concrete
15681612 * collection type or matching the default implementation type of the collection
15931637
15941638 /**
15951639 * Adds an implicit array.
1596 *
1640 *
15971641 * @param ownerType class owning the implicit array
15981642 * @param fieldName name of the array field
15991643 * @since 1.4
16331677
16341678 /**
16351679 * Adds an implicit map.
1636 *
1680 *
16371681 * @param ownerType class owning the implicit map
16381682 * @param fieldName name of the field in the ownerType. This field must be a concrete
16391683 * map type or matching the default implementation type of the map
16481692
16491693 /**
16501694 * Adds an implicit map.
1651 *
1695 *
16521696 * @param ownerType class owning the implicit map
16531697 * @param fieldName name of the field in the ownerType. This field must be a concrete
16541698 * map type or matching the default implementation type of the map
16721716 * Create a DataHolder that can be used to pass data to the converters. The DataHolder is
16731717 * provided with a call to {@link #marshal(Object, HierarchicalStreamWriter, DataHolder)} or
16741718 * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)}.
1675 *
1719 *
16761720 * @return a new {@link DataHolder}
16771721 */
16781722 public DataHolder newDataHolder() {
17751819 * be incomplete.
17761820 * </p>
17771821 * <h3>Example</h3>
1778 *
1822 *
17791823 * <pre>
17801824 * ObjectOutputStream out = xstream.createObjectOutputStream(aWriter, &quot;things&quot;);
17811825 * out.writeInt(123);
17831827 * out.writeObject(someObject)
17841828 * out.close();
17851829 * </pre>
1786 *
1830 *
17871831 * @param writer The writer to serialize the objects to.
17881832 * @param rootNodeName The name of the root node enclosing the stream of objects.
17891833 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
19071951
19081952 /**
19091953 * Retrieve the ClassLoader XStream uses to load classes.
1910 *
1954 *
19111955 * @since 1.1.1
19121956 */
19131957 public ClassLoader getClassLoader() {
19441988
19451989 /**
19461990 * Ignore all unknown elements.
1947 *
1991 *
19481992 * @since 1.4.5
19491993 */
19501994 public void ignoreUnknownElements() {
19531997
19541998 /**
19551999 * Add pattern for unknown element names to ignore.
1956 *
2000 *
19572001 * @param pattern the name pattern as regular expression
19582002 * @since 1.4.5
19592003 */
19632007
19642008 /**
19652009 * Add pattern for unknown element names to ignore.
1966 *
2010 *
19672011 * @param pattern the name pattern as regular expression
19682012 * @since 1.4.5
19692013 */
19782022
19792023 /**
19802024 * Process the annotations of the given types and configure the XStream.
1981 *
2025 *
19822026 * @param types the types with XStream annotations
19832027 * @since 1.3
19842028 */
20242068 * Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
20252069 * {@link AnyTypePermission} will implicitly wipe any existing permission.
20262070 * </p>
2027 *
2071 *
20282072 * @param permission the permission to add
20292073 * @since 1.4.7
20302074 */
20362080
20372081 /**
20382082 * Add security permission for explicit types by name.
2039 *
2083 *
20402084 * @param names the type names to allow
20412085 * @since 1.4.7
20422086 */
20462090
20472091 /**
20482092 * Add security permission for explicit types.
2049 *
2093 *
20502094 * @param types the types to allow
20512095 * @since 1.4.7
20522096 */
20562100
20572101 /**
20582102 * Add security permission for a type hierarchy.
2059 *
2103 *
20602104 * @param type the base type to allow
20612105 * @since 1.4.7
20622106 */
20662110
20672111 /**
20682112 * Add security permission for types matching one of the specified regular expressions.
2069 *
2113 *
20702114 * @param regexps the regular expressions to allow type names
20712115 * @since 1.4.7
20722116 */
20762120
20772121 /**
20782122 * Add security permission for types matching one of the specified regular expressions.
2079 *
2123 *
20802124 * @param regexps the regular expressions to allow type names
20812125 * @since 1.4.7
20822126 */
20942138 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
20952139 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
20962140 * </ul>
2097 *
2141 *
20982142 * @param patterns the patterns to allow type names
20992143 * @since 1.4.7
21002144 */
21042148
21052149 /**
21062150 * Add security permission denying another one.
2107 *
2151 *
21082152 * @param permission the permission to deny
21092153 * @since 1.4.7
21102154 */
21142158
21152159 /**
21162160 * Add security permission forbidding explicit types by name.
2117 *
2161 *
21182162 * @param names the type names to forbid
21192163 * @since 1.4.7
21202164 */
21242168
21252169 /**
21262170 * Add security permission forbidding explicit types.
2127 *
2171 *
21282172 * @param types the types to forbid
21292173 * @since 1.4.7
21302174 */
21342178
21352179 /**
21362180 * Add security permission forbidding a type hierarchy.
2137 *
2181 *
21382182 * @param type the base type to forbid
21392183 * @since 1.4.7
21402184 */
21442188
21452189 /**
21462190 * Add security permission forbidding types matching one of the specified regular expressions.
2147 *
2191 *
21482192 * @param regexps the regular expressions to forbid type names
21492193 * @since 1.4.7
21502194 */
21542198
21552199 /**
21562200 * Add security permission forbidding types matching one of the specified regular expressions.
2157 *
2201 *
21582202 * @param regexps the regular expressions to forbid type names
21592203 * @since 1.4.7
21602204 */
21722216 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
21732217 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
21742218 * </ul>
2175 *
2219 *
21762220 * @param patterns the patterns to forbid names
21772221 * @since 1.4.7
21782222 */
00 /*
1 * Copyright (C) 2007, 2008 XStream Committers.
1 * Copyright (C) 2007, 2008, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1313
1414
1515 /**
16 * Base exception for all thrown exceptions with XStream. JDK 1.3 friendly cause handling.
16 * Base exception for all thrown exceptions with XStream.
1717 *
1818 * @author Joe Walnes
1919 * @author J&ouml;rg Schaible
2020 * @since 1.3
2121 */
2222 public class XStreamException extends BaseException {
23
24 private Throwable cause;
2523
2624 /**
2725 * Default constructor.
6159 * @since 1.3
6260 */
6361 public XStreamException(String message, Throwable cause) {
64 super(message + (cause == null ? "" : " : " + cause.getMessage()));
65 this.cause = cause;
62 super(message, cause);
6663 }
67
68 public Throwable getCause() {
69 return cause;
70 }
71
7264 }
00 /*
1 * Copyright (C) 2006, 2007, 2014 XStream Committers.
1 * Copyright (C) 2006, 2007, 2014, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
2020
2121 import javax.xml.datatype.DatatypeFactory;
2222
23 import com.thoughtworks.xstream.converters.ConversionException;
2423 import com.thoughtworks.xstream.converters.ConverterLookup;
2524 import com.thoughtworks.xstream.converters.ConverterMatcher;
2625 import com.thoughtworks.xstream.converters.ConverterRegistry;
3231 import com.thoughtworks.xstream.core.JVM;
3332 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
3433 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
34 import com.thoughtworks.xstream.io.StreamException;
3535 import com.thoughtworks.xstream.io.naming.NameCoder;
3636 import com.thoughtworks.xstream.io.xml.XppDriver;
3737 import com.thoughtworks.xstream.mapper.Mapper;
8484 } catch (final ObjectStreamException e) {
8585 throw e;
8686 } catch (final IOException e) {
87 throw new ConversionException("Unexpected IO error from a StringWriter", e);
87 throw new StreamException("Unexpected IO error from a StringWriter", e);
8888 }
8989 return writer.toString();
9090 }
134134 } catch (final ObjectStreamException e) {
135135 throw e;
136136 } catch (final IOException e) {
137 throw new ConversionException("Unexpected IO error from a StringReader", e);
137 throw new StreamException("Unexpected IO error from a StringReader", e);
138138 }
139139 }
140140
156156 } catch (final ObjectStreamException e) {
157157 throw e;
158158 } catch (final IOException e) {
159 throw new ConversionException("Unexpected IO error from a StringReader", e);
159 throw new StreamException("Unexpected IO error from a StringReader", e);
160160 }
161161 }
162162
178178 } catch (final ObjectStreamException e) {
179179 throw e;
180180 } catch (final IOException e) {
181 throw new ConversionException("Unexpected IO error from a StringReader", e);
181 throw new StreamException("Unexpected IO error from a StringReader", e);
182182 }
183183 }
184184
201201 } catch (final ObjectStreamException e) {
202202 throw e;
203203 } catch (final IOException e) {
204 throw new ConversionException("Unexpected IO error from a StringReader", e);
204 throw new StreamException("Unexpected IO error from a StringReader", e);
205205 }
206206 }
207207
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
105105 double[] doubles() default {};
106106
107107 boolean[] booleans() default {};
108
109 /**
110 * Provide null types as arguments for the converter's constructor arguments.
111 *
112 * @return the types provided as null values
113 * @since 1.4.9
114 */
115 Class<?>[] nulls() default {};
108116 }
00 /*
11 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
99 * Created on 26. September 2003 by Joe Walnes
1010 */
1111 package com.thoughtworks.xstream.converters;
12
13 import com.thoughtworks.xstream.XStreamException;
14 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
15
16 import java.util.Iterator;
17 import java.util.Map;
1812
1913 /**
2014 * Thrown by {@link Converter} implementations when they cannot convert an object
2822 *
2923 * @see ErrorWriter
3024 */
31 public class ConversionException extends XStreamException implements ErrorWriter {
32
33 private static final String SEPARATOR = "\n-------------------------------";
34 private Map stuff = new OrderRetainingMap();
25 public class ConversionException extends ErrorWritingException {
3526
3627 public ConversionException(String msg, Throwable cause) {
3728 super(msg, cause);
38 if (msg != null) {
39 add("message", msg);
40 }
41 if (cause != null) {
42 add("cause-exception", cause.getClass().getName());
43 add("cause-message", cause instanceof ConversionException ? ((ConversionException)cause).getShortMessage() : cause.getMessage());
44 }
4529 }
4630
4731 public ConversionException(String msg) {
4933 }
5034
5135 public ConversionException(Throwable cause) {
52 this(cause.getMessage(), cause);
53 }
54
55 public String get(String errorKey) {
56 return (String) stuff.get(errorKey);
57 }
58
59 public void add(String name, String information) {
60 String key = name;
61 int i = 0;
62 while (stuff.containsKey(key)) {
63 String value = (String)stuff.get(key);
64 if (information.equals(value))
65 return;
66 key = name + "[" + ++i +"]";
67 }
68 stuff.put(key, information);
69 }
70
71 public void set(String name, String information) {
72 String key = name;
73 int i = 0;
74 stuff.put(key, information); // keep order
75 while (stuff.containsKey(key)) {
76 if (i != 0) {
77 stuff.remove(key);
78 }
79 key = name + "[" + ++i +"]";
80 }
81 }
82
83 public Iterator keys() {
84 return stuff.keySet().iterator();
85 }
86
87 public String getMessage() {
88 StringBuffer result = new StringBuffer();
89 if (super.getMessage() != null) {
90 result.append(super.getMessage());
91 }
92 if (!result.toString().endsWith(SEPARATOR)) {
93 result.append("\n---- Debugging information ----");
94 }
95 for (Iterator iterator = keys(); iterator.hasNext();) {
96 String k = (String) iterator.next();
97 String v = get(k);
98 result.append('\n').append(k);
99 result.append(" ".substring(Math.min(20, k.length())));
100 result.append(": ").append(v);
101 }
102 result.append(SEPARATOR);
103 return result.toString();
104 }
105
106 public String getShortMessage() {
107 return super.getMessage();
36 super(cause);
10837 }
10938 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers.
3 * All rights reserved.
4 *
5 * The software in this package is published under the terms of the BSD
6 * style license a copy of which has been included with this distribution in
7 * the LICENSE.txt file.
8 *
9 * Created on 24. February 2016 by Joerg Schaible, factored out of ConversionException.
10 */
11 package com.thoughtworks.xstream.converters;
12
13 import java.util.Iterator;
14 import java.util.Map;
15
16 import com.thoughtworks.xstream.XStreamException;
17 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
18
19
20 /**
21 * Abstract base class for exceptions supporting an ErrorWriter. It can be passed around to things accepting an
22 * ErrorWriter to add diagnostics.
23 *
24 * @author J&ouml;rg Schaible
25 * @see ErrorWriter
26 * @since 1.4.9
27 */
28 public abstract class ErrorWritingException extends XStreamException implements ErrorWriter {
29
30 private static final String SEPARATOR = "\n-------------------------------";
31 private final Map stuff = new OrderRetainingMap();
32
33 /**
34 * Constructs a ErrorWritingException.
35 *
36 * @param message the error message
37 * @since 1.4.9
38 */
39 public ErrorWritingException(String message) {
40 super(message);
41 addData(message, null);
42 }
43
44 /**
45 * Constructs a ErrorWritingException.
46 *
47 * @param cause the causing exception
48 * @since 1.4.9
49 */
50 public ErrorWritingException(Throwable cause) {
51 super(cause);
52 addData(null, cause);
53 }
54
55 /**
56 * Constructs a ErrorWritingException.
57 *
58 * @param message the error message
59 * @param cause the causing exception
60 * @since 1.4.9
61 */
62 public ErrorWritingException(String message, Throwable cause) {
63 super(message, cause);
64 addData(message, cause);
65 }
66
67 private void addData(String msg, Throwable cause) {
68 if (msg != null) {
69 add("message", msg);
70 }
71 if (cause != null) {
72 add("cause-exception", cause.getClass().getName());
73 add("cause-message", cause instanceof ErrorWritingException ? ((ErrorWritingException)cause).getShortMessage() : cause.getMessage());
74 }
75 }
76
77 public String get(String errorKey) {
78 return (String) stuff.get(errorKey);
79 }
80
81 public void add(String name, String information) {
82 String key = name;
83 int i = 0;
84 while (stuff.containsKey(key)) {
85 String value = (String)stuff.get(key);
86 if (information.equals(value))
87 return;
88 key = name + "[" + ++i +"]";
89 }
90 stuff.put(key, information);
91 }
92
93 public void set(String name, String information) {
94 String key = name;
95 int i = 0;
96 stuff.put(key, information); // keep order
97 while (stuff.containsKey(key)) {
98 if (i != 0) {
99 stuff.remove(key);
100 }
101 key = name + "[" + ++i +"]";
102 }
103 }
104
105 public Iterator keys() {
106 return stuff.keySet().iterator();
107 }
108
109 public String getMessage() {
110 StringBuffer result = new StringBuffer();
111 if (super.getMessage() != null) {
112 result.append(super.getMessage());
113 }
114 if (!result.toString().endsWith(SEPARATOR)) {
115 result.append("\n---- Debugging information ----");
116 }
117 for (Iterator iterator = keys(); iterator.hasNext();) {
118 String k = (String) iterator.next();
119 String v = get(k);
120 result.append('\n').append(k);
121 result.append(" ".substring(Math.min(20, k.length())));
122 result.append(": ").append(v);
123 }
124 result.append(SEPARATOR);
125 return result.toString();
126 }
127
128 public String getShortMessage() {
129 return super.getMessage();
130 }
131
132 }
00 /*
11 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
226226 }
227227 }
228228 // no dateFormats left to try
229 throw new ConversionException("Cannot parse date " + str);
229 ConversionException exception = new ConversionException("Cannot parse date");
230 exception.add("date", str);
231 throw exception;
230232 }
231233
232234 public String toString(Object obj) {
00 /*
11 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1212
1313 import com.thoughtworks.xstream.converters.ConversionException;
1414 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.ErrorWritingException;
1516 import com.thoughtworks.xstream.converters.MarshallingContext;
1617 import com.thoughtworks.xstream.converters.UnmarshallingContext;
18 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
1719 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
1820 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
1921 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
7173 }
7274
7375 protected Object createCollection(Class type) {
76 ErrorWritingException ex = null;
7477 Class defaultType = mapper().defaultImplementationOf(type);
7578 try {
7679 return defaultType.newInstance();
7780 } catch (InstantiationException e) {
78 throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
81 ex = new ConversionException("Cannot instantiate default collection", e);
7982 } catch (IllegalAccessException e) {
80 throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
83 ex = new ObjectAccessException("Cannot instantiate default collection", e);
8184 }
85 ex.add("collection-type", type.getName());
86 ex.add("default-type", defaultType.getName());
87 throw ex;
8288 }
8389 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1010 */
1111 package com.thoughtworks.xstream.converters.collections;
1212
13 import com.thoughtworks.xstream.converters.ConversionException;
1413 import com.thoughtworks.xstream.converters.MarshallingContext;
1514 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
1616 import com.thoughtworks.xstream.core.JVM;
1717 import com.thoughtworks.xstream.core.util.Fields;
1818 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
127127 result.putAll(sortedMap); // will use comparator for already sorted map
128128 }
129129 } catch (final IllegalAccessException e) {
130 throw new ConversionException("Cannot set comparator of TreeMap", e);
130 throw new ObjectAccessException("Cannot set comparator of TreeMap", e);
131131 }
132132 }
133133 }
00 /*
11 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 XStream Committers.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
1010 */
1111 package com.thoughtworks.xstream.converters.collections;
1212
13 import com.thoughtworks.xstream.converters.ConversionException;
1413 import com.thoughtworks.xstream.converters.MarshallingContext;
1514 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
1616 import com.thoughtworks.xstream.core.JVM;
1717 import com.thoughtworks.xstream.core.util.Fields;
1818 import com.thoughtworks.xstream.core.util.PresortedSet;
9898 try {
9999 backingMap = sortedMapField.get(possibleResult);
100100 } catch (IllegalAccessException e) {
101 throw new ConversionException("Cannot get backing map of TreeSet", e);
101 throw new ObjectAccessException("Cannot get backing map of TreeSet", e);
102102 }
103103 if (backingMap instanceof TreeMap) {
104104 treeMap = (TreeMap)backingMap;
00 /*
1 * Copyright (C) 2013 XStream Committers.
1 * Copyright (C) 2013, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1212 import java.util.EnumMap;
1313 import java.util.EnumSet;
1414 import java.util.HashMap;
15 import java.util.Iterator;
1615 import java.util.Map;
1716
17 import com.thoughtworks.xstream.InitializationException;
1818 import com.thoughtworks.xstream.converters.ConversionException;
1919 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
2020
5252 Map<String, T> strings = new HashMap<String, T>(values.size());
5353 for (T value : values) {
5454 if (strings.put(value.toString(), value) != null) {
55 throw new IllegalArgumentException("Enum type "
55 throw new InitializationException("Enum type "
5656 + type.getName()
5757 + " does not have unique string representations for its values");
5858 }
6262
6363 private static <T> void checkType(Class<T> type) {
6464 if (!Enum.class.isAssignableFrom(type) && type != Enum.class) {
65 throw new IllegalArgumentException("Converter can only handle enum types");
65 throw new InitializationException("Converter can only handle enum types");
6666 }
6767 }
6868
9393 }
9494 T result = strings.get(str);
9595 if (result == null) {
96 throw new ConversionException("Invalid string representation for enum type "
97 + enumType.getName()
98 + ": <"
99 + str
100 + ">");
96 ConversionException exception = new ConversionException("Invalid string representation for enum type");
97 exception.add("enum-type", enumType.getName());
98 exception.add("enum-string", str);
99 throw exception;
101100 }
102101 return result;
103102 }
0 /*
1 * Copyright (C) 2015 XStream Committers.
2 * All rights reserved.
3 *
4 * The software in this package is published under the terms of the BSD
5 * style license a copy of which has been included with this distribution in
6 * the LICENSE.txt file.
7 *
8 * Created on 21.06.2015 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import javax.activation.ActivationDataFlavor;
13
14 import com.thoughtworks.xstream.converters.ConversionException;
15 import com.thoughtworks.xstream.converters.Converter;
16 import com.thoughtworks.xstream.converters.MarshallingContext;
17 import com.thoughtworks.xstream.converters.UnmarshallingContext;
18 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
19 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
20
21
22 /**
23 * Converts an {@link ActivationDataFlavor}.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4.9
27 */
28 public class ActivationDataFlavorConverter implements Converter {
29
30 public boolean canConvert(final Class type) {
31 return type == ActivationDataFlavor.class;
32 }
33
34 public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
35 final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source;
36 final String mimeType = dataFlavor.getMimeType();
37 if (mimeType != null) {
38 writer.startNode("mimeType");
39 writer.setValue(mimeType);
40 writer.endNode();
41 }
42 final String name = dataFlavor.getHumanPresentableName();
43 if (name != null) {
44 writer.startNode("humanRepresentableName");
45 writer.setValue(name);
46 writer.endNode();
47 }
48 final Class representationClass = dataFlavor.getRepresentationClass();
49 if (representationClass != null) {
50 writer.startNode("representationClass");
51 context.convertAnother(representationClass);
52 writer.endNode();
53 }
54 }
55
56 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
57 String mimeType = null;
58 String name = null;
59 Class type = null;
60 while (reader.hasMoreChildren()) {
61 reader.moveDown();
62
63 final String elementName = reader.getNodeName();
64 if (elementName.equals("mimeType")) {
65 mimeType = reader.getValue();
66 } else if (elementName.equals("humanRepresentableName")) {
67 name = reader.getValue();
68 } else if (elementName.equals("representationClass")) {
69 type = (Class)context.convertAnother(null, Class.class);
70 } else {
71 final ConversionException exception = new ConversionException("Unknown child element");
72 exception.add("element", reader.getNodeName());
73 throw exception;
74 }
75 reader.moveUp();
76 }
77 ActivationDataFlavor dataFlavor = null;
78 try {
79 if (type == null) {
80 dataFlavor = new ActivationDataFlavor(mimeType, name);
81 } else if (mimeType == null) {
82 dataFlavor = new ActivationDataFlavor(type, name);
83 } else {
84 dataFlavor = new ActivationDataFlavor(type, mimeType, name);
85 }
86 } catch (final IllegalArgumentException ex) {
87 throw new ConversionException(ex);
88 } catch (final NullPointerException ex) {
89 throw new ConversionException(ex);
90 }
91 return dataFlavor;
92 }
93 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015 XStream Committers.
2 * Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
108108 // try with next formatter
109109 }
110110 }
111 throw new ConversionException("Cannot parse date " + str);
111 ConversionException exception = new ConversionException("Cannot parse date");
112 exception.add("date", str);
113 throw exception;
112114 }
113115
114116 public String toString(Object obj) {
00 /*
1 * Copyright (C) 2013 XStream Committers.
1 * Copyright (C) 2013, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
246246 SingleValueConverter keyConverter = null;
247247 SingleValueConverter valueConverter = null;
248248 if (keyAsAttribute) {
249 keyConverter = getSingleValueConverter(keyType);
249 keyConverter = getSingleValueConverter(keyType, "key");
250250 }
251251 if (valueAsAttribute || valueName == null) {
252 valueConverter = getSingleValueConverter(valueType);
252 valueConverter = getSingleValueConverter(valueType, "value");
253253 }
254254 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
255255 Map.Entry entry = (Map.Entry)iterator.next();
286286 SingleValueConverter keyConverter = null;
287287 SingleValueConverter valueConverter = null;
288288 if (keyAsAttribute) {
289 keyConverter = getSingleValueConverter(keyType);
289 keyConverter = getSingleValueConverter(keyType, "key");
290290 }
291291 if (valueAsAttribute || valueName == null) {
292 valueConverter = getSingleValueConverter(valueType);
292 valueConverter = getSingleValueConverter(valueType, "value");
293293 }
294294
295295 while (reader.hasMoreChildren()) {
335335 }
336336 reader.moveUp();
337337 } else if (!valueAsAttribute) {
338 value = reader.getValue();
338 value = valueConverter.fromString(reader.getValue());
339339 }
340340
341341 target.put(key, value);
346346 }
347347 }
348348
349 private SingleValueConverter getSingleValueConverter(Class type) {
349 private SingleValueConverter getSingleValueConverter(Class type, String part) {
350350 SingleValueConverter conv = UseAttributeForEnumMapper.isEnum(type) ? enumMapper
351351 .getConverterFromItemType(null, type, null) : mapper().getConverterFromItemType(
352352 null, type, null);
355355 if (converter instanceof SingleValueConverter) {
356356 conv = (SingleValueConverter)converter;
357357 } else {
358 throw new ConversionException("No SingleValueConverter for key available");
358 throw new ConversionException("No SingleValueConverter for " + part + " available");
359359 }
360360 }
361361 return conv;
0 /*
1 * Copyright (C) 2016 XStream Committers.
2 * All rights reserved.
3 *
4 * The software in this package is published under the terms of the BSD
5 * style license a copy of which has been included with this distribution in
6 * the LICENSE.txt file.
7 *
8 * Created on 7. February 2016 by Aaron Johnson
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import java.net.URI;
13 import java.net.URISyntaxException;
14 import java.nio.file.FileSystems;
15 import java.nio.file.Path;
16 import java.nio.file.Paths;
17
18 import com.thoughtworks.xstream.converters.ConversionException;
19 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
20
21
22 /**
23 * Converts a {@link Path} to string.
24 *
25 * @author Aaron Johnson
26 * @author J&ouml;rg Schaible
27 */
28 public class PathConverter extends AbstractSingleValueConverter {
29
30 @Override
31 public boolean canConvert(final Class type) {
32 return Path.class.isAssignableFrom(type);
33 }
34
35 @Override
36 public Object fromString(final String str) {
37 try {
38 final URI uri = new URI(str);
39 if (uri.getScheme() == null) {
40 return Paths.get(str);
41 } else {
42 return Paths.get(uri);
43 }
44 } catch (final URISyntaxException e) {
45 throw new ConversionException(e);
46 }
47 }
48
49 @Override
50 public String toString(final Object obj) {
51 final Path path = (Path)obj;
52 if (path.getFileSystem() == FileSystems.getDefault()) {
53 return path.toString();
54 } else {
55 return path.toUri().toString();
56 }
57 }
58 }
00 /*
11 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 XStream Committers.
2 * Copyright (C) 2006, 2007, 2014, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
66 * style license a copy of which has been included with this distribution in
77 * the LICENSE.txt file.
8 *
8 *
99 * Created on 30. May 2004 by Joe Walnes
1010 */
1111 package com.thoughtworks.xstream.converters.extended;
1212
13 import com.thoughtworks.xstream.converters.ConversionException;
14
1513 import java.lang.reflect.Field;
1614
15 import com.thoughtworks.xstream.core.util.Fields;
16
17
1718 /**
18 * Factory for creating StackTraceElements.
1919 * Factory for creating StackTraceElements.
2020 *
2121 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
2424 */
2525 public class StackTraceElementFactory {
2626
27 public StackTraceElement nativeMethodElement(String declaringClass, String methodName) {
27 public StackTraceElement nativeMethodElement(final String declaringClass, final String methodName) {
2828 return create(declaringClass, methodName, "Native Method", -2);
2929 }
3030
31 public StackTraceElement unknownSourceElement(String declaringClass, String methodName) {
31 public StackTraceElement unknownSourceElement(final String declaringClass, final String methodName) {
3232 return create(declaringClass, methodName, "Unknown Source", -1);
3333 }
3434
35 public StackTraceElement element(String declaringClass, String methodName, String fileName) {
35 public StackTraceElement element(final String declaringClass, final String methodName, final String fileName) {
3636 return create(declaringClass, methodName, fileName, -1);
3737 }
3838
39 public StackTraceElement element(String declaringClass, String methodName, String fileName, int lineNumber) {
39 public StackTraceElement element(final String declaringClass, final String methodName, final String fileName,
40 final int lineNumber) {
4041 return create(declaringClass, methodName, fileName, lineNumber);
4142 }
4243
43 protected StackTraceElement create(String declaringClass, String methodName, String fileName, int lineNumber) {
44 StackTraceElement result = new Throwable().getStackTrace()[0];
44 protected StackTraceElement create(final String declaringClass, final String methodName, final String fileName,
45 final int lineNumber) {
46 final StackTraceElement result = new Throwable().getStackTrace()[0];
4547 setField(result, "declaringClass", declaringClass);
4648 setField(result, "methodName", methodName);
4749 setField(result, "fileName", fileName);
4951 return result;
5052 }
5153
52 private void setField(StackTraceElement element, String fieldName, Object value) {
53 try {
54 final Field field = StackTraceElement.class.getDeclaredField(fieldName);
55 field.setAccessible(true);
56 field.set(element, value);
57 } catch (Exception e) {
58 throw new ConversionException(e);
59 }
54 private void setField(final StackTraceElement element, final String fieldName, final Object value) {
55 final Field field = Fields.find(StackTraceElement.class, fieldName);
56 Fields.write(field, element, value);
6057 }
6158
6259 }
00 /*
1 * Copyright (C) 2011, 2013 XStream Committers.
1 * Copyright (C) 2011, 2013, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
5959 /**
6060 * Creates a new ToAttributedValueConverter instance.
6161 *
62 * All field elements will be attributes, the element itself will have no value.
63 *
64 * @param type the type that is handled by this converter instance
65 * @param mapper the mapper in use
66 * @param reflectionProvider the reflection provider in use
67 * @param lookup the converter lookup in use
68 * @since 1.4.9
69 */
70 public ToAttributedValueConverter(
71 final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider,
72 final ConverterLookup lookup) {
73 this(type, mapper, reflectionProvider, lookup, null, null);
74 }
75
76 /**
77 * Creates a new ToAttributedValueConverter instance.
78 *
6279 * @param type the type that is handled by this converter instance
6380 * @param mapper the mapper in use
6481 * @param reflectionProvider the reflection provider in use
00 /*
1 * Copyright (C) 2006, 2007 XStream Committers.
1 * Copyright (C) 2006, 2007, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
1111
1212 import com.thoughtworks.xstream.converters.ConversionException;
1313 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
1415
1516 import java.lang.reflect.Constructor;
1617 import java.lang.reflect.InvocationTargetException;
2526 * @author Paul Hammant
2627 */
2728 public class ToStringConverter extends AbstractSingleValueConverter {
29 private static final Class[] STRING_PARAMETER = {String.class};
2830 private final Class clazz;
2931 private final Constructor ctor;
3032
3133 public ToStringConverter(Class clazz) throws NoSuchMethodException {
3234 this.clazz = clazz;
33 ctor = clazz.getConstructor(new Class[] {String.class});
35 ctor = clazz.getConstructor(STRING_PARAMETER);
3436 }
3537 public boolean canConvert(Class type) {
3638 return type.equals(clazz);
4547 } catch (InstantiationException e) {
4648 throw new ConversionException("Unable to instantiate single String param constructor", e);
4749 } catch (IllegalAccessException e) {
48 throw new ConversionException("Unable to access single String param constructor", e);
50 throw new ObjectAccessException("Unable to access single String param constructor", e);
4951 } catch (InvocationTargetException e) {
5052 throw new ConversionException("Unable to target single String param constructor", e.getTargetException());
5153 }
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
2020 import java.util.Iterator;
2121 import java.util.List;
2222
23 import com.thoughtworks.xstream.converters.ConversionException;
24 import com.thoughtworks.xstream.converters.ErrorWritingException;
2325 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
2426
2527
5961 }
6062
6163 public Object newInstance(Class type) {
64 ErrorWritingException ex = null;
6265 try {
6366 return type.newInstance();
6467 } catch (InstantiationException e) {
65 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
68 ex = new ConversionException("Cannot construct type", e);
6669 } catch (IllegalAccessException e) {
67 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
70 ex = new ObjectAccessException("Cannot construct type", e);
6871 } catch (SecurityException e) {
69 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
72 ex = new ObjectAccessException("Cannot construct type", e);
7073 } catch (ExceptionInInitializerError e) {
71 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
74 ex = new ConversionException("Cannot construct type", e);
7275 }
76 ex.add("construction-type", type.getName());
77 throw ex;
7378 }
7479
7580 public void visitSerializableProperties(Object object, JavaBeanProvider.Visitor visitor) {
7681 PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object);
7782 for (int i = 0; i < propertyDescriptors.length; i++ ) {
83 ErrorWritingException ex = null;
7884 PropertyDescriptor property = propertyDescriptors[i];
7985 try {
8086 Method readMethod = property.getReadMethod();
8591 visitor.visit(name, property.getPropertyType(), definedIn, value);
8692 }
8793 } catch (IllegalArgumentException e) {
88 throw new ObjectAccessException("Could not get property "
89 + object.getClass()
90 + "."
91 + property.getName(), e);
94 ex = new ConversionException("Cannot get property", e);
9295 } catch (IllegalAccessException e) {
93 throw new ObjectAccessException("Could not get property "
94 + object.getClass()
95 + "."
96 + property.getName(), e);
96 ex = new ObjectAccessException("Cannot access property", e);
9797 } catch (InvocationTargetException e) {
98 throw new ObjectAccessException("Could not get property "
99 + object.getClass()
100 + "."
101 + property.getName(), e);
98 ex = new ConversionException("Cannot get property", e.getTargetException());
99 }
100 if (ex != null) {
101 ex.add("property", object.getClass() + "." + property.getName());
102 throw ex;
102103 }
103104 }
104105 }
105106
106107 public void writeProperty(Object object, String propertyName, Object value) {
108 ErrorWritingException ex = null;
107109 PropertyDescriptor property = getProperty(propertyName, object.getClass());
108110 try {
109111 property.getWriteMethod().invoke(object, new Object[]{value});
110112 } catch (IllegalArgumentException e) {
111 throw new ObjectAccessException("Could not set property "
112 + object.getClass()
113 + "."
114 + property.getName(), e);
113 ex = new ConversionException("Cannot set property", e);
115114 } catch (IllegalAccessException e) {
116 throw new ObjectAccessException("Could not set property "
117 + object.getClass()
118 + "."
119 + property.getName(), e);
115 ex = new ObjectAccessException("Cannot access property", e);
120116 } catch (InvocationTargetException e) {
121 throw new ObjectAccessException("Could not set property "
122 + object.getClass()
123 + "."
124 + property.getName(), e);
117 ex = new ConversionException("Cannot set property", e.getTargetException());
118 }
119 if (ex != null) {
120 ex.add("property", object.getClass() + "." + property.getName());
121 throw ex;
125122 }
126123 }
127124
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
66 * style license a copy of which has been included with this distribution in
77 * the LICENSE.txt file.
8 *
8 *
99 * Created on 12. April 2005 by Joe Walnes
1010 */
1111 package com.thoughtworks.xstream.converters.javabean;
1919 import com.thoughtworks.xstream.converters.UnmarshallingContext;
2020 import com.thoughtworks.xstream.converters.reflection.MissingFieldException;
2121 import com.thoughtworks.xstream.core.util.FastField;
22 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
2223 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
2324 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
24 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
2525 import com.thoughtworks.xstream.mapper.Mapper;
2626
27
2728 /**
28 * Can convert any bean with a public default constructor. The {@link BeanProvider} used as
29 * default is based on {@link java.beans.BeanInfo}. Indexed properties are currently not supported.
29 * Can convert any bean with a public default constructor. The {@link BeanProvider} used as default is based on
30 * {@link java.beans.BeanInfo}. Indexed properties are currently not supported.
3031 */
3132 public class JavaBeanConverter implements Converter {
3233
8182 }
8283
8384 public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
84 final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class");
85 final String classAttributeName = mapper.aliasForSystemAttribute("class");
8586 beanProvider.visitSerializableProperties(source, new JavaBeanProvider.Visitor() {
8687 public boolean shouldVisit(String name, Class definedIn) {
8788 return mapper.shouldSerializeMember(definedIn, name);
8990
9091 public void visit(String propertyName, Class fieldType, Class definedIn, Object newObj) {
9192 if (newObj != null) {
92 writeField(propertyName, fieldType, newObj, definedIn);
93 writeField(propertyName, fieldType, newObj);
94 } else {
95 writeNullField(propertyName);
9396 }
9497 }
9598
96 private void writeField(String propertyName, Class fieldType, Object newObj, Class definedIn) {
99 private void writeField(String propertyName, Class fieldType, Object newObj) {
97100 Class actualType = newObj.getClass();
98101 Class defaultType = mapper.defaultImplementationOf(fieldType);
99102 String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
100 ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType);
103 ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType);
101104 if (!actualType.equals(defaultType) && classAttributeName != null) {
102105 writer.addAttribute(classAttributeName, mapper.serializedClass(actualType));
103106 }
104107 context.convertAnother(newObj);
105108
109 writer.endNode();
110 }
111
112 private void writeNullField(final String propertyName) {
113 final String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
114 ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, Mapper.Null.class);
115 writer.addAttribute(classAttributeName, mapper.serializedClass(Mapper.Null.class));
106116 writer.endNode();
107117 }
108118 });
00 /*
11 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
106106 try {
107107 beanInfo = Introspector.getBeanInfo(type, Object.class);
108108 } catch (IntrospectionException e) {
109 throw new ObjectAccessException(
110 "Cannot get BeanInfo of type " + type.getName(), e);
109 ObjectAccessException oaex = new ObjectAccessException("Cannot get BeanInfo of type", e);
110 oaex.add("bean-type", type.getName());
111 throw oaex;
111112 }
112113 nameMap = new OrderRetainingMap();
113114 PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
00 /*
1 * Copyright (C) 2007, 2013 XStream Committers.
1 * Copyright (C) 2007, 2013, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
8888 if (s.startsWith(className)) {
8989 return s.substring(className.length()+1, s.length()-1);
9090 }
91 throw new ConversionException("Cannot find name of attribute of type " + className, ex);
91 ConversionException exception = new ConversionException("Cannot find name of attribute", ex);
92 exception.add("attribute-type", className);
93 throw exception;
9294 }
9395
9496 public Object fromString(final String str) {
9597 if (attributeMap.containsKey(str)) {
9698 return attributeMap.get(str);
9799 }
98 throw new ConversionException("Cannot find attribute of type " + type.getName() + " with name " + str);
100 ConversionException exception = new ConversionException("Cannot find attribute");
101 exception.add("attribute-type", type.getName());
102 exception.add("attribute-name", str);
103 throw exception;
99104 }
100105
101106 private Object readResolve() {
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
66 * style license a copy of which has been included with this distribution in
77 * the LICENSE.txt file.
8 *
8 *
99 * Created on 02. March 2006 by Joerg Schaible
1010 */
1111 package com.thoughtworks.xstream.converters.reflection;
1919 import com.thoughtworks.xstream.core.ReferencingMarshallingContext;
2020 import com.thoughtworks.xstream.core.util.ArrayIterator;
2121 import com.thoughtworks.xstream.core.util.FastField;
22 import com.thoughtworks.xstream.core.util.Fields;
2223 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
2324 import com.thoughtworks.xstream.core.util.Primitives;
2425 import com.thoughtworks.xstream.core.util.SerializationMembers;
9394 final MarshallingContext context) {
9495 final List fields = new ArrayList();
9596 final Map defaultFieldDefinition = new HashMap();
97 final Class sourceType = source.getClass();
9698
9799 // Attributes might be preferred to child elements ...
98100 reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() {
105107 if (!defaultFieldDefinition.containsKey(fieldName)) {
106108 Class lookupType = source.getClass();
107109 // See XSTR-457 and OmitFieldsTest
108 if (definedIn != source.getClass()
110 if (definedIn != sourceType
109111 && !mapper.shouldSerializeMember(lookupType, fieldName)) {
110112 lookupType = definedIn;
111113 }
119121 final String attribute = mapper.aliasForAttribute(mapper.serializedMember(
120122 definedIn, fieldName));
121123 if (value != null) {
122 if (writtenAttributes.contains(fieldName)) { // TODO: use attribute
123 throw new ConversionException("Cannot write field with name '"
124 + fieldName
125 + "' twice as attribute for object of type "
126 + source.getClass().getName());
124 if (writtenAttributes.contains(fieldName)) {
125 ConversionException exception =
126 new ConversionException("Cannot write field as attribute for object, attribute name already in use");
127 exception.add("field-name", fieldName);
128 exception.add("object-type", sourceType.getName());
129 throw exception;
127130 }
128131 final String str = converter.toString(value);
129132 if (str != null) {
130133 writer.addAttribute(attribute, str);
131134 }
132135 }
133 writtenAttributes.add(fieldName); // TODO: use attribute
136 writtenAttributes.add(fieldName);
134137 } else {
135138 fields.add(new FieldInfo(fieldName, type, definedIn, value));
136139 }
139142
140143 new Object() {
141144 {
145 final Map hiddenMappers = new HashMap();
142146 for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) {
143147 FieldInfo info = (FieldInfo)fieldIter.next();
144148 if (info.value != null) {
149 final Field defaultField = (Field)defaultFieldDefinition.get(info.fieldName);
145150 Mapper.ImplicitCollectionMapping mapping = mapper
146151 .getImplicitCollectionDefForFieldName(
147 source.getClass(), info.fieldName);
152 defaultField.getDeclaringClass() == info.definedIn ? sourceType : info.definedIn,
153 info.fieldName);
154 if (mapping != null) {
155 Set mappings = (Set)hiddenMappers.get(info.fieldName);
156 if (mappings == null) {
157 mappings = new HashSet();
158 mappings.add(mapping);
159 hiddenMappers.put(info.fieldName, mappings);
160 } else {
161 if (!mappings.add(mapping)) {
162 mapping = null;
163 }
164 }
165 }
148166 if (mapping != null) {
149167 if (context instanceof ReferencingMarshallingContext) {
150168 if (info.value != Collections.EMPTY_LIST
204222 Class actualType = newObj != null ? newObj.getClass() : fieldType;
205223 ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null
206224 ? aliasName
207 : mapper.serializedMember(source.getClass(), fieldName), actualType);
225 : mapper.serializedMember(sourceType, fieldName), actualType);
208226
209227 if (newObj != null) {
210228 Class defaultType = mapper.defaultImplementationOf(fieldType);
299317 type = Primitives.box(type);
300318 }
301319 if (value != null && !type.isAssignableFrom(value.getClass())) {
302 throw new ConversionException("Cannot convert type "
303 + value.getClass().getName()
304 + " to type "
305 + type.getName());
320 ConversionException exception = new ConversionException("Cannot convert type");
321 exception.add("source-type", value.getClass().getName());
322 exception.add("target-type", type.getName());
323 throw exception;
306324 }
307325 seenFields.add(new FastField(classDefiningField, attrName));
308326 reflectionProvider.writeField(result, attrName, value, classDefiningField);
331349 field = reflectionProvider.getFieldOrNull(fieldDeclaringClass, fieldName);
332350 if (field == null) {
333351 // it is not a field ... do we have a field alias?
334 Class itemType = mapper.getItemTypeForItemFieldName(resultType, fieldName);
352 Class itemType = mapper.getItemTypeForItemFieldName(fieldDeclaringClass, fieldName);
335353 if (itemType != null) {
336354 String classAttribute = HierarchicalStreams.readClassAttribute(
337355 reader, mapper);
346364 try {
347365 type = mapper.realClass(originalNodeName);
348366 implicitFieldName = mapper.getFieldNameForItemTypeAndName(
349 context.getRequiredType(), type, originalNodeName);
367 fieldDeclaringClass, type, originalNodeName);
350368 } catch (CannotResolveClassException e) {
351369 // type stays null ...
352370 }
354372 // either not a type or element is a type alias, but does not
355373 // belong to an implicit field
356374 handleUnknownField(
357 explicitDeclaringClass, fieldName, resultType, originalNodeName);
375 explicitDeclaringClass, fieldName, fieldDeclaringClass, originalNodeName);
358376
359377 // element is unknown in declaring class, ignore it now
360378 type = null;
399417 if (field != null
400418 && (fieldAlreadyChecked || (shouldUnmarshalField(field) && mapper
401419 .shouldSerializeMember(field.getDeclaringClass(), fieldName)))) {
402
403420 String classAttribute = HierarchicalStreams.readClassAttribute(
404421 reader, mapper);
405422 if (classAttribute != null) {
445462 if (implicitFieldName == null) {
446463 // look for implicit field
447464 implicitFieldName = mapper.getFieldNameForItemTypeAndName(
448 context.getRequiredType(),
465 fieldDeclaringClass,
449466 value != null ? value.getClass() : Mapper.Null.class,
450467 originalNodeName);
451468 }
453470 implicitCollectionsForCurrentObject = new HashMap();
454471 }
455472 writeValueToImplicitCollection(
456 value, implicitCollectionsForCurrentObject, result, implicitFieldName);
473 value, implicitCollectionsForCurrentObject, result, new FieldLocation(
474 implicitFieldName, fieldDeclaringClass));
457475 }
458476
459477 reader.moveUp();
466484 Object value = entry.getValue();
467485 if (value instanceof ArraysList) {
468486 Object array = ((ArraysList)value).toPhysicalArray();
469 reflectionProvider.writeField(result, (String)entry.getKey(), array, null);
487 final FieldLocation fieldLocation = (FieldLocation)entry.getKey();
488 final Field field = reflectionProvider.getFieldOrNull(fieldLocation.definedIn,
489 fieldLocation.fieldName);
490 reflectionProvider.writeField(result, fieldLocation.fieldName, array, field != null
491 ? field.getDeclaringClass()
492 : null);
470493 }
471494 }
472495 }
500523 throw new UnknownFieldException(resultType.getName(), fieldName);
501524 }
502525
503 private void writeValueToImplicitCollection(Object value, Map implicitCollections, Object result, String implicitFieldName) {
504 Collection collection = (Collection)implicitCollections.get(implicitFieldName);
526 private void writeValueToImplicitCollection(Object value, Map implicitCollections, Object result, final FieldLocation fieldLocation) {
527 Collection collection = (Collection)implicitCollections.get(fieldLocation);
505528 if (collection == null) {
506 Class physicalFieldType = reflectionProvider.getFieldType(
507 result, implicitFieldName, null);
529 final Field field = reflectionProvider.getFieldOrNull(fieldLocation.definedIn, fieldLocation.fieldName);
530 Class physicalFieldType = field != null
531 ? field.getType()
532 : reflectionProvider.getFieldType(result, fieldLocation.fieldName, null);
508533 if (physicalFieldType.isArray()) {
509534 collection = new ArraysList(physicalFieldType);
510535 } else {
511536 Class fieldType = mapper.defaultImplementationOf(physicalFieldType);
512537 if (!(Collection.class.isAssignableFrom(fieldType) || Map.class
513538 .isAssignableFrom(fieldType))) {
514 throw new ObjectAccessException(
515 "Field "
516 + implicitFieldName
517 + " of "
518 + result.getClass().getName()
519 + " is configured for an implicit Collection or Map, but field is of type "
520 + fieldType.getName());
539 ObjectAccessException oaex = new ObjectAccessException(
540 "Field is configured for an implicit Collection or Map, but is of an incompatible type");
541 oaex.add("field", result.getClass().getName() + "."+fieldLocation.fieldName);
542 oaex.add("field-type", fieldType.getName());
543 throw oaex;
521544 }
522545 if (pureJavaReflectionProvider == null) {
523546 pureJavaReflectionProvider = new PureJavaReflectionProvider();
527550 collection = (Collection)instance;
528551 } else {
529552 Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper
530 .getImplicitCollectionDefForFieldName(result.getClass(), implicitFieldName);
553 .getImplicitCollectionDefForFieldName(fieldLocation.definedIn, fieldLocation.fieldName);
531554 collection = new MappingList(
532555 (Map)instance, implicitCollectionMapping.getKeyFieldName());
533556 }
534 reflectionProvider.writeField(result, implicitFieldName, instance, null);
535 }
536 implicitCollections.put(implicitFieldName, collection);
557 reflectionProvider.writeField(result, fieldLocation.fieldName, instance, field != null
558 ? field.getDeclaringClass()
559 : null);
560 }
561 implicitCollections.put(fieldLocation, collection);
537562 }
538563 collection.add(value);
539564 }
583608 }
584609 }
585610
586 private static class FieldInfo {
611 private static class FieldLocation {
587612 final String fieldName;
613 final Class definedIn;
614
615 FieldLocation(final String fieldName, final Class definedIn) {
616 this.fieldName = fieldName;
617 this.definedIn = definedIn;
618 }
619
620 public int hashCode() {
621 final int prime = 7;
622 int result = 1;
623 result = prime * result + (definedIn == null ? 0 : definedIn.getName().hashCode());
624 result = prime * result + (fieldName == null ? 0 : fieldName.hashCode());
625 return result;
626 }
627
628 public boolean equals(final Object obj) {
629 if (this == obj) {
630 return true;
631 }
632 if (obj == null) {
633 return false;
634 }
635 if (getClass() != obj.getClass()) {
636 return false;
637 }
638 final FieldLocation other = (FieldLocation)obj;
639 if (definedIn != other.definedIn) {
640 return false;
641 }
642 if (fieldName == null) {
643 if (other.fieldName != null) {
644 return false;
645 }
646 } else if (!fieldName.equals(other.fieldName)) {
647 return false;
648 }
649 return true;
650 }
651 }
652
653 private static class FieldInfo extends FieldLocation {
588654 final Class type;
589 final Class definedIn;
590655 final Object value;
591656
592 FieldInfo(String fieldName, Class type, Class definedIn, Object value) {
593 this.fieldName = fieldName;
657 FieldInfo(final String fieldName, final Class type, final Class definedIn, final Object value) {
658 super(fieldName, definedIn);
594659 this.type = type;
595 this.definedIn = definedIn;
596660 this.value = value;
597661 }
598662 }
645709 fieldCache.put(itemType, field);
646710 }
647711 if (field != null) {
648 try {
649 Object key = field.get(object);
650 return map.put(key, object) == null;
651 } catch (IllegalArgumentException e) {
652 throw new ObjectAccessException("Could not get field "
653 + field.getClass()
654 + "."
655 + field.getName(), e);
656 } catch (IllegalAccessException e) {
657 throw new ObjectAccessException("Could not get field "
658 + field.getClass()
659 + "."
660 + field.getName(), e);
661 }
712 Object key = Fields.read(field, object);
713 return map.put(key, object) == null;
662714 }
663715 } else if (object instanceof Map.Entry) {
664716 final Map.Entry entry = (Map.Entry)object;
665717 return map.put(entry.getKey(), entry.getValue()) == null;
666718 }
667719
668 throw new ConversionException("Element of type "
669 + object.getClass().getName()
670 + " is not defined as entry for map of type "
671 + map.getClass().getName());
720 ConversionException exception =
721 new ConversionException("Element is not defined as entry for implicit map");
722 exception.add("map-type", map.getClass().getName());
723 exception.add("element-type", object.getClass().getName());
724 throw exception;
672725 }
673726
674727 public Object get(int index) {
00 /*
1 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015 XStream Committers.
1 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016 XStream Committers.
22 * All rights reserved.
33 *
44 * The software in this package is published under the terms of the BSD
124124 } else {
125125 ConversionException exception = new ConversionException(
126126 "Cannot handle CGLIB enhanced proxies without factory that have multiple callbacks");
127 exception.add("proxy superclass", type.getSuperclass().getName());
128 exception.add("number of callbacks", String.valueOf(callbacks.length));
127 exception.add("proxy-superclass", type.getSuperclass().getName());
128 exception.add("number-of-callbacks", String.valueOf(callbacks.length));
129129 throw exception;
130130 }
131131 writer.startNode("callbacks");
165165 } catch (NoSuchFieldException e) {
166166 // OK, ignore
167167 } catch (IllegalAccessException e) {
168 throw new ObjectAccessException("Access to serialVersionUID of "
169 + type.getName()
170 + " not allowed", e);
168 ObjectAccessException exception = new ObjectAccessException("Cannot access field", e);
169 exception.add("field", type.getName() + ".serialVersionUID");
170 throw exception;
171171 }
172172 if (hasInterceptor) {
173173 writer.startNode("instance");
201201 Object callback = field.get(source);
202202 list.add(callback);
203203 } catch (IllegalAccessException e) {
204 throw new ObjectAccessException("Access to "
205 + type.getName()
206 + "."
207 + CALLBACK_MARKER
208 + i
209 + " not allowed", e);
204 ObjectAccessException exception = new ObjectAccessException("Cannot access field", e);
205 exception.add("field", type.getName() + "." + CALLBACK_MARKER + i);
206 throw exception;
210207 }
211208 }
212209 return (Callback[])list.toArray(new Callback[list.size()]);
268265 ? (Object[])null
269266 : createNullArguments(parameterTypes));
270267 } catch (IllegalAccessException e) {
271 throw new ObjectAccessException("Access to "
272 + calledMethod
273 + " not allowed", e);
268 ObjectAccessException exception = new ObjectAccessException("Cannot access method", e);
269 exception.add("method", calledMethod.toString());
270 throw exception;
274271 } catch (InvocationTargetException e) {
275272 // OK, ignore
276273 } catch (NoSuchMethodException e) {
277274 ConversionException exception = new ConversionException(
278275 "CGLIB enhanced proxies wit abstract nethod that has not been implemented");
279 exception.add("proxy superclass", type.getSuperclass().getName());
276 exception.add("proxy-superclass", type.getSuperclass().getName());
280277 exception.add("method", method.toString());
281278 throw exception;
282279 }
335332 if (iface == Callback.class) {
336333 ConversionException exception = new ConversionException(
337334 "Cannot handle CGLIB callback");
338 exception.add("CGLIB callback type", callback.getClass().getName());
335 exception.add("CGLIB-callback-type", callback.getClass().getName());
339336 throw exception;
340337 }
341338 interfaces = iface.getInterfaces();
487484 if (!callbackIndexMap.containsKey(method)) {
488485 ConversionException exception = new ConversionException(
489486 "CGLIB callback not detected in reverse engineering");
490 exception.add("CGLIB callback", method.toString());
487 exception.add("CGLIB-callback", method.toString());
491488 throw exception;
492489 }
493490 return ((Integer)callbackIndexMap.get(method)).intValue();
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016 XStream Committers.
33 * All rights reserved.
44 *
55 * The software in this package is published under the terms of the BSD
2424 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
2525 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
2626 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
27 import com.thoughtworks.xstream.io.StreamException;
2728 import com.thoughtworks.xstream.mapper.Mapper;
2829
2930 import java.io.Externalizable;
123124 externalizable.writeExternal(objectOutput);
124125 objectOutput.popCallback();
125126 } catch (IOException e) {
126 throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization", e);
127 throw new StreamException("Cannot serialize " + source.getClass().getName() + " using Externalization", e);
127128 }
128129 }
129130 }
167168 objectInput.popCallback();
168169 return serializationMembers.callReadResolve(externalizable);
169170 } catch (NoSuchMethodException e) {
170 throw new ConversionException("Cannot construct " + type.getClass() + ", missing default constructor", e);
171 throw new ConversionException("Missing default constructor of type", e);
171172 } catch (InvocationTargetException e) {
172 throw new ConversionException("Cannot construct " + type.getClass(), e);
173 throw new ConversionException("Cannot construct type", e);
173174 } catch (InstantiationException e) {
174 throw new ConversionException("Cannot construct " + type.getClass(), e);
175 throw new ConversionException("Cannot construct type", e);
175176 } catch (IllegalAccessException e) {
176 throw new ConversionException("Cannot construct " + type.getClass(), e);
177 throw new ObjectAccessException("Cannot construct type", e);
177178 } catch (IOException e) {
178 throw new ConversionException("Cannot externalize " + type.getClass(), e);
179 throw new StreamException("Cannot externalize " + type.getClass(), e);
179180 } catch (ClassNotFoundException e) {
180 throw new ConversionException("Cannot externalize " + type.getClass(), e);
181 throw new ConversionException("Cannot construct type", e);
181182 }
182183 }
183184
00 /*
11 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream Committers.
33 * All rights reserved.
4 *
54 * The software in this package is published under the terms of the BSD
65 * style license a copy of which has been included with this distribution in
76 * the LICENSE.txt file.
8 *
97 * Created on 14. May 2004 by Joe Walnes
108 */
119 package com.thoughtworks.xstream.converters.reflection;
1210
1311 import java.lang.reflect.Field;
1412 import java.lang.reflect.Modifier;
15 import java.util.ArrayList;
1613 import java.util.Collections;
1714 import java.util.HashMap;
1815 import java.util.Iterator;
19 import java.util.List;
16 import java.util.LinkedList;
2017 import java.util.Map;
21 import java.util.Set;
2218
2319 import com.thoughtworks.xstream.core.Caching;
2420 import com.thoughtworks.xstream.core.JVM;
2723
2824 /**
2925 * A field dictionary instance caches information about classes fields.
30 *
26 *
3127 * @author Joe Walnes
3228 * @author J&ouml;rg Schaible
3329 * @author Guilherme Silveira
3430 */
3531 public class FieldDictionary implements Caching {
3632
37 private transient Map keyedByFieldNameCache;
38 private transient Map keyedByFieldKeyCache;
33 private static final DictionaryEntry OBJECT_DICTIONARY_ENTRY = new DictionaryEntry(Collections.EMPTY_MAP,
34 Collections.EMPTY_MAP);
35
36 private transient Map dictionaryEntries;
3937 private final FieldKeySorter sorter;
4038
4139 public FieldDictionary() {
4240 this(new ImmutableFieldKeySorter());
4341 }
4442
45 public FieldDictionary(FieldKeySorter sorter) {
43 public FieldDictionary(final FieldKeySorter sorter) {
4644 this.sorter = sorter;
4745 init();
4846 }
4947
5048 private void init() {
51 keyedByFieldNameCache = new HashMap();
52 keyedByFieldKeyCache = new HashMap();
53 keyedByFieldNameCache.put(Object.class, Collections.EMPTY_MAP);
54 keyedByFieldKeyCache.put(Object.class, Collections.EMPTY_MAP);
49 dictionaryEntries = new HashMap();
5550 }
5651
5752 /**
5853 * Returns an iterator for all fields for some class
59 *
54 *
6055 * @param cls the class you are interested on
6156 * @return an iterator for its fields
6257 * @deprecated As of 1.3, use {@link #fieldsFor(Class)} instead
6358 */
64 public Iterator serializableFieldsFor(Class cls) {
59 public Iterator serializableFieldsFor(final Class cls) {
6560 return fieldsFor(cls);
6661 }
6762
6863 /**
6964 * Returns an iterator for all fields for some class
70 *
65 *
7166 * @param cls the class you are interested on
7267 * @return an iterator for its fields
7368 */
7671 }
7772
7873 /**
79 * Returns an specific field of some class. If definedIn is null, it searches for the field
80 * named 'name' inside the class cls. If definedIn is different than null, tries to find the
81 * specified field name in the specified class cls which should be defined in class
82 * definedIn (either equals cls or a one of it's superclasses)
83 *
74 * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the
75 * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls
76 * which should be defined in class definedIn (either equals cls or a one of it's superclasses)
77 *
8478 * @param cls the class where the field is to be searched
8579 * @param name the field name
8680 * @param definedIn the superclass (or the class itself) of cls where the field was defined
8781 * @return the field itself
8882 * @throws ObjectAccessException if no field can be found
8983 */
90 public Field field(Class cls, String name, Class definedIn) {
91 Field field = fieldOrNull(cls, name, definedIn);
84 public Field field(final Class cls, final String name, final Class definedIn) {
85 final Field field = fieldOrNull(cls, name, definedIn);
9286 if (field == null) {
9387 throw new MissingFieldException(cls.getName(), name);
9488 } else {
9791 }
9892
9993 /**
100 * Returns an specific field of some class. If definedIn is null, it searches for the field
101 * named 'name' inside the class cls. If definedIn is different than null, tries to find the
102 * specified field name in the specified class cls which should be defined in class
103 * definedIn (either equals cls or a one of it's superclasses)
104 *
94 * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the
95 * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls
96 * which should be defined in class definedIn (either equals cls or a one of it's superclasses)
97 *
10598 * @param cls the class where the field is to be searched
10699 * @param name the field name
107100 * @param definedIn the superclass (or the class itself) of cls where the field was defined
108101 * @return the field itself or <code>null</code>
109102 * @since 1.4
110103 */
111 public Field fieldOrNull(Class cls, String name, Class definedIn) {
112 Map fields = buildMap(cls, definedIn != null);
113 Field field = (Field)fields.get(definedIn != null
104 public Field fieldOrNull(final Class cls, final String name, final Class definedIn) {
105 final Map fields = buildMap(cls, definedIn != null);
106 final Field field = (Field)fields.get(definedIn != null
114107 ? (Object)new FieldKey(name, definedIn, -1)
115108 : (Object)name);
116109 return field;
117110 }
118111
119 private Map buildMap(final Class type, boolean tupleKeyed) {
112 private Map buildMap(final Class type, final boolean tupleKeyed) {
113
120114 Class cls = type;
121 synchronized (this) {
122 if (!keyedByFieldNameCache.containsKey(type)) {
123 final List superClasses = new ArrayList();
124 while (!Object.class.equals(cls) && cls != null) {
125 superClasses.add(0, cls);
126 cls = cls.getSuperclass();
115
116 DictionaryEntry lastDictionaryEntry = null;
117 final LinkedList superClasses = new LinkedList();
118 while (lastDictionaryEntry == null) {
119 if (Object.class.equals(cls) || cls == null) {
120 lastDictionaryEntry = OBJECT_DICTIONARY_ENTRY;
121 } else {
122 lastDictionaryEntry = getDictionaryEntry(cls);
123 }
124 if (lastDictionaryEntry == null) {
125 superClasses.addFirst(cls);
126 cls = cls.getSuperclass();
127 }
128 }
129
130 for (final Iterator iter = superClasses.iterator(); iter.hasNext();) {
131 cls = (Class)iter.next();
132 DictionaryEntry newDictionaryEntry = buildDictionaryEntryForClass(cls, lastDictionaryEntry);
133 synchronized (this) {
134 final DictionaryEntry concurrentEntry = getDictionaryEntry(cls);
135 if (concurrentEntry == null) {
136 dictionaryEntries.put(cls, newDictionaryEntry);
137 } else {
138 newDictionaryEntry = concurrentEntry;
127139 }
128 Map lastKeyedByFieldName = Collections.EMPTY_MAP;
129 Map lastKeyedByFieldKey = Collections.EMPTY_MAP;
130 for (final Iterator iter = superClasses.iterator(); iter.hasNext();) {
131 cls = (Class)iter.next();
132 if (!keyedByFieldNameCache.containsKey(cls)) {
133 final Map keyedByFieldName = new HashMap(lastKeyedByFieldName);
134 final Map keyedByFieldKey = new OrderRetainingMap(lastKeyedByFieldKey);
135 Field[] fields = cls.getDeclaredFields();
136 if (JVM.reverseFieldDefinition()) {
137 for (int i = fields.length >> 1; i-- > 0;) {
138 final int idx = fields.length - i - 1;
139 final Field field = fields[i];
140 fields[i] = fields[idx];
141 fields[idx] = field;
142 }
143 }
144 for (int i = 0; i < fields.length; i++ ) {
145 Field field = fields[i];
146 if (!field.isAccessible()) {
147 field.setAccessible(true);
148 }
149 FieldKey fieldKey = new FieldKey(
150 field.getName(), field.getDeclaringClass(), i);
151 Field existent = (Field)keyedByFieldName.get(field.getName());
152 if (existent == null
153 // do overwrite statics
154 || ((existent.getModifiers() & Modifier.STATIC) != 0)
155 // overwrite non-statics with non-statics only
156 || (existent != null && ((field.getModifiers() & Modifier.STATIC) == 0))) {
157 keyedByFieldName.put(field.getName(), field);
158 }
159 keyedByFieldKey.put(fieldKey, field);
160 }
161 final Map sortedFieldKeys = sorter.sort(cls, keyedByFieldKey);
162 keyedByFieldNameCache.put(cls, keyedByFieldName);
163 keyedByFieldKeyCache.put(cls, sortedFieldKeys);
164 lastKeyedByFieldName = keyedByFieldName;
165 lastKeyedByFieldKey = sortedFieldKeys;
166 } else {
167 lastKeyedByFieldName = (Map)keyedByFieldNameCache.get(cls);
168 lastKeyedByFieldKey = (Map)keyedByFieldKeyCache.get(cls);
169 }
170 }
171 return tupleKeyed ? lastKeyedByFieldKey : lastKeyedByFieldName;
172 }
173 }
174 return (Map)(tupleKeyed
175 ? keyedByFieldKeyCache.get(type)
176 : keyedByFieldNameCache.get(type));
140 }
141 lastDictionaryEntry = newDictionaryEntry;
142 }
143
144 return tupleKeyed ? lastDictionaryEntry.getKeyedByFieldKey() : lastDictionaryEntry.getKeyedByFieldName();
145
146 }
147
148 private DictionaryEntry buildDictionaryEntryForClass(final Class cls, final DictionaryEntry lastDictionaryEntry) {
149 final Map keyedByFieldName = new HashMap(lastDictionaryEntry.getKeyedByFieldName());
150 final Map keyedByFieldKey = new OrderRetainingMap(lastDictionaryEntry.getKeyedByFieldKey());
151 final Field[] fields = cls.getDeclaredFields();
152 if (JVM.reverseFieldDefinition()) {
153 for (int i = fields.length >> 1; i-- > 0;) {
154 final int idx = fields.length - i - 1;
155 final Field field = fields[i];
156 fields[i] = fields[idx];
157 fields[idx] = field;
158 }
159 }
160 for (int i = 0; i < fields.length; i++) {
161 final Field field = fields[i];
162 if (!field.isAccessible()) {
163 field.setAccessible(true);
164 }
165 final FieldKey fieldKey = new FieldKey(field.getName(), field.getDeclaringClass(), i);
166 final Field existent = (Field)keyedByFieldName.get(field.getName());
167 if (existent == null
168 // do overwrite statics
169 || (existent.getModifiers() & Modifier.STATIC) != 0
170 // overwrite non-statics with non-statics only
171 || (existent != null && (field.getModifiers() & Modifier.STATIC) == 0)) {
172 keyedByFieldName.put(field.getName(), field);
173 }
174 keyedByFieldKey.put(fieldKey, field);
175 }
176 final Map sortedFieldKeys = sorter.sort(cls, keyedByFieldKey);
177 return new DictionaryEntry(keyedByFieldName, sortedFieldKeys);
178 }
179
180 private synchronized DictionaryEntry getDictionaryEntry(final Class cls) {
181 return (DictionaryEntry)dictionaryEntries.get(cls);
177182 }
178183
179184 public synchronized void flushCache() {
180 Set objectTypeSet = Collections.singleton(Object.class);
181 keyedByFieldNameCache.keySet().retainAll(objectTypeSet);
182 keyedByFieldKeyCache.keySet().retainAll(objectTypeSet);
185 dictionaryEntries.clear();
183186 if (sorter instanceof Caching) {
184187 ((Caching)sorter).flushCache();
185188 }
189192 init();
190193 return this;
191194 }
195
196 private static final class DictionaryEntry {
197
198 private final Map keyedByFieldName;
199 private final Map keyedByFieldKey;
200
201 public DictionaryEntry(final Map keyedByFieldName, final Map keyedByFieldKey) {
202 super();
203 this.keyedByFieldName = keyedByFieldName;
204 this.keyedByFieldKey = keyedByFieldKey;
205 }
206
207 public Map getKeyedByFieldName() {
208 return keyedByFieldName;
209 }
210
211 public Map getKeyedByFieldKey() {
212 return keyedByFieldKey;
213 }
214 }
192215 }