Codebase list libxstream-java / upstream/1.4.8
Imported Upstream version 1.4.8 Emmanuel Bourg 8 years ago
715 changed file(s) with 92161 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 For Java 5 or higher build with Maven 2.2 or 3
1 For Java 1.4 build with Maven 2.0.11
2
3 Before building:
4
5 To build:
6
7 mvn clean install
8
9 Before deploying:
10
11 copy settings-template.xml to ~/.m2/settings.xml adding your Codehaus DAV username and passwords.
12
13 To deploy (optionally adding sources and javadoc jars):
14 mvn deploy
0 (BSD Style License)
1
2 Copyright (c) 2003-2006, Joe Walnes
3 Copyright (c) 2006-2011, XStream Committers
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 Redistributions of source code must retain the above copyright notice, this list of
10 conditions and the following disclaimer. Redistributions in binary form must reproduce
11 the above copyright notice, this list of conditions and the following disclaimer in
12 the documentation and/or other materials provided with the distribution.
13
14 Neither the name of XStream nor the names of its contributors may be used to endorse
15 or promote products derived from this software without specific prior written
16 permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
19 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
26 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 DAMAGE.
0
1 ***********
2 ********************** XStream **********************
3 ***********
4
5 "Java to XML Serialization, and back again"
6
7
8 --[ Binaries ]-----------------------------------------------
9
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
13 greatly improve the performance of XStream.
14
15 --[ Documentation ]------------------------------------------
16
17 Documentation can be found in docs/index.html. This includes:
18 * Introduction and tutorial
19 * JavaDoc
20 * Change log
21 * Frequently asked questions
22
23 --[ Source ]-------------------------------------------------
24
25 The complete source for XStream is bundled. This includes:
26 * Main API [src/java]
27 * Unit tests [src/test]
28 * Maven build files [pom.xml]
29 * Dependencies [lib]
30
31 -------------------------------------------------------------
32
33 -XStream Ccommitters
34
35 http://xstream.codehaus.org/
36
0 <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">
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. July 2006 by Mauro Talevi
11 -->
12 <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>
19 <groupId>com.thoughtworks.xstream</groupId>
20 <artifactId>xstream-parent</artifactId>
21 <packaging>pom</packaging>
22 <version>1.4.8</version>
23 <name>XStream Parent</name>
24 <description>
25 XStream is a serialization library from Java objects to XML and back.
26 </description>
27
28 <inceptionYear>2004</inceptionYear>
29 <organization>
30 <name>XStream</name>
31 <url>http://xstream.codehaus.org</url>
32 </organization>
33
34 <profiles>
35 <profile>
36 <id>jdk19</id>
37 <activation>
38 <jdk>1.9</jdk>
39 </activation>
40 <properties>
41 <version.java.source>1.6</version.java.source>
42 <version.java.target>1.6</version.java.target>
43 </properties>
44 </profile>
45 <profile>
46 <id>jdk18ge</id>
47 <activation>
48 <jdk>[1.8,)</jdk>
49 </activation>
50 <properties>
51 <javadoc.xdoclint>-Xdoclint:-missing</javadoc.xdoclint>
52 </properties>
53 </profile>
54 <profile>
55 <id>jdk15-ge</id>
56 <activation>
57 <jdk>[1.5,)</jdk>
58 </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>
76 <modules>
77 <!--module>xstream-builder</module-->
78 </modules>
79 </profile>
80 <profile>
81 <id>jdk15</id>
82 <activation>
83 <jdk>1.5</jdk>
84 </activation>
85 <properties>
86 <version.hsqldb>1.8.0.10</version.hsqldb>
87 <version.org.hibernate.core>3.6.6.Final</version.org.hibernate.core>
88 </properties>
89 </profile>
90 <profile>
91 <!-- build with Maven 2.0.10 !!! -->
92 <id>jdk14</id>
93 <activation>
94 <jdk>1.4</jdk>
95 </activation>
96 <properties>
97 <version.java.source>1.3</version.java.source>
98 <version.java.target>1.3</version.java.target>
99 <link.javadoc.javase>http://docs.oracle.com/javase/1.4.2/docs/api/</link.javadoc.javase>
100 <!-- repeat Hibernate version dependencies, JDK intervals in activation is not supported with M2.0.x -->
101 <version.hsqldb>1.8.0.10</version.hsqldb>
102 <version.org.hibernate.core>3.3.2.GA</version.org.hibernate.core>
103 <version.org.hibernate.envers>3.6.6.Final</version.org.hibernate.envers><!-- not usable with JDK 1.4 -->
104 </properties>
105 </profile>
106 <profile>
107 <id>java</id>
108 <activation>
109 <file>
110 <exists>src/java</exists>
111 </file>
112 </activation>
113 <build>
114 <plugins>
115 <plugin>
116 <groupId>org.apache.maven.plugins</groupId>
117 <artifactId>maven-enforcer-plugin</artifactId>
118 <!-- overwrite codehaus-parent -->
119 <version>${version.plugin.maven.enforcer}</version>
120 <executions>
121 <execution>
122 <id>enforce-java-version</id>
123 <goals>
124 <goal>enforce</goal>
125 </goals>
126 <configuration>
127 <rules>
128 <requireJavaVersion>
129 <version>${version.java.enforced}</version>
130 </requireJavaVersion>
131 </rules>
132 </configuration>
133 </execution>
134 </executions>
135 </plugin>
136 </plugins>
137 </build>
138 </profile>
139 <profile>
140 <id>xstream-release</id>
141 <properties>
142 <version.java.enforced>[1.8,1.9)</version.java.enforced>
143 </properties>
144 <build>
145 <plugins>
146 <plugin>
147 <groupId>org.apache.maven.plugins</groupId>
148 <artifactId>maven-gpg-plugin</artifactId>
149 <executions>
150 <execution>
151 <id>sign-artifacts</id>
152 <phase>verify</phase>
153 <goals>
154 <goal>sign</goal>
155 </goals>
156 </execution>
157 </executions>
158 </plugin>
159 </plugins>
160 </build>
161 </profile>
162 </profiles>
163
164 <modules>
165 <module>xstream</module>
166 <module>xstream-hibernate</module>
167 <module>xstream-benchmark</module>
168 <module>xstream-distribution</module>
169 </modules>
170
171 <licenses>
172 <license>
173 <name>BSD style</name>
174 <url>http://xstream.codehaus.org/license.html</url>
175 <distribution>repo</distribution>
176 </license>
177 </licenses>
178
179 <dependencyManagement>
180 <dependencies>
181 <dependency>
182 <groupId>com.thoughtworks.xstream</groupId>
183 <artifactId>xstream</artifactId>
184 <version>1.4.8</version>
185 </dependency>
186 <dependency>
187 <groupId>com.thoughtworks.xstream</groupId>
188 <artifactId>xstream</artifactId>
189 <version>1.4.8</version>
190 <classifier>tests</classifier>
191 <type>test-jar</type>
192 <scope>test</scope>
193 </dependency>
194 <dependency>
195 <groupId>com.thoughtworks.xstream</groupId>
196 <artifactId>xstream</artifactId>
197 <version>1.4.8</version>
198 <classifier>javadoc</classifier>
199 <scope>provided</scope>
200 </dependency>
201 <dependency>
202 <groupId>com.thoughtworks.xstream</groupId>
203 <artifactId>xstream-hibernate</artifactId>
204 <version>1.4.8</version>
205 </dependency>
206 <dependency>
207 <groupId>com.thoughtworks.xstream</groupId>
208 <artifactId>xstream-hibernate</artifactId>
209 <version>1.4.8</version>
210 <classifier>javadoc</classifier>
211 <scope>provided</scope>
212 </dependency>
213 <dependency>
214 <groupId>com.thoughtworks.xstream</groupId>
215 <artifactId>xstream-benchmark</artifactId>
216 <version>1.4.8</version>
217 </dependency>
218 <dependency>
219 <groupId>com.thoughtworks.xstream</groupId>
220 <artifactId>xstream-benchmark</artifactId>
221 <version>1.4.8</version>
222 <classifier>javadoc</classifier>
223 <scope>provided</scope>
224 </dependency>
225
226 <dependency>
227 <groupId>commons-io</groupId>
228 <artifactId>commons-io</artifactId>
229 <version>${version.commons.io}</version>
230 </dependency>
231
232 <dependency>
233 <groupId>commons-cli</groupId>
234 <artifactId>commons-cli</artifactId>
235 <version>${version.commons.cli}</version>
236 </dependency>
237
238 <dependency>
239 <groupId>commons-lang</groupId>
240 <artifactId>commons-lang</artifactId>
241 <version>${version.commons.lang}</version>
242 </dependency>
243
244 <dependency>
245 <groupId>cglib</groupId>
246 <artifactId>cglib-nodep</artifactId>
247 <version>${version.cglib.nodep}</version>
248 </dependency>
249 <dependency>
250 <groupId>javassist</groupId>
251 <artifactId>javassist</artifactId>
252 <version>${version.javaassist}</version>
253 </dependency>
254
255 <dependency>
256 <groupId>dom4j</groupId>
257 <artifactId>dom4j</artifactId>
258 <version>${version.dom4j}</version>
259 <exclusions>
260 <exclusion>
261 <groupId>xml-apis</groupId>
262 <artifactId>xml-apis</artifactId>
263 </exclusion>
264 </exclusions>
265 </dependency>
266
267 <dependency>
268 <groupId>org.jdom</groupId>
269 <artifactId>jdom</artifactId>
270 <version>${version.org.jdom}</version>
271 </dependency>
272 <dependency>
273 <groupId>org.jdom</groupId>
274 <artifactId>jdom2</artifactId>
275 <version>${version.org.jdom2}</version>
276 </dependency>
277
278 <dependency>
279 <groupId>joda-time</groupId>
280 <artifactId>joda-time</artifactId>
281 <version>${version.joda-time}</version>
282 </dependency>
283
284 <dependency>
285 <groupId>com.megginson.sax</groupId>
286 <artifactId>xml-writer</artifactId>
287 <version>${version.com.megginson.sax.xml-writer}</version>
288 <exclusions>
289 <exclusion>
290 <groupId>xml-apis</groupId>
291 <artifactId>xml-apis</artifactId>
292 </exclusion>
293 </exclusions>
294 </dependency>
295
296 <dependency>
297 <groupId>stax</groupId>
298 <artifactId>stax</artifactId>
299 <version>${version.stax}</version>
300 </dependency>
301 <dependency>
302 <groupId>stax</groupId>
303 <artifactId>stax-api</artifactId>
304 <version>${version.stax.api}</version>
305 </dependency>
306
307 <dependency>
308 <groupId>org.codehaus.woodstox</groupId>
309 <artifactId>wstx-asl</artifactId>
310 <version>${version.org.codehaus.woodstox.asl}</version>
311 </dependency>
312
313 <dependency>
314 <groupId>xom</groupId>
315 <artifactId>xom</artifactId>
316 <version>${version.xom}</version>
317 <exclusions>
318 <exclusion>
319 <groupId>xerces</groupId>
320 <artifactId>xmlParserAPIs</artifactId>
321 </exclusion>
322 <exclusion>
323 <groupId>xerces</groupId>
324 <artifactId>xercesImpl</artifactId>
325 </exclusion>
326 <exclusion>
327 <groupId>xalan</groupId>
328 <artifactId>xalan</artifactId>
329 </exclusion>
330 <exclusion>
331 <groupId>jaxen</groupId>
332 <artifactId>jaxen</artifactId>
333 </exclusion>
334 </exclusions>
335 </dependency>
336
337 <dependency>
338 <groupId>xpp3</groupId>
339 <artifactId>xpp3_min</artifactId>
340 <version>${version.xpp3}</version>
341 </dependency>
342 <dependency>
343 <groupId>net.sf.kxml</groupId>
344 <artifactId>kxml2-min</artifactId>
345 <version>${version.net.sf.kxml.kxml2}</version>
346 </dependency>
347 <dependency>
348 <groupId>net.sf.kxml</groupId>
349 <artifactId>kxml2</artifactId>
350 <version>${version.net.sf.kxml.kxml2}</version>
351 </dependency>
352 <dependency>
353 <groupId>xmlpull</groupId>
354 <artifactId>xmlpull</artifactId>
355 <version>${version.xmlpull}</version>
356 </dependency>
357
358 <dependency>
359 <groupId>oro</groupId>
360 <artifactId>oro</artifactId>
361 <version>${version.oro}</version>
362 </dependency>
363
364 <dependency>
365 <groupId>org.json</groupId>
366 <artifactId>json</artifactId>
367 <version>${version.org.json}</version>
368 </dependency>
369
370 <dependency>
371 <groupId>org.codehaus.jettison</groupId>
372 <artifactId>jettison</artifactId>
373 <version>${version.org.codehaus.jettison}</version>
374 </dependency>
375
376 <dependency>
377 <groupId>xml-apis</groupId>
378 <artifactId>xml-apis</artifactId>
379 <version>${version.xml-apis}</version>
380 </dependency>
381
382 <dependency>
383 <groupId>xerces</groupId>
384 <artifactId>xercesImpl</artifactId>
385 <version>${version.xerces.impl}</version>
386 </dependency>
387
388 <dependency>
389 <groupId>org.hibernate</groupId>
390 <artifactId>hibernate-core</artifactId>
391 <version>${version.org.hibernate.core}</version>
392 </dependency>
393 <dependency>
394 <groupId>org.hibernate</groupId>
395 <artifactId>hibernate-envers</artifactId>
396 <version>${version.org.hibernate.envers}</version>
397 <exclusions>
398 <exclusion>
399 <groupId>cglib</groupId>
400 <artifactId>cglib</artifactId>
401 </exclusion>
402 </exclusions>
403 </dependency>
404 <dependency>
405 <groupId>org.hsqldb</groupId>
406 <artifactId>hsqldb</artifactId>
407 <version>${version.hsqldb}</version>
408 </dependency>
409 <dependency>
410 <groupId>org.slf4j</groupId>
411 <artifactId>slf4j-api</artifactId>
412 <version>${version.org.slf4j}</version>
413 <scope>runtime</scope>
414 </dependency>
415 <dependency>
416 <groupId>org.slf4j</groupId>
417 <artifactId>slf4j-simple</artifactId>
418 <version>${version.org.slf4j}</version>
419 <scope>runtime</scope>
420 </dependency>
421
422 <!-- always test-scoped -->
423 <dependency>
424 <groupId>junit</groupId>
425 <artifactId>junit</artifactId>
426 <version>${version.junit}</version>
427 <scope>test</scope>
428 </dependency>
429
430 <dependency>
431 <groupId>jmock</groupId>
432 <artifactId>jmock</artifactId>
433 <version>${version.jmock}</version>
434 <scope>test</scope>
435 </dependency>
436
437 </dependencies>
438 </dependencyManagement>
439
440 <build>
441 <sourceDirectory>${basedir}/src/java</sourceDirectory>
442 <resources>
443 <resource>
444 <directory>${basedir}/src/java</directory>
445 <includes>
446 <include>**/*.properties</include>
447 <include>**/*.xml</include>
448 </includes>
449 </resource>
450 </resources>
451 <testSourceDirectory>${basedir}/src/test</testSourceDirectory>
452 <testResources>
453 <testResource>
454 <directory>${basedir}/src/test</directory>
455 <includes>
456 <include>**/*.xml</include>
457 <include>**/*.xsl</include>
458 <include>**/*.txt</include>
459 </includes>
460 </testResource>
461 </testResources>
462 <pluginManagement>
463 <plugins>
464 <plugin>
465 <groupId>org.apache.maven.plugins</groupId>
466 <artifactId>maven-antrun-plugin</artifactId>
467 <version>${version.plugin.maven.antrun}</version>
468 </plugin>
469 <plugin>
470 <groupId>org.apache.maven.plugins</groupId>
471 <artifactId>maven-assembly-plugin</artifactId>
472 <version>${version.plugin.maven.assembly}</version>
473 </plugin>
474 <plugin>
475 <groupId>org.apache.maven.plugins</groupId>
476 <artifactId>maven-clean-plugin</artifactId>
477 <version>${version.plugin.maven.clean}</version>
478 </plugin>
479 <plugin>
480 <groupId>org.apache.maven.plugins</groupId>
481 <artifactId>maven-compiler-plugin</artifactId>
482 <version>${version.plugin.maven.compiler}</version>
483 <configuration>
484 <source>${version.java.source}</source>
485 <target>${version.java.target}</target>
486 </configuration>
487 </plugin>
488 <plugin>
489 <groupId>org.apache.maven.plugins</groupId>
490 <artifactId>maven-dependency-plugin</artifactId>
491 <version>${version.plugin.maven.dependency}</version>
492 </plugin>
493 <plugin>
494 <groupId>org.apache.maven.plugins</groupId>
495 <artifactId>maven-deploy-plugin</artifactId>
496 <version>${version.plugin.maven.deploy}</version>
497 </plugin>
498 <plugin>
499 <groupId>org.apache.maven.plugins</groupId>
500 <artifactId>maven-eclipse-plugin</artifactId>
501 <configuration>
502 <downloadSources>true</downloadSources>
503 <projectNameTemplate>[artifactId]-1.4.x</projectNameTemplate>
504 </configuration>
505 </plugin>
506 <plugin>
507 <groupId>org.apache.maven.plugins</groupId>
508 <artifactId>maven-enforcer-plugin</artifactId>
509 <version>${version.plugin.maven.enforcer}</version>
510 </plugin>
511 <plugin>
512 <groupId>org.apache.maven.plugins</groupId>
513 <artifactId>maven-gpg-plugin</artifactId>
514 <version>${version.plugin.maven.gpg}</version>
515 </plugin>
516 <plugin>
517 <groupId>org.apache.maven.plugins</groupId>
518 <artifactId>maven-install-plugin</artifactId>
519 <version>${version.plugin.maven.install}</version>
520 </plugin>
521 <plugin>
522 <groupId>org.apache.maven.plugins</groupId>
523 <artifactId>maven-jar-plugin</artifactId>
524 <version>${version.plugin.maven.jar}</version>
525 <configuration>
526 <archive>
527 <manifest>
528 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
529 <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
530 </manifest>
531 <manifestEntries>
532 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
533 <X-Compile-Source>${version.java.source}</X-Compile-Source>
534 <X-Compile-Target>${version.java.target}</X-Compile-Target>
535 <X-Builder>Maven ${maven.version}</X-Builder>
536 <X-Build-Time>${maven.build.timestamp}</X-Build-Time>
537 <X-Build-Os>${os.name}</X-Build-Os>
538 </manifestEntries>
539 </archive>
540 </configuration>
541 </plugin>
542 <plugin>
543 <groupId>org.apache.maven.plugins</groupId>
544 <artifactId>maven-javadoc-plugin</artifactId>
545 <version>${version.plugin.maven.javadoc}</version>
546 <executions>
547 <execution>
548 <id>attach-javadocs</id>
549 <goals>
550 <goal>jar</goal>
551 </goals>
552 </execution>
553 </executions>
554 <configuration>
555 <detectJavaApiLink>false</detectJavaApiLink>
556 <additionalparam>${javadoc.xdoclint}</additionalparam>
557 <source>${version.java.source}</source>
558 <links>
559 <link>${link.javadoc.javase}</link>
560 </links>
561 <archive>
562 <manifest>
563 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
564 <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
565 </manifest>
566 <manifestEntries>
567 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
568 </manifestEntries>
569 </archive>
570 </configuration>
571 </plugin>
572 <plugin>
573 <groupId>org.apache.maven.plugins</groupId>
574 <artifactId>maven-release-plugin</artifactId>
575 <version>${version.plugin.maven.release}</version>
576 <configuration>
577 <goals>deploy</goals>
578 <autoVersionSubmodules>true</autoVersionSubmodules>
579 <!-- overwrite codehaus-parent -->
580 <arguments>-Pxstream-release</arguments>
581 </configuration>
582 </plugin>
583 <plugin>
584 <groupId>org.apache.maven.plugins</groupId>
585 <artifactId>maven-resources-plugin</artifactId>
586 <version>${version.plugin.maven.resources}</version>
587 </plugin>
588 <plugin>
589 <groupId>org.apache.maven.plugins</groupId>
590 <artifactId>maven-site-plugin</artifactId>
591 <version>${version.plugin.maven.site}</version>
592 </plugin>
593 <plugin>
594 <groupId>org.apache.maven.plugins</groupId>
595 <artifactId>maven-source-plugin</artifactId>
596 <version>${version.plugin.maven.source}</version>
597 <executions>
598 <execution>
599 <id>attach-sources</id>
600 <phase>package</phase>
601 <goals>
602 <goal>jar-no-fork</goal>
603 </goals>
604 </execution>
605 </executions>
606 <configuration>
607 <archive>
608 <manifest>
609 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
610 <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
611 </manifest>
612 <manifestEntries>
613 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version>
614 <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
615 <Bundle-Name>${project.name} Sources</Bundle-Name>
616 <Bundle-SymbolicName>${project.artifactId}.sources</Bundle-SymbolicName>
617 <Bundle-Vendor>${project.organization.name} Sources</Bundle-Vendor>
618 <Bundle-Version>${project.info.osgiVersion} Sources</Bundle-Version>
619 <Eclipse-SourceBundle>${project.artifactId};version=${project.info.osgiVersion}</Eclipse-SourceBundle>
620 <X-Compile-Source>${version.java.source}</X-Compile-Source>
621 <X-Compile-Target>${version.java.target}</X-Compile-Target>
622 <X-Builder>Maven ${maven.version}</X-Builder>
623 <X-Build-Time>${maven.build.timestamp}</X-Build-Time>
624 <X-Build-Os>${os.name}</X-Build-Os>
625 </manifestEntries>
626 </archive>
627 </configuration>
628 </plugin>
629 <plugin>
630 <groupId>org.apache.maven.plugins</groupId>
631 <artifactId>maven-surefire-plugin</artifactId>
632 <version>${version.plugin.maven.surefire}</version>
633 <configuration>
634 <forkMode>once</forkMode>
635 <printSummary>true</printSummary>
636 <useFile>false</useFile>
637 <includes>
638 <include>**/*Test.java</include>
639 <include>**/*TestSuite.java</include>
640 </includes>
641 <excludes>
642 <exclude>**/Abstract*Test.java</exclude>
643 <exclude>**/*$*.java</exclude>
644 </excludes>
645 <systemProperties>
646 <property>
647 <name>java.awt.headless</name>
648 <value>true</value>
649 </property>
650 </systemProperties>
651 </configuration>
652 </plugin>
653 <plugin>
654 <groupId>org.apache.maven.plugins</groupId>
655 <artifactId>maven-surefire-report-plugin</artifactId>
656 <version>${version.plugin.maven.surefire}</version>
657 </plugin>
658 <plugin>
659 <groupId>org.codehaus.mojo</groupId>
660 <artifactId>build-helper-maven-plugin</artifactId>
661 <version>${version.plugin.mojo.build-helper}</version>
662 </plugin>
663 <plugin>
664 <groupId>org.codehaus.mojo</groupId>
665 <artifactId>cobertura-maven-plugin</artifactId>
666 <version>${version.plugin.mojo.cobertura}</version>
667 <executions>
668 <execution>
669 <goals>
670 <goal>clean</goal>
671 </goals>
672 </execution>
673 </executions>
674 </plugin>
675 <plugin>
676 <groupId>org.codehaus.mojo</groupId>
677 <artifactId>jxr-maven-plugin</artifactId>
678 <version>${version.plugin.mojo.jxr}</version>
679 </plugin>
680 <plugin>
681 <groupId>org.codehaus.xsite</groupId>
682 <artifactId>xsite-maven-plugin</artifactId>
683 <version>${version.plugin.codehaus.xsite}</version>
684 </plugin>
685 <plugin>
686 <groupId>org.apache.felix</groupId>
687 <artifactId>maven-bundle-plugin</artifactId>
688 <version>${version.plugin.felix.bundle}</version>
689 <configuration>
690 <manifestLocation>${project.build.directory}/OSGi</manifestLocation>
691 <instructions>
692 <_nouses>true</_nouses>
693 <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
694 <Specification-Version>${project.info.majorVersion}.${project.info.minorVersion}</Specification-Version><!-- FELIX-3392 -->
695 </instructions>
696 <archive>
697 <manifest>
698 <addDefaultSpecificationEntries>false</addDefaultSpecificationEntries><!-- FELIX-3392 -->
699 </manifest>
700 </archive>
701 </configuration>
702 </plugin>
703 </plugins>
704 </pluginManagement>
705 <plugins>
706 <plugin>
707 <groupId>org.codehaus.mojo</groupId>
708 <artifactId>build-helper-maven-plugin</artifactId>
709 <executions>
710 <execution>
711 <id>versions</id>
712 <phase>initialize</phase>
713 <goals>
714 <goal>maven-version</goal>
715 <goal>parse-version</goal>
716 </goals>
717 <configuration>
718 <propertyPrefix>project.info</propertyPrefix>
719 </configuration>
720 </execution>
721 </executions>
722 </plugin>
723 <plugin>
724 <groupId>org.apache.maven.plugins</groupId>
725 <artifactId>maven-release-plugin</artifactId>
726 <configuration>
727 <tagBase>https://svn.codehaus.org/xstream/tags</tagBase>
728 </configuration>
729 </plugin>
730 </plugins>
731 <extensions>
732 <extension>
733 <groupId>org.apache.maven.wagon</groupId>
734 <artifactId>wagon-webdav</artifactId>
735 <version>${version.org.apache.maven.wagon.webdev}</version>
736 </extension>
737 </extensions>
738 </build>
739
740 <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>
751 </distributionManagement>
752
753 <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>
757 </scm>
758
759 <properties>
760 <version.java.source>1.5</version.java.source>
761 <version.java.target>1.5</version.java.target>
762 <version.java.enforced>[1.4,)</version.java.enforced>
763
764 <version.plugin.codehaus.xsite>1.2.1</version.plugin.codehaus.xsite>
765 <version.plugin.felix.bundle>2.3.7</version.plugin.felix.bundle>
766 <version.plugin.maven.antrun>1.1</version.plugin.maven.antrun>
767 <version.plugin.maven.assembly>2.1</version.plugin.maven.assembly>
768 <version.plugin.maven.clean>2.2</version.plugin.maven.clean>
769 <version.plugin.maven.compiler>2.1</version.plugin.maven.compiler><!-- JDK 1.4 compatible -->
770 <version.plugin.maven.dependency>2.1</version.plugin.maven.dependency>
771 <version.plugin.maven.deploy>2.3</version.plugin.maven.deploy>
772 <version.plugin.maven.enforcer>1.4</version.plugin.maven.enforcer>
773 <version.plugin.maven.gpg>1.4</version.plugin.maven.gpg>
774 <version.plugin.maven.install>2.2</version.plugin.maven.install>
775 <version.plugin.maven.jar>2.2</version.plugin.maven.jar>
776 <version.plugin.maven.javadoc>2.10</version.plugin.maven.javadoc>
777 <version.plugin.maven.release>2.1</version.plugin.maven.release>
778 <version.plugin.maven.resources>2.2</version.plugin.maven.resources>
779 <version.plugin.maven.site>2.0-beta-6</version.plugin.maven.site>
780 <version.plugin.maven.source>2.1.2</version.plugin.maven.source>
781 <version.plugin.maven.surefire>2.4.3</version.plugin.maven.surefire>
782 <version.plugin.mojo.build-helper>1.5</version.plugin.mojo.build-helper>
783 <version.plugin.mojo.cobertura>2.0</version.plugin.mojo.cobertura>
784 <version.plugin.mojo.jxr>2.0-beta-1</version.plugin.mojo.jxr>
785
786 <version.org.apache.maven.wagon.webdev>1.0-beta-2</version.org.apache.maven.wagon.webdev>
787
788 <version.cglib.nodep>2.2</version.cglib.nodep>
789 <version.com.megginson.sax.xml-writer>0.2</version.com.megginson.sax.xml-writer>
790 <version.commons.cli>1.1</version.commons.cli>
791 <version.commons.io>1.4</version.commons.io>
792 <version.commons.lang>2.4</version.commons.lang>
793 <version.dom4j>1.6.1</version.dom4j>
794 <version.hsqldb>2.2.8</version.hsqldb>
795 <version.javaassist>3.12.1.GA</version.javaassist>
796 <version.jmock>1.0.1</version.jmock>
797 <version.joda-time>1.6</version.joda-time>
798 <version.junit>3.8.1</version.junit>
799 <version.net.sf.kxml.kxml2>2.3.0</version.net.sf.kxml.kxml2>
800 <version.org.codehaus.jettison>1.2</version.org.codehaus.jettison>
801 <version.org.codehaus.woodstox.asl>3.2.7</version.org.codehaus.woodstox.asl>
802 <version.org.hibernate.core>4.2.5.Final</version.org.hibernate.core>
803 <version.org.hibernate.envers>${version.org.hibernate.core}</version.org.hibernate.envers>
804 <version.org.jdom>1.1.3</version.org.jdom>
805 <version.org.jdom2>2.0.5</version.org.jdom2>
806 <version.org.json>20080701</version.org.json>
807 <version.org.slf4j>1.6.1</version.org.slf4j>
808 <version.oro>2.0.8</version.oro>
809 <version.stax>1.2.0</version.stax>
810 <version.stax.api>1.0.1</version.stax.api>
811 <version.xerces.impl>2.8.1</version.xerces.impl>
812 <version.xml-apis>1.3.04</version.xml-apis>
813 <version.xmlpull>1.1.3.1</version.xmlpull>
814 <version.xom>1.1</version.xom>
815 <version.xpp3>1.1.4c</version.xpp3>
816
817 <link.javadoc.javase>http://docs.oracle.com/javase/8/docs/api/</link.javadoc.javase>
818
819 <javadoc.xdoclint />
820 </properties>
821 </project>
0 <?xml version="1.0" encoding="UTF-8"?>
1 <!--
2 Copyright (C) 2006, 2007, 2010 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 30. July 2006 by Mauro Talevi
10 -->
11 <settings>
12 <servers>
13 <server>
14 <id>codehaus-nexus-snapshots</id>
15 <username>your-xircles-id</username>
16 <password>your-xircles-pwd</password>
17 </server>
18 <server>
19 <id>codehaus-nexus-staging</id>
20 <username>your-xircles-id</username>
21 <password>your-xircles-pwd</password>
22 </server>
23 <server>
24 <id>codehaus.org</id>
25 <username></username>
26 <password></password>
27 </server>
28 </servers>
29 </settings>
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
0 <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">
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. July 2006 by Mauro Talevi
11 -->
12 <modelVersion>4.0.0</modelVersion>
13 <parent>
14 <groupId>com.thoughtworks.xstream</groupId>
15 <artifactId>xstream-parent</artifactId>
16 <version>1.4.8</version>
17 </parent>
18 <artifactId>xstream</artifactId>
19 <packaging>jar</packaging>
20 <name>XStream Core</name>
21
22 <dependencies>
23 <dependency>
24 <groupId>dom4j</groupId>
25 <artifactId>dom4j</artifactId>
26 <optional>true</optional>
27 </dependency>
28
29 <dependency>
30 <groupId>org.jdom</groupId>
31 <artifactId>jdom</artifactId>
32 <optional>true</optional>
33 </dependency>
34 <dependency>
35 <groupId>org.jdom</groupId>
36 <artifactId>jdom2</artifactId>
37 <optional>true</optional>
38 </dependency>
39
40 <dependency>
41 <groupId>joda-time</groupId>
42 <artifactId>joda-time</artifactId>
43 <optional>true</optional>
44 </dependency>
45
46 <dependency>
47 <groupId>stax</groupId>
48 <artifactId>stax</artifactId>
49 <optional>true</optional>
50 </dependency>
51
52 <dependency>
53 <groupId>org.codehaus.woodstox</groupId>
54 <artifactId>wstx-asl</artifactId>
55 <optional>true</optional>
56 </dependency>
57
58 <dependency>
59 <groupId>stax</groupId>
60 <artifactId>stax-api</artifactId>
61 <optional>true</optional>
62 </dependency>
63
64 <dependency>
65 <groupId>xom</groupId>
66 <artifactId>xom</artifactId>
67 <optional>true</optional>
68 </dependency>
69
70 <dependency>
71 <groupId>xmlpull</groupId>
72 <artifactId>xmlpull</artifactId>
73 </dependency>
74
75 <dependency>
76 <groupId>net.sf.kxml</groupId>
77 <artifactId>kxml2-min</artifactId>
78 <optional>true</optional>
79 </dependency>
80
81 <dependency>
82 <groupId>net.sf.kxml</groupId>
83 <artifactId>kxml2</artifactId>
84 <optional>true</optional>
85 </dependency>
86
87 <dependency>
88 <groupId>xpp3</groupId>
89 <artifactId>xpp3_min</artifactId>
90 </dependency>
91
92 <dependency>
93 <groupId>cglib</groupId>
94 <artifactId>cglib-nodep</artifactId>
95 <optional>true</optional>
96 </dependency>
97
98 <dependency>
99 <groupId>org.codehaus.jettison</groupId>
100 <artifactId>jettison</artifactId>
101 <optional>true</optional>
102 </dependency>
103
104 <!-- test-scoped -->
105 <dependency>
106 <groupId>junit</groupId>
107 <artifactId>junit</artifactId>
108 </dependency>
109
110 <dependency>
111 <groupId>jmock</groupId>
112 <artifactId>jmock</artifactId>
113 </dependency>
114
115 <dependency>
116 <groupId>org.json</groupId>
117 <artifactId>json</artifactId>
118 <scope>test</scope>
119 </dependency>
120
121 <dependency>
122 <groupId>com.megginson.sax</groupId>
123 <artifactId>xml-writer</artifactId>
124 <scope>test</scope>
125 </dependency>
126
127 <dependency>
128 <groupId>oro</groupId>
129 <artifactId>oro</artifactId>
130 <scope>test</scope>
131 </dependency>
132
133 <dependency>
134 <groupId>commons-lang</groupId>
135 <artifactId>commons-lang</artifactId>
136 <scope>test</scope>
137 </dependency>
138 </dependencies>
139
140 <build>
141 <plugins>
142 <plugin>
143 <groupId>org.apache.maven.plugins</groupId>
144 <artifactId>maven-dependency-plugin</artifactId>
145 <executions>
146 <execution>
147 <id>complete-test-classpath</id>
148 <phase>process-test-resources</phase>
149 <goals>
150 <goal>copy</goal>
151 </goals>
152 <configuration>
153 <outputDirectory>target/lib</outputDirectory>
154 <artifactItems>
155 <artifactItem>
156 <groupId>proxytoys</groupId>
157 <artifactId>proxytoys</artifactId>
158 <version>0.2.1</version>
159 </artifactItem>
160 </artifactItems>
161 </configuration>
162 </execution>
163 <execution>
164 <id>collect-dependencies</id>
165 <phase>package</phase>
166 <goals>
167 <goal>copy-dependencies</goal>
168 </goals>
169 <configuration>
170 <outputDirectory>target/dependencies</outputDirectory>
171 <includeScope>runtime</includeScope>
172 </configuration>
173 </execution>
174 </executions>
175 </plugin>
176 <plugin>
177 <groupId>org.apache.maven.plugins</groupId>
178 <artifactId>maven-jar-plugin</artifactId>
179 <executions>
180 <execution>
181 <goals>
182 <goal>test-jar</goal>
183 </goals>
184 <configuration>
185 <includes>
186 <include>**/AbstractAcceptanceTest.*</include>
187 </includes>
188 <archive combine.children="append">
189 <manifestEntries>
190 <Specification-Title>${project.name} Test</Specification-Title>
191 <Implementation-Title>${project.name} Test</Implementation-Title>
192 </manifestEntries>
193 </archive>
194 </configuration>
195 </execution>
196 </executions>
197 </plugin>
198 </plugins>
199 </build>
200
201 <profiles>
202 <profile>
203 <id>jdk18ge</id>
204 <activation>
205 <jdk>[1.8,)</jdk>
206 </activation>
207 <build>
208 <plugins>
209 <plugin>
210 <groupId>org.apache.maven.plugins</groupId>
211 <artifactId>maven-compiler-plugin</artifactId>
212 <configuration>
213 <compilerArgs>
214 <arg>-XDignore.symbol.file</arg>
215 </compilerArgs>
216 <excludes>
217 <exclude>**/Lambda**</exclude>
218 </excludes>
219 <testExcludes>
220 <exclude>**/Lambda**</exclude>
221 </testExcludes>
222 </configuration>
223 <executions>
224 <execution>
225 <id>compile-jdk18</id>
226 <configuration>
227 <source>1.8</source>
228 <target>1.8</target>
229 <excludes>
230 <exclude>foo</exclude>
231 </excludes>
232 <testExcludes>
233 <exclude>foo</exclude>
234 </testExcludes>
235 </configuration>
236 <goals>
237 <goal>compile</goal>
238 <goal>testCompile</goal>
239 </goals>
240 </execution>
241 </executions>
242 </plugin>
243 <plugin>
244 <groupId>org.apache.maven.plugins</groupId>
245 <artifactId>maven-javadoc-plugin</artifactId>
246 <configuration>
247 <excludePackageNames>com.thoughtworks.xstream.core.util</excludePackageNames>
248 </configuration>
249 </plugin>
250 </plugins>
251 </build>
252 <reporting>
253 <plugins>
254 <plugin>
255 <groupId>org.apache.maven.plugins</groupId>
256 <artifactId>maven-javadoc-plugin</artifactId>
257 <version>${version.plugin.maven.javadoc}</version>
258 <configuration>
259 <excludePackageNames>com.thoughtworks.xstream.core.util</excludePackageNames>
260 <additionalparam>${javadoc.xdoclint}</additionalparam>
261 <detectJavaApiLink>false</detectJavaApiLink>
262 <source>${version.java.source}</source>
263 <links>
264 <link>${link.javadoc.javase}</link>
265 </links>
266 </configuration>
267 </plugin>
268 </plugins>
269 </reporting>
270 </profile>
271 <profile>
272 <id>jdk17</id>
273 <activation>
274 <jdk>1.7</jdk>
275 </activation>
276 <build>
277 <plugins>
278 <plugin>
279 <groupId>org.apache.maven.plugins</groupId>
280 <artifactId>maven-compiler-plugin</artifactId>
281 <configuration>
282 <compilerArgs>
283 <arg>-XDignore.symbol.file</arg>
284 </compilerArgs>
285 <excludes>
286 <exclude>**/Lambda**</exclude>
287 </excludes>
288 <testExcludes>
289 <exclude>**/Lambda**</exclude>
290 </testExcludes>
291 </configuration>
292 </plugin>
293 </plugins>
294 </build>
295 </profile>
296 <profile>
297 <id>jdk15-16</id>
298 <activation>
299 <jdk>[1.5,1.7)</jdk>
300 </activation>
301 <build>
302 <plugins>
303 <plugin>
304 <groupId>org.apache.maven.plugins</groupId>
305 <artifactId>maven-compiler-plugin</artifactId>
306 <configuration>
307 <compilerArgs>
308 <arg>-XDignore.symbol.file</arg>
309 </compilerArgs>
310 <excludes>
311 <exclude>**/Lambda**</exclude>
312 </excludes>
313 <testExcludes>
314 <exclude>**/Lambda**</exclude>
315 <exclude>**/extended/*17Test*</exclude>
316 </testExcludes>
317 </configuration>
318 </plugin>
319 </plugins>
320 </build>
321 </profile>
322 <profile>
323 <id>jdk15-ge</id>
324 <activation>
325 <jdk>[1.5,)</jdk>
326 </activation>
327 <build>
328 <plugins>
329 <plugin>
330 <groupId>org.apache.maven.plugins</groupId>
331 <artifactId>maven-jar-plugin</artifactId>
332 <executions>
333 <execution>
334 <id>default-jar</id>
335 <goals>
336 <goal>jar</goal>
337 </goals>
338 <configuration>
339 <archive combine.children="append">
340 <manifestFile>${project.build.directory}/OSGi/MANIFEST.MF</manifestFile>
341 </archive>
342 </configuration>
343 </execution>
344 </executions>
345 </plugin>
346 <plugin>
347 <groupId>org.apache.maven.plugins</groupId>
348 <artifactId>maven-source-plugin</artifactId>
349 </plugin>
350 <plugin>
351 <groupId>org.apache.felix</groupId>
352 <artifactId>maven-bundle-plugin</artifactId>
353 <configuration>
354 <instructions combine.children="append">
355 <Export-Package>!com.thoughtworks.xstream.core.util,com.thoughtworks.xstream.*;-noimport:=true</Export-Package>
356 </instructions>
357 </configuration>
358 </plugin>
359 </plugins>
360 </build>
361 </profile>
362 <profile>
363 <id>jdk14</id>
364 <activation>
365 <jdk>1.4</jdk>
366 </activation>
367 <build>
368 <plugins>
369 <plugin>
370 <groupId>org.apache.maven.plugins</groupId>
371 <artifactId>maven-compiler-plugin</artifactId>
372 <configuration>
373 <excludes>
374 <exclude>**/Lambda**</exclude>
375 <exclude>**/annotations/*</exclude>
376 <exclude>**/AnnotationMapper*</exclude>
377 <exclude>**/EnumMapper*</exclude>
378 <exclude>**/enums/*</exclude>
379 <exclude>**/basic/StringBuilder*</exclude>
380 <exclude>**/basic/UUID*</exclude>
381 <exclude>**/core/util/Types*</exclude>
382 <exclude>**/extended/*15*</exclude>
383 <exclude>**/io/xml/JDom2*</exclude>
384 </excludes>
385 <testExcludes>
386 <exclude>**/Lambda**</exclude>
387 <exclude>**/annotations/*</exclude>
388 <exclude>**/enums/*</exclude>
389 <exclude>**/extended/*17Test*</exclude>
390 <exclude>**/reflection/SunLimitedUnsafeReflectionProviderTest*</exclude>
391 <exclude>**/reflection/PureJavaReflectionProvider15Test*</exclude>
392 <exclude>**/io/xml/JDom2*Test*</exclude>
393 <exclude>**/acceptance/Basic15TypesTest*</exclude>
394 <exclude>**/acceptance/Concurrent15TypesTest*</exclude>
395 </testExcludes>
396 </configuration>
397 </plugin>
398 </plugins>
399 </build>
400 <dependencies>
401 <dependency>
402 <groupId>xml-apis</groupId>
403 <artifactId>xml-apis</artifactId>
404 </dependency>
405 <dependency>
406 <groupId>xerces</groupId>
407 <artifactId>xercesImpl</artifactId>
408 </dependency>
409 </dependencies>
410 <properties>
411 <version.org.codehaus.jettison>1.0.1</version.org.codehaus.jettison>
412 </properties>
413 </profile>
414 </profiles>
415
416 <reporting>
417 <plugins>
418 <plugin>
419 <groupId>org.apache.maven.plugins</groupId>
420 <artifactId>maven-surefire-report-plugin</artifactId>
421 <version>${version.plugin.maven.surefire}</version>
422 </plugin>
423 <plugin>
424 <groupId>org.codehaus.mojo</groupId>
425 <artifactId>cobertura-maven-plugin</artifactId>
426 <version>${version.plugin.mojo.cobertura}</version>
427 </plugin>
428 </plugins>
429 </reporting>
430
431 </project>
0 /*
1 * Copyright (C) 2007, 2008 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 22. October 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream;
11
12 /**
13 * Exception thrown configuring an XStream instance.
14 *
15 * @author Joe Walnes
16 * @author J&ouml;rg Schaible
17 * @since 1.3
18 */
19 public class InitializationException extends XStream.InitializationException {
20 public InitializationException(String message, Throwable cause) {
21 super(message, cause);
22 }
23
24 public InitializationException(String message) {
25 super(message);
26 }
27 }
0 /*
1 * Copyright (C) 2004, 2006 Joe Walnes.
2 * Copyright (C) 2007, 2009 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 16. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.converters.DataHolder;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19 public interface MarshallingStrategy {
20
21 Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper);
22 void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder);
23 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream;
12
13 import java.io.EOFException;
14 import java.io.File;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.NotActiveException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectInputValidation;
20 import java.io.ObjectOutputStream;
21 import java.io.OutputStream;
22 import java.io.Reader;
23 import java.io.StringReader;
24 import java.io.StringWriter;
25 import java.io.Writer;
26 import java.lang.reflect.Constructor;
27 import java.lang.reflect.Field;
28 import java.lang.reflect.Method;
29 import java.math.BigDecimal;
30 import java.math.BigInteger;
31 import java.net.URI;
32 import java.net.URL;
33 import java.util.ArrayList;
34 import java.util.BitSet;
35 import java.util.Calendar;
36 import java.util.Collections;
37 import java.util.Date;
38 import java.util.GregorianCalendar;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.Hashtable;
42 import java.util.LinkedList;
43 import java.util.List;
44 import java.util.Locale;
45 import java.util.Map;
46 import java.util.Properties;
47 import java.util.Set;
48 import java.util.SortedSet;
49 import java.util.TreeMap;
50 import java.util.TreeSet;
51 import java.util.Vector;
52 import java.util.regex.Pattern;
53
54 import com.thoughtworks.xstream.converters.ConversionException;
55 import com.thoughtworks.xstream.converters.Converter;
56 import com.thoughtworks.xstream.converters.ConverterLookup;
57 import com.thoughtworks.xstream.converters.ConverterRegistry;
58 import com.thoughtworks.xstream.converters.DataHolder;
59 import com.thoughtworks.xstream.converters.SingleValueConverter;
60 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
61 import com.thoughtworks.xstream.converters.basic.BigDecimalConverter;
62 import com.thoughtworks.xstream.converters.basic.BigIntegerConverter;
63 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
64 import com.thoughtworks.xstream.converters.basic.ByteConverter;
65 import com.thoughtworks.xstream.converters.basic.CharConverter;
66 import com.thoughtworks.xstream.converters.basic.DateConverter;
67 import com.thoughtworks.xstream.converters.basic.DoubleConverter;
68 import com.thoughtworks.xstream.converters.basic.FloatConverter;
69 import com.thoughtworks.xstream.converters.basic.IntConverter;
70 import com.thoughtworks.xstream.converters.basic.LongConverter;
71 import com.thoughtworks.xstream.converters.basic.NullConverter;
72 import com.thoughtworks.xstream.converters.basic.ShortConverter;
73 import com.thoughtworks.xstream.converters.basic.StringBufferConverter;
74 import com.thoughtworks.xstream.converters.basic.StringConverter;
75 import com.thoughtworks.xstream.converters.basic.URIConverter;
76 import com.thoughtworks.xstream.converters.basic.URLConverter;
77 import com.thoughtworks.xstream.converters.collections.ArrayConverter;
78 import com.thoughtworks.xstream.converters.collections.BitSetConverter;
79 import com.thoughtworks.xstream.converters.collections.CharArrayConverter;
80 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
81 import com.thoughtworks.xstream.converters.collections.MapConverter;
82 import com.thoughtworks.xstream.converters.collections.PropertiesConverter;
83 import com.thoughtworks.xstream.converters.collections.SingletonCollectionConverter;
84 import com.thoughtworks.xstream.converters.collections.SingletonMapConverter;
85 import com.thoughtworks.xstream.converters.collections.TreeMapConverter;
86 import com.thoughtworks.xstream.converters.collections.TreeSetConverter;
87 import com.thoughtworks.xstream.converters.extended.ColorConverter;
88 import com.thoughtworks.xstream.converters.extended.DynamicProxyConverter;
89 import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
90 import com.thoughtworks.xstream.converters.extended.FileConverter;
91 import com.thoughtworks.xstream.converters.extended.FontConverter;
92 import com.thoughtworks.xstream.converters.extended.GregorianCalendarConverter;
93 import com.thoughtworks.xstream.converters.extended.JavaClassConverter;
94 import com.thoughtworks.xstream.converters.extended.JavaFieldConverter;
95 import com.thoughtworks.xstream.converters.extended.JavaMethodConverter;
96 import com.thoughtworks.xstream.converters.extended.LocaleConverter;
97 import com.thoughtworks.xstream.converters.extended.LookAndFeelConverter;
98 import com.thoughtworks.xstream.converters.extended.SqlDateConverter;
99 import com.thoughtworks.xstream.converters.extended.SqlTimeConverter;
100 import com.thoughtworks.xstream.converters.extended.SqlTimestampConverter;
101 import com.thoughtworks.xstream.converters.extended.TextAttributeConverter;
102 import com.thoughtworks.xstream.converters.reflection.ExternalizableConverter;
103 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
104 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
105 import com.thoughtworks.xstream.converters.reflection.SerializableConverter;
106 import com.thoughtworks.xstream.core.ClassLoaderReference;
107 import com.thoughtworks.xstream.core.DefaultConverterLookup;
108 import com.thoughtworks.xstream.core.JVM;
109 import com.thoughtworks.xstream.core.MapBackedDataHolder;
110 import com.thoughtworks.xstream.core.ReferenceByIdMarshallingStrategy;
111 import com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy;
112 import com.thoughtworks.xstream.core.TreeMarshallingStrategy;
113 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
114 import com.thoughtworks.xstream.core.util.CustomObjectInputStream;
115 import com.thoughtworks.xstream.core.util.CustomObjectOutputStream;
116 import com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker;
117 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
118 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
119 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
120 import com.thoughtworks.xstream.io.StatefulWriter;
121 import com.thoughtworks.xstream.io.xml.XppDriver;
122 import com.thoughtworks.xstream.mapper.AnnotationConfiguration;
123 import com.thoughtworks.xstream.mapper.ArrayMapper;
124 import com.thoughtworks.xstream.mapper.AttributeAliasingMapper;
125 import com.thoughtworks.xstream.mapper.AttributeMapper;
126 import com.thoughtworks.xstream.mapper.CachingMapper;
127 import com.thoughtworks.xstream.mapper.ClassAliasingMapper;
128 import com.thoughtworks.xstream.mapper.DefaultImplementationsMapper;
129 import com.thoughtworks.xstream.mapper.DefaultMapper;
130 import com.thoughtworks.xstream.mapper.DynamicProxyMapper;
131 import com.thoughtworks.xstream.mapper.FieldAliasingMapper;
132 import com.thoughtworks.xstream.mapper.ImmutableTypesMapper;
133 import com.thoughtworks.xstream.mapper.ImplicitCollectionMapper;
134 import com.thoughtworks.xstream.mapper.LocalConversionMapper;
135 import com.thoughtworks.xstream.mapper.Mapper;
136 import com.thoughtworks.xstream.mapper.MapperWrapper;
137 import com.thoughtworks.xstream.mapper.OuterClassMapper;
138 import com.thoughtworks.xstream.mapper.PackageAliasingMapper;
139 import com.thoughtworks.xstream.mapper.SecurityMapper;
140 import com.thoughtworks.xstream.mapper.SystemAttributeAliasingMapper;
141 import com.thoughtworks.xstream.mapper.XStream11XmlFriendlyMapper;
142 import com.thoughtworks.xstream.security.AnyTypePermission;
143 import com.thoughtworks.xstream.security.ExplicitTypePermission;
144 import com.thoughtworks.xstream.security.NoPermission;
145 import com.thoughtworks.xstream.security.NoTypePermission;
146 import com.thoughtworks.xstream.security.RegExpTypePermission;
147 import com.thoughtworks.xstream.security.TypeHierarchyPermission;
148 import com.thoughtworks.xstream.security.TypePermission;
149 import com.thoughtworks.xstream.security.WildcardTypePermission;
150
151
152 /**
153 * Simple facade to XStream library, a Java-XML serialization tool.
154 * <p>
155 * <hr>
156 * <b>Example</b><blockquote>
157 *
158 * <pre>
159 * XStream xstream = new XStream();
160 * String xml = xstream.toXML(myObject); // serialize to XML
161 * Object myObject2 = xstream.fromXML(xml); // deserialize from XML
162 * </pre>
163 *
164 * </blockquote>
165 * <hr>
166 *
167 * <h3>Aliasing classes</h3>
168 *
169 * <p>
170 * To create shorter XML, you can specify aliases for classes using the <code>alias()</code>
171 * method. For example, you can shorten all occurrences of element
172 * <code>&lt;com.blah.MyThing&gt;</code> to <code>&lt;my-thing&gt;</code> by registering an
173 * alias for the class.
174 * <p>
175 * <hr>
176 * <blockquote>
177 *
178 * <pre>
179 * xstream.alias(&quot;my-thing&quot;, MyThing.class);
180 * </pre>
181 *
182 * </blockquote>
183 * <hr>
184 *
185 * <h3>Converters</h3>
186 *
187 * <p>
188 * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each
189 * of which acts as a strategy for converting a particular type of class to XML and back again. Out
190 * of the box, XStream contains converters for most basic types (String, Date, int, boolean, etc)
191 * and collections (Map, List, Set, Properties, etc). For other objects reflection is used to
192 * serialize each field recursively.
193 * </p>
194 *
195 * <p>
196 * Extra converters can be registered using the <code>registerConverter()</code> method. Some
197 * non-standard converters are supplied in the {@link com.thoughtworks.xstream.converters.extended}
198 * package and you can create your own by implementing the
199 * {@link com.thoughtworks.xstream.converters.Converter} interface.
200 * </p>
201 *
202 * <p>
203 * <hr>
204 * <b>Example</b><blockquote>
205 *
206 * <pre>
207 * xstream.registerConverter(new SqlTimestampConverter());
208 * xstream.registerConverter(new DynamicProxyConverter());
209 * </pre>
210 *
211 * </blockquote>
212 * <hr>
213 * <p>
214 * The converters can be registered with an explicit priority. By default they are registered with
215 * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence
216 * they have been registered. The default converter, i.e. the converter which will be used if
217 * no other registered converter is suitable, can be registered with priority
218 * XStream.PRIORITY_VERY_LOW. XStream uses by default the
219 * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback
220 * converter.
221 * </p>
222 *
223 * <p>
224 * <hr>
225 * <b>Example</b><blockquote>
226 *
227 * <pre>
228 * xstream.registerConverter(new CustomDefaultConverter(), XStream.PRIORITY_VERY_LOW);
229 * </pre>
230 *
231 * </blockquote>
232 * <hr>
233 *
234 * <h3>Object graphs</h3>
235 *
236 * <p>
237 * XStream has support for object graphs; a deserialized object graph will keep references intact,
238 * including circular references.
239 * </p>
240 *
241 * <p>
242 * XStream can signify references in XML using either relative/absolute XPath or IDs. The mode can be changed using
243 * <code>setMode()</code>:
244 * </p>
245 *
246 * <table border='1'>
247 * <caption></caption>
248 * <tr>
249 * <td><code>xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);</code></td>
250 * <td><i>(Default)</i> Uses XPath relative references to signify duplicate references. This produces XML
251 * with the least clutter.</td>
252 * </tr>
253 * <tr>
254 * <td><code>xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);</code></td>
255 * <td>Uses XPath absolute references to signify duplicate
256 * references. This produces XML with the least clutter.</td>
257 * </tr>
258 * <tr>
259 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);</code></td>
260 * <td>Uses XPath relative references to signify duplicate references. The XPath expression ensures that
261 * a single node only is selected always.</td>
262 * </tr>
263 * <tr>
264 * <td><code>xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);</code></td>
265 * <td>Uses XPath absolute references to signify duplicate references. The XPath expression ensures that
266 * a single node only is selected always.</td>
267 * </tr>
268 * <tr>
269 * <td><code>xstream.setMode(XStream.ID_REFERENCES);</code></td>
270 * <td>Uses ID references to signify duplicate references. In some scenarios, such as when using
271 * hand-written XML, this is easier to work with.</td>
272 * </tr>
273 * <tr>
274 * <td><code>xstream.setMode(XStream.NO_REFERENCES);</code></td>
275 * <td>This disables object graph support and treats the object structure like a tree. Duplicate
276 * references are treated as two separate objects and circular references cause an exception. This
277 * is slightly faster and uses less memory than the other two modes.</td>
278 * </tr>
279 * </table>
280 * <h3>Thread safety</h3>
281 * <p>
282 * The XStream instance is thread-safe. That is, once the XStream instance has been created and
283 * configured, it may be shared across multiple threads allowing objects to be
284 * serialized/deserialized concurrently. <em>Note, that this only applies if annotations are not
285 * auto-detected on-the-fly.</em>
286 * </p>
287 * <h3>Implicit collections</h3>
288 *
289 * <p>
290 * To avoid the need for special tags for collections, you can define implicit collections using one
291 * of the <code>addImplicitCollection</code> methods.
292 * </p>
293 *
294 * @author Joe Walnes
295 * @author J&ouml;rg Schaible
296 * @author Mauro Talevi
297 * @author Guilherme Silveira
298 */
299 public class XStream {
300
301 // CAUTION: The sequence of the fields is intentional for an optimal XML output of a
302 // self-serialization!
303 private ReflectionProvider reflectionProvider;
304 private HierarchicalStreamDriver hierarchicalStreamDriver;
305 private ClassLoaderReference classLoaderReference;
306 private MarshallingStrategy marshallingStrategy;
307 private ConverterLookup converterLookup;
308 private ConverterRegistry converterRegistry;
309 private Mapper mapper;
310
311 private PackageAliasingMapper packageAliasingMapper;
312 private ClassAliasingMapper classAliasingMapper;
313 private FieldAliasingMapper fieldAliasingMapper;
314 private AttributeAliasingMapper attributeAliasingMapper;
315 private SystemAttributeAliasingMapper systemAttributeAliasingMapper;
316 private AttributeMapper attributeMapper;
317 private DefaultImplementationsMapper defaultImplementationsMapper;
318 private ImmutableTypesMapper immutableTypesMapper;
319 private ImplicitCollectionMapper implicitCollectionMapper;
320 private LocalConversionMapper localConversionMapper;
321 private SecurityMapper securityMapper;
322 private AnnotationConfiguration annotationConfiguration;
323
324 public static final int NO_REFERENCES = 1001;
325 public static final int ID_REFERENCES = 1002;
326 public static final int XPATH_RELATIVE_REFERENCES = 1003;
327 public static final int XPATH_ABSOLUTE_REFERENCES = 1004;
328 public static final int SINGLE_NODE_XPATH_RELATIVE_REFERENCES = 1005;
329 public static final int SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES = 1006;
330
331 public static final int PRIORITY_VERY_HIGH = 10000;
332 public static final int PRIORITY_NORMAL = 0;
333 public static final int PRIORITY_LOW = -10;
334 public static final int PRIORITY_VERY_LOW = -20;
335
336 private static final String ANNOTATION_MAPPER_TYPE = "com.thoughtworks.xstream.mapper.AnnotationMapper";
337 private static final Pattern IGNORE_ALL = Pattern.compile(".*");
338
339 /**
340 * Constructs a default XStream.
341 * <p>
342 * The instance will use the {@link XppDriver} as default and tries to determine the best
343 * match for the {@link ReflectionProvider} on its own.
344 * </p>
345 *
346 * @throws InitializationException in case of an initialization problem
347 */
348 public XStream() {
349 this(null, (Mapper)null, new XppDriver());
350 }
351
352 /**
353 * Constructs an XStream with a special {@link ReflectionProvider}.
354 * <p>
355 * The instance will use the {@link XppDriver} as default.
356 * </p>
357 *
358 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
359 * matching reflection provider
360 * @throws InitializationException in case of an initialization problem
361 */
362 public XStream(ReflectionProvider reflectionProvider) {
363 this(reflectionProvider, (Mapper)null, new XppDriver());
364 }
365
366 /**
367 * Constructs an XStream with a special {@link HierarchicalStreamDriver}.
368 * <p>
369 * The instance will tries to determine the best match for the {@link ReflectionProvider} on
370 * its own.
371 * </p>
372 *
373 * @param hierarchicalStreamDriver the driver instance
374 * @throws InitializationException in case of an initialization problem
375 */
376 public XStream(HierarchicalStreamDriver hierarchicalStreamDriver) {
377 this(null, (Mapper)null, hierarchicalStreamDriver);
378 }
379
380 /**
381 * Constructs an XStream with a special {@link HierarchicalStreamDriver} and
382 * {@link ReflectionProvider}.
383 *
384 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
385 * matching Provider
386 * @param hierarchicalStreamDriver the driver instance
387 * @throws InitializationException in case of an initialization problem
388 */
389 public XStream(
390 ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) {
391 this(reflectionProvider, (Mapper)null, hierarchicalStreamDriver);
392 }
393
394 /**
395 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
396 * {@link ReflectionProvider} and a prepared {@link Mapper} chain.
397 *
398 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
399 * matching Provider
400 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
401 * chain
402 * @param driver the driver instance
403 * @throws InitializationException in case of an initialization problem
404 * @deprecated As of 1.3, use
405 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)}
406 * instead
407 */
408 public XStream(
409 ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) {
410 this(reflectionProvider, driver, new CompositeClassLoader(), mapper);
411 }
412
413 /**
414 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
415 * {@link ReflectionProvider} and a {@link ClassLoaderReference}.
416 *
417 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
418 * matching Provider
419 * @param driver the driver instance
420 * @param classLoaderReference the reference to the {@link ClassLoader} to use
421 * @throws InitializationException in case of an initialization problem
422 * @since 1.4.5
423 */
424 public XStream(
425 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
426 ClassLoaderReference classLoaderReference) {
427 this(reflectionProvider, driver, classLoaderReference, null);
428 }
429
430 /**
431 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
432 * {@link ReflectionProvider} and the {@link ClassLoader} to use.
433 *
434 * @throws InitializationException in case of an initialization problem
435 * @since 1.3
436 * @deprecated As of 1.4.5 use
437 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)}
438 */
439 public XStream(
440 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
441 ClassLoader classLoader) {
442 this(reflectionProvider, driver, classLoader, null);
443 }
444
445 /**
446 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
447 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the {@link ClassLoader}
448 * to use.
449 *
450 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
451 * matching Provider
452 * @param driver the driver instance
453 * @param classLoader the {@link ClassLoader} to use
454 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
455 * chain
456 * @throws InitializationException in case of an initialization problem
457 * @since 1.3
458 * @deprecated As of 1.4.5 use
459 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper)}
460 */
461 public XStream(
462 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
463 ClassLoader classLoader, Mapper mapper) {
464 this(
465 reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup());
466 }
467
468 /**
469 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
470 * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the
471 * {@link ClassLoaderReference}.
472 * <p>
473 * The {@link ClassLoaderReference} should also be used for the {@link Mapper} chain.
474 * </p>
475 *
476 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
477 * matching Provider
478 * @param driver the driver instance
479 * @param classLoaderReference the reference to the {@link ClassLoader} to use
480 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
481 * chain
482 * @throws InitializationException in case of an initialization problem
483 * @since 1.4.5
484 */
485 public XStream(
486 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
487 ClassLoaderReference classLoaderReference, Mapper mapper) {
488 this(
489 reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup());
490 }
491
492 private XStream(
493 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader,
494 Mapper mapper, final DefaultConverterLookup defaultConverterLookup) {
495 this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() {
496 public Converter lookupConverterForType(Class type) {
497 return defaultConverterLookup.lookupConverterForType(type);
498 }
499 }, new ConverterRegistry() {
500 public void registerConverter(Converter converter, int priority) {
501 defaultConverterLookup.registerConverter(converter, priority);
502 }
503 });
504 }
505
506 /**
507 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
508 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
509 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
510 * {@link ConverterRegistry}.
511 *
512 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
513 * matching Provider
514 * @param driver the driver instance
515 * @param classLoader the {@link ClassLoader} to use
516 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
517 * chain
518 * @param converterLookup the instance that is used to lookup the converters
519 * @param converterRegistry an instance to manage the converter instances
520 * @throws InitializationException in case of an initialization problem
521 * @since 1.3
522 * @deprecated As of 1.4.5 use
523 * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper, ConverterLookup, ConverterRegistry)}
524 */
525 public XStream(
526 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
527 ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup,
528 ConverterRegistry converterRegistry) {
529 this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, converterRegistry);
530 }
531
532 /**
533 * Constructs an XStream with a special {@link HierarchicalStreamDriver},
534 * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the
535 * {@link ClassLoaderReference} and an own {@link ConverterLookup} and
536 * {@link ConverterRegistry}.
537 * <p>
538 * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup
539 * should access the ConverterRegistry if you intent to register {@link Converter} instances
540 * with XStream facade or you are using annotations.
541 * </p>
542 *
543 * @param reflectionProvider the reflection provider to use or <em>null</em> for best
544 * matching Provider
545 * @param driver the driver instance
546 * @param classLoaderReference the reference to the {@link ClassLoader} to use
547 * @param mapper the instance with the {@link Mapper} chain or <em>null</em> for the default
548 * chain
549 * @param converterLookup the instance that is used to lookup the converters
550 * @param converterRegistry an instance to manage the converter instances or <em>null</em>
551 * to prevent any further registry (including annotations)
552 * @throws InitializationException in case of an initialization problem
553 * @since 1.4.5
554 */
555 public XStream(
556 ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver,
557 ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup,
558 ConverterRegistry converterRegistry) {
559 if (reflectionProvider == null) {
560 reflectionProvider = JVM.newReflectionProvider();
561 }
562 this.reflectionProvider = reflectionProvider;
563 this.hierarchicalStreamDriver = driver;
564 this.classLoaderReference = classLoaderReference;
565 this.converterLookup = converterLookup;
566 this.converterRegistry = converterRegistry;
567 this.mapper = mapper == null ? buildMapper() : mapper;
568
569 setupMappers();
570 setupSecurity();
571 setupAliases();
572 setupDefaultImplementations();
573 setupConverters();
574 setupImmutableTypes();
575 setMode(XPATH_RELATIVE_REFERENCES);
576 }
577
578 private Mapper buildMapper() {
579 Mapper mapper = new DefaultMapper(classLoaderReference);
580 if (useXStream11XmlFriendlyMapper()) {
581 mapper = new XStream11XmlFriendlyMapper(mapper);
582 }
583 mapper = new DynamicProxyMapper(mapper);
584 mapper = new PackageAliasingMapper(mapper);
585 mapper = new ClassAliasingMapper(mapper);
586 mapper = new FieldAliasingMapper(mapper);
587 mapper = new AttributeAliasingMapper(mapper);
588 mapper = new SystemAttributeAliasingMapper(mapper);
589 mapper = new ImplicitCollectionMapper(mapper);
590 mapper = new OuterClassMapper(mapper);
591 mapper = new ArrayMapper(mapper);
592 mapper = new DefaultImplementationsMapper(mapper);
593 mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider);
594 if (JVM.is15()) {
595 mapper = buildMapperDynamically(
596 "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class},
597 new Object[]{mapper});
598 }
599 mapper = new LocalConversionMapper(mapper);
600 mapper = new ImmutableTypesMapper(mapper);
601 if (JVM.is18()) {
602 mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class},
603 new Object[]{mapper});
604 }
605 mapper = new SecurityMapper(mapper);
606 if (JVM.is15()) {
607 mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{
608 Mapper.class, ConverterRegistry.class, ConverterLookup.class,
609 ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{
610 mapper, converterRegistry, converterLookup, classLoaderReference,
611 reflectionProvider});
612 }
613 mapper = wrapMapper((MapperWrapper)mapper);
614 mapper = new CachingMapper(mapper);
615 return mapper;
616 }
617
618 private Mapper buildMapperDynamically(String className, Class[] constructorParamTypes,
619 Object[] constructorParamValues) {
620 try {
621 Class type = Class.forName(className, false, classLoaderReference.getReference());
622 Constructor constructor = type.getConstructor(constructorParamTypes);
623 return (Mapper)constructor.newInstance(constructorParamValues);
624 } catch (Exception e) {
625 throw new com.thoughtworks.xstream.InitializationException(
626 "Could not instantiate mapper : " + className, e);
627 } catch (LinkageError e) {
628 throw new com.thoughtworks.xstream.InitializationException(
629 "Could not instantiate mapper : " + className, e);
630 }
631 }
632
633 protected MapperWrapper wrapMapper(MapperWrapper next) {
634 return next;
635 }
636
637 /**
638 * @deprecated As of 1.4.8
639 */
640 protected boolean useXStream11XmlFriendlyMapper() {
641 return false;
642 }
643
644 private void setupMappers() {
645 packageAliasingMapper = (PackageAliasingMapper)this.mapper
646 .lookupMapperOfType(PackageAliasingMapper.class);
647 classAliasingMapper = (ClassAliasingMapper)this.mapper
648 .lookupMapperOfType(ClassAliasingMapper.class);
649 fieldAliasingMapper = (FieldAliasingMapper)this.mapper
650 .lookupMapperOfType(FieldAliasingMapper.class);
651 attributeMapper = (AttributeMapper)this.mapper
652 .lookupMapperOfType(AttributeMapper.class);
653 attributeAliasingMapper = (AttributeAliasingMapper)this.mapper
654 .lookupMapperOfType(AttributeAliasingMapper.class);
655 systemAttributeAliasingMapper = (SystemAttributeAliasingMapper)this.mapper
656 .lookupMapperOfType(SystemAttributeAliasingMapper.class);
657 implicitCollectionMapper = (ImplicitCollectionMapper)this.mapper
658 .lookupMapperOfType(ImplicitCollectionMapper.class);
659 defaultImplementationsMapper = (DefaultImplementationsMapper)this.mapper
660 .lookupMapperOfType(DefaultImplementationsMapper.class);
661 immutableTypesMapper = (ImmutableTypesMapper)this.mapper
662 .lookupMapperOfType(ImmutableTypesMapper.class);
663 localConversionMapper = (LocalConversionMapper)this.mapper
664 .lookupMapperOfType(LocalConversionMapper.class);
665 securityMapper = (SecurityMapper)this.mapper
666 .lookupMapperOfType(SecurityMapper.class);
667 annotationConfiguration = (AnnotationConfiguration)this.mapper
668 .lookupMapperOfType(AnnotationConfiguration.class);
669 }
670
671 protected void setupSecurity() {
672 if (securityMapper == null) {
673 return;
674 }
675
676 addPermission(AnyTypePermission.ANY);
677 }
678
679 protected void setupAliases() {
680 if (classAliasingMapper == null) {
681 return;
682 }
683
684 alias("null", Mapper.Null.class);
685 alias("int", Integer.class);
686 alias("float", Float.class);
687 alias("double", Double.class);
688 alias("long", Long.class);
689 alias("short", Short.class);
690 alias("char", Character.class);
691 alias("byte", Byte.class);
692 alias("boolean", Boolean.class);
693 alias("number", Number.class);
694 alias("object", Object.class);
695 alias("big-int", BigInteger.class);
696 alias("big-decimal", BigDecimal.class);
697
698 alias("string-buffer", StringBuffer.class);
699 alias("string", String.class);
700 alias("java-class", Class.class);
701 alias("method", Method.class);
702 alias("constructor", Constructor.class);
703 alias("field", Field.class);
704 alias("date", Date.class);
705 alias("uri", URI.class);
706 alias("url", URL.class);
707 alias("bit-set", BitSet.class);
708
709 alias("map", Map.class);
710 alias("entry", Map.Entry.class);
711 alias("properties", Properties.class);
712 alias("list", List.class);
713 alias("set", Set.class);
714 alias("sorted-set", SortedSet.class);
715
716 alias("linked-list", LinkedList.class);
717 alias("vector", Vector.class);
718 alias("tree-map", TreeMap.class);
719 alias("tree-set", TreeSet.class);
720 alias("hashtable", Hashtable.class);
721
722 alias("empty-list", Collections.EMPTY_LIST.getClass());
723 alias("empty-map", Collections.EMPTY_MAP.getClass());
724 alias("empty-set", Collections.EMPTY_SET.getClass());
725 alias("singleton-list", Collections.singletonList(this).getClass());
726 alias("singleton-map", Collections.singletonMap(this, null).getClass());
727 alias("singleton-set", Collections.singleton(this).getClass());
728
729 if (JVM.isAWTAvailable()) {
730 // Instantiating these two classes starts the AWT system, which is undesirable.
731 // Calling loadClass ensures a reference to the class is found but they are not
732 // instantiated.
733 alias("awt-color", JVM.loadClassForName("java.awt.Color", false));
734 alias("awt-font", JVM.loadClassForName("java.awt.Font", false));
735 alias("awt-text-attribute", JVM.loadClassForName("java.awt.font.TextAttribute"));
736 }
737
738 if (JVM.isSQLAvailable()) {
739 alias("sql-timestamp", JVM.loadClassForName("java.sql.Timestamp"));
740 alias("sql-time", JVM.loadClassForName("java.sql.Time"));
741 alias("sql-date", JVM.loadClassForName("java.sql.Date"));
742 }
743
744 alias("file", File.class);
745 alias("locale", Locale.class);
746 alias("gregorian-calendar", Calendar.class);
747
748 if (JVM.is14()) {
749 aliasDynamically("auth-subject", "javax.security.auth.Subject");
750 alias("linked-hash-map", JVM.loadClassForName("java.util.LinkedHashMap"));
751 alias("linked-hash-set", JVM.loadClassForName("java.util.LinkedHashSet"));
752 alias("trace", JVM.loadClassForName("java.lang.StackTraceElement"));
753 alias("currency", JVM.loadClassForName("java.util.Currency"));
754 aliasType("charset", JVM.loadClassForName("java.nio.charset.Charset"));
755 }
756
757 if (JVM.is15()) {
758 aliasDynamically("duration", "javax.xml.datatype.Duration");
759 alias("concurrent-hash-map", JVM.loadClassForName("java.util.concurrent.ConcurrentHashMap"));
760 alias("enum-set", JVM.loadClassForName("java.util.EnumSet"));
761 alias("enum-map", JVM.loadClassForName("java.util.EnumMap"));
762 alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder"));
763 alias("uuid", JVM.loadClassForName("java.util.UUID"));
764 }
765 if (JVM.loadClassForName("java.lang.invoke.SerializedLambda") != null) {
766 aliasDynamically("serialized-lambda", "java.lang.invoke.SerializedLambda");
767 }
768 }
769
770 private void aliasDynamically(String alias, String className) {
771 Class type = JVM.loadClassForName(className);
772 if (type != null) {
773 alias(alias, type);
774 }
775 }
776
777 protected void setupDefaultImplementations() {
778 if (defaultImplementationsMapper == null) {
779 return;
780 }
781 addDefaultImplementation(HashMap.class, Map.class);
782 addDefaultImplementation(ArrayList.class, List.class);
783 addDefaultImplementation(HashSet.class, Set.class);
784 addDefaultImplementation(TreeSet.class, SortedSet.class);
785 addDefaultImplementation(GregorianCalendar.class, Calendar.class);
786 }
787
788 protected void setupConverters() {
789 registerConverter(
790 new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW);
791
792 registerConverter(
793 new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW);
794 registerConverter(new ExternalizableConverter(mapper, classLoaderReference), PRIORITY_LOW);
795
796 registerConverter(new NullConverter(), PRIORITY_VERY_HIGH);
797 registerConverter(new IntConverter(), PRIORITY_NORMAL);
798 registerConverter(new FloatConverter(), PRIORITY_NORMAL);
799 registerConverter(new DoubleConverter(), PRIORITY_NORMAL);
800 registerConverter(new LongConverter(), PRIORITY_NORMAL);
801 registerConverter(new ShortConverter(), PRIORITY_NORMAL);
802 registerConverter((Converter)new CharConverter(), PRIORITY_NORMAL);
803 registerConverter(new BooleanConverter(), PRIORITY_NORMAL);
804 registerConverter(new ByteConverter(), PRIORITY_NORMAL);
805
806 registerConverter(new StringConverter(), PRIORITY_NORMAL);
807 registerConverter(new StringBufferConverter(), PRIORITY_NORMAL);
808 registerConverter(new DateConverter(), PRIORITY_NORMAL);
809 registerConverter(new BitSetConverter(), PRIORITY_NORMAL);
810 registerConverter(new URIConverter(), PRIORITY_NORMAL);
811 registerConverter(new URLConverter(), PRIORITY_NORMAL);
812 registerConverter(new BigIntegerConverter(), PRIORITY_NORMAL);
813 registerConverter(new BigDecimalConverter(), PRIORITY_NORMAL);
814
815 registerConverter(new ArrayConverter(mapper), PRIORITY_NORMAL);
816 registerConverter(new CharArrayConverter(), PRIORITY_NORMAL);
817 registerConverter(new CollectionConverter(mapper), PRIORITY_NORMAL);
818 registerConverter(new MapConverter(mapper), PRIORITY_NORMAL);
819 registerConverter(new TreeMapConverter(mapper), PRIORITY_NORMAL);
820 registerConverter(new TreeSetConverter(mapper), PRIORITY_NORMAL);
821 registerConverter(new SingletonCollectionConverter(mapper), PRIORITY_NORMAL);
822 registerConverter(new SingletonMapConverter(mapper), PRIORITY_NORMAL);
823 registerConverter(new PropertiesConverter(), PRIORITY_NORMAL);
824 registerConverter((Converter)new EncodedByteArrayConverter(), PRIORITY_NORMAL);
825
826 registerConverter(new FileConverter(), PRIORITY_NORMAL);
827 if (JVM.isSQLAvailable()) {
828 registerConverter(new SqlTimestampConverter(), PRIORITY_NORMAL);
829 registerConverter(new SqlTimeConverter(), PRIORITY_NORMAL);
830 registerConverter(new SqlDateConverter(), PRIORITY_NORMAL);
831 }
832 registerConverter(
833 new DynamicProxyConverter(mapper, classLoaderReference), PRIORITY_NORMAL);
834 registerConverter(new JavaClassConverter(classLoaderReference), PRIORITY_NORMAL);
835 registerConverter(new JavaMethodConverter(classLoaderReference), PRIORITY_NORMAL);
836 registerConverter(new JavaFieldConverter(classLoaderReference), PRIORITY_NORMAL);
837 if (JVM.isAWTAvailable()) {
838 registerConverter(new FontConverter(mapper), PRIORITY_NORMAL);
839 registerConverter(new ColorConverter(), PRIORITY_NORMAL);
840 registerConverter(new TextAttributeConverter(), PRIORITY_NORMAL);
841 }
842 if (JVM.isSwingAvailable()) {
843 registerConverter(
844 new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL);
845 }
846 registerConverter(new LocaleConverter(), PRIORITY_NORMAL);
847 registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL);
848
849 if (JVM.is14()) {
850 // late bound converters - allows XStream to be compiled on earlier JDKs
851 registerConverterDynamically(
852 "com.thoughtworks.xstream.converters.extended.SubjectConverter",
853 PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper});
854 registerConverterDynamically(
855 "com.thoughtworks.xstream.converters.extended.ThrowableConverter",
856 PRIORITY_NORMAL, new Class[]{ConverterLookup.class},
857 new Object[]{converterLookup});
858 registerConverterDynamically(
859 "com.thoughtworks.xstream.converters.extended.StackTraceElementConverter",
860 PRIORITY_NORMAL, null, null);
861 registerConverterDynamically(
862 "com.thoughtworks.xstream.converters.extended.CurrencyConverter",
863 PRIORITY_NORMAL, null, null);
864 registerConverterDynamically(
865 "com.thoughtworks.xstream.converters.extended.RegexPatternConverter",
866 PRIORITY_NORMAL, null, null);
867 registerConverterDynamically(
868 "com.thoughtworks.xstream.converters.extended.CharsetConverter",
869 PRIORITY_NORMAL, null, null);
870 }
871
872 if (JVM.is15()) {
873 // late bound converters - allows XStream to be compiled on earlier JDKs
874 if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) {
875 registerConverterDynamically(
876 "com.thoughtworks.xstream.converters.extended.DurationConverter",
877 PRIORITY_NORMAL, null, null);
878 }
879 registerConverterDynamically(
880 "com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL,
881 null, null);
882 registerConverterDynamically(
883 "com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL,
884 new Class[]{Mapper.class}, new Object[]{mapper});
885 registerConverterDynamically(
886 "com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL,
887 new Class[]{Mapper.class}, new Object[]{mapper});
888 registerConverterDynamically(
889 "com.thoughtworks.xstream.converters.basic.StringBuilderConverter",
890 PRIORITY_NORMAL, null, null);
891 registerConverterDynamically(
892 "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL,
893 null, null);
894 }
895 if (JVM.is18()) {
896 registerConverterDynamically("com.thoughtworks.xstream.converters.reflection.LambdaConverter",
897 PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class, ClassLoaderReference.class},
898 new Object[]{mapper, reflectionProvider, classLoaderReference});
899 }
900
901 registerConverter(
902 new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL);
903 }
904
905 private void registerConverterDynamically(String className, int priority,
906 Class[] constructorParamTypes, Object[] constructorParamValues) {
907 try {
908 Class type = Class.forName(className, false, classLoaderReference.getReference());
909 Constructor constructor = type.getConstructor(constructorParamTypes);
910 Object instance = constructor.newInstance(constructorParamValues);
911 if (instance instanceof Converter) {
912 registerConverter((Converter)instance, priority);
913 } else if (instance instanceof SingleValueConverter) {
914 registerConverter((SingleValueConverter)instance, priority);
915 }
916 } catch (Exception e) {
917 throw new com.thoughtworks.xstream.InitializationException(
918 "Could not instantiate converter : " + className, e);
919 } catch (LinkageError e) {
920 throw new com.thoughtworks.xstream.InitializationException(
921 "Could not instantiate converter : " + className, e);
922 }
923 }
924
925 protected void setupImmutableTypes() {
926 if (immutableTypesMapper == null) {
927 return;
928 }
929
930 // 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);
947
948 // 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());
961
962 if (JVM.isAWTAvailable()) {
963 addImmutableTypeDynamically("java.awt.font.TextAttribute");
964 }
965
966 if (JVM.is14()) {
967 // 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) {
974 Class type = JVM.loadClassForName(className);
975 if (type != null) {
976 addImmutableType(type);
977 }
978 }
979
980 public void setMarshallingStrategy(MarshallingStrategy marshallingStrategy) {
981 this.marshallingStrategy = marshallingStrategy;
982 }
983
984 /**
985 * Serialize an object to a pretty-printed XML String.
986 *
987 * @throws XStreamException if the object cannot be serialized
988 */
989 public String toXML(Object obj) {
990 Writer writer = new StringWriter();
991 toXML(obj, writer);
992 return writer.toString();
993 }
994
995 /**
996 * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed
997 * afterwards and in case of an exception.
998 *
999 * @throws XStreamException if the object cannot be serialized
1000 */
1001 public void toXML(Object obj, Writer out) {
1002 HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
1003 try {
1004 marshal(obj, writer);
1005 } finally {
1006 writer.flush();
1007 }
1008 }
1009
1010 /**
1011 * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream
1012 * will be flushed afterwards and in case of an exception.
1013 *
1014 * @throws XStreamException if the object cannot be serialized
1015 */
1016 public void toXML(Object obj, OutputStream out) {
1017 HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out);
1018 try {
1019 marshal(obj, writer);
1020 } finally {
1021 writer.flush();
1022 }
1023 }
1024
1025 /**
1026 * Serialize and object to a hierarchical data structure (such as XML).
1027 *
1028 * @throws XStreamException if the object cannot be serialized
1029 */
1030 public void marshal(Object obj, HierarchicalStreamWriter writer) {
1031 marshal(obj, writer, null);
1032 }
1033
1034 /**
1035 * Serialize and object to a hierarchical data structure (such as XML).
1036 *
1037 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1038 * want. If not present, XStream shall create one lazily as needed.
1039 * @throws XStreamException if the object cannot be serialized
1040 */
1041 public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) {
1042 marshallingStrategy.marshal(writer, obj, converterLookup, mapper, dataHolder);
1043 }
1044
1045 /**
1046 * Deserialize an object from an XML String.
1047 *
1048 * @throws XStreamException if the object cannot be deserialized
1049 */
1050 public Object fromXML(String xml) {
1051 return fromXML(new StringReader(xml));
1052 }
1053
1054 /**
1055 * Deserialize an object from an XML Reader.
1056 *
1057 * @throws XStreamException if the object cannot be deserialized
1058 */
1059 public Object fromXML(Reader reader) {
1060 return unmarshal(hierarchicalStreamDriver.createReader(reader), null);
1061 }
1062
1063 /**
1064 * Deserialize an object from an XML InputStream.
1065 *
1066 * @throws XStreamException if the object cannot be deserialized
1067 */
1068 public Object fromXML(InputStream input) {
1069 return unmarshal(hierarchicalStreamDriver.createReader(input), null);
1070 }
1071
1072 /**
1073 * Deserialize an object from a URL.
1074 *
1075 * Depending on the parser implementation, some might take the file path as SystemId to
1076 * resolve additional references.
1077 *
1078 * @throws XStreamException if the object cannot be deserialized
1079 * @since 1.4
1080 */
1081 public Object fromXML(URL url) {
1082 return fromXML(url, null);
1083 }
1084
1085 /**
1086 * Deserialize an object from a file.
1087 *
1088 * Depending on the parser implementation, some might take the file path as SystemId to
1089 * resolve additional references.
1090 *
1091 * @throws XStreamException if the object cannot be deserialized
1092 * @since 1.4
1093 */
1094 public Object fromXML(File file) {
1095 return fromXML(file, null);
1096 }
1097
1098 /**
1099 * Deserialize an object from an XML String, populating the fields of the given root object
1100 * instead of instantiating a new one. Note, that this is a special use case! With the
1101 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1102 * object. Use with care!
1103 *
1104 * @throws XStreamException if the object cannot be deserialized
1105 */
1106 public Object fromXML(String xml, Object root) {
1107 return fromXML(new StringReader(xml), root);
1108 }
1109
1110 /**
1111 * Deserialize an object from an XML Reader, populating the fields of the given root object
1112 * instead of instantiating a new one. Note, that this is a special use case! With the
1113 * ReflectionConverter XStream will write directly into the raw memory area of the existing
1114 * object. Use with care!
1115 *
1116 * @throws XStreamException if the object cannot be deserialized
1117 */
1118 public Object fromXML(Reader xml, Object root) {
1119 return unmarshal(hierarchicalStreamDriver.createReader(xml), root);
1120 }
1121
1122 /**
1123 * Deserialize an object from a URL, populating the fields of the given root
1124 * object instead of instantiating a new one. Note, that this is a special use case! With
1125 * the ReflectionConverter XStream will write directly into the raw memory area of the
1126 * existing object. Use with care!
1127 *
1128 * Depending on the parser implementation, some might take the file path as SystemId to
1129 * resolve additional references.
1130 *
1131 * @throws XStreamException if the object cannot be deserialized
1132 * @since 1.4
1133 */
1134 public Object fromXML(URL url, Object root) {
1135 return unmarshal(hierarchicalStreamDriver.createReader(url), root);
1136 }
1137
1138 /**
1139 * Deserialize an object from a file, populating the fields of the given root
1140 * object instead of instantiating a new one. Note, that this is a special use case! With
1141 * the ReflectionConverter XStream will write directly into the raw memory area of the
1142 * existing object. Use with care!
1143 *
1144 * Depending on the parser implementation, some might take the file path as SystemId to
1145 * resolve additional references.
1146 *
1147 * @throws XStreamException if the object cannot be deserialized
1148 * @since 1.4
1149 */
1150 public Object fromXML(File file, Object root) {
1151 HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file);
1152 try {
1153 return unmarshal(reader, root);
1154 } finally {
1155 reader.close();
1156 }
1157 }
1158
1159 /**
1160 * Deserialize an object from an XML InputStream, populating the fields of the given root
1161 * object instead of instantiating a new one. Note, that this is a special use case! With
1162 * the ReflectionConverter XStream will write directly into the raw memory area of the
1163 * existing object. Use with care!
1164 *
1165 * @throws XStreamException if the object cannot be deserialized
1166 */
1167 public Object fromXML(InputStream input, Object root) {
1168 return unmarshal(hierarchicalStreamDriver.createReader(input), root);
1169 }
1170
1171 /**
1172 * Deserialize an object from a hierarchical data structure (such as XML).
1173 *
1174 * @throws XStreamException if the object cannot be deserialized
1175 */
1176 public Object unmarshal(HierarchicalStreamReader reader) {
1177 return unmarshal(reader, null, null);
1178 }
1179
1180 /**
1181 * Deserialize an object from a hierarchical data structure (such as XML), populating the
1182 * fields of the given root object instead of instantiating a new one. Note, that this is a
1183 * special use case! With the ReflectionConverter XStream will write directly into the raw
1184 * memory area of the existing object. Use with care!
1185 *
1186 * @throws XStreamException if the object cannot be deserialized
1187 */
1188 public Object unmarshal(HierarchicalStreamReader reader, Object root) {
1189 return unmarshal(reader, root, null);
1190 }
1191
1192 /**
1193 * Deserialize an object from a hierarchical data structure (such as XML).
1194 *
1195 * @param root If present, the passed in object will have its fields populated, as opposed
1196 * to XStream creating a new instance. Note, that this is a special use case!
1197 * With the ReflectionConverter XStream will write directly into the raw memory
1198 * area of the existing object. Use with care!
1199 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
1200 * want. If not present, XStream shall create one lazily as needed.
1201 * @throws XStreamException if the object cannot be deserialized
1202 */
1203 public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
1204 try {
1205 return marshallingStrategy.unmarshal(
1206 root, reader, dataHolder, converterLookup, mapper);
1207
1208 } catch (ConversionException e) {
1209 Package pkg = getClass().getPackage();
1210 String version = pkg != null ? pkg.getImplementationVersion() : null;
1211 e.add("version", version != null ? version : "not available");
1212 throw e;
1213 }
1214 }
1215
1216 /**
1217 * Alias a Class to a shorter name to be used in XML elements.
1218 *
1219 * @param name Short name
1220 * @param type Type to be aliased
1221 * @throws InitializationException if no {@link ClassAliasingMapper} is available
1222 */
1223 public void alias(String name, Class type) {
1224 if (classAliasingMapper == null) {
1225 throw new com.thoughtworks.xstream.InitializationException("No "
1226 + ClassAliasingMapper.class.getName()
1227 + " available");
1228 }
1229 classAliasingMapper.addClassAlias(name, type);
1230 }
1231
1232 /**
1233 * Alias a type to a shorter name to be used in XML elements. Any class that is assignable
1234 * to this type will be aliased to the same name.
1235 *
1236 * @param name Short name
1237 * @param type Type to be aliased
1238 * @since 1.2
1239 * @throws InitializationException if no {@link ClassAliasingMapper} is available
1240 */
1241 public void aliasType(String name, Class type) {
1242 if (classAliasingMapper == null) {
1243 throw new com.thoughtworks.xstream.InitializationException("No "
1244 + ClassAliasingMapper.class.getName()
1245 + " available");
1246 }
1247 classAliasingMapper.addTypeAlias(name, type);
1248 }
1249
1250 /**
1251 * Alias a Class to a shorter name to be used in XML elements.
1252 *
1253 * @param name Short name
1254 * @param type Type to be aliased
1255 * @param defaultImplementation Default implementation of type to use if no other specified.
1256 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1257 * {@link ClassAliasingMapper} is available
1258 */
1259 public void alias(String name, Class type, Class defaultImplementation) {
1260 alias(name, type);
1261 addDefaultImplementation(defaultImplementation, type);
1262 }
1263
1264 /**
1265 * Alias a package to a shorter name to be used in XML elements.
1266 *
1267 * @param name Short name
1268 * @param pkgName package to be aliased
1269 * @throws InitializationException if no {@link DefaultImplementationsMapper} or no
1270 * {@link PackageAliasingMapper} is available
1271 * @since 1.3.1
1272 */
1273 public void aliasPackage(String name, String pkgName) {
1274 if (packageAliasingMapper == null) {
1275 throw new com.thoughtworks.xstream.InitializationException("No "
1276 + PackageAliasingMapper.class.getName()
1277 + " available");
1278 }
1279 packageAliasingMapper.addPackageAlias(name, pkgName);
1280 }
1281
1282 /**
1283 * Create an alias for a field name.
1284 *
1285 * @param alias the alias itself
1286 * @param definedIn the type that declares the field
1287 * @param fieldName the name of the field
1288 * @throws InitializationException if no {@link FieldAliasingMapper} is available
1289 */
1290 public void aliasField(String alias, Class definedIn, String fieldName) {
1291 if (fieldAliasingMapper == null) {
1292 throw new com.thoughtworks.xstream.InitializationException("No "
1293 + FieldAliasingMapper.class.getName()
1294 + " available");
1295 }
1296 fieldAliasingMapper.addFieldAlias(alias, definedIn, fieldName);
1297 }
1298
1299 /**
1300 * Create an alias for an attribute
1301 *
1302 * @param alias the alias itself
1303 * @param attributeName the name of the attribute
1304 * @throws InitializationException if no {@link AttributeAliasingMapper} is available
1305 */
1306 public void aliasAttribute(String alias, String attributeName) {
1307 if (attributeAliasingMapper == null) {
1308 throw new com.thoughtworks.xstream.InitializationException("No "
1309 + AttributeAliasingMapper.class.getName()
1310 + " available");
1311 }
1312 attributeAliasingMapper.addAliasFor(attributeName, alias);
1313 }
1314
1315 /**
1316 * Create an alias for a system attribute. XStream will not write a system attribute if its
1317 * alias is set to <code>null</code>. However, this is not reversible, i.e. deserialization
1318 * of the result is likely to fail afterwards and will not produce an object equal to the
1319 * originally written one.
1320 *
1321 * @param alias the alias itself (may be <code>null</code>)
1322 * @param systemAttributeName the name of the system attribute
1323 * @throws InitializationException if no {@link SystemAttributeAliasingMapper} is available
1324 * @since 1.3.1
1325 */
1326 public void aliasSystemAttribute(String alias, String systemAttributeName) {
1327 if (systemAttributeAliasingMapper == null) {
1328 throw new com.thoughtworks.xstream.InitializationException("No "
1329 + SystemAttributeAliasingMapper.class.getName()
1330 + " available");
1331 }
1332 systemAttributeAliasingMapper.addAliasFor(systemAttributeName, alias);
1333 }
1334
1335 /**
1336 * Create an alias for an attribute.
1337 *
1338 * @param definedIn the type where the attribute is defined
1339 * @param attributeName the name of the attribute
1340 * @param alias the alias itself
1341 * @throws InitializationException if no {@link AttributeAliasingMapper} is available
1342 * @since 1.2.2
1343 */
1344 public void aliasAttribute(Class definedIn, String attributeName, String alias) {
1345 aliasField(alias, definedIn, attributeName);
1346 useAttributeFor(definedIn, attributeName);
1347 }
1348
1349 /**
1350 * Use an attribute for a field or a specific type.
1351 *
1352 * @param fieldName the name of the field
1353 * @param type the Class of the type to be rendered as XML attribute
1354 * @throws InitializationException if no {@link AttributeMapper} is available
1355 * @since 1.2
1356 */
1357 public void useAttributeFor(String fieldName, Class type) {
1358 if (attributeMapper == null) {
1359 throw new com.thoughtworks.xstream.InitializationException("No "
1360 + AttributeMapper.class.getName()
1361 + " available");
1362 }
1363 attributeMapper.addAttributeFor(fieldName, type);
1364 }
1365
1366 /**
1367 * Use an attribute for a field declared in a specific type.
1368 *
1369 * @param fieldName the name of the field
1370 * @param definedIn the Class containing such field
1371 * @throws InitializationException if no {@link AttributeMapper} is available
1372 * @since 1.2.2
1373 */
1374 public void useAttributeFor(Class definedIn, String fieldName) {
1375 if (attributeMapper == null) {
1376 throw new com.thoughtworks.xstream.InitializationException("No "
1377 + AttributeMapper.class.getName()
1378 + " available");
1379 }
1380 attributeMapper.addAttributeFor(definedIn, fieldName);
1381 }
1382
1383 /**
1384 * Use an attribute for an arbitrary type.
1385 *
1386 * @param type the Class of the type to be rendered as XML attribute
1387 * @throws InitializationException if no {@link AttributeMapper} is available
1388 * @since 1.2
1389 */
1390 public void useAttributeFor(Class type) {
1391 if (attributeMapper == null) {
1392 throw new com.thoughtworks.xstream.InitializationException("No "
1393 + AttributeMapper.class.getName()
1394 + " available");
1395 }
1396 attributeMapper.addAttributeFor(type);
1397 }
1398
1399 /**
1400 * Associate a default implementation of a class with an object. Whenever XStream encounters
1401 * an instance of this type, it will use the default implementation instead. For example,
1402 * java.util.ArrayList is the default implementation of java.util.List.
1403 *
1404 * @param defaultImplementation
1405 * @param ofType
1406 * @throws InitializationException if no {@link DefaultImplementationsMapper} is available
1407 */
1408 public void addDefaultImplementation(Class defaultImplementation, Class ofType) {
1409 if (defaultImplementationsMapper == null) {
1410 throw new com.thoughtworks.xstream.InitializationException("No "
1411 + DefaultImplementationsMapper.class.getName()
1412 + " available");
1413 }
1414 defaultImplementationsMapper.addDefaultImplementation(defaultImplementation, ofType);
1415 }
1416
1417 /**
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 *
1421 * @throws InitializationException if no {@link ImmutableTypesMapper} is available
1422 */
1423 public void addImmutableType(Class type) {
1424 if (immutableTypesMapper == null) {
1425 throw new com.thoughtworks.xstream.InitializationException("No "
1426 + ImmutableTypesMapper.class.getName()
1427 + " available");
1428 }
1429 immutableTypesMapper.addImmutableType(type);
1430 }
1431
1432 public void registerConverter(Converter converter) {
1433 registerConverter(converter, PRIORITY_NORMAL);
1434 }
1435
1436 public void registerConverter(Converter converter, int priority) {
1437 if (converterRegistry != null) {
1438 converterRegistry.registerConverter(converter, priority);
1439 }
1440 }
1441
1442 public void registerConverter(SingleValueConverter converter) {
1443 registerConverter(converter, PRIORITY_NORMAL);
1444 }
1445
1446 public void registerConverter(SingleValueConverter converter, int priority) {
1447 if (converterRegistry != null) {
1448 converterRegistry.registerConverter(
1449 new SingleValueConverterWrapper(converter), priority);
1450 }
1451 }
1452
1453 /**
1454 * Register a local {@link Converter} for a field.
1455 *
1456 * @param definedIn the class type the field is defined in
1457 * @param fieldName the field name
1458 * @param converter the converter to use
1459 * @since 1.3
1460 */
1461 public void registerLocalConverter(Class definedIn, String fieldName, Converter converter) {
1462 if (localConversionMapper == null) {
1463 throw new com.thoughtworks.xstream.InitializationException("No "
1464 + LocalConversionMapper.class.getName()
1465 + " available");
1466 }
1467 localConversionMapper.registerLocalConverter(definedIn, fieldName, converter);
1468 }
1469
1470 /**
1471 * Register a local {@link SingleValueConverter} for a field.
1472 *
1473 * @param definedIn the class type the field is defined in
1474 * @param fieldName the field name
1475 * @param converter the converter to use
1476 * @since 1.3
1477 */
1478 public void registerLocalConverter(Class definedIn, String fieldName,
1479 SingleValueConverter converter) {
1480 registerLocalConverter(
1481 definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter));
1482 }
1483
1484 /**
1485 * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper
1486 * MapperWrappers}.
1487 *
1488 * @return the mapper
1489 * @since 1.2
1490 */
1491 public Mapper getMapper() {
1492 return mapper;
1493 }
1494
1495 /**
1496 * Retrieve the {@link ReflectionProvider} in use.
1497 *
1498 * @return the mapper
1499 * @since 1.2.1
1500 */
1501 public ReflectionProvider getReflectionProvider() {
1502 return reflectionProvider;
1503 }
1504
1505 public ConverterLookup getConverterLookup() {
1506 return converterLookup;
1507 }
1508
1509 /**
1510 * Change mode for dealing with duplicate references. Valid values are
1511 * <code>XPATH_ABSOLUTE_REFERENCES</code>, <code>XPATH_RELATIVE_REFERENCES</code>,
1512 * <code>XStream.ID_REFERENCES</code> and <code>XStream.NO_REFERENCES</code>.
1513 *
1514 * @throws IllegalArgumentException if the mode is not one of the declared types
1515 * @see #XPATH_ABSOLUTE_REFERENCES
1516 * @see #XPATH_RELATIVE_REFERENCES
1517 * @see #ID_REFERENCES
1518 * @see #NO_REFERENCES
1519 */
1520 public void setMode(int mode) {
1521 switch (mode) {
1522 case NO_REFERENCES:
1523 setMarshallingStrategy(new TreeMarshallingStrategy());
1524 break;
1525 case ID_REFERENCES:
1526 setMarshallingStrategy(new ReferenceByIdMarshallingStrategy());
1527 break;
1528 case XPATH_RELATIVE_REFERENCES:
1529 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1530 ReferenceByXPathMarshallingStrategy.RELATIVE));
1531 break;
1532 case XPATH_ABSOLUTE_REFERENCES:
1533 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1534 ReferenceByXPathMarshallingStrategy.ABSOLUTE));
1535 break;
1536 case SINGLE_NODE_XPATH_RELATIVE_REFERENCES:
1537 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1538 ReferenceByXPathMarshallingStrategy.RELATIVE
1539 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
1540 break;
1541 case SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES:
1542 setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(
1543 ReferenceByXPathMarshallingStrategy.ABSOLUTE
1544 | ReferenceByXPathMarshallingStrategy.SINGLE_NODE));
1545 break;
1546 default:
1547 throw new IllegalArgumentException("Unknown mode : " + mode);
1548 }
1549 }
1550
1551 /**
1552 * Adds a default implicit collection which is used for any unmapped XML tag.
1553 *
1554 * @param ownerType class owning the implicit collection
1555 * @param fieldName name of the field in the ownerType. This field must be a concrete
1556 * collection type or matching the default implementation type of the collection
1557 * type.
1558 */
1559 public void addImplicitCollection(Class ownerType, String fieldName) {
1560 addImplicitCollection(ownerType, fieldName, null, null);
1561 }
1562
1563 /**
1564 * Adds implicit collection which is used for all items of the given itemType.
1565 *
1566 * @param ownerType class owning the implicit collection
1567 * @param fieldName name of the field in the ownerType. This field must be a concrete
1568 * collection type or matching the default implementation type of the collection
1569 * type.
1570 * @param itemType type of the items to be part of this collection
1571 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
1572 */
1573 public void addImplicitCollection(Class ownerType, String fieldName, Class itemType) {
1574 addImplicitCollection(ownerType, fieldName, null, itemType);
1575 }
1576
1577 /**
1578 * Adds implicit collection which is used for all items of the given element name defined by
1579 * itemFieldName.
1580 *
1581 * @param ownerType class owning the implicit collection
1582 * @param fieldName name of the field in the ownerType. This field must be a concrete
1583 * collection type or matching the default implementation type of the collection
1584 * type.
1585 * @param itemFieldName element name of the implicit collection
1586 * @param itemType item type to be aliases be the itemFieldName
1587 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
1588 */
1589 public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName,
1590 Class itemType) {
1591 addImplicitMap(ownerType, fieldName, itemFieldName, itemType, null);
1592 }
1593
1594 /**
1595 * Adds an implicit array.
1596 *
1597 * @param ownerType class owning the implicit array
1598 * @param fieldName name of the array field
1599 * @since 1.4
1600 */
1601 public void addImplicitArray(Class ownerType, String fieldName) {
1602 addImplicitCollection(ownerType, fieldName);
1603 }
1604
1605 /**
1606 * Adds an implicit array which is used for all items of the given itemType when the array
1607 * type matches.
1608 *
1609 * @param ownerType class owning the implicit array
1610 * @param fieldName name of the array field in the ownerType
1611 * @param itemType type of the items to be part of this array
1612 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the
1613 * array type does not match the itemType
1614 * @since 1.4
1615 */
1616 public void addImplicitArray(Class ownerType, String fieldName, Class itemType) {
1617 addImplicitCollection(ownerType, fieldName, itemType);
1618 }
1619
1620 /**
1621 * Adds an implicit array which is used for all items of the given element name defined by
1622 * itemName.
1623 *
1624 * @param ownerType class owning the implicit array
1625 * @param fieldName name of the array field in the ownerType
1626 * @param itemName alias name of the items
1627 * @throws InitializationException if no {@link ImplicitCollectionMapper} is available
1628 * @since 1.4
1629 */
1630 public void addImplicitArray(Class ownerType, String fieldName, String itemName) {
1631 addImplicitCollection(ownerType, fieldName, itemName, null);
1632 }
1633
1634 /**
1635 * Adds an implicit map.
1636 *
1637 * @param ownerType class owning the implicit map
1638 * @param fieldName name of the field in the ownerType. This field must be a concrete
1639 * map type or matching the default implementation type of the map
1640 * type.
1641 * @param itemType type of the items to be part of this map as value
1642 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1643 * @since 1.4
1644 */
1645 public void addImplicitMap(Class ownerType, String fieldName, Class itemType, String keyFieldName) {
1646 addImplicitMap(ownerType, fieldName, null, itemType, keyFieldName);
1647 }
1648
1649 /**
1650 * Adds an implicit map.
1651 *
1652 * @param ownerType class owning the implicit map
1653 * @param fieldName name of the field in the ownerType. This field must be a concrete
1654 * map type or matching the default implementation type of the map
1655 * type.
1656 * @param itemName alias name of the items
1657 * @param itemType type of the items to be part of this map as value
1658 * @param keyFieldName the name of the field of the itemType that is used for the key in the map
1659 * @since 1.4
1660 */
1661 public void addImplicitMap(Class ownerType, String fieldName, String itemName,
1662 Class itemType, String keyFieldName) {
1663 if (implicitCollectionMapper == null) {
1664 throw new com.thoughtworks.xstream.InitializationException("No "
1665 + ImplicitCollectionMapper.class.getName()
1666 + " available");
1667 }
1668 implicitCollectionMapper.add(ownerType, fieldName, itemName, itemType, keyFieldName);
1669 }
1670
1671 /**
1672 * Create a DataHolder that can be used to pass data to the converters. The DataHolder is
1673 * provided with a call to {@link #marshal(Object, HierarchicalStreamWriter, DataHolder)} or
1674 * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)}.
1675 *
1676 * @return a new {@link DataHolder}
1677 */
1678 public DataHolder newDataHolder() {
1679 return new MapBackedDataHolder();
1680 }
1681
1682 /**
1683 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1684 * XStream.
1685 * <p>
1686 * To change the name of the root element (from &lt;object-stream&gt;), use
1687 * {@link #createObjectOutputStream(java.io.Writer, String)}.
1688 * </p>
1689 *
1690 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1691 * String)
1692 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1693 * @since 1.0.3
1694 */
1695 public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException {
1696 return createObjectOutputStream(
1697 hierarchicalStreamDriver.createWriter(writer), "object-stream");
1698 }
1699
1700 /**
1701 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1702 * XStream.
1703 * <p>
1704 * To change the name of the root element (from &lt;object-stream&gt;), use
1705 * {@link #createObjectOutputStream(java.io.Writer, String)}.
1706 * </p>
1707 *
1708 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1709 * String)
1710 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1711 * @since 1.0.3
1712 */
1713 public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer)
1714 throws IOException {
1715 return createObjectOutputStream(writer, "object-stream");
1716 }
1717
1718 /**
1719 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1720 * XStream.
1721 *
1722 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1723 * String)
1724 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1725 * @since 1.0.3
1726 */
1727 public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName)
1728 throws IOException {
1729 return createObjectOutputStream(
1730 hierarchicalStreamDriver.createWriter(writer), rootNodeName);
1731 }
1732
1733 /**
1734 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
1735 * using XStream.
1736 * <p>
1737 * To change the name of the root element (from &lt;object-stream&gt;), use
1738 * {@link #createObjectOutputStream(java.io.Writer, String)}.
1739 * </p>
1740 *
1741 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1742 * String)
1743 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1744 * @since 1.3
1745 */
1746 public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException {
1747 return createObjectOutputStream(
1748 hierarchicalStreamDriver.createWriter(out), "object-stream");
1749 }
1750
1751 /**
1752 * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream
1753 * using XStream.
1754 *
1755 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1756 * String)
1757 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1758 * @since 1.3
1759 */
1760 public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName)
1761 throws IOException {
1762 return createObjectOutputStream(
1763 hierarchicalStreamDriver.createWriter(out), rootNodeName);
1764 }
1765
1766 /**
1767 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using
1768 * XStream.
1769 * <p>
1770 * Because an ObjectOutputStream can contain multiple items and XML only allows a single
1771 * root node, the stream must be written inside an enclosing node.
1772 * </p>
1773 * <p>
1774 * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will
1775 * be incomplete.
1776 * </p>
1777 * <h3>Example</h3>
1778 *
1779 * <pre>
1780 * ObjectOutputStream out = xstream.createObjectOutputStream(aWriter, &quot;things&quot;);
1781 * out.writeInt(123);
1782 * out.writeObject(&quot;Hello&quot;);
1783 * out.writeObject(someObject)
1784 * out.close();
1785 * </pre>
1786 *
1787 * @param writer The writer to serialize the objects to.
1788 * @param rootNodeName The name of the root node enclosing the stream of objects.
1789 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1790 * @since 1.0.3
1791 */
1792 public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer,
1793 String rootNodeName) throws IOException {
1794 final StatefulWriter statefulWriter = new StatefulWriter(writer);
1795 statefulWriter.startNode(rootNodeName, null);
1796 return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
1797 public void writeToStream(Object object) {
1798 marshal(object, statefulWriter);
1799 }
1800
1801 public void writeFieldsToStream(Map fields) throws NotActiveException {
1802 throw new NotActiveException("not in call to writeObject");
1803 }
1804
1805 public void defaultWriteObject() throws NotActiveException {
1806 throw new NotActiveException("not in call to writeObject");
1807 }
1808
1809 public void flush() {
1810 statefulWriter.flush();
1811 }
1812
1813 public void close() {
1814 if (statefulWriter.state() != StatefulWriter.STATE_CLOSED) {
1815 statefulWriter.endNode();
1816 statefulWriter.close();
1817 }
1818 }
1819 });
1820 }
1821
1822 /**
1823 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using
1824 * XStream.
1825 *
1826 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1827 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1828 * String)
1829 * @since 1.0.3
1830 */
1831 public ObjectInputStream createObjectInputStream(Reader xmlReader) throws IOException {
1832 return createObjectInputStream(hierarchicalStreamDriver.createReader(xmlReader));
1833 }
1834
1835 /**
1836 * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream
1837 * using XStream.
1838 *
1839 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
1840 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1841 * String)
1842 * @since 1.3
1843 */
1844 public ObjectInputStream createObjectInputStream(InputStream in) throws IOException {
1845 return createObjectInputStream(hierarchicalStreamDriver.createReader(in));
1846 }
1847
1848 /**
1849 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using
1850 * XStream. <h3>Example</h3>
1851 *
1852 * <pre>
1853 * ObjectInputStream in = xstream.createObjectOutputStream(aReader);
1854 * int a = out.readInt();
1855 * Object b = out.readObject();
1856 * Object c = out.readObject();
1857 * </pre>
1858 *
1859 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter,
1860 * String)
1861 * @since 1.0.3
1862 */
1863 public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader)
1864 throws IOException {
1865 return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() {
1866 public Object readFromStream() throws EOFException {
1867 if (!reader.hasMoreChildren()) {
1868 throw new EOFException();
1869 }
1870 reader.moveDown();
1871 Object result = unmarshal(reader);
1872 reader.moveUp();
1873 return result;
1874 }
1875
1876 public Map readFieldsFromStream() throws IOException {
1877 throw new NotActiveException("not in call to readObject");
1878 }
1879
1880 public void defaultReadObject() throws NotActiveException {
1881 throw new NotActiveException("not in call to readObject");
1882 }
1883
1884 public void registerValidation(ObjectInputValidation validation, int priority)
1885 throws NotActiveException {
1886 throw new NotActiveException("stream inactive");
1887 }
1888
1889 public void close() {
1890 reader.close();
1891 }
1892 }, classLoaderReference);
1893 }
1894
1895 /**
1896 * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will
1897 * register for all kind of classes and types of the current JDK, but not for any 3rd party
1898 * type. To ensure that all other types are loaded with your class loader, you should call
1899 * this method as early as possible - or consider to provide the class loader directly in
1900 * the constructor.
1901 *
1902 * @since 1.1.1
1903 */
1904 public void setClassLoader(ClassLoader classLoader) {
1905 classLoaderReference.setReference(classLoader);
1906 }
1907
1908 /**
1909 * Retrieve the ClassLoader XStream uses to load classes.
1910 *
1911 * @since 1.1.1
1912 */
1913 public ClassLoader getClassLoader() {
1914 return classLoaderReference.getReference();
1915 }
1916
1917 /**
1918 * Retrieve the reference to this instance' ClassLoader. Use this reference for other
1919 * XStream components (like converters) to ensure that they will use a changed ClassLoader
1920 * instance automatically.
1921 *
1922 * @return the reference
1923 * @since 1.4.5
1924 */
1925 public ClassLoaderReference getClassLoaderReference() {
1926 return classLoaderReference;
1927 }
1928
1929 /**
1930 * Prevents a field from being serialized. To omit a field you must always provide the
1931 * declaring type and not necessarily the type that is converted.
1932 *
1933 * @since 1.1.3
1934 * @throws InitializationException if no {@link FieldAliasingMapper} is available
1935 */
1936 public void omitField(Class definedIn, String fieldName) {
1937 if (fieldAliasingMapper == null) {
1938 throw new com.thoughtworks.xstream.InitializationException("No "
1939 + FieldAliasingMapper.class.getName()
1940 + " available");
1941 }
1942 fieldAliasingMapper.omitField(definedIn, fieldName);
1943 }
1944
1945 /**
1946 * Ignore all unknown elements.
1947 *
1948 * @since 1.4.5
1949 */
1950 public void ignoreUnknownElements() {
1951 ignoreUnknownElements(IGNORE_ALL);
1952 }
1953
1954 /**
1955 * Add pattern for unknown element names to ignore.
1956 *
1957 * @param pattern the name pattern as regular expression
1958 * @since 1.4.5
1959 */
1960 public void ignoreUnknownElements(String pattern) {
1961 ignoreUnknownElements(Pattern.compile(pattern));
1962 }
1963
1964 /**
1965 * Add pattern for unknown element names to ignore.
1966 *
1967 * @param pattern the name pattern as regular expression
1968 * @since 1.4.5
1969 */
1970 public void ignoreUnknownElements(final Pattern pattern) {
1971 if (fieldAliasingMapper == null) {
1972 throw new com.thoughtworks.xstream.InitializationException("No "
1973 + FieldAliasingMapper.class.getName()
1974 + " available");
1975 }
1976 fieldAliasingMapper.addFieldsToIgnore(pattern);
1977 }
1978
1979 /**
1980 * Process the annotations of the given types and configure the XStream.
1981 *
1982 * @param types the types with XStream annotations
1983 * @since 1.3
1984 */
1985 public void processAnnotations(final Class[] types) {
1986 if (annotationConfiguration == null) {
1987 throw new com.thoughtworks.xstream.InitializationException("No "
1988 + ANNOTATION_MAPPER_TYPE
1989 + " available");
1990 }
1991 annotationConfiguration.processAnnotations(types);
1992 }
1993
1994 /**
1995 * Process the annotations of the given type and configure the XStream. A call of this
1996 * method will automatically turn the auto-detection mode for annotations off.
1997 *
1998 * @param type the type with XStream annotations
1999 * @since 1.3
2000 */
2001 public void processAnnotations(final Class type) {
2002 processAnnotations(new Class[]{type});
2003 }
2004
2005 /**
2006 * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies
2007 * that the XStream is configured while it is processing the XML steams. This is a potential
2008 * concurrency problem. Also is it technically not possible to detect all class aliases at
2009 * deserialization. You have been warned!
2010 *
2011 * @param mode <code>true</code> if annotations are auto-detected
2012 * @since 1.3
2013 */
2014 public void autodetectAnnotations(boolean mode) {
2015 if (annotationConfiguration != null) {
2016 annotationConfiguration.autodetectAnnotations(mode);
2017 }
2018 }
2019
2020 /**
2021 * Add a new security permission.
2022 *
2023 * <p>
2024 * Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
2025 * {@link AnyTypePermission} will implicitly wipe any existing permission.
2026 * </p>
2027 *
2028 * @param permission the permission to add
2029 * @since 1.4.7
2030 */
2031 public void addPermission(TypePermission permission) {
2032 if (securityMapper != null) {
2033 securityMapper.addPermission(permission);
2034 }
2035 }
2036
2037 /**
2038 * Add security permission for explicit types by name.
2039 *
2040 * @param names the type names to allow
2041 * @since 1.4.7
2042 */
2043 public void allowTypes(String[] names) {
2044 addPermission(new ExplicitTypePermission(names));
2045 }
2046
2047 /**
2048 * Add security permission for explicit types.
2049 *
2050 * @param types the types to allow
2051 * @since 1.4.7
2052 */
2053 public void allowTypes(Class[] types) {
2054 addPermission(new ExplicitTypePermission(types));
2055 }
2056
2057 /**
2058 * Add security permission for a type hierarchy.
2059 *
2060 * @param type the base type to allow
2061 * @since 1.4.7
2062 */
2063 public void allowTypeHierarchy(Class type) {
2064 addPermission(new TypeHierarchyPermission(type));
2065 }
2066
2067 /**
2068 * Add security permission for types matching one of the specified regular expressions.
2069 *
2070 * @param regexps the regular expressions to allow type names
2071 * @since 1.4.7
2072 */
2073 public void allowTypesByRegExp(String[] regexps) {
2074 addPermission(new RegExpTypePermission(regexps));
2075 }
2076
2077 /**
2078 * Add security permission for types matching one of the specified regular expressions.
2079 *
2080 * @param regexps the regular expressions to allow type names
2081 * @since 1.4.7
2082 */
2083 public void allowTypesByRegExp(Pattern[] regexps) {
2084 addPermission(new RegExpTypePermission(regexps));
2085 }
2086
2087 /**
2088 * Add security permission for types matching one of the specified wildcard patterns.
2089 * <p>
2090 * Supported are patterns with path expressions using dot as separator:
2091 * </p>
2092 * <ul>
2093 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2094 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2095 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2096 * </ul>
2097 *
2098 * @param patterns the patterns to allow type names
2099 * @since 1.4.7
2100 */
2101 public void allowTypesByWildcard(String[] patterns) {
2102 addPermission(new WildcardTypePermission(patterns));
2103 }
2104
2105 /**
2106 * Add security permission denying another one.
2107 *
2108 * @param permission the permission to deny
2109 * @since 1.4.7
2110 */
2111 public void denyPermission(TypePermission permission) {
2112 addPermission(new NoPermission(permission));
2113 }
2114
2115 /**
2116 * Add security permission forbidding explicit types by name.
2117 *
2118 * @param names the type names to forbid
2119 * @since 1.4.7
2120 */
2121 public void denyTypes(String[] names) {
2122 denyPermission(new ExplicitTypePermission(names));
2123 }
2124
2125 /**
2126 * Add security permission forbidding explicit types.
2127 *
2128 * @param types the types to forbid
2129 * @since 1.4.7
2130 */
2131 public void denyTypes(Class[] types) {
2132 denyPermission(new ExplicitTypePermission(types));
2133 }
2134
2135 /**
2136 * Add security permission forbidding a type hierarchy.
2137 *
2138 * @param type the base type to forbid
2139 * @since 1.4.7
2140 */
2141 public void denyTypeHierarchy(Class type) {
2142 denyPermission(new TypeHierarchyPermission(type));
2143 }
2144
2145 /**
2146 * Add security permission forbidding types matching one of the specified regular expressions.
2147 *
2148 * @param regexps the regular expressions to forbid type names
2149 * @since 1.4.7
2150 */
2151 public void denyTypesByRegExp(String[] regexps) {
2152 denyPermission(new RegExpTypePermission(regexps));
2153 }
2154
2155 /**
2156 * Add security permission forbidding types matching one of the specified regular expressions.
2157 *
2158 * @param regexps the regular expressions to forbid type names
2159 * @since 1.4.7
2160 */
2161 public void denyTypesByRegExp(Pattern[] regexps) {
2162 denyPermission(new RegExpTypePermission(regexps));
2163 }
2164
2165 /**
2166 * Add security permission forbidding types matching one of the specified wildcard patterns.
2167 * <p>
2168 * Supported are patterns with path expressions using dot as separator:
2169 * </p>
2170 * <ul>
2171 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
2172 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
2173 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
2174 * </ul>
2175 *
2176 * @param patterns the patterns to forbid names
2177 * @since 1.4.7
2178 */
2179 public void denyTypesByWildcard(String[] patterns) {
2180 denyPermission(new WildcardTypePermission(patterns));
2181 }
2182
2183 /**
2184 * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException}
2185 * instead
2186 */
2187 public static class InitializationException extends XStreamException {
2188 /**
2189 * @deprecated As of 1.3, use
2190 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String, Throwable)}
2191 * instead
2192 */
2193 public InitializationException(String message, Throwable cause) {
2194 super(message, cause);
2195 }
2196
2197 /**
2198 * @deprecated As of 1.3, use
2199 * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)}
2200 * instead
2201 */
2202 public InitializationException(String message) {
2203 super(message);
2204 }
2205 }
2206 }
0 /*
1 * Copyright (C) 2007, 2008 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 22. October 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream;
11
12 import com.thoughtworks.xstream.core.BaseException;
13
14
15 /**
16 * Base exception for all thrown exceptions with XStream. JDK 1.3 friendly cause handling.
17 *
18 * @author Joe Walnes
19 * @author J&ouml;rg Schaible
20 * @since 1.3
21 */
22 public class XStreamException extends BaseException {
23
24 private Throwable cause;
25
26 /**
27 * Default constructor.
28 *
29 * @since 1.3
30 */
31 protected XStreamException() {
32 this("", null);
33 }
34
35 /**
36 * Constructs an XStreamException with a message.
37 *
38 * @param message
39 * @since 1.3
40 */
41 public XStreamException(String message) {
42 this(message, null);
43 }
44
45 /**
46 * Constructs an XStreamException as wrapper for a different causing {@link Throwable}.
47 *
48 * @param cause
49 * @since 1.3
50 */
51 public XStreamException(Throwable cause) {
52 this("", cause);
53 }
54
55 /**
56 * Constructs an XStreamException with a message as wrapper for a different causing
57 * {@link Throwable}.
58 *
59 * @param message
60 * @param cause
61 * @since 1.3
62 */
63 public XStreamException(String message, Throwable cause) {
64 super(message + (cause == null ? "" : " : " + cause.getMessage()));
65 this.cause = cause;
66 }
67
68 public Throwable getCause() {
69 return cause;
70 }
71
72 }
0 /*
1 * Copyright (C) 2006, 2007, 2014 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 13. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.io.ObjectStreamException;
16 import java.io.Reader;
17 import java.io.StringReader;
18 import java.io.StringWriter;
19 import java.io.Writer;
20
21 import javax.xml.datatype.DatatypeFactory;
22
23 import com.thoughtworks.xstream.converters.ConversionException;
24 import com.thoughtworks.xstream.converters.ConverterLookup;
25 import com.thoughtworks.xstream.converters.ConverterMatcher;
26 import com.thoughtworks.xstream.converters.ConverterRegistry;
27 import com.thoughtworks.xstream.converters.MarshallingContext;
28 import com.thoughtworks.xstream.converters.UnmarshallingContext;
29 import com.thoughtworks.xstream.converters.javabean.JavaBeanProvider;
30 import com.thoughtworks.xstream.converters.reflection.FieldKeySorter;
31 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
32 import com.thoughtworks.xstream.core.JVM;
33 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
34 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
35 import com.thoughtworks.xstream.io.naming.NameCoder;
36 import com.thoughtworks.xstream.io.xml.XppDriver;
37 import com.thoughtworks.xstream.mapper.Mapper;
38 import com.thoughtworks.xstream.security.AnyTypePermission;
39 import com.thoughtworks.xstream.security.TypeHierarchyPermission;
40 import com.thoughtworks.xstream.security.TypePermission;
41 import com.thoughtworks.xstream.security.WildcardTypePermission;
42
43 /**
44 * Self-contained XStream generator. The class is a utility to write XML streams that contain
45 * additionally the XStream that was used to serialize the object graph. Such a stream can
46 * be unmarshalled using this embedded XStream instance, that kept any settings.
47 *
48 * @author J&ouml;rg Schaible
49 * @since 1.2
50 */
51 public class XStreamer {
52
53 private final static TypePermission[] PERMISSIONS = {
54 new TypeHierarchyPermission(ConverterMatcher.class),
55 new TypeHierarchyPermission(Mapper.class),
56 new TypeHierarchyPermission(XStream.class),
57 new TypeHierarchyPermission(ReflectionProvider.class),
58 new TypeHierarchyPermission(JavaBeanProvider.class),
59 new TypeHierarchyPermission(FieldKeySorter.class),
60 new TypeHierarchyPermission(ConverterLookup.class),
61 new TypeHierarchyPermission(ConverterRegistry.class),
62 new TypeHierarchyPermission(HierarchicalStreamDriver.class),
63 new TypeHierarchyPermission(MarshallingStrategy.class),
64 new TypeHierarchyPermission(MarshallingContext.class),
65 new TypeHierarchyPermission(UnmarshallingContext.class),
66 new TypeHierarchyPermission(NameCoder.class),
67 new TypeHierarchyPermission(TypePermission.class),
68 new WildcardTypePermission(new String[]{JVM.class.getPackage().getName()+".**"}),
69 new TypeHierarchyPermission(DatatypeFactory.class) // required by DurationConverter
70 };
71
72 /**
73 * Serialize an object including the XStream to a pretty-printed XML String.
74 *
75 * @throws ObjectStreamException if the XML contains non-serializable elements
76 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be serialized
77 * @since 1.2
78 * @see #toXML(XStream, Object, Writer)
79 */
80 public String toXML(final XStream xstream, final Object obj) throws ObjectStreamException {
81 final Writer writer = new StringWriter();
82 try {
83 toXML(xstream, obj, writer);
84 } catch (final ObjectStreamException e) {
85 throw e;
86 } catch (final IOException e) {
87 throw new ConversionException("Unexpected IO error from a StringWriter", e);
88 }
89 return writer.toString();
90 }
91
92 /**
93 * Serialize an object including the XStream to the given Writer as pretty-printed XML.
94 * <p>
95 * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you
96 * should use {@link XStreamer#fromXML(Reader)} or one of the other overloaded
97 * methods. Since a lot of internals are written into the stream, you cannot expect to use such
98 * an XML to work with another XStream version or with XStream running on different JDKs and/or
99 * versions. We have currently no JDK 1.3 support, nor will the PureReflectionConverter work
100 * with a JDK less than 1.5.
101 * </p>
102 *
103 * @throws IOException if an error occurs reading from the Writer.
104 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be serialized
105 * @since 1.2
106 */
107 public void toXML(final XStream xstream, final Object obj, final Writer out)
108 throws IOException {
109 final XStream outer = new XStream();
110 final ObjectOutputStream oos = outer.createObjectOutputStream(out);
111 try {
112 oos.writeObject(xstream);
113 oos.flush();
114 xstream.toXML(obj, out);
115 } finally {
116 oos.close();
117 }
118 }
119
120 /**
121 * Deserialize a self-contained XStream with object from a String. The method will use
122 * internally an XppDriver to load the contained XStream instance with default permissions.
123 *
124 * @param xml the XML data
125 * @throws ClassNotFoundException if a class in the XML stream cannot be found
126 * @throws ObjectStreamException if the XML contains non-deserializable elements
127 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
128 * @since 1.2
129 * @see #toXML(XStream, Object, Writer)
130 */
131 public Object fromXML(final String xml) throws ClassNotFoundException, ObjectStreamException {
132 try {
133 return fromXML(new StringReader(xml));
134 } catch (final ObjectStreamException e) {
135 throw e;
136 } catch (final IOException e) {
137 throw new ConversionException("Unexpected IO error from a StringReader", e);
138 }
139 }
140
141 /**
142 * Deserialize a self-contained XStream with object from a String. The method will use
143 * internally an XppDriver to load the contained XStream instance.
144 *
145 * @param xml the XML data
146 * @param permissions the permissions to use (ensure that they include the defaults)
147 * @throws ClassNotFoundException if a class in the XML stream cannot be found
148 * @throws ObjectStreamException if the XML contains non-deserializable elements
149 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
150 * @since 1.4.7
151 * @see #toXML(XStream, Object, Writer)
152 */
153 public Object fromXML(final String xml, final TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException {
154 try {
155 return fromXML(new StringReader(xml), permissions);
156 } catch (final ObjectStreamException e) {
157 throw e;
158 } catch (final IOException e) {
159 throw new ConversionException("Unexpected IO error from a StringReader", e);
160 }
161 }
162
163 /**
164 * Deserialize a self-contained XStream with object from a String.
165 *
166 * @param driver the implementation to use
167 * @param xml the XML data
168 * @throws ClassNotFoundException if a class in the XML stream cannot be found
169 * @throws ObjectStreamException if the XML contains non-deserializable elements
170 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
171 * @since 1.2
172 * @see #toXML(XStream, Object, Writer)
173 */
174 public Object fromXML(final HierarchicalStreamDriver driver, final String xml)
175 throws ClassNotFoundException, ObjectStreamException {
176 try {
177 return fromXML(driver, new StringReader(xml));
178 } catch (final ObjectStreamException e) {
179 throw e;
180 } catch (final IOException e) {
181 throw new ConversionException("Unexpected IO error from a StringReader", e);
182 }
183 }
184
185 /**
186 * Deserialize a self-contained XStream with object from a String.
187 *
188 * @param driver the implementation to use
189 * @param xml the XML data
190 * @param permissions the permissions to use (ensure that they include the defaults)
191 * @throws ClassNotFoundException if a class in the XML stream cannot be found
192 * @throws ObjectStreamException if the XML contains non-deserializable elements
193 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
194 * @since 1.4.7
195 * @see #toXML(XStream, Object, Writer)
196 */
197 public Object fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission[] permissions)
198 throws ClassNotFoundException, ObjectStreamException {
199 try {
200 return fromXML(driver, new StringReader(xml), permissions);
201 } catch (final ObjectStreamException e) {
202 throw e;
203 } catch (final IOException e) {
204 throw new ConversionException("Unexpected IO error from a StringReader", e);
205 }
206 }
207
208 /**
209 * Deserialize a self-contained XStream with object from an XML Reader. The method will use
210 * internally an XppDriver to load the contained XStream instance with default permissions.
211 *
212 * @param xml the {@link Reader} providing the XML data
213 * @throws IOException if an error occurs reading from the Reader.
214 * @throws ClassNotFoundException if a class in the XML stream cannot be found
215 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
216 * @since 1.2
217 * @see #toXML(XStream, Object, Writer)
218 */
219 public Object fromXML(final Reader xml)
220 throws IOException, ClassNotFoundException {
221 return fromXML(new XppDriver(), xml);
222 }
223
224 /**
225 * Deserialize a self-contained XStream with object from an XML Reader. The method will use
226 * internally an XppDriver to load the contained XStream instance.
227 *
228 * @param xml the {@link Reader} providing the XML data
229 * @param permissions the permissions to use (ensure that they include the defaults)
230 * @throws IOException if an error occurs reading from the Reader.
231 * @throws ClassNotFoundException if a class in the XML stream cannot be found
232 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
233 * @since 1.4.7
234 * @see #toXML(XStream, Object, Writer)
235 */
236 public Object fromXML(final Reader xml, final TypePermission[] permissions)
237 throws IOException, ClassNotFoundException {
238 return fromXML(new XppDriver(), xml, permissions);
239 }
240
241 /**
242 * Deserialize a self-contained XStream with object from an XML Reader.
243 *
244 * @param driver the implementation to use
245 * @param xml the {@link Reader} providing the XML data
246 * @throws IOException if an error occurs reading from the Reader.
247 * @throws ClassNotFoundException if a class in the XML stream cannot be found
248 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
249 * @since 1.2
250 */
251 public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml)
252 throws IOException, ClassNotFoundException {
253 return fromXML(driver, xml, new TypePermission[]{AnyTypePermission.ANY});
254 }
255
256 /**
257 * Deserialize a self-contained XStream with object from an XML Reader.
258 *
259 * @param driver the implementation to use
260 * @param xml the {@link Reader} providing the XML data
261 * @param permissions the permissions to use (ensure that they include the defaults)
262 * @throws IOException if an error occurs reading from the Reader.
263 * @throws ClassNotFoundException if a class in the XML stream cannot be found
264 * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized
265 * @since 1.4.7
266 */
267 public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission[] permissions)
268 throws IOException, ClassNotFoundException {
269 final XStream outer = new XStream(driver);
270 for(int i = 0; i < permissions.length; ++i) {
271 outer.addPermission(permissions[i]);
272 }
273 final HierarchicalStreamReader reader = driver.createReader(xml);
274 final ObjectInputStream configIn = outer.createObjectInputStream(reader);
275 try {
276 final XStream configured = (XStream)configIn.readObject();
277 final ObjectInputStream in = configured.createObjectInputStream(reader);
278 try {
279 return in.readObject();
280 } finally {
281 in.close();
282 }
283 } finally {
284 configIn.close();
285 }
286 }
287
288 /**
289 * Retrieve the default permissions to unmarshal an XStream instance.
290 * <p>
291 * The returned list will only cover permissions for XStream's own types. If your custom converters or mappers keep
292 * references to other types, you will have to add permission for those types on your own.
293 * </p>
294 *
295 * @since 1.4.7
296 */
297 public static TypePermission[] getDefaultPermissions() {
298 return (TypePermission[])PERMISSIONS.clone();
299 }
300 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2009 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 02. March 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.annotation.Annotation;
13 import java.lang.reflect.Field;
14
15
16 /**
17 * An utility class to provide annotations from different sources
18 *
19 * @author Guilherme Silveira
20 * @deprecated As of 1.3
21 */
22 @Deprecated
23 public class AnnotationProvider {
24
25 /**
26 * Returns a field annotation based on an annotation type
27 *
28 * @param field the annotation Field
29 * @param annotationClass the annotation Class
30 * @return The Annotation type
31 * @deprecated As of 1.3
32 */
33 @Deprecated
34 public <T extends Annotation> T getAnnotation(Field field, Class<T> annotationClass) {
35 return field.getAnnotation(annotationClass);
36 }
37
38 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2009 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 02. March 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.reflect.Field;
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import com.thoughtworks.xstream.converters.Converter;
18 import com.thoughtworks.xstream.converters.ConverterMatcher;
19 import com.thoughtworks.xstream.converters.MarshallingContext;
20 import com.thoughtworks.xstream.converters.SingleValueConverter;
21 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
22 import com.thoughtworks.xstream.converters.UnmarshallingContext;
23 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
24 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
25 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
26 import com.thoughtworks.xstream.mapper.Mapper;
27
28
29 /**
30 * ReflectionConverter which uses an AnnotationProvider to marshall and unmarshall fields based
31 * on the annotated converters.
32 *
33 * @author Guilherme Silveira
34 * @author Mauro Talevi
35 * @deprecated As of 1.3, build into {@link ReflectionConverter}
36 */
37 @Deprecated
38 public class AnnotationReflectionConverter extends ReflectionConverter {
39
40 private final AnnotationProvider annotationProvider;
41
42 private final Map<Class<? extends ConverterMatcher>, Converter> cachedConverters;
43
44 @Deprecated
45 public AnnotationReflectionConverter(
46 Mapper mapper, ReflectionProvider reflectionProvider,
47 AnnotationProvider annotationProvider) {
48 super(mapper, reflectionProvider);
49 this.annotationProvider = annotationProvider;
50 this.cachedConverters = new HashMap<Class<? extends ConverterMatcher>, Converter>();
51 }
52
53 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
54 XStreamConverter annotation = annotationProvider.getAnnotation(
55 field, XStreamConverter.class);
56 if (annotation != null) {
57 Class<? extends ConverterMatcher> type = annotation.value();
58 ensureCache(type);
59 context.convertAnother(newObj, cachedConverters.get(type));
60 } else {
61 context.convertAnother(newObj);
62 }
63 }
64
65 private void ensureCache(Class<? extends ConverterMatcher> type) {
66 if (!this.cachedConverters.containsKey(type)) {
67 cachedConverters.put(type, newInstance(type));
68 }
69 }
70
71 protected Object unmarshallField(
72 final UnmarshallingContext context, final Object result,
73 Class type, Field field) {
74 XStreamConverter annotation = annotationProvider.getAnnotation(
75 field, XStreamConverter.class);
76 if (annotation != null) {
77 Class<? extends Converter> converterType = (Class<? extends Converter>)annotation.value();
78 ensureCache(converterType);
79 return context.convertAnother(result, type, cachedConverters.get(converterType));
80 } else {
81 return context.convertAnother(result, type);
82 }
83 }
84
85 /**
86 * Instantiates a converter using its default constructor.
87 *
88 * @param type the converter type to instantiate
89 * @return the new instance
90 */
91 private Converter newInstance(Class<? extends ConverterMatcher> type) {
92 Converter converter;
93 // TODO: We need a separate exception for runtime initialization.
94 try {
95 if (SingleValueConverter.class.isAssignableFrom(type)) {
96 final SingleValueConverter svc = (SingleValueConverter)type.getConstructor().newInstance();
97 converter = new SingleValueConverterWrapper(svc);
98 } else {
99 converter = (Converter)type.getConstructor().newInstance();
100 }
101 } catch (InvocationTargetException e) {
102 throw new ObjectAccessException("Cannot construct " + type.getName(), e
103 .getCause());
104 } catch (InstantiationException e) {
105 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
106 } catch (IllegalAccessException e) {
107 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
108 } catch (NoSuchMethodException e) {
109 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
110 }
111 return converter;
112 }
113
114 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 11. August 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import com.thoughtworks.xstream.XStream;
14
15
16 /**
17 * Contains utility methods that enable to configure an XStream instance with class and field
18 * aliases, based on a class decorated with annotations defined in this package.
19 *
20 * @author Emil Kirschner
21 * @author Chung-Onn Cheong
22 * @author Guilherme Silveira
23 * @author J&ouml;rg Schaible
24 * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])}
25 */
26 @Deprecated
27 public class Annotations {
28 /**
29 * This class is not instantiable
30 */
31 private Annotations() {
32 }
33
34 /**
35 * Configures aliases on the specified XStream object based on annotations that decorate the
36 * specified class. It will recursively invoke itself. If a field is parameterized, a
37 * recursive call for each of its parameters type will be made.
38 *
39 * @param topLevelClasses the class for which the XStream object is configured. This class
40 * is expected to be decorated with annotations defined in this package.
41 * @param xstream the XStream object that will be configured
42 * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])}
43 */
44 @Deprecated
45 public static synchronized void configureAliases(XStream xstream,
46 Class<?> ... topLevelClasses) {
47 xstream.processAnnotations(topLevelClasses);
48 }
49 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 11. August 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import java.lang.annotation.ElementType;
14 import java.lang.annotation.Retention;
15 import java.lang.annotation.RetentionPolicy;
16 import java.lang.annotation.Target;
17
18 /**
19 * Annotation used to define an XStream class or field alias.
20 *
21 * @author Emil Kirschner
22 * @author Chung-Onn Cheong
23 * @see com.thoughtworks.xstream.XStream#alias(String, Class)
24 * @see com.thoughtworks.xstream.XStream#alias(String, Class, Class)
25 * @see com.thoughtworks.xstream.XStream#addDefaultImplementation(Class, Class)
26 */
27 @Retention(RetentionPolicy.RUNTIME)
28 @Target({ElementType.TYPE, ElementType.FIELD})
29 public @interface XStreamAlias {
30 /**
31 * The name of the class or field alias.
32 */
33 public String value();
34 /**
35 * A possible default implementation if the annotated type is an interface.
36 */
37 public Class<?> impl() default Void.class; //Use Void to denote as Null
38 }
0 /*
1 * Copyright (C) 2013 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 12.07.2013 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.annotations;
7
8 import java.lang.annotation.ElementType;
9 import java.lang.annotation.Retention;
10 import java.lang.annotation.RetentionPolicy;
11 import java.lang.annotation.Target;
12
13
14 /**
15 * Annotation used to define an XStream type alias.
16 *
17 * @author J&ouml;rg Schaible
18 * @since 1.4.5
19 * @see com.thoughtworks.xstream.XStream#aliasType(String, Class)
20 */
21 @Retention(RetentionPolicy.RUNTIME)
22 @Target(ElementType.TYPE)
23 public @interface XStreamAliasType {
24 /**
25 * The name of the type alias.
26 */
27 public String value();
28 }
0 /*
1 * Copyright (C) 2006, 2007 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 24. December 2006 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.annotation.Documented;
13 import java.lang.annotation.ElementType;
14 import java.lang.annotation.Retention;
15 import java.lang.annotation.RetentionPolicy;
16 import java.lang.annotation.Target;
17
18 /**
19 * Defines that a field should be serialized as an attribute.
20 *
21 * @author Guilherme Silveira
22 * @since 1.2.2
23 */
24 @Retention(RetentionPolicy.RUNTIME)
25 @Target(ElementType.FIELD)
26 @Documented
27 public @interface XStreamAsAttribute {
28 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 11. August 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import java.lang.annotation.ElementType;
14 import java.lang.annotation.Retention;
15 import java.lang.annotation.RetentionPolicy;
16 import java.lang.annotation.Target;
17
18 /**
19 * Annotation used to notify Annotations.configureAliases that it should recursively invoke itself for
20 * all parameterized types of this field.
21 *
22 * @author Emil Kirschner
23 * @author Chung-Onn Cheong
24 * @deprecated As of 1.3, recursive behaviour is now always used and the annotation is therefore superfluous
25 */
26 @Retention(RetentionPolicy.RUNTIME)
27 @Target(ElementType.FIELD)
28 @Deprecated
29 public @interface XStreamContainedType {
30
31 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014 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 16. September 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.converters.ConverterMatcher;
15
16 import java.lang.annotation.Documented;
17 import java.lang.annotation.ElementType;
18 import java.lang.annotation.Retention;
19 import java.lang.annotation.RetentionPolicy;
20 import java.lang.annotation.Target;
21
22
23 /**
24 * Annotation to declare a converter. The annotation supports additionally the injection of
25 * various constructor arguments provided by XStream:
26 * <ul>
27 * <li>{@link com.thoughtworks.xstream.mapper.Mapper}: The current mapper chain of the XStream
28 * instance.</li>
29 * <li>{@link com.thoughtworks.xstream.core.ClassLoaderReference}: The reference to the class
30 * loader used by the XStream instance to deserialize the objects.</li>
31 * <li>{@link com.thoughtworks.xstream.converters.reflection.ReflectionProvider}: The reflection
32 * provider used by the reflection based converters of the current XStream instance.</li>
33 * <li>{@link com.thoughtworks.xstream.converters.ConverterLookup}: The lookup for converters
34 * handling a special type.</li>
35 * <li>All elements provided with the individual arrays of this annotation. The provided values
36 * follow the declaration sequence if a constructor requires multiple arguments of the same
37 * type.</li>
38 * <li>{@link Class}: The type of the element where the annotation is declared. Note, that this
39 * argument is not supported when using
40 * {@link com.thoughtworks.xstream.annotations.XStreamConverters} or {@link #useImplicitType()}
41 * == false.</li>
42 * <li>{@link com.thoughtworks.xstream.core.JVM}: Utility e.g. to load classes.</li>
43 * <li>{@link ClassLoader} (deprecated since 1.4.5): The class loader used by the XStream
44 * instance to deserialize the objects. Use ClassLoaderReference as argument</li>
45 * </ul>
46 * <p>
47 * The algorithm will try the converter's constructor with the most arguments first.
48 * </p>
49 * <p>
50 * Note, the annotation matches a {@link ConverterMatcher}.
51 * {@link com.thoughtworks.xstream.converters.Converter} as well as
52 * {@link com.thoughtworks.xstream.converters.SingleValueConverter} extend this interface. The
53 * {@link com.thoughtworks.xstream.mapper.AnnotationMapper} can only handle these two
54 * <strong>known</strong> types.
55 * </p>
56 *
57 * @author Chung-Onn Cheong
58 * @author J&ouml;rg Schaible
59 */
60 @Retention(RetentionPolicy.RUNTIME)
61 @Target({ElementType.TYPE, ElementType.FIELD})
62 @Documented
63 public @interface XStreamConverter {
64 Class<? extends ConverterMatcher> value();
65
66 int priority() default XStream.PRIORITY_NORMAL;
67
68 /**
69 * Flag to provide the current type as implicit first Class argument to a converter's
70 * constructor.
71 *
72 * @return true if the current type is provided
73 * @since 1.4.5
74 */
75 boolean useImplicitType() default true;
76
77 /**
78 * Provide class types as arguments for the converter's constructor arguments.
79 * <p>
80 * Note, that XStream itself provides the current class type as first Class argument to a
81 * constructor, if the annotation is added directly to a class type (and not as part of a
82 * parameter declaration of a {@link XStreamConverters} annotation). The current type has
83 * precedence over any type provided with this method. This behavior can be overridden
84 * setting {@link #useImplicitType()} to false.
85 *
86 * @return the types
87 * @since 1.4.2
88 */
89 Class<?>[] types() default {};
90
91 String[] strings() default {};
92
93 byte[] bytes() default {};
94
95 char[] chars() default {};
96
97 short[] shorts() default {};
98
99 int[] ints() default {};
100
101 long[] longs() default {};
102
103 float[] floats() default {};
104
105 double[] doubles() default {};
106
107 boolean[] booleans() default {};
108 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 16. September 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import java.lang.annotation.ElementType;
14 import java.lang.annotation.Retention;
15 import java.lang.annotation.RetentionPolicy;
16 import java.lang.annotation.Target;
17
18 /**
19 *
20 * @author Chung-Onn Cheong
21 */
22 @Retention(RetentionPolicy.RUNTIME)
23 @Target(ElementType.TYPE)
24 public @interface XStreamConverters {
25 XStreamConverter[] value();
26 }
0 /*
1 * Copyright (C) 2006, 2007, 2011 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 01. December 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.annotation.ElementType;
13 import java.lang.annotation.Retention;
14 import java.lang.annotation.RetentionPolicy;
15 import java.lang.annotation.Target;
16
17 /**
18 * An annotation for marking a field as an implicit collection or array.
19 *
20 * @author Lucio Benfante
21 * @author J&ouml;rg Schaible
22 * @since 1.2.2
23 */
24 @Retention(RetentionPolicy.RUNTIME)
25 @Target(ElementType.FIELD)
26 public @interface XStreamImplicit {
27 /**
28 * Element name of the implicit collection.
29 */
30 String itemFieldName() default "";
31 /**
32 * Field name of map entries that are used as key for the element in the implicit map.
33 * @since 1.4
34 */
35 String keyFieldName() default "";
36 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 16. September 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.annotations;
12
13 import java.lang.annotation.ElementType;
14 import java.lang.annotation.Retention;
15 import java.lang.annotation.RetentionPolicy;
16 import java.lang.annotation.Target;
17
18 /**
19 *
20 * @author Chung-Onn Cheong
21 * @deprecated As of 1.3, use @XStreamImplicit at field level
22 */
23 @Retention(RetentionPolicy.RUNTIME)
24 @Target(ElementType.TYPE)
25 public @interface XStreamImplicitCollection {
26 String value(); //fieldName
27 String item() default ""; //itemfieldName
28 }
0 /*
1 * Copyright (C) 2008 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 13. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.annotation.ElementType;
13 import java.lang.annotation.Retention;
14 import java.lang.annotation.RetentionPolicy;
15 import java.lang.annotation.Target;
16
17 /**
18 * Annotation to force automated processing of further classes.
19 *
20 * @author Steven Sparling
21 * @since 1.3.1
22 */
23 @Retention(RetentionPolicy.RUNTIME)
24 @Target(ElementType.TYPE)
25 public @interface XStreamInclude
26 {
27 public Class<?>[] value();
28 }
0 /*
1 * Copyright (C) 2007 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 06. May 2005 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.annotations;
11
12 import java.lang.annotation.Retention;
13 import java.lang.annotation.RetentionPolicy;
14 import java.lang.annotation.Target;
15 import java.lang.annotation.ElementType;
16
17 /**
18 * Declares a field to be omitted. The result is the same as invoking the method
19 * omitField in a XStream instance.
20 *
21 * @author Chung-Onn Cheong
22 * @author Guilherme Silveira
23 * @since 1.2.2
24 */
25 @Retention(RetentionPolicy.RUNTIME)
26 @Target(ElementType.FIELD)
27 public @ interface XStreamOmitField {
28 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 26. September 2003 by Joe Walnes
10 */
11 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;
18
19 /**
20 * Thrown by {@link Converter} implementations when they cannot convert an object
21 * to/from textual data.
22 *
23 * When this exception is thrown it can be passed around to things that accept an
24 * {@link ErrorWriter}, allowing them to add diagnostics to the stack trace.
25 *
26 * @author Joe Walnes
27 * @author J&ouml;rg Schaible
28 *
29 * @see ErrorWriter
30 */
31 public class ConversionException extends XStreamException implements ErrorWriter {
32
33 private static final String SEPARATOR = "\n-------------------------------";
34 private Map stuff = new OrderRetainingMap();
35
36 public ConversionException(String msg, Throwable cause) {
37 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 }
45 }
46
47 public ConversionException(String msg) {
48 super(msg);
49 }
50
51 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();
108 }
109 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15
16 /**
17 * Converter implementations are responsible marshalling Java objects
18 * to/from textual data.
19 *
20 * <p>If an exception occurs during processing, a {@link ConversionException}
21 * should be thrown.</p>
22 *
23 * <p>If working with the high level {@link com.thoughtworks.xstream.XStream} facade,
24 * you can register new converters using the XStream.registerConverter() method.</p>
25 *
26 * <p>If working with the lower level API, the
27 * {@link com.thoughtworks.xstream.converters.ConverterLookup} implementation is
28 * responsible for looking up the appropriate converter.</p>
29 *
30 * <p>Converters for object that can store all information in a single value
31 * should implement {@link com.thoughtworks.xstream.converters.SingleValueConverter}.
32 * {@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter}
33 * provides a starting point.</p>
34 *
35 * <p>{@link com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter}
36 * provides a starting point for objects that hold a collection of other objects
37 * (such as Lists and Maps).</p>
38 *
39 * @author Joe Walnes
40 * @see com.thoughtworks.xstream.XStream
41 * @see com.thoughtworks.xstream.converters.ConverterLookup
42 * @see com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter
43 * @see com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter
44 */
45 public interface Converter extends ConverterMatcher {
46
47 /**
48 * Convert an object to textual data.
49 *
50 * @param source The object to be marshalled.
51 * @param writer A stream to write to.
52 * @param context A context that allows nested objects to be processed by XStream.
53 */
54 void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context);
55
56 /**
57 * Convert textual data back into an object.
58 *
59 * @param reader The stream to read the text from.
60 * @param context
61 * @return The resulting object.
62 */
63 Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context);
64
65 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 /**
14 * Responsible for looking up the correct Converter implementation for a specific type.
15 *
16 * @author Joe Walnes
17 * @see Converter
18 */
19 public interface ConverterLookup {
20
21 /**
22 * Lookup a converter for a specific type.
23 * <p>
24 * This type may be any Class, including primitive and array types. It may also be null, signifying
25 * the value to be converted is a null type.
26 * </p>
27 */
28 Converter lookupConverterForType(Class type);
29 }
0 /*
1 * Copyright (C) 2006, 2007 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 15. February 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.converters;
11
12 /**
13 * ConverterMatcher allows to match converters to classes by
14 * determining if a given type can be converted by the converter instance.
15 * ConverterMatcher is the base interface of any converter.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @author Mauro Talevi
20 * @see com.thoughtworks.xstream.converters.Converter
21 * @see com.thoughtworks.xstream.converters.SingleValueConverter
22 * @since 1.2
23 */
24 public interface ConverterMatcher {
25
26 /**
27 * Determines whether the converter can marshall a particular type.
28 * @param type the Class representing the object type to be converted
29 */
30 boolean canConvert(Class type);
31
32 }
0 /*
1 * Copyright (C) 2008 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters;
11
12 /**
13 * An interface for the converter management.
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.3
17 */
18 public interface ConverterRegistry {
19
20 void registerConverter(Converter converter, int priority);
21
22 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 16. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 import java.util.Iterator;
14
15 /**
16 * Holds generic data, to be used as seen fit by the user.
17 *
18 * @author Joe Walnes
19 */
20 public interface DataHolder {
21
22 Object get(Object key);
23 void put(Object key, Object value);
24 Iterator keys();
25
26 }
0 /*
1 * Copyright (C) 2011 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 15.02.2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters;
11
12 /**
13 * To aid debugging, some components expose themselves as ErrorReporter
14 * indicating that they can add information in case of an error..
15 *
16 * @author Joerg Schaible
17 *
18 * @since 1.4
19 */
20 public interface ErrorReporter {
21 /**
22 * Append context information to an {@link ErrorWriter}.
23 *
24 * @param errorWriter the error writer
25 * @since 1.4
26 */
27 void appendErrors(ErrorWriter errorWriter);
28 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 08. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 import java.util.Iterator;
14
15 /**
16 * To aid debugging, some components are passed an ErrorWriter
17 * when things go wrong, allowing them to add information
18 * to the error message that may be helpful to diagnose problems.
19 *
20 * @author Joe Walnes
21 * @author J&ouml;rg Schaible
22 */
23 public interface ErrorWriter {
24
25 /**
26 * Add some information to the error message. The information will be added even
27 * if the identifier is already in use.
28 *
29 * @param name something to identify the type of information (e.g. 'XPath').
30 * @param information detail of the message (e.g. '/blah/moo[3]'
31 */
32 void add(String name, String information);
33
34 /**
35 * Set some information to the error message. If the identifier is already in use, the
36 * new information will replace the old one.
37 *
38 * @param name something to identify the type of information (e.g. 'XPath').
39 * @param information detail of the message (e.g. '/blah/moo[3]'
40 * @since 1.4
41 */
42 void set(String name, String information);
43
44 /**
45 * Retrieve information of the error message.
46 *
47 * @param errorKey the key of the message
48 * @return the value
49 * @since 1.3
50 */
51 String get(String errorKey);
52
53 /**
54 * Retrieve an iterator over all keys of the error message.
55 *
56 * @return an Iterator
57 * @since 1.3
58 */
59 Iterator keys();
60 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 public interface MarshallingContext extends DataHolder {
14
15 /**
16 * Converts another object searching for the default converter
17 * @param nextItem the next item to convert
18 */
19 void convertAnother(Object nextItem);
20
21 /**
22 * Converts another object using the specified converter
23 * @param nextItem the next item to convert
24 * @param converter the Converter to use
25 * @since 1.2
26 */
27 void convertAnother(Object nextItem, Converter converter);
28
29 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 15. February 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.converters;
11
12 /**
13 * SingleValueConverter implementations are marshallable to/from a single value String representation.
14 *
15 * <p>{@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter}
16 * provides a starting point for objects that can store all information in a single value String.</p>
17 *
18 * @author Joe Walnes
19 * @author J&ouml;rg Schaible
20 * @author Mauro Talevi
21 * @see com.thoughtworks.xstream.converters.Converter
22 * @see com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter
23 * @since 1.2
24 */
25 public interface SingleValueConverter extends ConverterMatcher {
26
27 /**
28 * Marshals an Object into a single value representation.
29 * @param obj the Object to be converted
30 * @return a String with the single value of the Object or <code>null</code>
31 */
32 public String toString(Object obj);
33
34 /**
35 * Unmarshals an Object from its single value representation.
36 * @param str the String with the single value of the Object
37 * @return the Object
38 */
39 public Object fromString(String str);
40
41 }
0 /*
1 * Copyright (C) 2006, 2007, 2011, 2014 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 20. February 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.converters;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
13 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
14
15 /**
16 * Wrapper to convert a {@link com.thoughtworks.xstream.converters.SingleValueConverter} into a
17 * {@link com.thoughtworks.xstream.converters.Converter}.
18 *
19 * @author J&ouml;rg Schaible
20 * @see com.thoughtworks.xstream.converters.Converter
21 * @see com.thoughtworks.xstream.converters.SingleValueConverter
22 */
23 public class SingleValueConverterWrapper implements Converter, SingleValueConverter, ErrorReporter {
24
25 private final SingleValueConverter wrapped;
26
27 public SingleValueConverterWrapper(SingleValueConverter wrapped) {
28 this.wrapped = wrapped;
29 }
30
31 public boolean canConvert(Class type) {
32 return wrapped.canConvert(type);
33 }
34
35 public String toString(Object obj) {
36 return wrapped.toString(obj);
37 }
38
39 public Object fromString(String str) {
40 return wrapped.fromString(str);
41 }
42
43 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
44 writer.setValue(toString(source));
45 }
46
47 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
48 return fromString(reader.getValue());
49 }
50
51 public void appendErrors(ErrorWriter errorWriter) {
52 errorWriter.add("wrapped-converter", wrapped == null ? "(null)" : wrapped.getClass().getName());
53 if (wrapped instanceof ErrorReporter) {
54 ((ErrorReporter)wrapped).appendErrors(errorWriter);
55 }
56 }
57 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters;
12
13 public interface UnmarshallingContext extends DataHolder {
14
15 Object convertAnother(Object current, Class type);
16
17 /**
18 * @since 1.2
19 */
20 Object convertAnother(Object current, Class type, Converter converter);
21
22 Object currentObject();
23
24 Class getRequiredType();
25
26 void addCompletionCallback(Runnable work, int priority);
27
28 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 15. February 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.converters.basic;
11
12 import com.thoughtworks.xstream.converters.SingleValueConverter;
13
14 /**
15 * Base abstract implementation of {@link com.thoughtworks.xstream.converters.SingleValueConverter}.
16 *
17 * <p>Subclasses should implement methods canConvert(Class) and fromString(String) for the conversion.</p>
18 *
19 * @author Joe Walnes
20 * @author J&ouml;rg Schaible
21 * @author Mauro Talevi
22 * @see com.thoughtworks.xstream.converters.SingleValueConverter
23 */
24 public abstract class AbstractSingleValueConverter implements SingleValueConverter {
25
26 public abstract boolean canConvert(Class type);
27
28 public String toString(Object obj) {
29 return obj == null ? null : obj.toString();
30 }
31
32 public abstract Object fromString(String str);
33
34 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import java.math.BigDecimal;
14
15 /**
16 * Converts a java.math.BigDecimal to a String, retaining
17 * its precision.
18 *
19 * @author Joe Walnes
20 */
21 public class BigDecimalConverter extends AbstractSingleValueConverter {
22
23 public boolean canConvert(Class type) {
24 return type.equals(BigDecimal.class);
25 }
26
27 public Object fromString(String str) {
28 return new BigDecimal(str);
29 }
30
31 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import java.math.BigInteger;
14
15 /**
16 * Converts a java.math.BigInteger to a String.
17 *
18 * @author Joe Walnes
19 */
20 public class BigIntegerConverter extends AbstractSingleValueConverter {
21
22 public boolean canConvert(Class type) {
23 return type.equals(BigInteger.class);
24 }
25
26 public Object fromString(String str) {
27 return new BigInteger(str);
28 }
29
30 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13
14 /**
15 * Converts a boolean primitive or java.lang.Boolean wrapper to
16 * a String.
17 *
18 * @author Joe Walnes
19 * @author David Blevins
20 */
21 public class BooleanConverter extends AbstractSingleValueConverter {
22
23 public static final BooleanConverter TRUE_FALSE = new BooleanConverter("true", "false", false);
24
25 public static final BooleanConverter YES_NO = new BooleanConverter("yes", "no", false);
26
27 public static final BooleanConverter BINARY = new BooleanConverter("1", "0", true);
28
29 private final String positive;
30 private final String negative;
31 private final boolean caseSensitive;
32
33 public BooleanConverter(final String positive, final String negative, final boolean caseSensitive) {
34 this.positive = positive;
35 this.negative = negative;
36 this.caseSensitive = caseSensitive;
37 }
38
39 public BooleanConverter() {
40 this("true", "false", false);
41 }
42
43 /**
44 * @deprecated As of 1.4.8 use {@link #canConvert(Class)}
45 */
46 public boolean shouldConvert(final Class type, final Object value) {
47 return true;
48 }
49
50 public boolean canConvert(final Class type) {
51 return type.equals(boolean.class) || type.equals(Boolean.class);
52 }
53
54 public Object fromString(final String str) {
55 if (caseSensitive) {
56 return positive.equals(str) ? Boolean.TRUE : Boolean.FALSE;
57 } else {
58 return positive.equalsIgnoreCase(str) ? Boolean.TRUE : Boolean.FALSE;
59 }
60 }
61
62 public String toString(final Object obj) {
63 final Boolean value = (Boolean) obj;
64 return obj == null ? null : value.booleanValue() ? positive : negative;
65 }
66 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts a byte primitive or java.lang.Byte wrapper to
15 * a String.
16 *
17 * @author Joe Walnes
18 */
19 public class ByteConverter extends AbstractSingleValueConverter {
20
21 public boolean canConvert(Class type) {
22 return type.equals(byte.class) || type.equals(Byte.class);
23 }
24
25 public Object fromString(String str) {
26 int value = Integer.decode(str).intValue();
27 if(value < Byte.MIN_VALUE || value > 0xFF) {
28 throw new NumberFormatException("For input string: \"" + str + '"');
29 }
30 return new Byte((byte)value);
31 }
32
33 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.SingleValueConverter;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19
20 /**
21 * Converts a char primitive or java.lang.Character wrapper to
22 * a String. If char is \0 the representing String is empty.
23 *
24 * @author Joe Walnes
25 * @author J&ouml;rg Schaible
26 */
27 public class CharConverter implements Converter, SingleValueConverter {
28
29 public boolean canConvert(Class type) {
30 return type.equals(char.class) || type.equals(Character.class);
31 }
32
33 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
34 writer.setValue(toString(source));
35 }
36
37 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
38 String nullAttribute = reader.getAttribute("null");
39 if (nullAttribute != null && nullAttribute.equals("true")) {
40 return new Character('\0');
41 } else {
42 return fromString(reader.getValue());
43 }
44 }
45
46 public Object fromString(String str) {
47 if (str.length() == 0) {
48 return new Character('\0');
49 } else {
50 return new Character(str.charAt(0));
51 }
52 }
53
54 public String toString(Object obj) {
55 char ch = ((Character)obj).charValue();
56 return ch == '\0' ? "" : obj.toString();
57 }
58
59 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import java.text.ParseException;
14 import java.text.SimpleDateFormat;
15 import java.util.ArrayList;
16 import java.util.Calendar;
17 import java.util.Date;
18 import java.util.List;
19 import java.util.Locale;
20 import java.util.TimeZone;
21
22 import com.thoughtworks.xstream.converters.ConversionException;
23 import com.thoughtworks.xstream.converters.ErrorReporter;
24 import com.thoughtworks.xstream.converters.ErrorWriter;
25 import com.thoughtworks.xstream.core.JVM;
26 import com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat;
27
28
29 /**
30 * Converts a {@link Date} to a string as a date format, retaining precision down to milliseconds.
31 * <p>
32 * The formatted string is by default in UTC and English locale. You can provide a different {@link Locale} and
33 * {@link TimeZone} that are used for serialization or <code>null</code> to use always the current TimeZone. Note, that
34 * the default format uses 3-letter time zones that can be ambiguous and may cause wrong results at deserialization and
35 * is localized since Java 6.
36 * </p>
37 * <p>
38 * Using a Java 7 runtime or higher, the converter supports the <a href="http://www.w3.org/TR/NOTE-datetime">datetime
39 * format defined by W3C</a> (a subset of ISO 8601) at deserialization. Only the formats that also contain the time
40 * information.
41 * </p>
42 * <p>
43 * Dates in a different era are using a special default pattern that contains the era itself.
44 * </p>
45 *
46 * @author Joe Walnes
47 * @author J&ouml;rg Schaible
48 */
49 public class DateConverter extends AbstractSingleValueConverter implements ErrorReporter {
50
51 private static final String[] DEFAULT_ACCEPTABLE_FORMATS;
52 private static final String DEFAULT_PATTERN;
53 private static final String DEFAULT_ERA_PATTERN;
54 private static final TimeZone UTC;
55 private static final long ERA_START;
56 static {
57 UTC = TimeZone.getTimeZone("UTC");
58
59 final String defaultPattern = "yyyy-MM-dd HH:mm:ss.S z";
60 final String defaultEraPattern = "yyyy-MM-dd G HH:mm:ss.S z";
61 final List acceptablePatterns = new ArrayList();
62 final boolean utcSupported = JVM.canParseUTCDateFormat();
63 DEFAULT_PATTERN = utcSupported ? defaultPattern : "yyyy-MM-dd HH:mm:ss.S 'UTC'";
64 DEFAULT_ERA_PATTERN = utcSupported ? defaultEraPattern : "yyyy-MM-dd G HH:mm:ss.S 'UTC'";
65 acceptablePatterns.add("yyyy-MM-dd HH:mm:ss.S z");
66 if (!utcSupported) {
67 acceptablePatterns.add(defaultPattern);
68 }
69 acceptablePatterns.add("yyyy-MM-dd HH:mm:ss.S a");
70 // JDK 1.3 needs both versions
71 acceptablePatterns.add("yyyy-MM-dd HH:mm:ssz");
72 acceptablePatterns.add("yyyy-MM-dd HH:mm:ss z");
73 if (!utcSupported) {
74 acceptablePatterns.add("yyyy-MM-dd HH:mm:ss 'UTC'");
75 }
76 if (JVM.canParseISO8601TimeZoneInDateFormat()) {
77 acceptablePatterns.add("yyyy-MM-dd'T'HH:mm:ss.SX");
78 acceptablePatterns.add("yyyy-MM-dd'T'HH:mm:ssX");
79 acceptablePatterns.add("yyyy-MM-dd'T'HH:mmX");
80 }
81 // backwards compatibility
82 acceptablePatterns.add("yyyy-MM-dd HH:mm:ssa");
83 DEFAULT_ACCEPTABLE_FORMATS = (String[]) acceptablePatterns.toArray(new String[acceptablePatterns.size()]);
84
85 final Calendar cal = Calendar.getInstance();
86 cal.setTimeZone(UTC);
87 cal.clear();
88 cal.set(1, Calendar.JANUARY, 1);
89 ERA_START = cal.getTime().getTime(); // calendar.getTimeInMillis() not available under JDK 1.3
90 }
91 private final ThreadSafeSimpleDateFormat defaultFormat;
92 private final ThreadSafeSimpleDateFormat defaultEraFormat;
93 private final ThreadSafeSimpleDateFormat[] acceptableFormats;
94
95 /**
96 * Construct a DateConverter with standard formats and lenient set off.
97 */
98 public DateConverter() {
99 this(false);
100 }
101
102 /**
103 * Construct a DateConverter with standard formats, lenient set off and uses a given
104 * TimeZone for serialization.
105 *
106 * @param timeZone the TimeZone used to serialize the Date
107 * @since 1.4
108 */
109 public DateConverter(final TimeZone timeZone) {
110 this(DEFAULT_PATTERN, DEFAULT_ACCEPTABLE_FORMATS, timeZone);
111 }
112
113 /**
114 * Construct a DateConverter with standard formats and using UTC.
115 *
116 * @param lenient the lenient setting of {@link SimpleDateFormat#setLenient(boolean)}
117 * @since 1.3
118 */
119 public DateConverter(final boolean lenient) {
120 this(DEFAULT_PATTERN, DEFAULT_ACCEPTABLE_FORMATS, lenient);
121 }
122
123 /**
124 * Construct a DateConverter with lenient set off using UTC.
125 *
126 * @param defaultFormat the default format
127 * @param acceptableFormats fallback formats
128 */
129 public DateConverter(final String defaultFormat, final String[] acceptableFormats) {
130 this(defaultFormat, acceptableFormats, false);
131 }
132
133 /**
134 * Construct a DateConverter with a given TimeZone and lenient set off.
135 *
136 * @param defaultFormat the default format
137 * @param acceptableFormats fallback formats
138 * @since 1.4
139 */
140 public DateConverter(final String defaultFormat, final String[] acceptableFormats, final TimeZone timeZone) {
141 this(defaultFormat, acceptableFormats, timeZone, false);
142 }
143
144 /**
145 * Construct a DateConverter.
146 *
147 * @param defaultFormat the default format
148 * @param acceptableFormats fallback formats
149 * @param lenient the lenient setting of {@link SimpleDateFormat#setLenient(boolean)}
150 * @since 1.3
151 */
152 public DateConverter(final String defaultFormat, final String[] acceptableFormats, final boolean lenient) {
153 this(defaultFormat, acceptableFormats, UTC, lenient);
154 }
155
156 /**
157 * Construct a DateConverter.
158 *
159 * @param defaultFormat the default format
160 * @param acceptableFormats fallback formats
161 * @param timeZone the TimeZone used to serialize the Date
162 * @param lenient the lenient setting of {@link SimpleDateFormat#setLenient(boolean)}
163 * @since 1.4
164 */
165 public DateConverter(
166 final String defaultFormat, final String[] acceptableFormats, final TimeZone timeZone, final boolean lenient) {
167 this(DEFAULT_ERA_PATTERN, defaultFormat, acceptableFormats, Locale.ENGLISH, timeZone, lenient);
168 }
169
170 /**
171 * Construct a DateConverter.
172 *
173 * @param defaultEraFormat the default format for dates in a different era (may be
174 * <code>null</code> to drop era support)
175 * @param defaultFormat the default format
176 * @param acceptableFormats fallback formats
177 * @param locale locale to use for the format
178 * @param timeZone the TimeZone used to serialize the Date
179 * @param lenient the lenient setting of {@link SimpleDateFormat#setLenient(boolean)}
180 * @since 1.4.4
181 */
182 public DateConverter(
183 final String defaultEraFormat, final String defaultFormat, final String[] acceptableFormats,
184 final Locale locale, final TimeZone timeZone, final boolean lenient) {
185 if (defaultEraFormat != null) {
186 this.defaultEraFormat = new ThreadSafeSimpleDateFormat(
187 defaultEraFormat, timeZone, locale, 4, 20, lenient);
188 } else {
189 this.defaultEraFormat = null;
190 }
191 this.defaultFormat = new ThreadSafeSimpleDateFormat(
192 defaultFormat, timeZone, locale, 4, 20, lenient);
193 this.acceptableFormats = acceptableFormats != null
194 ? new ThreadSafeSimpleDateFormat[acceptableFormats.length]
195 : new ThreadSafeSimpleDateFormat[0];
196 for (int i = 0; i < this.acceptableFormats.length; i++ ) {
197 this.acceptableFormats[i] = new ThreadSafeSimpleDateFormat(
198 acceptableFormats[i], timeZone, locale, 1, 20, lenient);
199 }
200 }
201
202 public boolean canConvert(Class type) {
203 return type.equals(Date.class);
204 }
205
206 public Object fromString(String str) {
207 if (defaultEraFormat != null) {
208 try {
209 return defaultEraFormat.parse(str);
210 } catch (ParseException e) {
211 // try next ...
212 }
213 }
214 if (defaultEraFormat != defaultFormat) {
215 try {
216 return defaultFormat.parse(str);
217 } catch (ParseException e) {
218 // try next ...
219 }
220 }
221 for (int i = 0; i < acceptableFormats.length; i++ ) {
222 try {
223 return acceptableFormats[i].parse(str);
224 } catch (ParseException e3) {
225 // no worries, let's try the next format.
226 }
227 }
228 // no dateFormats left to try
229 throw new ConversionException("Cannot parse date " + str);
230 }
231
232 public String toString(Object obj) {
233 final Date date = (Date)obj;
234 if (date.getTime() < ERA_START && defaultEraFormat != null) {
235 return defaultEraFormat.format(date);
236 } else {
237 return defaultFormat.format(date);
238 }
239 }
240
241 public void appendErrors(ErrorWriter errorWriter) {
242 errorWriter.add("Default date pattern", defaultFormat.toString());
243 if (defaultEraFormat != null) {
244 errorWriter.add("Default era date pattern", defaultEraFormat.toString());
245 }
246 for (int i = 0; i < acceptableFormats.length; i++ ) {
247 errorWriter.add("Alternative date pattern", acceptableFormats[i].toString());
248 }
249 }
250 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts a double primitive or java.lang.Double wrapper to
15 * a String.
16 *
17 * @author Joe Walnes
18 */
19 public class DoubleConverter extends AbstractSingleValueConverter {
20
21 public boolean canConvert(Class type) {
22 return type.equals(double.class) || type.equals(Double.class);
23 }
24
25 public Object fromString(String str) {
26 return Double.valueOf(str);
27 }
28
29 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts a float primitive or java.lang.Float wrapper to
15 * a String.
16 *
17 * @author Joe Walnes
18 */
19 public class FloatConverter extends AbstractSingleValueConverter {
20
21 public boolean canConvert(Class type) {
22 return type.equals(float.class) || type.equals(Float.class);
23 }
24
25 public Object fromString(String str) {
26 return Float.valueOf(str);
27 }
28
29 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts an int primitive or java.lang.Integer wrapper to
15 * a String.
16 *
17 * @author Joe Walnes
18 */
19 public class IntConverter extends AbstractSingleValueConverter {
20
21 public boolean canConvert(Class type) {
22 return type.equals(int.class) || type.equals(Integer.class);
23 }
24
25 public Object fromString(String str) {
26 long value = Long.decode(str).longValue();
27 if(value < Integer.MIN_VALUE || value > 0xFFFFFFFFl) {
28 throw new NumberFormatException("For input string: \"" + str + '"');
29 }
30 return new Integer((int)value);
31 }
32
33 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts a long primitive or java.lang.Long wrapper to a String.
15 *
16 * @author Joe Walnes
17 */
18 public class LongConverter extends AbstractSingleValueConverter {
19
20 public boolean canConvert(Class type) {
21 return type.equals(long.class) || type.equals(Long.class);
22 }
23
24 public Object fromString(String str) {
25 int len = str.length();
26 if (len == 0) {
27 throw new NumberFormatException("For input string: \"\"");
28 }
29 if (len < 17) {
30 return Long.decode(str);
31 }
32 char c0 = str.charAt(0);
33 if (c0 != '0' && c0 != '#') {
34 return Long.decode(str);
35 }
36 char c1 = str.charAt(1);
37 final long high;
38 final long low;
39 if (c0 == '#' && len == 17) {
40 high = Long.parseLong(str.substring(1, 9), 16) << 32;
41 low = Long.parseLong(str.substring(9, 17), 16);
42 } else if ((c1 == 'x' || c1 == 'X') && len == 18) {
43 high = Long.parseLong(str.substring(2, 10), 16) << 32;
44 low = Long.parseLong(str.substring(10, 18), 16);
45 } else if (len == 23 && c1 == '1') {
46 high = Long.parseLong(str.substring(1, 12), 8) << 33;
47 low = Long.parseLong(str.substring(12, 23), 8);
48 } else {
49 return Long.decode(str);
50 }
51 final long num = high | low;
52 return new Long(num);
53 }
54
55 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2012 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 03. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
19 import com.thoughtworks.xstream.mapper.Mapper;
20
21 /**
22 * Special converter to signify nulls at the root level.
23 *
24 * @author Joe Walnes
25 */
26 public class NullConverter implements Converter {
27
28 public boolean canConvert(Class type) {
29 return type == null || Mapper.Null.class.isAssignableFrom(type);
30 }
31
32 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
33 ExtendedHierarchicalStreamWriterHelper.startNode(writer, "null", Mapper.Null.class);
34 writer.endNode();
35 }
36
37 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
38 return null;
39 }
40 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts a short primitive or java.lang.Short wrapper to
15 * a String.
16 *
17 * @author Joe Walnes
18 */
19 public class ShortConverter extends AbstractSingleValueConverter {
20
21 public boolean canConvert(Class type) {
22 return type.equals(short.class) || type.equals(Short.class);
23 }
24
25 public Object fromString(String str) {
26 int value = Integer.decode(str).intValue();
27 if(value < Short.MIN_VALUE || value > 0xFFFF) {
28 throw new NumberFormatException("For input string: \"" + str + '"');
29 }
30 return new Short((short)value);
31 }
32
33 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 29. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 /**
14 * Converts the contents of a StringBuffer to XML.
15 *
16 * @author Joe Walnes
17 */
18 public class StringBufferConverter extends AbstractSingleValueConverter {
19
20 public Object fromString(String str) {
21 return new StringBuffer(str);
22 }
23
24 public boolean canConvert(Class type) {
25 return type.equals(StringBuffer.class);
26 }
27 }
0 /*
1 * Copyright (C) 2008 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.basic;
11
12 /**
13 * Converts the contents of a StringBuilder to XML.
14 *
15 * @author J&ouml;rg Schaible
16 */
17 public class StringBuilderConverter extends AbstractSingleValueConverter {
18
19 public Object fromString(String str) {
20 return new StringBuilder(str);
21 }
22
23 public boolean canConvert(Class type) {
24 return type.equals(StringBuilder.class);
25 }
26 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import java.util.Collections;
14 import java.util.Map;
15
16 import com.thoughtworks.xstream.core.util.WeakCache;
17
18
19 /**
20 * Converts a String to a String ;).
21 * <p>
22 * Well ok, it doesn't <i>actually</i> do any conversion. The converter uses by default a map
23 * with weak references to reuse instances of strings that do not exceed a length limit. This
24 * limit is by default 38 characters to cache typical strings containing UUIDs. Only shorter
25 * strings are typically repeated more often in XML values.
26 * </p>
27 *
28 * @author Joe Walnes
29 * @author Rene Schwietzke
30 * @author J&ouml;rg Schaible
31 */
32 public class StringConverter extends AbstractSingleValueConverter {
33
34 private static final int LENGTH_LIMIT = 38;
35
36 /**
37 * A Map to store strings as long as needed to map similar strings onto the same instance
38 * and conserve memory. The map can be set from the outside during construction, so it can
39 * be a LRU map or a weak map, synchronised or not.
40 */
41 private final Map cache;
42 private final int lengthLimit;
43
44 /**
45 * Construct a StringConverter using a map-based cache for strings not exceeding the length limit.
46 *
47 * @param map the map to use for the instances to reuse (may be null to not cache at all)
48 * @param lengthLimit maximum string length of a cached string, -1 to cache all, 0 to turn off the cache
49 * @since 1.4.2
50 */
51 public StringConverter(final Map map, int lengthLimit) {
52 cache = map;
53 this.lengthLimit = lengthLimit;
54 }
55
56 /**
57 * Construct a StringConverter using a map-based cache for strings not exceeding 38 characters.
58 *
59 * @param map the map to use for the instances to reuse (may be null to not cache at all)
60 */
61 public StringConverter(final Map map) {
62 this(map, LENGTH_LIMIT);
63 }
64
65 /**
66 * Construct a StringConverter using a cache with weak references for strings not exceeding the length limit.
67 *
68 * @param lengthLimit maximum string length of a cached string, -1 to cache all, 0 to turn off the cache
69 * @since 1.4.2
70 */
71 public StringConverter(int lengthLimit) {
72 this(Collections.synchronizedMap(new WeakCache()), lengthLimit);
73 }
74
75 /**
76 * Construct a StringConverter using a cache with weak references for strings not exceeding 38 characters.
77 */
78 public StringConverter() {
79 this(LENGTH_LIMIT);
80 }
81
82 public boolean canConvert(final Class type) {
83 return type.equals(String.class);
84 }
85
86 public Object fromString(final String str) {
87 if (cache != null && str != null && (lengthLimit < 0 || str.length() <= lengthLimit)) {
88 String s = (String)cache.get(str);
89
90 if (s == null) {
91 // fill cache
92 cache.put(str, str);
93
94 s = str;
95 }
96
97 return s;
98 } else {
99 return str;
100 }
101 }
102 }
0 /*
1 * Copyright (C) 2010 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 3. August 2010 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.basic;
11
12 import java.net.URI;
13 import java.net.URISyntaxException;
14
15 import com.thoughtworks.xstream.converters.ConversionException;
16
17
18 /**
19 * Converts a java.net.URI to a string.
20 *
21 * @author Carlos Roman
22 */
23 public class URIConverter extends AbstractSingleValueConverter {
24
25 public boolean canConvert(Class type) {
26 return type.equals(URI.class);
27 }
28
29 public Object fromString(String str) {
30 try {
31 return new URI(str);
32 } catch (URISyntaxException e) {
33 throw new ConversionException(e);
34 }
35 }
36 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 25. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14
15 import java.net.MalformedURLException;
16 import java.net.URL;
17
18 /**
19 * Converts a java.net.URL to a string.
20 *
21 * @author J. Matthew Pryor
22 */
23 public class URLConverter extends AbstractSingleValueConverter {
24
25 public boolean canConvert(Class type) {
26 return type.equals(URL.class);
27 }
28
29 public Object fromString(String str) {
30 try {
31 return new URL(str);
32 } catch (MalformedURLException e) {
33 throw new ConversionException(e);
34 }
35 }
36
37 }
0 /*
1 * Copyright (C) 2008 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.basic;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13
14 import java.util.UUID;
15
16
17 /**
18 * Converts a java.util.UUID to a string.
19 *
20 * @author J&ouml;rg Schaible
21 */
22 public class UUIDConverter extends AbstractSingleValueConverter {
23
24 public boolean canConvert(Class type) {
25 return type.equals(UUID.class);
26 }
27
28 public Object fromString(String str) {
29 try {
30 return UUID.fromString(str);
31 } catch(IllegalArgumentException e) {
32 throw new ConversionException("Cannot create UUID instance", e);
33 }
34 }
35
36 }
0 <!--
1 Copyright (C) 2004 Joe Walnes.
2 Copyright (C) 2006, 2007 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 10. May 2004 by Joe Walnes
10 -->
11 <body>
12 <p>Converters for common basic types in Java. These include
13 primitives (int, boolean, etc), wrapper objects (Integer, Boolean, etc),
14 String, StringBuffer, java.util.Date, null, java.net.URL,
15 java.math.BigInteger and java.math.BigDecimal.</p>
16
17 <p>These converters are enabled by default.</p>
18
19 <p>All of the basic converters will convert the item
20 into a single String, with no nested elements.</p>
21 </body>
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
18 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
19 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
20 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 /**
24 * Base helper class for converters that need to handle
25 * collections of items (arrays, Lists, Maps, etc).
26 *
27 * <p>Typically, subclasses of this will converter the outer
28 * structure of the collection, loop through the contents and
29 * call readItem() or writeItem() for each item.</p>
30 *
31 * @author Joe Walnes
32 */
33 public abstract class AbstractCollectionConverter implements Converter {
34
35 private final Mapper mapper;
36
37 public abstract boolean canConvert(Class type);
38
39 public AbstractCollectionConverter(Mapper mapper) {
40 this.mapper = mapper;
41 }
42
43 protected Mapper mapper() {
44 return mapper;
45 }
46
47 public abstract void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context);
48
49 public abstract Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context);
50
51
52
53 protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
54 // PUBLISHED API METHOD! If changing signature, ensure backwards compatibility.
55 if (item == null) {
56 // todo: this is duplicated in TreeMarshaller.start()
57 String name = mapper().serializedClass(null);
58 ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class);
59 writer.endNode();
60 } else {
61 String name = mapper().serializedClass(item.getClass());
62 ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass());
63 context.convertAnother(item);
64 writer.endNode();
65 }
66 }
67
68 protected Object readItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) {
69 Class type = HierarchicalStreams.readClassType(reader, mapper());
70 return context.convertAnother(current, type);
71 }
72
73 protected Object createCollection(Class type) {
74 Class defaultType = mapper().defaultImplementationOf(type);
75 try {
76 return defaultType.newInstance();
77 } catch (InstantiationException e) {
78 throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
79 } catch (IllegalAccessException e) {
80 throw new ConversionException("Cannot instantiate " + defaultType.getName(), e);
81 }
82 }
83 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.MarshallingContext;
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19 import java.lang.reflect.Array;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 /**
25 * Converts an array of objects or primitives to XML, using
26 * a nested child element for each item.
27 *
28 * @author Joe Walnes
29 */
30 public class ArrayConverter extends AbstractCollectionConverter {
31
32 public ArrayConverter(Mapper mapper) {
33 super(mapper);
34 }
35
36 public boolean canConvert(Class type) {
37 return type.isArray();
38 }
39
40 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
41 int length = Array.getLength(source);
42 for (int i = 0; i < length; i++) {
43 Object item = Array.get(source, i);
44 writeItem(item, context, writer);
45 }
46
47 }
48
49 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
50 // read the items from xml into a list
51 List items = new ArrayList();
52 while (reader.hasMoreChildren()) {
53 reader.moveDown();
54 Object item = readItem(reader, context, null); // TODO: arg, what should replace null?
55 items.add(item);
56 reader.moveUp();
57 }
58 // now convertAnother the list into an array
59 // (this has to be done as a separate list as the array size is not
60 // known until all items have been read)
61 Object array = Array.newInstance(context.getRequiredType().getComponentType(), items.size());
62 int i = 0;
63 for (Iterator iterator = items.iterator(); iterator.hasNext();) {
64 Array.set(array, i++, iterator.next());
65 }
66 return array;
67 }
68 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18
19 import java.util.BitSet;
20 import java.util.StringTokenizer;
21
22 /**
23 * Converts a java.util.BitSet to XML, as a compact
24 * comma delimited list of ones and zeros.
25 *
26 * @author Joe Walnes
27 */
28 public class BitSetConverter implements Converter {
29
30 public boolean canConvert(Class type) {
31 return type.equals(BitSet.class);
32 }
33
34 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
35 BitSet bitSet = (BitSet) source;
36 StringBuffer buffer = new StringBuffer();
37 boolean seenFirst = false;
38 for (int i = 0; i < bitSet.length(); i++) {
39 if (bitSet.get(i)) {
40 if (seenFirst) {
41 buffer.append(',');
42 } else {
43 seenFirst = true;
44 }
45 buffer.append(i);
46 }
47 }
48 writer.setValue(buffer.toString());
49 }
50
51 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
52 BitSet result = new BitSet();
53 StringTokenizer tokenizer = new StringTokenizer(reader.getValue(), ",", false);
54 while (tokenizer.hasMoreTokens()) {
55 int index = Integer.parseInt(tokenizer.nextToken());
56 result.set(index);
57 }
58 return result;
59 }
60 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18
19 /**
20 * Converts a char[] to XML, storing the contents as a single
21 * String.
22 *
23 * @author Joe Walnes
24 */
25 public class CharArrayConverter implements Converter {
26
27 public boolean canConvert(Class type) {
28 return type.isArray() && type.getComponentType().equals(char.class);
29 }
30
31 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
32 char[] chars = (char[]) source;
33 writer.setValue(new String(chars));
34 }
35
36 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
37 return reader.getValue().toCharArray();
38 }
39 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013 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 01. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.MarshallingContext;
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.core.JVM;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18 import com.thoughtworks.xstream.mapper.Mapper;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.LinkedList;
25 import java.util.Vector;
26
27 /**
28 * Converts most common Collections (Lists and Sets) to XML, specifying a nested
29 * element for each item.
30 *
31 * <p>Supports java.util.ArrayList, java.util.HashSet,
32 * java.util.LinkedList, java.util.Vector and java.util.LinkedHashSet.</p>
33 *
34 * @author Joe Walnes
35 */
36 public class CollectionConverter extends AbstractCollectionConverter {
37
38 private final Class type;
39
40 public CollectionConverter(Mapper mapper) {
41 this(mapper, null);
42 }
43
44 /**
45 * Construct a CollectionConverter for a special Collection type.
46 * @param mapper the mapper
47 * @param type the Collection type to handle
48 * @since 1.4.5
49 */
50 public CollectionConverter(Mapper mapper, Class type) {
51 super(mapper);
52 this.type = type;
53 if (type != null && !Collection.class.isAssignableFrom(type)) {
54 throw new IllegalArgumentException(type + " not of type " + Collection.class);
55 }
56 }
57
58 public boolean canConvert(Class type) {
59 if (this.type != null) {
60 return type.equals(this.type);
61 }
62 return type.equals(ArrayList.class)
63 || type.equals(HashSet.class)
64 || type.equals(LinkedList.class)
65 || type.equals(Vector.class)
66 || (JVM.is14() && type.getName().equals("java.util.LinkedHashSet"));
67 }
68
69 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
70 Collection collection = (Collection) source;
71 for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
72 Object item = iterator.next();
73 writeItem(item, context, writer);
74 }
75 }
76
77 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
78 Collection collection = (Collection) createCollection(context.getRequiredType());
79 populateCollection(reader, context, collection);
80 return collection;
81 }
82
83 protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection) {
84 populateCollection(reader, context, collection, collection);
85 }
86
87 protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection, Collection target) {
88 while (reader.hasMoreChildren()) {
89 reader.moveDown();
90 addCurrentElementToCollection(reader, context, collection, target);
91 reader.moveUp();
92 }
93 }
94
95 protected void addCurrentElementToCollection(HierarchicalStreamReader reader, UnmarshallingContext context,
96 Collection collection, Collection target) {
97 Object item = readItem(reader, context, collection);
98 target.add(item);
99 }
100
101 protected Object createCollection(Class type) {
102 return super.createCollection(this.type != null ? this.type : type);
103 }
104 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.MarshallingContext;
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18 import com.thoughtworks.xstream.mapper.Mapper;
19
20 import java.util.HashMap;
21 import java.util.Hashtable;
22 import java.util.Iterator;
23 import java.util.Map;
24
25 /**
26 * Converts a java.util.Map to XML, specifying an 'entry'
27 * element with 'key' and 'value' children.
28 * <p>Note: 'key' and 'value' is not the name of the generated tag. The
29 * children are serialized as normal elements and the implementation expects
30 * them in the order 'key'/'value'.</p>
31 * <p>Supports java.util.HashMap, java.util.Hashtable,
32 * java.util.LinkedHashMap and java.util.concurrent.ConcurrentHashMap.</p>
33 *
34 * @author Joe Walnes
35 */
36 public class MapConverter extends AbstractCollectionConverter {
37
38 private final Class type;
39
40 public MapConverter(Mapper mapper) {
41 this(mapper, null);
42 }
43
44 /**
45 * Construct a MapConverter for a special Map type.
46 * @param mapper the mapper
47 * @param type the type to handle
48 * @since 1.4.5
49 */
50 public MapConverter(Mapper mapper, Class type) {
51 super(mapper);
52 this.type = type;
53 if (type != null && !Map.class.isAssignableFrom(type)) {
54 throw new IllegalArgumentException(type + " not of type " + Map.class);
55 }
56 }
57
58 public boolean canConvert(Class type) {
59 if (this.type != null) {
60 return type.equals(this.type);
61 }
62 return type.equals(HashMap.class)
63 || type.equals(Hashtable.class)
64 || type.getName().equals("java.util.LinkedHashMap")
65 || type.getName().equals("java.util.concurrent.ConcurrentHashMap")
66 || type.getName().equals("sun.font.AttributeMap") // Used by java.awt.Font in JDK 6
67 ;
68 }
69
70 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
71 Map map = (Map) source;
72 String entryName = mapper().serializedClass(Map.Entry.class);
73 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
74 Map.Entry entry = (Map.Entry) iterator.next();
75 ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass());
76
77 writeItem(entry.getKey(), context, writer);
78 writeItem(entry.getValue(), context, writer);
79
80 writer.endNode();
81 }
82 }
83
84 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
85 Map map = (Map) createCollection(context.getRequiredType());
86 populateMap(reader, context, map);
87 return map;
88 }
89
90 protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) {
91 populateMap(reader, context, map, map);
92 }
93
94 protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, Map target) {
95 while (reader.hasMoreChildren()) {
96 reader.moveDown();
97 putCurrentEntryIntoMap(reader, context, map, target);
98 reader.moveUp();
99 }
100 }
101
102 protected void putCurrentEntryIntoMap(HierarchicalStreamReader reader, UnmarshallingContext context,
103 Map map, Map target) {
104 reader.moveDown();
105 Object key = readItem(reader, context, map);
106 reader.moveUp();
107
108 reader.moveDown();
109 Object value = readItem(reader, context, map);
110 reader.moveUp();
111
112 target.put(key, value);
113 }
114
115 protected Object createCollection(Class type) {
116 return super.createCollection(this.type != null ? this.type : type);
117 }
118 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 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 23. February 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.core.util.Fields;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19
20 import java.lang.reflect.Field;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.Properties;
24 import java.util.TreeMap;
25
26
27 /**
28 * Special converter for java.util.Properties that stores properties in a more compact form than
29 * java.util.Map.
30 * <p>
31 * Because all entries of a Properties instance are Strings, a single element is used for each
32 * property with two attributes; one for key and one for value.
33 * </p>
34 * <p>
35 * Additionally, default properties are also serialized, if they are present or if a
36 * SecurityManager is set, and it has permissions for SecurityManager.checkPackageAccess,
37 * SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) and
38 * ReflectPermission("suppressAccessChecks").
39 * </p>
40 *
41 * @author Joe Walnes
42 * @author Kevin Ring
43 */
44 public class PropertiesConverter implements Converter {
45
46 private final static Field defaultsField = Fields.locate(Properties.class, Properties.class, false);
47 private final boolean sort;
48
49 public PropertiesConverter() {
50 this(false);
51 }
52
53 public PropertiesConverter(boolean sort) {
54 this.sort = sort;
55 }
56
57 public boolean canConvert(Class type) {
58 return Properties.class == type;
59 }
60
61 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
62 final Properties properties = (Properties) source;
63 Map map = sort ? (Map)new TreeMap(properties) : (Map)properties;
64 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
65 Map.Entry entry = (Map.Entry) iterator.next();
66 writer.startNode("property");
67 writer.addAttribute("name", entry.getKey().toString());
68 writer.addAttribute("value", entry.getValue().toString());
69 writer.endNode();
70 }
71 if (defaultsField != null) {
72 Properties defaults = (Properties)Fields.read(defaultsField, properties);
73 if (defaults != null) {
74 writer.startNode("defaults");
75 marshal(defaults, writer, context);
76 writer.endNode();
77 }
78 }
79 }
80
81 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
82 Properties properties = new Properties();
83 Properties defaults = null;
84 while (reader.hasMoreChildren()) {
85 reader.moveDown();
86 if (reader.getNodeName().equals("defaults")) {
87 defaults = (Properties) unmarshal(reader, context);
88 } else {
89 String name = reader.getAttribute("name");
90 String value = reader.getAttribute("value");
91 properties.setProperty(name, value);
92 }
93 reader.moveUp();
94 }
95 if (defaults == null) {
96 return properties;
97 } else {
98 Properties propertiesWithDefaults = new Properties(defaults);
99 propertiesWithDefaults.putAll(properties);
100 return propertiesWithDefaults;
101 }
102 }
103
104 }
0 /*
1 * Copyright (C) 2011 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 11. October 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.collections;
11
12 import java.util.Collections;
13
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18
19 /**
20 * Converts singleton collections (list and set) to XML, specifying a nested element for the
21 * item.
22 * <p>
23 * Supports Collections.singleton(Object) and Collections.singletonList(Object).
24 * </p>
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.4.2
28 */
29 public class SingletonCollectionConverter extends CollectionConverter {
30
31 private static final Class LIST = Collections.singletonList(Boolean.TRUE).getClass();
32 private static final Class SET = Collections.singleton(Boolean.TRUE).getClass();
33
34 /**
35 * Construct a SingletonCollectionConverter.
36 *
37 * @param mapper the mapper
38 * @since 1.4.2
39 */
40 public SingletonCollectionConverter(Mapper mapper) {
41 super(mapper);
42 }
43
44 public boolean canConvert(Class type) {
45 return LIST == type || SET == type;
46 }
47
48 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
49 reader.moveDown();
50 Object item = readItem(reader, context, null);
51 reader.moveUp();
52 return context.getRequiredType() == LIST
53 ? (Object)Collections.singletonList(item)
54 : (Object)Collections.singleton(item);
55 }
56 }
0 /*
1 * Copyright (C) 2011 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 11. October 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.collections;
11
12 import java.util.Collections;
13
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 /**
19 * Converts a singleton map to XML, specifying an 'entry'
20 * element with 'key' and 'value' children.
21 * <p>Note: 'key' and 'value' is not the name of the generated tag. The
22 * children are serialized as normal elements and the implementation expects
23 * them in the order 'key'/'value'.</p>
24 * <p>Supports Collections.singletonMap.</p>
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.4.2
28 */
29 public class SingletonMapConverter extends MapConverter {
30
31 private static final Class MAP = Collections.singletonMap(Boolean.TRUE, null).getClass();
32
33 /**
34 * Construct a SingletonMapConverter.
35 * @param mapper
36 * @since 1.4.2
37 */
38 public SingletonMapConverter(Mapper mapper) {
39 super(mapper);
40 }
41
42 public boolean canConvert(Class type) {
43 return MAP == type;
44 }
45
46 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
47 reader.moveDown();
48 reader.moveDown();
49 Object key = readItem(reader, context, null);
50 reader.moveUp();
51
52 reader.moveDown();
53 Object value = readItem(reader, context, null);
54 reader.moveUp();
55 reader.moveUp();
56
57 return Collections.singletonMap(key, value);
58 }
59
60 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013 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 08. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.core.JVM;
17 import com.thoughtworks.xstream.core.util.Fields;
18 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
19 import com.thoughtworks.xstream.core.util.PresortedMap;
20 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
21 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
22 import com.thoughtworks.xstream.mapper.Mapper;
23
24 import java.lang.reflect.Field;
25 import java.util.Comparator;
26 import java.util.SortedMap;
27 import java.util.TreeMap;
28
29 /**
30 * Converts a java.util.TreeMap to XML, and serializes
31 * the associated java.util.Comparator. The converter
32 * assumes that the entries in the XML are already sorted
33 * according the comparator.
34 *
35 * @author Joe Walnes
36 * @author J&ouml;rg Schaible
37 */
38 public class TreeMapConverter extends MapConverter {
39
40 private static final class NullComparator extends Mapper.Null implements Comparator {
41 public int compare(Object o1, Object o2) {
42 Comparable c1 = (Comparable)o1;
43 Comparable c2 = (Comparable)o2;
44 return c1.compareTo(o2);
45 }
46 }
47
48 private final static Comparator NULL_MARKER = new NullComparator();
49 private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false);
50
51 public TreeMapConverter(Mapper mapper) {
52 super(mapper, TreeMap.class);
53 }
54
55 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
56 SortedMap sortedMap = (SortedMap) source;
57 marshalComparator(sortedMap.comparator(), writer, context);
58 super.marshal(source, writer, context);
59 }
60
61 protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer,
62 MarshallingContext context) {
63 if (comparator != null) {
64 writer.startNode("comparator");
65 writer.addAttribute(mapper().aliasForSystemAttribute("class"),
66 mapper().serializedClass(comparator.getClass()));
67 context.convertAnother(comparator);
68 writer.endNode();
69 }
70 }
71
72 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
73 TreeMap result = comparatorField != null ? new TreeMap() : null;
74 final Comparator comparator = unmarshalComparator(reader, context, result);
75 if (result == null) {
76 result = comparator == null ? new TreeMap() : new TreeMap(comparator);
77 }
78 populateTreeMap(reader, context, result, comparator);
79 return result;
80 }
81
82 protected Comparator unmarshalComparator(HierarchicalStreamReader reader,
83 UnmarshallingContext context, TreeMap result) {
84 final Comparator comparator;
85 if (reader.hasMoreChildren()) {
86 reader.moveDown();
87 if (reader.getNodeName().equals("comparator")) {
88 Class comparatorClass = HierarchicalStreams.readClassType(reader, mapper());
89 comparator = (Comparator) context.convertAnother(result, comparatorClass);
90 } else if (reader.getNodeName().equals("no-comparator")) { // pre 1.4 format
91 comparator = null;
92 } else {
93 // we are already within the first entry
94 return NULL_MARKER;
95 }
96 reader.moveUp();
97 } else {
98 comparator = null;
99 }
100 return comparator;
101 }
102
103 protected void populateTreeMap(HierarchicalStreamReader reader, UnmarshallingContext context,
104 TreeMap result, Comparator comparator) {
105 boolean inFirstElement = comparator == NULL_MARKER;
106 if (inFirstElement) {
107 comparator = null;
108 }
109 SortedMap sortedMap = new PresortedMap(comparator != null && JVM.hasOptimizedTreeMapPutAll() ? comparator : null);
110 if (inFirstElement) {
111 // we are already within the first entry
112 putCurrentEntryIntoMap(reader, context, result, sortedMap);
113 reader.moveUp();
114 }
115 populateMap(reader, context, result, sortedMap);
116 try {
117 if (JVM.hasOptimizedTreeMapPutAll()) {
118 if (comparator != null && comparatorField != null) {
119 comparatorField.set(result, comparator);
120 }
121 result.putAll(sortedMap); // internal optimization will not call comparator
122 } else if (comparatorField != null) {
123 comparatorField.set(result, sortedMap.comparator());
124 result.putAll(sortedMap); // "sort" by index
125 comparatorField.set(result, comparator);
126 } else {
127 result.putAll(sortedMap); // will use comparator for already sorted map
128 }
129 } catch (final IllegalAccessException e) {
130 throw new ConversionException("Cannot set comparator of TreeMap", e);
131 }
132 }
133 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 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 08. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.core.JVM;
17 import com.thoughtworks.xstream.core.util.Fields;
18 import com.thoughtworks.xstream.core.util.PresortedSet;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import java.lang.reflect.Field;
24 import java.util.AbstractList;
25 import java.util.Comparator;
26 import java.util.Map;
27 import java.util.SortedMap;
28 import java.util.SortedSet;
29 import java.util.TreeMap;
30 import java.util.TreeSet;
31
32 /**
33 * Converts a java.util.TreeSet to XML, and serializes
34 * the associated java.util.Comparator. The converter
35 * assumes that the elements in the XML are already sorted
36 * according the comparator.
37 *
38 * @author Joe Walnes
39 * @author J&ouml;rg Schaible
40 */
41 public class TreeSetConverter extends CollectionConverter {
42 private transient TreeMapConverter treeMapConverter;
43 private final static Field sortedMapField;
44 private final static Object constantValue;
45 static {
46 Object value = null;
47 sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null;
48 if (sortedMapField != null) {
49 TreeSet set = new TreeSet();
50 set.add("1");
51 set.add("2");
52
53 Map backingMap = null;
54 try {
55 backingMap = (Map)sortedMapField.get(set);
56 } catch (final IllegalAccessException e) {
57 // give up;
58 }
59 if (backingMap != null) {
60 Object[] values = backingMap.values().toArray();
61 if (values[0] == values[1]) {
62 value = values[0];
63 }
64 }
65 } else {
66 Field valueField = Fields.locate(TreeSet.class, Object.class, true);
67 if (valueField != null) {
68 try {
69 value = valueField.get(null);
70 } catch (final IllegalAccessException e) {
71 // give up;
72 }
73 }
74 }
75 constantValue = value;
76 }
77
78 public TreeSetConverter(Mapper mapper) {
79 super(mapper, TreeSet.class);
80 readResolve();
81 }
82
83 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
84 SortedSet sortedSet = (SortedSet) source;
85 treeMapConverter.marshalComparator(sortedSet.comparator(), writer, context);
86 super.marshal(source, writer, context);
87 }
88
89 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
90 TreeSet result = null;
91 final TreeMap treeMap;
92 Comparator unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null);
93 boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null;
94 Comparator comparator = inFirstElement ? null : unmarshalledComparator;
95 if (sortedMapField != null) {
96 TreeSet possibleResult = comparator == null ? new TreeSet() : new TreeSet(comparator);
97 Object backingMap = null;
98 try {
99 backingMap = sortedMapField.get(possibleResult);
100 } catch (IllegalAccessException e) {
101 throw new ConversionException("Cannot get backing map of TreeSet", e);
102 }
103 if (backingMap instanceof TreeMap) {
104 treeMap = (TreeMap)backingMap;
105 result = possibleResult;
106 } else {
107 treeMap = null;
108 }
109 } else {
110 treeMap = null;
111 }
112 if (treeMap == null) {
113 final PresortedSet set = new PresortedSet(comparator);
114 result = comparator == null ? new TreeSet() : new TreeSet(comparator);
115 if (inFirstElement) {
116 // we are already within the first element
117 addCurrentElementToCollection(reader, context, result, set);
118 reader.moveUp();
119 }
120 populateCollection(reader, context, result, set);
121 if (set.size() > 0) {
122 result.addAll(set); // comparator will not be called if internally optimized
123 }
124 } else {
125 treeMapConverter.populateTreeMap(reader, context, treeMap, unmarshalledComparator);
126 }
127 return result;
128 }
129
130 private Object readResolve() {
131 treeMapConverter = new TreeMapConverter(mapper()) {
132
133 protected void populateMap(HierarchicalStreamReader reader,
134 UnmarshallingContext context, Map map, final Map target) {
135 populateCollection(reader, context, new AbstractList() {
136 public boolean add(Object object) {
137 return target.put(object, constantValue != null ? constantValue : object) != null;
138 }
139
140 public Object get(int location) {
141 return null;
142 }
143
144 public int size() {
145 return target.size();
146 }
147 });
148 }
149
150 protected void putCurrentEntryIntoMap(HierarchicalStreamReader reader, UnmarshallingContext context,
151 Map map, Map target) {
152 Object key = readItem(reader, context, map);
153 target.put(key, key);
154 }
155 };
156 return this;
157 }
158 }
0 <!--
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 10. May 2004 by Joe Walnes
10 -->
11 <body>
12 <p>Converters for collection objects that write their items as
13 nested elements, such as arrays, Lists, Sets and Maps.</p>
14
15 <p>All the converters in this package are enabled by default.</p>
16 </body>
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2013 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 18. March 2005 by Joe Walnes
10 */
11
12 // ***** READ THIS *****
13 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
14 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
15
16 package com.thoughtworks.xstream.converters.enums;
17
18 import com.thoughtworks.xstream.converters.Converter;
19 import com.thoughtworks.xstream.converters.MarshallingContext;
20 import com.thoughtworks.xstream.converters.UnmarshallingContext;
21 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
22 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
23
24 /**
25 * Converter for JDK 1.5 enums. Combined with EnumMapper this also deals with polymorphic enums.
26 *
27 * @author Eric Snell
28 * @author Bryan Coleman
29 */
30 public class EnumConverter implements Converter {
31
32 public boolean canConvert(Class type) {
33 return type.isEnum() || Enum.class.isAssignableFrom(type);
34 }
35
36 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
37 writer.setValue(((Enum) source).name());
38 }
39
40 @SuppressWarnings("unchecked")
41 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
42 Class type = context.getRequiredType();
43 if (type.getSuperclass() != Enum.class) {
44 type = type.getSuperclass(); // polymorphic enums
45 }
46 String name = reader.getValue();
47 try {
48 return Enum.valueOf(type, name);
49 } catch (IllegalArgumentException e) {
50 // failed to find it, do a case insensitive match
51 for (Enum c : (Enum[])type.getEnumConstants())
52 if (c.name().equalsIgnoreCase(name))
53 return c;
54 // all else failed
55 throw e;
56 }
57 }
58
59 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013 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 06. April 2005 by Joe Walnes
10 */
11
12 // ***** READ THIS *****
13 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
14 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
15
16 package com.thoughtworks.xstream.converters.enums;
17
18 import com.thoughtworks.xstream.converters.collections.MapConverter;
19 import com.thoughtworks.xstream.converters.ConversionException;
20 import com.thoughtworks.xstream.converters.MarshallingContext;
21 import com.thoughtworks.xstream.converters.UnmarshallingContext;
22 import com.thoughtworks.xstream.mapper.Mapper;
23 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
24 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
25 import com.thoughtworks.xstream.core.util.Fields;
26
27 import java.util.EnumMap;
28 import java.lang.reflect.Field;
29
30 /**
31 * Serializes an Java 5 EnumMap, including the type of Enum it's for. If a SecurityManager is set, the converter will only work with permissions
32 * for SecurityManager.checkPackageAccess, SecurityManager.checkMemberAccess(this, EnumSet.MEMBER)
33 * and ReflectPermission("suppressAccessChecks").
34 *
35 * @author Joe Walnes
36 */
37 public class EnumMapConverter extends MapConverter {
38
39 private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false);
40
41 public EnumMapConverter(Mapper mapper) {
42 super(mapper);
43 }
44
45 public boolean canConvert(Class type) {
46 return typeField != null && type == EnumMap.class;
47 }
48
49 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
50 Class type = (Class) Fields.read(typeField, source);
51 String attributeName = mapper().aliasForSystemAttribute("enum-type");
52 if (attributeName != null) {
53 writer.addAttribute(attributeName, mapper().serializedClass(type));
54 }
55 super.marshal(source, writer, context);
56 }
57
58 @SuppressWarnings("unchecked")
59 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
60 String attributeName = mapper().aliasForSystemAttribute("enum-type");
61 if (attributeName == null) {
62 throw new ConversionException("No EnumType specified for EnumMap");
63 }
64 Class type = mapper().realClass(reader.getAttribute(attributeName));
65 EnumMap map = new EnumMap(type);
66 populateMap(reader, context, map);
67 return map;
68 }
69 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 06. April 2005 by Joe Walnes
10 */
11
12 // ***** READ THIS *****
13 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
14 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
15
16 package com.thoughtworks.xstream.converters.enums;
17
18 import com.thoughtworks.xstream.converters.ConversionException;
19 import com.thoughtworks.xstream.converters.Converter;
20 import com.thoughtworks.xstream.converters.MarshallingContext;
21 import com.thoughtworks.xstream.converters.UnmarshallingContext;
22 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
23 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
24 import com.thoughtworks.xstream.mapper.Mapper;
25 import com.thoughtworks.xstream.core.util.Fields;
26
27 import java.lang.reflect.Field;
28 import java.util.EnumSet;
29 import java.util.Iterator;
30
31 /**
32 * Serializes a Java 5 EnumSet. If a SecurityManager is set, the converter will only work with permissions
33 * for SecurityManager.checkPackageAccess, SecurityManager.checkMemberAccess(this, EnumSet.MEMBER)
34 * and ReflectPermission("suppressAccessChecks").
35 *
36 * @author Joe Walnes
37 * @author J&ouml;rg Schaible
38 */
39 public class EnumSetConverter implements Converter {
40
41 private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false);
42 private final Mapper mapper;
43
44 public EnumSetConverter(Mapper mapper) {
45 this.mapper = mapper;
46 }
47
48 public boolean canConvert(Class type) {
49 return typeField != null && EnumSet.class.isAssignableFrom(type);
50 }
51
52 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
53 EnumSet set = (EnumSet) source;
54 Class enumTypeForSet = (Class) Fields.read(typeField, set);
55 String attributeName = mapper.aliasForSystemAttribute("enum-type");
56 if (attributeName != null) {
57 writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet));
58 }
59 writer.setValue(joinEnumValues(set));
60 }
61
62 private String joinEnumValues(EnumSet set) {
63 boolean seenFirst = false;
64 StringBuffer result = new StringBuffer();
65 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
66 Enum value = (Enum) iterator.next();
67 if (seenFirst) {
68 result.append(',');
69 } else {
70 seenFirst = true;
71 }
72 result.append(value.name());
73 }
74 return result.toString();
75 }
76
77 @SuppressWarnings("unchecked")
78 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
79 String attributeName = mapper.aliasForSystemAttribute("enum-type");
80 if (attributeName == null) {
81 throw new ConversionException("No EnumType specified for EnumSet");
82 }
83 Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName));
84 EnumSet set = EnumSet.noneOf(enumTypeForSet);
85 String[] enumValues = reader.getValue().split(",");
86 for (int i = 0; i < enumValues.length; i++) {
87 String enumValue = enumValues[i];
88 if(enumValue.length() > 0) {
89 set.add(Enum.valueOf(enumTypeForSet, enumValue));
90 }
91 }
92 return set;
93 }
94
95 }
0 /*
1 * Copyright (C) 2008, 2009, 2010, 2013 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 12. February 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
13
14
15 /**
16 * A single value converter for a special enum type. Converter is internally automatically
17 * instantiated for enum types.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.3
21 */
22 public class EnumSingleValueConverter extends AbstractSingleValueConverter {
23
24 private final Class<? extends Enum> enumType;
25
26 public EnumSingleValueConverter(Class<? extends Enum> type) {
27 if (!Enum.class.isAssignableFrom(type) && type != Enum.class) {
28 throw new IllegalArgumentException("Converter can only handle defined enums");
29 }
30 enumType = type;
31 }
32
33 @Override
34 public boolean canConvert(Class type) {
35 return enumType.isAssignableFrom(type);
36 }
37
38 @Override
39 public String toString(Object obj) {
40 return Enum.class.cast(obj).name();
41 }
42
43 @Override
44 public Object fromString(String str) {
45 @SuppressWarnings("unchecked")
46 Enum result = Enum.valueOf(enumType, str);
47 return result;
48 }
49 }
0 /*
1 * Copyright (C) 2013 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 14. March 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 import java.util.EnumMap;
13 import java.util.EnumSet;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.Map;
17
18 import com.thoughtworks.xstream.converters.ConversionException;
19 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
20
21
22 /**
23 * A single value converter for a special enum type using its string representation.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4.5
27 */
28 public class EnumToStringConverter<T extends Enum<T>> extends AbstractSingleValueConverter {
29
30 private final Class<T> enumType;
31 private final Map<String, T> strings;
32 private final EnumMap<T, String> values;
33
34 public EnumToStringConverter(Class<T> type) {
35 this(type, extractStringMap(type), null);
36 }
37
38 public EnumToStringConverter(Class<T> type, Map<String, T> strings) {
39 this(type, strings, buildValueMap(type, strings));
40 }
41
42 private EnumToStringConverter(
43 Class<T> type, Map<String, T> strings, EnumMap<T, String> values) {
44 enumType = type;
45 this.strings = strings;
46 this.values = values;
47 }
48
49 private static <T extends Enum<T>> Map<String, T> extractStringMap(Class<T> type) {
50 checkType(type);
51 EnumSet<T> values = EnumSet.allOf(type);
52 Map<String, T> strings = new HashMap<String, T>(values.size());
53 for (T value : values) {
54 if (strings.put(value.toString(), value) != null) {
55 throw new IllegalArgumentException("Enum type "
56 + type.getName()
57 + " does not have unique string representations for its values");
58 }
59 }
60 return strings;
61 }
62
63 private static <T> void checkType(Class<T> type) {
64 if (!Enum.class.isAssignableFrom(type) && type != Enum.class) {
65 throw new IllegalArgumentException("Converter can only handle enum types");
66 }
67 }
68
69 private static <T extends Enum<T>> EnumMap<T, String> buildValueMap(Class<T> type,
70 Map<String, T> strings) {
71 EnumMap<T, String> values = new EnumMap<T, String>(type);
72 for (Map.Entry<String, T> entry : strings.entrySet()) {
73 values.put(entry.getValue(), entry.getKey());
74 }
75 return values;
76 }
77
78 @Override
79 public boolean canConvert(Class type) {
80 return enumType.isAssignableFrom(type);
81 }
82
83 @Override
84 public String toString(Object obj) {
85 Enum value = Enum.class.cast(obj);
86 return values == null ? value.toString() : values.get(value);
87 }
88
89 @Override
90 public Object fromString(String str) {
91 if (str == null) {
92 return null;
93 }
94 T result = strings.get(str);
95 if (result == null) {
96 throw new ConversionException("Invalid string representation for enum type "
97 + enumType.getName()
98 + ": <"
99 + str
100 + ">");
101 }
102 return result;
103 }
104 }
0 /*
1 * Copyright (C) 2006, 2007 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 07. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
13
14 import java.nio.charset.Charset;
15
16 /**
17 * Converts a java.nio.charset.Carset to a string.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.2
21 */
22 public class CharsetConverter extends AbstractSingleValueConverter {
23
24 public boolean canConvert(Class type) {
25 return Charset.class.isAssignableFrom(type);
26 }
27
28 public String toString(Object obj) {
29 return obj == null ? null : ((Charset)obj).name();
30 }
31
32
33 public Object fromString(String str) {
34 return Charset.forName(str);
35 }
36 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 01. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19
20 import java.awt.Color;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 /**
25 * Converts a java.awt.Color to XML, using four nested elements:
26 * red, green, blue, alpha.
27 *
28 * @author Joe Walnes
29 */
30 public class ColorConverter implements Converter {
31
32 public boolean canConvert(Class type) {
33 // String comparison is used here because Color.class loads the class which in turns instantiates AWT,
34 // which is nasty if you don't want it.
35 return type.getName().equals("java.awt.Color");
36 }
37
38 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
39 Color color = (Color) source;
40 write("red", color.getRed(), writer);
41 write("green", color.getGreen(), writer);
42 write("blue", color.getBlue(), writer);
43 write("alpha", color.getAlpha(), writer);
44 }
45
46 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
47 Map elements = new HashMap();
48 while (reader.hasMoreChildren()) {
49 reader.moveDown();
50 elements.put(reader.getNodeName(), Integer.valueOf(reader.getValue()));
51 reader.moveUp();
52 }
53 return new Color(((Integer) elements.get("red")).intValue(),
54 ((Integer) elements.get("green")).intValue(),
55 ((Integer) elements.get("blue")).intValue(),
56 ((Integer) elements.get("alpha")).intValue());
57 }
58
59 private void write(String fieldName, int value, HierarchicalStreamWriter writer) {
60 ExtendedHierarchicalStreamWriterHelper.startNode(writer, fieldName, int.class);
61 writer.setValue(String.valueOf(value));
62 writer.endNode();
63 }
64
65 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.util.Currency;
14
15 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
16
17 /**
18 * Converts a java.util.Currency to String. Despite the name of this class, it has nothing to do with converting
19 * currencies between exchange rates! It makes sense in the context of XStream.
20 *
21 * @author Jose A. Illescas
22 * @author Joe Walnes
23 */
24 public class CurrencyConverter extends AbstractSingleValueConverter {
25
26 public boolean canConvert(Class type) {
27 return type.equals(Currency.class);
28 }
29
30 public Object fromString(String str) {
31 return Currency.getInstance(str);
32 }
33
34 }
0 /*
1 * Copyright (C) 2007, 2008, 2011 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.09.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
13
14 import javax.xml.datatype.DatatypeConfigurationException;
15 import javax.xml.datatype.DatatypeFactory;
16 import javax.xml.datatype.Duration;
17
18
19 /**
20 * A Converter for the XML Schema datatype <a
21 * href="http://www.w3.org/TR/xmlschema-2/#duration">duration</a> and the Java type
22 * {@link Duration}. The implementation uses a {@link DatatypeFactory} to create Duration
23 * objects. If no factory is provided and the instantiation of the internal factory fails with a
24 * {@link DatatypeConfigurationException}, the converter will not claim the responsibility for
25 * Duration objects.
26 *
27 * @author John Kristian
28 * @author J&ouml;rg Schaible
29 * @since 1.3
30 */
31 public class DurationConverter extends AbstractSingleValueConverter {
32 private final DatatypeFactory factory;
33
34 public DurationConverter() {
35 this(new Object() {
36 DatatypeFactory getFactory() {
37 try {
38 return DatatypeFactory.newInstance();
39 } catch (final DatatypeConfigurationException e) {
40 return null;
41 }
42 }
43 }.getFactory());
44 }
45
46 public DurationConverter(DatatypeFactory factory) {
47 this.factory = factory;
48 }
49
50 public boolean canConvert(Class c) {
51 return factory != null && Duration.class.isAssignableFrom(c);
52 }
53
54 public Object fromString(String s) {
55 return factory.newDuration(s);
56 }
57 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013 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 25. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.core.ClassLoaderReference;
18 import com.thoughtworks.xstream.core.util.Fields;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21 import com.thoughtworks.xstream.mapper.DynamicProxyMapper;
22 import com.thoughtworks.xstream.mapper.Mapper;
23
24 import java.lang.reflect.Field;
25 import java.lang.reflect.InvocationHandler;
26 import java.lang.reflect.Method;
27 import java.lang.reflect.Proxy;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32 * Converts a dynamic proxy to XML, storing the implemented
33 * interfaces and handler.
34 *
35 * @author Joe Walnes
36 */
37 public class DynamicProxyConverter implements Converter {
38
39 private ClassLoaderReference classLoaderReference;
40 private Mapper mapper;
41 private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false);
42 private static final InvocationHandler DUMMY = new InvocationHandler() {
43 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
44 return null;
45 }
46 };
47
48 /**
49 * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)}
50 */
51 public DynamicProxyConverter(Mapper mapper) {
52 this(mapper, DynamicProxyConverter.class.getClassLoader());
53 }
54
55 /**
56 * Construct a DynamicProxyConverter.
57 * @param mapper the Mapper chain
58 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
59 * @since 1.4.5
60 */
61 public DynamicProxyConverter(Mapper mapper, ClassLoaderReference classLoaderReference) {
62 this.classLoaderReference = classLoaderReference;
63 this.mapper = mapper;
64 }
65
66 /**
67 * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)}
68 */
69 public DynamicProxyConverter(Mapper mapper, ClassLoader classLoader) {
70 this(mapper,new ClassLoaderReference(classLoader));
71 }
72
73 public boolean canConvert(Class type) {
74 return type.equals(DynamicProxyMapper.DynamicProxy.class) || Proxy.isProxyClass(type);
75 }
76
77 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
78 InvocationHandler invocationHandler = Proxy.getInvocationHandler(source);
79 addInterfacesToXml(source, writer);
80 writer.startNode("handler");
81 String attributeName = mapper.aliasForSystemAttribute("class");
82 if (attributeName != null) {
83 writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass()));
84 }
85 context.convertAnother(invocationHandler);
86 writer.endNode();
87 }
88
89 private void addInterfacesToXml(Object source, HierarchicalStreamWriter writer) {
90 Class[] interfaces = source.getClass().getInterfaces();
91 for (int i = 0; i < interfaces.length; i++) {
92 Class currentInterface = interfaces[i];
93 writer.startNode("interface");
94 writer.setValue(mapper.serializedClass(currentInterface));
95 writer.endNode();
96 }
97 }
98
99 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
100 List interfaces = new ArrayList();
101 InvocationHandler handler = null;
102 Class handlerType = null;
103 while (reader.hasMoreChildren()) {
104 reader.moveDown();
105 String elementName = reader.getNodeName();
106 if (elementName.equals("interface")) {
107 interfaces.add(mapper.realClass(reader.getValue()));
108 } else if (elementName.equals("handler")) {
109 String attributeName = mapper.aliasForSystemAttribute("class");
110 if (attributeName != null) {
111 handlerType = mapper.realClass(reader.getAttribute(attributeName));
112 break;
113 }
114 }
115 reader.moveUp();
116 }
117 if (handlerType == null) {
118 throw new ConversionException("No InvocationHandler specified for dynamic proxy");
119 }
120 Class[] interfacesAsArray = new Class[interfaces.size()];
121 interfaces.toArray(interfacesAsArray);
122 Object proxy = null;
123 if (HANDLER != null) { // we will not be able to resolve references to the proxy
124 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, DUMMY);
125 }
126 handler = (InvocationHandler) context.convertAnother(proxy, handlerType);
127 reader.moveUp();
128 if (HANDLER != null) {
129 Fields.write(HANDLER, proxy, handler);
130 } else {
131 proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, handler);
132 }
133 return proxy;
134 }
135 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010 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 03. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.SingleValueConverter;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.converters.basic.ByteConverter;
18 import com.thoughtworks.xstream.core.util.Base64Encoder;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 /**
27 * Converts a byte array to a single Base64 encoding string.
28 *
29 * @author Joe Walnes
30 * @author J&ouml;rg Schaible
31 */
32 public class EncodedByteArrayConverter implements Converter, SingleValueConverter {
33
34 private static final Base64Encoder base64 = new Base64Encoder();
35 private static final ByteConverter byteConverter = new ByteConverter();
36
37 public boolean canConvert(Class type) {
38 return type.isArray() && type.getComponentType().equals(byte.class);
39 }
40
41 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
42 writer.setValue(toString(source));
43 }
44
45 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
46 String data = reader.getValue(); // needs to be called before hasMoreChildren.
47 if (!reader.hasMoreChildren()) {
48 return fromString(data);
49 } else {
50 // backwards compatibility ... try to unmarshal byte arrays that haven't been encoded
51 return unmarshalIndividualByteElements(reader, context);
52 }
53 }
54
55 private Object unmarshalIndividualByteElements(HierarchicalStreamReader reader, UnmarshallingContext context) {
56 List bytes = new ArrayList(); // have to create a temporary list because don't know the size of the array
57 boolean firstIteration = true;
58 while (firstIteration || reader.hasMoreChildren()) { // hangover from previous hasMoreChildren
59 reader.moveDown();
60 bytes.add(byteConverter.fromString(reader.getValue()));
61 reader.moveUp();
62 firstIteration = false;
63 }
64 // copy into real array
65 byte[] result = new byte[bytes.size()];
66 int i = 0;
67 for (Iterator iterator = bytes.iterator(); iterator.hasNext();) {
68 Byte b = (Byte) iterator.next();
69 result[i] = b.byteValue();
70 i++;
71 }
72 return result;
73 }
74
75 public String toString(Object obj) {
76 return base64.encode((byte[]) obj);
77 }
78
79 public Object fromString(String str) {
80 return base64.decode(str);
81 }
82 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 13. January 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14
15 import java.io.File;
16
17 /**
18 * This converter will take care of storing and retrieving File with either
19 * an absolute path OR a relative path depending on how they were created.
20 *
21 * @author Joe Walnes
22 */
23 public class FileConverter extends AbstractSingleValueConverter {
24
25 public boolean canConvert(Class type) {
26 return type.equals(File.class);
27 }
28
29 public Object fromString(String str) {
30 return new File(str);
31 }
32
33 public String toString(Object obj) {
34 return ((File) obj).getPath();
35 }
36
37 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 08. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.SingleValueConverter;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.core.JVM;
18 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import javax.swing.plaf.FontUIResource;
24
25 import java.awt.Font;
26 import java.awt.font.TextAttribute;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.Map;
31
32 public class FontConverter implements Converter {
33
34 private final SingleValueConverter textAttributeConverter;
35 private final Mapper mapper;
36
37 /**
38 * Constructs a FontConverter.
39 * @deprecated As of 1.4.5
40 */
41 public FontConverter() {
42 this(null);
43 }
44
45 /**
46 * Constructs a FontConverter.
47 * @param mapper
48 * @since 1.4.5
49 */
50 public FontConverter(Mapper mapper) {
51 this.mapper = mapper;
52 if (mapper == null) {
53 textAttributeConverter = null;
54 } else {
55 textAttributeConverter = new TextAttributeConverter();
56 }
57 }
58
59 public boolean canConvert(Class type) {
60 // String comparison is used here because Font.class loads the class which in turns instantiates AWT,
61 // which is nasty if you don't want it.
62 return type.getName().equals("java.awt.Font") || type.getName().equals("javax.swing.plaf.FontUIResource");
63 }
64
65 public void marshal(Object source, HierarchicalStreamWriter writer,
66 MarshallingContext context) {
67 Font font = (Font)source;
68 Map attributes = font.getAttributes();
69 if (mapper != null) {
70 String classAlias = mapper.aliasForSystemAttribute("class");
71 for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
72 Map.Entry entry = (Map.Entry)iter.next();
73 String name = textAttributeConverter.toString(entry.getKey());
74 Object value = entry.getValue();
75 Class type = value != null ? value.getClass() : Mapper.Null.class;
76 ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
77 writer.addAttribute(classAlias, mapper.serializedClass(type));
78 if (value != null) {
79 context.convertAnother(value);
80 }
81 writer.endNode();
82 }
83 } else {
84 writer.startNode("attributes"); // <attributes>
85 context.convertAnother(attributes);
86 writer.endNode(); // </attributes>
87 }
88 }
89
90 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
91 final Map attributes;
92 if (reader.hasMoreChildren()) {
93 reader.moveDown();
94 if (!reader.getNodeName().equals("attributes")) {
95 String classAlias = mapper.aliasForSystemAttribute("class");
96 attributes = new HashMap();
97 do {
98 if (!attributes.isEmpty()) {
99 reader.moveDown();
100 }
101 Class type = mapper.realClass(reader.getAttribute(classAlias));
102 TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName());
103 Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type);
104 attributes.put(attribute, value);
105 reader.moveUp();
106 } while(reader.hasMoreChildren());
107 } else {
108 // in <attributes>
109 attributes = (Map)context.convertAnother(null, Map.class);
110 reader.moveUp(); // out of </attributes>
111 }
112 } else {
113 attributes = Collections.EMPTY_MAP;
114 }
115 if (!JVM.is16()) {
116 for (Iterator iter = attributes.values().iterator(); iter.hasNext(); ) {
117 if (iter.next() == null) {
118 iter.remove();
119 }
120 }
121 }
122 Font font = Font.getFont(attributes);
123 if (context.getRequiredType() == FontUIResource.class) {
124 return new FontUIResource(font);
125 } else {
126 return font;
127 }
128 }
129 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19
20 import java.util.Date;
21 import java.util.GregorianCalendar;
22 import java.util.TimeZone;
23
24 /**
25 * Converts a java.util.GregorianCalendar to XML. Note that although it currently only contains one field, it nests
26 * it inside a child element, to allow for other fields to be stored in the future.
27 *
28 * @author Joe Walnes
29 * @author J&ouml;rg Schaible
30 */
31 public class GregorianCalendarConverter implements Converter {
32
33 public boolean canConvert(Class type) {
34 return type.equals(GregorianCalendar.class);
35 }
36
37 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
38 GregorianCalendar calendar = (GregorianCalendar) source;
39 ExtendedHierarchicalStreamWriterHelper.startNode(writer, "time", long.class);
40 long timeInMillis = calendar.getTime().getTime(); // calendar.getTimeInMillis() not available under JDK 1.3
41 writer.setValue(String.valueOf(timeInMillis));
42 writer.endNode();
43 ExtendedHierarchicalStreamWriterHelper.startNode(writer, "timezone", String.class);
44 writer.setValue(calendar.getTimeZone().getID());
45 writer.endNode();
46 }
47
48 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
49 reader.moveDown();
50 long timeInMillis = Long.parseLong(reader.getValue());
51 reader.moveUp();
52 final String timeZone;
53 if (reader.hasMoreChildren()) {
54 reader.moveDown();
55 timeZone = reader.getValue();
56 reader.moveUp();
57 } else { // backward compatibility to XStream 1.1.2 and below
58 timeZone = TimeZone.getDefault().getID();
59 }
60
61 GregorianCalendar result = new GregorianCalendar();
62 result.setTimeZone(TimeZone.getTimeZone(timeZone));
63 result.setTime(new Date(timeInMillis)); // calendar.setTimeInMillis() not available under JDK 1.3
64
65 return result;
66 }
67
68 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 22. November 2004 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.util.Calendar;
14 import java.util.Date;
15
16
17 /**
18 * A DateConverter conforming to the ISO8601 standard.
19 * http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=26780
20 *
21 * @author Mauro Talevi
22 * @author J&ouml;rg Schaible
23 */
24 public class ISO8601DateConverter extends ISO8601GregorianCalendarConverter {
25
26 public boolean canConvert(Class type) {
27 return type.equals(Date.class);
28 }
29
30 public Object fromString(String str) {
31 return ((Calendar)super.fromString(str)).getTime();
32 }
33
34 public String toString(Object obj) {
35 Calendar calendar = Calendar.getInstance();
36 calendar.setTime((Date)obj);
37 return super.toString(calendar);
38 }
39 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015 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 03. October 2005 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
15
16 import org.joda.time.DateTime;
17 import org.joda.time.DateTimeZone;
18 import org.joda.time.format.DateTimeFormatter;
19 import org.joda.time.format.ISODateTimeFormat;
20
21 import java.util.Calendar;
22 import java.util.GregorianCalendar;
23 import java.util.TimeZone;
24
25
26 /**
27 * A GregorianCalendarConverter conforming to the ISO8601 standard. The converter will always
28 * serialize the calendar value in UTC and deserialize it to a value in the current default time
29 * zone.
30 *
31 * @author Mauro Talevi
32 * @author J&ouml;rg Schaible
33 * @see <a href="http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=40874">ISO 8601</a>
34 * @since 1.1.3
35 */
36 public class ISO8601GregorianCalendarConverter extends AbstractSingleValueConverter {
37 private static final DateTimeFormatter[] formattersUTC = new DateTimeFormatter[]{
38 ISODateTimeFormat.dateTime(),
39 ISODateTimeFormat.dateTimeNoMillis(),
40 ISODateTimeFormat.basicDateTime(),
41 ISODateTimeFormat.basicOrdinalDateTime(),
42 ISODateTimeFormat.basicOrdinalDateTimeNoMillis(),
43 ISODateTimeFormat.basicTime(),
44 ISODateTimeFormat.basicTimeNoMillis(),
45 ISODateTimeFormat.basicTTime(),
46 ISODateTimeFormat.basicTTimeNoMillis(),
47 ISODateTimeFormat.basicWeekDateTime(),
48 ISODateTimeFormat.basicWeekDateTimeNoMillis(),
49 ISODateTimeFormat.ordinalDateTime(),
50 ISODateTimeFormat.ordinalDateTimeNoMillis(),
51 ISODateTimeFormat.time(),
52 ISODateTimeFormat.timeNoMillis(),
53 ISODateTimeFormat.tTime(),
54 ISODateTimeFormat.tTimeNoMillis(),
55 ISODateTimeFormat.weekDateTime(),
56 ISODateTimeFormat.weekDateTimeNoMillis()
57 };
58 private static final DateTimeFormatter[] formattersNoUTC = new DateTimeFormatter[]{
59 ISODateTimeFormat.basicDate(),
60 ISODateTimeFormat.basicOrdinalDate(),
61 ISODateTimeFormat.basicWeekDate(),
62 ISODateTimeFormat.date(),
63 ISODateTimeFormat.dateHour(),
64 ISODateTimeFormat.dateHourMinute(),
65 ISODateTimeFormat.dateHourMinuteSecond(),
66 ISODateTimeFormat.dateHourMinuteSecondFraction(),
67 ISODateTimeFormat.dateHourMinuteSecondMillis(),
68 ISODateTimeFormat.hour(),
69 ISODateTimeFormat.hourMinute(),
70 ISODateTimeFormat.hourMinuteSecond(),
71 ISODateTimeFormat.hourMinuteSecondFraction(),
72 ISODateTimeFormat.hourMinuteSecondMillis(),
73 ISODateTimeFormat.ordinalDate(),
74 ISODateTimeFormat.weekDate(),
75 ISODateTimeFormat.year(),
76 ISODateTimeFormat.yearMonth(),
77 ISODateTimeFormat.yearMonthDay(),
78 ISODateTimeFormat.weekyear(),
79 ISODateTimeFormat.weekyearWeek(),
80 ISODateTimeFormat.weekyearWeekDay()
81 };
82
83 public boolean canConvert(Class type) {
84 return type.equals(GregorianCalendar.class);
85 }
86
87 public Object fromString(String str) {
88 for (int i = 0; i < formattersUTC.length; i++ ) {
89 DateTimeFormatter formatter = formattersUTC[i];
90 try {
91 DateTime dt = formatter.parseDateTime(str);
92 Calendar calendar = dt.toGregorianCalendar();
93 calendar.setTimeZone(TimeZone.getDefault());
94 return calendar;
95 } catch (IllegalArgumentException e) {
96 // try with next formatter
97 }
98 }
99 final DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
100 for (int i = 0; i < formattersNoUTC.length; i++ ) {
101 try {
102 final DateTimeFormatter formatter = formattersNoUTC[i].withZone(dateTimeZone);
103 final DateTime dt = formatter.parseDateTime(str);
104 final Calendar calendar = dt.toGregorianCalendar();
105 calendar.setTimeZone(TimeZone.getDefault());
106 return calendar;
107 } catch (IllegalArgumentException e) {
108 // try with next formatter
109 }
110 }
111 throw new ConversionException("Cannot parse date " + str);
112 }
113
114 public String toString(Object obj) {
115 DateTime dt = new DateTime(obj);
116 return dt.toString(formattersUTC[0]);
117 }
118 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. October 2005 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.sql.Timestamp;
14 import java.util.Date;
15
16
17 /**
18 * A SqlTimestampConverter conforming to the ISO8601 standard.
19 * http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=26780
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.1.3
23 */
24 public class ISO8601SqlTimestampConverter extends ISO8601DateConverter {
25
26 private final static String PADDING = "000000000";
27
28 public boolean canConvert(Class type) {
29 return type.equals(Timestamp.class);
30 }
31
32 public Object fromString(String str) {
33 final int idxFraction = str.lastIndexOf('.');
34 int nanos = 0;
35 if (idxFraction > 0) {
36 int idx;
37 for (idx = idxFraction + 1; Character.isDigit(str.charAt(idx)); ++idx)
38 ;
39 nanos = Integer.parseInt(str.substring(idxFraction + 1, idx));
40 str = str.substring(0, idxFraction) + str.substring(idx);
41 }
42 final Date date = (Date)super.fromString(str);
43 final Timestamp timestamp = new Timestamp(date.getTime());
44 timestamp.setNanos(nanos);
45 return timestamp;
46 }
47
48 public String toString(Object obj) {
49 final Timestamp timestamp = (Timestamp)obj;
50 String str = super.toString(new Date((timestamp.getTime() / 1000) * 1000));
51 final String nanos = String.valueOf(timestamp.getNanos());
52 final int idxFraction = str.lastIndexOf('.');
53 str = str.substring(0, idxFraction + 1)
54 + PADDING.substring(nanos.length())
55 + nanos
56 + str.substring(idxFraction + 4);
57 return str;
58 }
59
60 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013 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 04. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
15 import com.thoughtworks.xstream.core.ClassLoaderReference;
16 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
17 import com.thoughtworks.xstream.mapper.DefaultMapper;
18 import com.thoughtworks.xstream.mapper.Mapper;
19
20 /**
21 * Converts a java.lang.Class to XML.
22 *
23 * @author Aslak Helles&oslash;y
24 * @author Joe Walnes
25 * @author Matthew Sandoz
26 * @author J&ouml;rg Schaible
27 */
28 public class JavaClassConverter extends AbstractSingleValueConverter {
29
30 private Mapper mapper;
31
32 /**
33 * Construct a JavaClassConverter.
34 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
35 * @since 1.4.5
36 */
37 public JavaClassConverter(ClassLoaderReference classLoaderReference) {
38 this(new DefaultMapper(classLoaderReference));
39 }
40
41 /**
42 * @deprecated As of 1.4.5 use {@link #JavaClassConverter(ClassLoaderReference)}
43 */
44 public JavaClassConverter(ClassLoader classLoader) {
45 this(new ClassLoaderReference(classLoader));
46 }
47
48 /**
49 * Construct a JavaClassConverter that uses a provided mapper. Depending on the mapper
50 * chain it will not only be used to load classes, but also to support type aliases.
51 * @param mapper to use
52 * @since 1.4.5
53 */
54 protected JavaClassConverter(Mapper mapper) {
55 this.mapper = mapper;
56 }
57
58 public boolean canConvert(Class clazz) {
59 return Class.class.equals(clazz); // :)
60 }
61
62 public String toString(Object obj) {
63 return mapper.serializedClass(((Class) obj));
64 }
65
66 public Object fromString(String str) {
67 try {
68 return mapper.realClass(str);
69 } catch (CannotResolveClassException e) {
70 throw new ConversionException("Cannot load java class " + str, e.getCause());
71 }
72 }
73 }
0 /*
1 * Copyright (C) 2009, 2013 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 17. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.SingleValueConverter;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.core.ClassLoaderReference;
18 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
19 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
20 import com.thoughtworks.xstream.mapper.DefaultMapper;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import java.lang.reflect.Field;
24
25 /**
26 * Converts a java.lang.reflect.Field to XML.
27 *
28 * @author J&ouml;rg Schaible
29 */
30 public class JavaFieldConverter implements Converter {
31
32 private final SingleValueConverter javaClassConverter;
33 private final Mapper mapper;
34
35 /**
36 * Construct a JavaFieldConverter.
37 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
38 * @since 1.4.5
39 */
40 public JavaFieldConverter(ClassLoaderReference classLoaderReference) {
41 this(new JavaClassConverter(classLoaderReference), new DefaultMapper(classLoaderReference));
42 }
43
44 /**
45 * @deprecated As of 1.4.5 use {@link #JavaFieldConverter(ClassLoaderReference)}
46 */
47 public JavaFieldConverter(ClassLoader classLoader) {
48 this(new ClassLoaderReference(classLoader));
49 }
50
51 /**
52 * Construct a JavaFieldConverter. Depending on the mapper chain the converter will also respect aliases.
53 * @param javaClassConverter the converter to use
54 * @param mapper to use
55 * @since 1.4.5
56 */
57 protected JavaFieldConverter(SingleValueConverter javaClassConverter, Mapper mapper) {
58 this.javaClassConverter = javaClassConverter;
59 this.mapper = mapper;
60 }
61
62 public boolean canConvert(Class type) {
63 return type.equals(Field.class);
64 }
65
66 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
67 Field field = (Field) source;
68 Class type = field.getDeclaringClass();
69
70 writer.startNode("name");
71 writer.setValue(mapper.serializedMember(type, field.getName()));
72 writer.endNode();
73
74 writer.startNode("clazz");
75 writer.setValue(javaClassConverter.toString(type));
76 writer.endNode();
77 }
78
79 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
80 String methodName = null;
81 String declaringClassName = null;
82
83 while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) {
84 reader.moveDown();
85
86 if (reader.getNodeName().equals("name")) {
87 methodName = reader.getValue();
88 } else if (reader.getNodeName().equals("clazz")) {
89 declaringClassName = reader.getValue();
90 }
91 reader.moveUp();
92 }
93
94 Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName);
95 try {
96 return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName));
97 } catch (NoSuchFieldException e) {
98 throw new ConversionException(e);
99 }
100 }
101 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2013 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 04. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.SingleValueConverter;
17 import com.thoughtworks.xstream.converters.UnmarshallingContext;
18 import com.thoughtworks.xstream.core.ClassLoaderReference;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21
22 import java.lang.reflect.Constructor;
23 import java.lang.reflect.Method;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /**
28 * Converts a java.lang.reflect.Method to XML.
29 *
30 * @author Aslak Helles&oslash;y
31 * @author J&ouml;rg Schaible
32 */
33 public class JavaMethodConverter implements Converter {
34
35 private final SingleValueConverter javaClassConverter;
36
37 /**
38 * Construct a JavaMethodConverter.
39 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
40 * @since 1.4.5
41 */
42 public JavaMethodConverter(ClassLoaderReference classLoaderReference) {
43 this(new JavaClassConverter(classLoaderReference));
44 }
45
46 /**
47 * @deprecated As of 1.4.5 use {@link #JavaMethodConverter(ClassLoaderReference)}
48 */
49 public JavaMethodConverter(ClassLoader classLoader) {
50 this(new ClassLoaderReference(classLoader));
51 }
52
53 /**
54 * Construct a JavaMethodConverter.
55 * @param javaClassConverter the converter to use
56 * @since 1.4.5
57 */
58 protected JavaMethodConverter(SingleValueConverter javaClassConverter) {
59 this.javaClassConverter = javaClassConverter;
60 }
61
62 public boolean canConvert(Class type) {
63 return type.equals(Method.class) || type.equals(Constructor.class);
64 }
65
66 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
67 if (source instanceof Method) {
68 Method method = (Method) source;
69 String declaringClassName = javaClassConverter.toString(method.getDeclaringClass());
70 marshalMethod(writer, declaringClassName, method.getName(), method.getParameterTypes());
71 } else {
72 Constructor method = (Constructor) source;
73 String declaringClassName = javaClassConverter.toString(method.getDeclaringClass());
74 marshalMethod(writer, declaringClassName, null, method.getParameterTypes());
75 }
76 }
77
78 private void marshalMethod(HierarchicalStreamWriter writer, String declaringClassName, String methodName, Class[] parameterTypes) {
79
80 writer.startNode("class");
81 writer.setValue(declaringClassName);
82 writer.endNode();
83
84 if (methodName != null) {
85 // it's a method and not a ctor
86 writer.startNode("name");
87 writer.setValue(methodName);
88 writer.endNode();
89 }
90
91 writer.startNode("parameter-types");
92 for (int i = 0; i < parameterTypes.length; i++) {
93 writer.startNode("class");
94 writer.setValue(javaClassConverter.toString(parameterTypes[i]));
95 writer.endNode();
96 }
97 writer.endNode();
98 }
99
100 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
101 try {
102 boolean isMethodNotConstructor = context.getRequiredType().equals(Method.class);
103
104 reader.moveDown();
105 String declaringClassName = reader.getValue();
106 Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName);
107 reader.moveUp();
108
109 String methodName = null;
110 if (isMethodNotConstructor) {
111 reader.moveDown();
112 methodName = reader.getValue();
113 reader.moveUp();
114 }
115
116 reader.moveDown();
117 List parameterTypeList = new ArrayList();
118 while (reader.hasMoreChildren()) {
119 reader.moveDown();
120 String parameterTypeName = reader.getValue();
121 parameterTypeList.add(javaClassConverter.fromString(parameterTypeName));
122 reader.moveUp();
123 }
124 Class[] parameterTypes = (Class[]) parameterTypeList.toArray(new Class[parameterTypeList.size()]);
125 reader.moveUp();
126
127 if (isMethodNotConstructor) {
128 return declaringClass.getDeclaredMethod(methodName, parameterTypes);
129 } else {
130 return declaringClass.getDeclaredConstructor(parameterTypes);
131 }
132 } catch (NoSuchMethodException e) {
133 throw new ConversionException(e);
134 }
135 }
136 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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. Julyl 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14
15 import java.util.Locale;
16
17 /**
18 * Converts a java.util.Locale to a string.
19 *
20 * @author Jose A. Illescas
21 * @author Joe Walnes
22 */
23 public class LocaleConverter extends AbstractSingleValueConverter {
24
25 public boolean canConvert(Class type) {
26 return type.equals(Locale.class);
27 }
28
29 public Object fromString(String str) {
30 int[] underscorePositions = underscorePositions(str);
31 String language, country, variant;
32 if (underscorePositions[0] == -1) { // "language"
33 language = str;
34 country = "";
35 variant = "";
36 } else if (underscorePositions[1] == -1) { // "language_country"
37 language = str.substring(0, underscorePositions[0]);
38 country = str.substring(underscorePositions[0] + 1);
39 variant = "";
40 } else { // "language_country_variant"
41 language = str.substring(0, underscorePositions[0]);
42 country = str.substring(underscorePositions[0] + 1, underscorePositions[1]);
43 variant = str.substring(underscorePositions[1] + 1);
44 }
45 return new Locale(language, country, variant);
46 }
47
48 private int[] underscorePositions(String in) {
49 int[] result = new int[2];
50 for (int i = 0; i < result.length; i++) {
51 int last = i == 0 ? 0 : result[i - 1];
52 result[i] = in.indexOf('_', last + 1);
53 }
54 return result;
55 }
56
57 }
0 /*
1 * Copyright (C) 2007, 2008, 2013 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 08.12.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
13 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
14 import com.thoughtworks.xstream.mapper.Mapper;
15
16 import javax.swing.LookAndFeel;
17
18 import java.io.NotSerializableException;
19
20
21 /**
22 * A converter for Swing LookAndFeel implementations. The JDK's implementations are serializable
23 * for historical reasons but will throw a {@link NotSerializableException} in their writeObject
24 * method. Therefore XStream will use an implementation based on the ReflectionConverter.
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.3
28 */
29 public class LookAndFeelConverter extends ReflectionConverter {
30
31 /**
32 * Constructs a LookAndFeelConverter.
33 *
34 * @param mapper the mapper
35 * @param reflectionProvider the reflection provider
36 * @since 1.3
37 */
38 public LookAndFeelConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
39 super(mapper, reflectionProvider);
40 }
41
42 public boolean canConvert(Class type) {
43 return LookAndFeel.class.isAssignableFrom(type) && canAccess(type);
44 }
45 }
0 /*
1 * Copyright (C) 2013 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 03. December 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import java.lang.reflect.Array;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import com.thoughtworks.xstream.converters.Converter;
17 import com.thoughtworks.xstream.converters.MarshallingContext;
18 import com.thoughtworks.xstream.converters.UnmarshallingContext;
19 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
20 import com.thoughtworks.xstream.core.util.Primitives;
21 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
22 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
23 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
24 import com.thoughtworks.xstream.mapper.Mapper;
25
26 /**
27 * An array converter that uses predefined names for its items.
28 * <p>
29 * To be used as local converter.
30 * </p>
31 *
32 * @author J&ouml;rg Schaible
33 * @since 1.4.6
34 */
35 public class NamedArrayConverter implements Converter {
36
37 private final Class arrayType;
38 private final String itemName;
39 private final Mapper mapper;
40
41 /**
42 * Construct a NamedArrayConverter.
43 * @param arrayType
44 * @param mapper
45 * @param itemName
46 * @since 1.4.6
47 */
48 public NamedArrayConverter(final Class arrayType, final Mapper mapper, final String itemName) {
49 if (!arrayType.isArray()) {
50 throw new IllegalArgumentException(arrayType.getName() + " is not an array");
51 }
52 this.arrayType = arrayType;
53 this.mapper = mapper;
54 this.itemName = itemName;
55 }
56
57 public boolean canConvert(final Class type) {
58 return type == arrayType;
59 }
60
61 public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
62 final int length = Array.getLength(source);
63 for (int i = 0; i < length; ++i) {
64 final Object item = Array.get(source, i);
65 final Class itemType = item == null
66 ? Mapper.Null.class
67 : arrayType.getComponentType().isPrimitive()
68 ? Primitives.unbox(item.getClass())
69 : item.getClass();
70 ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType);
71 if (!itemType.equals(arrayType.getComponentType())) {
72 final String attributeName = mapper.aliasForSystemAttribute("class");
73 if (attributeName != null) {
74 writer.addAttribute(attributeName, mapper.serializedClass(itemType));
75 }
76 }
77 if (item != null) {
78 context.convertAnother(item);
79 }
80 writer.endNode();
81 }
82 }
83
84 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
85 final List list = new ArrayList();
86 while (reader.hasMoreChildren()) {
87 reader.moveDown();
88 final Object item;
89 final String className = HierarchicalStreams.readClassAttribute(reader, mapper);
90 final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className);
91 if (Mapper.Null.class.equals(itemType)) {
92 item = null;
93 } else {
94 item = context.convertAnother(null, itemType);
95 }
96 list.add(item);
97 reader.moveUp();
98 }
99 final Object array = Array.newInstance(arrayType.getComponentType(), list.size());
100 for (int i = 0; i < list.size(); ++i) {
101 Array.set(array, i, list.get(i));
102 }
103 return array;
104 }
105
106 }
0 /*
1 * Copyright (C) 2013 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 19. September 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.MarshallingContext;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
15 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
16 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19 import com.thoughtworks.xstream.mapper.Mapper;
20
21
22 /**
23 * A collection converter that uses predefined names for its items.
24 * <p>
25 * To be used as local converter. Note, suppress the usage of the implicit type argument, if
26 * registered with annotation.
27 * </p>
28 *
29 * @author J&ouml;rg Schaible
30 * @since 1.4.5
31 */
32 public class NamedCollectionConverter extends CollectionConverter {
33
34 private final String name;
35 private final Class type;
36
37 /**
38 * Constructs a NamedCollectionConverter.
39 *
40 * @param mapper the mapper
41 * @param itemName the name of the items
42 * @param itemType the base type of the items
43 * @since 1.4.5
44 */
45 public NamedCollectionConverter(Mapper mapper, String itemName, Class itemType) {
46 this(null, mapper, itemName, itemType);
47 }
48
49 /**
50 * Constructs a NamedCollectionConverter handling an explicit Collection type.
51 *
52 * @param type the Collection type to handle
53 * @param mapper the mapper
54 * @param itemName the name of the items
55 * @param itemType the base type of the items
56 * @since 1.4.5
57 */
58 public NamedCollectionConverter(Class type, Mapper mapper, String itemName, Class itemType) {
59 super(mapper, type);
60 this.name = itemName;
61 this.type = itemType;
62 }
63
64 protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
65 Class itemType = item == null ? Mapper.Null.class : item.getClass();
66 ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
67 if (!itemType.equals(type)) {
68 String attributeName = mapper().aliasForSystemAttribute("class");
69 if (attributeName != null) {
70 writer.addAttribute(attributeName, mapper().serializedClass(itemType));
71 }
72 }
73 if (item != null) {
74 context.convertAnother(item);
75 }
76 writer.endNode();
77 }
78
79 protected Object readItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) {
80 String className = HierarchicalStreams.readClassAttribute(reader, mapper());
81 Class itemType = className == null ? type : mapper().realClass(className);
82 if (Mapper.Null.class.equals(itemType)) {
83 return null;
84 } else {
85 return context.convertAnother(current, itemType);
86 }
87 }
88 }
0 /*
1 * Copyright (C) 2013 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 20. September 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import java.util.Iterator;
13 import java.util.Map;
14
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.converters.Converter;
17 import com.thoughtworks.xstream.converters.ConverterLookup;
18 import com.thoughtworks.xstream.converters.MarshallingContext;
19 import com.thoughtworks.xstream.converters.SingleValueConverter;
20 import com.thoughtworks.xstream.converters.UnmarshallingContext;
21 import com.thoughtworks.xstream.converters.collections.MapConverter;
22 import com.thoughtworks.xstream.core.JVM;
23 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
24 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
25 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
26 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
27 import com.thoughtworks.xstream.mapper.Mapper;
28
29
30 /**
31 * A map converter that uses predefined names for its elements.
32 * <p>
33 * To be used as local converter. Note, suppress the usage of the implicit type argument, if
34 * registered with annotation. Depending on the constructor arguments it is possible to support
35 * various formats:
36 * </p>
37 * <ul>
38 * <li>new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
39 * Integer.class);
40 *
41 * <pre>
42 * &lt;map&gt;
43 * &lt;entry&gt;
44 * &lt;key&gt;keyValue&lt;/key&gt;
45 * &lt;value&gt;0&lt;/value&gt;
46 * &lt;/entry&gt;
47 * &lt;/map&gt;
48 * </pre>
49 *
50 * </li>
51 * <li>new NamedMapConverter(xstream.getMapper(), null, "key", String.class, "value",
52 * Integer.class);
53 *
54 * <pre>
55 * &lt;map&gt;
56 * &lt;key&gt;keyValue&lt;/key&gt;
57 * &lt;value&gt;0&lt;/value&gt;
58 * &lt;/map&gt;
59 * </pre>
60 *
61 * </li>
62 * <li>new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
63 * Integer.class, true, true, xstream.getConverterLookup());
64 *
65 * <pre>
66 * &lt;map&gt;
67 * &lt;entry&gt; key=&quot;keyValue&quot; value=&quot;0&quot;/&gt;
68 * &lt;/map&gt;
69 * </pre>
70 *
71 * </li>
72 * <li>new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
73 * Integer.class, true, false, xstream.getConverterLookup());
74 *
75 * <pre>
76 * &lt;map&gt;
77 * &lt;entry key=&quot;keyValue&quot;&gt;
78 * &lt;value&gt;0&lt;/value&gt;
79 * &lt;/entry&gt;
80 * &lt;/map&gt;
81 * </pre>
82 *
83 * </li>
84 * <li>new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value",
85 * Integer.class, false, true, xstream.getConverterLookup());
86 *
87 * <pre>
88 * &lt;map&gt;
89 * &lt;entry value=&quot;0&quot;&gt;
90 * &lt;key&gt;keyValue&lt;/key&gt;
91 * &lt;/entry&gt;
92 * &lt;/map&gt;
93 * </pre>
94 *
95 * </li>
96 * <li>new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, null,
97 * Integer.class, true, false, xstream.getConverterLookup());
98 *
99 * <pre>
100 * &lt;map&gt;
101 * &lt;entry key=&quot;keyValue&quot;&gt;0&lt;/entry&gt;
102 * &lt;/map&gt;
103 * </pre>
104 *
105 * </li>
106 * </ul>
107 *
108 * @author J&ouml;rg Schaible
109 * @since 1.4.5
110 */
111 public class NamedMapConverter extends MapConverter {
112
113 private final String entryName;
114 private final String keyName;
115 private final Class keyType;
116 private final String valueName;
117 private final Class valueType;
118 private final boolean keyAsAttribute;
119 private final boolean valueAsAttribute;
120 private final ConverterLookup lookup;
121 private final Mapper enumMapper;
122
123 /**
124 * Constructs a NamedMapConverter.
125 *
126 * @param mapper the mapper
127 * @param entryName the name of the entry elements
128 * @param keyName the name of the key elements
129 * @param keyType the base type of key elements
130 * @param valueName the name of the value elements
131 * @param valueType the base type of value elements
132 * @since 1.4.5
133 */
134 public NamedMapConverter(
135 Mapper mapper, String entryName, String keyName, Class keyType, String valueName,
136 Class valueType) {
137 this(mapper, entryName, keyName, keyType, valueName, valueType, false, false, null);
138 }
139
140 /**
141 * Constructs a NamedMapConverter handling an explicit Map type.
142 *
143 * @param type the Map type this instance will handle
144 * @param mapper the mapper
145 * @param entryName the name of the entry elements
146 * @param keyName the name of the key elements
147 * @param keyType the base type of key elements
148 * @param valueName the name of the value elements
149 * @param valueType the base type of value elements
150 * @since 1.4.5
151 */
152 public NamedMapConverter(
153 Class type, Mapper mapper, String entryName, String keyName, Class keyType,
154 String valueName, Class valueType) {
155 this(
156 type, mapper, entryName, keyName, keyType, valueName, valueType, false, false, null);
157 }
158
159 /**
160 * Constructs a NamedMapConverter with attribute support.
161 *
162 * @param mapper the mapper
163 * @param entryName the name of the entry elements
164 * @param keyName the name of the key elements
165 * @param keyType the base type of key elements
166 * @param valueName the name of the value elements
167 * @param valueType the base type of value elements
168 * @param keyAsAttribute flag to write key as attribute of entry element
169 * @param valueAsAttribute flag to write value as attribute of entry element
170 * @param lookup used to lookup SingleValueConverter for attributes
171 * @since 1.4.5
172 */
173 public NamedMapConverter(
174 Mapper mapper, String entryName, String keyName, Class keyType, String valueName,
175 Class valueType, boolean keyAsAttribute, boolean valueAsAttribute,
176 ConverterLookup lookup) {
177 this(
178 null, mapper, entryName, keyName, keyType, valueName, valueType, keyAsAttribute,
179 valueAsAttribute, lookup);
180 }
181
182 /**
183 * Constructs a NamedMapConverter with attribute support handling an explicit Map type.
184 *
185 * @param type the Map type this instance will handle
186 * @param mapper the mapper
187 * @param entryName the name of the entry elements
188 * @param keyName the name of the key elements
189 * @param keyType the base type of key elements
190 * @param valueName the name of the value elements
191 * @param valueType the base type of value elements
192 * @param keyAsAttribute flag to write key as attribute of entry element
193 * @param valueAsAttribute flag to write value as attribute of entry element
194 * @param lookup used to lookup SingleValueConverter for attributes
195 * @since 1.4.5
196 */
197 public NamedMapConverter(
198 Class type, Mapper mapper, String entryName, String keyName, Class keyType,
199 String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute,
200 ConverterLookup lookup) {
201 super(mapper, type);
202 this.entryName = entryName != null && entryName.length() == 0 ? null : entryName;
203 this.keyName = keyName != null && keyName.length() == 0 ? null : keyName;
204 this.keyType = keyType;
205 this.valueName = valueName != null && valueName.length() == 0 ? null : valueName;
206 this.valueType = valueType;
207 this.keyAsAttribute = keyAsAttribute;
208 this.valueAsAttribute = valueAsAttribute;
209 this.lookup = lookup;
210 enumMapper = JVM.is15() ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
211
212 if (keyType == null || valueType == null) {
213 throw new IllegalArgumentException("Class types of key and value are mandatory");
214 }
215 if (entryName == null) {
216 if (keyAsAttribute || valueAsAttribute) {
217 throw new IllegalArgumentException(
218 "Cannot write attributes to map entry, if map entry must be omitted");
219 }
220 if (valueName == null) {
221 throw new IllegalArgumentException(
222 "Cannot write value as text of entry, if entry must be omitted");
223 }
224 }
225 if (keyName == null) {
226 throw new IllegalArgumentException("Cannot write key without name");
227 }
228 if (valueName == null) {
229 if (valueAsAttribute) {
230 throw new IllegalArgumentException(
231 "Cannot write value as attribute without name");
232 } else if (!keyAsAttribute) {
233 throw new IllegalArgumentException(
234 "Cannot write value as text of entry, if key is also child element");
235 }
236 }
237 if (keyAsAttribute && valueAsAttribute && keyName.equals(valueName)) {
238 throw new IllegalArgumentException(
239 "Cannot write key and value with same attribute name");
240 }
241 }
242
243 public void marshal(Object source, HierarchicalStreamWriter writer,
244 MarshallingContext context) {
245 Map map = (Map)source;
246 SingleValueConverter keyConverter = null;
247 SingleValueConverter valueConverter = null;
248 if (keyAsAttribute) {
249 keyConverter = getSingleValueConverter(keyType);
250 }
251 if (valueAsAttribute || valueName == null) {
252 valueConverter = getSingleValueConverter(valueType);
253 }
254 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
255 Map.Entry entry = (Map.Entry)iterator.next();
256 Object key = entry.getKey();
257 Object value = entry.getValue();
258 if (entryName != null) {
259 ExtendedHierarchicalStreamWriterHelper.startNode(
260 writer, entryName, entry.getClass());
261 if (keyConverter != null && key != null) {
262 writer.addAttribute(keyName, keyConverter.toString(key));
263 }
264 if (valueName != null && valueConverter != null && value != null) {
265 writer.addAttribute(valueName, valueConverter.toString(value));
266 }
267 }
268
269 if (keyConverter == null) {
270 writeItem(keyName, keyType, key, context, writer);
271 }
272 if (valueConverter == null) {
273 writeItem(valueName, valueType, value, context, writer);
274 } else if (valueName == null) {
275 writer.setValue(valueConverter.toString(value));
276 }
277
278 if (entryName != null) {
279 writer.endNode();
280 }
281 }
282 }
283
284 protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context,
285 Map map, Map target) {
286 SingleValueConverter keyConverter = null;
287 SingleValueConverter valueConverter = null;
288 if (keyAsAttribute) {
289 keyConverter = getSingleValueConverter(keyType);
290 }
291 if (valueAsAttribute || valueName == null) {
292 valueConverter = getSingleValueConverter(valueType);
293 }
294
295 while (reader.hasMoreChildren()) {
296 Object key = null;
297 Object value = null;
298
299 if (entryName != null) {
300 reader.moveDown();
301
302 if (keyConverter != null) {
303 String attribute = reader.getAttribute(keyName);
304 if (attribute != null) {
305 key = keyConverter.fromString(attribute);
306 }
307 }
308
309 if (valueAsAttribute && valueConverter != null) {
310 String attribute = reader.getAttribute(valueName);
311 if (attribute != null) {
312 value = valueConverter.fromString(attribute);
313 }
314 }
315 }
316
317 if (keyConverter == null) {
318 reader.moveDown();
319 if (valueConverter == null
320 && !keyName.equals(valueName)
321 && reader.getNodeName().equals(valueName)) {
322 value = readItem(valueType, reader, context, map);
323 } else {
324 key = readItem(keyType, reader, context, map);
325 }
326 reader.moveUp();
327 }
328
329 if (valueConverter == null) {
330 reader.moveDown();
331 if (keyConverter == null && key == null && value != null) {
332 key = readItem(keyType, reader, context, map);
333 } else {
334 value = readItem(valueType, reader, context, map);
335 }
336 reader.moveUp();
337 } else if (!valueAsAttribute) {
338 value = reader.getValue();
339 }
340
341 target.put(key, value);
342
343 if (entryName != null) {
344 reader.moveUp();
345 }
346 }
347 }
348
349 private SingleValueConverter getSingleValueConverter(Class type) {
350 SingleValueConverter conv = UseAttributeForEnumMapper.isEnum(type) ? enumMapper
351 .getConverterFromItemType(null, type, null) : mapper().getConverterFromItemType(
352 null, type, null);
353 if (conv == null) {
354 Converter converter = lookup.lookupConverterForType(type);
355 if (converter instanceof SingleValueConverter) {
356 conv = (SingleValueConverter)converter;
357 } else {
358 throw new ConversionException("No SingleValueConverter for key available");
359 }
360 }
361 return conv;
362 }
363
364 protected void writeItem(String name, Class type, Object item, MarshallingContext context,
365 HierarchicalStreamWriter writer) {
366 Class itemType = item == null ? Mapper.Null.class : item.getClass();
367 ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
368 if (!itemType.equals(type)) {
369 String attributeName = mapper().aliasForSystemAttribute("class");
370 if (attributeName != null) {
371 writer.addAttribute(attributeName, mapper().serializedClass(itemType));
372 }
373 }
374 if (item != null) {
375 context.convertAnother(item);
376 }
377 writer.endNode();
378 }
379
380 protected Object readItem(Class type, HierarchicalStreamReader reader,
381 UnmarshallingContext context, Object current) {
382 String className = HierarchicalStreams.readClassAttribute(reader, mapper());
383 Class itemType = className == null ? type : mapper().realClass(className);
384 if (Mapper.Null.class.equals(itemType)) {
385 return null;
386 } else {
387 return context.convertAnother(current, itemType);
388 }
389 }
390 }
0 /*
1 * Copyright (C) 2007, 2008 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 20.09.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.SingleValueConverter;
13 import com.thoughtworks.xstream.core.util.ThreadSafePropertyEditor;
14
15 import java.beans.PropertyEditor;
16
17
18 /**
19 * A SingleValueConverter that can utilize a {@link PropertyEditor} implementation used for a
20 * specific type. The converter ensures that the editors can be used concurrently.
21 *
22 * @author Jukka Lindstr&ouml;m
23 * @author J&ouml;rg Schaible
24 * @since 1.3
25 */
26 public class PropertyEditorCapableConverter implements SingleValueConverter {
27
28 private final ThreadSafePropertyEditor editor;
29 private final Class type;
30
31 public PropertyEditorCapableConverter(final Class propertyEditorType, final Class type) {
32 this.type = type;
33 editor = new ThreadSafePropertyEditor(propertyEditorType, 2, 5);
34 }
35
36 public boolean canConvert(final Class type) {
37 return this.type == type;
38 }
39
40 public Object fromString(final String str) {
41 return editor.setAsText(str);
42 }
43
44 public String toString(final Object obj) {
45 return editor.getAsText(obj);
46 }
47
48 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 31. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18
19 import java.util.regex.Pattern;
20
21 /**
22 * Ensures java.util.regex.Pattern is compiled upon deserialization.
23 *
24 * @author Joe Walnes
25 * @author J&ouml;rg Schaible
26 */
27 public class RegexPatternConverter implements Converter {
28
29 /**
30 * @since 1.4.5
31 */
32 public RegexPatternConverter() {
33 }
34
35 /**
36 * @deprecated As of 1.4.5, use {@link #RegexPatternConverter()} instead
37 */
38 public RegexPatternConverter(Converter defaultConverter) {
39 }
40
41 public boolean canConvert(final Class type) {
42 return type.equals(Pattern.class);
43 }
44
45 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
46 Pattern pattern = (Pattern)source;
47 writer.startNode("pattern");
48 writer.setValue(pattern.pattern());
49 writer.endNode();
50 writer.startNode("flags");
51 writer.setValue(String.valueOf(pattern.flags()));
52 writer.endNode();
53 }
54
55 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
56 reader.moveDown();
57 String pattern = reader.getValue();
58 reader.moveUp();
59 reader.moveDown();
60 int flags = Integer.parseInt(reader.getValue());
61 reader.moveUp();
62 return Pattern.compile(pattern, flags);
63 }
64
65 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.sql.Date;
14
15 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
16
17 /**
18 * Converts a java.sql.Date to text.
19 *
20 * @author Jose A. Illescas
21 */
22 public class SqlDateConverter extends AbstractSingleValueConverter {
23
24 public boolean canConvert(Class type) {
25 return type.equals(Date.class);
26 }
27
28 public Object fromString(String str) {
29 return Date.valueOf(str);
30 }
31
32 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14
15 import java.sql.Time;
16
17 /**
18 * Converts a java.sql.Time to text. Warning: Any granularity smaller than seconds is lost.
19 *
20 * @author Jose A. Illescas
21 */
22 public class SqlTimeConverter extends AbstractSingleValueConverter {
23
24 public boolean canConvert(Class type) {
25 return type.equals(Time.class);
26 }
27
28 public Object fromString(String str) {
29 return Time.valueOf(str);
30 }
31
32 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2012, 2014 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 01. October 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
15 import com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat;
16
17 import java.sql.Timestamp;
18 import java.text.ParseException;
19 import java.util.TimeZone;
20
21
22 /**
23 * Converts a java.sql.Timestamp to text.
24 *
25 * @author Joe Walnes
26 * @author J&ouml;rg Schaible
27 */
28 public class SqlTimestampConverter extends AbstractSingleValueConverter {
29
30 private final ThreadSafeSimpleDateFormat format = new ThreadSafeSimpleDateFormat(
31 "yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("UTC"), 0, 5, false);
32
33 public boolean canConvert(Class type) {
34 return type.equals(Timestamp.class);
35 }
36
37 public String toString(Object obj) {
38 Timestamp timestamp = (Timestamp)obj;
39 StringBuffer buffer = new StringBuffer(format.format(timestamp)).append('.');
40 if (timestamp.getNanos() == 0) {
41 buffer.append('0');
42 } else {
43 String nanos = String.valueOf(timestamp.getNanos() + 1000000000);
44 int last = 10;
45 while (last > 2 && nanos.charAt(last-1) == '0')
46 --last;
47 buffer.append(nanos.subSequence(1, last));
48 }
49 return buffer.toString();
50 }
51
52 public Object fromString(String str) {
53 int idx = str.lastIndexOf('.');
54 if (idx < 0 || str.length() - idx < 2 || str.length() - idx > 10) {
55 throw new ConversionException(
56 "Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]");
57 }
58 try {
59 Timestamp timestamp = new Timestamp(format.parse(str.substring(0, idx)).getTime());
60 StringBuffer buffer = new StringBuffer(str.substring(idx + 1));
61 while(buffer.length() != 9) {
62 buffer.append('0');
63 }
64 timestamp.setNanos(Integer.parseInt(buffer.toString()));
65 return timestamp;
66 } catch (NumberFormatException e) {
67 throw new ConversionException(
68 "Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e);
69 } catch (ParseException e) {
70 throw new ConversionException(
71 "Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e);
72 }
73 }
74
75 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 29. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16 import com.thoughtworks.xstream.converters.ConversionException;
17 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
18 import com.thoughtworks.xstream.core.JVM;
19
20 /**
21 * Converter for StackTraceElement (the lines of a stack trace) - JDK 1.4+ only.
22 *
23 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
24 * @author Joe Walnes
25 */
26 public class StackTraceElementConverter extends AbstractSingleValueConverter {
27
28 // Regular expression to parse a line of a stack trace. Returns 4 groups.
29 //
30 // Example: com.blah.MyClass.doStuff(MyClass.java:123)
31 // |-------1------| |--2--| |----3-----| |4|
32 // (Note group 4 is optional is optional and only present if a colon char exists.)
33
34 private static final Pattern PATTERN = Pattern.compile("^(.+)\\.([^\\(]+)\\(([^:]*)(:(\\d+))?\\)$");
35 private static final StackTraceElementFactory FACTORY;
36 static {
37 StackTraceElementFactory factory = null;
38 if (JVM.is15()) {
39 Class factoryType = JVM.loadClassForName(
40 "com.thoughtworks.xstream.converters.extended.StackTraceElementFactory15",
41 false);
42 try {
43 factory = (StackTraceElementFactory)factoryType.newInstance();
44 } catch (Exception e) {
45 // N/A
46 } catch (LinkageError e) {
47 // N/A
48 }
49 }
50 if (factory == null) {
51 factory = new StackTraceElementFactory();
52 }
53 try {
54 factory.unknownSourceElement("a", "b");
55 } catch (Exception e) {
56 factory = null;
57 } catch (NoClassDefFoundError e) { // GAE
58 factory = null;
59 }
60 FACTORY = factory;
61 }
62
63 public boolean canConvert(Class type) {
64 return StackTraceElement.class.equals(type) && FACTORY != null;
65 }
66
67 public String toString(Object obj) {
68 String s = super.toString(obj);
69 // JRockit adds ":???" for invalid line number
70 return s.replaceFirst(":\\?\\?\\?", "");
71 }
72
73 public Object fromString(String str) {
74 Matcher matcher = PATTERN.matcher(str);
75 if (matcher.matches()) {
76 String declaringClass = matcher.group(1);
77 String methodName = matcher.group(2);
78 String fileName = matcher.group(3);
79 if (fileName.equals("Unknown Source")) {
80 return FACTORY.unknownSourceElement(declaringClass, methodName);
81 } else if (fileName.equals("Native Method")) {
82 return FACTORY.nativeMethodElement(declaringClass, methodName);
83 } else {
84 if (matcher.group(4) != null) {
85 int lineNumber = Integer.parseInt(matcher.group(5));
86 return FACTORY.element(declaringClass, methodName, fileName, lineNumber);
87 } else {
88 return FACTORY.element(declaringClass, methodName, fileName);
89 }
90 }
91 } else {
92 throw new ConversionException("Could not parse StackTraceElement : " + str);
93 }
94 }
95
96 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 30. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14
15 import java.lang.reflect.Field;
16
17 /**
18 * Factory for creating StackTraceElements.
19 * Factory for creating StackTraceElements.
20 *
21 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
22 * @author Joe Walnes
23 * @deprecated As of 1.4.8, it is an internal helper class
24 */
25 public class StackTraceElementFactory {
26
27 public StackTraceElement nativeMethodElement(String declaringClass, String methodName) {
28 return create(declaringClass, methodName, "Native Method", -2);
29 }
30
31 public StackTraceElement unknownSourceElement(String declaringClass, String methodName) {
32 return create(declaringClass, methodName, "Unknown Source", -1);
33 }
34
35 public StackTraceElement element(String declaringClass, String methodName, String fileName) {
36 return create(declaringClass, methodName, fileName, -1);
37 }
38
39 public StackTraceElement element(String declaringClass, String methodName, String fileName, int lineNumber) {
40 return create(declaringClass, methodName, fileName, lineNumber);
41 }
42
43 protected StackTraceElement create(String declaringClass, String methodName, String fileName, int lineNumber) {
44 StackTraceElement result = new Throwable().getStackTrace()[0];
45 setField(result, "declaringClass", declaringClass);
46 setField(result, "methodName", methodName);
47 setField(result, "fileName", fileName);
48 setField(result, "lineNumber", new Integer(lineNumber));
49 return result;
50 }
51
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 }
60 }
61
62 }
0 /*
1 * Copyright (C) 2013 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 03. December 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 /**
13 * @author J&ouml;rg Schaible
14 *
15 * @since 1.4.6
16 */
17 class StackTraceElementFactory15 extends StackTraceElementFactory {
18
19 @Override
20 protected StackTraceElement create(final String declaringClass, final String methodName,
21 final String fileName, final int lineNumber) {
22 return new StackTraceElement(declaringClass, methodName, fileName, lineNumber);
23 }
24 }
0 /*
1 * Copyright (C) 2006, 2007 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 12. January 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.MarshallingContext;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19 import javax.security.auth.Subject;
20
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.Set;
25
26 /**
27 * Converts a {@link Subject} instance. Note, that this Converter does only convert the contained Principals as
28 * it is done by JDK serialization, but not any credentials. For other behaviour you can derive your own converter,
29 * overload the appropriate methods and register it in the {@link com.thoughtworks.xstream.XStream}.
30 *
31 * @author J&ouml;rg Schaible
32 * @since 1.1.3
33 */
34 public class SubjectConverter extends AbstractCollectionConverter {
35
36 public SubjectConverter(Mapper mapper) {
37 super(mapper);
38 }
39
40 public boolean canConvert(Class type) {
41 return type.equals(Subject.class);
42 }
43
44 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
45 Subject subject = (Subject) source;
46 marshalPrincipals(subject.getPrincipals(), writer, context);
47 marshalPublicCredentials(subject.getPublicCredentials(), writer, context);
48 marshalPrivateCredentials(subject.getPrivateCredentials(), writer, context);
49 marshalReadOnly(subject.isReadOnly(), writer);
50 }
51
52 protected void marshalPrincipals(Set principals, HierarchicalStreamWriter writer, MarshallingContext context) {
53 writer.startNode("principals");
54 for (final Iterator iter = principals.iterator(); iter.hasNext();) {
55 final Object principal = iter.next(); // pre jdk 1.4 a Principal was also in javax.security
56 writeItem(principal, context, writer);
57 }
58 writer.endNode();
59 };
60
61 protected void marshalPublicCredentials(Set pubCredentials, HierarchicalStreamWriter writer, MarshallingContext context) {
62 };
63
64 protected void marshalPrivateCredentials(Set privCredentials, HierarchicalStreamWriter writer, MarshallingContext context) {
65 };
66
67 protected void marshalReadOnly(boolean readOnly, HierarchicalStreamWriter writer) {
68 writer.startNode("readOnly");
69 writer.setValue(String.valueOf(readOnly));
70 writer.endNode();
71 };
72
73 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
74 Set principals = unmarshalPrincipals(reader, context);
75 Set publicCredentials = unmarshalPublicCredentials(reader, context);
76 Set privateCredentials = unmarshalPrivateCredentials(reader, context);
77 boolean readOnly = unmarshalReadOnly(reader);
78 return new Subject(readOnly, principals, publicCredentials, privateCredentials);
79 }
80
81 protected Set unmarshalPrincipals(HierarchicalStreamReader reader, UnmarshallingContext context) {
82 return populateSet(reader, context);
83 };
84
85 protected Set unmarshalPublicCredentials(HierarchicalStreamReader reader, UnmarshallingContext context) {
86 return Collections.EMPTY_SET;
87 };
88
89 protected Set unmarshalPrivateCredentials(HierarchicalStreamReader reader, UnmarshallingContext context) {
90 return Collections.EMPTY_SET;
91 };
92
93 protected boolean unmarshalReadOnly(HierarchicalStreamReader reader) {
94 reader.moveDown();
95 boolean readOnly = Boolean.getBoolean(reader.getValue());
96 reader.moveUp();
97 return readOnly;
98 };
99
100 protected Set populateSet(HierarchicalStreamReader reader, UnmarshallingContext context) {
101 Set set = new HashSet();
102 reader.moveDown();
103 while (reader.hasMoreChildren()) {
104 reader.moveDown();
105 Object elementl = readItem(reader, context, set);
106 reader.moveUp();
107 set.add(elementl);
108 }
109 reader.moveUp();
110 return set;
111 }
112 }
0 /*
1 * Copyright (C) 2006, 2007 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 25. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.reflection.AbstractAttributedCharacterIteratorAttributeConverter;
13
14 import java.awt.font.TextAttribute;
15
16
17 /**
18 * A converter for {@link TextAttribute} constants.
19 *
20 * @author J&ouml;rg Schaible
21 * @since 1.2
22 */
23 public class TextAttributeConverter extends
24 AbstractAttributedCharacterIteratorAttributeConverter {
25
26 /**
27 * Constructs a TextAttributeConverter.
28 *
29 * @since 1.2.2
30 */
31 public TextAttributeConverter() {
32 super(TextAttribute.class);
33 }
34 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 29. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.ConverterLookup;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19
20 /**
21 * Converter for Throwable (and Exception) that retains stack trace.
22 *
23 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
24 * @author Joe Walnes
25 * @author J&ouml;rg Schaible
26 */
27 public class ThrowableConverter implements Converter {
28
29 private Converter defaultConverter;
30 private final ConverterLookup lookup;
31
32 /**
33 * @deprecated As of 1.4.5 use {@link #ThrowableConverter(ConverterLookup)}
34 */
35 public ThrowableConverter(Converter defaultConverter) {
36 this.defaultConverter = defaultConverter;
37 lookup = null;
38 }
39
40 /**
41 * @since 1.4.5
42 */
43 public ThrowableConverter(ConverterLookup lookup) {
44 this.lookup = lookup;
45 }
46
47 public boolean canConvert(final Class type) {
48 return Throwable.class.isAssignableFrom(type);
49 }
50
51 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
52 Throwable throwable = (Throwable) source;
53 if (throwable.getCause() == null) {
54 try {
55 throwable.initCause(null);
56 } catch (IllegalStateException e) {
57 // ignore, initCause failed, cause was already set
58 }
59 }
60 throwable.getStackTrace(); // Force stackTrace field to be lazy loaded by special JVM native witchcraft (outside our control).
61 getConverter().marshal(throwable, writer, context);
62 }
63
64 private Converter getConverter() {
65 return defaultConverter != null ? defaultConverter : lookup.lookupConverterForType(Object.class);
66 }
67
68 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
69 return getConverter().unmarshal(reader, context);
70 }
71 }
0 /*
1 * Copyright (C) 2011, 2013 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 30. July 2011 by Joerg Schaible
9 */
10
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.lang.reflect.Field;
14 import java.lang.reflect.Modifier;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.Map;
19 import java.util.Set;
20
21 import com.thoughtworks.xstream.converters.ConversionException;
22 import com.thoughtworks.xstream.converters.Converter;
23 import com.thoughtworks.xstream.converters.ConverterLookup;
24 import com.thoughtworks.xstream.converters.ConverterMatcher;
25 import com.thoughtworks.xstream.converters.MarshallingContext;
26 import com.thoughtworks.xstream.converters.SingleValueConverter;
27 import com.thoughtworks.xstream.converters.UnmarshallingContext;
28 import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException;
29 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
30 import com.thoughtworks.xstream.core.JVM;
31 import com.thoughtworks.xstream.core.util.FastField;
32 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
33 import com.thoughtworks.xstream.core.util.Primitives;
34 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
35 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
36 import com.thoughtworks.xstream.mapper.Mapper;
37
38
39 /**
40 * Converter that supports the definition of one field member that will be written as value and
41 * all other field members are written as attributes. The converter requires that all the field
42 * types (expect the one with the value) are handled by a {@link SingleValueConverter}. The
43 * value field is defined using the name of the type that declares the field and the field name
44 * itself. Therefore it is possible to define an inherited field as value. It is also possible
45 * to provide no value field at all, so that all fields are written as attributes.
46 *
47 * @author J&ouml;rg Schaible
48 * @since 1.4
49 */
50 public class ToAttributedValueConverter implements Converter {
51 private static final String STRUCTURE_MARKER = "";
52 private final Class type;
53 private final Mapper mapper;
54 private final Mapper enumMapper;
55 private final ReflectionProvider reflectionProvider;
56 private final ConverterLookup lookup;
57 private final Field valueField;
58
59 /**
60 * Creates a new ToAttributedValueConverter instance.
61 *
62 * @param type the type that is handled by this converter instance
63 * @param mapper the mapper in use
64 * @param reflectionProvider the reflection provider in use
65 * @param lookup the converter lookup in use
66 * @param valueFieldName the field defining the tag's value (may be null)
67 */
68 public ToAttributedValueConverter(
69 final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider,
70 final ConverterLookup lookup, final String valueFieldName) {
71 this(type, mapper, reflectionProvider, lookup, valueFieldName, null);
72 }
73
74 /**
75 * Creates a new ToAttributedValueConverter instance.
76 *
77 * @param type the type that is handled by this converter instance
78 * @param mapper the mapper in use
79 * @param reflectionProvider the reflection provider in use
80 * @param lookup the converter lookup in use
81 * @param valueFieldName the field defining the tag's value (may be null)
82 * @param valueDefinedIn the type defining the field
83 */
84 public ToAttributedValueConverter(
85 final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider,
86 final ConverterLookup lookup, final String valueFieldName, Class valueDefinedIn) {
87 this.type = type;
88 this.mapper = mapper;
89 this.reflectionProvider = reflectionProvider;
90 this.lookup = lookup;
91
92 if (valueFieldName == null) {
93 valueField = null;
94 } else {
95 Field field = null;
96 try {
97 field = (valueDefinedIn != null ? valueDefinedIn : type)
98 .getDeclaredField(valueFieldName);
99 if (!field.isAccessible()) {
100 field.setAccessible(true);
101 }
102 } catch (NoSuchFieldException e) {
103 throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName);
104 }
105 this.valueField = field;
106 }
107 enumMapper = JVM.is15() ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
108 }
109
110 public boolean canConvert(final Class type) {
111 return this.type == type;
112 }
113
114 public void marshal(final Object source, final HierarchicalStreamWriter writer,
115 final MarshallingContext context) {
116 final Class sourceType = source.getClass();
117 final Map defaultFieldDefinition = new HashMap();
118 final String[] tagValue = new String[1];
119 final Object[] realValue = new Object[1];
120 final Class[] fieldType = new Class[1];
121 final Class[] definingType = new Class[1];
122 reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() {
123 public void visit(final String fieldName, final Class type, final Class definedIn,
124 final Object value) {
125 if (!mapper.shouldSerializeMember(definedIn, fieldName)) {
126 return;
127 }
128
129 final FastField field = new FastField(definedIn, fieldName);
130 final String alias = mapper.serializedMember(definedIn, fieldName);
131 if (!defaultFieldDefinition.containsKey(alias)) {
132 final Class lookupType = sourceType;
133 defaultFieldDefinition.put(
134 alias, reflectionProvider.getField(lookupType, fieldName));
135 } else if (!fieldIsEqual(field)) {
136 final ConversionException exception = new ConversionException(
137 "Cannot write attribute twice for object");
138 exception.add("alias", alias);
139 exception.add("type", sourceType.getName());
140 throw exception;
141 }
142
143 ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type)
144 ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null)
145 : (ConverterMatcher)mapper.getLocalConverter(definedIn, fieldName);
146 if (converter == null) {
147 converter = lookup.lookupConverterForType(type);
148 }
149
150 if (value != null) {
151 boolean isValueField = valueField != null && fieldIsEqual(field);
152 if (isValueField) {
153 definingType[0] = definedIn;
154 fieldType[0] = type;
155 realValue[0] = value;
156 tagValue[0] = STRUCTURE_MARKER;
157 }
158 if (converter instanceof SingleValueConverter) {
159 final String str = ((SingleValueConverter)converter).toString(value);
160
161 if (isValueField) {
162 tagValue[0] = str;
163 } else {
164 if (str != null) {
165 writer.addAttribute(alias, str);
166 }
167 }
168 } else {
169 if (!isValueField) {
170 final ConversionException exception = new ConversionException(
171 "Cannot write element as attribute");
172 exception.add("alias", alias);
173 exception.add("type", sourceType.getName());
174 throw exception;
175 }
176 }
177 }
178 }
179 });
180
181 if (tagValue[0] != null) {
182 final Class actualType = realValue[0].getClass();
183 final Class defaultType = mapper.defaultImplementationOf(fieldType[0]);
184 if (!actualType.equals(defaultType)) {
185 final String serializedClassName = mapper.serializedClass(actualType);
186 if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
187 final String attributeName = mapper.aliasForSystemAttribute("class");
188 if (attributeName != null) {
189 writer.addAttribute(attributeName, serializedClassName);
190 }
191 }
192 }
193
194 if (tagValue[0] == STRUCTURE_MARKER) {
195 context.convertAnother(realValue[0]);
196 } else {
197 writer.setValue(tagValue[0]);
198 }
199 }
200 }
201
202 public Object unmarshal(final HierarchicalStreamReader reader,
203 final UnmarshallingContext context) {
204 final Object result = reflectionProvider.newInstance(context.getRequiredType());
205 final Class resultType = result.getClass();
206
207 final Set seenFields = new HashSet();
208 final Iterator it = reader.getAttributeNames();
209
210 final Set systemAttributes = new HashSet();
211 systemAttributes.add(mapper.aliasForSystemAttribute("class"));
212
213 // Process attributes before recursing into child elements.
214 while (it.hasNext()) {
215 final String attrName = (String)it.next();
216 if (systemAttributes.contains(attrName)) {
217 continue;
218 }
219
220 final String fieldName = mapper.realMember(resultType, attrName);
221 final Field field = reflectionProvider.getFieldOrNull(resultType, fieldName);
222 if (field != null) {
223 if (Modifier.isTransient(field.getModifiers())) {
224 continue;
225 }
226
227 Class type = field.getType();
228 final Class declaringClass = field.getDeclaringClass();
229 ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type)
230 ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null)
231 : (ConverterMatcher)mapper.getLocalConverter(declaringClass, fieldName);
232 if (converter == null) {
233 converter = lookup.lookupConverterForType(type);
234 }
235
236 if (!(converter instanceof SingleValueConverter)) {
237 final ConversionException exception = new ConversionException(
238 "Cannot read field as a single value for object");
239 exception.add("field", fieldName);
240 exception.add("type", resultType.getName());
241 throw exception;
242 }
243
244 if (converter != null) {
245 final Object value = ((SingleValueConverter)converter).fromString(reader
246 .getAttribute(attrName));
247 if (type.isPrimitive()) {
248 type = Primitives.box(type);
249 }
250
251 if (value != null && !type.isAssignableFrom(value.getClass())) {
252 final ConversionException exception = new ConversionException(
253 "Cannot assign object to type");
254 exception.add("object type", value.getClass().getName());
255 exception.add("target type", type.getName());
256 throw exception;
257 }
258
259 reflectionProvider.writeField(result, fieldName, value, declaringClass);
260 if (!seenFields.add(new FastField(declaringClass, fieldName))) {
261 throw new DuplicateFieldException(fieldName
262 + " ["
263 + declaringClass.getName()
264 + "]");
265 }
266 }
267 }
268 }
269
270 if (valueField != null) {
271 final Class classDefiningField = valueField.getDeclaringClass();
272 final String fieldName = valueField.getName();
273 final Field field = fieldName == null ? null : reflectionProvider.getField(
274 classDefiningField, fieldName);
275 if (fieldName == null || field == null) {
276 final ConversionException exception = new ConversionException(
277 "Cannot assign value to field of type");
278 exception.add("element", reader.getNodeName());
279 exception.add("field", fieldName);
280 exception.add("target type", context.getRequiredType().getName());
281 throw exception;
282 }
283
284 Class type;
285 final String classAttribute = HierarchicalStreams
286 .readClassAttribute(reader, mapper);
287 if (classAttribute != null) {
288 type = mapper.realClass(classAttribute);
289 } else {
290 type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(
291 result, fieldName, classDefiningField));
292 }
293
294 final Object value = context.convertAnother(
295 result, type,
296 mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
297
298 final Class definedType = reflectionProvider.getFieldType(
299 result, fieldName, classDefiningField);
300 if (!definedType.isPrimitive()) {
301 type = definedType;
302 }
303
304 if (value != null && !type.isAssignableFrom(value.getClass())) {
305 final ConversionException exception = new ConversionException(
306 "Cannot assign object to type");
307 exception.add("object type", value.getClass().getName());
308 exception.add("target type", type.getName());
309 throw exception;
310 }
311
312 reflectionProvider.writeField(result, fieldName, value, classDefiningField);
313 if (!seenFields.add(new FastField(classDefiningField, fieldName))) {
314 throw new DuplicateFieldException(fieldName
315 + " ["
316 + classDefiningField.getName()
317 + "]");
318 }
319 }
320 return result;
321 }
322
323 private boolean fieldIsEqual(FastField field) {
324 return valueField.getName().equals(field.getName())
325 && valueField.getDeclaringClass().getName().equals(field.getDeclaringClass());
326 }
327 }
0 /*
1 * Copyright (C) 2006, 2007 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 07. July 2006 by Mauro Talevi
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.InvocationTargetException;
17
18 /**
19 * Convenient converter for classes with natural string representation.
20 *
21 * Converter for classes that adopt the following convention:
22 * - a constructor that takes a single string parameter
23 * - a toString() that is overloaded to issue a string that is meaningful
24 *
25 * @author Paul Hammant
26 */
27 public class ToStringConverter extends AbstractSingleValueConverter {
28 private final Class clazz;
29 private final Constructor ctor;
30
31 public ToStringConverter(Class clazz) throws NoSuchMethodException {
32 this.clazz = clazz;
33 ctor = clazz.getConstructor(new Class[] {String.class});
34 }
35 public boolean canConvert(Class type) {
36 return type.equals(clazz);
37 }
38 public String toString(Object obj) {
39 return obj == null ? null : obj.toString();
40 }
41
42 public Object fromString(String str) {
43 try {
44 return ctor.newInstance(new Object[] {str});
45 } catch (InstantiationException e) {
46 throw new ConversionException("Unable to instantiate single String param constructor", e);
47 } catch (IllegalAccessException e) {
48 throw new ConversionException("Unable to access single String param constructor", e);
49 } catch (InvocationTargetException e) {
50 throw new ConversionException("Unable to target single String param constructor", e.getTargetException());
51 }
52 }
53 }
0 /*
1 * Copyright (C) 2013 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 25. September 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.SingleValueConverter;
13 import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
14 import com.thoughtworks.xstream.mapper.AttributeMapper;
15 import com.thoughtworks.xstream.mapper.DefaultMapper;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 class UseAttributeForEnumMapper extends AttributeMapper {
19
20 public UseAttributeForEnumMapper(Mapper wrapped) {
21 super(wrapped, null, null);
22 }
23
24 /**
25 * @deprecated only used for Java 1.4 support
26 */
27 public static boolean isEnum(Class type) {
28 while(type != null && type != Object.class) {
29 if (type.getName().equals("java.lang.Enum")) {
30 return true;
31 }
32 type = type.getSuperclass();
33 }
34 return false;
35 }
36
37 public boolean shouldLookForSingleValueConverter(String fieldName, Class type,
38 Class definedIn) {
39 return isEnum(type);
40 }
41
42 public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
43 Class definedIn) {
44 return null;
45 }
46
47 public SingleValueConverter getConverterFromAttribute(Class definedIn,
48 String attribute, Class type) {
49 return null;
50 }
51
52 static Mapper createEnumMapper(final Mapper mapper) {
53 try {
54 Class enumMapperClass = Class.forName(
55 "com.thoughtworks.xstream.mapper.EnumMapper", true,
56 Mapper.class.getClassLoader());
57 return (Mapper)DependencyInjectionFactory.newInstance(
58 enumMapperClass,
59 new Object[]{new UseAttributeForEnumMapper(mapper
60 .lookupMapperOfType(DefaultMapper.class))});
61 } catch (Exception e) {
62 return null;
63 }
64 }
65 }
0 <!--
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 10. May 2004 by Joe Walnes
10 -->
11 <body>
12 <p>Extra converters that may not be enabled in XStream by default.</p>
13 </body>
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import java.lang.reflect.InvocationTargetException;
14 import java.lang.reflect.Method;
15 import java.lang.reflect.UndeclaredThrowableException;
16
17 /**
18 * Provide access to a bean property.
19 *
20 * @author <a href="mailto:andrea.aime@aliceposta.it">Andrea Aime</a>
21 * @deprecated As of 1.3.1, no longer in use
22 */
23 public class BeanProperty {
24
25 /** the target class */
26 private Class memberClass;
27
28 /** the property name */
29 private String propertyName;
30
31 /** the property type */
32 private Class type;
33
34 /** the getter */
35 protected Method getter;
36
37 /** the setter */
38 private Method setter;
39
40 private static final Object[] EMPTY_ARGS = new Object[0];
41
42 /**
43 * Creates a new {@link BeanProperty}that gets the specified property from
44 * the specified class.
45 */
46 public BeanProperty(Class memberClass, String propertyName, Class propertyType) {
47 this.memberClass = memberClass;
48 this.propertyName = propertyName;
49 this.type = propertyType;
50 }
51
52 /**
53 * Gets the base class that this getter accesses.
54 */
55 public Class getBeanClass() {
56 return memberClass;
57 }
58
59 /**
60 * Returns the property type
61 */
62 public Class getType() {
63 return type;
64 }
65
66 /**
67 * Gets the name of the property that this getter extracts.
68 */
69 public String getName() {
70 return propertyName;
71 }
72
73 /**
74 * Gets whether this property can get get.
75 */
76 public boolean isReadable() {
77 return (getter != null);
78 }
79
80 /**
81 * Gets whether this property can be set.
82 */
83 public boolean isWritable() {
84 return (setter != null);
85 }
86
87 /**
88 * Gets the value of this property for the specified Object.
89 * @throws IllegalAccessException
90 * @throws IllegalArgumentException
91 */
92 public Object get(Object member) throws IllegalArgumentException, IllegalAccessException {
93 if (!isReadable())
94 throw new IllegalStateException("Property " + propertyName + " of " + memberClass
95 + " not readable");
96
97 try {
98 return getter.invoke(member, EMPTY_ARGS);
99 } catch (InvocationTargetException e) {
100 throw new UndeclaredThrowableException(e.getTargetException());
101 }
102 }
103
104 /**
105 * Sets the value of this property for the specified Object.
106 * @throws IllegalAccessException
107 * @throws IllegalArgumentException
108 */
109 public Object set(Object member, Object newValue) throws IllegalArgumentException, IllegalAccessException {
110 if (!isWritable())
111 throw new IllegalStateException("Property " + propertyName + " of " + memberClass
112 + " not writable");
113
114 try {
115 return setter.invoke(member, new Object[] { newValue });
116 } catch (InvocationTargetException e) {
117 throw new UndeclaredThrowableException(e.getTargetException());
118 }
119 }
120
121 /**
122 * @param method
123 */
124 public void setGetterMethod(Method method) {
125 this.getter = method;
126
127 }
128
129 /**
130 * @param method
131 */
132 public void setSetterMethod(Method method) {
133 this.setter = method;
134 }
135 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import java.beans.PropertyDescriptor;
14 import java.lang.reflect.Constructor;
15 import java.lang.reflect.InvocationTargetException;
16 import java.lang.reflect.Method;
17 import java.lang.reflect.Modifier;
18 import java.util.ArrayList;
19 import java.util.Comparator;
20 import java.util.Iterator;
21 import java.util.List;
22
23 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
24
25
26 public class BeanProvider implements JavaBeanProvider {
27
28 /**
29 * @deprecated As of 1.4.6
30 */
31 protected static final Object[] NO_PARAMS = new Object[0];
32 protected PropertyDictionary propertyDictionary;
33
34 /**
35 * Construct a BeanProvider that will process the bean properties in their natural order.
36 */
37 public BeanProvider() {
38 this(new PropertyDictionary(new NativePropertySorter()));
39 }
40
41 /**
42 * Construct a BeanProvider with a comparator to sort the bean properties by name in the
43 * dictionary.
44 *
45 * @param propertyNameComparator the comparator
46 */
47 public BeanProvider(final Comparator propertyNameComparator) {
48 this(new PropertyDictionary(new ComparingPropertySorter(propertyNameComparator)));
49 }
50
51 /**
52 * Construct a BeanProvider with a provided property dictionary.
53 *
54 * @param propertyDictionary the property dictionary to use
55 * @since 1.4
56 */
57 public BeanProvider(final PropertyDictionary propertyDictionary) {
58 this.propertyDictionary = propertyDictionary;
59 }
60
61 public Object newInstance(Class type) {
62 try {
63 return type.newInstance();
64 } catch (InstantiationException e) {
65 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
66 } catch (IllegalAccessException e) {
67 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
68 } catch (SecurityException e) {
69 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
70 } catch (ExceptionInInitializerError e) {
71 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
72 }
73 }
74
75 public void visitSerializableProperties(Object object, JavaBeanProvider.Visitor visitor) {
76 PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object);
77 for (int i = 0; i < propertyDescriptors.length; i++ ) {
78 PropertyDescriptor property = propertyDescriptors[i];
79 try {
80 Method readMethod = property.getReadMethod();
81 String name = property.getName();
82 Class definedIn = readMethod.getDeclaringClass();
83 if (visitor.shouldVisit(name, definedIn)) {
84 Object value = readMethod.invoke(object, new Object[0]);
85 visitor.visit(name, property.getPropertyType(), definedIn, value);
86 }
87 } catch (IllegalArgumentException e) {
88 throw new ObjectAccessException("Could not get property "
89 + object.getClass()
90 + "."
91 + property.getName(), e);
92 } catch (IllegalAccessException e) {
93 throw new ObjectAccessException("Could not get property "
94 + object.getClass()
95 + "."
96 + property.getName(), e);
97 } catch (InvocationTargetException e) {
98 throw new ObjectAccessException("Could not get property "
99 + object.getClass()
100 + "."
101 + property.getName(), e);
102 }
103 }
104 }
105
106 public void writeProperty(Object object, String propertyName, Object value) {
107 PropertyDescriptor property = getProperty(propertyName, object.getClass());
108 try {
109 property.getWriteMethod().invoke(object, new Object[]{value});
110 } catch (IllegalArgumentException e) {
111 throw new ObjectAccessException("Could not set property "
112 + object.getClass()
113 + "."
114 + property.getName(), e);
115 } catch (IllegalAccessException e) {
116 throw new ObjectAccessException("Could not set property "
117 + object.getClass()
118 + "."
119 + property.getName(), e);
120 } catch (InvocationTargetException e) {
121 throw new ObjectAccessException("Could not set property "
122 + object.getClass()
123 + "."
124 + property.getName(), e);
125 }
126 }
127
128 public Class getPropertyType(Object object, String name) {
129 return getProperty(name, object.getClass()).getPropertyType();
130 }
131
132 public boolean propertyDefinedInClass(String name, Class type) {
133 return getProperty(name, type) != null;
134 }
135
136 /**
137 * Returns true if the Bean provider can instantiate the specified class
138 */
139 public boolean canInstantiate(Class type) {
140 try {
141 return newInstance(type) != null;
142 } catch (ObjectAccessException e) {
143 return false;
144 }
145 }
146
147 /**
148 * Returns the default constructor, or null if none is found
149 *
150 * @param type
151 * @deprecated As of 1.4.6 use {@link #newInstance(Class)} or {@link #canInstantiate(Class)} directly.
152 */
153 protected Constructor getDefaultConstrutor(Class type) {
154
155 Constructor[] constructors = type.getConstructors();
156 for (int i = 0; i < constructors.length; i++ ) {
157 Constructor c = constructors[i];
158 if (c.getParameterTypes().length == 0 && Modifier.isPublic(c.getModifiers()))
159 return c;
160 }
161 return null;
162 }
163
164 protected PropertyDescriptor[] getSerializableProperties(Object object) {
165 List result = new ArrayList();
166 for (final Iterator iter = propertyDictionary.propertiesFor(object.getClass()); iter.hasNext();) {
167 final PropertyDescriptor descriptor = (PropertyDescriptor)iter.next();
168 if (canStreamProperty(descriptor)) {
169 result.add(descriptor);
170 }
171 }
172 return (PropertyDescriptor[])result.toArray(new PropertyDescriptor[result.size()]);
173 }
174
175 protected boolean canStreamProperty(PropertyDescriptor descriptor) {
176 return descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null;
177 }
178
179 public boolean propertyWriteable(String name, Class type) {
180 PropertyDescriptor property = getProperty(name, type);
181 return property.getWriteMethod() != null;
182 }
183
184 protected PropertyDescriptor getProperty(String name, Class type) {
185 return (PropertyDescriptor)propertyDictionary.propertyDescriptor(type, name);
186 }
187
188 /**
189 * @deprecated As of 1.4 use {@link JavaBeanProvider.Visitor}
190 */
191 public interface Visitor extends JavaBeanProvider.Visitor {
192 }
193 }
0 /*
1 * Copyright (C) 2011 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 16. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.javabean;
11
12 import java.util.Comparator;
13 import java.util.Map;
14 import java.util.TreeMap;
15
16 /**
17 * A sorter that uses a comparator to determine the order of the bean properties.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.4
21 */
22 public class ComparingPropertySorter implements PropertySorter {
23
24 private final Comparator comparator;
25
26 public ComparingPropertySorter(final Comparator propertyNameComparator) {
27 this.comparator = propertyNameComparator;
28 }
29
30 public Map sort(final Class type, final Map nameMap) {
31 TreeMap map = new TreeMap(comparator);
32 map.putAll(nameMap);
33 return map;
34 }
35
36 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import java.util.HashSet;
14 import java.util.Set;
15
16 import com.thoughtworks.xstream.converters.ConversionException;
17 import com.thoughtworks.xstream.converters.Converter;
18 import com.thoughtworks.xstream.converters.MarshallingContext;
19 import com.thoughtworks.xstream.converters.UnmarshallingContext;
20 import com.thoughtworks.xstream.converters.reflection.MissingFieldException;
21 import com.thoughtworks.xstream.core.util.FastField;
22 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
23 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
24 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
25 import com.thoughtworks.xstream.mapper.Mapper;
26
27 /**
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.
30 */
31 public class JavaBeanConverter implements Converter {
32
33 /*
34 * TODO:
35 * - support indexed properties
36 * - support attributes (XSTR-620)
37 * - support local converters (XSTR-601)
38 * Problem: Mappers take definitions based on reflection, they don't know about bean info
39 */
40 protected final Mapper mapper;
41 protected final JavaBeanProvider beanProvider;
42 private final Class type;
43
44 /**
45 * @deprecated As of 1.3, no necessity for field anymore.
46 */
47 private String classAttributeIdentifier;
48
49 public JavaBeanConverter(Mapper mapper) {
50 this(mapper, (Class)null);
51 }
52
53 public JavaBeanConverter(Mapper mapper, Class type) {
54 this(mapper, new BeanProvider(), type);
55 }
56
57 public JavaBeanConverter(Mapper mapper, JavaBeanProvider beanProvider) {
58 this(mapper,beanProvider, null);
59 }
60
61 public JavaBeanConverter(Mapper mapper, JavaBeanProvider beanProvider, Class type) {
62 this.mapper = mapper;
63 this.beanProvider = beanProvider;
64 this.type = type;
65 }
66
67 /**
68 * @deprecated As of 1.3, use {@link #JavaBeanConverter(Mapper)} and {@link com.thoughtworks.xstream.XStream#aliasAttribute(String, String)}
69 */
70 public JavaBeanConverter(Mapper mapper, String classAttributeIdentifier) {
71 this(mapper, new BeanProvider());
72 this.classAttributeIdentifier = classAttributeIdentifier;
73 }
74
75 /**
76 * Checks if the bean provider can instantiate this type.
77 * If you need less strict checks, subclass JavaBeanConverter
78 */
79 public boolean canConvert(Class type) {
80 return (this.type == null || this.type == type) && beanProvider.canInstantiate(type);
81 }
82
83 public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
84 final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class");
85 beanProvider.visitSerializableProperties(source, new JavaBeanProvider.Visitor() {
86 public boolean shouldVisit(String name, Class definedIn) {
87 return mapper.shouldSerializeMember(definedIn, name);
88 }
89
90 public void visit(String propertyName, Class fieldType, Class definedIn, Object newObj) {
91 if (newObj != null) {
92 writeField(propertyName, fieldType, newObj, definedIn);
93 }
94 }
95
96 private void writeField(String propertyName, Class fieldType, Object newObj, Class definedIn) {
97 Class actualType = newObj.getClass();
98 Class defaultType = mapper.defaultImplementationOf(fieldType);
99 String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
100 ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType);
101 if (!actualType.equals(defaultType) && classAttributeName != null) {
102 writer.addAttribute(classAttributeName, mapper.serializedClass(actualType));
103 }
104 context.convertAnother(newObj);
105
106 writer.endNode();
107 }
108 });
109 }
110
111 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
112 final Object result = instantiateNewInstance(context);
113 final Set seenProperties = new HashSet() {
114 public boolean add(Object e) {
115 if (!super.add(e)) {
116 throw new DuplicatePropertyException(((FastField)e).getName());
117 }
118 return true;
119 }
120 };
121
122 Class resultType = result.getClass();
123 while (reader.hasMoreChildren()) {
124 reader.moveDown();
125
126 String propertyName = mapper.realMember(resultType, reader.getNodeName());
127
128 if (mapper.shouldSerializeMember(resultType, propertyName)) {
129 boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType);
130
131 if (propertyExistsInClass) {
132 Class type = determineType(reader, result, propertyName);
133 Object value = context.convertAnother(result, type);
134 beanProvider.writeProperty(result, propertyName, value);
135 seenProperties.add(new FastField(resultType, propertyName));
136 } else {
137 throw new MissingFieldException(resultType.getName(), propertyName);
138 }
139 }
140 reader.moveUp();
141 }
142
143 return result;
144 }
145
146 private Object instantiateNewInstance(UnmarshallingContext context) {
147 Object result = context.currentObject();
148 if (result == null) {
149 result = beanProvider.newInstance(context.getRequiredType());
150 }
151 return result;
152 }
153
154 private Class determineType(HierarchicalStreamReader reader, Object result, String fieldName) {
155 final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class");
156 String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName);
157 if (classAttribute != null) {
158 return mapper.realClass(classAttribute);
159 } else {
160 return mapper.defaultImplementationOf(beanProvider.getPropertyType(result, fieldName));
161 }
162 }
163
164 /**
165 * @deprecated As of 1.3
166 */
167 public static class DuplicateFieldException extends ConversionException {
168 public DuplicateFieldException(String msg) {
169 super(msg);
170 }
171 }
172
173 /**
174 * Exception to indicate double processing of a property to avoid silent clobbering.
175 *
176 * @author J&ouml;rg Schaible
177 * @since 1.4.2
178 */
179 public static class DuplicatePropertyException extends ConversionException {
180 public DuplicatePropertyException(String msg) {
181 super("Duplicate property " + msg);
182 add("property", msg);
183 }
184 }
185 }
0 /*
1 * Copyright (C) 2011 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 07. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.javabean;
11
12
13 /**
14 * @author J&ouml;rg Schaible
15 *
16 * @since 1.4
17 */
18 public interface JavaBeanProvider {
19
20 Object newInstance(Class type);
21
22 void visitSerializableProperties(Object object, Visitor visitor);
23
24 void writeProperty(Object object, String propertyName, Object value);
25
26 Class getPropertyType(Object object, String name);
27
28 boolean propertyDefinedInClass(String name, Class type);
29
30 /**
31 * Returns true if the Bean provider can instantiate the specified class
32 */
33 boolean canInstantiate(Class type);
34
35 public interface Visitor {
36 boolean shouldVisit(String name, Class definedIn);
37 void visit(String name, Class type, Class definedIn, Object value);
38 }
39
40 }
0 /*
1 * Copyright (C) 2011 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 16. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.javabean;
11
12 import java.util.Map;
13
14
15 /**
16 * A sorter that keeps the natural order of the bean properties as they are returned by the
17 * JavaBean introspection.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.4
21 */
22 public class NativePropertySorter implements PropertySorter {
23
24 public Map sort(final Class type, final Map nameMap) {
25 return nameMap;
26 }
27
28 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import java.beans.BeanInfo;
14 import java.beans.IntrospectionException;
15 import java.beans.Introspector;
16 import java.beans.PropertyDescriptor;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23
24 import com.thoughtworks.xstream.converters.reflection.MissingFieldException;
25 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
26 import com.thoughtworks.xstream.core.Caching;
27 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
28
29
30 /**
31 * Builds the properties maps for each bean and caches them.
32 *
33 * @author Joe Walnes
34 * @author J&ouml;rg Schaible
35 */
36 public class PropertyDictionary implements Caching {
37 private transient Map propertyNameCache = Collections.synchronizedMap(new HashMap());
38 private final PropertySorter sorter;
39
40 public PropertyDictionary() {
41 this(new NativePropertySorter());
42 }
43
44 public PropertyDictionary(PropertySorter sorter) {
45 this.sorter = sorter;
46 }
47
48 /**
49 * @deprecated As of 1.3.1, use {@link #propertiesFor(Class)} instead
50 */
51 public Iterator serializablePropertiesFor(Class type) {
52 Collection beanProperties = new ArrayList();
53 Collection descriptors = buildMap(type).values();
54 for (Iterator iter = descriptors.iterator(); iter.hasNext();) {
55 PropertyDescriptor descriptor = (PropertyDescriptor)iter.next();
56 if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) {
57 beanProperties.add(new BeanProperty(type, descriptor.getName(), descriptor
58 .getPropertyType()));
59 }
60 }
61 return beanProperties.iterator();
62 }
63
64 /**
65 * Locates a serializable property.
66 *
67 * @param cls
68 * @param name
69 * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead
70 */
71 public BeanProperty property(Class cls, String name) {
72 BeanProperty beanProperty = null;
73 PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(cls).get(name);
74 if (descriptor == null) {
75 throw new MissingFieldException(cls.getName(), name);
76 }
77 if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) {
78 beanProperty = new BeanProperty(
79 cls, descriptor.getName(), descriptor.getPropertyType());
80 }
81 return beanProperty;
82 }
83
84 public Iterator propertiesFor(Class type) {
85 return buildMap(type).values().iterator();
86 }
87
88 /**
89 * Locates a property descriptor.
90 *
91 * @param type
92 * @param name
93 */
94 public PropertyDescriptor propertyDescriptor(Class type, String name) {
95 PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(type).get(name);
96 if (descriptor == null) {
97 throw new MissingFieldException(type.getName(), name);
98 }
99 return descriptor;
100 }
101
102 private Map buildMap(Class type) {
103 Map nameMap = (Map)propertyNameCache.get(type);
104 if (nameMap == null) {
105 BeanInfo beanInfo;
106 try {
107 beanInfo = Introspector.getBeanInfo(type, Object.class);
108 } catch (IntrospectionException e) {
109 throw new ObjectAccessException(
110 "Cannot get BeanInfo of type " + type.getName(), e);
111 }
112 nameMap = new OrderRetainingMap();
113 PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
114 for (int i = 0; i < propertyDescriptors.length; i++ ) {
115 PropertyDescriptor descriptor = propertyDescriptors[i];
116 nameMap.put(descriptor.getName(), descriptor);
117 }
118 nameMap = sorter.sort(type, nameMap);
119 propertyNameCache.put(type, nameMap);
120 }
121 return nameMap;
122 }
123
124 public void flushCache() {
125 propertyNameCache.clear();
126 }
127 }
0 /*
1 * Copyright (C) 2011 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 16. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.javabean;
11
12 import java.beans.PropertyDescriptor;
13 import java.util.Map;
14
15 /**
16 * An interface capable of sorting Java bean properties. Implement this interface if you
17 * want to customize the order in which XStream serializes the properties of a bean.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.4
21 */
22 public interface PropertySorter {
23
24 /**
25 * Sort the properties of a bean type. The method will be called with the class type
26 * that contains all the properties and a Map that retains the order in which the
27 * elements have been added. The sequence in which elements are returned by an iterator
28 * defines the processing order of the properties. An implementation may create a
29 * different Map with similar semantic, add all elements of the original map and return
30 * the new one.
31 *
32 * @param type the bean class that contains all the properties
33 * @param nameMap the map to sort, key is the property name, value the
34 * {@link PropertyDescriptor}
35 * @return the sorted nameMap
36 * @since 1.4
37 */
38 Map sort(Class type, Map nameMap);
39
40 }
0 /*
1 * Copyright (C) 2007, 2013 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 01. February 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14 import com.thoughtworks.xstream.core.util.Fields;
15
16 import java.lang.reflect.Field;
17 import java.lang.reflect.InvocationTargetException;
18 import java.lang.reflect.Method;
19 import java.lang.reflect.Modifier;
20 import java.text.AttributedCharacterIterator;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24
25
26 /**
27 * An abstract converter implementation for constants of
28 * {@link java.text.AttributedCharacterIterator.Attribute} and derived types.
29 *
30 * @author J&ouml;rg Schaible
31 * @since 1.2.2
32 */
33 public class AbstractAttributedCharacterIteratorAttributeConverter extends
34 AbstractSingleValueConverter {
35
36 private static final Map instanceMaps = new HashMap();
37 private static final Method getName;
38 static {
39 Method method = null;
40 try {
41 method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod(
42 "getName", (Class[])null);
43 if (!method.isAccessible()) {
44 method.setAccessible(true);
45 }
46 } catch (SecurityException e) {
47 // ignore for now
48 } catch (NoSuchMethodException e) {
49 // ignore for now
50 }
51 getName = method;
52 }
53
54 private final Class type;
55 private transient Map attributeMap;
56
57 public AbstractAttributedCharacterIteratorAttributeConverter(final Class type) {
58 super();
59 if (!AttributedCharacterIterator.Attribute.class.isAssignableFrom(type)) {
60 throw new IllegalArgumentException(type.getName()
61 + " is not a " + AttributedCharacterIterator.Attribute.class.getName());
62 }
63 this.type = type;
64 readResolve();
65 }
66
67 public boolean canConvert(final Class type) {
68 return type == this.type && !attributeMap.isEmpty();
69 }
70
71 public String toString(final Object source) {
72 return getName((AttributedCharacterIterator.Attribute)source);
73 }
74
75 private String getName(AttributedCharacterIterator.Attribute attribute) {
76 Exception ex = null;
77 if (getName != null) {
78 try {
79 return (String)getName.invoke(attribute, (Object[])null);
80 } catch (IllegalAccessException e) {
81 ex = e;
82 } catch (InvocationTargetException e) {
83 ex = e;
84 }
85 }
86 String s = attribute.toString();
87 String className = attribute.getClass().getName();
88 if (s.startsWith(className)) {
89 return s.substring(className.length()+1, s.length()-1);
90 }
91 throw new ConversionException("Cannot find name of attribute of type " + className, ex);
92 }
93
94 public Object fromString(final String str) {
95 if (attributeMap.containsKey(str)) {
96 return attributeMap.get(str);
97 }
98 throw new ConversionException("Cannot find attribute of type " + type.getName() + " with name " + str);
99 }
100
101 private Object readResolve() {
102 attributeMap = (Map)instanceMaps.get(type.getName());
103 if (attributeMap == null) {
104 attributeMap = new HashMap();
105 Field instanceMap = Fields.locate(type, Map.class, true);
106 if (instanceMap != null) {
107 try {
108 Map map = (Map)Fields.read(instanceMap, null);
109 if (map != null) {
110 boolean valid = true;
111 for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) {
112 Map.Entry entry = (Map.Entry)iter.next();
113 valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type;
114 }
115 if (valid) {
116 attributeMap.putAll(map);
117 }
118 }
119 } catch (ObjectAccessException e) {
120 }
121 }
122 if (attributeMap.isEmpty()) {
123 try {
124 Field[] fields = type.getDeclaredFields();
125 for(int i = 0; i < fields.length; ++i) {
126 if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) {
127 AttributedCharacterIterator.Attribute attribute =
128 (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null);
129 attributeMap.put(toString(attribute), attribute);
130 }
131 }
132 } catch (SecurityException e) {
133 attributeMap.clear();
134 } catch (ObjectAccessException e) {
135 attributeMap.clear();
136 } catch (NoClassDefFoundError e) {
137 attributeMap.clear();
138 }
139 }
140 instanceMaps.put(type.getName(), attributeMap);
141 }
142 return this;
143 }
144
145 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 02. March 2006 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.SingleValueConverter;
17 import com.thoughtworks.xstream.converters.UnmarshallingContext;
18 import com.thoughtworks.xstream.core.Caching;
19 import com.thoughtworks.xstream.core.ReferencingMarshallingContext;
20 import com.thoughtworks.xstream.core.util.ArrayIterator;
21 import com.thoughtworks.xstream.core.util.FastField;
22 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
23 import com.thoughtworks.xstream.core.util.Primitives;
24 import com.thoughtworks.xstream.core.util.SerializationMembers;
25 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
26 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
27 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
28 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
29 import com.thoughtworks.xstream.mapper.Mapper;
30
31 import java.lang.reflect.Array;
32 import java.lang.reflect.Field;
33 import java.lang.reflect.Modifier;
34 import java.util.AbstractList;
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.Collections;
38 import java.util.HashMap;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Set;
44
45
46 public abstract class AbstractReflectionConverter implements Converter, Caching {
47
48 protected final ReflectionProvider reflectionProvider;
49 protected final Mapper mapper;
50 /**
51 * @deprecated As of 1.4.8, use {@link #serializationMembers}.
52 */
53 protected transient SerializationMethodInvoker serializationMethodInvoker;
54 protected transient SerializationMembers serializationMembers;
55 private transient ReflectionProvider pureJavaReflectionProvider;
56
57 public AbstractReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
58 this.mapper = mapper;
59 this.reflectionProvider = reflectionProvider;
60 serializationMethodInvoker = new SerializationMethodInvoker();
61 serializationMembers = serializationMethodInvoker.serializationMembers;
62 }
63
64 protected boolean canAccess(Class type) {
65 try {
66 reflectionProvider.getFieldOrNull(type, "%");
67 return true;
68 } catch (NoClassDefFoundError e) {
69 // restricted type in GAE
70 }
71 return false;
72 }
73
74 public void marshal(Object original, final HierarchicalStreamWriter writer,
75 final MarshallingContext context) {
76 final Object source = serializationMembers.callWriteReplace(original);
77
78 if (source != original && context instanceof ReferencingMarshallingContext) {
79 ((ReferencingMarshallingContext)context).replace(original, source);
80 }
81 if (source.getClass() != original.getClass()) {
82 String attributeName = mapper.aliasForSystemAttribute("resolves-to");
83 if (attributeName != null) {
84 writer.addAttribute(attributeName, mapper.serializedClass(source.getClass()));
85 }
86 context.convertAnother(source);
87 } else {
88 doMarshal(source, writer, context);
89 }
90 }
91
92 protected void doMarshal(final Object source, final HierarchicalStreamWriter writer,
93 final MarshallingContext context) {
94 final List fields = new ArrayList();
95 final Map defaultFieldDefinition = new HashMap();
96
97 // Attributes might be preferred to child elements ...
98 reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() {
99 final Set writtenAttributes = new HashSet();
100
101 public void visit(String fieldName, Class type, Class definedIn, Object value) {
102 if (!mapper.shouldSerializeMember(definedIn, fieldName)) {
103 return;
104 }
105 if (!defaultFieldDefinition.containsKey(fieldName)) {
106 Class lookupType = source.getClass();
107 // See XSTR-457 and OmitFieldsTest
108 if (definedIn != source.getClass()
109 && !mapper.shouldSerializeMember(lookupType, fieldName)) {
110 lookupType = definedIn;
111 }
112 defaultFieldDefinition.put(
113 fieldName, reflectionProvider.getField(lookupType, fieldName));
114 }
115
116 SingleValueConverter converter = mapper.getConverterFromItemType(
117 fieldName, type, definedIn);
118 if (converter != null) {
119 final String attribute = mapper.aliasForAttribute(mapper.serializedMember(
120 definedIn, fieldName));
121 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());
127 }
128 final String str = converter.toString(value);
129 if (str != null) {
130 writer.addAttribute(attribute, str);
131 }
132 }
133 writtenAttributes.add(fieldName); // TODO: use attribute
134 } else {
135 fields.add(new FieldInfo(fieldName, type, definedIn, value));
136 }
137 }
138 });
139
140 new Object() {
141 {
142 for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) {
143 FieldInfo info = (FieldInfo)fieldIter.next();
144 if (info.value != null) {
145 Mapper.ImplicitCollectionMapping mapping = mapper
146 .getImplicitCollectionDefForFieldName(
147 source.getClass(), info.fieldName);
148 if (mapping != null) {
149 if (context instanceof ReferencingMarshallingContext) {
150 if (info.value != Collections.EMPTY_LIST
151 && info.value != Collections.EMPTY_SET
152 && info.value != Collections.EMPTY_MAP) {
153 ReferencingMarshallingContext refContext = (ReferencingMarshallingContext)context;
154 refContext.registerImplicit(info.value);
155 }
156 }
157 final boolean isCollection = info.value instanceof Collection;
158 final boolean isMap = info.value instanceof Map;
159 final boolean isEntry = isMap && mapping.getKeyFieldName() == null;
160 final boolean isArray = info.value.getClass().isArray();
161 for (Iterator iter = isArray
162 ? new ArrayIterator(info.value)
163 : isCollection ? ((Collection)info.value).iterator() : isEntry
164 ? ((Map)info.value).entrySet().iterator()
165 : ((Map)info.value).values().iterator(); iter.hasNext();) {
166 Object obj = iter.next();
167 final String itemName;
168 final Class itemType;
169 if (obj == null) {
170 itemType = Object.class;
171 itemName = mapper.serializedClass(null);
172 } else if (isEntry) {
173 final String entryName = mapping.getItemFieldName() != null
174 ? mapping.getItemFieldName()
175 : mapper.serializedClass(Map.Entry.class);
176 Map.Entry entry = (Map.Entry)obj;
177 ExtendedHierarchicalStreamWriterHelper.startNode(
178 writer, entryName, entry.getClass());
179 writeItem(entry.getKey(), context, writer);
180 writeItem(entry.getValue(), context, writer);
181 writer.endNode();
182 continue;
183 } else if (mapping.getItemFieldName() != null) {
184 itemType = mapping.getItemType();
185 itemName = mapping.getItemFieldName();
186 } else {
187 itemType = obj.getClass();
188 itemName = mapper.serializedClass(itemType);
189 }
190 writeField(
191 info.fieldName, itemName, itemType, info.definedIn, obj);
192 }
193 } else {
194 writeField(
195 info.fieldName, null, info.type, info.definedIn, info.value);
196 }
197 }
198 }
199
200 }
201
202 void writeField(String fieldName, String aliasName, Class fieldType,
203 Class definedIn, Object newObj) {
204 Class actualType = newObj != null ? newObj.getClass() : fieldType;
205 ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null
206 ? aliasName
207 : mapper.serializedMember(source.getClass(), fieldName), actualType);
208
209 if (newObj != null) {
210 Class defaultType = mapper.defaultImplementationOf(fieldType);
211 if (!actualType.equals(defaultType)) {
212 String serializedClassName = mapper.serializedClass(actualType);
213 if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
214 String attributeName = mapper.aliasForSystemAttribute("class");
215 if (attributeName != null) {
216 writer.addAttribute(attributeName, serializedClassName);
217 }
218 }
219 }
220
221 final Field defaultField = (Field)defaultFieldDefinition.get(fieldName);
222 if (defaultField.getDeclaringClass() != definedIn) {
223 String attributeName = mapper.aliasForSystemAttribute("defined-in");
224 if (attributeName != null) {
225 writer.addAttribute(
226 attributeName, mapper.serializedClass(definedIn));
227 }
228 }
229
230 Field field = reflectionProvider.getField(definedIn, fieldName);
231 marshallField(context, newObj, field);
232 }
233 writer.endNode();
234 }
235
236 void writeItem(Object item, MarshallingContext context,
237 HierarchicalStreamWriter writer) {
238 if (item == null) {
239 String name = mapper.serializedClass(null);
240 ExtendedHierarchicalStreamWriterHelper.startNode(
241 writer, name, Mapper.Null.class);
242 writer.endNode();
243 } else {
244 String name = mapper.serializedClass(item.getClass());
245 ExtendedHierarchicalStreamWriterHelper.startNode(
246 writer, name, item.getClass());
247 context.convertAnother(item);
248 writer.endNode();
249 }
250 }
251 };
252 }
253
254 protected void marshallField(final MarshallingContext context, Object newObj, Field field) {
255 context.convertAnother(
256 newObj, mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
257 }
258
259 public Object unmarshal(final HierarchicalStreamReader reader,
260 final UnmarshallingContext context) {
261 Object result = instantiateNewInstance(reader, context);
262 result = doUnmarshal(result, reader, context);
263 return serializationMembers.callReadResolve(result);
264 }
265
266 public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader,
267 final UnmarshallingContext context) {
268 final Class resultType = result.getClass();
269 final Set seenFields = new HashSet() {
270 public boolean add(Object e) {
271 if (!super.add(e)) {
272 throw new DuplicateFieldException(((FastField)e).getName());
273 }
274 return true;
275 }
276 };
277
278 // process attributes before recursing into child elements.
279 Iterator it = reader.getAttributeNames();
280 while (it.hasNext()) {
281 String attrAlias = (String)it.next();
282 // TODO: realMember should return FastField
283 String attrName = mapper
284 .realMember(resultType, mapper.attributeForAlias(attrAlias));
285 Field field = reflectionProvider.getFieldOrNull(resultType, attrName);
286 if (field != null && shouldUnmarshalField(field)) {
287 Class classDefiningField = field.getDeclaringClass();
288 if (!mapper.shouldSerializeMember(classDefiningField, attrName)) {
289 continue;
290 }
291
292 // we need a converter that produces a string representation only
293 SingleValueConverter converter = mapper.getConverterFromAttribute(
294 classDefiningField, attrName, field.getType());
295 Class type = field.getType();
296 if (converter != null) {
297 Object value = converter.fromString(reader.getAttribute(attrAlias));
298 if (type.isPrimitive()) {
299 type = Primitives.box(type);
300 }
301 if (value != null && !type.isAssignableFrom(value.getClass())) {
302 throw new ConversionException("Cannot convert type "
303 + value.getClass().getName()
304 + " to type "
305 + type.getName());
306 }
307 seenFields.add(new FastField(classDefiningField, attrName));
308 reflectionProvider.writeField(result, attrName, value, classDefiningField);
309 }
310 }
311 }
312
313 Map implicitCollectionsForCurrentObject = null;
314 while (reader.hasMoreChildren()) {
315 reader.moveDown();
316
317 String originalNodeName = reader.getNodeName();
318 Class explicitDeclaringClass = readDeclaringClass(reader);
319 Class fieldDeclaringClass = explicitDeclaringClass == null
320 ? resultType
321 : explicitDeclaringClass;
322 String fieldName = mapper.realMember(fieldDeclaringClass, originalNodeName);
323 Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper
324 .getImplicitCollectionDefForFieldName(fieldDeclaringClass, fieldName);
325 final Object value;
326 String implicitFieldName = null;
327 Field field = null;
328 Class type = null;
329 if (implicitCollectionMapping == null) {
330 // no item of an implicit collection for this name ... do we have a field?
331 field = reflectionProvider.getFieldOrNull(fieldDeclaringClass, fieldName);
332 if (field == null) {
333 // it is not a field ... do we have a field alias?
334 Class itemType = mapper.getItemTypeForItemFieldName(resultType, fieldName);
335 if (itemType != null) {
336 String classAttribute = HierarchicalStreams.readClassAttribute(
337 reader, mapper);
338 if (classAttribute != null) {
339 type = mapper.realClass(classAttribute);
340 } else {
341 type = itemType;
342 }
343 } else {
344 // it is not an alias ... do we have an element of an implicit
345 // collection based on type only?
346 try {
347 type = mapper.realClass(originalNodeName);
348 implicitFieldName = mapper.getFieldNameForItemTypeAndName(
349 context.getRequiredType(), type, originalNodeName);
350 } catch (CannotResolveClassException e) {
351 // type stays null ...
352 }
353 if (type == null || (type != null && implicitFieldName == null)) {
354 // either not a type or element is a type alias, but does not
355 // belong to an implicit field
356 handleUnknownField(
357 explicitDeclaringClass, fieldName, resultType, originalNodeName);
358
359 // element is unknown in declaring class, ignore it now
360 type = null;
361 }
362 }
363 if (type == null) {
364 // no type, no value
365 value = null;
366 } else {
367 if (Map.Entry.class.equals(type)) {
368 // it is an element of an implicit map with two elements now for
369 // key and value
370 reader.moveDown();
371 final Object key = context.convertAnother(
372 result, HierarchicalStreams.readClassType(reader, mapper));
373 reader.moveUp();
374 reader.moveDown();
375 final Object v = context.convertAnother(
376 result, HierarchicalStreams.readClassType(reader, mapper));
377 reader.moveUp();
378 value = Collections.singletonMap(key, v)
379 .entrySet().iterator().next();
380 } else {
381 // recurse info hierarchy
382 value = context.convertAnother(result, type);
383 }
384 }
385 } else {
386 boolean fieldAlreadyChecked = false;
387
388 // we have a field, but do we have to address a hidden one?
389 if (explicitDeclaringClass == null) {
390 while (field != null
391 && !(fieldAlreadyChecked = shouldUnmarshalField(field)
392 && mapper.shouldSerializeMember(
393 field.getDeclaringClass(), fieldName))) {
394 field = reflectionProvider.getFieldOrNull(field
395 .getDeclaringClass()
396 .getSuperclass(), fieldName);
397 }
398 }
399 if (field != null
400 && (fieldAlreadyChecked || (shouldUnmarshalField(field) && mapper
401 .shouldSerializeMember(field.getDeclaringClass(), fieldName)))) {
402
403 String classAttribute = HierarchicalStreams.readClassAttribute(
404 reader, mapper);
405 if (classAttribute != null) {
406 type = mapper.realClass(classAttribute);
407 } else {
408 type = mapper.defaultImplementationOf(field.getType());
409 }
410 // TODO the reflection provider should already return the proper field
411 value = unmarshallField(context, result, type, field);
412 Class definedType = field.getType();
413 if (!definedType.isPrimitive()) {
414 type = definedType;
415 }
416 } else {
417 value = null;
418 }
419 }
420 } else {
421 // we have an implicit collection with defined names
422 implicitFieldName = implicitCollectionMapping.getFieldName();
423 type = implicitCollectionMapping.getItemType();
424 if (type == null) {
425 String classAttribute = HierarchicalStreams.readClassAttribute(
426 reader, mapper);
427 type = mapper.realClass(classAttribute != null
428 ? classAttribute
429 : originalNodeName);
430 }
431 value = context.convertAnother(result, type);
432 }
433
434 if (value != null && !type.isAssignableFrom(value.getClass())) {
435 throw new ConversionException("Cannot convert type "
436 + value.getClass().getName()
437 + " to type "
438 + type.getName());
439 }
440
441 if (field != null) {
442 reflectionProvider.writeField(result, fieldName, value, field.getDeclaringClass());
443 seenFields.add(new FastField(field.getDeclaringClass(), fieldName));
444 } else if (type != null) {
445 if (implicitFieldName == null) {
446 // look for implicit field
447 implicitFieldName = mapper.getFieldNameForItemTypeAndName(
448 context.getRequiredType(),
449 value != null ? value.getClass() : Mapper.Null.class,
450 originalNodeName);
451 }
452 if (implicitCollectionsForCurrentObject == null) {
453 implicitCollectionsForCurrentObject = new HashMap();
454 }
455 writeValueToImplicitCollection(
456 value, implicitCollectionsForCurrentObject, result, implicitFieldName);
457 }
458
459 reader.moveUp();
460 }
461
462 if (implicitCollectionsForCurrentObject != null) {
463 for (Iterator iter = implicitCollectionsForCurrentObject.entrySet().iterator(); iter
464 .hasNext();) {
465 Map.Entry entry = (Map.Entry)iter.next();
466 Object value = entry.getValue();
467 if (value instanceof ArraysList) {
468 Object array = ((ArraysList)value).toPhysicalArray();
469 reflectionProvider.writeField(result, (String)entry.getKey(), array, null);
470 }
471 }
472 }
473
474 return result;
475 }
476
477 protected Object unmarshallField(final UnmarshallingContext context, final Object result,
478 Class type, Field field) {
479 return context.convertAnother(
480 result, type, mapper.getLocalConverter(field.getDeclaringClass(), field.getName()));
481 }
482
483 protected boolean shouldUnmarshalTransientFields() {
484 return false;
485 }
486
487 protected boolean shouldUnmarshalField(Field field) {
488 return !(Modifier.isTransient(field.getModifiers()) && !shouldUnmarshalTransientFields());
489 }
490
491 private void handleUnknownField(Class classDefiningField, String fieldName,
492 Class resultType, String originalNodeName) {
493 if (classDefiningField == null) {
494 for (Class cls = resultType; cls != null; cls = cls.getSuperclass()) {
495 if (!mapper.shouldSerializeMember(cls, originalNodeName)) {
496 return;
497 }
498 }
499 }
500 throw new UnknownFieldException(resultType.getName(), fieldName);
501 }
502
503 private void writeValueToImplicitCollection(Object value, Map implicitCollections, Object result, String implicitFieldName) {
504 Collection collection = (Collection)implicitCollections.get(implicitFieldName);
505 if (collection == null) {
506 Class physicalFieldType = reflectionProvider.getFieldType(
507 result, implicitFieldName, null);
508 if (physicalFieldType.isArray()) {
509 collection = new ArraysList(physicalFieldType);
510 } else {
511 Class fieldType = mapper.defaultImplementationOf(physicalFieldType);
512 if (!(Collection.class.isAssignableFrom(fieldType) || Map.class
513 .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());
521 }
522 if (pureJavaReflectionProvider == null) {
523 pureJavaReflectionProvider = new PureJavaReflectionProvider();
524 }
525 Object instance = pureJavaReflectionProvider.newInstance(fieldType);
526 if (instance instanceof Collection) {
527 collection = (Collection)instance;
528 } else {
529 Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper
530 .getImplicitCollectionDefForFieldName(result.getClass(), implicitFieldName);
531 collection = new MappingList(
532 (Map)instance, implicitCollectionMapping.getKeyFieldName());
533 }
534 reflectionProvider.writeField(result, implicitFieldName, instance, null);
535 }
536 implicitCollections.put(implicitFieldName, collection);
537 }
538 collection.add(value);
539 }
540
541 private Class readDeclaringClass(HierarchicalStreamReader reader) {
542 String attributeName = mapper.aliasForSystemAttribute("defined-in");
543 String definedIn = attributeName == null ? null : reader.getAttribute(attributeName);
544 return definedIn == null ? null : mapper.realClass(definedIn);
545 }
546
547 protected Object instantiateNewInstance(HierarchicalStreamReader reader,
548 UnmarshallingContext context) {
549 String attributeName = mapper.aliasForSystemAttribute("resolves-to");
550 String readResolveValue = attributeName == null ? null : reader
551 .getAttribute(attributeName);
552 Object currentObject = context.currentObject();
553 if (currentObject != null) {
554 return currentObject;
555 } else if (readResolveValue != null) {
556 return reflectionProvider.newInstance(mapper.realClass(readResolveValue));
557 } else {
558 return reflectionProvider.newInstance(context.getRequiredType());
559 }
560 }
561
562 public void flushCache() {
563 serializationMethodInvoker.flushCache();
564 }
565
566 protected Object readResolve() {
567 serializationMethodInvoker = new SerializationMethodInvoker();
568 serializationMembers = serializationMethodInvoker.serializationMembers;
569 return this;
570 }
571
572 public static class DuplicateFieldException extends ConversionException {
573 public DuplicateFieldException(String msg) {
574 super("Duplicate field " + msg);
575 add("field", msg);
576 }
577 }
578
579 public static class UnknownFieldException extends ConversionException {
580 public UnknownFieldException(String type, String field) {
581 super("No such field " + type + "." + field);
582 add("field", field);
583 }
584 }
585
586 private static class FieldInfo {
587 final String fieldName;
588 final Class type;
589 final Class definedIn;
590 final Object value;
591
592 FieldInfo(String fieldName, Class type, Class definedIn, Object value) {
593 this.fieldName = fieldName;
594 this.type = type;
595 this.definedIn = definedIn;
596 this.value = value;
597 }
598 }
599
600 private static class ArraysList extends ArrayList {
601 final Class physicalFieldType;
602
603 ArraysList(Class physicalFieldType) {
604 this.physicalFieldType = physicalFieldType;
605 }
606
607 Object toPhysicalArray() {
608 Object[] objects = toArray();
609 Object array = Array.newInstance(
610 physicalFieldType.getComponentType(), objects.length);
611 if (physicalFieldType.getComponentType().isPrimitive()) {
612 for (int i = 0; i < objects.length; ++i) {
613 Array.set(array, i, Array.get(objects, i));
614 }
615 } else {
616 System.arraycopy(objects, 0, array, 0, objects.length);
617 }
618 return array;
619 }
620 }
621
622 private class MappingList extends AbstractList {
623
624 private final Map map;
625 private final String keyFieldName;
626 private final Map fieldCache = new HashMap();
627
628 public MappingList(Map map, String keyFieldName) {
629 this.map = map;
630 this.keyFieldName = keyFieldName;
631 }
632
633 public boolean add(Object object) {
634 if (object == null) {
635 boolean containsNull = !map.containsKey(null);
636 map.put(null, null);
637 return containsNull;
638 }
639 Class itemType = object.getClass();
640
641 if (keyFieldName != null) {
642 Field field = (Field)fieldCache.get(itemType);
643 if (field == null) {
644 field = reflectionProvider.getField(itemType, keyFieldName);
645 fieldCache.put(itemType, field);
646 }
647 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 }
662 }
663 } else if (object instanceof Map.Entry) {
664 final Map.Entry entry = (Map.Entry)object;
665 return map.put(entry.getKey(), entry.getValue()) == null;
666 }
667
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());
672 }
673
674 public Object get(int index) {
675 throw new UnsupportedOperationException();
676 }
677
678 public int size() {
679 return map.size();
680 }
681 }
682 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 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 13. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.MarshallingContext;
14 import com.thoughtworks.xstream.converters.UnmarshallingContext;
15 import com.thoughtworks.xstream.core.ClassLoaderReference;
16 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19 import com.thoughtworks.xstream.mapper.CGLIBMapper;
20 import com.thoughtworks.xstream.mapper.Mapper;
21
22 import net.sf.cglib.proxy.Callback;
23 import net.sf.cglib.proxy.CallbackFilter;
24 import net.sf.cglib.proxy.Enhancer;
25 import net.sf.cglib.proxy.Factory;
26 import net.sf.cglib.proxy.MethodInterceptor;
27 import net.sf.cglib.proxy.NoOp;
28
29 import java.lang.reflect.Field;
30 import java.lang.reflect.InvocationHandler;
31 import java.lang.reflect.InvocationTargetException;
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Modifier;
34 import java.lang.reflect.Proxy;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.Iterator;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.Set;
43
44
45 /**
46 * Converts a proxy created by the CGLIB {@link Enhancer}. Such a proxy is recreated while
47 * deserializing the proxy. The converter does only work, if<br>
48 * <ul>
49 * <li>the DefaultNamingPolicy is used for the proxy's name</li>
50 * <li>the proxy uses a factory or only one Callback is registered</li>
51 * <li>a possible super class has at least a protected default constructor</li>
52 * </ul>
53 * Note, that the this converter relies on the CGLIBMapper.
54 *
55 * @author J&ouml;rg Schaible
56 * @since 1.2
57 */
58 public class CGLIBEnhancedConverter extends SerializableConverter {
59 private static String DEFAULT_NAMING_MARKER = "$$EnhancerByCGLIB$$";
60 private static String CALLBACK_MARKER = "CGLIB$CALLBACK_";
61 private transient Map fieldCache;
62
63 /**
64 * Construct a CGLIBEnhancedConverter.
65 * @param mapper the mapper chain instance
66 * @param reflectionProvider the reflection provider
67 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
68 * @since 1.4.5
69 */
70 public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoaderReference classLoaderReference) {
71 super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoaderReference);
72 this.fieldCache = new HashMap();
73 }
74
75 /**
76 * @deprecated As of 1.4.5 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
77 */
78 public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoader classLoader) {
79 super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoader);
80 this.fieldCache = new HashMap();
81 }
82
83 /**
84 * @deprecated As of 1.4 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
85 */
86 public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
87 this(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), CGLIBEnhancedConverter.class.getClassLoader());
88 }
89
90 public boolean canConvert(Class type) {
91 return (Enhancer.isEnhanced(type) && type.getName().indexOf(DEFAULT_NAMING_MARKER) > 0)
92 || type == CGLIBMapper.Marker.class;
93 }
94
95 public void marshal(Object source, HierarchicalStreamWriter writer,
96 MarshallingContext context) {
97 Class type = source.getClass();
98 boolean hasFactory = Factory.class.isAssignableFrom(type);
99 ExtendedHierarchicalStreamWriterHelper.startNode(writer, "type", type);
100 context.convertAnother(type.getSuperclass());
101 writer.endNode();
102 writer.startNode("interfaces");
103 Class[] interfaces = type.getInterfaces();
104 for (int i = 0; i < interfaces.length; i++ ) {
105 if (interfaces[i] == Factory.class) {
106 continue;
107 }
108 ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
109 .serializedClass(interfaces[i].getClass()), interfaces[i].getClass());
110 context.convertAnother(interfaces[i]);
111 writer.endNode();
112 }
113 writer.endNode();
114 writer.startNode("hasFactory");
115 writer.setValue(String.valueOf(hasFactory));
116 writer.endNode();
117 Map callbackIndexMap = null;
118 Callback[] callbacks = hasFactory
119 ? ((Factory)source).getCallbacks()
120 : getCallbacks(source);
121 if (callbacks.length > 1) {
122 if (hasFactory) {
123 callbackIndexMap = createCallbackIndexMap((Factory)source);
124 } else {
125 ConversionException exception = new ConversionException(
126 "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));
129 throw exception;
130 }
131 writer.startNode("callbacks");
132 writer.startNode("mapping");
133 context.convertAnother(callbackIndexMap);
134 writer.endNode();
135 }
136 boolean hasInterceptor = false;
137 for (int i = 0; i < callbacks.length; i++ ) {
138 final Callback callback = callbacks[i];
139 if (callback == null) {
140 String name = mapper.serializedClass(null);
141 writer.startNode(name);
142 writer.endNode();
143 } else {
144 hasInterceptor = hasInterceptor
145 || MethodInterceptor.class.isAssignableFrom(callback.getClass());
146 ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
147 .serializedClass(callback.getClass()), callback.getClass());
148 context.convertAnother(callback);
149 writer.endNode();
150 }
151 }
152 if (callbacks.length > 1) {
153 writer.endNode();
154 }
155 try {
156 final Field field = type.getDeclaredField("serialVersionUID");
157 if (!field.isAccessible()) {
158 field.setAccessible(true);
159 }
160 long serialVersionUID = field.getLong(null);
161 ExtendedHierarchicalStreamWriterHelper.startNode(
162 writer, "serialVersionUID", String.class);
163 writer.setValue(String.valueOf(serialVersionUID));
164 writer.endNode();
165 } catch (NoSuchFieldException e) {
166 // OK, ignore
167 } catch (IllegalAccessException e) {
168 throw new ObjectAccessException("Access to serialVersionUID of "
169 + type.getName()
170 + " not allowed", e);
171 }
172 if (hasInterceptor) {
173 writer.startNode("instance");
174 super.doMarshalConditionally(source, writer, context);
175 writer.endNode();
176 }
177 }
178
179 private Callback[] getCallbacks(Object source) {
180 Class type = source.getClass();
181 List fields = (List)fieldCache.get(type.getName());
182 if (fields == null) {
183 fields = new ArrayList();
184 fieldCache.put(type.getName(), fields);
185 for (int i = 0; true; ++i) {
186 try {
187 Field field = type.getDeclaredField(CALLBACK_MARKER + i);
188 if (!field.isAccessible()) {
189 field.setAccessible(true);
190 }
191 fields.add(field);
192 } catch (NoSuchFieldException e) {
193 break;
194 }
195 }
196 }
197 List list = new ArrayList();
198 for (int i = 0; i < fields.size(); ++i) {
199 try {
200 Field field = (Field)fields.get(i);
201 Object callback = field.get(source);
202 list.add(callback);
203 } catch (IllegalAccessException e) {
204 throw new ObjectAccessException("Access to "
205 + type.getName()
206 + "."
207 + CALLBACK_MARKER
208 + i
209 + " not allowed", e);
210 }
211 }
212 return (Callback[])list.toArray(new Callback[list.size()]);
213 }
214
215 private Map createCallbackIndexMap(Factory source) {
216 Callback[] originalCallbacks = source.getCallbacks();
217 Callback[] reverseEngineeringCallbacks = new Callback[originalCallbacks.length];
218 Map callbackIndexMap = new HashMap();
219 int idxNoOp = -1;
220 for (int i = 0; i < originalCallbacks.length; i++ ) {
221 Callback callback = originalCallbacks[i];
222 if (callback == null) {
223 reverseEngineeringCallbacks[i] = null;
224 } else if (NoOp.class.isAssignableFrom(callback.getClass())) {
225 reverseEngineeringCallbacks[i] = NoOp.INSTANCE;
226 idxNoOp = i;
227 } else {
228 reverseEngineeringCallbacks[i] = createReverseEngineeredCallbackOfProperType(
229 callback, i, callbackIndexMap);
230 }
231 }
232
233 try {
234 source.setCallbacks(reverseEngineeringCallbacks);
235 final Set interfaces = new HashSet();
236 final Set methods = new HashSet();
237 Class type = source.getClass();
238 do {
239 methods.addAll(Arrays.asList(type.getDeclaredMethods()));
240 methods.addAll(Arrays.asList(type.getMethods()));
241 Class[] implementedInterfaces = type.getInterfaces();
242 interfaces.addAll(Arrays.asList(implementedInterfaces));
243 type = type.getSuperclass();
244 } while (type != null);
245 for (final Iterator iterator = interfaces.iterator(); iterator.hasNext();) {
246 type = (Class)iterator.next();
247 methods.addAll(Arrays.asList(type.getDeclaredMethods()));
248 }
249 for (final Iterator iter = methods.iterator(); iter.hasNext();) {
250 final Method method = (Method)iter.next();
251 if (!method.isAccessible()) {
252 method.setAccessible(true);
253 }
254 if (Factory.class.isAssignableFrom(method.getDeclaringClass())
255 || (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) {
256 iter.remove();
257 continue;
258 }
259 Class[] parameterTypes = method.getParameterTypes();
260 Method calledMethod = method;
261 try {
262 if ((method.getModifiers() & Modifier.ABSTRACT) > 0) {
263 calledMethod = source.getClass().getMethod(
264 method.getName(), method.getParameterTypes());
265 }
266 callbackIndexMap.put(null, method);
267 calledMethod.invoke(source, parameterTypes == null
268 ? (Object[])null
269 : createNullArguments(parameterTypes));
270 } catch (IllegalAccessException e) {
271 throw new ObjectAccessException("Access to "
272 + calledMethod
273 + " not allowed", e);
274 } catch (InvocationTargetException e) {
275 // OK, ignore
276 } catch (NoSuchMethodException e) {
277 ConversionException exception = new ConversionException(
278 "CGLIB enhanced proxies wit abstract nethod that has not been implemented");
279 exception.add("proxy superclass", type.getSuperclass().getName());
280 exception.add("method", method.toString());
281 throw exception;
282 }
283 if (callbackIndexMap.containsKey(method)) {
284 iter.remove();
285 }
286 }
287 if (idxNoOp >= 0) {
288 Integer idx = new Integer(idxNoOp);
289 for (final Iterator iter = methods.iterator(); iter.hasNext();) {
290 callbackIndexMap.put(iter.next(), idx);
291 }
292 }
293 } finally {
294 source.setCallbacks(originalCallbacks);
295 }
296
297 callbackIndexMap.remove(null);
298 return callbackIndexMap;
299 }
300
301 private Object[] createNullArguments(Class[] parameterTypes) {
302 Object[] arguments = new Object[parameterTypes.length];
303 for (int i = 0; i < arguments.length; i++ ) {
304 Class type = parameterTypes[i];
305 if (type.isPrimitive()) {
306 if (type == byte.class) {
307 arguments[i] = new Byte((byte)0);
308 } else if (type == short.class) {
309 arguments[i] = new Short((short)0);
310 } else if (type == int.class) {
311 arguments[i] = new Integer(0);
312 } else if (type == long.class) {
313 arguments[i] = new Long(0);
314 } else if (type == float.class) {
315 arguments[i] = new Float(0);
316 } else if (type == double.class) {
317 arguments[i] = new Double(0);
318 } else if (type == char.class) {
319 arguments[i] = new Character('\0');
320 } else {
321 arguments[i] = Boolean.FALSE;
322 }
323 }
324 }
325 return arguments;
326 }
327
328 private Callback createReverseEngineeredCallbackOfProperType(Callback callback, int index,
329 Map callbackIndexMap) {
330 Class iface = null;
331 Class[] interfaces = callback.getClass().getInterfaces();
332 for (int i = 0; i < interfaces.length; i++ ) {
333 if (Callback.class.isAssignableFrom(interfaces[i])) {
334 iface = interfaces[i];
335 if (iface == Callback.class) {
336 ConversionException exception = new ConversionException(
337 "Cannot handle CGLIB callback");
338 exception.add("CGLIB callback type", callback.getClass().getName());
339 throw exception;
340 }
341 interfaces = iface.getInterfaces();
342 if (Arrays.asList(interfaces).contains(Callback.class)) {
343 break;
344 }
345 i = -1;
346 }
347 }
348 return (Callback)Proxy.newProxyInstance(
349 iface.getClassLoader(), new Class[]{iface},
350 new ReverseEngineeringInvocationHandler(index, callbackIndexMap));
351 }
352
353 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
354 final Enhancer enhancer = new Enhancer();
355 reader.moveDown();
356 enhancer.setSuperclass((Class)context.convertAnother(null, Class.class));
357 reader.moveUp();
358 reader.moveDown();
359 List interfaces = new ArrayList();
360 while (reader.hasMoreChildren()) {
361 reader.moveDown();
362 interfaces
363 .add(context.convertAnother(null, mapper.realClass(reader.getNodeName())));
364 reader.moveUp();
365 }
366 enhancer.setInterfaces((Class[])interfaces.toArray(new Class[interfaces.size()]));
367 reader.moveUp();
368 reader.moveDown();
369 boolean useFactory = Boolean.valueOf(reader.getValue()).booleanValue();
370 enhancer.setUseFactory(useFactory);
371 reader.moveUp();
372
373 List callbacksToEnhance = new ArrayList();
374 List callbacks = new ArrayList();
375 Map callbackIndexMap = null;
376 reader.moveDown();
377 if ("callbacks".equals(reader.getNodeName())) {
378 reader.moveDown();
379 callbackIndexMap = (Map)context.convertAnother(null, HashMap.class);
380 reader.moveUp();
381 while (reader.hasMoreChildren()) {
382 reader.moveDown();
383 readCallback(reader, context, callbacksToEnhance, callbacks);
384 reader.moveUp();
385 }
386 } else {
387 readCallback(reader, context, callbacksToEnhance, callbacks);
388 }
389 enhancer.setCallbacks((Callback[])callbacksToEnhance
390 .toArray(new Callback[callbacksToEnhance.size()]));
391 if (callbackIndexMap != null) {
392 enhancer.setCallbackFilter(new ReverseEngineeredCallbackFilter(callbackIndexMap));
393 }
394 reader.moveUp();
395 Object result = null;
396 while (reader.hasMoreChildren()) {
397 reader.moveDown();
398 if (reader.getNodeName().equals("serialVersionUID")) {
399 enhancer.setSerialVersionUID(Long.valueOf(reader.getValue()));
400 } else if (reader.getNodeName().equals("instance")) {
401 result = create(enhancer, callbacks, useFactory);
402 super.doUnmarshalConditionally(result, reader, context);
403 }
404 reader.moveUp();
405 }
406 if (result == null) {
407 result = create(enhancer, callbacks, useFactory);
408 }
409 return serializationMembers.callReadResolve(result);
410 }
411
412 private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context,
413 List callbacksToEnhance, List callbacks) {
414 Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader
415 .getNodeName()));
416 callbacks.add(callback);
417 if (callback == null) {
418 callbacksToEnhance.add(NoOp.INSTANCE);
419 } else {
420 callbacksToEnhance.add(callback);
421 }
422 }
423
424 private Object create(final Enhancer enhancer, List callbacks, boolean useFactory) {
425 Object result = enhancer.create();
426 if (useFactory) {
427 ((Factory)result).setCallbacks((Callback[])callbacks.toArray(new Callback[callbacks
428 .size()]));
429 }
430 return result;
431 }
432
433 protected List hierarchyFor(Class type) {
434 List typeHierarchy = super.hierarchyFor(type);
435 // drop the CGLIB proxy
436 typeHierarchy.remove(typeHierarchy.size() - 1);
437 return typeHierarchy;
438 }
439
440 protected Object readResolve() {
441 super.readResolve();
442 fieldCache = new HashMap();
443 return this;
444 }
445
446 private static class CGLIBFilteringReflectionProvider extends ReflectionProviderWrapper {
447
448 public CGLIBFilteringReflectionProvider(final ReflectionProvider reflectionProvider) {
449 super(reflectionProvider);
450 }
451
452 public void visitSerializableFields(final Object object, final Visitor visitor) {
453 wrapped.visitSerializableFields(object, new Visitor() {
454 public void visit(String name, Class type, Class definedIn, Object value) {
455 if (!name.startsWith("CGLIB$")) {
456 visitor.visit(name, type, definedIn, value);
457 }
458 }
459 });
460 }
461 }
462
463 private static final class ReverseEngineeringInvocationHandler implements InvocationHandler {
464 private final Integer index;
465 private final Map indexMap;
466
467 public ReverseEngineeringInvocationHandler(int index, Map indexMap) {
468 this.indexMap = indexMap;
469 this.index = new Integer(index);
470 }
471
472 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
473 indexMap.put(indexMap.get(null), index);
474 return null;
475 }
476 }
477
478 private static class ReverseEngineeredCallbackFilter implements CallbackFilter {
479
480 private final Map callbackIndexMap;
481
482 public ReverseEngineeredCallbackFilter(Map callbackIndexMap) {
483 this.callbackIndexMap = callbackIndexMap;
484 }
485
486 public int accept(Method method) {
487 if (!callbackIndexMap.containsKey(method)) {
488 ConversionException exception = new ConversionException(
489 "CGLIB callback not detected in reverse engineering");
490 exception.add("CGLIB callback", method.toString());
491 throw exception;
492 }
493 return ((Integer)callbackIndexMap.get(method)).intValue();
494 }
495
496 }
497 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015 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. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.core.ClassLoaderReference;
18 import com.thoughtworks.xstream.core.JVM;
19 import com.thoughtworks.xstream.core.ReferencingMarshallingContext;
20 import com.thoughtworks.xstream.core.util.CustomObjectInputStream;
21 import com.thoughtworks.xstream.core.util.CustomObjectOutputStream;
22 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
23 import com.thoughtworks.xstream.core.util.SerializationMembers;
24 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
25 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
26 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
27 import com.thoughtworks.xstream.mapper.Mapper;
28
29 import java.io.Externalizable;
30 import java.io.IOException;
31 import java.io.NotActiveException;
32 import java.io.ObjectInputValidation;
33 import java.lang.reflect.Constructor;
34 import java.lang.reflect.InvocationTargetException;
35 import java.util.Map;
36
37 /**
38 * Converts any object that implements the java.io.Externalizable interface, allowing compatibility with native Java
39 * serialization.
40 *
41 * @author Joe Walnes
42 */
43 public class ExternalizableConverter implements Converter {
44
45 private Mapper mapper;
46 private final ClassLoaderReference classLoaderReference;
47 private transient SerializationMembers serializationMembers;
48
49 /**
50 * Construct an ExternalizableConverter.
51 *
52 * @param mapper the Mapper chain
53 * @param classLoaderReference the reference to XStream's {@link ClassLoader} instance
54 * @since 1.4.5
55 */
56 public ExternalizableConverter(Mapper mapper, ClassLoaderReference classLoaderReference) {
57 this.mapper = mapper;
58 this.classLoaderReference = classLoaderReference;
59 serializationMembers = new SerializationMembers();
60 }
61
62 /**
63 * @deprecated As of 1.4.5 use {@link #ExternalizableConverter(Mapper, ClassLoaderReference)}
64 */
65 public ExternalizableConverter(Mapper mapper, ClassLoader classLoader) {
66 this(mapper, new ClassLoaderReference(classLoader));
67 }
68
69 /**
70 * @deprecated As of 1.4 use {@link #ExternalizableConverter(Mapper, ClassLoader)}
71 */
72 public ExternalizableConverter(Mapper mapper) {
73 this(mapper, ExternalizableConverter.class.getClassLoader());
74 }
75
76 public boolean canConvert(Class type) {
77 return JVM.canCreateDerivedObjectOutputStream() && Externalizable.class.isAssignableFrom(type);
78 }
79
80 public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
81 final Object source = serializationMembers.callWriteReplace(original);
82 if (source != original && context instanceof ReferencingMarshallingContext) {
83 ((ReferencingMarshallingContext)context).replace(original, source);
84 }
85 if (source.getClass() != original.getClass()) {
86 final String attributeName = mapper.aliasForSystemAttribute("resolves-to");
87 if (attributeName != null) {
88 writer.addAttribute(attributeName, mapper.serializedClass(source.getClass()));
89 }
90 context.convertAnother(source);
91 } else {
92 try {
93 Externalizable externalizable = (Externalizable)source;
94 CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() {
95 public void writeToStream(final Object object) {
96 if (object == null) {
97 writer.startNode("null");
98 writer.endNode();
99 } else {
100 ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass());
101 context.convertAnother(object);
102 writer.endNode();
103 }
104 }
105
106 public void writeFieldsToStream(final Map fields) {
107 throw new UnsupportedOperationException();
108 }
109
110 public void defaultWriteObject() {
111 throw new UnsupportedOperationException();
112 }
113
114 public void flush() {
115 writer.flush();
116 }
117
118 public void close() {
119 throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutput.close() from writeExternal()");
120 }
121 };
122 final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback);
123 externalizable.writeExternal(objectOutput);
124 objectOutput.popCallback();
125 } catch (IOException e) {
126 throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization", e);
127 }
128 }
129 }
130
131 public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
132 final Class type = context.getRequiredType();
133 final Constructor defaultConstructor;
134 try {
135 defaultConstructor = type.getDeclaredConstructor((Class[]) null);
136 if (!defaultConstructor.isAccessible()) {
137 defaultConstructor.setAccessible(true);
138 }
139 final Externalizable externalizable = (Externalizable) defaultConstructor.newInstance((Object[]) null);
140 CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() {
141 public Object readFromStream() {
142 reader.moveDown();
143 Class type = HierarchicalStreams.readClassType(reader, mapper);
144 Object streamItem = context.convertAnother(externalizable, type);
145 reader.moveUp();
146 return streamItem;
147 }
148
149 public Map readFieldsFromStream() {
150 throw new UnsupportedOperationException();
151 }
152
153 public void defaultReadObject() {
154 throw new UnsupportedOperationException();
155 }
156
157 public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException {
158 throw new NotActiveException("stream inactive");
159 }
160
161 public void close() {
162 throw new UnsupportedOperationException("Objects are not allowed to call ObjectInput.close() from readExternal()");
163 }
164 };
165 CustomObjectInputStream objectInput = CustomObjectInputStream.getInstance(context, callback, classLoaderReference);
166 externalizable.readExternal(objectInput);
167 objectInput.popCallback();
168 return serializationMembers.callReadResolve(externalizable);
169 } catch (NoSuchMethodException e) {
170 throw new ConversionException("Cannot construct " + type.getClass() + ", missing default constructor", e);
171 } catch (InvocationTargetException e) {
172 throw new ConversionException("Cannot construct " + type.getClass(), e);
173 } catch (InstantiationException e) {
174 throw new ConversionException("Cannot construct " + type.getClass(), e);
175 } catch (IllegalAccessException e) {
176 throw new ConversionException("Cannot construct " + type.getClass(), e);
177 } catch (IOException e) {
178 throw new ConversionException("Cannot externalize " + type.getClass(), e);
179 } catch (ClassNotFoundException e) {
180 throw new ConversionException("Cannot externalize " + type.getClass(), e);
181 }
182 }
183
184 private Object readResolve() {
185 serializationMembers = new SerializationMembers();
186 return this;
187 }
188 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 14. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.lang.reflect.Field;
14 import java.lang.reflect.Modifier;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import com.thoughtworks.xstream.core.Caching;
24 import com.thoughtworks.xstream.core.JVM;
25 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
26
27
28 /**
29 * A field dictionary instance caches information about classes fields.
30 *
31 * @author Joe Walnes
32 * @author J&ouml;rg Schaible
33 * @author Guilherme Silveira
34 */
35 public class FieldDictionary implements Caching {
36
37 private transient Map keyedByFieldNameCache;
38 private transient Map keyedByFieldKeyCache;
39 private final FieldKeySorter sorter;
40
41 public FieldDictionary() {
42 this(new ImmutableFieldKeySorter());
43 }
44
45 public FieldDictionary(FieldKeySorter sorter) {
46 this.sorter = sorter;
47 init();
48 }
49
50 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);
55 }
56
57 /**
58 * Returns an iterator for all fields for some class
59 *
60 * @param cls the class you are interested on
61 * @return an iterator for its fields
62 * @deprecated As of 1.3, use {@link #fieldsFor(Class)} instead
63 */
64 public Iterator serializableFieldsFor(Class cls) {
65 return fieldsFor(cls);
66 }
67
68 /**
69 * Returns an iterator for all fields for some class
70 *
71 * @param cls the class you are interested on
72 * @return an iterator for its fields
73 */
74 public Iterator fieldsFor(final Class cls) {
75 return buildMap(cls, true).values().iterator();
76 }
77
78 /**
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 *
84 * @param cls the class where the field is to be searched
85 * @param name the field name
86 * @param definedIn the superclass (or the class itself) of cls where the field was defined
87 * @return the field itself
88 * @throws ObjectAccessException if no field can be found
89 */
90 public Field field(Class cls, String name, Class definedIn) {
91 Field field = fieldOrNull(cls, name, definedIn);
92 if (field == null) {
93 throw new MissingFieldException(cls.getName(), name);
94 } else {
95 return field;
96 }
97 }
98
99 /**
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 *
105 * @param cls the class where the field is to be searched
106 * @param name the field name
107 * @param definedIn the superclass (or the class itself) of cls where the field was defined
108 * @return the field itself or <code>null</code>
109 * @since 1.4
110 */
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
114 ? (Object)new FieldKey(name, definedIn, -1)
115 : (Object)name);
116 return field;
117 }
118
119 private Map buildMap(final Class type, boolean tupleKeyed) {
120 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();
127 }
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));
177 }
178
179 public synchronized void flushCache() {
180 Set objectTypeSet = Collections.singleton(Object.class);
181 keyedByFieldNameCache.keySet().retainAll(objectTypeSet);
182 keyedByFieldKeyCache.keySet().retainAll(objectTypeSet);
183 if (sorter instanceof Caching) {
184 ((Caching)sorter).flushCache();
185 }
186 }
187
188 protected Object readResolve() {
189 init();
190 return this;
191 }
192 }
0 /*
1 * Copyright (C) 2007 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 /**
13 * A field key.
14 *
15 * @author Guilherme Silveira
16 * @author J&ouml;rg Schaible
17 */
18 public class FieldKey {
19 final private String fieldName;
20 final private Class declaringClass;
21 final private int depth;
22 final private int order;
23
24 public FieldKey(String fieldName, Class declaringClass, int order) {
25 if (fieldName == null || declaringClass == null) {
26 throw new IllegalArgumentException("fieldName or declaringClass is null");
27 }
28 this.fieldName = fieldName;
29 this.declaringClass = declaringClass;
30 this.order = order;
31 Class c = declaringClass;
32 int i = 0;
33 while (c.getSuperclass() != null) {
34 i++;
35 c = c.getSuperclass();
36 }
37 depth = i;
38 }
39
40 public String getFieldName() {
41 return this.fieldName;
42 }
43
44 public Class getDeclaringClass() {
45 return this.declaringClass;
46 }
47
48 public int getDepth() {
49 return this.depth;
50 }
51
52 public int getOrder() {
53 return this.order;
54 }
55
56 public boolean equals(Object o) {
57 if (this == o) return true;
58 if (!(o instanceof FieldKey)) return false;
59
60 final FieldKey fieldKey = (FieldKey)o;
61
62 if (!declaringClass.equals(fieldKey.declaringClass))
63 return false;
64 if (!fieldName.equals(fieldKey.fieldName))
65 return false;
66
67 return true;
68 }
69
70 public int hashCode() {
71 int result;
72 result = fieldName.hashCode();
73 result = 29 * result +declaringClass.hashCode();
74 return result;
75 }
76
77 public String toString() {
78 return "FieldKey{"
79 + "order="
80 + order
81 + ", writer="
82 + depth
83 + ", declaringClass="
84 + declaringClass
85 + ", fieldName='"
86 + fieldName
87 + "'"
88 + "}";
89 }
90
91 }
0 /*
1 * Copyright (C) 2007 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.util.Map;
13
14
15 /**
16 * An interface capable of sorting fields. Implement this interface if you want to customize the
17 * field order in which XStream serializes objects.
18 *
19 * @author Guilherme Silveira
20 * @since 1.2.2
21 */
22 public interface FieldKeySorter {
23
24 /**
25 * Sort the fields of a type. The method will be called with the class type that contains
26 * all the fields and a Map that retains the order in which the elements have been added.
27 * The sequence in which elements are returned by an iterator defines the processing order
28 * of the fields. An implementation may create a different Map with similar semantic, add
29 * all elements of the original map and return the new one.
30 *
31 * @param type the class that contains all the fields
32 * @param keyedByFieldKey a Map containing a {@link FieldKey} as key element and a
33 * {@link java.lang.reflect.Field} as value.
34 * @return a Map with all the entries of the original Map
35 * @since 1.2.2
36 */
37 Map sort(Class type, Map keyedByFieldKey);
38
39 }
0 /*
1 * Copyright (C) 2007 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.util.Map;
13
14 /**
15 * Does not change the order of the fields.
16 *
17 * @author Guilherme Silveira
18 * @since 1.2.2
19 */
20 public class ImmutableFieldKeySorter implements FieldKeySorter {
21
22 public Map sort(Class type, Map keyedByFieldKey) {
23 return keyedByFieldKey;
24 }
25
26 }
0 /*
1 * Copyright (C) 2015 XStream Committer.
2 * All rights reserved.
3 *
4 * Created on 17. January 2015 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.converters.reflection;
7
8 import java.io.Serializable;
9
10 import com.thoughtworks.xstream.converters.MarshallingContext;
11 import com.thoughtworks.xstream.core.ClassLoaderReference;
12 import com.thoughtworks.xstream.core.JVM;
13 import com.thoughtworks.xstream.core.util.Types;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.mapper.Mapper;
16
17
18 /**
19 * Converts a lambda type.
20 *
21 * The implementation maps any non-serializable lambda instance to {@code null}.
22 *
23 * @author J&ouml;rg Schaible
24 * @since 1.4.8
25 */
26 public class LambdaConverter extends SerializableConverter {
27
28 /**
29 * Constructs a LambdaConverter.
30 *
31 * @param mapper
32 * @param reflectionProvider
33 * @param classLoaderReference
34 * @since 1.4.8
35 */
36 public LambdaConverter(
37 final Mapper mapper, final ReflectionProvider reflectionProvider,
38 final ClassLoaderReference classLoaderReference) {
39 super(mapper, reflectionProvider, classLoaderReference);
40 }
41
42 @Override
43 public boolean canConvert(final Class type) {
44 return Types.isLambdaType(type)
45 && (JVM.canCreateDerivedObjectOutputStream() || !Serializable.class.isAssignableFrom(type));
46 }
47
48 @Override
49 public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
50 if (original instanceof Serializable) {
51 super.marshal(original, writer, context);
52 }
53 }
54 }
0 /*
1 * Copyright (C) 2011 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 01. October 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 /**
13 * Indicates a missing field or property creating an object.
14 *
15 * @author Nikita Levyankov
16 * @author Joerg Schaible
17 * @since 1.4.2
18 */
19 public class MissingFieldException extends ObjectAccessException {
20
21 private final String fieldName;
22 private final String className;
23
24 /**
25 * Construct a MissingFieldException.
26 * @param className the name of the class missing the field
27 * @param fieldName the name of the missed field
28 * @since 1.4.2
29 */
30 public MissingFieldException(final String className, final String fieldName) {
31 super("No field '" + fieldName + "' found in class '" + className + "'");
32 this.className = className;
33 this.fieldName = fieldName;
34 }
35
36 /**
37 * Retrieve the name of the missing field.
38 * @return the field name
39 * @since 1.4.2
40 */
41 public String getFieldName() {
42 return fieldName;
43 }
44
45 /**
46 * Retrieve the name of the class with the missing field.
47 * @return the class name
48 * @since 1.4.2
49 */
50 protected String getClassName() {
51 return className;
52 }
53 }
0 /*
1 * Copyright (C) 2007 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 17.05.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.util.Comparator;
13 import java.util.Map;
14 import java.util.TreeMap;
15
16
17 /**
18 * Sort the fields in their natural order. Fields are returned in their declaration order,
19 * fields of base classes first.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.2.2
23 */
24 public class NativeFieldKeySorter implements FieldKeySorter {
25
26 public Map sort(final Class type, final Map keyedByFieldKey) {
27 final Map map = new TreeMap(new Comparator() {
28
29 public int compare(final Object o1, final Object o2) {
30 final FieldKey fieldKey1 = (FieldKey)o1;
31 final FieldKey fieldKey2 = (FieldKey)o2;
32 int i = fieldKey1.getDepth() - fieldKey2.getDepth();
33 if (i == 0) {
34 i = fieldKey1.getOrder() - fieldKey2.getOrder();
35 }
36 return i;
37 }
38 });
39 map.putAll(keyedByFieldKey);
40 return map;
41 }
42
43 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.xstream.XStreamException;
14
15 public class ObjectAccessException extends XStreamException {
16 public ObjectAccessException(String message) {
17 super(message);
18 }
19
20 public ObjectAccessException(String message, Throwable cause) {
21 super(message, cause);
22 }
23 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.xstream.core.JVM;
14
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.DataOutputStream;
18 import java.io.IOException;
19 import java.io.ObjectInputStream;
20 import java.io.ObjectStreamClass;
21 import java.io.ObjectStreamConstants;
22 import java.io.Serializable;
23 import java.lang.reflect.Constructor;
24 import java.lang.reflect.Field;
25 import java.lang.reflect.InvocationTargetException;
26 import java.lang.reflect.Modifier;
27 import java.util.Iterator;
28 import java.util.Map;
29 import java.util.WeakHashMap;
30
31 /**
32 * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects
33 * that can be constructed are limited.
34 * <p>
35 * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default constructors
36 * and any class that implements java.io.Serializable.
37 * </p>
38 * <p>
39 * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default constructors.
40 * Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates the object.
41 * </p>
42 * @author Joe Walnes
43 */
44 public class PureJavaReflectionProvider implements ReflectionProvider {
45
46 private transient Map serializedDataCache;
47 protected FieldDictionary fieldDictionary;
48
49 public PureJavaReflectionProvider() {
50 this(new FieldDictionary(new ImmutableFieldKeySorter()));
51 }
52
53 public PureJavaReflectionProvider(FieldDictionary fieldDictionary) {
54 this.fieldDictionary = fieldDictionary;
55 init();
56 }
57
58 public Object newInstance(Class type) {
59 try {
60 Constructor[] constructors = type.getDeclaredConstructors();
61 for (int i = 0; i < constructors.length; i++) {
62 final Constructor constructor = constructors[i];
63 if (constructor.getParameterTypes().length == 0) {
64 if (!constructor.isAccessible()) {
65 constructor.setAccessible(true);
66 }
67 return constructor.newInstance(new Object[0]);
68 }
69 }
70 if (Serializable.class.isAssignableFrom(type)) {
71 return instantiateUsingSerialization(type);
72 } else {
73 throw new ObjectAccessException("Cannot construct " + type.getName()
74 + " as it does not have a no-args constructor");
75 }
76 } catch (InstantiationException e) {
77 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
78 } catch (IllegalAccessException e) {
79 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
80 } catch (InvocationTargetException e) {
81 if (e.getTargetException() instanceof RuntimeException) {
82 throw (RuntimeException)e.getTargetException();
83 } else if (e.getTargetException() instanceof Error) {
84 throw (Error)e.getTargetException();
85 } else {
86 throw new ObjectAccessException("Constructor for " + type.getName() + " threw an exception", e.getTargetException());
87 }
88 }
89 }
90
91 private Object instantiateUsingSerialization(final Class type) {
92 try {
93 synchronized (serializedDataCache) {
94 byte[] data = (byte[]) serializedDataCache.get(type);
95 if (data == null) {
96 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
97 DataOutputStream stream = new DataOutputStream(bytes);
98 stream.writeShort(ObjectStreamConstants.STREAM_MAGIC);
99 stream.writeShort(ObjectStreamConstants.STREAM_VERSION);
100 stream.writeByte(ObjectStreamConstants.TC_OBJECT);
101 stream.writeByte(ObjectStreamConstants.TC_CLASSDESC);
102 stream.writeUTF(type.getName());
103 stream.writeLong(ObjectStreamClass.lookup(type).getSerialVersionUID());
104 stream.writeByte(2); // classDescFlags (2 = Serializable)
105 stream.writeShort(0); // field count
106 stream.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
107 stream.writeByte(ObjectStreamConstants.TC_NULL);
108 data = bytes.toByteArray();
109 serializedDataCache.put(type, data);
110 }
111
112 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)) {
113 protected Class resolveClass(ObjectStreamClass desc)
114 throws IOException, ClassNotFoundException {
115 return Class.forName(desc.getName(), false, type.getClassLoader());
116 }
117 };
118 return in.readObject();
119 }
120 } catch (IOException e) {
121 throw new ObjectAccessException("Cannot create " + type.getName() + " by JDK serialization", e);
122 } catch (ClassNotFoundException e) {
123 throw new ObjectAccessException("Cannot find class " + e.getMessage(), e);
124 }
125 }
126
127 public void visitSerializableFields(Object object, ReflectionProvider.Visitor visitor) {
128 for (Iterator iterator = fieldDictionary.fieldsFor(object.getClass()); iterator.hasNext();) {
129 Field field = (Field) iterator.next();
130 if (!fieldModifiersSupported(field)) {
131 continue;
132 }
133 validateFieldAccess(field);
134 try {
135 Object value = field.get(object);
136 visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value);
137 } catch (IllegalArgumentException e) {
138 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
139 } catch (IllegalAccessException e) {
140 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
141 }
142 }
143 }
144
145 public void writeField(Object object, String fieldName, Object value, Class definedIn) {
146 Field field = fieldDictionary.field(object.getClass(), fieldName, definedIn);
147 validateFieldAccess(field);
148 try {
149 field.set(object, value);
150 } catch (IllegalArgumentException e) {
151 throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e);
152 } catch (IllegalAccessException e) {
153 throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e);
154 }
155 }
156
157 public Class getFieldType(Object object, String fieldName, Class definedIn) {
158 return fieldDictionary.field(object.getClass(), fieldName, definedIn).getType();
159 }
160
161 /**
162 * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead
163 */
164 public boolean fieldDefinedInClass(String fieldName, Class type) {
165 Field field = fieldDictionary.fieldOrNull(type, fieldName, null);
166 return field != null && fieldModifiersSupported(field);
167 }
168
169 protected boolean fieldModifiersSupported(Field field) {
170 int modifiers = field.getModifiers();
171 return !(Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers));
172 }
173
174 protected void validateFieldAccess(Field field) {
175 if (Modifier.isFinal(field.getModifiers())) {
176 if (JVM.is15()) {
177 if (!field.isAccessible()) {
178 field.setAccessible(true);
179 }
180 } else {
181 throw new ObjectAccessException("Invalid final field "
182 + field.getDeclaringClass().getName() + "." + field.getName());
183 }
184 }
185 }
186
187 public Field getField(Class definedIn, String fieldName) {
188 return fieldDictionary.field(definedIn, fieldName, null);
189 }
190
191 public Field getFieldOrNull(Class definedIn, String fieldName) {
192 return fieldDictionary.fieldOrNull(definedIn, fieldName, null);
193 }
194
195 public void setFieldDictionary(FieldDictionary dictionary) {
196 this.fieldDictionary = dictionary;
197 }
198
199 private Object readResolve() {
200 init();
201 return this;
202 }
203
204 protected void init() {
205 serializedDataCache = new WeakHashMap();
206 }
207 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013, 2014 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.xstream.core.JVM;
14 import com.thoughtworks.xstream.mapper.Mapper;
15
16 public class ReflectionConverter extends AbstractReflectionConverter {
17
18 // Might be missing in Android
19 private final static Class eventHandlerType = JVM.loadClassForName("java.beans.EventHandler");
20 private Class type;
21
22 public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
23 super(mapper, reflectionProvider);
24 }
25
26 /**
27 * Construct a ReflectionConverter for an explicit type.
28 *
29 * @param mapper the mapper in use
30 * @param reflectionProvider the reflection provider in use
31 * @param type the explicit type to handle
32 * @since 1.4.7
33 */
34 public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider, Class type) {
35 this(mapper, reflectionProvider);
36 this.type = type;
37 }
38
39 public boolean canConvert(Class type) {
40 return ((this.type != null && this.type == type) || (this.type == null && type != null && type != eventHandlerType))
41 && canAccess(type);
42 }
43 }
0 /*
1 * Copyright (C) 2004, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.lang.reflect.Field;
14
15
16 /**
17 * Provides core reflection services.
18 *
19 * @author Joe Walnes
20 */
21 public interface ReflectionProvider {
22
23 /**
24 * Creates a new instance of the specified type. It is in the responsibility of the
25 * implementation how such an instance is created.
26 *
27 * @param type the type to instantiate
28 * @return a new instance of this type
29 */
30 Object newInstance(Class type);
31
32 void visitSerializableFields(Object object, Visitor visitor);
33
34 void writeField(Object object, String fieldName, Object value, Class definedIn);
35
36 Class getFieldType(Object object, String fieldName, Class definedIn);
37
38 /**
39 * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead
40 */
41 boolean fieldDefinedInClass(String fieldName, Class type);
42
43 /**
44 * A visitor interface for serializable fields defined in a class.
45 */
46 interface Visitor {
47
48 /**
49 * Callback for each visit
50 *
51 * @param name field name
52 * @param type field type
53 * @param definedIn where the field was defined
54 * @param value field value
55 */
56 void visit(String name, Class type, Class definedIn, Object value);
57 }
58
59 /**
60 * Returns a field defined in some class.
61 *
62 * @param definedIn class where the field was defined
63 * @param fieldName field name
64 * @return the field itself
65 * @throws ObjectAccessException if field does not exist
66 */
67 Field getField(Class definedIn, String fieldName);
68
69 /**
70 * Returns a field defined in some class.
71 *
72 * @param definedIn class where the field was defined
73 * @param fieldName field name
74 * @return the field itself or null
75 * @since 1.4.5
76 */
77 Field getFieldOrNull(Class definedIn, String fieldName);
78 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 13. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.lang.reflect.Field;
13
14 /**
15 * A wrapper implementation for the ReflectionProvider.
16 *
17 * @author J&ouml;rg Schaible
18 * @since 1.2
19 */
20 public class ReflectionProviderWrapper implements ReflectionProvider {
21
22 final protected ReflectionProvider wrapped;
23
24 public ReflectionProviderWrapper(ReflectionProvider wrapper) {
25 this.wrapped = wrapper;
26 }
27
28 /**
29 * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead
30 */
31 public boolean fieldDefinedInClass(String fieldName, Class type) {
32 return this.wrapped.fieldDefinedInClass(fieldName, type);
33 }
34
35 public Field getField(Class definedIn, String fieldName) {
36 return this.wrapped.getField(definedIn, fieldName);
37 }
38
39 public Field getFieldOrNull(Class definedIn, String fieldName) {
40 return this.wrapped.getFieldOrNull(definedIn, fieldName);
41 }
42
43 public Class getFieldType(Object object, String fieldName, Class definedIn) {
44 return this.wrapped.getFieldType(object, fieldName, definedIn);
45 }
46
47 public Object newInstance(Class type) {
48 return this.wrapped.newInstance(type);
49 }
50
51 public void visitSerializableFields(Object object, Visitor visitor) {
52 this.wrapped.visitSerializableFields(object, visitor);
53 }
54
55 public void writeField(Object object, String fieldName, Object value, Class definedIn) {
56 this.wrapped.writeField(object, fieldName, value, definedIn);
57 }
58
59 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 03. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.xstream.converters.Converter;
13
14 /**
15 * A special converter that prevents self-serialization. The serializing XStream instance
16 * adds a converter of this type to prevent self-serialization and will throw an
17 * exception instead.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.2
21 * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker}
22 */
23 public class SelfStreamingInstanceChecker extends com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker {
24
25 public SelfStreamingInstanceChecker(Converter defaultConverter, Object xstream) {
26 super(defaultConverter, xstream);
27 }
28
29 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015 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 21. December 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.io.IOException;
14 import java.io.InvalidObjectException;
15 import java.io.ObjectInputValidation;
16 import java.io.ObjectStreamClass;
17 import java.io.ObjectStreamField;
18 import java.io.Serializable;
19 import java.lang.reflect.Field;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27 import com.thoughtworks.xstream.converters.ConversionException;
28 import com.thoughtworks.xstream.converters.MarshallingContext;
29 import com.thoughtworks.xstream.converters.UnmarshallingContext;
30 import com.thoughtworks.xstream.core.ClassLoaderReference;
31 import com.thoughtworks.xstream.core.JVM;
32 import com.thoughtworks.xstream.core.util.CustomObjectInputStream;
33 import com.thoughtworks.xstream.core.util.CustomObjectOutputStream;
34 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
35 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
36 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
37 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
38 import com.thoughtworks.xstream.mapper.Mapper;
39
40 /**
41 * Emulates the mechanism used by standard Java Serialization for classes that implement java.io.Serializable AND
42 * implement or inherit a custom readObject()/writeObject() method.
43 *
44 * <h3>Supported features of serialization</h3>
45 * <ul>
46 * <li>readObject(), writeObject()</li>
47 * <li>class inheritance</li>
48 * <li>readResolve(), writeReplace()</li>
49 * <li>getFields(), putFields(), writeFields(), readFields()</li>
50 * <li>ObjectStreamField[] serialPersistentFields</li>
51 * <li>ObjectInputValidation</li>
52 * </ul>
53 *
54 * @author Joe Walnes
55 * @author J&ouml;rg Schaible
56 */
57 public class SerializableConverter extends AbstractReflectionConverter {
58
59 private static final String ELEMENT_NULL = "null";
60 private static final String ELEMENT_DEFAULT = "default";
61 private static final String ELEMENT_UNSERIALIZABLE_PARENTS = "unserializable-parents";
62 private static final String ATTRIBUTE_CLASS = "class";
63 private static final String ATTRIBUTE_SERIALIZATION = "serialization";
64 private static final String ATTRIBUTE_VALUE_CUSTOM = "custom";
65 private static final String ELEMENT_FIELDS = "fields";
66 private static final String ELEMENT_FIELD = "field";
67 private static final String ATTRIBUTE_NAME = "name";
68
69 private final ClassLoaderReference classLoaderReference;
70
71 /**
72 * Construct a SerializableConverter.
73 *
74 * @param mapper the mapper chain instance
75 * @param reflectionProvider the reflection provider
76 * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance
77 * @since 1.4.5
78 */
79 public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoaderReference classLoaderReference) {
80 super(mapper, new UnserializableParentsReflectionProvider(reflectionProvider));
81 this.classLoaderReference = classLoaderReference;
82 }
83
84 /**
85 * @deprecated As of 1.4.5 use {@link #SerializableConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
86 */
87 public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoader classLoader) {
88 this(mapper, reflectionProvider, new ClassLoaderReference(classLoader));
89 }
90
91 /**
92 * @deprecated As of 1.4 use {@link #SerializableConverter(Mapper, ReflectionProvider, ClassLoaderReference)}
93 */
94 public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
95 this(mapper, new UnserializableParentsReflectionProvider(reflectionProvider), new ClassLoaderReference(null));
96 }
97
98 public boolean canConvert(Class type) {
99 return JVM.canCreateDerivedObjectOutputStream() && isSerializable(type);
100 }
101
102 private boolean isSerializable(Class type) {
103 if (type != null
104 && Serializable.class.isAssignableFrom(type)
105 && !type.isInterface()
106 && (serializationMembers.supportsReadObject(type, true) || serializationMembers.supportsWriteObject(type,
107 true))) {
108 for (Iterator iter = hierarchyFor(type).iterator(); iter.hasNext();) {
109 if (!Serializable.class.isAssignableFrom((Class)iter.next())) {
110 return canAccess(type);
111 }
112 }
113 return true;
114 }
115 return false;
116 }
117
118 public void doMarshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
119 String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION);
120 if (attributeName != null) {
121 writer.addAttribute(attributeName, ATTRIBUTE_VALUE_CUSTOM);
122 }
123
124 // this is an array as it's a non final value that's accessed from an anonymous inner class.
125 final Class[] currentType = new Class[1];
126 final boolean[] writtenClassWrapper = {false};
127
128 CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() {
129
130 public void writeToStream(Object object) {
131 if (object == null) {
132 writer.startNode(ELEMENT_NULL);
133 writer.endNode();
134 } else {
135 ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass());
136 context.convertAnother(object);
137 writer.endNode();
138 }
139 }
140
141 public void writeFieldsToStream(Map fields) {
142 ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
143
144 writer.startNode(ELEMENT_DEFAULT);
145 for (Iterator iterator = fields.keySet().iterator(); iterator.hasNext();) {
146 String name = (String) iterator.next();
147 if (!mapper.shouldSerializeMember(currentType[0], name)) {
148 continue;
149 }
150 ObjectStreamField field = objectStreamClass.getField(name);
151 Object value = fields.get(name);
152 if (field == null) {
153 throw new ObjectAccessException("Class " + value.getClass().getName()
154 + " may not write a field named '" + name + "'");
155 }
156 if (value != null) {
157 ExtendedHierarchicalStreamWriterHelper.startNode(
158 writer, mapper.serializedMember(source.getClass(), name),
159 value.getClass());
160 if (field.getType() != value.getClass() && !field.getType().isPrimitive()) {
161 String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
162 if (attributeName != null) {
163 writer.addAttribute(attributeName, mapper.serializedClass(value.getClass()));
164 }
165 }
166 context.convertAnother(value);
167 writer.endNode();
168 }
169 }
170 writer.endNode();
171 }
172
173 public void defaultWriteObject() {
174 boolean writtenDefaultFields = false;
175
176 ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
177
178 if (objectStreamClass == null) {
179 return;
180 }
181
182 ObjectStreamField[] fields = objectStreamClass.getFields();
183 for (int i = 0; i < fields.length; i++) {
184 ObjectStreamField field = fields[i];
185 Object value = readField(field, currentType[0], source);
186 if (value != null) {
187 if (!writtenClassWrapper[0]) {
188 writer.startNode(mapper.serializedClass(currentType[0]));
189 writtenClassWrapper[0] = true;
190 }
191 if (!writtenDefaultFields) {
192 writer.startNode(ELEMENT_DEFAULT);
193 writtenDefaultFields = true;
194 }
195 if (!mapper.shouldSerializeMember(currentType[0], field.getName())) {
196 continue;
197 }
198
199 Class actualType = value.getClass();
200 ExtendedHierarchicalStreamWriterHelper.startNode(
201 writer, mapper.serializedMember(source.getClass(), field.getName()), actualType);
202 Class defaultType = mapper.defaultImplementationOf(field.getType());
203 if (!actualType.equals(defaultType)) {
204 String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
205 if (attributeName != null) {
206 writer.addAttribute(attributeName, mapper.serializedClass(actualType));
207 }
208 }
209
210 context.convertAnother(value);
211
212 writer.endNode();
213 }
214 }
215 if (writtenClassWrapper[0] && !writtenDefaultFields) {
216 writer.startNode(ELEMENT_DEFAULT);
217 writer.endNode();
218 } else if (writtenDefaultFields) {
219 writer.endNode();
220 }
221 }
222
223 public void flush() {
224 writer.flush();
225 }
226
227 public void close() {
228 throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutputStream.close() from writeObject()");
229 }
230 };
231
232 try {
233 boolean mustHandleUnserializableParent = false;
234 Iterator classHieararchy = hierarchyFor(source.getClass()).iterator();
235 while (classHieararchy.hasNext()) {
236 currentType[0] = (Class) classHieararchy.next();
237 if (!Serializable.class.isAssignableFrom(currentType[0])) {
238 mustHandleUnserializableParent = true;
239 continue;
240 } else {
241 if (mustHandleUnserializableParent) {
242 marshalUnserializableParent(writer, context, source);
243 mustHandleUnserializableParent = false;
244 }
245 if (serializationMembers.supportsWriteObject(currentType[0], false)) {
246 writtenClassWrapper[0] = true;
247 writer.startNode(mapper.serializedClass(currentType[0]));
248 if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
249 String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
250 if (classAttributeName != null) {
251 writer.addAttribute(classAttributeName, currentType[0].getName());
252 }
253 }
254 CustomObjectOutputStream objectOutputStream = CustomObjectOutputStream.getInstance(context, callback);
255 serializationMembers.callWriteObject(currentType[0], source, objectOutputStream);
256 objectOutputStream.popCallback();
257 writer.endNode();
258 } else if (serializationMembers.supportsReadObject(currentType[0], false)) {
259 // Special case for objects that have readObject(), but not writeObject().
260 // The class wrapper is always written, whether or not this class in the hierarchy has
261 // serializable fields. This guarantees that readObject() will be called upon deserialization.
262 writtenClassWrapper[0] = true;
263 writer.startNode(mapper.serializedClass(currentType[0]));
264 if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) {
265 String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
266 if (classAttributeName != null) {
267 writer.addAttribute(classAttributeName, currentType[0].getName());
268 }
269 }
270 callback.defaultWriteObject();
271 writer.endNode();
272 } else {
273 writtenClassWrapper[0] = false;
274 callback.defaultWriteObject();
275 if (writtenClassWrapper[0]) {
276 writer.endNode();
277 }
278 }
279 }
280 }
281 } catch (IOException e) {
282 throw new ObjectAccessException("Could not call defaultWriteObject()", e);
283 }
284 }
285
286 protected void marshalUnserializableParent(final HierarchicalStreamWriter writer, final MarshallingContext context, final Object replacedSource) {
287 writer.startNode(ELEMENT_UNSERIALIZABLE_PARENTS);
288 super.doMarshal(replacedSource, writer, context);
289 writer.endNode();
290 }
291
292 private Object readField(ObjectStreamField field, Class type, Object instance) {
293 try {
294 Field javaField = type.getDeclaredField(field.getName());
295 if (!javaField.isAccessible()) {
296 javaField.setAccessible(true);
297 }
298 return javaField.get(instance);
299 } catch (IllegalArgumentException e) {
300 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
301 } catch (IllegalAccessException e) {
302 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
303 } catch (NoSuchFieldException e) {
304 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
305 } catch (SecurityException e) {
306 throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
307 }
308 }
309
310 protected List hierarchyFor(Class type) {
311 List result = new ArrayList();
312 while(type != Object.class && type != null) {
313 result.add(type);
314 type = type.getSuperclass();
315 }
316
317 // In Java Object Serialization, the classes are deserialized starting from parent class and moving down.
318 Collections.reverse(result);
319
320 return result;
321 }
322
323 public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) {
324 // this is an array as it's a non final value that's accessed from an anonymous inner class.
325 final Class[] currentType = new Class[1];
326
327 String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION);
328 if (attributeName != null && !ATTRIBUTE_VALUE_CUSTOM.equals(reader.getAttribute(attributeName))) {
329 throw new ConversionException("Cannot deserialize object with new readObject()/writeObject() methods");
330 }
331
332 CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() {
333 public Object readFromStream() {
334 reader.moveDown();
335 Class type = HierarchicalStreams.readClassType(reader, mapper);
336 Object value = context.convertAnother(result, type);
337 reader.moveUp();
338 return value;
339 }
340
341 public Map readFieldsFromStream() {
342 final Map fields = new HashMap();
343 reader.moveDown();
344 if (reader.getNodeName().equals(ELEMENT_FIELDS)) {
345 // Maintain compatibility with XStream 1.1.0
346 while (reader.hasMoreChildren()) {
347 reader.moveDown();
348 if (!reader.getNodeName().equals(ELEMENT_FIELD)) {
349 throw new ConversionException("Expected <" + ELEMENT_FIELD + "/> element inside <" + ELEMENT_FIELD + "/>");
350 }
351 String name = reader.getAttribute(ATTRIBUTE_NAME);
352 Class type = mapper.realClass(reader.getAttribute(ATTRIBUTE_CLASS));
353 Object value = context.convertAnother(result, type);
354 fields.put(name, value);
355 reader.moveUp();
356 }
357 } else if (reader.getNodeName().equals(ELEMENT_DEFAULT)) {
358 // New format introduced in XStream 1.1.1
359 ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
360 while (reader.hasMoreChildren()) {
361 reader.moveDown();
362 String name = mapper.realMember(currentType[0], reader.getNodeName());
363 if (mapper.shouldSerializeMember(currentType[0], name)) {
364 String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
365 Class type;
366 if (classAttribute != null) {
367 type = mapper.realClass(classAttribute);
368 } else {
369 ObjectStreamField field = objectStreamClass.getField(name);
370 if (field == null) {
371 throw new MissingFieldException(currentType[0].getName(), name);
372 }
373 type = field.getType();
374 }
375 Object value = context.convertAnother(result, type);
376 fields.put(name, value);
377 }
378 reader.moveUp();
379 }
380 } else {
381 throw new ConversionException("Expected <" + ELEMENT_FIELDS + "/> or <" +
382 ELEMENT_DEFAULT + "/> element when calling ObjectInputStream.readFields()");
383 }
384 reader.moveUp();
385 return fields;
386 }
387
388 public void defaultReadObject() {
389 if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) {
390 readFieldsFromStream();
391 return;
392 }
393 if (!reader.hasMoreChildren()) {
394 return;
395 }
396 reader.moveDown();
397 if (!reader.getNodeName().equals(ELEMENT_DEFAULT)) {
398 throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream");
399 }
400 while (reader.hasMoreChildren()) {
401 reader.moveDown();
402
403 String fieldName = mapper.realMember(currentType[0], reader.getNodeName());
404 if (mapper.shouldSerializeMember(currentType[0], fieldName)) {
405 String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
406 final Class type;
407 if (classAttribute != null) {
408 type = mapper.realClass(classAttribute);
409 } else {
410 type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0]));
411 }
412
413 Object value = context.convertAnother(result, type);
414 reflectionProvider.writeField(result, fieldName, value, currentType[0]);
415 }
416
417 reader.moveUp();
418 }
419 reader.moveUp();
420 }
421
422 public void registerValidation(final ObjectInputValidation validation, int priority) {
423 context.addCompletionCallback(new Runnable() {
424 public void run() {
425 try {
426 validation.validateObject();
427 } catch (InvalidObjectException e) {
428 throw new ObjectAccessException("Cannot validate object : " + e.getMessage(), e);
429 }
430 }
431 }, priority);
432 }
433
434 public void close() {
435 throw new UnsupportedOperationException("Objects are not allowed to call ObjectInputStream.close() from readObject()");
436 }
437 };
438
439 while (reader.hasMoreChildren()) {
440 reader.moveDown();
441 String nodeName = reader.getNodeName();
442 if (nodeName.equals(ELEMENT_UNSERIALIZABLE_PARENTS)) {
443 super.doUnmarshal(result, reader, context);
444 } else {
445 String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper);
446 if (classAttribute == null) {
447 currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName));
448 } else {
449 currentType[0] = mapper.realClass(classAttribute);
450 }
451 if (serializationMembers.supportsReadObject(currentType[0], false)) {
452 CustomObjectInputStream objectInputStream =
453 CustomObjectInputStream.getInstance(context, callback, classLoaderReference);
454 serializationMembers.callReadObject(currentType[0], result, objectInputStream);
455 objectInputStream.popCallback();
456 } else {
457 try {
458 callback.defaultReadObject();
459 } catch (IOException e) {
460 throw new ObjectAccessException("Could not call defaultWriteObject()", e);
461 }
462 }
463 }
464 reader.moveUp();
465 }
466
467 return result;
468 }
469
470 protected void doMarshalConditionally(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
471 if(isSerializable(source.getClass())) {
472 doMarshal(source, writer, context);
473 } else {
474 super.doMarshal(source, writer, context);
475 }
476 }
477
478 protected Object doUnmarshalConditionally(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) {
479 return isSerializable(result.getClass()) ? doUnmarshal(result, reader, context) : super.doUnmarshal(result, reader, context);
480 }
481
482 private static class UnserializableParentsReflectionProvider extends ReflectionProviderWrapper {
483
484 public UnserializableParentsReflectionProvider(final ReflectionProvider reflectionProvider) {
485 super(reflectionProvider);
486 }
487
488 public void visitSerializableFields(final Object object, final Visitor visitor) {
489 wrapped.visitSerializableFields(object, new Visitor() {
490 public void visit(String name, Class type, Class definedIn, Object value) {
491 if (!Serializable.class.isAssignableFrom(definedIn)) {
492 visitor.visit(name, type, definedIn, value);
493 }
494 }
495 });
496 }
497 }
498 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2014, 2015 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 23. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15
16 import com.thoughtworks.xstream.core.Caching;
17 import com.thoughtworks.xstream.core.util.SerializationMembers;
18
19 /**
20 * Convenience wrapper to invoke special serialization methods on objects (and perform
21 * reflection caching).
22 *
23 * @author Joe Walnes
24 * @author J&ouml;rg Schaible
25 * @deprecated As of 1.4.8, moved into internal util package.
26 */
27 public class SerializationMethodInvoker implements Caching {
28
29 SerializationMembers serializationMembers = new SerializationMembers();
30
31 /**
32 * Resolves an object as native serialization does by calling readResolve(), if available.
33 *
34 * @deprecated As of 1.4.8, moved into internal util package.
35 */
36 public Object callReadResolve(Object result) {
37 return serializationMembers.callReadResolve(result);
38 }
39
40 /**
41 * @deprecated As of 1.4.8, moved into internal util package.
42 */
43 public Object callWriteReplace(Object object) {
44 return serializationMembers.callWriteReplace(object);
45 }
46
47 /**
48 * @deprecated As of 1.4.8, moved into internal util package.
49 */
50 public boolean supportsReadObject(Class type, boolean includeBaseClasses) {
51 return serializationMembers.supportsReadObject(type, includeBaseClasses);
52 }
53
54 /**
55 * @deprecated As of 1.4.8, moved into internal util package.
56 */
57 public void callReadObject(Class type, Object object, ObjectInputStream stream) {
58 serializationMembers.callReadObject(type, object, stream);
59 }
60
61 /**
62 * @deprecated As of 1.4.8, moved into internal util package.
63 */
64 public boolean supportsWriteObject(Class type, boolean includeBaseClasses) {
65 return serializationMembers.supportsWriteObject(type, includeBaseClasses);
66 }
67
68 /**
69 * @deprecated As of 1.4.8, moved into internal util package.
70 */
71 public void callWriteObject(Class type, Object instance, ObjectOutputStream stream) {
72 serializationMembers.callWriteObject(type, instance, stream);
73 }
74
75 /**
76 * @deprecated As of 1.4.8, moved into internal util package.
77 */
78 public void flushCache() {
79 serializationMembers.flushCache();
80 }
81 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.xstream.core.Caching;
13 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
14 import com.thoughtworks.xstream.io.StreamException;
15
16 import java.util.Arrays;
17 import java.util.Comparator;
18 import java.util.HashMap;
19 import java.util.Map;
20
21
22 /**
23 * The default implementation for sorting fields. Invoke registerFieldOrder in order to set the
24 * field order for an specific type.
25 *
26 * @author Guilherme Silveira
27 * @since 1.2.2
28 */
29 public class SortableFieldKeySorter implements FieldKeySorter, Caching {
30
31 private final Map map = new HashMap();
32
33 public Map sort(Class type, Map keyedByFieldKey) {
34 if (map.containsKey(type)) {
35 Map result = new OrderRetainingMap();
36 FieldKey[] fieldKeys = (FieldKey[])keyedByFieldKey.keySet().toArray(
37 new FieldKey[keyedByFieldKey.size()]);
38 Arrays.sort(fieldKeys, (Comparator)map.get(type));
39 for (int i = 0; i < fieldKeys.length; i++ ) {
40 result.put(fieldKeys[i], keyedByFieldKey.get(fieldKeys[i]));
41 }
42 return result;
43 } else {
44 return keyedByFieldKey;
45 }
46 }
47
48 /**
49 * Registers the field order to use for a specific type. This will not affect any of the
50 * type's super or sub classes. If you skip a field which will be serialized, XStream will
51 * thrown an StreamException during the serialization process.
52 *
53 * @param type the type
54 * @param fields the field order
55 */
56 public void registerFieldOrder(Class type, String[] fields) {
57 map.put(type, new FieldComparator(fields));
58 }
59
60 private class FieldComparator implements Comparator {
61
62 private final String[] fieldOrder;
63
64 public FieldComparator(String[] fields) {
65 this.fieldOrder = fields;
66 }
67
68 public int compare(String first, String second) {
69 int firstPosition = -1, secondPosition = -1;
70 for (int i = 0; i < fieldOrder.length; i++ ) {
71 if (fieldOrder[i].equals(first)) {
72 firstPosition = i;
73 }
74 if (fieldOrder[i].equals(second)) {
75 secondPosition = i;
76 }
77 }
78 if (firstPosition == -1 || secondPosition == -1) {
79 // field not defined!!!
80 throw new StreamException(
81 "You have not given XStream a list of all fields to be serialized.");
82 }
83 return firstPosition - secondPosition;
84 }
85
86 public int compare(Object firstObject, Object secondObject) {
87 FieldKey first = (FieldKey)firstObject, second = (FieldKey)secondObject;
88 return compare(first.getFieldName(), second.getFieldName());
89 }
90
91 }
92
93 public void flushCache() {
94 map.clear();
95 }
96 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 /**
14 * Instantiates a new object on the Sun JVM by bypassing the constructor (meaning code in the constructor will never be
15 * executed and parameters do not have to be known). This is the same method used by the internals of standard Java
16 * serialization, but relies on internal Sun code that may not be present on all JVMs.
17 *
18 * @author Joe Walnes
19 * @author Brian Slesinsky
20 * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider}
21 */
22 public class Sun14ReflectionProvider extends SunUnsafeReflectionProvider {
23 /**
24 * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider()}
25 */
26 public Sun14ReflectionProvider() {
27 super();
28 }
29
30 /**
31 * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider(FieldDictionary)}
32 */
33 public Sun14ReflectionProvider(FieldDictionary dic) {
34 super(dic);
35 }
36
37 private Object readResolve() {
38 init();
39 return this;
40 }
41 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014 XStream Committers.
3 * All rights reserved.
4 *
5 * Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProvider
6 */
7 package com.thoughtworks.xstream.converters.reflection;
8
9 import java.lang.reflect.Field;
10
11 import sun.misc.Unsafe;
12
13
14 /**
15 * Instantiates a new object bypassing the constructor using undocumented internal JDK features.
16 * <p>
17 * The code in the constructor will never be executed and parameters do not have to be known. This is the same method
18 * used by the internals of standard Java serialization, but relies on internal code (sun.misc.Unsafe) that may not be
19 * present on all JVMs.
20 * <p>
21 * <p>
22 * The implementation will use standard Java functionality to write any fields. This requires Java 5 as minimum runtime
23 * and is used as fallback on platforms that do not provide the complete implementation level for the internals (like
24 * Dalvik).
25 * <p>
26 *
27 * @author J&ouml;rg Schaible
28 * @author Joe Walnes
29 * @author Brian Slesinsky
30 * @since 1.4.7
31 */
32 public class SunLimitedUnsafeReflectionProvider extends PureJavaReflectionProvider {
33
34 protected static final Unsafe unsafe;
35 protected static final Exception exception;
36 static {
37 Unsafe u = null;
38 Exception ex = null;
39 try {
40 Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
41 unsafeField.setAccessible(true);
42 u = (Unsafe)unsafeField.get(null);
43 } catch (SecurityException e) {
44 ex = e;
45 } catch (NoSuchFieldException e) {
46 ex = e;
47 } catch (IllegalArgumentException e) {
48 ex = e;
49 } catch (IllegalAccessException e) {
50 ex = e;
51 }
52 exception = ex;
53 unsafe = u;
54 }
55
56 /**
57 * @since 1.4.7
58 */
59 public SunLimitedUnsafeReflectionProvider() {
60 super();
61 }
62
63 /**
64 * @since 1.4.7
65 */
66 public SunLimitedUnsafeReflectionProvider(FieldDictionary fieldDictionary) {
67 super(fieldDictionary);
68 }
69
70 public Object newInstance(Class type) {
71 if (exception != null) {
72 throw new ObjectAccessException("Cannot construct " + type.getName(), exception);
73 }
74 try {
75 return unsafe.allocateInstance(type);
76 } catch (SecurityException e) {
77 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
78 } catch (InstantiationException e) {
79 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
80 } catch (IllegalArgumentException e) {
81 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
82 }
83 }
84
85 protected void validateFieldAccess(Field field) {
86 // (overriden) don't mind final fields.
87 }
88
89 private Object readResolve() {
90 init();
91 return this;
92 }
93 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014 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 08. January 2014 by Joerg Schaible, renamed from Sun14ReflectionProvider
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.lang.reflect.Field;
14 import java.util.Map;
15 import java.util.WeakHashMap;
16
17
18 /**
19 * Instantiates a new object bypassing the constructor using undocumented internal JDK features.
20 * <p>
21 * The code in the constructor will never be executed and parameters do not have to be known. This is the same method
22 * used by the internals of standard Java serialization, but relies on internal code (sun.misc.Unsafe) that may not be
23 * present on all JVMs.
24 * <p>
25 * <p>
26 * The implementation will use the same internals to write into fields. This is a lot faster and was additionally the
27 * only possibility to set final fields prior to Java 5.
28 * <p>
29 *
30 * @author Joe Walnes
31 * @author Brian Slesinsky
32 * @author J&ouml;rg Schaible
33 * @since 1.4.7
34 */
35 public class SunUnsafeReflectionProvider extends SunLimitedUnsafeReflectionProvider {
36
37 // references to the Field key are kept in the FieldDictionary
38 private transient Map fieldOffsetCache;
39
40 /**
41 * @since 1.4.7
42 */
43 public SunUnsafeReflectionProvider() {
44 super();
45 }
46
47 /**
48 * @since 1.4.7
49 */
50 public SunUnsafeReflectionProvider(FieldDictionary dic) {
51 super(dic);
52 }
53
54 public void writeField(Object object, String fieldName, Object value, Class definedIn) {
55 write(fieldDictionary.field(object.getClass(), fieldName, definedIn), object, value);
56 }
57
58 private void write(Field field, Object object, Object value) {
59 if (exception != null) {
60 throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(),
61 exception);
62 }
63 try {
64 long offset = getFieldOffset(field);
65 Class type = field.getType();
66 if (type.isPrimitive()) {
67 if (type.equals(Integer.TYPE)) {
68 unsafe.putInt(object, offset, ((Integer)value).intValue());
69 } else if (type.equals(Long.TYPE)) {
70 unsafe.putLong(object, offset, ((Long)value).longValue());
71 } else if (type.equals(Short.TYPE)) {
72 unsafe.putShort(object, offset, ((Short)value).shortValue());
73 } else if (type.equals(Character.TYPE)) {
74 unsafe.putChar(object, offset, ((Character)value).charValue());
75 } else if (type.equals(Byte.TYPE)) {
76 unsafe.putByte(object, offset, ((Byte)value).byteValue());
77 } else if (type.equals(Float.TYPE)) {
78 unsafe.putFloat(object, offset, ((Float)value).floatValue());
79 } else if (type.equals(Double.TYPE)) {
80 unsafe.putDouble(object, offset, ((Double)value).doubleValue());
81 } else if (type.equals(Boolean.TYPE)) {
82 unsafe.putBoolean(object, offset, ((Boolean)value).booleanValue());
83 } else {
84 throw new ObjectAccessException("Could not set field "
85 + object.getClass()
86 + "."
87 + field.getName()
88 + ": Unknown type "
89 + type);
90 }
91 } else {
92 unsafe.putObject(object, offset, value);
93 }
94
95 } catch (IllegalArgumentException e) {
96 throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e);
97 }
98 }
99
100 private synchronized long getFieldOffset(Field f) {
101 Long l = (Long)fieldOffsetCache.get(f);
102 if (l == null) {
103 l = new Long(unsafe.objectFieldOffset(f));
104 fieldOffsetCache.put(f, l);
105 }
106
107 return l.longValue();
108 }
109
110 private Object readResolve() {
111 init();
112 return this;
113 }
114
115 protected void init() {
116 super.init();
117 fieldOffsetCache = new WeakHashMap();
118 }
119 }
0 /*
1 * Copyright (C) 2007, 2008, 2013 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 19.09.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.util.Comparator;
13 import java.util.Map;
14 import java.util.TreeMap;
15
16
17 /**
18 * Sort the fields in the order of XStream 1.2.x. Fields are returned in their declaration order,
19 * fields of base classes last.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.3
23 */
24 public class XStream12FieldKeySorter implements FieldKeySorter {
25
26 public Map sort(final Class type, final Map keyedByFieldKey) {
27 final Map map = new TreeMap(new Comparator() {
28
29 public int compare(final Object o1, final Object o2) {
30 final FieldKey fieldKey1 = (FieldKey)o1;
31 final FieldKey fieldKey2 = (FieldKey)o2;
32 int i = fieldKey2.getDepth() - fieldKey1.getDepth();
33 if (i == 0) {
34 i = fieldKey1.getOrder() - fieldKey2.getOrder();
35 }
36 return i;
37 }
38 });
39 map.putAll(keyedByFieldKey);
40 keyedByFieldKey.clear();
41 keyedByFieldKey.putAll(map);
42 return keyedByFieldKey;
43 }
44
45 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 15. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.ConverterLookup;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.core.util.ObjectIdDictionary;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18 import com.thoughtworks.xstream.io.path.Path;
19 import com.thoughtworks.xstream.io.path.PathTracker;
20 import com.thoughtworks.xstream.io.path.PathTrackingWriter;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import java.util.Iterator;
24
25 /**
26 * Abstract base class for a TreeMarshaller, that can build references.
27 *
28 * @author Joe Walnes
29 * @author J&ouml;rg Schaible
30 * @author Mauro Talevi
31 * @since 1.2
32 */
33 public abstract class AbstractReferenceMarshaller extends TreeMarshaller implements MarshallingContext {
34
35 private ObjectIdDictionary references = new ObjectIdDictionary();
36 private ObjectIdDictionary implicitElements = new ObjectIdDictionary();
37 private PathTracker pathTracker = new PathTracker();
38 private Path lastPath;
39
40 public AbstractReferenceMarshaller(HierarchicalStreamWriter writer,
41 ConverterLookup converterLookup,
42 Mapper mapper) {
43 super(writer, converterLookup, mapper);
44 this.writer = new PathTrackingWriter(writer, pathTracker);
45 }
46
47 public void convert(Object item, Converter converter) {
48 if (getMapper().isImmutableValueType(item.getClass())) {
49 // strings, ints, dates, etc... don't bother using references.
50 converter.marshal(item, writer, this);
51 } else {
52 final Path currentPath = pathTracker.getPath();
53 Id existingReference = (Id)references.lookupId(item);
54 if (existingReference != null && existingReference.getPath() != currentPath) {
55 String attributeName = getMapper().aliasForSystemAttribute("reference");
56 if (attributeName != null) {
57 writer.addAttribute(attributeName, createReference(currentPath, existingReference.getItem()));
58 }
59 } else {
60 final Object newReferenceKey = existingReference == null
61 ? createReferenceKey(currentPath, item)
62 : existingReference.getItem();
63 if (lastPath == null || !currentPath.isAncestor(lastPath)) {
64 fireValidReference(newReferenceKey);
65 lastPath = currentPath;
66 references.associateId(item, new Id(newReferenceKey, currentPath));
67 }
68 converter.marshal(item, writer, new ReferencingMarshallingContext() {
69
70 public void put(Object key, Object value) {
71 AbstractReferenceMarshaller.this.put(key, value);
72 }
73
74 public Iterator keys() {
75 return AbstractReferenceMarshaller.this.keys();
76 }
77
78 public Object get(Object key) {
79 return AbstractReferenceMarshaller.this.get(key);
80 }
81
82 public void convertAnother(Object nextItem, Converter converter) {
83 AbstractReferenceMarshaller.this.convertAnother(nextItem, converter);
84 }
85
86 public void convertAnother(Object nextItem) {
87 AbstractReferenceMarshaller.this.convertAnother(nextItem);
88 }
89
90 public void replace(Object original, Object replacement) {
91 references.associateId(replacement, new Id(newReferenceKey, currentPath));
92 }
93
94 public Object lookupReference(Object item) {
95 Id id = (Id)references.lookupId(item);
96 return id.getItem();
97 }
98
99 /**
100 * @deprecated As of 1.4.2
101 */
102 public Path currentPath() {
103 return pathTracker.getPath();
104 }
105
106 public void registerImplicit(Object item) {
107 if (implicitElements.containsId(item)) {
108 throw new ReferencedImplicitElementException(item, currentPath);
109 }
110 implicitElements.associateId(item, newReferenceKey);
111 }
112 });
113 }
114 }
115 }
116
117 protected abstract String createReference(Path currentPath, Object existingReferenceKey);
118 protected abstract Object createReferenceKey(Path currentPath, Object item);
119 protected abstract void fireValidReference(Object referenceKey);
120
121 private static class Id {
122 private Object item;
123 private Path path;
124 public Id(Object item, Path path) {
125 this.item = item;
126 this.path = path;
127 }
128 protected Object getItem() {
129 return this.item;
130 }
131 protected Path getPath() {
132 return this.path;
133 }
134 }
135
136 public static class ReferencedImplicitElementException extends ConversionException {
137 public ReferencedImplicitElementException(final Object item, final Path path) {
138 super("Cannot reference implicit element");
139 add("implicit-element", item.toString());
140 add("referencing-element", path.toString());
141 }
142 }
143 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2011 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 15. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.converters.Converter;
17 import com.thoughtworks.xstream.converters.ConverterLookup;
18 import com.thoughtworks.xstream.core.util.FastStack;
19 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
20 import com.thoughtworks.xstream.mapper.Mapper;
21
22 /**
23 * Abstract base class for a TreeUnmarshaller, that resolves references.
24 *
25 * @author Joe Walnes
26 * @author J&ouml;rg Schaible
27 * @author Mauro Talevi
28 * @since 1.2
29 */
30 public abstract class AbstractReferenceUnmarshaller extends TreeUnmarshaller {
31
32 private static final Object NULL = new Object();
33 private Map values = new HashMap();
34 private FastStack parentStack = new FastStack(16);
35
36 public AbstractReferenceUnmarshaller(Object root, HierarchicalStreamReader reader,
37 ConverterLookup converterLookup, Mapper mapper) {
38 super(root, reader, converterLookup, mapper);
39 }
40
41 protected Object convert(Object parent, Class type, Converter converter) {
42 if (parentStack.size() > 0) { // handles circular references
43 Object parentReferenceKey = parentStack.peek();
44 if (parentReferenceKey != null) {
45 if (!values.containsKey(parentReferenceKey)) { // see AbstractCircularReferenceTest.testWeirdCircularReference()
46 values.put(parentReferenceKey, parent);
47 }
48 }
49 }
50 final Object result;
51 String attributeName = getMapper().aliasForSystemAttribute("reference");
52 String reference = attributeName == null ? null : reader.getAttribute(attributeName);
53 if (reference != null) {
54 Object cache = values.get(getReferenceKey(reference));
55 if (cache == null) {
56 final ConversionException ex = new ConversionException("Invalid reference");
57 ex.add("reference", reference);
58 throw ex;
59 }
60 result = cache == NULL ? null : cache;
61 } else {
62 Object currentReferenceKey = getCurrentReferenceKey();
63 parentStack.push(currentReferenceKey);
64 result = super.convert(parent, type, converter);
65 if (currentReferenceKey != null) {
66 values.put(currentReferenceKey, result == null ? NULL : result);
67 }
68 parentStack.popSilently();
69 }
70 return result;
71 }
72
73 protected abstract Object getReferenceKey(String reference);
74 protected abstract Object getCurrentReferenceKey();
75 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2009 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 26.09.2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import com.thoughtworks.xstream.MarshallingStrategy;
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.converters.DataHolder;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 /**
21 * Basic functionality of a tree based marshalling strategy.
22 *
23 * @author Joe Walnes
24 * @author J&ouml;rg Schaible
25 * @since 1.3
26 */
27 public abstract class AbstractTreeMarshallingStrategy implements MarshallingStrategy {
28
29 public Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) {
30 TreeUnmarshaller context = createUnmarshallingContext(root, reader, converterLookup, mapper);
31 return context.start(dataHolder);
32 }
33
34 public void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder) {
35 TreeMarshaller context = createMarshallingContext(writer, converterLookup, mapper);
36 context.start(obj, dataHolder);
37 }
38
39 protected abstract TreeUnmarshaller createUnmarshallingContext(Object root,
40 HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper);
41
42 protected abstract TreeMarshaller createMarshallingContext(
43 HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper);
44 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 14. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.XStreamException;
14
15 /**
16 * JDK1.3 friendly exception that retains cause.
17 * @deprecated As of 1.3, use {@link XStreamException} instead
18 */
19 public abstract class BaseException extends RuntimeException {
20
21 protected BaseException(String message) {
22 super(message);
23 }
24
25 public abstract Throwable getCause();
26 }
0 /*
1 * Copyright (C) 2011 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 19. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 /**
13 * Marker interface for caching implementations.
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.4
17 */
18 public interface Caching {
19 void flushCache();
20 }
0 /*
1 * Copyright (C) 2013 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 26. June 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
13
14 /**
15 * Reference to a ClassLoader, allowing a single instance to be passed around the codebase that
16 * can later have its destination changed.
17 *
18 * @author J&ouml;rg Schaible
19 * @since 1.4.5
20 */
21 public final class ClassLoaderReference {
22
23 private transient ClassLoader reference;
24
25 public ClassLoaderReference(ClassLoader reference) {
26 setReference(reference);
27 }
28
29 public ClassLoader getReference() {
30 return reference;
31 }
32
33 public void setReference(ClassLoader reference) {
34 this.reference = reference instanceof com.thoughtworks.xstream.core.util.ClassLoaderReference
35 ? ((com.thoughtworks.xstream.core.util.ClassLoaderReference)reference)
36 .getReference() : reference;
37 }
38
39 private Object readResolve() {
40 this.reference = new CompositeClassLoader();
41 return this;
42 }
43 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.ConverterLookup;
16 import com.thoughtworks.xstream.converters.ConverterRegistry;
17 import com.thoughtworks.xstream.core.util.PrioritizedList;
18 import com.thoughtworks.xstream.mapper.Mapper;
19
20 import java.util.Collections;
21 import java.util.Iterator;
22 import java.util.Map;
23 import java.util.WeakHashMap;
24
25 /**
26 * The default implementation of converters lookup.
27 *
28 * @author Joe Walnes
29 * @author J&ouml;rg Schaible
30 * @author Guilherme Silveira
31 */
32 public class DefaultConverterLookup implements ConverterLookup, ConverterRegistry, Caching {
33
34 private final PrioritizedList converters = new PrioritizedList();
35 private transient Map typeToConverterMap;
36
37 public DefaultConverterLookup() {
38 readResolve();
39 }
40
41 /**
42 * @deprecated As of 1.3, use {@link #DefaultConverterLookup()}
43 */
44 public DefaultConverterLookup(Mapper mapper) {
45 }
46
47 public Converter lookupConverterForType(Class type) {
48 Converter cachedConverter = (Converter) typeToConverterMap.get(type);
49 if (cachedConverter != null) {
50 return cachedConverter;
51 }
52 Iterator iterator = converters.iterator();
53 while (iterator.hasNext()) {
54 Converter converter = (Converter) iterator.next();
55 if (converter.canConvert(type)) {
56 typeToConverterMap.put(type, converter);
57 return converter;
58 }
59 }
60 throw new ConversionException("No converter specified for " + type);
61 }
62
63 public void registerConverter(Converter converter, int priority) {
64 converters.add(converter, priority);
65 for (Iterator iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) {
66 Class type = (Class) iter.next();
67 if (converter.canConvert(type)) {
68 iter.remove();
69 }
70 }
71 }
72
73 public void flushCache() {
74 typeToConverterMap.clear();
75 Iterator iterator = converters.iterator();
76 while (iterator.hasNext()) {
77 Converter converter = (Converter) iterator.next();
78 if (converter instanceof Caching) {
79 ((Caching)converter).flushCache();
80 }
81 }
82 }
83
84 private Object readResolve() {
85 typeToConverterMap = Collections.synchronizedMap(new WeakHashMap());
86 return this;
87 }
88 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015 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 09. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.reflection.FieldDictionary;
14 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
15 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
16 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
17 import com.thoughtworks.xstream.core.util.CustomObjectOutputStream;
18 import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
19 import com.thoughtworks.xstream.core.util.PresortedMap;
20 import com.thoughtworks.xstream.core.util.PresortedSet;
21
22 import java.io.IOException;
23 import java.lang.reflect.Field;
24 import java.lang.reflect.Method;
25 import java.text.AttributedString;
26 import java.text.ParseException;
27 import java.text.SimpleDateFormat;
28 import java.util.Comparator;
29 import java.util.SortedMap;
30 import java.util.SortedSet;
31 import java.util.TreeMap;
32 import java.util.TreeSet;
33
34 public class JVM implements Caching {
35
36 private ReflectionProvider reflectionProvider;
37
38 private static final boolean isAWTAvailable;
39 private static final boolean isSwingAvailable;
40 private static final boolean isSQLAvailable;
41 private static final boolean canAllocateWithUnsafe;
42 private static final boolean canWriteWithUnsafe;
43 private static final boolean optimizedTreeSetAddAll;
44 private static final boolean optimizedTreeMapPutAll;
45 private static final boolean canParseUTCDateFormat;
46 private static final boolean canParseISO8601TimeZoneInDateFormat;
47 private static final boolean canCreateDerivedObjectOutputStream;
48
49 private static final String vendor = System.getProperty("java.vm.vendor");
50 private static final float majorJavaVersion = getMajorJavaVersion();
51 private static final float DEFAULT_JAVA_VERSION = 1.4f;
52 private static final boolean reverseFieldOrder = false;
53 private static final Class reflectionProviderType;
54
55 static class Test {
56 private Object o;
57 private char c;
58 private byte b;
59 private short s;
60 private int i;
61 private long l;
62 private float f;
63 private double d;
64 private boolean bool;
65 Test() {
66 throw new UnsupportedOperationException();
67 }
68 }
69
70 static {
71 boolean test = true;
72 Object unsafe = null;
73 try {
74 Class unsafeClass = Class.forName("sun.misc.Unsafe");
75 Field unsafeField = unsafeClass.getDeclaredField("theUnsafe");
76 unsafeField.setAccessible(true);
77 unsafe = unsafeField.get(null);
78 Method allocateInstance = unsafeClass.getDeclaredMethod("allocateInstance", new Class[]{Class.class});
79 allocateInstance.setAccessible(true);
80 test = allocateInstance.invoke(unsafe, new Object[]{Test.class}) != null;
81 } catch (Exception e) {
82 test = false;
83 } catch (Error e) {
84 test = false;
85 }
86 canAllocateWithUnsafe = test;
87 test = false;
88 Class type = PureJavaReflectionProvider.class;
89 if (canUseSunUnsafeReflectionProvider()) {
90 Class cls = loadClassForName("com.thoughtworks.xstream.converters.reflection.SunUnsafeReflectionProvider");
91 if (cls != null) {
92 try {
93 ReflectionProvider provider = (ReflectionProvider)DependencyInjectionFactory.newInstance(cls, null);
94 Test t = (Test)provider.newInstance(Test.class);
95 try {
96 provider.writeField(t, "o", "object", Test.class);
97 provider.writeField(t, "c", new Character('c'), Test.class);
98 provider.writeField(t, "b", new Byte((byte)1), Test.class);
99 provider.writeField(t, "s", new Short((short)1), Test.class);
100 provider.writeField(t, "i", new Integer(1), Test.class);
101 provider.writeField(t, "l", new Long(1), Test.class);
102 provider.writeField(t, "f", new Float(1), Test.class);
103 provider.writeField(t, "d", new Double(1), Test.class);
104 provider.writeField(t, "bool", Boolean.TRUE, Test.class);
105 test = true;
106 } catch(IncompatibleClassChangeError e) {
107 cls = null;
108 } catch (ObjectAccessException e) {
109 cls = null;
110 }
111 if (cls == null) {
112 cls = loadClassForName("com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider");
113 }
114 type = cls;
115 } catch (ObjectAccessException e) {
116 }
117 }
118 }
119 reflectionProviderType = type;
120 canWriteWithUnsafe = test;
121 Comparator comparator = new Comparator() {
122 public int compare(Object o1, Object o2) {
123 throw new RuntimeException();
124 }
125 };
126 SortedMap map = new PresortedMap(comparator);
127 map.put("one", null);
128 map.put("two", null);
129 try {
130 new TreeMap(comparator).putAll(map);
131 test = true;
132 } catch (RuntimeException e) {
133 test = false;
134 }
135 optimizedTreeMapPutAll = test;
136 SortedSet set = new PresortedSet(comparator);
137 set.addAll(map.keySet());
138 try {
139 new TreeSet(comparator).addAll(set);
140 test = true;
141 } catch (RuntimeException e) {
142 test = false;
143 }
144 optimizedTreeSetAddAll = test;
145 try {
146 new SimpleDateFormat("z").parse("UTC");
147 test = true;
148 } catch (ParseException e) {
149 test = false;
150 }
151 canParseUTCDateFormat = test;
152 try {
153 new SimpleDateFormat("X").parse("Z");
154 test = true;
155 } catch (final ParseException e) {
156 test = false;
157 } catch (final IllegalArgumentException e) {
158 test = false;
159 }
160 canParseISO8601TimeZoneInDateFormat = test;
161 try {
162 test = new CustomObjectOutputStream(null) != null;
163 } catch (RuntimeException e) {
164 test = false;
165 } catch (IOException e) {
166 test = false;
167 }
168 canCreateDerivedObjectOutputStream = test;
169
170 isAWTAvailable = loadClassForName("java.awt.Color", false) != null;
171 isSwingAvailable = loadClassForName("javax.swing.LookAndFeel", false) != null;
172 isSQLAvailable = loadClassForName("java.sql.Date") != null;
173 }
174
175 /**
176 * @deprecated As of 1.4.5 use the static methods of JVM.
177 */
178 public JVM() {
179 }
180
181 /**
182 * Parses the java version system property to determine the major java version,
183 * i.e. 1.x
184 *
185 * @return A float of the form 1.x
186 */
187 private static final float getMajorJavaVersion() {
188 try {
189 return isAndroid() ? 1.5f : Float.parseFloat(System.getProperty("java.specification.version"));
190 } catch ( NumberFormatException e ){
191 // Some JVMs may not conform to the x.y.z java.version format
192 return DEFAULT_JAVA_VERSION;
193 }
194 }
195
196 /**
197 * @deprecated As of 1.4.4, minimal JDK version is 1.4 already
198 */
199 public static boolean is14() {
200 return majorJavaVersion >= 1.4f;
201 }
202
203 /**
204 * @deprecated As of 1.4.4, minimal JDK version will be 1.6 for next major release
205 */
206 public static boolean is15() {
207 return majorJavaVersion >= 1.5f;
208 }
209
210 /**
211 * @deprecated As of 1.4.4, minimal JDK version will be 1.6 for next major release
212 */
213 public static boolean is16() {
214 return majorJavaVersion >= 1.6f;
215 }
216
217 /**
218 * @since 1.4
219 */
220 public static boolean is17() {
221 return majorJavaVersion >= 1.7f;
222 }
223
224 /**
225 * @since 1.4
226 */
227 public static boolean is18() {
228 return majorJavaVersion >= 1.8f;
229 }
230
231 /**
232 * @since 1.4.8
233 */
234 public static boolean is19() {
235 return majorJavaVersion >= 1.9f;
236 }
237
238 private static boolean isIBM() {
239 return vendor.indexOf("IBM") != -1;
240 }
241
242 /**
243 * @since 1.4
244 */
245 private static boolean isAndroid() {
246 return vendor.indexOf("Android") != -1;
247 }
248
249 /**
250 * Load a XStream class for the given name.
251 *
252 * <p>This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap
253 * until it is able to use the user provided or the default {@link ClassLoader}.</p>
254 *
255 * @since 1.4.5
256 */
257 public static Class loadClassForName(String name) {
258 return loadClassForName(name, true);
259 }
260
261 /**
262 * @deprecated As of 1.4.5 use {@link #loadClassForName(String)}
263 */
264 public Class loadClass(String name) {
265 return loadClassForName(name, true);
266 }
267
268 /**
269 * Load a XStream class for the given name.
270 *
271 * <p>This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap
272 * until it is able to use the user provided or the default {@link ClassLoader}.</p>
273 *
274 * @since 1.4.5
275 */
276 public static Class loadClassForName(String name, boolean initialize) {
277 try {
278 Class clazz = Class.forName(name, initialize, JVM.class.getClassLoader());
279 return clazz;
280 } catch (LinkageError e) {
281 return null;
282 } catch (ClassNotFoundException e) {
283 return null;
284 }
285 }
286
287 /**
288 * @since 1.4.4
289 * @deprecated As of 1.4.5 use {@link #loadClassForName(String, boolean)}
290 */
291 public Class loadClass(String name, boolean initialize) {
292 return loadClassForName(name, initialize);
293 }
294
295 /**
296 * Create the best matching ReflectionProvider.
297 *
298 * @return a new instance
299 * @since 1.4.5
300 */
301 public static ReflectionProvider newReflectionProvider() {
302 return (ReflectionProvider)DependencyInjectionFactory.newInstance(reflectionProviderType, null);
303 }
304
305 /**
306 * Create the best matching ReflectionProvider.
307 *
308 * @param dictionary the FieldDictionary to use by the ReflectionProvider
309 * @return a new instance
310 * @since 1.4.5
311 */
312 public static ReflectionProvider newReflectionProvider(FieldDictionary dictionary) {
313 return (ReflectionProvider)DependencyInjectionFactory.newInstance(reflectionProviderType, new Object[]{ dictionary });
314 }
315
316 /**
317 * Get the XMLInputFactory implementation used normally by the current Java runtime as
318 * standard.
319 * <p>
320 * In contrast to XMLInputFactory.newFactory() this method will ignore any implementations
321 * provided with the system property <em>javax.xml.stream.XMLInputFactory</em>,
322 * implementations configured in <em>lib/stax.properties</em> or registered with the Service
323 * API.
324 * </p>
325 *
326 * @return the XMLInputFactory implementation or null
327 * @throws ClassNotFoundException if the standard class cannot be found
328 * @since 1.4.5
329 */
330 public static Class getStaxInputFactory() throws ClassNotFoundException {
331 if (is16()) {
332 if (isIBM()) {
333 return Class.forName("com.ibm.xml.xlxp.api.stax.XMLInputFactoryImpl");
334 } else {
335 return Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl");
336 }
337 }
338 return null;
339 }
340
341 /**
342 * Get the XMLOutputFactory implementation used normally by the current Java runtime as
343 * standard.
344 * <p>
345 * In contrast to XMLOutputFactory.newFactory() this method will ignore any implementations
346 * provided with the system property <em>javax.xml.stream.XMLOutputFactory</em>,
347 * implementations configured in <em>lib/stax.properties</em> or registered with the Service
348 * API.
349 * </p>
350 *
351 * @return the XMLOutputFactory implementation or null
352 * @throws ClassNotFoundException if the standard class cannot be found
353 * @since 1.4.5
354 */
355 public static Class getStaxOutputFactory() throws ClassNotFoundException {
356 if (is16()) {
357 if (isIBM()) {
358 return Class.forName("com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl");
359 } else {
360 return Class.forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl");
361 }
362 }
363 return null;
364 }
365
366 /**
367 * @deprecated As of 1.4.5 use {@link #newReflectionProvider()}
368 */
369 public synchronized ReflectionProvider bestReflectionProvider() {
370 if (reflectionProvider == null) {
371 reflectionProvider = newReflectionProvider();
372 }
373 return reflectionProvider;
374 }
375
376 private static boolean canUseSunUnsafeReflectionProvider() {
377 return canAllocateWithUnsafe && is14();
378 }
379
380 private static boolean canUseSunLimitedUnsafeReflectionProvider() {
381 return canWriteWithUnsafe;
382 }
383
384 /**
385 * @deprecated As of 1.4.5
386 */
387 public static boolean reverseFieldDefinition() {
388 return reverseFieldOrder;
389 }
390
391 /**
392 * Checks if AWT is available.
393 * @since 1.4.5
394 */
395 public static boolean isAWTAvailable() {
396 return isAWTAvailable;
397 }
398
399 /**
400 * Checks if the jvm supports awt.
401 * @deprecated As of 1.4.5 use {@link #isAWTAvailable()}
402 */
403 public boolean supportsAWT() {
404 return this.isAWTAvailable;
405 }
406
407 /**
408 * Checks if Swing is available.
409 * @since 1.4.5
410 */
411 public static boolean isSwingAvailable() {
412 return isSwingAvailable;
413 }
414
415 /**
416 * Checks if the jvm supports swing.
417 * @deprecated As of 1.4.5 use {@link #isSwingAvailable()}
418 */
419 public boolean supportsSwing() {
420 return this.isSwingAvailable;
421 }
422
423 /**
424 * Checks if SQL is available.
425 * @since 1.4.5
426 */
427 public static boolean isSQLAvailable() {
428 return isSQLAvailable;
429 }
430
431 /**
432 * Checks if the jvm supports sql.
433 * @deprecated As of 1.4.5 use {@link #isSQLAvailable()}
434 */
435 public boolean supportsSQL() {
436 return this.isSQLAvailable;
437 }
438
439 /**
440 * Checks if TreeSet.addAll is optimized for SortedSet argument.
441 *
442 * @since 1.4
443 */
444 public static boolean hasOptimizedTreeSetAddAll() {
445 return optimizedTreeSetAddAll;
446 }
447
448 /**
449 * Checks if TreeMap.putAll is optimized for SortedMap argument.
450 *
451 * @since 1.4
452 */
453 public static boolean hasOptimizedTreeMapPutAll() {
454 return optimizedTreeMapPutAll;
455 }
456
457 public static boolean canParseUTCDateFormat() {
458 return canParseUTCDateFormat;
459 }
460
461 /**
462 * @since 1.4.8
463 */
464 public static boolean canParseISO8601TimeZoneInDateFormat() {
465 return canParseISO8601TimeZoneInDateFormat;
466 }
467
468 /**
469 * @since 1.4.6
470 */
471 public static boolean canCreateDerivedObjectOutputStream() {
472 return canCreateDerivedObjectOutputStream;
473 }
474
475 /**
476 * @deprecated As of 1.4.5 no functionality
477 */
478 public void flushCache() {
479 }
480
481 public static void main(String[] args) {
482 boolean reverseJDK = false;
483 Field[] fields = AttributedString.class.getDeclaredFields();
484 for (int i = 0; i < fields.length; i++) {
485 if (fields[i].getName().equals("text")) {
486 reverseJDK = i > 3;
487 break;
488 }
489 }
490
491 boolean reverseLocal = false;
492 fields = Test.class.getDeclaredFields();
493 for (int i = 0; i < fields.length; i++) {
494 if (fields[i].getName().equals("o")) {
495 reverseLocal = i > 3;
496 break;
497 }
498 }
499
500 String staxInputFactory = null;
501 try {
502 staxInputFactory = getStaxInputFactory().getName();
503 } catch (ClassNotFoundException e) {
504 staxInputFactory = e.getMessage();
505 } catch (NullPointerException e) {
506 }
507
508 String staxOutputFactory = null;
509 try {
510 staxOutputFactory = getStaxOutputFactory().getName();
511 } catch (ClassNotFoundException e) {
512 staxOutputFactory = e.getMessage();
513 } catch (NullPointerException e) {
514 }
515
516 System.out.println("XStream JVM diagnostics");
517 System.out.println("java.specification.version: " + System.getProperty("java.specification.version"));
518 System.out.println("java.specification.vendor: " + System.getProperty("java.specification.vendor"));
519 System.out.println("java.specification.name: " + System.getProperty("java.specification.name"));
520 System.out.println("java.vm.vendor: " + vendor);
521 System.out.println("java.vendor: " + System.getProperty("java.vendor"));
522 System.out.println("java.vm.name: " + System.getProperty("java.vm.name"));
523 System.out.println("Version: " + majorJavaVersion);
524 System.out.println("XStream support for enhanced Mode: " + canUseSunUnsafeReflectionProvider());
525 System.out.println("XStream support for reduced Mode: " + canUseSunLimitedUnsafeReflectionProvider());
526 System.out.println("Supports AWT: " + isAWTAvailable());
527 System.out.println("Supports Swing: " + isSwingAvailable());
528 System.out.println("Supports SQL: " + isSQLAvailable());
529 System.out.println("Java Beans EventHandler present: " + (loadClassForName("java.beans.EventHandler") != null));
530 System.out.println("Standard StAX XMLInputFactory: " + staxInputFactory);
531 System.out.println("Standard StAX XMLOutputFactory: " + staxOutputFactory);
532 System.out.println("Optimized TreeSet.addAll: " + hasOptimizedTreeSetAddAll());
533 System.out.println("Optimized TreeMap.putAll: " + hasOptimizedTreeMapPutAll());
534 System.out.println("Can parse UTC date format: " + canParseUTCDateFormat());
535 System.out.println("Can create derive ObjectOutputStream: " + canCreateDerivedObjectOutputStream());
536 System.out.println("Reverse field order detected for JDK: " + reverseJDK);
537 System.out.println("Reverse field order detected (only if JVM class itself has been compiled): " + reverseLocal);
538 }
539 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 04. October 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.DataHolder;
14
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.Iterator;
18 import java.util.Map;
19
20 public class MapBackedDataHolder implements DataHolder {
21 private final Map map;
22
23 public MapBackedDataHolder() {
24 this(new HashMap());
25 }
26
27 public MapBackedDataHolder(Map map) {
28 this.map = map;
29 }
30
31 public Object get(Object key) {
32 return map.get(key);
33 }
34
35 public void put(Object key, Object value) {
36 map.put(key, value);
37 }
38
39 public Iterator keys() {
40 return Collections.unmodifiableCollection(map.keySet()).iterator();
41 }
42 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 15. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.path.Path;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 public class ReferenceByIdMarshaller extends AbstractReferenceMarshaller {
19
20 private final IDGenerator idGenerator;
21
22 public static interface IDGenerator {
23 String next(Object item);
24 }
25
26 public ReferenceByIdMarshaller(HierarchicalStreamWriter writer,
27 ConverterLookup converterLookup,
28 Mapper mapper,
29 IDGenerator idGenerator) {
30 super(writer, converterLookup, mapper);
31 this.idGenerator = idGenerator;
32 }
33
34 public ReferenceByIdMarshaller(HierarchicalStreamWriter writer,
35 ConverterLookup converterLookup,
36 Mapper mapper) {
37 this(writer, converterLookup, mapper, new SequenceGenerator(1));
38 }
39
40 protected String createReference(Path currentPath, Object existingReferenceKey) {
41 return existingReferenceKey.toString();
42 }
43
44 protected Object createReferenceKey(Path currentPath, Object item) {
45 return idGenerator.next(item);
46 }
47
48 protected void fireValidReference(Object referenceKey) {
49 String attributeName = getMapper().aliasForSystemAttribute("id");
50 if (attributeName != null) {
51 writer.addAttribute(attributeName, referenceKey.toString());
52 }
53 }
54 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 16. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 public class ReferenceByIdMarshallingStrategy extends AbstractTreeMarshallingStrategy {
19
20 protected TreeUnmarshaller createUnmarshallingContext(Object root,
21 HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) {
22 return new ReferenceByIdUnmarshaller(root, reader, converterLookup, mapper);
23 }
24
25 protected TreeMarshaller createMarshallingContext(
26 HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
27 return new ReferenceByIdMarshaller(writer, converterLookup, mapper);
28 }
29 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 15. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.mapper.Mapper;
16
17 public class ReferenceByIdUnmarshaller extends AbstractReferenceUnmarshaller {
18
19 public ReferenceByIdUnmarshaller(Object root, HierarchicalStreamReader reader,
20 ConverterLookup converterLookup, Mapper mapper) {
21 super(root, reader, converterLookup, mapper);
22 }
23
24 protected Object getReferenceKey(String reference) {
25 return reference;
26 }
27
28 protected Object getCurrentReferenceKey() {
29 String attributeName = getMapper().aliasForSystemAttribute("id");
30 return attributeName == null ? null : reader.getAttribute(attributeName);
31 }
32 }
0 /*
1 * Copyright (C) 2004, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 03. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.path.Path;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 public class ReferenceByXPathMarshaller extends AbstractReferenceMarshaller {
19
20 private final int mode;
21
22 public ReferenceByXPathMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper, int mode) {
23 super(writer, converterLookup, mapper);
24 this.mode = mode;
25 }
26
27 protected String createReference(Path currentPath, Object existingReferenceKey) {
28 Path existingPath = (Path)existingReferenceKey;
29 Path referencePath = (mode & ReferenceByXPathMarshallingStrategy.ABSOLUTE) > 0 ? existingPath : currentPath.relativeTo(existingPath);
30 return (mode & ReferenceByXPathMarshallingStrategy.SINGLE_NODE) > 0 ? referencePath.explicit() : referencePath.toString();
31 }
32
33 protected Object createReferenceKey(Path currentPath, Object item) {
34 return currentPath;
35 }
36
37 protected void fireValidReference(Object referenceKey) {
38 // nothing to do
39 }
40 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 03. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 public class ReferenceByXPathMarshallingStrategy extends AbstractTreeMarshallingStrategy {
19
20 public static int RELATIVE = 0;
21 public static int ABSOLUTE = 1;
22 public static int SINGLE_NODE = 2;
23 private final int mode;
24
25 public ReferenceByXPathMarshallingStrategy(int mode) {
26 this.mode = mode;
27 }
28
29 protected TreeUnmarshaller createUnmarshallingContext(Object root,
30 HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) {
31 return new ReferenceByXPathUnmarshaller(root, reader, converterLookup, mapper);
32 }
33
34 protected TreeMarshaller createMarshallingContext(
35 HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
36 return new ReferenceByXPathMarshaller(writer, converterLookup, mapper, mode);
37 }
38 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.AbstractReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.path.Path;
17 import com.thoughtworks.xstream.io.path.PathTracker;
18 import com.thoughtworks.xstream.io.path.PathTrackingReader;
19 import com.thoughtworks.xstream.mapper.Mapper;
20
21 public class ReferenceByXPathUnmarshaller extends AbstractReferenceUnmarshaller {
22
23 private PathTracker pathTracker = new PathTracker();
24 protected boolean isNameEncoding;
25
26 public ReferenceByXPathUnmarshaller(Object root, HierarchicalStreamReader reader,
27 ConverterLookup converterLookup, Mapper mapper) {
28 super(root, reader, converterLookup, mapper);
29 this.reader = new PathTrackingReader(reader, pathTracker);
30 isNameEncoding = reader.underlyingReader() instanceof AbstractReader;
31 }
32
33 protected Object getReferenceKey(String reference) {
34 final Path path = new Path(isNameEncoding ? ((AbstractReader)reader.underlyingReader()).decodeNode(reference) : reference);
35 // We have absolute references, if path starts with '/'
36 return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path;
37 }
38
39 protected Object getCurrentReferenceKey() {
40 return pathTracker.getPath();
41 }
42
43 }
0 /*
1 * Copyright (C) 2009, 2011 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 06. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import com.thoughtworks.xstream.converters.MarshallingContext;
13 import com.thoughtworks.xstream.io.path.Path;
14
15 /**
16 * A {@link MarshallingContext} that manages references.
17 *
18 * @author J&ouml;rg Schaible
19 * @since 1.4
20 */
21 public interface ReferencingMarshallingContext extends MarshallingContext {
22
23 /**
24 * Retrieve the current path.
25 *
26 * @return the current path
27 * @since 1.4
28 * @deprecated As of 1.4.2
29 */
30 Path currentPath();
31
32 /**
33 * Request the reference key for the given item
34 *
35 * @param item the item to lookup
36 * @return the reference key or <code>null</code>
37 * @since 1.4
38 */
39 Object lookupReference(Object item);
40
41 /**
42 * Replace the currently marshalled item.
43 *
44 * <p><strong>Use this method only, if you know exactly what you do!</strong> It is a special solution for
45 * Serializable types that make usage of the writeReplace method where the replacing object itself is referenced.</p>
46 *
47 * @param original the original item to convert
48 * @param replacement the replacement item that is converted instead
49 * @since 1.4
50 */
51 void replace(Object original, Object replacement);
52
53 /**
54 * Register an implicit element. This is typically some kind of collection. Note, that this object may not be
55 * referenced anywhere else in the object stream.
56 *
57 * @param item the object that is implicit
58 * @since 1.4
59 */
60 void registerImplicit(Object item);
61 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 16. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 public class SequenceGenerator implements ReferenceByIdMarshaller.IDGenerator {
14
15 private int counter;
16
17 public SequenceGenerator(int startsAt) {
18 this.counter = startsAt;
19 }
20
21 public String next(Object item) {
22 return String.valueOf(counter++);
23 }
24
25 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 15. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.ConverterLookup;
16 import com.thoughtworks.xstream.converters.DataHolder;
17 import com.thoughtworks.xstream.converters.MarshallingContext;
18 import com.thoughtworks.xstream.core.util.ObjectIdDictionary;
19 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
20 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import java.util.Iterator;
24
25
26 public class TreeMarshaller implements MarshallingContext {
27
28 protected HierarchicalStreamWriter writer;
29 protected ConverterLookup converterLookup;
30 private Mapper mapper;
31 private ObjectIdDictionary parentObjects = new ObjectIdDictionary();
32 private DataHolder dataHolder;
33
34 public TreeMarshaller(
35 HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
36 this.writer = writer;
37 this.converterLookup = converterLookup;
38 this.mapper = mapper;
39 }
40
41 public void convertAnother(Object item) {
42 convertAnother(item, null);
43 }
44
45 public void convertAnother(Object item, Converter converter) {
46 if (converter == null) {
47 converter = converterLookup.lookupConverterForType(item.getClass());
48 } else {
49 if (!converter.canConvert(item.getClass())) {
50 ConversionException e = new ConversionException(
51 "Explicit selected converter cannot handle item");
52 e.add("item-type", item.getClass().getName());
53 e.add("converter-type", converter.getClass().getName());
54 throw e;
55 }
56 }
57 convert(item, converter);
58 }
59
60 protected void convert(Object item, Converter converter) {
61 if (parentObjects.containsId(item)) {
62 ConversionException e = new CircularReferenceException(
63 "Recursive reference to parent object");
64 e.add("item-type", item.getClass().getName());
65 e.add("converter-type", converter.getClass().getName());
66 throw e;
67 }
68 parentObjects.associateId(item, "");
69 converter.marshal(item, writer, this);
70 parentObjects.removeId(item);
71 }
72
73 public void start(Object item, DataHolder dataHolder) {
74 this.dataHolder = dataHolder;
75 if (item == null) {
76 writer.startNode(mapper.serializedClass(null));
77 writer.endNode();
78 } else {
79 ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
80 .serializedClass(item.getClass()), item.getClass());
81 convertAnother(item);
82 writer.endNode();
83 }
84 }
85
86 public Object get(Object key) {
87 lazilyCreateDataHolder();
88 return dataHolder.get(key);
89 }
90
91 public void put(Object key, Object value) {
92 lazilyCreateDataHolder();
93 dataHolder.put(key, value);
94 }
95
96 public Iterator keys() {
97 lazilyCreateDataHolder();
98 return dataHolder.keys();
99 }
100
101 private void lazilyCreateDataHolder() {
102 if (dataHolder == null) {
103 dataHolder = new MapBackedDataHolder();
104 }
105 }
106
107 protected Mapper getMapper() {
108 return this.mapper;
109 }
110
111 public static class CircularReferenceException extends ConversionException {
112
113 public CircularReferenceException(String msg) {
114 super(msg);
115 }
116 }
117 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 16. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 public class TreeMarshallingStrategy extends AbstractTreeMarshallingStrategy {
19
20 protected TreeUnmarshaller createUnmarshallingContext(Object root,
21 HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) {
22 return new TreeUnmarshaller(root, reader, converterLookup, mapper);
23 }
24
25 protected TreeMarshaller createMarshallingContext(
26 HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) {
27 return new TreeMarshaller(writer, converterLookup, mapper);
28 }
29 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 15. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import java.util.Iterator;
14
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.converters.Converter;
17 import com.thoughtworks.xstream.converters.ConverterLookup;
18 import com.thoughtworks.xstream.converters.DataHolder;
19 import com.thoughtworks.xstream.converters.ErrorReporter;
20 import com.thoughtworks.xstream.converters.ErrorWriter;
21 import com.thoughtworks.xstream.converters.UnmarshallingContext;
22 import com.thoughtworks.xstream.core.util.FastStack;
23 import com.thoughtworks.xstream.core.util.HierarchicalStreams;
24 import com.thoughtworks.xstream.core.util.PrioritizedList;
25 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
26 import com.thoughtworks.xstream.mapper.Mapper;
27
28
29 public class TreeUnmarshaller implements UnmarshallingContext {
30
31 private Object root;
32 protected HierarchicalStreamReader reader;
33 private ConverterLookup converterLookup;
34 private Mapper mapper;
35 private FastStack types = new FastStack(16);
36 private DataHolder dataHolder;
37 private final PrioritizedList validationList = new PrioritizedList();
38
39 public TreeUnmarshaller(
40 Object root, HierarchicalStreamReader reader, ConverterLookup converterLookup,
41 Mapper mapper) {
42 this.root = root;
43 this.reader = reader;
44 this.converterLookup = converterLookup;
45 this.mapper = mapper;
46 }
47
48 public Object convertAnother(Object parent, Class type) {
49 return convertAnother(parent, type, null);
50 }
51
52 public Object convertAnother(Object parent, Class type, Converter converter) {
53 type = mapper.defaultImplementationOf(type);
54 if (converter == null) {
55 converter = converterLookup.lookupConverterForType(type);
56 } else {
57 if (!converter.canConvert(type)) {
58 ConversionException e = new ConversionException(
59 "Explicit selected converter cannot handle type");
60 e.add("item-type", type.getName());
61 e.add("converter-type", converter.getClass().getName());
62 throw e;
63 }
64 }
65 return convert(parent, type, converter);
66 }
67
68 protected Object convert(Object parent, Class type, Converter converter) {
69 try {
70 types.push(type);
71 Object result = converter.unmarshal(reader, this);
72 types.popSilently();
73 return result;
74 } catch (ConversionException conversionException) {
75 addInformationTo(conversionException, type, converter, parent);
76 throw conversionException;
77 } catch (RuntimeException e) {
78 ConversionException conversionException = new ConversionException(e);
79 addInformationTo(conversionException, type, converter, parent);
80 throw conversionException;
81 }
82 }
83
84 private void addInformationTo(ErrorWriter errorWriter, Class type, Converter converter, Object parent) {
85 errorWriter.add("class", type.getName());
86 errorWriter.add("required-type", getRequiredType().getName());
87 errorWriter.add("converter-type", converter.getClass().getName());
88 if (converter instanceof ErrorReporter) {
89 ((ErrorReporter)converter).appendErrors(errorWriter);
90 }
91 if (parent instanceof ErrorReporter) {
92 ((ErrorReporter)parent).appendErrors(errorWriter);
93 }
94 reader.appendErrors(errorWriter);
95 }
96
97 public void addCompletionCallback(Runnable work, int priority) {
98 validationList.add(work, priority);
99 }
100
101 public Object currentObject() {
102 return types.size() == 1 ? root : null;
103 }
104
105 public Class getRequiredType() {
106 return (Class)types.peek();
107 }
108
109 public Object get(Object key) {
110 lazilyCreateDataHolder();
111 return dataHolder.get(key);
112 }
113
114 public void put(Object key, Object value) {
115 lazilyCreateDataHolder();
116 dataHolder.put(key, value);
117 }
118
119 public Iterator keys() {
120 lazilyCreateDataHolder();
121 return dataHolder.keys();
122 }
123
124 private void lazilyCreateDataHolder() {
125 if (dataHolder == null) {
126 dataHolder = new MapBackedDataHolder();
127 }
128 }
129
130 public Object start(DataHolder dataHolder) {
131 this.dataHolder = dataHolder;
132 Class type = HierarchicalStreams.readClassType(reader, mapper);
133 Object result = convertAnother(null, type);
134 Iterator validations = validationList.iterator();
135 while (validations.hasNext()) {
136 Runnable runnable = (Runnable)validations.next();
137 runnable.run();
138 }
139 return result;
140 }
141
142 protected Mapper getMapper() {
143 return this.mapper;
144 }
145
146 }
0 /*
1 * Copyright (C) 2011 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 29.07.2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.lang.reflect.Array;
13 import java.util.Iterator;
14
15 /**
16 * @author J&ouml;rg Schaible
17 *
18 * @since 1.4
19 */
20 public class ArrayIterator implements Iterator {
21 private final Object array;
22 private int idx;
23 private int length;
24 public ArrayIterator(Object array) {
25 this.array = array;
26 length = Array.getLength(array);
27 }
28
29 public boolean hasNext() {
30 return idx < length;
31 }
32
33 public Object next() {
34 return Array.get(array, idx++);
35 }
36
37 public void remove() {
38 throw new UnsupportedOperationException("Remove from array");
39 }
40 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.io.ByteArrayOutputStream;
14 import java.io.IOException;
15 import java.io.Reader;
16 import java.io.StringReader;
17
18 /**
19 * Encodes binary data to plain text as Base64.
20 *
21 * <p>Despite there being a gazillion other Base64 implementations out there, this has been written as part of XStream as
22 * it forms a core part but is too trivial to warrant an extra dependency.</p>
23 *
24 * <p>This meets the standard as described in RFC 1521, section 5.2 <http://www.freesoft.org/CIE/RFC/1521/7.htm>, allowing
25 * other Base64 tools to manipulate the data.</p>
26 *
27 * @author Joe Walnes
28 */
29 public class Base64Encoder {
30
31 // Here's how encoding works:
32 //
33 // 1) Incoming bytes are broken up into groups of 3 (each byte having 8 bits).
34 //
35 // 2) The combined 24 bits (3 * 8) are split into 4 groups of 6 bits.
36 //
37 // input |------||------||------| (3 values each with 8 bits)
38 // 101010101010101010101010
39 // output |----||----||----||----| (4 values each with 6 bits)
40 //
41 // 3) Each of these 4 groups of 6 bits are converted back to a number, which will fall in the range of 0 - 63.
42 //
43 // 4) Each of these 4 numbers are converted to an alphanumeric char in a specified mapping table, to create
44 // a 4 character string.
45 //
46 // 5) This is repeated for all groups of three bytes.
47 //
48 // 6) Special padding is done at the end of the stream using the '=' char.
49
50 private static final char[] SIXTY_FOUR_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
51 private static final int[] REVERSE_MAPPING = new int[123];
52
53 static {
54 for (int i = 0; i < SIXTY_FOUR_CHARS.length; i++) REVERSE_MAPPING[SIXTY_FOUR_CHARS[i]] = i + 1;
55 }
56
57 public String encode(byte[] input) {
58 StringBuffer result = new StringBuffer();
59 int outputCharCount = 0;
60 for (int i = 0; i < input.length; i += 3) {
61 int remaining = Math.min(3, input.length - i);
62 int oneBigNumber = (input[i] & 0xff) << 16 | (remaining <= 1 ? 0 : input[i + 1] & 0xff) << 8 | (remaining <= 2 ? 0 : input[i + 2] & 0xff);
63 for (int j = 0; j < 4; j++) result.append(remaining + 1 > j ? SIXTY_FOUR_CHARS[0x3f & oneBigNumber >> 6 * (3 - j)] : '=');
64 if ((outputCharCount += 4) % 76 == 0) result.append('\n');
65 }
66 return result.toString();
67 }
68
69 public byte[] decode(String input) {
70 try {
71 ByteArrayOutputStream out = new ByteArrayOutputStream();
72 StringReader in = new StringReader(input);
73 for (int i = 0; i < input.length(); i += 4) {
74 int a[] = {mapCharToInt(in), mapCharToInt(in), mapCharToInt(in), mapCharToInt(in)};
75 int oneBigNumber = (a[0] & 0x3f) << 18 | (a[1] & 0x3f) << 12 | (a[2] & 0x3f) << 6 | (a[3] & 0x3f);
76 for (int j = 0; j < 3; j++) if (a[j + 1] >= 0) out.write(0xff & oneBigNumber >> 8 * (2 - j));
77 }
78 return out.toByteArray();
79 } catch (IOException e) {
80 throw new Error(e + ": " + e.getMessage());
81 }
82 }
83
84 private int mapCharToInt(Reader input) throws IOException {
85 int c;
86 while ((c = input.read()) != -1) {
87 int result = REVERSE_MAPPING[c];
88 if (result != 0) return result -1;
89 if (c == '=') return -1;
90 }
91 return -1;
92 }
93 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 07. March 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 /**
14 * ClassLoader that refers to another ClassLoader, allowing a single instance to be passed around the codebase that
15 * can later have its destination changed.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @since 1.1.1
20 * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.ClassLoaderReference} instead
21 */
22 public class ClassLoaderReference extends ClassLoader {
23
24 private transient ClassLoader reference;
25
26 /**
27 * @deprecated As of 1.4.5 use
28 * {@link com.thoughtworks.xstream.core.ClassLoaderReference#ClassLoaderReference(ClassLoader)}
29 * instead
30 */
31 public ClassLoaderReference(ClassLoader reference) {
32 this.reference = reference;
33 }
34
35 /**
36 * @deprecated As of 1.4.5 use
37 * {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()}
38 * .loadClass(String) instead
39 */
40 public Class loadClass(String name) throws ClassNotFoundException {
41 return reference.loadClass(name);
42 }
43
44 /**
45 * @deprecated As of 1.4.5 use
46 * {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()}
47 * instead
48 */
49 public ClassLoader getReference() {
50 return reference;
51 }
52
53 /**
54 * @deprecated As of 1.4.5 use
55 * {@link com.thoughtworks.xstream.core.ClassLoaderReference#setReference(ClassLoader)}
56 * instead
57 */
58 public void setReference(ClassLoader reference) {
59 this.reference = reference;
60 }
61
62 private Object writeReplace() {
63 return new Replacement();
64 }
65
66 static class Replacement {
67
68 private Object readResolve() {
69 return new ClassLoaderReference(new CompositeClassLoader());
70 }
71
72 };
73 }
0 /*
1 * Copyright (C) 2009, 2010, 2011 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 29. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.lang.reflect.Array;
13 import java.lang.reflect.InvocationTargetException;
14 import java.lang.reflect.Method;
15
16 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
17
18 /**
19 * Utility functions for {@link Cloneable} objects.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.4
23 */
24 public class Cloneables {
25
26 public static Object clone(Object o) {
27 if (o instanceof Cloneable) {
28 if (o.getClass().isArray()) {
29 final Class componentType = o.getClass().getComponentType();
30 if (!componentType.isPrimitive()) {
31 return ((Object[])o).clone();
32 } else {
33 int length = Array.getLength(o);
34 final Object clone = Array.newInstance(componentType, length);
35 while (length-- > 0) {
36 Array.set(clone, length, Array.get(o, length));
37 }
38
39 return clone;
40 }
41 } else {
42 try {
43 Method clone = o.getClass().getMethod("clone", (Class[])null);
44 return clone.invoke(o, (Object[])null);
45 } catch (NoSuchMethodException e) {
46 throw new ObjectAccessException("Cloneable type has no clone method", e);
47 } catch (IllegalAccessException e) {
48 throw new ObjectAccessException("Cannot clone Cloneable type", e);
49 } catch (InvocationTargetException e) {
50 throw new ObjectAccessException("Exception cloning Cloneable type", e.getCause());
51 }
52 }
53 }
54 return null;
55 }
56
57 public static Object cloneIfPossible(Object o) {
58 Object clone = clone(o);
59 return clone == null ? o : clone;
60 }
61 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013 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 16. November 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.lang.ref.ReferenceQueue;
14 import java.lang.ref.WeakReference;
15 import java.lang.reflect.Method;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import com.thoughtworks.xstream.core.JVM;
22
23 /**
24 * ClassLoader that is composed of other classloaders. Each loader will be used to try to load the particular class, until
25 * one of them succeeds. <b>Note:</b> The loaders will always be called in the REVERSE order they were added in.
26 *
27 * <p>The Composite class loader also has registered the classloader that loaded xstream.jar
28 * and (if available) the thread's context classloader.</p>
29 *
30 * <h1>Example</h1>
31 * <pre><code>CompositeClassLoader loader = new CompositeClassLoader();
32 * loader.add(MyClass.class.getClassLoader());
33 * loader.add(new AnotherClassLoader());
34 * &nbsp;
35 * loader.loadClass("com.blah.ChickenPlucker");
36 * </code></pre>
37 *
38 * <p>The above code will attempt to load a class from the following classloaders (in order):</p>
39 *
40 * <ul>
41 * <li>AnotherClassLoader (and all its parents)</li>
42 * <li>The classloader for MyClas (and all its parents)</li>
43 * <li>The thread's context classloader (and all its parents)</li>
44 * <li>The classloader for XStream (and all its parents)</li>
45 * </ul>
46 *
47 * <p>The added classloaders are kept with weak references to allow an application container to reload classes.</p>
48 *
49 * @author Joe Walnes
50 * @author J&ouml;rg Schaible
51 * @since 1.0.3
52 */
53 public class CompositeClassLoader extends ClassLoader {
54 static {
55 if (JVM.is17()) {
56 // see http://www.cs.duke.edu/csed/java/jdk1.7/technotes/guides/lang/cl-mt.html
57 try {
58 Method m = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", (Class[])null);
59 if (!m.isAccessible()) {
60 m.setAccessible(true);
61 }
62 m.invoke(null, (Object[])null);
63 } catch (Exception e) {
64 // ignore errors, JVM will synchronize class for Java 7 or higher
65 }
66 }
67 }
68
69 private final ReferenceQueue queue = new ReferenceQueue();
70 private final List classLoaders = new ArrayList();
71
72 public CompositeClassLoader() {
73 addInternal(Object.class.getClassLoader()); // bootstrap loader.
74 addInternal(getClass().getClassLoader()); // whichever classloader loaded this jar.
75 }
76
77 /**
78 * Add a loader to the n
79 * @param classLoader
80 */
81 public synchronized void add(ClassLoader classLoader) {
82 cleanup();
83 if (classLoader != null) {
84 addInternal(classLoader);
85 }
86 }
87
88 private void addInternal(ClassLoader classLoader) {
89 WeakReference refClassLoader = null;
90 for (Iterator iterator = classLoaders.iterator(); iterator.hasNext();) {
91 WeakReference ref = (WeakReference) iterator.next();
92 ClassLoader cl = (ClassLoader)ref.get();
93 if (cl == null) {
94 iterator.remove();
95 } else if (cl == classLoader) {
96 iterator.remove();
97 refClassLoader = ref;
98 }
99 }
100 classLoaders.add(0, refClassLoader != null ? refClassLoader : new WeakReference(classLoader, queue));
101 }
102
103 public Class loadClass(String name) throws ClassNotFoundException {
104 List copy = new ArrayList(classLoaders.size()) {
105
106 public boolean addAll(Collection c) {
107 boolean result = false;
108 for(Iterator iter = c.iterator(); iter.hasNext(); ) {
109 result |= add(iter.next());
110 }
111 return result;
112 }
113
114 public boolean add(Object ref) {
115 Object classLoader = ((WeakReference)ref).get();
116 if (classLoader != null) {
117 return super.add(classLoader);
118 }
119 return false;
120 }
121
122 };
123 synchronized(this) {
124 cleanup();
125 copy.addAll(classLoaders);
126 }
127
128 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
129 for (Iterator iterator = copy.iterator(); iterator.hasNext();) {
130 ClassLoader classLoader = (ClassLoader) iterator.next();
131 if (classLoader == contextClassLoader) {
132 contextClassLoader = null;
133 }
134 try {
135 return classLoader.loadClass(name);
136 } catch (ClassNotFoundException notFound) {
137 // ok.. try another one
138 }
139 }
140
141 // One last try - the context class loader associated with the current thread. Often used in j2ee servers.
142 // Note: The contextClassLoader cannot be added to the classLoaders list up front as the thread that constructs
143 // XStream is potentially different to thread that uses it.
144 if (contextClassLoader != null) {
145 return contextClassLoader.loadClass(name);
146 } else {
147 throw new ClassNotFoundException(name);
148 }
149 }
150
151 private void cleanup() {
152 WeakReference ref;
153 while ((ref = (WeakReference)queue.poll()) != null)
154 {
155 classLoaders.remove(ref);
156 }
157 }
158 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013 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 23. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.io.IOException;
14 import java.io.InvalidObjectException;
15 import java.io.NotActiveException;
16 import java.io.ObjectInputStream;
17 import java.io.ObjectInputValidation;
18 import java.io.ObjectStreamClass;
19 import java.io.StreamCorruptedException;
20 import java.util.Map;
21
22 import com.thoughtworks.xstream.converters.ConversionException;
23 import com.thoughtworks.xstream.converters.DataHolder;
24 import com.thoughtworks.xstream.core.ClassLoaderReference;
25
26 public class CustomObjectInputStream extends ObjectInputStream {
27
28 private FastStack callbacks = new FastStack(1);
29 private final ClassLoaderReference classLoaderReference;
30
31 private static final String DATA_HOLDER_KEY = CustomObjectInputStream.class.getName();
32
33 public static interface StreamCallback {
34 Object readFromStream() throws IOException;
35 Map readFieldsFromStream() throws IOException;
36 void defaultReadObject() throws IOException;
37 void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException, InvalidObjectException;
38 void close() throws IOException;
39 }
40
41 /**
42 * @deprecated As of 1.4 use {@link #getInstance(DataHolder, StreamCallback, ClassLoader)}
43 */
44 public static CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback) {
45 return getInstance(whereFrom, callback, (ClassLoader)null);
46 }
47
48 /**
49 * @deprecated As of 1.4.5 use {@link #getInstance(DataHolder, StreamCallback, ClassLoaderReference)}
50 */
51 public static synchronized CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback, ClassLoader classLoader) {
52 return getInstance(whereFrom, callback, new ClassLoaderReference(classLoader));
53 }
54
55 public static synchronized CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback, ClassLoaderReference classLoaderReference) {
56 try {
57 CustomObjectInputStream result = (CustomObjectInputStream) whereFrom.get(DATA_HOLDER_KEY);
58 if (result == null) {
59 result = new CustomObjectInputStream(callback, classLoaderReference);
60 whereFrom.put(DATA_HOLDER_KEY, result);
61 } else {
62 result.pushCallback(callback);
63 }
64 return result;
65 } catch (IOException e) {
66 throw new ConversionException("Cannot create CustomObjectStream", e);
67 }
68 }
69
70 /**
71 * Warning, this object is expensive to create (due to functionality inherited from superclass).
72 * Use the static fetch() method instead, wherever possible.
73 *
74 * @see #getInstance(DataHolder, StreamCallback, ClassLoaderReference)
75 */
76 public CustomObjectInputStream(StreamCallback callback, ClassLoaderReference classLoaderReference) throws IOException, SecurityException {
77 super();
78 this.callbacks.push(callback);
79 this.classLoaderReference = classLoaderReference;
80 }
81
82 /**
83 * @deprecated As of 1.4.5 use {@link #CustomObjectInputStream(StreamCallback, ClassLoaderReference)}
84 */
85 public CustomObjectInputStream(StreamCallback callback, ClassLoader classLoader) throws IOException, SecurityException {
86 this(callback, new ClassLoaderReference(classLoader));
87 }
88
89 /**
90 * Allows the CustomObjectInputStream (which is expensive to create) to be reused.
91 */
92 public void pushCallback(StreamCallback callback) {
93 this.callbacks.push(callback);
94 }
95
96 public StreamCallback popCallback(){
97 return (StreamCallback) this.callbacks.pop();
98 }
99
100 public StreamCallback peekCallback(){
101 return (StreamCallback) this.callbacks.peek();
102 }
103
104 protected Class resolveClass(ObjectStreamClass desc)
105 throws IOException, ClassNotFoundException {
106 ClassLoader classLoader = classLoaderReference.getReference();
107 if (classLoader == null) {
108 return super.resolveClass(desc);
109 } else {
110 return Class.forName(desc.getName(), false, classLoader);
111 }
112 }
113
114 public void defaultReadObject() throws IOException {
115 peekCallback().defaultReadObject();
116 }
117
118 protected Object readObjectOverride() throws IOException {
119 return peekCallback().readFromStream();
120 }
121
122 public Object readUnshared() throws IOException, ClassNotFoundException {
123 return readObject();
124 }
125
126 public boolean readBoolean() throws IOException {
127 return ((Boolean)peekCallback().readFromStream()).booleanValue();
128 }
129
130 public byte readByte() throws IOException {
131 return ((Byte)peekCallback().readFromStream()).byteValue();
132 }
133
134 public int readUnsignedByte() throws IOException {
135 int b = ((Byte)peekCallback().readFromStream()).byteValue();
136 if (b < 0) {
137 b += Byte.MAX_VALUE;
138 }
139 return b;
140 }
141
142 public int readInt() throws IOException {
143 return ((Integer)peekCallback().readFromStream()).intValue();
144 }
145
146 public char readChar() throws IOException {
147 return ((Character)peekCallback().readFromStream()).charValue();
148 }
149
150 public float readFloat() throws IOException {
151 return ((Float)peekCallback().readFromStream()).floatValue();
152 }
153
154 public double readDouble() throws IOException {
155 return ((Double)peekCallback().readFromStream()).doubleValue();
156 }
157
158 public long readLong() throws IOException {
159 return ((Long)peekCallback().readFromStream()).longValue();
160 }
161
162 public short readShort() throws IOException {
163 return ((Short)peekCallback().readFromStream()).shortValue();
164 }
165
166 public int readUnsignedShort() throws IOException {
167 int b = ((Short)peekCallback().readFromStream()).shortValue();
168 if (b < 0) {
169 b += Short.MAX_VALUE;
170 }
171 return b;
172 }
173
174 public String readUTF() throws IOException {
175 return (String)peekCallback().readFromStream();
176 }
177
178 public void readFully(byte[] buf) throws IOException {
179 readFully(buf, 0, buf.length);
180 }
181
182 public void readFully(byte[] buf, int off, int len) throws IOException {
183 byte[] b = (byte[])peekCallback().readFromStream();
184 System.arraycopy(b, 0, buf, off, len);
185 }
186
187 public int read() throws IOException {
188 return readUnsignedByte();
189 }
190
191 public int read(byte[] buf, int off, int len) throws IOException {
192 byte[] b = (byte[])peekCallback().readFromStream();
193 if (b.length != len) {
194 throw new StreamCorruptedException("Expected " + len + " bytes from stream, got " + b.length);
195 }
196 System.arraycopy(b, 0, buf, off, len);
197 return len;
198 }
199
200 public int read(byte b[]) throws IOException {
201 return read(b, 0, b.length);
202 }
203
204 public GetField readFields() throws IOException {
205 return new CustomGetField(peekCallback().readFieldsFromStream());
206 }
207
208 private class CustomGetField extends GetField {
209
210 private Map fields;
211
212 public CustomGetField(Map fields) {
213 this.fields = fields;
214 }
215
216 public ObjectStreamClass getObjectStreamClass() {
217 throw new UnsupportedOperationException();
218 }
219
220 private Object get(String name) {
221 return fields.get(name);
222 }
223
224 public boolean defaulted(String name) {
225 return !fields.containsKey(name);
226 }
227
228 public byte get(String name, byte val) {
229 return defaulted(name) ? val : ((Byte)get(name)).byteValue();
230 }
231
232 public char get(String name, char val) {
233 return defaulted(name) ? val : ((Character)get(name)).charValue();
234 }
235
236 public double get(String name, double val) {
237 return defaulted(name) ? val : ((Double)get(name)).doubleValue();
238 }
239
240 public float get(String name, float val) {
241 return defaulted(name) ? val : ((Float)get(name)).floatValue();
242 }
243
244 public int get(String name, int val) {
245 return defaulted(name) ? val : ((Integer)get(name)).intValue();
246 }
247
248 public long get(String name, long val) {
249 return defaulted(name) ? val : ((Long)get(name)).longValue();
250 }
251
252 public short get(String name, short val) {
253 return defaulted(name) ? val : ((Short)get(name)).shortValue();
254 }
255
256 public boolean get(String name, boolean val) {
257 return defaulted(name) ? val : ((Boolean)get(name)).booleanValue();
258 }
259
260 public Object get(String name, Object val) {
261 return defaulted(name) ? val : get(name);
262 }
263
264 }
265
266 public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException, InvalidObjectException {
267 peekCallback().registerValidation(validation, priority);
268 }
269
270 public void close() throws IOException {
271 peekCallback().close();
272 }
273
274 /****** Unsupported methods ******/
275
276 public int available() {
277 throw new UnsupportedOperationException();
278 }
279
280 public String readLine() {
281 throw new UnsupportedOperationException();
282 }
283
284 public int skipBytes(int len) {
285 throw new UnsupportedOperationException();
286 }
287
288 public long skip(long n) {
289 throw new UnsupportedOperationException();
290 }
291
292 public void mark(int readlimit) {
293 throw new UnsupportedOperationException();
294 }
295
296 public void reset() {
297 throw new UnsupportedOperationException();
298 }
299
300 public boolean markSupported() {
301 return false;
302 }
303
304 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 23. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.io.IOException;
14 import java.io.ObjectOutput;
15 import java.io.ObjectOutputStream;
16 import java.util.Map;
17
18 import com.thoughtworks.xstream.converters.ConversionException;
19 import com.thoughtworks.xstream.converters.DataHolder;
20
21 public class CustomObjectOutputStream extends ObjectOutputStream {
22
23 private FastStack callbacks = new FastStack(1);
24 private FastStack customFields = new FastStack(1);
25
26 private static final String DATA_HOLDER_KEY = CustomObjectOutputStream.class.getName();
27
28 public static synchronized CustomObjectOutputStream getInstance(DataHolder whereFrom, StreamCallback callback) {
29 try {
30 CustomObjectOutputStream result = (CustomObjectOutputStream) whereFrom.get(DATA_HOLDER_KEY);
31 if (result == null) {
32 result = new CustomObjectOutputStream(callback);
33 whereFrom.put(DATA_HOLDER_KEY, result);
34 } else {
35 result.pushCallback(callback);
36 }
37 return result;
38 } catch (IOException e) {
39 throw new ConversionException("Cannot create CustomObjectStream", e);
40 }
41 }
42
43 public static interface StreamCallback {
44 void writeToStream(Object object) throws IOException;
45 void writeFieldsToStream(Map fields) throws IOException;
46 void defaultWriteObject() throws IOException;
47 void flush() throws IOException;
48 void close() throws IOException;
49 }
50
51 /**
52 * Warning, this object is expensive to create (due to functionality inherited from superclass).
53 * Use the static fetch() method instead, wherever possible.
54 *
55 * @see #getInstance(com.thoughtworks.xstream.converters.DataHolder, com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback)
56 */
57 public CustomObjectOutputStream(StreamCallback callback) throws IOException, SecurityException {
58 this.callbacks.push(callback);
59 }
60
61 /**
62 * Allows the CustomObjectOutputStream (which is expensive to create) to be reused.
63 */
64 public void pushCallback(StreamCallback callback) {
65 this.callbacks.push(callback);
66 }
67
68 public StreamCallback popCallback(){
69 return (StreamCallback) this.callbacks.pop();
70 }
71
72 public StreamCallback peekCallback(){
73 return (StreamCallback) this.callbacks.peek();
74 }
75
76 /*** Methods to delegate to callback ***/
77
78 public void defaultWriteObject() throws IOException {
79 peekCallback().defaultWriteObject();
80 }
81
82 protected void writeObjectOverride(Object obj) throws IOException {
83 peekCallback().writeToStream(obj);
84 }
85
86 public void writeBoolean(boolean val) throws IOException {
87 peekCallback().writeToStream(val ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly
88 }
89
90 public void writeByte(int val) throws IOException {
91 peekCallback().writeToStream(new Byte((byte) val));
92 }
93
94 public void writeInt(int val) throws IOException {
95 peekCallback().writeToStream(new Integer(val));
96 }
97
98 public void writeChar(int val) throws IOException {
99 peekCallback().writeToStream(new Character((char)val));
100 }
101
102 public void writeDouble(double val) throws IOException {
103 peekCallback().writeToStream(new Double(val));
104 }
105
106 public void writeFloat(float val) throws IOException {
107 peekCallback().writeToStream(new Float(val));
108 }
109
110 public void writeLong(long val) throws IOException {
111 peekCallback().writeToStream(new Long(val));
112 }
113
114 public void writeShort(int val) throws IOException {
115 peekCallback().writeToStream(new Short((short) val));
116 }
117
118 public void write(byte[] buf) throws IOException {
119 peekCallback().writeToStream(buf);
120 }
121
122 public void writeChars(String str) throws IOException {
123 peekCallback().writeToStream(str.toCharArray());
124 }
125
126 public void writeUTF(String str) throws IOException {
127 peekCallback().writeToStream(str);
128 }
129
130 public void write(int val) throws IOException {
131 peekCallback().writeToStream(new Byte((byte) val));
132 }
133
134 public void write(byte[] buf, int off, int len) throws IOException {
135 byte[] b = new byte[len];
136 System.arraycopy(buf, off, b, 0, len);
137 peekCallback().writeToStream(b);
138 }
139
140 public void flush() throws IOException {
141 peekCallback().flush();
142 }
143
144 public void close() throws IOException {
145 peekCallback().close();
146 }
147
148 public PutField putFields() {
149 CustomPutField result = new CustomPutField();
150 customFields.push(result);
151 return result;
152 }
153
154 public void writeFields() throws IOException {
155 CustomPutField customPutField = (CustomPutField) customFields.pop();
156 peekCallback().writeFieldsToStream(customPutField.asMap());
157 }
158
159 private class CustomPutField extends PutField {
160
161 private final Map fields = new OrderRetainingMap();
162
163 public Map asMap() {
164 return fields;
165 }
166
167 public void write(ObjectOutput out) throws IOException {
168 peekCallback().writeToStream(asMap());
169 }
170
171 public void put(String name, Object val) {
172 fields.put(name, val);
173 }
174
175 public void put(String name, byte val) {
176 put(name, new Byte(val));
177 }
178
179 public void put(String name, char val) {
180 put(name, new Character(val));
181 }
182
183 public void put(String name, double val) {
184 put(name, new Double(val));
185 }
186
187 public void put(String name, float val) {
188 put(name, new Float(val));
189 }
190
191 public void put(String name, int val) {
192 put(name, new Integer(val));
193 }
194
195 public void put(String name, long val) {
196 put(name, new Long(val));
197 }
198
199 public void put(String name, short val) {
200 put(name, new Short(val));
201 }
202
203 public void put(String name, boolean val) {
204 put(name, val ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly
205 }
206
207 }
208
209 /****** Unsupported methods ******/
210
211 public void reset() {
212 throw new UnsupportedOperationException();
213 }
214
215 public void useProtocolVersion(int version) {
216 throw new UnsupportedOperationException();
217 }
218
219 public void writeBytes(String str) {
220 throw new UnsupportedOperationException();
221 }
222
223 public void writeUnshared(Object obj) {
224 throw new UnsupportedOperationException();
225 }
226
227 }
0 /*
1 * Copyright (c) 2007, 2009, 2010, 2011, 2012, 2013 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 30. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.ArrayList;
15 import java.util.Arrays;
16 import java.util.BitSet;
17 import java.util.Comparator;
18 import java.util.List;
19
20 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
21
22
23 /**
24 * A dependency injection factory.
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.2.2
28 */
29 public class DependencyInjectionFactory {
30
31 /**
32 * Create an instance with dependency injection. The given dependencies are used to match the parameters of the
33 * constructors of the type. Constructors with most parameters are examined first. A parameter type sequence
34 * matching the sequence of the dependencies' types match first. Otherwise all the types of the dependencies must
35 * match one of the the parameters although no dependency is used twice. Use a {@link TypedNull} instance to inject
36 * <code>null</code> as parameter.
37 *
38 * @param type the type to create an instance of
39 * @param dependencies the possible dependencies
40 * @return the instantiated object
41 * @throws ObjectAccessException if no instance can be generated
42 * @throws IllegalArgumentException if more than 63 dependencies have been provided
43 * @since 1.2.2
44 */
45 public static Object newInstance(final Class type, final Object[] dependencies) {
46 return newInstance(type, dependencies, null);
47 }
48
49 /**
50 * Create an instance with dependency injection. The given dependencies are used to match the parameters of the
51 * constructors of the type. Constructors with most parameters are examined first. A parameter type sequence
52 * matching the sequence of the dependencies' types match first. Otherwise all the types of the dependencies must
53 * match one of the the parameters although no dependency is used twice. Use a {@link TypedNull} instance to inject
54 * <code>null</code> as parameter.
55 *
56 * @param type the type to create an instance of
57 * @param dependencies the possible dependencies
58 * @param usedDependencies bit mask set by the method for all used dependencies (may be <code>null</code>)
59 * @return the instantiated object
60 * @throws ObjectAccessException if no instance can be generated
61 * @throws IllegalArgumentException if more than 63 dependencies have been provided
62 * @since 1.4
63 */
64 public static Object newInstance(final Class type, final Object[] dependencies, final BitSet usedDependencies) {
65 if (dependencies != null && dependencies.length > 63) {
66 throw new IllegalArgumentException("More than 63 arguments are not supported");
67 }
68 Constructor bestMatchingCtor = null;
69 final ArrayList matchingDependencies = new ArrayList();
70 List possibleMatchingDependencies = null;
71 long usedDeps = 0;
72 long possibleUsedDeps = 0;
73
74 if (dependencies != null && dependencies.length > 0) {
75 // sort available ctors according their arity
76 final Constructor[] ctors = type.getConstructors();
77 if (ctors.length > 1) {
78 Arrays.sort(ctors, new Comparator() {
79 public int compare(final Object o1, final Object o2) {
80 return ((Constructor)o2).getParameterTypes().length
81 - ((Constructor)o1).getParameterTypes().length;
82 }
83 });
84 }
85
86 final TypedValue[] typedDependencies = new TypedValue[dependencies.length];
87 for (int i = 0; i < dependencies.length; i++ ) {
88 Object dependency = dependencies[i];
89 Class depType = dependency.getClass();
90 if (depType.isPrimitive()) {
91 depType = Primitives.box(depType);
92 } else if (depType == TypedNull.class) {
93 depType = ((TypedNull)dependency).getType();
94 dependency = null;
95 }
96
97 typedDependencies[i] = new TypedValue(depType, dependency);
98 }
99
100 Constructor possibleCtor = null;
101 int arity = Integer.MAX_VALUE;
102 for (int i = 0; bestMatchingCtor == null && i < ctors.length; i++ ) {
103 final Constructor constructor = ctors[i];
104 final Class[] parameterTypes = constructor.getParameterTypes();
105 if (parameterTypes.length > dependencies.length) {
106 continue;
107 } else if (parameterTypes.length == 0) {
108 if (possibleCtor == null) {
109 bestMatchingCtor = constructor;
110 }
111 break;
112 }
113 if (arity > parameterTypes.length) {
114 if (possibleCtor != null) {
115 continue;
116 }
117 arity = parameterTypes.length;
118 }
119
120 for (int j = 0; j < parameterTypes.length; j++ ) {
121 if (parameterTypes[j].isPrimitive()) {
122 parameterTypes[j] = Primitives.box(parameterTypes[j]);
123 }
124 }
125
126 // first approach: test the ctor params against the dependencies in the sequence
127 // of the parameter declaration
128 matchingDependencies.clear();
129 usedDeps = 0;
130 for (int j = 0, k = 0; j < parameterTypes.length
131 && parameterTypes.length + k - j <= typedDependencies.length; k++ ) {
132 if (parameterTypes[j].isAssignableFrom(typedDependencies[k].type)) {
133 matchingDependencies.add(typedDependencies[k].value);
134 usedDeps |= 1L << k;
135 if ( ++j == parameterTypes.length) {
136 bestMatchingCtor = constructor;
137 break;
138 }
139 }
140 }
141
142 if (bestMatchingCtor == null) {
143 boolean possible = true; // assumption
144
145 // try to match all dependencies in the sequence of the parameter
146 // declaration
147 final TypedValue[] deps = new TypedValue[typedDependencies.length];
148 System.arraycopy(typedDependencies, 0, deps, 0, deps.length);
149 matchingDependencies.clear();
150 usedDeps = 0;
151 for (int j = 0; j < parameterTypes.length; j++ ) {
152 int assignable = -1;
153 for (int k = 0; k < deps.length; k++ ) {
154 if (deps[k] == null) {
155 continue;
156 }
157 if (deps[k].type == parameterTypes[j]) {
158 assignable = k;
159 // optimal match
160 break;
161 } else if (parameterTypes[j].isAssignableFrom(deps[k].type)) {
162 // use most specific type
163 if (assignable < 0
164 || (deps[assignable].type != deps[k].type && deps[assignable].type
165 .isAssignableFrom(deps[k].type))) {
166 assignable = k;
167 }
168 }
169 }
170
171 if (assignable >= 0) {
172 matchingDependencies.add(deps[assignable].value);
173 usedDeps |= 1L << assignable;
174 deps[assignable] = null; // do not match same dep twice
175 } else {
176 possible = false;
177 break;
178 }
179 }
180
181 if (possible) {
182 // the smaller the value, the smaller the indices in the deps array
183 if (possibleCtor != null && usedDeps >= possibleUsedDeps) {
184 continue;
185 }
186 possibleCtor = constructor;
187 possibleMatchingDependencies = (List)matchingDependencies.clone();
188 possibleUsedDeps = usedDeps;
189 }
190 }
191 }
192
193 if (bestMatchingCtor == null) {
194 if (possibleCtor == null) {
195 usedDeps = 0;
196 throw new ObjectAccessException("Cannot construct "
197 + type.getName()
198 + ", none of the dependencies match any constructor's parameters");
199 } else {
200 bestMatchingCtor = possibleCtor;
201 matchingDependencies.clear();
202 matchingDependencies.addAll(possibleMatchingDependencies);
203 usedDeps = possibleUsedDeps;
204 }
205 }
206 }
207
208 try {
209 final Object instance;
210 if (bestMatchingCtor == null) {
211 instance = type.newInstance();
212 } else {
213 instance = bestMatchingCtor.newInstance(matchingDependencies.toArray());
214 }
215 if (usedDependencies != null) {
216 usedDependencies.clear();
217 int i = 0;
218 for(long l = 1; l < usedDeps; l <<= 1, ++i) {
219 if ((usedDeps & l) > 0) {
220 usedDependencies.set(i);
221 }
222 }
223 }
224 return instance;
225 } catch (final InstantiationException e) {
226 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
227 } catch (final IllegalAccessException e) {
228 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
229 } catch (final InvocationTargetException e) {
230 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
231 } catch (final SecurityException e) {
232 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
233 } catch (final ExceptionInInitializerError e) {
234 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
235 }
236 }
237
238 private static class TypedValue {
239 final Class type;
240 final Object value;
241
242 public TypedValue(final Class type, final Object value) {
243 super();
244 this.type = type;
245 this.value = value;
246 }
247
248 public String toString()
249 {
250 return type.getName() + ":" + value;
251 }
252 }
253
254 }
0 /*
1 * Copyright (C) 2008, 2010 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 13. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 public final class FastField {
13 private final String name;
14 private final String declaringClass;
15
16 public FastField(String definedIn, String name) {
17 this.name = name;
18 this.declaringClass = definedIn;
19 }
20
21 public FastField(Class definedIn, String name) {
22 this(definedIn == null ? null : definedIn.getName(), name);
23 }
24
25 public String getName() {
26 return this.name;
27 }
28
29 public String getDeclaringClass() {
30 return this.declaringClass;
31 }
32
33 public boolean equals(Object obj) {
34 if (this == obj) {
35 return true;
36 }
37 if (obj == null) {
38 return false;
39 }
40 if (obj instanceof FastField) {
41 final FastField field = (FastField)obj;
42 if ((declaringClass == null && field.declaringClass != null)
43 || (declaringClass != null && field.declaringClass == null)) {
44 return false;
45 }
46 return name.equals(field.getName())
47 && (declaringClass == null || declaringClass.equals(field.getDeclaringClass()));
48 }
49 return false;
50 }
51
52 public int hashCode() {
53 return name.hashCode() ^ (declaringClass == null ? 0 : declaringClass.hashCode());
54 }
55
56 public String toString() {
57 return (declaringClass == null ? "" : declaringClass + ".") + name;
58 }
59 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 /**
14 * An array-based stack implementation.
15 *
16 * @author Joe Walnes
17 * @author J&ouml;rg Schaible
18 */
19 public final class FastStack {
20
21 private Object[] stack;
22 private int pointer;
23
24 public FastStack(int initialCapacity) {
25 stack = new Object[initialCapacity];
26 }
27
28 public Object push(Object value) {
29 if (pointer + 1 >= stack.length) {
30 resizeStack(stack.length * 2);
31 }
32 stack[pointer++] = value;
33 return value;
34 }
35
36 public void popSilently() {
37 stack[--pointer] = null;
38 }
39
40 public Object pop() {
41 final Object result = stack[--pointer];
42 stack[pointer] = null;
43 return result;
44 }
45
46 public Object peek() {
47 return pointer == 0 ? null : stack[pointer - 1];
48 }
49
50 public Object replace(Object value) {
51 final Object result = stack[pointer - 1];
52 stack[pointer - 1] = value;
53 return result;
54 }
55
56 public void replaceSilently(Object value) {
57 stack[pointer - 1] = value;
58 }
59
60 public int size() {
61 return pointer;
62 }
63
64 public boolean hasStuff() {
65 return pointer > 0;
66 }
67
68 public Object get(int i) {
69 return stack[i];
70 }
71
72 private void resizeStack(int newCapacity) {
73 Object[] newStack = new Object[newCapacity];
74 System.arraycopy(stack, 0, newStack, 0, Math.min(pointer, newCapacity));
75 stack = newStack;
76 }
77
78 public String toString() {
79 StringBuffer result = new StringBuffer("[");
80 for (int i = 0; i < pointer; i++) {
81 if (i > 0) {
82 result.append(", ");
83 }
84 result.append(stack[i]);
85 }
86 result.append(']');
87 return result.toString();
88 }
89 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 06. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.lang.reflect.Field;
14 import java.lang.reflect.Modifier;
15
16 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
17
18 /**
19 * Slightly nicer way to find, get and set fields in classes. Wraps standard java.lang.reflect.Field calls but wraps
20 * wraps exception in XStreamExceptions.
21 *
22 * @author Joe Walnes
23 * @author J&ouml;rg Schaible
24 */
25 public class Fields {
26 public static Field locate(Class definedIn, Class fieldType, boolean isStatic) {
27 Field field = null;
28 try {
29 Field[] fields = definedIn.getDeclaredFields();
30 for(int i = 0; i < fields.length; ++i) {
31 if (Modifier.isStatic(fields[i].getModifiers()) == isStatic) {
32 if (fieldType.isAssignableFrom(fields[i].getType())) {
33 field = fields[i];
34 }
35 }
36 }
37 if (field != null && !field.isAccessible()) {
38 field.setAccessible(true);
39 }
40 } catch (SecurityException e) {
41 // active SecurityManager
42 } catch (NoClassDefFoundError e) {
43 // restricted type in GAE
44 }
45 return field;
46 }
47
48 public static Field find(Class type, String name) {
49 try {
50 Field result = type.getDeclaredField(name);
51 if (!result.isAccessible()) {
52 result.setAccessible(true);
53 }
54 return result;
55 } catch (NoSuchFieldException e) {
56 throw new IllegalArgumentException("Could not access " + type.getName() + "." + name + " field: " + e.getMessage());
57 } catch (NoClassDefFoundError e) {
58 throw new ObjectAccessException("Could not access " + type.getName() + "." + name + " field: " + e.getMessage());
59 }
60 }
61
62 public static void write(Field field, Object instance, Object value) {
63 try {
64 field.set(instance, value);
65 } catch (IllegalAccessException e) {
66 throw new ObjectAccessException("Could not write " + field.getType().getName() + "." + field.getName() + " field", e);
67 } catch (NoClassDefFoundError e) {
68 throw new ObjectAccessException("Could not write " + field.getType().getName() + "." + field.getName() + " field", e);
69 }
70 }
71
72 public static Object read(Field field, Object instance) {
73 try {
74 return field.get(instance);
75 } catch (IllegalAccessException e) {
76 throw new ObjectAccessException("Could not read " + field.getType().getName() + "." + field.getName() + " field", e);
77 } catch (NoClassDefFoundError e) {
78 throw new ObjectAccessException("Could not read " + field.getType().getName() + "." + field.getName() + " field", e);
79 }
80 }
81 }
0 /*
1 * Copyright (C) 2008 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 09. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
13 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
14 import com.thoughtworks.xstream.mapper.Mapper;
15
16 /**
17 * Helper methods for {@link HierarchicalStreamReader} and {@link HierarchicalStreamWriter}.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.3.1
21 */
22 public class HierarchicalStreams {
23
24 public static Class readClassType(HierarchicalStreamReader reader, Mapper mapper) {
25 String classAttribute = readClassAttribute(reader, mapper);
26 Class type;
27 if (classAttribute == null) {
28 type = mapper.realClass(reader.getNodeName());
29 } else {
30 type = mapper.realClass(classAttribute);
31 }
32 return type;
33 }
34
35 public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) {
36 String attributeName = mapper.aliasForSystemAttribute("resolves-to");
37 String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName);
38 if (classAttribute == null) {
39 attributeName = mapper.aliasForSystemAttribute("class");
40 if (attributeName != null) {
41 classAttribute = reader.getAttribute(attributeName);
42 }
43 }
44 return classAttribute;
45 }
46
47 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010 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 09. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.lang.ref.ReferenceQueue;
14 import java.lang.ref.WeakReference;
15 import java.util.HashMap;
16 import java.util.Map;
17
18
19 /**
20 * Store IDs against given object references.
21 * <p>
22 * Behaves similar to java.util.IdentityHashMap, but in JDK1.3 as well. Additionally the
23 * implementation keeps track of orphaned IDs by using a WeakReference to store the reference
24 * object.
25 * </p>
26 */
27 public class ObjectIdDictionary {
28
29 private final Map map = new HashMap();
30 private final ReferenceQueue queue = new ReferenceQueue();
31
32 private static interface Wrapper {
33 int hashCode();
34 boolean equals(Object obj);
35 String toString();
36 Object get();
37 }
38
39 private static class IdWrapper implements Wrapper {
40
41 private final Object obj;
42 private final int hashCode;
43
44 public IdWrapper(Object obj) {
45 hashCode = System.identityHashCode(obj);
46 this.obj = obj;
47 }
48
49 public int hashCode() {
50 return hashCode;
51 }
52
53 public boolean equals(Object other) {
54 return obj == ((Wrapper)other).get();
55 }
56
57 public String toString() {
58 return obj.toString();
59 }
60
61 public Object get() {
62 return obj;
63 }
64 }
65
66 private class WeakIdWrapper extends WeakReference implements Wrapper {
67
68 private final int hashCode;
69
70 public WeakIdWrapper(Object obj) {
71 super(obj, queue);
72 hashCode = System.identityHashCode(obj);
73 }
74
75 public int hashCode() {
76 return hashCode;
77 }
78
79 public boolean equals(Object other) {
80 return get() == ((Wrapper)other).get();
81 }
82
83 public String toString() {
84 Object obj = get();
85 return obj == null ? "(null)" : obj.toString();
86 }
87 }
88
89 public void associateId(Object obj, Object id) {
90 map.put(new WeakIdWrapper(obj), id);
91 cleanup();
92 }
93
94 public Object lookupId(Object obj) {
95 Object id = map.get(new IdWrapper(obj));
96 return id;
97 }
98
99 public boolean containsId(Object item) {
100 boolean b = map.containsKey(new IdWrapper(item));
101 return b;
102 }
103
104 public void removeId(Object item) {
105 map.remove(new IdWrapper(item));
106 cleanup();
107 }
108
109 public int size() {
110 cleanup();
111 return map.size();
112 }
113
114 private void cleanup() {
115 WeakIdWrapper wrapper;
116 while ((wrapper = (WeakIdWrapper)queue.poll()) != null)
117 {
118 map.remove(wrapper);
119 }
120 }
121 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013, 2014 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 06. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23
24 /**
25 * @deprecated As of 1.4.8 use {@link java.util.LinkedHashMap}
26 */
27 public class OrderRetainingMap extends HashMap {
28
29 private ArraySet keyOrder = new ArraySet();
30 private List valueOrder = new ArrayList();
31
32 public OrderRetainingMap() {
33 super();
34 }
35
36 public OrderRetainingMap(Map m) {
37 super();
38 putAll(m);
39 }
40
41 public void putAll(Map m) {
42 for(Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
43 Map.Entry entry = (Map.Entry)iter.next();
44 put(entry.getKey(), entry.getValue());
45 }
46 }
47
48 public Object put(Object key, Object value) {
49 int idx = keyOrder.lastIndexOf(key);
50 if (idx < 0) {
51 keyOrder.add(key);
52 valueOrder.add(value);
53 } else {
54 valueOrder.set(idx, value);
55 }
56 return super.put(key, value);
57 }
58
59 public Object remove(Object key) {
60 int idx = keyOrder.lastIndexOf(key);
61 if (idx != 0) {
62 keyOrder.remove(idx);
63 valueOrder.remove(idx);
64 }
65 return super.remove(key);
66 }
67
68 public void clear() {
69 keyOrder.clear();
70 valueOrder.clear();
71 super.clear();
72 }
73
74 public Collection values() {
75 return Collections.unmodifiableList(valueOrder);
76 }
77
78 public Set keySet() {
79 return Collections.unmodifiableSet(keyOrder);
80 }
81
82 public Set entrySet() {
83 Map.Entry[] entries = new Map.Entry[size()];
84 for (Iterator iter = super.entrySet().iterator(); iter.hasNext();) {
85 Map.Entry entry = (Map.Entry)iter.next();
86 entries[keyOrder.indexOf(entry.getKey())] = entry;
87 }
88 Set set = new ArraySet();
89 set.addAll(Arrays.asList(entries));
90 return Collections.unmodifiableSet(set);
91 }
92
93 private static class ArraySet extends ArrayList implements Set {
94 }
95 }
0 /*
1 * Copyright (c) 2007 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 10. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 /**
13 * A simple pool implementation.
14 *
15 * @author J&ouml;rg Schaible
16 * @author Joe Walnes
17 */
18 public class Pool {
19
20 public interface Factory {
21 public Object newInstance();
22 }
23
24 private final int initialPoolSize;
25 private final int maxPoolSize;
26 private final Factory factory;
27 private transient Object[] pool;
28 private transient int nextAvailable;
29 private transient Object mutex = new Object();
30
31 public Pool(int initialPoolSize, int maxPoolSize, Factory factory) {
32 this.initialPoolSize = initialPoolSize;
33 this.maxPoolSize = maxPoolSize;
34 this.factory = factory;
35 }
36
37 public Object fetchFromPool() {
38 Object result;
39 synchronized (mutex) {
40 if (pool == null) {
41 pool = new Object[maxPoolSize];
42 for (nextAvailable = initialPoolSize; nextAvailable > 0; ) {
43 putInPool(factory.newInstance());
44 }
45 }
46 while (nextAvailable == maxPoolSize) {
47 try {
48 mutex.wait();
49 } catch (InterruptedException e) {
50 throw new RuntimeException("Interrupted whilst waiting " +
51 "for a free item in the pool : " + e.getMessage());
52 }
53 }
54 result = pool[nextAvailable++];
55 if (result == null) {
56 result = factory.newInstance();
57 putInPool(result);
58 ++nextAvailable;
59 }
60 }
61 return result;
62 }
63
64 protected void putInPool(Object object) {
65 synchronized (mutex) {
66 pool[--nextAvailable] = object;
67 mutex.notify();
68 }
69 }
70
71 private Object readResolve() {
72 mutex = new Object();
73 return this;
74 }
75 }
0 /*
1 * Copyright (C) 2006, 2007, 2010 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 12.10.2010 by Joerg Schaible, extracted from TreeMapConverter.
5 */
6 package com.thoughtworks.xstream.core.util;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Comparator;
11 import java.util.Iterator;
12 import java.util.Map;
13 import java.util.Set;
14 import java.util.SortedMap;
15
16 /**
17 * @author J&ouml;rg Schaible
18 */
19 public class PresortedMap implements SortedMap {
20
21 private static class ArraySet extends ArrayList implements Set {
22 }
23
24 private final PresortedMap.ArraySet set;
25 private final Comparator comparator;
26
27 public PresortedMap() {
28 this(null, new ArraySet());
29 }
30
31 public PresortedMap(Comparator comparator) {
32 this(comparator, new ArraySet());
33 }
34
35 private PresortedMap(Comparator comparator, PresortedMap.ArraySet set) {
36 this.comparator = comparator != null ? comparator : new ArraySetComparator(set);
37 this.set = set;
38 }
39
40 public Comparator comparator() {
41 return comparator;
42 }
43
44 public Set entrySet() {
45 return set;
46 }
47
48 public Object firstKey() {
49 throw new UnsupportedOperationException();
50 }
51
52 public SortedMap headMap(Object toKey) {
53 throw new UnsupportedOperationException();
54 }
55
56 public Set keySet() {
57 Set keySet = new ArraySet();
58 for (final Iterator iterator = set.iterator(); iterator.hasNext();) {
59 final Entry entry = (Entry)iterator.next();
60 keySet.add(entry.getKey());
61 }
62 return keySet;
63 }
64
65 public Object lastKey() {
66 throw new UnsupportedOperationException();
67 }
68
69 public SortedMap subMap(Object fromKey, Object toKey) {
70 throw new UnsupportedOperationException();
71 }
72
73 public SortedMap tailMap(Object fromKey) {
74 throw new UnsupportedOperationException();
75 }
76
77 public Collection values() {
78 Set values = new ArraySet();
79 for (final Iterator iterator = set.iterator(); iterator.hasNext();) {
80 final Entry entry = (Entry)iterator.next();
81 values.add(entry.getValue());
82 }
83 return values;
84 }
85
86 public void clear() {
87 throw new UnsupportedOperationException();
88 }
89
90 public boolean containsKey(Object key) {
91 return false;
92 }
93
94 public boolean containsValue(Object value) {
95 throw new UnsupportedOperationException();
96 }
97
98 public Object get(Object key) {
99 throw new UnsupportedOperationException();
100 }
101
102 public boolean isEmpty() {
103 return set.isEmpty();
104 }
105
106 public Object put(final Object key, final Object value) {
107 set.add(new Entry(){
108
109 public Object getKey() {
110 return key;
111 }
112
113 public Object getValue() {
114 return value;
115 }
116
117 public Object setValue(Object value) {
118 throw new UnsupportedOperationException();
119 }});
120 return null;
121 }
122
123 public void putAll(Map m) {
124 for (final Iterator iter = m.entrySet().iterator(); iter.hasNext();) {
125 set.add(iter.next());
126 }
127 }
128
129 public Object remove(Object key) {
130 throw new UnsupportedOperationException();
131 }
132
133 public int size() {
134 return set.size();
135 }
136
137 private static class ArraySetComparator implements Comparator {
138
139 private final ArrayList list;
140 private Map.Entry[] array;
141
142 ArraySetComparator(ArrayList list) {
143 this.list = list;
144 }
145
146 public int compare(Object object1, Object object2) {
147 if (array == null || list.size() != array.length) {
148 Map.Entry[] a = new Map.Entry[list.size()];
149 if (array != null) {
150 System.arraycopy(array, 0, a, 0, array.length);
151 }
152 for (int i = array == null ? 0 : array.length; i < list.size(); ++i) {
153 a[i] = (Map.Entry)list.get(i);
154 }
155 array = a;
156 }
157 int idx1 = Integer.MAX_VALUE, idx2 = Integer.MAX_VALUE;
158 for(int i = 0; i < array.length && !(idx1 < Integer.MAX_VALUE && idx2 < Integer.MAX_VALUE); ++i) {
159 if (idx1 == Integer.MAX_VALUE && object1 == array[i].getKey()) {
160 idx1 = i;
161 }
162 if (idx2 == Integer.MAX_VALUE && object2 == array[i].getKey()) {
163 idx2 = i;
164 }
165 }
166 return idx1 - idx2;
167 }
168 }
169 }
0 /*
1 * Copyright (C) 2006, 2007, 2010 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 12.10.2010 by Joerg Schaible, extracted from TreeSetConverter.
5 */
6 package com.thoughtworks.xstream.core.util;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Comparator;
11 import java.util.Iterator;
12 import java.util.List;
13 import java.util.SortedSet;
14
15 /**
16 * @author J&ouml;rg Schaible
17 */
18 public class PresortedSet implements SortedSet {
19 private final List list = new ArrayList();
20 private final Comparator comparator;
21
22 public PresortedSet() {
23 this(null);
24 }
25
26 public PresortedSet(Comparator comparator) {
27 this(comparator, null);
28 }
29
30 public PresortedSet(Comparator comparator, Collection c) {
31 this.comparator = comparator;
32 if (c != null) {
33 addAll(c);
34 }
35 }
36
37 public boolean add(Object e) {
38 return this.list.add(e);
39 }
40
41 public boolean addAll(Collection c) {
42 return this.list.addAll(c);
43 }
44
45 public void clear() {
46 this.list.clear();
47 }
48
49 public boolean contains(Object o) {
50 return this.list.contains(o);
51 }
52
53 public boolean containsAll(Collection c) {
54 return this.list.containsAll(c);
55 }
56
57 public boolean equals(Object o) {
58 return this.list.equals(o);
59 }
60
61 public int hashCode() {
62 return this.list.hashCode();
63 }
64
65 public boolean isEmpty() {
66 return this.list.isEmpty();
67 }
68
69 public Iterator iterator() {
70 return this.list.iterator();
71 }
72
73 public boolean remove(Object o) {
74 return this.list.remove(o);
75 }
76
77 public boolean removeAll(Collection c) {
78 return this.list.removeAll(c);
79 }
80
81 public boolean retainAll(Collection c) {
82 return this.list.retainAll(c);
83 }
84
85 public int size() {
86 return this.list.size();
87 }
88
89 public List subList(int fromIndex, int toIndex) {
90 return this.list.subList(fromIndex, toIndex);
91 }
92
93 public Object[] toArray() {
94 return this.list.toArray();
95 }
96
97 public Object[] toArray(Object[] a) {
98 return this.list.toArray(a);
99 }
100
101 public Comparator comparator() {
102 return comparator;
103 }
104
105 public Object first() {
106 return list.isEmpty() ? null : list.get(0);
107 }
108
109 public SortedSet headSet(Object toElement) {
110 throw new UnsupportedOperationException();
111 }
112
113 public Object last() {
114 return list.isEmpty() ? null : list.get(list.size() - 1);
115 }
116
117 public SortedSet subSet(Object fromElement, Object toElement) {
118 throw new UnsupportedOperationException();
119 }
120
121 public SortedSet tailSet(Object fromElement) {
122 throw new UnsupportedOperationException();
123 }
124 }
0 /*
1 * Copyright (c) 2006, 2007, 2011 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 11. October 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 /**
16 * Utility class for primitives.
17 *
18 * @author J&ouml;rg Schaible
19 * @since 1.2.1
20 */
21 public final class Primitives {
22 private final static Map BOX = new HashMap();
23 private final static Map UNBOX = new HashMap();
24 private final static Map NAMED_PRIMITIVE = new HashMap();
25 private final static Map REPRESENTING_CHAR = new HashMap();
26
27 static {
28 final Class[][] boxing = new Class[][]{
29 { Byte.TYPE, Byte.class},
30 { Character.TYPE, Character.class},
31 { Short.TYPE, Short.class},
32 { Integer.TYPE, Integer.class},
33 { Long.TYPE, Long.class},
34 { Float.TYPE, Float.class},
35 { Double.TYPE, Double.class},
36 { Boolean.TYPE, Boolean.class},
37 { Void.TYPE, Void.class},
38 };
39 final Character[] representingChars = {
40 new Character('B'),
41 new Character('C'),
42 new Character('S'),
43 new Character('I'),
44 new Character('J'),
45 new Character('F'),
46 new Character('D'),
47 new Character('Z'),
48 null
49 };
50 for (int i = 0; i < boxing.length; i++) {
51 final Class primitiveType = boxing[i][0];
52 final Class boxedType = boxing[i][1];
53 BOX.put(primitiveType, boxedType);
54 UNBOX.put(boxedType, primitiveType);
55 NAMED_PRIMITIVE.put(primitiveType.getName(), primitiveType);
56 REPRESENTING_CHAR.put(primitiveType, representingChars[i]);
57 }
58 }
59
60 /**
61 * Get the boxed type for a primitive.
62 *
63 * @param type the primitive type
64 * @return the boxed type or null
65 */
66 static public Class box(final Class type) {
67 return (Class)BOX.get(type);
68 }
69
70 /**
71 * Get the primitive type for a boxed one.
72 *
73 * @param type the boxed type
74 * @return the primitive type or null
75 */
76 static public Class unbox(final Class type) {
77 return (Class)UNBOX.get(type);
78 }
79
80 /**
81 * Check for a boxed type.
82 *
83 * @param type the type to check
84 * @return <code>true</code> if the type is boxed
85 * @since 1.4
86 */
87 static public boolean isBoxed(final Class type) {
88 return UNBOX.containsKey(type);
89 }
90
91 /**
92 * Get the primitive type by name.
93 *
94 * @param name the name of the type
95 * @return the Java type or <code>null</code>
96 * @since 1.4
97 */
98 static public Class primitiveType(final String name) {
99 return (Class)NAMED_PRIMITIVE.get(name);
100 }
101
102 /**
103 * Get the representing character of a primitive type.
104 *
105 * @param type the primitive type
106 * @return the representing character or 0
107 * @since 1.4
108 */
109 static public char representingChar(final Class type) {
110 Character ch = (Character)REPRESENTING_CHAR.get(type);
111 return ch == null ? 0 : ch.charValue();
112 }
113 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 06. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.util.Iterator;
14 import java.util.Set;
15 import java.util.TreeSet;
16
17
18 /**
19 * List that allows items to be added with a priority that will affect the order in which they are later iterated over.
20 * Objects with a high priority will appear before objects with a low priority in the list. If two objects of the same
21 * priority are added to the list, the most recently added one will be iterated over first. Implementation uses a
22 * TreeSet, which has a guaranteed add time of O(log(n)).
23 *
24 * @author Joe Walnes
25 * @author Guilherme Silveira
26 */
27 public class PrioritizedList {
28
29 private final Set set = new TreeSet();
30
31 private int lowestPriority = Integer.MAX_VALUE;
32
33 private int lastId = 0;
34
35 public void add(Object item, int priority) {
36 if (this.lowestPriority > priority) {
37 this.lowestPriority = priority;
38 }
39 this.set.add(new PrioritizedItem(item, priority, ++lastId));
40 }
41
42 public Iterator iterator() {
43 return new PrioritizedItemIterator(this.set.iterator());
44 }
45
46 private static class PrioritizedItem implements Comparable {
47
48 final Object value;
49 final int priority;
50 final int id;
51
52 public PrioritizedItem(Object value, int priority, int id) {
53 this.value = value;
54 this.priority = priority;
55 this.id = id;
56 }
57
58 public int compareTo(Object o) {
59 PrioritizedItem other = (PrioritizedItem)o;
60 if (this.priority != other.priority) {
61 return (other.priority - this.priority);
62 }
63 return (other.id - this.id);
64 }
65
66 public boolean equals(Object obj) {
67 return this.id == ((PrioritizedItem)obj).id;
68 }
69
70 }
71
72 private static class PrioritizedItemIterator implements Iterator {
73
74 private Iterator iterator;
75
76 public PrioritizedItemIterator(Iterator iterator) {
77 this.iterator = iterator;
78 }
79
80 public void remove() {
81 // call iterator.remove()?
82 throw new UnsupportedOperationException();
83 }
84
85 public boolean hasNext() {
86 return iterator.hasNext();
87 }
88
89 public Object next() {
90 return ((PrioritizedItem)iterator.next()).value;
91 }
92
93 }
94
95 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import com.thoughtworks.xstream.io.StreamException;
14
15 import java.io.IOException;
16 import java.io.Writer;
17
18 public class QuickWriter {
19
20 private final Writer writer;
21 private char[] buffer;
22 private int pointer;
23
24 public QuickWriter(Writer writer) {
25 this(writer, 1024);
26 }
27
28 public QuickWriter(Writer writer, int bufferSize) {
29 this.writer = writer;
30 buffer = new char[bufferSize];
31 }
32
33 public void write(String str) {
34 int len = str.length();
35 if (pointer + len >= buffer.length) {
36 flush();
37 if (len > buffer.length) {
38 raw(str.toCharArray());
39 return;
40 }
41 }
42 str.getChars(0, len, buffer, pointer);
43 pointer += len;
44 }
45
46 public void write(char c) {
47 if (pointer + 1 >= buffer.length) {
48 flush();
49 if (buffer.length == 0) {
50 raw(c);
51 return;
52 }
53 }
54 buffer[pointer++] = c;
55 }
56
57 public void write(char[] c) {
58 int len = c.length;
59 if (pointer + len >= buffer.length) {
60 flush();
61 if (len > buffer.length) {
62 raw(c);
63 return;
64 }
65 }
66 System.arraycopy(c, 0, buffer, pointer, len);
67 pointer += len;
68 }
69
70 public void flush() {
71 try {
72 writer.write(buffer, 0, pointer);
73 pointer = 0;
74 writer.flush();
75 } catch (IOException e) {
76 throw new StreamException(e);
77 }
78 }
79
80 public void close() {
81 try {
82 writer.write(buffer, 0, pointer);
83 pointer = 0;
84 writer.close();
85 } catch (IOException e) {
86 throw new StreamException(e);
87 }
88 }
89
90 private void raw(char[] c) {
91 try {
92 writer.write(c);
93 writer.flush();
94 } catch (IOException e) {
95 throw new StreamException(e);
96 }
97 }
98
99 private void raw(char c) {
100 try {
101 writer.write(c);
102 writer.flush();
103 } catch (IOException e) {
104 throw new StreamException(e);
105 }
106 }
107 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 01. March 2013 by Joerg Schaible, moved from package
9 * com.thoughtworks.xstream.converters.reflection.
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.ConverterLookup;
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 * A special converter that prevents self-serialization. The serializing XStream instance
23 * adds a converter of this type to prevent self-serialization and will throw an
24 * exception instead.
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.2
28 */
29 public class SelfStreamingInstanceChecker implements Converter {
30
31 private final Object self;
32 private Converter defaultConverter;
33 private final ConverterLookup lookup;
34
35 /**
36 * @since 1.4.5
37 */
38 public SelfStreamingInstanceChecker(ConverterLookup lookup, Object xstream) {
39 this.lookup = lookup;
40 this.self = xstream;
41 }
42
43 /**
44 * @deprecated As of 1.4.5 use {@link #SelfStreamingInstanceChecker(ConverterLookup, Object)}
45 */
46 public SelfStreamingInstanceChecker(Converter defaultConverter, Object xstream) {
47 this.defaultConverter = defaultConverter;
48 this.self = xstream;
49 lookup = null;
50 }
51
52 public boolean canConvert(Class type) {
53 return type == self.getClass();
54 }
55
56 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
57 if (source == self) {
58 throw new ConversionException("Cannot marshal the XStream instance in action");
59 }
60 getConverter().marshal(source, writer, context);
61 }
62
63 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
64 return getConverter().unmarshal(reader, context);
65 }
66
67 private Converter getConverter() {
68 return defaultConverter != null ? defaultConverter : lookup.lookupConverterForType(Object.class);
69 }
70 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2014, 2015 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 12. February 2015 by Joerg Schaible, copied from c.t.x.converters.reflection.SerializationMemberInvoker.
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.io.ObjectStreamField;
16 import java.lang.reflect.Field;
17 import java.lang.reflect.InvocationTargetException;
18 import java.lang.reflect.Method;
19 import java.lang.reflect.Modifier;
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import com.thoughtworks.xstream.converters.ConversionException;
26 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
27 import com.thoughtworks.xstream.core.Caching;
28
29
30 /**
31 * Convenience wrapper to invoke special serialization methods on objects (and perform reflection caching).
32 *
33 * @author Joe Walnes
34 * @author J&ouml;rg Schaible
35 */
36 public class SerializationMembers implements Caching {
37
38 private static final Method NO_METHOD = (new Object() {
39 private void noMethod() {
40 }
41 }).getClass().getDeclaredMethods()[0];
42 private static final Object[] EMPTY_ARGS = new Object[0];
43 private static final Class[] EMPTY_CLASSES = new Class[0];
44 private static final Map NO_FIELDS = Collections.EMPTY_MAP;
45 private static final int PERSISTENT_FIELDS_MODIFIER = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;
46 private static final FastField[] OBJECT_TYPE_FIELDS = {
47 new FastField(Object.class, "readResolve"),
48 new FastField(Object.class, "writeReplace"),
49 new FastField(Object.class, "readObject"),
50 new FastField(Object.class, "writeObject")
51 };
52 private Map declaredCache = Collections.synchronizedMap(new HashMap());
53 private Map resRepCache = Collections.synchronizedMap(new HashMap());
54 private final Map fieldCache = Collections.synchronizedMap(new HashMap());
55 {
56 for(int i = 0; i < OBJECT_TYPE_FIELDS.length; ++i) {
57 declaredCache.put(OBJECT_TYPE_FIELDS[i], NO_METHOD);
58 }
59 for(int i = 0; i < 2; ++i) {
60 resRepCache.put(OBJECT_TYPE_FIELDS[i], NO_METHOD);
61 }
62 }
63
64 /**
65 * Resolves an object as native serialization does by calling readResolve(), if available.
66 */
67 public Object callReadResolve(final Object result) {
68 if (result == null) {
69 return null;
70 } else {
71 final Class resultType = result.getClass();
72 final Method readResolveMethod = getRRMethod(resultType, "readResolve");
73 if (readResolveMethod != null) {
74 try {
75 return readResolveMethod.invoke(result, EMPTY_ARGS);
76 } catch (IllegalAccessException e) {
77 throw new ObjectAccessException("Could not call "
78 + resultType.getName()
79 + ".readResolve()", e);
80 } catch (InvocationTargetException e) {
81 throw new ObjectAccessException("Could not call "
82 + resultType.getName()
83 + ".readResolve()", e.getTargetException());
84 }
85 } else {
86 return result;
87 }
88 }
89 }
90
91 public Object callWriteReplace(final Object object) {
92 if (object == null) {
93 return null;
94 } else {
95 final Class objectType = object.getClass();
96 final Method writeReplaceMethod = getRRMethod(objectType, "writeReplace");
97 if (writeReplaceMethod != null) {
98 try {
99 return writeReplaceMethod.invoke(object, EMPTY_ARGS);
100 } catch (IllegalAccessException e) {
101 throw new ObjectAccessException("Could not call "
102 + objectType.getName()
103 + ".writeReplace()", e);
104 } catch (InvocationTargetException e) {
105 throw new ObjectAccessException("Could not call "
106 + objectType.getName()
107 + ".writeReplace()", e.getTargetException());
108 }
109 } else {
110 return object;
111 }
112 }
113 }
114
115 public boolean supportsReadObject(final Class type, final boolean includeBaseClasses) {
116 return getMethod(
117 type, "readObject", new Class[]{ObjectInputStream.class}, includeBaseClasses) != null;
118 }
119
120 public void callReadObject(final Class type, final Object object, final ObjectInputStream stream) {
121 try {
122 Method readObjectMethod = getMethod(
123 type, "readObject", new Class[]{ObjectInputStream.class}, false);
124 readObjectMethod.invoke(object, new Object[]{stream});
125 } catch (IllegalAccessException e) {
126 throw new ConversionException("Could not call "
127 + object.getClass().getName()
128 + ".readObject()", e);
129 } catch (InvocationTargetException e) {
130 throw new ConversionException("Could not call "
131 + object.getClass().getName()
132 + ".readObject()", e.getTargetException());
133 }
134 }
135
136 public boolean supportsWriteObject(final Class type, final boolean includeBaseClasses) {
137 return getMethod(
138 type, "writeObject", new Class[]{ObjectOutputStream.class}, includeBaseClasses) != null;
139 }
140
141 public void callWriteObject(final Class type, final Object instance, final ObjectOutputStream stream) {
142 try {
143 Method readObjectMethod = getMethod(
144 type, "writeObject", new Class[]{ObjectOutputStream.class}, false);
145 readObjectMethod.invoke(instance, new Object[]{stream});
146 } catch (IllegalAccessException e) {
147 throw new ConversionException("Could not call "
148 + instance.getClass().getName()
149 + ".writeObject()", e);
150 } catch (InvocationTargetException e) {
151 throw new ConversionException("Could not call "
152 + instance.getClass().getName()
153 + ".writeObject()", e.getTargetException());
154 }
155 }
156
157 private Method getMethod(Class type, String name, Class[] parameterTypes,
158 boolean includeBaseclasses) {
159 Method method = getMethod(type, name, parameterTypes);
160 return method == NO_METHOD
161 || (!includeBaseclasses && !method.getDeclaringClass().equals(type))
162 ? null
163 : method;
164 }
165
166 private Method getMethod(Class type, String name, Class[] parameterTypes) {
167 if (type == null) {
168 return null;
169 }
170 FastField method = new FastField(type, name);
171 Method result = (Method)declaredCache.get(method);
172 if (result == null) {
173 try {
174 result = type.getDeclaredMethod(name, parameterTypes);
175 if (!result.isAccessible()) {
176 result.setAccessible(true);
177 }
178 } catch (NoSuchMethodException e) {
179 result = getMethod(type.getSuperclass(), name, parameterTypes);
180 }
181 declaredCache.put(method, result);
182 }
183 return result;
184 }
185
186 private Method getRRMethod(final Class type, final String name) {
187 final FastField method = new FastField(type, name);
188 Method result = (Method)resRepCache.get(method);
189 if (result == null) {
190 result = getMethod(type, name, EMPTY_CLASSES, true);
191 if (result != null && result.getDeclaringClass() != type) {
192 if ((result.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0) {
193 if ((result.getModifiers() & Modifier.PRIVATE) > 0
194 || type.getPackage() != result.getDeclaringClass().getPackage()) {
195 result = NO_METHOD;
196 }
197 }
198 } else if (result == null) {
199 result = NO_METHOD;
200 }
201 resRepCache.put(method, result);
202 }
203 return result == NO_METHOD ? null : result;
204 }
205
206 public Map getSerializablePersistentFields(final Class type) {
207 if (type == null) {
208 return null;
209 }
210 Map result = (Map)fieldCache.get(type.getName());
211 if (result == null) {
212 try {
213 final Field field = type.getDeclaredField("serialPersistentFields");
214 if ((field.getModifiers() & PERSISTENT_FIELDS_MODIFIER) == PERSISTENT_FIELDS_MODIFIER) {
215 field.setAccessible(true);
216 final ObjectStreamField[] fields = (ObjectStreamField[])field.get(null);
217 if (fields != null) {
218 result = new HashMap();
219 for (int i = 0; i < fields.length; ++i) {
220 result.put(fields[i].getName(), fields[i]);
221 }
222 }
223 }
224 } catch (final NoSuchFieldException e) {
225 } catch (final IllegalAccessException e) {
226 throw new ObjectAccessException("Cannot get " + type.getName() + ".serialPersistentFields.", e);
227 } catch (final ClassCastException e) {
228 throw new ObjectAccessException("Cannot get " + type.getName() + ".serialPersistentFields.", e);
229 }
230 if (result == null) {
231 result = NO_FIELDS;
232 }
233 fieldCache.put(type.getName(), result);
234 }
235 return result == NO_FIELDS ? null : result;
236 }
237
238 public void flushCache() {
239 declaredCache.keySet().retainAll(Arrays.asList(OBJECT_TYPE_FIELDS));
240 resRepCache.keySet().retainAll(Arrays.asList(OBJECT_TYPE_FIELDS));
241 }
242 }
0 /*
1 * Copyright (c) 2007, 2008 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 20. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
13
14 import java.beans.PropertyEditor;
15
16
17 /**
18 * Wrapper around {@link PropertyEditor} that can be called by multiple threads concurrently.
19 * <p>
20 * A PropertyEditor is not thread safe. To make best use of resources, the PropertyEditor
21 * provides a dynamically sizing pool of instances, each of which will only be called by a
22 * single thread at a time.
23 * </p>
24 * <p>
25 * The pool has a maximum capacity, to limit overhead. If all instances in the pool are in use
26 * and another is required, it shall block until one becomes available.
27 * </p>
28 *
29 * @author J&ouml;rg Schaible
30 * @since 1.3
31 */
32 public class ThreadSafePropertyEditor {
33
34 private final Class editorType;
35 private final Pool pool;
36
37 public ThreadSafePropertyEditor(Class type, int initialPoolSize, int maxPoolSize) {
38 if (!PropertyEditor.class.isAssignableFrom(type)) {
39 throw new IllegalArgumentException(type.getName()
40 + " is not a "
41 + PropertyEditor.class.getName());
42 }
43 editorType = type;
44 pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() {
45 public Object newInstance() {
46 try {
47 return editorType.newInstance();
48 } catch (InstantiationException e) {
49 throw new ObjectAccessException("Could not call default constructor of "
50 + editorType.getName(), e);
51 } catch (IllegalAccessException e) {
52 throw new ObjectAccessException("Could not call default constructor of "
53 + editorType.getName(), e);
54 }
55 }
56
57 });
58 }
59
60 public String getAsText(Object object) {
61 PropertyEditor editor = fetchFromPool();
62 try {
63 editor.setValue(object);
64 return editor.getAsText();
65 } finally {
66 pool.putInPool(editor);
67 }
68 }
69
70 public Object setAsText(String str) {
71 PropertyEditor editor = fetchFromPool();
72 try {
73 editor.setAsText(str);
74 return editor.getValue();
75 } finally {
76 pool.putInPool(editor);
77 }
78 }
79
80 private PropertyEditor fetchFromPool() {
81 PropertyEditor editor = (PropertyEditor)pool.fetchFromPool();
82 return editor;
83 }
84 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2012 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 06. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import java.text.DateFormat;
14 import java.text.ParseException;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
17 import java.util.Locale;
18 import java.util.TimeZone;
19
20 /**
21 * Wrapper around java.text.SimpleDateFormat that can
22 * be called by multiple threads concurrently.
23 * <p>SimpleDateFormat has a high overhead in creating
24 * and is not thread safe. To make best use of resources,
25 * the ThreadSafeSimpleDateFormat provides a dynamically
26 * sizing pool of instances, each of which will only
27 * be called by a single thread at a time.</p>
28 * <p>The pool has a maximum capacity, to limit overhead.
29 * If all instances in the pool are in use and another is
30 * required, it shall block until one becomes available.</p>
31 *
32 * @author Joe Walnes
33 * @author J&ouml;rg Schaible
34 */
35 public class ThreadSafeSimpleDateFormat {
36
37 private final String formatString;
38 private final Pool pool;
39 private final TimeZone timeZone;
40
41 public ThreadSafeSimpleDateFormat(
42 String format, TimeZone timeZone, int initialPoolSize, int maxPoolSize,
43 final boolean lenient) {
44 this(format, timeZone, Locale.ENGLISH, initialPoolSize, maxPoolSize, lenient);
45 }
46
47 public ThreadSafeSimpleDateFormat(
48 String format, TimeZone timeZone, final Locale locale, int initialPoolSize,
49 int maxPoolSize, final boolean lenient) {
50 formatString = format;
51 this.timeZone = timeZone;
52 pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() {
53 public Object newInstance() {
54 SimpleDateFormat dateFormat = new SimpleDateFormat(formatString, locale);
55 dateFormat.setLenient(lenient);
56 return dateFormat;
57 }
58
59 });
60 }
61
62 public String format(Date date) {
63 DateFormat format = fetchFromPool();
64 try {
65 return format.format(date);
66 } finally {
67 pool.putInPool(format);
68 }
69 }
70
71 public Date parse(String date) throws ParseException {
72 DateFormat format = fetchFromPool();
73 try {
74 return format.parse(date);
75 } finally {
76 pool.putInPool(format);
77 }
78 }
79
80 private DateFormat fetchFromPool() {
81 DateFormat format = (DateFormat)pool.fetchFromPool();
82 TimeZone tz = timeZone != null ? timeZone : TimeZone.getDefault();
83 if (!tz.equals(format.getTimeZone())) {
84 format.setTimeZone(tz);
85 }
86 return format;
87 }
88
89 public String toString() {
90 return formatString;
91 }
92 }
0 /*
1 * Copyright (c) 2007 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 30. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 /**
13 * A placeholder for a <code>null</code> value of a specific type.
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.2.2
17 */
18 public class TypedNull
19 {
20 private final Class type;
21
22 public TypedNull(Class type)
23 {
24 super();
25 this.type = type;
26 }
27
28 public Class getType()
29 {
30 return this.type;
31 }
32 }
0 /*
1 * Copyright (C) 2015 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 17. January 2015 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.core.util;
7
8 import java.util.regex.Pattern;
9
10
11 /**
12 * Helper methods for class types.
13 *
14 * @author J&ouml;rg Schaible
15 * @since 1.4.8
16 */
17 public class Types {
18 private static final Pattern lambdaPattern = Pattern.compile(".*\\$\\$Lambda\\$[0-9]+/.*");
19
20 public static final boolean isLambdaType(final Class<?> type) {
21 return type != null && type.isSynthetic() && lambdaPattern.matcher(type.getSimpleName()).matches();
22 }
23
24 }
0 /*
1 * Copyright (C) 2011, 2013, 2014 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 12. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.lang.ref.Reference;
13 import java.lang.ref.WeakReference;
14 import java.util.AbstractMap;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.Map;
20 import java.util.Set;
21 import java.util.WeakHashMap;
22
23
24 /**
25 * A HashMap implementation with weak references values and by default for the key. When the
26 * value is garbage collected, the key will also vanish from the map.
27 *
28 * @author J&ouml;rg Schaible
29 * @since 1.4
30 */
31 public class WeakCache extends AbstractMap {
32
33 private final Map map;
34
35 /**
36 * Construct a WeakCache with weak keys.
37 *
38 * <p>Note, that the internally used WeakHashMap is <b>not</b> thread-safe.</p>
39 *
40 * @param map the map to use
41 * @since 1.4
42 */
43 public WeakCache() {
44 this(new WeakHashMap());
45 }
46
47 /**
48 * Construct a WeakCache.
49 *
50 * @param map the map to use
51 * @since 1.4
52 */
53 public WeakCache(Map map) {
54 this.map = map;
55 }
56
57 public Object get(Object key) {
58 Reference reference = (Reference)map.get(key);
59 return reference != null ? reference.get() : null;
60 }
61
62 public Object put(Object key, Object value) {
63 Reference ref = (Reference)map.put(key, createReference(value));
64 return ref == null ? null : ref.get();
65 }
66
67 public Object remove(Object key) {
68 Reference ref = (Reference)map.remove(key);
69 return ref == null ? null : ref.get();
70 }
71
72 protected Reference createReference(Object value) {
73 return new WeakReference(value);
74 }
75
76 public boolean containsValue(final Object value) {
77 Boolean result = (Boolean)iterate(new Visitor() {
78
79 public Object visit(Object element) {
80 return element.equals(value) ? Boolean.TRUE : null;
81 }
82
83 }, 0);
84 return result == Boolean.TRUE;
85 }
86
87 public int size() {
88 if (map.size() == 0) {
89 return 0;
90 }
91 final int i[] = new int[1];
92 i[0] = 0;
93 iterate(new Visitor() {
94
95 public Object visit(Object element) {
96 ++i[0];
97 return null;
98 }
99
100 }, 0);
101 return i[0];
102 }
103
104 public Collection values() {
105 final Collection collection = new ArrayList();
106 if (map.size() != 0) {
107 iterate(new Visitor() {
108
109 public Object visit(Object element) {
110 collection.add(element);
111 return null;
112 }
113
114 }, 0);
115 }
116 return collection;
117 }
118
119 public Set entrySet() {
120 final Set set = new HashSet();
121 if (map.size() != 0) {
122 iterate(new Visitor() {
123
124 public Object visit(Object element) {
125 final Map.Entry entry = (Map.Entry)element;
126 set.add(new Map.Entry() {
127
128 public Object getKey() {
129 return entry.getKey();
130 }
131
132 public Object getValue() {
133 return ((Reference)entry.getValue()).get();
134 }
135
136 public Object setValue(Object value) {
137 Reference reference = (Reference)entry.setValue(createReference(value));
138 return reference != null ? reference.get() : null;
139 }
140
141 });
142 return null;
143 }
144
145 }, 2);
146 }
147 return set;
148 }
149
150 private Object iterate(Visitor visitor, int type) {
151 Object result = null;
152 for (Iterator iter = map.entrySet().iterator(); result == null && iter.hasNext();) {
153 Map.Entry entry = (Map.Entry)iter.next();
154 Reference reference = (Reference)entry.getValue();
155 Object element = reference.get();
156 if (element == null) {
157 iter.remove();
158 continue;
159 }
160 switch (type) {
161 case 0:
162 result = visitor.visit(element);
163 break;
164 case 1:
165 result = visitor.visit(entry.getKey());
166 break;
167 case 2:
168 result = visitor.visit(entry);
169 break;
170 }
171
172 }
173 return result;
174 }
175
176 private interface Visitor {
177 Object visit(Object element);
178 }
179
180 public boolean containsKey(Object key) {
181 return map.containsKey(key);
182 }
183
184 public void clear() {
185 map.clear();
186 }
187
188 public Set keySet() {
189 return map.keySet();
190 }
191
192 public boolean equals(Object o) {
193 return map.equals(o);
194 }
195
196 public int hashCode() {
197 return map.hashCode();
198 }
199
200 public String toString() {
201 return map.toString();
202 }
203 }
0 /*
1 * Copyright (C) 2007, 2008, 2010 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 13. September 2007 by Joerg Schaible.
9 */
10
11 package com.thoughtworks.xstream.core.util;
12
13 import java.io.ByteArrayOutputStream;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.InputStreamReader;
17 import java.io.PushbackInputStream;
18 import java.io.Reader;
19 import java.io.UnsupportedEncodingException;
20 import java.util.HashMap;
21 import java.util.Map;
22
23
24 /**
25 * A {@link Reader} that evaluates the XML header. It selects its encoding based on the encoding read with the XML
26 * header of the provided {@link InputStream}. The default encoding is <em>UTF-8</em> and the version is 1.0 if the
27 * stream does not contain an XML header or the attributes are not set within the header.
28 *
29 * @author J&ouml;rg Schaible
30 * @since 1.3
31 */
32 public final class XmlHeaderAwareReader extends Reader {
33
34 private final InputStreamReader reader;
35 private final double version;
36
37 private static final String KEY_ENCODING = "encoding";
38 private static final String KEY_VERSION = "version";
39
40 private static final String XML_TOKEN = "?xml";
41
42 private static final int STATE_BOM = 0;
43 private static final int STATE_START = 1;
44 private static final int STATE_AWAIT_XML_HEADER = 2;
45 private static final int STATE_ATTR_NAME = 3;
46 private static final int STATE_ATTR_VALUE = 4;
47
48 /**
49 * Constructs an XmlHeaderAwareReader.
50 *
51 * @param in the {@link InputStream}
52 * @throws UnsupportedEncodingException if the encoding is not supported
53 * @throws IOException occurred while reading the XML header
54 * @since 1.3
55 */
56 public XmlHeaderAwareReader(final InputStream in) throws UnsupportedEncodingException, IOException {
57 final PushbackInputStream[] pin = new PushbackInputStream[]{in instanceof PushbackInputStream
58 ? (PushbackInputStream)in
59 : new PushbackInputStream(in, 64)};
60 final Map header = getHeader(pin);
61 version = Double.parseDouble((String)header.get(KEY_VERSION));
62 reader = new InputStreamReader(pin[0], (String)header.get(KEY_ENCODING));
63 }
64
65 private Map getHeader(final PushbackInputStream[] in) throws IOException {
66 final Map header = new HashMap();
67 header.put(KEY_ENCODING, "utf-8");
68 header.put(KEY_VERSION, "1.0");
69
70 int state = STATE_BOM;
71 final ByteArrayOutputStream out = new ByteArrayOutputStream(64);
72 int i = 0;
73 char ch = 0;
74 char valueEnd = 0;
75 final StringBuffer name = new StringBuffer();
76 final StringBuffer value = new StringBuffer();
77 boolean escape = false;
78 while (i != -1 && (i = in[0].read()) != -1) {
79 out.write(i);
80 ch = (char)i;
81 switch (state) {
82 case STATE_BOM:
83 if ((ch == 0xEF && out.size() == 1)
84 || (ch == 0xBB && out.size() == 2)
85 || (ch == 0xBF && out.size() == 3)) {
86 if (ch == 0xBF) {
87 out.reset();
88 state = STATE_START;
89 }
90 break;
91 } else if (out.size() > 1) {
92 i = -1;
93 break;
94 } else {
95 state = STATE_START;
96 }
97 // fall through
98 case STATE_START:
99 if (!Character.isWhitespace(ch)) {
100 if (ch == '<') {
101 state = STATE_AWAIT_XML_HEADER;
102 } else {
103 i = -1;
104 }
105 }
106 break;
107 case STATE_AWAIT_XML_HEADER:
108 if (!Character.isWhitespace(ch)) {
109 name.append(Character.toLowerCase(ch));
110 if (!XML_TOKEN.startsWith(name.substring(0))) {
111 i = -1;
112 }
113 } else {
114 if (name.toString().equals(XML_TOKEN)) {
115 state = STATE_ATTR_NAME;
116 name.setLength(0);
117 } else {
118 i = -1;
119 }
120 }
121 break;
122 case STATE_ATTR_NAME:
123 if (!Character.isWhitespace(ch)) {
124 if (ch == '=') {
125 state = STATE_ATTR_VALUE;
126 } else {
127 ch = Character.toLowerCase(ch);
128 if (Character.isLetter(ch)) {
129 name.append(ch);
130 } else {
131 i = -1;
132 }
133 }
134 } else if (name.length() > 0) {
135 i = -1;
136 }
137 break;
138 case STATE_ATTR_VALUE:
139 if (valueEnd == 0) {
140 if (ch == '"' || ch == '\'') {
141 valueEnd = ch;
142 } else {
143 i = -1;
144 }
145 } else {
146 if (ch == '\\' && !escape) {
147 escape = true;
148 break;
149 }
150 if (ch == valueEnd && !escape) {
151 valueEnd = 0;
152 state = STATE_ATTR_NAME;
153 header.put(name.toString(), value.toString());
154 name.setLength(0);
155 value.setLength(0);
156 } else {
157 escape = false;
158 if (ch != '\n') {
159 value.append(ch);
160 } else {
161 i = -1;
162 }
163 }
164 }
165 break;
166 }
167 }
168
169 byte[] pushbackData = out.toByteArray();
170 for (i = pushbackData.length; i-- > 0;) {
171 final byte b = pushbackData[i];
172 try {
173 in[0].unread(b);
174 } catch (IOException ex) {
175 in[0] = new PushbackInputStream(in[0], ++i);
176 }
177 }
178 return header;
179 }
180
181 /**
182 * @see InputStreamReader#getEncoding()
183 * @since 1.3
184 */
185 public String getEncoding() {
186 return reader.getEncoding();
187 }
188
189 /**
190 * @see InputStreamReader#getEncoding()
191 * @since 1.3
192 */
193 public double getVersion() {
194 return version;
195 }
196
197 /**
198 * @see java.io.Reader#mark(int)
199 */
200 public void mark(final int readAheadLimit) throws IOException {
201 reader.mark(readAheadLimit);
202 }
203
204 /**
205 * @see java.io.Reader#markSupported()
206 */
207 public boolean markSupported() {
208 return reader.markSupported();
209 }
210
211 /**
212 * @see java.io.Reader#read()
213 */
214 public int read() throws IOException {
215 return reader.read();
216 }
217
218 /**
219 * @see java.io.Reader#read(char[], int, int)
220 */
221 public int read(final char[] cbuf, final int offset, final int length) throws IOException {
222 return reader.read(cbuf, offset, length);
223 }
224
225 /**
226 * @see java.io.Reader#read(char[])
227 */
228 public int read(final char[] cbuf) throws IOException {
229 return reader.read(cbuf);
230 }
231
232 // TODO: This is JDK 1.5
233 // public int read(final CharBuffer target) throws IOException {
234 // return reader.read(target);
235 // }
236
237 /**
238 * @see java.io.Reader#ready()
239 */
240 public boolean ready() throws IOException {
241 return reader.ready();
242 }
243
244 /**
245 * @see java.io.Reader#reset()
246 */
247 public void reset() throws IOException {
248 reader.reset();
249 }
250
251 /**
252 * @see java.io.Reader#skip(long)
253 */
254 public long skip(final long n) throws IOException {
255 return reader.skip(n);
256 }
257
258 /**
259 * @see java.io.Reader#close()
260 */
261 public void close() throws IOException {
262 reader.close();
263 }
264
265 /**
266 * @see java.lang.Object#equals(java.lang.Object)
267 */
268 public boolean equals(final Object obj) {
269 return reader.equals(obj);
270 }
271
272 /**
273 * @see java.lang.Object#hashCode()
274 */
275 public int hashCode() {
276 return reader.hashCode();
277 }
278
279 /**
280 * @see java.lang.Object#toString()
281 */
282 public String toString() {
283 return reader.toString();
284 }
285 }
0 /*
1 * Copyright (C) 2009, 2011 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 15. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io;
11
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.FileNotFoundException;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.net.URL;
18
19 import com.thoughtworks.xstream.io.naming.NameCoder;
20 import com.thoughtworks.xstream.io.naming.NoNameCoder;
21
22
23 /**
24 * Abstract base class for all HierarchicalStreamDriver implementations. Implementations of
25 * {@link HierarchicalStreamDriver} should rather be derived from this class then implementing
26 * the interface directly.
27 *
28 * @author J&ouml;rg Schaible
29 * @since 1.4
30 */
31 public abstract class AbstractDriver implements HierarchicalStreamDriver {
32
33 private NameCoder replacer;
34
35 /**
36 * Creates an AbstractDriver with a NameCoder that does nothing.
37 */
38 public AbstractDriver() {
39 this(new NoNameCoder());
40 }
41
42 /**
43 * Creates an AbstractDriver with a provided {@link NameCoder}.
44 *
45 * @param nameCoder the name coder for the target format
46 */
47 public AbstractDriver(NameCoder nameCoder) {
48 this.replacer = nameCoder;
49 }
50
51 protected NameCoder getNameCoder() {
52 return replacer;
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public HierarchicalStreamReader createReader(URL in) {
59 InputStream stream = null;
60 try {
61 stream = in.openStream();
62 } catch (IOException e) {
63 throw new StreamException(e);
64 }
65 return createReader(stream);
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 public HierarchicalStreamReader createReader(File in) {
72 try {
73 return createReader(new FileInputStream(in));
74 } catch (FileNotFoundException e) {
75 throw new StreamException(e);
76 }
77 }
78 }
0 /*
1 * Copyright (C) 2009, 2011 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 16. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io;
11
12 import com.thoughtworks.xstream.core.util.Cloneables;
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import com.thoughtworks.xstream.io.naming.NoNameCoder;
15
16
17 /**
18 * Abstract base class for all HierarchicalStreamReader implementations. Implementations of
19 * {@link HierarchicalStreamReader} should rather be derived from this class then implementing
20 * the interface directly.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public abstract class AbstractReader implements ExtendedHierarchicalStreamReader {
26
27 private NameCoder nameCoder;
28
29 /**
30 * Creates an AbstractReader with a NameCoder that does nothing.
31 *
32 * @since 1.4
33 */
34 protected AbstractReader() {
35 this(new NoNameCoder());
36 }
37
38 /**
39 * Creates an AbstractReader with a provided {@link NameCoder}.
40 *
41 * @param nameCoder the name coder used to read names from the incoming format
42 * @since 1.4
43 */
44 protected AbstractReader(NameCoder nameCoder) {
45 this.nameCoder = (NameCoder)Cloneables.cloneIfPossible(nameCoder);
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public HierarchicalStreamReader underlyingReader() {
52 return this;
53 }
54
55 /**
56 * Decode a node name from the target format.
57 *
58 * @param name the name in the target format
59 * @return the original name
60 * @since 1.4
61 */
62 public String decodeNode(String name) {
63 return nameCoder.decodeNode(name);
64 }
65
66 /**
67 * Decode an attribute name from the target format.
68 *
69 * @param name the name in the target format
70 * @return the original name
71 * @since 1.4
72 */
73 public String decodeAttribute(String name) {
74 return nameCoder.decodeAttribute(name);
75 }
76
77 /**
78 * Encode the node name again into the name of the target format. Internally used.
79 *
80 * @param name the original name
81 * @return the name in the target format
82 * @since 1.4
83 */
84 protected String encodeNode(String name) {
85 return nameCoder.encodeNode(name);
86 }
87
88 /**
89 * Encode the attribute name again into the name of the target format. Internally used.
90 *
91 * @param name the original name
92 * @return the name in the target format
93 * @since 1.4
94 */
95 protected String encodeAttribute(String name) {
96 return nameCoder.encodeAttribute(name);
97 }
98
99 public String peekNextChild() {
100 throw new UnsupportedOperationException("peekNextChild");
101 }
102 }
0 /*
1 * Copyright (C) 2009, 2011 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 17. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io;
11
12 import com.thoughtworks.xstream.core.util.Cloneables;
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import com.thoughtworks.xstream.io.naming.NoNameCoder;
15
16
17 /**
18 * Abstract base class for all HierarchicalStreamWriter implementations. Implementations of
19 * {@link HierarchicalStreamWriter} should rather be derived from this class then implementing
20 * the interface directly.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public abstract class AbstractWriter implements ExtendedHierarchicalStreamWriter {
26
27 private NameCoder nameCoder;
28
29 /**
30 * Creates an AbstractWriter with a NameCoder that does nothing.
31 *
32 * @since 1.4
33 */
34 protected AbstractWriter() {
35 this(new NoNameCoder());
36 }
37
38 /**
39 * Creates an AbstractWriter with a provided {@link NameCoder}.
40 *
41 * @param nameCoder the name coder used to write names in the target format
42 * @since 1.4
43 */
44 protected AbstractWriter(NameCoder nameCoder) {
45 this.nameCoder = (NameCoder)Cloneables.cloneIfPossible(nameCoder);
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public void startNode(String name, Class clazz) {
52 startNode(name);
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public HierarchicalStreamWriter underlyingWriter() {
59 return this;
60 }
61
62 /**
63 * Encode the node name into the name of the target format.
64 *
65 * @param name the original name
66 * @return the name in the target format
67 * @since 1.4
68 */
69 public String encodeNode(String name) {
70 return nameCoder.encodeNode(name);
71 }
72
73 /**
74 * Encode the attribute name into the name of the target format.
75 *
76 * @param name the original name
77 * @return the name in the target format
78 * @since 1.4
79 */
80 public String encodeAttribute(String name) {
81 return nameCoder.encodeAttribute(name);
82 }
83 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import java.util.Iterator;
14
15 /**
16 * Provide an iterator over the attribute names of the current node of a reader.
17 *
18 * @author Joe Walnes
19 * @deprecated As of 1.4.8, it is an internal helper class only
20 */
21 public class AttributeNameIterator implements Iterator {
22
23 private int current;
24 private final int count;
25 private final HierarchicalStreamReader reader;
26
27 public AttributeNameIterator(HierarchicalStreamReader reader) {
28 this.reader = reader;
29 count = reader.getAttributeCount();
30 }
31
32 public boolean hasNext() {
33 return current < count;
34 }
35
36 public Object next() {
37 return reader.getAttributeName(current++);
38 }
39
40 public void remove() {
41 throw new UnsupportedOperationException();
42 }
43
44 }
0 /*
1 * Copyright (C) 2011 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 13. October 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io;
11
12 /**
13 * @author J&ouml;rg Schaible
14 * @since 1.4.2
15 */
16 public interface ExtendedHierarchicalStreamReader extends HierarchicalStreamReader {
17
18 /**
19 * Peek the name of the next child. In situation where {@link #hasMoreChildren()} returns
20 * true, peek the tag name of the child.
21 *
22 * @since 1.4.2
23 */
24 String peekNextChild();
25 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 22. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io;
12
13 /**
14 * @author Paul Hammant
15 */
16 public interface ExtendedHierarchicalStreamWriter extends HierarchicalStreamWriter {
17
18 void startNode(String name, Class clazz);
19
20 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 22. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io;
12
13 public class ExtendedHierarchicalStreamWriterHelper {
14 public static void startNode(HierarchicalStreamWriter writer, String name, Class clazz) {
15 if (writer instanceof ExtendedHierarchicalStreamWriter) {
16 ((ExtendedHierarchicalStreamWriter) writer).startNode(name, clazz);
17 } else {
18 writer.startNode(name);
19 }
20 }
21 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import java.io.File;
14 import java.io.InputStream;
15 import java.io.OutputStream;
16 import java.io.Reader;
17 import java.io.Writer;
18 import java.net.URL;
19
20 /**
21 * Provides implementation of stream parsers and writers to XStream.
22 *
23 * @author Joe Walnes
24 * @author James Strachan
25 */
26 public interface HierarchicalStreamDriver {
27
28 /**
29 * Create the HierarchicalStreamReader with the stream parser reading from the IO reader.
30 *
31 * @param in the {@link Reader} with the data to parse
32 * @return the HierarchicalStreamReader
33 */
34 HierarchicalStreamReader createReader(Reader in);
35
36 /**
37 * Create the HierarchicalStreamReader with the stream parser reading from the input stream.
38 *
39 * @param in the {@link InputStream} with the data to parse
40 * @since 1.1.3
41 */
42 HierarchicalStreamReader createReader(InputStream in);
43
44 /**
45 * Create the HierarchicalStreamReader with the stream parser reading from a URL.
46 *
47 * Depending on the parser implementation, some might take the URL as SystemId to resolve
48 * additional references.
49 *
50 * @param in the {@link URL} defining the location with the data to parse
51 * @return the HierarchicalStreamReader
52 * @since 1.4
53 */
54 HierarchicalStreamReader createReader(URL in);
55
56 /**
57 * Create the HierarchicalStreamReader with the stream parser reading from a File.
58 *
59 * Depending on the parser implementation, some might take the file path as SystemId to
60 * resolve additional references.
61 *
62 * @param in the {@link URL} defining the location with the data to parse
63 * @return the HierarchicalStreamReader
64 * @since 1.4
65 */
66 HierarchicalStreamReader createReader(File in);
67
68 /**
69 * Create the HierarchicalStreamWriter with the formatted writer.
70 *
71 * @param out the {@link Writer} to receive the formatted data
72 * @return the HierarchicalStreamWriter
73 */
74 HierarchicalStreamWriter createWriter(Writer out);
75 /**
76 * Create the HierarchicalStreamWriter with the formatted writer.
77 *
78 * @param out the {@link OutputStream} to receive the formatted data
79 * @return the HierarchicalStreamWriter
80 * @since 1.1.3
81 */
82 HierarchicalStreamWriter createWriter(OutputStream out);
83
84 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import com.thoughtworks.xstream.converters.ErrorReporter;
14 import com.thoughtworks.xstream.converters.ErrorWriter;
15
16 import java.util.Iterator;
17
18 /**
19 * @author Joe Walnes
20 */
21 public interface HierarchicalStreamReader extends ErrorReporter {
22
23 /**
24 * Does the node have any more children remaining that have not yet been read?
25 */
26 boolean hasMoreChildren();
27
28 /**
29 * Select the current child as current node.
30 * A call to this function must be balanced with a call to {@link #moveUp()}.
31 */
32 void moveDown();
33
34 /**
35 * Select the parent node as current node.
36 */
37 void moveUp();
38
39 /**
40 * Get the name of the current node.
41 */
42 String getNodeName();
43
44 /**
45 * Get the value (text content) of the current node.
46 */
47 String getValue();
48
49 /**
50 * Get the value of an attribute of the current node.
51 */
52 String getAttribute(String name);
53
54 /**
55 * Get the value of an attribute of the current node, by index.
56 */
57 String getAttribute(int index);
58
59 /**
60 * Number of attributes in current node.
61 */
62 int getAttributeCount();
63
64 /**
65 * Name of attribute in current node.
66 */
67 String getAttributeName(int index);
68
69 /**
70 * Names of attributes (as Strings).
71 */
72 Iterator getAttributeNames();
73
74 /**
75 * If any errors are detected, allow the reader to add any additional information that can aid debugging
76 * (such as line numbers, XPath expressions, etc).
77 */
78 void appendErrors(ErrorWriter errorWriter);
79
80 /**
81 * Close the reader, if necessary.
82 */
83 void close();
84
85 /**
86 * Return the underlying HierarchicalStreamReader implementation.
87 *
88 * <p>If a Converter needs to access methods of a specific HierarchicalStreamReader implementation that are not
89 * defined in the HierarchicalStreamReader interface, it should call this method before casting. This is because
90 * the reader passed to the Converter is often wrapped/decorated by another implementation to provide additional
91 * functionality (such as XPath tracking).</p>
92 *
93 * <p>For example:</p>
94 * <pre>MySpecificReader mySpecificReader = (MySpecificReader)reader; <b>// INCORRECT!</b>
95 * mySpecificReader.doSomethingSpecific();</pre>
96
97 * <pre>MySpecificReader mySpecificReader = (MySpecificReader)reader.underlyingReader(); <b>// CORRECT!</b>
98 * mySpecificReader.doSomethingSpecific();</pre>
99 *
100 * <p>Implementations of HierarchicalStreamReader should return 'this', unless they are a decorator, in which case
101 * they should delegate to whatever they are wrapping.</p>
102 */
103 HierarchicalStreamReader underlyingReader();
104
105 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 /**
14 * @author Joe Walnes
15 */
16 public interface HierarchicalStreamWriter {
17
18 void startNode(String name);
19
20 void addAttribute(String name, String value);
21
22 /**
23 * Write the value (text content) of the current node.
24 */
25 void setValue(String text);
26
27 void endNode();
28
29 /**
30 * Flush the writer, if necessary.
31 */
32 void flush();
33
34 /**
35 * Close the writer, if necessary.
36 */
37 void close();
38
39 /**
40 * Return the underlying HierarchicalStreamWriter implementation.
41 *
42 * <p>If a Converter needs to access methods of a specific HierarchicalStreamWriter implementation that are not
43 * defined in the HierarchicalStreamWriter interface, it should call this method before casting. This is because
44 * the writer passed to the Converter is often wrapped/decorated by another implementation to provide additional
45 * functionality (such as XPath tracking).</p>
46 *
47 * <p>For example:</p>
48 * <pre>MySpecificWriter mySpecificWriter = (MySpecificWriter)writer; <b>// INCORRECT!</b>
49 * mySpecificWriter.doSomethingSpecific();</pre>
50
51 * <pre>MySpecificWriter mySpecificWriter = (MySpecificWriter)writer.underlyingWriter(); <b>// CORRECT!</b>
52 * mySpecificWriter.doSomethingSpecific();</pre>
53 *
54 * <p>Implementations of HierarchicalStreamWriter should return 'this', unless they are a decorator, in which case
55 * they should delegate to whatever they are wrapping.</p>
56 */
57 HierarchicalStreamWriter underlyingWriter();
58
59 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 10. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import com.thoughtworks.xstream.converters.ErrorWriter;
14
15 import java.util.Iterator;
16
17 /**
18 * Base class to make it easy to create wrappers (decorators) for HierarchicalStreamReader.
19 *
20 * @author Joe Walnes
21 */
22 public abstract class ReaderWrapper implements ExtendedHierarchicalStreamReader {
23
24 protected HierarchicalStreamReader wrapped;
25
26 protected ReaderWrapper(HierarchicalStreamReader reader) {
27 this.wrapped = reader;
28 }
29
30 public boolean hasMoreChildren() {
31 return wrapped.hasMoreChildren();
32 }
33
34 public void moveDown() {
35 wrapped.moveDown();
36 }
37
38 public void moveUp() {
39 wrapped.moveUp();
40 }
41
42 public String getNodeName() {
43 return wrapped.getNodeName();
44 }
45
46 public String getValue() {
47 return wrapped.getValue();
48 }
49
50 public String getAttribute(String name) {
51 return wrapped.getAttribute(name);
52 }
53
54 public String getAttribute(int index) {
55 return wrapped.getAttribute(index);
56 }
57
58 public int getAttributeCount() {
59 return wrapped.getAttributeCount();
60 }
61
62 public String getAttributeName(int index) {
63 return wrapped.getAttributeName(index);
64 }
65
66 public Iterator getAttributeNames() {
67 return wrapped.getAttributeNames();
68 }
69
70 public void appendErrors(ErrorWriter errorWriter) {
71 wrapped.appendErrors(errorWriter);
72 }
73
74 public void close() {
75 wrapped.close();
76 }
77
78 public String peekNextChild() {
79 if (! (wrapped instanceof ExtendedHierarchicalStreamReader)) {
80 throw new UnsupportedOperationException("peekNextChild");
81 }
82 return ((ExtendedHierarchicalStreamReader)wrapped).peekNextChild();
83 }
84
85 public HierarchicalStreamReader underlyingReader() {
86 return wrapped.underlyingReader();
87 }
88 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. March 2006 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.io;
12
13 import com.thoughtworks.xstream.core.util.FastStack;
14
15 import java.io.IOException;
16 import java.util.HashSet;
17 import java.util.Set;
18
19
20 /**
21 * An wrapper for all {@link HierarchicalStreamWriter} implementations, that keeps the state.
22 * Writing in a wrong state will throw a {@link StreamException}, that wraps either an
23 * {@link IOException} (writing to a closed writer) or an {@link IllegalStateException}. The
24 * implementation will also track unbalanced nodes or multiple attributes with the same name.
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.2
28 */
29 public class StatefulWriter extends WriterWrapper {
30
31 /**
32 * <code>STATE_OPEN</code> is the initial value of the writer.
33 *
34 * @since 1.2
35 */
36 public static int STATE_OPEN = 0;
37 /**
38 * <code>STATE_NODE_START</code> is the state of a new node has been started.
39 *
40 * @since 1.2
41 */
42 public static int STATE_NODE_START = 1;
43 /**
44 * <code>STATE_VALUE</code> is the state if the value of a node has been written.
45 *
46 * @since 1.2
47 */
48 public static int STATE_VALUE = 2;
49 /**
50 * <code>STATE_NODE_END</code> is the state if a node has ended
51 *
52 * @since 1.2
53 */
54 public static int STATE_NODE_END = 3;
55 /**
56 * <code>STATE_CLOSED</code> is the state if the writer has been closed.
57 *
58 * @since 1.2
59 */
60 public static int STATE_CLOSED = 4;
61
62 private transient int state = STATE_OPEN;
63 private transient int balance;
64 private transient FastStack attributes;
65
66 /**
67 * Constructs a StatefulWriter.
68 *
69 * @param wrapped the wrapped writer
70 * @since 1.2
71 */
72 public StatefulWriter(final HierarchicalStreamWriter wrapped) {
73 super(wrapped);
74 attributes = new FastStack(16);
75 }
76
77 public void startNode(final String name) {
78 startNodeCommon();
79 super.startNode(name);
80 }
81
82 public void startNode(final String name, final Class clazz) {
83 startNodeCommon();
84 super.startNode(name, clazz);
85 }
86
87 private void startNodeCommon() {
88 checkClosed();
89 if (state == STATE_VALUE) {
90 // legal XML, but not in XStream ... ?
91 throw new StreamException(new IllegalStateException("Opening node after writing text"));
92 }
93 state = STATE_NODE_START;
94 ++balance;
95 attributes.push(new HashSet());
96 }
97
98 public void addAttribute(String name, String value) {
99 checkClosed();
100 if (state != STATE_NODE_START) {
101 throw new StreamException(new IllegalStateException("Writing attribute '"
102 + name
103 + "' without an opened node"));
104 }
105 Set currentAttributes = (Set)attributes.peek();
106 if (currentAttributes.contains(name)) {
107 throw new StreamException(new IllegalStateException("Writing attribute '"
108 + name
109 + "' twice"));
110 }
111 currentAttributes.add(name);
112 super.addAttribute(name, value);
113 }
114
115 public void setValue(String text) {
116 checkClosed();
117 if (state != STATE_NODE_START) {
118 // STATE_NODE_END is legal XML, but not in XStream ... ?
119 throw new StreamException(new IllegalStateException(
120 "Writing text without an opened node"));
121 }
122 state = STATE_VALUE;
123 super.setValue(text);
124 }
125
126 public void endNode() {
127 checkClosed();
128 if (balance-- == 0) {
129 throw new StreamException(new IllegalStateException("Unbalanced node"));
130 }
131 attributes.popSilently();
132 state = STATE_NODE_END;
133 super.endNode();
134 }
135
136 public void flush() {
137 checkClosed();
138 super.flush();
139 }
140
141 public void close() {
142 if (state != STATE_NODE_END && state != STATE_OPEN) {
143 // calling close in a finally block should not throw again
144 // throw new StreamException(new IllegalStateException("Closing with unbalanced tag"));
145 }
146 state = STATE_CLOSED;
147 super.close();
148 }
149
150 private void checkClosed() {
151 if (state == STATE_CLOSED) {
152 throw new StreamException(new IOException("Writing on a closed stream"));
153 }
154 }
155
156 /**
157 * Retrieve the state of the writer.
158 *
159 * @return one of the states
160 * @see #STATE_OPEN
161 * @see #STATE_NODE_START
162 * @see #STATE_VALUE
163 * @see #STATE_NODE_END
164 * @see #STATE_CLOSED
165 * @since 1.2
166 */
167 public int state() {
168 return state;
169 }
170
171 private Object readResolve() {
172 attributes = new FastStack(16);
173 return this;
174 }
175 }
0 /*
1 * Copyright (C) 2004, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import com.thoughtworks.xstream.XStreamException;
14
15 public class StreamException extends XStreamException {
16 public StreamException(Throwable e) {
17 super(e);
18 }
19
20 public StreamException(String message) {
21 super(message);
22 }
23
24 /**
25 * @since 1.4
26 */
27 public StreamException(String message, Throwable cause) {
28 super(message, cause);
29 }
30 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 10. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 /**
14 * Base class to make it easy to create wrappers (decorators) for HierarchicalStreamWriter.
15 *
16 * @author Joe Walnes
17 */
18 public abstract class WriterWrapper implements ExtendedHierarchicalStreamWriter {
19
20 protected HierarchicalStreamWriter wrapped;
21
22 protected WriterWrapper(HierarchicalStreamWriter wrapped) {
23 this.wrapped = wrapped;
24 }
25
26 public void startNode(String name) {
27 wrapped.startNode(name);
28 }
29
30 public void startNode(String name, Class clazz) {
31
32 ((ExtendedHierarchicalStreamWriter) wrapped).startNode(name, clazz);
33 }
34
35 public void endNode() {
36 wrapped.endNode();
37 }
38
39 public void addAttribute(String key, String value) {
40 wrapped.addAttribute(key, value);
41 }
42
43 public void setValue(String text) {
44 wrapped.setValue(text);
45 }
46
47 public void flush() {
48 wrapped.flush();
49 }
50
51 public void close() {
52 wrapped.close();
53 }
54
55 public HierarchicalStreamWriter underlyingWriter() {
56 return wrapped.underlyingWriter();
57 }
58
59 }
0 /*
1 * Copyright (C) 2011 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 14. October 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.binary;
11
12 import java.io.InputStream;
13 import java.io.OutputStream;
14 import java.io.Reader;
15 import java.io.Writer;
16
17 import com.thoughtworks.xstream.io.AbstractDriver;
18 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
19 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
20
21
22 /**
23 * HierarchicalStreamDriver for binary input and output. The driver uses an optimized binary
24 * format to store an object graph. The format is not as compact as Java serialization, but a
25 * lot more than typical text-based formats like XML. However, due to its nature it cannot use a
26 * {@link Reader} for input or a {@link Writer} for output.
27 *
28 * @author J&ouml;rg Schaible
29 * @since 1.4.2
30 */
31 public class BinaryStreamDriver extends AbstractDriver {
32
33 /**
34 * @throws UnsupportedOperationException if called
35 */
36 public HierarchicalStreamReader createReader(Reader in) {
37 throw new UnsupportedOperationException(
38 "The BinaryDriver cannot use character-oriented input streams.");
39 }
40
41 public HierarchicalStreamReader createReader(InputStream in) {
42 return new BinaryStreamReader(in);
43 }
44
45 /**
46 * @throws UnsupportedOperationException if called
47 */
48 public HierarchicalStreamWriter createWriter(Writer out) {
49 throw new UnsupportedOperationException(
50 "The BinaryDriver cannot use character-oriented output streams.");
51 }
52
53 public HierarchicalStreamWriter createWriter(OutputStream out) {
54 return new BinaryStreamWriter(out);
55 }
56 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import com.thoughtworks.xstream.converters.ErrorWriter;
14 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
16 import com.thoughtworks.xstream.io.StreamException;
17
18 import java.io.DataInputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24
25 /**
26 * A HierarchicalStreamReader that reads from a binary stream created by
27 * {@link BinaryStreamWriter}.
28 *
29 * @author Joe Walnes
30 * @see BinaryStreamReader
31 * @since 1.2
32 */
33 public class BinaryStreamReader implements ExtendedHierarchicalStreamReader {
34
35 private final DataInputStream in;
36 private final ReaderDepthState depthState = new ReaderDepthState();
37 private final IdRegistry idRegistry = new IdRegistry();
38
39 private Token pushback;
40 private final Token.Formatter tokenFormatter = new Token.Formatter();
41
42 public BinaryStreamReader(InputStream inputStream) {
43 in = new DataInputStream(inputStream);
44 moveDown();
45 }
46
47 public boolean hasMoreChildren() {
48 return depthState.hasMoreChildren();
49 }
50
51 public String getNodeName() {
52 return depthState.getName();
53 }
54
55 public String getValue() {
56 return depthState.getValue();
57 }
58
59 public String getAttribute(String name) {
60 return depthState.getAttribute(name);
61 }
62
63 public String getAttribute(int index) {
64 return depthState.getAttribute(index);
65 }
66
67 public int getAttributeCount() {
68 return depthState.getAttributeCount();
69 }
70
71 public String getAttributeName(int index) {
72 return depthState.getAttributeName(index);
73 }
74
75 public Iterator getAttributeNames() {
76 return depthState.getAttributeNames();
77 }
78
79 public void moveDown() {
80 depthState.push();
81 Token firstToken = readToken();
82 switch (firstToken.getType()) {
83 case Token.TYPE_START_NODE:
84 depthState.setName(idRegistry.get(firstToken.getId()));
85 break;
86 default:
87 throw new StreamException("Expected StartNode");
88 }
89 while (true) {
90 Token nextToken = readToken();
91 switch (nextToken.getType()) {
92 case Token.TYPE_ATTRIBUTE:
93 depthState.addAttribute(idRegistry.get(nextToken.getId()), nextToken.getValue());
94 break;
95 case Token.TYPE_VALUE:
96 depthState.setValue(nextToken.getValue());
97 break;
98 case Token.TYPE_END_NODE:
99 depthState.setHasMoreChildren(false);
100 pushBack(nextToken);
101 return;
102 case Token.TYPE_START_NODE:
103 depthState.setHasMoreChildren(true);
104 pushBack(nextToken);
105 return;
106 default:
107 throw new StreamException("Unexpected token " + nextToken);
108 }
109 }
110 }
111
112 public void moveUp() {
113 depthState.pop();
114 // We're done with this depth. Skip over all tokens until we get to the end.
115 int depth = 0;
116 slurp:
117 while (true) {
118 Token nextToken = readToken();
119 switch(nextToken.getType()) {
120 case Token.TYPE_END_NODE:
121 if (depth == 0) {
122 break slurp;
123 } else {
124 depth--;
125 }
126 break;
127 case Token.TYPE_START_NODE:
128 depth++;
129 break;
130 default:
131 // Ignore other tokens
132 }
133 }
134 // Peek ahead to determine if there are any more kids at this level.
135 Token nextToken = readToken();
136 switch(nextToken.getType()) {
137 case Token.TYPE_END_NODE:
138 depthState.setHasMoreChildren(false);
139 break;
140 case Token.TYPE_START_NODE:
141 depthState.setHasMoreChildren(true);
142 break;
143 default:
144 throw new StreamException("Unexpected token " + nextToken);
145 }
146 pushBack(nextToken);
147 }
148
149 private Token readToken() {
150 if (pushback == null) {
151 try {
152 Token token = tokenFormatter.read(in);
153 switch (token.getType()) {
154 case Token.TYPE_MAP_ID_TO_VALUE:
155 idRegistry.put(token.getId(), token.getValue());
156 return readToken(); // Next one please.
157 default:
158 return token;
159 }
160 } catch (IOException e) {
161 throw new StreamException(e);
162 }
163 } else {
164 Token result = pushback;
165 pushback = null;
166 return result;
167 }
168 }
169
170 public void pushBack(Token token) {
171 if (pushback == null) {
172 pushback = token;
173 } else {
174 // If this happens, I've messed up :( -joe.
175 throw new Error("Cannot push more than one token back");
176 }
177 }
178
179 public void close() {
180 try {
181 in.close();
182 } catch (IOException e) {
183 throw new StreamException(e);
184 }
185 }
186
187 public String peekNextChild() {
188 if (depthState.hasMoreChildren()) {
189 return idRegistry.get(pushback.getId());
190 }
191 return null;
192 }
193
194 public HierarchicalStreamReader underlyingReader() {
195 return this;
196 }
197
198 public void appendErrors(ErrorWriter errorWriter) {
199 // TODO: When things go bad, it would be good to know where!
200 }
201
202 private static class IdRegistry {
203
204 private Map map = new HashMap();
205
206 public void put(long id, String value) {
207 map.put(new Long(id), value);
208 }
209
210 public String get(long id) {
211 String result = (String) map.get(new Long(id));
212 if (result == null) {
213 throw new StreamException("Unknown ID : " + id);
214 } else {
215 return result;
216 }
217 }
218 }
219
220 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
14 import com.thoughtworks.xstream.io.StreamException;
15 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter;
16
17 import java.io.DataOutputStream;
18 import java.io.OutputStream;
19 import java.io.IOException;
20 import java.util.Map;
21 import java.util.HashMap;
22
23 /**
24 * @since 1.2
25 */
26 public class BinaryStreamWriter implements ExtendedHierarchicalStreamWriter {
27
28 private final IdRegistry idRegistry = new IdRegistry();
29 private final DataOutputStream out;
30 private final Token.Formatter tokenFormatter = new Token.Formatter();
31
32 public BinaryStreamWriter(OutputStream outputStream) {
33 out = new DataOutputStream(outputStream);
34 }
35
36 public void startNode(String name) {
37 write(new Token.StartNode(idRegistry.getId(name)));
38 }
39
40 public void startNode(String name, Class clazz) {
41 startNode(name);
42 }
43
44 public void addAttribute(String name, String value) {
45 write(new Token.Attribute(idRegistry.getId(name), value));
46 }
47
48 public void setValue(String text) {
49 write(new Token.Value(text));
50 }
51
52 public void endNode() {
53 write(new Token.EndNode());
54 }
55
56 public void flush() {
57 try {
58 out.flush();
59 } catch (IOException e) {
60 throw new StreamException(e);
61 }
62 }
63
64 public void close() {
65 try {
66 out.close();
67 } catch (IOException e) {
68 throw new StreamException(e);
69 }
70 }
71
72 public HierarchicalStreamWriter underlyingWriter() {
73 return this;
74 }
75
76 private void write(Token token) {
77 try {
78 tokenFormatter.write(out, token);
79 } catch (IOException e) {
80 throw new StreamException(e);
81 }
82 }
83
84 private class IdRegistry {
85
86 private long nextId = 0;
87 private Map ids = new HashMap();
88
89 public long getId(String value) {
90 Long id = (Long) ids.get(value);
91 if (id == null) {
92 id = new Long(++nextId);
93 ids.put(value, id);
94 write(new Token.MapIdToValue(id.longValue(), value));
95 }
96 return id.longValue();
97 }
98
99 }
100 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import java.util.List;
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.Collections;
17
18 /**
19 * Maintains the state of a pull reader at various states in the document depth.
20 *
21 * Used by the {@link BinaryStreamReader}
22 *
23 * @author Joe Walnes
24 * @since 1.2
25 */
26 class ReaderDepthState {
27
28 private static final String EMPTY_STRING = "";
29
30 private static class State {
31 String name;
32 String value;
33 List attributes;
34 boolean hasMoreChildren;
35 State parent;
36 }
37
38 private static class Attribute {
39 String name;
40 String value;
41 }
42
43 private State current;
44
45 public void push() {
46 State newState = new State();
47 newState.parent = current;
48 current = newState;
49 }
50
51 public void pop() {
52 current = current.parent;
53 }
54
55 public String getName() {
56 return current.name;
57 }
58
59 public void setName(String name) {
60 current.name = name;
61 }
62
63 public String getValue() {
64 return current.value == null ? EMPTY_STRING : current.value;
65 }
66
67 public void setValue(String value) {
68 current.value = value;
69 }
70
71 public boolean hasMoreChildren() {
72 return current.hasMoreChildren;
73 }
74
75 public void setHasMoreChildren(boolean hasMoreChildren) {
76 current.hasMoreChildren = hasMoreChildren;
77 }
78
79 public void addAttribute(String name, String value) {
80 Attribute attribute = new Attribute();
81 attribute.name = name;
82 attribute.value = value;
83 if (current.attributes == null) {
84 current.attributes = new ArrayList();
85 }
86 current.attributes.add(attribute);
87 }
88
89 public String getAttribute(String name) {
90 if (current.attributes == null) {
91 return null;
92 } else {
93 // For short maps, it's faster to iterate then do a hashlookup.
94 for (Iterator iterator = current.attributes.iterator(); iterator.hasNext();) {
95 Attribute attribute = (Attribute) iterator.next();
96 if (attribute.name.equals(name)) {
97 return attribute.value;
98 }
99 }
100 return null;
101 }
102 }
103
104 public String getAttribute(int index) {
105 if (current.attributes == null) {
106 return null;
107 } else {
108 Attribute attribute = (Attribute) current.attributes.get(index);
109 return attribute.value;
110 }
111 }
112
113 public String getAttributeName(int index) {
114 if (current.attributes == null) {
115 return null;
116 } else {
117 Attribute attribute = (Attribute) current.attributes.get(index);
118 return attribute.name;
119 }
120 }
121
122 public int getAttributeCount() {
123 return current.attributes == null ? 0 : current.attributes.size();
124 }
125
126 public Iterator getAttributeNames() {
127 if (current.attributes == null) {
128 return Collections.EMPTY_SET.iterator();
129 } else {
130 final Iterator attributeIterator = current.attributes.iterator();
131 return new Iterator() {
132 public boolean hasNext() {
133 return attributeIterator.hasNext();
134 }
135
136 public Object next() {
137 Attribute attribute = (Attribute) attributeIterator.next();
138 return attribute.name;
139 }
140
141 public void remove() {
142 throw new UnsupportedOperationException();
143 }
144 };
145 }
146 }
147
148 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2013 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import com.thoughtworks.xstream.io.StreamException;
14
15 import java.io.DataOutput;
16 import java.io.IOException;
17 import java.io.DataInput;
18
19 /**
20 * Represents the Tokens stored in the binary stream used by
21 * {@link BinaryStreamReader} and {@link BinaryStreamWriter}.
22 * <p>
23 * A token consists of a type and (depending on this type)
24 * it may additionally have an ID (positive long number)
25 * and/or a value (String).</p>
26 * <p>
27 * The first byte of the token represents how many subsequent
28 * bytes are used by the ID.</p>
29 *
30 * @author Joe Walnes
31 * @see BinaryStreamReader
32 * @see BinaryStreamWriter
33 * @since 1.2
34 */
35 public abstract class Token {
36
37 private static final byte TYPE_MASK = 0x7;
38 public static final byte TYPE_VERSION = 0x1;
39 public static final byte TYPE_MAP_ID_TO_VALUE = 0x2;
40 public static final byte TYPE_START_NODE = 0x3;
41 public static final byte TYPE_END_NODE = 0x4;
42 public static final byte TYPE_ATTRIBUTE = 0x5;
43 public static final byte TYPE_VALUE = 0x6;
44
45 private static final byte ID_MASK = 0x38;
46 private static final byte ID_ONE_BYTE = 0x08;
47 private static final byte ID_TWO_BYTES = 0x10;
48 private static final byte ID_FOUR_BYTES = 0x18;
49 private static final byte ID_EIGHT_BYTES = 0x20;
50
51 private static final String ID_SPLITTED = "\u0000\u2021\u0000";
52 private static final int MAX_UTF8_LENGTH = 0xffff;
53
54 private final byte type;
55
56 protected long id = -1;
57 protected String value;
58
59 public Token(byte type) {
60 this.type = type;
61 }
62
63 public byte getType() {
64 return type;
65 }
66
67 public long getId() {
68 return id;
69 }
70
71 public String getValue() {
72 return value;
73 }
74
75 public String toString() {
76 return getClass().getName() + " [id=" + id + ", value='" + value + "']";
77 }
78
79 public boolean equals(Object o) {
80 if (this == o) return true;
81 if (o == null || getClass() != o.getClass()) return false;
82
83 final Token token = (Token) o;
84
85 if (id != token.id) return false;
86 if (type != token.type) return false;
87 return !(value != null ? !value.equals(token.value) : token.value != null);
88 }
89
90 public int hashCode() {
91 int result;
92 result = type;
93 result = 29 * result + (int) (id ^ (id >>> 32));
94 result = 29 * result + (value != null ? value.hashCode() : 0);
95 return result;
96 }
97
98 public abstract void writeTo(DataOutput out, byte idType) throws IOException;
99
100 public abstract void readFrom(DataInput in, byte idType) throws IOException;
101
102 protected void writeId(DataOutput out, long id, byte idType) throws IOException {
103 if (id < 0) {
104 throw new IOException("id must not be negative " + id);
105 }
106 switch (idType) {
107 case ID_ONE_BYTE:
108 out.writeByte((byte) id + Byte.MIN_VALUE);
109 break;
110 case ID_TWO_BYTES:
111 out.writeShort((short) id + Short.MIN_VALUE);
112 break;
113 case ID_FOUR_BYTES:
114 out.writeInt((int) id + Integer.MIN_VALUE);
115 break;
116 case ID_EIGHT_BYTES:
117 out.writeLong(id + Long.MIN_VALUE);
118 break;
119 default:
120 throw new Error("Unknown idType " + idType);
121 }
122 }
123
124 protected void writeString(DataOutput out, String string) throws IOException {
125 final byte[] bytes = (string.length() > MAX_UTF8_LENGTH / 4) ? string.getBytes("utf-8") : new byte[0];
126 int length = bytes.length;
127 if (length <= MAX_UTF8_LENGTH) {
128 out.writeUTF(string);
129 } else {
130 out.writeUTF(ID_SPLITTED);
131 out.writeInt(bytes.length);
132 out.write(bytes);
133 }
134 }
135
136 protected long readId(DataInput in, byte idType) throws IOException {
137 switch (idType) {
138 case ID_ONE_BYTE:
139 return in.readByte() - Byte.MIN_VALUE;
140 case ID_TWO_BYTES:
141 return in.readShort() - Short.MIN_VALUE;
142 case ID_FOUR_BYTES:
143 return in.readInt() - Integer.MIN_VALUE;
144 case ID_EIGHT_BYTES:
145 return in.readLong() - Long.MIN_VALUE;
146 default:
147 throw new Error("Unknown idType " + idType);
148 }
149 }
150
151 protected String readString(DataInput in) throws IOException {
152 final String string = in.readUTF();
153 if (!ID_SPLITTED.equals(string)) {
154 return string;
155 }
156 final int size = in.readInt();
157 final byte[] bytes = new byte[size];
158 in.readFully(bytes);
159 return new String(bytes, "utf-8");
160 }
161
162 public static class Formatter {
163
164 public void write(DataOutput out, Token token) throws IOException {
165 long id = token.getId();
166 byte idType;
167 if (id <= Byte.MAX_VALUE - Byte.MIN_VALUE) {
168 idType = ID_ONE_BYTE;
169 } else if (id <= Short.MAX_VALUE - Short.MIN_VALUE) {
170 idType = ID_TWO_BYTES;
171 } else if (id <= (long) Integer.MAX_VALUE - (long) Integer.MIN_VALUE) { // cast to long to prevent overflow
172 idType = ID_FOUR_BYTES;
173 } else {
174 idType = ID_EIGHT_BYTES;
175 }
176 out.write(token.getType() + idType);
177 token.writeTo(out, idType);
178 }
179
180 public Token read(DataInput in) throws IOException {
181 byte nextByte = in.readByte();
182 byte type = (byte) (nextByte & TYPE_MASK);
183 byte idType = (byte) (nextByte & ID_MASK);
184 Token token = contructToken(type);
185 token.readFrom(in, idType);
186 return token;
187 }
188
189 private Token contructToken(byte type) {
190 switch (type) {
191 case Token.TYPE_START_NODE:
192 return new StartNode();
193 case Token.TYPE_MAP_ID_TO_VALUE:
194 return new MapIdToValue();
195 case Token.TYPE_ATTRIBUTE:
196 return new Attribute();
197 case Token.TYPE_END_NODE:
198 return new EndNode();
199 case Token.TYPE_VALUE:
200 return new Value();
201 default:
202 throw new StreamException("Unknown token type");
203 }
204 }
205 }
206
207 public static class MapIdToValue extends Token {
208
209 public MapIdToValue(long id, String value) {
210 super(TYPE_MAP_ID_TO_VALUE);
211 this.id = id;
212 this.value = value;
213 }
214
215 public MapIdToValue() {
216 super(TYPE_MAP_ID_TO_VALUE);
217 }
218
219 public void writeTo(DataOutput out, byte idType) throws IOException {
220 writeId(out, id, idType);
221 writeString(out, value);
222 }
223
224 public void readFrom(DataInput in, byte idType) throws IOException {
225 id = readId(in, idType);
226 value = readString(in);
227 }
228
229 }
230
231 public static class StartNode extends Token {
232
233 public StartNode(long id) {
234 super(TYPE_START_NODE);
235 this.id = id;
236 }
237
238 public StartNode() {
239 super(TYPE_START_NODE);
240 }
241
242 public void writeTo(DataOutput out, byte idType) throws IOException {
243 writeId(out, id, idType);
244 }
245
246 public void readFrom(DataInput in, byte idType) throws IOException {
247 id = readId(in, idType);
248 }
249
250 }
251
252 public static class EndNode extends Token {
253
254 public EndNode() {
255 super(TYPE_END_NODE);
256 }
257
258 public void writeTo(DataOutput out, byte idType) {
259 }
260
261 public void readFrom(DataInput in, byte idType) {
262 }
263
264 }
265
266 public static class Attribute extends Token {
267
268 public Attribute(long id, String value) {
269 super(TYPE_ATTRIBUTE);
270 this.id = id;
271 this.value = value;
272 }
273
274 public Attribute() {
275 super(TYPE_ATTRIBUTE);
276 }
277
278 public void writeTo(DataOutput out, byte idType) throws IOException {
279 writeId(out, id, idType);
280 writeString(out, value);
281 }
282
283 public void readFrom(DataInput in, byte idType) throws IOException {
284 this.id = readId(in, idType);
285 this.value = readString(in);
286 }
287
288 }
289
290 public static class Value extends Token {
291
292 public Value(String value) {
293 super(TYPE_VALUE);
294 this.value = value;
295 }
296
297 public Value() {
298 super(TYPE_VALUE);
299 }
300
301 public void writeTo(DataOutput out, byte idType) throws IOException {
302 writeString(out, value);
303 }
304
305 public void readFrom(DataInput in, byte idType) throws IOException {
306 value = readString(in);
307 }
308
309 }
310
311 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2013 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.copy;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15
16 /**
17 * Tool for copying the contents of one HierarichalStreamReader to a HierarichalStreamWriter.
18 * <p>
19 * This is useful for transforming the output of one format to another (e.g. binary to XML)
20 * without needing to know details about the classes and avoiding the overhead of serialization.</p>
21 *
22 * <h3>Example</h3>
23 * <pre>
24 * HierarchicalStreamReader reader = new BinaryStreamReader(someBinaryInput);
25 * HierarchicalStreamWriter writer = new PrettyPrintWriter(someXmlOutput);
26 * HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
27 * copier.copy(reader, writer);
28 * </pre>
29 *
30 * @author Joe Walnes
31 * @since 1.2
32 */
33 public class HierarchicalStreamCopier {
34 public void copy(HierarchicalStreamReader source, HierarchicalStreamWriter destination) {
35 destination.startNode(source.getNodeName());
36 int attributeCount = source.getAttributeCount();
37 for (int i = 0; i < attributeCount; i++) {
38 destination.addAttribute(source.getAttributeName(i), source.getAttribute(i));
39 }
40 String value = source.getValue();
41 if (value != null && value.length() > 0) {
42 destination.setValue(value);
43 }
44 while (source.hasMoreChildren()) {
45 source.moveDown();
46 copy(source, destination);
47 source.moveUp();
48 }
49 destination.endNode();
50 }
51 }
0 /*
1 * Copyright (C) 2009, 2010, 2011, 2012, 2013 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 20. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import java.io.Externalizable;
13 import java.math.BigDecimal;
14 import java.math.BigInteger;
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.HashSet;
18 import java.util.Map;
19 import java.util.Set;
20
21 import com.thoughtworks.xstream.converters.ConversionException;
22 import com.thoughtworks.xstream.core.util.FastStack;
23 import com.thoughtworks.xstream.io.AbstractWriter;
24 import com.thoughtworks.xstream.io.naming.NameCoder;
25 import com.thoughtworks.xstream.io.naming.NoNameCoder;
26 import com.thoughtworks.xstream.mapper.Mapper;
27
28
29 /**
30 * An abstract implementation of a writer that calls abstract methods to build JSON structures.
31 * Note, that XStream's implicit collection feature is only compatible with the syntax in
32 * {@link #EXPLICIT_MODE}.
33 *
34 * @author J&ouml;rg Schaible
35 * @since 1.4
36 */
37 public abstract class AbstractJsonWriter extends AbstractWriter {
38 /**
39 * DROP_ROOT_MODE drops the JSON root node.
40 * <p>
41 * The root node is the first level of the JSON object i.e.</p>
42 *
43 * <pre>
44 * { &quot;person&quot;: {
45 * &quot;name&quot;: &quot;Joe&quot;
46 * }}
47 * </pre>
48 *
49 * <p>will be written without root simply as</p>
50 *
51 * <pre>
52 * {
53 * &quot;name&quot;: &quot;Joe&quot;
54 * }
55 * </pre>
56 *
57 * <p>
58 * Without a root node, the top level element might now also be an array. However, it is
59 * possible to generate invalid JSON unless {@link #STRICT_MODE} is also set.</p>
60 *
61 * @since 1.3.1
62 */
63 public static final int DROP_ROOT_MODE = 1;
64 /**
65 * STRICT_MODE prevents invalid JSON for single value objects when dropping the root.
66 * <p>
67 * The mode is only useful in combination with the {@link #DROP_ROOT_MODE}. An object with a
68 * single value as first node i.e.</p>
69 *
70 * <pre>
71 * { &quot;name&quot;: &quot;Joe&quot; }
72 * </pre>
73 *
74 * <p>is simply written as</p>
75 *
76 * <pre>
77 * &quot;Joe&quot;
78 * </pre>
79 *
80 * <p>
81 * However, this is no longer valid JSON. Therefore you can activate {@link #STRICT_MODE}
82 * and a {@link ConversionException} is thrown instead.</p>
83 *
84 * @since 1.3.1
85 */
86 public static final int STRICT_MODE = 2;
87 /**
88 * EXPLICIT_MODE assures that all data has its explicit equivalent in the resulting JSON.
89 * <p>
90 * XStream is normally using attributes in XML that have no real equivalent in JSON.
91 * Additionally it is essential in XML that the individual child elements of a tag keep
92 * order and may have the same tag name. XStream's model relies on both characteristics.
93 * However, properties of a JSON object do not have a defined order, but their names have to
94 * be unique. Only a JSON array defines the order of its elements.
95 * </p>
96 * <p>
97 * Therefore XStream uses in explicit mode a JSON format that supports the original
98 * requirements at the expense of the simplicity of the JSON objects and arrays. Each Java
99 * object will be represented by a JSON object with a single property representing the name
100 * of the object and an array as value that contains two more arrays. The first one contains
101 * a JSON object with all attributes, the second one the value of the Java object which can
102 * be null, a string or integer value or again a new JSON object representing a Java object.
103 * Here an example of an string array with one member, where the array and the string has an
104 * additional attribute 'id':</p>
105 *
106 * <pre>
107 * {&quot;string-array&quot;:[[{&quot;id&quot;:&quot;1&quot;}],[{&quot;string&quot;:[[{&quot;id&quot;:&quot;2&quot;}],[&quot;Joe&quot;]]}]]}
108 * </pre>
109 *
110 * <p>
111 * This format can be used to always deserialize into Java again.
112 * </p>
113 * <p>
114 * This mode cannot combined with {@link #STRICT_MODE} or {@link #DROP_ROOT_MODE}.
115 * </p>
116 *
117 * @since 1.4
118 */
119 public static final int EXPLICIT_MODE = 4;
120 /**
121 * IEEE_754_MODE keeps precision of 64-bit integer values.
122 * <p>
123 * In JavaScript every number is expressed as 64-bit double value with a precision of 53
124 * bits following IEEE 754. Therefore it is not possible to represent the complete value
125 * range of 64-bit integer values. Any integer value &gt; 2<sup>53</sup>
126 * (9007199254740992) or &lt; -2<sup>53</sup> (-9007199254740992) will therefore be
127 * written as string value.
128 * </p>
129 * <p>
130 * CAUTION: A client must be aware that the element may contain a number or a string value.
131 * </p>
132 *
133 * @since 1.4.5
134 * @see <a href="http://ecma262-5.com/ELS5_HTML.htm#Section_8.5">ECMA Specification: The Number Type</a>
135 */
136 public static final int IEEE_754_MODE = 8;
137
138 public static class Type {
139 public static Type NULL = new Type();
140 public static Type STRING = new Type();
141 public static Type NUMBER = new Type();
142 public static Type BOOLEAN = new Type();
143 }
144
145 private static class StackElement {
146 final Class type;
147 int status;
148 public StackElement(Class type, int status) {
149 this.type = type;
150 this.status = status;
151 }
152 }
153
154 private static class IllegalWriterStateException extends IllegalStateException {
155 public IllegalWriterStateException(int from, int to, String element) {
156 super("Cannot turn from state " + getState(from) + " into state " + getState(to)
157 + (element == null ? "" : " for property " + element));
158 }
159 private static String getState(int state) {
160 switch (state) {
161 case STATE_ROOT: return "ROOT";
162 case STATE_END_OBJECT: return "END_OBJECT";
163 case STATE_START_OBJECT: return "START_OBJECT";
164 case STATE_START_ATTRIBUTES: return "START_ATTRIBUTES";
165 case STATE_NEXT_ATTRIBUTE: return "NEXT_ATTRIBUTE";
166 case STATE_END_ATTRIBUTES: return "END_ATTRIBUTES";
167 case STATE_START_ELEMENTS: return "START_ELEMENTS";
168 case STATE_NEXT_ELEMENT: return "NEXT_ELEMENT";
169 case STATE_END_ELEMENTS: return "END_ELEMENTS";
170 case STATE_SET_VALUE: return "SET_VALUE";
171 default: throw new IllegalArgumentException("Unknown state provided: " + state
172 + ", cannot create message for IllegalWriterStateException");
173 }
174 }
175 }
176
177 private static final int STATE_ROOT = 1 << 0;
178 private static final int STATE_END_OBJECT = 1 << 1;
179 private static final int STATE_START_OBJECT = 1 << 2;
180 private static final int STATE_START_ATTRIBUTES = 1 << 3;
181 private static final int STATE_NEXT_ATTRIBUTE = 1 << 4;
182 private static final int STATE_END_ATTRIBUTES = 1 << 5;
183 private static final int STATE_START_ELEMENTS = 1 << 6;
184 private static final int STATE_NEXT_ELEMENT = 1 << 7;
185 private static final int STATE_END_ELEMENTS = 1 << 8;
186 private static final int STATE_SET_VALUE = 1 << 9;
187
188 private static final Set NUMBER_TYPES = new HashSet(Arrays.asList(new Class[]{
189 byte.class, Byte.class, short.class, Short.class, int.class, Integer.class, long.class,
190 Long.class, float.class, Float.class, double.class, Double.class, BigInteger.class,
191 BigDecimal.class}));
192 private int mode;
193 private FastStack stack = new FastStack(16);
194 private int expectedStates;
195
196 /**
197 * Construct a JSON writer.
198 *
199 * @since 1.4
200 */
201 public AbstractJsonWriter() {
202 this(new NoNameCoder());
203 }
204
205 /**
206 * Construct a JSON writer with a special mode.
207 *
208 * @param mode a bit mask of the mode constants
209 * @since 1.4
210 */
211 public AbstractJsonWriter(int mode) {
212 this(mode, new NoNameCoder());
213 }
214
215 /**
216 * Construct a JSON writer with a special name coder.
217 *
218 * @param nameCoder the name coder to use
219 * @since 1.4
220 */
221 public AbstractJsonWriter(NameCoder nameCoder) {
222 this(0, nameCoder);
223 }
224
225 /**
226 * Construct a JSON writer with a special mode and name coder.
227 *
228 * @param mode a bit mask of the mode constants
229 * @param nameCoder the name coder to use
230 * @since 1.4
231 */
232 public AbstractJsonWriter(int mode, NameCoder nameCoder) {
233 super(nameCoder);
234 this.mode = (mode & EXPLICIT_MODE) > 0 ? EXPLICIT_MODE : mode;
235 stack.push(new StackElement(null, STATE_ROOT));
236 expectedStates = STATE_START_OBJECT;
237 }
238
239 public void startNode(String name, Class clazz) {
240 if (name == null) {
241 throw new NullPointerException("name");
242 }
243 stack.push(new StackElement(clazz, ((StackElement)stack.peek()).status));
244 handleCheckedStateTransition(STATE_START_OBJECT, name, null);
245 expectedStates = STATE_SET_VALUE | STATE_NEXT_ATTRIBUTE | STATE_START_OBJECT | STATE_NEXT_ELEMENT | STATE_ROOT;
246 }
247
248 public void startNode(String name) {
249 startNode(name, null);
250 }
251
252 public void addAttribute(String name, String value) {
253 handleCheckedStateTransition(STATE_NEXT_ATTRIBUTE, name, value);
254 expectedStates = STATE_SET_VALUE | STATE_NEXT_ATTRIBUTE | STATE_START_OBJECT | STATE_NEXT_ELEMENT | STATE_ROOT;
255 }
256
257 public void setValue(String text) {
258 Class type = ((StackElement)stack.peek()).type;
259 if ((type == Character.class || type == Character.TYPE) && "".equals(text)) {
260 text = "\u0000";
261 }
262 handleCheckedStateTransition(STATE_SET_VALUE, null, text);
263 expectedStates = STATE_NEXT_ELEMENT | STATE_ROOT;
264 }
265
266 public void endNode() {
267 int size = stack.size();
268 int nextState = size > 2 ? STATE_NEXT_ELEMENT : STATE_ROOT;
269 handleCheckedStateTransition(nextState, null, null);
270 stack.pop();
271 ((StackElement)stack.peek()).status = nextState;
272 expectedStates = STATE_START_OBJECT;
273 if (size > 2) {
274 expectedStates |= STATE_NEXT_ELEMENT | STATE_ROOT;
275 }
276 }
277
278 private void handleCheckedStateTransition(final int requiredState, final String elementToAdd, final String valueToAdd)
279 {
280 final StackElement stackElement = (StackElement)stack.peek();
281 if ((expectedStates & requiredState) == 0) {
282 throw new IllegalWriterStateException(stackElement.status, requiredState, elementToAdd);
283 }
284 int currentState = handleStateTransition(stackElement.status, requiredState, elementToAdd, valueToAdd);
285 stackElement.status = currentState;
286 }
287
288 private int handleStateTransition(int currentState, final int requiredState, final String elementToAdd, final String valueToAdd)
289 {
290 int size = stack.size();
291 Class currentType = ((StackElement)stack.peek()).type;
292 boolean isArray = size > 1 && isArray(currentType);
293 boolean isArrayElement = size > 1 && isArray(((StackElement)stack.get(size-2)).type);
294 switch(currentState) {
295 case STATE_ROOT:
296 if (requiredState == STATE_START_OBJECT) {
297 currentState = handleStateTransition(STATE_START_ELEMENTS, STATE_START_OBJECT, elementToAdd, null);
298 return requiredState;
299 }
300 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
301
302 case STATE_END_OBJECT:
303 switch(requiredState) {
304 case STATE_START_OBJECT:
305 currentState = handleStateTransition(currentState, STATE_NEXT_ELEMENT, null, null);
306 currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, null);
307 return requiredState;
308 case STATE_NEXT_ELEMENT:
309 nextElement();
310 return requiredState;
311 case STATE_ROOT:
312 if (((mode & DROP_ROOT_MODE) == 0 || size > 2) && (mode & EXPLICIT_MODE) == 0) {
313 endObject();
314 }
315 return requiredState;
316 default:
317 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
318 }
319
320 case STATE_START_OBJECT:
321 switch(requiredState) {
322 case STATE_SET_VALUE:
323 case STATE_START_OBJECT:
324 case STATE_ROOT:
325 case STATE_NEXT_ELEMENT:
326 if (!isArrayElement || (mode & EXPLICIT_MODE) != 0) {
327 currentState = handleStateTransition(currentState, STATE_START_ATTRIBUTES, null, null);
328 currentState = handleStateTransition(currentState, STATE_END_ATTRIBUTES, null, null);
329 }
330 currentState = STATE_START_ELEMENTS;
331
332 switch(requiredState) {
333 case STATE_SET_VALUE:
334 currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, valueToAdd);
335 break;
336 case STATE_START_OBJECT:
337 currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, null);
338 break;
339 case STATE_ROOT:
340 case STATE_NEXT_ELEMENT:
341 currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, null);
342 currentState = handleStateTransition(currentState, requiredState, null, null);
343 break;
344 }
345 return requiredState;
346 case STATE_START_ATTRIBUTES:
347 if ((mode & EXPLICIT_MODE) != 0) {
348 startArray();
349 }
350 return requiredState;
351 case STATE_NEXT_ATTRIBUTE:
352 if ((mode & EXPLICIT_MODE) != 0 || !isArray) {
353 currentState = handleStateTransition(currentState, STATE_START_ATTRIBUTES, null, null);
354 currentState = handleStateTransition(currentState, STATE_NEXT_ATTRIBUTE, elementToAdd, valueToAdd);
355 return requiredState;
356 } else {
357 return STATE_START_OBJECT;
358 }
359 default:
360 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
361 }
362
363 case STATE_NEXT_ELEMENT:
364 switch(requiredState) {
365 case STATE_START_OBJECT:
366 nextElement();
367 if (!isArrayElement && (mode & EXPLICIT_MODE) == 0) {
368 addLabel(encodeNode(elementToAdd));
369 if ((mode & EXPLICIT_MODE) == 0 && isArray) {
370 startArray();
371 }
372 return requiredState;
373 }
374 break;
375 case STATE_ROOT:
376 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
377 currentState = handleStateTransition(currentState, STATE_ROOT, null, null);
378 return requiredState;
379 case STATE_NEXT_ELEMENT:
380 case STATE_END_OBJECT:
381 currentState = handleStateTransition(currentState, STATE_END_ELEMENTS, null, null);
382 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
383 if ((mode & EXPLICIT_MODE) == 0 && !isArray) {
384 endObject();
385 }
386 return requiredState;
387 case STATE_END_ELEMENTS:
388 if ((mode & EXPLICIT_MODE) == 0 && isArray) {
389 endArray();
390 }
391 return requiredState;
392 default:
393 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
394 }
395 // fall through
396 case STATE_START_ELEMENTS:
397 switch(requiredState) {
398 case STATE_START_OBJECT:
399 if ((mode & DROP_ROOT_MODE) == 0 || size > 2) {
400 if (!isArrayElement || (mode & EXPLICIT_MODE) != 0) {
401 if (!"".equals(valueToAdd)) {
402 startObject();
403 }
404 addLabel(encodeNode(elementToAdd));
405 }
406 if ((mode & EXPLICIT_MODE) != 0) {
407 startArray();
408 }
409 }
410 if ((mode & EXPLICIT_MODE) == 0) {
411 if (isArray) {
412 startArray();
413 }
414 }
415 return requiredState;
416 case STATE_SET_VALUE:
417 if ((mode & STRICT_MODE) != 0 && size == 2) {
418 throw new ConversionException("Single value cannot be root element");
419 }
420 if (valueToAdd == null) {
421 if (currentType == Mapper.Null.class) {
422 addValue("null", Type.NULL);
423 } else if ((mode & EXPLICIT_MODE) == 0 && !isArray) {
424 startObject();
425 endObject();
426 }
427 } else {
428 if (((mode & IEEE_754_MODE) != 0)
429 && (currentType == long.class || currentType == Long.class)) {
430 long longValue = Long.parseLong(valueToAdd);
431 // JavaScript supports a maximum of 2^53
432 if (longValue > 9007199254740992L || longValue < -9007199254740992L) {
433 addValue(valueToAdd, Type.STRING);
434 } else {
435 addValue(valueToAdd, getType(currentType));
436 }
437 } else {
438 addValue(valueToAdd, getType(currentType));
439 }
440 }
441 return requiredState;
442 case STATE_END_ELEMENTS:
443 case STATE_NEXT_ELEMENT:
444 if ((mode & EXPLICIT_MODE) == 0) {
445 if (isArray) {
446 endArray();
447 } else {
448 endObject();
449 }
450 }
451 return requiredState;
452 default:
453 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
454 }
455
456 case STATE_END_ELEMENTS:
457 switch(requiredState) {
458 case STATE_END_OBJECT:
459 if ((mode & EXPLICIT_MODE) != 0) {
460 endArray();
461 endArray();
462 endObject();
463 }
464 return requiredState;
465 default:
466 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
467 }
468
469 case STATE_START_ATTRIBUTES:
470 switch(requiredState) {
471 case STATE_NEXT_ATTRIBUTE:
472 if (elementToAdd != null) {
473 String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "" ) + elementToAdd;
474 startObject();
475 addLabel(encodeAttribute(name));
476 addValue(valueToAdd, Type.STRING);
477 }
478 return requiredState;
479 }
480 // fall through
481 case STATE_NEXT_ATTRIBUTE:
482 switch(requiredState) {
483 case STATE_END_ATTRIBUTES:
484 if ((mode & EXPLICIT_MODE) != 0) {
485 if (currentState == STATE_NEXT_ATTRIBUTE) {
486 endObject();
487 }
488 endArray();
489 nextElement();
490 startArray();
491 }
492 return requiredState;
493 case STATE_NEXT_ATTRIBUTE:
494 if (!isArray || (mode & EXPLICIT_MODE) != 0) {
495 nextElement();
496 String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "" ) + elementToAdd;
497 addLabel(encodeAttribute(name));
498 addValue(valueToAdd, Type.STRING);
499 }
500 return requiredState;
501 case STATE_SET_VALUE:
502 case STATE_START_OBJECT:
503 currentState = handleStateTransition(currentState, STATE_END_ATTRIBUTES, null, null);
504 currentState = handleStateTransition(currentState, STATE_START_ELEMENTS, null, null);
505 switch (requiredState) {
506 case STATE_SET_VALUE:
507 if ((mode & EXPLICIT_MODE) == 0) {
508 addLabel(encodeNode("$"));
509 }
510 currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, valueToAdd);
511 if ((mode & EXPLICIT_MODE) == 0) {
512 endObject();
513 }
514 break;
515 case STATE_START_OBJECT:
516 currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, (mode & EXPLICIT_MODE) == 0 ? "" : null);
517 break;
518 case STATE_END_OBJECT:
519 currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, null);
520 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
521 break;
522 }
523 return requiredState;
524 case STATE_NEXT_ELEMENT:
525 currentState = handleStateTransition(currentState, STATE_END_ATTRIBUTES, null, null);
526 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
527 return requiredState;
528 case STATE_ROOT:
529 currentState = handleStateTransition(currentState, STATE_END_ATTRIBUTES, null, null);
530 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
531 currentState = handleStateTransition(currentState, STATE_ROOT, null, null);
532 return requiredState;
533 default:
534 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
535 }
536
537 case STATE_END_ATTRIBUTES:
538 switch(requiredState) {
539 case STATE_START_ELEMENTS:
540 if ((mode & EXPLICIT_MODE) == 0) {
541 nextElement();
542 }
543 break;
544 case STATE_END_OBJECT:
545 currentState = handleStateTransition(STATE_START_ELEMENTS, STATE_END_ELEMENTS, null, null);
546 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
547 break;
548 default:
549 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
550 }
551 return requiredState;
552
553 case STATE_SET_VALUE:
554 switch(requiredState) {
555 case STATE_END_ELEMENTS:
556 if ((mode & EXPLICIT_MODE) == 0 && isArray) {
557 endArray();
558 }
559 return requiredState;
560 case STATE_NEXT_ELEMENT:
561 currentState = handleStateTransition(currentState, STATE_END_ELEMENTS, null, null);
562 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
563 return requiredState;
564 case STATE_ROOT:
565 currentState = handleStateTransition(currentState, STATE_END_ELEMENTS, null, null);
566 currentState = handleStateTransition(currentState, STATE_END_OBJECT, null, null);
567 currentState = handleStateTransition(currentState, STATE_ROOT, null, null);
568 return requiredState;
569 default:
570 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
571 }
572 }
573
574 throw new IllegalWriterStateException(currentState, requiredState, elementToAdd);
575 }
576
577 /**
578 * Method to return the appropriate JSON type for a Java type.
579 *
580 * @param clazz the type
581 * @return One of the {@link Type} instances
582 * @since 1.4.4
583 */
584 protected Type getType(Class clazz) {
585 return clazz == Mapper.Null.class
586 ? Type.NULL
587 : (clazz == Boolean.class || clazz == Boolean.TYPE)
588 ? Type.BOOLEAN
589 : NUMBER_TYPES.contains(clazz)
590 ? Type.NUMBER
591 : Type.STRING;
592 }
593
594 /**
595 * Method to declare various Java types to be handles as JSON array.
596 *
597 * @param clazz the type
598 * @return <code>true</code> if handles as array
599 * @since 1.4
600 */
601 protected boolean isArray(Class clazz) {
602 return clazz != null && (clazz.isArray()
603 || Collection.class.isAssignableFrom(clazz)
604 || Externalizable.class.isAssignableFrom(clazz)
605 || Map.class.isAssignableFrom(clazz)
606 || Map.Entry.class.isAssignableFrom(clazz));
607 }
608
609 /**
610 * Start a JSON object.
611 *
612 * @since 1.4
613 */
614 protected abstract void startObject();
615
616 /**
617 * Add a label to a JSON object.
618 *
619 * @param name the label's name
620 * @since 1.4
621 */
622 protected abstract void addLabel(String name);
623
624 /**
625 * Add a value to a JSON object's label or to an array.
626 *
627 * @param value the value itself
628 * @param type the JSON type
629 * @since 1.4
630 */
631 protected abstract void addValue(String value, Type type);
632
633 /**
634 * Start a JSON array.
635 *
636 * @since 1.4
637 */
638 protected abstract void startArray();
639
640 /**
641 * Prepare a JSON object or array for another element.
642 *
643 * @since 1.4
644 */
645 protected abstract void nextElement();
646
647 /**
648 * End the JSON array.
649 *
650 * @since 1.4
651 */
652 protected abstract void endArray();
653
654 /**
655 * End the JSON object.
656 *
657 * @since 1.4
658 */
659 protected abstract void endObject();
660 }
0 /*
1 * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013 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 30. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import com.thoughtworks.xstream.io.AbstractDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.StreamException;
16 import com.thoughtworks.xstream.io.xml.QNameMap;
17 import com.thoughtworks.xstream.io.xml.StaxReader;
18 import com.thoughtworks.xstream.io.xml.StaxWriter;
19
20 import org.codehaus.jettison.mapped.Configuration;
21 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
22 import org.codehaus.jettison.mapped.MappedXMLInputFactory;
23 import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
24
25 import javax.xml.stream.XMLStreamException;
26
27 import java.io.File;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.io.Reader;
33 import java.io.Writer;
34 import java.net.URL;
35
36
37 /**
38 * Simple XStream driver wrapping Jettison's Mapped reader and writer. Serializes object from
39 * and to JSON.
40 *
41 * @author Dejan Bosanac
42 */
43 public class JettisonMappedXmlDriver extends AbstractDriver {
44
45 protected final MappedXMLOutputFactory mof;
46 protected final MappedXMLInputFactory mif;
47 protected final MappedNamespaceConvention convention;
48 protected final boolean useSerializeAsArray;
49
50 /**
51 * Construct a JettisonMappedXmlDriver.
52 */
53 public JettisonMappedXmlDriver() {
54 this(new Configuration());
55 }
56
57 /**
58 * Construct a JettisonMappedXmlDriver with configuration.
59 * @param config the Jettison configuration
60 */
61 public JettisonMappedXmlDriver(final Configuration config) {
62 this(config, true);
63 }
64
65 /**
66 * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added
67 * by special request of Jettison users to support JSON generated by older Jettison
68 * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is
69 * neither support from XStream's side nor are there any tests to ensure this mode.
70 *
71 * @param config the Jettison configuration
72 * @param useSerializeAsArray flag to use XStream's hints for collections and arrays
73 * @since 1.4
74 */
75 public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) {
76 mof = new MappedXMLOutputFactory(config);
77 mif = new MappedXMLInputFactory(config);
78 convention = new MappedNamespaceConvention(config);
79 this.useSerializeAsArray = useSerializeAsArray;
80 }
81
82 public HierarchicalStreamReader createReader(final Reader reader) {
83 try {
84 return new StaxReader(new QNameMap(), mif.createXMLStreamReader(reader), getNameCoder());
85 } catch (final XMLStreamException e) {
86 throw new StreamException(e);
87 }
88 }
89
90 public HierarchicalStreamReader createReader(final InputStream input) {
91 try {
92 return new StaxReader(new QNameMap(), mif.createXMLStreamReader(input), getNameCoder());
93 } catch (final XMLStreamException e) {
94 throw new StreamException(e);
95 }
96 }
97
98 public HierarchicalStreamReader createReader(URL in) {
99 InputStream instream = null;
100 try {
101 instream = in.openStream();
102 return new StaxReader(new QNameMap(), mif.createXMLStreamReader(
103 in.toExternalForm(), instream), getNameCoder());
104 } catch (final XMLStreamException e) {
105 throw new StreamException(e);
106 } catch (IOException e) {
107 throw new StreamException(e);
108 } finally {
109 if (instream != null) {
110 try {
111 instream.close();
112 } catch (IOException e) {
113 // ignore
114 }
115 }
116 }
117 }
118
119 public HierarchicalStreamReader createReader(File in) {
120 InputStream instream = null;
121 try {
122 instream = new FileInputStream(in);
123 return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in
124 .toURI()
125 .toASCIIString(), instream), getNameCoder());
126 } catch (final XMLStreamException e) {
127 throw new StreamException(e);
128 } catch (IOException e) {
129 throw new StreamException(e);
130 } finally {
131 if (instream != null) {
132 try {
133 instream.close();
134 } catch (IOException e) {
135 // ignore
136 }
137 }
138 }
139 }
140
141 public HierarchicalStreamWriter createWriter(final Writer writer) {
142 try {
143 if (useSerializeAsArray) {
144 return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder(), convention);
145 } else {
146 return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder());
147 }
148 } catch (final XMLStreamException e) {
149 throw new StreamException(e);
150 }
151 }
152
153 public HierarchicalStreamWriter createWriter(final OutputStream output) {
154 try {
155 if (useSerializeAsArray) {
156 return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), getNameCoder(), convention);
157 } else {
158 return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), getNameCoder());
159 }
160 } catch (final XMLStreamException e) {
161 throw new StreamException(e);
162 }
163 }
164
165 }
0 /*
1 * Copyright (c) 2008, 2009, 2010, 2011 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 17.04.2008 by Joerg Schaible.
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import com.thoughtworks.xstream.io.naming.NameCoder;
13 import com.thoughtworks.xstream.io.xml.QNameMap;
14 import com.thoughtworks.xstream.io.xml.StaxWriter;
15 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
16
17 import org.codehaus.jettison.AbstractXMLStreamWriter;
18 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
19
20 import javax.xml.namespace.QName;
21 import javax.xml.stream.XMLStreamException;
22 import javax.xml.stream.XMLStreamWriter;
23
24 import java.util.Collection;
25 import java.util.Map;
26
27
28 /**
29 * A specialized {@link StaxWriter} that makes usage of internal functionality of Jettison.
30 *
31 * @author J&ouml;rg Schaible
32 * @since 1.3.1
33 */
34 public class JettisonStaxWriter extends StaxWriter {
35
36 private final MappedNamespaceConvention convention;
37
38 /**
39 * @since 1.4
40 */
41 public JettisonStaxWriter(
42 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
43 boolean namespaceRepairingMode, NameCoder nameCoder,
44 MappedNamespaceConvention convention) throws XMLStreamException {
45 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, nameCoder);
46 this.convention = convention;
47 }
48
49 /**
50 * @deprecated As of 1.4 use
51 * {@link JettisonStaxWriter#JettisonStaxWriter(QNameMap, XMLStreamWriter, boolean, boolean, NameCoder, MappedNamespaceConvention)}
52 * instead
53 */
54 public JettisonStaxWriter(
55 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
56 boolean namespaceRepairingMode, XmlFriendlyReplacer replacer,
57 MappedNamespaceConvention convention) throws XMLStreamException {
58 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder) replacer, convention);
59 }
60
61 public JettisonStaxWriter(
62 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
63 boolean namespaceRepairingMode, MappedNamespaceConvention convention)
64 throws XMLStreamException {
65 super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode);
66 this.convention = convention;
67 }
68
69 public JettisonStaxWriter(
70 QNameMap qnameMap, XMLStreamWriter out, MappedNamespaceConvention convention)
71 throws XMLStreamException {
72 super(qnameMap, out);
73 this.convention = convention;
74 }
75
76 /**
77 * @since 1.4
78 */
79 public JettisonStaxWriter(
80 QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder, MappedNamespaceConvention convention)
81 throws XMLStreamException {
82 super(qnameMap, out, nameCoder);
83 this.convention = convention;
84 }
85
86 public void startNode(String name, Class clazz) {
87 XMLStreamWriter out = getXMLStreamWriter();
88 if (clazz != null && out instanceof AbstractXMLStreamWriter) {
89 if (Collection.class.isAssignableFrom(clazz)
90 || Map.class.isAssignableFrom(clazz)
91 || clazz.isArray()) {
92 QName qname = getQNameMap().getQName(encodeNode(name));
93 String prefix = qname.getPrefix();
94 String uri = qname.getNamespaceURI();
95 String key = convention.createKey(prefix, uri, qname.getLocalPart());
96 if (!((AbstractXMLStreamWriter)out).getSerializedAsArrays().contains(key)) {
97 // Typo is in the API of Jettison ...
98 ((AbstractXMLStreamWriter)out).seriliazeAsArray(key);
99 }
100 }
101 }
102 startNode(name);
103 }
104 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011 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 22. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.json;
12
13 import com.thoughtworks.xstream.io.AbstractDriver;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
16 import com.thoughtworks.xstream.io.StreamException;
17 import com.thoughtworks.xstream.io.naming.NameCoder;
18
19 import java.io.File;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.io.OutputStreamWriter;
23 import java.io.Reader;
24 import java.io.UnsupportedEncodingException;
25 import java.io.Writer;
26 import java.net.URL;
27
28 /**
29 * A driver for JSON that writes optimized JSON format, but is not able to deserialize the result.
30 *
31 * @author Paul Hammant
32 * @since 1.2
33 */
34 public class JsonHierarchicalStreamDriver extends AbstractDriver {
35
36 /**
37 * Construct a JsonHierarchicalStreamDriver.
38 */
39 public JsonHierarchicalStreamDriver() {
40 super();
41 }
42
43 /**
44 * Construct a JsonHierarchicalStreamDriver with name coding.
45 *
46 * @param nameCoder the coder to encode and decode the JSON labels.
47 * @since 1.4.2
48 */
49 public JsonHierarchicalStreamDriver(NameCoder nameCoder) {
50 super(nameCoder);
51 }
52
53 public HierarchicalStreamReader createReader(Reader in) {
54 throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON");
55 }
56
57 public HierarchicalStreamReader createReader(InputStream in) {
58 throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON");
59 }
60
61 public HierarchicalStreamReader createReader(URL in) {
62 throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON");
63 }
64
65 public HierarchicalStreamReader createReader(File in) {
66 throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON");
67 }
68
69 /**
70 * Create a HierarchicalStreamWriter that writes JSON.
71 */
72 public HierarchicalStreamWriter createWriter(Writer out) {
73 return new JsonWriter(out);
74 }
75
76 public HierarchicalStreamWriter createWriter(OutputStream out) {
77 try {
78 // JSON spec requires UTF-8
79 return createWriter(new OutputStreamWriter(out, "UTF-8"));
80 } catch (UnsupportedEncodingException e) {
81 throw new StreamException(e);
82 }
83 }
84
85 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 22. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.json;
12
13 import java.io.Writer;
14
15
16 /**
17 * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets
18 * rely on you NOT using XStream.addImplicitCollection(..)
19 *
20 * @author Paul Hammant
21 * @author J&ouml;rg Schaible
22 * @since 1.2
23 * @deprecated As of 1.3.1, use JsonWriter instead
24 */
25 public class JsonHierarchicalStreamWriter extends JsonWriter {
26
27 /**
28 * @deprecated As of 1.3.1, use JsonWriter instead
29 */
30 public JsonHierarchicalStreamWriter(Writer writer, char[] lineIndenter, String newLine) {
31 super(writer, lineIndenter, newLine);
32 }
33
34 /**
35 * @deprecated As of 1.3.1, use JsonWriter instead
36 */
37 public JsonHierarchicalStreamWriter(Writer writer, char[] lineIndenter) {
38 this(writer, lineIndenter, "\n");
39 }
40
41 /**
42 * @deprecated As of 1.3.1, use JsonWriter instead
43 */
44 public JsonHierarchicalStreamWriter(Writer writer, String lineIndenter, String newLine) {
45 this(writer, lineIndenter.toCharArray(), newLine);
46 }
47
48 /**
49 * @deprecated As of 1.3.1, use JsonWriter instead
50 */
51 public JsonHierarchicalStreamWriter(Writer writer, String lineIndenter) {
52 this(writer, lineIndenter.toCharArray());
53 }
54
55 /**
56 * @deprecated As of 1.3.1, use JsonWriter instead
57 */
58 public JsonHierarchicalStreamWriter(Writer writer) {
59 this(writer, new char[]{' ', ' '});
60 }
61 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 28. November 2008 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.io.json;
12
13 import java.io.Writer;
14
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.core.util.QuickWriter;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18 import com.thoughtworks.xstream.io.naming.NameCoder;
19 import com.thoughtworks.xstream.io.naming.NoNameCoder;
20
21
22 /**
23 * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets
24 * rely on you NOT using XStream.addImplicitCollection(..).
25 *
26 * @author Paul Hammant
27 * @author J&ouml;rg Schaible
28 * @since 1.3.1
29 */
30 public class JsonWriter extends AbstractJsonWriter {
31
32 protected final QuickWriter writer;
33 protected final Format format;
34 private int depth;
35 private boolean newLineProposed;
36
37 /**
38 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead}
39 */
40 public JsonWriter(Writer writer, char[] lineIndenter, String newLine) {
41 this(writer, 0, new Format(
42 lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL
43 | Format.COMPACT_EMPTY_ELEMENT));
44 }
45
46 /**
47 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead}
48 */
49 public JsonWriter(Writer writer, char[] lineIndenter) {
50 this(writer, 0, new Format(lineIndenter, new char[]{'\n'}, Format.SPACE_AFTER_LABEL
51 | Format.COMPACT_EMPTY_ELEMENT));
52 }
53
54 /**
55 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead}
56 */
57 public JsonWriter(Writer writer, String lineIndenter, String newLine) {
58 this(writer, 0, new Format(
59 lineIndenter.toCharArray(), newLine.toCharArray(), Format.SPACE_AFTER_LABEL
60 | Format.COMPACT_EMPTY_ELEMENT));
61 }
62
63 /**
64 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead}
65 */
66 public JsonWriter(Writer writer, String lineIndenter) {
67 this(writer, 0, new Format(
68 lineIndenter.toCharArray(), new char[]{'\n'}, Format.SPACE_AFTER_LABEL
69 | Format.COMPACT_EMPTY_ELEMENT));
70 }
71
72 public JsonWriter(Writer writer) {
73 this(writer, 0, new Format(
74 new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL
75 | Format.COMPACT_EMPTY_ELEMENT));
76 }
77
78 /**
79 * @since 1.3.1
80 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, int, Format) instead}
81 */
82 public JsonWriter(Writer writer, char[] lineIndenter, String newLine, int mode) {
83 this(writer, mode, new Format(
84 lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL
85 | Format.COMPACT_EMPTY_ELEMENT));
86 }
87
88 /**
89 * Create a JsonWriter where the writer mode can be chosen.
90 *
91 * @param writer the {@link Writer} where the JSON is written to
92 * @param mode the JsonWriter mode
93 * @since 1.3.1
94 * @see #JsonWriter(Writer, int, Format)
95 */
96 public JsonWriter(Writer writer, int mode) {
97 this(writer, mode, new Format());
98 }
99
100 /**
101 * Create a JsonWriter where the format is provided.
102 *
103 * @param writer the {@link Writer} where the JSON is written to
104 * @param format the JSON format definition
105 * @since 1.4
106 * @see #JsonWriter(Writer, int, Format)
107 */
108 public JsonWriter(Writer writer, Format format) {
109 this(writer, 0, format);
110 }
111
112 /**
113 * Create a JsonWriter where the writer mode can be chosen and the format definition is
114 * provided.
115 * <p>
116 * Following constants can be used as bit mask for the mode:
117 * </p>
118 * <ul>
119 * <li>{@link #DROP_ROOT_MODE}: drop the root node</li>
120 * <li>{@link #STRICT_MODE}: do not throw {@link ConversionException}, if writer should
121 * generate invalid JSON</li>
122 * <li>{@link #EXPLICIT_MODE}: ensure that all available data is explicitly written even if
123 * addition objects must be added</li>
124 * </ul>
125 *
126 * @param writer the {@link Writer} where the JSON is written to
127 * @param mode the JsonWriter mode
128 * @param format the JSON format definition
129 * @since 1.4
130 */
131 public JsonWriter(Writer writer, int mode, Format format) {
132 this(writer, mode, format, 1024);
133 }
134
135 /**
136 * Create a JsonWriter.
137 *
138 * @param writer the {@link Writer} where the JSON is written to
139 * @param mode the JsonWriter mode
140 * @param format the JSON format definition
141 * @param bufferSize the buffer size of the internally used QuickWriter
142 * @see JsonWriter#JsonWriter(Writer, int, Format)
143 * @since 1.4
144 */
145 public JsonWriter(Writer writer, int mode, Format format, int bufferSize) {
146 super(mode, format.getNameCoder());
147 this.writer = new QuickWriter(writer, bufferSize);
148 this.format = format;
149 depth = (mode & DROP_ROOT_MODE) == 0 ? -1 : 0;
150 }
151
152 public void flush() {
153 writer.flush();
154 }
155
156 public void close() {
157 writer.close();
158 }
159
160 public HierarchicalStreamWriter underlyingWriter() {
161 return this;
162 }
163
164 /**
165 * {@inheritDoc}
166 */
167 protected void startObject() {
168 if (newLineProposed) {
169 writeNewLine();
170 }
171 writer.write('{');
172 startNewLine();
173 }
174
175 /**
176 * {@inheritDoc}
177 */
178 protected void addLabel(String name) {
179 if (newLineProposed) {
180 writeNewLine();
181 }
182 writer.write('"');
183 writeText(name);
184 writer.write("\":");
185 if ((format.mode() & Format.SPACE_AFTER_LABEL) != 0) {
186 writer.write(' ');
187 }
188 }
189
190 /**
191 * {@inheritDoc}
192 */
193 protected void addValue(String value, Type type) {
194 if (newLineProposed) {
195 writeNewLine();
196 }
197 if (type == Type.STRING) {
198 writer.write('"');
199 }
200 writeText(value);
201 if (type == Type.STRING) {
202 writer.write('"');
203 }
204 }
205
206 /**
207 * {@inheritDoc}
208 */
209 protected void startArray() {
210 if (newLineProposed) {
211 writeNewLine();
212 }
213 writer.write("[");
214 startNewLine();
215 }
216
217 /**
218 * {@inheritDoc}
219 */
220 protected void nextElement() {
221 writer.write(",");
222 writeNewLine();
223 }
224
225 /**
226 * {@inheritDoc}
227 */
228 protected void endArray() {
229 endNewLine();
230 writer.write("]");
231 }
232
233 /**
234 * {@inheritDoc}
235 */
236 protected void endObject() {
237 endNewLine();
238 writer.write("}");
239 }
240
241 private void startNewLine() {
242 if ( ++depth > 0) {
243 newLineProposed = true;
244 }
245 }
246
247 private void endNewLine() {
248 if (depth-- > 0) {
249 if (((format.mode() & Format.COMPACT_EMPTY_ELEMENT) != 0) && newLineProposed) {
250 newLineProposed = false;
251 } else {
252 writeNewLine();
253 }
254 }
255 }
256
257 private void writeNewLine() {
258 int depth = this.depth;
259 writer.write(format.getNewLine());
260 while (depth-- > 0) {
261 writer.write(format.getLineIndenter());
262 }
263 newLineProposed = false;
264 }
265
266 private void writeText(String text) {
267 int length = text.length();
268 for (int i = 0; i < length; i++ ) {
269 char c = text.charAt(i);
270 switch (c) {
271 case '"':
272 this.writer.write("\\\"");
273 break;
274 case '\\':
275 this.writer.write("\\\\");
276 break;
277 // turn this off - it is no CTRL char anyway
278 // case '/':
279 // this.writer.write("\\/");
280 // break;
281 case '\b':
282 this.writer.write("\\b");
283 break;
284 case '\f':
285 this.writer.write("\\f");
286 break;
287 case '\n':
288 this.writer.write("\\n");
289 break;
290 case '\r':
291 this.writer.write("\\r");
292 break;
293 case '\t':
294 this.writer.write("\\t");
295 break;
296 default:
297 if (c > 0x1f) {
298 this.writer.write(c);
299 } else {
300 this.writer.write("\\u");
301 String hex = "000" + Integer.toHexString(c);
302 this.writer.write(hex.substring(hex.length() - 4));
303 }
304 }
305 }
306 }
307
308 /**
309 * Format definition for JSON.
310 *
311 * @author J&ouml;rg Schaible
312 * @since 1.4
313 */
314 public static class Format {
315
316 public static int SPACE_AFTER_LABEL = 1;
317 public static int COMPACT_EMPTY_ELEMENT = 2;
318
319 private char[] lineIndenter;
320 private char[] newLine;
321 private final int mode;
322 private final NameCoder nameCoder;
323
324 /**
325 * Create a new default Formatter. The formatter uses two spaces, normal line feed
326 * character, adds a space after the label and will try to compact the output.
327 *
328 * @since 1.4.2
329 */
330 public Format() {
331 this(new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL
332 | Format.COMPACT_EMPTY_ELEMENT);
333 }
334
335
336 /**
337 * Create a new Formatter.
338 *
339 * @param lineIndenter the characters used for indenting the line
340 * @param newLine the characters used to create a new line
341 * @param mode the flags for the format modes
342 * @since 1.4
343 */
344 public Format(char[] lineIndenter, char[] newLine, int mode) {
345 this(lineIndenter, newLine, mode, new NoNameCoder());
346 }
347
348 /**
349 * Create a new Formatter.
350 *
351 * @param lineIndenter the characters used for indenting the line
352 * @param newLine the characters used to create a new line
353 * @param mode the flags for the format modes
354 * @param nameCoder the name encoder and decoder
355 * @since 1.4.2
356 */
357 public Format(char[] lineIndenter, char[] newLine, int mode, NameCoder nameCoder) {
358 this.lineIndenter = lineIndenter;
359 this.newLine = newLine;
360 this.mode = mode;
361 this.nameCoder = nameCoder;
362 }
363
364 /**
365 * Retrieve the lineIndenter.
366 *
367 * @return the lineIndenter
368 * @since 1.4
369 */
370 public char[] getLineIndenter() {
371 return this.lineIndenter;
372 }
373
374 /**
375 * Retrieve the newLine.
376 *
377 * @return the newLine
378 * @since 1.4
379 */
380 public char[] getNewLine() {
381 return this.newLine;
382 }
383
384 /**
385 * Retrieve the mode flags of the formatter.
386 *
387 * @return the mode
388 * @since 1.4
389 */
390 public int mode() {
391 return this.mode;
392 }
393
394
395 /**
396 * Retrieve the NameCoder.
397 *
398 * @return the name coder
399 * @since 1.4.2
400 */
401 public NameCoder getNameCoder() {
402 return nameCoder;
403 }
404 }
405 }
0 /*
1 * Copyright (C) 2009, 2011 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 14. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.naming;
11
12 /**
13 * Coder between names in the object graph and names of a target format.
14 * <p>
15 * The names form the object graph are typically names generated from Java identifiers (Java
16 * types or field members), but some names may also contain a minus sign. However, the original
17 * name might have already been aliased, so a wider range of characters can occur.
18 * </p>
19 * <p>
20 * The target names should satisfy the syntax of the target format. Transforming Java objects to
21 * XML this affects names that contain or even start with a dollar sign. Such names violate the
22 * XML specification.
23 * </p>
24 * <p>
25 * By default all names from the object graph are used as node names in the target format.
26 * Meta-data that is necessary to unmarshal the object again is typically written as attribute.
27 * Since such attributes might be represented differently in the target format, the NameCoder
28 * distinguishes between the names used for meta-data elements and the ones for the object data.
29 * The names in the target format might even have to follow a different syntax. Remember, that
30 * XStream can be easily configured to write also object data as attributes.
31 * </p>
32 * <p>
33 * Note that the instance of a NameCoder should be either thread-safe or implement {@link Cloneable}.
34 * </p>
35 *
36 * @author J&ouml;rg Schaible
37 * @since 1.4
38 */
39 public interface NameCoder {
40 /**
41 * Encode an object name for a node in the target format.
42 *
43 * @param name the name of the object data
44 * @return the node name in the target format
45 * @since 1.4
46 */
47 String encodeNode(String name);
48
49 /**
50 * Encode a meta-data name for an attribute in the target format.
51 *
52 * @param name the name of the meta-data
53 * @return the attribute name in the target format
54 * @since 1.4
55 */
56 String encodeAttribute(String name);
57
58 /**
59 * Decode a node name to an object name.
60 *
61 * @param nodeName the name of the node
62 * @return the name of the object
63 * @since 1.4
64 */
65 String decodeNode(String nodeName);
66
67 /**
68 * Decode an attribute name to an object name.
69 *
70 * @param attributeName the name of the attribute
71 * @return the name of the meta-data
72 * @since 1.4
73 */
74 String decodeAttribute(String attributeName);
75 }
0 /*
1 * Copyright (C) 2009, 2011 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 15. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.naming;
11
12 /**
13 * A wrapper for another NameCoder.
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.4
17 */
18 public class NameCoderWrapper implements NameCoder {
19
20 private final NameCoder wrapped;
21
22 /**
23 * Construct a new wrapper for a NameCoder.
24 *
25 * @param inner the wrapped NameCoder
26 * @since 1.4
27 */
28 public NameCoderWrapper(NameCoder inner) {
29 this.wrapped = inner;
30 }
31
32 /**
33 * {@inheritDoc}
34 */
35 public String decodeAttribute(String attributeName) {
36 return wrapped.decodeAttribute(attributeName);
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public String decodeNode(String nodeName) {
43 return wrapped.decodeNode(nodeName);
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public String encodeAttribute(String name) {
50 return wrapped.encodeAttribute(name);
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 public String encodeNode(String name) {
57 return wrapped.encodeNode(name);
58 }
59
60 }
0 /*
1 * Copyright (C) 2009, 2011 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 15. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.naming;
11
12 /**
13 * A NameCoder that does nothing.
14 * <p>
15 * The usage of this implementation implies that the names used for the objects can also be used
16 * in the target format without any change. This applies also for XML if the object graph
17 * contains no object that is an instance of an inner class type or is in the default package.
18 * </p>
19 *
20 * @author J&ouml;rg Schaiblea
21 * @since 1.4
22 */
23 public class NoNameCoder implements NameCoder {
24
25 /**
26 * {@inheritDoc}
27 */
28 public String decodeAttribute(String attributeName) {
29 return attributeName;
30 }
31
32 /**
33 * {@inheritDoc}
34 */
35 public String decodeNode(String nodeName) {
36 return nodeName;
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 public String encodeAttribute(String name) {
43 return name;
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public String encodeNode(String name) {
50 return name;
51 }
52
53 }
0 /*
1 * Copyright (C) 2009, 2011 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 15. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.naming;
11
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import java.util.Map;
15
16
17 /**
18 * A NameCoder that encodes and decodes names based on a map.
19 * <p>
20 * The provided map should contain a mapping between the name of the Java type or field to the
21 * proper element in the target format. If a name cannot be found in the map, it is assumed not
22 * to be mapped at all. Note that the values of the map should be unique also, otherwise the
23 * decoding will produce wrong results.
24 * </p>
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.4
28 */
29 public class StaticNameCoder implements NameCoder {
30
31 private final Map java2Node;
32 private final Map java2Attribute;
33
34 private transient Map node2Java;
35 private transient Map attribute2Java;
36
37 /**
38 * Construct a StaticNameCoder.
39 *
40 * @param java2Node mapping of Java names to nodes
41 * @param java2Attribute mapping of Java names to attributes
42 * @since 1.4
43 */
44 public StaticNameCoder(Map java2Node, Map java2Attribute) {
45 this.java2Node = new HashMap(java2Node);
46 if (java2Node == java2Attribute || java2Attribute == null) {
47 this.java2Attribute = this.java2Node;
48 } else {
49 this.java2Attribute = new HashMap(java2Attribute);
50 }
51 readResolve();
52 }
53
54 /**
55 * {@inheritDoc}
56 */
57 public String decodeAttribute(String attributeName) {
58 String name = (String)attribute2Java.get(attributeName);
59 return name == null ? attributeName : name;
60 }
61
62 /**
63 * {@inheritDoc}
64 */
65 public String decodeNode(String nodeName) {
66 String name = (String)node2Java.get(nodeName);
67 return name == null ? nodeName : name;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 public String encodeAttribute(String name) {
74 String friendlyName = (String)java2Attribute.get(name);
75 return friendlyName == null ? name : friendlyName;
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 public String encodeNode(String name) {
82 String friendlyName = (String)java2Node.get(name);
83 return friendlyName == null ? name : friendlyName;
84 }
85
86 private Object readResolve() {
87 node2Java = invertMap(java2Node);
88 if (java2Node == java2Attribute) {
89 attribute2Java = node2Java;
90 } else {
91 attribute2Java = invertMap(java2Attribute);
92 }
93 return this;
94 }
95
96 private Map invertMap(Map map) {
97 Map inverseMap = new HashMap(map.size());
98 for (final Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
99 final Map.Entry entry = (Map.Entry)iter.next();
100 inverseMap.put((String)entry.getValue(), (String)entry.getKey());
101 }
102 return inverseMap;
103 }
104 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2013 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import com.thoughtworks.xstream.core.util.FastStack;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 /**
19 * Represents a path to a single node in the tree.
20 *
21 * <p>Two absolute paths can also be compared to calculate the relative path between them.
22 * A relative path can be applied to an absolute path to calculate another absolute path.</p>
23 *
24 * <p>Note that the paths are normally XPath compliant, so can be read by other XPath engines.
25 * However, {@link #toString()} will select a node list while {@link #explicit()} will always select
26 * an individual node. If the return type of the XPath evaluation is a node, the result will be the same,
27 * because XPath will then use the first element of the list. The following are examples of path
28 * expressions that the Path object supports:</p>
29 *
30 * <p>Note that the implementation does not take care if the paths are XPath compliant, it simply
31 * manages the values between the path separator. However, it normalizes the path if a path element
32 * ends with a selector for the first element (i.e. "[1]"). Those will be handled transparent i.e. two Paths
33 * are treated equal if one was created with path elements containing this selector and the other one
34 * without.</p>
35 *
36 * <p>The following are examples of path expressions that the Path object supports:</p>
37 * <ul>
38 * <li>/</li>
39 * <li>/some/node</li>
40 * <li>/a/b/c/b/a</li>
41 * <li>/a/b[1]/c[1]/b[1]/a[1]</li>
42 * <li>/some[3]/node[2]/a</li>
43 * <li>../../../another[3]/node</li>
44 * </ul>
45 *
46 * <h3>Example</h3>
47 *
48 * <pre>
49 * Path a = new Path("/html/body/div[1]/table[2]/tr[3]/td/div");
50 * Path b = new Path("/html/body/div/table[2]/tr[6]/td/form");
51 *
52 * Path relativePath = a.relativeTo(b); // produces: "../../../tr[6]/td/form"
53 * Path c = a.apply(relativePath); // same as Path b.
54 * </pre>
55 *
56 * @see PathTracker
57 *
58 * @author Joe Walnes
59 */
60 public class Path {
61
62 private final String[] chunks;
63 private transient String pathAsString;
64 private transient String pathExplicit;
65 private static final Path DOT = new Path(new String[] {"."});
66
67 public Path(String pathAsString) {
68 // String.split() too slow. StringTokenizer too crappy.
69 List result = new ArrayList();
70 int currentIndex = 0;
71 int nextSeparator;
72 this.pathAsString = pathAsString;
73 while ((nextSeparator = pathAsString.indexOf('/', currentIndex)) != -1) {
74 // normalize explicit paths
75 result.add(normalize(pathAsString, currentIndex, nextSeparator));
76 currentIndex = nextSeparator + 1;
77 }
78 result.add(normalize(pathAsString,currentIndex,pathAsString.length()));
79 String[] arr = new String[result.size()];
80 result.toArray(arr);
81 chunks = arr;
82 }
83
84 private String normalize(String s, int start, int end) {
85 if (end - start > 3
86 && s.charAt(end-3) == '['
87 && s.charAt(end-2) == '1'
88 && s.charAt(end-1) == ']') {
89 this.pathAsString = null;
90 return s.substring(start, end-3);
91 } else {
92 return s.substring(start, end);
93 }
94
95 }
96
97 public Path(String[] chunks) {
98 this.chunks = chunks;
99 }
100
101 public String toString() {
102 if (pathAsString == null) {
103 StringBuffer buffer = new StringBuffer();
104 for (int i = 0; i < chunks.length; i++) {
105 if (i > 0) buffer.append('/');
106 buffer.append(chunks[i]);
107 }
108 pathAsString = buffer.toString();
109 }
110 return pathAsString;
111 }
112
113 public String explicit() {
114 if (pathExplicit == null) {
115 StringBuffer buffer = new StringBuffer();
116 for (int i = 0; i < chunks.length; i++) {
117 if (i > 0) buffer.append('/');
118 String chunk = chunks[i];
119 buffer.append(chunk);
120 int length = chunk.length();
121 if (length > 0) {
122 char c = chunk.charAt(length-1);
123 if (c != ']' && c != '.') {
124 buffer.append("[1]");
125 }
126 }
127 }
128 pathExplicit = buffer.toString();
129 }
130 return pathExplicit;
131 }
132
133 public boolean equals(Object o) {
134 if (this == o) return true;
135 if (!(o instanceof Path)) return false;
136
137 final Path other = (Path) o;
138 if (chunks.length != other.chunks.length) return false;
139 for (int i = 0; i < chunks.length; i++) {
140 if (!chunks[i].equals(other.chunks[i])) return false;
141 }
142
143 return true;
144 }
145
146 public int hashCode() {
147 int result = 543645643;
148 for (int i = 0; i < chunks.length; i++) {
149 result = 29 * result + chunks[i].hashCode();
150 }
151 return result;
152 }
153
154 public Path relativeTo(Path that) {
155 int depthOfPathDivergence = depthOfPathDivergence(chunks, that.chunks);
156 String[] result = new String[chunks.length + that.chunks.length - 2 * depthOfPathDivergence];
157 int count = 0;
158
159 for (int i = depthOfPathDivergence; i < chunks.length; i++) {
160 result[count++] = "..";
161 }
162 for (int j = depthOfPathDivergence; j < that.chunks.length; j++) {
163 result[count++] = that.chunks[j];
164 }
165
166 if (count == 0) {
167 return DOT;
168 } else {
169 return new Path(result);
170 }
171 }
172
173 private int depthOfPathDivergence(String[] path1, String[] path2) {
174 int minLength = Math.min(path1.length, path2.length);
175 for (int i = 0; i < minLength; i++) {
176 if (!path1[i].equals(path2[i])) {
177 return i;
178 }
179 }
180 return minLength;
181 }
182
183 public Path apply(Path relativePath) {
184 FastStack absoluteStack = new FastStack(16);
185
186 for (int i = 0; i < chunks.length; i++) {
187 absoluteStack.push(chunks[i]);
188 }
189
190 for (int i = 0; i < relativePath.chunks.length; i++) {
191 String relativeChunk = relativePath.chunks[i];
192 if (relativeChunk.equals("..")) {
193 absoluteStack.pop();
194 } else if (!relativeChunk.equals(".")) {
195 absoluteStack.push(relativeChunk);
196 }
197 }
198
199 String[] result = new String[absoluteStack.size()];
200 for (int i = 0; i < result.length; i++) {
201 result[i] = (String) absoluteStack.get(i);
202 }
203
204 return new Path(result);
205 }
206
207 public boolean isAncestor(Path child) {
208 if (child == null || child.chunks.length < chunks.length) {
209 return false;
210 }
211 for (int i = 0; i < chunks.length; i++) {
212 if (!chunks[i].equals(child.chunks[i])) {
213 return false;
214 }
215 }
216 return true;
217 }
218 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 /**
17 * Maintains the current {@link Path} as a stream is moved through.
18 *
19 * <p>Can be linked to a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} or
20 * {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} by wrapping them with a
21 * {@link PathTrackingWriter} or {@link PathTrackingReader}.</p>
22 *
23 * <h3>Example</h3>
24 *
25 * <pre>
26 * PathTracker tracker = new PathTracker();
27 * tracker.pushElement("table");
28 * tracker.pushElement("tr");
29 * tracker.pushElement("td");
30 * tracker.pushElement("form");
31 * tracker.popElement("form");
32 * tracker.popElement("td");
33 * tracker.pushElement("td");
34 * tracker.pushElement("div");
35 *
36 * Path path = tracker.getPath(); // returns "/table/tr/td[2]/div"
37 * </pre>
38 *
39 * @see Path
40 * @see PathTrackingReader
41 * @see PathTrackingWriter
42 *
43 * @author Joe Walnes
44 */
45 public class PathTracker {
46
47 private int pointer;
48 private int capacity;
49 private String[] pathStack;
50 private Map[] indexMapStack;
51
52 private Path currentPath;
53
54 public PathTracker() {
55 this(16);
56 }
57
58 /**
59 * @param initialCapacity Size of the initial stack of nodes (one level per depth in the tree). Note that this is
60 * only for optimizations - the stack will resize itself if it exceeds its capacity. If in doubt,
61 * use the other constructor.
62 */
63 public PathTracker(int initialCapacity) {
64 this.capacity = Math.max(1, initialCapacity);
65 pathStack = new String[capacity];
66 indexMapStack = new Map[capacity];
67 }
68
69 /**
70 * Notify the tracker that the stream has moved into a new element.
71 *
72 * @param name Name of the element
73 */
74 public void pushElement(String name) {
75 if (pointer + 1 >= capacity) {
76 resizeStacks(capacity * 2);
77 }
78 pathStack[pointer] = name;
79 Map indexMap = indexMapStack[pointer];
80 if (indexMap == null) {
81 indexMap = new HashMap();
82 indexMapStack[pointer] = indexMap;
83 }
84 if (indexMap.containsKey(name)) {
85 indexMap.put(name, new Integer(((Integer) indexMap.get(name)).intValue() + 1));
86 } else {
87 indexMap.put(name, new Integer(1));
88 }
89 pointer++;
90 currentPath = null;
91 }
92
93 /**
94 * Notify the tracker that the stream has moved out of an element.
95 */
96 public void popElement() {
97 indexMapStack[pointer] = null;
98 pathStack[pointer] = null;
99 currentPath = null;
100 pointer--;
101 }
102
103 /**
104 * Get the last path element from the stack.
105 *
106 * @return the name of the path element
107 * @since 1.4.2
108 */
109 public String peekElement() {
110 return peekElement(0);
111 }
112
113 /**
114 * Get a path element from the stack.
115 *
116 * @param i path index
117 * @return the name of the path element
118 * @since 1.4.2
119 * @throws ArrayIndexOutOfBoundsException if the index is &gt;= 0 or &lt;= -depth()
120 */
121 public String peekElement(int i) {
122 if (i < -pointer || i > 0) {
123 throw new ArrayIndexOutOfBoundsException(i);
124 }
125 int idx = pointer + i - 1;
126 final String name;
127 Integer integer = ((Integer) indexMapStack[idx].get(pathStack[idx]));
128 int index = integer.intValue();
129 if (index > 1) {
130 StringBuffer chunk = new StringBuffer(pathStack[idx].length() + 6);
131 chunk.append(pathStack[idx]).append('[').append(index).append(']');
132 name = chunk.toString();
133 } else {
134 name = pathStack[idx];
135 }
136 return name;
137 }
138
139 /**
140 * Get the depth of the stack.
141 *
142 * @return the stack depth
143 * @since 1.4.2
144 */
145 public int depth() {
146 return pointer;
147 }
148
149 private void resizeStacks(int newCapacity) {
150 String[] newPathStack = new String[newCapacity];
151 Map[] newIndexMapStack = new Map[newCapacity];
152 int min = Math.min(capacity, newCapacity);
153 System.arraycopy(pathStack, 0, newPathStack, 0, min);
154 System.arraycopy(indexMapStack, 0, newIndexMapStack, 0, min);
155 pathStack = newPathStack;
156 indexMapStack = newIndexMapStack;
157 capacity = newCapacity;
158 }
159
160 /**
161 * Current Path in stream.
162 */
163 public Path getPath() {
164 if (currentPath == null) {
165 String[] chunks = new String[pointer + 1];
166 chunks[0] = "";
167 for (int i = -pointer; ++i <= 0; ) {
168 final String name = peekElement(i);
169 chunks[i + pointer] = name;
170 }
171 currentPath = new Path(chunks);
172 }
173 return currentPath;
174 }
175 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import com.thoughtworks.xstream.converters.ErrorWriter;
14 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
15 import com.thoughtworks.xstream.io.ReaderWrapper;
16
17 /**
18 * Wrapper for HierarchicalStreamReader that tracks the path (a subset of XPath) of the current node that is being read.
19 *
20 * @see PathTracker
21 * @see Path
22 *
23 * @author Joe Walnes
24 */
25 public class PathTrackingReader extends ReaderWrapper {
26
27 private final PathTracker pathTracker;
28
29 public PathTrackingReader(HierarchicalStreamReader reader, PathTracker pathTracker) {
30 super(reader);
31 this.pathTracker = pathTracker;
32 pathTracker.pushElement(getNodeName());
33 }
34
35 public void moveDown() {
36 super.moveDown();
37 pathTracker.pushElement(getNodeName());
38 }
39
40 public void moveUp() {
41 super.moveUp();
42 pathTracker.popElement();
43 }
44
45 public void appendErrors(ErrorWriter errorWriter) {
46 errorWriter.add("path", pathTracker.getPath().toString());
47 super.appendErrors(errorWriter);
48 }
49
50 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import com.thoughtworks.xstream.io.AbstractWriter;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.WriterWrapper;
16
17 /**
18 * Wrapper for HierarchicalStreamWriter that tracks the path (a subset of XPath) of the current node that is being written.
19 *
20 * @see PathTracker
21 * @see Path
22 *
23 * @author Joe Walnes
24 */
25 public class PathTrackingWriter extends WriterWrapper {
26
27 private final PathTracker pathTracker;
28 private final boolean isNameEncoding;
29
30 public PathTrackingWriter(HierarchicalStreamWriter writer, PathTracker pathTracker) {
31 super(writer);
32 this.isNameEncoding = writer.underlyingWriter() instanceof AbstractWriter;
33 this.pathTracker = pathTracker;
34 }
35
36 public void startNode(String name) {
37 pathTracker.pushElement(isNameEncoding ? ((AbstractWriter)wrapped.underlyingWriter()).encodeNode(name) : name);
38 super.startNode(name);
39 }
40
41 public void startNode(String name, Class clazz) {
42 pathTracker.pushElement(isNameEncoding ? ((AbstractWriter)wrapped.underlyingWriter()).encodeNode(name) : name);
43 super.startNode(name, clazz);
44 }
45
46 public void endNode() {
47 super.endNode();
48 pathTracker.popElement();
49 }
50 }
0 <!--
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 10. April 2004 by Joe Walnes
10 -->
11 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
12 <html>
13 <body>
14
15 <p>Library for tracking paths of nodes in documents using a subset of XPath. This subset of XPath is <i>just enough</i>
16 for XStream to be able to use XPath expressions to represent references across the object graph, while still remaining
17 very quick.</p>
18
19 <p>The <a href="Path.html">Path</a> class represents a path to a single node in the tree.
20 Two absolute paths can also be compared to calculate the relative path between them.
21 A relative path can be applied to an absolute path to calculate another absolute path.</p>
22
23 <p>A <a href="PathTracker.html">PathTracker</a> can be linked to a
24 <a href="../HierarchicalStreamWriter.html">HierarchicalStreamWriter</a> or
25 <a href="../HierarchicalStreamReader.html">HierarchicalStreamReader</a> and expose the path of wherever the node
26 is currently positioned. This is done by wrapping the HierarchicalStreamWriter/HierarchicalStreamReader instances
27 with a <a href="PathTrackingWriter.html">PathTrackingWriter</a> or <a href="PathTrackingReader.html">PathTrackingReader</a>.</p>
28
29 <p>Note that the paths produced are XPath compliant, so can be read by other XPath engines. The following are examples of path
30 expressions that the Path object supports:</p>
31
32 <ul>
33 <li>/</li>
34 <li>/some/node</li>
35 <li>/a/b/c/b/a</li>
36 <li>/some[3]/node[2]/a</li>
37 <li>../../../another[3]/node</li>
38 </ul>
39
40 </body>
41 </html>
42
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.util.Iterator;
14
15 import com.thoughtworks.xstream.converters.ErrorWriter;
16 import com.thoughtworks.xstream.core.util.FastStack;
17 import com.thoughtworks.xstream.io.AttributeNameIterator;
18 import com.thoughtworks.xstream.io.naming.NameCoder;
19
20 public abstract class AbstractDocumentReader extends AbstractXmlReader implements DocumentReader {
21
22 private FastStack pointers = new FastStack(16);
23 private Object current;
24
25 protected AbstractDocumentReader(Object rootElement) {
26 this(rootElement, new XmlFriendlyNameCoder());
27 }
28
29 /**
30 * @since 1.4
31 */
32 protected AbstractDocumentReader(Object rootElement, NameCoder nameCoder) {
33 super(nameCoder);
34 this.current = rootElement;
35 pointers.push(new Pointer());
36 reassignCurrentElement(current);
37 }
38
39 /**
40 * @since 1.2
41 * @deprecated As of 1.4, use {@link AbstractDocumentReader#AbstractDocumentReader(Object, NameCoder)} instead.
42 */
43 protected AbstractDocumentReader(Object rootElement, XmlFriendlyReplacer replacer) {
44 this(rootElement, (NameCoder)replacer);
45 }
46
47 protected abstract void reassignCurrentElement(Object current);
48 protected abstract Object getParent();
49 protected abstract Object getChild(int index);
50 protected abstract int getChildCount();
51
52 private static class Pointer {
53 public int v;
54 }
55
56 public boolean hasMoreChildren() {
57 Pointer pointer = (Pointer) pointers.peek();
58
59 if (pointer.v < getChildCount()) {
60 return true;
61 } else {
62 return false;
63 }
64 }
65
66 public void moveUp() {
67 current = getParent();
68 pointers.popSilently();
69 reassignCurrentElement(current);
70 }
71
72 public void moveDown() {
73 Pointer pointer = (Pointer) pointers.peek();
74 pointers.push(new Pointer());
75
76 current = getChild(pointer.v);
77
78 pointer.v++;
79 reassignCurrentElement(current);
80 }
81
82 public Iterator getAttributeNames() {
83 return new AttributeNameIterator(this);
84 }
85
86 public void appendErrors(ErrorWriter errorWriter) {
87 }
88
89 public Object getCurrent() {
90 return this.current;
91 }
92
93 public void close() {
94 // don't need to do anything
95 }
96 }
0 /*
1 * Copyright (C) 2006, 2007, 2009, 2011 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 18. October 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.core.util.FastStack;
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18
19 /**
20 * A generic {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} for DOM writer
21 * implementations. The implementation manages a list of top level DOM nodes. Every time the
22 * last node is closed on the node stack, the next started node is added to the list. This list
23 * can be retrieved using the {@link DocumentWriter#getTopLevelNodes()} method.
24 *
25 * @author Laurent Bihanic
26 * @author J&ouml;rg Schaible
27 * @since 1.2.1
28 */
29 public abstract class AbstractDocumentWriter extends AbstractXmlWriter implements
30 DocumentWriter {
31
32 private final List result = new ArrayList();
33 private final FastStack nodeStack = new FastStack(16);
34
35 /**
36 * Constructs an AbstractDocumentWriter.
37 *
38 * @param container the top level container for the nodes to create (may be
39 * <code>null</code>)
40 * @param nameCoder the object that creates XML-friendly names
41 * @since 1.4
42 */
43 public AbstractDocumentWriter(final Object container, final NameCoder nameCoder) {
44 super(nameCoder);
45 if (container != null) {
46 nodeStack.push(container);
47 result.add(container);
48 }
49 }
50
51 /**
52 * Constructs an AbstractDocumentWriter.
53 *
54 * @param container the top level container for the nodes to create (may be
55 * <code>null</code>)
56 * @param replacer the object that creates XML-friendly names
57 * @since 1.2.1
58 * @deprecated As of 1.4 use
59 * {@link AbstractDocumentWriter#AbstractDocumentWriter(Object, NameCoder)}
60 * instead.
61 */
62 public AbstractDocumentWriter(final Object container, final XmlFriendlyReplacer replacer) {
63 this(container, (NameCoder)replacer);
64 }
65
66 public final void startNode(final String name) {
67 final Object node = createNode(name);
68 nodeStack.push(node);
69 }
70
71 /**
72 * Create a node. The provided node name is not yet XML friendly. If {@link #getCurrent()}
73 * returns <code>null</code> the node is a top level node.
74 *
75 * @param name the node name
76 * @return the new node
77 * @since 1.2.1
78 */
79 protected abstract Object createNode(String name);
80
81 public final void endNode() {
82 endNodeInternally();
83 final Object node = nodeStack.pop();
84 if (nodeStack.size() == 0) {
85 result.add(node);
86 }
87 }
88
89 /**
90 * Called when a node ends. Hook for derived implementations.
91 *
92 * @since 1.2.1
93 */
94 public void endNodeInternally() {
95 }
96
97 /**
98 * @since 1.2.1
99 */
100 protected final Object getCurrent() {
101 return nodeStack.peek();
102 }
103
104 public List getTopLevelNodes() {
105 return result;
106 }
107
108 public void flush() {
109 // don't need to do anything
110 }
111
112 public void close() {
113 // don't need to do anything
114 }
115 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 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. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.util.Iterator;
14
15 import com.thoughtworks.xstream.core.util.FastStack;
16 import com.thoughtworks.xstream.io.AttributeNameIterator;
17 import com.thoughtworks.xstream.io.naming.NameCoder;
18
19 /**
20 * Base class that contains common functionality across HierarchicalStreamReader implementations
21 * that need to read from a pull parser.
22 *
23 * @author Joe Walnes
24 * @author James Strachan
25 */
26 public abstract class AbstractPullReader extends AbstractXmlReader {
27
28 protected static final int START_NODE = 1;
29 protected static final int END_NODE = 2;
30 protected static final int TEXT = 3;
31 protected static final int COMMENT = 4;
32 protected static final int OTHER = 0;
33
34 private final FastStack elementStack = new FastStack(16);
35 private final FastStack pool = new FastStack(16);
36
37 private final FastStack lookahead = new FastStack(4);
38 private final FastStack lookback = new FastStack(4);
39 private boolean marked;
40
41 private static class Event {
42 int type;
43 String value;
44 }
45
46 /**
47 * @since 1.4
48 */
49 protected AbstractPullReader(NameCoder nameCoder) {
50 super(nameCoder);
51 }
52
53 /**
54 * @since 1.2
55 * @deprecated As of 1.4 use {@link AbstractPullReader#AbstractPullReader(NameCoder)} instead
56 */
57 protected AbstractPullReader(XmlFriendlyReplacer replacer) {
58 this((NameCoder)replacer);
59 }
60
61
62 /**
63 * Pull the next event from the stream.
64 *
65 * <p>This MUST return {@link #START_NODE}, {@link #END_NODE}, {@link #TEXT}, {@link #COMMENT},
66 * {@link #OTHER} or throw {@link com.thoughtworks.xstream.io.StreamException}.</p>
67 *
68 * <p>The underlying pull parser will most likely return its own event types. These must be
69 * mapped to the appropriate events.</p>
70 */
71 protected abstract int pullNextEvent();
72
73 /**
74 * Pull the name of the current element from the stream.
75 */
76 protected abstract String pullElementName();
77
78 /**
79 * Pull the contents of the current text node from the stream.
80 */
81 protected abstract String pullText();
82
83 public boolean hasMoreChildren() {
84 mark();
85 while (true) {
86 switch (readEvent().type) {
87 case START_NODE:
88 reset();
89 return true;
90 case END_NODE:
91 reset();
92 return false;
93 default:
94 continue;
95 }
96 }
97 }
98
99 public void moveDown() {
100 int currentDepth = elementStack.size();
101 while (elementStack.size() <= currentDepth) {
102 move();
103 if (elementStack.size() < currentDepth) {
104 throw new RuntimeException(); // sanity check
105 }
106 }
107 }
108
109 public void moveUp() {
110 int currentDepth = elementStack.size();
111 while (elementStack.size() >= currentDepth) {
112 move();
113 }
114 }
115
116 private void move() {
117 final Event event = readEvent();
118 pool.push(event);
119 switch (event.type) {
120 case START_NODE:
121 elementStack.push(pullElementName());
122 break;
123 case END_NODE:
124 elementStack.pop();
125 break;
126 }
127 }
128
129 private Event readEvent() {
130 if (marked) {
131 if (lookback.hasStuff()) {
132 return (Event) lookahead.push(lookback.pop());
133 } else {
134 return (Event) lookahead.push(readRealEvent());
135 }
136 } else {
137 if (lookback.hasStuff()) {
138 return (Event) lookback.pop();
139 } else {
140 return readRealEvent();
141 }
142 }
143 }
144
145 private Event readRealEvent() {
146 Event event = pool.hasStuff() ? (Event)pool.pop() : new Event();
147 event.type = pullNextEvent();
148 if (event.type == TEXT) {
149 event.value = pullText();
150 } else if (event.type == START_NODE) {
151 event.value = pullElementName();
152 } else {
153 event.value = null;
154 }
155 return event;
156 }
157
158 public void mark() {
159 marked = true;
160 }
161
162 public void reset() {
163 while(lookahead.hasStuff()) {
164 lookback.push(lookahead.pop());
165 }
166 marked = false;
167 }
168
169 public String getValue() {
170 // we should collapse together any text which
171 // contains comments
172
173 // lets only use a string buffer when we get 2 strings
174 // to avoid copying strings
175 String last = null;
176 StringBuffer buffer = null;
177
178 mark();
179 Event event = readEvent();
180 while (true) {
181 if (event.type == TEXT) {
182 String text = event.value;
183 if (text != null && text.length() > 0) {
184 if (last == null) {
185 last = text;
186 } else {
187 if (buffer == null) {
188 buffer = new StringBuffer(last);
189 }
190 buffer.append(text);
191 }
192 }
193 } else if (event.type != COMMENT) {
194 break;
195 }
196 event = readEvent();
197 }
198 reset();
199 if (buffer != null) {
200 return buffer.toString();
201 } else {
202 return (last == null) ? "" : last;
203 }
204 }
205
206 public Iterator getAttributeNames() {
207 return new AttributeNameIterator(this);
208 }
209
210 public String getNodeName() {
211 return unescapeXmlName((String) elementStack.peek());
212 }
213
214 public String peekNextChild() {
215 mark();
216 while (true) {
217 Event ev = readEvent();
218 switch (ev.type) {
219 case START_NODE:
220 reset();
221 return ev.value;
222 case END_NODE:
223 reset();
224 return null;
225 default:
226 continue;
227 }
228 }
229 }
230 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 28. May 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.AbstractDriver;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16
17 /**
18 * Base class for HierarchicalStreamDrivers to use xml-based HierarchicalStreamReader and
19 * HierarchicalStreamWriter.
20 *
21 * @author Mauro Talevi
22 * @author J&ouml;rg Schaible
23 * @since 1.2
24 * @deprecated As of 1.4
25 */
26 public abstract class AbstractXmlDriver extends AbstractDriver {
27
28 /**
29 * Creates a AbstractXmlFriendlyDriver with default XmlFriendlyReplacer
30 *
31 * @deprecated As of 1.4
32 */
33 public AbstractXmlDriver() {
34 this(new XmlFriendlyNameCoder());
35 }
36
37 /**
38 * Creates a AbstractXmlFriendlyDriver with default XmlFriendlyReplacer
39 * @since 1.4
40 */
41 public AbstractXmlDriver(NameCoder nameCoder) {
42 super(nameCoder);
43 }
44
45 /**
46 * Creates a AbstractXmlFriendlyDriver with custom XmlFriendlyReplacer
47 *
48 * @param replacer the XmlFriendlyReplacer
49 * @deprecated As of 1.4
50 */
51 public AbstractXmlDriver(XmlFriendlyReplacer replacer) {
52 this((NameCoder)replacer);
53 }
54
55 /**
56 * @deprecated As of 1.4
57 */
58 protected XmlFriendlyReplacer xmlFriendlyReplacer() {
59 NameCoder nameCoder = getNameCoder();
60 return nameCoder instanceof XmlFriendlyReplacer ? (XmlFriendlyReplacer)nameCoder : null;
61 }
62
63 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 04. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.AbstractReader;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16
17 /**
18 * Abstract base implementation of HierarchicalStreamReader that provides common functionality
19 * to all XML-based readers.
20 *
21 * @author Mauro Talevi
22 * @author J&ouml;rg Schaible
23 * @since 1.2
24 * @deprecated As of 1.4, use {@link AbstractReader} instead.
25 */
26 public abstract class AbstractXmlReader extends AbstractReader /* implements XmlFriendlyReader */ {
27
28 protected AbstractXmlReader() {
29 this(new XmlFriendlyNameCoder());
30 }
31
32 /**
33 * @deprecated As of 1.4, use {@link AbstractReader} instead.
34 */
35 protected AbstractXmlReader(XmlFriendlyReplacer replacer) {
36 this((NameCoder)replacer);
37 }
38
39 protected AbstractXmlReader(NameCoder nameCoder) {
40 super(nameCoder);
41 }
42
43 /**
44 * Unescapes XML-friendly name (node or attribute)
45 *
46 * @param name the escaped XML-friendly name
47 * @return An unescaped name with original characters
48 * @deprecated As of 1.4, use {@link #decodeNode(String)} or {@link #decodeAttribute(String)} instead.
49 */
50 public String unescapeXmlName(String name) {
51 return decodeNode(name);
52 }
53
54 /**
55 * Escapes XML-unfriendly name (node or attribute)
56 *
57 * @param name the unescaped XML-unfriendly name
58 * @return An escaped name with original characters
59 * @deprecated As of 1.4, use {@link AbstractReader} instead.
60 */
61 protected String escapeXmlName(String name) {
62 return encodeNode(name);
63 }
64
65 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 04. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.AbstractWriter;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 /**
17 * Abstract base implementation of HierarchicalStreamWriter that provides common functionality
18 * to all XML-based writers.
19 *
20 * @author Mauro Talevi
21 * @author J&ouml;rg Schaible
22 * @since 1.2
23 * @deprecated As of 1.4 use {@link AbstractWriter} instead
24 */
25 public abstract class AbstractXmlWriter extends AbstractWriter implements XmlFriendlyWriter {
26
27 protected AbstractXmlWriter(){
28 this(new XmlFriendlyNameCoder());
29 }
30
31 /**
32 * @deprecated As of 1.4
33 */
34 protected AbstractXmlWriter(XmlFriendlyReplacer replacer) {
35 this((NameCoder)replacer);
36 }
37
38 protected AbstractXmlWriter(NameCoder nameCoder) {
39 super(nameCoder);
40 }
41
42 /**
43 * Escapes XML name (node or attribute) to be XML-friendly
44 *
45 * @param name the unescaped XML name
46 * @return An escaped name with original characters replaced
47 * @deprecated As of 1.4 use {@link #encodeNode(String)} or {@link #encodeAttribute(String)} instead
48 */
49 public String escapeXmlName(String name) {
50 return super.encodeNode(name);
51 }
52
53 }
0 /*
1 * Copyright (C) 2009, 2011 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 03. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.StreamException;
16 import com.thoughtworks.xstream.io.naming.NameCoder;
17 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
18
19 import org.xmlpull.v1.XmlPullParser;
20 import org.xmlpull.v1.XmlPullParserException;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.io.OutputStreamWriter;
26 import java.io.Reader;
27 import java.io.UnsupportedEncodingException;
28 import java.io.Writer;
29
30 /**
31 * An abstract base class for a driver using an XPP DOM implementation.
32 *
33 * @author Joe Walnes
34 * @author J&ouml;rg Schaible
35 * @since 1.4
36 */
37 public abstract class AbstractXppDomDriver extends AbstractXmlDriver {
38
39 /**
40 * Construct an AbstractXppDomDriver.
41 *
42 * @param nameCoder the replacer for XML friendly names
43 * @since 1.4
44 */
45 public AbstractXppDomDriver(NameCoder nameCoder) {
46 super(nameCoder);
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 public HierarchicalStreamReader createReader(Reader in) {
53 try {
54 XmlPullParser parser = createParser();
55 parser.setInput(in);
56 return new XppDomReader(XppDom.build(parser), getNameCoder());
57 } catch (XmlPullParserException e) {
58 throw new StreamException(e);
59 } catch (IOException e) {
60 throw new StreamException(e);
61 }
62 }
63
64 /**
65 * {@inheritDoc}
66 */
67 public HierarchicalStreamReader createReader(InputStream in) {
68 try {
69 return createReader(new XmlHeaderAwareReader(in));
70 } catch (UnsupportedEncodingException e) {
71 throw new StreamException(e);
72 } catch (IOException e) {
73 throw new StreamException(e);
74 }
75 }
76
77 /**
78 * {@inheritDoc}
79 */
80 public HierarchicalStreamWriter createWriter(Writer out) {
81 return new PrettyPrintWriter(out, getNameCoder());
82 }
83
84 /**
85 * {@inheritDoc}
86 */
87 public HierarchicalStreamWriter createWriter(OutputStream out) {
88 return createWriter(new OutputStreamWriter(out));
89 }
90
91 /**
92 * Create the parser of the XPP implementation.
93
94 * @throws XmlPullParserException if the parser cannot be created
95 * @since 1.4
96 */
97 protected abstract XmlPullParser createParser() throws XmlPullParserException;
98 }
0 /*
1 * Copyright (C) 2009, 2011 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.StreamException;
16 import com.thoughtworks.xstream.io.naming.NameCoder;
17
18 import org.xmlpull.v1.XmlPullParser;
19 import org.xmlpull.v1.XmlPullParserException;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24 import java.io.OutputStreamWriter;
25 import java.io.Reader;
26 import java.io.UnsupportedEncodingException;
27 import java.io.Writer;
28
29 /**
30 * An abstract base class for a driver using an XPP implementation.
31 *
32 * @author Joe Walnes
33 * @author J&ouml;rg Schaible
34 * @since 1.4
35 */
36 public abstract class AbstractXppDriver extends AbstractXmlDriver {
37
38 /**
39 * Construct an AbstractXppDriver.
40 *
41 * @param nameCoder the replacer for XML friendly tag and attribute names
42 * @since 1.4
43 */
44 public AbstractXppDriver(NameCoder nameCoder) {
45 super(nameCoder);
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public HierarchicalStreamReader createReader(Reader in) {
52 try {
53 return new XppReader(in, createParser(), getNameCoder());
54 } catch (XmlPullParserException e) {
55 throw new StreamException("Cannot create XmlPullParser");
56 }
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 public HierarchicalStreamReader createReader(InputStream in) {
63 try {
64 return createReader(new XmlHeaderAwareReader(in));
65 } catch (UnsupportedEncodingException e) {
66 throw new StreamException(e);
67 } catch (IOException e) {
68 throw new StreamException(e);
69 }
70 }
71
72 /**
73 * {@inheritDoc}
74 */
75 public HierarchicalStreamWriter createWriter(Writer out) {
76 return new PrettyPrintWriter(out, getNameCoder());
77 }
78
79 /**
80 * {@inheritDoc}
81 */
82 public HierarchicalStreamWriter createWriter(OutputStream out) {
83 return createWriter(new OutputStreamWriter(out));
84 }
85
86 /**
87 * Create the parser of the XPP implementation.
88
89 * @throws XmlPullParserException if the parser cannot be created
90 * @since 1.4
91 */
92 protected abstract XmlPullParser createParser() throws XmlPullParserException;
93 }
0 /*
1 * Copyright (C) 2009, 2011 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.bea.xml.stream.MXParserFactory;
13 import com.bea.xml.stream.XMLOutputFactoryBase;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import javax.xml.stream.XMLInputFactory;
17 import javax.xml.stream.XMLOutputFactory;
18
19 /**
20 * A driver using the BEA StAX implementation.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class BEAStaxDriver extends StaxDriver {
26
27 public BEAStaxDriver() {
28 super();
29 }
30
31 /**
32 * @deprecated As of 1.4.6 use {@link #BEAStaxDriver(QNameMap, NameCoder)}
33 */
34 public BEAStaxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
35 super(qnameMap, nameCoder);
36 }
37
38 /**
39 * @since 1.4.6
40 */
41 public BEAStaxDriver(QNameMap qnameMap, NameCoder nameCoder) {
42 super(qnameMap, nameCoder);
43 }
44
45 public BEAStaxDriver(QNameMap qnameMap) {
46 super(qnameMap);
47 }
48
49 /**
50 * @deprecated As of 1.4.6 use {@link #BEAStaxDriver(NameCoder)}
51 */
52 public BEAStaxDriver(XmlFriendlyNameCoder nameCoder) {
53 super(nameCoder);
54 }
55
56 /**
57 * @since 1.4.6
58 */
59 public BEAStaxDriver(NameCoder nameCoder) {
60 super(nameCoder);
61 }
62
63 protected XMLInputFactory createInputFactory() {
64 return new MXParserFactory();
65 }
66
67 protected XMLOutputFactory createOutputFactory() {
68 return new XMLOutputFactoryBase();
69 }
70
71 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import java.io.Writer;
16
17 public class CompactWriter extends PrettyPrintWriter {
18
19 public CompactWriter(Writer writer) {
20 super(writer);
21 }
22
23 /**
24 * @since 1.3
25 */
26 public CompactWriter(Writer writer, int mode) {
27 super(writer, mode);
28 }
29
30 /**
31 * @since 1.4
32 */
33 public CompactWriter(Writer writer, NameCoder nameCoder) {
34 super(writer, nameCoder);
35 }
36
37 /**
38 * @since 1.4
39 */
40 public CompactWriter(Writer writer, int mode, NameCoder nameCoder) {
41 super(writer, mode, nameCoder);
42 }
43
44 /**
45 * @deprecated As of 1.4 use {@link CompactWriter#CompactWriter(Writer, NameCoder)} instead.
46 */
47 public CompactWriter(Writer writer, XmlFriendlyReplacer replacer) {
48 super(writer, replacer);
49 }
50
51 /**
52 * @since 1.3
53 * @deprecated As of 1.4 use {@link CompactWriter#CompactWriter(Writer, int, NameCoder)} instead.
54 */
55 public CompactWriter(Writer writer, int mode, XmlFriendlyReplacer replacer) {
56 super(writer, mode, replacer);
57 }
58
59 protected void endOfLine() {
60 // override parent: don't write anything at end of line
61 }
62 }
0 /*
1 * Copyright (C) 2006, 2007 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 18. October 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
13
14
15 /**
16 * A generic interface for all {@link HierarchicalStreamReader} implementations reading a DOM.
17 *
18 * @author J&ouml;rg Schaible
19 * @since 1.2.1
20 */
21 public interface DocumentReader extends HierarchicalStreamReader {
22
23 /**
24 * Retrieve the current processed node of the DOM.
25 *
26 * @return the current node
27 * @since 1.2.1
28 */
29 public Object getCurrent();
30 }
0 /*
1 * Copyright (C) 2006, 2007 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 18. October 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import java.util.List;
13
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15
16
17 /**
18 * A generic interface for all {@link HierarchicalStreamWriter} implementations generating a
19 * DOM.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.2.1
23 */
24 public interface DocumentWriter extends HierarchicalStreamWriter {
25
26 /**
27 * Retrieve a {@link List} with the top elements. In the standard use case this list will
28 * only contain a single element. Additional elements can only occur, if
29 * {@link HierarchicalStreamWriter#startNode(String)} of the implementing
30 * {@link HierarchicalStreamWriter} was called multiple times with an empty node stack. Such
31 * a situation occurs calling
32 * {@link com.thoughtworks.xstream.XStream#marshal(Object, HierarchicalStreamWriter)}
33 * multiple times directly.
34 *
35 * @return a {@link List} with top nodes
36 * @since 1.2.1
37 */
38 List getTopLevelNodes();
39 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.File;
14 import java.io.FilterWriter;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17 import java.io.OutputStreamWriter;
18 import java.io.Reader;
19 import java.io.Writer;
20 import java.net.URL;
21
22 import org.dom4j.Document;
23 import org.dom4j.DocumentException;
24 import org.dom4j.DocumentFactory;
25 import org.dom4j.io.OutputFormat;
26 import org.dom4j.io.SAXReader;
27 import org.dom4j.io.XMLWriter;
28
29 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
30 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
31 import com.thoughtworks.xstream.io.StreamException;
32 import com.thoughtworks.xstream.io.naming.NameCoder;
33
34 public class Dom4JDriver extends AbstractXmlDriver {
35
36 private DocumentFactory documentFactory;
37 private OutputFormat outputFormat;
38
39 public Dom4JDriver() {
40 this(new XmlFriendlyNameCoder());
41 }
42
43 /**
44 * @since 1.4
45 */
46 public Dom4JDriver(NameCoder nameCoder) {
47 this(new DocumentFactory(), OutputFormat.createPrettyPrint(), nameCoder);
48 outputFormat.setTrimText(false);
49 }
50
51 public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat) {
52 this(documentFactory, outputFormat, new XmlFriendlyNameCoder());
53 }
54
55 /**
56 * @since 1.4
57 */
58 public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, NameCoder nameCoder) {
59 super(nameCoder);
60 this.documentFactory = documentFactory;
61 this.outputFormat = outputFormat;
62 }
63
64 /**
65 * @since 1.2
66 * @deprecated As of 1.4, use {@link Dom4JDriver#Dom4JDriver(DocumentFactory, OutputFormat, NameCoder)} instead.
67 */
68 public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, XmlFriendlyReplacer replacer) {
69 this(documentFactory, outputFormat, (NameCoder)replacer);
70 }
71
72
73 public DocumentFactory getDocumentFactory() {
74 return documentFactory;
75 }
76
77 public void setDocumentFactory(DocumentFactory documentFactory) {
78 this.documentFactory = documentFactory;
79 }
80
81 public OutputFormat getOutputFormat() {
82 return outputFormat;
83 }
84
85 public void setOutputFormat(OutputFormat outputFormat) {
86 this.outputFormat = outputFormat;
87 }
88
89 public HierarchicalStreamReader createReader(Reader text) {
90 try {
91 SAXReader reader = new SAXReader();
92 Document document = reader.read(text);
93 return new Dom4JReader(document, getNameCoder());
94 } catch (DocumentException e) {
95 throw new StreamException(e);
96 }
97 }
98
99 public HierarchicalStreamReader createReader(InputStream in) {
100 try {
101 SAXReader reader = new SAXReader();
102 Document document = reader.read(in);
103 return new Dom4JReader(document, getNameCoder());
104 } catch (DocumentException e) {
105 throw new StreamException(e);
106 }
107 }
108
109 /**
110 * @since 1.4
111 */
112 public HierarchicalStreamReader createReader(URL in) {
113 try {
114 SAXReader reader = new SAXReader();
115 Document document = reader.read(in);
116 return new Dom4JReader(document, getNameCoder());
117 } catch (DocumentException e) {
118 throw new StreamException(e);
119 }
120 }
121
122 /**
123 * @since 1.4
124 */
125 public HierarchicalStreamReader createReader(File in) {
126 try {
127 SAXReader reader = new SAXReader();
128 Document document = reader.read(in);
129 return new Dom4JReader(document, getNameCoder());
130 } catch (DocumentException e) {
131 throw new StreamException(e);
132 }
133 }
134
135 public HierarchicalStreamWriter createWriter(final Writer out) {
136 final HierarchicalStreamWriter[] writer = new HierarchicalStreamWriter[1];
137 final FilterWriter filter = new FilterWriter(out){
138 public void close() {
139 writer[0].close();
140 }
141 };
142 writer[0] = new Dom4JXmlWriter(new XMLWriter(filter, outputFormat), getNameCoder());
143 return writer[0];
144 }
145
146 public HierarchicalStreamWriter createWriter(final OutputStream out) {
147 final Writer writer = new OutputStreamWriter(out);
148 return createWriter(writer);
149 }
150 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.converters.ErrorWriter;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15 import java.util.List;
16 import org.dom4j.Document;
17 import org.dom4j.Element;
18
19 public class Dom4JReader extends AbstractDocumentReader {
20
21 private Element currentElement;
22
23 public Dom4JReader(Element rootElement) {
24 this(rootElement, new XmlFriendlyNameCoder());
25 }
26
27 public Dom4JReader(Document document) {
28 this(document.getRootElement());
29 }
30
31 /**
32 * @since 1.4
33 */
34 public Dom4JReader(Element rootElement, NameCoder nameCoder) {
35 super(rootElement, nameCoder);
36 }
37
38 /**
39 * @since 1.4
40 */
41 public Dom4JReader(Document document, NameCoder nameCoder) {
42 this(document.getRootElement(), nameCoder);
43 }
44
45 /**
46 * @since 1.2
47 * @deprecated As of 1.4, use {@link Dom4JReader#Dom4JReader(Element, NameCoder)} instead
48 */
49 public Dom4JReader(Element rootElement, XmlFriendlyReplacer replacer) {
50 this(rootElement, (NameCoder)replacer);
51 }
52
53 /**
54 * @since 1.2
55 * @deprecated As of 1.4, use {@link Dom4JReader#Dom4JReader(Document, NameCoder)} instead
56 */
57 public Dom4JReader(Document document, XmlFriendlyReplacer replacer) {
58 this(document.getRootElement(), (NameCoder)replacer);
59 }
60
61 public String getNodeName() {
62 return decodeNode(currentElement.getName());
63 }
64
65 public String getValue() {
66 return currentElement.getText();
67 }
68
69 public String getAttribute(String name) {
70 return currentElement.attributeValue(encodeAttribute(name));
71 }
72
73 public String getAttribute(int index) {
74 return currentElement.attribute(index).getValue();
75 }
76
77 public int getAttributeCount() {
78 return currentElement.attributeCount();
79 }
80
81 public String getAttributeName(int index) {
82 return decodeAttribute(currentElement.attribute(index).getQualifiedName());
83 }
84
85 protected Object getParent() {
86 return currentElement.getParent();
87 }
88
89 protected Object getChild(int index) {
90 return currentElement.elements().get(index);
91 }
92
93 protected int getChildCount() {
94 return currentElement.elements().size();
95 }
96
97 protected void reassignCurrentElement(Object current) {
98 currentElement = (Element) current;
99 }
100
101 public String peekNextChild() {
102 List list = currentElement.elements();
103 if (null == list || list.isEmpty()) {
104 return null;
105 }
106 return decodeNode(((Element) list.get(0)).getName());
107 }
108
109 public void appendErrors(ErrorWriter errorWriter) {
110 errorWriter.add("xpath", currentElement.getPath());
111 }
112
113 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.dom4j.Branch;
16 import org.dom4j.DocumentFactory;
17 import org.dom4j.Element;
18
19
20 public class Dom4JWriter extends AbstractDocumentWriter {
21
22 private final DocumentFactory documentFactory;
23
24 /**
25 * @since 1.4
26 */
27 public Dom4JWriter(
28 final Branch root, final DocumentFactory factory, final NameCoder nameCoder) {
29 super(root, nameCoder);
30 documentFactory = factory;
31 }
32
33 /**
34 * @since 1.4
35 */
36 public Dom4JWriter(final DocumentFactory factory, final NameCoder nameCoder) {
37 this(null, factory, nameCoder);
38 }
39
40 /**
41 * @since 1.4
42 */
43 public Dom4JWriter(final Branch root, final NameCoder nameCoder) {
44 this(root, new DocumentFactory(), nameCoder);
45 }
46
47 /**
48 * @since 1.2.1
49 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, DocumentFactory, NameCoder)} instead.
50 */
51 public Dom4JWriter(
52 final Branch root, final DocumentFactory factory, final XmlFriendlyReplacer replacer) {
53 this(root, factory, (NameCoder)replacer);
54 }
55
56 /**
57 * @since 1.2.1
58 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(DocumentFactory, NameCoder)} instead.
59 */
60 public Dom4JWriter(final DocumentFactory factory, final XmlFriendlyReplacer replacer) {
61 this(null, factory, (NameCoder)replacer);
62 }
63
64 /**
65 * @since 1.2.1
66 */
67 public Dom4JWriter(final DocumentFactory documentFactory) {
68 this(documentFactory, new XmlFriendlyNameCoder());
69 }
70
71 /**
72 * @since 1.2.1
73 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, NameCoder)} instead
74 */
75 public Dom4JWriter(final Branch root, final XmlFriendlyReplacer replacer) {
76 this(root, new DocumentFactory(), (NameCoder)replacer);
77 }
78
79 public Dom4JWriter(final Branch root) {
80 this(root, new DocumentFactory(), new XmlFriendlyNameCoder());
81 }
82
83 /**
84 * @since 1.2.1
85 */
86 public Dom4JWriter() {
87 this(new DocumentFactory(), new XmlFriendlyNameCoder());
88 }
89
90 protected Object createNode(final String name) {
91 final Element element = documentFactory.createElement(encodeNode(name));
92 final Branch top = top();
93 if (top != null) {
94 top().add(element);
95 }
96 return element;
97 }
98
99 public void setValue(final String text) {
100 top().setText(text);
101 }
102
103 public void addAttribute(final String key, final String value) {
104 ((Element)top()).addAttribute(encodeAttribute(key), value);
105 }
106
107 private Branch top() {
108 return (Branch)getCurrent();
109 }
110 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.core.util.FastStack;
14 import com.thoughtworks.xstream.io.StreamException;
15 import com.thoughtworks.xstream.io.naming.NameCoder;
16
17 import org.dom4j.Element;
18 import org.dom4j.io.XMLWriter;
19 import org.dom4j.tree.DefaultElement;
20 import org.xml.sax.SAXException;
21 import org.xml.sax.helpers.AttributesImpl;
22
23 import java.io.IOException;
24
25
26 public class Dom4JXmlWriter extends AbstractXmlWriter {
27
28 private final XMLWriter writer;
29 private final FastStack elementStack;
30 private AttributesImpl attributes;
31 private boolean started;
32 private boolean children;
33
34 public Dom4JXmlWriter(XMLWriter writer) {
35 this(writer, new XmlFriendlyNameCoder());
36 }
37
38 /**
39 * @since 1.4
40 */
41 public Dom4JXmlWriter(XMLWriter writer, NameCoder nameCoder) {
42 super(nameCoder);
43 this.writer = writer;
44 this.elementStack = new FastStack(16);
45 this.attributes = new AttributesImpl();
46 try {
47 writer.startDocument();
48 } catch (SAXException e) {
49 throw new StreamException(e);
50 }
51 }
52
53 /**
54 * @since 1.2
55 * @deprecated As of 1.4 use {@link Dom4JXmlWriter#Dom4JXmlWriter(XMLWriter, NameCoder)} instead.
56 */
57 public Dom4JXmlWriter(XMLWriter writer, XmlFriendlyReplacer replacer) {
58 this(writer, (NameCoder)replacer);
59 }
60
61 public void startNode(String name) {
62 if (elementStack.size() > 0) {
63 try {
64 startElement();
65 } catch (SAXException e) {
66 throw new StreamException(e);
67 }
68 started = false;
69 }
70 elementStack.push(encodeNode(name));
71 children = false;
72 }
73
74 public void setValue(String text) {
75 char[] value = text.toCharArray();
76 if (value.length > 0) {
77 try {
78 startElement();
79 writer.characters(value, 0, value.length);
80 } catch (SAXException e) {
81 throw new StreamException(e);
82 }
83 children = true;
84 }
85 }
86
87 public void addAttribute(String key, String value) {
88 attributes.addAttribute("", "", encodeAttribute(key), "string", value);
89 }
90
91 public void endNode() {
92 try {
93 if (!children) {
94 Element element = new DefaultElement((String)elementStack.pop());
95 for (int i = 0; i < attributes.getLength(); ++i) {
96 element.addAttribute(attributes.getQName(i), attributes.getValue(i));
97 }
98 writer.write(element);
99 attributes.clear();
100 children = true; // node just closed is child of node on top of stack
101 started = true;
102 } else {
103 startElement();
104 writer.endElement("", "", (String)elementStack.pop());
105 }
106 } catch (SAXException e) {
107 throw new StreamException(e);
108 } catch (IOException e) {
109 throw new StreamException(e);
110 }
111 }
112
113 public void flush() {
114 try {
115 writer.flush();
116 } catch (IOException e) {
117 throw new StreamException(e);
118 }
119 }
120
121 public void close() {
122 try {
123 writer.endDocument();
124 } catch (SAXException e) {
125 throw new StreamException(e);
126 }
127 }
128
129 private void startElement() throws SAXException {
130 if (!started) {
131 writer.startElement("", "", (String)elementStack.peek(), attributes);
132 attributes.clear();
133 started = true;
134 }
135 }
136 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17 import java.io.OutputStreamWriter;
18 import java.io.Reader;
19 import java.io.UnsupportedEncodingException;
20 import java.io.Writer;
21 import java.net.URL;
22
23 import javax.xml.parsers.DocumentBuilder;
24 import javax.xml.parsers.DocumentBuilderFactory;
25 import javax.xml.parsers.FactoryConfigurationError;
26 import javax.xml.parsers.ParserConfigurationException;
27
28 import org.w3c.dom.Document;
29 import org.xml.sax.InputSource;
30 import org.xml.sax.SAXException;
31
32 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
33 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
34 import com.thoughtworks.xstream.io.StreamException;
35 import com.thoughtworks.xstream.io.naming.NameCoder;
36
37
38 public class DomDriver extends AbstractXmlDriver {
39
40 private final String encoding;
41 private final DocumentBuilderFactory documentBuilderFactory;
42
43 /**
44 * Construct a DomDriver.
45 */
46 public DomDriver() {
47 this(null);
48 }
49
50 /**
51 * Construct a DomDriver with a specified encoding. The created DomReader will ignore any
52 * encoding attribute of the XML header though.
53 */
54 public DomDriver(String encoding) {
55 this(encoding, new XmlFriendlyNameCoder());
56 }
57
58 /**
59 * @since 1.4
60 */
61 public DomDriver(String encoding, NameCoder nameCoder) {
62 super(nameCoder);
63 documentBuilderFactory = DocumentBuilderFactory.newInstance();
64 this.encoding = encoding;
65 }
66
67 /**
68 * @since 1.2
69 * @deprecated As of 1.4, use {@link #DomDriver(String, NameCoder)} instead.
70 */
71 public DomDriver(String encoding, XmlFriendlyReplacer replacer) {
72 this(encoding, (NameCoder)replacer);
73 }
74
75 public HierarchicalStreamReader createReader(Reader in) {
76 return createReader(new InputSource(in));
77 }
78
79 public HierarchicalStreamReader createReader(InputStream in) {
80 return createReader(new InputSource(in));
81 }
82
83 public HierarchicalStreamReader createReader(URL in) {
84 return createReader(new InputSource(in.toExternalForm()));
85 }
86
87 public HierarchicalStreamReader createReader(File in) {
88 return createReader(new InputSource(in.toURI().toASCIIString()));
89 }
90
91 private HierarchicalStreamReader createReader(InputSource source) {
92 try {
93 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
94 if (encoding != null) {
95 source.setEncoding(encoding);
96 }
97 Document document = documentBuilder.parse(source);
98 return new DomReader(document, getNameCoder());
99 } catch (FactoryConfigurationError e) {
100 throw new StreamException(e);
101 } catch (ParserConfigurationException e) {
102 throw new StreamException(e);
103 } catch (SAXException e) {
104 throw new StreamException(e);
105 } catch (IOException e) {
106 throw new StreamException(e);
107 }
108 }
109
110 public HierarchicalStreamWriter createWriter(Writer out) {
111 return new PrettyPrintWriter(out, getNameCoder());
112 }
113
114 public HierarchicalStreamWriter createWriter(OutputStream out) {
115 try {
116 return createWriter(encoding != null
117 ? new OutputStreamWriter(out, encoding)
118 : new OutputStreamWriter(out));
119 } catch (UnsupportedEncodingException e) {
120 throw new StreamException(e);
121 }
122 }
123 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.w3c.dom.Attr;
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20 import org.w3c.dom.Text;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 public class DomReader extends AbstractDocumentReader {
26
27 private Element currentElement;
28 private StringBuffer textBuffer;
29 private List childElements;
30
31 public DomReader(Element rootElement) {
32 this(rootElement, new XmlFriendlyNameCoder());
33 }
34
35 public DomReader(Document document) {
36 this(document.getDocumentElement());
37 }
38
39 /**
40 * @since 1.4
41 */
42 public DomReader(Element rootElement, NameCoder nameCoder) {
43 super(rootElement, nameCoder);
44 textBuffer = new StringBuffer();
45 }
46
47 /**
48 * @since 1.4
49 */
50 public DomReader(Document document, NameCoder nameCoder) {
51 this(document.getDocumentElement(), nameCoder);
52 }
53
54 /**
55 * @since 1.2
56 * @deprecated As of 1.4, use {@link DomReader#DomReader(Element, NameCoder)} instead.
57 */
58 public DomReader(Element rootElement, XmlFriendlyReplacer replacer) {
59 this(rootElement, (NameCoder)replacer);
60 }
61
62 /**
63 * @since 1.2
64 * @deprecated As of 1.4, use {@link DomReader#DomReader(Document, NameCoder)} instead.
65 */
66 public DomReader(Document document, XmlFriendlyReplacer replacer) {
67 this(document.getDocumentElement(), (NameCoder)replacer);
68 }
69
70 public String getNodeName() {
71 return decodeNode(currentElement.getTagName());
72 }
73
74 public String getValue() {
75 NodeList childNodes = currentElement.getChildNodes();
76 textBuffer.setLength(0);
77 int length = childNodes.getLength();
78 for (int i = 0; i < length; i++) {
79 Node childNode = childNodes.item(i);
80 if (childNode instanceof Text) {
81 Text text = (Text) childNode;
82 textBuffer.append(text.getData());
83 }
84 }
85 return textBuffer.toString();
86 }
87
88 public String getAttribute(String name) {
89 Attr attribute = currentElement.getAttributeNode(encodeAttribute(name));
90 return attribute == null ? null : attribute.getValue();
91 }
92
93 public String getAttribute(int index) {
94 return ((Attr) currentElement.getAttributes().item(index)).getValue();
95 }
96
97 public int getAttributeCount() {
98 return currentElement.getAttributes().getLength();
99 }
100
101 public String getAttributeName(int index) {
102 return decodeAttribute(((Attr) currentElement.getAttributes().item(index)).getName());
103 }
104
105 protected Object getParent() {
106 return currentElement.getParentNode();
107 }
108
109 protected Object getChild(int index) {
110 return childElements.get(index);
111 }
112
113 protected int getChildCount() {
114 return childElements.size();
115 }
116
117 protected void reassignCurrentElement(Object current) {
118 currentElement = (Element) current;
119 NodeList childNodes = currentElement.getChildNodes();
120 childElements = new ArrayList();
121 for (int i = 0; i < childNodes.getLength(); i++) {
122 Node node = childNodes.item(i);
123 if (node instanceof Element) {
124 childElements.add(node);
125 }
126 }
127 }
128
129 public String peekNextChild() {
130 NodeList childNodes = currentElement.getChildNodes();
131 for (int i = 0; i < childNodes.getLength(); i++) {
132 Node node = childNodes.item(i);
133 if (node instanceof Element) {
134 return decodeNode(((Element) node).getTagName());
135 }
136 }
137 return null;
138 }
139 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
17
18
19 /**
20 * @author Michael Kopp
21 */
22 public class DomWriter extends AbstractDocumentWriter {
23
24 private final Document document;
25 private boolean hasRootElement;
26
27 public DomWriter(final Document document) {
28 this(document, new XmlFriendlyNameCoder());
29 }
30
31 public DomWriter(final Element rootElement) {
32 this(rootElement, new XmlFriendlyNameCoder());
33 }
34
35 /**
36 * @since 1.4
37 */
38 public DomWriter(final Document document, final NameCoder nameCoder) {
39 this(document.getDocumentElement(), document, nameCoder);
40 }
41
42 /**
43 * @since 1.4
44 */
45 public DomWriter(final Element element, final Document document, final NameCoder nameCoder) {
46 super(element, nameCoder);
47 this.document = document;
48 hasRootElement = document.getDocumentElement() != null;
49 }
50
51 /**
52 * @since 1.4
53 */
54 public DomWriter(final Element rootElement, final NameCoder nameCoder) {
55 this(rootElement, rootElement.getOwnerDocument(), nameCoder);
56 }
57
58 /**
59 * @since 1.2
60 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Document, NameCoder)} instead.
61 */
62 public DomWriter(final Document document, final XmlFriendlyReplacer replacer) {
63 this(document.getDocumentElement(), document, (NameCoder)replacer);
64 }
65
66 /**
67 * @since 1.2.1
68 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Element, Document, NameCoder)} instead.
69 */
70 public DomWriter(final Element element, final Document document, final XmlFriendlyReplacer replacer) {
71 this(element, document, (NameCoder)replacer);
72 }
73
74 /**
75 * @since 1.2
76 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Element, NameCoder)} instead.
77 */
78 public DomWriter(final Element rootElement, final XmlFriendlyReplacer replacer) {
79 this(rootElement, rootElement.getOwnerDocument(), (NameCoder)replacer);
80 }
81
82 protected Object createNode(final String name) {
83 final Element child = document.createElement(encodeNode(name));
84 final Element top = top();
85 if (top != null) {
86 top().appendChild(child);
87 } else if (!hasRootElement) {
88 document.appendChild(child);
89 hasRootElement = true;
90 }
91 return child;
92 }
93
94 public void addAttribute(final String name, final String value) {
95 top().setAttribute(encodeAttribute(name), value);
96 }
97
98 public void setValue(final String text) {
99 top().appendChild(document.createTextNode(text));
100 }
101
102 private Element top() {
103 return (Element)getCurrent();
104 }
105 }
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.OutputStream;
16 import java.io.OutputStreamWriter;
17 import java.io.Reader;
18 import java.io.Writer;
19 import java.net.URL;
20
21 import org.jdom2.Document;
22 import org.jdom2.JDOMException;
23 import org.jdom2.input.SAXBuilder;
24
25 import com.thoughtworks.xstream.io.AbstractDriver;
26 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
27 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
28 import com.thoughtworks.xstream.io.StreamException;
29 import com.thoughtworks.xstream.io.naming.NameCoder;
30
31 /**
32 * @since 1.4.5
33 */
34 public class JDom2Driver extends AbstractDriver {
35
36 public JDom2Driver() {
37 super(new XmlFriendlyNameCoder());
38 }
39
40 /**
41 * @since 1.4.5
42 */
43 public JDom2Driver(NameCoder nameCoder) {
44 super(nameCoder);
45 }
46
47 public HierarchicalStreamReader createReader(Reader reader) {
48 try {
49 SAXBuilder builder = new SAXBuilder();
50 Document document = builder.build(reader);
51 return new JDom2Reader(document, getNameCoder());
52 } catch (IOException e) {
53 throw new StreamException(e);
54 } catch (JDOMException e) {
55 throw new StreamException(e);
56 }
57 }
58
59 public HierarchicalStreamReader createReader(InputStream in) {
60 try {
61 SAXBuilder builder = new SAXBuilder();
62 Document document = builder.build(in);
63 return new JDom2Reader(document, getNameCoder());
64 } catch (IOException e) {
65 throw new StreamException(e);
66 } catch (JDOMException e) {
67 throw new StreamException(e);
68 }
69 }
70
71 public HierarchicalStreamReader createReader(URL in) {
72 try {
73 SAXBuilder builder = new SAXBuilder();
74 Document document = builder.build(in);
75 return new JDom2Reader(document, getNameCoder());
76 } catch (IOException e) {
77 throw new StreamException(e);
78 } catch (JDOMException e) {
79 throw new StreamException(e);
80 }
81 }
82
83 public HierarchicalStreamReader createReader(File in) {
84 try {
85 SAXBuilder builder = new SAXBuilder();
86 Document document = builder.build(in);
87 return new JDom2Reader(document, getNameCoder());
88 } catch (IOException e) {
89 throw new StreamException(e);
90 } catch (JDOMException e) {
91 throw new StreamException(e);
92 }
93 }
94
95 public HierarchicalStreamWriter createWriter(Writer out) {
96 return new PrettyPrintWriter(out, getNameCoder());
97 }
98
99 public HierarchicalStreamWriter createWriter(OutputStream out) {
100 return new PrettyPrintWriter(new OutputStreamWriter(out));
101 }
102 }
103
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.naming.NameCoder;
13 import java.util.List;
14 import org.jdom2.Document;
15 import org.jdom2.Element;
16
17 /**
18 * @since 1.4.5
19 */
20 public class JDom2Reader extends AbstractDocumentReader {
21
22 private Element currentElement;
23
24 /**
25 * @since 1.4.5
26 */
27 public JDom2Reader(Element root) {
28 super(root);
29 }
30
31 /**
32 * @since 1.4.5
33 */
34 public JDom2Reader(Document document) {
35 super(document.getRootElement());
36 }
37
38 /**
39 * @since 1.4.5
40 */
41 public JDom2Reader(Element root, NameCoder nameCoder) {
42 super(root, nameCoder);
43 }
44
45 /**
46 * @since 1.4.5
47 */
48 public JDom2Reader(Document document, NameCoder nameCoder) {
49 super(document.getRootElement(), nameCoder);
50 }
51
52 protected void reassignCurrentElement(Object current) {
53 currentElement = (Element) current;
54 }
55
56 protected Object getParent() {
57 return currentElement.getParentElement();
58 }
59
60 protected Object getChild(int index) {
61 return currentElement.getChildren().get(index);
62 }
63
64 protected int getChildCount() {
65 return currentElement.getChildren().size();
66 }
67
68 public String getNodeName() {
69 return decodeNode(currentElement.getName());
70 }
71
72 public String getValue() {
73 return currentElement.getText();
74 }
75
76 public String getAttribute(String name) {
77 return currentElement.getAttributeValue(encodeAttribute(name));
78 }
79
80 public String getAttribute(int index) {
81 return currentElement.getAttributes().get(index).getValue();
82 }
83
84 public int getAttributeCount() {
85 return currentElement.getAttributes().size();
86 }
87
88 public String getAttributeName(int index) {
89 return decodeAttribute(currentElement.getAttributes().get(index).getQualifiedName());
90 }
91
92 public String peekNextChild() {
93 List list = currentElement.getChildren();
94 if (null == list || list.isEmpty()) {
95 return null;
96 }
97 return decodeNode(((Element) list.get(0)).getName());
98 }
99 }
100
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.naming.NameCoder;
13
14 import org.jdom2.DefaultJDOMFactory;
15 import org.jdom2.Element;
16 import org.jdom2.JDOMFactory;
17
18
19 /**
20 * @since 1.4.5
21 */
22 public class JDom2Writer extends AbstractDocumentWriter {
23
24 private final JDOMFactory documentFactory;
25
26 /**
27 * @since 1.4.5
28 */
29 public JDom2Writer(
30 final Element container, final JDOMFactory factory,
31 final NameCoder nameCoder) {
32 super(container, nameCoder);
33 documentFactory = factory;
34 }
35
36 /**
37 * @since 1.4.5
38 */
39 public JDom2Writer(final Element container, final JDOMFactory factory) {
40 this(container, factory, new XmlFriendlyNameCoder());
41 }
42
43 /**
44 * @since 1.4.5
45 */
46 public JDom2Writer(final JDOMFactory factory, final NameCoder nameCoder) {
47 this(null, factory, nameCoder);
48 }
49
50 /**
51 * @since 1.4.5
52 */
53 public JDom2Writer(final JDOMFactory factory) {
54 this(null, factory);
55 }
56
57 /**
58 * @since 1.4.5
59 */
60 public JDom2Writer(final Element container, final NameCoder nameCoder) {
61 this(container, new DefaultJDOMFactory(), nameCoder);
62 }
63
64 /**
65 * @since 1.4.5
66 */
67 public JDom2Writer(final Element container) {
68 this(container, new DefaultJDOMFactory());
69 }
70
71 /**
72 * @since 1.4.5
73 */
74 public JDom2Writer() {
75 this(new DefaultJDOMFactory());
76 }
77
78 protected Object createNode(final String name) {
79 final Element element = documentFactory.element(encodeNode(name));
80 final Element parent = top();
81 if (parent != null) {
82 parent.addContent(element);
83 }
84 return element;
85 }
86
87 public void setValue(final String text) {
88 top().addContent(documentFactory.text(text));
89 }
90
91 public void addAttribute(final String key, final String value) {
92 top().setAttribute(documentFactory.attribute(encodeAttribute(key), value));
93 }
94
95 /**
96 * @since 1.4.5
97 */
98 private Element top() {
99 return (Element)getCurrent();
100 }
101 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17 import java.io.OutputStreamWriter;
18 import java.io.Reader;
19 import java.io.Writer;
20 import java.net.URL;
21
22 import org.jdom.Document;
23 import org.jdom.JDOMException;
24 import org.jdom.input.SAXBuilder;
25
26 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
27 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
28 import com.thoughtworks.xstream.io.StreamException;
29 import com.thoughtworks.xstream.io.naming.NameCoder;
30
31 /**
32 * @author Laurent Bihanic
33 */
34 public class JDomDriver extends AbstractXmlDriver {
35
36 public JDomDriver() {
37 super(new XmlFriendlyNameCoder());
38 }
39
40 /**
41 * @since 1.4
42 */
43 public JDomDriver(NameCoder nameCoder) {
44 super(nameCoder);
45 }
46
47 /**
48 * @since 1.2
49 * @deprecated As of 1.4, use {@link JDomDriver#JDomDriver(NameCoder)} instead.
50 */
51 public JDomDriver(XmlFriendlyReplacer replacer) {
52 this((NameCoder)replacer);
53 }
54
55 public HierarchicalStreamReader createReader(Reader reader) {
56 try {
57 SAXBuilder builder = new SAXBuilder();
58 Document document = builder.build(reader);
59 return new JDomReader(document, getNameCoder());
60 } catch (IOException e) {
61 throw new StreamException(e);
62 } catch (JDOMException e) {
63 throw new StreamException(e);
64 }
65 }
66
67 public HierarchicalStreamReader createReader(InputStream in) {
68 try {
69 SAXBuilder builder = new SAXBuilder();
70 Document document = builder.build(in);
71 return new JDomReader(document, getNameCoder());
72 } catch (IOException e) {
73 throw new StreamException(e);
74 } catch (JDOMException e) {
75 throw new StreamException(e);
76 }
77 }
78
79 public HierarchicalStreamReader createReader(URL in) {
80 try {
81 SAXBuilder builder = new SAXBuilder();
82 Document document = builder.build(in);
83 return new JDomReader(document, getNameCoder());
84 } catch (IOException e) {
85 throw new StreamException(e);
86 } catch (JDOMException e) {
87 throw new StreamException(e);
88 }
89 }
90
91 public HierarchicalStreamReader createReader(File in) {
92 try {
93 SAXBuilder builder = new SAXBuilder();
94 Document document = builder.build(in);
95 return new JDomReader(document, getNameCoder());
96 } catch (IOException e) {
97 throw new StreamException(e);
98 } catch (JDOMException e) {
99 throw new StreamException(e);
100 }
101 }
102
103 public HierarchicalStreamWriter createWriter(Writer out) {
104 return new PrettyPrintWriter(out, getNameCoder());
105 }
106
107 public HierarchicalStreamWriter createWriter(OutputStream out) {
108 return new PrettyPrintWriter(new OutputStreamWriter(out));
109 }
110
111 }
112
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import java.util.List;
15 import org.jdom.Attribute;
16 import org.jdom.Document;
17 import org.jdom.Element;
18
19 /**
20 * @author Laurent Bihanic
21 */
22 public class JDomReader extends AbstractDocumentReader {
23
24 private Element currentElement;
25
26 public JDomReader(Element root) {
27 super(root);
28 }
29
30 public JDomReader(Document document) {
31 super(document.getRootElement());
32 }
33
34 /**
35 * @since 1.4
36 */
37 public JDomReader(Element root, NameCoder nameCoder) {
38 super(root, nameCoder);
39 }
40
41 /**
42 * @since 1.4
43 */
44 public JDomReader(Document document, NameCoder nameCoder) {
45 super(document.getRootElement(), nameCoder);
46 }
47
48 /**
49 * @since 1.2
50 * @deprecated As of 1.4, use {@link JDomReader#JDomReader(Element, NameCoder)} instead.
51 */
52 public JDomReader(Element root, XmlFriendlyReplacer replacer) {
53 this(root, (NameCoder)replacer);
54 }
55
56 /**
57 * @since 1.2
58 * @deprecated As of 1.4, use {@link JDomReader#JDomReader(Document, NameCoder)} instead.
59 */
60 public JDomReader(Document document, XmlFriendlyReplacer replacer) {
61 this(document.getRootElement(), (NameCoder)replacer);
62 }
63
64 protected void reassignCurrentElement(Object current) {
65 currentElement = (Element) current;
66 }
67
68 protected Object getParent() {
69 // JDOM 1.0:
70 return currentElement.getParentElement();
71
72 // JDOM b10:
73 // Parent parent = currentElement.getParent();
74 // return (parent instanceof Element) ? (Element)parent : null;
75
76 // JDOM b9 and earlier:
77 // return currentElement.getParent();
78 }
79
80 protected Object getChild(int index) {
81 return currentElement.getChildren().get(index);
82 }
83
84 protected int getChildCount() {
85 return currentElement.getChildren().size();
86 }
87
88 public String getNodeName() {
89 return decodeNode(currentElement.getName());
90 }
91
92 public String getValue() {
93 return currentElement.getText();
94 }
95
96 public String getAttribute(String name) {
97 return currentElement.getAttributeValue(encodeAttribute(name));
98 }
99
100 public String getAttribute(int index) {
101 return ((Attribute) currentElement.getAttributes().get(index)).getValue();
102 }
103
104 public int getAttributeCount() {
105 return currentElement.getAttributes().size();
106 }
107
108 public String getAttributeName(int index) {
109 return decodeAttribute(((Attribute) currentElement.getAttributes().get(index)).getQualifiedName());
110 }
111
112 public String peekNextChild() {
113 List list = currentElement.getChildren();
114 if (null == list || list.isEmpty()) {
115 return null;
116 }
117 return decodeNode(((Element) list.get(0)).getName());
118 }
119
120 }
121
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.jdom.DefaultJDOMFactory;
16 import org.jdom.Element;
17 import org.jdom.JDOMFactory;
18
19
20 /**
21 * @author Laurent Bihanic
22 */
23 public class JDomWriter extends AbstractDocumentWriter {
24
25 private final JDOMFactory documentFactory;
26
27 /**
28 * @since 1.4
29 */
30 public JDomWriter(
31 final Element container, final JDOMFactory factory,
32 final NameCoder nameCoder) {
33 super(container, nameCoder);
34 documentFactory = factory;
35 }
36
37 /**
38 * @since 1.2
39 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(Element, JDOMFactory, NameCoder)} instead.
40 */
41 public JDomWriter(
42 final Element container, final JDOMFactory factory,
43 final XmlFriendlyReplacer replacer) {
44 this(container, factory, (NameCoder)replacer);
45 }
46
47 public JDomWriter(final Element container, final JDOMFactory factory) {
48 this(container, factory, new XmlFriendlyNameCoder());
49 }
50
51 /**
52 * @since 1.4
53 */
54 public JDomWriter(final JDOMFactory factory, final NameCoder nameCoder) {
55 this(null, factory, nameCoder);
56 }
57
58 /**
59 * @since 1.2.1
60 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(JDOMFactory, NameCoder)} instead.
61 */
62 public JDomWriter(final JDOMFactory factory, final XmlFriendlyReplacer replacer) {
63 this(null, factory, (NameCoder)replacer);
64 }
65
66 public JDomWriter(final JDOMFactory factory) {
67 this(null, factory);
68 }
69
70 /**
71 * @since 1.4
72 */
73 public JDomWriter(final Element container, final NameCoder nameCoder) {
74 this(container, new DefaultJDOMFactory(), nameCoder);
75 }
76
77 /**
78 * @since 1.2.1
79 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(Element, NameCoder)} instead.
80 */
81 public JDomWriter(final Element container, final XmlFriendlyReplacer replacer) {
82 this(container, new DefaultJDOMFactory(), (NameCoder)replacer);
83 }
84
85 public JDomWriter(final Element container) {
86 this(container, new DefaultJDOMFactory());
87 }
88
89 public JDomWriter() {
90 this(new DefaultJDOMFactory());
91 }
92
93 protected Object createNode(final String name) {
94 final Element element = documentFactory.element(encodeNode(name));
95 final Element parent = top();
96 if (parent != null) {
97 parent.addContent(element);
98 }
99 return element;
100 }
101
102 public void setValue(final String text) {
103 top().addContent(documentFactory.text(text));
104 }
105
106 public void addAttribute(final String key, final String value) {
107 top().setAttribute(documentFactory.attribute(encodeAttribute(key), value));
108 }
109
110 private Element top() {
111 return (Element)getCurrent();
112 }
113 }
0 /*
1 * Copyright (C) 2009, 2011 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 03. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.kxml2.io.KXmlParser;
16 import org.xmlpull.v1.XmlPullParser;
17
18 /**
19 * A {@link HierarchicalStreamDriver} for XPP DOM using the kXML2 parser.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.4
23 */
24 public class KXml2DomDriver extends AbstractXppDomDriver {
25
26 /**
27 * Construct an KXml2DomDriver.
28 *
29 * @since 1.4
30 */
31 public KXml2DomDriver() {
32 super(new XmlFriendlyNameCoder());
33 }
34
35 /**
36 * Construct a KXml2DomDriver.
37 *
38 * @param nameCoder the replacer for XML friendly names
39 * @since 1.4
40 */
41 public KXml2DomDriver(NameCoder nameCoder) {
42 super(nameCoder);
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 protected XmlPullParser createParser() {
49 return new KXmlParser();
50 }
51 }
0 /*
1 * Copyright (C) 2009, 2011 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import org.kxml2.io.KXmlParser;
17 import org.xmlpull.v1.XmlPullParser;
18
19
20 /**
21 * A {@link HierarchicalStreamDriver} using the kXML2 parser.
22 *
23 * @author J&ouml;rg Schaible
24 * @since 1.4
25 */
26 public class KXml2Driver extends AbstractXppDriver {
27
28 /**
29 * Construct a KXml2Driver.
30 *
31 * @since 1.4
32 */
33 public KXml2Driver() {
34 super(new XmlFriendlyNameCoder());
35 }
36
37 /**
38 * Construct a KXml2Driver.
39 *
40 * @param nameCoder the replacer for XML friendly names
41 * @since 1.4
42 */
43 public KXml2Driver(NameCoder nameCoder) {
44 super(nameCoder);
45 }
46
47 /**
48 * {@inheritDoc}
49 */
50 protected XmlPullParser createParser() {
51 return new KXmlParser();
52 }
53 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.core.util.FastStack;
14 import com.thoughtworks.xstream.core.util.QuickWriter;
15 import com.thoughtworks.xstream.io.StreamException;
16 import com.thoughtworks.xstream.io.naming.NameCoder;
17
18 import java.io.Writer;
19
20
21 /**
22 * A simple writer that outputs XML in a pretty-printed indented stream.
23 * <p>
24 * By default, the chars <br><code>&amp; &lt; &gt; &quot; ' \r</code><br> are escaped
25 * and replaced with a suitable XML entity. To alter this behavior, override
26 * the {@link #writeText(com.thoughtworks.xstream.core.util.QuickWriter, String)} and
27 * {@link #writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter, String)} methods.
28 * </p>
29 * <p>
30 * The XML specification requires XML parsers to drop CR characters completely. This implementation
31 * will therefore use only a LF for line endings, never the platform encoding. You can overwrite the
32 * {@link #getNewLine()} method for a different behavior.
33 * </p>
34 * <p>
35 * Note: Depending on the XML version some characters cannot be written. Especially a 0
36 * character is never valid in XML, neither directly nor as entity nor within CDATA. However, this writer
37 * works by default in a quirks mode, where it will write any character at least as character entity (even
38 * a null character). You may switch into XML_1_1 mode (which supports most characters) or XML_1_0
39 * that does only support a very limited number of control characters. See XML specification for version
40 * <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#charsets">1.0</a> or
41 * <a href="http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets">1.1</a>. If a character is
42 * not supported, a {@link StreamException} is thrown. Select a proper parser implementation that
43 * respects the version in the XML header (the Xpp3 parser will also read character entities of normally
44 * invalid characters).
45 * </p>
46 *
47 * @author Joe Walnes
48 * @author J&ouml;rg Schaible
49 */
50 public class PrettyPrintWriter extends AbstractXmlWriter {
51
52 public static int XML_QUIRKS = -1;
53 public static int XML_1_0 = 0;
54 public static int XML_1_1 = 1;
55
56 private final QuickWriter writer;
57 private final FastStack elementStack = new FastStack(16);
58 private final char[] lineIndenter;
59 private final int mode;
60
61 private boolean tagInProgress;
62 protected int depth;
63 private boolean readyForNewLine;
64 private boolean tagIsEmpty;
65 private String newLine;
66
67 private static final char[] NULL = "&#x0;".toCharArray();
68 private static final char[] AMP = "&amp;".toCharArray();
69 private static final char[] LT = "&lt;".toCharArray();
70 private static final char[] GT = "&gt;".toCharArray();
71 private static final char[] CR = "&#xd;".toCharArray();
72 private static final char[] QUOT = "&quot;".toCharArray();
73 private static final char[] APOS = "&apos;".toCharArray();
74 private static final char[] CLOSE = "</".toCharArray();
75
76 private PrettyPrintWriter(
77 Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder,
78 String newLine) {
79 super(nameCoder);
80 this.writer = new QuickWriter(writer);
81 this.lineIndenter = lineIndenter;
82 this.newLine = newLine;
83 this.mode = mode;
84 if (mode < XML_QUIRKS || mode > XML_1_1) {
85 throw new IllegalArgumentException("Not a valid XML mode");
86 }
87 }
88
89 /**
90 * @since 1.2
91 * @deprecated As of 1.3
92 */
93 public PrettyPrintWriter(
94 Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer) {
95 this(writer, XML_QUIRKS, lineIndenter, replacer, newLine);
96 }
97
98 /**
99 * @since 1.4
100 */
101 public PrettyPrintWriter(
102 Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder) {
103 this(writer, mode, lineIndenter, nameCoder, "\n");
104 }
105
106 /**
107 * @since 1.3
108 * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, int, char[], NameCoder)} instead
109 */
110 public PrettyPrintWriter(
111 Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer) {
112 this(writer, mode, lineIndenter, replacer, "\n");
113 }
114
115 /**
116 * @deprecated As of 1.3
117 */
118 public PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine) {
119 this(writer, lineIndenter, newLine, new XmlFriendlyReplacer());
120 }
121
122 /**
123 * @since 1.3
124 */
125 public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter) {
126 this(writer, mode, lineIndenter, new XmlFriendlyNameCoder());
127 }
128
129 public PrettyPrintWriter(Writer writer, char[] lineIndenter) {
130 this(writer, XML_QUIRKS, lineIndenter);
131 }
132
133 /**
134 * @deprecated As of 1.3
135 */
136 public PrettyPrintWriter(Writer writer, String lineIndenter, String newLine) {
137 this(writer, lineIndenter.toCharArray(), newLine);
138 }
139
140 /**
141 * @since 1.3
142 */
143 public PrettyPrintWriter(Writer writer, int mode, String lineIndenter) {
144 this(writer, mode, lineIndenter.toCharArray());
145 }
146
147 public PrettyPrintWriter(Writer writer, String lineIndenter) {
148 this(writer, lineIndenter.toCharArray());
149 }
150
151 /**
152 * @since 1.4
153 */
154 public PrettyPrintWriter(Writer writer, int mode, NameCoder nameCoder) {
155 this(writer, mode, new char[]{' ', ' '}, nameCoder);
156 }
157
158 /**
159 * @since 1.3
160 * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, int, NameCoder)} instead
161 */
162 public PrettyPrintWriter(Writer writer, int mode, XmlFriendlyReplacer replacer) {
163 this(writer, mode, new char[]{' ', ' '}, replacer);
164 }
165
166 /**
167 * @since 1.4
168 */
169 public PrettyPrintWriter(Writer writer, NameCoder nameCoder) {
170 this(writer, XML_QUIRKS, new char[]{' ', ' '}, nameCoder, "\n");
171 }
172
173 /**
174 * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, NameCoder)} instead.
175 */
176 public PrettyPrintWriter(Writer writer, XmlFriendlyReplacer replacer) {
177 this(writer, new char[]{' ', ' '}, "\n", replacer);
178 }
179
180 /**
181 * @since 1.3
182 */
183 public PrettyPrintWriter(Writer writer, int mode) {
184 this(writer, mode, new char[]{' ', ' '});
185 }
186
187 public PrettyPrintWriter(Writer writer) {
188 this(writer, new char[]{' ', ' '});
189 }
190
191 public void startNode(String name) {
192 String escapedName = encodeNode(name);
193 tagIsEmpty = false;
194 finishTag();
195 writer.write('<');
196 writer.write(escapedName);
197 elementStack.push(escapedName);
198 tagInProgress = true;
199 depth++ ;
200 readyForNewLine = true;
201 tagIsEmpty = true;
202 }
203
204 public void startNode(String name, Class clazz) {
205 startNode(name);
206 }
207
208 public void setValue(String text) {
209 readyForNewLine = false;
210 tagIsEmpty = false;
211 finishTag();
212
213 writeText(writer, text);
214 }
215
216 public void addAttribute(String key, String value) {
217 writer.write(' ');
218 writer.write(encodeAttribute(key));
219 writer.write('=');
220 writer.write('\"');
221 writeAttributeValue(writer, value);
222 writer.write('\"');
223 }
224
225 protected void writeAttributeValue(QuickWriter writer, String text) {
226 writeText(text, true);
227 }
228
229 protected void writeText(QuickWriter writer, String text) {
230 writeText(text, false);
231 }
232
233 private void writeText(String text, boolean isAttribute) {
234 int length = text.length();
235 for (int i = 0; i < length; i++ ) {
236 char c = text.charAt(i);
237 switch (c) {
238 case '\0':
239 if (mode == XML_QUIRKS) {
240 this.writer.write(NULL);
241 } else {
242 throw new StreamException("Invalid character 0x0 in XML stream");
243 }
244 break;
245 case '&':
246 this.writer.write(AMP);
247 break;
248 case '<':
249 this.writer.write(LT);
250 break;
251 case '>':
252 this.writer.write(GT);
253 break;
254 case '"':
255 this.writer.write(QUOT);
256 break;
257 case '\'':
258 this.writer.write(APOS);
259 break;
260 case '\r':
261 this.writer.write(CR);
262 break;
263 case '\t':
264 case '\n':
265 if (!isAttribute) {
266 this.writer.write(c);
267 break;
268 }
269 default:
270 if (Character.isDefined(c) && !Character.isISOControl(c)) {
271 if (mode != XML_QUIRKS) {
272 if (c > '\ud7ff' && c < '\ue000') {
273 throw new StreamException("Invalid character 0x"
274 + Integer.toHexString(c)
275 + " in XML stream");
276 }
277 }
278 this.writer.write(c);
279 } else {
280 if (mode == XML_1_0) {
281 if (c < 9
282 || c == '\u000b'
283 || c == '\u000c'
284 || c == '\u000e'
285 || (c >= '\u000f' && c <= '\u001f')) {
286 throw new StreamException("Invalid character 0x"
287 + Integer.toHexString(c)
288 + " in XML 1.0 stream");
289 }
290 }
291 if (mode != XML_QUIRKS) {
292 if (c == '\ufffe' || c == '\uffff') {
293 throw new StreamException("Invalid character 0x"
294 + Integer.toHexString(c)
295 + " in XML stream");
296 }
297 }
298 this.writer.write("&#x");
299 this.writer.write(Integer.toHexString(c));
300 this.writer.write(';');
301 }
302 }
303 }
304 }
305
306 public void endNode() {
307 depth-- ;
308 if (tagIsEmpty) {
309 writer.write('/');
310 readyForNewLine = false;
311 finishTag();
312 elementStack.popSilently();
313 } else {
314 finishTag();
315 writer.write(CLOSE);
316 writer.write((String)elementStack.pop());
317 writer.write('>');
318 }
319 readyForNewLine = true;
320 if (depth == 0) {
321 writer.flush();
322 }
323 }
324
325 private void finishTag() {
326 if (tagInProgress) {
327 writer.write('>');
328 }
329 tagInProgress = false;
330 if (readyForNewLine) {
331 endOfLine();
332 }
333 readyForNewLine = false;
334 tagIsEmpty = false;
335 }
336
337 protected void endOfLine() {
338 writer.write(getNewLine());
339 for (int i = 0; i < depth; i++ ) {
340 writer.write(lineIndenter);
341 }
342 }
343
344 public void flush() {
345 writer.flush();
346 }
347
348 public void close() {
349 writer.close();
350 }
351
352 /**
353 * Retrieve the line terminator.
354 *
355 * This method returns always a line feed, since according the XML specification any parser
356 * must ignore a carriage return. Overload this method, if you need different behavior.
357 *
358 * @return the line terminator
359 * @since 1.3
360 */
361 protected String getNewLine() {
362 return newLine;
363 }
364 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 01. October 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import javax.xml.namespace.QName;
14
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 /**
20 * Represents a mapping of {@link QName} instances to Java class names
21 * allowing class aliases and namespace aware mappings of QNames to class names.
22 *
23 * @author James Strachan
24 * @version $Revision: 1345 $
25 */
26 public class QNameMap {
27
28 // lets make the mapping a no-op unless we specify some mapping
29 private Map qnameToJava;
30 private Map javaToQName;
31 private String defaultPrefix = "";
32 private String defaultNamespace = "";
33
34 /**
35 * Returns the Java class name that should be used for the given QName.
36 * If no explicit mapping has been made then the localPart of the QName is used
37 * which is the normal default in XStream.
38 */
39 public String getJavaClassName(QName qname) {
40 if (qnameToJava != null) {
41 String answer = (String) qnameToJava.get(qname);
42 if (answer != null) {
43 return answer;
44 }
45 }
46 return qname.getLocalPart();
47 }
48
49 /**
50 * Returns the Java class name that should be used for the given QName.
51 * If no explicit mapping has been made then the localPart of the QName is used
52 * which is the normal default in XStream.
53 */
54 public QName getQName(String javaClassName) {
55 if (javaToQName != null) {
56 QName answer = (QName) javaToQName.get(javaClassName);
57 if (answer != null) {
58 return answer;
59 }
60 }
61 return new QName(defaultNamespace, javaClassName, defaultPrefix);
62 }
63
64 /**
65 * Registers the mapping of the Java class name to the QName
66 */
67 public synchronized void registerMapping(QName qname, String javaClassName) {
68 if (javaToQName == null) {
69 javaToQName = Collections.synchronizedMap(new HashMap());
70 }
71 if (qnameToJava == null) {
72 qnameToJava = Collections.synchronizedMap(new HashMap());
73 }
74 javaToQName.put(javaClassName, qname);
75 qnameToJava.put(qname, javaClassName);
76 }
77
78 /**
79 * Registers the mapping of the type to the QName
80 */
81 public synchronized void registerMapping(QName qname, Class type) {
82 registerMapping(qname, type.getName());
83 }
84
85 public String getDefaultNamespace() {
86 return defaultNamespace;
87 }
88
89 public void setDefaultNamespace(String defaultNamespace) {
90 this.defaultNamespace = defaultNamespace;
91 }
92
93 public String getDefaultPrefix() {
94 return defaultPrefix;
95 }
96
97 public void setDefaultPrefix(String defaultPrefix) {
98 this.defaultPrefix = defaultPrefix;
99 }
100 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013 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 14. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.io.StreamException;
15 import com.thoughtworks.xstream.io.naming.NameCoder;
16
17 import org.xml.sax.ContentHandler;
18 import org.xml.sax.DTDHandler;
19 import org.xml.sax.EntityResolver;
20 import org.xml.sax.ErrorHandler;
21 import org.xml.sax.InputSource;
22 import org.xml.sax.SAXException;
23 import org.xml.sax.SAXNotRecognizedException;
24 import org.xml.sax.SAXNotSupportedException;
25 import org.xml.sax.XMLReader;
26 import org.xml.sax.helpers.AttributesImpl;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.LinkedList;
33 import java.util.List;
34 import java.util.Map;
35
36 /**
37 * A SAX {@link org.xml.sax.XMLReader parser} that acts as an XStream
38 * {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} to enable direct generation of a
39 * SAX event flow from the XStream serialization of a list of list of Java objects.
40 * <p>
41 * As a
42 * custom SAX parser, this class ignores the arguments of the two standard parse methods ({@link #parse(java.lang.String)}
43 * and {@link #parse(org.xml.sax.InputSource)}) but relies on a proprietary SAX property
44 * {@link #SOURCE_OBJECT_LIST_PROPERTY} to define the list of objects to serialize.
45 * </p>
46 * <p>
47 * Configuration of this SAX parser is achieved through the standard
48 * {@link #setProperty SAX property mechanism}. While specific setter methods require direct
49 * access to the parser instance, SAX properties support configuration settings to be propagated
50 * through a chain of {@link org.xml.sax.XMLFilter filters} down to the underlying parser
51 * object.
52 * </p>
53 * <p>
54 * This mechanism shall be used to configure the
55 * {@link #SOURCE_OBJECT_LIST_PROPERTY objects to be serialized} as well as the
56 * {@link #CONFIGURED_XSTREAM_PROPERTY XStream facade}.
57 * </p>
58 *
59 * @author Laurent Bihanic
60 */
61 public final class SaxWriter extends AbstractXmlWriter implements XMLReader {
62 /**
63 * The {@link #setProperty SAX property} to configure the XStream
64 * facade to be used for object serialization. If the property
65 * is not set, a new XStream facade will be allocated for each
66 * parse.
67 */
68 public final static String CONFIGURED_XSTREAM_PROPERTY =
69 "http://com.thoughtworks.xstream/sax/property/configured-xstream";
70
71 /**
72 * The {@link #setProperty SAX property} to configure the list of
73 * Java objects to serialize. Setting this property prior
74 * invoking one of the parse() methods is mandatory.
75 *
76 * @see #parse(java.lang.String)
77 * @see #parse(org.xml.sax.InputSource)
78 */
79 public final static String SOURCE_OBJECT_LIST_PROPERTY =
80 "http://com.thoughtworks.xstream/sax/property/source-object-list";
81
82 //=========================================================================
83 // SAX XMLReader interface support
84 //=========================================================================
85
86 /**
87 * The SAX EntityResolver associated to this XMLReader.
88 */
89 private EntityResolver entityResolver = null;
90
91 /**
92 * The SAX DTDHandler associated to this XMLReader.
93 */
94 private DTDHandler dtdHandler = null;
95
96 /**
97 * The SAX ContentHandler associated to this XMLReader.
98 */
99 private ContentHandler contentHandler = null;
100
101 /**
102 * The SAX ErrorHandler associated to this XMLReader.
103 */
104 private ErrorHandler errorHandler = null;
105
106 /**
107 * The SAX features defined for this XMLReader.
108 * <p>
109 * This class does not define any feature (yet) and ignores
110 * the SAX mandatory feature. Thus, this member is present
111 * only to support the mandatory feature setting and retrieval
112 * logic defined by SAX.</p>
113 */
114 private Map features = new HashMap();
115
116 /**
117 * The SAX properties defined for this XMLReader.
118 */
119 private final Map properties = new HashMap();
120
121 private final boolean includeEnclosingDocument;
122
123 /**
124 * @since 1.4
125 */
126 public SaxWriter(NameCoder nameCoder)
127 {
128 this(true, nameCoder);
129 }
130
131 /**
132 * @since 1.4
133 */
134 public SaxWriter(boolean includeEnclosingDocument, NameCoder nameCoder)
135 {
136 super(nameCoder);
137 this.includeEnclosingDocument = includeEnclosingDocument;
138 }
139
140 /**
141 * @deprecated As of 1.4 use {@link SaxWriter#SaxWriter(NameCoder)} instead.
142 */
143 public SaxWriter(XmlFriendlyReplacer replacer)
144 {
145 this(true, replacer);
146 }
147
148 /**
149 * @deprecated As of 1.4 use {@link SaxWriter#SaxWriter(boolean, NameCoder)} instead.
150 */
151 public SaxWriter(boolean includeEnclosingDocument, XmlFriendlyReplacer replacer)
152 {
153 this(includeEnclosingDocument, (NameCoder)replacer);
154 }
155
156 public SaxWriter(boolean includeEnclosingDocument) {
157 this(includeEnclosingDocument, new XmlFriendlyNameCoder());
158 }
159
160 public SaxWriter() {
161 this(true);
162 }
163
164 //-------------------------------------------------------------------------
165 // Configuration
166 //-------------------------------------------------------------------------
167
168 /**
169 * Sets the state of a feature.
170 * <p>
171 * The feature name is any fully-qualified URI.</p>
172 * <p>
173 * All XMLReaders are required to support setting
174 * <code>http://xml.org/sax/features/namespaces</code> to
175 * <code>true</code> and
176 * <code>http://xml.org/sax/features/namespace-prefixes</code> to
177 * <code>false</code>.</p>
178 * <p>
179 * Some feature values may be immutable or mutable only
180 * in specific contexts, such as before, during, or after
181 * a parse.</p>
182 * <p>
183 * <strong>Note</strong>: This implementation only supports the two
184 * mandatory SAX features.</p>
185 *
186 * @param name the feature name, which is a fully-qualified URI.
187 * @param value the requested state of the feature (true or false).
188 * @throws SAXNotRecognizedException when the XMLReader does not
189 * recognize the feature name.
190 * @see #getFeature
191 */
192 public void setFeature(String name, boolean value)
193 throws SAXNotRecognizedException {
194 if ((name.equals("http://xml.org/sax/features/namespaces")) ||
195 (name.equals("http://xml.org/sax/features/namespace-prefixes"))) {
196 this.features.put(name, value ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly
197 } else {
198 throw new SAXNotRecognizedException(name);
199 }
200 }
201
202 /**
203 * Looks up the value of a feature.
204 * <p>
205 * The feature name is any fully-qualified URI. It is
206 * possible for an XMLReader to recognize a feature name but
207 * to be unable to return its value; this is especially true
208 * in the case of an adapter for a SAX1 Parser, which has
209 * no way of knowing whether the underlying parser is
210 * performing validation or expanding external entities.</p>
211 * <p>
212 * All XMLReaders are required to recognize the
213 * <code>http://xml.org/sax/features/namespaces</code> and the
214 * <code>http://xml.org/sax/features/namespace-prefixes</code> feature
215 * names.</p>
216 * <p>
217 * Some feature values may be available only in specific
218 * contexts, such as before, during, or after a parse.</p>
219 * <p>
220 * Implementors are free (and encouraged) to invent their own
221 * features, using names built on their own URIs.</p>
222 *
223 * @param name the feature name, which is a fully-qualified URI.
224 * @return the current state of the feature (true or false).
225 * @throws SAXNotRecognizedException when the XMLReader does not
226 * recognize the feature name.
227 * @see #setFeature
228 */
229 public boolean getFeature(String name)
230 throws SAXNotRecognizedException {
231 if ((name.equals("http://xml.org/sax/features/namespaces")) ||
232 (name.equals("http://xml.org/sax/features/namespace-prefixes"))) {
233 Boolean value = (Boolean) (this.features.get(name));
234
235 if (value == null) {
236 value = Boolean.FALSE;
237 }
238 return value.booleanValue();
239 } else {
240 throw new SAXNotRecognizedException(name);
241 }
242 }
243
244 /**
245 * Sets the value of a property.
246 * <p>
247 * The property name is any fully-qualified URI. It is
248 * possible for an XMLReader to recognize a property name but
249 * to be unable to set its value.</p>
250 * <p>
251 * XMLReaders are not required to recognize setting any
252 * specific property names, though a core set is provided with
253 * SAX2.</p>
254 * <p>
255 * Some property values may be immutable or mutable only
256 * in specific contexts, such as before, during, or after
257 * a parse.</p>
258 * <p>
259 * This method is also the standard mechanism for setting
260 * extended handlers.</p>
261 * <p>
262 * <strong>Note</strong>: This implementation only supports two
263 * (proprietary) properties: {@link #CONFIGURED_XSTREAM_PROPERTY}
264 * and {@link #SOURCE_OBJECT_LIST_PROPERTY}.</p>
265 *
266 * @param name the property name, which is a fully-qualified URI.
267 * @param value the requested value for the property.
268 * @throws SAXNotRecognizedException when the XMLReader does not
269 * recognize the property name.
270 * @throws SAXNotSupportedException when the XMLReader recognizes
271 * the property name but cannot set
272 * the requested value.
273 * @see #getProperty
274 */
275 public void setProperty(String name, Object value)
276 throws SAXNotRecognizedException,
277 SAXNotSupportedException {
278 if (name.equals(CONFIGURED_XSTREAM_PROPERTY)) {
279 if (!(value instanceof XStream)) {
280 throw new SAXNotSupportedException("Value for property \"" +
281 CONFIGURED_XSTREAM_PROPERTY +
282 "\" must be a non-null XStream object");
283 }
284 } else if (name.equals(SOURCE_OBJECT_LIST_PROPERTY)) {
285 if (value instanceof List) {
286 List list = (List) value;
287
288 if (list.isEmpty()) {
289 throw new SAXNotSupportedException("Value for property \"" +
290 SOURCE_OBJECT_LIST_PROPERTY +
291 "\" shall not be an empty list");
292 } else {
293 // Perform a copy of the list to prevent the application to
294 // modify its content while the parse is being performed.
295 value = Collections.unmodifiableList(new ArrayList(list));
296 }
297 } else {
298 throw new SAXNotSupportedException("Value for property \"" +
299 SOURCE_OBJECT_LIST_PROPERTY +
300 "\" must be a non-null List object");
301 }
302 } else {
303 throw new SAXNotRecognizedException(name);
304 }
305 this.properties.put(name, value);
306 }
307
308 /**
309 * Looks up the value of a property.
310 * <p>
311 * The property name is any fully-qualified URI. It is
312 * possible for an XMLReader to recognize a property name but
313 * to be unable to return its state.</p>
314 * <p>
315 * XMLReaders are not required to recognize any specific
316 * property names, though an initial core set is documented for
317 * SAX2.</p>
318 * <p>
319 * Some property values may be available only in specific
320 * contexts, such as before, during, or after a parse.</p>
321 * <p>
322 * Implementors are free (and encouraged) to invent their own properties,
323 * using names built on their own URIs.</p>
324 *
325 * @param name the property name, which is a fully-qualified URI.
326 * @return the current value of the property.
327 * @throws SAXNotRecognizedException when the XMLReader does not
328 * recognize the property name.
329 * @see #getProperty
330 */
331 public Object getProperty(String name)
332 throws SAXNotRecognizedException {
333 if ((name.equals(CONFIGURED_XSTREAM_PROPERTY)) ||
334 (name.equals(SOURCE_OBJECT_LIST_PROPERTY))) {
335 return this.properties.get(name);
336 } else {
337 throw new SAXNotRecognizedException(name);
338 }
339 }
340
341 //---------------------------------------------------------------------
342 // Event handlers
343 //---------------------------------------------------------------------
344
345 /**
346 * Allows an application to register an entity resolver.
347 * <p>
348 * If the application does not register an entity resolver,
349 * the XMLReader will perform its own default resolution.</p>
350 * <p>
351 * Applications may register a new or different resolver in the
352 * middle of a parse, and the SAX parser must begin using the new
353 * resolver immediately.</p>
354 *
355 * @param resolver the entity resolver.
356 * @throws NullPointerException if the resolver argument is
357 * <code>null</code>.
358 * @see #getEntityResolver
359 */
360 public void setEntityResolver(EntityResolver resolver) {
361 if (resolver == null) {
362 throw new NullPointerException("resolver");
363 }
364 this.entityResolver = resolver;
365 return;
366 }
367
368 /**
369 * Returns the current entity resolver.
370 *
371 * @return the current entity resolver, or <code>null</code> if none
372 * has been registered.
373 * @see #setEntityResolver
374 */
375 public EntityResolver getEntityResolver() {
376 return this.entityResolver;
377 }
378
379 /**
380 * Allows an application to register a DTD event handler.
381 * <p>
382 * If the application does not register a DTD handler, all DTD
383 * events reported by the SAX parser will be silently ignored.</p>
384 * <p>
385 * Applications may register a new or different handler in the
386 * middle of a parse, and the SAX parser must begin using the new
387 * handler immediately.</p>
388 *
389 * @param handler the DTD handler.
390 * @throws NullPointerException if the handler argument is
391 * <code>null</code>.
392 * @see #getDTDHandler
393 */
394 public void setDTDHandler(DTDHandler handler) {
395 if (handler == null) {
396 throw new NullPointerException("handler");
397 }
398 this.dtdHandler = handler;
399 return;
400 }
401
402 /**
403 * Returns the current DTD handler.
404 *
405 * @return the current DTD handler, or <code>null</code> if none
406 * has been registered.
407 * @see #setDTDHandler
408 */
409 public DTDHandler getDTDHandler() {
410 return this.dtdHandler;
411 }
412
413 /**
414 * Allows an application to register a content event handler.
415 * <p>
416 * If the application does not register a content handler, all
417 * content events reported by the SAX parser will be silently
418 * ignored.</p>
419 * <p>
420 * Applications may register a new or different handler in the
421 * middle of a parse, and the SAX parser must begin using the new
422 * handler immediately.</p>
423 *
424 * @param handler the content handler.
425 * @throws NullPointerException if the handler argument is
426 * <code>null</code>.
427 * @see #getContentHandler
428 */
429 public void setContentHandler(ContentHandler handler) {
430 if (handler == null) {
431 throw new NullPointerException("handler");
432 }
433 this.contentHandler = handler;
434 return;
435 }
436
437 /**
438 * Returns the current content handler.
439 *
440 * @return the current content handler, or <code>null</code> if none
441 * has been registered.
442 * @see #setContentHandler
443 */
444 public ContentHandler getContentHandler() {
445 return this.contentHandler;
446 }
447
448 /**
449 * Allows an application to register an error event handler.
450 * <p>
451 * If the application does not register an error handler, all
452 * error events reported by the SAX parser will be silently
453 * ignored; however, normal processing may not continue. It is
454 * highly recommended that all SAX applications implement an
455 * error handler to avoid unexpected bugs.</p>
456 * <p>
457 * Applications may register a new or different handler in the
458 * middle of a parse, and the SAX parser must begin using the new
459 * handler immediately.</p>
460 *
461 * @param handler the error handler.
462 * @throws NullPointerException if the handler argument is
463 * <code>null</code>.
464 * @see #getErrorHandler
465 */
466 public void setErrorHandler(ErrorHandler handler) {
467 if (handler == null) {
468 throw new NullPointerException("handler");
469 }
470 this.errorHandler = handler;
471 return;
472 }
473
474 /**
475 * Returns the current error handler.
476 *
477 * @return the current error handler, or <code>null</code> if none
478 * has been registered.
479 * @see #setErrorHandler
480 */
481 public ErrorHandler getErrorHandler() {
482 return this.errorHandler;
483 }
484
485 //---------------------------------------------------------------------
486 // Parsing
487 //---------------------------------------------------------------------
488
489 /**
490 * Parses an XML document from a system identifier (URI).
491 * <p>
492 * This method is a shortcut for the common case of reading a
493 * document from a system identifier. It is the exact
494 * equivalent of the following:</p>
495 * <blockquote>
496 * <pre>
497 * parse(new InputSource(systemId));
498 * </pre>
499 * </blockquote>
500 * <p>
501 * If the system identifier is a URL, it must be fully resolved
502 * by the application before it is passed to the parser.</p>
503 * <p>
504 * <strong>Note</strong>: As a custom SAX parser, this class
505 * ignores the <code>systemId</code> argument of this method
506 * and relies on the proprietary SAX property
507 * {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of
508 * objects to serialize.</p>
509 *
510 * @param systemId the system identifier (URI).
511 * @throws SAXException Any SAX exception, possibly wrapping
512 * another exception.
513 * @see #parse(org.xml.sax.InputSource)
514 */
515 public void parse(String systemId) throws SAXException {
516 this.parse();
517 }
518
519 /**
520 * Parse an XML document.
521 * <p>
522 * The application can use this method to instruct the XML
523 * reader to begin parsing an XML document from any valid input
524 * source (a character stream, a byte stream, or a URI).</p>
525 * <p>
526 * Applications may not invoke this method while a parse is in
527 * progress (they should create a new XMLReader instead for each
528 * nested XML document). Once a parse is complete, an
529 * application may reuse the same XMLReader object, possibly
530 * with a different input source.</p>
531 * <p>
532 * During the parse, the XMLReader will provide information
533 * about the XML document through the registered event
534 * handlers.</p>
535 * <p>
536 * This method is synchronous: it will not return until parsing
537 * has ended. If a client application wants to terminate
538 * parsing early, it should throw an exception.</p>
539 * <p>
540 * <strong>Note</strong>: As a custom SAX parser, this class
541 * ignores the <code>source</code> argument of this method
542 * and relies on the proprietary SAX property
543 * {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of
544 * objects to serialize.</p>
545 *
546 * @param input The input source for the top-level of the
547 * XML document.
548 * @throws SAXException Any SAX exception, possibly wrapping
549 * another exception.
550 * @see org.xml.sax.InputSource
551 * @see #parse(java.lang.String)
552 * @see #setEntityResolver
553 * @see #setDTDHandler
554 * @see #setContentHandler
555 * @see #setErrorHandler
556 */
557 public void parse(InputSource input) throws SAXException {
558 this.parse();
559 }
560
561 /**
562 * Serializes the Java objects of the configured list into a flow
563 * of SAX events.
564 *
565 * @throws SAXException if the configured object list is invalid
566 * or object serialization failed.
567 */
568 private void parse() throws SAXException {
569 XStream xstream = (XStream) (this.properties.get(CONFIGURED_XSTREAM_PROPERTY));
570 if (xstream == null) {
571 xstream = new XStream();
572 }
573
574 List source = (List) (this.properties.get(SOURCE_OBJECT_LIST_PROPERTY));
575 if ((source == null) || (source.isEmpty())) {
576 throw new SAXException("Missing or empty source object list. Setting property \"" +
577 SOURCE_OBJECT_LIST_PROPERTY + "\" is mandatory");
578 }
579
580 try {
581 this.startDocument(true);
582 for (Iterator i = source.iterator(); i.hasNext();) {
583 xstream.marshal(i.next(), this);
584 }
585 this.endDocument(true);
586 } catch (StreamException e) {
587 if (e.getCause() instanceof SAXException) {
588 throw (SAXException) (e.getCause());
589 } else {
590 throw new SAXException(e);
591 }
592 }
593 }
594
595
596 //=========================================================================
597 // XStream HierarchicalStreamWriter interface support
598 //=========================================================================
599
600 private int depth = 0;
601 private List elementStack = new LinkedList();
602 private char[] buffer = new char[128];
603 private boolean startTagInProgress = false;
604 private final AttributesImpl attributeList = new AttributesImpl();
605
606 public void startNode(String name) {
607 try {
608 if (this.depth != 0) {
609 this.flushStartTag();
610 } else if (includeEnclosingDocument) {
611 this.startDocument(false);
612 }
613 this.elementStack.add(0, escapeXmlName(name));
614
615 this.startTagInProgress = true;
616 this.depth++;
617 } catch (SAXException e) {
618 throw new StreamException(e);
619 }
620 }
621
622 public void addAttribute(String name, String value) {
623 if (this.startTagInProgress) {
624 String escapedName = escapeXmlName(name);
625 this.attributeList.addAttribute("", escapedName, escapedName, "CDATA", value);
626 } else {
627 throw new StreamException(new IllegalStateException("No startElement being processed"));
628 }
629 }
630
631 public void setValue(String text) {
632 try {
633 this.flushStartTag();
634
635 int lg = text.length();
636 if (lg > buffer.length) {
637 buffer = new char[lg];
638 }
639 text.getChars(0, lg, buffer, 0);
640
641 this.contentHandler.characters(buffer, 0, lg);
642 } catch (SAXException e) {
643 throw new StreamException(e);
644 }
645 }
646
647 public void endNode() {
648 try {
649 this.flushStartTag();
650
651 String tagName = (String) (this.elementStack.remove(0));
652
653 this.contentHandler.endElement("", tagName, tagName);
654
655 this.depth--;
656 if (this.depth == 0 && includeEnclosingDocument) {
657 this.endDocument(false);
658 }
659 } catch (SAXException e) {
660 throw new StreamException(e);
661 }
662 }
663
664 /**
665 * Fires the SAX startDocument event towards the configured
666 * ContentHandler.
667 *
668 * @param multiObjectMode whether serialization of several
669 * object will be merge into a single
670 * SAX document.
671 * @throws SAXException if thrown by the ContentHandler.
672 */
673 private void startDocument(boolean multiObjectMode) throws SAXException {
674 if (this.depth == 0) {
675 // Notify contentHandler of document start.
676 this.contentHandler.startDocument();
677
678 if (multiObjectMode) {
679 // Prevent marshalling of each object to fire its own
680 // start/endDocument events.
681 this.depth++;
682 }
683 }
684 }
685
686 /**
687 * Fires the SAX endDocument event towards the configured
688 * ContentHandler.
689 *
690 * @param multiObjectMode whether serialization of several
691 * object will be merge into a single
692 * SAX document.
693 * @throws SAXException if thrown by the ContentHandler.
694 */
695 private void endDocument(boolean multiObjectMode) throws SAXException {
696 if ((this.depth == 0) || ((this.depth == 1) && (multiObjectMode))) {
697 this.contentHandler.endDocument();
698 this.depth = 0;
699 }
700 }
701
702 /**
703 * Fires any pending SAX startElement event towards the
704 * configured ContentHandler.
705 *
706 * @throws SAXException if thrown by the ContentHandler.
707 */
708 private void flushStartTag() throws SAXException {
709 if (this.startTagInProgress) {
710 String tagName = (String) (this.elementStack.get(0));
711
712 this.contentHandler.startElement("", tagName,
713 tagName, this.attributeList);
714 this.attributeList.clear();
715 this.startTagInProgress = false;
716 }
717 }
718
719 public void flush() {
720 // don't need to do anything
721 }
722
723 public void close() {
724 // don't need to do anything
725 }
726 }
727
0 /*
1 * Copyright (C) 2009, 2011, 2013 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.StreamException;
13
14 import javax.xml.stream.XMLInputFactory;
15 import javax.xml.stream.XMLOutputFactory;
16
17 /**
18 * A driver using the JDK 6 StAX implementation of Sun.
19 *
20 * @author J&ouml;rg Schaible
21 * @since 1.4
22 * @deprecated As of 1.4.5 use {@link StandardStaxDriver}
23 */
24 public class SjsxpDriver extends StaxDriver {
25
26 /**
27 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver()}
28 */
29 public SjsxpDriver() {
30 super();
31 }
32
33 /**
34 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(QNameMap, XmlFriendlyNameCoder)}
35 */
36 public SjsxpDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
37 super(qnameMap, nameCoder);
38 }
39
40 /**
41 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(QNameMap)}
42 */
43 public SjsxpDriver(QNameMap qnameMap) {
44 super(qnameMap);
45 }
46
47 /**
48 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(XmlFriendlyNameCoder)}
49 */
50 public SjsxpDriver(XmlFriendlyNameCoder nameCoder) {
51 super(nameCoder);
52 }
53
54 /**
55 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#createInputFactory()}
56 */
57 protected XMLInputFactory createInputFactory() {
58 Exception exception = null;
59 try {
60 return (XMLInputFactory)Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl").newInstance();
61 } catch (InstantiationException e) {
62 exception = e;
63 } catch (IllegalAccessException e) {
64 exception = e;
65 } catch (ClassNotFoundException e) {
66 exception = e;
67 }
68 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFaqctory instance.", exception);
69 }
70
71 /**
72 * @deprecated As of 1.4.5 use {@link StandardStaxDriver#createOutputFactory()}
73 */
74 protected XMLOutputFactory createOutputFactory() {
75 Exception exception = null;
76 try {
77 return (XMLOutputFactory)Class.forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl").newInstance();
78 } catch (InstantiationException e) {
79 exception = e;
80 } catch (IllegalAccessException e) {
81 exception = e;
82 } catch (ClassNotFoundException e) {
83 exception = e;
84 }
85 throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFaqctory instance.", exception);
86 }
87
88 }
0 /*
1 * Copyright (C) 2013 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 27. July 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.core.JVM;
13 import com.thoughtworks.xstream.io.StreamException;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import javax.xml.stream.XMLInputFactory;
17 import javax.xml.stream.XMLOutputFactory;
18
19
20 /**
21 * A driver using the standard JDK StAX implementation provided by the Java runtime (since Java
22 * 6).
23 * <p>
24 * In contrast to XMLInputFactory.newFactory() or XMLOutputFactory.newFactory() this
25 * implementation will ignore any implementations provided with the system properties
26 * <em>javax.xml.stream.XMLInputFactory</em> and <em>javax.xml.stream.XMLOutputFactory</em>, all
27 * implementations configured in <em>lib/stax.properties</em> or registered with the Service
28 * API.
29 * </p>
30 *
31 * @author J&ouml;rg Schaible
32 * @since 1.4.5
33 */
34 public class StandardStaxDriver extends StaxDriver {
35
36 public StandardStaxDriver() {
37 super();
38 }
39
40 /**
41 * @deprecated As of 1.4.6 use {@link #StandardStaxDriver(QNameMap, NameCoder)}
42 */
43 public StandardStaxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
44 super(qnameMap, nameCoder);
45 }
46
47 /**
48 * @since 1.4.6
49 */
50 public StandardStaxDriver(QNameMap qnameMap, NameCoder nameCoder) {
51 super(qnameMap, nameCoder);
52 }
53
54 public StandardStaxDriver(QNameMap qnameMap) {
55 super(qnameMap);
56 }
57
58 /**
59 * @deprecated As of 1.4.6 use {@link #StandardStaxDriver(NameCoder)}
60 */
61 public StandardStaxDriver(XmlFriendlyNameCoder nameCoder) {
62 super(nameCoder);
63 }
64
65 /**
66 * @since 1.4.6
67 */
68 public StandardStaxDriver(NameCoder nameCoder) {
69 super(nameCoder);
70 }
71
72 protected XMLInputFactory createInputFactory() {
73 Exception exception = null;
74 try {
75 Class staxInputFactory = JVM.getStaxInputFactory();
76 if (staxInputFactory != null) {
77 return (XMLInputFactory)staxInputFactory.newInstance();
78 } else {
79 throw new StreamException("Java runtime has no standard XMLInputFactory implementation.", exception);
80 }
81 } catch (InstantiationException e) {
82 exception = e;
83 } catch (IllegalAccessException e) {
84 exception = e;
85 } catch (ClassNotFoundException e) {
86 exception = e;
87 }
88 throw new StreamException("Cannot create standard XMLInputFactory instance of Java runtime.", exception);
89 }
90
91 protected XMLOutputFactory createOutputFactory() {
92 Exception exception = null;
93 try {
94 Class staxOutputFactory = JVM.getStaxOutputFactory();
95 if (staxOutputFactory != null) {
96 return (XMLOutputFactory)staxOutputFactory.newInstance();
97 } else {
98 throw new StreamException("Java runtime has no standard XMLOutputFactory implementation.", exception);
99 }
100 } catch (InstantiationException e) {
101 exception = e;
102 } catch (IllegalAccessException e) {
103 exception = e;
104 } catch (ClassNotFoundException e) {
105 exception = e;
106 }
107 throw new StreamException("Cannot create standard XMLOutputFactory instance of Java runtime.", exception);
108 }
109
110 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013 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 29. September 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.File;
14 import java.io.FileInputStream;
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.io.OutputStream;
19 import java.io.Reader;
20 import java.io.Writer;
21 import java.net.URL;
22
23 import javax.xml.stream.XMLInputFactory;
24 import javax.xml.stream.XMLOutputFactory;
25 import javax.xml.stream.XMLStreamException;
26 import javax.xml.stream.XMLStreamReader;
27 import javax.xml.stream.XMLStreamWriter;
28 import javax.xml.transform.Source;
29 import javax.xml.transform.stream.StreamSource;
30
31 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
32 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
33 import com.thoughtworks.xstream.io.ReaderWrapper;
34 import com.thoughtworks.xstream.io.StreamException;
35 import com.thoughtworks.xstream.io.naming.NameCoder;
36
37 /**
38 * A driver using the StAX API to create XML reader and writer.
39 *
40 * @author James Strachan
41 * @author J&ouml;rg Schaible
42 * @version $Revision: 2116 $
43 */
44 public class StaxDriver extends AbstractXmlDriver {
45
46 private QNameMap qnameMap;
47 private XMLInputFactory inputFactory;
48 private XMLOutputFactory outputFactory;
49
50 public StaxDriver() {
51 this(new QNameMap());
52 }
53
54 public StaxDriver(QNameMap qnameMap) {
55 this(qnameMap, new XmlFriendlyNameCoder());
56 }
57
58 /**
59 * @since 1.4
60 */
61 public StaxDriver(QNameMap qnameMap, NameCoder nameCoder) {
62 super(nameCoder);
63 this.qnameMap = qnameMap;
64 }
65
66 /**
67 * @since 1.4
68 */
69 public StaxDriver(NameCoder nameCoder) {
70 this(new QNameMap(), nameCoder);
71 }
72
73 /**
74 * @since 1.2
75 * @deprecated As of 1.4, use {@link StaxDriver#StaxDriver(QNameMap, NameCoder)} instead.
76 */
77 public StaxDriver(QNameMap qnameMap, XmlFriendlyReplacer replacer) {
78 this(qnameMap, (NameCoder)replacer);
79 }
80
81 /**
82 * @since 1.2
83 * @deprecated As of 1.4, use {@link StaxDriver#StaxDriver(NameCoder)} instead.
84 */
85 public StaxDriver(XmlFriendlyReplacer replacer) {
86 this(new QNameMap(), (NameCoder)replacer);
87 }
88
89 public HierarchicalStreamReader createReader(Reader xml) {
90 try {
91 return createStaxReader(createParser(xml));
92 } catch (XMLStreamException e) {
93 throw new StreamException(e);
94 }
95 }
96
97 public HierarchicalStreamReader createReader(InputStream in) {
98 try {
99 return createStaxReader(createParser(in));
100 } catch (XMLStreamException e) {
101 throw new StreamException(e);
102 }
103 }
104
105 public HierarchicalStreamReader createReader(URL in) {
106 final InputStream stream;
107 try {
108 stream = in.openStream();
109 HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource(
110 stream, in.toExternalForm())));
111 return new ReaderWrapper(reader) {
112
113 public void close() {
114 super.close();
115 try {
116 stream.close();
117 } catch (IOException e) {
118 // ignore
119 }
120 }
121 };
122 } catch (XMLStreamException e) {
123 throw new StreamException(e);
124 } catch (IOException e) {
125 throw new StreamException(e);
126 }
127 }
128
129 public HierarchicalStreamReader createReader(File in) {
130 final InputStream stream;
131 try {
132 stream = new FileInputStream(in);
133 HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource(
134 stream, in.toURI().toASCIIString())));
135 return new ReaderWrapper(reader) {
136
137 public void close() {
138 super.close();
139 try {
140 stream.close();
141 } catch (IOException e) {
142 // ignore
143 }
144 }
145 };
146 } catch (XMLStreamException e) {
147 throw new StreamException(e);
148 } catch (FileNotFoundException e) {
149 throw new StreamException(e);
150 }
151 }
152
153 public HierarchicalStreamWriter createWriter(Writer out) {
154 try {
155 return createStaxWriter(getOutputFactory().createXMLStreamWriter(out));
156 }
157 catch (XMLStreamException e) {
158 throw new StreamException(e);
159 }
160 }
161
162 public HierarchicalStreamWriter createWriter(OutputStream out) {
163 try {
164 return createStaxWriter(getOutputFactory().createXMLStreamWriter(out));
165 }
166 catch (XMLStreamException e) {
167 throw new StreamException(e);
168 }
169 }
170
171 public AbstractPullReader createStaxReader(XMLStreamReader in) {
172 return new StaxReader(qnameMap, in, getNameCoder());
173 }
174
175 public StaxWriter createStaxWriter(XMLStreamWriter out, boolean writeStartEndDocument) throws XMLStreamException {
176 return new StaxWriter(qnameMap, out, writeStartEndDocument, isRepairingNamespace(), getNameCoder());
177 }
178
179 public StaxWriter createStaxWriter(XMLStreamWriter out) throws XMLStreamException {
180 return createStaxWriter(out, true);
181 }
182
183
184 // Properties
185 //-------------------------------------------------------------------------
186 public QNameMap getQnameMap() {
187 return qnameMap;
188 }
189
190 public void setQnameMap(QNameMap qnameMap) {
191 this.qnameMap = qnameMap;
192 }
193
194 public XMLInputFactory getInputFactory() {
195 if (inputFactory == null) {
196 inputFactory = createInputFactory();
197 }
198 return inputFactory;
199 }
200
201 public XMLOutputFactory getOutputFactory() {
202 if (outputFactory == null) {
203 outputFactory = createOutputFactory();
204 }
205 return outputFactory;
206 }
207
208 public boolean isRepairingNamespace() {
209 return Boolean.TRUE.equals(getOutputFactory().getProperty(
210 XMLOutputFactory.IS_REPAIRING_NAMESPACES));
211 }
212
213 /**
214 * @since 1.2
215 */
216 public void setRepairingNamespace(boolean repairing) {
217 getOutputFactory().setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
218 repairing ? Boolean.TRUE : Boolean.FALSE);
219 }
220
221
222 // Implementation methods
223 //-------------------------------------------------------------------------
224 protected XMLStreamReader createParser(Reader xml) throws XMLStreamException {
225 return getInputFactory().createXMLStreamReader(xml);
226 }
227
228 protected XMLStreamReader createParser(InputStream xml) throws XMLStreamException {
229 return getInputFactory().createXMLStreamReader(xml);
230 }
231
232 protected XMLStreamReader createParser(Source source) throws XMLStreamException {
233 return getInputFactory().createXMLStreamReader(source);
234 }
235
236 /**
237 * @since 1.4
238 */
239 protected XMLInputFactory createInputFactory() {
240 return XMLInputFactory.newInstance();
241 }
242
243 /**
244 * @since 1.4
245 */
246 protected XMLOutputFactory createOutputFactory() {
247 return XMLOutputFactory.newInstance();
248 }
249 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 29. September 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.converters.ErrorWriter;
14 import com.thoughtworks.xstream.io.StreamException;
15 import com.thoughtworks.xstream.io.naming.NameCoder;
16
17 import javax.xml.namespace.QName;
18 import javax.xml.stream.XMLStreamConstants;
19 import javax.xml.stream.XMLStreamException;
20 import javax.xml.stream.XMLStreamReader;
21
22 /**
23 * A reader using the StAX API.
24 *
25 * @author James Strachan
26 * @version $Revision: 1861 $
27 */
28 public class StaxReader extends AbstractPullReader {
29
30 private final QNameMap qnameMap;
31 private final XMLStreamReader in;
32
33 public StaxReader(QNameMap qnameMap, XMLStreamReader in) {
34 this(qnameMap, in, new XmlFriendlyNameCoder());
35 }
36
37 /**
38 * @since 1.4
39 */
40 public StaxReader(QNameMap qnameMap, XMLStreamReader in, NameCoder replacer) {
41 super(replacer);
42 this.qnameMap = qnameMap;
43 this.in = in;
44 moveDown();
45 }
46
47 /**
48 * @since 1.2
49 * @deprecated As of 1.4 use {@link StaxReader#StaxReader(QNameMap, XMLStreamReader, NameCoder)} instead.
50 */
51 public StaxReader(QNameMap qnameMap, XMLStreamReader in, XmlFriendlyReplacer replacer) {
52 this(qnameMap, in, (NameCoder)replacer);
53 }
54
55 protected int pullNextEvent() {
56 try {
57 switch(in.next()) {
58 case XMLStreamConstants.START_DOCUMENT:
59 case XMLStreamConstants.START_ELEMENT:
60 return START_NODE;
61 case XMLStreamConstants.END_DOCUMENT:
62 case XMLStreamConstants.END_ELEMENT:
63 return END_NODE;
64 case XMLStreamConstants.CHARACTERS:
65 return TEXT;
66 case XMLStreamConstants.COMMENT:
67 return COMMENT;
68 default:
69 return OTHER;
70 }
71 } catch (XMLStreamException e) {
72 throw new StreamException(e);
73 }
74 }
75
76 protected String pullElementName() {
77 // let the QNameMap handle any mapping of QNames to Java class names
78 QName qname = in.getName();
79 return qnameMap.getJavaClassName(qname);
80 }
81
82 protected String pullText() {
83 return in.getText();
84 }
85
86 public String getAttribute(String name) {
87 return in.getAttributeValue(null, encodeAttribute(name));
88 }
89
90 public String getAttribute(int index) {
91 return in.getAttributeValue(index);
92 }
93
94 public int getAttributeCount() {
95 return in.getAttributeCount();
96 }
97
98 public String getAttributeName(int index) {
99 return decodeAttribute(in.getAttributeLocalName(index));
100 }
101
102 public void appendErrors(ErrorWriter errorWriter) {
103 errorWriter.add("line number", String.valueOf(in.getLocation().getLineNumber()));
104 }
105
106 public void close() {
107 try {
108 in.close();
109 } catch (XMLStreamException e) {
110 throw new StreamException(e);
111 }
112 }
113
114 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 29. September 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.StreamException;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import javax.xml.namespace.QName;
17 import javax.xml.stream.XMLStreamException;
18 import javax.xml.stream.XMLStreamWriter;
19
20
21 /**
22 * A stream writing that outputs to a StAX stream writer
23 *
24 * @author James Strachan
25 * @version $Revision: 1906 $
26 */
27 public class StaxWriter extends AbstractXmlWriter {
28
29 private final QNameMap qnameMap;
30 private final XMLStreamWriter out;
31 private final boolean writeEnclosingDocument;
32 private boolean namespaceRepairingMode;
33
34 private int tagDepth;
35
36 public StaxWriter(QNameMap qnameMap, XMLStreamWriter out) throws XMLStreamException {
37 this(qnameMap, out, true, true);
38 }
39
40 /**
41 * Allows a StaxWriter to be created for partial XML output
42 *
43 * @param qnameMap is the mapper of Java class names to QNames
44 * @param out the stream to output to
45 * @param nameCoder the xml-friendly replacer to escape Java names
46 * @throws XMLStreamException if the events could not be written to the output
47 * @since 1.4
48 */
49 public StaxWriter(QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder)
50 throws XMLStreamException {
51 this(qnameMap, out, true, true, nameCoder);
52 }
53
54 /**
55 * Allows a StaxWriter to be created for partial XML output
56 *
57 * @param qnameMap is the mapper of Java class names to QNames
58 * @param out the stream to output to
59 * @param writeEnclosingDocument a flag to indicate whether or not the start/end document
60 * events should be written
61 * @param namespaceRepairingMode a flag to enable StAX' namespace repairing mode
62 * @param nameCoder the xml-friendly replacer to escape Java names
63 * @throws XMLStreamException if the events could not be written to the output
64 * @since 1.4
65 */
66 public StaxWriter(
67 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
68 boolean namespaceRepairingMode, NameCoder nameCoder) throws XMLStreamException {
69 super(nameCoder);
70 this.qnameMap = qnameMap;
71 this.out = out;
72 this.writeEnclosingDocument = writeEnclosingDocument;
73 this.namespaceRepairingMode = namespaceRepairingMode;
74 if (writeEnclosingDocument) {
75 out.writeStartDocument();
76 }
77 }
78
79 /**
80 * Allows a StaxWriter to be created for partial XML output
81 *
82 * @param qnameMap is the mapper of Java class names to QNames
83 * @param out the stream to output to
84 * @param writeEnclosingDocument a flag to indicate whether or not the start/end document
85 * events should be written
86 * @throws XMLStreamException if the events could not be written to the output
87 */
88 public StaxWriter(
89 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
90 boolean namespaceRepairingMode) throws XMLStreamException {
91 this(
92 qnameMap, out, writeEnclosingDocument, namespaceRepairingMode,
93 new XmlFriendlyNameCoder());
94 }
95
96 /**
97 * Allows a StaxWriter to be created for partial XML output
98 *
99 * @param qnameMap is the mapper of Java class names to QNames
100 * @param out the stream to output to
101 * @param writeEnclosingDocument a flag to indicate whether or not the start/end document
102 * events should be written
103 * @param replacer the xml-friendly replacer to escape Java names
104 * @throws XMLStreamException if the events could not be written to the output
105 * @since 1.2
106 * @deprecated As of 1.4 use
107 * {@link StaxWriter#StaxWriter(QNameMap, XMLStreamWriter, boolean, boolean, NameCoder)}
108 * instead
109 */
110 public StaxWriter(
111 QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument,
112 boolean namespaceRepairingMode, XmlFriendlyReplacer replacer) throws XMLStreamException {
113 this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder)replacer);
114 }
115
116 public void flush() {
117 try {
118 out.flush();
119 } catch (XMLStreamException e) {
120 throw new StreamException(e);
121 }
122 }
123
124 /**
125 * Call this method when you're finished with me
126 */
127 public void close() {
128 try {
129 out.close();
130 } catch (XMLStreamException e) {
131 throw new StreamException(e);
132 }
133 }
134
135 public void addAttribute(String name, String value) {
136 try {
137 out.writeAttribute(encodeAttribute(name), value);
138 } catch (XMLStreamException e) {
139 throw new StreamException(e);
140 }
141 }
142
143 public void endNode() {
144 try {
145 tagDepth-- ;
146 out.writeEndElement();
147 if (tagDepth == 0 && writeEnclosingDocument) {
148 out.writeEndDocument();
149 }
150 } catch (XMLStreamException e) {
151 throw new StreamException(e);
152 }
153 }
154
155 public void setValue(String text) {
156 try {
157 out.writeCharacters(text);
158 } catch (XMLStreamException e) {
159 throw new StreamException(e);
160 }
161 }
162
163 public void startNode(String name) {
164 try {
165 QName qname = qnameMap.getQName(encodeNode(name));
166 String prefix = qname.getPrefix();
167 String uri = qname.getNamespaceURI();
168
169 // before you ask - yes it really is this complicated to output QNames to StAX
170 // handling both repair namespace modes :)
171
172 boolean hasPrefix = prefix != null && prefix.length() > 0;
173 boolean hasURI = uri != null && uri.length() > 0;
174 boolean writeNamespace = false;
175
176 if (hasURI) {
177 if (hasPrefix) {
178 String currentNamespace = out.getNamespaceContext().getNamespaceURI(prefix);
179 if (currentNamespace == null || !currentNamespace.equals(uri)) {
180 writeNamespace = true;
181 }
182 } else {
183 String defaultNamespace = out.getNamespaceContext().getNamespaceURI("");
184 if (defaultNamespace == null || !defaultNamespace.equals(uri)) {
185 writeNamespace = true;
186 }
187 }
188 }
189
190 out.writeStartElement(prefix, qname.getLocalPart(), uri);
191 if (hasPrefix) {
192 out.setPrefix(prefix, uri);
193 } else if (hasURI) {
194 if (writeNamespace) {
195 out.setDefaultNamespace(uri);
196 }
197 }
198 if (hasURI && writeNamespace && !isNamespaceRepairingMode()) {
199 if (hasPrefix) {
200 out.writeNamespace(prefix, uri);
201 } else {
202 out.writeDefaultNamespace(uri);
203 }
204 }
205 tagDepth++ ;
206 } catch (XMLStreamException e) {
207 throw new StreamException(e);
208 }
209 }
210
211 /**
212 * Is StAX namespace repairing mode on or off?
213 */
214 public boolean isNamespaceRepairingMode() {
215 return namespaceRepairingMode;
216 }
217
218 protected QNameMap getQNameMap() {
219 return this.qnameMap;
220 }
221
222 protected XMLStreamWriter getXMLStreamWriter() {
223 return this.out;
224 }
225
226 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 14. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import org.xml.sax.InputSource;
16 import org.xml.sax.SAXException;
17 import org.xml.sax.XMLFilter;
18 import org.xml.sax.XMLReader;
19
20 import javax.xml.transform.sax.SAXSource;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26 /**
27 * A {@link SAXSource JAXP TrAX Source} that enables using XStream object serialization as
28 * direct input for XSLT processors without resorting to an intermediate representation such as
29 * text XML, DOM or DOM4J.
30 * <p>
31 * The following example shows how to apply an XSL Transformation
32 * to a set of Java objects gathered into a List (<code>source</code>):
33 * </p>
34 *
35 * <pre><code>
36 * public static String transform(List source, String stylesheet) {
37 * try {
38 * Transformer transformer = TransformerFactory.newInstance().newTransformer(
39 * new StreamSource(stylesheet));
40 * TraxSource in = new TraxSource(source);
41 * Writer out = new StringWriter();
42 * transformer.transform(in, new StreamResult(out));
43 * return out.toString();
44 * } catch (TransformerException e) {
45 * throw new RuntimeException(&quot;XSLT Transformation failed&quot;, e);
46 * }
47 * }
48 * </code></pre>
49 *
50 * @author Laurent Bihanic
51 */
52 public class TraxSource extends SAXSource {
53
54 /**
55 * If {@link javax.xml.transform.TransformerFactory#getFeature} returns <code>true</code>
56 * when passed this value as an argument, the Transformer natively supports XStream.
57 * <p>
58 * <strong>Note</strong>: This implementation does not override the
59 * {@link SAXSource#FEATURE} value defined by its superclass to be considered as a SAXSource
60 * by Transformer implementations not natively supporting this XStream-specific source
61 * </p>
62 */
63 public final static String XSTREAM_FEATURE = "http://com.thoughtworks.xstream/XStreamSource/feature";
64
65 /**
66 * The XMLReader object associated to this source or <code>null</code> if no XMLReader has
67 * yet been requested.
68 *
69 * @see #getXMLReader
70 */
71 private XMLReader xmlReader = null;
72
73 /**
74 * The configured XStream facade to use for serializing objects.
75 */
76 private XStream xstream = null;
77
78 /**
79 * The list of Java objects to be serialized.
80 */
81 private List source = null;
82
83 // -------------------------------------------------------------------------
84 // Constructors
85 // -------------------------------------------------------------------------
86
87 /**
88 * Creates a XStream TrAX source.
89 */
90 public TraxSource() {
91 super(new InputSource());
92 }
93
94 /**
95 * Creates a XStream TrAX source, specifying the object to marshal.
96 *
97 * @param source the object to marshal.
98 * @throws IllegalArgumentException if <code>source</code> is <code>null</code>.
99 * @see #setSource(java.lang.Object)
100 */
101 public TraxSource(Object source) {
102 super(new InputSource());
103
104 this.setSource(source);
105 }
106
107 /**
108 * Creates a XStream TrAX source, specifying the object to marshal and a configured (with
109 * aliases) XStream facade.
110 *
111 * @param source the object to marshal.
112 * @param xstream a configured XStream facade.
113 * @throws IllegalArgumentException if <code>source</code> or <code>xstream</code> is
114 * <code>null</code>.
115 * @see #setSource(java.lang.Object)
116 * @see #setXStream(com.thoughtworks.xstream.XStream)
117 */
118 public TraxSource(Object source, XStream xstream) {
119 super(new InputSource());
120
121 this.setSource(source);
122 this.setXStream(xstream);
123 }
124
125 /**
126 * Creates a XStream TrAX source, setting the objects to marshal.
127 *
128 * @param source the list of objects to marshal.
129 * @throws IllegalArgumentException if <code>source</code> is <code>null</code> or
130 * empty.
131 * @see #setSourceAsList(java.util.List)
132 */
133 public TraxSource(List source) {
134 super(new InputSource());
135
136 this.setSourceAsList(source);
137 }
138
139 /**
140 * Creates a XStream TrAX source, setting the objects to marshal and a configured (with
141 * aliases) XStream facade.
142 *
143 * @param source the list of objects to marshal.
144 * @param xstream a configured XStream facade.
145 * @throws IllegalArgumentException if <code>source</code> or <code>xstream</code> is
146 * <code>null</code> or <code>source</code> is empty.
147 * @see #setSourceAsList(java.util.List)
148 * @see #setXStream(com.thoughtworks.xstream.XStream)
149 */
150 public TraxSource(List source, XStream xstream) {
151 super(new InputSource());
152
153 this.setSourceAsList(source);
154 this.setXStream(xstream);
155 }
156
157 // -------------------------------------------------------------------------
158 // SAXSource overwritten methods
159 // -------------------------------------------------------------------------
160
161 /**
162 * Sets the SAX InputSource to be used for the Source.
163 * <p>
164 * As this implementation only
165 * supports object lists as data source, this method always throws an
166 * {@link UnsupportedOperationException}.
167 * </p>
168 *
169 * @param inputSource a valid InputSource reference.
170 * @throws UnsupportedOperationException always!
171 */
172 public void setInputSource(InputSource inputSource) {
173 throw new UnsupportedOperationException();
174 }
175
176 /**
177 * Set the XMLReader to be used for the Source.
178 * <p>
179 * As this implementation only supports
180 * object lists as data source, this method throws an {@link UnsupportedOperationException}
181 * if the provided reader object does not implement the SAX {@link XMLFilter} interface.
182 * Otherwise, a {@link SaxWriter} instance will be attached as parent of the filter chain.
183 * </p>
184 *
185 * @param reader a valid XMLReader or XMLFilter reference.
186 * @throws UnsupportedOperationException if <code>reader</code> is not a SAX
187 * {@link XMLFilter}.
188 * @see #getXMLReader
189 */
190 public void setXMLReader(XMLReader reader) {
191 this.createXMLReader(reader);
192 }
193
194 /**
195 * Returns the XMLReader to be used for the Source.
196 * <p>
197 * This implementation returns a
198 * specific XMLReader ({@link SaxWriter}) generating the XML from a list of input objects.
199 * </p>
200 *
201 * @return an XMLReader generating the XML from a list of input objects.
202 */
203 public XMLReader getXMLReader() {
204 if (this.xmlReader == null) {
205 this.createXMLReader(null);
206 }
207 return this.xmlReader;
208 }
209
210 // -------------------------------------------------------------------------
211 // Specific implementation
212 // -------------------------------------------------------------------------
213
214 /**
215 * Sets the XStream facade to use when marshalling objects.
216 *
217 * @param xstream a configured XStream facade.
218 * @throws IllegalArgumentException if <code>xstream</code> is <code>null</code>.
219 */
220 public void setXStream(XStream xstream) {
221 if (xstream == null) {
222 throw new IllegalArgumentException("xstream");
223 }
224 this.xstream = xstream;
225
226 this.configureXMLReader();
227 }
228
229 /**
230 * Sets the object to marshal.
231 *
232 * @param obj the object to marshal.
233 * @throws IllegalArgumentException if <code>source</code> is <code>null</code>.
234 */
235 public void setSource(Object obj) {
236 if (obj == null) {
237 throw new IllegalArgumentException("obj");
238 }
239 List list = new ArrayList(1);
240 list.add(obj);
241
242 this.setSourceAsList(list);
243 }
244
245 /**
246 * Sets the list of objects to marshal.
247 * <p>
248 * When dealing with non-text input (such as SAX
249 * or DOM), XSLT processors support multiple root node children for the source tree (see <a
250 * href="http://www.w3.org/TR/xslt#root-node-children">section 3.1</a> of the &quot;XSL
251 * Transformations (XSLT) Version 1.0&quot; specification. Using a list of objects as source
252 * makes use of this feature and allows creating XML documents merging the XML serialization
253 * of several Java objects.
254 *
255 * @param list the list of objects to marshal.
256 * @throws IllegalArgumentException if <code>source</code> is <code>null</code> or
257 * empty.
258 */
259 public void setSourceAsList(List list) {
260 if ((list == null) || (list.isEmpty())) {
261 throw new IllegalArgumentException("list");
262 }
263 this.source = list;
264
265 this.configureXMLReader();
266 }
267
268 private void createXMLReader(XMLReader filterChain) {
269 if (filterChain == null) {
270 this.xmlReader = new SaxWriter();
271 } else {
272 if (filterChain instanceof XMLFilter) {
273 // Connect the filter chain to a document reader.
274 XMLFilter filter = (XMLFilter)filterChain;
275 while (filter.getParent() instanceof XMLFilter) {
276 filter = (XMLFilter)(filter.getParent());
277 }
278 if (!(filter.getParent() instanceof SaxWriter)) {
279 filter.setParent(new SaxWriter());
280 }
281
282 // Read XML data from filter chain.
283 this.xmlReader = filterChain;
284 } else {
285 throw new UnsupportedOperationException();
286 }
287 }
288 this.configureXMLReader();
289 }
290
291 private void configureXMLReader() {
292 if (this.xmlReader != null) {
293 try {
294 if (this.xstream != null) {
295 this.xmlReader.setProperty(
296 SaxWriter.CONFIGURED_XSTREAM_PROPERTY, this.xstream);
297 }
298 if (this.source != null) {
299 this.xmlReader.setProperty(
300 SaxWriter.SOURCE_OBJECT_LIST_PROPERTY, this.source);
301 }
302 } catch (SAXException e) {
303 throw new IllegalArgumentException(e.getMessage());
304 }
305 }
306 }
307 }
0 /*
1 * Copyright (C) 2009, 2011 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.ctc.wstx.stax.WstxInputFactory;
13 import com.ctc.wstx.stax.WstxOutputFactory;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import javax.xml.stream.XMLInputFactory;
17 import javax.xml.stream.XMLOutputFactory;
18
19 /**
20 * A driver using the Woodstox StAX implementation.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class WstxDriver extends StaxDriver {
26
27 public WstxDriver() {
28 super();
29 }
30
31 /**
32 * @deprecated As of 1.4.6 use {@link #WstxDriver(QNameMap, NameCoder)}
33 */
34 public WstxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) {
35 super(qnameMap, nameCoder);
36 }
37
38 /**
39 * @since 1.4.6
40 */
41 public WstxDriver(QNameMap qnameMap, NameCoder nameCoder) {
42 super(qnameMap, nameCoder);
43 }
44
45 public WstxDriver(QNameMap qnameMap) {
46 super(qnameMap);
47 }
48
49 /**
50 * @deprecated As of 1.4.6 use {@link #WstxDriver(NameCoder)}
51 */
52 public WstxDriver(XmlFriendlyNameCoder nameCoder) {
53 super(nameCoder);
54 }
55
56 /**
57 * @since 1.4.6
58 */
59 public WstxDriver(NameCoder nameCoder) {
60 super(nameCoder);
61 }
62
63 protected XMLInputFactory createInputFactory() {
64 return new WstxInputFactory();
65 }
66
67 protected XMLOutputFactory createOutputFactory() {
68 return new WstxOutputFactory();
69 }
70
71 }
0 /*
1 * Copyright (C) 2009, 2011 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 15. August 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12
13 /**
14 * A XmlFriendlyNameCoder to support backward compatibility with XStream 1.1.
15 *
16 * @author J&ouml;rg Schaible
17 * @since 1.4
18 */
19 public class XStream11NameCoder extends XmlFriendlyNameCoder {
20
21 /**
22 * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1
23 * compatibility.
24 */
25 public String decodeAttribute(String attributeName) {
26 return attributeName;
27 }
28
29 /**
30 * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1
31 * compatibility.
32 */
33 public String decodeNode(String elementName) {
34 return elementName;
35 }
36 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 22. April 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 /**
14 * Allows replacement of Strings in xml-friendly drivers to provide compatibility with XStream
15 * 1.1 format
16 *
17 * @author Mauro Talevi
18 * @since 1.2
19 * @deprecated As of 1.4, use {@link XStream11NameCoder} instead
20 */
21 public class XStream11XmlFriendlyReplacer extends XmlFriendlyReplacer {
22
23 /**
24 * Default constructor.
25 *
26 * @deprecated As of 1.4, use {@link XStream11NameCoder} instead
27 */
28 public XStream11XmlFriendlyReplacer() {
29 }
30
31 /**
32 * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1
33 * compatibility.
34 */
35 public String decodeAttribute(String attributeName) {
36 return attributeName;
37 }
38
39 /**
40 * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1
41 * compatibility.
42 */
43 public String decodeNode(String elementName) {
44 return elementName;
45 }
46
47 /**
48 * Noop implementation that does not unescape name. Used for XStream 1.1 compatibility.
49 *
50 * @param name the name of attribute or node
51 * @return The String with unescaped name
52 */
53 public String unescapeName(String name) {
54 return name;
55 }
56
57 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 15. August 2009 by Joerg Schaible, copied from XmlFriendlyReplacer.
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.Map;
19
20
21 /**
22 * Encode and decode tag and attribute names in XML drivers.
23 * <p>
24 * This NameCoder is designed to ensure the correct encoding and decoding of names used for Java
25 * types and fields to XML tags and attribute names.
26 * </p>
27 * <p>
28 * The default replacements are:
29 * </p>
30 * <ul>
31 * <li><b>$</b> (dollar) chars are replaced with <b>_-</b> (underscore dash) string.</li>
32 * <li><b>_</b> (underscore) chars are replaced with <b>__</b> (double underscore) string.</li>
33 * <li>other characters that are invalid in XML names are encoded with <b>_.XXXX</b> (underscore
34 * dot followed by hex representation of character).</li>
35 * </ul>
36 *
37 * @author J&ouml;rg Schaible
38 * @author Mauro Talevi
39 * @author Tatu Saloranta
40 * @author Michael Schnell
41 * @see <a href="http://www.w3.org/TR/REC-xml/#dt-name">XML 1.0 name definition</a>
42 * @see <a href="http://www.w3.org/TR/xml11/#dt-name">XML 1.1 name definition</a>
43 * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">Java
44 * identifier definition</a>
45 * @since 1.4
46 */
47 public class XmlFriendlyNameCoder implements NameCoder, Cloneable {
48 private static final IntPair[] XML_NAME_START_CHAR_BOUNDS;
49 private static final IntPair[] XML_NAME_CHAR_EXTRA_BOUNDS;
50 static {
51 class IntPairList extends ArrayList {
52 void add(int min, int max) {
53 super.add(new IntPair(min, max));
54 }
55
56 void add(char cp) {
57 super.add(new IntPair(cp, cp));
58 }
59 }
60
61 // legal characters in XML names according to
62 // http://www.w3.org/TR/REC-xml/#NT-Name and
63 // http://www.w3.org/TR/xml11/#NT-Name
64 IntPairList list = new IntPairList();
65
66 list.add(':');
67 list.add('A', 'Z');
68 list.add('a', 'z');
69 list.add('_');
70
71 list.add(0xC0, 0xD6);
72 list.add(0xD8, 0xF6);
73 list.add(0xF8, 0x2FF);
74 list.add(0x370, 0x37D);
75 list.add(0x37F, 0x1FFF);
76 list.add(0x200C, 0x200D);
77 list.add(0x2070, 0x218F);
78 list.add(0x2C00, 0x2FEF);
79 list.add(0x3001, 0xD7FF);
80 list.add(0xF900, 0xFDCF);
81 list.add(0xFDF0, 0xFFFD);
82 list.add(0x10000, 0xEFFFF);
83 XML_NAME_START_CHAR_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]);
84
85 list.clear();
86 list.add('-');
87 list.add('.');
88 list.add('0', '9');
89 list.add('\u00b7');
90 list.add(0x0300, 0x036F);
91 list.add(0x203F, 0x2040);
92 XML_NAME_CHAR_EXTRA_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]);
93 }
94
95 private final String dollarReplacement;
96 private final String escapeCharReplacement;
97 private transient Map escapeCache;
98 private transient Map unescapeCache;
99 private final String hexPrefix;
100
101 /**
102 * Construct a new XmlFriendlyNameCoder.
103 *
104 * @since 1.4
105 */
106 public XmlFriendlyNameCoder() {
107 this("_-", "__");
108 }
109
110 /**
111 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the
112 * escape character.
113 *
114 * @param dollarReplacement
115 * @param escapeCharReplacement
116 * @since 1.4
117 */
118 public XmlFriendlyNameCoder(String dollarReplacement, String escapeCharReplacement) {
119 this(dollarReplacement, escapeCharReplacement, "_.");
120 }
121
122 /**
123 * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the
124 * escape character and the prefix for hexadecimal encoding of invalid characters in XML
125 * names.
126 *
127 * @param dollarReplacement
128 * @param escapeCharReplacement
129 * @since 1.4
130 */
131 public XmlFriendlyNameCoder(
132 String dollarReplacement, String escapeCharReplacement, String hexPrefix) {
133 this.dollarReplacement = dollarReplacement;
134 this.escapeCharReplacement = escapeCharReplacement;
135 this.hexPrefix = hexPrefix;
136 readResolve();
137 }
138
139 /**
140 * {@inheritDoc}
141 */
142 public String decodeAttribute(String attributeName) {
143 return decodeName(attributeName);
144 }
145
146 /**
147 * {@inheritDoc}
148 */
149 public String decodeNode(String elementName) {
150 return decodeName(elementName);
151 }
152
153 /**
154 * {@inheritDoc}
155 */
156 public String encodeAttribute(String name) {
157 return encodeName(name);
158 }
159
160 /**
161 * {@inheritDoc}
162 */
163 public String encodeNode(String name) {
164 return encodeName(name);
165 }
166
167 private String encodeName(String name) {
168 String s = (String)escapeCache.get(name);
169 if (s == null) {
170 final int length = name.length();
171
172 // First, fast (common) case: nothing to escape
173 int i = 0;
174
175 for (; i < length; i++ ) {
176 char c = name.charAt(i);
177 if (c == '$' || c == '_' || c <= 27 || c >= 127) {
178 break;
179 }
180 }
181
182 if (i == length) {
183 return name;
184 }
185
186 // Otherwise full processing
187 final StringBuffer result = new StringBuffer(length + 8);
188
189 // We know first N chars are safe
190 if (i > 0) {
191 result.append(name.substring(0, i));
192 }
193
194 for (; i < length; i++ ) {
195 char c = name.charAt(i);
196 if (c == '$') {
197 result.append(dollarReplacement);
198 } else if (c == '_') {
199 result.append(escapeCharReplacement);
200 } else if ((i == 0 && !isXmlNameStartChar(c)) || (i > 0 && !isXmlNameChar(c))) {
201 result.append(hexPrefix);
202 if (c < 16) result.append("000");
203 else if (c < 256) result.append("00");
204 else if (c < 4096) result.append("0");
205 result.append(Integer.toHexString(c));
206 } else {
207 result.append(c);
208 }
209 }
210 s = result.toString();
211 escapeCache.put(name, s);
212 }
213 return s;
214 }
215
216 private String decodeName(String name) {
217 String s = (String)unescapeCache.get(name);
218 if (s == null) {
219 final char dollarReplacementFirstChar = dollarReplacement.charAt(0);
220 final char escapeReplacementFirstChar = escapeCharReplacement.charAt(0);
221 final char hexPrefixFirstChar = hexPrefix.charAt(0);
222 final int length = name.length();
223
224 // First, fast (common) case: nothing to decode
225 int i = 0;
226
227 for (; i < length; i++ ) {
228 char c = name.charAt(i);
229 // We'll do a quick check for potential match
230 if (c == dollarReplacementFirstChar
231 || c == escapeReplacementFirstChar
232 || c == hexPrefixFirstChar) {
233 // and if it might be a match, just quit, will check later on
234 break;
235 }
236 }
237
238 if (i == length) {
239 return name;
240 }
241
242 // Otherwise full processing
243 final StringBuffer result = new StringBuffer(length + 8);
244
245 // We know first N chars are safe
246 if (i > 0) {
247 result.append(name.substring(0, i));
248 }
249
250 for (; i < length; i++ ) {
251 char c = name.charAt(i);
252 if (c == dollarReplacementFirstChar && name.startsWith(dollarReplacement, i)) {
253 i += dollarReplacement.length() - 1;
254 result.append('$');
255 } else if (c == hexPrefixFirstChar && name.startsWith(hexPrefix, i)) {
256 i += hexPrefix.length();
257 c = (char)Integer.parseInt(name.substring(i, i + 4), 16);
258 i += 3;
259 result.append(c);
260 } else if (c == escapeReplacementFirstChar
261 && name.startsWith(escapeCharReplacement, i)) {
262 i += escapeCharReplacement.length() - 1;
263 result.append('_');
264 } else {
265 result.append(c);
266 }
267 }
268
269 s = result.toString();
270 unescapeCache.put(name, s);
271 }
272 return s;
273 }
274
275 public Object clone() {
276 try {
277 XmlFriendlyNameCoder coder = (XmlFriendlyNameCoder)super.clone();
278 coder.readResolve();
279 return coder;
280
281 } catch (CloneNotSupportedException e) {
282 throw new ObjectAccessException("Cannot clone XmlFriendlyNameCoder", e);
283 }
284 }
285
286 private Object readResolve() {
287 escapeCache = createCacheMap();
288 unescapeCache = createCacheMap();
289 return this;
290 }
291
292 protected Map createCacheMap() {
293 return new HashMap();
294 }
295
296 private static class IntPair {
297 int min;
298 int max;
299
300 public IntPair(int min, int max) {
301 this.min = min;
302 this.max = max;
303 }
304 }
305
306 private static boolean isXmlNameStartChar(int cp) {
307 return isInNameCharBounds(cp, XML_NAME_START_CHAR_BOUNDS);
308 }
309
310 private static boolean isXmlNameChar(int cp) {
311 if (isXmlNameStartChar(cp)) {
312 return true;
313 }
314 return isInNameCharBounds(cp, XML_NAME_CHAR_EXTRA_BOUNDS);
315 }
316
317 private static boolean isInNameCharBounds(int cp, IntPair[] nameCharBounds) {
318 for (int i = 0; i < nameCharBounds.length; ++i) {
319 IntPair p = nameCharBounds[i];
320 if (cp >= p.min && cp <= p.max) {
321 return true;
322 }
323 }
324 return false;
325 }
326 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011 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 26. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 /**
13 * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} supporting
14 * XML-friendly names.
15 *
16 * @author J&ouml;rg Schaible
17 * @author Mauro Talevi
18 * @since 1.3
19 * @deprecated As of 1.4
20 */
21 public interface XmlFriendlyReader {
22
23 /**
24 * Unescapes XML-friendly name (node or attribute)
25 *
26 * @param name the escaped XML-friendly name
27 * @return An unescaped name with original characters
28 * @deprecated As of 1.4
29 */
30 String unescapeXmlName(String name);
31
32 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 17. April 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 /**
14 * Allows replacement of Strings in XML-friendly drivers. The default replacements are:
15 * <ul>
16 * <li><b>$</b> (dollar) chars are replaced with <b>_-</b> (underscore dash) string.<br>
17 * </li>
18 * <li><b>_</b> (underscore) chars are replaced with <b>__</b> (double underscore) string.<br>
19 * </li>
20 * </ul>
21 *
22 * @author Mauro Talevi
23 * @author J&ouml;rg Schaible
24 * @author Tatu Saloranta
25 * @since 1.2
26 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead
27 */
28 public class XmlFriendlyReplacer extends XmlFriendlyNameCoder {
29
30 /**
31 * Default constructor.
32 *
33 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead
34 */
35 public XmlFriendlyReplacer() {
36 this("_-", "__");
37 }
38
39 /**
40 * Creates an XmlFriendlyReplacer with custom replacements
41 *
42 * @param dollarReplacement the replacement for '$'
43 * @param underscoreReplacement the replacement for '_'
44 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead
45 */
46 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement) {
47 super(dollarReplacement, underscoreReplacement);
48 }
49
50 /**
51 * Escapes name substituting '$' and '_' with replacement strings
52 *
53 * @param name the name of attribute or node
54 * @return The String with the escaped name
55 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead
56 */
57 public String escapeName(String name) {
58 return super.encodeNode(name);
59 }
60
61 /**
62 * Unescapes name re-enstating '$' and '_' when replacement strings are found
63 *
64 * @param name the name of attribute or node
65 * @return The String with unescaped name
66 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead
67 */
68 public String unescapeName(String name) {
69 return super.decodeNode(name);
70 }
71
72 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011 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 26. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 /**
13 * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} supporting
14 * XML-friendly names.
15 *
16 * @author J&ouml;rg Schaible
17 * @author Mauro Talevi
18 * @since 1.3
19 * @deprecated As of 1.4
20 */
21 public interface XmlFriendlyWriter {
22
23 /**
24 * Escapes XML name (node or attribute) to be XML-friendly
25 *
26 * @param name the unescaped XML name
27 * @return An escaped name with original characters replaced
28 * @deprecated As of 1.4
29 */
30 String escapeXmlName(String name);
31 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 12. April 2006 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17 import java.io.OutputStreamWriter;
18 import java.io.Reader;
19 import java.io.Writer;
20 import java.net.URL;
21
22 import nu.xom.Builder;
23 import nu.xom.Document;
24 import nu.xom.ParsingException;
25 import nu.xom.ValidityException;
26
27 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
28 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
29 import com.thoughtworks.xstream.io.StreamException;
30 import com.thoughtworks.xstream.io.naming.NameCoder;
31
32 public class XomDriver extends AbstractXmlDriver {
33
34 private final Builder builder;
35
36 public XomDriver() {
37 this(new Builder());
38 }
39
40 public XomDriver(Builder builder) {
41 this(builder, new XmlFriendlyNameCoder());
42 }
43
44 /**
45 * @since 1.4
46 */
47 public XomDriver(NameCoder nameCoder) {
48 this(new Builder(), nameCoder);
49 }
50
51 /**
52 * @since 1.4
53 */
54 public XomDriver(Builder builder, NameCoder nameCoder) {
55 super(nameCoder);
56 this.builder = builder;
57 }
58
59 /**
60 * @since 1.2
61 * @deprecated As of 1.4, use {@link #XomDriver(Builder, NameCoder)} instead
62 */
63 public XomDriver(XmlFriendlyReplacer replacer) {
64 this(new Builder(), replacer);
65 }
66
67 /**
68 * @since 1.2
69 * @deprecated As of 1.4, use {@link #XomDriver(Builder, NameCoder)} instead
70 */
71 public XomDriver(Builder builder, XmlFriendlyReplacer replacer) {
72 this((NameCoder)replacer);
73 }
74
75 protected Builder getBuilder() {
76 return this.builder;
77 }
78
79 public HierarchicalStreamReader createReader(Reader text) {
80 try {
81 Document document = builder.build(text);
82 return new XomReader(document, getNameCoder());
83 } catch (ValidityException e) {
84 throw new StreamException(e);
85 } catch (ParsingException e) {
86 throw new StreamException(e);
87 } catch (IOException e) {
88 throw new StreamException(e);
89 }
90 }
91
92 public HierarchicalStreamReader createReader(InputStream in) {
93 try {
94 Document document = builder.build(in);
95 return new XomReader(document, getNameCoder());
96 } catch (ValidityException e) {
97 throw new StreamException(e);
98 } catch (ParsingException e) {
99 throw new StreamException(e);
100 } catch (IOException e) {
101 throw new StreamException(e);
102 }
103 }
104
105 public HierarchicalStreamReader createReader(URL in) {
106 try {
107 Document document = builder.build(in.toExternalForm());
108 return new XomReader(document, getNameCoder());
109 } catch (ValidityException e) {
110 throw new StreamException(e);
111 } catch (ParsingException e) {
112 throw new StreamException(e);
113 } catch (IOException e) {
114 throw new StreamException(e);
115 }
116 }
117
118 public HierarchicalStreamReader createReader(File in) {
119 try {
120 Document document = builder.build(in);
121 return new XomReader(document, getNameCoder());
122 } catch (ValidityException e) {
123 throw new StreamException(e);
124 } catch (ParsingException e) {
125 throw new StreamException(e);
126 } catch (IOException e) {
127 throw new StreamException(e);
128 }
129 }
130
131 public HierarchicalStreamWriter createWriter(final Writer out) {
132 return new PrettyPrintWriter(out, getNameCoder());
133 }
134
135 public HierarchicalStreamWriter createWriter(final OutputStream out) {
136 return new PrettyPrintWriter(new OutputStreamWriter(out), getNameCoder());
137 }
138 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import nu.xom.Document;
15 import nu.xom.Element;
16 import nu.xom.Elements;
17 import nu.xom.Node;
18 import nu.xom.Text;
19
20 public class XomReader extends AbstractDocumentReader {
21
22 private Element currentElement;
23
24 public XomReader(Element rootElement) {
25 super(rootElement);
26 }
27
28 public XomReader(Document document) {
29 super(document.getRootElement());
30 }
31
32 /**
33 * @since 1.4
34 */
35 public XomReader(Element rootElement, NameCoder nameCoder) {
36 super(rootElement, nameCoder);
37 }
38
39 /**
40 * @since 1.4
41 */
42 public XomReader(Document document, NameCoder nameCoder) {
43 super(document.getRootElement(), nameCoder);
44 }
45
46 /**
47 * @since 1.2
48 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead.
49 */
50 public XomReader(Element rootElement, XmlFriendlyReplacer replacer) {
51 this(rootElement, (NameCoder)replacer);
52 }
53
54 /**
55 * @since 1.2
56 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead.
57 */
58 public XomReader(Document document, XmlFriendlyReplacer replacer) {
59 this(document.getRootElement(), (NameCoder)replacer);
60 }
61
62 public String getNodeName() {
63 return decodeNode(currentElement.getLocalName());
64 }
65
66 public String getValue() {
67 // currentElement.getValue() not used as this includes text of child elements, which we don't want.
68 StringBuffer result = new StringBuffer();
69 int childCount = currentElement.getChildCount();
70 for(int i = 0; i < childCount; i++) {
71 Node child = currentElement.getChild(i);
72 if (child instanceof Text) {
73 Text text = (Text) child;
74 result.append(text.getValue());
75 }
76 }
77 return result.toString();
78 }
79
80 public String getAttribute(String name) {
81 return currentElement.getAttributeValue(encodeAttribute(name));
82 }
83
84 public String getAttribute(int index) {
85 return currentElement.getAttribute(index).getValue();
86 }
87
88 public int getAttributeCount() {
89 return currentElement.getAttributeCount();
90 }
91
92 public String getAttributeName(int index) {
93 return decodeAttribute(currentElement.getAttribute(index).getQualifiedName());
94 }
95
96 protected int getChildCount() {
97 return currentElement.getChildElements().size();
98 }
99
100 protected Object getParent() {
101 return currentElement.getParent();
102 }
103
104 protected Object getChild(int index) {
105 return currentElement.getChildElements().get(index);
106 }
107
108 protected void reassignCurrentElement(Object current) {
109 currentElement = (Element) current;
110 }
111
112 public String peekNextChild() {
113 Elements children = currentElement.getChildElements();
114 if (null == children || children.size() == 0) {
115 return null;
116 }
117 return decodeNode(children.get(0).getLocalName());
118 }
119 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import nu.xom.Attribute;
16 import nu.xom.Element;
17
18
19 public class XomWriter extends AbstractDocumentWriter {
20
21 /**
22 * @since 1.2.1
23 */
24 public XomWriter() {
25 this(null);
26 }
27
28 public XomWriter(final Element parentElement) {
29 this(parentElement, new XmlFriendlyNameCoder());
30 }
31
32 /**
33 * @since 1.4
34 */
35 public XomWriter(final Element parentElement, final NameCoder nameCoder) {
36 super(parentElement, nameCoder);
37 }
38
39 /**
40 * @since 1.2
41 * @deprecated As of 1.4 use {@link XomWriter#XomWriter(Element, NameCoder)} instead
42 */
43 public XomWriter(final Element parentElement, final XmlFriendlyReplacer replacer) {
44 this(parentElement, (NameCoder)replacer);
45 }
46
47 protected Object createNode(final String name) {
48 final Element newNode = new Element(encodeNode(name));
49 final Element top = top();
50 if (top != null){
51 top().appendChild(newNode);
52 }
53 return newNode;
54 }
55
56 public void addAttribute(final String name, final String value) {
57 top().addAttribute(new Attribute(encodeAttribute(name), value));
58 }
59
60 public void setValue(final String text) {
61 top().appendChild(text);
62 }
63
64 private Element top() {
65 return (Element)getCurrent();
66 }
67 }
0 /*
1 * Copyright (C) 2009, 2011 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 03. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14
15 import org.xmlpull.mxp1.MXParser;
16 import org.xmlpull.v1.XmlPullParser;
17
18 /**
19 * A {@link HierarchicalStreamDriver} for XPP DOM using the Xpp3 parser.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.4
23 */
24 public class Xpp3DomDriver extends AbstractXppDomDriver {
25
26 /**
27 * Construct an Xpp3DomDriver.
28 *
29 * @since 1.4
30 */
31 public Xpp3DomDriver() {
32 super(new XmlFriendlyNameCoder());
33 }
34
35 /**
36 * Construct an Xpp3DomDriver.
37 *
38 * @param nameCoder the replacer for XML friendly names
39 * @since 1.4
40 */
41 public Xpp3DomDriver(NameCoder nameCoder) {
42 super(nameCoder);
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 protected XmlPullParser createParser() {
49 return new MXParser();
50 }
51 }
0 /*
1 * Copyright (C) 2009, 2011 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 29. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import org.xmlpull.mxp1.MXParser;
17 import org.xmlpull.v1.XmlPullParser;
18
19
20 /**
21 * A {@link HierarchicalStreamDriver} using the Xpp3 parser.
22 *
23 * @author J&ouml;rg Schaible
24 * @since 1.4
25 */
26 public class Xpp3Driver extends AbstractXppDriver {
27
28 /**
29 * Construct an Xpp3Driver.
30 *
31 * @since 1.4
32 */
33 public Xpp3Driver() {
34 super(new XmlFriendlyNameCoder());
35 }
36
37 /**
38 * Construct an Xpp3Driver.
39 *
40 * @param nameCoder the replacer for XML friendly names
41 * @since 1.4
42 */
43 public Xpp3Driver(NameCoder nameCoder) {
44 super(nameCoder);
45 }
46
47 /**
48 * {@inheritDoc}
49 */
50 protected XmlPullParser createParser() {
51 return new MXParser();
52 }
53 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
14 import com.thoughtworks.xstream.io.naming.NameCoder;
15
16 import org.xmlpull.v1.XmlPullParser;
17 import org.xmlpull.v1.XmlPullParserException;
18 import org.xmlpull.v1.XmlPullParserFactory;
19
20 /**
21 * A {@link HierarchicalStreamDriver} for XPP DOM using the XmlPullParserFactory to locate an parser.
22 *
23 * @author Joe Walnes
24 * @author J&ouml;rg Schaible
25 */
26 public class XppDomDriver extends AbstractXppDomDriver {
27
28 private static XmlPullParserFactory factory;
29
30 public XppDomDriver() {
31 super(new XmlFriendlyNameCoder());
32 }
33
34 /**
35 * @since 1.4
36 */
37 public XppDomDriver(NameCoder nameCoder) {
38 super(nameCoder);
39 }
40
41 /**
42 * @since 1.2
43 * @deprecated As of 1.4, use {@link XppDomDriver#XppDomDriver(NameCoder)} instead.
44 */
45 public XppDomDriver(XmlFriendlyReplacer replacer) {
46 super(replacer);
47 }
48
49 /**
50 * {@inheritDoc}
51 */
52 protected synchronized XmlPullParser createParser() throws XmlPullParserException {
53 if (factory == null) {
54 factory = XmlPullParserFactory.newInstance(null, XppDomDriver.class);
55 }
56 return factory.newPullParser();
57 }
58 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
15
16 /**
17 * @author Jason van Zyl
18 */
19 public class XppDomReader extends AbstractDocumentReader {
20
21 private XppDom currentElement;
22
23 public XppDomReader(XppDom xppDom) {
24 super(xppDom);
25 }
26
27 /**
28 * @since 1.4
29 */
30 public XppDomReader(XppDom xppDom, NameCoder nameCoder) {
31 super(xppDom, nameCoder);
32 }
33
34 /**
35 * @since 1.2
36 * @deprecated As of 1.4 use {@link XppDomReader#XppDomReader(XppDom, NameCoder)} instead.
37 */
38 public XppDomReader(XppDom xppDom, XmlFriendlyReplacer replacer) {
39 this(xppDom, (NameCoder)replacer);
40 }
41
42 public String getNodeName() {
43 return decodeNode(currentElement.getName());
44 }
45
46 public String getValue() {
47 String text = null;
48
49 try {
50 text = currentElement.getValue();
51 } catch (Exception e) {
52 // do nothing.
53 }
54
55 return text == null ? "" : text;
56 }
57
58 public String getAttribute(String attributeName) {
59 return currentElement.getAttribute(encodeAttribute(attributeName));
60 }
61
62 public String getAttribute(int index) {
63 return currentElement.getAttribute(currentElement.getAttributeNames()[index]);
64 }
65
66 public int getAttributeCount() {
67 return currentElement.getAttributeNames().length;
68 }
69
70 public String getAttributeName(int index) {
71 return decodeAttribute(currentElement.getAttributeNames()[index]);
72 }
73
74 protected Object getParent() {
75 return currentElement.getParent();
76 }
77
78 protected Object getChild(int index) {
79 return currentElement.getChild(index);
80 }
81
82 protected int getChildCount() {
83 return currentElement.getChildCount();
84 }
85
86 protected void reassignCurrentElement(Object current) {
87 this.currentElement = (XppDom) current;
88 }
89
90 public String peekNextChild() {
91 if (currentElement.getChildCount() == 0) {
92 return null;
93 }
94 return decodeNode(currentElement.getChild(0).getName());
95 }
96
97 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.naming.NameCoder;
14 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
15
16
17 public class XppDomWriter extends AbstractDocumentWriter {
18 public XppDomWriter() {
19 this(null, new XmlFriendlyNameCoder());
20 }
21
22 /**
23 * @since 1.2.1
24 */
25 public XppDomWriter(final XppDom parent) {
26 this(parent, new XmlFriendlyNameCoder());
27 }
28
29 /**
30 * @since 1.4
31 */
32 public XppDomWriter(final NameCoder nameCoder) {
33 this(null, nameCoder);
34 }
35
36 /**
37 * @since 1.4
38 */
39 public XppDomWriter(final XppDom parent, final NameCoder nameCoder) {
40 super(parent, nameCoder);
41 }
42
43 /**
44 * @since 1.2
45 * @deprecated As of 1.4 use {@link XppDomWriter#XppDomWriter(NameCoder)} instead
46 */
47 public XppDomWriter(final XmlFriendlyReplacer replacer) {
48 this(null, replacer);
49 }
50
51 /**
52 * @since 1.2.1
53 * @deprecated As of 1.4 use {@link XppDomWriter#XppDomWriter(XppDom, NameCoder)} instead.
54 */
55 public XppDomWriter(final XppDom parent, final XmlFriendlyReplacer replacer) {
56 this(parent, (NameCoder)replacer);
57 }
58
59 public XppDom getConfiguration() {
60 return (XppDom)getTopLevelNodes().get(0);
61 }
62
63 protected Object createNode(final String name) {
64 final XppDom newNode = new XppDom(encodeNode(name));
65 final XppDom top = top();
66 if (top != null) {
67 top().addChild(newNode);
68 }
69 return newNode;
70 }
71
72 public void setValue(final String text) {
73 top().setValue(text);
74 }
75
76 public void addAttribute(final String key, final String value) {
77 top().setAttribute(encodeAttribute(key), value);
78 }
79
80 private XppDom top() {
81 return (XppDom)getCurrent();
82 }
83 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 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 08. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13
14 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
15 import com.thoughtworks.xstream.io.naming.NameCoder;
16
17 import org.xmlpull.v1.XmlPullParser;
18 import org.xmlpull.v1.XmlPullParserException;
19 import org.xmlpull.v1.XmlPullParserFactory;
20
21
22 /**
23 * A {@link HierarchicalStreamDriver} using the XmlPullParserFactory to locate an XML Pull Parser.
24 *
25 * @author Joe Walnes
26 * @author J&ouml;rg Schaible
27 */
28 public class XppDriver extends AbstractXppDriver {
29
30 private static XmlPullParserFactory factory;
31
32 public XppDriver() {
33 super(new XmlFriendlyNameCoder());
34 }
35
36 /**
37 * @since 1.4
38 */
39 public XppDriver(NameCoder nameCoder) {
40 super(nameCoder);
41 }
42
43 /**
44 * @since 1.2
45 * @deprecated As of 1.4, use {@link XppDriver#XppDriver(NameCoder)} instead.
46 */
47 public XppDriver(XmlFriendlyReplacer replacer) {
48 this((NameCoder)replacer);
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 protected synchronized XmlPullParser createParser() throws XmlPullParserException {
55 if (factory == null) {
56 factory = XmlPullParserFactory.newInstance();
57 }
58 return factory.newPullParser();
59 }
60 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 08. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.IOException;
14 import java.io.Reader;
15
16 import org.xmlpull.v1.XmlPullParser;
17 import org.xmlpull.v1.XmlPullParserException;
18
19 import com.thoughtworks.xstream.converters.ErrorWriter;
20 import com.thoughtworks.xstream.io.StreamException;
21 import com.thoughtworks.xstream.io.naming.NameCoder;
22
23 /**
24 * XStream reader that pulls directly from the stream using the XmlPullParser API.
25 *
26 * @author Joe Walnes
27 * @author J&ouml;rg Schaible
28 */
29 public class XppReader extends AbstractPullReader {
30
31 private final XmlPullParser parser;
32 private final Reader reader;
33
34 /**
35 * Construct an XppReader.
36 *
37 * @param reader the reader with the input data
38 * @param parser the XPP parser to use
39 * @since 1.4
40 */
41 public XppReader(Reader reader, XmlPullParser parser) {
42 this(reader, parser, new XmlFriendlyNameCoder());
43 }
44
45 /**
46 * Construct an XppReader.
47 *
48 * @param reader the reader with the input data
49 * @param parser the XPP parser to use
50 * @param nameCoder the coder for XML friendly tag and attribute names
51 * @since 1.4
52 */
53 public XppReader(Reader reader, XmlPullParser parser, NameCoder nameCoder) {
54 super(nameCoder);
55 this.parser = parser;
56 this.reader = reader;
57 try {
58 parser.setInput(this.reader);
59 } catch (XmlPullParserException e) {
60 throw new StreamException(e);
61 }
62 moveDown();
63 }
64
65 /**
66 * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead
67 */
68 public XppReader(Reader reader) {
69 this(reader, new XmlFriendlyReplacer());
70 }
71
72 /**
73 * @since 1.2
74 * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser, NameCoder)} instead
75 */
76 public XppReader(Reader reader, XmlFriendlyReplacer replacer) {
77 super(replacer);
78 try {
79 parser = createParser();
80 this.reader = reader;
81 parser.setInput(this.reader);
82 moveDown();
83 } catch (XmlPullParserException e) {
84 throw new StreamException(e);
85 }
86 }
87
88 /**
89 * To use another implementation of org.xmlpull.v1.XmlPullParser, override this method.
90 * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead
91 */
92 protected XmlPullParser createParser() {
93 Exception exception = null;
94 try {
95 return (XmlPullParser)Class.forName("org.xmlpull.mxp1.MXParser", true, XmlPullParser.class.getClassLoader()).newInstance();
96 } catch (InstantiationException e) {
97 exception = e;
98 } catch (IllegalAccessException e) {
99 exception = e;
100 } catch (ClassNotFoundException e) {
101 exception = e;
102 }
103 throw new StreamException("Cannot create Xpp3 parser instance.", exception);
104 }
105
106 protected int pullNextEvent() {
107 try {
108 switch(parser.next()) {
109 case XmlPullParser.START_DOCUMENT:
110 case XmlPullParser.START_TAG:
111 return START_NODE;
112 case XmlPullParser.END_DOCUMENT:
113 case XmlPullParser.END_TAG:
114 return END_NODE;
115 case XmlPullParser.TEXT:
116 return TEXT;
117 case XmlPullParser.COMMENT:
118 return COMMENT;
119 default:
120 return OTHER;
121 }
122 } catch (XmlPullParserException e) {
123 throw new StreamException(e);
124 } catch (IOException e) {
125 throw new StreamException(e);
126 }
127 }
128
129 protected String pullElementName() {
130 return parser.getName();
131 }
132
133 protected String pullText() {
134 return parser.getText();
135 }
136
137 public String getAttribute(String name) {
138 return parser.getAttributeValue(null, encodeAttribute(name));
139 }
140
141 public String getAttribute(int index) {
142 return parser.getAttributeValue(index);
143 }
144
145 public int getAttributeCount() {
146 return parser.getAttributeCount();
147 }
148
149 public String getAttributeName(int index) {
150 return decodeAttribute(parser.getAttributeName(index));
151 }
152
153 public void appendErrors(ErrorWriter errorWriter) {
154 errorWriter.add("line number", String.valueOf(parser.getLineNumber()));
155 }
156
157 public void close() {
158 try {
159 reader.close();
160 } catch (IOException e) {
161 throw new StreamException(e);
162 }
163 }
164
165 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml.xppdom;
12
13 /**
14 * Simple Document Object Model for XmlPullParser implementations.
15 *
16 * @author Jason van Zyl
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @deprecated As of 1.4, use {@link XppDom} instead
20 */
21 public class Xpp3Dom extends XppDom {
22
23 /**
24 * @deprecated As of 1.4, use {@link XppDom} instead
25 */
26 public Xpp3Dom(String name) {
27 super(name);
28 }
29 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml.xppdom;
12
13 import org.xmlpull.mxp1.MXParser;
14 import org.xmlpull.v1.XmlPullParser;
15
16 import java.io.Reader;
17
18
19 /**
20 * @author Jason van Zyl
21 * @author Joe Walnes
22 * @author J&ouml;rg Schaible
23 * @deprecated As of 1.4, use {@link XppDom#build(XmlPullParser)} instead
24 */
25 public class Xpp3DomBuilder {
26 /**
27 * @deprecated As of 1.4, use {@link XppDom#build(XmlPullParser)} instead
28 */
29 public static Xpp3Dom build(Reader reader) throws Exception {
30 XmlPullParser parser = new MXParser();
31 parser.setInput(reader);
32 try {
33 return (Xpp3Dom)XppDom.build(parser);
34 } finally {
35 reader.close();
36 }
37 }
38 }
0 /*
1 * Copyright (C) 2009, 2011 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 02. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml.xppdom;
11
12 import org.xmlpull.v1.XmlPullParser;
13 import org.xmlpull.v1.XmlPullParserException;
14
15 import java.io.IOException;
16 import java.io.Serializable;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23
24 /**
25 * Simple Document Object Model for XmlPullParser implementations.
26 *
27 * @author Jason van Zyl
28 * @author Joe Walnes
29 * @author J&ouml;rg Schaible
30 * @since 1.4
31 */
32 public class XppDom implements Serializable {
33 private static final long serialVersionUID = 1L;
34
35 private String name;
36 private String value;
37 private Map attributes;
38 private List childList;
39 transient private Map childMap;
40 private XppDom parent;
41
42 public XppDom(String name) {
43 this.name = name;
44 childList = new ArrayList();
45 childMap = new HashMap();
46 }
47
48 // ----------------------------------------------------------------------
49 // Name handling
50 // ----------------------------------------------------------------------
51
52 public String getName() {
53 return name;
54 }
55
56 // ----------------------------------------------------------------------
57 // Value handling
58 // ----------------------------------------------------------------------
59
60 public String getValue() {
61 return value;
62 }
63
64 public void setValue(String value) {
65 this.value = value;
66 }
67
68 // ----------------------------------------------------------------------
69 // Attribute handling
70 // ----------------------------------------------------------------------
71
72 public String[] getAttributeNames() {
73 if (null == attributes) {
74 return new String[0];
75 } else {
76 return (String[])attributes.keySet().toArray(new String[0]);
77 }
78 }
79
80 public String getAttribute(String name) {
81 return (null != attributes) ? (String)attributes.get(name) : null;
82 }
83
84 public void setAttribute(String name, String value) {
85 if (null == attributes) {
86 attributes = new HashMap();
87 }
88
89 attributes.put(name, value);
90 }
91
92 // ----------------------------------------------------------------------
93 // Child handling
94 // ----------------------------------------------------------------------
95
96 public XppDom getChild(int i) {
97 return (XppDom)childList.get(i);
98 }
99
100 public XppDom getChild(String name) {
101 return (XppDom)childMap.get(name);
102 }
103
104 public void addChild(XppDom xpp3Dom) {
105 xpp3Dom.setParent(this);
106 childList.add(xpp3Dom);
107 childMap.put(xpp3Dom.getName(), xpp3Dom);
108 }
109
110 public XppDom[] getChildren() {
111 if (null == childList) {
112 return new XppDom[0];
113 } else {
114 return (XppDom[])childList.toArray(new XppDom[0]);
115 }
116 }
117
118 public XppDom[] getChildren(String name) {
119 if (null == childList) {
120 return new XppDom[0];
121 } else {
122 ArrayList children = new ArrayList();
123 int size = this.childList.size();
124
125 for (int i = 0; i < size; i++ ) {
126 XppDom configuration = (XppDom)this.childList.get(i);
127 if (name.equals(configuration.getName())) {
128 children.add(configuration);
129 }
130 }
131
132 return (XppDom[])children.toArray(new XppDom[0]);
133 }
134 }
135
136 public int getChildCount() {
137 if (null == childList) {
138 return 0;
139 }
140
141 return childList.size();
142 }
143
144 // ----------------------------------------------------------------------
145 // Parent handling
146 // ----------------------------------------------------------------------
147
148 public XppDom getParent() {
149 return parent;
150 }
151
152 public void setParent(XppDom parent) {
153 this.parent = parent;
154 }
155
156 // ----------------------------------------------------------------------
157 // Serialization
158 // ----------------------------------------------------------------------
159
160 Object readResolve() {
161 childMap = new HashMap();
162 for (final Iterator iter = childList.iterator(); iter.hasNext();) {
163 final XppDom element = (XppDom)iter.next();
164 childMap.put(element.getName(), element);
165 }
166 return this;
167 }
168
169 // ----------------------------------------------------------------------
170 // DOM builder
171 // ----------------------------------------------------------------------
172
173 /**
174 * Build an XPP DOM hierarchy. The {@link java.io.InputStream} or {@link java.io.Reader}
175 * used by the parser must have already been set. The method does not close it after reading
176 * the document's end.
177 *
178 * @param parser the XPP instance
179 * @throws XmlPullParserException if the parser turns into an invalid state or reads invalid
180 * XML
181 * @throws IOException if the data cannot be read
182 */
183 public static XppDom build(XmlPullParser parser) throws XmlPullParserException, IOException {
184 List elements = new ArrayList();
185 List values = new ArrayList();
186 XppDom node = null;
187
188 int eventType = parser.getEventType();
189 while (eventType != XmlPullParser.END_DOCUMENT) {
190 if (eventType == XmlPullParser.START_TAG) {
191 String rawName = parser.getName();
192
193 // Use XppDom when deprecated Xpp3Dom is removed
194 XppDom child = new Xpp3Dom(rawName);
195
196 int depth = elements.size();
197 if (depth > 0) {
198 XppDom parent = (XppDom)elements.get(depth - 1);
199 parent.addChild(child);
200 }
201
202 elements.add(child);
203 values.add(new StringBuffer());
204
205 int attributesSize = parser.getAttributeCount();
206 for (int i = 0; i < attributesSize; i++ ) {
207 String name = parser.getAttributeName(i);
208 String value = parser.getAttributeValue(i);
209 child.setAttribute(name, value);
210 }
211 } else if (eventType == XmlPullParser.TEXT) {
212 int depth = values.size() - 1;
213 StringBuffer valueBuffer = (StringBuffer)values.get(depth);
214 valueBuffer.append(parser.getText());
215 } else if (eventType == XmlPullParser.END_TAG) {
216 int depth = elements.size() - 1;
217 XppDom finalNode = (XppDom)elements.remove(depth);
218 String accumulatedValue = (values.remove(depth)).toString();
219
220 String finishedValue;
221 if (0 == accumulatedValue.length()) {
222 finishedValue = null;
223 } else {
224 finishedValue = accumulatedValue;
225 }
226
227 finalNode.setValue(finishedValue);
228 if (0 == depth) {
229 node = finalNode;
230 }
231 }
232
233 eventType = parser.next();
234 }
235
236 return node;
237 }
238 }
0 /*
1 * Copyright (C) 2011 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 11. August 2011 by Joerg Schaible.
9 */
10 package com.thoughtworks.xstream.io.xml.xppdom;
11
12 import java.util.Arrays;
13 import java.util.Comparator;
14 import java.util.HashMap;
15 import java.util.Map;
16
17
18 /**
19 * Comparator for {@link XppDom}. Comparator can trace the XPath where the comparison failed.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.4.1
23 */
24 public class XppDomComparator implements Comparator {
25 private final ThreadLocal xpath;
26
27 /**
28 * Creates a new Xpp3DomComparator object.
29 *
30 * @since 1.4.1
31 */
32 public XppDomComparator() {
33 this(null);
34 }
35
36 /**
37 * Creates a new Xpp3DomComparator object with XPath identification.
38 *
39 * @param xpath the reference for the XPath
40 * @since 1.4.1
41 */
42 public XppDomComparator(final ThreadLocal xpath) {
43 this.xpath = xpath;
44 }
45
46 public int compare(final Object dom1, final Object dom2) {
47
48 final StringBuffer xpath = new StringBuffer("/");
49 final int s = compareInternal((XppDom)dom1, (XppDom)dom2, xpath, -1);
50 if (this.xpath != null) {
51 if (s != 0) {
52 this.xpath.set(xpath.toString());
53 } else {
54 this.xpath.set(null);
55 }
56 }
57
58 return s;
59 }
60
61 private int compareInternal(final XppDom dom1, final XppDom dom2,
62 final StringBuffer xpath, final int count) {
63 final int pathlen = xpath.length();
64 final String name = dom1.getName();
65 int s = name.compareTo(dom2.getName());
66 xpath.append(name);
67 if (count >= 0) {
68 xpath.append('[').append(count).append(']');
69 }
70
71 if (s != 0) {
72 xpath.append('?');
73
74 return s;
75 }
76
77 final String[] attributes = dom1.getAttributeNames();
78 final String[] attributes2 = dom2.getAttributeNames();
79 final int len = attributes.length;
80 s = attributes2.length - len;
81 if (s != 0) {
82 xpath.append("::count(@*)");
83
84 return s < 0 ? 1 : -1;
85 }
86
87 Arrays.sort(attributes);
88 Arrays.sort(attributes2);
89 for (int i = 0; i < len; ++i) {
90 final String attribute = attributes[i];
91 s = attribute.compareTo(attributes2[i]);
92 if (s != 0) {
93 xpath.append("[@").append(attribute).append("?]");
94
95 return s;
96 }
97
98 s = dom1.getAttribute(attribute).compareTo(dom2.getAttribute(attribute));
99 if (s != 0) {
100 xpath.append("[@").append(attribute).append(']');
101
102 return s;
103 }
104 }
105
106 final int children = dom1.getChildCount();
107 s = dom2.getChildCount() - children;
108 if (s != 0) {
109 xpath.append("::count(*)");
110
111 return s < 0 ? 1 : -1;
112 }
113
114 if (children > 0) {
115 if (dom1.getValue() != null || dom2.getValue() != null) {
116 throw new IllegalArgumentException("XppDom cannot handle mixed mode at "
117 + xpath
118 + "::text()");
119 }
120
121 xpath.append('/');
122
123 final Map names = new HashMap();
124 for (int i = 0; i < children; ++i) {
125 final XppDom child1 = dom1.getChild(i);
126 final XppDom child2 = dom2.getChild(i);
127 final String child = child1.getName();
128 if (!names.containsKey(child)) {
129 names.put(child, new int[1]);
130 }
131
132 s = compareInternal(child1, child2, xpath, ((int[])names.get(child))[0]++);
133 if (s != 0) {
134 return s;
135 }
136 }
137 } else {
138 final String value2 = dom2.getValue();
139 final String value1 = dom1.getValue();
140 if (value1 == null) {
141 s = value2 == null ? 0 : -1;
142 } else {
143 s = value2 == null ? 1 : value1.compareTo(value2);
144 }
145
146 if (s != 0) {
147 xpath.append("::text()");
148
149 return s;
150 }
151 }
152
153 xpath.setLength(pathlen);
154
155 return s;
156 }
157 }
0 /*
1 * Copyright (C) 2011 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 11. August 2011 by Joerg Schaible, code from XppDom.
9 */
10 package com.thoughtworks.xstream.io.xml.xppdom;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.io.Reader;
15 import java.io.StringReader;
16
17 import org.xmlpull.v1.XmlPullParser;
18 import org.xmlpull.v1.XmlPullParserException;
19 import org.xmlpull.v1.XmlPullParserFactory;
20
21 /**
22 * XmlPullParser utility methods.
23 *
24 * @author J&ouml;rg Schaible
25 * @since 1.4.1
26 */
27 public class XppFactory {
28
29 /**
30 * Create a new XmlPullParser using the XPP factory.
31 *
32 * @return a new parser instance
33 * @throws XmlPullParserException if the factory fails
34 * @since 1.4.1
35 */
36 public static XmlPullParser createDefaultParser() throws XmlPullParserException {
37 XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
38 return factory.newPullParser();
39 }
40
41 /**
42 * Build an XPP DOM hierarchy from a String.
43 *
44 * @param xml the XML data
45 * @throws XmlPullParserException if the default parser cannot be created or fails with invalid XML
46 * @throws IOException if the data cannot be read
47 * @see XppDom#build(XmlPullParser)
48 * @since 1.4.1
49 */
50 public static XppDom buildDom(String xml) throws XmlPullParserException, IOException {
51 return buildDom(new StringReader(xml));
52 }
53
54 /**
55 * Build an XPP DOM hierarchy from a Reader.
56 *
57 * @param r the reader
58 * @throws XmlPullParserException if the default parser cannot be created or fails with invalid XML
59 * @throws IOException if the data cannot be read
60 * @see XppDom#build(XmlPullParser)
61 * @since 1.4.1
62 */
63 public static XppDom buildDom(Reader r) throws XmlPullParserException, IOException {
64 XmlPullParser parser = createDefaultParser();
65 parser.setInput(r);
66 return XppDom.build(parser);
67 }
68
69 /**
70 * Build an XPP DOM hierarchy from an InputStream.
71 *
72 * @param in the input stream
73 * @param encoding the encoding of the input stream
74 * @throws XmlPullParserException if the default parser cannot be created or fails with invalid XML
75 * @throws IOException if the data cannot be read
76 * @see XppDom#build(XmlPullParser)
77 * @since 1.4.1
78 */
79 public static XppDom buildDom(InputStream in, String encoding) throws XmlPullParserException, IOException {
80 XmlPullParser parser = createDefaultParser();
81 parser.setInput(in, encoding);
82 return XppDom.build(parser);
83 }
84 }
0 /*
1 * Copyright (C) 2008 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 09. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import java.util.Map;
15
16 /**
17 * Abstract base class for AttributeAliassingMapper and its system version.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.3.1
21 */
22 public abstract class AbstractAttributeAliasingMapper extends MapperWrapper {
23
24 protected final Map aliasToName = new HashMap();
25 protected transient Map nameToAlias = new HashMap();
26
27 public AbstractAttributeAliasingMapper(Mapper wrapped) {
28 super(wrapped);
29 }
30
31 public void addAliasFor(final String attributeName, final String alias) {
32 aliasToName.put(alias, attributeName);
33 nameToAlias.put(attributeName, alias);
34 }
35
36 Object readResolve() {
37 nameToAlias = new HashMap();
38 for (final Iterator iter = aliasToName.keySet().iterator(); iter.hasNext();) {
39 final Object alias = iter.next();
40 nameToAlias.put(aliasToName.get(alias), alias);
41 }
42 return this;
43 }
44
45 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 03. May 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.mapper;
12
13
14 /**
15 * Mapper that ensures that all names in the serialization stream are XML friendly.
16 * The replacement chars and strings are:
17 * <ul>
18 * <li><b>$</b> (dollar) chars appearing in class names are replaced with <b>_</b> (underscore) chars.<br></li>
19 * <li><b>$</b> (dollar) chars appearing in field names are replaced with <b>_DOLLAR_</b> string.<br></li>
20 * <li><b>_</b> (underscore) chars appearing in field names are replaced with <b>__</b> (double underscore) string.<br></li>
21 * <li><b>default</b> as the prefix for class names with no package.</li>
22 * </ul>
23 *
24 * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward compatibility
25 * to existing XML data written with older XStream versions.
26 *
27 * @author Joe Walnes
28 * @author Mauro Talevi
29 * @deprecated As of 1.4 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
30 */
31 public class AbstractXmlFriendlyMapper extends MapperWrapper {
32
33 private char dollarReplacementInClass = '-';
34 private String dollarReplacementInField = "_DOLLAR_";
35 private String underscoreReplacementInField = "__";
36 private String noPackagePrefix = "default";
37
38 protected AbstractXmlFriendlyMapper(Mapper wrapped) {
39 super(wrapped);
40 }
41
42 protected String escapeClassName(String className) {
43 // the $ used in inner class names is illegal as an xml element getNodeName
44 className = className.replace('$', dollarReplacementInClass);
45
46 // special case for classes named $Blah with no package; <-Blah> is illegal XML
47 if (className.charAt(0) == dollarReplacementInClass) {
48 className = noPackagePrefix + className;
49 }
50
51 return className;
52 }
53
54 protected String unescapeClassName(String className) {
55 // special case for classes named $Blah with no package; <-Blah> is illegal XML
56 if (className.startsWith(noPackagePrefix+dollarReplacementInClass)) {
57 className = className.substring(noPackagePrefix.length());
58 }
59
60 // the $ used in inner class names is illegal as an xml element getNodeName
61 className = className.replace(dollarReplacementInClass, '$');
62
63 return className;
64 }
65
66 protected String escapeFieldName(String fieldName) {
67 StringBuffer result = new StringBuffer();
68 int length = fieldName.length();
69 for(int i = 0; i < length; i++) {
70 char c = fieldName.charAt(i);
71 if (c == '$' ) {
72 result.append(dollarReplacementInField);
73 } else if (c == '_') {
74 result.append(underscoreReplacementInField);
75 } else {
76 result.append(c);
77 }
78 }
79 return result.toString();
80 }
81
82 protected String unescapeFieldName(String xmlName) {
83 StringBuffer result = new StringBuffer();
84 int length = xmlName.length();
85 for(int i = 0; i < length; i++) {
86 char c = xmlName.charAt(i);
87 if ( stringFoundAt(xmlName, i,underscoreReplacementInField)) {
88 i +=underscoreReplacementInField.length() - 1;
89 result.append('_');
90 } else if ( stringFoundAt(xmlName, i,dollarReplacementInField)) {
91 i +=dollarReplacementInField.length() - 1;
92 result.append('$');
93 } else {
94 result.append(c);
95 }
96 }
97 return result.toString();
98 }
99
100 private boolean stringFoundAt(String name, int i, String replacement) {
101 if ( name.length() >= i + replacement.length()
102 && name.substring(i, i + replacement.length()).equals(replacement) ){
103 return true;
104 }
105 return false;
106 }
107
108 }
0 /*
1 * Copyright (C) 2007, 2008, 2013 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 07. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 /**
13 * An interface for the configuration part of the AnnotationMapper.
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.3
17 * @deprecated As of 1.4.5, minimal JDK version will be 1.6 for next major release
18 */
19 public interface AnnotationConfiguration {
20
21 void autodetectAnnotations(boolean mode);
22
23 void processAnnotations(Class[] types);
24
25 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 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 07. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.lang.reflect.Array;
16 import java.lang.reflect.Field;
17 import java.lang.reflect.GenericArrayType;
18 import java.lang.reflect.Modifier;
19 import java.lang.reflect.ParameterizedType;
20 import java.lang.reflect.Type;
21 import java.lang.reflect.TypeVariable;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.LinkedHashSet;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32
33 import com.thoughtworks.xstream.InitializationException;
34 import com.thoughtworks.xstream.annotations.XStreamAlias;
35 import com.thoughtworks.xstream.annotations.XStreamAliasType;
36 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
37 import com.thoughtworks.xstream.annotations.XStreamConverter;
38 import com.thoughtworks.xstream.annotations.XStreamConverters;
39 import com.thoughtworks.xstream.annotations.XStreamImplicit;
40 import com.thoughtworks.xstream.annotations.XStreamImplicitCollection;
41 import com.thoughtworks.xstream.annotations.XStreamInclude;
42 import com.thoughtworks.xstream.annotations.XStreamOmitField;
43 import com.thoughtworks.xstream.converters.Converter;
44 import com.thoughtworks.xstream.converters.ConverterLookup;
45 import com.thoughtworks.xstream.converters.ConverterMatcher;
46 import com.thoughtworks.xstream.converters.ConverterRegistry;
47 import com.thoughtworks.xstream.converters.SingleValueConverter;
48 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
49 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
50 import com.thoughtworks.xstream.core.ClassLoaderReference;
51 import com.thoughtworks.xstream.core.JVM;
52 import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
53 import com.thoughtworks.xstream.core.util.TypedNull;
54
55
56 /**
57 * A mapper that uses annotations to prepare the remaining mappers in the chain.
58 *
59 * @author J&ouml;rg Schaible
60 * @since 1.3
61 */
62 public class AnnotationMapper extends MapperWrapper implements AnnotationConfiguration {
63
64 private boolean locked;
65 private transient Object[] arguments;
66 private final ConverterRegistry converterRegistry;
67 private transient ClassAliasingMapper classAliasingMapper;
68 private transient DefaultImplementationsMapper defaultImplementationsMapper;
69 private transient ImplicitCollectionMapper implicitCollectionMapper;
70 private transient FieldAliasingMapper fieldAliasingMapper;
71 private transient AttributeMapper attributeMapper;
72 private transient LocalConversionMapper localConversionMapper;
73 private final Map<Class<?>, Map<List<Object>, Converter>> converterCache =
74 new HashMap<Class<?>, Map<List<Object>, Converter>>();
75 private final Set<Class<?>> annotatedTypes =
76 Collections.synchronizedSet(new HashSet<Class<?>>());
77
78 /**
79 * Construct an AnnotationMapper.
80 *
81 * @param wrapped the next {@link Mapper} in the chain
82 * @since 1.4.5
83 */
84 public AnnotationMapper(
85 final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup,
86 final ClassLoaderReference classLoaderReference, final ReflectionProvider reflectionProvider) {
87 super(wrapped);
88 this.converterRegistry = converterRegistry;
89 annotatedTypes.add(Object.class);
90 setupMappers();
91 locked = true;
92
93 final ClassLoader classLoader = classLoaderReference.getReference();
94 arguments = new Object[]{
95 this, classLoaderReference, reflectionProvider, converterLookup, new JVM(),
96 classLoader != null ? classLoader : new TypedNull(ClassLoader.class)};
97 }
98
99 /**
100 * Construct an AnnotationMapper.
101 *
102 * @param wrapped the next {@link Mapper} in the chain
103 * @since 1.3
104 * @deprecated As of 1.4.5 use {@link #AnnotationMapper(Mapper, ConverterRegistry, ConverterLookup, ClassLoaderReference, ReflectionProvider)}
105 */
106 public AnnotationMapper(
107 final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup,
108 final ClassLoader classLoader, final ReflectionProvider reflectionProvider,
109 final JVM jvm) {
110 this(wrapped, converterRegistry, converterLookup, new ClassLoaderReference(classLoader), reflectionProvider);
111 }
112
113 @Override
114 public String realMember(final Class type, final String serialized) {
115 if (!locked) {
116 processAnnotations(type);
117 }
118 return super.realMember(type, serialized);
119 }
120
121 @Override
122 public String serializedClass(final Class type) {
123 if (!locked) {
124 processAnnotations(type);
125 }
126 return super.serializedClass(type);
127 }
128
129 @Override
130 public Class defaultImplementationOf(final Class type) {
131 if (!locked) {
132 processAnnotations(type);
133 }
134 final Class defaultImplementation = super.defaultImplementationOf(type);
135 if (!locked) {
136 processAnnotations(defaultImplementation);
137 }
138 return defaultImplementation;
139 }
140
141 @Override
142 public Converter getLocalConverter(final Class definedIn, final String fieldName) {
143 if (!locked) {
144 processAnnotations(definedIn);
145 }
146 return super.getLocalConverter(definedIn, fieldName);
147 }
148
149 public void autodetectAnnotations(final boolean mode) {
150 locked = !mode;
151 }
152
153 public void processAnnotations(final Class[] initialTypes) {
154 if (initialTypes == null || initialTypes.length == 0) {
155 return;
156 }
157 locked = true;
158
159 final Set<Class<?>> types = new UnprocessedTypesSet();
160 for (final Class initialType : initialTypes) {
161 types.add(initialType);
162 }
163 processTypes(types);
164 }
165
166 private void processAnnotations(final Class initialType) {
167 if (initialType == null) {
168 return;
169 }
170
171 final Set<Class<?>> types = new UnprocessedTypesSet();
172 types.add(initialType);
173 processTypes(types);
174 }
175
176 private void processTypes(final Set<Class<?>> types) {
177 while (!types.isEmpty()) {
178 final Iterator<Class<?>> iter = types.iterator();
179 final Class<?> type = iter.next();
180 iter.remove();
181
182 synchronized(type) {
183 if (annotatedTypes.contains(type)) {
184 continue;
185 }
186 try {
187 if (type.isPrimitive()) {
188 continue;
189 }
190
191 addParametrizedTypes(type, types);
192
193 processConverterAnnotations(type);
194 processAliasAnnotation(type, types);
195 processAliasTypeAnnotation(type);
196
197 if (type.isInterface()) {
198 continue;
199 }
200
201 processImplicitCollectionAnnotation(type);
202
203 final Field[] fields = type.getDeclaredFields();
204 for (int i = 0; i < fields.length; i++ ) {
205 final Field field = fields[i];
206 if (field.isEnumConstant()
207 || (field.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) > 0) {
208 continue;
209 }
210
211 addParametrizedTypes(field.getGenericType(), types);
212
213 if (field.isSynthetic()) {
214 continue;
215 }
216
217 processFieldAliasAnnotation(field);
218 processAsAttributeAnnotation(field);
219 processImplicitAnnotation(field);
220 processOmitFieldAnnotation(field);
221 processLocalConverterAnnotation(field);
222 }
223 } finally {
224 annotatedTypes.add(type);
225 }
226 }
227 }
228 }
229
230 private void addParametrizedTypes(Type type, final Set<Class<?>> types) {
231 final Set<Type> processedTypes = new HashSet<Type>();
232 final Set<Type> localTypes = new LinkedHashSet<Type>() {
233
234 @Override
235 public boolean add(final Type o) {
236 if (o instanceof Class) {
237 return types.add((Class<?>)o);
238 }
239 return o == null || processedTypes.contains(o) ? false : super.add(o);
240 }
241
242 };
243 while (type != null) {
244 processedTypes.add(type);
245 if (type instanceof Class) {
246 final Class<?> clazz = (Class<?>)type;
247 types.add(clazz);
248 if (!clazz.isPrimitive()) {
249 final TypeVariable<?>[] typeParameters = clazz.getTypeParameters();
250 for (final TypeVariable<?> typeVariable : typeParameters) {
251 localTypes.add(typeVariable);
252 }
253 localTypes.add(clazz.getGenericSuperclass());
254 for (final Type iface : clazz.getGenericInterfaces()) {
255 localTypes.add(iface);
256 }
257 }
258 } else if (type instanceof TypeVariable) {
259 final TypeVariable<?> typeVariable = (TypeVariable<?>)type;
260 final Type[] bounds = typeVariable.getBounds();
261 for (final Type bound : bounds) {
262 localTypes.add(bound);
263 }
264 } else if (type instanceof ParameterizedType) {
265 final ParameterizedType parametrizedType = (ParameterizedType)type;
266 localTypes.add(parametrizedType.getRawType());
267 final Type[] actualArguments = parametrizedType.getActualTypeArguments();
268 for (final Type actualArgument : actualArguments) {
269 localTypes.add(actualArgument);
270 }
271 } else if (type instanceof GenericArrayType) {
272 final GenericArrayType arrayType = (GenericArrayType)type;
273 localTypes.add(arrayType.getGenericComponentType());
274 }
275
276 if (!localTypes.isEmpty()) {
277 final Iterator<Type> iter = localTypes.iterator();
278 type = iter.next();
279 iter.remove();
280 } else {
281 type = null;
282 }
283 }
284 }
285
286 private void processConverterAnnotations(final Class<?> type) {
287 if (converterRegistry != null) {
288 final XStreamConverters convertersAnnotation = type
289 .getAnnotation(XStreamConverters.class);
290 final XStreamConverter converterAnnotation = type
291 .getAnnotation(XStreamConverter.class);
292 final List<XStreamConverter> annotations = convertersAnnotation != null
293 ? new ArrayList<XStreamConverter>(Arrays.asList(convertersAnnotation.value()))
294 : new ArrayList<XStreamConverter>();
295 if (converterAnnotation != null) {
296 annotations.add(converterAnnotation);
297 }
298 for (final XStreamConverter annotation : annotations) {
299 final Converter converter = cacheConverter(
300 annotation, converterAnnotation != null ? type : null);
301 if (converter != null) {
302 if (converterAnnotation != null || converter.canConvert(type)) {
303 converterRegistry.registerConverter(converter, annotation.priority());
304 } else {
305 throw new InitializationException("Converter "
306 + annotation.value().getName()
307 + " cannot handle annotated class "
308 + type.getName());
309 }
310 }
311 }
312 }
313 }
314
315 private void processAliasAnnotation(final Class<?> type, final Set<Class<?>> types) {
316 final XStreamAlias aliasAnnotation = type.getAnnotation(XStreamAlias.class);
317 if (aliasAnnotation != null) {
318 if (classAliasingMapper == null) {
319 throw new InitializationException("No "
320 + ClassAliasingMapper.class.getName()
321 + " available");
322 }
323 classAliasingMapper.addClassAlias(aliasAnnotation.value(), type);
324 if (aliasAnnotation.impl() != Void.class) {
325 // Alias for Interface/Class with an impl
326 defaultImplementationsMapper.addDefaultImplementation(
327 aliasAnnotation.impl(), type);
328 if (type.isInterface()) {
329 types.add(aliasAnnotation.impl()); // alias Interface's impl
330 }
331 }
332 }
333 }
334
335 private void processAliasTypeAnnotation(final Class<?> type) {
336 final XStreamAliasType aliasAnnotation = type.getAnnotation(XStreamAliasType.class);
337 if (aliasAnnotation != null) {
338 if (classAliasingMapper == null) {
339 throw new InitializationException("No "
340 + ClassAliasingMapper.class.getName()
341 + " available");
342 }
343 classAliasingMapper.addTypeAlias(aliasAnnotation.value(), type);
344 }
345 }
346
347 @Deprecated
348 private void processImplicitCollectionAnnotation(final Class<?> type) {
349 final XStreamImplicitCollection implicitColAnnotation = type
350 .getAnnotation(XStreamImplicitCollection.class);
351 if (implicitColAnnotation != null) {
352 if (implicitCollectionMapper == null) {
353 throw new InitializationException("No "
354 + ImplicitCollectionMapper.class.getName()
355 + " available");
356 }
357 final String fieldName = implicitColAnnotation.value();
358 final String itemFieldName = implicitColAnnotation.item();
359 final Field field;
360 try {
361 field = type.getDeclaredField(fieldName);
362 } catch (final NoSuchFieldException e) {
363 throw new InitializationException(type.getName()
364 + " does not have a field named '"
365 + fieldName
366 + "' as required by "
367 + XStreamImplicitCollection.class.getName());
368 }
369 Class itemType = null;
370 final Type genericType = field.getGenericType();
371 if (genericType instanceof ParameterizedType) {
372 final Type typeArgument = ((ParameterizedType)genericType)
373 .getActualTypeArguments()[0];
374 itemType = getClass(typeArgument);
375 }
376 if (itemType == null) {
377 implicitCollectionMapper.add(type, fieldName, null, Object.class);
378 } else {
379 if (itemFieldName.equals("")) {
380 implicitCollectionMapper.add(type, fieldName, null, itemType);
381 } else {
382 implicitCollectionMapper.add(type, fieldName, itemFieldName, itemType);
383 }
384 }
385 }
386 }
387
388 private void processFieldAliasAnnotation(final Field field) {
389 final XStreamAlias aliasAnnotation = field.getAnnotation(XStreamAlias.class);
390 if (aliasAnnotation != null) {
391 if (fieldAliasingMapper == null) {
392 throw new InitializationException("No "
393 + FieldAliasingMapper.class.getName()
394 + " available");
395 }
396 fieldAliasingMapper.addFieldAlias(
397 aliasAnnotation.value(), field.getDeclaringClass(), field.getName());
398 }
399 }
400
401 private void processAsAttributeAnnotation(final Field field) {
402 final XStreamAsAttribute asAttributeAnnotation = field
403 .getAnnotation(XStreamAsAttribute.class);
404 if (asAttributeAnnotation != null) {
405 if (attributeMapper == null) {
406 throw new InitializationException("No "
407 + AttributeMapper.class.getName()
408 + " available");
409 }
410 attributeMapper.addAttributeFor(field);
411 }
412 }
413
414 private void processImplicitAnnotation(final Field field) {
415 final XStreamImplicit implicitAnnotation = field.getAnnotation(XStreamImplicit.class);
416 if (implicitAnnotation != null) {
417 if (implicitCollectionMapper == null) {
418 throw new InitializationException("No "
419 + ImplicitCollectionMapper.class.getName()
420 + " available");
421 }
422 final String fieldName = field.getName();
423 final String itemFieldName = implicitAnnotation.itemFieldName();
424 final String keyFieldName = implicitAnnotation.keyFieldName();
425 boolean isMap = Map.class.isAssignableFrom(field.getType());
426 Class itemType = null;
427 if (!field.getType().isArray()) {
428 final Type genericType = field.getGenericType();
429 if (genericType instanceof ParameterizedType) {
430 final Type[] actualTypeArguments = ((ParameterizedType)genericType)
431 .getActualTypeArguments();
432 final Type typeArgument = actualTypeArguments[isMap ? 1 : 0];
433 itemType = getClass(typeArgument);
434 }
435 }
436 if (isMap) {
437 implicitCollectionMapper.add(
438 field.getDeclaringClass(), fieldName,
439 itemFieldName != null && !"".equals(itemFieldName) ? itemFieldName : null,
440 itemType, keyFieldName != null && !"".equals(keyFieldName)
441 ? keyFieldName
442 : null);
443 } else {
444 if (itemFieldName != null && !"".equals(itemFieldName)) {
445 implicitCollectionMapper.add(
446 field.getDeclaringClass(), fieldName, itemFieldName, itemType);
447 } else {
448 implicitCollectionMapper
449 .add(field.getDeclaringClass(), fieldName, itemType);
450 }
451 }
452 }
453 }
454
455 private void processOmitFieldAnnotation(final Field field) {
456 final XStreamOmitField omitFieldAnnotation = field
457 .getAnnotation(XStreamOmitField.class);
458 if (omitFieldAnnotation != null) {
459 if (fieldAliasingMapper == null) {
460 throw new InitializationException("No "
461 + FieldAliasingMapper.class.getName()
462 + " available");
463 }
464 fieldAliasingMapper.omitField(field.getDeclaringClass(), field.getName());
465 }
466 }
467
468 private void processLocalConverterAnnotation(final Field field) {
469 final XStreamConverter annotation = field.getAnnotation(XStreamConverter.class);
470 if (annotation != null) {
471 final Converter converter = cacheConverter(annotation, field.getType());
472 if (converter != null) {
473 if (localConversionMapper == null) {
474 throw new InitializationException("No "
475 + LocalConversionMapper.class.getName()
476 + " available");
477 }
478 localConversionMapper.registerLocalConverter(
479 field.getDeclaringClass(), field.getName(), converter);
480 }
481 }
482 }
483
484 private Converter cacheConverter(final XStreamConverter annotation,
485 final Class targetType) {
486 Converter result = null;
487 final Object[] args;
488 final List<Object> parameter = new ArrayList<Object>();
489 if (targetType != null && annotation.useImplicitType()) {
490 parameter.add(targetType);
491 }
492 final List<Object> arrays = new ArrayList<Object>();
493 arrays.add(annotation.booleans());
494 arrays.add(annotation.bytes());
495 arrays.add(annotation.chars());
496 arrays.add(annotation.doubles());
497 arrays.add(annotation.floats());
498 arrays.add(annotation.ints());
499 arrays.add(annotation.longs());
500 arrays.add(annotation.shorts());
501 arrays.add(annotation.strings());
502 arrays.add(annotation.types());
503 for(Object array : arrays) {
504 if (array != null) {
505 int length = Array.getLength(array);
506 for (int i = 0; i < length; i++ ) {
507 Object object = Array.get(array, i);
508 if (!parameter.contains(object)) {
509 parameter.add(object);
510 }
511 }
512 }
513 }
514 final Class<? extends ConverterMatcher> converterType = annotation.value();
515 Map<List<Object>, Converter> converterMapping = converterCache.get(converterType);
516 if (converterMapping != null) {
517 result = converterMapping.get(parameter);
518 }
519 if (result == null) {
520 int size = parameter.size();
521 if (size > 0) {
522 args = new Object[arguments.length + size];
523 System.arraycopy(arguments, 0, args, size, arguments.length);
524 System.arraycopy(parameter.toArray(new Object[size]), 0, args, 0, size);
525 } else {
526 args = arguments;
527 }
528
529 final Converter converter;
530 try {
531 if (SingleValueConverter.class.isAssignableFrom(converterType)
532 && !Converter.class.isAssignableFrom(converterType)) {
533 final SingleValueConverter svc = (SingleValueConverter)DependencyInjectionFactory
534 .newInstance(converterType, args);
535 converter = new SingleValueConverterWrapper(svc);
536 } else {
537 converter = (Converter)DependencyInjectionFactory.newInstance(
538 converterType, args);
539 }
540 } catch (final Exception e) {
541 throw new InitializationException("Cannot instantiate converter "
542 + converterType.getName()
543 + (targetType != null ? " for type " + targetType.getName() : ""), e);
544 }
545 if (converterMapping == null) {
546 converterMapping = new HashMap<List<Object>, Converter>();
547 converterCache.put(converterType, converterMapping);
548 }
549 converterMapping.put(parameter, converter);
550 result = converter;
551 }
552 return result;
553 }
554
555 private Class<?> getClass(final Type typeArgument) {
556 Class<?> type = null;
557 if (typeArgument instanceof ParameterizedType) {
558 type = (Class<?>)((ParameterizedType)typeArgument).getRawType();
559 } else if (typeArgument instanceof Class) {
560 type = (Class<?>)typeArgument;
561 }
562 return type;
563 }
564
565 private void setupMappers() {
566 classAliasingMapper = (ClassAliasingMapper)lookupMapperOfType(ClassAliasingMapper.class);
567 defaultImplementationsMapper = (DefaultImplementationsMapper)lookupMapperOfType(DefaultImplementationsMapper.class);
568 implicitCollectionMapper = (ImplicitCollectionMapper)lookupMapperOfType(ImplicitCollectionMapper.class);
569 fieldAliasingMapper = (FieldAliasingMapper)lookupMapperOfType(FieldAliasingMapper.class);
570 attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class);
571 localConversionMapper = (LocalConversionMapper)lookupMapperOfType(LocalConversionMapper.class);
572 }
573
574 private void writeObject(final ObjectOutputStream out) throws IOException {
575 out.defaultWriteObject();
576 int max = arguments.length - 2;
577 out.writeInt(max);
578 for (int i = 0; i < max; i++ ) {
579 out.writeObject(arguments[i]);
580 }
581 }
582
583 private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
584 in.defaultReadObject();
585 setupMappers();
586 int max = in.readInt();
587 arguments = new Object[max+2];
588 for (int i = 0; i < max; i++ ) {
589 arguments[i] = in.readObject();
590 if (arguments[i] instanceof ClassLoaderReference) {
591 arguments[max+1] = ((ClassLoaderReference)arguments[i]).getReference();
592 }
593 }
594 arguments[max] = new JVM();
595 }
596
597 private final class UnprocessedTypesSet extends LinkedHashSet<Class<?>> {
598 @Override
599 public boolean add(Class<?> type) {
600 if (type == null) {
601 return false;
602 }
603 while (type.isArray()) {
604 type = type.getComponentType();
605 }
606 final String name = type.getName();
607 if (name.startsWith("java.") || name.startsWith("javax.")) {
608 return false;
609 }
610 final boolean ret = annotatedTypes.contains(type) ? false : super.add(type);
611 if (ret) {
612 final XStreamInclude inc = type.getAnnotation(XStreamInclude.class);
613 if (inc != null) {
614 final Class<?>[] incTypes = inc.value();
615 if (incTypes != null) {
616 for (final Class<?> incType : incTypes) {
617 add(incType);
618 }
619 }
620 }
621 }
622 return ret;
623 }
624 }
625 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.core.util.Primitives;
14
15 /**
16 * Mapper that detects arrays and changes the name so it can identified as an array
17 * (for example Foo[] gets serialized as foo-array). Supports multi-dimensional arrays.
18 *
19 * @author Joe Walnes
20 */
21 public class ArrayMapper extends MapperWrapper {
22
23 public ArrayMapper(Mapper wrapped) {
24 super(wrapped);
25 }
26
27 public String serializedClass(Class type) {
28 StringBuffer arraySuffix = new StringBuffer();
29 String name = null;
30 while (type.isArray()) {
31 name = super.serializedClass(type);
32 if (type.getName().equals(name)) {
33 type = type.getComponentType();
34 arraySuffix.append("-array");
35 name = null;
36 } else {
37 break;
38 }
39 }
40 if (name == null) {
41 name = boxedTypeName(type);
42 }
43 if (name == null) {
44 name = super.serializedClass(type);
45 }
46 if (arraySuffix.length() > 0) {
47 return name + arraySuffix;
48 } else {
49 return name;
50 }
51 }
52
53 public Class realClass(String elementName) {
54 int dimensions = 0;
55
56 // strip off "-array" suffix
57 while (elementName.endsWith("-array")) {
58 elementName = elementName.substring(0, elementName.length() - 6); // cut off -array
59 ++dimensions;
60 }
61
62 if (dimensions > 0) {
63 Class componentType = Primitives.primitiveType(elementName);
64 if (componentType == null) {
65 componentType = super.realClass(elementName);
66 }
67 while (componentType.isArray()) {
68 componentType = componentType.getComponentType();
69 ++dimensions;
70 }
71 return super.realClass(arrayType(dimensions, componentType));
72 } else {
73 return super.realClass(elementName);
74 }
75 }
76
77 private String arrayType(int dimensions, Class componentType) {
78 StringBuffer className = new StringBuffer();
79 for (int i = 0; i < dimensions; i++) {
80 className.append('[');
81 }
82 if (componentType.isPrimitive()) {
83 className.append(Primitives.representingChar(componentType));
84 return className.toString();
85 } else {
86 className.append('L').append(componentType.getName()).append(';');
87 return className.toString();
88 }
89 }
90
91 private String boxedTypeName(Class type) {
92 return Primitives.isBoxed(type) ? type.getName() : null;
93 }
94 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 27. March 2006 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.mapper;
12
13
14
15 /**
16 * Mapper that allows aliasing of attribute names.
17 *
18 * @author J&ouml;rg Schaible
19 * @author Guilherme Silveira
20 * @since 1.2
21 */
22 public class AttributeAliasingMapper extends AbstractAttributeAliasingMapper {
23
24 public AttributeAliasingMapper(Mapper wrapped) {
25 super(wrapped);
26 }
27
28 public String aliasForAttribute(String attribute) {
29 String alias = (String)nameToAlias.get(attribute);
30 return alias == null ? super.aliasForAttribute(attribute) : alias;
31 }
32
33 public String attributeForAlias(String alias) {
34 String name = (String)aliasToName.get(alias);
35 return name == null ? super.attributeForAlias(alias) : name;
36 }
37 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 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 20. February 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.lang.reflect.Field;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Map;
17 import java.util.Set;
18
19 import com.thoughtworks.xstream.converters.Converter;
20 import com.thoughtworks.xstream.converters.ConverterLookup;
21 import com.thoughtworks.xstream.converters.SingleValueConverter;
22 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
23
24 /**
25 * Mapper that allows the usage of attributes for fields and corresponding
26 * types or specified arbitrary types. It is responsible for the lookup of the
27 * {@link SingleValueConverter} for item types and attribute names.
28 *
29 * @author Paul Hammant
30 * @author Ian Cartwright
31 * @author J&ouml;rg Schaible
32 * @author Mauro Talevi
33 * @author Guilherme Silveira
34 * @since 1.2
35 */
36 public class AttributeMapper extends MapperWrapper {
37
38 private final Map fieldNameToTypeMap = new HashMap();
39 private final Set typeSet = new HashSet();
40 private ConverterLookup converterLookup;
41 private ReflectionProvider reflectionProvider;
42 private final Set fieldToUseAsAttribute = new HashSet();
43
44 /**
45 * @deprecated As of 1.3
46 */
47 public AttributeMapper(Mapper wrapped) {
48 this(wrapped, null, null);
49 }
50
51 public AttributeMapper(Mapper wrapped, ConverterLookup converterLookup, ReflectionProvider refProvider) {
52 super(wrapped);
53 this.converterLookup = converterLookup;
54 this.reflectionProvider = refProvider;
55 }
56
57 /**
58 * @deprecated As of 1.3
59 */
60 public void setConverterLookup(ConverterLookup converterLookup) {
61 this.converterLookup = converterLookup;
62 }
63
64 public void addAttributeFor(final String fieldName, final Class type) {
65 fieldNameToTypeMap.put(fieldName, type);
66 }
67
68 public void addAttributeFor(final Class type) {
69 typeSet.add(type);
70 }
71
72 private SingleValueConverter getLocalConverterFromItemType(Class type) {
73 Converter converter = converterLookup.lookupConverterForType(type);
74 if (converter != null && converter instanceof SingleValueConverter) {
75 return (SingleValueConverter)converter;
76 } else {
77 return null;
78 }
79 }
80
81 /**
82 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
83 */
84 public SingleValueConverter getConverterFromItemType(String fieldName, Class type) {
85 if (fieldNameToTypeMap.get(fieldName) == type) {
86 return getLocalConverterFromItemType(type);
87 } else {
88 return null;
89 }
90 }
91
92 public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
93 Class definedIn) {
94 if (shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
95 SingleValueConverter converter = getLocalConverterFromItemType(type);
96 if (converter != null) {
97 return converter;
98 }
99 }
100 return super.getConverterFromItemType(fieldName, type, definedIn);
101 }
102
103 public boolean shouldLookForSingleValueConverter(String fieldName, Class type, Class definedIn) {
104 if (typeSet.contains(type)) {
105 return true;
106 } else if (fieldNameToTypeMap.get(fieldName) == type) {
107 return true;
108 } else if (fieldName != null && definedIn != null) {
109 Field field = reflectionProvider.getField(definedIn, fieldName);
110 return fieldToUseAsAttribute.contains(field);
111 }
112 return false;
113 }
114
115 /**
116 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
117 */
118 public SingleValueConverter getConverterFromItemType(Class type) {
119 if (typeSet.contains(type)) {
120 return getLocalConverterFromItemType(type);
121 } else {
122 return null;
123 }
124 }
125
126 /**
127 * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)}
128 */
129 public SingleValueConverter getConverterFromAttribute(String attributeName) {
130 SingleValueConverter converter = null;
131 Class type = (Class)fieldNameToTypeMap.get(attributeName);
132 if (type != null) {
133 converter = getLocalConverterFromItemType(type);
134 }
135 return converter;
136 }
137
138 /**
139 * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)}
140 */
141 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute) {
142 Field field = reflectionProvider.getField(definedIn, attribute);
143 return getConverterFromAttribute(definedIn, attribute, field.getType());
144 }
145
146 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) {
147 if (shouldLookForSingleValueConverter(attribute, type, definedIn)) {
148 SingleValueConverter converter = getLocalConverterFromItemType(type);
149 if (converter != null) {
150 return converter;
151 }
152 }
153 return super.getConverterFromAttribute(definedIn, attribute, type);
154 }
155
156 /**
157 * Tells this mapper to use an attribute for this field.
158 *
159 * @param field the field itself
160 * @since 1.2.2
161 */
162 public void addAttributeFor(Field field) {
163 fieldToUseAsAttribute.add(field);
164 }
165
166 /**
167 * Tells this mapper to use an attribute for this field.
168 *
169 * @param definedIn the declaring class of the field
170 * @param fieldName the name of the field
171 * @throws IllegalArgumentException if the field does not exist
172 * @since 1.3
173 */
174 public void addAttributeFor(Class definedIn, String fieldName) {
175 fieldToUseAsAttribute.add(reflectionProvider.getField(definedIn, fieldName));
176 }
177 }
0 /*
1 * Copyright (C) 2006, 2007, 2008 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 08. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import net.sf.cglib.proxy.Enhancer;
13
14 /**
15 * Mapper that detects proxies generated by the CGLIB enhancer. The implementation modifies
16 * the name, so that it can identify these types. Note, that this mapper relies on the CGLIB
17 * converters:
18 * <ul>
19 * <li>CGLIBEnhancedConverter</li>
20 * </ul>
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.2
24 */
25 public class CGLIBMapper extends MapperWrapper {
26
27 private static String DEFAULT_NAMING_MARKER = "$$EnhancerByCGLIB$$";
28 private final String alias;
29
30 public interface Marker {
31 }
32
33 public CGLIBMapper(Mapper wrapped) {
34 this(wrapped, "CGLIB-enhanced-proxy");
35 }
36
37 public CGLIBMapper(Mapper wrapped, String alias) {
38 super(wrapped);
39 this.alias = alias;
40 }
41
42 public String serializedClass(Class type) {
43 String serializedName = super.serializedClass(type);
44 if (type == null) {
45 return serializedName;
46 }
47 String typeName = type.getName();
48 return typeName.equals(serializedName)
49 && typeName.indexOf(DEFAULT_NAMING_MARKER) > 0
50 && Enhancer.isEnhanced(type) ? alias : serializedName;
51 }
52
53 public Class realClass(String elementName) {
54 return elementName.equals(alias) ? Marker.class : super.realClass(elementName);
55 }
56 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import com.thoughtworks.xstream.XStreamException;
18 import com.thoughtworks.xstream.core.Caching;
19 import com.thoughtworks.xstream.security.ForbiddenClassException;
20
21 /**
22 * Mapper that caches which names map to which classes. Prevents repetitive searching and class loading.
23 *
24 * @author Joe Walnes
25 * @author J&ouml;rg Schaible
26 */
27 public class CachingMapper extends MapperWrapper implements Caching {
28
29 private transient Map realClassCache;
30
31 public CachingMapper(Mapper wrapped) {
32 super(wrapped);
33 readResolve();
34 }
35
36 public Class realClass(String elementName) {
37 Object cached = realClassCache.get(elementName);
38 if (cached != null) {
39 if (cached instanceof Class) {
40 return (Class)cached;
41 }
42 throw (XStreamException)cached;
43 }
44
45 try {
46 Class result = super.realClass(elementName);
47 realClassCache.put(elementName, result);
48 return result;
49 } catch (ForbiddenClassException e) {
50 realClassCache.put(elementName, e);
51 throw e;
52 } catch (CannotResolveClassException e) {
53 realClassCache.put(elementName, e);
54 throw e;
55 }
56 }
57
58 public void flushCache() {
59 realClassCache.clear();
60 }
61
62 private Object readResolve() {
63 realClassCache = Collections.synchronizedMap(new HashMap(128));
64 return this;
65 }
66 }
0 /*
1 * Copyright (C) 2003 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.XStreamException;
14
15 /**
16 * Exception thrown if a mapper cannot locate the appropriate class for an element.
17 *
18 * @author Joe Walnes
19 * @author J&ouml;rg Schaible
20 * @since 1.2
21 */
22 public class CannotResolveClassException extends XStreamException {
23 public CannotResolveClassException(String className) {
24 super(className);
25 }
26 /**
27 * @since 1.4.2
28 */
29 public CannotResolveClassException(String className, Throwable cause) {
30 super(className, cause);
31 }
32 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 09. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.util.HashMap;
14 import java.util.Iterator;
15 import java.util.Map;
16
17 import com.thoughtworks.xstream.core.util.Primitives;
18
19 /**
20 * Mapper that allows a fully qualified class name to be replaced with an alias.
21 *
22 * @author Joe Walnes
23 * @author J&ouml;rg Schaible
24 */
25 public class ClassAliasingMapper extends MapperWrapper {
26
27 private final Map typeToName = new HashMap();
28 private final Map classToName = new HashMap();
29 private transient Map nameToType = new HashMap();
30
31 public ClassAliasingMapper(Mapper wrapped) {
32 super(wrapped);
33 }
34
35 public void addClassAlias(String name, Class type) {
36 nameToType.put(name, type.getName());
37 classToName.put(type.getName(), name);
38 }
39
40 /**
41 * @deprecated As of 1.3, method was a leftover of an old implementation
42 */
43 public void addClassAttributeAlias(String name, Class type) {
44 addClassAlias(name, type);
45 }
46
47 public void addTypeAlias(String name, Class type) {
48 nameToType.put(name, type.getName());
49 typeToName.put(type, name);
50 }
51
52 public String serializedClass(Class type) {
53 String alias = (String) classToName.get(type.getName());
54 if (alias != null) {
55 return alias;
56 } else {
57 for (final Iterator iter = typeToName.keySet().iterator(); iter.hasNext();) {
58 final Class compatibleType = (Class)iter.next();
59 if (compatibleType.isAssignableFrom(type)) {
60 return (String)typeToName.get(compatibleType);
61 }
62 }
63 return super.serializedClass(type);
64 }
65 }
66
67 public Class realClass(String elementName) {
68 String mappedName = (String) nameToType.get(elementName);
69
70 if (mappedName != null) {
71 Class type = Primitives.primitiveType(mappedName);
72 if (type != null) {
73 return type;
74 }
75 elementName = mappedName;
76 }
77
78 return super.realClass(elementName);
79 }
80
81 public boolean itemTypeAsAttribute(Class clazz) {
82 return classToName.containsKey(clazz);
83 }
84
85 public boolean aliasIsAttribute(String name) {
86 return nameToType.containsKey(name);
87 }
88
89 private Object readResolve() {
90 nameToType = new HashMap();
91 for (final Iterator iter = classToName.keySet().iterator(); iter.hasNext();) {
92 final Object type = iter.next();
93 nameToType.put(classToName.get(type), type);
94 }
95 for (final Iterator iter = typeToName.keySet().iterator(); iter.hasNext();) {
96 final Class type = (Class)iter.next();
97 nameToType.put(typeToName.get(type), type.getName());
98 }
99 return this;
100 }
101 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.InitializationException;
14
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.Map;
18
19
20 /**
21 * Mapper that resolves default implementations of classes. For example,
22 * mapper.serializedClass(ArrayList.class) will return java.util.List. Calling
23 * mapper.defaultImplementationOf(List.class) will return ArrayList.
24 *
25 * @author Joe Walnes
26 */
27 public class DefaultImplementationsMapper extends MapperWrapper {
28
29 private final Map typeToImpl = new HashMap();
30 private transient Map implToType = new HashMap();
31
32 public DefaultImplementationsMapper(Mapper wrapped) {
33 super(wrapped);
34 addDefaults();
35 }
36
37 protected void addDefaults() {
38 // null handling
39 addDefaultImplementation(null, Mapper.Null.class);
40 // register primitive types
41 addDefaultImplementation(Boolean.class, boolean.class);
42 addDefaultImplementation(Character.class, char.class);
43 addDefaultImplementation(Integer.class, int.class);
44 addDefaultImplementation(Float.class, float.class);
45 addDefaultImplementation(Double.class, double.class);
46 addDefaultImplementation(Short.class, short.class);
47 addDefaultImplementation(Byte.class, byte.class);
48 addDefaultImplementation(Long.class, long.class);
49 }
50
51 public void addDefaultImplementation(Class defaultImplementation, Class ofType) {
52 if (defaultImplementation != null && defaultImplementation.isInterface()) {
53 throw new InitializationException(
54 "Default implementation is not a concrete class: "
55 + defaultImplementation.getName());
56 }
57 typeToImpl.put(ofType, defaultImplementation);
58 implToType.put(defaultImplementation, ofType);
59 }
60
61 public String serializedClass(Class type) {
62 Class baseType = (Class)implToType.get(type);
63 return baseType == null ? super.serializedClass(type) : super.serializedClass(baseType);
64 }
65
66 public Class defaultImplementationOf(Class type) {
67 if (typeToImpl.containsKey(type)) {
68 return (Class)typeToImpl.get(type);
69 } else {
70 return super.defaultImplementationOf(type);
71 }
72 }
73
74 private Object readResolve() {
75 implToType = new HashMap();
76 for (final Iterator iter = typeToImpl.keySet().iterator(); iter.hasNext();) {
77 final Object type = iter.next();
78 implToType.put(typeToImpl.get(type), type);
79 }
80 return this;
81 }
82 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15 import com.thoughtworks.xstream.core.ClassLoaderReference;
16 import com.thoughtworks.xstream.core.util.Primitives;
17
18
19 /**
20 * Default mapper implementation with 'vanilla' functionality. To build up the functionality required, wrap this mapper
21 * with other mapper implementations.
22 *
23 * @author Joe Walnes
24 * @author J&ouml;rg Schaible
25 */
26 public class DefaultMapper implements Mapper {
27
28 private static String XSTREAM_PACKAGE_ROOT;
29 static {
30 String packageName = DefaultMapper.class.getName();
31 int idx = packageName.indexOf(".xstream.");
32 XSTREAM_PACKAGE_ROOT = idx > 0 ? packageName.substring(0, idx+9) : ".N/A";
33 }
34
35 private final ClassLoaderReference classLoaderReference;
36
37
38 /**
39 * Construct a DefaultMapper.
40 *
41 * @param classLoaderReference the reference to the classloader used by the XStream instance.
42 * @since 1.4.5
43 */
44 public DefaultMapper(ClassLoaderReference classLoaderReference) {
45 this.classLoaderReference = classLoaderReference;
46 }
47
48 /**
49 * Construct a DefaultMapper.
50 *
51 * @param classLoader the ClassLoader used by the XStream instance.
52 * @deprecated As of 1.4.5 use {@link #DefaultMapper(ClassLoaderReference)}
53 */
54 public DefaultMapper(ClassLoader classLoader) {
55 this(new ClassLoaderReference(classLoader));
56 }
57
58 public String serializedClass(Class type) {
59 return type.getName();
60 }
61
62 public Class realClass(String elementName) {
63 Class resultingClass = Primitives.primitiveType(elementName);
64 if( resultingClass != null ){
65 return resultingClass;
66 }
67 try {
68 boolean initialize = true;
69 final ClassLoader classLoader;
70 if (elementName.startsWith(XSTREAM_PACKAGE_ROOT)) {
71 classLoader = DefaultMapper.class.getClassLoader();
72 } else {
73 classLoader = classLoaderReference.getReference();
74 initialize = elementName.charAt(0) == '[';
75 }
76 return Class.forName(elementName, initialize, classLoader);
77 } catch (ClassNotFoundException e) {
78 throw new CannotResolveClassException(elementName);
79 }
80 }
81
82 public Class defaultImplementationOf(Class type) {
83 return type;
84 }
85
86 public String aliasForAttribute(String attribute) {
87 return attribute;
88 }
89
90 public String attributeForAlias(String alias) {
91 return alias;
92 }
93
94 public String aliasForSystemAttribute(String attribute) {
95 return attribute;
96 }
97
98 public boolean isImmutableValueType(Class type) {
99 return false;
100 }
101
102 public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName) {
103 return null;
104 }
105
106 public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) {
107 return null;
108 }
109
110 public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName) {
111 return null;
112 }
113
114 public boolean shouldSerializeMember(Class definedIn, String fieldName) {
115 return true;
116 }
117
118 public String lookupName(Class type) {
119 return serializedClass(type);
120 }
121
122 public Class lookupType(String elementName) {
123 return realClass(elementName);
124 }
125
126 public String serializedMember(Class type, String memberName) {
127 return memberName;
128 }
129
130 public String realMember(Class type, String serialized) {
131 return serialized;
132 }
133
134 /**
135 * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)}
136 */
137 public SingleValueConverter getConverterFromAttribute(String name) {
138 return null;
139 }
140
141 /**
142 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
143 */
144 public SingleValueConverter getConverterFromItemType(String fieldName, Class type) {
145 return null;
146 }
147
148 /**
149 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
150 */
151 public SingleValueConverter getConverterFromItemType(Class type) {
152 return null;
153 }
154
155 public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
156 Class definedIn) {
157 return null;
158 }
159
160 public Converter getLocalConverter(Class definedIn, String fieldName) {
161 return null;
162 }
163
164 public Mapper lookupMapperOfType(Class type) {
165 return null;
166 }
167
168 /**
169 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
170 */
171 public String aliasForAttribute(Class definedIn, String fieldName) {
172 return fieldName;
173 }
174
175 /**
176 * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
177 */
178 public String attributeForAlias(Class definedIn, String alias) {
179 return alias;
180 }
181
182 /**
183 * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)}
184 */
185 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute) {
186 return null;
187 }
188
189 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) {
190 return null;
191 }
192 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.lang.reflect.Proxy;
14
15 /**
16 * Mapper for handling special cases of aliasing dynamic proxies. The alias property specifies the name an instance
17 * of a dynamic proxy should be serialized with.
18 *
19 * @author Joe Walnes
20 */
21 public class DynamicProxyMapper extends MapperWrapper {
22
23 private String alias;
24
25 public DynamicProxyMapper(Mapper wrapped) {
26 this(wrapped, "dynamic-proxy");
27 }
28
29 public DynamicProxyMapper(Mapper wrapped, String alias) {
30 super(wrapped);
31 this.alias = alias;
32 }
33
34 public String getAlias() {
35 return alias;
36 }
37
38 public void setAlias(String alias) {
39 this.alias = alias;
40 }
41
42 public String serializedClass(Class type) {
43 if (Proxy.isProxyClass(type)) {
44 return alias;
45 } else {
46 return super.serializedClass(type);
47 }
48 }
49
50 public Class realClass(String elementName) {
51 if (elementName.equals(alias)) {
52 return DynamicProxy.class;
53 } else {
54 return super.realClass(elementName);
55 }
56 }
57
58 /**
59 * Place holder type used for dynamic proxies.
60 */
61 public static class DynamicProxy {}
62
63 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 20. March 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15 import com.thoughtworks.xstream.converters.enums.EnumSingleValueConverter;
16 import com.thoughtworks.xstream.core.Caching;
17
18 import java.util.EnumSet;
19 import java.util.HashMap;
20 import java.util.Map;
21
22
23 /**
24 * Mapper that handles the special case of polymorphic enums in Java 1.5. This renames MyEnum$1
25 * to MyEnum making it less bloaty in the XML and avoiding the need for an alias per enum value
26 * to be specified. Additionally every enum is treated automatically as immutable type and can
27 * be written as attribute.
28 *
29 * @author Joe Walnes
30 * @author J&ouml;rg Schaible
31 */
32 public class EnumMapper extends MapperWrapper implements Caching {
33
34 private transient AttributeMapper attributeMapper;
35 private transient Map<Class, SingleValueConverter> enumConverterMap;
36
37 /**
38 * @deprecated As of 1.3.1, use {@link #EnumMapper(Mapper)}
39 */
40 @Deprecated
41 public EnumMapper(Mapper wrapped, ConverterLookup lookup) {
42 super(wrapped);
43 readResolve();
44 }
45
46 public EnumMapper(Mapper wrapped) {
47 super(wrapped);
48 readResolve();
49 }
50
51 @Override
52 public String serializedClass(Class type) {
53 if (type == null) {
54 return super.serializedClass(type);
55 }
56 if (Enum.class.isAssignableFrom(type) && type.getSuperclass() != Enum.class) {
57 return super.serializedClass(type.getSuperclass());
58 } else if (EnumSet.class.isAssignableFrom(type)) {
59 return super.serializedClass(EnumSet.class);
60 } else {
61 return super.serializedClass(type);
62 }
63 }
64
65 @Override
66 public boolean isImmutableValueType(Class type) {
67 return (Enum.class.isAssignableFrom(type)) || super.isImmutableValueType(type);
68 }
69
70 @Override
71 public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
72 Class definedIn) {
73 SingleValueConverter converter = getLocalConverter(fieldName, type, definedIn);
74 return converter == null
75 ? super.getConverterFromItemType(fieldName, type, definedIn)
76 : converter;
77 }
78
79 @Override
80 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute,
81 Class type) {
82 SingleValueConverter converter = getLocalConverter(attribute, type, definedIn);
83 return converter == null
84 ? super.getConverterFromAttribute(definedIn, attribute, type)
85 : converter;
86 }
87
88 private SingleValueConverter getLocalConverter(String fieldName, Class type, Class definedIn) {
89 if (attributeMapper != null
90 && Enum.class.isAssignableFrom(type)
91 && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
92 synchronized (enumConverterMap) {
93 SingleValueConverter singleValueConverter = enumConverterMap.get(type);
94 if (singleValueConverter == null) {
95 singleValueConverter = super.getConverterFromItemType(fieldName, type, definedIn);
96 if (singleValueConverter == null) {
97 @SuppressWarnings("unchecked")
98 Class<? extends Enum> enumType = type;
99 singleValueConverter = new EnumSingleValueConverter(enumType);
100 }
101 enumConverterMap.put(type, singleValueConverter);
102 }
103 return singleValueConverter;
104 }
105 }
106 return null;
107 }
108
109 public void flushCache() {
110 if (enumConverterMap.size() > 0) {
111 synchronized (enumConverterMap) {
112 enumConverterMap.clear();
113 }
114 }
115 }
116
117 private Object readResolve() {
118 this.enumConverterMap = new HashMap<Class, SingleValueConverter>();
119 this.attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class);
120 return this;
121 }
122 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 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 09. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.core.util.FastField;
14
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.LinkedHashSet;
19 import java.util.Map;
20 import java.util.Set;
21 import java.util.regex.Pattern;
22
23 /**
24 * Mapper that allows a field of a specific class to be replaced with a shorter alias, or omitted
25 * entirely.
26 *
27 * @author Joe Walnes
28 */
29 public class FieldAliasingMapper extends MapperWrapper {
30
31 protected final Map fieldToAliasMap = new HashMap();
32 protected final Map aliasToFieldMap = new HashMap();
33 protected final Set fieldsToOmit = new HashSet();
34 protected final Set unknownFieldsToIgnore = new LinkedHashSet();
35
36 public FieldAliasingMapper(Mapper wrapped) {
37 super(wrapped);
38 }
39
40 public void addFieldAlias(String alias, Class type, String fieldName) {
41 fieldToAliasMap.put(key(type, fieldName), alias);
42 aliasToFieldMap.put(key(type, alias), fieldName);
43 }
44
45 public void addFieldsToIgnore(final Pattern pattern) {
46 unknownFieldsToIgnore.add(pattern);
47 }
48
49 private Object key(Class type, String name) {
50 return new FastField(type, name);
51 }
52
53 public String serializedMember(Class type, String memberName) {
54 String alias = getMember(type, memberName, fieldToAliasMap);
55 if (alias == null) {
56 return super.serializedMember(type, memberName);
57 } else {
58 return alias;
59 }
60 }
61
62 public String realMember(Class type, String serialized) {
63 String real = getMember(type, serialized, aliasToFieldMap);
64 if (real == null) {
65 return super.realMember(type, serialized);
66 } else {
67 return real;
68 }
69 }
70
71 private String getMember(Class type, String name, Map map) {
72 String member = null;
73 for (Class declaringType = type;
74 member == null && declaringType != Object.class && declaringType != null;
75 declaringType = declaringType.getSuperclass()) {
76 member = (String) map.get(key(declaringType, name));
77 }
78 return member;
79 }
80
81 public boolean shouldSerializeMember(Class definedIn, String fieldName) {
82 if (fieldsToOmit.contains(key(definedIn, fieldName))) {
83 return false;
84 } else if (definedIn == Object.class && !unknownFieldsToIgnore.isEmpty()) {
85 for(Iterator iter = unknownFieldsToIgnore.iterator(); iter.hasNext();) {
86 Pattern pattern = (Pattern)iter.next();
87 if (pattern.matcher(fieldName).matches()) {
88 return false;
89 }
90 }
91 }
92 return true;
93 }
94
95 public void omitField(Class definedIn, String fieldName) {
96 fieldsToOmit.add(key(definedIn, fieldName));
97 }
98 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.util.HashSet;
14 import java.util.Set;
15
16 /**
17 * Mapper that specifies which types are basic immutable types. Types that are marked as immutable will be written
18 * multiple times in the serialization stream without using references.
19 *
20 * @author Joe Walnes
21 */
22 public class ImmutableTypesMapper extends MapperWrapper {
23
24 private final Set immutableTypes = new HashSet();
25
26 public ImmutableTypesMapper(Mapper wrapped) {
27 super(wrapped);
28 }
29
30 public void addImmutableType(Class type) {
31 immutableTypes.add(type);
32 }
33
34 public boolean isImmutableValueType(Class type) {
35 if (immutableTypes.contains(type)) {
36 return true;
37 } else {
38 return super.isImmutableValueType(type);
39 }
40 }
41
42 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2012, 2013, 2014 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 16. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.InitializationException;
14 import com.thoughtworks.xstream.core.util.Primitives;
15
16 import java.lang.reflect.Field;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.Map;
21
22
23 public class ImplicitCollectionMapper extends MapperWrapper {
24
25 public ImplicitCollectionMapper(Mapper wrapped) {
26 super(wrapped);
27 }
28
29 // { definedIn (Class) -> (ImplicitCollectionMapperForClass) }
30 private final Map classNameToMapper = new HashMap();
31
32 private ImplicitCollectionMapperForClass getMapper(Class definedIn) {
33 while (definedIn != null) {
34 ImplicitCollectionMapperForClass mapper = (ImplicitCollectionMapperForClass)classNameToMapper
35 .get(definedIn);
36 if (mapper != null) {
37 return mapper;
38 }
39 definedIn = definedIn.getSuperclass();
40 }
41 return null;
42 }
43
44 private ImplicitCollectionMapperForClass getOrCreateMapper(Class definedIn) {
45 ImplicitCollectionMapperForClass mapper = (ImplicitCollectionMapperForClass)classNameToMapper
46 .get(definedIn);
47 if (mapper == null) {
48 mapper = new ImplicitCollectionMapperForClass(definedIn);
49 classNameToMapper.put(definedIn, mapper);
50 }
51 return mapper;
52 }
53
54 public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType,
55 String itemFieldName) {
56 ImplicitCollectionMapperForClass mapper = getMapper(definedIn);
57 if (mapper != null) {
58 return mapper.getFieldNameForItemTypeAndName(itemType, itemFieldName);
59 } else {
60 return null;
61 }
62 }
63
64 public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) {
65 ImplicitCollectionMapperForClass mapper = getMapper(definedIn);
66 if (mapper != null) {
67 return mapper.getItemTypeForItemFieldName(itemFieldName);
68 } else {
69 return null;
70 }
71 }
72
73 public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType,
74 String fieldName) {
75 ImplicitCollectionMapperForClass mapper = getMapper(itemType);
76 if (mapper != null) {
77 return mapper.getImplicitCollectionDefForFieldName(fieldName);
78 } else {
79 return null;
80 }
81 }
82
83 public void add(Class definedIn, String fieldName, Class itemType) {
84 add(definedIn, fieldName, null, itemType);
85 }
86
87 public void add(Class definedIn, String fieldName, String itemFieldName, Class itemType) {
88 add(definedIn, fieldName, itemFieldName, itemType, null);
89 }
90
91 public void add(Class definedIn, String fieldName, String itemFieldName, Class itemType, String keyFieldName) {
92 Field field = null;
93 Class declaredIn = definedIn;
94 while (declaredIn != Object.class && definedIn != null) {
95 try {
96 field = declaredIn.getDeclaredField(fieldName);
97 break;
98 } catch (SecurityException e) {
99 throw new InitializationException(
100 "Access denied for field with implicit collection", e);
101 } catch (NoSuchFieldException e) {
102 declaredIn = declaredIn.getSuperclass();
103 }
104 }
105 if (field == null) {
106 throw new InitializationException("No field \""
107 + fieldName
108 + "\" for implicit collection");
109 } else if (Map.class.isAssignableFrom(field.getType())) {
110 if (itemFieldName == null && keyFieldName == null) {
111 itemType = Map.Entry.class;
112 }
113 } else if (!Collection.class.isAssignableFrom(field.getType())) {
114 Class fieldType = field.getType();
115 if (!fieldType.isArray()) {
116 throw new InitializationException("Field \""
117 + fieldName
118 + "\" declares no collection or array");
119 } else {
120 Class componentType = fieldType.getComponentType();
121 componentType = componentType.isPrimitive() ? Primitives.box(componentType) : componentType;
122 if (itemType == null) {
123 itemType = componentType;
124 } else {
125 itemType = itemType.isPrimitive() ? Primitives.box(itemType) : itemType;
126 if (!componentType.isAssignableFrom(itemType)) {
127 throw new InitializationException("Field \""
128 + fieldName
129 + "\" declares an array, but the array type is not compatible with " + itemType.getName());
130
131 }
132 }
133 }
134 }
135 ImplicitCollectionMapperForClass mapper = getOrCreateMapper(definedIn);
136 mapper.add(new ImplicitCollectionMappingImpl(fieldName, itemType, itemFieldName, keyFieldName));
137 }
138
139 private class ImplicitCollectionMapperForClass {
140 private Class definedIn;
141 // { (NamedItemType) -> (ImplicitCollectionDefImpl) }
142 private Map namedItemTypeToDef = new HashMap();
143 // { itemFieldName (String) -> (ImplicitCollectionDefImpl) }
144 private Map itemFieldNameToDef = new HashMap();
145 // { fieldName (String) -> (ImplicitCollectionDefImpl) }
146 private Map fieldNameToDef = new HashMap();
147
148 ImplicitCollectionMapperForClass(Class definedIn) {
149 this.definedIn = definedIn;
150 }
151
152 public String getFieldNameForItemTypeAndName(Class itemType, String itemFieldName) {
153 ImplicitCollectionMappingImpl unnamed = null;
154 for (Iterator iterator = namedItemTypeToDef.keySet().iterator(); iterator.hasNext();) {
155 NamedItemType itemTypeForFieldName = (NamedItemType)iterator.next();
156 ImplicitCollectionMappingImpl def = (ImplicitCollectionMappingImpl)namedItemTypeToDef
157 .get(itemTypeForFieldName);
158 if (itemType == Mapper.Null.class) {
159 unnamed = def;
160 break;
161 } else if (itemTypeForFieldName.itemType.isAssignableFrom(itemType)) {
162 if (def.getItemFieldName() != null) {
163 if (def.getItemFieldName().equals(itemFieldName)) {
164 return def.getFieldName();
165 }
166 } else {
167 if (unnamed == null
168 || unnamed.getItemType() == null
169 || (def.getItemType() != null
170 && unnamed.getItemType().isAssignableFrom(def.getItemType()))) {
171 unnamed = def;
172 }
173 }
174 }
175 }
176 if (unnamed != null) {
177 return unnamed.getFieldName();
178 } else {
179 ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass());
180 return mapper != null ? mapper.getFieldNameForItemTypeAndName(itemType, itemFieldName) : null;
181 }
182 }
183
184 public Class getItemTypeForItemFieldName(String itemFieldName) {
185 ImplicitCollectionMappingImpl def = getImplicitCollectionDefByItemFieldName(itemFieldName);
186 if (def != null) {
187 return def.getItemType();
188 } else {
189 ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass());
190 return mapper != null ? mapper.getItemTypeForItemFieldName(itemFieldName) : null;
191 }
192 }
193
194 private ImplicitCollectionMappingImpl getImplicitCollectionDefByItemFieldName(
195 String itemFieldName) {
196 if (itemFieldName == null) {
197 return null;
198 } else {
199 ImplicitCollectionMappingImpl mapping = (ImplicitCollectionMappingImpl)itemFieldNameToDef.get(itemFieldName);
200 if (mapping != null) {
201 return mapping;
202 } else {
203 ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass());
204 return mapper != null ? mapper.getImplicitCollectionDefByItemFieldName(itemFieldName) : null;
205 }
206 }
207 }
208
209 public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(String fieldName) {
210 ImplicitCollectionMapping mapping = (ImplicitCollectionMapping)fieldNameToDef.get(fieldName);
211 if (mapping != null) {
212 return mapping;
213 } else {
214 ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass());
215 return mapper != null ? mapper.getImplicitCollectionDefForFieldName(fieldName) : null;
216 }
217 }
218
219 public void add(ImplicitCollectionMappingImpl def) {
220 fieldNameToDef.put(def.getFieldName(), def);
221 namedItemTypeToDef.put(def.createNamedItemType(), def);
222 if (def.getItemFieldName() != null) {
223 itemFieldNameToDef.put(def.getItemFieldName(), def);
224 }
225 }
226
227 }
228
229 private static class ImplicitCollectionMappingImpl implements ImplicitCollectionMapping {
230 private final String fieldName;
231 private final String itemFieldName;
232 private final Class itemType;
233 private final String keyFieldName;
234
235 ImplicitCollectionMappingImpl(String fieldName, Class itemType, String itemFieldName, String keyFieldName) {
236 this.fieldName = fieldName;
237 this.itemFieldName = itemFieldName;
238 this.itemType = itemType;
239 this.keyFieldName = keyFieldName;
240 }
241
242 public NamedItemType createNamedItemType() {
243 return new NamedItemType(itemType, itemFieldName);
244 }
245
246 public String getFieldName() {
247 return fieldName;
248 }
249
250 public String getItemFieldName() {
251 return itemFieldName;
252 }
253
254 public Class getItemType() {
255 return itemType;
256 }
257
258 public String getKeyFieldName() {
259 return keyFieldName;
260 }
261 }
262
263 private static class NamedItemType {
264 Class itemType;
265 String itemFieldName;
266
267 NamedItemType(Class itemType, String itemFieldName) {
268 this.itemType = itemType == null ? Object.class : itemType;
269 this.itemFieldName = itemFieldName;
270 }
271
272 public boolean equals(Object obj) {
273 if (obj instanceof NamedItemType) {
274 NamedItemType b = (NamedItemType)obj;
275 return itemType.equals(b.itemType) && isEquals(itemFieldName, b.itemFieldName);
276 } else {
277 return false;
278 }
279 }
280
281 private static boolean isEquals(Object a, Object b) {
282 if (a == null) {
283 return b == null;
284 } else {
285 return a.equals(b);
286 }
287 }
288
289 public int hashCode() {
290 int hash = itemType.hashCode() << 7;
291 if (itemFieldName != null) {
292 hash += itemFieldName.hashCode();
293 }
294 return hash;
295 }
296 }
297 }
0 /*
1 * Copyright (C) 2015 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 15. January 2015 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.mapper;
7
8 import java.io.Serializable;
9 import java.lang.reflect.Method;
10 import java.lang.reflect.Modifier;
11
12 import com.thoughtworks.xstream.core.util.Types;
13
14
15 /**
16 * Mapper to map serializable lambda types to the name of their functional interface and non-serializable ones to
17 * Mapper.Null.
18 *
19 * @author J&ouml;rg Schaible
20 * @since 1.4.8
21 */
22 public class LambdaMapper extends MapperWrapper {
23
24 /**
25 * Constructs a LambdaMapper.
26 *
27 * @param wrapped mapper
28 * @since 1.4.8
29 */
30 public LambdaMapper(final Mapper wrapped) {
31 super(wrapped);
32 }
33
34 @Override
35 public String serializedClass(final Class type) {
36 Class<?> replacement = null;
37 if (Types.isLambdaType(type)) {
38 if (Serializable.class.isAssignableFrom(type)) {
39 final Class<?>[] interfaces = type.getInterfaces();
40 if (interfaces.length > 1) {
41 for (int i = 0; replacement == null && i < interfaces.length; i++) {
42 final Class<?> iface = interfaces[i];
43 for (final Method method : iface.getMethods()) {
44 if (!method.isDefault() && !Modifier.isStatic(method.getModifiers())) {
45 replacement = iface;
46 break;
47 }
48 }
49 }
50 } else {
51 replacement = interfaces[0];
52 }
53 } else {
54 replacement = Null.class;
55 }
56 }
57 return super.serializedClass(replacement == null ? type : replacement);
58 }
59 }
0 /*
1 * Copyright (C) 2007, 2008 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 06. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import com.thoughtworks.xstream.converters.Converter;
13 import com.thoughtworks.xstream.converters.SingleValueConverter;
14 import com.thoughtworks.xstream.core.util.FastField;
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19
20 /**
21 * A Mapper for locally defined converters for a member field.
22 *
23 * @author J&ouml;rg Schaible
24 * @since 1.3
25 */
26 public class LocalConversionMapper extends MapperWrapper {
27
28 private final Map localConverters = new HashMap();
29 private transient AttributeMapper attributeMapper;
30
31 /**
32 * Constructs a LocalConversionMapper.
33 *
34 * @param wrapped
35 * @since 1.3
36 */
37 public LocalConversionMapper(Mapper wrapped) {
38 super(wrapped);
39 readResolve();
40 }
41
42 public void registerLocalConverter(Class definedIn, String fieldName, Converter converter) {
43 localConverters.put(new FastField(definedIn, fieldName), converter);
44 }
45
46 public Converter getLocalConverter(Class definedIn, String fieldName) {
47 return (Converter)localConverters.get(new FastField(definedIn, fieldName));
48 }
49
50 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute,
51 Class type) {
52 SingleValueConverter converter = getLocalSingleValueConverter(
53 definedIn, attribute, type);
54 return converter == null
55 ? super.getConverterFromAttribute(definedIn, attribute, type)
56 : converter;
57 }
58
59 public SingleValueConverter getConverterFromItemType(String fieldName, Class type,
60 Class definedIn) {
61 SingleValueConverter converter = getLocalSingleValueConverter(
62 definedIn, fieldName, type);
63 return converter == null
64 ? super.getConverterFromItemType(fieldName, type, definedIn)
65 : converter;
66 }
67
68 private SingleValueConverter getLocalSingleValueConverter(Class definedIn,
69 String fieldName, Class type) {
70 if (attributeMapper != null
71 && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) {
72 Converter converter = getLocalConverter(definedIn, fieldName);
73 if (converter != null && converter instanceof SingleValueConverter) {
74 return (SingleValueConverter)converter;
75 }
76 }
77 return null;
78 }
79
80 private Object readResolve() {
81 this.attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class);
82 return this;
83 }
84 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15
16 public interface Mapper {
17 /**
18 * Place holder type used for null values.
19 */
20 class Null {}
21
22 /**
23 * How a class name should be represented in its serialized form.
24 */
25 String serializedClass(Class type);
26
27 /**
28 * How a serialized class representation should be mapped back to a real class.
29 */
30 Class realClass(String elementName);
31
32 /**
33 * How a class member should be represented in its serialized form.
34 */
35 String serializedMember(Class type, String memberName);
36
37 /**
38 * How a serialized member representation should be mapped back to a real member.
39 */
40 String realMember(Class type, String serialized);
41
42 /**
43 * Whether this type is a simple immutable value (int, boolean, String, URL, etc.
44 * Immutable types will be repeatedly written in the serialized stream, instead of using object references.
45 */
46 boolean isImmutableValueType(Class type);
47
48 Class defaultImplementationOf(Class type);
49
50 /**
51 * Get the alias for an attribute's name.
52 *
53 * @param attribute the attribute
54 * @return the alias
55 * @since 1.2
56 */
57 String aliasForAttribute(String attribute);
58
59 /**
60 * Get the attribute's name for an alias.
61 *
62 * @param alias the alias
63 * @return the attribute's name
64 * @since 1.2
65 */
66 String attributeForAlias(String alias);
67
68 /**
69 * Get the alias for a system attribute's name.
70 *
71 * @param attribute the system attribute
72 * @return the alias
73 * @since 1.3.1
74 */
75 String aliasForSystemAttribute(String attribute);
76
77 /**
78 * Get the name of the field that acts as the default collection for an object, or return null if there is none.
79 *
80 * @param definedIn owning type
81 * @param itemType item type
82 * @param itemFieldName optional item element name
83 */
84 String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName);
85
86 Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName);
87
88 ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName);
89
90 /**
91 * Determine whether a specific member should be serialized.
92 *
93 * @since 1.1.3
94 */
95 boolean shouldSerializeMember(Class definedIn, String fieldName);
96
97 interface ImplicitCollectionMapping {
98 String getFieldName();
99 String getItemFieldName();
100 Class getItemType();
101 String getKeyFieldName();
102 }
103
104 /**
105 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
106 */
107 SingleValueConverter getConverterFromItemType(String fieldName, Class type);
108
109 /**
110 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
111 */
112 SingleValueConverter getConverterFromItemType(Class type);
113
114 /**
115 * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)}
116 */
117 SingleValueConverter getConverterFromAttribute(String name);
118
119 Converter getLocalConverter(Class definedIn, String fieldName);
120
121 Mapper lookupMapperOfType(Class type);
122
123 /**
124 * Returns a single value converter to be used in a specific field.
125 *
126 * @param fieldName the field name
127 * @param type the field type
128 * @param definedIn the type which defines this field
129 * @return a SingleValueConverter or null if there no such converter should be used for this
130 * field.
131 * @since 1.2.2
132 */
133 SingleValueConverter getConverterFromItemType(String fieldName, Class type, Class definedIn);
134
135 /**
136 * Returns an alias for a single field defined in an specific type.
137 *
138 * @param definedIn the type where the field was defined
139 * @param fieldName the field name
140 * @return the alias for this field or its own name if no alias was defined
141 * @since 1.2.2
142 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
143 */
144 String aliasForAttribute(Class definedIn, String fieldName);
145
146 /**
147 * Returns the field name for an aliased attribute.
148 *
149 * @param definedIn the type where the field was defined
150 * @param alias the alias
151 * @return the original attribute name
152 * @since 1.2.2
153 * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
154 */
155 String attributeForAlias(Class definedIn, String alias);
156
157 /**
158 * Returns which converter to use for an specific attribute in a type.
159 *
160 * @param definedIn the field's parent
161 * @param attribute the attribute name
162 * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)}
163 */
164 SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute);
165
166 /**
167 * Returns which converter to use for an specific attribute in a type.
168 *
169 * @param definedIn the field's parent
170 * @param attribute the attribute name
171 * @param type the type the converter should create
172 * @since 1.3.1
173 */
174 SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type);
175 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15
16 public abstract class MapperWrapper implements Mapper {
17
18 private final Mapper wrapped;
19
20 public MapperWrapper(Mapper wrapped) {
21 this.wrapped = wrapped;
22 }
23
24 public String serializedClass(Class type) {
25 return wrapped.serializedClass(type);
26 }
27
28 public Class realClass(String elementName) {
29 return wrapped.realClass(elementName);
30 }
31
32 public String serializedMember(Class type, String memberName) {
33 return wrapped.serializedMember(type, memberName);
34 }
35
36 public String realMember(Class type, String serialized) {
37 return wrapped.realMember(type, serialized);
38 }
39
40 public boolean isImmutableValueType(Class type) {
41 return wrapped.isImmutableValueType(type);
42 }
43
44 public Class defaultImplementationOf(Class type) {
45 return wrapped.defaultImplementationOf(type);
46 }
47
48 public String aliasForAttribute(String attribute) {
49 return wrapped.aliasForAttribute(attribute);
50 }
51
52 public String attributeForAlias(String alias) {
53 return wrapped.attributeForAlias(alias);
54 }
55
56 public String aliasForSystemAttribute(String attribute) {
57 return wrapped.aliasForSystemAttribute(attribute);
58 }
59
60 public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName) {
61 return wrapped.getFieldNameForItemTypeAndName(definedIn, itemType, itemFieldName);
62 }
63
64 public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) {
65 return wrapped.getItemTypeForItemFieldName(definedIn, itemFieldName);
66 }
67
68 public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName) {
69 return wrapped.getImplicitCollectionDefForFieldName(itemType, fieldName);
70 }
71
72 public boolean shouldSerializeMember(Class definedIn, String fieldName) {
73 return wrapped.shouldSerializeMember(definedIn, fieldName);
74 }
75
76 /**
77 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
78 */
79 public SingleValueConverter getConverterFromItemType(String fieldName, Class type) {
80 return wrapped.getConverterFromItemType(fieldName, type);
81 }
82
83 /**
84 * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)}
85 */
86 public SingleValueConverter getConverterFromItemType(Class type) {
87 return wrapped.getConverterFromItemType(type);
88 }
89
90 /**
91 * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)}
92 */
93 public SingleValueConverter getConverterFromAttribute(String name) {
94 return wrapped.getConverterFromAttribute(name);
95 }
96
97 public Converter getLocalConverter(Class definedIn, String fieldName) {
98 return wrapped.getLocalConverter(definedIn, fieldName);
99 }
100
101 public Mapper lookupMapperOfType(Class type) {
102 return type.isAssignableFrom(getClass()) ? this : wrapped.lookupMapperOfType(type);
103 }
104
105 public SingleValueConverter getConverterFromItemType(String fieldName, Class type, Class definedIn) {
106 return wrapped.getConverterFromItemType(fieldName, type, definedIn);
107 }
108
109 /**
110 * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
111 */
112 public String aliasForAttribute(Class definedIn, String fieldName) {
113 return wrapped.aliasForAttribute(definedIn, fieldName);
114 }
115
116 /**
117 * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)}
118 */
119 public String attributeForAlias(Class definedIn, String alias) {
120 return wrapped.attributeForAlias(definedIn, alias);
121 }
122
123 /**
124 * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)}
125 */
126 public SingleValueConverter getConverterFromAttribute(Class type, String attribute) {
127 return wrapped.getConverterFromAttribute(type, attribute);
128 }
129
130 public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) {
131 return wrapped.getConverterFromAttribute(definedIn, attribute, type);
132 }
133
134 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 31. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 /**
14 * Mapper that uses a more meaningful alias for the field in an inner class (this$0) that refers to the outer class.
15 *
16 * @author Joe Walnes
17 */
18 public class OuterClassMapper extends MapperWrapper {
19
20 private final String alias;
21
22 public OuterClassMapper(Mapper wrapped) {
23 this(wrapped, "outer-class");
24 }
25
26 public OuterClassMapper(Mapper wrapped, String alias) {
27 super(wrapped);
28 this.alias = alias;
29 }
30
31 public String serializedMember(Class type, String memberName) {
32 if (memberName.equals("this$0")) {
33 return alias;
34 } else {
35 return super.serializedMember(type, memberName);
36 }
37 }
38
39 public String realMember(Class type, String serialized) {
40 if (serialized.equals(alias)) {
41 return "this$0";
42 } else {
43 return super.realMember(type, serialized);
44 }
45 }
46 }
0 /*
1 * Copyright (C) 2008 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 10. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.io.Serializable;
16 import java.util.Comparator;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.Map;
20 import java.util.TreeMap;
21
22
23 /**
24 * Mapper that allows a package name to be replaced with an alias.
25 *
26 * @author J&ouml;rg Schaible
27 */
28 public class PackageAliasingMapper extends MapperWrapper implements Serializable {
29
30 private static final Comparator REVERSE = new Comparator() {
31
32 public int compare(final Object o1, final Object o2) {
33 return ((String)o2).compareTo((String)o1);
34 }
35 };
36
37 private Map packageToName = new TreeMap(REVERSE);
38 protected transient Map nameToPackage = new HashMap();
39
40 public PackageAliasingMapper(final Mapper wrapped) {
41 super(wrapped);
42 }
43
44 public void addPackageAlias(String name, String pkg) {
45 if (name.length() > 0 && name.charAt(name.length() - 1) != '.') {
46 name += '.';
47 }
48 if (pkg.length() > 0 && pkg.charAt(pkg.length() - 1) != '.') {
49 pkg += '.';
50 }
51 nameToPackage.put(name, pkg);
52 packageToName.put(pkg, name);
53 }
54
55 public String serializedClass(final Class type) {
56 final String className = type.getName();
57 int length = className.length();
58 int dot = -1;
59 do {
60 dot = className.lastIndexOf('.', length);
61 final String pkg = dot < 0 ? "" : className.substring(0, dot + 1);
62 final String alias = (String)packageToName.get(pkg);
63 if (alias != null) {
64 return alias + (dot < 0 ? className : className.substring(dot + 1));
65 }
66 length = dot - 1;
67 } while (dot >= 0);
68 return super.serializedClass(type);
69 }
70
71 public Class realClass(String elementName) {
72 int length = elementName.length();
73 int dot = -1;
74 do {
75 dot = elementName.lastIndexOf('.', length);
76 final String name = dot < 0 ? "" : elementName.substring(0, dot) + '.';
77 final String packageName = (String)nameToPackage.get(name);
78
79 if (packageName != null) {
80 elementName = packageName
81 + (dot < 0 ? elementName : elementName.substring(dot + 1));
82 break;
83 }
84 length = dot - 1;
85 } while (dot >= 0);
86
87 return super.realClass(elementName);
88 }
89
90 private void writeObject(final ObjectOutputStream out) throws IOException {
91 out.writeObject(new HashMap(packageToName));
92 }
93
94 private void readObject(final ObjectInputStream in)
95 throws IOException, ClassNotFoundException {
96 packageToName = new TreeMap(REVERSE);
97 packageToName.putAll((Map)in.readObject());
98 nameToPackage = new HashMap();
99 for (final Iterator iter = packageToName.keySet().iterator(); iter.hasNext();) {
100 final Object type = iter.next();
101 nameToPackage.put(packageToName.get(type), type);
102 }
103 }
104 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 08. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.mapper;
7
8 import java.util.ArrayList;
9 import java.util.Arrays;
10 import java.util.List;
11
12 import com.thoughtworks.xstream.security.AnyTypePermission;
13 import com.thoughtworks.xstream.security.ForbiddenClassException;
14 import com.thoughtworks.xstream.security.NoTypePermission;
15 import com.thoughtworks.xstream.security.TypePermission;
16
17
18 /**
19 * A Mapper implementation injecting a security layer based on permission rules for any type required in the
20 * unmarshalling process.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4.7
24 */
25 public class SecurityMapper extends MapperWrapper {
26
27 private final List permissions;
28
29 /**
30 * Construct a SecurityMapper.
31 *
32 * @param wrapped the mapper chain
33 * @since 1.4.7
34 */
35 public SecurityMapper(final Mapper wrapped) {
36 this(wrapped, (TypePermission[])null);
37 }
38
39 /**
40 * Construct a SecurityMapper.
41 *
42 * @param wrapped the mapper chain
43 * @param permissions the predefined permissions
44 * @since 1.4.7
45 */
46 public SecurityMapper(final Mapper wrapped, final TypePermission[] permissions) {
47 super(wrapped);
48 this.permissions = permissions == null //
49 ? new ArrayList()
50 : new ArrayList(Arrays.asList(permissions));
51 }
52
53 /**
54 * Add a new permission.
55 * <p>
56 * Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or
57 * {@link AnyTypePermission} will implicitly wipe any existing permission.
58 * </p>
59 *
60 * @param permission the permission to add.
61 * @since 1.4.7
62 */
63 public void addPermission(final TypePermission permission) {
64 if (permission.equals(NoTypePermission.NONE) || permission.equals(AnyTypePermission.ANY))
65 permissions.clear();
66 permissions.add(0, permission);
67 }
68
69 public Class realClass(final String elementName) {
70 final Class type = super.realClass(elementName);
71 for (int i = 0; i < permissions.size(); ++i) {
72 final TypePermission permission = (TypePermission)permissions.get(i);
73 if (permission.allows(type))
74 return type;
75 }
76 throw new ForbiddenClassException(type);
77 }
78 }
0 /*
1 * Copyright (C) 2008 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 09. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12
13 /**
14 * Mapper that allows aliasing of system attribute names.
15 *
16 * @author J&ouml;rg Schaible
17 * @since 1.3.1
18 */
19 public class SystemAttributeAliasingMapper extends AbstractAttributeAliasingMapper {
20
21 public SystemAttributeAliasingMapper(Mapper wrapped) {
22 super(wrapped);
23 }
24
25 public String aliasForSystemAttribute(String attribute) {
26 String alias = (String)nameToAlias.get(attribute);
27 if (alias == null && !nameToAlias.containsKey(attribute)) {
28 alias = super.aliasForSystemAttribute(attribute);
29 if (alias == attribute) {
30 alias = super.aliasForAttribute(attribute);
31 }
32 }
33 return alias;
34 }
35 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. May 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.mapper;
12
13
14 /**
15 * Mapper that ensures that all names in the serialization stream are read in an XML friendly way.
16 * <ul>
17 * <li><b>_</b> (underscore) chars appearing in class names are replaced with <b>$</b> (dollar)</li>
18 * <li><b>_DOLLAR_</b> string appearing in field names are replaced with <b>$</b> (dollar)</li>
19 * <li><b>__</b> string appearing in field names are replaced with <b>_</b> (underscore)</li>
20 * <li><b>default</b> is the prefix for class names with no package.</li>
21 * </ul>
22 *
23 * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward compatibility
24 * to existing XML data written with older XStream versions (&lt;= 1.1).
25 *
26 * @author Joe Walnes
27 * @author Mauro Talevi
28 * @deprecated As of 1.4 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
29 */
30 public class XStream11XmlFriendlyMapper extends AbstractXmlFriendlyMapper {
31
32 public XStream11XmlFriendlyMapper(Mapper wrapped) {
33 super(wrapped);
34 }
35
36 public Class realClass(String elementName) {
37 return super.realClass(unescapeClassName(elementName));
38 }
39
40 public String realMember(Class type, String serialized) {
41 return unescapeFieldName(super.realMember(type, serialized));
42 }
43
44 public String mapNameFromXML(String xmlName) {
45 return unescapeFieldName(xmlName);
46 }
47 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 22. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 /**
14 * Mapper that ensures that all names in the serialization stream are XML friendly.
15 * The replacement chars and strings are:
16 * <ul>
17 * <li><b>$</b> (dollar) chars appearing in class names are replaced with <b>_</b> (underscore) chars.<br></li>
18 * <li><b>$</b> (dollar) chars appearing in field names are replaced with <b>_DOLLAR_</b> string.<br></li>
19 * <li><b>_</b> (underscore) chars appearing in field names are replaced with <b>__</b> (double underscore) string.<br></li>
20 * <li><b>default</b> as the prefix for class names with no package.</li>
21 * </ul>
22 *
23 * @author Joe Walnes
24 * @author Mauro Talevi
25 * @deprecated As of 1.3 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
26 */
27 public class XmlFriendlyMapper extends AbstractXmlFriendlyMapper {
28
29 /**
30 * @deprecated As of 1.3 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader}
31 */
32 public XmlFriendlyMapper(Mapper wrapped) {
33 super(wrapped);
34 }
35
36 public String serializedClass(Class type) {
37 return escapeClassName(super.serializedClass(type));
38 }
39
40 public Class realClass(String elementName) {
41 return super.realClass(unescapeClassName(elementName));
42 }
43
44 public String serializedMember(Class type, String memberName) {
45 return escapeFieldName(super.serializedMember(type, memberName));
46 }
47
48 public String realMember(Class type, String serialized) {
49 return unescapeFieldName(super.realMember(type, serialized));
50 }
51
52 public String mapNameToXML(String javaName) {
53 return escapeFieldName(javaName);
54 }
55
56 public String mapNameFromXML(String xmlName) {
57 return unescapeFieldName(xmlName);
58 }
59
60 }
0 /*
1 * Copyright (C) 2008 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 18. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.persistence;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.ConverterLookup;
14 import com.thoughtworks.xstream.io.StreamException;
15 import com.thoughtworks.xstream.mapper.Mapper;
16
17 import java.io.File;
18 import java.io.FileInputStream;
19 import java.io.FileNotFoundException;
20 import java.io.FileOutputStream;
21 import java.io.FilenameFilter;
22 import java.io.IOException;
23 import java.io.InputStreamReader;
24 import java.io.OutputStreamWriter;
25 import java.io.Reader;
26 import java.io.Writer;
27 import java.util.Iterator;
28 import java.util.Map;
29 import java.util.Map.Entry;
30
31
32 /**
33 * Abstract base class for file based persistence strategies.
34 *
35 * @author Guilherme Silveira
36 * @author Joerg Schaible
37 * @since 1.3.1
38 */
39 public abstract class AbstractFilePersistenceStrategy implements PersistenceStrategy {
40
41 private final FilenameFilter filter;
42 private final File baseDirectory;
43 private final String encoding;
44 private final transient XStream xstream;
45
46 public AbstractFilePersistenceStrategy(
47 final File baseDirectory, final XStream xstream, final String encoding) {
48 this.baseDirectory = baseDirectory;
49 this.xstream = xstream;
50 this.encoding = encoding;
51 filter = new ValidFilenameFilter();
52 }
53
54 protected ConverterLookup getConverterLookup() {
55 return xstream.getConverterLookup();
56 }
57
58 protected Mapper getMapper() {
59 return xstream.getMapper();
60 }
61
62 protected boolean isValid(final File dir, final String name) {
63 return name.endsWith(".xml");
64 }
65
66 /**
67 * Given a filename, the unescape method returns the key which originated it.
68 *
69 * @param name the filename
70 * @return the original key
71 */
72 protected abstract Object extractKey(String name);
73
74 /**
75 * Given a key, the escape method returns the filename which shall be used.
76 *
77 * @param key the key
78 * @return the desired and escaped filename
79 */
80 protected abstract String getName(Object key);
81
82 protected class ValidFilenameFilter implements FilenameFilter {
83 public boolean accept(final File dir, final String name) {
84 return new File(dir, name).isFile() && isValid(dir, name);
85 }
86 }
87
88 protected class XmlMapEntriesIterator implements Iterator {
89
90 private final File[] files = baseDirectory.listFiles(filter);
91
92 private int position = -1;
93
94 private File current = null;
95
96 public boolean hasNext() {
97 return position + 1 < files.length;
98 }
99
100 public void remove() {
101 if (current == null) {
102 throw new IllegalStateException();
103 }
104 // removes without loading
105 current.delete();
106 }
107
108 public Object next() {
109 return new Map.Entry() {
110 private final File file = current = files[ ++position];
111 private final Object key = extractKey(file.getName());
112
113 public Object getKey() {
114 return key;
115 }
116
117 public Object getValue() {
118 return readFile(file);
119 }
120
121 public Object setValue(final Object value) {
122 return put(key, value);
123 }
124
125 public boolean equals(final Object obj) {
126 if (!(obj instanceof Entry)) {
127 return false;
128 }
129 Object value = getValue();
130 final Entry e2 = (Entry)obj;
131 Object key2 = e2.getKey();
132 Object value2 = e2.getValue();
133 return (key == null ? key2 == null : key.equals(key2))
134 && (value == null ? value2 == null : getValue().equals(e2.getValue()));
135 }
136 };
137 }
138 }
139
140 private void writeFile(final File file, final Object value) {
141 try {
142 final FileOutputStream out = new FileOutputStream(file);
143 final Writer writer = encoding != null
144 ? new OutputStreamWriter(out, encoding)
145 : new OutputStreamWriter(out);
146 try {
147 xstream.toXML(value, writer);
148 } finally {
149 writer.close();
150 }
151 } catch (final IOException e) {
152 throw new StreamException(e);
153 }
154 }
155
156 private File getFile(final String filename) {
157 return new File(baseDirectory, filename);
158 }
159
160 private Object readFile(final File file) {
161 try {
162 final FileInputStream in = new FileInputStream(file);
163 final Reader reader = encoding != null
164 ? new InputStreamReader(in, encoding)
165 : new InputStreamReader(in);
166 try {
167 return xstream.fromXML(reader);
168 } finally {
169 reader.close();
170 }
171 } catch (final FileNotFoundException e) {
172 // not found... file.exists might generate a sync problem
173 return null;
174 } catch (final IOException e) {
175 throw new StreamException(e);
176 }
177 }
178
179 public Object put(final Object key, final Object value) {
180 final Object oldValue = get(key);
181 final String filename = getName(key);
182 writeFile(new File(baseDirectory, filename), value);
183 return oldValue;
184 }
185
186 public Iterator iterator() {
187 return new XmlMapEntriesIterator();
188 }
189
190 public int size() {
191 return baseDirectory.list(filter).length;
192 }
193
194 public boolean containsKey(final Object key) {
195 // faster lookup
196 final File file = getFile(getName(key));
197 return file.isFile();
198 }
199
200 public Object get(final Object key) {
201 return readFile(getFile(getName(key)));
202 }
203
204 public Object remove(final Object key) {
205 // faster lookup
206 final File file = getFile(getName(key));
207 Object value = null;
208 if (file.isFile()) {
209 value = readFile(file);
210 file.delete();
211 }
212 return value;
213 }
214
215 }
0 /*
1 * Copyright (C) 2008 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 20. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.persistence;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15 import com.thoughtworks.xstream.io.StreamException;
16 import com.thoughtworks.xstream.io.xml.DomDriver;
17
18 import java.io.File;
19
20
21 /**
22 * PersistenceStrategy to assign keys with single value to objects persisted in files. The
23 * default naming strategy is based on the key's type and its {@link SingleValueConverter}. It
24 * escapes all characters that are normally illegal in the most common file systems. Such a
25 * character is escaped with percent escaping as it is done by URL encoding. The XStream used to
26 * marshal the values is also requested for the key's SingleValueConverter. A
27 * {@link StreamException} is thrown if no such converter is registered.
28 *
29 * @author J&ouml;rg Schaible
30 * @author Guilherme Silveira
31 * @since 1.3.1
32 */
33 public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy {
34
35 private final String illegalChars;
36
37 /**
38 * Create a new FilePersistenceStrategy. Use a standard XStream instance with a
39 * {@link DomDriver}.
40 *
41 * @param baseDirectory the directory for the serialized values
42 * @since 1.3.1
43 */
44 public FilePersistenceStrategy(final File baseDirectory) {
45 this(baseDirectory, new XStream(new DomDriver()));
46 }
47
48 /**
49 * Create a new FilePersistenceStrategy with a provided XStream instance.
50 *
51 * @param baseDirectory the directory for the serialized values
52 * @param xstream the XStream instance to use for (de)serialization
53 * @since 1.3.1
54 */
55 public FilePersistenceStrategy(final File baseDirectory, final XStream xstream) {
56 this(baseDirectory, xstream, "utf-8", "<>?:/\\\"|*%");
57 }
58
59 /**
60 * Create a new FilePersistenceStrategy with a provided XStream instance and the characters
61 * to encode.
62 *
63 * @param baseDirectory the directory for the serialized values
64 * @param xstream the XStream instance to use for (de)serialization
65 * @param encoding encoding used to write the files
66 * @param illegalChars illegal characters for file names (should always include '%' as long
67 * as you do not overwrite the (un)escape methods)
68 * @since 1.3.1
69 */
70 public FilePersistenceStrategy(
71 final File baseDirectory, final XStream xstream, final String encoding,
72 final String illegalChars) {
73 super(baseDirectory, xstream, encoding);
74 this.illegalChars = illegalChars;
75 }
76
77 protected boolean isValid(final File dir, final String name) {
78 return super.isValid(dir, name) && name.indexOf('@') > 0;
79 }
80
81 /**
82 * Given a filename, the unescape method returns the key which originated it.
83 *
84 * @param name the filename
85 * @return the original key
86 */
87 protected Object extractKey(final String name) {
88 final String key = unescape(name.substring(0, name.length() - 4));
89 if ("null@null".equals(key)) {
90 return null;
91 }
92 int idx = key.indexOf('@');
93 if (idx < 0) {
94 throw new StreamException("Not a valid key: " + key);
95 }
96 Class type = getMapper().realClass(key.substring(0, idx));
97 Converter converter = getConverterLookup().lookupConverterForType(type);
98 if (converter instanceof SingleValueConverter) {
99 final SingleValueConverter svConverter = (SingleValueConverter)converter;
100 return svConverter.fromString(key.substring(idx + 1));
101 } else {
102 throw new StreamException("No SingleValueConverter for type "
103 + type.getName()
104 + " available");
105 }
106 }
107
108 protected String unescape(String name) {
109 final StringBuffer buffer = new StringBuffer();
110 for (int idx = name.indexOf('%'); idx >= 0; idx = name.indexOf('%')) {
111 buffer.append(name.substring(0, idx));
112 int c = Integer.parseInt(name.substring(idx + 1, idx + 3), 16);
113 buffer.append((char)c);
114 name = name.substring(idx + 3);
115 }
116 buffer.append(name);
117 return buffer.toString();
118 }
119
120 /**
121 * Given a key, the escape method returns the filename which shall be used.
122 *
123 * @param key the key
124 * @return the desired and escaped filename
125 */
126 protected String getName(final Object key) {
127 if (key == null) {
128 return "null@null.xml";
129 }
130 Class type = key.getClass();
131 Converter converter = getConverterLookup().lookupConverterForType(type);
132 if (converter instanceof SingleValueConverter) {
133 final SingleValueConverter svConverter = (SingleValueConverter)converter;
134 return getMapper().serializedClass(type)
135 + '@'
136 + escape(svConverter.toString(key))
137 + ".xml";
138 } else {
139 throw new StreamException("No SingleValueConverter for type "
140 + type.getName()
141 + " available");
142 }
143 }
144
145 protected String escape(final String key) {
146 final StringBuffer buffer = new StringBuffer();
147 final char[] array = key.toCharArray();
148 for (int i = 0; i < array.length; i++ ) {
149 final char c = array[i];
150 if (c >= ' ' && illegalChars.indexOf(c) < 0) {
151 buffer.append(c);
152 } else {
153 buffer.append("%" + Integer.toHexString(c).toUpperCase());
154 }
155 }
156 return buffer.toString();
157 }
158 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008, 2009 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 13. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import java.io.File;
16
17
18 /**
19 * PersistenceStrategy to assign string based keys to objects persisted in files. The file
20 * naming strategy is based on the key's type name and its toString method. It escapes non
21 * digit, non a-z and A-Z characters. In order to change the escaping/unescaping algorithm,
22 * simply extend this class and rewrite its getName/extractKey methods. Note, this
23 * implementation silently implies that the keys actually are Strings, since the keys will be
24 * turned into string keys at deserialization time.
25 *
26 * @author Guilherme Silveira
27 * @deprecated As of 1.3.1, use FilePersistenceStrategy
28 */
29 public class FileStreamStrategy extends AbstractFilePersistenceStrategy implements
30 StreamStrategy {
31 public FileStreamStrategy(final File baseDirectory) {
32 this(baseDirectory, new XStream());
33 }
34
35 public FileStreamStrategy(final File baseDirectory, final XStream xstream) {
36 super(baseDirectory, xstream, null);
37 }
38
39 /**
40 * Given a filename, the unescape method returns the key which originated it.
41 *
42 * @param name the filename
43 * @return the original key
44 */
45 protected Object extractKey(final String name) {
46 final String key = unescape(name.substring(0, name.length() - 4));
47 return key.equals("\0") ? null : key;
48 }
49
50 protected String unescape(final String name) {
51 final StringBuffer buffer = new StringBuffer();
52 char lastC = '\uffff';
53 int currentValue = -1;
54 // do we have a regex master to do it?
55 final char[] array = name.toCharArray();
56 for (int i = 0; i < array.length; i++ ) {
57 final char c = array[i];
58 if (c == '_' && currentValue != -1) {
59 if (lastC == '_') {
60 buffer.append('_');
61 } else {
62 buffer.append((char)currentValue);
63 }
64 currentValue = -1;
65 } else if (c == '_') {
66 currentValue = 0;
67 } else if (currentValue != -1) {
68 currentValue = currentValue * 16 + Integer.parseInt(String.valueOf(c), 16);
69 } else {
70 buffer.append(c);
71 }
72 lastC = c;
73 }
74 return buffer.toString();
75 }
76
77 /**
78 * Given a key, the escape method returns the filename which shall be used.
79 *
80 * @param key the key
81 * @return the desired and escaped filename
82 */
83 protected String getName(final Object key) {
84 return escape(key == null ? "\0" : key.toString()) + ".xml";
85 }
86
87 protected String escape(final String key) {
88 // do we have a regex master to do it?
89 final StringBuffer buffer = new StringBuffer();
90 final char[] array = key.toCharArray();
91 for (int i = 0; i < array.length; i++ ) {
92 final char c = array[i];
93 if (Character.isDigit(c) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
94 buffer.append(c);
95 } else if (c == '_') {
96 buffer.append("__");
97 } else {
98 buffer.append("_" + (Integer.toHexString(c)) + "_");
99 }
100 }
101 return buffer.toString();
102 }
103 }
0 /*
1 * Copyright (C) 2008 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 20. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.persistence;
11
12 import java.util.Iterator;
13
14
15 /**
16 * A key to a persistent storage and vice-versa strategy interface.
17 *
18 * @author Guilherme Silveira
19 * @since 1.3.1
20 */
21 public interface PersistenceStrategy {
22
23 Iterator iterator();
24
25 int size();
26
27 Object get(Object key);
28
29 Object put(Object key, Object value);
30
31 Object remove(Object key);
32
33 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008, 2009 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 13. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 /**
14 * A key to filename and vice-versa strategy interface.
15 *
16 * @author Guilherme Silveira
17 * @deprecated As of 1.3.1, use {@link PersistenceStrategy} instead
18 */
19 public interface StreamStrategy extends PersistenceStrategy {
20 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008 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 06. July 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.AbstractList;
14
15 /**
16 * A persistent list implementation backed on a XmlMap.
17 *
18 * @author Guilherme Silveira
19 */
20 public class XmlArrayList extends AbstractList {
21
22 private final XmlMap map;
23
24 public XmlArrayList(PersistenceStrategy persistenceStrategy) {
25 this.map = new XmlMap(persistenceStrategy);
26 }
27
28 public int size() {
29 return map.size();
30 }
31
32 public Object set(int index, Object element) {
33 rangeCheck(index);
34 Object value = get(index);
35 map.put(new Integer(index), element);
36 return value;
37 }
38
39 public void add(int index, Object element) {
40 int size = size();
41 if (index >= (size + 1) || index < 0) {
42 throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
43 + size);
44 }
45 int to = index != size ? index - 1 : index;
46 for (int i = size; i > to; i--) {
47 map.put(new Integer(i + 1), map.get(new Integer(i)));
48 }
49 map.put(new Integer(index), element);
50 }
51
52 private void rangeCheck(int index) {
53 int size = size();
54 if (index >= size || index < 0) {
55 throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
56 + size);
57 }
58 }
59
60 public Object get(int index) {
61 rangeCheck(index);
62 return map.get(new Integer(index));
63 }
64
65 public Object remove(int index) {
66 int size = size();
67 rangeCheck(index);
68 Object value = map.get(new Integer(index));
69 for (int i = index; i < size - 1; i++) {
70 map.put(new Integer(i), map.get(new Integer(i + 1)));
71 }
72 map.remove(new Integer(size - 1));
73 return value;
74 }
75
76 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008 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 13. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.AbstractMap;
14 import java.util.AbstractSet;
15 import java.util.Iterator;
16 import java.util.Set;
17
18 /**
19 * A persistent map. Its values are actually serialized as xml files. If you
20 * need an application-wide synchronized version of this map, try the respective
21 * Collections methods.
22 *
23 * @author Guilherme Silveira
24 */
25 public class XmlMap extends AbstractMap {
26
27 private final PersistenceStrategy persistenceStrategy;
28
29 public XmlMap(PersistenceStrategy streamStrategy) {
30 this.persistenceStrategy = streamStrategy;
31 }
32
33 public int size() {
34 return persistenceStrategy.size();
35 }
36
37 public Object get(Object key) {
38 // faster lookup
39 return persistenceStrategy.get(key);
40 }
41
42 public Object put(Object key, Object value) {
43 return persistenceStrategy.put(key,value);
44 }
45
46 public Object remove(Object key) {
47 return persistenceStrategy.remove(key);
48 }
49
50 public Set entrySet() {
51 return new XmlMapEntries();
52 }
53
54 class XmlMapEntries extends AbstractSet {
55
56 public int size() {
57 return XmlMap.this.size();
58 }
59
60 public boolean isEmpty() {
61 return XmlMap.this.isEmpty();
62 }
63
64 public Iterator iterator() {
65 return persistenceStrategy.iterator();
66 }
67
68 }
69
70 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008 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 28. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.AbstractSet;
14 import java.util.Iterator;
15
16 /**
17 * A persistent set implementation.
18 *
19 * @author Guilherme Silveira
20 */
21 public class XmlSet extends AbstractSet {
22
23 private final XmlMap map;
24
25 public XmlSet(PersistenceStrategy persistenceStrategy) {
26 this.map = new XmlMap(persistenceStrategy);
27 }
28
29 public Iterator iterator() {
30 return map.values().iterator();
31 }
32
33 public int size() {
34 return map.size();
35 }
36
37 public boolean add(Object o) {
38 if (map.containsValue(o)) {
39 return false;
40 } else {
41 // not-synchronized!
42 map.put(findEmptyKey(), o);
43 return true;
44 }
45 }
46
47 private Long findEmptyKey() {
48 long i = System.currentTimeMillis();
49 while (map.containsKey(new Long(i))) {
50 i++;
51 }
52 return new Long(i);
53 }
54
55 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 08. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Permission for any type and <code>null</code>.
10 *
11 * @author J&ouml;rg Schaible
12 * @since 1.4.7
13 */
14 public class AnyTypePermission implements TypePermission {
15 /**
16 * @since 1.4.7
17 */
18 public static final TypePermission ANY = new AnyTypePermission();
19
20 public boolean allows(Class type) {
21 return true;
22 }
23
24 public int hashCode() {
25 return 3;
26 }
27
28 public boolean equals(Object obj) {
29 return obj != null && obj.getClass() == AnyTypePermission.class;
30 }
31 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Permission for any array type.
10 *
11 * @author J&ouml;rg Schaible
12 * @since 1.4.7
13 */
14 public class ArrayTypePermission implements TypePermission {
15 /**
16 * @since 1.4.7
17 */
18 public static final TypePermission ARRAYS = new ArrayTypePermission();
19
20 public boolean allows(Class type) {
21 return type != null && type.isArray();
22 }
23
24 public int hashCode() {
25 return 13;
26 }
27
28 public boolean equals(Object obj) {
29 return obj != null && obj.getClass() == ArrayTypePermission.class;
30 }
31 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 19. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import net.sf.cglib.proxy.Proxy;
9
10
11 /**
12 * Permission for any array type.
13 *
14 * @author J&ouml;rg Schaible
15 * @since 1.4.7
16 */
17 public class CGLIBProxyTypePermission implements TypePermission {
18 /**
19 * @since 1.4.7
20 */
21 public static final TypePermission PROXIES = new CGLIBProxyTypePermission();
22
23 public boolean allows(final Class type) {
24 return type != null && type != Object.class && !type.isInterface()
25 && (Proxy.isProxyClass(type) || type.getName().startsWith(Proxy.class.getPackage().getName() + "."));
26 }
27
28 public int hashCode() {
29 return 19;
30 }
31
32 public boolean equals(final Object obj) {
33 return obj != null && obj.getClass() == CGLIBProxyTypePermission.class;
34 }
35 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.HashSet;
11 import java.util.Set;
12
13
14 /**
15 * Explicit permission for a type with a name matching one in the provided list.
16 *
17 * @author J&ouml;rg Schaible
18 * @since 1.4.7
19 */
20 public class ExplicitTypePermission implements TypePermission {
21
22 final Set names;
23
24 /**
25 * @since 1.4.7
26 */
27 public ExplicitTypePermission(final Class[] types) {
28 this(new Object() {
29 public String[] getNames() {
30 if (types == null)
31 return null;
32 String[] names = new String[types.length];
33 for (int i = 0; i < types.length; ++i)
34 names[i] = types[i].getName();
35 return names;
36 }
37 }.getNames());
38 }
39
40 /**
41 * @since 1.4.7
42 */
43 public ExplicitTypePermission(String[] names) {
44 this.names = names == null ? Collections.EMPTY_SET : new HashSet(Arrays.asList(names));
45 }
46
47 public boolean allows(Class type) {
48 if (type == null)
49 return false;
50 return names.contains(type.getName());
51 }
52
53 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 08. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import com.thoughtworks.xstream.XStreamException;
9
10 /**
11 * Exception thrown for a forbidden class.
12 *
13 * @author J&ouml;rg Schaible
14 * @since 1.4.7
15 */
16 public class ForbiddenClassException extends XStreamException {
17
18 /**
19 * Construct a ForbiddenClassException.
20 * @param type the forbidden class
21 * @since 1.4.7
22 */
23 public ForbiddenClassException(Class type) {
24 super(type == null ? "null" : type.getName());
25 }
26 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 27. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Permission for any interface type.
10 *
11 * @author J&ouml;rg Schaible
12 * @since 1.4.7
13 */
14 public class InterfaceTypePermission implements TypePermission {
15 /**
16 * @since 1.4.7
17 */
18 public static final TypePermission INTERFACES = new InterfaceTypePermission();
19
20 public boolean allows(Class type) {
21 return type != null && type.isInterface();
22 }
23
24 public int hashCode() {
25 return 31;
26 }
27
28 public boolean equals(Object obj) {
29 return obj != null && obj.getClass() == InterfaceTypePermission.class;
30 }
31
32 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Wrapper to negate another type permission.
10 * <p>
11 * If the wrapped {@link TypePermission} allows the type, this instance will throw a {@link ForbiddenClassException}
12 * instead. An instance of this permission cannot be used to allow a type.
13 * </p>
14 *
15 * @author J&ouml;rg Schaible
16 * @since 1.4.7
17 */
18 public class NoPermission implements TypePermission {
19
20 private final TypePermission permission;
21
22 /**
23 * Construct a NoPermission.
24 *
25 * @param permission the permission to negate or <code>null</code> to forbid any type
26 * @since 1.4.7
27 */
28 public NoPermission(final TypePermission permission) {
29 this.permission = permission;
30 }
31
32 public boolean allows(final Class type) {
33 if (permission == null || permission.allows(type)) {
34 throw new ForbiddenClassException(type);
35 }
36 return false;
37 }
38 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 08. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * No permission for any type.
10 * <p>
11 * Can be used to skip any existing default permission.
12 * </p>
13 *
14 * @author J&ouml;rg Schaible
15 * @since 1.4.7
16 */
17 public class NoTypePermission implements TypePermission {
18
19 /**
20 * @since 1.4.7
21 */
22 public static final TypePermission NONE = new NoTypePermission();
23
24 public boolean allows(Class type) {
25 throw new ForbiddenClassException(type);
26 }
27
28 public int hashCode() {
29 return 1;
30 }
31
32 public boolean equals(Object obj) {
33 return obj != null && obj.getClass() == NoTypePermission.class;
34 }
35 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import com.thoughtworks.xstream.mapper.Mapper;
9
10 /**
11 * Permission for <code>null</code> or XStream's null replacement type.
12 *
13 * @author J&ouml;rg Schaible
14 * @since 1.4.7
15 */
16 public class NullPermission implements TypePermission {
17 /**
18 * @since 1.4.7
19 */
20 public static final TypePermission NULL = new NullPermission();
21
22 public boolean allows(Class type) {
23 return type == null || type == Mapper.Null.class;
24 }
25 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import com.thoughtworks.xstream.core.util.Primitives;
9
10 /**
11 * Permission for any primitive type and its boxed counterpart (incl. void).
12 *
13 * @author J&ouml;rg Schaible
14 * @since 1.4.7
15 */
16 public class PrimitiveTypePermission implements TypePermission {
17 /**
18 * @since 1.4.7
19 */
20 public static final TypePermission PRIMITIVES = new PrimitiveTypePermission();
21
22 public boolean allows(Class type) {
23 return type != null && type.isPrimitive() || Primitives.isBoxed(type);
24 }
25
26 public int hashCode() {
27 return 7;
28 }
29
30 public boolean equals(Object obj) {
31 return obj != null && obj.getClass() == PrimitiveTypePermission.class;
32 }
33 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 19. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import java.lang.reflect.Proxy;
9
10 import com.thoughtworks.xstream.mapper.DynamicProxyMapper;
11
12
13 /**
14 * Permission for any array type.
15 *
16 * @author J&ouml;rg Schaible
17 * @since 1.4.7
18 */
19 public class ProxyTypePermission implements TypePermission {
20 /**
21 * @since 1.4.7
22 */
23 public static final TypePermission PROXIES = new ProxyTypePermission();
24
25 public boolean allows(final Class type) {
26 return type != null && (Proxy.isProxyClass(type) || type == DynamicProxyMapper.DynamicProxy.class);
27 }
28
29 public int hashCode() {
30 return 17;
31 }
32
33 public boolean equals(final Object obj) {
34 return obj != null && obj.getClass() == ProxyTypePermission.class;
35 }
36 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 import java.util.regex.Pattern;
9
10
11 /**
12 * Permission for any type with a name matching one of the provided regular expressions.
13 *
14 * @author J&ouml;rg Schaible
15 * @since 1.4.7
16 */
17 public class RegExpTypePermission implements TypePermission {
18
19 private final Pattern[] patterns;
20
21 public RegExpTypePermission(final String[] patterns) {
22 this(getPatterns(patterns));
23 }
24
25 public RegExpTypePermission(final Pattern[] patterns) {
26 this.patterns = patterns == null ? new Pattern[0] : patterns;
27 }
28
29 public boolean allows(final Class type) {
30 if (type != null) {
31 final String name = type.getName();
32 for (int i = 0; i < patterns.length; ++i)
33 if (patterns[i].matcher(name).matches())
34 return true;
35 }
36 return false;
37 }
38
39 private static Pattern[] getPatterns(final String[] patterns) {
40 if (patterns == null)
41 return null;
42 final Pattern[] array = new Pattern[patterns.length];
43 for (int i = 0; i < array.length; ++i)
44 array[i] = Pattern.compile(patterns[i]);
45 return array;
46 }
47 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 23. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Permission for a type hierarchy with a name matching one in the provided list.
10 *
11 * @author J&ouml;rg Schaible
12 * @since 1.4.7
13 */
14 public class TypeHierarchyPermission implements TypePermission {
15
16 private Class type;
17
18 /**
19 * @since 1.4.7
20 */
21 public TypeHierarchyPermission(Class type) {
22 this.type = type;
23 }
24
25 public boolean allows(Class type) {
26 if (type == null)
27 return false;
28 return this.type.isAssignableFrom(type);
29 }
30
31 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 08. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Definition of a type permission.
10 *
11 * @author J&ouml;rg Schaible
12 * @since 1.4.7
13 */
14 public interface TypePermission {
15 /**
16 * Check permission for a provided type.
17 *
18 * @param type the type to check
19 * @return <code>true</code> if provided type is allowed, <code>false</code> if permission does not handle the type
20 * @throws ForbiddenClassException if provided type is explicitly forbidden
21 * @since 1.4.7
22 */
23 boolean allows(Class type);
24 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.security;
7
8 /**
9 * Permission for any type with a name matching one of the provided wildcard expressions.
10 *
11 * <p>
12 * Supported are patterns with path expressions using dot as separator:
13 * </p>
14 * <ul>
15 * <li>?: one non-control character except separator, e.g. for 'java.net.Inet?Address'</li>
16 * <li>*: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'</li>
17 * <li>**: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'</li>
18 * </ul>
19 * <p>
20 * The complete range of UTF-8 characters is supported except control characters.
21 * </p>
22 *
23 * @author J&ouml;rg Schaible
24 * @since 1.4.7
25 */
26 public class WildcardTypePermission extends RegExpTypePermission {
27
28 /**
29 * @since 1.4.7
30 */
31 public WildcardTypePermission(final String[] patterns) {
32 super(getRegExpPatterns(patterns));
33 }
34
35 private static String[] getRegExpPatterns(final String[] wildcards) {
36 if (wildcards == null)
37 return null;
38 final String[] regexps = new String[wildcards.length];
39 for (int i = 0; i < wildcards.length; ++i) {
40 final String wildcardExpression = wildcards[i];
41 final StringBuffer result = new StringBuffer(wildcardExpression.length() * 2);
42 result.append("(?u)");
43 final int length = wildcardExpression.length();
44 for (int j = 0; j < length; j++) {
45 final char ch = wildcardExpression.charAt(j);
46 switch (ch) {
47 case '\\':
48 case '.':
49 case '+':
50 case '|':
51 case '[':
52 case ']':
53 case '(':
54 case ')':
55 case '^':
56 case '$':
57 result.append('\\').append(ch);
58 break;
59
60 case '?':
61 result.append('.');
62 break;
63
64 case '*':
65 // see "General Category Property" in http://www.unicode.org/reports/tr18/
66 if (j + 1 < length && wildcardExpression.charAt(j + 1) == '*') {
67 result.append("[\\P{C}]*");
68 j++;
69 } else {
70 result.append("[\\P{C}&&[^").append('.').append("]]*");
71 }
72 break;
73
74 default:
75 result.append(ch);
76 break;
77 }
78 }
79 regexps[i] = result.toString();
80 }
81 return regexps;
82 }
83 }
0 /*
1 * Copyright (C) 2013 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 22. February 2013 by Joerg Schaible
5 */
6
7 /**
8 * Dummy class in default package starting with dollar.
9 *
10 * <p>The Java compiler used to generate such class names for dynamic proxies.
11 * However, the Oracle/Sun compilers changed behavior with version 1.7.0.13 /
12 * 1.6.0.39 and its generated proxy classes are now in package com.sun.proxy.
13 * It is expected that other vendors will follow.</p>
14 */
15 public class $Package {
16 // empty
17 }
0 /*
1 * Copyright (C) 2006, 2007, 2009, 2010, 2011 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 30. July 2011 by Joerg Schaible by merging
9 * AbsolutSingleNodeXPathCircularReferenceTest, AbsolutSingleNodeXPathDuplicateReferenceTest
10 * and AbsolutSingleNodeXPathReplacedReferenceTest.
11 */
12 package com.thoughtworks.acceptance;
13
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.mapper.Mapper;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21 public class AbsoluteSingleNodeXPathReferenceTest extends AbstractReferenceTest {
22
23 // tests inherited from superclass
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);
28 }
29
30 public void testXmlContainsReferencePaths() {
31
32 Thing sameThing = new Thing("hello");
33 Thing anotherThing = new Thing("hello");
34
35 List list = new ArrayList();
36 list.add(sameThing);
37 list.add(sameThing);
38 list.add(anotherThing);
39
40 String expected = ""
41 + "<list>\n"
42 + " <thing>\n"
43 + " <field>hello</field>\n"
44 + " </thing>\n"
45 + " <thing reference=\"/list[1]/thing[1]\"/>\n"
46 + " <thing>\n"
47 + " <field>hello</field>\n"
48 + " </thing>\n"
49 + "</list>";
50
51 assertEquals(expected, xstream.toXML(list));
52 }
53
54 public void testCircularReferenceXml() {
55 Person bob = new Person("bob");
56 Person jane = new Person("jane");
57 bob.likes = jane;
58 jane.likes = bob;
59
60 String expected = ""
61 + "<person>\n"
62 + " <firstname>bob</firstname>\n"
63 + " <likes>\n"
64 + " <firstname>jane</firstname>\n"
65 + " <likes reference=\"/person[1]\"/>\n"
66 + " </likes>\n"
67 + "</person>";
68
69 assertEquals(expected, xstream.toXML(bob));
70 }
71
72 public void testCircularReferenceToSelfXml() {
73 Person bob = new Person("bob");
74 bob.likes = bob;
75
76 String expected = ""
77 + "<person>\n"
78 + " <firstname>bob</firstname>\n"
79 + " <likes reference=\"/person[1]\"/>\n"
80 + "</person>";
81
82 assertEquals(expected, xstream.toXML(bob));
83 }
84
85 public void testRing() {
86 LinkedElement tom = new LinkedElement("Tom");
87 LinkedElement dick = new LinkedElement("Dick");
88 LinkedElement harry = new LinkedElement("Harry");
89 tom.next = dick;
90 dick.next = harry;
91 harry.next = tom;
92
93 xstream.alias("elem", LinkedElement.class);
94 String expected = ""
95 + "<elem>\n"
96 + " <name>Tom</name>\n"
97 + " <next>\n"
98 + " <name>Dick</name>\n"
99 + " <next>\n"
100 + " <name>Harry</name>\n"
101 + " <next reference=\"/elem[1]\"/>\n"
102 + " </next>\n"
103 + " </next>\n"
104 + "</elem>";
105
106 assertEquals(expected, xstream.toXML(tom));
107 }
108
109 public void testTree() {
110 TreeElement root = new TreeElement("X");
111 TreeElement left = new TreeElement("Y");
112 TreeElement right = new TreeElement("Z");
113 root.left = left;
114 root.right = right;
115 left.left = new TreeElement(root.name);
116 right.right = new TreeElement(left.name);
117 right.left = left.left;
118
119 xstream.alias("elem", TreeElement.class);
120 String expected = ""
121 + "<elem>\n"
122 + " <name>X</name>\n"
123 + " <left>\n"
124 + " <name>Y</name>\n"
125 + " <left>\n"
126 + " <name reference=\"/elem[1]/name[1]\"/>\n"
127 + " </left>\n"
128 + " </left>\n"
129 + " <right>\n"
130 + " <name>Z</name>\n"
131 + " <left reference=\"/elem[1]/left[1]/left[1]\"/>\n"
132 + " <right>\n"
133 + " <name reference=\"/elem[1]/left[1]/name[1]\"/>\n"
134 + " </right>\n"
135 + " </right>\n"
136 + "</elem>";
137
138 assertEquals(expected, xstream.toXML(root));
139 }
140
141 public void testReplacedReference() {
142 String expectedXml = ""
143 + "<element>\n"
144 + " <data>parent</data>\n"
145 + " <children>\n"
146 + " <anonymous-element resolves-to=\"element\">\n"
147 + " <data>child</data>\n"
148 + " <parent reference=\"/element[1]\"/>\n"
149 + " <children/>\n"
150 + " </anonymous-element>\n"
151 + " </children>\n"
152 + "</element>";
153
154 replacedReference(expectedXml);
155 }
156
157 public void testCanReferenceDeserializedNullValues() {
158 xstream.alias("test", Mapper.Null.class);
159 String xml = ""
160 + "<list>\n"
161 + " <test/>\n"
162 + " <test reference=\"/list/test[1]\"/>\n"
163 + "</list>";
164 List list = (List)xstream.fromXML(xml);
165 assertEquals(2, list.size());
166 assertNull(list.get(0));
167 assertNull(list.get(1));
168 }
169
170 }
0 /*
1 * Copyright (C) 2006, 2007, 2009, 2010, 2011 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 30. July 2011 by Joerg Schaible by merging AbsolutXPathCircularReferenceTest,
9 * AbsolutXPathDuplicateReferenceTest, AbsolutXPathNestedCircularReferenceTest and
10 * AbsolutXPathReplacedReferenceTest.
11 */
12 package com.thoughtworks.acceptance;
13
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.mapper.Mapper;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21 public class AbsoluteXPathReferenceTest extends AbstractReferenceTest {
22
23 // tests inherited from superclass
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
28 }
29
30 public void testXmlContainsReferencePaths() {
31
32 Thing sameThing = new Thing("hello");
33 Thing anotherThing = new Thing("hello");
34
35 List list = new ArrayList();
36 list.add(sameThing);
37 list.add(sameThing);
38 list.add(anotherThing);
39
40 String expected = ""
41 + "<list>\n"
42 + " <thing>\n"
43 + " <field>hello</field>\n"
44 + " </thing>\n"
45 + " <thing reference=\"/list/thing\"/>\n"
46 + " <thing>\n"
47 + " <field>hello</field>\n"
48 + " </thing>\n"
49 + "</list>";
50
51 assertEquals(expected, xstream.toXML(list));
52 }
53
54 public void testCircularReferenceXml() {
55 Person bob = new Person("bob");
56 Person jane = new Person("jane");
57 bob.likes = jane;
58 jane.likes = bob;
59
60 String expected = ""
61 + "<person>\n"
62 + " <firstname>bob</firstname>\n"
63 + " <likes>\n"
64 + " <firstname>jane</firstname>\n"
65 + " <likes reference=\"/person\"/>\n"
66 + " </likes>\n"
67 + "</person>";
68
69 assertEquals(expected, xstream.toXML(bob));
70 }
71
72 public void testCircularReferenceToSelfXml() {
73 Person bob = new Person("bob");
74 bob.likes = bob;
75
76 String expected = ""
77 + "<person>\n"
78 + " <firstname>bob</firstname>\n"
79 + " <likes reference=\"/person\"/>\n"
80 + "</person>";
81
82 assertEquals(expected, xstream.toXML(bob));
83 }
84
85 public void testRing() {
86 LinkedElement tom = new LinkedElement("Tom");
87 LinkedElement dick = new LinkedElement("Dick");
88 LinkedElement harry = new LinkedElement("Harry");
89 tom.next = dick;
90 dick.next = harry;
91 harry.next = tom;
92
93 xstream.alias("elem", LinkedElement.class);
94 String expected = ""
95 + "<elem>\n"
96 + " <name>Tom</name>\n"
97 + " <next>\n"
98 + " <name>Dick</name>\n"
99 + " <next>\n"
100 + " <name>Harry</name>\n"
101 + " <next reference=\"/elem\"/>\n"
102 + " </next>\n"
103 + " </next>\n"
104 + "</elem>";
105
106 assertEquals(expected, xstream.toXML(tom));
107 }
108
109 public void testTree() {
110 TreeElement root = new TreeElement("X");
111 TreeElement left = new TreeElement("Y");
112 TreeElement right = new TreeElement("Z");
113 root.left = left;
114 root.right = right;
115 left.left = new TreeElement(root.name);
116 right.right = new TreeElement(left.name);
117 right.left = left.left;
118
119 xstream.alias("elem", TreeElement.class);
120 String expected = ""
121 + "<elem>\n"
122 + " <name>X</name>\n"
123 + " <left>\n"
124 + " <name>Y</name>\n"
125 + " <left>\n"
126 + " <name reference=\"/elem/name\"/>\n"
127 + " </left>\n"
128 + " </left>\n"
129 + " <right>\n"
130 + " <name>Z</name>\n"
131 + " <left reference=\"/elem/left/left\"/>\n"
132 + " <right>\n"
133 + " <name reference=\"/elem/left/name\"/>\n"
134 + " </right>\n"
135 + " </right>\n"
136 + "</elem>";
137
138 assertEquals(expected, xstream.toXML(root));
139 }
140
141 public void testReplacedReference() {
142 String expectedXml = ""
143 + "<element>\n"
144 + " <data>parent</data>\n"
145 + " <children>\n"
146 + " <anonymous-element resolves-to=\"element\">\n"
147 + " <data>child</data>\n"
148 + " <parent reference=\"/element\"/>\n"
149 + " <children/>\n"
150 + " </anonymous-element>\n"
151 + " </children>\n"
152 + "</element>";
153
154 replacedReference(expectedXml);
155 }
156
157 public void testCanReferenceDeserializedNullValues() {
158 xstream.alias("test", Mapper.Null.class);
159 String xml = ""
160 + "<list>\n"
161 + " <test/>\n"
162 + " <test reference=\"/list/test\"/>\n"
163 + "</list>";
164 List list = (List)xstream.fromXML(xml);
165 assertEquals(2, list.size());
166 assertNull(list.get(0));
167 assertNull(list.get(1));
168 }
169
170 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2014 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.lang.reflect.AccessibleObject;
14 import java.lang.reflect.Array;
15 import java.net.URL;
16 import java.nio.charset.Charset;
17 import java.text.DecimalFormatSymbols;
18 import java.util.BitSet;
19 import java.util.Calendar;
20 import java.util.Collection;
21 import java.util.Currency;
22 import java.util.Date;
23 import java.util.Locale;
24 import java.util.Map;
25 import java.util.TimeZone;
26 import java.util.regex.Pattern;
27 import java.io.ByteArrayOutputStream;
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.StringReader;
31 import java.io.StringWriter;
32
33 import junit.framework.AssertionFailedError;
34 import junit.framework.TestCase;
35
36 import javax.xml.transform.Transformer;
37 import javax.xml.transform.TransformerException;
38 import javax.xml.transform.TransformerFactory;
39 import javax.xml.transform.stream.StreamResult;
40 import javax.xml.transform.stream.StreamSource;
41
42 import com.thoughtworks.xstream.XStream;
43 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
44 import com.thoughtworks.xstream.io.binary.BinaryStreamWriter;
45 import com.thoughtworks.xstream.io.binary.BinaryStreamReader;
46 import com.thoughtworks.xstream.io.xml.XppDriver;
47 import com.thoughtworks.xstream.security.ArrayTypePermission;
48 import com.thoughtworks.xstream.security.InterfaceTypePermission;
49 import com.thoughtworks.xstream.security.NoTypePermission;
50 import com.thoughtworks.xstream.security.NullPermission;
51 import com.thoughtworks.xstream.security.PrimitiveTypePermission;
52
53 public abstract class AbstractAcceptanceTest extends TestCase {
54
55 protected transient XStream xstream = createXStream();
56
57 protected XStream createXStream() {
58 XStream xstream = new XStream(createDriver());
59 setupSecurity(xstream);
60 return xstream;
61 }
62
63 protected HierarchicalStreamDriver createDriver() {
64 // if the system property is set, use it to load the driver
65 String driver = null;
66 try {
67 driver = System.getProperty("xstream.driver");
68 if (driver != null) {
69 System.out.println("Using driver: " + driver);
70 Class type = Class.forName(driver);
71 return (HierarchicalStreamDriver) type.newInstance();
72 }
73 }
74 catch (Exception e) {
75 throw new RuntimeException("Could not load driver: " + driver);
76 }
77 return new XppDriver();
78 }
79
80 protected void setupSecurity(XStream xstream) {
81 xstream.addPermission(NoTypePermission.NONE); // clear out defaults
82 xstream.addPermission(NullPermission.NULL);
83 xstream.addPermission(ArrayTypePermission.ARRAYS);
84 xstream.addPermission(InterfaceTypePermission.INTERFACES);
85 xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
86 xstream.allowTypeHierarchy(AccessibleObject.class);
87 xstream.allowTypeHierarchy(Calendar.class);
88 xstream.allowTypeHierarchy(Collection.class);
89 xstream.allowTypeHierarchy(Map.class);
90 xstream.allowTypeHierarchy(Map.Entry.class);
91 xstream.allowTypeHierarchy(Number.class);
92 xstream.allowTypeHierarchy(TimeZone.class);
93 xstream.allowTypeHierarchy(Throwable.class);
94 xstream.allowTypes(new Class[]{
95 BitSet.class, Charset.class, Class.class, Currency.class, Date.class, DecimalFormatSymbols.class,
96 File.class, Locale.class, Object.class, Pattern.class, StackTraceElement.class, String.class,
97 StringBuffer.class, URL.class});
98 xstream.allowTypesByWildcard(new String[]{
99 AbstractAcceptanceTest.class.getPackage().getName()+".*objects.**",
100 this.getClass().getName()+"$*"
101 });
102 }
103
104 protected Object assertBothWaysNormalized(Object root, String xml, final String match,
105 final String templateSelect, final String sortSelect) {
106 try {
107 // First, serialize the object to XML and check it matches the expected XML.
108 String resultXml = normalizedXML(
109 toXML(root), new String[]{match}, templateSelect, sortSelect);
110 assertEquals(
111 normalizedXML(xml, new String[]{match}, templateSelect, sortSelect), resultXml);
112
113 // Now deserialize the XML back into the object and check it equals the original
114 // object.
115 Object resultRoot = xstream.fromXML(resultXml);
116 assertObjectsEqual(root, resultRoot);
117
118 // While we're at it, let's check the binary serialization works...
119 assertBinarySerialization(root);
120
121 return resultRoot;
122
123 } catch (TransformerException e) {
124 throw new AssertionFailedError("Cannot normalize XML: " + e.getMessage());
125 // .initCause(e); ... still JDK 1.3
126 }
127 }
128
129 protected Object assertBothWays(Object root, String xml) {
130
131 // First, serialize the object to XML and check it matches the expected XML.
132 String resultXml = toXML(root);
133 assertEquals(xml, resultXml);
134
135 // Now deserialize the XML back into the object and check it equals the original object.
136 Object resultRoot = xstream.fromXML(resultXml);
137 assertObjectsEqual(root, resultRoot);
138
139 // While we're at it, let's check the binary serialization works...
140 assertBinarySerialization(root);
141
142 return resultRoot;
143 }
144
145 private void assertBinarySerialization(Object root) {
146 // Serialize as binary
147 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
148 xstream.marshal(root, new BinaryStreamWriter(outputStream));
149
150 // Deserialize the binary and check it equals the original object.
151 ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
152 Object binaryResult = xstream.unmarshal(new BinaryStreamReader(inputStream));
153 assertObjectsEqual(root, binaryResult);
154 }
155
156 protected Object assertWithAsymmetricalXml(Object root, String inXml, String outXml) {
157 String resultXml = toXML(root);
158 assertEquals(outXml, resultXml);
159 Object resultRoot = xstream.fromXML(inXml);
160 assertObjectsEqual(root, resultRoot);
161 return resultRoot;
162 }
163
164 /**
165 * Allow derived classes to decide how to turn the object into XML text
166 */
167 protected String toXML(Object root) {
168 return xstream.toXML(root);
169 }
170
171 /**
172 * More descriptive version of assertEquals
173 */
174 protected void assertObjectsEqual(Object expected, Object actual) {
175 if (expected == null) {
176 assertNull(actual);
177 } else {
178 assertNotNull("Should not be null", actual);
179 if (actual.getClass().isArray()) {
180 assertArrayEquals(expected, actual);
181 } else {
182 // assertEquals(expected.getClass(), actual.getClass());
183 if (!expected.equals(actual)) {
184 assertEquals("Object deserialization failed",
185 "DESERIALIZED OBJECT\n" + xstream.toXML(expected),
186 "DESERIALIZED OBJECT\n" + xstream.toXML(actual));
187 }
188 }
189 }
190 }
191
192 protected void assertArrayEquals(Object expected, Object actual) {
193 assertEquals(Array.getLength(expected), Array.getLength(actual));
194 for (int i = 0; i < Array.getLength(expected); i++) {
195 assertObjectsEqual(Array.get(expected, i), Array.get(actual, i));
196 }
197 }
198
199 protected void assertByteArrayEquals(byte expected[], byte actual[]) {
200 assertEquals(dumpBytes(expected), dumpBytes(actual));
201 }
202
203 private String dumpBytes(byte bytes[]) {
204 StringBuffer result = new StringBuffer();
205 for (int i = 0; i < bytes.length; i++) {
206 result.append(bytes[i]).append(' ');
207 if (bytes[i] < 100) result.append(' ');
208 if (bytes[i] < 10) result.append(' ');
209 if (bytes[i] >= 0) result.append(' ');
210 if (i % 16 == 15) result.append('\n');
211 }
212 return result.toString();
213 }
214
215 protected String normalizedXML(final String xml, final String[] matches,
216 final String templateSelect, final String sortSelect) throws TransformerException {
217 final StringBuffer match = new StringBuffer();
218 for (int i = 0; i < matches.length; i++) {
219 if (i > 0) {
220 match.append('|');
221 }
222 match.append(matches[i]);
223 }
224 final StringBuffer sort = new StringBuffer();
225 if (sortSelect != null) {
226 sort.append(" select=\"");
227 sort.append(sortSelect);
228 sort.append('"');
229 }
230
231 final TransformerFactory transformerFactory = TransformerFactory.newInstance();
232 final Transformer transformer = transformerFactory
233 .newTransformer(new StreamSource(
234 new StringReader(
235 ""
236 + "<?xml version=\"1.0\"?>\n"
237 + "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
238 + "<xsl:template match=\"" + match.toString() + "\">\n"
239 + " <xsl:copy>\n"
240 + " <xsl:apply-templates select=\"" + templateSelect + "\">\n"
241 + " <xsl:sort" + sort.toString() + "/>\n"
242 + " </xsl:apply-templates>\n"
243 + " </xsl:copy>\n"
244 + "</xsl:template>\n"
245 + "<xsl:template match=\"@*|node()\">\n"
246 + " <xsl:copy>\n"
247 + " <xsl:apply-templates select=\"@*|node()\"/>\n"
248 + " </xsl:copy>\n"
249 + "</xsl:template>\n"
250 + "</xsl:stylesheet>")));
251 final StringWriter writer = new StringWriter();
252 transformer
253 .transform(new StreamSource(new StringReader(xml)), new StreamResult(writer));
254 return writer.toString();
255 }
256 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2014 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 30. July 2011 by Joerg Schaible by merging AbstractCircularReferenceTest,
10 * AbstractDuplicateReferenceTest, AbstractNestedCircularReferenceTest and
11 * AbstractReplacedReferenceTest.
12 */
13 package com.thoughtworks.acceptance;
14
15 import java.io.IOException;
16 import java.io.ObjectInputStream;
17 import java.io.ObjectOutputStream;
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import com.thoughtworks.acceptance.objects.StandardObject;
23 import com.thoughtworks.acceptance.someobjects.WithNamedList;
24 import com.thoughtworks.xstream.converters.ConversionException;
25 import com.thoughtworks.xstream.core.AbstractReferenceMarshaller;
26
27
28 public abstract class AbstractReferenceTest extends AbstractAcceptanceTest {
29 protected void setUp() throws Exception {
30 super.setUp();
31 xstream.alias("person", Person.class);
32 xstream.alias("thing", Thing.class);
33 xstream.allowTypesByWildcard(new String[]{AbstractReferenceTest.class.getName()+"$*"});
34 }
35
36 public void testReferencesAreWorking() {
37
38 Thing sameThing = new Thing("hello");
39 Thing anotherThing = new Thing("hello");
40
41 List list = new ArrayList();
42 list.add(sameThing);
43 list.add(sameThing);
44 list.add(anotherThing);
45
46 String xml = xstream.toXML(list);
47 List result = (List)xstream.fromXML(xml);
48
49 assertEquals(list, result);
50 }
51
52 public void testReferencesAreTheSameObjectWhenDeserialized() {
53
54 Thing sameThing = new Thing("hello");
55 Thing anotherThing = new Thing("hello");
56
57 List list = new ArrayList();
58 list.add(sameThing);
59 list.add(sameThing);
60 list.add(anotherThing);
61
62 String xml = xstream.toXML(list);
63 List result = (List)xstream.fromXML(xml);
64
65 Thing t0 = (Thing)result.get(0);
66 Thing t1 = (Thing)result.get(1);
67 Thing t2 = (Thing)result.get(2);
68
69 t0.field = "bye";
70
71 assertEquals("bye", t0.field);
72 assertEquals("bye", t1.field);
73 assertEquals("hello", t2.field);
74
75 }
76
77 public static class Thing extends StandardObject {
78 public String field;
79
80 public Thing() {
81 }
82
83 public Thing(String field) {
84 this.field = field;
85 }
86 }
87
88 public static class MultRef {
89 public Object s1 = new Object();
90 public Object s2 = s1;
91 }
92
93 public void testMultipleReferencesToObjectsWithNoChildren() {
94 MultRef in = new MultRef();
95 assertSame(in.s1, in.s2);
96
97 String xml = xstream.toXML(in);
98 MultRef out = (MultRef)xstream.fromXML(xml);
99
100 assertSame(out.s1, out.s2);
101 }
102
103 public void testReferencesNotUsedForImmutableValueTypes() {
104 MultRef in = new MultRef();
105 in.s1 = new Integer(4);
106 in.s2 = in.s1;
107
108 String xml = xstream.toXML(in);
109 MultRef out = (MultRef)xstream.fromXML(xml);
110
111 assertEquals(out.s1, out.s2);
112 assertNotSame(out.s1, out.s2);
113 }
114
115 public void testReferencesUsedForMutableValueTypes() {
116 MultRef in = new MultRef();
117 in.s1 = new StringBuffer("hi");
118 in.s2 = in.s1;
119
120 String xml = xstream.toXML(in);
121 MultRef out = (MultRef)xstream.fromXML(xml);
122
123 StringBuffer buffer = (StringBuffer)out.s2;
124 buffer.append("bye");
125
126 assertEquals("hibye", out.s1.toString());
127 assertSame(out.s1, out.s2);
128 }
129
130 public void testReferencesToImplicitCollectionIsNotPossible() {
131 xstream.alias("strings", WithNamedList.class);
132 xstream.addImplicitCollection(WithNamedList.class, "things");
133 WithNamedList[] wls = new WithNamedList[]{
134 new WithNamedList("foo"), new WithNamedList("bar")};
135 wls[0].things.add("Hello");
136 wls[0].things.add("Daniel");
137 wls[1].things = wls[0].things;
138
139 try {
140 xstream.toXML(wls);
141 fail("Thrown "
142 + AbstractReferenceMarshaller.ReferencedImplicitElementException.class
143 .getName() + " expected");
144 } catch (final AbstractReferenceMarshaller.ReferencedImplicitElementException e) {
145 // OK
146 }
147 }
148
149 public void testReferencesToElementsOfImplicitCollectionIsPossible() {
150 xstream.alias("strings", WithNamedList.class);
151 xstream.addImplicitCollection(WithNamedList.class, "things");
152 WithNamedList[] wls = new WithNamedList[]{
153 new WithNamedList("foo"), new WithNamedList("bar")};
154 wls[0].things.add("Hello");
155 wls[0].things.add("Daniel");
156 wls[1].things.add(wls[0]);
157
158 String xml = xstream.toXML(wls);
159 WithNamedList[] out = (WithNamedList[])xstream.fromXML(xml);
160
161 assertSame(out[0], out[1].things.get(0));
162 }
163
164 public void testReferencesToElementsOfNthImplicitCollectionIsPossible() {
165 xstream.alias("strings", WithNamedList.class);
166 xstream.addImplicitCollection(WithNamedList.class, "things");
167 WithNamedList[] wls = new WithNamedList[]{
168 new WithNamedList("foo"), new WithNamedList("bar"), new WithNamedList("foobar")};
169 wls[1].things.add("Hello");
170 wls[1].things.add("Daniel");
171 wls[2].things.add(wls[1]);
172
173 String xml = xstream.toXML(wls);
174 WithNamedList[] out = (WithNamedList[])xstream.fromXML(xml);
175
176 assertSame(out[1], out[2].things.get(0));
177 }
178
179 public void testThrowsForInvalidReference() {
180 String xml = "" //
181 + "<list>\n"
182 + " <thing>\n"
183 + " <field>Hello</field>\n"
184 + " </thing>\n"
185 + " <thing reference=\"foo\">\n"
186 + "</list>";
187
188 try {
189 xstream.fromXML(xml);
190 fail("Thrown " + ConversionException.class.getName() + " expected");
191 } catch (final ConversionException e) {
192 assertEquals("foo", e.get("reference"));
193 }
194 }
195
196 public static class Person {
197 public String firstname;
198 public Person likes;
199 public Person loathes;
200
201 public Person() {
202 }
203
204 public Person(String name) {
205 this.firstname = name;
206 }
207 }
208
209 static class LinkedElement {
210 String name;
211 LinkedElement next;
212
213 LinkedElement(String name) {
214 this.name = name;
215 }
216 }
217
218 static class TreeElement {
219 StringBuffer name;
220 TreeElement left;
221 TreeElement right;
222
223 TreeElement(StringBuffer name) {
224 this.name = name;
225 }
226
227 TreeElement(String name) {
228 this.name = new StringBuffer(name);
229 }
230 }
231
232 public void testCircularReference() {
233 Person bob = new Person("bob");
234 Person jane = new Person("jane");
235 bob.likes = jane;
236 jane.likes = bob;
237
238 String xml = xstream.toXML(bob);
239
240 Person bobOut = (Person)xstream.fromXML(xml);
241 assertEquals("bob", bobOut.firstname);
242 Person janeOut = bobOut.likes;
243
244 assertEquals("jane", janeOut.firstname);
245
246 assertSame(bobOut.likes, janeOut);
247 assertSame(bobOut, janeOut.likes);
248 }
249
250 public void testCircularReferenceToSelf() {
251 Person bob = new Person("bob");
252 bob.likes = bob;
253
254 String xml = xstream.toXML(bob);
255
256 Person bobOut = (Person)xstream.fromXML(xml);
257 assertEquals("bob", bobOut.firstname);
258 assertSame(bobOut, bobOut.likes);
259 }
260
261 public void testDeepCircularReferences() {
262 Person bob = new Person("bob");
263 Person jane = new Person("jane");
264 Person ann = new Person("ann");
265 Person poo = new Person("poo");
266
267 bob.likes = jane;
268 bob.loathes = ann;
269 ann.likes = jane;
270 ann.loathes = poo;
271 poo.likes = jane;
272 poo.loathes = ann;
273 jane.likes = jane;
274 jane.loathes = bob;
275
276 String xml = xstream.toXML(bob);
277 Person bobOut = (Person)xstream.fromXML(xml);
278 Person janeOut = bobOut.likes;
279 Person annOut = bobOut.loathes;
280 Person pooOut = annOut.loathes;
281
282 assertEquals("bob", bobOut.firstname);
283 assertEquals("jane", janeOut.firstname);
284 assertEquals("ann", annOut.firstname);
285 assertEquals("poo", pooOut.firstname);
286
287 assertSame(janeOut, bobOut.likes);
288 assertSame(annOut, bobOut.loathes);
289 assertSame(janeOut, annOut.likes);
290 assertSame(pooOut, annOut.loathes);
291 assertSame(janeOut, pooOut.likes);
292 assertSame(annOut, pooOut.loathes);
293 assertSame(janeOut, janeOut.likes);
294 assertSame(bobOut, janeOut.loathes);
295 }
296
297 public static class WeirdThing implements Serializable {
298 public transient Object anotherObject;
299 private NestedThing nestedThing = new NestedThing();
300
301 private void readObject(ObjectInputStream in)
302 throws IOException, ClassNotFoundException {
303 in.defaultReadObject();
304 anotherObject = in.readObject();
305 }
306
307 private void writeObject(ObjectOutputStream out) throws IOException {
308 out.defaultWriteObject();
309 out.writeObject(anotherObject);
310 }
311
312 private class NestedThing implements Serializable {
313 private void readObject(ObjectInputStream in)
314 throws IOException, ClassNotFoundException {
315 in.defaultReadObject();
316 }
317
318 private void writeObject(ObjectOutputStream out) throws IOException {
319 out.defaultWriteObject();
320 }
321
322 }
323 }
324
325 public void testWeirdCircularReference() {
326 // I cannot fully explain what's special about WeirdThing, however without ensuring that
327 // a reference is only
328 // put in the references map once, this fails.
329
330 // This case was first noticed when serializing JComboBox, deserializing it and then
331 // serializing it again.
332 // Upon the second serialization, it would cause the Sun 1.4.1 JVM to crash:
333 // Object in = new javax.swing.JComboBox();
334 // Object out = xstream.fromXML(xstream.toXML(in));
335 // xstream.toXML(out); ....causes JVM crash on 1.4.1
336
337 // WeirdThing is the least possible code I can create to reproduce the problem.
338
339 // This also fails for JRockit 1.4.2 deeply nested, when it tries to set the final field
340 // AbstractNestedCircularReferenceTest$WeirdThing$NestedThing$this$1.
341
342 // setup
343 WeirdThing in = new WeirdThing();
344 in.anotherObject = in;
345
346 String xml = xstream.toXML(in);
347 // System.out.println(xml + "\n");
348
349 // execute
350 WeirdThing out = (WeirdThing)xstream.fromXML(xml);
351
352 // verify
353 assertSame(out, out.anotherObject);
354 }
355
356 public static class TreeData implements Serializable {
357 String data;
358 TreeData parent;
359 List children;
360
361 public TreeData(String data) {
362 this.data = data;
363 children = new ArrayList();
364 }
365
366 private TreeData(TreeData clone) {
367 data = clone.data;
368 parent = clone.parent;
369 children = clone.children;
370 }
371
372 public void add(TreeData child) {
373 child.parent = this;
374 children.add(child);
375 }
376
377 public int hashCode() {
378 final int prime = 31;
379 int result = 1;
380 result = prime * result + ((this.children == null) ? 0 : this.children.hashCode());
381 result = prime * result + ((this.data == null) ? 0 : this.data.hashCode());
382 return result;
383 }
384
385 public boolean equals(Object obj) {
386 if (this == obj) return true;
387 if (obj == null) return false;
388 if (!(obj instanceof TreeData)) return false;
389 TreeData other = (TreeData)obj;
390 if (this.children == null) {
391 if (other.children != null) return false;
392 } else if (!this.children.equals(other.children)) return false;
393 if (this.data == null) {
394 if (other.data != null) return false;
395 } else if (!this.data.equals(other.data)) return false;
396 return true;
397 }
398
399 protected Object writeReplace() {
400 if (getClass() == TreeData.class) {
401 return this;
402 }
403 return new TreeData(this);
404 }
405 }
406
407 public abstract void testReplacedReference();
408
409 public void replacedReference(String expectedXml) {
410 TreeData parent = new TreeData("parent");
411 parent.add(new TreeData("child") {
412 // anonymous type
413 });
414
415 xstream.alias("element", TreeData.class);
416 xstream.alias("anonymous-element", parent.children.get(0).getClass());
417
418 assertEquals(expectedXml, xstream.toXML(parent));
419 TreeData clone = (TreeData)xstream.fromXML(expectedXml);
420 assertEquals(parent, clone);
421 }
422
423 static class Email extends StandardObject {
424 String email;
425 private final Email alias;
426
427 Email(String email) {
428 this(email, null);
429 }
430 Email(String email, Email alias) {
431 this.email = email;
432 this.alias = alias;
433 }
434 }
435
436 static class EmailList extends StandardObject {
437 List addresses = new ArrayList();
438 Email main;
439 }
440
441 public void testReferenceElementInImplicitCollection() {
442 EmailList emails = new EmailList();
443 emails.addresses.add(new Email("private@joewalnes.com"));
444 emails.addresses.add(new Email("joe@joewalnes.com"));
445 emails.addresses.add(new Email("joe.walnes@thoughtworks.com"));
446 emails.addresses.add(new Email("joe@thoughtworks.com", (Email)emails.addresses.get(2)));
447 emails.main = (Email)emails.addresses.get(1);
448
449 xstream.addImplicitCollection(EmailList.class, "addresses", "address", Email.class);
450 String xml = xstream.toXML(emails);
451 assertEquals(emails, xstream.fromXML(xml));
452 }
453
454 static class EmailArray extends StandardObject {
455 Email[] addresses;
456 Email main;
457 }
458
459 public void testReferenceElementInImplicitArrays() {
460 EmailArray emails = new EmailArray();
461 Email alias = new Email("joe.walnes@thoughtworks.com");
462 emails.addresses = new Email[]{
463 new Email("private@joewalnes.com"),
464 new Email("joe@joewalnes.com"),
465 alias,
466 new Email("joe@thoughtworks.com", alias)
467 };
468 emails.main = emails.addresses[1];
469
470 xstream.addImplicitArray(EmailArray.class, "addresses", "address");
471 String xml = xstream.toXML(emails);
472 assertEquals(emails, xstream.fromXML(xml));
473 }
474 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Category;
14 import com.thoughtworks.acceptance.objects.Product;
15 import com.thoughtworks.acceptance.objects.Software;
16 import com.thoughtworks.acceptance.someobjects.WithList;
17 import com.thoughtworks.acceptance.someobjects.X;
18 import com.thoughtworks.xstream.XStream;
19 import com.thoughtworks.xstream.converters.SingleValueConverter;
20 import com.thoughtworks.xstream.converters.extended.JavaClassConverter;
21 import com.thoughtworks.xstream.converters.extended.JavaFieldConverter;
22 import com.thoughtworks.xstream.converters.extended.JavaMethodConverter;
23 import com.thoughtworks.xstream.core.util.Primitives;
24 import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
25 import com.thoughtworks.xstream.io.xml.XppDriver;
26 import com.thoughtworks.xstream.mapper.ArrayMapper;
27 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
28 import com.thoughtworks.xstream.mapper.Mapper;
29 import com.thoughtworks.xstream.mapper.MapperWrapper;
30
31 import java.util.ArrayList;
32 import java.util.LinkedList;
33 import java.util.List;
34
35 /**
36 * @author Paul Hammant
37 * @author J&ouml;rg Schaible
38 */
39 public class AliasTest extends AbstractAcceptanceTest {
40
41 public void testBarfsIfItDoesNotExist() {
42
43 String xml = "" +
44 "<X-array>\n" +
45 " <X>\n" +
46 " <anInt>0</anInt>\n" +
47 " </X>\n" +
48 "</X-array>";
49
50 // now change the alias
51 xstream.alias("Xxxxxxxx", X.class);
52 try {
53 xstream.fromXML(xml);
54 fail("ShouldCannotResolveClassException expected");
55 } catch (CannotResolveClassException expectedException) {
56 // expected
57 }
58 }
59
60 public void testWithUnderscore() {
61 xstream = new XStream(new XppDriver(new XmlFriendlyNameCoder("_-", "_")));
62 setupSecurity(xstream);
63 String xml = "" +
64 "<X_alias>\n" +
65 " <anInt>0</anInt>\n" +
66 "</X_alias>";
67
68 // now change the alias
69 xstream.alias("X_alias", X.class);
70 X x = new X(0);
71 assertBothWays(x, xml);
72 }
73
74 public static class HasUnderscore {
75 private String _attr = "foo";
76 }
77
78 public void testWithPrefixedUnderscore(){
79 HasUnderscore x = new HasUnderscore();
80
81 xstream.alias("underscore", HasUnderscore.class);
82 xstream.aliasField("attr", HasUnderscore.class, "_attr");
83
84 String xml = "" +
85 "<underscore>\n" +
86 " <attr>foo</attr>\n" +
87 "</underscore>";
88
89 assertBothWays(x, xml);
90 }
91
92 public void testForFieldAsAttribute() {
93 Software software = new Software("walness", "xstream");
94
95 xstream.alias("software", Software.class);
96 xstream.useAttributeFor(String.class);
97 xstream.aliasAttribute("id", "name");
98
99 String xml = "<software vendor=\"walness\" id=\"xstream\"/>";
100
101 assertBothWays(software, xml);
102 }
103
104 public void testForReferenceSystemAttribute() {
105 List list = new ArrayList();
106 Software software = new Software("walness", "xstream");
107 list.add(software);
108 list.add(software);
109
110 xstream.alias("software", Software.class);
111 xstream.useAttributeFor(String.class);
112 xstream.aliasAttribute("refid", "reference");
113
114 String xml = "" +
115 "<list>\n" +
116 " <software vendor=\"walness\" name=\"xstream\"/>\n" +
117 " <software refid=\"../software\"/>\n" +
118 "</list>";
119
120 assertBothWays(list, xml);
121 }
122
123 public void testForSystemAttributes() {
124 List list = new LinkedList();
125 Category category = new Category("walness", "xstream");
126 category.setProducts(list);
127 list.add(category);
128
129 xstream.alias("category", Category.class);
130 xstream.useAttributeFor(Category.class, "id");
131 xstream.aliasAttribute("class", "id");
132 xstream.aliasSystemAttribute("type", "class");
133 xstream.aliasSystemAttribute("refid", "reference");
134
135 String xml = "" +
136 "<category class=\"xstream\">\n" +
137 " <name>walness</name>\n" +
138 " <products type=\"linked-list\">\n" +
139 " <category refid=\"../..\"/>\n" +
140 " </products>\n" +
141 "</category>";
142
143 assertBothWays(category, xml);
144 }
145
146 public void testIdentityForFields() {
147 Software software = new Software("walness", "xstream");
148
149 xstream.alias("software", Software.class);
150 xstream.aliasField("name", Software.class, "name");
151 xstream.aliasField("vendor", Software.class, "vendor");
152
153 String xml = ""
154 + "<software>\n"
155 + " <vendor>walness</vendor>\n"
156 + " <name>xstream</name>\n"
157 + "</software>";
158
159 assertBothWays(software, xml);
160 }
161
162 private static class FieldsWithInternalNames {
163 String clazz;
164 String ref;
165 }
166
167 public void testCanUseInternalNameAsFieldAlias() {
168 FieldsWithInternalNames object = new FieldsWithInternalNames();
169 object.clazz = "TestIt";
170 object.ref = "MyReference";
171
172 xstream.alias("internalNames", FieldsWithInternalNames.class);
173 xstream.aliasField("class", FieldsWithInternalNames.class, "clazz");
174 xstream.aliasField("reference", FieldsWithInternalNames.class, "ref");
175
176 String xml = ""
177 + "<internalNames>\n"
178 + " <class>TestIt</class>\n"
179 + " <reference>MyReference</reference>\n"
180 + "</internalNames>";
181
182 assertBothWays(object, xml);
183 }
184
185 public void testCanAliasPrimitiveTypes() {
186 Object object = new boolean[]{true, false};
187 xstream.alias("bo", Boolean.TYPE);
188 String xml = ""
189 + "<bo-array>\n"
190 + " <bo>true</bo>\n"
191 + " <bo>false</bo>\n"
192 + "</bo-array>";
193 assertBothWays(object, xml);
194 }
195
196 public void testCanAliasArray() {
197 Object object = new boolean[]{true, false};
198 xstream.alias("boa", boolean[].class);
199 String xml = ""
200 + "<boa>\n"
201 + " <boolean>true</boolean>\n"
202 + " <boolean>false</boolean>\n"
203 + "</boa>";
204 assertBothWays(object, xml);
205 }
206
207 public void testCanAliasArrayInMultiDimension() {
208 Object object = new boolean[][]{{true, false}};
209 xstream.alias("boa", boolean[].class);
210 String xml = ""
211 + "<boa-array>\n"
212 + " <boa>\n"
213 + " <boolean>true</boolean>\n"
214 + " <boolean>false</boolean>\n"
215 + " </boa>\n"
216 + "</boa-array>";
217 assertBothWays(object, xml);
218 }
219
220 public static class TypeA {
221 private String attrA = "testA";
222 }
223
224 public static class TypeB extends TypeA {
225 private String attrB = "testB";
226 }
227
228 public static class TypeC extends TypeB {
229 private String attrC = "testC";
230 }
231
232 public void testCanAliasInheritedFields() {
233 xstream.alias("test", TypeC.class);
234 xstream.aliasField("a", TypeA.class, "attrA");
235 xstream.aliasField("b", TypeB.class, "attrB");
236 xstream.aliasField("c", TypeC.class, "attrC");
237 TypeC object = new TypeC();
238 String xml = ""
239 + "<test>\n"
240 + " <a>testA</a>\n"
241 + " <b>testB</b>\n"
242 + " <c>testC</c>\n"
243 + "</test>";
244 assertBothWays(object, xml);
245 }
246
247 public void testCanDeserializeAliasedInheritedFieldsToSameName() {
248 xstream.alias("test", TypeC.class);
249 xstream.alias("A", TypeA.class);
250 xstream.alias("B", TypeB.class);
251 xstream.aliasField("attr", TypeA.class, "attrA");
252 xstream.aliasField("attr", TypeB.class, "attrB");
253 xstream.aliasField("attr", TypeC.class, "attrC");
254 TypeC object = new TypeC();
255 String xml = ""
256 + "<test>\n"
257 + " <attr defined-in=\"A\">testA</attr>\n"
258 + " <attr defined-in=\"B\">testB</attr>\n"
259 + " <attr>testC</attr>\n"
260 + "</test>";
261 assertObjectsEqual(object, xstream.fromXML(xml));
262 //assertBothWays(object, xml);
263 }
264
265 public void testCanOverwriteInheritedAlias() {
266 xstream.alias("test", TypeC.class);
267 xstream.aliasField("a", TypeA.class, "attrA");
268 xstream.aliasField("b", TypeB.class, "attrB");
269 xstream.aliasField("c", TypeC.class, "attrC");
270 xstream.aliasField("y", TypeC.class, "attrA");
271 TypeC object = new TypeC();
272 String xml = ""
273 + "<test>\n"
274 + " <y>testA</y>\n"
275 + " <b>testB</b>\n"
276 + " <c>testC</c>\n"
277 + "</test>";
278 assertBothWays(object, xml);
279 }
280
281 public void testCanAliasArrayElements() {
282 Object[] software = new Object[]{new Software("walness", "xstream")};
283
284 xstream.alias("software", Software.class);
285 xstream.aliasField("Name", Software.class, "name");
286 xstream.aliasField("Vendor", Software.class, "vendor");
287
288 String xml = "" //
289 + "<object-array>\n"
290 + " <software>\n"
291 + " <Vendor>walness</Vendor>\n"
292 + " <Name>xstream</Name>\n"
293 + " </software>\n"
294 + "</object-array>";
295
296 assertBothWays(software, xml);
297 }
298
299 public void testCanAliasCompletePackage() {
300 Software software = new Software("walness", "xstream");
301 xstream.aliasPackage("org.codehaus", "com.thoughtworks.acceptance.objects");
302
303 String xml = "" //
304 + "<org.codehaus.Software>\n"
305 + " <vendor>walness</vendor>\n"
306 + " <name>xstream</name>\n"
307 + "</org.codehaus.Software>";
308
309 assertBothWays(software, xml);
310 }
311
312 public void testCanAliasSubPackage() {
313 Software software = new Software("walness", "xstream");
314 xstream.aliasPackage("org.codehaus", "com.thoughtworks");
315
316 String xml = "" //
317 + "<org.codehaus.acceptance.objects.Software>\n"
318 + " <vendor>walness</vendor>\n"
319 + " <name>xstream</name>\n"
320 + "</org.codehaus.acceptance.objects.Software>";
321
322 assertBothWays(software, xml);
323 }
324
325 public void testToDefaultPackage() {
326 Software software = new Software("walness", "xstream");
327 xstream.aliasPackage("", "com.thoughtworks.acceptance.objects");
328
329 String xml = "" //
330 + "<Software>\n"
331 + " <vendor>walness</vendor>\n"
332 + " <name>xstream</name>\n"
333 + "</Software>";
334
335 assertBothWays(software, xml);
336 }
337
338 public void testForLongerPackageNameTakesPrecedence() {
339 WithList withList = new WithList();
340 withList.things.add(new Software("walness", "xstream"));
341 withList.things.add(new TypeA());
342 xstream.aliasPackage("model", "com.thoughtworks.acceptance.objects");
343 xstream.aliasPackage("org.codehaus", "com.thoughtworks");
344 xstream.aliasPackage("model.foo", "com.thoughtworks.acceptance.someobjects");
345
346 String xml = "" //
347 + "<model.foo.WithList>\n"
348 + " <things>\n"
349 + " <model.Software>\n"
350 + " <vendor>walness</vendor>\n"
351 + " <name>xstream</name>\n"
352 + " </model.Software>\n"
353 + " <org.codehaus.acceptance.AliasTest_-TypeA>\n"
354 + " <attrA>testA</attrA>\n"
355 + " </org.codehaus.acceptance.AliasTest_-TypeA>\n"
356 + " </things>\n"
357 + "</model.foo.WithList>";
358
359 assertBothWays(withList, xml);
360 }
361
362 public void testClassTakesPrecedenceOfPackage() {
363 WithList withList = new WithList();
364 withList.things.add(new Software("walness", "xstream"));
365 xstream.alias("MySoftware", Software.class);
366 xstream.aliasPackage("org.codehaus", "com.thoughtworks");
367 xstream.aliasPackage("model.foo", "com.thoughtworks.acceptance.someobjects");
368
369 String xml = "" //
370 + "<model.foo.WithList>\n"
371 + " <things>\n"
372 + " <MySoftware>\n"
373 + " <vendor>walness</vendor>\n"
374 + " <name>xstream</name>\n"
375 + " </MySoftware>\n"
376 + " </things>\n"
377 + "</model.foo.WithList>";
378
379 assertBothWays(withList, xml);
380 }
381
382 private void takingDoubles(Double d1, double d2) {}
383
384 public void testCanCreateAliasingJavaTypeConverter() throws NoSuchFieldException, NoSuchMethodException {
385 Mapper mapper = new MapperWrapper(xstream.getMapper().lookupMapperOfType(ArrayMapper.class)) {
386 public Class realClass(String elementName) {
387 Class primitiveType = Primitives.primitiveType(elementName);
388 return primitiveType != null ? primitiveType : super.realClass(elementName);
389 }
390 };
391 SingleValueConverter javaClassConverter = new JavaClassConverter(mapper) {};
392 xstream.registerConverter(javaClassConverter);
393 xstream.registerConverter(new JavaMethodConverter(javaClassConverter){});
394 xstream.registerConverter(new JavaFieldConverter(javaClassConverter, mapper){});
395 xstream.alias("A", TypeA.class);
396 xstream.alias("Prod", Product.class);
397 xstream.aliasField("a", TypeA.class, "attrA");
398 xstream.alias("Test", getClass());
399
400 List list = new ArrayList();
401 list.add(TypeA.class);
402 list.add(int[][][].class);
403 list.add(Integer[][][].class);
404 list.add(TypeA.class.getDeclaredField("attrA"));
405 list.add(Product.class.getConstructor(new Class[]{String.class, String.class, double.class}));
406 list.add(getClass().getDeclaredMethod("takingDoubles", new Class[]{Double.class, double.class}));
407 list.add(ArrayList.class);
408
409 String xml = "" //
410 + "<list>\n"
411 + " <java-class>A</java-class>\n"
412 + " <java-class>int-array-array-array</java-class>\n"
413 + " <java-class>java.lang.Integer-array-array-array</java-class>\n"
414 + " <field>\n"
415 + " <name>a</name>\n"
416 + " <clazz>A</clazz>\n"
417 + " </field>\n"
418 + " <constructor>\n"
419 + " <class>Prod</class>\n"
420 + " <parameter-types>\n"
421 + " <class>string</class>\n"
422 + " <class>string</class>\n"
423 + " <class>double</class>\n"
424 + " </parameter-types>\n"
425 + " </constructor>\n"
426 + " <method>\n"
427 + " <class>Test</class>\n"
428 + " <name>takingDoubles</name>\n"
429 + " <parameter-types>\n"
430 + " <class>java.lang.Double</class>\n"
431 + " <class>double</class>\n"
432 + " </parameter-types>\n"
433 + " </method>\n"
434 + " <java-class>java.util.ArrayList</java-class>\n"
435 + "</list>";
436
437 assertBothWays(list, xml);
438 }
439 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class ArraysTest extends AbstractAcceptanceTest {
16
17 public void testStringArray() {
18 String[] array = new String[]{"a", "b", "c"};
19
20 String expected = "" +
21 "<string-array>\n" +
22 " <string>a</string>\n" +
23 " <string>b</string>\n" +
24 " <string>c</string>\n" +
25 "</string-array>";
26
27 assertBothWays(array, expected);
28 }
29
30 public void testPrimitiveArray() {
31 int[] array = new int[]{1, 2};
32
33 String expected = "" +
34 "<int-array>\n" +
35 " <int>1</int>\n" +
36 " <int>2</int>\n" +
37 "</int-array>";
38
39 assertBothWays(array, expected);
40 }
41
42 public void testBoxedTypeArray() {
43 Integer[] array = new Integer[]{new Integer(1), new Integer(2)};
44
45 String expected = "" +
46 "<java.lang.Integer-array>\n" +
47 " <int>1</int>\n" +
48 " <int>2</int>\n" +
49 "</java.lang.Integer-array>";
50
51 assertBothWays(array, expected);
52 }
53
54 public static class X extends StandardObject {
55 String s = "hi";
56 }
57
58 public void testCustomObjectArray() {
59
60 X[] array = new X[]{new X(), new X()};
61
62 String expected = "" +
63 "<com.thoughtworks.acceptance.ArraysTest_-X-array>\n" +
64 " <com.thoughtworks.acceptance.ArraysTest_-X>\n" +
65 " <s>hi</s>\n" +
66 " </com.thoughtworks.acceptance.ArraysTest_-X>\n" +
67 " <com.thoughtworks.acceptance.ArraysTest_-X>\n" +
68 " <s>hi</s>\n" +
69 " </com.thoughtworks.acceptance.ArraysTest_-X>\n" +
70 "</com.thoughtworks.acceptance.ArraysTest_-X-array>";
71
72 assertBothWays(array, expected);
73 }
74
75 public void testArrayOfMixedTypes() {
76
77 Object[] array = new Number[]{new Long(2), new Integer(3)};
78
79 String expected = "" +
80 "<number-array>\n" +
81 " <long>2</long>\n" +
82 " <int>3</int>\n" +
83 "</number-array>";
84
85 assertBothWays(array, expected);
86
87 }
88
89 public void testEmptyArray() {
90 int[] array = new int[]{};
91
92 String expected = "<int-array/>";
93
94 assertBothWays(array, expected);
95
96 }
97
98 public void testUninitializedArray() {
99 String[] array = new String[4];
100 array[0] = "zero";
101 array[2] = "two";
102
103 String expected = "" +
104 "<string-array>\n" +
105 " <string>zero</string>\n" +
106 " <null/>\n" +
107 " <string>two</string>\n" +
108 " <null/>\n" +
109 "</string-array>";
110
111 assertBothWays(array, expected);
112
113 }
114
115 public void testArrayInCustomObject() {
116 ObjWithArray objWithArray = new ObjWithArray();
117 objWithArray.strings = new String[]{"hi", "bye"};
118 xstream.alias("owa", ObjWithArray.class);
119 String expected = "" +
120 "<owa>\n" +
121 " <strings>\n" +
122 " <string>hi</string>\n" +
123 " <string>bye</string>\n" +
124 " </strings>\n" +
125 "</owa>";
126 assertBothWays(objWithArray, expected);
127 }
128
129 public void testNullArrayInCustomObject() {
130 ObjWithArray objWithArray = new ObjWithArray();
131 xstream.alias("owa", ObjWithArray.class);
132 String expected = "<owa/>";
133 assertBothWays(objWithArray, expected);
134 }
135
136 public static class ObjWithArray extends StandardObject {
137 String[] strings;
138 }
139
140 public void testDeserializingObjectWhichContainsAPrimitiveLongArray() {
141 String xml =
142 "<owla>" +
143 " <bits class=\"long-array\">" +
144 " <long>0</long>" +
145 " <long>1</long>" +
146 " <long>2</long>" +
147 " </bits>" +
148 "</owla>";
149
150 xstream.alias("owla", ObjectWithLongArray.class);
151
152 ObjectWithLongArray o = (ObjectWithLongArray) xstream.fromXML(xml);
153
154 assertEquals(o.bits[0], 0);
155 assertEquals(o.bits[1], 1);
156 assertEquals(o.bits[2], 2);
157 }
158
159 public static class ObjectWithLongArray {
160 long[] bits;
161 }
162
163 public void testMultidimensionalArray() {
164 int[][] array = new int[3][2];
165 array[0][0] = 2;
166 array[0][1] = 4;
167 array[1][0] = 8;
168 array[1][1] = 16;
169 array[2] = new int[3];
170 array[2][0] = 33;
171 array[2][1] = 66;
172 array[2][2] = 99;
173
174 String expectedXml = "" +
175 "<int-array-array>\n" +
176 " <int-array>\n" +
177 " <int>2</int>\n" +
178 " <int>4</int>\n" +
179 " </int-array>\n" +
180 " <int-array>\n" +
181 " <int>8</int>\n" +
182 " <int>16</int>\n" +
183 " </int-array>\n" +
184 " <int-array>\n" +
185 " <int>33</int>\n" +
186 " <int>66</int>\n" +
187 " <int>99</int>\n" +
188 " </int-array>\n" +
189 "</int-array-array>";
190
191 String actualXml = xstream.toXML(array);
192 assertEquals(expectedXml, actualXml);
193
194 int[][] result = (int[][]) xstream.fromXML(actualXml);
195 assertEquals(2, result[0][0]);
196 assertEquals(4, result[0][1]);
197 assertEquals(8, result[1][0]);
198 assertEquals(16, result[1][1]);
199 assertEquals(99, result[2][2]);
200 assertEquals(3, result.length);
201 assertEquals(2, result[0].length);
202 assertEquals(2, result[1].length);
203 assertEquals(3, result[2].length);
204 }
205
206 public static class Thing {
207 }
208
209 public static class SpecialThing extends Thing {
210 }
211
212 public void testMultidimensionalArrayOfMixedTypes() {
213 xstream.alias("thing", Thing.class);
214 xstream.alias("special-thing", SpecialThing.class);
215
216 Object[][] array = new Object[2][2];
217 array[0][0] = new Object();
218 array[0][1] = "a string";
219 array[1] = new Thing[2];
220 array[1][0] = new Thing();
221 array[1][1] = new SpecialThing();
222 String expectedXml = "" +
223 "<object-array-array>\n" +
224 " <object-array>\n" +
225 " <object/>\n" +
226 " <string>a string</string>\n" +
227 " </object-array>\n" +
228 " <thing-array>\n" +
229 " <thing/>\n" +
230 " <special-thing/>\n" +
231 " </thing-array>\n" +
232 "</object-array-array>";
233
234 String actualXml = xstream.toXML(array);
235 assertEquals(expectedXml, actualXml);
236
237 Object[][] result = (Object[][]) xstream.fromXML(actualXml);
238 assertEquals(Object.class, result[0][0].getClass());
239 assertEquals("a string", result[0][1]);
240 assertEquals(Thing.class, result[1][0].getClass());
241 assertEquals(SpecialThing.class, result[1][1].getClass());
242 }
243
244 public static class NoOneLikesMe extends StandardObject {
245 private int name;
246
247 public NoOneLikesMe(int name) {
248 this.name = name;
249 }
250 }
251
252 public void testHandlesArrayClassesThatHaveNotYetBeenLoaded() {
253 // Catch weirdness in classloader.
254 // Resolved by using Class.forName(x, false, classLoader), instead of classLoader.loadClass(x);
255 String xml = ""
256 + "<com.thoughtworks.acceptance.ArraysTest_-NoOneLikesMe-array>\n"
257 + " <com.thoughtworks.acceptance.ArraysTest_-NoOneLikesMe>\n"
258 + " <name>99</name>\n"
259 + " </com.thoughtworks.acceptance.ArraysTest_-NoOneLikesMe>\n"
260 + "</com.thoughtworks.acceptance.ArraysTest_-NoOneLikesMe-array>";
261 NoOneLikesMe[] result = (NoOneLikesMe[]) xstream.fromXML(xml);
262 assertEquals(1, result.length);
263 assertEquals(99, result[0].name);
264 }
265
266 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 20. February 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.text.DateFormat;
14 import java.text.SimpleDateFormat;
15 import java.util.Date;
16
17 import com.thoughtworks.xstream.XStream;
18 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
19 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
20
21 /**
22 * @author Paul Hammant
23 * @author Ian Cartwright
24 * @author Mauro Talevi
25 * @author J&ouml;rg Schaible
26 * @author Guilherme Silveira
27 */
28 public class AttributeTest extends AbstractAcceptanceTest {
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 TimeZoneChanger.change("GMT");
33 }
34
35 protected void tearDown() throws Exception {
36 TimeZoneChanger.reset();
37 super.tearDown();
38 }
39
40 public static class One implements HasID {
41 public ID id;
42 public Two two;
43
44 public void setID(ID id) {
45 this.id = id;
46 }
47 }
48
49 public static interface HasID {
50 void setID(ID id);
51 }
52
53 public static class Two {}
54
55 public static class Three {
56 public Date date;
57 }
58
59 public static class Four extends One {
60 public ID id;
61 }
62
63 public static class ID {
64 public ID(String value) {
65 this.value = value;
66 }
67
68 public String value;
69 }
70
71 private static class MyIDConverter extends AbstractSingleValueConverter {
72 public boolean canConvert(Class type) {
73 return type.equals(ID.class);
74 }
75
76 public String toString(Object obj) {
77 return obj == null ? null : ((ID) obj).value;
78 }
79
80 public Object fromString(String str) {
81 return new ID(str);
82 }
83 }
84
85 static class C
86 {
87 private Date dt;
88 private String str;
89 private int i;
90
91 C() {
92 // for JDK 1.3
93 }
94
95 C(Date dt, String st, int i)
96 {
97 this.dt = dt;
98 this.str = st;
99 this.i = i;
100 }
101 }
102
103 public void testAllowsAttributeWithCustomConverterAndFieldName() {
104 One one = new One();
105 one.two = new Two();
106 one.id = new ID("hullo");
107
108 xstream.alias("one", One.class);
109 xstream.useAttributeFor("id", ID.class);
110 xstream.registerConverter(new MyIDConverter());
111
112 String expected =
113 "<one id=\"hullo\">\n" +
114 " <two/>\n" +
115 "</one>";
116 assertBothWays(one, expected);
117 }
118
119 public void testDoesNotAllowAttributeWithCustomConverterAndDifferentFieldName() {
120 One one = new One();
121 one.two = new Two();
122 one.id = new ID("hullo");
123
124 xstream.alias("one", One.class);
125 xstream.useAttributeFor("foo", ID.class);
126 xstream.registerConverter(new MyIDConverter());
127
128 String expected =
129 "<one>\n" +
130 " <id>hullo</id>\n" +
131 " <two/>\n" +
132 "</one>";
133 assertBothWays(one, expected);
134 }
135
136 // TODO: Currently not possible, see comment in AbstractReflectionProvider.doUnmarshal
137 public void todoTestHidingMemberCanBeWrittenIfAliasDiffers() {
138 Four four = new Four();
139 four.two = new Two();
140 four.id = new ID("4");
141 four.setID(new ID("1"));
142
143 xstream.alias("four", Four.class);
144 xstream.aliasField("id4", Four.class, "id");
145 xstream.useAttributeFor(ID.class);
146 xstream.registerConverter(new MyIDConverter());
147
148 String expected =
149 "<four id=\"1\" id4=\"4\">\n" +
150 " <two/>\n" +
151 "</four>";
152 assertBothWays(four, expected);
153 }
154
155 public void testAllowsAttributeWithKnownConverterAndFieldName() throws Exception {
156 Three three = new Three();
157 DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
158 three.date = format.parse("19/02/2006");
159
160 xstream.alias("three", Three.class);
161 xstream.useAttributeFor("date", Date.class);
162
163 String expected =
164 "<three date=\"2006-02-19 00:00:00.0 UTC\"/>";
165 assertBothWays(three, expected);
166 }
167
168 public void testAllowsAttributeWithArbitraryFieldType() {
169 One one = new One();
170 one.two = new Two();
171 one.id = new ID("hullo");
172
173 xstream.alias("one", One.class);
174 xstream.useAttributeFor(ID.class);
175 xstream.registerConverter(new MyIDConverter());
176
177 String expected =
178 "<one id=\"hullo\">\n" +
179 " <two/>\n" +
180 "</one>";
181 assertBothWays(one, expected);
182 }
183
184 public void testDoesNotAllowAttributeWithNullAttribute() {
185 One one = new One();
186 one.two = new Two();
187
188 xstream.alias("one", One.class);
189 xstream.useAttributeFor(ID.class);
190 xstream.registerConverter(new MyIDConverter());
191
192 String expected =
193 "<one>\n" +
194 " <two/>\n" +
195 "</one>";
196 assertBothWays(one, expected);
197 }
198
199 public void testAllowsAttributeToBeAliased() {
200 One one = new One();
201 one.two = new Two();
202 one.id = new ID("hullo");
203
204 xstream.alias("one", One.class);
205 xstream.aliasAttribute("id-alias", "id");
206 xstream.useAttributeFor("id", ID.class);
207 xstream.registerConverter(new MyIDConverter());
208
209 String expected =
210 "<one id-alias=\"hullo\">\n" +
211 " <two/>\n" +
212 "</one>";
213 assertBothWays(one, expected);
214 }
215
216 public void testCanHandleNullValues() {
217 C c = new C(null, null, 0);
218 xstream.alias("C", C.class);
219 xstream.useAttributeFor(Date.class);
220 xstream.useAttributeFor(String.class);
221 String expected =
222 "<C>\n" +
223 " <i>0</i>\n" +
224 "</C>";
225 assertBothWays(c, expected);
226 }
227
228 public void testCanHandlePrimitiveValues() {
229 C c = new C(null, null, 0);
230 xstream.alias("C", C.class);
231 xstream.useAttributeFor(Date.class);
232 xstream.useAttributeFor(String.class);
233 xstream.useAttributeFor(int.class);
234 String expected ="<C i=\"0\"/>";
235 assertBothWays(c, expected);
236 }
237
238 static class Name {
239 private String name;
240 Name() {
241 // for JDK 1.3
242 }
243 Name(String name) {
244 this.name = name;
245 }
246 }
247
248 static class Camera {
249 private String name;
250 protected Name n;
251
252 Camera() {
253 // for JDK 1.3
254 }
255
256 Camera(String name) {
257 this.name = name;
258 }
259 }
260
261 public void testAllowsAnAttributeForASpecificField() {
262 xstream.alias("camera", Camera.class);
263 xstream.useAttributeFor(Camera.class, "name");
264 Camera camera = new Camera("Rebel 350");
265 camera.n = new Name("foo");
266 String expected = "" +
267 "<camera name=\"Rebel 350\">\n" +
268 " <n>\n" +
269 " <name>foo</name>\n" +
270 " </n>\n" +
271 "</camera>";
272 assertBothWays(camera, expected);
273 }
274
275 public void testAllowsAnAttributeForASpecificAliasedField() {
276 xstream.alias("camera", Camera.class);
277 xstream.aliasAttribute(Camera.class, "name", "model");
278 Camera camera = new Camera("Rebel 350");
279 camera.n = new Name("foo");
280 String expected = "" +
281 "<camera model=\"Rebel 350\">\n" +
282 " <n>\n" +
283 " <name>foo</name>\n" +
284 " </n>\n" +
285 "</camera>";
286 assertBothWays(camera, expected);
287 }
288
289 static class PersonalizedCamera extends Camera {
290 private String owner;
291
292 PersonalizedCamera() {
293 // for JDK 1.3
294 }
295
296 PersonalizedCamera(String name, String owner) {
297 super(name);
298 this.owner = owner;
299 }
300 }
301
302 public void testAllowsAnAttributeForASpecificFieldInASuperClass() {
303 xstream.alias("camera", PersonalizedCamera.class);
304 xstream.useAttributeFor(Camera.class, "name");
305 PersonalizedCamera camera = new PersonalizedCamera("Rebel 350", "Guilherme");
306 camera.n = new Name("foo");
307 String expected = "" +
308 "<camera name=\"Rebel 350\">\n" +
309 " <n>\n" +
310 " <name>foo</name>\n" +
311 " </n>\n" +
312 " <owner>Guilherme</owner>\n" +
313 "</camera>";
314 assertBothWays(camera, expected);
315 }
316
317 public void testAllowsAnAttributeForAFieldOfASpecialTypeAlsoInASuperClass() {
318 xstream.alias("camera", PersonalizedCamera.class);
319 xstream.useAttributeFor("name", String.class);
320 PersonalizedCamera camera = new PersonalizedCamera("Rebel 350", "Guilherme");
321 camera.n = new Name("foo");
322 String expected = "" +
323 "<camera name=\"Rebel 350\">\n" +
324 " <n name=\"foo\"/>\n" +
325 " <owner>Guilherme</owner>\n" +
326 "</camera>";
327 assertBothWays(camera, expected);
328 }
329
330 public static class TransientIdField {
331 transient String id;
332 String name;
333
334 public TransientIdField() {
335 // for JDK 1.3
336 }
337
338 public TransientIdField(String id, String name) {
339 this.id = id;
340 this.name = name;
341 }
342
343 public boolean equals(Object obj) {
344 return name.equals(((TransientIdField)obj).name);
345 }
346 }
347
348 public void testAttributeNamedLikeTransientFieldDoesNotAbortDeserializationOfFollowingFields() {
349 xstream.setMode(XStream.ID_REFERENCES);
350 xstream.alias("transient", TransientIdField.class);
351
352 TransientIdField field = new TransientIdField("foo", "test");
353 String xml = "" //
354 + "<transient id=\"1\">\n" //
355 + " <name>test</name>\n" //
356 + "</transient>";
357
358 assertBothWays(field, xml);
359 }
360
361 static class Person {
362 String _name;
363 int _age;
364 Person() {} // JDK 1.3
365 Person(String name, int age) {
366 this._name = name;
367 this._age = age;
368 }
369 };
370
371 public void testAttributeMayHaveXmlUnfriendlyName() {
372 xstream.alias("person", Person.class);
373 xstream.useAttributeFor(Person.class, "_name");
374 xstream.useAttributeFor(Person.class, "_age");
375 Person person = new Person("joe", 25);
376 String xml = "<person __name=\"joe\" __age=\"25\"/>";
377 assertBothWays(person, xml);
378 }
379 }
0 /*
1 * Copyright (C) 2008, 2014 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.UUID;
13
14 import com.thoughtworks.xstream.XStream;
15
16 public class Basic15TypesTest extends AbstractAcceptanceTest {
17
18 @Override
19 protected void setupSecurity(XStream xstream) {
20 super.setupSecurity(xstream);
21 xstream.allowTypes(new Class[]{StringBuilder.class, UUID.class});
22 }
23
24 public void testUUID() {
25 UUID uuid = UUID.randomUUID();
26 assertBothWays(uuid, "<uuid>" + uuid + "</uuid>");
27 }
28
29 public void testStringBuilder() {
30 StringBuilder builder = new StringBuilder();
31 builder.append("woo");
32 String xml = xstream.toXML(builder);
33 assertEquals(xml, "<string-builder>woo</string-builder>");
34 StringBuilder out = (StringBuilder) xstream.fromXML(xml);
35 assertEquals("woo", out.toString());
36 }
37 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2013 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.math.BigDecimal;
14 import java.math.BigInteger;
15
16
17 public class BasicTypesTest extends AbstractAcceptanceTest {
18
19 public void testPrimitiveNumbers() {
20 assertBothWays(new Integer(99), "<int>99</int>");
21 assertBothWays(new Integer(-99), "<int>-99</int>");
22 assertBothWays(new Integer(0), "<int>0</int>");
23 assertBothWays(new Float(-123.45f), "<float>-123.45</float>");
24 assertBothWays(new Double(-1234567890.12345), "<double>-1.23456789012345E9</double>");
25 assertBothWays(new Long(123456789123456L), "<long>123456789123456</long>");
26 assertBothWays(new Short((short)123), "<short>123</short>");
27 }
28
29 public void testDifferentBaseIntegers() {
30 assertEquals(new Integer(255), xstream.fromXML("<int>0xFF</int>"));
31 assertEquals(new Integer(255), xstream.fromXML("<int>#FF</int>"));
32 assertEquals(new Integer(8), xstream.fromXML("<int>010</int>"));
33 assertEquals(new Long(01777777773427777777773L), xstream.fromXML("<long>01777777773427777777773</long>"));
34 }
35
36 public void testNegativeIntegersInHex() {
37 assertEquals(new Byte((byte)-1), xstream.fromXML("<byte>0xFF</byte>"));
38 assertEquals(new Short((short)-1), xstream.fromXML("<short>0xFFFF</short>"));
39 assertEquals(new Integer(-1), xstream.fromXML("<int>0xFFFFFFFF</int>"));
40 assertEquals(new Long(-1), xstream.fromXML("<long>0xFFFFFFFFFFFFFFFF</long>"));
41 }
42
43 public void testNegativeIntegersInOctal() {
44 assertEquals(new Byte((byte)-1), xstream.fromXML("<byte>0377</byte>"));
45 assertEquals(new Short((short)-1), xstream.fromXML("<short>0177777</short>"));
46 assertEquals(new Integer(-1), xstream.fromXML("<int>037777777777</int>"));
47 assertEquals(new Long(-1), xstream.fromXML("<long>01777777777777777777777</long>"));
48 }
49
50 public void testOtherPrimitives() {
51 assertBothWays(new Character('z'), "<char>z</char>");
52 assertBothWays(Boolean.TRUE, "<boolean>true</boolean>");
53 assertBothWays(Boolean.FALSE, "<boolean>false</boolean>");
54 assertBothWays(new Byte((byte)44), "<byte>44</byte>");
55 }
56
57 public void testNullCharacter() {
58 assertEquals(new Character('\0'), xstream.fromXML("<char null=\"true\"/>")); // pre XStream 1.3
59 assertBothWays(new Character('\0'), "<char></char>");
60 }
61
62 public void testNonUnicodeCharacter() {
63 assertBothWays(new Character('\uffff'), "<char>&#xffff;</char>");
64 }
65
66 public void testStrings() {
67 assertBothWays("hello world", "<string>hello world</string>");
68 assertBothWays("-0770", "<string>-0770</string>");
69 }
70
71 public void testStringsWithISOControlCharacter() {
72 assertBothWays("hello\u0004world", "<string>hello&#x4;world</string>");
73 assertBothWays("hello\u0096world", "<string>hello&#x96;world</string>");
74 }
75
76 public void testStringBuffer() {
77 StringBuffer buffer = new StringBuffer();
78 buffer.append("woo");
79 String xml = xstream.toXML(buffer);
80 assertEquals(xml, "<string-buffer>woo</string-buffer>");
81 StringBuffer out = (StringBuffer)xstream.fromXML(xml);
82 assertEquals("woo", out.toString());
83 }
84
85 public void testBigInteger() {
86 BigInteger bigInteger = new BigInteger("1234567890123456");
87 assertBothWays(bigInteger, "<big-int>1234567890123456</big-int>");
88 }
89
90 public void testBigDecimal() {
91 BigDecimal bigDecimal = new BigDecimal("1234567890123456.987654321");
92 assertBothWays(bigDecimal, "<big-decimal>1234567890123456.987654321</big-decimal>");
93 }
94
95 public void testNull() {
96 assertBothWays(null, "<null/>");
97 }
98
99 public void testNumberFormats() {
100 assertEquals(1.0, ((Double)xstream.fromXML("<double>1</double>")).doubleValue(), 0.001);
101 assertEquals(1.0f, ((Float)xstream.fromXML("<float>1</float>")).floatValue(), 0.001);
102 }
103 }
0 /*
1 * Copyright (C) 2008, 2010, 2011 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 12. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.converters.ConverterLookup;
13 import com.thoughtworks.xstream.core.ReferenceByIdMarshaller;
14 import com.thoughtworks.xstream.core.ReferenceByIdMarshallingStrategy;
15 import com.thoughtworks.xstream.core.TreeMarshaller;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 public class BeanIDCircularReferenceTest extends AbstractReferenceTest {
21
22 private ReferenceByFirstnameMarshallingStrategy marshallingStrategy;
23
24 private static final class ReferenceByFirstnameMarshallingStrategy extends
25 ReferenceByIdMarshallingStrategy {
26 protected TreeMarshaller createMarshallingContext(HierarchicalStreamWriter writer,
27 ConverterLookup converterLookup, Mapper mapper) {
28 return new ReferenceByIdMarshaller(
29 writer, converterLookup, mapper, new ReferenceByIdMarshaller.IDGenerator() {
30 int id = 0;
31
32 public String next(Object item) {
33 final String id;
34 if (item instanceof Person) {
35 id = ((Person)item).firstname;
36 } else if (item instanceof TreeData) {
37 id = ((TreeData)item).data;
38 } else {
39 id = String.valueOf(this.id++ );
40 }
41 return id;
42 }
43 });
44 }
45 }
46
47 // inherits test from superclass
48 protected void setUp() throws Exception {
49 super.setUp();
50 marshallingStrategy = new ReferenceByFirstnameMarshallingStrategy();
51 xstream.setMarshallingStrategy(marshallingStrategy);
52 }
53
54 public void testCircularReferenceXml() {
55 Person bob = new Person("bob");
56 Person jane = new Person("jane");
57 bob.likes = jane;
58 jane.likes = bob;
59
60 String expected = ""
61 + "<person id=\"bob\">\n"
62 + " <firstname>bob</firstname>\n"
63 + " <likes id=\"jane\">\n"
64 + " <firstname>jane</firstname>\n"
65 + " <likes reference=\"bob\"/>\n"
66 + " </likes>\n"
67 + "</person>";
68
69 assertEquals(expected, xstream.toXML(bob));
70 }
71
72 public void testCircularReferenceToSelfXml() {
73 Person bob = new Person("bob");
74 bob.likes = bob;
75
76 String expected = ""
77 + "<person id=\"bob\">\n"
78 + " <firstname>bob</firstname>\n"
79 + " <likes reference=\"bob\"/>\n"
80 + "</person>";
81
82 assertEquals(expected, xstream.toXML(bob));
83 }
84
85 public void testCanAvoidMemberIfUsedAsId() throws Exception {
86 xstream.omitField(Person.class, "firstname");
87
88 Person bob = new Person("bob");
89 Person jane = new Person("jane");
90 bob.likes = jane;
91 jane.likes = bob;
92
93 String expected = ""
94 + "<person id=\"bob\">\n"
95 + " <likes id=\"jane\">\n"
96 + " <likes reference=\"bob\"/>\n"
97 + " </likes>\n"
98 + "</person>";
99
100 assertEquals(expected, xstream.toXML(bob));
101
102 // new XStream instance, since marshal and unmarshal is asymmetric
103 xstream = createXStream();
104 setUp();
105 xstream.useAttributeFor("firstname", String.class);
106 xstream.aliasField("id", Person.class, "firstname");
107
108 Person bobAgain = (Person)xstream.fromXML(expected);
109 assertEquals("bob", bobAgain.firstname);
110 assertEquals("jane", bobAgain.likes.firstname);
111 }
112
113 public void testReplacedReference() {
114 String expectedXml = ""
115 + "<element id=\"parent\">\n"
116 + " <data>parent</data>\n"
117 + " <children id=\"0\">\n"
118 + " <anonymous-element id=\"child\" resolves-to=\"element\">\n"
119 + " <data>child</data>\n"
120 + " <parent reference=\"parent\"/>\n"
121 + " <children id=\"1\"/>\n"
122 + " </anonymous-element>\n"
123 + " </children>\n"
124 + "</element>";
125
126 replacedReference(expectedXml);
127 }
128 }
0 /*
1 * Copyright (C) 2006, 2007 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 19. October 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
13
14 import java.util.List;
15 import java.util.ArrayList;
16
17 /**
18 * @author David Blevins
19 */
20 public class BooleanFieldsTest extends AbstractAcceptanceTest {
21
22 public static class Musican {
23 public String name;
24 public String genre;
25 public boolean alive;
26
27 public Musican() {
28 // for JDK 1.3
29 }
30
31 public Musican(String name, String genre, boolean alive) {
32 this.name = name;
33 this.genre = genre;
34 this.alive = alive;
35 }
36 }
37
38 public void testTrueFalseValues() {
39 List jazzIcons = new ArrayList();
40 jazzIcons.add(new Musican("Miles Davis", "jazz", false));
41 jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
42
43 xstream.alias("musician", Musican.class);
44
45 String expectedXml =
46 "<list>\n" +
47 " <musician>\n" +
48 " <name>Miles Davis</name>\n" +
49 " <genre>jazz</genre>\n" +
50 " <alive>false</alive>\n" +
51 " </musician>\n" +
52 " <musician>\n" +
53 " <name>Wynton Marsalis</name>\n" +
54 " <genre>jazz</genre>\n" +
55 " <alive>true</alive>\n" +
56 " </musician>\n" +
57 "</list>";
58
59 assertBothWays(jazzIcons, expectedXml);
60 }
61
62 public void testYesNoValues() {
63 List jazzIcons = new ArrayList();
64 jazzIcons.add(new Musican("Miles Davis", "jazz", false));
65 jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
66
67 xstream.alias("musician", Musican.class);
68 xstream.registerConverter(BooleanConverter.YES_NO);
69
70 String expectedXml =
71 "<list>\n" +
72 " <musician>\n" +
73 " <name>Miles Davis</name>\n" +
74 " <genre>jazz</genre>\n" +
75 " <alive>no</alive>\n" +
76 " </musician>\n" +
77 " <musician>\n" +
78 " <name>Wynton Marsalis</name>\n" +
79 " <genre>jazz</genre>\n" +
80 " <alive>yes</alive>\n" +
81 " </musician>\n" +
82 "</list>";
83
84 assertBothWays(jazzIcons, expectedXml);
85 }
86
87 public void testBinaryValues() {
88 List jazzIcons = new ArrayList();
89 jazzIcons.add(new Musican("Miles Davis", "jazz", false));
90 jazzIcons.add(new Musican("Wynton Marsalis", "jazz", true));
91
92 xstream.alias("musician", Musican.class);
93 xstream.registerConverter(BooleanConverter.BINARY);
94
95 String expectedXml =
96 "<list>\n" +
97 " <musician>\n" +
98 " <name>Miles Davis</name>\n" +
99 " <genre>jazz</genre>\n" +
100 " <alive>0</alive>\n" +
101 " </musician>\n" +
102 " <musician>\n" +
103 " <name>Wynton Marsalis</name>\n" +
104 " <genre>jazz</genre>\n" +
105 " <alive>1</alive>\n" +
106 " </musician>\n" +
107 "</list>";
108
109 assertBothWays(jazzIcons, expectedXml);
110 }
111
112 }
0 /*
1 * Copyright (C) 2008 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 28. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.core.JVM;
13
14 import junit.framework.TestSuite;
15
16 import javax.imageio.ImageIO;
17
18 import java.awt.Color;
19 import java.awt.Graphics2D;
20 import java.awt.image.BufferedImage;
21 import java.awt.image.RenderedImage;
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24
25
26 /**
27 * Tests with buffered images.
28 *
29 * Note, these tests are deactivated by default. They normally work at first sight, but they are highly dangerous,
30 * since some of the serialized objects contain member variables that reference native memory. Typical result is
31 * a JVM crash somewhat later because of double freed memory.
32 *
33 * @author J&ouml;rg Schaible
34 */
35 public class BufferedImagesTest extends AbstractAcceptanceTest {
36
37 public static TestSuite suite() {
38 final TestSuite suite = new TestSuite("BufferedImagesSuite");
39 //suite.addTestSuite(BufferedImagesTest.class);
40 return suite;
41 }
42
43 public void testInBWCanBeMarshalled() throws IOException {
44 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
45 if (!isHeadless || JVM.is15()) {
46 final BufferedImage image = new BufferedImage(3, 3, BufferedImage.TYPE_BYTE_BINARY);
47 final Graphics2D graphics = image.createGraphics();
48 graphics.setBackground(Color.WHITE);
49 graphics.clearRect(0, 0, 2, 2);
50 graphics.setColor(Color.BLACK);
51 graphics.drawLine(0, 0, 2, 2);
52
53 final ByteArrayOutputStream baosOriginal = new ByteArrayOutputStream();
54 ImageIO.write(image, "tiff", baosOriginal);
55
56 xstream.alias("image", BufferedImage.class);
57 final String xml = xstream.toXML(image);
58
59 final ByteArrayOutputStream baosSerialized = new ByteArrayOutputStream();
60 ImageIO.write((RenderedImage)xstream.fromXML(xml), "tiff", baosSerialized);
61
62 assertArrayEquals(baosOriginal.toByteArray(), baosSerialized.toByteArray());
63 }
64 }
65
66 public void testInRGBACanBeMarshalled() throws IOException {
67 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
68 if (!isHeadless || JVM.is15()) {
69 final BufferedImage image = new BufferedImage(3, 3, BufferedImage.TYPE_INT_ARGB);
70 final Graphics2D graphics = image.createGraphics();
71 graphics.setBackground(Color.WHITE);
72 graphics.clearRect(0, 0, 2, 2);
73 graphics.setColor(Color.RED);
74 graphics.drawLine(0, 0, 2, 2);
75
76 final ByteArrayOutputStream baosOriginal = new ByteArrayOutputStream();
77 ImageIO.write(image, "png", baosOriginal);
78
79 xstream.alias("image", BufferedImage.class);
80 final String xml = xstream.toXML(image);
81
82 final ByteArrayOutputStream baosSerialized = new ByteArrayOutputStream();
83 ImageIO.write((RenderedImage)xstream.fromXML(xml), "png", baosSerialized);
84
85 assertArrayEquals(baosOriginal.toByteArray(), baosSerialized.toByteArray());
86 }
87 }
88 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2014 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 08. April 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.reflection.CGLIBEnhancedConverter;
15 import com.thoughtworks.xstream.core.JVM;
16 import com.thoughtworks.xstream.mapper.CGLIBMapper;
17 import com.thoughtworks.xstream.mapper.MapperWrapper;
18 import com.thoughtworks.xstream.security.CGLIBProxyTypePermission;
19
20 import net.sf.cglib.proxy.Callback;
21 import net.sf.cglib.proxy.CallbackFilter;
22 import net.sf.cglib.proxy.Dispatcher;
23 import net.sf.cglib.proxy.Enhancer;
24 import net.sf.cglib.proxy.Factory;
25 import net.sf.cglib.proxy.InvocationHandler;
26 import net.sf.cglib.proxy.MethodInterceptor;
27 import net.sf.cglib.proxy.MethodProxy;
28 import net.sf.cglib.proxy.NoOp;
29
30 import java.io.Serializable;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.Method;
33 import java.net.MalformedURLException;
34 import java.net.URL;
35 import java.util.HashMap;
36 import java.util.Map;
37
38
39 /**
40 * @author J&ouml;rg Schaible
41 */
42 public class CglibCompatibilityTest extends AbstractAcceptanceTest {
43
44 protected XStream createXStream() {
45 XStream xstream = new XStream(createDriver()) {
46 protected MapperWrapper wrapMapper(MapperWrapper next) {
47 return new CGLIBMapper(next);
48 }
49 };
50 setupSecurity(xstream);
51 xstream.addPermission(CGLIBProxyTypePermission.PROXIES);
52 xstream.registerConverter(new CGLIBEnhancedConverter(xstream.getMapper(), xstream
53 .getReflectionProvider(), xstream.getClassLoaderReference()));
54 return xstream;
55 }
56
57 public static class DelegatingHandler implements InvocationHandler, Serializable {
58 private Object delegate;
59
60 public DelegatingHandler(Object delegate) {
61 this.delegate = delegate;
62 }
63
64 public Object invoke(Object obj, Method method, Object[] args) throws Throwable {
65 return method.invoke(delegate, args);
66 }
67 }
68
69 public static class DelegatingInterceptor implements MethodInterceptor, Serializable,
70 Runnable {
71 private Object delegate;
72
73 public DelegatingInterceptor(Object delegate) {
74 this.delegate = delegate;
75 }
76
77 public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
78 throws Throwable {
79 return method.invoke(delegate, args);
80 }
81
82 public void run() {
83 }
84 }
85
86 public static class DelegatingDispatcher implements Dispatcher, Serializable {
87 private Object delegate;
88
89 public DelegatingDispatcher(Object delegate) {
90 this.delegate = delegate;
91 }
92
93 public Object loadObject() throws Exception {
94 return delegate;
95 }
96 }
97
98 public void testSupportsClassBasedProxiesWithFactory()
99 throws NullPointerException, MalformedURLException {
100 final Enhancer enhancer = new Enhancer();
101 enhancer.setSuperclass(HashMap.class);
102 enhancer.setCallback(new DelegatingHandler(new HashMap()));
103 enhancer.setUseFactory(true); // true by default
104 final Map orig = (Map)enhancer.create();
105 final URL url = new URL("http://xstream.codehaus.org");
106 orig.put("URL", url);
107 final String xml = ""
108 + "<CGLIB-enhanced-proxy>\n"
109 + " <type>java.util.HashMap</type>\n"
110 + " <interfaces/>\n"
111 + " <hasFactory>true</hasFactory>\n"
112 + " <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
113 + " <delegate class=\"map\">\n"
114 + " <entry>\n"
115 + " <string>URL</string>\n"
116 + " <url>http://xstream.codehaus.org</url>\n"
117 + " </entry>\n"
118 + " </delegate>\n"
119 + " </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
120 + "</CGLIB-enhanced-proxy>";
121
122 final Map serialized = (Map)assertBothWays(orig, xml);
123 assertEquals(url, serialized.get("URL"));
124 }
125
126 public void testSupportsClassBasedProxiesWithoutFactory()
127 throws NullPointerException, MalformedURLException {
128 final Enhancer enhancer = new Enhancer();
129 enhancer.setSuperclass(HashMap.class);
130 enhancer.setCallback(new DelegatingHandler(new HashMap()));
131 enhancer.setUseFactory(false);
132 final Map orig = (Map)enhancer.create();
133 final URL url = new URL("http://xstream.codehaus.org");
134 orig.put("URL", url);
135 final String xml = ""
136 + "<CGLIB-enhanced-proxy>\n"
137 + " <type>java.util.HashMap</type>\n"
138 + " <interfaces/>\n"
139 + " <hasFactory>false</hasFactory>\n"
140 + " <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
141 + " <delegate class=\"map\">\n"
142 + " <entry>\n"
143 + " <string>URL</string>\n"
144 + " <url>http://xstream.codehaus.org</url>\n"
145 + " </entry>\n"
146 + " </delegate>\n"
147 + " </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
148 + "</CGLIB-enhanced-proxy>";
149
150 final Map serialized = (Map)assertBothWays(orig, xml);
151 assertEquals(url, serialized.get("URL"));
152 }
153
154 public void testSupportForClassBasedProxyWithAdditionalInterface()
155 throws NullPointerException {
156 final Enhancer enhancer = new Enhancer();
157 enhancer.setSuperclass(HashMap.class);
158 enhancer.setCallback(NoOp.INSTANCE);
159 enhancer.setInterfaces(new Class[]{Runnable.class});
160 final Map orig = (Map)enhancer.create();
161 final String xml = ""
162 + "<CGLIB-enhanced-proxy>\n"
163 + " <type>java.util.HashMap</type>\n"
164 + " <interfaces>\n"
165 + " <java-class>java.lang.Runnable</java-class>\n"
166 + " </interfaces>\n"
167 + " <hasFactory>true</hasFactory>\n"
168 + " <net.sf.cglib.proxy.NoOp_-1/>\n"
169 + "</CGLIB-enhanced-proxy>";
170
171 final Object serialized = assertBothWays(orig, xml);
172 assertTrue(serialized instanceof HashMap);
173 assertTrue(serialized instanceof Map);
174 assertTrue(serialized instanceof Runnable);
175 }
176
177 public void testSupportsProxiesWithMultipleInterfaces() throws NullPointerException {
178 final Enhancer enhancer = new Enhancer();
179 enhancer.setCallback(NoOp.INSTANCE);
180 enhancer.setInterfaces(new Class[]{Map.class, Runnable.class});
181 final Map orig = (Map)enhancer.create();
182 final String xml = ""
183 + "<CGLIB-enhanced-proxy>\n"
184 + " <type>java.lang.Object</type>\n"
185 + " <interfaces>\n"
186 + " <java-class>java.util.Map</java-class>\n"
187 + " <java-class>java.lang.Runnable</java-class>\n"
188 + " </interfaces>\n"
189 + " <hasFactory>true</hasFactory>\n"
190 + " <net.sf.cglib.proxy.NoOp_-1/>\n"
191 + "</CGLIB-enhanced-proxy>";
192
193 final Object serialized = assertBothWays(orig, xml);
194 assertTrue(serialized instanceof Map);
195 assertTrue(serialized instanceof Runnable);
196 }
197
198 public void testSupportProxiesUsingFactoryWithMultipleCallbacks()
199 throws NullPointerException {
200 final Enhancer enhancer = new Enhancer();
201 enhancer.setCallbacks(new Callback[]{
202
203 new DelegatingInterceptor(null), new DelegatingHandler(null),
204 new DelegatingDispatcher(null), NoOp.INSTANCE});
205 enhancer.setCallbackFilter(new CallbackFilter() {
206 int i = 1;
207
208 public int accept(Method method) {
209 if (method.getDeclaringClass() == Runnable.class) {
210 return 0;
211 }
212 return i < 3 ? i++ : i;
213 }
214 });
215 enhancer.setInterfaces(new Class[]{Runnable.class});
216 enhancer.setUseFactory(true);
217 final Runnable orig = (Runnable)enhancer.create();
218 final String xml = xstream.toXML(orig);
219 final Factory deserialized = (Factory)xstream.fromXML(xml);
220 assertTrue("Not a Runnable anymore", deserialized instanceof Runnable);
221 Callback[] callbacks = deserialized.getCallbacks();
222 assertEquals(4, callbacks.length);
223 assertTrue(callbacks[0] instanceof DelegatingInterceptor);
224 assertTrue(callbacks[1] instanceof DelegatingHandler);
225 assertTrue(callbacks[2] instanceof DelegatingDispatcher);
226 assertTrue(callbacks[3] instanceof NoOp);
227 }
228
229 public void testThrowsExceptionForProxiesNotUsingFactoryWithMultipleCallbacks()
230 throws NullPointerException {
231 final Enhancer enhancer = new Enhancer();
232 enhancer.setCallbacks(new Callback[]{
233
234 new DelegatingInterceptor(null), new DelegatingHandler(null),
235 new DelegatingDispatcher(null), NoOp.INSTANCE});
236 enhancer.setCallbackFilter(new CallbackFilter() {
237 int i = 1;
238
239 public int accept(Method method) {
240 if (method.getDeclaringClass() == Runnable.class) {
241 return 0;
242 }
243 return i < 3 ? i++ : i;
244 }
245 });
246 enhancer.setInterfaces(new Class[]{Runnable.class});
247 enhancer.setUseFactory(false);
248 final Runnable orig = (Runnable)enhancer.create();
249 try {
250 xstream.toXML(orig);
251 fail("Thrown " + ConversionException.class.getName() + " expected");
252 } catch (final ConversionException e) {
253
254 }
255 }
256
257 public void testSupportProxiesWithMultipleCallbackSetToNull() throws NullPointerException {
258 final Enhancer enhancer = new Enhancer();
259 enhancer.setSuperclass(HashMap.class);
260 enhancer.setCallback(NoOp.INSTANCE);
261 final HashMap orig = (HashMap)enhancer.create();
262 ((Factory)orig).setCallback(0, null);
263 final String xml = ""
264 + "<CGLIB-enhanced-proxy>\n"
265 + " <type>java.util.HashMap</type>\n"
266 + " <interfaces/>\n"
267 + " <hasFactory>true</hasFactory>\n"
268 + " <null/>\n"
269 + "</CGLIB-enhanced-proxy>";
270
271 assertBothWays(orig, xml);
272 }
273
274 public void testSupportsSerialVersionUID()
275 throws NullPointerException, NoSuchFieldException, IllegalAccessException {
276 final Enhancer enhancer = new Enhancer();
277 enhancer.setCallback(NoOp.INSTANCE);
278 enhancer.setInterfaces(new Class[]{Runnable.class});
279 enhancer.setSerialVersionUID(new Long(20060804L));
280 final Runnable orig = (Runnable)enhancer.create();
281 final String xml = ""
282 + "<CGLIB-enhanced-proxy>\n"
283 + " <type>java.lang.Object</type>\n"
284 + " <interfaces>\n"
285 + " <java-class>java.lang.Runnable</java-class>\n"
286 + " </interfaces>\n"
287 + " <hasFactory>true</hasFactory>\n"
288 + " <net.sf.cglib.proxy.NoOp_-1/>\n"
289 + " <serialVersionUID>20060804</serialVersionUID>\n"
290 + "</CGLIB-enhanced-proxy>";
291
292 final Object serialized = assertBothWays(orig, xml);
293 final Field field = serialized.getClass().getDeclaredField("serialVersionUID");
294 field.setAccessible(true);
295 assertEquals(20060804L, field.getLong(null));
296 }
297
298 public static class InterceptingHandler implements MethodInterceptor {
299
300 public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
301 throws Throwable {
302 return proxy.invokeSuper(obj, args);
303 }
304 }
305
306 private final static String THRESHOLD_PARAM = "$THRESHOLD$";
307 private final static String CAPACITY_PARAM = "$CAPACITY$";
308
309 public void testSupportsInterceptedClassBasedProxies()
310 throws NullPointerException, MalformedURLException {
311 final Enhancer enhancer = new Enhancer();
312 enhancer.setSuperclass(HashMap.class);
313 enhancer.setCallback(new InterceptingHandler());
314 enhancer.setUseFactory(true);
315 final Map orig = (Map)enhancer.create();
316 orig.put("URL", new URL("http://xstream.codehaus.org"));
317 final StringBuffer xml = new StringBuffer(""
318 + "<CGLIB-enhanced-proxy>\n"
319 + " <type>java.util.HashMap</type>\n"
320 + " <interfaces/>\n"
321 + " <hasFactory>true</hasFactory>\n"
322 + " <com.thoughtworks.acceptance.CglibCompatibilityTest_-InterceptingHandler/>\n"
323 + " <instance serialization=\"custom\">\n"
324 + " <unserializable-parents/>\n"
325 + " <map>\n"
326 + " <default>\n"
327 + " <loadFactor>0.75</loadFactor>\n"
328 + " <threshold>$THRESHOLD$</threshold>\n"
329 + " </default>\n"
330 + " <int>$CAPACITY$</int>\n"
331 + " <int>1</int>\n"
332 + " <string>URL</string>\n"
333 + " <url>http://xstream.codehaus.org</url>\n"
334 + " </map>\n"
335 + " </instance>\n"
336 + "</CGLIB-enhanced-proxy>");
337
338 // JDK 1.3 has different threshold and capacity algorithms
339 int idx = xml.toString().indexOf(THRESHOLD_PARAM);
340 xml.replace(idx, idx + THRESHOLD_PARAM.length(), JVM.is14() ? "12" : "8");
341 idx = xml.toString().indexOf(CAPACITY_PARAM);
342 xml.replace(idx, idx + CAPACITY_PARAM.length(), JVM.is14() ? "16" : "11");
343
344 Map serialized = (Map)assertBothWays(orig, xml.toString());
345 assertEquals(orig.toString(), serialized.toString());
346 }
347
348 public static class ClassWithProxyMember {
349 Runnable runnable;
350 Map map;
351 };
352
353 public void testSupportsProxiesAsFieldMember() throws NullPointerException {
354 ClassWithProxyMember expected = new ClassWithProxyMember();
355 xstream.alias("with-proxy", ClassWithProxyMember.class);
356 final Enhancer enhancer = new Enhancer();
357 enhancer.setCallback(NoOp.INSTANCE);
358 enhancer.setInterfaces(new Class[]{Map.class, Runnable.class});
359 final Map orig = (Map)enhancer.create();
360 expected.runnable = (Runnable)orig;
361 expected.map = orig;
362 final String xml = ""
363 + "<with-proxy>\n"
364 + " <runnable class=\"CGLIB-enhanced-proxy\">\n"
365 + " <type>java.lang.Object</type>\n"
366 + " <interfaces>\n"
367 + " <java-class>java.util.Map</java-class>\n"
368 + " <java-class>java.lang.Runnable</java-class>\n"
369 + " </interfaces>\n"
370 + " <hasFactory>true</hasFactory>\n"
371 + " <net.sf.cglib.proxy.NoOp_-1/>\n"
372 + " </runnable>\n"
373 + " <map class=\"CGLIB-enhanced-proxy\" reference=\"../runnable\"/>\n"
374 + "</with-proxy>";
375
376 final Object serialized = assertBothWays(expected, xml);
377 assertTrue(serialized instanceof ClassWithProxyMember);
378 }
379
380 public void testProxyTypeCanBeAliased() throws MalformedURLException {
381 final Enhancer enhancer = new Enhancer();
382 enhancer.setSuperclass(HashMap.class);
383 enhancer.setCallback(new DelegatingHandler(new HashMap()));
384 final Map orig = (Map)enhancer.create();
385 orig.put("URL", new URL("http://xstream.codehaus.org"));
386 xstream.aliasType("cglib", Map.class);
387 final String expected = ""
388 + "<cglib>\n"
389 + " <type>java.util.HashMap</type>\n"
390 + " <interfaces/>\n"
391 + " <hasFactory>true</hasFactory>\n"
392 + " <com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
393 + " <delegate class=\"map\">\n"
394 + " <entry>\n"
395 + " <string>URL</string>\n"
396 + " <url>http://xstream.codehaus.org</url>\n"
397 + " </entry>\n"
398 + " </delegate>\n"
399 + " </com.thoughtworks.acceptance.CglibCompatibilityTest_-DelegatingHandler>\n"
400 + "</cglib>";
401 assertEquals(expected, xstream.toXML(orig));
402 }
403 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013, 2014 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 07. March 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.io.File;
14 import java.net.MalformedURLException;
15 import java.net.URL;
16 import java.net.URLClassLoader;
17
18 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
19
20
21 public class ClassLoaderTest extends AbstractAcceptanceTest {
22
23 public void testAllowsClassLoaderToBeOverriden() throws MalformedURLException {
24 String name = "com.thoughtworks.proxy.kit.SimpleReference";
25 String xml = "<com.thoughtworks.proxy.kit.SimpleReference/>";
26 xstream.allowTypes(new String[]{name});
27 try {
28 xstream.fromXML(xml);
29 fail("Thrown " + CannotResolveClassException.class.getName() + " expected");
30 } catch (final CannotResolveClassException e) {
31 assertEquals(name, e.getMessage());
32 }
33
34 File proxyToys = new File("target/lib/proxytoys-0.2.1.jar");
35 ClassLoader classLoader = new URLClassLoader(
36 new URL[]{proxyToys.toURI().toURL()}, getClass().getClassLoader());
37 // will not work, since class has already been cached
38 xstream.setClassLoader(classLoader);
39
40 try {
41 xstream.fromXML(xml);
42 fail("Thrown " + CannotResolveClassException.class.getName() + " expected");
43 } catch (final CannotResolveClassException e) {
44 assertEquals(name, e.getMessage());
45 }
46
47 xstream = createXStream();
48 xstream.setClassLoader(classLoader);
49 xstream.allowTypes(new String[]{name});
50 assertEquals(name, xstream.fromXML(xml).getClass().getName());
51
52 xstream = createXStream();
53 xstream.allowTypes(new String[]{name});
54 try {
55 xstream.fromXML(xml);
56 fail("Thrown " + CannotResolveClassException.class.getName() + " expected");
57 } catch (final CannotResolveClassException e) {
58 assertEquals(name, e.getMessage());
59 }
60 }
61 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 01. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Hardware;
14 import com.thoughtworks.acceptance.objects.SampleLists;
15 import com.thoughtworks.acceptance.objects.Software;
16 import com.thoughtworks.xstream.XStream;
17 import com.thoughtworks.xstream.core.JVM;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.LinkedHashSet;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Properties;
30 import java.util.Set;
31 import java.util.Vector;
32
33 public class CollectionsTest extends AbstractAcceptanceTest {
34
35 public void testListsCanContainCustomObjects() {
36 SampleLists lists = new SampleLists();
37 lists.good.add(new Software("apache", "geronimo"));
38 lists.good.add(new Software("caucho", "resin"));
39 lists.good.add(new Hardware("risc", "strong-arm"));
40 lists.bad.add(new Software("apache", "jserv"));
41
42 xstream.alias("lists", SampleLists.class);
43 xstream.alias("software", Software.class);
44 xstream.alias("hardware", Hardware.class);
45
46 String expected = "" +
47 "<lists>\n" +
48 " <good>\n" +
49 " <software>\n" +
50 " <vendor>apache</vendor>\n" +
51 " <name>geronimo</name>\n" +
52 " </software>\n" +
53 " <software>\n" +
54 " <vendor>caucho</vendor>\n" +
55 " <name>resin</name>\n" +
56 " </software>\n" +
57 " <hardware>\n" +
58 " <arch>risc</arch>\n" +
59 " <name>strong-arm</name>\n" +
60 " </hardware>\n" +
61 " </good>\n" +
62 " <bad class=\"list\">\n" +
63 " <software>\n" +
64 " <vendor>apache</vendor>\n" +
65 " <name>jserv</name>\n" +
66 " </software>\n" +
67 " </bad>\n" +
68 "</lists>";
69
70 assertBothWays(lists, expected);
71 }
72
73 public void testListsCanContainBasicObjects() {
74 SampleLists lists = new SampleLists();
75 lists.good.add("hello");
76 lists.good.add(new Integer(3));
77 lists.good.add(Boolean.TRUE);
78
79 xstream.alias("lists", SampleLists.class);
80
81 String expected = "" +
82 "<lists>\n" +
83 " <good>\n" +
84 " <string>hello</string>\n" +
85 " <int>3</int>\n" +
86 " <boolean>true</boolean>\n" +
87 " </good>\n" +
88 " <bad class=\"list\"/>\n" +
89 "</lists>";
90
91 assertBothWays(lists, expected);
92 }
93
94 public void testListCanBeRootObject() {
95 Collection list = new ArrayList();
96 list.add("hi");
97 list.add("bye");
98
99 String expected = "" +
100 "<list>\n" +
101 " <string>hi</string>\n" +
102 " <string>bye</string>\n" +
103 "</list>";
104
105 assertBothWays(list, expected);
106 }
107
108 public void testSetCanBeRootObject() {
109 Collection set = new HashSet();
110 set.add("hi");
111 set.add("bye");
112
113 String expected = "" +
114 "<set>\n" +
115 " <string>hi</string>\n" +
116 " <string>bye</string>\n" +
117 "</set>";
118
119 assertBothWaysNormalized(set, expected, "set", "string", null);
120 }
121
122 public void testVector() {
123 Vector vector = new Vector();
124 vector.addElement("a");
125 vector.addElement("b");
126
127 assertBothWays(vector,
128 "<vector>\n" +
129 " <string>a</string>\n" +
130 " <string>b</string>\n" +
131 "</vector>");
132 }
133
134 public void testSyncronizedList() {
135 final String xml;
136 if (JVM.is15()) {
137 xml =
138 "<java.util.Collections_-SynchronizedList serialization=\"custom\">\n" +
139 " <java.util.Collections_-SynchronizedCollection>\n" +
140 " <default>\n" +
141 " <c class=\"linked-list\">\n" +
142 " <string>hi</string>\n" +
143 " </c>\n" +
144 " <mutex class=\"java.util.Collections$SynchronizedList\" reference=\"../../..\"/>\n" +
145 " </default>\n" +
146 " </java.util.Collections_-SynchronizedCollection>\n" +
147 " <java.util.Collections_-SynchronizedList>\n" +
148 " <default>\n" +
149 " <list class=\"linked-list\" reference=\"../../../java.util.Collections_-SynchronizedCollection/default/c\"/>\n" +
150 " </default>\n" +
151 " </java.util.Collections_-SynchronizedList>\n" +
152 "</java.util.Collections_-SynchronizedList>";
153 } else {
154 xml =
155 "<java.util.Collections_-SynchronizedList>\n" +
156 " <c class=\"linked-list\">\n" +
157 " <string>hi</string>\n" +
158 " </c>\n" +
159 " <mutex class=\"java.util.Collections$SynchronizedList\" reference=\"..\"/>\n" +
160 " <list class=\"linked-list\" reference=\"../c\"/>\n" +
161 "</java.util.Collections_-SynchronizedList>";
162 }
163
164 // synchronized list has circular reference
165 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
166
167 List list = Collections.synchronizedList(new LinkedList());
168 list.add("hi");
169
170 assertBothWays(list, xml);
171 }
172
173 public void testSyncronizedArrayList() {
174 final String xml;
175 if (JVM.is15()) {
176 xml =
177 "<java.util.Collections_-SynchronizedRandomAccessList resolves-to=\"java.util.Collections$SynchronizedList\" serialization=\"custom\">\n" +
178 " <java.util.Collections_-SynchronizedCollection>\n" +
179 " <default>\n" +
180 " <c class=\"list\">\n" +
181 " <string>hi</string>\n" +
182 " </c>\n" +
183 " <mutex class=\"java.util.Collections$SynchronizedList\" reference=\"../../..\"/>\n" +
184 " </default>\n" +
185 " </java.util.Collections_-SynchronizedCollection>\n" +
186 " <java.util.Collections_-SynchronizedList>\n" +
187 " <default>\n" +
188 " <list reference=\"../../../java.util.Collections_-SynchronizedCollection/default/c\"/>\n" +
189 " </default>\n" +
190 " </java.util.Collections_-SynchronizedList>\n" +
191 "</java.util.Collections_-SynchronizedRandomAccessList>";
192 } else {
193 xml =
194 "<java.util.Collections_-SynchronizedRandomAccessList resolves-to=\"java.util.Collections$SynchronizedList\">\n" +
195 " <c class=\"list\">\n" +
196 " <string>hi</string>\n" +
197 " </c>\n" +
198 " <mutex class=\"java.util.Collections$SynchronizedList\" reference=\"..\"/>\n" +
199 " <list reference=\"../c\"/>\n" +
200 "</java.util.Collections_-SynchronizedRandomAccessList>";
201 }
202
203 // synchronized list has circular reference
204 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
205
206 List list = Collections.synchronizedList(new ArrayList());
207 list.add("hi");
208
209 assertBothWays(list, xml);
210 }
211
212 public void testEmptyList() {
213 assertBothWays(Collections.EMPTY_LIST, "<empty-list/>");
214 }
215
216 public void testEmptySet() {
217 assertBothWays(Collections.EMPTY_SET, "<empty-set/>");
218 }
219
220 public void testEmptyListIsImmutable() {
221 List list = new ArrayList();
222 list.add(Collections.EMPTY_LIST);
223 list.add(Collections.EMPTY_LIST);
224 assertBothWays(list,
225 "<list>\n" +
226 " <empty-list/>\n" +
227 " <empty-list/>\n" +
228 "</list>");
229 }
230
231 public void testEmptySetIsImmutable() {
232 List list = new ArrayList();
233 list.add(Collections.EMPTY_SET);
234 list.add(Collections.EMPTY_SET);
235 assertBothWays(list,
236 "<list>\n" +
237 " <empty-set/>\n" +
238 " <empty-set/>\n" +
239 "</list>");
240 }
241
242 public void testEmptyListIsSingleton() {
243 assertSame(Collections.EMPTY_LIST, xstream.fromXML("<empty-list/>"));
244 }
245
246 public void testEmptySetIsSingleton() {
247 assertSame(Collections.EMPTY_SET, xstream.fromXML("<empty-set/>"));
248 }
249
250 public void testSingletonList() {
251 assertBothWays(Collections.singletonList("XStream"),
252 "<singleton-list>\n" +
253 " <string>XStream</string>\n" +
254 "</singleton-list>");
255 }
256
257 public void testSingletonSet() {
258 assertBothWays(Collections.singleton("XStream"),
259 "<singleton-set>\n" +
260 " <string>XStream</string>\n" +
261 "</singleton-set>");
262 }
263
264 public void testPropertiesWithDefaults() {
265 Properties defaults = new Properties();
266 defaults.setProperty("1", "one");
267 defaults.setProperty("2", "two");
268 Properties properties = new Properties(defaults);
269 properties.setProperty("1", "I");
270 properties.setProperty("3", "III");
271
272 assertBothWays(properties,
273 "<properties>\n" +
274 " <property name=\"3\" value=\"III\"/>\n" +
275 " <property name=\"1\" value=\"I\"/>\n" +
276 " <defaults>\n" +
277 " <property name=\"2\" value=\"two\"/>\n" +
278 " <property name=\"1\" value=\"one\"/>\n" +
279 " </defaults>\n" +
280 "</properties>");
281 }
282
283 public void testUnmodifiableList() {
284 // unmodifiable list has duplicate references
285 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
286
287 List list = new ArrayList();
288 list.add("hi");
289 list = Collections.unmodifiableList(list);
290
291 assertBothWays(list,
292 "<java.util.Collections_-UnmodifiableRandomAccessList resolves-to=\"java.util.Collections$UnmodifiableList\">\n" +
293 " <c class=\"list\">\n" +
294 " <string>hi</string>\n" +
295 " </c>\n" +
296 " <list reference=\"../c\"/>\n" +
297 "</java.util.Collections_-UnmodifiableRandomAccessList>");
298 }
299
300 public void testLinkedHashSetRetainsOrdering() {
301 Set set = new LinkedHashSet();
302 set.add("Z");
303 set.add("C");
304 set.add("X");
305
306 LinkedHashSet result = (LinkedHashSet) assertBothWays(set,
307 "<linked-hash-set>\n" +
308 " <string>Z</string>\n" +
309 " <string>C</string>\n" +
310 " <string>X</string>\n" +
311 "</linked-hash-set>");
312
313 Object[] values = result.toArray();
314 assertEquals("Z", values[0]);
315 assertEquals("C", values[1]);
316 assertEquals("X", values[2]);
317 }
318
319 public void testListFromArrayAsList() {
320 List list = Arrays.asList(new String[] {"hi", "bye"});
321
322 assertBothWays(list,
323 "<java.util.Arrays_-ArrayList>\n" +
324 " <a class=\"string-array\">\n" +
325 " <string>hi</string>\n" +
326 " <string>bye</string>\n" +
327 " </a>\n" +
328 "</java.util.Arrays_-ArrayList>");
329 }
330
331 public void testKeySetOfHashMapCanBeSerialized() {
332 final Map map = new HashMap();
333 map.put("JUnit", null);
334 final Collection set = map.keySet();
335
336 xstream.alias("key-set", set.getClass());
337
338 assertBothWays(set,
339 "<key-set>\n" +
340 " <outer-class>\n" +
341 " <entry>\n" +
342 " <string>JUnit</string>\n" +
343 " <null/>\n" +
344 " </entry>\n" +
345 " </outer-class>\n" +
346 "</key-set>");
347 }
348
349 public void testValueSetOfHashMapCanBeSerialized() {
350 final Map map = new HashMap();
351 map.put(Boolean.TRUE, "JUnit");
352 final Collection set = map.values();
353 xstream.alias("value-set", set.getClass());
354
355 assertBothWays(set,
356 "<value-set>\n" +
357 " <outer-class>\n" +
358 " <entry>\n" +
359 " <boolean>true</boolean>\n" +
360 " <string>JUnit</string>\n" +
361 " </entry>\n" +
362 " </outer-class>\n" +
363 "</value-set>");
364 }
365
366 public void testEntrySetOfHashMapCanBeSerialized() {
367 final Map map = new HashMap();
368 map.put(Boolean.TRUE, "JUnit");
369 final Collection set = map.entrySet();
370 xstream.alias("entry-set", set.getClass());
371
372 if (JVM.is16() && System.getProperty("java.vm.vendor").indexOf("IBM") >= 0) {
373 assertBothWays(set,
374 "<entry-set>\n" +
375 " <associatedMap>\n" +
376 " <entry>\n" +
377 " <boolean>true</boolean>\n" +
378 " <string>JUnit</string>\n" +
379 " </entry>\n" +
380 " </associatedMap>\n" +
381 "</entry-set>");
382 } else {
383 assertBothWays(set,
384 "<entry-set>\n" +
385 " <outer-class>\n" +
386 " <entry>\n" +
387 " <boolean>true</boolean>\n" +
388 " <string>JUnit</string>\n" +
389 " </entry>\n" +
390 " </outer-class>\n" +
391 "</entry-set>");
392 }
393 }
394 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.acceptance.someobjects.WithList;
15 import com.thoughtworks.xstream.converters.ConversionException;
16
17 import java.util.ArrayList;
18 import java.util.LinkedList;
19
20 public class ConcreteClassesTest extends AbstractAcceptanceTest {
21
22 public void testDefaultImplementationOfInterface() {
23
24 xstream.alias("with-list", WithList.class);
25
26 WithList withList = new WithList();
27 withList.things = new ArrayList();
28
29 String expected =
30 "<with-list>\n" +
31 " <things/>\n" +
32 "</with-list>";
33
34 assertBothWays(withList, expected);
35
36 }
37
38 public void testAlternativeImplementationOfInterface() {
39
40 xstream.alias("with-list", WithList.class);
41 xstream.alias("linked-list", LinkedList.class);
42
43 WithList withList = new WithList();
44 withList.things = new LinkedList();
45
46 String expected =
47 "<with-list>\n" +
48 " <things class=\"linked-list\"/>\n" +
49 "</with-list>";
50
51 assertBothWays(withList, expected);
52
53 }
54
55 interface MyInterface {
56 }
57
58 public static class MyImp1 extends StandardObject implements MyInterface {
59 int x = 1;
60 }
61
62 public static class MyImp2 extends StandardObject implements MyInterface {
63 int y = 2;
64 }
65
66 public static class MyHolder extends StandardObject {
67 MyInterface field1;
68 MyInterface field2;
69 }
70
71 public void testCustomInterfaceCanHaveMultipleImplementations() {
72 xstream.alias("intf", MyInterface.class);
73 xstream.alias("imp1", MyImp1.class);
74 xstream.alias("imp2", MyImp2.class);
75 xstream.alias("h", MyHolder.class);
76
77 MyHolder in = new MyHolder();
78 in.field1 = new MyImp1();
79 in.field2 = new MyImp2();
80
81 String expected = "" +
82 "<h>\n" +
83 " <field1 class=\"imp1\">\n" +
84 " <x>1</x>\n" +
85 " </field1>\n" +
86 " <field2 class=\"imp2\">\n" +
87 " <y>2</y>\n" +
88 " </field2>\n" +
89 "</h>";
90
91 String xml = xstream.toXML(in);
92 assertEquals(expected, xml);
93
94 MyHolder out = (MyHolder) xstream.fromXML(xml);
95 assertEquals(MyImp1.class, out.field1.getClass());
96 assertEquals(MyImp2.class, out.field2.getClass());
97 assertEquals(2, ((MyImp2) out.field2).y);
98 }
99
100 public void testUnknownChildMatchingATypeThrowsConversionException() {
101 xstream.alias("h", MyHolder.class);
102
103 String xml = ""
104 + "<h>\n"
105 + " <int>100</int>\n"
106 + "</h>";
107
108 try {
109 xstream.fromXML(xml);
110 fail("Thrown " + ConversionException.class.getName() + " expected");
111 } catch (final ConversionException e) {
112 // ok
113 }
114 }
115 }
0 /*
1 * Copyright (C) 2006, 2007 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 22. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.Arrays;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16
17 import com.thoughtworks.acceptance.objects.Software;
18 import com.thoughtworks.acceptance.someobjects.WithNamedList;
19
20
21 /**
22 * @author J&ouml;rg Schaible
23 */
24 public class ConcurrencyTest extends AbstractAcceptanceTest {
25
26 public void testConcurrentXStreaming() throws InterruptedException {
27 xstream.alias("thing", WithNamedList.class);
28 xstream.addImplicitCollection(WithNamedList.class, "things");
29
30 final List reference = Arrays.asList(new String[]{"A", "B", "C", "D"});
31 final WithNamedList[] namedLists = new WithNamedList[5];
32 for (int i = 0; i < namedLists.length; ++i) {
33 namedLists[i] = new WithNamedList("Name " + (i + 1));
34 namedLists[i].things.add(new Software("walnes", "XStream 1." + i));
35 namedLists[i].things.add(reference);
36 namedLists[i].things.add(new RuntimeException("JUnit " + i)); // a Serializable
37 }
38
39 final Map exceptions = new HashMap();
40 final ThreadGroup tg = new ThreadGroup(getName()) {
41 public void uncaughtException(Thread t, Throwable e) {
42 exceptions.put(e, t.getName());
43 super.uncaughtException(t, e);
44 }
45 };
46
47 final Object object = Arrays.asList(namedLists);
48 final String xml = xstream.toXML(object);
49 final int[] counter = new int[1];
50 counter[0] = 0;
51 final Thread[] threads = new Thread[5];
52 for (int i = 0; i < threads.length; ++i) {
53 threads[i] = new Thread(tg, "JUnit Thread " + i) {
54
55 public void run() {
56 int i = 0;
57 try {
58 synchronized (this) {
59 notifyAll();
60 wait();
61 }
62 while (!interrupted()) {
63 assertBothWays(object, xml);
64 ++i;
65 }
66 } catch (InterruptedException e) {
67 fail("Unexpected InterruptedException");
68 }
69 synchronized (counter) {
70 counter[0] += i;
71 }
72 }
73
74 };
75 }
76
77 for (int i = 0; i < threads.length; ++i) {
78 synchronized (threads[i]) {
79 threads[i].start();
80 threads[i].wait();
81 }
82 }
83
84 for (int i = 0; i < threads.length; ++i) {
85 synchronized (threads[i]) {
86 threads[i].notifyAll();
87 }
88 }
89
90 Thread.sleep(1000);
91
92 for (int i = 0; i < threads.length; ++i) {
93 threads[i].interrupt();
94 }
95 for (int i = 0; i < threads.length; ++i) {
96 synchronized (threads[i]) {
97 threads[i].join();
98 }
99 }
100
101 assertEquals("Exceptions has been thrown: " + exceptions, 0, exceptions.size());
102 assertTrue("Each thread should have made at least 1 conversion", counter[0] >= threads.length);
103 }
104 }
0 /*
1 * Copyright (C) 2012, 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. March 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.Map;
13 import java.util.concurrent.ConcurrentHashMap;
14
15 import com.thoughtworks.xstream.core.JVM;
16
17
18 public class Concurrent15TypesTest extends AbstractAcceptanceTest {
19
20 public void testConcurrentHashMap() {
21 ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();
22 map.put("walnes", "joe");
23 String xml = xstream.toXML(map);
24 String expected = ""
25 + "<concurrent-hash-map>\n"
26 + " <entry>\n"
27 + " <string>walnes</string>\n"
28 + " <string>joe</string>\n"
29 + " </entry>\n"
30 + "</concurrent-hash-map>";
31 assertEquals(xml, expected);
32 @SuppressWarnings("unchecked")
33 ConcurrentHashMap<String, String> out = (ConcurrentHashMap<String, String>)xstream.fromXML(xml);
34 assertEquals("{walnes=joe}", out.toString());
35 }
36
37 public static class DerivedConcurrentHashMap extends ConcurrentHashMap<Object, Object> {
38 private static final long serialVersionUID = 1L;
39 }
40
41 public void testDerivedConcurrentHashMap() {
42 if (JVM.is18()) {
43 xstream.alias("derived-map", DerivedConcurrentHashMap.class);
44
45 Map<Object, Object> map = new DerivedConcurrentHashMap();
46 map.put("test", "JUnit");
47
48 String xml = ""
49 + "<derived-map serialization=\"custom\">\n"
50 + " <unserializable-parents/>\n"
51 + " <concurrent-hash-map>\n"
52 + " <default>\n"
53 + " <segmentMask>15</segmentMask>\n"
54 + " </default>\n"
55 + " <string>test</string>\n"
56 + " <string>JUnit</string>\n"
57 + " <null/>\n"
58 + " <null/>\n"
59 + " </concurrent-hash-map>\n"
60 + "</derived-map>";
61
62 assertBothWays(map, xml);
63 }
64 }
65 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
15 import com.thoughtworks.xstream.core.JVM;
16 import com.thoughtworks.xstream.io.xml.XppReader;
17
18 import java.io.StringReader;
19
20 public class CustomClassesTest extends AbstractAcceptanceTest {
21
22 public static class SamplePerson extends StandardObject {
23 int anInt;
24 String firstName;
25 String lastName;
26 transient String aComment = "";
27 }
28
29 public void testCustomObjectWithBasicFields() {
30
31 xstream.alias("friend", SamplePerson.class);
32
33 SamplePerson person = new SamplePerson();
34 person.anInt = 3;
35 person.firstName = "Joe";
36 person.lastName = "Walnes";
37
38 String expected =
39 "<friend>\n" +
40 " <anInt>3</anInt>\n" +
41 " <firstName>Joe</firstName>\n" +
42 " <lastName>Walnes</lastName>\n" +
43 "</friend>";
44
45 assertBothWays(person, expected);
46
47 }
48
49 public static class SamplePersonHolder {
50 String aString;
51 SamplePerson brother;
52
53 public boolean equals(Object obj) {
54 SamplePersonHolder containerObject = (SamplePersonHolder) obj;
55 return (aString == null ? containerObject.aString == null : aString.equals(containerObject.aString))
56 && brother.equals(containerObject.brother);
57 }
58 }
59
60 public void testCustomObjectWithCustomObjectField() {
61 xstream.alias("friend", SamplePerson.class);
62 xstream.alias("personHolder", SamplePersonHolder.class);
63
64 SamplePersonHolder personHolder = new SamplePersonHolder();
65 personHolder.aString = "hello world";
66
67 SamplePerson person = new SamplePerson();
68 person.anInt = 3;
69 person.firstName = "Joe";
70 person.lastName = "Walnes";
71
72 personHolder.brother = person;
73
74 String expected =
75 "<personHolder>\n" +
76 " <aString>hello world</aString>\n" +
77 " <brother>\n" +
78 " <anInt>3</anInt>\n" +
79 " <firstName>Joe</firstName>\n" +
80 " <lastName>Walnes</lastName>\n" +
81 " </brother>\n" +
82 "</personHolder>";
83
84 assertBothWays(personHolder, expected);
85
86 }
87
88 public void testCustomObjectWithCustomObjectFieldsSetToNull() {
89 xstream.alias("friend", SamplePerson.class);
90 xstream.alias("personHolder", SamplePersonHolder.class);
91
92 SamplePersonHolder personHolder = new SamplePersonHolder();
93 personHolder.aString = null;
94
95 SamplePerson person = new SamplePerson();
96 person.anInt = 3;
97 person.firstName = "Joe";
98 person.lastName = null;
99
100 personHolder.brother = person;
101
102 String expected =
103 "<personHolder>\n" +
104 " <brother>\n" +
105 " <anInt>3</anInt>\n" +
106 " <firstName>Joe</firstName>\n" +
107 " </brother>\n" +
108 "</personHolder>";
109
110 assertBothWays(personHolder, expected);
111
112 }
113
114 public void testCustomObjectCanBeInstantiatedExternallyBeforeDeserialization() {
115 xstream.alias("friend", SamplePerson.class);
116 xstream.alias("personHolder", SamplePersonHolder.class);
117
118 String xml =
119 "<personHolder>\n" +
120 " <aString>hello world</aString>\n" +
121 " <brother>\n" +
122 " <anInt>3</anInt>\n" +
123 " <firstName>Joe</firstName>\n" +
124 " <lastName>Walnes</lastName>\n" +
125 " </brother>\n" +
126 "</personHolder>";
127
128 // execute
129 SamplePersonHolder alreadyInstantiated = new SamplePersonHolder();
130 xstream.unmarshal(new XppReader(new StringReader(xml)), alreadyInstantiated);
131
132 // verify
133 SamplePersonHolder expectedResult = new SamplePersonHolder();
134 expectedResult.aString = "hello world";
135
136 SamplePerson expectedPerson = new SamplePerson();
137 expectedPerson.anInt = 3;
138 expectedPerson.firstName = "Joe";
139 expectedPerson.lastName = "Walnes";
140 expectedResult.brother = expectedPerson;
141
142 assertEquals(expectedResult, alreadyInstantiated);
143 }
144
145 public void testCustomObjectWillNotUnmarshalTransientFields() {
146
147 xstream.alias("friend", SamplePerson.class);
148
149 String xml =
150 "<friend>\n" +
151 " <anInt>3</anInt>\n" +
152 " <firstName>Joe</firstName>\n" +
153 " <lastName>Walnes</lastName>\n" +
154 " <aComment>XStream Despot</aComment>\n" +
155 "</friend>";
156
157 SamplePerson person = (SamplePerson)xstream.fromXML(xml);
158 if (JVM.is14()) {
159 assertNull(person.aComment);
160 } else {
161 assertEquals("", person.aComment);
162 }
163 }
164
165 static class Joe extends SamplePerson {
166 boolean aBoolean;
167 }
168
169 public void testCustomObjectWillNotUnmarshalInheritedTransientFields() {
170
171 xstream.alias("joe", Joe.class);
172
173 String xml =
174 "<joe>\n" +
175 " <anInt>3</anInt>\n" +
176 " <firstName>Joe</firstName>\n" +
177 " <lastName>Walnes</lastName>\n" +
178 " <aComment>XStream Despot</aComment>\n" +
179 " <aBoolean>true</aBoolean>\n" +
180 "</joe>";
181
182 Joe joe = (Joe)xstream.fromXML(xml);
183 if (JVM.is14()) {
184 assertNull(joe.aComment);
185 } else {
186 assertEquals("", joe.aComment);
187 }
188 }
189
190 public void testCustomObjectWillNotUnmarshalTransientFieldsFromAttributes() {
191
192 xstream.alias("friend", SamplePerson.class);
193
194 String xml =
195 "<friend aComment='XStream Despot'>\n" +
196 " <anInt>3</anInt>\n" +
197 " <firstName>Joe</firstName>\n" +
198 " <lastName>Walnes</lastName>\n" +
199 "</friend>";
200
201 // without attribute definition
202 SamplePerson person = (SamplePerson)xstream.fromXML(xml);
203 if (JVM.is14()) {
204 assertNull(person.aComment);
205 } else {
206 assertEquals("", person.aComment);
207 }
208
209 xstream.useAttributeFor("aComment", String.class);
210
211 // with attribute definition
212 person = (SamplePerson)xstream.fromXML(xml);
213 if (JVM.is14()) {
214 assertNull(person.aComment);
215 } else {
216 assertEquals("", person.aComment);
217 }
218 }
219
220 public void testNullObjectsDoNotHaveFieldsWritten() {
221
222 xstream.alias("cls", WithSomeFields.class);
223
224 WithSomeFields obj = new WithSomeFields();
225
226 String expected = "<cls/>";
227
228 assertBothWays(obj, expected);
229 }
230
231 public void testEmptyStringsAreNotTreatedAsNulls() {
232 xstream.alias("cls", WithSomeFields.class);
233
234 WithSomeFields obj = new WithSomeFields();
235 obj.b = "";
236
237 String expected = "" +
238 "<cls>\n" +
239 " <b></b>\n" +
240 "</cls>";
241
242 assertBothWays(obj, expected);
243 }
244
245 public static class WithSomeFields extends StandardObject {
246 Object a;
247 String b;
248 }
249
250 public void testNullsAreDistinguishedFromEmptyStrings() {
251 LotsOfStrings in = new LotsOfStrings();
252 in.a = ".";
253 in.b = "";
254 in.c = null;
255
256 String xml = xstream.toXML(in);
257 LotsOfStrings out = (LotsOfStrings) xstream.fromXML(xml);
258
259 assertEquals(".", out.a);
260 assertEquals("", out.b);
261 assertNull(out.c);
262 }
263
264 public static class LotsOfStrings {
265 String a;
266 String b;
267 String c;
268 }
269
270 public void testFieldWithObjectType() {
271 String expected = "" +
272 "<thing>\n" +
273 " <one>1.0</one>\n" +
274 " <two class=\"double\">2.0</two>\n" +
275 "</thing>";
276 xstream.alias("thing", FieldWithObjectType.class);
277
278 assertBothWays(new FieldWithObjectType(), expected);
279 }
280
281 public static class FieldWithObjectType extends StandardObject {
282 Double one = new Double(1.0);
283 Object two = new Double(2.0);
284 }
285
286 public void testFailsFastIfFieldIsDefinedTwice() {
287 String input = "" +
288 "<thing>\n" +
289 " <one>1.0</one>\n" +
290 " <one>2.0</one>\n" +
291 "</thing>";
292 xstream.alias("thing", FieldWithObjectType.class);
293
294 try {
295
296 xstream.fromXML(input);
297 fail("Expected exception");
298
299 } catch (ReflectionConverter.DuplicateFieldException expected) {
300 assertEquals("one", expected.get("field"));
301 }
302 }
303
304 public static class TransientInitializingClass extends StandardObject {
305 private transient String s = "";
306 private Object readResolve() {
307 this.s = "foo";
308 return this;
309 }
310 }
311
312 public void testCustomObjectWithTransientFieldInitialization() {
313
314 xstream.alias("tran", TransientInitializingClass.class);
315
316 TransientInitializingClass tran = new TransientInitializingClass();
317
318 String expected = "<tran/>";
319
320 TransientInitializingClass serialized = (TransientInitializingClass)assertBothWays(tran, expected);
321 assertEquals("foo", serialized.s);
322 }
323 }
0 /*
1 * Copyright (C) 2006, 2007 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 17. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.SingleValueConverter;
14
15 import java.text.DecimalFormat;
16 import java.text.ParseException;
17
18 public class CustomConverterTest extends AbstractAcceptanceTest {
19
20 private final class DoubleConverter implements SingleValueConverter {
21 private final DecimalFormat formatter;
22
23 private DoubleConverter() {
24 formatter = new DecimalFormat("#,###,##0");
25 }
26
27 public boolean canConvert(Class type) {
28 return type == double.class || type == Double.class;
29 }
30
31 public String toString(Object obj) {
32 return this.formatter.format(obj);
33 }
34
35 public Object fromString(String str) {
36 try {
37 // the formatter will chose the most appropriate format ... Long
38 return this.formatter.parseObject(str);
39 } catch (ParseException e) {
40 throw new ConversionException(e);
41 }
42 }
43 }
44
45 public static class DoubleWrapper {
46 Double d;
47
48 public DoubleWrapper(double d) {
49 this.d = new Double(d);
50 }
51
52 protected DoubleWrapper() {
53 // JDK 1.3 issue
54 }
55 }
56
57 public void testWrongObjectTypeReturned() {
58 xstream.alias("dw", DoubleWrapper.class);
59 xstream.registerConverter(new DoubleConverter());
60
61 String xml = "" +
62 "<dw>\n" +
63 " <d>-92.000.000</d>\n" +
64 "</dw>";
65
66 try {
67 xstream.fromXML(xml);
68 fail("Thrown " + ConversionException.class.getName() + " expected");
69 } catch (final ConversionException e) {
70 assertTrue(e.getMessage().indexOf(Long.class.getName()) > 0);
71 }
72 }
73 }
0 /*
1 * Copyright (C) 2007, 2014 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 17. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.reflection.FieldDictionary;
14 import com.thoughtworks.xstream.converters.reflection.FieldKey;
15 import com.thoughtworks.xstream.converters.reflection.FieldKeySorter;
16 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
17
18 import java.util.Comparator;
19 import java.util.Map;
20 import java.util.TreeMap;
21
22
23 /**
24 * @author J&ouml;rg Schaible
25 */
26 public class CustomFieldKeySorterTest extends AbstractAcceptanceTest {
27
28 protected XStream createXStream() {
29 XStream xstream = new XStream(new PureJavaReflectionProvider(new FieldDictionary(
30 new AlphabeticalFieldkeySorter())));
31 setupSecurity(xstream);
32 return xstream;
33 }
34
35 static class Base {
36 String yyy = "y";
37 String ccc = "c";
38 String bbb = "b";
39 }
40
41 static class First extends Base {
42 String aaa = "a";
43 }
44
45 static class Second extends First {
46 String xxx = "x";
47 String zzz = "z";
48 }
49
50 public void testSortsAlphabetically() {
51 xstream.alias("second", Second.class);
52
53 String xml = ""
54 + "<second>\n"
55 + " <aaa>a</aaa>\n"
56 + " <bbb>b</bbb>\n"
57 + " <ccc>c</ccc>\n"
58 + " <xxx>x</xxx>\n"
59 + " <yyy>y</yyy>\n"
60 + " <zzz>z</zzz>\n"
61 + "</second>";
62
63 assertBothWays(new Second(), xml);
64 }
65
66 private static class AlphabeticalFieldkeySorter implements FieldKeySorter {
67
68 public Map sort(Class type, Map keyedByFieldKey) {
69 Map map = new TreeMap(new Comparator() {
70
71 public int compare(Object o1, Object o2) {
72 final FieldKey fieldKey1 = (FieldKey)o1;
73 final FieldKey fieldKey2 = (FieldKey)o2;
74 return fieldKey1.getFieldName().compareTo(fieldKey2.getFieldName());
75 }
76 });
77 map.putAll(keyedByFieldKey);
78 return map;
79 }
80
81 }
82 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 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 06. March 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.LinkedList;
16
17 import com.thoughtworks.acceptance.objects.Software;
18 import com.thoughtworks.acceptance.objects.StandardObject;
19 import com.thoughtworks.acceptance.someobjects.WithList;
20 import com.thoughtworks.xstream.XStream;
21 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
22 import com.thoughtworks.xstream.core.ClassLoaderReference;
23 import com.thoughtworks.xstream.io.xml.DomDriver;
24 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
25 import com.thoughtworks.xstream.mapper.DefaultMapper;
26 import com.thoughtworks.xstream.mapper.Mapper;
27 import com.thoughtworks.xstream.mapper.MapperWrapper;
28
29 public class CustomMapperTest extends AbstractAcceptanceTest {
30
31 /**
32 * A sample mapper strips the underscore prefix of field names in the XML
33 */
34 private static class FieldPrefixStrippingMapper extends MapperWrapper {
35 public FieldPrefixStrippingMapper(Mapper wrapped) {
36 super(wrapped);
37 }
38
39 public String serializedMember(Class type, String memberName) {
40 if (memberName.startsWith("_")) {
41 // _blah -> blah
42 memberName = memberName.substring(1); // chop off leading char (the underscore)
43 } else if (memberName.startsWith("my")) {
44 // myBlah -> blah
45 memberName = memberName.substring(2, 3).toLowerCase() + memberName.substring(3);
46 }
47 return super.serializedMember(type, memberName);
48 }
49
50 public String realMember(Class type, String serialized) {
51 String fieldName = super.realMember(type, serialized);
52 // Not very efficient or elegant, but enough to get the point across.
53 // Luckily the CachingMapper will ensure this is only ever called once per field per class.
54 try {
55 type.getDeclaredField("_" + fieldName);
56 return "_" + fieldName;
57 } catch (NoSuchFieldException e) {
58 try {
59 String myified = "my" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
60 type.getDeclaredField(myified);
61 return myified;
62 } catch (NoSuchFieldException e2) {
63 return fieldName;
64 }
65 }
66 }
67 }
68
69 public static class ThingWithStupidNamingConventions extends StandardObject {
70 String _firstName;
71 String lastName;
72 int myAge;
73
74 public ThingWithStupidNamingConventions(String firstname, String lastname, int age) {
75 _firstName = firstname;
76 this.lastName = lastname;
77 myAge = age;
78 }
79 }
80
81 public void testUserDefinedMappingCanAlterFieldName() {
82 xstream = new XStream() {
83 protected MapperWrapper wrapMapper(MapperWrapper next) {
84 return new FieldPrefixStrippingMapper(next);
85 }
86 };
87 setupSecurity(xstream);
88 xstream.alias("thing", ThingWithStupidNamingConventions.class);
89
90 ThingWithStupidNamingConventions in = new ThingWithStupidNamingConventions("Joe", "Walnes", 10);
91 String expectedXml = ""
92 + "<thing>\n"
93 + " <firstName>Joe</firstName>\n" // look, no underscores!
94 + " <lastName>Walnes</lastName>\n"
95 + " <age>10</age>\n"
96 + "</thing>";
97
98 assertBothWays(in, expectedXml);
99 }
100
101 private static class PackageStrippingMapper extends MapperWrapper {
102 public PackageStrippingMapper(Mapper wrapped) {
103 super(wrapped);
104 }
105
106 public String serializedClass(Class type) {
107 return type.getName().replaceFirst(".*\\.", "");
108 }
109 }
110
111 public void testStripsPackagesUponDeserialization() {
112 // obviously this isn't deserializable!
113 xstream = new XStream() {
114 protected MapperWrapper wrapMapper(MapperWrapper next) {
115 return new PackageStrippingMapper(next);
116 }
117 };
118
119 // NOTE: no aliases defined!
120
121 String expectedXml = "" +
122 "<Software>\n" +
123 " <vendor>ms</vendor>\n" +
124 " <name>word</name>\n" +
125 "</Software>";
126 assertEquals(expectedXml, xstream.toXML(new Software("ms", "word")));
127 }
128
129 public void testOwnMapperChainCanBeRegistered() {
130 ClassLoaderReference classLoaderReference = new ClassLoaderReference(getClass().getClassLoader());
131 Mapper mapper = new DefaultMapper(classLoaderReference);
132 xstream = new XStream(new PureJavaReflectionProvider(), new DomDriver(), getClass().getClassLoader(), mapper);
133
134 String expected = "" +
135 "<com.thoughtworks.acceptance.objects.Software>\n" +
136 " <vendor>ms</vendor>\n" +
137 " <name>word</name>\n" +
138 "</com.thoughtworks.acceptance.objects.Software>";
139 assertEquals(expected, xstream.toXML(new Software("ms", "word")));
140 }
141
142 public void testCanBeUsedToOmitUnexpectedElements() {
143 String expectedXml = "" +
144 "<software>\n" +
145 " <version>1.0</version>\n" +
146 " <vendor>Joe</vendor>\n" +
147 " <name>XStream</name>\n" +
148 "</software>";
149
150 xstream = new XStream() {
151
152 protected MapperWrapper wrapMapper(MapperWrapper next) {
153 return new MapperWrapper(next) {
154
155 public boolean shouldSerializeMember(Class definedIn, String fieldName) {
156 return definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false;
157 }
158
159 };
160 }
161
162 };
163 setupSecurity(xstream);
164 xstream.alias("software", Software.class);
165
166 Software out = (Software) xstream.fromXML(expectedXml);
167 assertEquals("Joe", out.vendor);
168 assertEquals("XStream", out.name);
169 }
170
171 public void testInjectingReplacements() {
172 XStream xstream = new XStream() {
173
174 protected MapperWrapper wrapMapper(MapperWrapper next) {
175 return new MapperWrapper(next) {
176 public Class realClass(String elementName) {
177 try {
178 return super.realClass(elementName);
179
180 } catch (CannotResolveClassException e) {
181 if (elementName.endsWith("oo")) {
182 return Integer.class;
183 }
184 if (elementName.equals("UnknownList")) {
185 return LinkedList.class;
186 }
187 throw e;
188 }
189 }
190
191 };
192 }
193
194 };
195 setupSecurity(xstream);
196 xstream.alias("wl", WithList.class);
197 WithList wl = (WithList)xstream.fromXML(""
198 + "<wl>\n"
199 + " <things class='UnknownList'>\n"
200 + " <foo>1</foo>\n"
201 + " <cocoo>2</cocoo>\n"
202 + " </things>\n"
203 + "</wl>");
204 assertEquals(new ArrayList(Arrays.asList(new Integer[]{new Integer(1), new Integer(2)})), wl.things);
205 assertTrue(wl.things instanceof LinkedList);
206 }
207 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2015 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 23. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Hardware;
14 import com.thoughtworks.acceptance.objects.Software;
15 import com.thoughtworks.acceptance.objects.StandardObject;
16
17 import java.io.IOException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectOutputStream;
20 import java.io.ObjectStreamField;
21 import java.io.Serializable;
22
23 public class CustomSerializationTest extends AbstractAcceptanceTest {
24
25 public static class ObjectWithCustomSerialization extends StandardObject implements Serializable {
26
27 private int a;
28 private transient int b;
29 private transient String c;
30 private transient Object d;
31 private transient Software e;
32
33 public ObjectWithCustomSerialization() {
34 }
35
36 public ObjectWithCustomSerialization(int a, int b, String c, Software e) {
37 this.a = a;
38 this.b = b;
39 this.c = c;
40 this.e = e;
41 }
42
43 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
44 b = in.readInt();
45 in.defaultReadObject();
46 c = (String) in.readObject();
47 d = in.readObject();
48 e = (Software) in.readObject();
49 }
50
51 private void writeObject(ObjectOutputStream out) throws IOException {
52 out.writeInt(b);
53 out.defaultWriteObject();
54 out.writeObject(c);
55 out.writeObject(d);
56 out.writeObject(e);
57 }
58
59 }
60
61 public void testWritesCustomFieldsToStream() {
62 ObjectWithCustomSerialization obj = new ObjectWithCustomSerialization(1, 2, "hello", new Software("tw", "xs"));
63 xstream.alias("custom", ObjectWithCustomSerialization.class);
64 xstream.alias("software", Software.class);
65
66 String expectedXml = ""
67 + "<custom serialization=\"custom\">\n"
68 + " <custom>\n"
69 + " <int>2</int>\n"
70 + " <default>\n"
71 + " <a>1</a>\n"
72 + " </default>\n"
73 + " <string>hello</string>\n"
74 + " <null/>\n"
75 + " <software>\n"
76 + " <vendor>tw</vendor>\n"
77 + " <name>xs</name>\n"
78 + " </software>\n"
79 + " </custom>\n"
80 + "</custom>";
81
82 assertBothWays(obj, expectedXml);
83 }
84
85 public static class Parent extends StandardObject implements Serializable {
86
87 private transient int parentA;
88 private int parentB;
89 private transient int parentC;
90
91 public Parent() {
92 }
93
94 public Parent(int parentA, int parentB, int parentC) {
95 this.parentA = parentA;
96 this.parentB = parentB;
97 this.parentC = parentC;
98 }
99
100 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
101 parentA = in.readInt();
102 in.defaultReadObject();
103 parentC = in.readInt();
104 }
105
106 private void writeObject(ObjectOutputStream out) throws IOException {
107 out.writeInt(parentA);
108 out.defaultWriteObject();
109 out.writeInt(parentC);
110 }
111 }
112
113 public static class Child extends Parent {
114
115 private transient int childA;
116 private int childB;
117 private transient int childC;
118
119 public Child() {
120 }
121
122 public Child(int parentA, int parentB, int parentC, int childA, int childB, int childC) {
123 super(parentA, parentB, parentC);
124 this.childA = childA;
125 this.childB = childB;
126 this.childC = childC;
127 }
128
129 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
130 childA = in.readInt();
131 in.defaultReadObject();
132 childC = in.readInt();
133 }
134
135 private void writeObject(ObjectOutputStream out) throws IOException {
136 out.writeInt(childA);
137 out.defaultWriteObject();
138 out.writeInt(childC);
139 }
140 }
141
142 public void testIncludesCompleteClassHierarchyWhenParentAndChildHaveSerializationMethods() {
143 Child child = new Child(1, 2, 3, 10, 20, 30);
144 xstream.alias("child", Child.class);
145 xstream.alias("parent", Parent.class);
146
147 String expectedXml = ""
148 + "<child serialization=\"custom\">\n"
149 + " <parent>\n"
150 + " <int>1</int>\n"
151 + " <default>\n"
152 + " <parentB>2</parentB>\n"
153 + " </default>\n"
154 + " <int>3</int>\n"
155 + " </parent>\n"
156 + " <child>\n"
157 + " <int>10</int>\n"
158 + " <default>\n"
159 + " <childB>20</childB>\n"
160 + " </default>\n"
161 + " <int>30</int>\n"
162 + " </child>\n"
163 + "</child>";
164
165 assertBothWays(child, expectedXml);
166 }
167
168 public static class Child2 extends Parent {
169
170 private int childA;
171
172 public Child2(int parentA, int parentB, int parentC, int childA) {
173 super(parentA, parentB, parentC);
174 this.childA = childA;
175 }
176
177 }
178
179 public void testIncludesCompleteClassHierarchyWhenOnlyParentHasSerializationMethods() {
180 Child2 child = new Child2(1, 2, 3, 20);
181 xstream.alias("child2", Child2.class);
182 xstream.alias("parent", Parent.class);
183
184 String expectedXml = ""
185 + "<child2 serialization=\"custom\">\n"
186 + " <parent>\n"
187 + " <int>1</int>\n"
188 + " <default>\n"
189 + " <parentB>2</parentB>\n"
190 + " </default>\n"
191 + " <int>3</int>\n"
192 + " </parent>\n"
193 + " <child2>\n"
194 + " <default>\n"
195 + " <childA>20</childA>\n"
196 + " </default>\n"
197 + " </child2>\n"
198 + "</child2>";
199
200 assertBothWays(child, expectedXml);
201 }
202
203 static class MyDate extends java.util.Date {
204 public MyDate(int time) {
205 super(time);
206 }
207 }
208
209 static class MyHashtable extends java.util.Hashtable {
210 private String name;
211
212 public MyHashtable(String name) {
213 this.name = name;
214 }
215
216 public synchronized boolean equals(Object o) {
217 return super.equals(o) && ((MyHashtable)o).name.equals(name);
218 }
219 }
220
221 public void testSupportsSubclassesOfClassesThatAlreadyHaveConverters() {
222 MyDate in = new MyDate(1234567890);
223 String xml = xstream.toXML(in);
224 assertObjectsEqual(in, xstream.fromXML(xml));
225
226 MyHashtable in2 = new MyHashtable("hi");
227 in2.put("cheese", "curry");
228 in2.put("apple", new Integer(3));
229 String xml2 = xstream.toXML(in2);
230 assertObjectsEqual(in2, xstream.fromXML(xml2));
231 }
232
233 public static class ObjectWithNamedFields extends StandardObject implements Serializable {
234
235 private String name;
236 private int number;
237 private Software someSoftware;
238 private Object polymorphic;
239 private Object nothing;
240
241 private static final ObjectStreamField[] serialPersistentFields = {
242 new ObjectStreamField("theName", String.class),
243 new ObjectStreamField("theNumber", int.class),
244 new ObjectStreamField("theSoftware", Software.class),
245 new ObjectStreamField("thePolymorphic", Object.class),
246 new ObjectStreamField("theNothing", Object.class)
247 };
248
249 private void writeObject(ObjectOutputStream out) throws IOException {
250 // don't call defaultWriteObject()
251 ObjectOutputStream.PutField fields = out.putFields();
252 fields.put("theName", name);
253 fields.put("theNumber", number);
254 fields.put("theSoftware", someSoftware);
255 fields.put("thePolymorphic", polymorphic);
256 fields.put("theNothing", nothing);
257 out.writeFields();
258 }
259
260 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
261 // don't call defaultReadObject()
262 ObjectInputStream.GetField fields = in.readFields();
263 name = (String) fields.get("theName", "unknown");
264 number = fields.get("theNumber", -1);
265 someSoftware = (Software) fields.get("theSoftware", null);
266 polymorphic = fields.get("thePolymorphic", null);
267 nothing = fields.get("theNothing", null);
268 }
269
270 }
271
272 public void testAllowsNamedFields() {
273 ObjectWithNamedFields obj = new ObjectWithNamedFields();
274 obj.name = "Joe";
275 obj.number = 99;
276 obj.someSoftware = new Software("tw", "xs");
277 obj.polymorphic = new Hardware("small", "ipod");
278 obj.nothing = null;
279
280 xstream.alias("with-named-fields", ObjectWithNamedFields.class);
281 xstream.alias("software", Software.class);
282
283 String expectedXml = ""
284 + "<with-named-fields serialization=\"custom\">\n"
285 + " <with-named-fields>\n"
286 + " <default>\n"
287 + " <theName>Joe</theName>\n"
288 + " <theNumber>99</theNumber>\n"
289 + " <theSoftware>\n"
290 + " <vendor>tw</vendor>\n"
291 + " <name>xs</name>\n"
292 + " </theSoftware>\n"
293 + " <thePolymorphic class=\"com.thoughtworks.acceptance.objects.Hardware\">\n"
294 + " <arch>small</arch>\n"
295 + " <name>ipod</name>\n"
296 + " </thePolymorphic>\n"
297 + " </default>\n"
298 + " </with-named-fields>\n"
299 + "</with-named-fields>";
300
301 assertBothWays(obj, expectedXml);
302 }
303
304 public void testUsesDefaultIfNamedFieldNotFound() {
305 xstream.alias("with-named-fields", ObjectWithNamedFields.class);
306 xstream.alias("software", Software.class);
307
308 String inputXml = ""
309 + "<with-named-fields serialization=\"custom\">\n"
310 + " <with-named-fields>\n"
311 + " <default>\n"
312 + " <theSoftware>\n"
313 + " <vendor>tw</vendor>\n"
314 + " <name>xs</name>\n"
315 + " </theSoftware>\n"
316 + " <thePolymorphic class=\"com.thoughtworks.acceptance.objects.Hardware\">\n"
317 + " <arch>small</arch>\n"
318 + " <name>ipod</name>\n"
319 + " </thePolymorphic>\n"
320 + " </default>\n"
321 + " </with-named-fields>\n"
322 + "</with-named-fields>";
323
324 ObjectWithNamedFields result = (ObjectWithNamedFields) xstream.fromXML(inputXml);
325 assertEquals(-1, result.number);
326 assertEquals("unknown", result.name);
327 assertEquals(new Software("tw", "xs"), result.someSoftware);
328 }
329
330 public void testCustomStreamWithNestedCustomStream() {
331 ObjectWithNamedFields outer = new ObjectWithNamedFields();
332 outer.name = "Joe";
333 outer.someSoftware = new Software("tw", "xs");
334 outer.nothing = null;
335
336 ObjectWithNamedFields inner = new ObjectWithNamedFields();
337 inner.name = "Thing";
338
339 outer.polymorphic = inner;
340
341 xstream.alias("with-named-fields", ObjectWithNamedFields.class);
342 xstream.alias("software", Software.class);
343
344 String expectedXml = ""
345 + "<with-named-fields serialization=\"custom\">\n"
346 + " <with-named-fields>\n"
347 + " <default>\n"
348 + " <theName>Joe</theName>\n"
349 + " <theNumber>0</theNumber>\n"
350 + " <theSoftware>\n"
351 + " <vendor>tw</vendor>\n"
352 + " <name>xs</name>\n"
353 + " </theSoftware>\n"
354 + " <thePolymorphic class=\"with-named-fields\" serialization=\"custom\">\n"
355 + " <with-named-fields>\n"
356 + " <default>\n"
357 + " <theName>Thing</theName>\n"
358 + " <theNumber>0</theNumber>\n"
359 + " </default>\n"
360 + " </with-named-fields>\n"
361 + " </thePolymorphic>\n"
362 + " </default>\n"
363 + " </with-named-fields>\n"
364 + "</with-named-fields>";
365
366 assertBothWays(outer, expectedXml);
367 }
368
369 public static class NoDefaultFields extends StandardObject implements Serializable {
370
371 private transient int something;
372
373 public NoDefaultFields() {
374 }
375
376 public NoDefaultFields(int something) {
377 this.something = something;
378 }
379
380 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
381 in.defaultReadObject();
382 something = in.readInt();
383 }
384
385 private void writeObject(ObjectOutputStream out) throws IOException {
386 out.defaultWriteObject();
387 out.writeInt(something);
388 }
389
390 }
391
392 public void testObjectWithCallToDefaultWriteButNoDefaultFields() {
393 xstream.alias("x", NoDefaultFields.class);
394
395 String expectedXml = ""
396 + "<x serialization=\"custom\">\n"
397 + " <x>\n"
398 + " <default/>\n"
399 + " <int>77</int>\n"
400 + " </x>\n"
401 + "</x>";
402 assertBothWays(new NoDefaultFields(77), expectedXml);
403 }
404
405 public void testMaintainsBackwardsCompatabilityWithXStream1_1_0FieldFormat() {
406 ObjectWithNamedFields outer = new ObjectWithNamedFields();
407 outer.name = "Joe";
408 outer.someSoftware = new Software("tw", "xs");
409 outer.nothing = null;
410
411 ObjectWithNamedFields inner = new ObjectWithNamedFields();
412 inner.name = "Thing";
413
414 outer.polymorphic = inner;
415
416 xstream.alias("with-named-fields", ObjectWithNamedFields.class);
417 xstream.alias("software", Software.class);
418
419 String oldFormatOfXml = ""
420 + "<with-named-fields serialization=\"custom\">\n"
421 + " <with-named-fields>\n"
422 + " <fields>\n"
423 + " <field name=\"theName\" class=\"string\">Joe</field>\n"
424 + " <field name=\"theNumber\" class=\"int\">0</field>\n"
425 + " <field name=\"theSoftware\" class=\"software\">\n"
426 + " <vendor>tw</vendor>\n"
427 + " <name>xs</name>\n"
428 + " </field>\n"
429 + " <field name=\"thePolymorphic\" class=\"with-named-fields\" serialization=\"custom\">\n"
430 + " <with-named-fields>\n"
431 + " <fields>\n"
432 + " <field name=\"theName\" class=\"string\">Thing</field>\n"
433 + " <field name=\"theNumber\" class=\"int\">0</field>\n"
434 + " </fields>\n"
435 + " </with-named-fields>\n"
436 + " </field>\n"
437 + " </fields>\n"
438 + " </with-named-fields>\n"
439 + "</with-named-fields>";
440
441
442 assertEquals(outer, xstream.fromXML(oldFormatOfXml));
443 }
444
445 public static class ObjectWithNamedThatMatchRealFields extends StandardObject implements Serializable {
446
447 private String name;
448 private int number;
449
450 private void writeObject(ObjectOutputStream out) throws IOException {
451 ObjectOutputStream.PutField fields = out.putFields();
452 fields.put("name", name.toUpperCase());
453 fields.put("number", number * 100);
454 out.writeFields();
455 }
456
457 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
458 ObjectInputStream.GetField fields = in.readFields();
459 name = ((String) fields.get("name", "unknown")).toLowerCase();
460 number = fields.get("number", 10000) / 100;
461 }
462
463 }
464
465 public void testSupportsWritingFieldsForObjectsThatDoNotExplicitlyDefineThem() {
466 xstream.alias("an-object", ObjectWithNamedThatMatchRealFields.class);
467
468 ObjectWithNamedThatMatchRealFields input = new ObjectWithNamedThatMatchRealFields();
469 input.name = "a name";
470 input.number = 5;
471
472 String expectedXml = ""
473 + "<an-object serialization=\"custom\">\n"
474 + " <an-object>\n"
475 + " <default>\n"
476 + " <name>A NAME</name>\n"
477 + " <number>500</number>\n"
478 + " </default>\n"
479 + " </an-object>\n"
480 + "</an-object>";
481
482 assertBothWays(input, expectedXml);
483 }
484
485 public static class ObjectThatReadsCustomFieldsButDoesNotWriteThem extends StandardObject implements Serializable {
486
487 private String name;
488 private int number;
489
490 private void writeObject(ObjectOutputStream out) throws IOException {
491 out.defaultWriteObject();
492 }
493
494 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
495 ObjectInputStream.GetField fields = in.readFields();
496 name = ((String) fields.get("name", "unknown"));
497 number = fields.get("number", 10000);
498 }
499
500 }
501
502 public void testSupportsGetFieldsWithoutPutFields() {
503 xstream.alias("an-object", ObjectThatReadsCustomFieldsButDoesNotWriteThem.class);
504
505 ObjectThatReadsCustomFieldsButDoesNotWriteThem input = new ObjectThatReadsCustomFieldsButDoesNotWriteThem();
506 input.name = "a name";
507 input.number = 5;
508
509 String expectedXml = ""
510 + "<an-object serialization=\"custom\">\n"
511 + " <an-object>\n"
512 + " <default>\n"
513 + " <number>5</number>\n"
514 + " <name>a name</name>\n"
515 + " </default>\n"
516 + " </an-object>\n"
517 + "</an-object>";
518
519 assertBothWays(input, expectedXml);
520 }
521
522 public static class ObjectThatWritesCustomFieldsButDoesNotReadThem extends StandardObject implements Serializable {
523
524 private static final ObjectStreamField[] serialPersistentFields = {
525 new ObjectStreamField("number", int.class),
526 new ObjectStreamField("name", String.class),
527 };
528
529 private void writeObject(ObjectOutputStream out) throws IOException {
530 ObjectOutputStream.PutField fields = out.putFields();
531 fields.put("name", "test");
532 fields.put("number", 42);
533 out.writeFields();
534 }
535
536 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
537 in.defaultReadObject();
538 }
539
540 }
541
542 public void testSupportsPutFieldsWithoutGetFields() {
543 xstream.alias("an-object", ObjectThatWritesCustomFieldsButDoesNotReadThem.class);
544
545 ObjectThatWritesCustomFieldsButDoesNotReadThem input = new ObjectThatWritesCustomFieldsButDoesNotReadThem();
546
547 String expectedXml = ""
548 + "<an-object serialization=\"custom\">\n"
549 + " <an-object>\n"
550 + " <default>\n"
551 + " <name>test</name>\n"
552 + " <number>42</number>\n"
553 + " </default>\n"
554 + " </an-object>\n"
555 + "</an-object>";
556
557 assertBothWays(input, expectedXml);
558 }
559 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 04. October 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.DataHolder;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
20 import com.thoughtworks.xstream.io.xml.XppReader;
21
22 import java.io.StringReader;
23 import java.io.StringWriter;
24
25 public class DataHolderTest extends AbstractAcceptanceTest {
26
27 class StringWithPrefixConverter implements Converter {
28
29 public boolean canConvert(Class type) {
30 return type == String.class;
31 }
32
33 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
34 String prefix = (String) context.get("prefix");
35 if (prefix != null) {
36 writer.addAttribute("prefix", prefix);
37 }
38 writer.setValue(source.toString());
39 }
40
41 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
42 context.put("saw-this", reader.getAttribute("can-you-see-me"));
43 return reader.getValue();
44 }
45
46 }
47
48 public void testCanBePassedInToMarshallerExternally() {
49 // setup
50 xstream.registerConverter(new StringWithPrefixConverter());
51 StringWriter writer = new StringWriter();
52 DataHolder dataHolder = xstream.newDataHolder();
53
54 // execute
55 dataHolder.put("prefix", "additional stuff");
56 xstream.marshal("something", new PrettyPrintWriter(writer), dataHolder);
57
58 // verify
59 String expected = "<string prefix=\"additional stuff\">something</string>";
60 assertEquals(expected, writer.toString());
61 }
62
63 public void testCanBePassedInToUnmarshallerExternally() {
64 // setup
65 xstream.registerConverter(new StringWithPrefixConverter());
66 DataHolder dataHolder = xstream.newDataHolder();
67
68 // execute
69 String xml = "<string can-you-see-me=\"yes\">something</string>";
70 Object result = xstream.unmarshal(new XppReader(new StringReader(xml)), null, dataHolder);
71
72 // verify
73 assertEquals("something", result);
74 assertEquals("yes", dataHolder.get("saw-this"));
75 }
76
77
78 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 08. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
15
16 import java.util.ArrayList;
17 import java.util.Calendar;
18 import java.util.List;
19 import java.util.TimeZone;
20
21 public class DefaultImplementationTest extends AbstractAcceptanceTest {
22
23
24 public static class Farm extends StandardObject {
25 int size;
26 List animals = new ArrayList();
27 String name;
28
29 public Farm(int size, String name) {
30 this.size = size;
31 this.name = name;
32 }
33
34 public void add(Animal animal) {
35 animals.add(animal);
36 }
37 }
38
39 public static class Animal extends StandardObject {
40 String name;
41
42 public Animal(String name) {
43 this.name = name;
44 }
45 }
46
47 protected void setUp() throws Exception {
48 super.setUp();
49 TimeZoneChanger.change("GMT");
50 xstream.alias("farm", Farm.class);
51 xstream.alias("animal", Animal.class);
52 xstream.alias("age", Age.class);
53 }
54
55 /**
56 * @see junit.framework.TestCase#tearDown()
57 */
58 protected void tearDown() throws Exception {
59 TimeZoneChanger.reset();
60 super.tearDown();
61 }
62
63 public void testArrayList() {
64 Farm farm = new Farm(100, "Old McDonald's");
65 farm.add(new Animal("Cow"));
66 farm.add(new Animal("Sheep"));
67
68 String expected = "" +
69 "<farm>\n" +
70 " <size>100</size>\n" +
71 " <animals>\n" +
72 " <animal>\n" +
73 " <name>Cow</name>\n" +
74 " </animal>\n" +
75 " <animal>\n" +
76 " <name>Sheep</name>\n" +
77 " </animal>\n" +
78 " </animals>\n" +
79 " <name>Old McDonald&apos;s</name>\n" +
80 "</farm>";
81
82 assertBothWays(farm, expected);
83 }
84
85 public static class Age extends StandardObject {
86 java.util.Date date;
87
88 public Age(java.util.Date age) {
89 this.date = age;
90 }
91 }
92
93 public void testCustomDate() {
94 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
95 cal.clear();
96 cal.set(2007, Calendar.DECEMBER, 18);
97 Age age = new Age(new java.sql.Date(cal.getTime().getTime()));
98
99 xstream.addDefaultImplementation(java.sql.Date.class, java.util.Date.class);
100
101 String expected = "" +
102 "<age>\n" +
103 " <date>2007-12-18</date>\n" +
104 "</age>";
105
106 assertBothWays(age, expected);
107 }
108 }
0 /*
1 * Copyright (C) 2004, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2014 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 25. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import com.thoughtworks.acceptance.objects.SampleDynamicProxy;
17 import com.thoughtworks.xstream.XStream;
18 import com.thoughtworks.xstream.security.ProxyTypePermission;
19
20
21 public class DynamicProxyTest extends AbstractAcceptanceTest {
22 public static class ClassWithProxyMember {
23 SampleDynamicProxy.InterfaceOne one;
24 SampleDynamicProxy.InterfaceTwo two;
25 };
26
27 protected void setupSecurity(XStream xstream) {
28 super.setupSecurity(xstream);
29 xstream.addPermission(ProxyTypePermission.PROXIES);
30 }
31
32 public void testCanBeMarshaled() {
33 assertBothWays(
34 SampleDynamicProxy.newInstance(),
35 ""
36 + "<dynamic-proxy>\n"
37 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceOne</interface>\n"
38 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceTwo</interface>\n"
39 + " <handler class=\"com.thoughtworks.acceptance.objects.SampleDynamicProxy\">\n"
40 + " <aField class=\"string\">hello</aField>\n"
41 + " </handler>\n"
42 + "</dynamic-proxy>");
43 }
44
45 public void testAsFieldMember() {
46 ClassWithProxyMember expected = new ClassWithProxyMember();
47 expected.one = (SampleDynamicProxy.InterfaceOne)SampleDynamicProxy.newInstance();
48 expected.two = (SampleDynamicProxy.InterfaceTwo)expected.one;
49 xstream.alias("with-proxy", ClassWithProxyMember.class);
50 assertBothWays(
51 expected,
52 ""
53 + "<with-proxy>\n"
54 + " <one class=\"dynamic-proxy\">\n"
55 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceOne</interface>\n"
56 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceTwo</interface>\n"
57 + " <handler class=\"com.thoughtworks.acceptance.objects.SampleDynamicProxy\">\n"
58 + " <aField class=\"string\">hello</aField>\n"
59 + " </handler>\n"
60 + " </one>\n"
61 + " <two class=\"dynamic-proxy\" reference=\"../one\"/>\n"
62 + "</with-proxy>");
63 }
64
65 public void testTypeCanBeAliased() {
66 xstream.aliasType("one", SampleDynamicProxy.InterfaceOne.class);
67 xstream.alias("two", SampleDynamicProxy.InterfaceTwo.class);
68 xstream.alias("handler", SampleDynamicProxy.class);
69 String expected = ""
70 + "<one>\n"
71 + " <interface>one</interface>\n"
72 + " <interface>two</interface>\n"
73 + " <handler class=\"handler\">\n"
74 + " <aField class=\"string\">hello</aField>\n"
75 + " </handler>\n"
76 + "</one>";
77 assertEquals(expected, xstream.toXML(SampleDynamicProxy.newInstance()));
78 }
79
80 public void testCanBeReferenced() {
81 List list = new ArrayList();
82 Object proxy = SampleDynamicProxy.newInstance(list);
83 list.add(proxy);
84 assertBothWays(
85 proxy,
86 ""
87 + "<dynamic-proxy>\n"
88 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceOne</interface>\n"
89 + " <interface>com.thoughtworks.acceptance.objects.SampleDynamicProxy$InterfaceTwo</interface>\n"
90 + " <handler class=\"com.thoughtworks.acceptance.objects.SampleDynamicProxy\">\n"
91 + " <aField class=\"list\">\n"
92 + " <dynamic-proxy reference=\"../../..\"/>\n"
93 + " </aField>\n"
94 + " </handler>\n"
95 + "</dynamic-proxy>");
96 }
97 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 25. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.io.ByteArrayInputStream;
14 import java.io.ByteArrayOutputStream;
15 import java.io.IOException;
16 import java.io.OutputStreamWriter;
17 import java.util.Properties;
18
19 import javax.xml.stream.XMLInputFactory;
20
21 import junit.framework.Assert;
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import com.bea.xml.stream.MXParserFactory;
27 import com.thoughtworks.acceptance.objects.StandardObject;
28 import com.thoughtworks.xstream.XStream;
29 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
30 import com.thoughtworks.xstream.io.xml.Dom4JDriver;
31 import com.thoughtworks.xstream.io.xml.DomDriver;
32 import com.thoughtworks.xstream.io.xml.JDomDriver;
33 import com.thoughtworks.xstream.io.xml.StaxDriver;
34 import com.thoughtworks.xstream.io.xml.XomDriver;
35 import com.thoughtworks.xstream.io.xml.XppDomDriver;
36 import com.thoughtworks.xstream.io.xml.XppDriver;
37
38
39 /**
40 * @author Sanjiv Jivan
41 * @author Guilherme Silveira
42 * @author J&ouml;rg Schaible
43 */
44 public class EncodingTestSuite extends TestSuite {
45
46 public static class TestObject extends StandardObject {
47 private String data;
48 }
49
50 public EncodingTestSuite() {
51 super(EncodingTestSuite.class.getName());
52 addDriverTest(new Dom4JDriver());
53 addDriverTest(new DomDriver());
54 addDriverTest(new JDomDriver());
55 addDriverTest(new StaxDriver());
56 addDriverTest(new XppDomDriver());
57 addDriverTest(new XppDriver());
58 addDriverTest(new XomDriver());
59 }
60
61 private void test(HierarchicalStreamDriver driver, String encoding) throws IOException {
62 String headerLine = encoding != null
63 ? ("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n")
64 : "";
65 String xmlData = headerLine // force code format
66 + "<test>\n"
67 + " <data>J\u00f6rg</data>\n"
68 + "</test>";
69
70 XStream xstream = new XStream(driver);
71 xstream.alias("test", TestObject.class);
72 TestObject obj = new TestObject();
73 obj.data = "J\u00f6rg";
74
75 ByteArrayOutputStream bos = new ByteArrayOutputStream();
76 OutputStreamWriter writer = encoding != null
77 ? new OutputStreamWriter(bos, encoding)
78 : new OutputStreamWriter(bos);
79 xstream.toXML(obj, writer);
80 writer.close();
81
82 String generated = encoding != null ? bos.toString(encoding) : bos.toString();
83 Assert.assertTrue("'" + obj.data + "' was not found", generated.indexOf(obj.data) > 0);
84
85 Object restored = xstream.fromXML(new ByteArrayInputStream(encoding != null ? xmlData
86 .getBytes(encoding) : xmlData.getBytes()));
87 Assert.assertEquals(obj, restored);
88 }
89
90 private void addDriverTest(final HierarchicalStreamDriver driver) {
91 String testName = getShortName(driver);
92 final String allEncodingTests = System.getProperty("xstream.test.encoding.all");
93 if ("true".equals(allEncodingTests)) {
94 // Native encoding normally fails on most systems!!
95 addTest(new TestCase(testName + "Native") {
96 protected void runTest() throws Throwable {
97 test(driver, null);
98 }
99 });
100 // System encoding fails on US-ASCII systems, like Codehaus Bamboo
101 final String systemEncoding = System.getProperty("file.encoding");
102 addTest(new TestCase(testName + "With" + systemEncoding + "SystemEncoding") {
103 protected void runTest() throws Throwable {
104 final Properties systemProperties = new Properties();
105 systemProperties.putAll(System.getProperties());
106 try {
107 // Use BEA reference implementation for StAX
108 // (Woodstox will fail on Windows because of unknown system encoding)
109 System.setProperty(
110 XMLInputFactory.class.getName(), MXParserFactory.class.getName());
111 test(driver, systemEncoding);
112 } finally {
113 System.setProperties(systemProperties);
114 }
115 }
116 });
117 }
118 addTest(new TestCase(testName + "WithUTF_8Encoding") {
119 protected void runTest() throws Throwable {
120 test(driver, "UTF-8");
121 }
122 });
123 addTest(new TestCase(testName + "WithIS0_8859_1Encoding") {
124 protected void runTest() throws Throwable {
125 test(driver, "ISO-8859-1");
126 }
127 });
128 }
129
130 private String getShortName(HierarchicalStreamDriver driver) {
131 String result = driver.getClass().getName();
132 result = result.substring(result.lastIndexOf('.') + 1);
133 return result;
134 }
135
136 public static Test suite() {
137 return new EncodingTestSuite();
138 }
139
140 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011, 2013 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 08. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.core.JVM;
15 import com.thoughtworks.xstream.io.StreamException;
16
17 public class ErrorTest extends AbstractAcceptanceTest {
18
19 public static class Thing {
20 String one;
21 int two;
22 }
23
24 protected void setUp() throws Exception {
25 super.setUp();
26 xstream.alias("thing", Thing.class);
27 }
28
29 public void testUnmarshallerThrowsExceptionWithDebuggingInfo() {
30 try {
31 xstream.fromXML(""
32 + "<thing>\n"
33 + " <one>string 1</one>\n"
34 + " <two>another string</two>\n"
35 + "</thing>");
36 fail("Error expected");
37 } catch (ConversionException e) {
38 assertEquals("java.lang.NumberFormatException",
39 e.get("cause-exception"));
40 if (JVM.is14()) {
41 assertEquals("For input string: \"another string\"",
42 e.get("cause-message"));
43 } else {
44 assertEquals("another string",
45 e.get("cause-message"));
46 }
47 assertEquals(Integer.class.getName(),
48 e.get("class"));
49 assertEquals("/thing/two",
50 e.get("path"));
51 assertEquals("3",
52 e.get("line number"));
53 assertEquals("java.lang.Integer",
54 e.get("required-type"));
55 assertEquals(Thing.class.getName(),
56 e.get("class[1]"));
57 }
58 }
59
60 public void testInvalidXml() {
61 try {
62 xstream.fromXML(""
63 + "<thing>\n"
64 + " <one>string 1</one>\n"
65 + " <two><<\n"
66 + "</thing>");
67 fail("Error expected");
68 } catch (ConversionException e) {
69 assertEquals(StreamException.class.getName(),
70 e.get("cause-exception"));
71 assertNotNull(e.get("cause-message")); // depends on parser
72 assertEquals("/thing/two",
73 e.get("path"));
74 assertEquals("3",
75 e.get("line number"));
76 }
77 }
78
79 public void testNonExistingMember() {
80 try {
81 xstream.fromXML(""
82 + "<thing>\n"
83 + " <one>string 1</one>\n"
84 + " <three>3</three>\n"
85 + "</thing>");
86 fail("Error expected");
87 } catch (ConversionException e) {
88 assertEquals("three",
89 e.get("field"));
90 assertEquals("/thing/three",
91 e.get("path"));
92 assertEquals("3",
93 e.get("line number"));
94 }
95 }
96
97 public void testNonExistingMemberMatchingAlias() {
98 try {
99 xstream.fromXML(""
100 + "<thing>\n"
101 + " <string>string 1</string>\n"
102 + "</thing>");
103 fail("Error expected");
104 } catch (ConversionException e) {
105 assertEquals("/thing/string",
106 e.get("path"));
107 assertEquals("2",
108 e.get("line number"));
109 }
110 }
111 }
0 /*
1 * Copyright (C) 2006, 2007, 2014 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 12. January 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
14
15 import javax.security.auth.Subject;
16 import javax.security.auth.x500.X500Principal;
17
18 import java.nio.charset.Charset;
19 import java.security.Principal;
20 import java.util.Calendar;
21 import java.util.Currency;
22 import java.util.Locale;
23 import java.util.TimeZone;
24 import java.util.regex.Pattern;
25
26 public class Extended14TypesTest extends AbstractAcceptanceTest {
27
28 protected void setUp() throws Exception {
29 super.setUp();
30
31 // Ensure that this test always run as if it were in the EST timezone.
32 // This prevents failures when running the tests in different zones.
33 // Note: 'EST' has no relevance - it was just a randomly chosen zone.
34 TimeZoneChanger.change("EST");
35 }
36
37 protected void tearDown() throws Exception {
38 TimeZoneChanger.reset();
39 super.tearDown();
40 }
41
42 public void testLocaleWithVariant() {
43 assertBothWays(new Locale("zh", "CN", "cc"), "<locale>zh_CN_cc</locale>");
44 assertBothWays(new Locale("zh", "", "cc"), "<locale>zh__cc</locale>");
45 }
46
47 public void testCurrency() {
48 assertBothWays(Currency.getInstance("USD"), "<currency>USD</currency>");
49 }
50
51 public void testGregorianCalendar() {
52 Calendar in = Calendar.getInstance();
53 in.setTimeZone(TimeZone.getTimeZone("AST"));
54 in.setTimeInMillis(44444);
55 String expected = "" +
56 "<gregorian-calendar>\n" +
57 " <time>44444</time>\n" +
58 " <timezone>AST</timezone>\n" +
59 "</gregorian-calendar>";
60 Calendar out = (Calendar) assertBothWays(in, expected);
61 assertEquals(in.getTime(), out.getTime());
62 assertEquals(TimeZone.getTimeZone("AST"), out.getTimeZone());
63 }
64
65 public void testGregorianCalendarCompat() { // compatibility to 1.1.2 and below
66 Calendar in = Calendar.getInstance();
67 in.setTimeInMillis(44444);
68 String oldXML = "" +
69 "<gregorian-calendar>\n" +
70 " <time>44444</time>\n" +
71 "</gregorian-calendar>";
72 Calendar out = (Calendar) xstream.fromXML(oldXML);
73 assertEquals(in.getTime(), out.getTime());
74 assertEquals(TimeZone.getTimeZone("EST"), out.getTimeZone());
75 }
76
77 public void testRegexPattern() {
78 // setup
79 Pattern pattern = Pattern.compile("^[ae]*$", Pattern.MULTILINE | Pattern.UNIX_LINES);
80 String expectedXml = "" +
81 "<java.util.regex.Pattern>\n" +
82 " <pattern>^[ae]*$</pattern>\n" +
83 " <flags>9</flags>\n" +
84 "</java.util.regex.Pattern>";
85
86 // execute
87 String actualXml = xstream.toXML(pattern);
88 Pattern result = (Pattern) xstream.fromXML(actualXml);
89
90 // verify
91 assertEquals(expectedXml, actualXml);
92 assertEquals(pattern.pattern(), result.pattern());
93 assertEquals(pattern.flags(), result.flags());
94
95 assertFalse("regex should not hava matched", result.matcher("oooo").matches());
96 assertTrue("regex should have matched", result.matcher("aeae").matches());
97 }
98
99 public void testSubject() {
100 xstream.allowTypes(new Class[]{Subject.class});
101 xstream.allowTypeHierarchy(Principal.class);
102
103 Subject subject = new Subject();
104 Principal principal = new X500Principal("c=uk, o=Thoughtworks, ou=XStream");
105 subject.getPrincipals().add(principal);
106 String expectedXml = "" +
107 "<auth-subject>\n" +
108 " <principals>\n" +
109 " <javax.security.auth.x500.X500Principal serialization=\"custom\">\n" +
110 " <javax.security.auth.x500.X500Principal>\n" +
111 " <byte-array>MDYxEDAOBgNVBAsTB1hTdHJlYW0xFTATBgNVBAoTDFRob3VnaHR3b3JrczELMAkGA1UEBhMCdWs=\n</byte-array>\n" +
112 " </javax.security.auth.x500.X500Principal>\n" +
113 " </javax.security.auth.x500.X500Principal>\n" +
114 " </principals>\n" +
115 " <readOnly>false</readOnly>\n" +
116 "</auth-subject>";
117
118 assertBothWays(subject, expectedXml);
119 }
120
121 public void testCharset() {
122 Charset charset = Charset.forName("utf-8");
123 String expectedXml = "<charset>UTF-8</charset>";
124
125 assertBothWays(charset, expectedXml);
126 }
127 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2012, 2014 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 01. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.xstream.core.JVM;
14 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
15
16 import org.jdom.Element;
17
18 import java.awt.Color;
19 import java.io.File;
20 import java.io.IOException;
21 import java.sql.Date;
22 import java.sql.Time;
23 import java.sql.Timestamp;
24 import java.util.Locale;
25
26 public class ExtendedTypesTest extends AbstractAcceptanceTest {
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 xstream.allowTypes(new Class[]{Element.class, Date.class, Time.class, Timestamp.class});
31
32 // Ensure that this test always run as if it were in the EST timezone.
33 // This prevents failures when running the tests in different zones.
34 // Note: 'EST' has no relevance - it was just a randomly chosen zone.
35 TimeZoneChanger.change("EST");
36 }
37
38 protected void tearDown() throws Exception {
39 TimeZoneChanger.reset();
40 super.tearDown();
41 }
42
43 public void testAwtColor() {
44 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
45 if (!isHeadless || JVM.is15()) {
46 xstream.allowTypes(new Class[]{Color.class});
47 Color color = new Color(0, 10, 20, 30);
48
49 String expected = "" +
50 "<awt-color>\n" +
51 " <red>0</red>\n" +
52 " <green>10</green>\n" +
53 " <blue>20</blue>\n" +
54 " <alpha>30</alpha>\n" +
55 "</awt-color>";
56
57 assertBothWays(color, expected);
58 }
59 }
60
61 public void testSqlTimestamp() {
62 Timestamp timestamp = new Timestamp(1234);
63 timestamp.setNanos(78900);
64 assertBothWays(timestamp,
65 "<sql-timestamp>1970-01-01 00:00:01.0000789</sql-timestamp>");
66 }
67
68 public void testSqlTime() {
69 assertBothWays(new Time(14, 7, 33),
70 "<sql-time>14:07:33</sql-time>");
71 }
72
73 public void testSqlDate() {
74 assertBothWays(new Date(78, 7, 25),
75 "<sql-date>1978-08-25</sql-date>");
76 }
77
78 public void testFile() throws IOException {
79 // using temp file to avoid os specific or directory layout issues
80 File absFile = File.createTempFile("bleh", ".tmp");
81 absFile.deleteOnExit();
82 assertTrue(absFile.isAbsolute());
83 String expectedXml = "<file>" + absFile.getPath() + "</file>";
84 assertFilesBothWay(absFile, expectedXml);
85
86 // test a relative file now
87 File relFile = new File("bloh.tmp");
88 relFile.deleteOnExit();
89 assertFalse(relFile.isAbsolute());
90 expectedXml = "<file>" + relFile.getPath() + "</file>";
91 assertFilesBothWay(relFile, expectedXml);
92 }
93
94 private void assertFilesBothWay(File f, String expectedXml) {
95 String resultXml = xstream.toXML(f);
96 assertEquals(expectedXml, resultXml);
97 Object resultObj = xstream.fromXML(resultXml);
98 assertEquals(File.class, resultObj.getClass());
99 assertEquals(f, resultObj);
100 // now comes the part that fails without a specific converter
101 // in the case of a relative file, this will work, because we run the comparison test from the same working directory
102 assertEquals(f.getAbsolutePath(), ((File)resultObj).getAbsolutePath());
103 assertEquals(f.isAbsolute(), ((File)resultObj).isAbsolute()); // needed because File's equals method only compares the path getAttribute, at least in the win32 implementation
104 }
105
106 public void testLocale() {
107 assertBothWays(new Locale("zh", "", ""), "<locale>zh</locale>");
108 assertBothWays(new Locale("zh", "CN", ""), "<locale>zh_CN</locale>");
109 }
110
111 public void testCanHandleJDomElement() {
112 Element element = new Element("JUnit");
113
114 String expected = "" +
115 "<org.jdom.Element serialization=\"custom\">\n" +
116 " <org.jdom.Element>\n" +
117 " <default>\n" +
118 " <attributes>\n" +
119 " <size>0</size>\n" +
120 " <parent reference=\"../../../..\"/>\n" +
121 " </attributes>\n" +
122 " <content>\n" +
123 " <size>0</size>\n" +
124 " <parent class=\"org.jdom.Element\" reference=\"../../../..\"/>\n" +
125 " </content>\n" +
126 " <name>JUnit</name>\n" +
127 " </default>\n" +
128 " <string></string>\n" +
129 " <string></string>\n" +
130 " <byte>0</byte>\n" +
131 " </org.jdom.Element>\n" +
132 "</org.jdom.Element>";
133
134 assertBothWays(element, expected);
135 }
136
137 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011 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. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.OwnerOfExternalizable;
14 import com.thoughtworks.acceptance.objects.SomethingExternalizable;
15 import com.thoughtworks.acceptance.objects.StandardObject;
16
17 import java.io.Externalizable;
18 import java.io.IOException;
19 import java.io.ObjectInput;
20 import java.io.ObjectOutput;
21
22 public class ExternalizableTest extends AbstractAcceptanceTest {
23
24 public void testExternalizable() {
25 xstream.alias("something", SomethingExternalizable.class);
26
27 SomethingExternalizable in = new SomethingExternalizable("Joe", "Walnes");
28
29 String expected = ""
30 + "<something>\n"
31 + " <int>3</int>\n"
32 + " <string>JoeWalnes</string>\n"
33 + " <null/>\n"
34 + " <string>XStream</string>\n"
35 + "</something>";
36
37 assertBothWays(in, expected);
38 }
39
40 public void testExternalizableAsFieldOfAnotherObject() {
41 xstream.alias("something", SomethingExternalizable.class);
42 xstream.alias("owner", OwnerOfExternalizable.class);
43
44 OwnerOfExternalizable in = new OwnerOfExternalizable();
45 in.target = new SomethingExternalizable("Joe", "Walnes");
46
47 String expected = ""
48 + "<owner>\n"
49 + " <target>\n"
50 + " <int>3</int>\n"
51 + " <string>JoeWalnes</string>\n"
52 + " <null/>\n"
53 + " <string>XStream</string>\n"
54 + " </target>\n"
55 + "</owner>";
56
57 assertBothWays(in, expected);
58 }
59
60 public static class CircularExternalizable implements Externalizable {
61 private String name;
62 private CircularExternalizable parent;
63 private CircularExternalizable child;
64
65 public CircularExternalizable() {
66 }
67
68 public CircularExternalizable(String name) {
69 this.name = name;
70 }
71
72 public void setParent(CircularExternalizable parent) {
73 this.parent = parent;
74 if (parent != null) {
75 parent.child = this;
76 }
77 }
78
79 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
80 name = (String)in.readObject();
81 parent = (CircularExternalizable)in.readObject();
82 child = (CircularExternalizable)in.readObject();
83 }
84
85 public void writeExternal(ObjectOutput out) throws IOException {
86 out.writeObject(name);
87 out.writeObject(parent);
88 out.writeObject(child);
89 }
90
91 // StandardObject uses EqualsBuilder.reflectionEquals of commons-lang,
92 // that does not handle circular dependencies
93 public boolean equals(Object obj) {
94 return obj instanceof CircularExternalizable && name.equals(obj.toString());
95 }
96
97 public int hashCode() {
98 return name.hashCode()+1;
99 }
100
101 public String toString() {
102 return name;
103 }
104
105 }
106
107 public void testCircularExternalizable() {
108 xstream.alias("elem", CircularExternalizable.class);
109
110 CircularExternalizable parent = new CircularExternalizable("parent");
111 CircularExternalizable child = new CircularExternalizable("child");
112 child.setParent(parent);
113
114 String expected = ""
115 + "<elem>\n"
116 + " <string>parent</string>\n"
117 + " <null/>\n"
118 + " <elem>\n"
119 + " <string>child</string>\n"
120 + " <elem reference=\"../..\"/>\n"
121 + " <null/>\n"
122 + " </elem>\n"
123 + "</elem>";
124
125 assertBothWays(parent, expected);
126 }
127
128 public static class OtherOwner extends StandardObject {
129 Object member1;
130 Object member2;
131 public OtherOwner(int i) {
132 member1 = new InnerExternalizable1(i);
133 member2 = new InnerExternalizable2(i);
134 }
135
136 private static class InnerExternalizable1 extends StandardObject implements Externalizable {
137 private int i;
138
139 public InnerExternalizable1() {
140 }
141
142 InnerExternalizable1(int i) {
143 this.i = i;
144 }
145
146 public void writeExternal(ObjectOutput out) throws IOException {
147 out.writeInt(i);
148 }
149
150 public void readExternal(ObjectInput in)
151 throws IOException {
152 this.i = in.readInt();
153 }
154 };
155
156 private static class InnerExternalizable2 extends StandardObject implements Externalizable {
157 private int i;
158
159 private InnerExternalizable2() {
160 }
161
162 InnerExternalizable2(int i) {
163 this.i = i;
164 }
165
166 public void writeExternal(ObjectOutput out) throws IOException {
167 out.writeInt(i);
168 }
169
170 public void readExternal(ObjectInput in)
171 throws IOException {
172 this.i = in.readInt();
173 }
174 };
175 }
176
177 public void testWithPrivateDefaultConstructor() {
178 String name1 = OtherOwner.class.getDeclaredClasses()[0].getName();
179 String name2 = OtherOwner.class.getDeclaredClasses()[1].getName();
180 xstream.alias("owner", OtherOwner.class);
181 xstream.alias("inner" + name1.charAt(name1.length() - 1),
182 OtherOwner.class.getDeclaredClasses()[0]);
183 xstream.alias("inner" + name2.charAt(name2.length() - 1),
184 OtherOwner.class.getDeclaredClasses()[1]);
185
186 OtherOwner owner = new OtherOwner(42);
187
188 String expected = ""
189 + "<owner>\n"
190 + " <member1 class=\"inner1\">\n"
191 + " <int>42</int>\n"
192 + " </member1>\n"
193 + " <member2 class=\"inner2\">\n"
194 + " <int>42</int>\n"
195 + " </member2>\n"
196 + "</owner>";
197
198 assertBothWays(owner, expected);
199 }
200 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2013, 2014 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 09. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
16 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
17 import com.thoughtworks.xstream.core.JVM;
18
19 public class FinalFieldsTest extends AbstractAcceptanceTest {
20
21 static class ThingWithFinalField extends StandardObject {
22 final int number = 9;
23 }
24
25 public void testSerializeFinalFieldsIfSupported() {
26 xstream = new XStream(JVM.newReflectionProvider());
27 setupSecurity(xstream);
28 xstream.alias("thing", ThingWithFinalField.class);
29
30 assertBothWays(new ThingWithFinalField(),
31 "<thing>\n" +
32 " <number>9</number>\n" +
33 "</thing>");
34 }
35
36 public void testExceptionThrownUponSerializationIfNotSupport() {
37 xstream = new XStream(new PureJavaReflectionProvider());
38 xstream.alias("thing", ThingWithFinalField.class);
39
40 try {
41 xstream.toXML(new ThingWithFinalField());
42 if (!JVM.is15()) {
43 fail("Expected exception");
44 }
45 } catch (ObjectAccessException expectedException) {
46 assertEquals("Invalid final field " + ThingWithFinalField.class.getName() + ".number",
47 expectedException.getMessage());
48 }
49 }
50 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010 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 30. July 2011 by Joerg Schaible by merging IDCircularReferenceTest,
10 * IDDuplicateReferenceTest, IDNestedCircularReferenceTest and
11 * IDReplacedReferenceTest.
12 */
13 package com.thoughtworks.acceptance;
14
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 public class IDReferenceTest extends AbstractReferenceTest {
22
23 // tests inherited from superclass
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 xstream.setMode(XStream.ID_REFERENCES);
28 }
29
30 public void testXmlContainsReferenceIds() {
31
32 Thing sameThing = new Thing("hello");
33 Thing anotherThing = new Thing("hello");
34
35 List list = new ArrayList();
36 list.add(sameThing);
37 list.add(sameThing);
38 list.add(anotherThing);
39
40 String expected = "" +
41 "<list id=\"1\">\n" +
42 " <thing id=\"2\">\n" +
43 " <field>hello</field>\n" +
44 " </thing>\n" +
45 " <thing reference=\"2\"/>\n" +
46 " <thing id=\"3\">\n" +
47 " <field>hello</field>\n" +
48 " </thing>\n" +
49 "</list>";
50
51 assertEquals(expected, xstream.toXML(list));
52 }
53
54 public void testCircularReferenceXml() {
55 Person bob = new Person("bob");
56 Person jane = new Person("jane");
57 bob.likes = jane;
58 jane.likes = bob;
59
60 String expected = "" +
61 "<person id=\"1\">\n" +
62 " <firstname>bob</firstname>\n" +
63 " <likes id=\"2\">\n" +
64 " <firstname>jane</firstname>\n" +
65 " <likes reference=\"1\"/>\n" +
66 " </likes>\n" +
67 "</person>";
68
69 assertEquals(expected, xstream.toXML(bob));
70 }
71
72 public void testCircularReferenceToSelfXml() {
73 Person bob = new Person("bob");
74 bob.likes = bob;
75
76 String expected = "" +
77 "<person id=\"1\">\n" +
78 " <firstname>bob</firstname>\n" +
79 " <likes reference=\"1\"/>\n" +
80 "</person>";
81
82 assertEquals(expected, xstream.toXML(bob));
83 }
84
85 public void testReplacedReference() {
86 String expectedXml = ""
87 + "<element id=\"1\">\n"
88 + " <data>parent</data>\n"
89 + " <children id=\"2\">\n"
90 + " <anonymous-element id=\"3\" resolves-to=\"element\">\n"
91 + " <data>child</data>\n"
92 + " <parent reference=\"1\"/>\n"
93 + " <children id=\"4\"/>\n"
94 + " </anonymous-element>\n"
95 + " </children>\n"
96 + "</element>";
97
98 replacedReference(expectedXml);
99 }
100
101 public void testCanReferenceDeserializedNullValues() {
102 xstream.alias("test", Mapper.Null.class);
103 String xml = ""
104 + "<list id=\"1\">\n"
105 + " <test id=\"2\"/>\n"
106 + " <test reference=\"2\"/>\n"
107 + "</list>";
108 List list = (List)xstream.fromXML(xml);
109 assertEquals(2, list.size());
110 assertNull(list.get(0));
111 assertNull(list.get(1));
112 }
113 }
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 29. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15
16 import com.thoughtworks.acceptance.objects.StandardObject;
17 import com.thoughtworks.xstream.InitializationException;
18
19 /**
20 * @author J&ouml;rg Schaible
21 */
22 public class ImplicitArrayTest extends AbstractAcceptanceTest {
23
24 protected void setUp() throws Exception {
25 super.setUp();
26 xstream.alias("farm", Farm.class);
27 xstream.alias("animal", Animal.class);
28 xstream.alias("MEGA-farm", MegaFarm.class);
29 xstream.ignoreUnknownElements();
30 }
31
32 public static class Farm extends StandardObject {
33 private transient int idx;
34 Animal[] animals;
35 }
36
37 public static class Animal extends StandardObject implements Comparable {
38 String name;
39
40 public Animal(String name) {
41 this.name = name;
42 }
43
44 public int compareTo(Object o) {
45 return name.compareTo(((Animal)o).name);
46 }
47 }
48
49 public void testWithDirectType() {
50 Farm farm = new Farm();
51 farm.animals = new Animal[] {
52 new Animal("Cow"),
53 new Animal("Sheep")
54 };
55
56 String expected = "" +
57 "<farm>\n" +
58 " <animal>\n" +
59 " <name>Cow</name>\n" +
60 " </animal>\n" +
61 " <animal>\n" +
62 " <name>Sheep</name>\n" +
63 " </animal>\n" +
64 "</farm>";
65
66 xstream.addImplicitArray(Farm.class, "animals");
67 assertBothWays(farm, expected);
68 }
69
70 public static class MegaFarm extends Farm {
71 String separator = "---";
72 String[] names;
73 }
74
75 public void testInheritsImplicitArrayFromSuperclass() {
76 Farm farm = new MegaFarm(); // subclass
77 farm.animals = new Animal[] {
78 new Animal("Cow"),
79 new Animal("Sheep")
80 };
81
82 String expected = "" +
83 "<MEGA-farm>\n" +
84 " <animal>\n" +
85 " <name>Cow</name>\n" +
86 " </animal>\n" +
87 " <animal>\n" +
88 " <name>Sheep</name>\n" +
89 " </animal>\n" +
90 " <separator>---</separator>\n" +
91 "</MEGA-farm>";
92
93 xstream.addImplicitCollection(Farm.class, "animals");
94 assertBothWays(farm, expected);
95 }
96
97 public void testSupportsInheritedAndDirectDeclaredImplicitArraysAtOnce() {
98 MegaFarm farm = new MegaFarm(); // subclass
99 farm.animals = new Animal[] {
100 new Animal("Cow"),
101 new Animal("Sheep")
102 };
103 farm.names = new String[] {
104 "McDonald",
105 "Ponte Rosa"
106 };
107
108 String expected = "" +
109 "<MEGA-farm>\n" +
110 " <animal>\n" +
111 " <name>Cow</name>\n" +
112 " </animal>\n" +
113 " <animal>\n" +
114 " <name>Sheep</name>\n" +
115 " </animal>\n" +
116 " <separator>---</separator>\n" +
117 " <name>McDonald</name>\n" +
118 " <name>Ponte Rosa</name>\n" +
119 "</MEGA-farm>";
120
121 xstream.addImplicitArray(Farm.class, "animals");
122 xstream.addImplicitArray(MegaFarm.class, "names", "name");
123 assertBothWays(farm, expected);
124 }
125
126 public void testInheritedAndDirectDeclaredImplicitArraysAtOnceIsNotDeclarationSequenceDependent() {
127 MegaFarm farm = new MegaFarm(); // subclass
128 farm.animals = new Animal[] {
129 new Animal("Cow"),
130 new Animal("Sheep")
131 };
132 farm.names = new String[] {
133 "McDonald",
134 "Ponte Rosa"
135 };
136
137 String expected = "" +
138 "<MEGA-farm>\n" +
139 " <animal>\n" +
140 " <name>Cow</name>\n" +
141 " </animal>\n" +
142 " <animal>\n" +
143 " <name>Sheep</name>\n" +
144 " </animal>\n" +
145 " <separator>---</separator>\n" +
146 " <name>McDonald</name>\n" +
147 " <name>Ponte Rosa</name>\n" +
148 "</MEGA-farm>";
149
150 xstream.addImplicitArray(MegaFarm.class, "names", "name");
151 xstream.addImplicitArray(Farm.class, "animals");
152 assertBothWays(farm, expected);
153 }
154
155 public void testAllowsSubclassToOverrideImplicitCollectionInSuperclass() {
156 Farm farm = new MegaFarm(); // subclass
157 farm.animals = new Animal[] {
158 new Animal("Cow"),
159 new Animal("Sheep")
160 };
161
162 String expected = "" +
163 "<MEGA-farm>\n" +
164 " <animal>\n" +
165 " <name>Cow</name>\n" +
166 " </animal>\n" +
167 " <animal>\n" +
168 " <name>Sheep</name>\n" +
169 " </animal>\n" +
170 " <separator>---</separator>\n" +
171 "</MEGA-farm>";
172
173 xstream.addImplicitCollection(MegaFarm.class, "animals");
174 assertBothWays(farm, expected);
175 }
176
177 public void testAllowDifferentImplicitArrayDefinitionsInSubclass() {
178 Farm farm = new Farm();
179 farm.animals = new Animal[] {
180 new Animal("Cod"),
181 new Animal("Salmon")
182 };
183 MegaFarm megaFarm = new MegaFarm(); // subclass
184 megaFarm.animals = new Animal[] {
185 new Animal("Cow"),
186 new Animal("Sheep")
187 };
188 megaFarm.names = new String[] {
189 "McDonald",
190 "Ponte Rosa"
191 };
192
193 List list = new ArrayList();
194 list.add(farm);
195 list.add(megaFarm);
196 String expected = "" +
197 "<list>\n" +
198 " <farm>\n" +
199 " <fish>\n" +
200 " <name>Cod</name>\n" +
201 " </fish>\n" +
202 " <fish>\n" +
203 " <name>Salmon</name>\n" +
204 " </fish>\n" +
205 " </farm>\n" +
206 " <MEGA-farm>\n" +
207 " <animal>\n" +
208 " <name>Cow</name>\n" +
209 " </animal>\n" +
210 " <animal>\n" +
211 " <name>Sheep</name>\n" +
212 " </animal>\n" +
213 " <separator>---</separator>\n" +
214 " <name>McDonald</name>\n" +
215 " <name>Ponte Rosa</name>\n" +
216 " </MEGA-farm>\n" +
217 "</list>";
218
219 xstream.addImplicitArray(Farm.class, "animals", "fish");
220 xstream.addImplicitArray(MegaFarm.class, "animals");
221 xstream.addImplicitArray(MegaFarm.class, "names", "name");
222 assertBothWays(list, expected);
223 }
224
225 public static class House extends StandardObject {
226 private Room[] rooms;
227 private String separator = "---";
228 private Person[] people;
229
230 public List getPeople() {
231 return Arrays.asList(people);
232 }
233
234 public List getRooms() {
235 return Arrays.asList(rooms);
236 }
237 }
238
239 public static class Room extends StandardObject {
240 private String name;
241
242 public Room(String name) {
243 this.name = name;
244 }
245 }
246
247 public static class Person extends StandardObject {
248 private String name;
249 private String[] emailAddresses;
250
251 public Person(String name) {
252 this.name = name;
253 }
254 }
255
256 public void testMultipleArraysBasedOnDifferentType() {
257 House house = new House();
258 house.rooms = new Room[] {
259 new Room("kitchen"),
260 new Room("bathroom")
261 };
262 Person joe = new Person("joe");
263 joe.emailAddresses = new String[]{
264 "joe@house.org",
265 "joe.farmer@house.org"
266 };
267 Person jaimie = new Person("jaimie");
268 jaimie.emailAddresses = new String[]{
269 "jaimie@house.org",
270 "jaimie.farmer@house.org",
271 "jaimie.ann.farmer@house.org"
272 };
273 house.people = new Person[]{
274 joe,
275 jaimie
276 };
277
278 String expected = ""
279 + "<house>\n"
280 + " <room>\n"
281 + " <name>kitchen</name>\n"
282 + " </room>\n"
283 + " <room>\n"
284 + " <name>bathroom</name>\n"
285 + " </room>\n"
286 + " <separator>---</separator>\n"
287 + " <person>\n"
288 + " <name>joe</name>\n"
289 + " <email>joe@house.org</email>\n"
290 + " <email>joe.farmer@house.org</email>\n"
291 + " </person>\n"
292 + " <person>\n"
293 + " <name>jaimie</name>\n"
294 + " <email>jaimie@house.org</email>\n"
295 + " <email>jaimie.farmer@house.org</email>\n"
296 + " <email>jaimie.ann.farmer@house.org</email>\n"
297 + " </person>\n"
298 + "</house>";
299
300 xstream.alias("room", Room.class);
301 xstream.alias("house", House.class);
302 xstream.alias("person", Person.class);
303 xstream.addImplicitArray(House.class, "rooms");
304 xstream.addImplicitArray(House.class, "people");
305 xstream.addImplicitArray(Person.class, "emailAddresses", "email");
306
307 House serializedHouse = (House)assertBothWays(house, expected);
308 assertEquals(house.getPeople(), serializedHouse.getPeople());
309 assertEquals(house.getRooms(), serializedHouse.getRooms());
310 }
311
312 public static class NumberedRoom extends Room {
313 private int number;
314
315 public NumberedRoom(int number) {
316 super("room");
317 this.number = number;
318 }
319 }
320
321 public void testArraysWithDerivedElements() {
322 House house = new House();
323 house.rooms = new Room[] {
324 new Room("kitchen"),
325 new NumberedRoom(13)
326 };
327
328 String expected = ""
329 + "<house>\n"
330 + " <room>\n"
331 + " <name>kitchen</name>\n"
332 + " </room>\n"
333 + " <room class=\"chamber\" number=\"13\">\n"
334 + " <name>room</name>\n"
335 + " </room>\n"
336 + " <separator>---</separator>\n"
337 + "</house>";
338
339 xstream.alias("house", House.class);
340 xstream.alias("chamber", NumberedRoom.class);
341 xstream.addImplicitArray(House.class, "rooms", "room");
342 xstream.useAttributeFor(int.class);
343
344 House serializedHouse = (House)assertBothWays(house, expected);
345 assertEquals(house.getRooms(), serializedHouse.getRooms());
346 }
347
348 public static class Aquarium extends StandardObject {
349 private String name;
350 private String[] fish;
351
352 public Aquarium(String name) {
353 this.name = name;
354 }
355 }
356
357 public void testWithExplicitItemNameMatchingTheNameOfTheFieldWithTheArray() {
358 Aquarium aquarium = new Aquarium("hatchery");
359 aquarium.fish = new String[]{
360 "salmon",
361 "halibut",
362 "snapper"
363 };
364
365 String expected = "" +
366 "<aquarium>\n" +
367 " <name>hatchery</name>\n" +
368 " <fish>salmon</fish>\n" +
369 " <fish>halibut</fish>\n" +
370 " <fish>snapper</fish>\n" +
371 "</aquarium>";
372
373 xstream.alias("aquarium", Aquarium.class);
374 xstream.addImplicitArray(Aquarium.class, "fish", "fish");
375
376 assertBothWays(aquarium, expected);
377 }
378
379 public void testWithImplicitNameMatchingTheNameOfTheFieldWithTheArray() {
380 Aquarium aquarium = new Aquarium("hatchery");
381 aquarium.fish = new String[]{
382 "salmon",
383 "halibut",
384 "snapper"
385 };
386
387 String expected = "" +
388 "<aquarium>\n" +
389 " <name>hatchery</name>\n" +
390 " <fish>salmon</fish>\n" +
391 " <fish>halibut</fish>\n" +
392 " <fish>snapper</fish>\n" +
393 "</aquarium>";
394
395 xstream.alias("aquarium", Aquarium.class);
396 xstream.alias("fish", String.class);
397 xstream.addImplicitArray(Aquarium.class, "fish");
398
399 assertBothWays(aquarium, expected);
400 }
401
402 public void testWithAliasedItemNameMatchingTheAliasedNameOfTheFieldWithTheArray() {
403 Aquarium aquarium = new Aquarium("hatchery");
404 aquarium.fish = new String[]{
405 "salmon",
406 "halibut",
407 "snapper"
408 };
409
410 String expected = "" +
411 "<aquarium>\n" +
412 " <name>hatchery</name>\n" +
413 " <animal>salmon</animal>\n" +
414 " <animal>halibut</animal>\n" +
415 " <animal>snapper</animal>\n" +
416 "</aquarium>";
417
418 xstream.alias("aquarium", Aquarium.class);
419 xstream.aliasField("animal", Aquarium.class, "fish");
420 xstream.addImplicitArray(Aquarium.class, "fish", "animal");
421
422 assertBothWays(aquarium, expected);
423 }
424
425 public void testCanBeDeclaredOnlyForMatchingType() {
426 try {
427 xstream.addImplicitArray(Animal.class, "name");
428 fail("Thrown " + InitializationException.class.getName() + " expected");
429 } catch (final InitializationException e) {
430 assertTrue(e.getMessage().indexOf("declares no collection") >= 0);
431 }
432 }
433
434 public void testCanBeDeclaredOnlyForMatchingComponentType() {
435 try {
436 xstream.addImplicitArray(Aquarium.class, "fish", Farm.class);
437 fail("Thrown " + InitializationException.class.getName() + " expected");
438 } catch (final InitializationException e) {
439 assertTrue(e.getMessage().indexOf("array type is not compatible") >= 0);
440 }
441 }
442
443 public void testWithNullElement() {
444 Farm farm = new Farm();
445 farm.animals = new Animal[] {
446 new Animal("Cow"),
447 null,
448 new Animal("Sheep")
449 };
450
451 String expected = "" +
452 "<farm>\n" +
453 " <animal>\n" +
454 " <name>Cow</name>\n" +
455 " </animal>\n" +
456 " <null/>\n" +
457 " <animal>\n" +
458 " <name>Sheep</name>\n" +
459 " </animal>\n" +
460 "</farm>";
461
462 xstream.addImplicitArray(Farm.class, "animals");
463 assertBothWays(farm, expected);
464 }
465
466 public void testWithAliasAndNullElement() {
467 Farm farm = new Farm();
468 farm.animals = new Animal[] {
469 null,
470 new Animal("Sheep")
471 };
472
473 String expected = "" +
474 "<farm>\n" +
475 " <null/>\n" +
476 " <beast>\n" +
477 " <name>Sheep</name>\n" +
478 " </beast>\n" +
479 "</farm>";
480
481 xstream.addImplicitArray(Farm.class, "animals", "beast");
482 assertBothWays(farm, expected);
483 }
484
485 static class PrimitiveArray {
486 int[] ints;
487 };
488
489 public void testWithPrimitiveArray() {
490 PrimitiveArray pa = new PrimitiveArray();
491 pa.ints = new int[]{ 47, 11 };
492
493 String expected = "" +
494 "<primitives>\n" +
495 " <int>47</int>\n" +
496 " <int>11</int>\n" +
497 "</primitives>";
498
499 xstream.alias("primitives", PrimitiveArray.class);
500 xstream.addImplicitArray(PrimitiveArray.class, "ints");
501 assertBothWays(pa, expected);
502 }
503
504 static class MultiDimenstionalArrays {
505 Object[][] multiObject;
506 String[][] multiString;
507 int[][] multiInt;
508 };
509
510 public void testMultiDimensionalDirectArray() {
511 MultiDimenstionalArrays multiDim = new MultiDimenstionalArrays();
512 multiDim.multiString = new String[][]{
513 new String[]{ "1", "2" },
514 new String[]{ "a", "b", "c" }
515 };
516
517 String expected = "" +
518 "<N>\n" +
519 " <string-array>\n" +
520 " <string>1</string>\n" +
521 " <string>2</string>\n" +
522 " </string-array>\n" +
523 " <string-array>\n" +
524 " <string>a</string>\n" +
525 " <string>b</string>\n" +
526 " <string>c</string>\n" +
527 " </string-array>\n" +
528 "</N>";
529
530 xstream.alias("N", MultiDimenstionalArrays.class);
531 xstream.addImplicitArray(MultiDimenstionalArrays.class, "multiString");
532 assertBothWays(multiDim, expected);
533 }
534
535 public void testMultiDimensionalPrimitiveArray() {
536 MultiDimenstionalArrays multiDim = new MultiDimenstionalArrays();
537 multiDim.multiInt = new int[][]{
538 new int[]{ 1, 2 },
539 new int[]{ 0, -1, -2 }
540 };
541
542 String expected = "" +
543 "<N>\n" +
544 " <int-array>\n" +
545 " <int>1</int>\n" +
546 " <int>2</int>\n" +
547 " </int-array>\n" +
548 " <int-array>\n" +
549 " <int>0</int>\n" +
550 " <int>-1</int>\n" +
551 " <int>-2</int>\n" +
552 " </int-array>\n" +
553 "</N>";
554
555 xstream.alias("N", MultiDimenstionalArrays.class);
556 xstream.addImplicitArray(MultiDimenstionalArrays.class, "multiInt");
557 assertBothWays(multiDim, expected);
558 }
559
560 public void testMultiDimensionalArrayWithAlias() {
561 MultiDimenstionalArrays multiDim = new MultiDimenstionalArrays();
562 multiDim.multiObject = new Object[][]{
563 new String[]{ "1" },
564 new Object[]{ "a", Boolean.FALSE }
565 };
566
567 String expected = "" +
568 "<N>\n" +
569 " <M class=\"string-array\">\n" +
570 " <string>1</string>\n" +
571 " </M>\n" +
572 " <M>\n" +
573 " <string>a</string>\n" +
574 " <boolean>false</boolean>\n" +
575 " </M>\n" +
576 "</N>";
577
578 xstream.alias("N", MultiDimenstionalArrays.class);
579 xstream.addImplicitArray(MultiDimenstionalArrays.class, "multiObject", "M");
580 assertBothWays(multiDim, expected);
581 }
582 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013 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 14. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.InitializationException;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.HashSet;
19 import java.util.LinkedList;
20 import java.util.List;
21 import java.util.Set;
22 import java.util.TreeSet;
23
24 public class ImplicitCollectionTest extends AbstractAcceptanceTest {
25
26 public static class Farm extends StandardObject {
27 int size;
28 List animals = new ArrayList();
29
30 public Farm(int size) {
31 this.size = size;
32 }
33
34 public void add(Animal animal) {
35 animals.add(animal);
36 }
37 }
38
39 public static class Animal extends StandardObject implements Comparable {
40 String name;
41
42 public Animal(String name) {
43 this.name = name;
44 }
45
46 public int compareTo(Object o) {
47 return name.compareTo(((Animal)o).name);
48 }
49 }
50
51 protected void setUp() throws Exception {
52 super.setUp();
53 xstream.alias("zoo", Zoo.class);
54 xstream.alias("farm", Farm.class);
55 xstream.alias("animal", Animal.class);
56 xstream.alias("room", Room.class);
57 xstream.alias("house", House.class);
58 xstream.alias("person", Person.class);
59 xstream.ignoreUnknownElements();
60 }
61
62 public void testWithout() {
63 Farm farm = new Farm(100);
64 farm.add(new Animal("Cow"));
65 farm.add(new Animal("Sheep"));
66
67 String expected = "" +
68 "<farm>\n" +
69 " <size>100</size>\n" +
70 " <animals>\n" +
71 " <animal>\n" +
72 " <name>Cow</name>\n" +
73 " </animal>\n" +
74 " <animal>\n" +
75 " <name>Sheep</name>\n" +
76 " </animal>\n" +
77 " </animals>\n" +
78 "</farm>";
79
80 assertBothWays(farm, expected);
81 }
82
83 public void testWithList() {
84 Farm farm = new Farm(100);
85 farm.add(new Animal("Cow"));
86 farm.add(new Animal("Sheep"));
87
88 String expected = "" +
89 "<farm>\n" +
90 " <size>100</size>\n" +
91 " <animal>\n" +
92 " <name>Cow</name>\n" +
93 " </animal>\n" +
94 " <animal>\n" +
95 " <name>Sheep</name>\n" +
96 " </animal>\n" +
97 "</farm>";
98
99 xstream.addImplicitCollection(Farm.class, "animals");
100 assertBothWays(farm, expected);
101 }
102
103 public static class MegaFarm extends Farm {
104 String separator = "---";
105 List names;
106 public MegaFarm(int size) {
107 super(size);
108 }
109 }
110
111 public void testInheritsImplicitCollectionFromSuperclass() {
112 xstream.alias("MEGA-farm", MegaFarm.class);
113
114 Farm farm = new MegaFarm(100); // subclass
115 farm.add(new Animal("Cow"));
116 farm.add(new Animal("Sheep"));
117
118 String expected = "" +
119 "<MEGA-farm>\n" +
120 " <size>100</size>\n" +
121 " <animal>\n" +
122 " <name>Cow</name>\n" +
123 " </animal>\n" +
124 " <animal>\n" +
125 " <name>Sheep</name>\n" +
126 " </animal>\n" +
127 " <separator>---</separator>\n" +
128 "</MEGA-farm>";
129
130 xstream.addImplicitCollection(Farm.class, "animals");
131 assertBothWays(farm, expected);
132 }
133
134 public void testSupportsInheritedAndDirectDeclaredImplicitCollectionAtOnce() {
135 xstream.alias("MEGA-farm", MegaFarm.class);
136
137 MegaFarm farm = new MegaFarm(100); // subclass
138 farm.add(new Animal("Cow"));
139 farm.add(new Animal("Sheep"));
140 farm.names = new ArrayList();
141 farm.names.add("McDonald");
142 farm.names.add("Ponte Rosa");
143
144 String expected = "" +
145 "<MEGA-farm>\n" +
146 " <size>100</size>\n" +
147 " <animal>\n" +
148 " <name>Cow</name>\n" +
149 " </animal>\n" +
150 " <animal>\n" +
151 " <name>Sheep</name>\n" +
152 " </animal>\n" +
153 " <separator>---</separator>\n" +
154 " <name>McDonald</name>\n" +
155 " <name>Ponte Rosa</name>\n" +
156 "</MEGA-farm>";
157
158 xstream.addImplicitCollection(Farm.class, "animals");
159 xstream.addImplicitCollection(MegaFarm.class, "names", "name", String.class);
160 assertBothWays(farm, expected);
161 }
162
163 public void testInheritedAndDirectDeclaredImplicitCollectionAtOnceIsNotDeclarationSequenceDependent() {
164 xstream.alias("MEGA-farm", MegaFarm.class);
165
166 MegaFarm farm = new MegaFarm(100); // subclass
167 farm.add(new Animal("Cow"));
168 farm.add(new Animal("Sheep"));
169 farm.names = new ArrayList();
170 farm.names.add("McDonald");
171 farm.names.add("Ponte Rosa");
172
173 String expected = "" +
174 "<MEGA-farm>\n" +
175 " <size>100</size>\n" +
176 " <animal>\n" +
177 " <name>Cow</name>\n" +
178 " </animal>\n" +
179 " <animal>\n" +
180 " <name>Sheep</name>\n" +
181 " </animal>\n" +
182 " <separator>---</separator>\n" +
183 " <name>McDonald</name>\n" +
184 " <name>Ponte Rosa</name>\n" +
185 "</MEGA-farm>";
186
187 xstream.addImplicitCollection(MegaFarm.class, "names", "name", String.class);
188 xstream.addImplicitCollection(Farm.class, "animals");
189 assertBothWays(farm, expected);
190 }
191
192 public void testAllowsSubclassToOverrideImplicitCollectionInSuperclass() {
193 xstream.alias("MEGA-farm", MegaFarm.class);
194
195 Farm farm = new MegaFarm(100); // subclass
196 farm.add(new Animal("Cow"));
197 farm.add(new Animal("Sheep"));
198
199 String expected = "" +
200 "<MEGA-farm>\n" +
201 " <size>100</size>\n" +
202 " <animal>\n" +
203 " <name>Cow</name>\n" +
204 " </animal>\n" +
205 " <animal>\n" +
206 " <name>Sheep</name>\n" +
207 " </animal>\n" +
208 " <separator>---</separator>\n" +
209 "</MEGA-farm>";
210
211 xstream.addImplicitCollection(MegaFarm.class, "animals");
212 assertBothWays(farm, expected);
213 }
214
215 public void testAllowDifferentImplicitCollectionDefinitionsInSubclass() {
216 xstream.alias("MEGA-farm", MegaFarm.class);
217
218 Farm farm = new Farm(10);
219 farm.add(new Animal("Cod"));
220 farm.add(new Animal("Salmon"));
221 MegaFarm megaFarm = new MegaFarm(100); // subclass
222 megaFarm.add(new Animal("Cow"));
223 megaFarm.add(new Animal("Sheep"));
224 megaFarm.names = new ArrayList();
225 megaFarm.names.add("McDonald");
226 megaFarm.names.add("Ponte Rosa");
227
228 List list = new ArrayList();
229 list.add(farm);
230 list.add(megaFarm);
231 String expected = "" +
232 "<list>\n" +
233 " <farm>\n" +
234 " <size>10</size>\n" +
235 " <fish>\n" +
236 " <name>Cod</name>\n" +
237 " </fish>\n" +
238 " <fish>\n" +
239 " <name>Salmon</name>\n" +
240 " </fish>\n" +
241 " </farm>\n" +
242 " <MEGA-farm>\n" +
243 " <size>100</size>\n" +
244 " <animal>\n" +
245 " <name>Cow</name>\n" +
246 " </animal>\n" +
247 " <animal>\n" +
248 " <name>Sheep</name>\n" +
249 " </animal>\n" +
250 " <separator>---</separator>\n" +
251 " <name>McDonald</name>\n" +
252 " <name>Ponte Rosa</name>\n" +
253 " </MEGA-farm>\n" +
254 "</list>";
255
256 xstream.addImplicitCollection(Farm.class, "animals", "fish", Animal.class);
257 xstream.addImplicitCollection(MegaFarm.class, "animals");
258 xstream.addImplicitCollection(MegaFarm.class, "names", "name", String.class);
259 assertBothWays(list, expected);
260 }
261
262 public static class House extends StandardObject {
263 private List rooms = new ArrayList();
264 private String separator = "---";
265 private List people = new ArrayList();
266
267 public void add(Room room) {
268 rooms.add(room);
269 }
270
271 public void add(Person person) {
272 people.add(person);
273 }
274
275 public List getPeople() {
276 return Collections.unmodifiableList(people);
277 }
278
279 public List getRooms() {
280 return Collections.unmodifiableList(rooms);
281 }
282 }
283
284 public static class Room extends StandardObject {
285 private String name;
286
287 public Room(String name) {
288 this.name = name;
289 }
290 }
291
292 public static class Person extends StandardObject {
293 private String name;
294 private LinkedList emailAddresses = new LinkedList();
295
296 public Person(String name) {
297 this.name = name;
298 }
299
300 public void addEmailAddress(String email) {
301 emailAddresses.add(email);
302 }
303 }
304
305 public void testDefaultCollectionBasedOnType() {
306 House house = new House();
307 house.add(new Room("kitchen"));
308 house.add(new Room("bathroom"));
309 Person joe = new Person("joe");
310 joe.addEmailAddress("joe@house.org");
311 joe.addEmailAddress("joe.farmer@house.org");
312 house.add(joe);
313 Person jaimie = new Person("jaimie");
314 jaimie.addEmailAddress("jaimie@house.org");
315 jaimie.addEmailAddress("jaimie.farmer@house.org");
316 jaimie.addEmailAddress("jaimie.ann.farmer@house.org");
317 house.add(jaimie);
318
319 String expected = ""
320 + "<house>\n"
321 + " <room>\n"
322 + " <name>kitchen</name>\n"
323 + " </room>\n"
324 + " <room>\n"
325 + " <name>bathroom</name>\n"
326 + " </room>\n"
327 + " <separator>---</separator>\n"
328 + " <person>\n"
329 + " <name>joe</name>\n"
330 + " <email>joe@house.org</email>\n"
331 + " <email>joe.farmer@house.org</email>\n"
332 + " </person>\n"
333 + " <person>\n"
334 + " <name>jaimie</name>\n"
335 + " <email>jaimie@house.org</email>\n"
336 + " <email>jaimie.farmer@house.org</email>\n"
337 + " <email>jaimie.ann.farmer@house.org</email>\n"
338 + " </person>\n"
339 + "</house>";
340
341 xstream.addImplicitCollection(House.class, "rooms", Room.class);
342 xstream.addImplicitCollection(House.class, "people", Person.class);
343 xstream.addImplicitCollection(Person.class, "emailAddresses", "email", String.class);
344
345 House serializedHouse = (House)assertBothWays(house, expected);
346 assertEquals(house.getPeople(), serializedHouse.getPeople());
347 assertEquals(house.getRooms(), serializedHouse.getRooms());
348 }
349
350 public void testWithEMPTY_LIST() {
351 House house = new House();
352 house.people = Collections.EMPTY_LIST;
353 house.rooms = Collections.EMPTY_LIST;
354 xstream.addImplicitCollection(House.class, "rooms", Room.class);
355 xstream.addImplicitCollection(House.class, "people", Person.class);
356 String expected = ""
357 + "<house>\n"
358 + " <separator>---</separator>\n"
359 + "</house>";
360 assertEquals(expected, xstream.toXML(house));
361 }
362
363 public static class Zoo extends StandardObject {
364 private Set animals;
365 public Zoo() {
366 this(new HashSet());
367 }
368 public Zoo(Set set) {
369 animals = set;
370 }
371 public void add(Animal animal) {
372 animals.add(animal);
373 }
374 }
375
376 public void testWithSet() {
377 Zoo zoo = new Zoo();
378 zoo.add(new Animal("Lion"));
379 zoo.add(new Animal("Ape"));
380
381 String expected = "" +
382 "<zoo>\n" +
383 " <animal>\n" +
384 " <name>Lion</name>\n" +
385 " </animal>\n" +
386 " <animal>\n" +
387 " <name>Ape</name>\n" +
388 " </animal>\n" +
389 "</zoo>";
390
391 xstream.addImplicitCollection(Zoo.class, "animals");
392 assertBothWaysNormalized(zoo, expected, "zoo", "animal", "name");
393 }
394
395 public void testWithDifferentDefaultImplementation() {
396 String xml = "" +
397 "<zoo>\n" +
398 " <animal>\n" +
399 " <name>Lion</name>\n" +
400 " </animal>\n" +
401 " <animal>\n" +
402 " <name>Ape</name>\n" +
403 " </animal>\n" +
404 "</zoo>";
405
406 xstream.addImplicitCollection(Zoo.class, "animals");
407 xstream.addDefaultImplementation(TreeSet.class, Set.class);
408 Zoo zoo = (Zoo)xstream.fromXML(xml);
409 assertTrue("Collection was a " + zoo.animals.getClass().getName(), zoo.animals instanceof TreeSet);
410 }
411
412 public void testWithSortedSet() {
413 Zoo zoo = new Zoo(new TreeSet());
414 zoo.add(new Animal("Lion"));
415 zoo.add(new Animal("Ape"));
416
417 String expected = "" +
418 "<zoo>\n" +
419 " <animal>\n" +
420 " <name>Ape</name>\n" +
421 " </animal>\n" +
422 " <animal>\n" +
423 " <name>Lion</name>\n" +
424 " </animal>\n" +
425 "</zoo>";
426
427 xstream.addImplicitCollection(Zoo.class, "animals");
428 xstream.addDefaultImplementation(TreeSet.class, Set.class);
429 assertBothWays(zoo, expected);
430 }
431
432 public static class Aquarium extends StandardObject {
433 private String name;
434 private List fish = new ArrayList();
435
436 public Aquarium(String name) {
437 this.name = name;
438 }
439
440 public void addFish(String fish) {
441 this.fish.add(fish);
442 }
443 }
444
445 public void testWithExplicitItemNameMatchingTheNameOfTheFieldWithTheCollection() {
446 Aquarium aquarium = new Aquarium("hatchery");
447 aquarium.addFish("salmon");
448 aquarium.addFish("halibut");
449 aquarium.addFish("snapper");
450
451 String expected = "" +
452 "<aquarium>\n" +
453 " <name>hatchery</name>\n" +
454 " <fish>salmon</fish>\n" +
455 " <fish>halibut</fish>\n" +
456 " <fish>snapper</fish>\n" +
457 "</aquarium>";
458
459 xstream.alias("aquarium", Aquarium.class);
460 xstream.addImplicitCollection(Aquarium.class, "fish", "fish", String.class);
461
462 assertBothWays(aquarium, expected);
463 }
464
465 public void testWithImplicitNameMatchingTheNameOfTheFieldWithTheCollection() {
466 Aquarium aquarium = new Aquarium("hatchery");
467 aquarium.addFish("salmon");
468 aquarium.addFish("halibut");
469 aquarium.addFish("snapper");
470
471 String expected = "" +
472 "<aquarium>\n" +
473 " <name>hatchery</name>\n" +
474 " <fish>salmon</fish>\n" +
475 " <fish>halibut</fish>\n" +
476 " <fish>snapper</fish>\n" +
477 "</aquarium>";
478
479 xstream.alias("aquarium", Aquarium.class);
480 xstream.alias("fish", String.class);
481 xstream.addImplicitCollection(Aquarium.class, "fish");
482
483 assertBothWays(aquarium, expected);
484 }
485
486 public void testWithAliasedItemNameMatchingTheAliasedNameOfTheFieldWithTheCollection() {
487 Aquarium aquarium = new Aquarium("hatchery");
488 aquarium.addFish("salmon");
489 aquarium.addFish("halibut");
490 aquarium.addFish("snapper");
491
492 String expected = "" +
493 "<aquarium>\n" +
494 " <name>hatchery</name>\n" +
495 " <animal>salmon</animal>\n" +
496 " <animal>halibut</animal>\n" +
497 " <animal>snapper</animal>\n" +
498 "</aquarium>";
499
500 xstream.alias("aquarium", Aquarium.class);
501 xstream.aliasField("animal", Aquarium.class, "fish");
502 xstream.addImplicitCollection(Aquarium.class, "fish", "animal", String.class);
503
504 assertBothWays(aquarium, expected);
505 }
506
507 public void testCanBeDeclaredOnlyForMatchingType() {
508 try {
509 xstream.addImplicitCollection(Animal.class, "name");
510 fail("Thrown " + InitializationException.class.getName() + " expected");
511 } catch (final InitializationException e) {
512 assertTrue(e.getMessage().indexOf("declares no collection") >= 0);
513 }
514 }
515
516 public void testWithNullElement() {
517 Farm farm = new Farm(100);
518 farm.add(null);
519 farm.add(new Animal("Cow"));
520
521 String expected = "" +
522 "<farm>\n" +
523 " <size>100</size>\n" +
524 " <null/>\n" +
525 " <animal>\n" +
526 " <name>Cow</name>\n" +
527 " </animal>\n" +
528 "</farm>";
529
530 xstream.addImplicitCollection(Farm.class, "animals");
531 assertBothWays(farm, expected);
532 }
533
534 public void testWithAliasAndNullElement() {
535 Farm farm = new Farm(100);
536 farm.add(null);
537 farm.add(new Animal("Cow"));
538
539 String expected = "" +
540 "<farm>\n" +
541 " <size>100</size>\n" +
542 " <null/>\n" +
543 " <beast>\n" +
544 " <name>Cow</name>\n" +
545 " </beast>\n" +
546 "</farm>";
547
548 xstream.addImplicitCollection(Farm.class, "animals", "beast", Animal.class);
549 assertBothWays(farm, expected);
550 }
551 }
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 05. August 2011 Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.acceptance.objects.Hardware;
13 import com.thoughtworks.acceptance.objects.Product;
14 import com.thoughtworks.acceptance.objects.SampleMaps;
15 import com.thoughtworks.acceptance.objects.Software;
16 import com.thoughtworks.acceptance.objects.StandardObject;
17 import com.thoughtworks.xstream.converters.collections.MapConverter;
18 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TreeMap;
25
26 public class ImplicitMapTest extends AbstractAcceptanceTest {
27
28 public static class Farm extends StandardObject {
29 int size;
30 List animals = new ArrayList();
31
32 public Farm(int size) {
33 this.size = size;
34 }
35
36 public void add(Animal animal) {
37 animals.add(animal);
38 }
39 }
40
41 public static class Animal extends StandardObject implements Comparable {
42 String name;
43
44 public Animal(String name) {
45 this.name = name;
46 }
47
48 public int compareTo(Object o) {
49 return name.compareTo(((Animal)o).name);
50 }
51 }
52
53 protected void setUp() throws Exception {
54 super.setUp();
55 xstream.registerConverter(new MapConverter(xstream.getMapper()) {
56 public boolean canConvert(Class type) {
57 return type == OrderRetainingMap.class;
58 }
59 });
60 xstream.addDefaultImplementation(OrderRetainingMap.class, Map.class);
61 xstream.alias("sample", SampleMaps.class);
62 xstream.alias("software", Software.class);
63 xstream.alias("hardware", Hardware.class);
64 xstream.alias("product", Product.class);
65 xstream.ignoreUnknownElements();
66 }
67
68 public void testWithout() {
69 SampleMaps sample = new SampleMaps();
70 sample.good = new OrderRetainingMap();
71 sample.good.put("Windows", new Software("Microsoft", "Windows"));
72 sample.good.put("Linux", new Software("Red Hat", "Linux"));
73
74 String expected = "" +
75 "<sample>\n" +
76 " <good>\n" +
77 " <entry>\n" +
78 " <string>Windows</string>\n" +
79 " <software>\n" +
80 " <vendor>Microsoft</vendor>\n" +
81 " <name>Windows</name>\n" +
82 " </software>\n" +
83 " </entry>\n" +
84 " <entry>\n" +
85 " <string>Linux</string>\n" +
86 " <software>\n" +
87 " <vendor>Red Hat</vendor>\n" +
88 " <name>Linux</name>\n" +
89 " </software>\n" +
90 " </entry>\n" +
91 " </good>\n" +
92 " <bad/>\n" +
93 "</sample>";
94
95 assertBothWays(sample, expected);
96 }
97
98 public void testWithMap() {
99 SampleMaps sample = new SampleMaps();
100 sample.good = new OrderRetainingMap();
101 sample.good.put("Windows", new Software("Microsoft", "Windows"));
102 sample.good.put("Linux", new Software("Red Hat", "Linux"));
103
104 String expected = "" +
105 "<sample>\n" +
106 " <software>\n" +
107 " <vendor>Microsoft</vendor>\n" +
108 " <name>Windows</name>\n" +
109 " </software>\n" +
110 " <software>\n" +
111 " <vendor>Red Hat</vendor>\n" +
112 " <name>Linux</name>\n" +
113 " </software>\n" +
114 " <bad/>\n" +
115 "</sample>";
116
117 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
118 assertBothWays(sample, expected);
119 }
120
121 public static class MegaSampleMaps extends SampleMaps {
122 String separator = "---";
123 Map other = new OrderRetainingMap();
124 {
125 good = new OrderRetainingMap();
126 bad = new OrderRetainingMap();
127 }
128 }
129
130 public void testInheritsImplicitMapFromSuperclass() {
131 xstream.alias("MEGA-sample", MegaSampleMaps.class);
132
133 SampleMaps sample = new MegaSampleMaps(); // subclass
134 sample.good.put("Windows", new Software("Microsoft", "Windows"));
135 sample.good.put("Linux", new Software("Red Hat", "Linux"));
136
137 String expected = "" +
138 "<MEGA-sample>\n" +
139 " <software>\n" +
140 " <vendor>Microsoft</vendor>\n" +
141 " <name>Windows</name>\n" +
142 " </software>\n" +
143 " <software>\n" +
144 " <vendor>Red Hat</vendor>\n" +
145 " <name>Linux</name>\n" +
146 " </software>\n" +
147 " <bad/>\n" +
148 " <separator>---</separator>\n" +
149 " <other/>\n" +
150 "</MEGA-sample>";
151
152 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
153 assertBothWays(sample, expected);
154 }
155
156 public void testSupportsInheritedAndDirectDeclaredImplicitMapAtOnce() {
157 xstream.alias("MEGA-sample", MegaSampleMaps.class);
158
159 MegaSampleMaps sample = new MegaSampleMaps(); // subclass
160 sample.good.put("Windows", new Software("Microsoft", "Windows"));
161 sample.good.put("Linux", new Software("Red Hat", "Linux"));
162 sample.other.put("i386", new Hardware("i386", "Intel"));
163
164 String expected = "" +
165 "<MEGA-sample>\n" +
166 " <software>\n" +
167 " <vendor>Microsoft</vendor>\n" +
168 " <name>Windows</name>\n" +
169 " </software>\n" +
170 " <software>\n" +
171 " <vendor>Red Hat</vendor>\n" +
172 " <name>Linux</name>\n" +
173 " </software>\n" +
174 " <bad/>\n" +
175 " <separator>---</separator>\n" +
176 " <hardware>\n" +
177 " <arch>i386</arch>\n" +
178 " <name>Intel</name>\n" +
179 " </hardware>\n" +
180 "</MEGA-sample>";
181
182 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
183 xstream.addImplicitMap(MegaSampleMaps.class, "other", Hardware.class, "arch");
184 assertBothWays(sample, expected);
185 }
186
187 public void testInheritedAndDirectDeclaredImplicitMapAtOnceIsNotDeclarationSequenceDependent() {
188 xstream.alias("MEGA-sample", MegaSampleMaps.class);
189
190 MegaSampleMaps sample = new MegaSampleMaps(); // subclass
191 sample.good.put("Windows", new Software("Microsoft", "Windows"));
192 sample.good.put("Linux", new Software("Red Hat", "Linux"));
193 sample.other.put("i386", new Hardware("i386", "Intel"));
194
195 String expected = "" +
196 "<MEGA-sample>\n" +
197 " <software>\n" +
198 " <vendor>Microsoft</vendor>\n" +
199 " <name>Windows</name>\n" +
200 " </software>\n" +
201 " <software>\n" +
202 " <vendor>Red Hat</vendor>\n" +
203 " <name>Linux</name>\n" +
204 " </software>\n" +
205 " <bad/>\n" +
206 " <separator>---</separator>\n" +
207 " <hardware>\n" +
208 " <arch>i386</arch>\n" +
209 " <name>Intel</name>\n" +
210 " </hardware>\n" +
211 "</MEGA-sample>";
212
213 xstream.addImplicitMap(MegaSampleMaps.class, "other", Hardware.class, "arch");
214 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
215 assertBothWays(sample, expected);
216 }
217
218 public void testAllowsSubclassToOverrideImplicitMapInSuperclass() {
219 xstream.alias("MEGA-sample", MegaSampleMaps.class);
220
221 SampleMaps sample = new MegaSampleMaps(); // subclass
222 sample.good.put("Windows", new Software("Microsoft", "Windows"));
223 sample.good.put("Linux", new Software("Red Hat", "Linux"));
224
225 String expected = "" +
226 "<MEGA-sample>\n" +
227 " <software>\n" +
228 " <vendor>Microsoft</vendor>\n" +
229 " <name>Windows</name>\n" +
230 " </software>\n" +
231 " <software>\n" +
232 " <vendor>Red Hat</vendor>\n" +
233 " <name>Linux</name>\n" +
234 " </software>\n" +
235 " <bad/>\n" +
236 " <separator>---</separator>\n" +
237 " <other/>\n" +
238 "</MEGA-sample>";
239
240 xstream.addImplicitMap(MegaSampleMaps.class, "good", Software.class, "name");
241 assertBothWays(sample, expected);
242 }
243
244 public void testAllowDifferentImplicitMapDefinitionsInSubclass() {
245 xstream.alias("MEGA-sample", MegaSampleMaps.class);
246
247 SampleMaps sample = new SampleMaps();
248 sample.good.put("Google", new Software("Google", "Android"));
249 MegaSampleMaps megaSample = new MegaSampleMaps(); // subclass
250 megaSample.good.put("Windows", new Software("Microsoft", "Windows"));
251 megaSample.good.put("Linux", new Software("Red Hat", "Linux"));
252 megaSample.other.put("i386", new Hardware("i386", "Intel"));
253
254 List list = new ArrayList();
255 list.add(sample);
256 list.add(megaSample);
257 String expected = "" +
258 "<list>\n" +
259 " <sample>\n" +
260 " <mobile>\n" +
261 " <vendor>Google</vendor>\n" +
262 " <name>Android</name>\n" +
263 " </mobile>\n" +
264 " <bad/>\n" +
265 " </sample>\n" +
266 " <MEGA-sample>\n" +
267 " <software>\n" +
268 " <vendor>Microsoft</vendor>\n" +
269 " <name>Windows</name>\n" +
270 " </software>\n" +
271 " <software>\n" +
272 " <vendor>Red Hat</vendor>\n" +
273 " <name>Linux</name>\n" +
274 " </software>\n" +
275 " <bad/>\n" +
276 " <separator>---</separator>\n" +
277 " <hardware>\n" +
278 " <arch>i386</arch>\n" +
279 " <name>Intel</name>\n" +
280 " </hardware>\n" +
281 " </MEGA-sample>\n" +
282 "</list>";
283
284 xstream.addImplicitMap(SampleMaps.class, "good", "mobile", Software.class, "vendor");
285 xstream.addImplicitMap(MegaSampleMaps.class, "good", Software.class, "name");
286 xstream.addImplicitMap(MegaSampleMaps.class, "other", Hardware.class, "arch");
287 assertBothWays(list, expected);
288 }
289
290 public void testDefaultMapBasedOnType() {
291 xstream.alias("MEGA-sample", MegaSampleMaps.class);
292
293 MegaSampleMaps sample = new MegaSampleMaps();
294 sample.good.put("Windows", new Software("Microsoft", "Windows"));
295 sample.good.put("Linux", new Software("Red Hat", "Linux"));
296 sample.good.put("Chrome", new Software("Google", "Chrome"));
297 sample.bad.put("iPhone", new Product("iPhone", "i", 399.99));
298 sample.other.put("Intel", new Hardware("i386", "Intel"));
299 sample.other.put("AMD", new Hardware("amd64", "AMD"));
300
301 String expected = "" +
302 "<MEGA-sample>\n" +
303 " <software>\n" +
304 " <vendor>Microsoft</vendor>\n" +
305 " <name>Windows</name>\n" +
306 " </software>\n" +
307 " <software>\n" +
308 " <vendor>Red Hat</vendor>\n" +
309 " <name>Linux</name>\n" +
310 " </software>\n" +
311 " <software>\n" +
312 " <vendor>Google</vendor>\n" +
313 " <name>Chrome</name>\n" +
314 " </software>\n" +
315 " <product>\n" +
316 " <name>iPhone</name>\n" +
317 " <id>i</id>\n" +
318 " <price>399.99</price>\n" +
319 " </product>\n" +
320 " <separator>---</separator>\n" +
321 " <hardware>\n" +
322 " <arch>i386</arch>\n" +
323 " <name>Intel</name>\n" +
324 " </hardware>\n" +
325 " <hardware>\n" +
326 " <arch>amd64</arch>\n" +
327 " <name>AMD</name>\n" +
328 " </hardware>\n" +
329 "</MEGA-sample>";
330
331 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
332 xstream.addImplicitMap(SampleMaps.class, "bad", Product.class, "name");
333 xstream.addImplicitMap(MegaSampleMaps.class, "other", Hardware.class, "name");
334 assertBothWays(sample, expected);
335 }
336
337 public void testWithEMPTY_MAP() {
338 SampleMaps sample = new SampleMaps();
339 sample.good = Collections.EMPTY_MAP;
340 sample.bad = Collections.EMPTY_MAP;
341
342 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
343 xstream.addImplicitMap(SampleMaps.class, "bad", Software.class, "name");
344 assertEquals("<sample/>", xstream.toXML(sample));
345 }
346
347 public void testWithSortedMap() {
348 SampleMaps sample = new SampleMaps();
349 sample.good = new TreeMap();
350 sample.good.put("Windows", new Software("Microsoft", "Windows"));
351 sample.good.put("Linux", new Software("Red Hat", "Linux"));
352
353 String expected = "" +
354 "<sample>\n" +
355 " <software>\n" +
356 " <vendor>Red Hat</vendor>\n" +
357 " <name>Linux</name>\n" +
358 " </software>\n" +
359 " <software>\n" +
360 " <vendor>Microsoft</vendor>\n" +
361 " <name>Windows</name>\n" +
362 " </software>\n" +
363 " <bad/>\n" +
364 "</sample>";
365
366 xstream.addDefaultImplementation(TreeMap.class, Map.class);
367 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
368 assertBothWays(sample, expected);
369 }
370
371 public void testWithExplicitItemNameMatchingTheNameOfTheFieldWithTheMap() {
372 SampleMaps sample = new SampleMaps();
373 sample.bad = new OrderRetainingMap();
374 sample.bad.put("Windows", new Software("Microsoft", "Windows"));
375 sample.bad.put("Linux", new Software("Red Hat", "Linux"));
376
377 String expected = "" +
378 "<sample>\n" +
379 " <good/>\n" +
380 " <bad>\n" +
381 " <vendor>Microsoft</vendor>\n" +
382 " <name>Windows</name>\n" +
383 " </bad>\n" +
384 " <bad>\n" +
385 " <vendor>Red Hat</vendor>\n" +
386 " <name>Linux</name>\n" +
387 " </bad>\n" +
388 "</sample>";
389
390 xstream.addImplicitMap(SampleMaps.class, "bad", "bad", Software.class, "name");
391 assertBothWays(sample, expected);
392 }
393
394 public void testWithImplicitNameMatchingTheNameOfTheFieldWithTheMap() {
395 SampleMaps sample = new SampleMaps();
396 sample.bad = new OrderRetainingMap();
397 sample.bad.put("Windows", new Software("Microsoft", "Windows"));
398 sample.bad.put("Linux", new Software("Red Hat", "Linux"));
399
400 String expected = "" +
401 "<sample>\n" +
402 " <good/>\n" +
403 " <bad>\n" +
404 " <vendor>Microsoft</vendor>\n" +
405 " <name>Windows</name>\n" +
406 " </bad>\n" +
407 " <bad>\n" +
408 " <vendor>Red Hat</vendor>\n" +
409 " <name>Linux</name>\n" +
410 " </bad>\n" +
411 "</sample>";
412
413 xstream.addImplicitMap(SampleMaps.class, "bad", Software.class, "name");
414 xstream.alias("bad", Software.class);
415 assertBothWays(sample, expected);
416 }
417
418 public void testWithAliasedItemNameMatchingTheAliasedNameOfTheFieldWithTheMap() {
419 SampleMaps sample = new SampleMaps();
420 sample.bad = new OrderRetainingMap();
421 sample.bad.put("Windows", new Software("Microsoft", "Windows"));
422 sample.bad.put("Linux", new Software("Red Hat", "Linux"));
423
424 String expected = "" +
425 "<sample>\n" +
426 " <good/>\n" +
427 " <test>\n" +
428 " <vendor>Microsoft</vendor>\n" +
429 " <name>Windows</name>\n" +
430 " </test>\n" +
431 " <test>\n" +
432 " <vendor>Red Hat</vendor>\n" +
433 " <name>Linux</name>\n" +
434 " </test>\n" +
435 "</sample>";
436
437 xstream.addImplicitMap(SampleMaps.class, "bad", "test", Software.class, "name");
438 xstream.aliasField("test", SampleMaps.class, "bad");
439 assertBothWays(sample, expected);
440 }
441
442 public void testWithNullElement() {
443 SampleMaps sample = new SampleMaps();
444 sample.good = new OrderRetainingMap();
445 sample.good.put(null, null);
446 sample.good.put("Linux", new Software("Red Hat", "Linux"));
447
448 String expected = "" +
449 "<sample>\n" +
450 " <null/>\n" +
451 " <software>\n" +
452 " <vendor>Red Hat</vendor>\n" +
453 " <name>Linux</name>\n" +
454 " </software>\n" +
455 " <bad/>\n" +
456 "</sample>";
457
458 xstream.addImplicitMap(SampleMaps.class, "good", Software.class, "name");
459 assertBothWays(sample, expected);
460 }
461
462 public void testWithAliasAndNullElement() {
463 SampleMaps sample = new SampleMaps();
464 sample.good = new OrderRetainingMap();
465 sample.good.put(null, null);
466 sample.good.put("Linux", new Software("Red Hat", "Linux"));
467
468 String expected = "" +
469 "<sample>\n" +
470 " <null/>\n" +
471 " <code>\n" +
472 " <vendor>Red Hat</vendor>\n" +
473 " <name>Linux</name>\n" +
474 " </code>\n" +
475 " <bad/>\n" +
476 "</sample>";
477
478 xstream.addImplicitMap(SampleMaps.class, "good", "code", Software.class, "name");
479 assertBothWays(sample, expected);
480 }
481
482 public void testCollectsDifferentTypesWithFieldOfSameName() {
483 SampleMaps sample = new SampleMaps();
484 sample.good = new OrderRetainingMap();
485 sample.good.put("iPhone", new Product("iPhone", "i", 399.99));
486 sample.good.put("Linux", new Software("Red Hat", "Linux"));
487 sample.good.put("Intel", new Hardware("i386", "Intel"));
488
489 String expected = "" +
490 "<sample>\n" +
491 " <product>\n" +
492 " <name>iPhone</name>\n" +
493 " <id>i</id>\n" +
494 " <price>399.99</price>\n" +
495 " </product>\n" +
496 " <software>\n" +
497 " <vendor>Red Hat</vendor>\n" +
498 " <name>Linux</name>\n" +
499 " </software>\n" +
500 " <hardware>\n" +
501 " <arch>i386</arch>\n" +
502 " <name>Intel</name>\n" +
503 " </hardware>\n" +
504 " <bad/>\n" +
505 "</sample>";
506
507 xstream.addImplicitMap(SampleMaps.class, "good", null, "name");
508 assertBothWays(sample, expected);
509 }
510
511 public void testSeparatesItemsBasedOnItemName() {
512 SampleMaps sample = new SampleMaps();
513 sample.good = new OrderRetainingMap();
514 sample.good.put("Chrome", new Software("Google", "Chrome"));
515 sample.bad = new OrderRetainingMap();
516 sample.bad.put("Linux", new Software("Red Hat", "Linux"));
517 sample.bad.put("Windows", new Software("Microsoft", "Windows"));
518
519 String expected = "" +
520 "<sample>\n" +
521 " <g>\n" +
522 " <vendor>Google</vendor>\n" +
523 " <name>Chrome</name>\n" +
524 " </g>\n" +
525 " <b>\n" +
526 " <vendor>Red Hat</vendor>\n" +
527 " <name>Linux</name>\n" +
528 " </b>\n" +
529 " <b>\n" +
530 " <vendor>Microsoft</vendor>\n" +
531 " <name>Windows</name>\n" +
532 " </b>\n" +
533 "</sample>";
534
535 xstream.addImplicitMap(SampleMaps.class, "good", "g", Software.class, "name");
536 xstream.addImplicitMap(SampleMaps.class, "bad", "b", Software.class, "name");
537 assertBothWays(sample, expected);
538 }
539
540 public void testWithoutKeyField() {
541 SampleMaps sample = new SampleMaps();
542 sample.good = new OrderRetainingMap();
543 sample.good.put("Windows", new Software("Microsoft", "Windows"));
544 sample.good.put("Linux", new Software("Red Hat", "Linux"));
545
546 String expected = "" +
547 "<sample>\n" +
548 " <entry>\n" +
549 " <string>Windows</string>\n" +
550 " <software>\n" +
551 " <vendor>Microsoft</vendor>\n" +
552 " <name>Windows</name>\n" +
553 " </software>\n" +
554 " </entry>\n" +
555 " <entry>\n" +
556 " <string>Linux</string>\n" +
557 " <software>\n" +
558 " <vendor>Red Hat</vendor>\n" +
559 " <name>Linux</name>\n" +
560 " </software>\n" +
561 " </entry>\n" +
562 " <bad/>\n" +
563 "</sample>";
564
565 xstream.addImplicitMap(SampleMaps.class, "good", null, null);
566 assertBothWays(sample, expected);
567 }
568
569 public void testCanUsePrimitiveAsKey() {
570 SampleMaps sample = new SampleMaps();
571 sample.good = new OrderRetainingMap();
572 sample.good.put(new Double(399.99), new Product("iPhone", "i", 399.99));
573
574 String expected = "" +
575 "<sample>\n" +
576 " <product>\n" +
577 " <name>iPhone</name>\n" +
578 " <id>i</id>\n" +
579 " <price>399.99</price>\n" +
580 " </product>\n" +
581 " <bad/>\n" +
582 "</sample>";
583
584 xstream.addImplicitMap(SampleMaps.class, "good", Product.class, "price");
585 assertBothWays(sample, expected);
586 }
587 }
0 /*
1 * Copyright (C) 2013 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 22. April 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.Map;
15
16 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
17
18 public class ImplicitTest extends AbstractAcceptanceTest {
19
20 public static class AllImplicitTypes {
21
22 public static class A {
23 public int val;
24 }
25
26 public static class B {
27 public int val;
28 }
29
30 public static class C {
31 public Integer val;
32 }
33
34 public A[] aArray = new A[2];
35 public String separator1 = "--1--";
36 public List bList = new ArrayList();
37 public String separator2 = "--2--";
38 public Map cMap = new OrderRetainingMap();
39 }
40
41 public void testAllImplicitTypesAtOnceWithImplicitElementTypes()
42 {
43 xstream.alias("implicits", AllImplicitTypes.class);
44 xstream.alias("a", AllImplicitTypes.A.class);
45 xstream.alias("b", AllImplicitTypes.B.class);
46 xstream.alias("c", AllImplicitTypes.C.class);
47 xstream.addDefaultImplementation(OrderRetainingMap.class, Map.class);
48 xstream.addImplicitArray(AllImplicitTypes.class, "aArray");
49 xstream.addImplicitCollection(AllImplicitTypes.class, "bList");
50 xstream.addImplicitMap(AllImplicitTypes.class, "cMap", AllImplicitTypes.C.class, "val");
51 String expected = ""
52 + "<implicits>\n"
53 + " <a>\n"
54 + " <val>1</val>\n"
55 + " </a>\n"
56 + " <a>\n"
57 + " <val>2</val>\n"
58 + " </a>\n"
59 + " <separator1>--1--</separator1>\n"
60 + " <b>\n"
61 + " <val>3</val>\n"
62 + " </b>\n"
63 + " <b>\n"
64 + " <val>4</val>\n"
65 + " </b>\n"
66 + " <separator2>--2--</separator2>\n"
67 + " <c>\n"
68 + " <val>5</val>\n"
69 + " </c>\n"
70 + " <c>\n"
71 + " <val>6</val>\n"
72 + " </c>\n"
73 + "</implicits>";
74
75 AllImplicitTypes implicits = new AllImplicitTypes();
76 implicits.aArray[0] = new AllImplicitTypes.A();
77 implicits.aArray[0].val = 1;
78 implicits.aArray[1] = new AllImplicitTypes.A();
79 implicits.aArray[1].val = 2;
80 implicits.bList.add(new AllImplicitTypes.B());
81 ((AllImplicitTypes.B)implicits.bList.get(0)).val = 3;
82 implicits.bList.add(new AllImplicitTypes.B());
83 ((AllImplicitTypes.B)implicits.bList.get(1)).val = 4;
84 AllImplicitTypes.C c = new AllImplicitTypes.C();
85 c.val = new Integer(5);
86 implicits.cMap.put(c.val, c);
87 c = new AllImplicitTypes.C();
88 c.val = new Integer(6);
89 implicits.cMap.put(c.val, c);
90 assertBothWays(implicits, expected);
91 }
92
93 public void testAllImplicitTypesAtOnceWithExplicitElementTypes()
94 {
95 xstream.alias("implicits", AllImplicitTypes.class);
96 xstream.alias("a", AllImplicitTypes.A.class);
97 xstream.alias("b", AllImplicitTypes.B.class);
98 xstream.alias("c", AllImplicitTypes.C.class);
99 xstream.addDefaultImplementation(OrderRetainingMap.class, Map.class);
100 xstream.addImplicitArray(AllImplicitTypes.class, "aArray");
101 xstream.addImplicitCollection(AllImplicitTypes.class, "bList", AllImplicitTypes.B.class);
102 xstream.addImplicitMap(AllImplicitTypes.class, "cMap", AllImplicitTypes.C.class, "val");
103 String expected = ""
104 + "<implicits>\n"
105 + " <a>\n"
106 + " <val>1</val>\n"
107 + " </a>\n"
108 + " <a>\n"
109 + " <val>2</val>\n"
110 + " </a>\n"
111 + " <separator1>--1--</separator1>\n"
112 + " <b>\n"
113 + " <val>3</val>\n"
114 + " </b>\n"
115 + " <b>\n"
116 + " <val>4</val>\n"
117 + " </b>\n"
118 + " <separator2>--2--</separator2>\n"
119 + " <c>\n"
120 + " <val>5</val>\n"
121 + " </c>\n"
122 + " <c>\n"
123 + " <val>6</val>\n"
124 + " </c>\n"
125 + "</implicits>";
126
127 AllImplicitTypes implicits = new AllImplicitTypes();
128 implicits.aArray[0] = new AllImplicitTypes.A();
129 implicits.aArray[0].val = 1;
130 implicits.aArray[1] = new AllImplicitTypes.A();
131 implicits.aArray[1].val = 2;
132 implicits.bList.add(new AllImplicitTypes.B());
133 ((AllImplicitTypes.B)implicits.bList.get(0)).val = 3;
134 implicits.bList.add(new AllImplicitTypes.B());
135 ((AllImplicitTypes.B)implicits.bList.get(1)).val = 4;
136 AllImplicitTypes.C c = new AllImplicitTypes.C();
137 c.val = new Integer(5);
138 implicits.cMap.put(c.val, c);
139 c = new AllImplicitTypes.C();
140 c.val = new Integer(6);
141 implicits.cMap.put(c.val, c);
142 assertBothWays(implicits, expected);
143 }
144
145 public void testAllImplicitTypesAtOnceWithExplicitElementNames()
146 {
147 xstream.alias("implicits", AllImplicitTypes.class);
148 xstream.addDefaultImplementation(OrderRetainingMap.class, Map.class);
149 xstream.addImplicitArray(AllImplicitTypes.class, "aArray", "a");
150 xstream.addImplicitCollection(AllImplicitTypes.class, "bList", "b", AllImplicitTypes.B.class);
151 xstream.addImplicitMap(AllImplicitTypes.class, "cMap", "c", AllImplicitTypes.C.class, "val");
152 String expected = ""
153 + "<implicits>\n"
154 + " <a>\n"
155 + " <val>1</val>\n"
156 + " </a>\n"
157 + " <a>\n"
158 + " <val>2</val>\n"
159 + " </a>\n"
160 + " <separator1>--1--</separator1>\n"
161 + " <b>\n"
162 + " <val>3</val>\n"
163 + " </b>\n"
164 + " <b>\n"
165 + " <val>4</val>\n"
166 + " </b>\n"
167 + " <separator2>--2--</separator2>\n"
168 + " <c>\n"
169 + " <val>5</val>\n"
170 + " </c>\n"
171 + " <c>\n"
172 + " <val>6</val>\n"
173 + " </c>\n"
174 + "</implicits>";
175
176 AllImplicitTypes implicits = new AllImplicitTypes();
177 implicits.aArray[0] = new AllImplicitTypes.A();
178 implicits.aArray[0].val = 1;
179 implicits.aArray[1] = new AllImplicitTypes.A();
180 implicits.aArray[1].val = 2;
181 implicits.bList.add(new AllImplicitTypes.B());
182 ((AllImplicitTypes.B)implicits.bList.get(0)).val = 3;
183 implicits.bList.add(new AllImplicitTypes.B());
184 ((AllImplicitTypes.B)implicits.bList.get(1)).val = 4;
185 AllImplicitTypes.C c = new AllImplicitTypes.C();
186 c.val = new Integer(5);
187 implicits.cMap.put(c.val, c);
188 c = new AllImplicitTypes.C();
189 c.val = new Integer(6);
190 implicits.cMap.put(c.val, c);
191 assertBothWays(implicits, expected);
192 }
193 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
14 import com.thoughtworks.acceptance.objects.StandardObject;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22 public class InheritanceTest extends AbstractAcceptanceTest {
23 public void testHandlesInheritanceHierarchies() {
24 OpenSourceSoftware openSourceSoftware = new OpenSourceSoftware("apache", "geronimo", "license");
25 String xml =
26 "<oss>\n" +
27 " <vendor>apache</vendor>\n" +
28 " <name>geronimo</name>\n" +
29 " <license>license</license>\n" +
30 "</oss>";
31
32 xstream.alias("oss", OpenSourceSoftware.class);
33 assertBothWays(openSourceSoftware, xml);
34 }
35
36 public static class ParentClass {
37 private String name;
38
39 public ParentClass() {
40 }
41
42 public ParentClass(String name) {
43 this.name = name;
44 }
45
46 public String getParentName() {
47 return name;
48 }
49 }
50
51 public static class ChildClass extends ParentClass {
52 private String name;
53
54 public ChildClass() {
55 }
56
57 public ChildClass(String parentName, String childName) {
58 super(parentName);
59 this.name = childName;
60 }
61
62 public String getChildName() {
63 return name;
64 }
65
66 public String toString() {
67 return getParentName() + "/" + getChildName();
68 }
69
70 public boolean equals(Object obj) {
71 return toString().equals(obj.toString());
72 }
73 }
74
75 public void testInheritanceHidingPrivateFieldOfSameName() {
76 xstream.alias("parent", ParentClass.class);
77 xstream.alias("child", ChildClass.class);
78
79 ChildClass child = new ChildClass("PARENT", "CHILD");
80 // sanity checks
81 assertEquals("PARENT", child.getParentName());
82 assertEquals("CHILD", child.getChildName());
83
84 String expected = "" +
85 "<child>\n" +
86 " <name defined-in=\"parent\">PARENT</name>\n" +
87 " <name>CHILD</name>\n" +
88 "</child>";
89
90 assertBothWays(child, expected);
91 }
92
93 public static class StaticChildClass extends ParentClass {
94 private static String name = "CHILD";
95
96 public StaticChildClass() {
97 }
98
99 public StaticChildClass(String parentName) {
100 super(parentName);
101 }
102 }
103
104 public void testHandlesStaticFieldInChildDoesNotHideFieldInParent() {
105 xstream.alias("child", StaticChildClass.class);
106
107 StaticChildClass child = new StaticChildClass("PARENT");
108 String expected = "" +
109 "<child>\n" +
110 " <name>PARENT</name>\n" +
111 "</child>";
112
113 assertBothWays(child, expected);
114 assertEquals("PARENT", child.getParentName());
115 assertEquals("CHILD", StaticChildClass.name);
116 }
117
118 public static class ParentA extends StandardObject {
119 private List stuff = new ArrayList();
120
121 public List getParentStuff() {
122 return stuff;
123 }
124 }
125
126 public static class ChildA extends ParentA {
127 private Map stuff = new HashMap();
128
129 public Map getChildStuff() {
130 return stuff;
131 }
132
133 public boolean equals(Object obj) {
134 ChildA a = (ChildA) obj;
135 if (!getChildStuff().getClass().equals(a.getChildStuff().getClass())) {
136 return false;
137 }
138 if (!getParentStuff().getClass().equals(a.getParentStuff().getClass())) {
139 return false;
140 }
141 return getChildStuff().equals(a.getChildStuff())
142 && getParentStuff().equals(a.getParentStuff());
143 }
144 }
145
146 public void testHiddenFieldsWithDifferentType() {
147 xstream.alias("child-a", ChildA.class);
148 xstream.alias("parent-a", ParentA.class);
149 ChildA childA = new ChildA();
150 childA.getChildStuff().put("hello", "world");
151 childA.getParentStuff().add("woo");
152 String expected = "" +
153 "<child-a>\n" +
154 " <stuff defined-in=\"parent-a\">\n" +
155 " <string>woo</string>\n" +
156 " </stuff>\n" +
157 " <stuff>\n" +
158 " <entry>\n" +
159 " <string>hello</string>\n" +
160 " <string>world</string>\n" +
161 " </entry>\n" +
162 " </stuff>\n" +
163 "</child-a>";
164 assertBothWays(childA, expected);
165 }
166 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 31. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 public class InnerClassesTest extends AbstractAcceptanceTest {
14
15 public void testSerializedInnerClassMaintainsReferenceToOuterClass() {
16 xstream.allowTypes(new Class[]{Outer.class, Outer.Inner.class});
17
18 Outer outer = new Outer("THE-OUTER-NAME", "THE-INNER-NAME");
19 Outer.Inner inner = outer.getInner();
20
21 assertEquals("Hello from THE-INNER-NAME (inside THE-OUTER-NAME)", inner.getMessage());
22
23 String xml = xstream.toXML(inner);
24
25 String expectedXml = ""
26 + "<com.thoughtworks.acceptance.Outer_-Inner>\n"
27 + " <innerName>THE-INNER-NAME</innerName>\n"
28 + " <outer-class>\n"
29 + " <inner reference=\"../..\"/>\n"
30 + " <outerName>THE-OUTER-NAME</outerName>\n"
31 + " </outer-class>\n"
32 + "</com.thoughtworks.acceptance.Outer_-Inner>";
33 assertEquals(expectedXml, xml);
34
35 Outer.Inner newInner = (Outer.Inner) xstream.fromXML(xml);
36
37 assertEquals("Hello from THE-INNER-NAME (inside THE-OUTER-NAME)", newInner.getMessage());
38 }
39 }
40
41 class Outer {
42
43 private Inner inner;
44 private String outerName;
45
46 public Outer(String outerName, String innerName) {
47 inner = new Inner(innerName);
48 this.outerName = outerName;
49 }
50
51 public Inner getInner() {
52 return inner;
53 }
54
55 public class Inner {
56 private String innerName;
57
58 public Inner(String innerName) {
59 this.innerName = innerName;
60 }
61
62 public String getMessage() {
63 return "Hello from " + innerName + " (inside " + outerName + ")";
64 }
65 }
66 }
67
68
0 /*
1 * Copyright (C) 2008, 2009, 2014 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 23. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.core.JVM;
13
14 import org.joda.time.DateTimeZone;
15 import org.joda.time.LocalDate;
16
17 /**
18 * Tests Joda Time types
19 *
20 * @author J&ouml;rg Schaible
21 */
22 public class JodaTimeTypesTest extends AbstractAcceptanceTest {
23
24 public void testCanHandleLocateDate() {
25 if (!JVM.is14()) {
26 // inner class, must use enhanced mode for this test
27 return;
28 }
29 xstream.allowTypesByWildcard(new String[]{"org.joda.time.**"});
30 DateTimeZone.setDefault(DateTimeZone.forID("America/Los_Angeles"));
31 final LocalDate localDate = new LocalDate(2008, 07, 03);
32 final String expected = "" +
33 "<org.joda.time.LocalDate>\n" +
34 " <iLocalMillis>1215043200000</iLocalMillis>\n" +
35 " <iChronology class=\"org.joda.time.chrono.ISOChronology\" resolves-to=\"org.joda.time.chrono.ISOChronology$Stub\" serialization=\"custom\">\n" +
36 " <org.joda.time.chrono.ISOChronology_-Stub>\n" +
37 " <org.joda.time.tz.FixedDateTimeZone resolves-to=\"org.joda.time.DateTimeZone$Stub\" serialization=\"custom\">\n" +
38 " <org.joda.time.DateTimeZone_-Stub>\n" +
39 " <string>UTC</string>\n" +
40 " </org.joda.time.DateTimeZone_-Stub>\n" +
41 " </org.joda.time.tz.FixedDateTimeZone>\n" +
42 " </org.joda.time.chrono.ISOChronology_-Stub>\n" +
43 " </iChronology>\n" +
44 "</org.joda.time.LocalDate>";
45 assertBothWays(localDate, expected);
46 }
47 }
0 /*
1 * Copyright (C) 2014, 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 31. December 2014 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.io.Serializable;
13 import java.lang.invoke.SerializedLambda;
14 import java.util.concurrent.Callable;
15
16
17 /**
18 * @author J&ouml;rg Schaible
19 */
20 public class LambdaTest extends AbstractAcceptanceTest {
21 public static class LambdaKeeper {
22 private Callable<String> callable;
23 @SuppressWarnings("unused")
24 private Object referenced;
25
26 void keep(final Callable<String> c) {
27 callable = c;
28 }
29
30 void reference() {
31 referenced = callable;
32 }
33 }
34
35 public void testLambdaExpression() {
36 final LambdaKeeper keeper = new LambdaKeeper();
37 keeper.keep((Callable<String>)() -> "result");
38
39 final String expected = "" + "<keeper>\n" + " <callable class=\"null\"/>\n" + "</keeper>";
40 xstream.alias("keeper", LambdaKeeper.class);
41 xstream.allowTypes(new Class[]{SerializedLambda.class});
42
43 assertEquals(expected, xstream.toXML(keeper));
44 assertBothWays(xstream.fromXML(expected), "<keeper/>");
45 }
46
47 public void testSerializableLambdaExpression() {
48 final LambdaKeeper keeper = new LambdaKeeper();
49 keeper.keep((Callable<String> & Serializable)() -> "result");
50
51 final String expected = ""
52 + "<keeper>\n"
53 + " <callable resolves-to=\"serialized-lambda\">\n"
54 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
55 + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
56 + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
57 + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
58 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
59 + " <implMethodName>lambda$0</implMethodName>\n"
60 + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
61 + " <implMethodKind>6</implMethodKind>\n"
62 + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
63 + " <capturedArgs/>\n"
64 + " </callable>\n"
65 + "</keeper>";
66 xstream.alias("keeper", LambdaKeeper.class);
67 xstream.allowTypes(new Class[]{SerializedLambda.class});
68
69 assertBothWaysNormalized(keeper, expected);
70
71 // ... deserialization fails if code was compiled with compiler of different vendor
72 // Object resultRoot = xstream.fromXML(expected);
73 // assertNotNull(resultRoot);
74 }
75
76 public void testReferencedLambdaExpression() {
77 final LambdaKeeper keeper = new LambdaKeeper();
78 keeper.keep((Callable<String> & Serializable)() -> "result");
79 keeper.reference();
80
81 final String expected = ""
82 + "<keeper>\n"
83 + " <callable resolves-to=\"serialized-lambda\">\n"
84 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
85 + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
86 + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
87 + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
88 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
89 + " <implMethodName>lambda$0</implMethodName>\n"
90 + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
91 + " <implMethodKind>6</implMethodKind>\n"
92 + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
93 + " <capturedArgs/>\n"
94 + " </callable>\n"
95 + " <referenced class=\"java.util.concurrent.Callable\" reference=\"../callable\"/>\n"
96 + "</keeper>";
97 xstream.alias("keeper", LambdaKeeper.class);
98 xstream.allowTypes(new Class[]{SerializedLambda.class});
99
100 assertBothWaysNormalized(keeper, expected);
101 }
102
103 public interface X {
104 static int getTwo() {
105 return 2;
106 }
107
108 default int getOne() {
109 return 1;
110 }
111 }
112
113 public interface SerializableCallable<T> extends X, Serializable, Callable<T> {}
114
115 public void testLambdaArray() {
116 Object[] lambdas = {
117 (Callable<String> & Serializable)() -> "result", (SerializableCallable<String>)() -> "result",
118 (Runnable & Serializable)() -> run(), (X & Serializable & Callable<String>)() -> "result",
119 (Runnable)() -> run(), null};
120 lambdas[lambdas.length - 1] = lambdas[0];
121
122 final String expected = ""
123 + "<object-array>\n"
124 + " <callable resolves-to=\"serialized-lambda\">\n"
125 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
126 + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
127 + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
128 + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
129 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
130 + " <implMethodName>lambda$0</implMethodName>\n"
131 + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
132 + " <implMethodKind>6</implMethodKind>\n"
133 + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
134 + " <capturedArgs/>\n"
135 + " </callable>\n"
136 + " <serializable-callable resolves-to=\"serialized-lambda\">\n"
137 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
138 + " <functionalInterfaceClass>com/thoughtworks/acceptance/LambdaTest$SerializableCallable</functionalInterfaceClass>\n"
139 + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
140 + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
141 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
142 + " <implMethodName>lambda$0</implMethodName>\n"
143 + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
144 + " <implMethodKind>6</implMethodKind>\n"
145 + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
146 + " <capturedArgs/>\n"
147 + " </serializable-callable>\n"
148 + " <runnable resolves-to=\"serialized-lambda\">\n"
149 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
150 + " <functionalInterfaceClass>java/lang/Runnable</functionalInterfaceClass>\n"
151 + " <functionalInterfaceMethodName>run</functionalInterfaceMethodName>\n"
152 + " <functionalInterfaceMethodSignature>()V</functionalInterfaceMethodSignature>\n"
153 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
154 + " <implMethodName>lambda$0</implMethodName>\n"
155 + " <implMethodSignature>()V</implMethodSignature>\n"
156 + " <implMethodKind>7</implMethodKind>\n"
157 + " <instantiatedMethodType>()V</instantiatedMethodType>\n"
158 + " <capturedArgs>\n"
159 + " <com.thoughtworks.acceptance.LambdaTest>\n"
160 + " <fName>testLambdaArray</fName>\n"
161 + " </com.thoughtworks.acceptance.LambdaTest>\n"
162 + " </capturedArgs>\n"
163 + " </runnable>\n"
164 + " <callable resolves-to=\"serialized-lambda\">\n"
165 + " <capturingClass>com.thoughtworks.acceptance.LambdaTest</capturingClass>\n"
166 + " <functionalInterfaceClass>java/util/concurrent/Callable</functionalInterfaceClass>\n"
167 + " <functionalInterfaceMethodName>call</functionalInterfaceMethodName>\n"
168 + " <functionalInterfaceMethodSignature>()Ljava/lang/Object;</functionalInterfaceMethodSignature>\n"
169 + " <implClass>com/thoughtworks/acceptance/LambdaTest</implClass>\n"
170 + " <implMethodName>lambda$0</implMethodName>\n"
171 + " <implMethodSignature>()Ljava/lang/String;</implMethodSignature>\n"
172 + " <implMethodKind>6</implMethodKind>\n"
173 + " <instantiatedMethodType>()Ljava/lang/String;</instantiatedMethodType>\n"
174 + " <capturedArgs/>\n"
175 + " </callable>\n"
176 + " <null/>\n"
177 + " <callable reference=\"../callable\"/>\n"
178 + "</object-array>";
179 xstream.alias("callable", Callable.class);
180 xstream.alias("runnable", Runnable.class);
181 xstream.alias("serializable-callable", SerializableCallable.class);
182 xstream.allowTypes(new Class[]{SerializedLambda.class, LambdaTest.class});
183
184 assertBothWaysNormalized(lambdas, expected);
185 }
186
187 private void assertBothWaysNormalized(final Object original, final String expected) {
188 String resultXml = toXML(original);
189 assertEquals(normalizeLambda(expected), normalizeLambda(resultXml));
190
191 final Object resultRoot = xstream.fromXML(resultXml);
192 resultXml = toXML(resultRoot);
193 assertEquals(normalizeLambda(expected), normalizeLambda(resultXml));
194 }
195
196 private String normalizeLambda(final String xml) {
197 // unify compiler specific name for implMethodName, Eclipse uses always "lambda$0"
198 return xml.replaceAll(">lambda\\$[^<]+<", ">lambda\\$0<");
199 }
200 }
0 /*
1 * Copyright (C) 2007, 2008, 2009 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 06. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.SingleValueConverter;
14 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
15 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
16 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
17
18
19 /**
20 * @author J&ouml;rg Schaible
21 */
22 public class LocalConverterTest extends AbstractAcceptanceTest {
23
24 public static class MultiBoolean {
25 private boolean bool;
26 private boolean speech;
27 private boolean bit;
28
29 private MultiBoolean() {
30 this(false, false, false);
31 }
32
33 public MultiBoolean(boolean bool, boolean speech, boolean bit) {
34 this.bool = bool;
35 this.speech = speech;
36 this.bit = bit;
37 }
38
39 }
40
41 protected void setUp() throws Exception {
42 super.setUp();
43 xstream.alias("mbool", MultiBoolean.class);
44 xstream.registerConverter(new ReflectionConverter(
45 xstream.getMapper(), new PureJavaReflectionProvider()), XStream.PRIORITY_VERY_LOW);
46 }
47
48 public void testCanBeAppliedToIndividualFields() {
49 MultiBoolean multiBool = new MultiBoolean(true, true, true);
50 String xml = ""
51 + "<mbool>\n"
52 + " <bool>true</bool>\n"
53 + " <speech>yes</speech>\n"
54 + " <bit>1</bit>\n"
55 + "</mbool>";
56
57 xstream.registerLocalConverter(MultiBoolean.class, "speech", BooleanConverter.YES_NO);
58 xstream.registerLocalConverter(MultiBoolean.class, "bit", BooleanConverter.BINARY);
59 assertBothWays(multiBool, xml);
60 }
61
62 public static class SymbolParameter {
63 private int type;
64 private int color;
65 private int width;
66
67 public SymbolParameter() {
68 }
69
70 public SymbolParameter(int type, int color, int width) {
71 this.type = type;
72 this.color = color;
73 this.width = width;
74 }
75
76 }
77
78 public static class HexNumberConverter implements SingleValueConverter {
79 public boolean canConvert(Class type) {
80 return type.equals(int.class) || type.equals(Integer.class);
81 }
82
83 public Object fromString(String value) {
84 return new Integer(Integer.parseInt(value, 16));
85 }
86
87 public String toString(Object obj) {
88 return Integer.toHexString(((Integer)obj).intValue());
89 }
90 }
91
92 public void testCanBeUsedForAttributeValue() {
93 SymbolParameter multiBool = new SymbolParameter(1, 0xff00ff, 100);
94 String xml = ""
95 + "<param color=\"ff00ff\">\n"
96 + " <type>1</type>\n"
97 + " <width>100</width>\n"
98 + "</param>";
99
100 xstream.alias("param", SymbolParameter.class);
101 xstream.useAttributeFor("color", int.class);
102 xstream.registerLocalConverter(SymbolParameter.class, "color", new HexNumberConverter());
103 assertBothWays(multiBool, xml);
104 }
105 }
0 /*
1 * Copyright (C) 2003, 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Hardware;
14 import com.thoughtworks.acceptance.objects.Software;
15 import com.thoughtworks.acceptance.objects.StandardObject;
16 import com.thoughtworks.xstream.core.JVM;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Hashtable;
22 import java.util.LinkedHashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 public class MapTest extends AbstractAcceptanceTest {
27
28 public void testMapCanContainBasicObjects() {
29 Map map = new HashMap();
30 map.put("benny", "hill");
31 map.put("joe", "walnes");
32
33 String expected = "" +
34 "<map>\n" +
35 " <entry>\n" +
36 " <string>benny</string>\n" +
37 " <string>hill</string>\n" +
38 " </entry>\n" +
39 " <entry>\n" +
40 " <string>joe</string>\n" +
41 " <string>walnes</string>\n" +
42 " </entry>\n" +
43 "</map>";
44
45 assertBothWaysNormalized(map, expected, "map", "entry", "string[1]");
46 }
47
48 public void testMapCanContainCustomObjects() {
49 Map map = new HashMap();
50 map.put(new Software("microsoft", "windows"), new Hardware("x86", "p4"));
51
52 xstream.alias("software", Software.class);
53 xstream.alias("hardware", Hardware.class);
54
55 String expected = "" +
56 "<map>\n" +
57 " <entry>\n" +
58 " <software>\n" +
59 " <vendor>microsoft</vendor>\n" +
60 " <name>windows</name>\n" +
61 " </software>\n" +
62 " <hardware>\n" +
63 " <arch>x86</arch>\n" +
64 " <name>p4</name>\n" +
65 " </hardware>\n" +
66 " </entry>\n" +
67 "</map>";
68
69 assertBothWays(map, expected);
70 }
71
72 static class ThingWithMap extends StandardObject {
73 Map stuff = new HashMap();
74 }
75
76 public void testObjectCanContainMapAsField() {
77 ThingWithMap t = new ThingWithMap();
78 t.stuff.put("hi", "bye");
79
80 xstream.alias("thing-with-map", ThingWithMap.class);
81
82 String expected = "" +
83 "<thing-with-map>\n" +
84 " <stuff>\n" +
85 " <entry>\n" +
86 " <string>hi</string>\n" +
87 " <string>bye</string>\n" +
88 " </entry>\n" +
89 " </stuff>\n" +
90 "</thing-with-map>";
91
92 assertBothWays(t, expected);
93 }
94
95 public void testSupportsOldHashtables() {
96
97 Hashtable hashtable = new Hashtable();
98 hashtable.put("hello", "world");
99
100 String expected = "" +
101 "<hashtable>\n" +
102 " <entry>\n" +
103 " <string>hello</string>\n" +
104 " <string>world</string>\n" +
105 " </entry>\n" +
106 "</hashtable>";
107
108 assertBothWays(hashtable, expected);
109 }
110
111 static class ThingWithDifferentTypesOfMaps extends StandardObject {
112 private Map m1 = new HashMap();
113 private Map m2 = new Hashtable();
114 private HashMap m3 = new HashMap();
115 private Hashtable m4 = new Hashtable();
116 }
117
118 public void testObjectCanContainDifferentMapImplementations() {
119
120 xstream.alias("thing", ThingWithDifferentTypesOfMaps.class);
121
122 ThingWithDifferentTypesOfMaps thing = new ThingWithDifferentTypesOfMaps();
123
124 String expected = "" +
125 "<thing>\n" +
126 " <m1/>\n" +
127 " <m2 class=\"hashtable\"/>\n" +
128 " <m3/>\n" +
129 " <m4/>\n" +
130 "</thing>";
131
132 assertBothWays(thing, expected);
133
134 }
135
136 public void testLinkedHashMapRetainsOrdering() {
137 Map map = new LinkedHashMap();
138 map.put("Z", "a");
139 map.put("C", "c");
140 map.put("X", "b");
141
142 LinkedHashMap result = (LinkedHashMap) assertBothWays(map,
143 "<linked-hash-map>\n" +
144 " <entry>\n" +
145 " <string>Z</string>\n" +
146 " <string>a</string>\n" +
147 " </entry>\n" +
148 " <entry>\n" +
149 " <string>C</string>\n" +
150 " <string>c</string>\n" +
151 " </entry>\n" +
152 " <entry>\n" +
153 " <string>X</string>\n" +
154 " <string>b</string>\n" +
155 " </entry>\n" +
156 "</linked-hash-map>");
157
158 Object[] keys = result.keySet().toArray();
159 assertEquals("Z", keys[0]);
160 assertEquals("C", keys[1]);
161 assertEquals("X", keys[2]);
162 }
163
164 public void testAllowsEntryToBeAliasedToSomethingElse() {
165 Map map = new HashMap();
166 map.put("benny", "hill");
167 map.put("joe", "walnes");
168
169 String expected = "" +
170 "<map>\n" +
171 " <thing>\n" +
172 " <string>benny</string>\n" +
173 " <string>hill</string>\n" +
174 " </thing>\n" +
175 " <thing>\n" +
176 " <string>joe</string>\n" +
177 " <string>walnes</string>\n" +
178 " </thing>\n" +
179 "</map>";
180
181 xstream.alias("thing", Map.Entry.class);
182 assertBothWaysNormalized(map, expected, "map", "thing", "string[1]");
183 }
184
185 public static class MyMap extends HashMap {
186
187 }
188
189 public void testSubclassesOfMapAreHandled() {
190 MyMap myMap = new MyMap();
191 myMap.put("hehe", "hoho");
192 String xml = xstream.toXML(myMap);
193 MyMap myOtherMap = (MyMap) xstream.fromXML(xml);
194 assertEquals(myMap, myOtherMap);
195 }
196
197 public void testSynchronizedMap() {
198 final String expected;
199 if (JVM.is15()) {
200 expected = "" +
201 "<java.util.Collections_-SynchronizedMap serialization=\"custom\">\n" +
202 " <java.util.Collections_-SynchronizedMap>\n" +
203 " <default>\n" +
204 " <m/>\n" +
205 " <mutex class=\"java.util.Collections$SynchronizedMap\" reference=\"../../..\"/>\n" +
206 " </default>\n" +
207 " </java.util.Collections_-SynchronizedMap>\n" +
208 "</java.util.Collections_-SynchronizedMap>";
209 } else {
210 expected = "" +
211 "<java.util.Collections_-SynchronizedMap>\n" +
212 " <m/>\n" +
213 " <mutex class=\"java.util.Collections$SynchronizedMap\" reference=\"..\"/>\n" +
214 "</java.util.Collections_-SynchronizedMap>";
215 }
216
217 assertBothWays(Collections.synchronizedMap(new HashMap()), expected);
218 }
219
220 public void testUnmodifiableMap() {
221 String expected = "" +
222 "<java.util.Collections_-UnmodifiableMap>\n" +
223 " <m/>\n" +
224 "</java.util.Collections_-UnmodifiableMap>";
225
226 assertBothWays(Collections.unmodifiableMap(new HashMap()), expected);
227 }
228
229 public void testEmptyMap() {
230 assertBothWays(Collections.EMPTY_MAP, "<empty-map/>");
231 }
232
233 public void testEmptyMapIsImmutable() {
234 List list = new ArrayList();
235 list.add(Collections.EMPTY_MAP);
236 list.add(Collections.EMPTY_MAP);
237 assertBothWays(list,
238 "<list>\n" +
239 " <empty-map/>\n" +
240 " <empty-map/>\n" +
241 "</list>");
242 }
243
244 public void testEmptyMapIsSingleton() {
245 assertSame(Collections.EMPTY_MAP, xstream.fromXML("<empty-map/>"));
246 }
247
248 public void testSingletonMap() {
249 String expected =""+
250 "<singleton-map>\n" +
251 " <entry>\n" +
252 " <com.thoughtworks.acceptance.objects.Software>\n" +
253 " <vendor>microsoft</vendor>\n" +
254 " <name>windows</name>\n" +
255 " </com.thoughtworks.acceptance.objects.Software>\n" +
256 " <com.thoughtworks.acceptance.objects.Hardware>\n" +
257 " <arch>x86</arch>\n" +
258 " <name>p4</name>\n" +
259 " </com.thoughtworks.acceptance.objects.Hardware>\n" +
260 " </entry>\n" +
261 "</singleton-map>";
262
263 assertBothWays(Collections.singletonMap(new Software("microsoft", "windows"), new Hardware("x86", "p4")), expected);
264 }
265 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 09. December 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Software;
14 import com.thoughtworks.acceptance.objects.StandardObject;
15 import com.thoughtworks.xstream.MarshallingStrategy;
16 import com.thoughtworks.xstream.converters.ConverterLookup;
17 import com.thoughtworks.xstream.converters.DataHolder;
18 import com.thoughtworks.xstream.core.ReferenceByIdMarshaller;
19 import com.thoughtworks.xstream.core.ReferenceByIdUnmarshaller;
20 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
21 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
22 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
23 import com.thoughtworks.xstream.io.xml.XppReader;
24 import com.thoughtworks.xstream.mapper.Mapper;
25 import com.thoughtworks.xstream.testutil.CallLog;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.ByteArrayOutputStream;
29 import java.io.EOFException;
30 import java.io.IOException;
31 import java.io.InputStreamReader;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34 import java.io.OutputStreamWriter;
35 import java.io.Reader;
36 import java.io.StringReader;
37 import java.io.StringWriter;
38 import java.io.Writer;
39 import java.util.zip.Deflater;
40 import java.util.zip.DeflaterOutputStream;
41 import java.util.zip.Inflater;
42 import java.util.zip.InflaterInputStream;
43
44
45 public class MultipleObjectsInOneStreamTest extends AbstractAcceptanceTest {
46
47 public static class Person extends StandardObject {
48
49 private String firstName;
50 private String lastName;
51 private Person secretary;
52
53 public Person(String firstName, String lastName) {
54 this.firstName = firstName;
55 this.lastName = lastName;
56 }
57
58 }
59
60 public void testReadAndWriteMultipleObjectsInOneStream() {
61 xstream.alias("person", Person.class);
62 StringWriter buffer = new StringWriter();
63
64 // serialize
65 HierarchicalStreamWriter writer = new PrettyPrintWriter(buffer);
66 writer.startNode("people");
67 xstream.marshal(new Person("Postman", "Pat"), writer);
68 xstream.marshal(new Person("Bob", "Builder"), writer);
69 xstream.marshal(new Person("Tinky", "Winky"), writer);
70 writer.endNode();
71
72 assertEquals(""
73 + "<people>\n"
74 + " <person>\n"
75 + " <firstName>Postman</firstName>\n"
76 + " <lastName>Pat</lastName>\n"
77 + " </person>\n"
78 + " <person>\n"
79 + " <firstName>Bob</firstName>\n"
80 + " <lastName>Builder</lastName>\n"
81 + " </person>\n"
82 + " <person>\n"
83 + " <firstName>Tinky</firstName>\n"
84 + " <lastName>Winky</lastName>\n"
85 + " </person>\n"
86 + "</people>", buffer.toString());
87
88 // deserialize
89 HierarchicalStreamReader reader = new XppReader(new StringReader(buffer.toString()));
90
91 assertTrue("should be another object to read (1)", reader.hasMoreChildren());
92 reader.moveDown();
93 assertEquals(new Person("Postman", "Pat"), xstream.unmarshal(reader));
94 reader.moveUp();
95
96 assertTrue("should be another object to read (2)", reader.hasMoreChildren());
97 reader.moveDown();
98 assertEquals(new Person("Bob", "Builder"), xstream.unmarshal(reader));
99 reader.moveUp();
100
101 assertTrue("should be another object to read (3)", reader.hasMoreChildren());
102 reader.moveDown();
103 assertEquals(new Person("Tinky", "Winky"), xstream.unmarshal(reader));
104 reader.moveUp();
105
106 assertFalse("should be no more objects", reader.hasMoreChildren());
107 }
108
109 public void testDrivenThroughObjectStream() throws IOException, ClassNotFoundException {
110 Writer writer = new StringWriter();
111 xstream.alias("software", Software.class);
112
113 ObjectOutputStream oos = xstream.createObjectOutputStream(writer);
114 oos.writeInt(123);
115 oos.writeObject("hello");
116 oos.writeObject(new Software("tw", "xs"));
117 oos.close();
118
119 String expectedXml = ""
120 + "<object-stream>\n"
121 + " <int>123</int>\n"
122 + " <string>hello</string>\n"
123 + " <software>\n"
124 + " <vendor>tw</vendor>\n"
125 + " <name>xs</name>\n"
126 + " </software>\n"
127 + "</object-stream>";
128
129 assertEquals(expectedXml, writer.toString());
130
131 ObjectInputStream ois = xstream.createObjectInputStream(new StringReader(writer
132 .toString()));
133 assertEquals(123, ois.readInt());
134 assertEquals("hello", ois.readObject());
135 assertEquals(new Software("tw", "xs"), ois.readObject());
136
137 try {
138 ois.readObject(); // As far as I can see this is the only clue the
139 // ObjectInputStream gives that it's done.
140 fail("Expected EOFException");
141 } catch (EOFException expectedException) {
142 // good
143 }
144 }
145
146 public void testDrivenThroughCompressedObjectStream()
147 throws IOException, ClassNotFoundException {
148 ByteArrayOutputStream baos = new ByteArrayOutputStream();
149 Writer writer = new OutputStreamWriter(new DeflaterOutputStream(baos, new Deflater(
150 Deflater.BEST_COMPRESSION)), "UTF-8");
151 xstream.alias("software", Software.class);
152
153 ObjectOutputStream oos = xstream.createObjectOutputStream(writer);
154 oos.writeInt(123);
155 oos.writeObject("hello");
156 oos.writeObject(new Software("tw", "xs"));
157 oos.flush();
158 oos.close();
159
160 byte[] data = baos.toByteArray();
161 assertTrue("Too less data: " + data.length, data.length > 2);
162
163 ObjectInputStream ois = xstream.createObjectInputStream(new InputStreamReader(
164 new InflaterInputStream(new ByteArrayInputStream(data), new Inflater()), "UTF-8"));
165 assertEquals(123, ois.readInt());
166 assertEquals("hello", ois.readObject());
167 assertEquals(new Software("tw", "xs"), ois.readObject());
168
169 try {
170 ois.readObject(); // As far as I can see this is the only clue the
171 // ObjectInputStream gives that it's done.
172 fail("Expected EOFException");
173 } catch (EOFException expectedException) {
174 // good
175 }
176 }
177
178 public void testObjectOutputStreamPropagatesCloseAndFlushEvents() throws IOException {
179 // setup
180 final CallLog log = new CallLog();
181 Writer loggingWriter = new Writer() {
182 public void close() {
183 log.actual("close");
184 }
185
186 public void flush() {
187 log.actual("flush");
188 }
189
190 public void write(char cbuf[], int off, int len) {
191 // don't care about this
192 }
193 };
194
195 // expectations
196 log.expect("flush"); // TWO flushes are currently caused. Only one is needed, but
197 // this is no big deal.
198 log.expect("flush");
199 log.expect("close");
200
201 // execute
202 ObjectOutputStream objectOutputStream = xstream.createObjectOutputStream(loggingWriter);
203 objectOutputStream.flush();
204 objectOutputStream.close();
205
206 // verify
207 log.verify();
208 }
209
210 public void testObjectInputStreamPropegatesCloseEvent() throws IOException {
211 // setup
212 final CallLog log = new CallLog();
213 Reader loggingReader = new StringReader("<int>1</int>") {
214 public void close() {
215 log.actual("close");
216 }
217 };
218
219 // expectations
220 log.expect("close");
221
222 // execute
223 ObjectInputStream objectInputStream = xstream.createObjectInputStream(loggingReader);
224 objectInputStream.close();
225
226 // verify
227 log.verify();
228 }
229
230 public void testByDefaultDoesNotPreserveReferencesAcrossDifferentObjectsInStream()
231 throws Exception {
232 xstream.alias("person", Person.class);
233
234 // Setup initial data: two object, one referencing another...
235 Person alice = new Person("Alice", "Thing");
236 Person jane = new Person("Jane", "Blah");
237 jane.secretary = alice;
238
239 // Serialize the two individual objects.
240 StringWriter writer = new StringWriter();
241 ObjectOutputStream out = xstream.createObjectOutputStream(writer);
242 out.writeObject(alice);
243 out.writeObject(jane);
244 out.close();
245
246 // Deserialize the two objects.
247 ObjectInputStream in = xstream.createObjectInputStream(new StringReader(writer
248 .toString()));
249 alice = (Person)in.readObject();
250 jane = (Person)in.readObject();
251 in.close();
252
253 assertNotSame(alice, jane.secretary); // NOT SAME
254 }
255
256 static class ReusingReferenceByIdMarshallingStrategy implements MarshallingStrategy {
257
258 private ReferenceByIdMarshaller marshaller;
259 private ReferenceByIdUnmarshaller unmarshaller;
260
261 public void marshal(HierarchicalStreamWriter writer, Object obj,
262 ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder) {
263 if (marshaller == null) {
264 marshaller = new ReferenceByIdMarshaller(writer, converterLookup, mapper);
265 }
266 marshaller.start(obj, dataHolder);
267 }
268
269 public Object unmarshal(Object root, HierarchicalStreamReader reader,
270 DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) {
271 if (unmarshaller == null) {
272 unmarshaller = new ReferenceByIdUnmarshaller(
273 root, reader, converterLookup, mapper);
274 }
275 return unmarshaller.start(dataHolder);
276 }
277 }
278
279 public void testSupportsOptionToPreserveReferencesAcrossDifferentObjectsInStream()
280 throws Exception {
281 xstream.alias("person", Person.class);
282 xstream.setMarshallingStrategy(new ReusingReferenceByIdMarshallingStrategy());
283
284 // Setup initial data: two object, one referencing another...
285 Person alice = new Person("Alice", "Thing");
286 Person jane = new Person("Jane", "Blah");
287 jane.secretary = alice;
288
289 // Serialize the two individual objects.
290 StringWriter writer = new StringWriter();
291 ObjectOutputStream out = xstream.createObjectOutputStream(writer);
292 out.writeObject(alice);
293 out.writeObject(jane);
294 out.close();
295
296 // Deserialize the two objects.
297 ObjectInputStream in = xstream.createObjectInputStream(new StringReader(writer
298 .toString()));
299 alice = (Person)in.readObject();
300 jane = (Person)in.readObject();
301 in.close();
302
303 assertSame(alice, jane.secretary);
304 }
305 }
0 /*
1 * Copyright (C) 2013 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 20. September 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.ArrayList;
13 import java.util.LinkedHashMap;
14 import java.util.List;
15 import java.util.Map;
16
17 import com.thoughtworks.acceptance.objects.Category;
18 import com.thoughtworks.acceptance.objects.SampleMaps;
19 import com.thoughtworks.xstream.converters.extended.NamedArrayConverter;
20 import com.thoughtworks.xstream.converters.extended.NamedCollectionConverter;
21 import com.thoughtworks.xstream.converters.extended.NamedMapConverter;
22
23 /**
24 * Tests named elements of collections and maps.
25 *
26 * @author J&ouml;rg Schaible
27 */
28 public class NamedLocalElementsTest extends AbstractAcceptanceTest {
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 xstream.alias("category", Category.class);
33 xstream.alias("maps", SampleMaps.class);
34 xstream.alias("arrays", Arrays.class);
35 xstream.aliasField("products", SampleMaps.class, "good");
36 xstream.addDefaultImplementation(LinkedHashMap.class, Map.class);
37 }
38
39 public void testListElementsWithFinalType() {
40 xstream.registerLocalConverter(Category.class, "products",
41 new NamedCollectionConverter(xstream.getMapper(), "product", String.class));
42
43 List products = new ArrayList();
44 products.add("SiteMesh");
45 products.add("XStream");
46 Category category = new Category("Joe Walnes", "joe");
47 category.setProducts(products);
48
49 String expected = ""
50 + "<category>\n"
51 + " <name>Joe Walnes</name>\n"
52 + " <id>joe</id>\n"
53 + " <products>\n"
54 + " <product>SiteMesh</product>\n"
55 + " <product>XStream</product>\n"
56 + " </products>\n"
57 + "</category>";
58
59 assertBothWays(category, expected);
60 }
61
62 public void testListElementsWithSuperTypes() {
63 xstream.registerLocalConverter(Category.class, "products",
64 new NamedCollectionConverter(xstream.getMapper(), "product", Object.class));
65
66 List products = new ArrayList();
67 products.add("SiteMesh");
68 products.add(new StringBuffer("XStream"));
69 Category category = new Category("Joe Walnes", "joe");
70 category.setProducts(products);
71
72 String expected = (""
73 + "<category>\n"
74 + " <name>Joe Walnes</name>\n"
75 + " <id>joe</id>\n"
76 + " <products>\n"
77 + " <product class='string'>SiteMesh</product>\n"
78 + " <product class='string-buffer'>XStream</product>\n"
79 + " </products>\n"
80 + "</category>").replace('\'', '"');
81
82 assertBothWays(category, expected);
83 }
84
85 public void testListWithNullElements() {
86 xstream.registerLocalConverter(Category.class, "products",
87 new NamedCollectionConverter(xstream.getMapper(), "product", String.class));
88
89 List products = new ArrayList();
90 products.add("SiteMesh");
91 products.add(null);
92 products.add("XStream");
93 Category category = new Category("Joe Walnes", "joe");
94 category.setProducts(products);
95
96 String expected = (""
97 + "<category>\n"
98 + " <name>Joe Walnes</name>\n"
99 + " <id>joe</id>\n"
100 + " <products>\n"
101 + " <product>SiteMesh</product>\n"
102 + " <product class='null'/>\n"
103 + " <product>XStream</product>\n"
104 + " </products>\n"
105 + "</category>").replace('\'', '"');
106
107 assertBothWays(category, expected);
108 }
109
110 public void testMapElementsWithFinalType() {
111 xstream.registerLocalConverter(SampleMaps.class, "good",
112 new NamedMapConverter(xstream.getMapper(), "product", "name", String.class, "domain", String.class));
113
114 SampleMaps maps = new SampleMaps();
115 maps.bad = null;
116 maps.good = new LinkedHashMap();
117 maps.good.put("SiteMesh", "com.opensymphony");
118 maps.good.put("XStream", "com.thoughtworks");
119
120 String expected = ""
121 + "<maps>\n"
122 + " <products>\n"
123 + " <product>\n"
124 + " <name>SiteMesh</name>\n"
125 + " <domain>com.opensymphony</domain>\n"
126 + " </product>\n"
127 + " <product>\n"
128 + " <name>XStream</name>\n"
129 + " <domain>com.thoughtworks</domain>\n"
130 + " </product>\n"
131 + " </products>\n"
132 + "</maps>";
133
134 assertBothWays(maps, expected);
135 }
136
137 public void testMapElementsWithSuperType() {
138 xstream.registerLocalConverter(SampleMaps.class, "good",
139 new NamedMapConverter(xstream.getMapper(), "product", "name", Object.class, "price", Number.class));
140
141 SampleMaps maps = new SampleMaps();
142 maps.bad = null;
143 maps.good = new LinkedHashMap();
144 maps.good.put("SiteMesh", new Integer(42));
145 maps.good.put(new StringBuffer("XStream"), new Double(42));
146
147 String expected = (""
148 + "<maps>\n"
149 + " <products>\n"
150 + " <product>\n"
151 + " <name class='string'>SiteMesh</name>\n"
152 + " <price class='int'>42</price>\n"
153 + " </product>\n"
154 + " <product>\n"
155 + " <name class='string-buffer'>XStream</name>\n"
156 + " <price class='double'>42.0</price>\n"
157 + " </product>\n"
158 + " </products>\n"
159 + "</maps>").replace('\'', '"');
160
161 assertBothWays(maps, expected);
162 }
163
164 public void testMapWithNullElements() {
165 xstream.registerLocalConverter(SampleMaps.class, "good",
166 new NamedMapConverter(xstream.getMapper(), "product", "name", String.class, "domain", String.class));
167
168 SampleMaps maps = new SampleMaps();
169 maps.bad = null;
170 maps.good = new LinkedHashMap();
171 maps.good.put(null, "com.opensymphony");
172 maps.good.put("XStream", null);
173
174 String expected = (""
175 + "<maps>\n"
176 + " <products>\n"
177 + " <product>\n"
178 + " <name class='null'/>\n"
179 + " <domain>com.opensymphony</domain>\n"
180 + " </product>\n"
181 + " <product>\n"
182 + " <name>XStream</name>\n"
183 + " <domain class='null'/>\n"
184 + " </product>\n"
185 + " </products>\n"
186 + "</maps>").replace('\'', '"');
187
188 assertBothWays(maps, expected);
189 }
190
191 public void testMapWithSwappedKeyAndValueElements() {
192 xstream.registerLocalConverter(SampleMaps.class, "good",
193 new NamedMapConverter(xstream.getMapper(), "product", "name", String.class, "domain", String.class));
194
195 SampleMaps maps = new SampleMaps();
196 maps.bad = null;
197 maps.good = new LinkedHashMap();
198 maps.good.put("SiteMesh", "com.opensymphony");
199 maps.good.put("XStream", "com.thoughtworks");
200
201 String xml = ""
202 + "<maps>\n"
203 + " <products>\n"
204 + " <product>\n"
205 + " <name>SiteMesh</name>\n"
206 + " <domain>com.opensymphony</domain>\n"
207 + " </product>\n"
208 + " <product>\n"
209 + " <domain>com.thoughtworks</domain>\n"
210 + " <name>XStream</name>\n"
211 + " </product>\n"
212 + " </products>\n"
213 + "</maps>";
214
215 assertEquals(maps, xstream.fromXML(xml));
216 }
217
218 public void testMapElementsUsingSameNames() {
219 xstream.registerLocalConverter(SampleMaps.class, "good",
220 new NamedMapConverter(xstream.getMapper(), "test", "test", String.class, "test", String.class));
221
222 SampleMaps maps = new SampleMaps();
223 maps.bad = null;
224 maps.good = new LinkedHashMap();
225 maps.good.put("SiteMesh", "com.opensymphony");
226 maps.good.put("XStream", "com.thoughtworks");
227
228 String expected = ""
229 + "<maps>\n"
230 + " <products>\n"
231 + " <test>\n"
232 + " <test>SiteMesh</test>\n"
233 + " <test>com.opensymphony</test>\n"
234 + " </test>\n"
235 + " <test>\n"
236 + " <test>XStream</test>\n"
237 + " <test>com.thoughtworks</test>\n"
238 + " </test>\n"
239 + " </products>\n"
240 + "</maps>";
241
242 assertBothWays(maps, expected);
243 }
244
245 public void testMapElementsWithoutEntry() {
246 xstream.registerLocalConverter(SampleMaps.class, "good",
247 new NamedMapConverter(xstream.getMapper(), null, "name", String.class, "domain", String.class));
248
249 SampleMaps maps = new SampleMaps();
250 maps.bad = null;
251 maps.good = new LinkedHashMap();
252 maps.good.put("SiteMesh", "com.opensymphony");
253 maps.good.put("XStream", "com.thoughtworks");
254
255 String expected = ""
256 + "<maps>\n"
257 + " <products>\n"
258 + " <name>SiteMesh</name>\n"
259 + " <domain>com.opensymphony</domain>\n"
260 + " <name>XStream</name>\n"
261 + " <domain>com.thoughtworks</domain>\n"
262 + " </products>\n"
263 + "</maps>";
264
265 assertBothWays(maps, expected);
266 }
267
268 public void testMapWithNullElementsWithoutEntry() {
269 xstream.registerLocalConverter(SampleMaps.class, "good",
270 new NamedMapConverter(xstream.getMapper(), null, "name", String.class, "domain", String.class));
271
272 SampleMaps maps = new SampleMaps();
273 maps.bad = null;
274 maps.good = new LinkedHashMap();
275 maps.good.put(null, "com.opensymphony");
276 maps.good.put("XStream", null);
277
278 String expected = (""
279 + "<maps>\n"
280 + " <products>\n"
281 + " <name class='null'/>\n"
282 + " <domain>com.opensymphony</domain>\n"
283 + " <name>XStream</name>\n"
284 + " <domain class='null'/>\n"
285 + " </products>\n"
286 + "</maps>").replace('\'', '"');
287
288 assertBothWays(maps, expected);
289 }
290
291 public void testMapWithSwappedKeyAndValueElementsWithoutEntry() {
292 xstream.registerLocalConverter(SampleMaps.class, "good",
293 new NamedMapConverter(xstream.getMapper(), null, "name", String.class, "domain", String.class));
294
295 SampleMaps maps = new SampleMaps();
296 maps.bad = null;
297 maps.good = new LinkedHashMap();
298 maps.good.put("SiteMesh", "com.opensymphony");
299 maps.good.put("XStream", "com.thoughtworks");
300
301 String xml = ""
302 + "<maps>\n"
303 + " <products>\n"
304 + " <domain>com.opensymphony</domain>\n"
305 + " <name>SiteMesh</name>\n"
306 + " <name>XStream</name>\n"
307 + " <domain>com.thoughtworks</domain>\n"
308 + " </products>\n"
309 + "</maps>";
310
311 assertEquals(maps, xstream.fromXML(xml));
312 }
313
314 public void testMapElementsUsingSameNamesWithoutEntry() {
315 xstream.registerLocalConverter(SampleMaps.class, "good",
316 new NamedMapConverter(xstream.getMapper(), null, "test", String.class, "test", String.class));
317
318 SampleMaps maps = new SampleMaps();
319 maps.bad = null;
320 maps.good = new LinkedHashMap();
321 maps.good.put("SiteMesh", "com.opensymphony");
322 maps.good.put("XStream", "com.thoughtworks");
323
324 String expected = ""
325 + "<maps>\n"
326 + " <products>\n"
327 + " <test>SiteMesh</test>\n"
328 + " <test>com.opensymphony</test>\n"
329 + " <test>XStream</test>\n"
330 + " <test>com.thoughtworks</test>\n"
331 + " </products>\n"
332 + "</maps>";
333
334 assertBothWays(maps, expected);
335 }
336
337 public void testMapElementsUsingAttributesOnly() {
338 xstream.registerLocalConverter(
339 SampleMaps.class, "good", new NamedMapConverter(
340 xstream.getMapper(), "product", "name", String.class, "domain", String.class,
341 true, true, xstream.getConverterLookup()));
342
343 SampleMaps maps = new SampleMaps();
344 maps.bad = null;
345 maps.good = new LinkedHashMap();
346 maps.good.put("SiteMesh", "com.opensymphony");
347 maps.good.put("XStream", "com.thoughtworks");
348
349 String expected = (""
350 + "<maps>\n"
351 + " <products>\n"
352 + " <product name='SiteMesh' domain='com.opensymphony'/>\n"
353 + " <product name='XStream' domain='com.thoughtworks'/>\n"
354 + " </products>\n"
355 + "</maps>").replace('\'', '"');
356
357 assertBothWays(maps, expected);
358 }
359
360 public void testMapElementsWithNullUsingAttributesOnly() {
361 xstream.registerLocalConverter(
362 SampleMaps.class, "good", new NamedMapConverter(
363 xstream.getMapper(), "product", "name", String.class, "domain", String.class,
364 true, true, xstream.getConverterLookup()));
365
366 SampleMaps maps = new SampleMaps();
367 maps.bad = null;
368 maps.good = new LinkedHashMap();
369 maps.good.put(null, "com.opensymphony");
370 maps.good.put("XStream", null);
371
372 String expected = (""
373 + "<maps>\n"
374 + " <products>\n"
375 + " <product domain='com.opensymphony'/>\n"
376 + " <product name='XStream'/>\n"
377 + " </products>\n"
378 + "</maps>").replace('\'', '"');
379
380 assertBothWays(maps, expected);
381 }
382
383 public void testMapElementsUsingAttributeAndText() {
384 xstream.registerLocalConverter(
385 SampleMaps.class, "good", new NamedMapConverter(
386 xstream.getMapper(), "product", "name", String.class, null, String.class,
387 true, false, xstream.getConverterLookup()));
388
389 SampleMaps maps = new SampleMaps();
390 maps.bad = null;
391 maps.good = new LinkedHashMap();
392 maps.good.put("SiteMesh", "com.opensymphony");
393 maps.good.put("XStream", "com.thoughtworks");
394
395 String expected = (""
396 + "<maps>\n"
397 + " <products>\n"
398 + " <product name='SiteMesh'>com.opensymphony</product>\n"
399 + " <product name='XStream'>com.thoughtworks</product>\n"
400 + " </products>\n"
401 + "</maps>").replace('\'', '"');
402
403 assertBothWays(maps, expected);
404 }
405
406 public void testMapElementsUsingAttributeForKeyOnly() {
407 xstream.registerLocalConverter(
408 SampleMaps.class, "good", new NamedMapConverter(
409 xstream.getMapper(), "product", "name", String.class, "domain", String.class,
410 true, false, xstream.getConverterLookup()));
411
412 SampleMaps maps = new SampleMaps();
413 maps.bad = null;
414 maps.good = new LinkedHashMap();
415 maps.good.put("SiteMesh", "com.opensymphony");
416 maps.good.put("XStream", "com.thoughtworks");
417
418 String expected = (""
419 + "<maps>\n"
420 + " <products>\n"
421 + " <product name='SiteMesh'>\n"
422 + " <domain>com.opensymphony</domain>\n"
423 + " </product>\n"
424 + " <product name='XStream'>\n"
425 + " <domain>com.thoughtworks</domain>\n"
426 + " </product>\n"
427 + " </products>\n"
428 + "</maps>").replace('\'', '"');
429
430 assertBothWays(maps, expected);
431 }
432
433 public void testMapElementsUsingAttributeForValueOnly() {
434 xstream.registerLocalConverter(
435 SampleMaps.class, "good", new NamedMapConverter(
436 xstream.getMapper(), "product", "name", String.class, "domain", String.class,
437 false, true, xstream.getConverterLookup()));
438
439 SampleMaps maps = new SampleMaps();
440 maps.bad = null;
441 maps.good = new LinkedHashMap();
442 maps.good.put("SiteMesh", "com.opensymphony");
443 maps.good.put("XStream", "com.thoughtworks");
444
445 String expected = (""
446 + "<maps>\n"
447 + " <products>\n"
448 + " <product domain='com.opensymphony'>\n"
449 + " <name>SiteMesh</name>\n"
450 + " </product>\n"
451 + " <product domain='com.thoughtworks'>\n"
452 + " <name>XStream</name>\n"
453 + " </product>\n"
454 + " </products>\n"
455 + "</maps>").replace('\'', '"');
456
457 assertBothWays(maps, expected);
458 }
459
460 public void testInvalidMapConfiguration() {
461 test(null, "key", "value", true, true);
462 test(null, "key", "value", false, true);
463 test(null, "key", "value", true, false);
464 test(null, "key", null, false, false);
465 test("entry", "key", null, false, false);
466 test("entry", "key", null, false, true);
467 test("entry", null, "value", false, false);
468 test("entry", null, "value", true, false);
469 test("entry", "foo", "foo", true, true);
470 }
471
472 private void test(String entry, String key, String value, boolean keyAttr, boolean valueAttr) {
473 try {
474 new NamedMapConverter(
475 xstream.getMapper(), entry, key, String.class, value, String.class, keyAttr,
476 valueAttr, xstream.getConverterLookup());
477 fail("Thrown " + IllegalArgumentException.class.getName() + " expected");
478 } catch (final IllegalArgumentException e) {
479 // OK
480 }
481 }
482
483 public static class Arrays {
484 String[] strings;
485 Object[] objects;
486 int[] ints;
487 short[][] shortArrays;
488 }
489
490 public void testArrayWithFinalType() {
491 xstream.registerLocalConverter(Arrays.class, "strings",
492 new NamedArrayConverter(String[].class, xstream.getMapper(), "name"));
493
494 Arrays arrays = new Arrays();
495 arrays.strings = new String[] {
496 "joe", "mauro"
497 };
498
499 String expected = ""
500 + "<arrays>\n"
501 + " <strings>\n"
502 + " <name>joe</name>\n"
503 + " <name>mauro</name>\n"
504 + " </strings>\n"
505 + "</arrays>";
506
507 assertBothWays(arrays, expected);
508 }
509
510 public void testArrayWithSuperTypes() {
511 xstream.registerLocalConverter(Arrays.class, "objects",
512 new NamedArrayConverter(Object[].class, xstream.getMapper(), "item"));
513
514 Arrays arrays = new Arrays();
515 arrays.objects = new Object[] {
516 "joe", Boolean.TRUE, new Integer(47)
517 };
518
519 String expected = (""
520 + "<arrays>\n"
521 + " <objects>\n"
522 + " <item class='string'>joe</item>\n"
523 + " <item class='boolean'>true</item>\n"
524 + " <item class='int'>47</item>\n"
525 + " </objects>\n"
526 + "</arrays>").replace('\'', '"');
527
528 assertBothWays(arrays, expected);
529 }
530
531 public void testArrayWithNullElement() {
532 xstream.registerLocalConverter(Arrays.class, "strings",
533 new NamedArrayConverter(String[].class, xstream.getMapper(), "name"));
534
535 Arrays arrays = new Arrays();
536 arrays.strings = new String[] {
537 "joe", null, "mauro"
538 };
539
540 String expected = ""
541 + "<arrays>\n"
542 + " <strings>\n"
543 + " <name>joe</name>\n"
544 + " <name class=\"null\"/>\n"
545 + " <name>mauro</name>\n"
546 + " </strings>\n"
547 + "</arrays>";
548
549 assertBothWays(arrays, expected);
550 }
551
552 public void testArrayWithPrimitives() {
553 xstream.registerLocalConverter(Arrays.class, "ints",
554 new NamedArrayConverter(int[].class, xstream.getMapper(), "value"));
555
556 Arrays arrays = new Arrays();
557 arrays.ints = new int[] {
558 47, 0, -3
559 };
560
561 String expected = ""
562 + "<arrays>\n"
563 + " <ints>\n"
564 + " <value>47</value>\n"
565 + " <value>0</value>\n"
566 + " <value>-3</value>\n"
567 + " </ints>\n"
568 + "</arrays>";
569
570 assertBothWays(arrays, expected);
571 }
572
573 public void testArrayWithPrimitiveArrays() {
574 xstream.registerLocalConverter(Arrays.class, "shortArrays",
575 new NamedArrayConverter(short[][].class, xstream.getMapper(), "values"));
576
577 Arrays arrays = new Arrays();
578 arrays.shortArrays = new short[][] {
579 {47, 0, -3},
580 null,
581 {13, 7}
582 };
583
584 String expected = ""
585 + "<arrays>\n"
586 + " <shortArrays>\n"
587 + " <values>\n"
588 + " <short>47</short>\n"
589 + " <short>0</short>\n"
590 + " <short>-3</short>\n"
591 + " </values>\n"
592 + " <values class=\"null\"/>\n"
593 + " <values>\n"
594 + " <short>13</short>\n"
595 + " <short>7</short>\n"
596 + " </values>\n"
597 + " </shortArrays>\n"
598 + "</arrays>";
599
600 assertBothWays(arrays, expected);
601 }
602 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2012, 2013, 2014 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 20. June 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.mapper.Mapper;
17 import com.thoughtworks.xstream.mapper.MapperWrapper;
18
19
20 public class OmitFieldsTest extends AbstractAcceptanceTest {
21
22 public static class Thing extends StandardObject {
23 transient String alwaysIgnore;
24 String sometimesIgnore;
25 String neverIgnore;
26 }
27
28 public void testTransientFieldsAreOmittedByDefault() {
29 Thing in = new Thing();
30 in.alwaysIgnore = "a";
31 in.sometimesIgnore = "b";
32 in.neverIgnore = "c";
33
34 String expectedXml = ""
35 + "<thing>\n"
36 + " <sometimesIgnore>b</sometimesIgnore>\n"
37 + " <neverIgnore>c</neverIgnore>\n"
38 + "</thing>";
39
40 xstream.alias("thing", Thing.class);
41
42 String actualXml = xstream.toXML(in);
43 assertEquals(expectedXml, actualXml);
44
45 Thing out = (Thing)xstream.fromXML(actualXml);
46 assertEquals(null, out.alwaysIgnore);
47 assertEquals("b", out.sometimesIgnore);
48 assertEquals("c", out.neverIgnore);
49 }
50
51 public void testAdditionalFieldsCanBeExplicitlyOmitted() {
52 Thing in = new Thing();
53 in.alwaysIgnore = "a";
54 in.sometimesIgnore = "b";
55 in.neverIgnore = "c";
56
57 String expectedXml = "" //
58 + "<thing>\n" //
59 + " <neverIgnore>c</neverIgnore>\n" //
60 + "</thing>";
61
62 xstream.alias("thing", Thing.class);
63 xstream.omitField(Thing.class, "sometimesIgnore");
64
65 String actualXml = xstream.toXML(in);
66 assertEquals(expectedXml, actualXml);
67
68 Thing out = (Thing)xstream.fromXML(actualXml);
69 assertEquals(null, out.alwaysIgnore);
70 assertEquals(null, out.sometimesIgnore);
71 assertEquals("c", out.neverIgnore);
72 }
73
74 public static class DerivedThing extends Thing {
75 String derived;
76 }
77
78 public void testInheritedFieldsCanBeExplicitlyOmittedThroughFacade() {
79 DerivedThing in = new DerivedThing();
80 in.alwaysIgnore = "a";
81 in.sometimesIgnore = "b";
82 in.neverIgnore = "c";
83 in.derived = "d";
84
85 String expectedXml = ""
86 + "<thing>\n"
87 + " <neverIgnore>c</neverIgnore>\n"
88 + " <derived>d</derived>\n"
89 + "</thing>";
90
91 xstream.alias("thing", DerivedThing.class);
92 xstream.omitField(Thing.class, "sometimesIgnore");
93
94 String actualXml = xstream.toXML(in);
95 assertEquals(expectedXml, actualXml);
96
97 DerivedThing out = (DerivedThing)xstream.fromXML(actualXml);
98 assertEquals(null, out.alwaysIgnore);
99 assertEquals(null, out.sometimesIgnore);
100 assertEquals("c", out.neverIgnore);
101 assertEquals("d", out.derived);
102 }
103
104 public void testFieldsOfDerivedTypesCanBeExplicitlyOmittedThroughFacade() {
105 DerivedThing in = new DerivedThing();
106 in.alwaysIgnore = "a";
107 in.sometimesIgnore = "b";
108 in.neverIgnore = "c";
109 in.derived = "d";
110
111 String expectedXml = ""
112 + "<thing>\n"
113 + " <sometimesIgnore>b</sometimesIgnore>\n"
114 + " <neverIgnore>c</neverIgnore>\n"
115 + "</thing>";
116
117 xstream.alias("thing", DerivedThing.class);
118 xstream.omitField(DerivedThing.class, "derived");
119
120 String actualXml = xstream.toXML(in);
121 assertEquals(expectedXml, actualXml);
122
123 DerivedThing out = (DerivedThing)xstream.fromXML(actualXml);
124 assertEquals(null, out.alwaysIgnore);
125 assertEquals("b", out.sometimesIgnore);
126 assertEquals("c", out.neverIgnore);
127 assertEquals(null, out.derived);
128 }
129
130 public static class AnotherThing extends StandardObject {
131 String stuff;
132 String cheese;
133 String myStuff;
134 String myCheese;
135 }
136
137 public void testFieldsCanBeIgnoredUsingCustomStrategy() {
138 AnotherThing in = new AnotherThing();
139 in.stuff = "a";
140 in.cheese = "b";
141 in.myStuff = "c";
142 in.myCheese = "d";
143
144 String expectedXml = ""
145 + "<thing>\n"
146 + " <stuff>a</stuff>\n"
147 + " <cheese>b</cheese>\n"
148 + "</thing>";
149
150 class OmitFieldsWithMyPrefixMapper extends MapperWrapper {
151 public OmitFieldsWithMyPrefixMapper(Mapper wrapped) {
152 super(wrapped);
153 }
154
155 public boolean shouldSerializeMember(Class definedIn, String fieldName) {
156 return !fieldName.startsWith("my");
157 }
158 }
159
160 xstream = new XStream() {
161 protected MapperWrapper wrapMapper(MapperWrapper next) {
162 return new OmitFieldsWithMyPrefixMapper(next);
163 }
164 };
165
166 xstream.allowTypes(new Class[]{AnotherThing.class});
167 xstream.alias("thing", AnotherThing.class);
168
169 String actualXml = xstream.toXML(in);
170 assertEquals(expectedXml, actualXml);
171
172 AnotherThing out = (AnotherThing)xstream.fromXML(actualXml);
173 assertEquals("a", out.stuff);
174 assertEquals("b", out.cheese);
175 assertEquals(null, out.myStuff);
176 assertEquals(null, out.myCheese);
177 }
178
179 public void testDeletedElementCanBeOmitted() {
180 String expectedXml = ""
181 + "<thing>\n"
182 + " <meanwhileDeletedIgnore>c</meanwhileDeletedIgnore>\n"
183 + " <sometimesIgnore>b</sometimesIgnore>\n"
184 + " <neverIgnore>c</neverIgnore>\n"
185 + "</thing>";
186
187 xstream.alias("thing", Thing.class);
188 xstream.omitField(Thing.class, "meanwhileDeletedIgnore");
189
190 Thing out = (Thing)xstream.fromXML(expectedXml);
191 assertEquals("b", out.sometimesIgnore);
192 assertEquals("c", out.neverIgnore);
193 }
194
195 public void testDeletedElementWithReferenceCanBeOmitted() {
196 String expectedXml = ""
197 + "<thing>\n"
198 + " <meanwhileDeletedIgnore reference=\"..\"/>\n"
199 + " <sometimesIgnore>b</sometimesIgnore>\n"
200 + " <neverIgnore>c</neverIgnore>\n"
201 + "</thing>";
202
203 xstream.alias("thing", Thing.class);
204 xstream.omitField(Thing.class, "meanwhileDeletedIgnore");
205
206 Thing out = (Thing)xstream.fromXML(expectedXml);
207 assertEquals("b", out.sometimesIgnore);
208 assertEquals("c", out.neverIgnore);
209 }
210
211 public void testDeletedElementWithClassAttributeCanBeOmitted() {
212 String expectedXml = ""
213 + "<thing>\n"
214 + " <meanwhileDeletedIgnore class=\"thing\"/>\n"
215 + " <sometimesIgnore>b</sometimesIgnore>\n"
216 + " <neverIgnore>c</neverIgnore>\n"
217 + "</thing>";
218
219 xstream.alias("thing", Thing.class);
220 xstream.omitField(Thing.class, "meanwhileDeletedIgnore");
221
222 Thing out = (Thing)xstream.fromXML(expectedXml);
223 assertEquals("b", out.sometimesIgnore);
224 assertEquals("c", out.neverIgnore);
225 }
226
227 public void testDeletedAttributeCanBeOmitted() {
228 String expectedXml = ""
229 + "<thing meanwhileDeletedIgnore='c'>\n"
230 + " <sometimesIgnore>b</sometimesIgnore>\n"
231 + " <neverIgnore>c</neverIgnore>\n"
232 + "</thing>";
233
234 xstream.alias("thing", Thing.class);
235 xstream.omitField(Thing.class, "meanwhileDeletedIgnore");
236
237 Thing out = (Thing)xstream.fromXML(expectedXml);
238 assertEquals("b", out.sometimesIgnore);
239 assertEquals("c", out.neverIgnore);
240 }
241
242 public void testAttributeCanBeOmitted() {
243 String expectedXml = "<thing neverIgnore=\"c\"/>";
244
245 xstream.alias("thing", Thing.class);
246 xstream.useAttributeFor(String.class);
247 xstream.omitField(Thing.class, "sometimesIgnore");
248
249 Thing in = new Thing();
250 in.alwaysIgnore = "a";
251 in.sometimesIgnore = "b";
252 in.neverIgnore = "c";
253 assertEquals(expectedXml, xstream.toXML(in));
254
255 Thing out = (Thing)xstream.fromXML(expectedXml);
256 assertNull(out.sometimesIgnore);
257 assertEquals("c", out.neverIgnore);
258 }
259
260 public void testExistingFieldsCanBeExplicitlyOmittedAtDeserialization() {
261 String actualXml = ""
262 + "<thing>\n"
263 + " <sometimesIgnore>foo</sometimesIgnore>\n"
264 + " <neverIgnore>c</neverIgnore>\n"
265 + "</thing>";
266
267 xstream.alias("thing", Thing.class);
268 xstream.omitField(Thing.class, "sometimesIgnore");
269
270 Thing out = (Thing)xstream.fromXML(actualXml);
271 assertEquals(null, out.alwaysIgnore);
272 assertEquals(null, out.sometimesIgnore);
273 assertEquals("c", out.neverIgnore);
274 }
275
276 public void testExistingFieldsInDerivedClassesCanBeExplicitlyOmittedAtDeserialization() {
277 String actualXml = ""
278 + "<thing>\n"
279 + " <sometimesIgnore>b</sometimesIgnore>\n"
280 + " <neverIgnore>c</neverIgnore>\n"
281 + " <derived>foo</derived>\n"
282 + "</thing>";
283
284 xstream.alias("thing", DerivedThing.class);
285 xstream.omitField(DerivedThing.class, "derived");
286
287 DerivedThing out = (DerivedThing)xstream.fromXML(actualXml);
288 assertEquals(null, out.alwaysIgnore);
289 assertEquals("b", out.sometimesIgnore);
290 assertEquals("c", out.neverIgnore);
291 assertEquals(null, out.derived);
292 }
293
294 public void testExistingInheritedFieldsCanBeExplicitlyOmittedAtDeserialization() {
295 String actualXml = ""
296 + "<thing>\n"
297 + " <sometimesIgnore>foo</sometimesIgnore>\n"
298 + " <neverIgnore>c</neverIgnore>\n"
299 + " <derived>d</derived>\n"
300 + "</thing>";
301
302 xstream.alias("thing", DerivedThing.class);
303 xstream.omitField(Thing.class, "sometimesIgnore");
304
305 DerivedThing out = (DerivedThing)xstream.fromXML(actualXml);
306 assertEquals(null, out.alwaysIgnore);
307 assertEquals(null, out.sometimesIgnore);
308 assertEquals("c", out.neverIgnore);
309 assertEquals("d", out.derived);
310 }
311
312 public void testIgnoreUnknownElementsMatchingPattern() {
313 String actualXml = ""
314 + "<thing>\n"
315 + " <sometimesIgnore>foo</sometimesIgnore>\n"
316 + " <neverIgnore>c</neverIgnore>\n"
317 + " <foobar>f</foobar>\n"
318 + " <derived>d</derived>\n"
319 + "</thing>";
320
321 xstream.alias("thing", DerivedThing.class);
322 xstream.omitField(Thing.class, "sometimesIgnore");
323 xstream.ignoreUnknownElements("foo.*");
324
325 DerivedThing out = (DerivedThing)xstream.fromXML(actualXml);
326 assertEquals(null, out.alwaysIgnore);
327 assertEquals(null, out.sometimesIgnore);
328 assertEquals("c", out.neverIgnore);
329 assertEquals("d", out.derived);
330
331 try {
332 xstream.fromXML(actualXml.replaceAll("foobar", "unknown"));
333 fail("Thrown " + ConversionException.class.getName() + " expected");
334 } catch (final ConversionException e) {
335 String message = e.getMessage();
336 assertTrue(message,
337 e.getMessage().substring(0, message.indexOf('\n')).endsWith(
338 DerivedThing.class.getName() + ".unknown"));
339 }
340 }
341
342 public void testIgnoreNonExistingElementsMatchingTypeAlias() {
343 xstream.alias("thing", Thing.class);
344 xstream.ignoreUnknownElements("string");
345 Thing thing = new Thing();
346 String provided = ""
347 + "<thing>\n"
348 + " <string>string 1</string>\n"
349 + "</thing>";
350 String expected = "<thing/>";
351 assertWithAsymmetricalXml(thing, provided, expected);
352 }
353
354 public void testIgnoredElementIsNotInstantiated() {
355 xstream.alias("thing", Thing.class);
356 xstream.ignoreUnknownElements("int");
357 Thing thing = new Thing();
358 String provided = ""
359 + "<thing>\n"
360 + " <int>invalid</int>\n"
361 + "</thing>";
362 String expected = "<thing/>";
363 assertWithAsymmetricalXml(thing, provided, expected);
364 }
365
366 static class ThingAgain extends Thing {
367 String sometimesIgnore;
368
369 void setHidden(String s) {
370 super.sometimesIgnore = s;
371 }
372
373 String getHidden() {
374 return super.sometimesIgnore;
375 }
376 }
377
378 public void testAnOmittedFieldMakesADefinedInAttributeSuperfluous() {
379 ThingAgain in = new ThingAgain();
380 in.alwaysIgnore = "a";
381 in.setHidden("b");
382 in.neverIgnore = "c";
383 in.sometimesIgnore = "d";
384
385 xstream.alias("thing", ThingAgain.class);
386 xstream.omitField(ThingAgain.class, "sometimesIgnore");
387
388 String expectedXml = ""
389 + "<thing>\n"
390 + " <sometimesIgnore>b</sometimesIgnore>\n"
391 + " <neverIgnore>c</neverIgnore>\n"
392 + "</thing>";
393
394 String actualXml = xstream.toXML(in);
395 assertEquals(expectedXml, actualXml);
396
397 ThingAgain out = (ThingAgain)xstream.fromXML(expectedXml);
398 assertNull(out.alwaysIgnore);
399 assertEquals("b", out.getHidden());
400 assertEquals("c", out.neverIgnore);
401 assertNull(out.sometimesIgnore);
402 }
403 }
0 /*
1 * Copyright (C) 2008 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 24. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.acceptance.objects.SampleLists;
13 import com.thoughtworks.acceptance.objects.Software;
14 import com.thoughtworks.xstream.converters.Converter;
15 import com.thoughtworks.xstream.converters.MarshallingContext;
16 import com.thoughtworks.xstream.converters.UnmarshallingContext;
17 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19 import com.thoughtworks.xstream.persistence.FilePersistenceStrategy;
20 import com.thoughtworks.xstream.persistence.XmlArrayList;
21
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collection;
27
28 /**
29 * Tests the persistence package.
30 *
31 * @author J&ouml;rg Schaible
32 */
33 public class PersistenceTest extends AbstractAcceptanceTest {
34
35 private File dir;
36
37 protected void setUp() throws Exception {
38 super.setUp();
39 dir = new File("target/test-storage");
40 dir.mkdirs();
41 cleanUp();
42 }
43
44 protected void tearDown() throws Exception {
45 cleanUp();
46 dir.delete();
47 super.tearDown();
48 }
49
50 private void cleanUp() {
51 File[] files = dir.listFiles();
52 for(int i = 0; i < files.length; ++i) {
53 if (files[i].isFile()) {
54 files[i].delete();
55 }
56 }
57 }
58
59 private final class PersistenceArrayListConverter implements Converter {
60 public void marshal(Object source, HierarchicalStreamWriter writer,
61 MarshallingContext context) {
62 final XmlArrayList list = new XmlArrayList(new FilePersistenceStrategy(dir, xstream));
63 context.convertAnother(dir);
64 list.addAll((Collection)source);
65 }
66
67 public Object unmarshal(HierarchicalStreamReader reader,
68 UnmarshallingContext context) {
69 final File directory = (File)context.convertAnother(null, File.class);
70 final XmlArrayList persistentList = new XmlArrayList(new FilePersistenceStrategy(directory, xstream));
71 final ArrayList list = new ArrayList(persistentList);
72 //persistentList.clear(); // remove files
73 return list;
74 }
75
76 public boolean canConvert(Class type) {
77 return type == ArrayList.class;
78 }
79 }
80
81 public void testCanUsePersistenceCollectionAsConverter() throws IOException {
82 xstream.alias("lists", SampleLists.class);
83 xstream.alias("software", Software.class);
84 xstream.registerLocalConverter(SampleLists.class, "good", new PersistenceArrayListConverter());
85
86 SampleLists lists = new SampleLists();
87 lists.good.add("Guilherme");
88 lists.good.add(new Integer(1970));
89 lists.good.add(new Software("Codehaus", "XStream"));
90
91 String expected = "" +
92 "<lists>\n" +
93 " <good>" + dir.getPath() + "</good>\n" +
94 " <bad class=\"list\"/>\n" +
95 "</lists>";
96
97 // assumes 'lists' is serialized first
98 SampleLists serialized = (SampleLists)assertBothWays(lists, expected);
99
100 // compare original list and list written in separate XML file
101 assertEquals(lists.good, serialized.good);
102
103 // retrieve value from external file
104 FileInputStream inputStream = new FileInputStream(new File(dir, "int@2.xml"));
105 try {
106 assertEquals(lists.good.get(2), xstream.fromXML(inputStream));
107 } finally {
108 inputStream.close();
109 }
110 }
111 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2014 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 01. October 2004 by James Strachan
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.util.ArrayList;
14
15 import javax.xml.namespace.QName;
16
17 import com.thoughtworks.acceptance.someobjects.Handler;
18 import com.thoughtworks.acceptance.someobjects.Protocol;
19 import com.thoughtworks.acceptance.someobjects.WithList;
20 import com.thoughtworks.acceptance.someobjects.X;
21 import com.thoughtworks.acceptance.someobjects.Y;
22 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
23 import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
24 import com.thoughtworks.xstream.io.xml.QNameMap;
25 import com.thoughtworks.xstream.io.xml.StaxDriver;
26
27 public class QNameMappedConcreteClassesTest extends AbstractAcceptanceTest {
28
29 public static final String XML_HEADER = "<?xml version='1.0' encoding='utf-8'?>";
30
31 protected QNameMap qnameMap;
32 protected String namespace = getDefaultNS(WithList.class);
33
34 public void testUsingNamespace() {
35 // lets register some qnames
36 QName qname = new QName(namespace, "withList", "w");
37 qnameMap.registerMapping(qname, WithList.class);
38
39 WithList withList = new WithList();
40 withList.things = new ArrayList();
41
42 String expected ="" +
43 XML_HEADER +
44 "<w:withList xmlns:w=\"java://com.thoughtworks.acceptance.someobjects\">" +
45 "<things></things>" +
46 "</w:withList>";
47
48 assertBothWays(withList, expected);
49 }
50
51 public void testUsingDefaultNamespace() {
52 qnameMap.setDefaultNamespace(namespace);
53 xstream.alias("withList", WithList.class);
54
55 WithList withList = new WithList();
56 withList.things = new ArrayList();
57
58 String expected =
59 XML_HEADER +
60 "<withList xmlns=\"java://com.thoughtworks.acceptance.someobjects\">" +
61 "<things></things>" +
62 "</withList>";
63
64 assertBothWays(withList, expected);
65 }
66
67 public void testUsingDefaultNamespaceAndPrefix() {
68 qnameMap.setDefaultNamespace(namespace);
69 qnameMap.setDefaultPrefix("x");
70 QName qname = new QName(namespace, "withList", "x");
71 qnameMap.registerMapping(qname, WithList.class);
72
73 WithList withList = new WithList();
74 withList.things = new ArrayList();
75
76 String expected =
77 XML_HEADER +
78 "<x:withList xmlns:x=\"java://com.thoughtworks.acceptance.someobjects\">" +
79 "<x:things></x:things>" +
80 "</x:withList>";
81
82 assertBothWays(withList, expected);
83 }
84
85 public void testUsingDifferentNamespaces() {
86 // lets register some qnames
87 qnameMap.registerMapping(new QName(namespace, "withList", "w"), WithList.class);
88 qnameMap.registerMapping(new QName("urn:foo", "things", "f"), "things");
89
90 WithList withList = new WithList();
91 withList.things = new ArrayList();
92
93 String expected =
94 XML_HEADER +
95 "<w:withList xmlns:w=\"java://com.thoughtworks.acceptance.someobjects\">" +
96 "<f:things xmlns:f=\"urn:foo\"></f:things>" +
97 "</w:withList>";
98
99 assertBothWays(withList, expected);
100 }
101
102 public void testUsingDifferentNamespacesWithAliases() {
103 xstream.alias("handler", X.class);
104 xstream.alias("protocol", Y.class);
105
106 qnameMap.registerMapping(new QName(getDefaultNS(Handler.class)+1, "handler", "h"), "handler");
107 qnameMap.registerMapping(new QName(getDefaultNS(Protocol.class)+2, "protocol", "p"), "innerObj");
108
109 X x = new X();
110 x.aStr = "foo";
111 x.anInt = 42;
112 x.innerObj = new Y();
113 x.innerObj.yField = "YField";
114
115 String expected =
116 XML_HEADER +
117 "<h:handler xmlns:h=\"java://com.thoughtworks.acceptance.someobjects1\">" +
118 "<aStr>foo</aStr>" +
119 "<anInt>42</anInt>" +
120 "<p:protocol xmlns:p=\"java://com.thoughtworks.acceptance.someobjects2\">" +
121 "<yField>YField</yField>" +
122 "</p:protocol>" +
123 "</h:handler>";
124
125 assertBothWays(x, expected);
126 }
127
128 protected HierarchicalStreamDriver createDriver() {
129 // careful, called from inside base class constructor
130 qnameMap = new QNameMap();
131 StaxDriver driver = new BEAStaxDriver(qnameMap);
132 driver.setRepairingNamespace(false);
133 return driver;
134 }
135
136 protected String getDefaultNS(Class type) {
137 return "java://" + type.getPackage().getName();
138 }
139 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 30. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StatusEnum;
14
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.IOException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectOutputStream;
20
21 /**
22 * @author Chris Kelly
23 * @author Joe Walnes
24 */
25 public class ReadResolveTest extends AbstractAcceptanceTest {
26
27 public void testReadResolveWithDefaultSerialization() throws IOException, ClassNotFoundException {
28 StatusEnum status = StatusEnum.STARTED;
29
30 ByteArrayOutputStream bout = new ByteArrayOutputStream();
31 ObjectOutputStream os = new ObjectOutputStream(bout);
32 os.writeObject(status);
33
34 byte[] bArray = bout.toByteArray();
35 StatusEnum rStatus = null;
36 ObjectInputStream in = null;
37
38 ByteArrayInputStream bin = new ByteArrayInputStream(bArray);
39 in = new ObjectInputStream(bin);
40 rStatus = (StatusEnum) in.readObject();
41 assertNotNull(rStatus);
42
43 assertSame(status, rStatus);
44 }
45
46 public void testReadResolveWithXStream() {
47 StatusEnum status = StatusEnum.STARTED;
48
49 String xml = xstream.toXML(status);
50 StatusEnum rStatus = (StatusEnum) xstream.fromXML(xml);
51
52 assertSame(status, rStatus);
53 }
54 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 08. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import java.lang.reflect.Constructor;
14 import java.lang.reflect.Field;
15 import java.lang.reflect.Method;
16
17 public class ReflectionClassesTest extends AbstractAcceptanceTest {
18 public static class StupidObject {
19 public String aField;
20 public static int aStaticField;
21 public StupidObject(String arg) {
22 }
23
24 public void aMethod(String something) {
25 }
26
27 public void aMethod(int cheese) {
28 }
29
30 public static void aStaticMethod(boolean bool) {
31 }
32 }
33
34 public void testReflectionMethod() throws NoSuchMethodException {
35 Method method = StupidObject.class.getMethod("aMethod", new Class[]{String.class});
36
37 String expected =
38 "<method>\n" +
39 " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n" +
40 " <name>aMethod</name>\n" +
41 " <parameter-types>\n" +
42 " <class>java.lang.String</class>\n" +
43 " </parameter-types>\n" +
44 "</method>";
45
46 assertBothWays(method, expected);
47 }
48
49 public void testReflectionStaticMethod() throws NoSuchMethodException {
50 Method method = StupidObject.class.getMethod("aStaticMethod", new Class[]{boolean.class});
51
52 String expected =
53 "<method>\n" +
54 " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n" +
55 " <name>aStaticMethod</name>\n" +
56 " <parameter-types>\n" +
57 " <class>boolean</class>\n" +
58 " </parameter-types>\n" +
59 "</method>";
60
61 assertBothWays(method, expected);
62 }
63
64 public void testReflectionConstructor() throws NoSuchMethodException {
65 Constructor constructor = StupidObject.class.getConstructor(new Class[]{String.class});
66
67 String expected =
68 "<constructor>\n" +
69 " <class>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</class>\n" +
70 " <parameter-types>\n" +
71 " <class>java.lang.String</class>\n" +
72 " </parameter-types>\n" +
73 "</constructor>";
74
75 assertBothWays(constructor, expected);
76 }
77
78 public void testSupportsPrimitiveTypes() {
79 assertBothWays(int.class, "<java-class>int</java-class>");
80 }
81
82 public void testReflectionField() throws NoSuchFieldException {
83 Field field = StupidObject.class.getField("aField");
84
85 String expected =
86 "<field>\n" +
87 " <name>aField</name>\n" +
88 " <clazz>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</clazz>\n" +
89 "</field>";
90
91 assertBothWays(field, expected);
92 }
93
94 public void testReflectionStaticField() throws NoSuchFieldException {
95 Field field = StupidObject.class.getField("aStaticField");
96
97 String expected =
98 "<field>\n" +
99 " <name>aStaticField</name>\n" +
100 " <clazz>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</clazz>\n" +
101 "</field>";
102
103 assertBothWays(field, expected);
104 }
105
106 public void testReflectionFieldMigrationFrom13() throws NoSuchFieldException {
107 Field field = StupidObject.class.getField("aField");
108
109 String xml =
110 "<field>\n" +
111 " <override>false</override>\n" +
112 " <clazz>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</clazz>\n" +
113 " <slot>0</slot>\n" +
114 " <name>aField</name>\n" +
115 " <type>java.lang.String</type>\n" +
116 " <modifiers>1</modifiers>\n" +
117 " <root>\n" +
118 " <override>false</override>\n" +
119 " <clazz>com.thoughtworks.acceptance.ReflectionClassesTest$StupidObject</clazz>\n" +
120 " <slot>0</slot>\n" +
121 " <name>aField</name>\n" +
122 " <type>java.lang.String</type>\n" +
123 " <modifiers>1</modifiers>\n" +
124 " </root>\n" +
125 "</field>";
126
127 assertEquals(field, xstream.fromXML(xml));
128 }
129 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 30. July 2011 by Joerg Schaible by merging
10 * RelativeSingleNodeXPathCircularReferenceTest and
11 * RelativeSingleNodeXPathDuplicateReferenceTest.
12 */
13 package com.thoughtworks.acceptance;
14
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22 public class RelativeSingleNodeXPathReferenceTest extends AbstractReferenceTest {
23
24 // tests inherited from superclass
25
26 protected void setUp() throws Exception {
27 super.setUp();
28 xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);
29 }
30
31 public void testXmlContainsReferencePaths() {
32
33 Thing sameThing = new Thing("hello");
34 Thing anotherThing = new Thing("hello");
35
36 List list = new ArrayList();
37 list.add(sameThing);
38 list.add(sameThing);
39 list.add(anotherThing);
40
41 String expected = ""
42 + "<list>\n"
43 + " <thing>\n"
44 + " <field>hello</field>\n"
45 + " </thing>\n"
46 + " <thing reference=\"../thing[1]\"/>\n"
47 + " <thing>\n"
48 + " <field>hello</field>\n"
49 + " </thing>\n"
50 + "</list>";
51
52 assertEquals(expected, xstream.toXML(list));
53 }
54
55 public void testTree() {
56 TreeElement root = new TreeElement("X");
57 TreeElement left = new TreeElement("Y");
58 TreeElement right = new TreeElement("Z");
59 root.left = left;
60 root.right = right;
61 left.left = new TreeElement(root.name);
62 right.right = new TreeElement(left.name);
63 right.left = left.left;
64
65 xstream.alias("elem", TreeElement.class);
66 String expected = ""
67 + "<elem>\n"
68 + " <name>X</name>\n"
69 + " <left>\n"
70 + " <name>Y</name>\n"
71 + " <left>\n"
72 + " <name reference=\"../../../name[1]\"/>\n"
73 + " </left>\n"
74 + " </left>\n"
75 + " <right>\n"
76 + " <name>Z</name>\n"
77 + " <left reference=\"../../left[1]/left[1]\"/>\n"
78 + " <right>\n"
79 + " <name reference=\"../../../left[1]/name[1]\"/>\n"
80 + " </right>\n"
81 + " </right>\n"
82 + "</elem>";
83
84 assertEquals(expected, xstream.toXML(root));
85 }
86
87 public void testReplacedReference() {
88 String expectedXml = ""
89 + "<element>\n"
90 + " <data>parent</data>\n"
91 + " <children>\n"
92 + " <anonymous-element resolves-to=\"element\">\n"
93 + " <data>child</data>\n"
94 + " <parent reference=\"../../..\"/>\n"
95 + " <children/>\n"
96 + " </anonymous-element>\n"
97 + " </children>\n"
98 + "</element>";
99
100 replacedReference(expectedXml);
101 }
102
103 public void testCanReferenceDeserializedNullValues() {
104 xstream.alias("test", Mapper.Null.class);
105 String xml = ""
106 + "<list>\n"
107 + " <test/>\n"
108 + " <test reference=\"../test[1]\"/>\n"
109 + "</list>";
110 List list = (List)xstream.fromXML(xml);
111 assertEquals(2, list.size());
112 assertNull(list.get(0));
113 assertNull(list.get(1));
114 }
115 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 30. July 2011 by Joerg Schaible by merging RelativeXPathCircularReferenceTest,
10 * RelativeXPathDuplicateReferenceTest, RelativeXPathNestedCircularReferenceTest and
11 * RelativeXPathReplacedReferenceTest.
12 */
13 package com.thoughtworks.acceptance;
14
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.mapper.Mapper;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23
24 public class RelativeXPathReferenceTest extends AbstractReferenceTest {
25
26 // tests inherited from superclass
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
31 }
32
33 public void testXmlContainsReferencePaths() {
34
35 Thing sameThing = new Thing("hello");
36 Thing anotherThing = new Thing("hello");
37
38 List list = new ArrayList();
39 list.add(sameThing);
40 list.add(sameThing);
41 list.add(anotherThing);
42
43 String expected = ""
44 + "<list>\n"
45 + " <thing>\n"
46 + " <field>hello</field>\n"
47 + " </thing>\n"
48 + " <thing reference=\"../thing\"/>\n"
49 + " <thing>\n"
50 + " <field>hello</field>\n"
51 + " </thing>\n"
52 + "</list>";
53
54 assertEquals(expected, xstream.toXML(list));
55 }
56
57 public void testCircularReferenceXml() {
58 Person bob = new Person("bob");
59 Person jane = new Person("jane");
60 bob.likes = jane;
61 jane.likes = bob;
62
63 String expected = ""
64 + "<person>\n"
65 + " <firstname>bob</firstname>\n"
66 + " <likes>\n"
67 + " <firstname>jane</firstname>\n"
68 + " <likes reference=\"../..\"/>\n"
69 + " </likes>\n"
70 + "</person>";
71
72 assertEquals(expected, xstream.toXML(bob));
73 }
74
75 public void testCircularReferenceToSelfXml() {
76 Person bob = new Person("bob");
77 bob.likes = bob;
78
79 String expected = ""
80 + "<person>\n"
81 + " <firstname>bob</firstname>\n"
82 + " <likes reference=\"..\"/>\n"
83 + "</person>";
84
85 assertEquals(expected, xstream.toXML(bob));
86 }
87
88 public void testRing() {
89 LinkedElement tom = new LinkedElement("Tom");
90 LinkedElement dick = new LinkedElement("Dick");
91 LinkedElement harry = new LinkedElement("Harry");
92 tom.next = dick;
93 dick.next = harry;
94 harry.next = tom;
95
96 xstream.alias("elem", LinkedElement.class);
97 String expected = ""
98 + "<elem>\n"
99 + " <name>Tom</name>\n"
100 + " <next>\n"
101 + " <name>Dick</name>\n"
102 + " <next>\n"
103 + " <name>Harry</name>\n"
104 + " <next reference=\"../../..\"/>\n"
105 + " </next>\n"
106 + " </next>\n"
107 + "</elem>";
108
109 assertEquals(expected, xstream.toXML(tom));
110 }
111
112 public void testTree() {
113 TreeElement root = new TreeElement("X");
114 TreeElement left = new TreeElement("Y");
115 TreeElement right = new TreeElement("Z");
116 root.left = left;
117 root.right = right;
118 left.left = new TreeElement(root.name);
119 right.right = new TreeElement(left.name);
120 right.left = left.left;
121
122 xstream.alias("elem", TreeElement.class);
123 String expected = ""
124 + "<elem>\n"
125 + " <name>X</name>\n"
126 + " <left>\n"
127 + " <name>Y</name>\n"
128 + " <left>\n"
129 + " <name reference=\"../../../name\"/>\n"
130 + " </left>\n"
131 + " </left>\n"
132 + " <right>\n"
133 + " <name>Z</name>\n"
134 + " <left reference=\"../../left/left\"/>\n"
135 + " <right>\n"
136 + " <name reference=\"../../../left/name\"/>\n"
137 + " </right>\n"
138 + " </right>\n"
139 + "</elem>";
140
141 assertEquals(expected, xstream.toXML(root));
142 }
143
144 public void testReplacedReference() {
145 String expectedXml = ""
146 + "<element>\n"
147 + " <data>parent</data>\n"
148 + " <children>\n"
149 + " <anonymous-element resolves-to=\"element\">\n"
150 + " <data>child</data>\n"
151 + " <parent reference=\"../../..\"/>\n"
152 + " <children/>\n"
153 + " </anonymous-element>\n"
154 + " </children>\n"
155 + "</element>";
156
157 replacedReference(expectedXml);
158 }
159
160 public void testCanReferenceDeserializedNullValues() {
161 xstream.alias("test", Mapper.Null.class);
162 String xml = ""
163 + "<list>\n"
164 + " <test/>\n"
165 + " <test reference=\"../test\"/>\n"
166 + "</list>";
167 List list = (List)xstream.fromXML(xml);
168 assertEquals(2, list.size());
169 assertNull(list.get(0));
170 assertNull(list.get(1));
171 }
172
173 static class RecursiveThing {
174 final Map map = new HashMap();
175 final String name; // wrong definition order for HashMap!
176 public RecursiveThing(String name) {
177 this.name = name;
178 }
179 public int hashCode() {
180 return name.hashCode();
181 }
182 public boolean equals(Object obj) {
183 return obj.getClass().equals(RecursiveThing.class) && name.equals(((RecursiveThing)obj).name);
184 }
185 }
186
187 public void todoTestRecursiveMap() {
188 RecursiveThing thing = new RecursiveThing("joe");
189 thing.map.put(thing, "walnes");
190
191 xstream.alias("rec-thing", RecursiveThing.class);
192
193 String expected = ""
194 + "<rec-thing>\n"
195 + " <map>\n"
196 + " <entry>\n"
197 + " <rec-thing reference=\"../../..\"/>\n"
198 + " <string>walnes</string>\n"
199 + " </entry>\n"
200 + " </map>\n"
201 + " <name>joe</name>\n"
202 + "</rec-thing>";
203 assertBothWays(thing, expected);
204 }
205 }
0 /*
1 * Copyright (C) 2006, 2007, 2009, 2010, 2013 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 24. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.acceptance.objects.Software;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
15 import com.thoughtworks.xstream.io.xml.DomDriver;
16 import com.thoughtworks.xstream.testutil.DynamicSecurityManager;
17
18 import junit.framework.TestCase;
19
20 import org.apache.commons.lang.StringUtils;
21
22 import java.io.File;
23 import java.io.FilePermission;
24 import java.lang.reflect.ReflectPermission;
25 import java.net.NetPermission;
26 import java.security.CodeSource;
27 import java.security.Permission;
28 import java.security.Policy;
29 import java.security.cert.Certificate;
30 import java.util.Iterator;
31 import java.util.PropertyPermission;
32
33
34 /**
35 * Test XStream with an active SecurityManager. Note, that it is intentional, that this test is
36 * not derived from AbstractAcceptanceTest to avoid loaded classes before the SecurityManager is
37 * in action. Also run each fixture in its own to avoid side-effects.
38 *
39 * @author J&ouml;rg Schaible
40 */
41 public class SecurityManagerTest extends TestCase {
42
43 private XStream xstream;
44 private DynamicSecurityManager sm;
45 private CodeSource source;
46
47 protected void setUp() throws Exception {
48 super.setUp();
49 System.setSecurityManager(null);
50 source = new CodeSource(new File("target").toURI().toURL(), (Certificate[])null);
51
52 sm = new DynamicSecurityManager();
53 Policy policy = Policy.getPolicy();
54 sm.setPermissions(source, policy.getPermissions(source));
55 sm.addPermission(source, new RuntimePermission("setSecurityManager"));
56
57 File mainClasses = new File(System.getProperty("user.dir"), "target/classes/-");
58 File testClasses = new File(System.getProperty("user.dir"), "target/test-classes/-");
59 String[] javaClassPath = StringUtils.split(System.getProperty("java.class.path"), File.pathSeparatorChar);
60 File javaHome = new File(System.getProperty("java.home"), "-");
61
62 // necessary permission start here
63 sm.addPermission(source, new FilePermission(mainClasses.toString(), "read"));
64 sm.addPermission(source, new FilePermission(testClasses.toString(), "read"));
65 sm.addPermission(source, new FilePermission(javaHome.toString(), "read"));
66 for (int i = 0; i < javaClassPath.length; ++i) {
67 if (javaClassPath[i].endsWith(".jar")) {
68 sm.addPermission(source, new FilePermission(javaClassPath[i], "read"));
69 }
70 }
71 }
72
73 protected void tearDown() throws Exception {
74 System.setSecurityManager(null);
75 super.tearDown();
76 }
77
78 protected void runTest() throws Throwable {
79 try {
80 super.runTest();
81 } catch(Throwable e) {
82 for (final Iterator iter = sm.getFailedPermissions().iterator(); iter.hasNext();) {
83 final Permission permission = (Permission)iter.next();
84 System.out.println("SecurityException: Permission " + permission.toString());
85 }
86 throw e;
87 }
88 }
89
90 public void testSerializeWithXppDriverAndSun14ReflectionProviderAndActiveSecurityManager() {
91 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.reflect"));
92 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
93 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
94 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
95 sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
96 sm.addPermission(source, new RuntimePermission("createClassLoader"));
97 sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
98 sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
99 sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
100 sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess"));
101 sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
102 sm.addPermission(source, new PropertyPermission("java.home", "read"));
103 sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
104 sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
105 sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
106 sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
107 sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
108 sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
109 sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
110 sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
111 sm.addPermission(source, new PropertyPermission("user.country", "read"));
112 sm.addPermission(source, new PropertyPermission("user.dir", "read"));
113 sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
114 sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
115 sm.addPermission(source, new NetPermission("specifyStreamHandler"));
116 sm.setReadOnly();
117 System.setSecurityManager(sm);
118
119 xstream = new XStream();
120
121 assertBothWays();
122 }
123
124 public void testSerializeWithXppDriverAndPureJavaReflectionProviderAndActiveSecurityManager() {
125 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.misc"));
126 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
127 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
128 sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
129 sm.addPermission(source, new RuntimePermission("createClassLoader"));
130 sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
131 sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
132 sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
133 sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
134 sm.addPermission(source, new PropertyPermission("java.home", "read"));
135 sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
136 sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
137 sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
138 sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
139 sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
140 sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
141 sm.addPermission(source, new PropertyPermission("sun.io.serialization.extendedDebugInfo", "read"));
142 sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
143 sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
144 sm.addPermission(source, new PropertyPermission("user.country", "read"));
145 sm.addPermission(source, new PropertyPermission("user.dir", "read"));
146 sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
147 sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
148 sm.addPermission(source, new NetPermission("specifyStreamHandler"));
149 sm.setReadOnly();
150 System.setSecurityManager(sm);
151
152 xstream = new XStream(new PureJavaReflectionProvider());
153
154 assertBothWays();
155 }
156
157 public void testSerializeWithDomDriverAndPureJavaReflectionProviderAndActiveSecurityManager() {
158 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.text.resources"));
159 sm.addPermission(source, new RuntimePermission("accessClassInPackage.sun.util.resources"));
160 sm.addPermission(source, new RuntimePermission("accessDeclaredMembers"));
161 sm.addPermission(source, new RuntimePermission("createClassLoader"));
162 sm.addPermission(source, new RuntimePermission("fileSystemProvider"));
163 sm.addPermission(source, new RuntimePermission("loadLibrary.nio"));
164 sm.addPermission(source, new RuntimePermission("modifyThreadGroup"));
165 sm.addPermission(source, new RuntimePermission("reflectionFactoryAccess"));
166 sm.addPermission(source, new PropertyPermission("com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration", "read"));
167 sm.addPermission(source, new PropertyPermission("elementAttributeLimit", "read"));
168 sm.addPermission(source, new PropertyPermission("entityExpansionLimit", "read"));
169 sm.addPermission(source, new PropertyPermission("http://java.sun.com/xml/dom/properties/ancestor-check", "read"));
170 sm.addPermission(source, new PropertyPermission("ibm.dst.compatibility", "read"));
171 sm.addPermission(source, new PropertyPermission("java.home", "read"));
172 sm.addPermission(source, new PropertyPermission("java.nio.file.spi.DefaultFileSystemProvider", "read"));
173 sm.addPermission(source, new PropertyPermission("java.security.debug", "read"));
174 sm.addPermission(source, new PropertyPermission("javax.xml.datatype.DatatypeFactory", "read"));
175 sm.addPermission(source, new PropertyPermission("javax.xml.parsers.DocumentBuilderFactory", "read"));
176 sm.addPermission(source, new PropertyPermission("javax.xml.accessExternalDTD", "read"));
177 sm.addPermission(source, new PropertyPermission("javax.xml.accessExternalSchema", "read"));
178 sm.addPermission(source, new PropertyPermission("jaxp.debug", "read"));
179 sm.addPermission(source, new PropertyPermission("jdk.util.TimeZone.allowSetDefault", "read"));
180 sm.addPermission(source, new PropertyPermission("jdk.xml.elementAttributeLimit", "read"));
181 sm.addPermission(source, new PropertyPermission("jdk.xml.entityExpansionLimit", "read"));
182 sm.addPermission(source, new PropertyPermission("jdk.xml.maxElementDepth", "read"));
183 sm.addPermission(source, new PropertyPermission("jdk.xml.maxGeneralEntitySizeLimit", "read"));
184 sm.addPermission(source, new PropertyPermission("jdk.xml.maxParameterEntitySizeLimit", "read"));
185 sm.addPermission(source, new PropertyPermission("jdk.xml.maxOccurLimit", "read"));
186 sm.addPermission(source, new PropertyPermission("jdk.xml.totalEntitySizeLimit", "read"));
187 sm.addPermission(source, new PropertyPermission("maxOccurLimit", "read"));
188 sm.addPermission(source, new PropertyPermission("sun.boot.class.path", "read"));
189 sm.addPermission(source, new PropertyPermission("sun.nio.fs.chdirAllowed", "read"));
190 sm.addPermission(source, new PropertyPermission("sun.timezone.ids.oldmapping", "read"));
191 sm.addPermission(source, new PropertyPermission("user.country", "read"));
192 sm.addPermission(source, new PropertyPermission("user.dir", "read"));
193 sm.addPermission(source, new PropertyPermission("user.timezone", "read,write"));
194 sm.addPermission(source, new NetPermission("specifyStreamHandler"));
195 sm.addPermission(source, new ReflectPermission("suppressAccessChecks"));
196 sm.setReadOnly();
197 System.setSecurityManager(sm);
198
199 xstream = new XStream(new PureJavaReflectionProvider(), new DomDriver());
200
201 assertBothWays();
202 }
203
204 private void assertBothWays() {
205
206 xstream.alias("software", Software.class);
207
208 final Software sw = new Software("jw", "xstr");
209 final String xml = "<software>\n"
210 + " <vendor>jw</vendor>\n"
211 + " <name>xstr</name>\n"
212 + "</software>";
213
214 String resultXml = xstream.toXML(sw);
215 assertEquals(xml, resultXml);
216 Object resultRoot = xstream.fromXML(resultXml);
217 if (!sw.equals(resultRoot)) {
218 assertEquals("Object deserialization failed", "DESERIALIZED OBJECT\n"
219 + xstream.toXML(sw), "DESERIALIZED OBJECT\n" + xstream.toXML(resultRoot));
220 }
221 }
222 }
0 /*
1 * Copyright (C) 2013, 2014 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 23. December 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.beans.EventHandler;
13
14 import com.thoughtworks.xstream.XStreamException;
15 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
16 import com.thoughtworks.xstream.security.ProxyTypePermission;
17
18 /**
19 * @author J&ouml;rg Schaible
20 */
21 public class SecurityVulnerabilityTest extends AbstractAcceptanceTest {
22
23 private final static StringBuffer BUFFER = new StringBuffer();
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 BUFFER.setLength(0);
28 xstream.alias("runnable", Runnable.class);
29 xstream.allowTypes(new Class[]{EventHandler.class});
30 xstream.allowTypeHierarchy(Runnable.class);
31 xstream.addPermission(ProxyTypePermission.PROXIES);
32 }
33
34 public void testCannotInjectEventHandler() {
35 final String xml = ""
36 + "<string class='runnable-array'>\n"
37 + " <dynamic-proxy>\n"
38 + " <interface>java.lang.Runnable</interface>\n"
39 + " <handler class='java.beans.EventHandler'>\n"
40 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
41 + " <action>exec</action>\n"
42 + " </handler>\n"
43 + " </dynamic-proxy>\n"
44 + "</string>";
45
46 try {
47 xstream.fromXML(xml);
48 fail("Thrown " + XStreamException.class.getName() + " expected");
49 } catch (final XStreamException e) {
50 assertTrue(e.getMessage().indexOf(EventHandler.class.getName()) > 0);
51 }
52 assertEquals(0, BUFFER.length());
53 }
54
55 public void testExplicitlyConvertEventHandler() {
56 final String xml = ""
57 + "<string class='runnable-array'>\n"
58 + " <dynamic-proxy>\n"
59 + " <interface>java.lang.Runnable</interface>\n"
60 + " <handler class='java.beans.EventHandler'>\n"
61 + " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
62 + " <action>exec</action>\n"
63 + " </handler>\n"
64 + " </dynamic-proxy>\n"
65 + "</string>";
66
67 xstream.registerConverter(new ReflectionConverter(xstream.getMapper(), xstream
68 .getReflectionProvider(), EventHandler.class));
69
70 final Runnable[] array = (Runnable[])xstream.fromXML(xml);
71 assertEquals(0, BUFFER.length());
72 array[0].run();
73 assertEquals("Executed!", BUFFER.toString());
74 }
75
76 public static class Exec {
77
78 public void exec() {
79 BUFFER.append("Executed!");
80 }
81 }
82 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 02. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.xstream.testutil.CallLog;
14
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.IOException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectInputValidation;
20 import java.io.ObjectOutputStream;
21 import java.io.Serializable;
22
23 public class SerializationCallbackOrderTest extends AbstractAcceptanceTest {
24
25 // static so it can be accessed by objects under test, without them needing a reference back to the testcase
26 private static CallLog log = new CallLog();
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 log.reset();
31 }
32
33
34 // --- Sample class hierarchy
35
36 public static class PrivateBase implements Serializable{
37
38 private void writeObject(ObjectOutputStream out) throws IOException {
39 log.actual("PrivateBase.writeObject() start");
40 out.defaultWriteObject();
41 log.actual("PrivateBase.writeObject() end");
42 }
43
44 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
45 log.actual("PrivateBase.readObject() start");
46 in.defaultReadObject();
47 log.actual("PrivateBase.readObject() end");
48 }
49
50 private Object writeReplace() {
51 log.actual("PrivateBase.writeReplace()");
52 return this;
53 }
54
55 private Object readResolve() {
56 log.actual("PrivateBase.readResolve()");
57 return this;
58 }
59 }
60
61 public static class PrivateChildOwnRR extends PrivateBase implements Serializable{
62
63 private void writeObject(ObjectOutputStream out) throws IOException {
64 log.actual("PrivateChildOwnRR.writeObject() start");
65 out.defaultWriteObject();
66 log.actual("PrivateChildOwnRR.writeObject() end");
67 }
68
69 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
70 log.actual("PrivateChildOwnRR.readObject() start");
71 in.defaultReadObject();
72 log.actual("PrivateChildOwnRR.readObject() end");
73 }
74
75 private Object writeReplace() {
76 log.actual("PrivateChildOwnRR.writeReplace()");
77 return this;
78 }
79
80 private Object readResolve() {
81 log.actual("PrivateChildOwnRR.readResolve()");
82 return this;
83 }
84 }
85
86 public static class PrivateChildNoRR extends PrivateBase implements Serializable{
87
88 private void writeObject(ObjectOutputStream out) throws IOException {
89 log.actual("PrivateChildNoRR.writeObject() start");
90 out.defaultWriteObject();
91 log.actual("PrivateChildNoRR.writeObject() end");
92 }
93
94 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
95 log.actual("PrivateChildNoRR.readObject() start");
96 in.defaultReadObject();
97 log.actual("PrivateChildNoRR.readObject() end");
98 }
99 }
100
101 public static class ProtectedBase implements Serializable{
102
103 private void writeObject(ObjectOutputStream out) throws IOException {
104 log.actual("ProtectedBase.writeObject() start");
105 out.defaultWriteObject();
106 log.actual("ProtectedBase.writeObject() end");
107 }
108
109 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
110 log.actual("ProtectedBase.readObject() start");
111 in.defaultReadObject();
112 log.actual("ProtectedBase.readObject() end");
113 }
114
115 protected Object writeReplace() {
116 log.actual("ProtectedBase.writeReplace()");
117 return this;
118 }
119
120 protected Object readResolve() {
121 log.actual("ProtectedBase.readResolve()");
122 return this;
123 }
124 }
125
126 public static class ProtectedChildOwnRR extends ProtectedBase implements Serializable{
127
128 private void writeObject(ObjectOutputStream out) throws IOException {
129 log.actual("ProtectedChildOwnRR.writeObject() start");
130 out.defaultWriteObject();
131 log.actual("ProtectedChildOwnRR.writeObject() end");
132 }
133
134 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
135 log.actual("ProtectedChildOwnRR.readObject() start");
136 in.defaultReadObject();
137 log.actual("ProtectedChildOwnRR.readObject() end");
138 }
139
140 protected Object writeReplace() {
141 log.actual("ProtectedChildOwnRR.writeReplace()");
142 return this;
143 }
144
145 protected Object readResolve() {
146 log.actual("ProtectedChildOwnRR.readResolve()");
147 return this;
148 }
149 }
150
151 public static class ProtectedChildInheritedRR extends ProtectedBase implements Serializable{
152
153 private void writeObject(ObjectOutputStream out) throws IOException {
154 log.actual("ProtectedChildInheritedRR.writeObject() start");
155 out.defaultWriteObject();
156 log.actual("ProtectedChildInheritedRR.writeObject() end");
157 }
158
159 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
160 log.actual("ProtectedChildInheritedRR.readObject() start");
161 in.defaultReadObject();
162 log.actual("ProtectedChildInheritedRR.readObject() end");
163 }
164 }
165
166 public static class PackageBase implements Serializable{
167
168 private void writeObject(ObjectOutputStream out) throws IOException {
169 log.actual("PackageBase.writeObject() start");
170 out.defaultWriteObject();
171 log.actual("PackageBase.writeObject() end");
172 }
173
174 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
175 log.actual("PackageBase.readObject() start");
176 in.defaultReadObject();
177 log.actual("PackageBase.readObject() end");
178 }
179
180 Object writeReplace() {
181 log.actual("PackageBase.writeReplace()");
182 return this;
183 }
184
185 Object readResolve() {
186 log.actual("PackageBase.readResolve()");
187 return this;
188 }
189 }
190
191 public static class PackageChildOwnRR extends PackageBase implements Serializable{
192
193 private void writeObject(ObjectOutputStream out) throws IOException {
194 log.actual("PackageChildOwnRR.writeObject() start");
195 out.defaultWriteObject();
196 log.actual("PackageChildOwnRR.writeObject() end");
197 }
198
199 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
200 log.actual("PackageChildOwnRR.readObject() start");
201 in.defaultReadObject();
202 log.actual("PackageChildOwnRR.readObject() end");
203 }
204
205 Object writeReplace() {
206 log.actual("PackageChildOwnRR.writeReplace()");
207 return this;
208 }
209
210 Object readResolve() {
211 log.actual("PackageChildOwnRR.readResolve()");
212 return this;
213 }
214 }
215
216 public static class PackageChildInheritedRR extends PackageBase implements Serializable{
217
218 private void writeObject(ObjectOutputStream out) throws IOException {
219 log.actual("PackageChildInheritedRR.writeObject() start");
220 out.defaultWriteObject();
221 log.actual("PackageChildInheritedRR.writeObject() end");
222 }
223
224 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
225 log.actual("PackageChildInheritedRR.readObject() start");
226 in.defaultReadObject();
227 log.actual("PackageChildInheritedRR.readObject() end");
228 }
229 }
230
231 // --- Convenience wrappers around Java Object Serialization
232
233 private byte[] javaSerialize(Object object) throws IOException {
234 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
235 ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes);
236 objectOutputStream.writeObject(object);
237 objectOutputStream.close();
238 return bytes.toByteArray();
239 }
240
241 private Object javaDeserialize(byte[] data) throws IOException, ClassNotFoundException {
242 ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data));
243 return objectInputStream.readObject();
244 }
245
246 // --- Tests
247
248 public void testJavaSerializationOwnPrivateRR() throws IOException {
249 // expectations
250 log.expect("PrivateChildOwnRR.writeReplace()");
251 log.expect("PrivateBase.writeObject() start");
252 log.expect("PrivateBase.writeObject() end");
253 log.expect("PrivateChildOwnRR.writeObject() start");
254 log.expect("PrivateChildOwnRR.writeObject() end");
255
256 // execute
257 javaSerialize(new PrivateChildOwnRR());
258
259 // verify
260 log.verify();
261 }
262
263 public void testJavaSerializationNoRR() throws IOException {
264 // expectations
265 log.expect("PrivateBase.writeObject() start");
266 log.expect("PrivateBase.writeObject() end");
267 log.expect("PrivateChildNoRR.writeObject() start");
268 log.expect("PrivateChildNoRR.writeObject() end");
269
270 // execute
271 javaSerialize(new PrivateChildNoRR());
272
273 // verify
274 log.verify();
275 }
276
277 public void testJavaSerializationOwnProtectedRR() throws IOException {
278 // expectations
279 log.expect("ProtectedChildOwnRR.writeReplace()");
280 log.expect("ProtectedBase.writeObject() start");
281 log.expect("ProtectedBase.writeObject() end");
282 log.expect("ProtectedChildOwnRR.writeObject() start");
283 log.expect("ProtectedChildOwnRR.writeObject() end");
284
285 // execute
286 javaSerialize(new ProtectedChildOwnRR());
287
288 // verify
289 log.verify();
290 }
291
292 public void testJavaSerializationInheritedRR() throws IOException {
293 // expectations
294 log.expect("ProtectedBase.writeReplace()");
295 log.expect("ProtectedBase.writeObject() start");
296 log.expect("ProtectedBase.writeObject() end");
297 log.expect("ProtectedChildInheritedRR.writeObject() start");
298 log.expect("ProtectedChildInheritedRR.writeObject() end");
299
300 // execute
301 javaSerialize(new ProtectedChildInheritedRR());
302
303 // verify
304 log.verify();
305 }
306
307 public void testJavaSerializationOwnPackageRR() throws IOException {
308 // expectations
309 log.expect("PackageChildOwnRR.writeReplace()");
310 log.expect("PackageBase.writeObject() start");
311 log.expect("PackageBase.writeObject() end");
312 log.expect("PackageChildOwnRR.writeObject() start");
313 log.expect("PackageChildOwnRR.writeObject() end");
314
315 // execute
316 javaSerialize(new PackageChildOwnRR());
317
318 // verify
319 log.verify();
320 }
321
322 public void testJavaSerializationInheritedPackageRR() throws IOException {
323 // expectations
324 log.expect("PackageBase.writeReplace()");
325 log.expect("PackageBase.writeObject() start");
326 log.expect("PackageBase.writeObject() end");
327 log.expect("PackageChildInheritedRR.writeObject() start");
328 log.expect("PackageChildInheritedRR.writeObject() end");
329
330 // execute
331 javaSerialize(new PackageChildInheritedRR());
332
333 // verify
334 log.verify();
335 }
336
337 public void testXStreamSerializationOwnPrivateRR() {
338 // expectations
339 log.expect("PrivateChildOwnRR.writeReplace()");
340 log.expect("PrivateBase.writeObject() start");
341 log.expect("PrivateBase.writeObject() end");
342 log.expect("PrivateChildOwnRR.writeObject() start");
343 log.expect("PrivateChildOwnRR.writeObject() end");
344
345 // execute
346 xstream.toXML(new PrivateChildOwnRR());
347
348 // verify
349 log.verify();
350 }
351
352 public void testXStreamSerializationNoRR() {
353 // expectations
354 log.expect("PrivateBase.writeObject() start");
355 log.expect("PrivateBase.writeObject() end");
356 log.expect("PrivateChildNoRR.writeObject() start");
357 log.expect("PrivateChildNoRR.writeObject() end");
358
359 // execute
360 xstream.toXML(new PrivateChildNoRR());
361
362 // verify
363 log.verify();
364 }
365
366 public void testXStreamSerializationOwnProtectedRR() {
367 // expectations
368 log.expect("ProtectedChildOwnRR.writeReplace()");
369 log.expect("ProtectedBase.writeObject() start");
370 log.expect("ProtectedBase.writeObject() end");
371 log.expect("ProtectedChildOwnRR.writeObject() start");
372 log.expect("ProtectedChildOwnRR.writeObject() end");
373
374 // execute
375 xstream.toXML(new ProtectedChildOwnRR());
376
377 // verify
378 log.verify();
379 }
380
381 public void testXStreamSerializationOwnInheritedRR() {
382 // expectations
383 log.expect("ProtectedBase.writeReplace()");
384 log.expect("ProtectedBase.writeObject() start");
385 log.expect("ProtectedBase.writeObject() end");
386 log.expect("ProtectedChildInheritedRR.writeObject() start");
387 log.expect("ProtectedChildInheritedRR.writeObject() end");
388
389 // execute
390 xstream.toXML(new ProtectedChildInheritedRR());
391
392 // verify
393 log.verify();
394 }
395
396 public void testXStreamSerializationOwnPackageRR() {
397 // expectations
398 log.expect("PackageChildOwnRR.writeReplace()");
399 log.expect("PackageBase.writeObject() start");
400 log.expect("PackageBase.writeObject() end");
401 log.expect("PackageChildOwnRR.writeObject() start");
402 log.expect("PackageChildOwnRR.writeObject() end");
403
404 // execute
405 xstream.toXML(new PackageChildOwnRR());
406
407 // verify
408 log.verify();
409 }
410
411 public void testXStreamSerializationOwnInheritedPackageRR() {
412 // expectations
413 log.expect("PackageBase.writeReplace()");
414 log.expect("PackageBase.writeObject() start");
415 log.expect("PackageBase.writeObject() end");
416 log.expect("PackageChildInheritedRR.writeObject() start");
417 log.expect("PackageChildInheritedRR.writeObject() end");
418
419 // execute
420 xstream.toXML(new PackageChildInheritedRR());
421
422 // verify
423 log.verify();
424 }
425
426 public void testJavaDeserializationOwnPrivateRR() throws IOException, ClassNotFoundException {
427 // setup
428 byte[] data = javaSerialize(new PrivateChildOwnRR());
429 log.reset();
430
431 // expectations
432 log.expect("PrivateBase.readObject() start");
433 log.expect("PrivateBase.readObject() end");
434 log.expect("PrivateChildOwnRR.readObject() start");
435 log.expect("PrivateChildOwnRR.readObject() end");
436 log.expect("PrivateChildOwnRR.readResolve()");
437
438 // execute
439 javaDeserialize(data);
440
441 // verify
442 log.verify();
443 }
444
445 public void testJavaDeserializationNoRR() throws IOException, ClassNotFoundException {
446 // setup
447 byte[] data = javaSerialize(new PrivateChildNoRR());
448 log.reset();
449
450 // expectations
451 log.expect("PrivateBase.readObject() start");
452 log.expect("PrivateBase.readObject() end");
453 log.expect("PrivateChildNoRR.readObject() start");
454 log.expect("PrivateChildNoRR.readObject() end");
455
456 // execute
457 javaDeserialize(data);
458
459 // verify
460 log.verify();
461 }
462
463 public void testJavaDeserializationOwnProtectedRR() throws IOException, ClassNotFoundException {
464 // setup
465 byte[] data = javaSerialize(new ProtectedChildOwnRR());
466 log.reset();
467
468 // expectations
469 log.expect("ProtectedBase.readObject() start");
470 log.expect("ProtectedBase.readObject() end");
471 log.expect("ProtectedChildOwnRR.readObject() start");
472 log.expect("ProtectedChildOwnRR.readObject() end");
473 log.expect("ProtectedChildOwnRR.readResolve()");
474
475 // execute
476 javaDeserialize(data);
477
478 // verify
479 log.verify();
480 }
481
482 public void testJavaDeserializationInheritedRR() throws IOException, ClassNotFoundException {
483 // setup
484 byte[] data = javaSerialize(new ProtectedChildInheritedRR());
485 log.reset();
486
487 // expectations
488 log.expect("ProtectedBase.readObject() start");
489 log.expect("ProtectedBase.readObject() end");
490 log.expect("ProtectedChildInheritedRR.readObject() start");
491 log.expect("ProtectedChildInheritedRR.readObject() end");
492 log.expect("ProtectedBase.readResolve()");
493
494 // execute
495 javaDeserialize(data);
496
497 // verify
498 log.verify();
499 }
500
501 public void testJavaDeserializationOwnPackageRR() throws IOException, ClassNotFoundException {
502 // setup
503 byte[] data = javaSerialize(new PackageChildOwnRR());
504 log.reset();
505
506 // expectations
507 log.expect("PackageBase.readObject() start");
508 log.expect("PackageBase.readObject() end");
509 log.expect("PackageChildOwnRR.readObject() start");
510 log.expect("PackageChildOwnRR.readObject() end");
511 log.expect("PackageChildOwnRR.readResolve()");
512
513 // execute
514 javaDeserialize(data);
515
516 // verify
517 log.verify();
518 }
519
520 public void testJavaDeserializationInheritedPackageRR() throws IOException, ClassNotFoundException {
521 // setup
522 byte[] data = javaSerialize(new PackageChildInheritedRR());
523 log.reset();
524
525 // expectations
526 log.expect("PackageBase.readObject() start");
527 log.expect("PackageBase.readObject() end");
528 log.expect("PackageChildInheritedRR.readObject() start");
529 log.expect("PackageChildInheritedRR.readObject() end");
530 log.expect("PackageBase.readResolve()");
531
532 // execute
533 javaDeserialize(data);
534
535 // verify
536 log.verify();
537 }
538
539 public void testXStreamDeserializationOwnPrivateRR() {
540 // setup
541 String data = xstream.toXML(new PrivateChildOwnRR());
542 log.reset();
543
544 // expectations
545 log.expect("PrivateBase.readObject() start");
546 log.expect("PrivateBase.readObject() end");
547 log.expect("PrivateChildOwnRR.readObject() start");
548 log.expect("PrivateChildOwnRR.readObject() end");
549 log.expect("PrivateChildOwnRR.readResolve()");
550
551 // execute
552 xstream.fromXML(data);
553
554 // verify
555 log.verify();
556 }
557
558 public void testXStreamDeserializationNoRR() {
559 // setup
560 String data = xstream.toXML(new PrivateChildNoRR());
561 log.reset();
562
563 // expectations
564 log.expect("PrivateBase.readObject() start");
565 log.expect("PrivateBase.readObject() end");
566 log.expect("PrivateChildNoRR.readObject() start");
567 log.expect("PrivateChildNoRR.readObject() end");
568
569 // execute
570 xstream.fromXML(data);
571
572 // verify
573 log.verify();
574 }
575
576 public void testXStreamDeserializationOwnProtectedRR() {
577 // setup
578 String data = xstream.toXML(new ProtectedChildOwnRR());
579 log.reset();
580
581 // expectations
582 log.expect("ProtectedBase.readObject() start");
583 log.expect("ProtectedBase.readObject() end");
584 log.expect("ProtectedChildOwnRR.readObject() start");
585 log.expect("ProtectedChildOwnRR.readObject() end");
586 log.expect("ProtectedChildOwnRR.readResolve()");
587
588 // execute
589 xstream.fromXML(data);
590
591 // verify
592 log.verify();
593 }
594
595 public void testXStreamDeserializationInheritedRR() {
596 // setup
597 String data = xstream.toXML(new ProtectedChildInheritedRR());
598 log.reset();
599
600 // expectations
601 log.expect("ProtectedBase.readObject() start");
602 log.expect("ProtectedBase.readObject() end");
603 log.expect("ProtectedChildInheritedRR.readObject() start");
604 log.expect("ProtectedChildInheritedRR.readObject() end");
605 log.expect("ProtectedBase.readResolve()");
606
607 // execute
608 xstream.fromXML(data);
609
610 // verify
611 log.verify();
612 }
613
614 public void testXStreamDeserializationOwnPackageRR() {
615 // setup
616 String data = xstream.toXML(new PackageChildOwnRR());
617 log.reset();
618
619 // expectations
620 log.expect("PackageBase.readObject() start");
621 log.expect("PackageBase.readObject() end");
622 log.expect("PackageChildOwnRR.readObject() start");
623 log.expect("PackageChildOwnRR.readObject() end");
624 log.expect("PackageChildOwnRR.readResolve()");
625
626 // execute
627 xstream.fromXML(data);
628
629 // verify
630 log.verify();
631 }
632
633 public void testXStreamDeserializationInheritedPackageRR() {
634 // setup
635 String data = xstream.toXML(new PackageChildInheritedRR());
636 log.reset();
637
638 // expectations
639 log.expect("PackageBase.readObject() start");
640 log.expect("PackageBase.readObject() end");
641 log.expect("PackageChildInheritedRR.readObject() start");
642 log.expect("PackageChildInheritedRR.readObject() end");
643 log.expect("PackageBase.readResolve()");
644
645 // execute
646 xstream.fromXML(data);
647
648 // verify
649 log.verify();
650 }
651
652 public static class ParentNotTransient implements Serializable {
653
654 public int somethingNotTransient;
655
656 public ParentNotTransient(int somethingNotTransient) {
657 this.somethingNotTransient = somethingNotTransient;
658 }
659
660 }
661
662 public static class ChildWithTransient extends ParentNotTransient implements Serializable {
663
664 public transient int somethingTransient;
665
666 public ChildWithTransient(int somethingNotTransient, int somethingTransient) {
667 super(somethingNotTransient);
668 this.somethingTransient = somethingTransient;
669 }
670
671 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
672 s.defaultReadObject();
673 somethingTransient = 99999;
674 }
675 }
676
677 public void testCallsReadObjectEvenWithoutNonTransientFields() {
678 xstream.alias("parent", ParentNotTransient.class);
679 xstream.alias("child", ChildWithTransient.class);
680
681 Object in = new ChildWithTransient(10, 22222);
682 String expectedXml = ""
683 + "<child serialization=\"custom\">\n"
684 + " <parent>\n"
685 + " <default>\n"
686 + " <somethingNotTransient>10</somethingNotTransient>\n"
687 + " </default>\n"
688 + " </parent>\n"
689 + " <child>\n"
690 + " <default/>\n"
691 + " </child>\n"
692 + "</child>";
693
694 String xml = xstream.toXML(in);
695 assertEquals(expectedXml, xml);
696
697 ChildWithTransient childWithTransient = (ChildWithTransient) xstream.fromXML(xml);
698
699 assertEquals(10, childWithTransient.somethingNotTransient);
700 assertEquals(99999, childWithTransient.somethingTransient);
701 }
702
703
704 public static class SomethingThatValidates implements Serializable {
705
706 private void readObject(ObjectInputStream s) throws IOException {
707
708 final int LOW_PRIORITY = -5;
709 final int MEDIUM_PRIORITY = 0;
710 final int HIGH_PRIORITY = 5;
711
712 s.registerValidation(new ObjectInputValidation() {
713 public void validateObject() {
714 log.actual("validateObject() medium priority 1");
715 }
716 }, MEDIUM_PRIORITY);
717
718 s.registerValidation(new ObjectInputValidation() {
719 public void validateObject() {
720 log.actual("validateObject() high priority");
721 }
722 }, HIGH_PRIORITY);
723
724 s.registerValidation(new ObjectInputValidation() {
725 public void validateObject() {
726 log.actual("validateObject() low priority");
727 }
728 }, LOW_PRIORITY);
729
730 s.registerValidation(new ObjectInputValidation() {
731 public void validateObject() {
732 log.actual("validateObject() medium priority 2");
733 }
734 }, MEDIUM_PRIORITY);
735 }
736
737 private Object readResolve() {
738 log.actual("readResolve()");
739 return this;
740 }
741 }
742
743 public void testJavaSerializationValidatesObjectIsCalledInPriorityOrder() throws IOException, ClassNotFoundException {
744 // expect
745 log.expect("readResolve()");
746 log.expect("validateObject() high priority");
747 log.expect("validateObject() medium priority 2");
748 log.expect("validateObject() medium priority 1");
749 log.expect("validateObject() low priority");
750
751 // execute
752 javaDeserialize(javaSerialize(new SomethingThatValidates()));
753
754 // verify
755 log.verify();
756 }
757
758 public void testXStreamSerializationValidatesObjectIsCalledInPriorityOrder() {
759 // expect
760 log.expect("readResolve()");
761 log.expect("validateObject() high priority");
762 log.expect("validateObject() medium priority 2");
763 log.expect("validateObject() medium priority 1");
764 log.expect("validateObject() low priority");
765
766 // execute
767 xstream.fromXML(xstream.toXML(new SomethingThatValidates()));
768
769 // verify
770 log.verify();
771 }
772
773 public static class UnserializableParent {
774 public int x;
775
776 public UnserializableParent() {
777 x = 5;
778 }
779 }
780
781 public static class CustomSerializableChild extends UnserializableParent implements Serializable {
782 public int y;
783
784 public CustomSerializableChild() {
785 y = 10;
786 }
787
788 private void writeObject(ObjectOutputStream stream) throws IOException {
789 log.actual("Child.writeObject() start");
790 stream.defaultWriteObject();
791 log.actual("Child.writeObject() end");
792 }
793
794 private void readObject(ObjectInputStream stream)
795 throws IOException, ClassNotFoundException {
796 log.actual("Child.readObject() start");
797 stream.defaultReadObject();
798 log.actual("Child.readObject() end");
799 }
800
801 private Object writeReplace() {
802 log.actual("Child.writeReplace()");
803 return this;
804 }
805
806 private Object readResolve() {
807 log.actual("Child.readResolve()");
808 return this;
809 }
810 }
811
812 public void testFieldsOfUnserializableParentsArePreserved() {
813 xstream.alias("parent", UnserializableParent.class);
814 xstream.alias("child", CustomSerializableChild.class);
815
816 CustomSerializableChild child = new CustomSerializableChild();
817 String expected = ""
818 + "<child serialization=\"custom\">\n"
819 + " <unserializable-parents>\n"
820 + " <x>5</x>\n"
821 + " </unserializable-parents>\n"
822 + " <child>\n"
823 + " <default>\n"
824 + " <y>10</y>\n"
825 + " </default>\n"
826 + " </child>\n"
827 + "</child>";
828
829 CustomSerializableChild serialized =(CustomSerializableChild)assertBothWays(child, expected);
830 assertEquals(5, serialized.x);
831 assertEquals(10, serialized.y);
832 }
833
834 public static class SerializableGrandChild extends CustomSerializableChild implements Serializable {
835 public int z;
836
837 public SerializableGrandChild() {
838 super();
839 z = 42;
840 }
841 }
842
843 public void testUnserializableParentsAreWrittenOnlyOnce() {
844 xstream.alias("parent", UnserializableParent.class);
845 xstream.alias("child", CustomSerializableChild.class);
846 xstream.alias("grandchild", SerializableGrandChild.class);
847
848 SerializableGrandChild grandChild = new SerializableGrandChild();
849 String expected = ""
850 + "<grandchild serialization=\"custom\">\n"
851 + " <unserializable-parents>\n"
852 + " <x>5</x>\n"
853 + " </unserializable-parents>\n"
854 + " <child>\n"
855 + " <default>\n"
856 + " <y>10</y>\n"
857 + " </default>\n"
858 + " </child>\n"
859 + " <grandchild>\n"
860 + " <default>\n"
861 + " <z>42</z>\n"
862 + " </default>\n"
863 + " </grandchild>\n"
864 + "</grandchild>";
865
866 SerializableGrandChild serialized =(SerializableGrandChild)assertBothWays(grandChild, expected);
867 assertEquals(5, serialized.x);
868 assertEquals(10, serialized.y);
869 assertEquals(42, serialized.z);
870 }
871
872 public void testXStreamSerializationForObjectsWithUnserializableParents() {
873 // expectations
874 log.expect("Child.writeReplace()");
875 log.expect("Child.writeObject() start");
876 log.expect("Child.writeObject() end");
877
878 // execute
879 xstream.toXML(new CustomSerializableChild());
880
881 // verify
882 log.verify();
883 }
884
885 public void testXStreamDeserializationForObjectsWithUnserializableParents() {
886 // setup
887 String data = xstream.toXML(new CustomSerializableChild());
888 log.reset();
889
890 // expectations
891 log.expect("Child.readObject() start");
892 log.expect("Child.readObject() end");
893 log.expect("Child.readResolve()");
894
895 // execute
896 xstream.fromXML(data);
897
898 // verify
899 log.verify();
900 }
901
902 }
0 /*
1 * Copyright (C) 2006, 2007, 2010, 2012, 2014 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 12. June 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.io.Serializable;
16 import java.io.StringReader;
17 import java.io.StringWriter;
18 import java.util.ArrayList;
19 import java.util.Calendar;
20 import java.util.GregorianCalendar;
21 import java.util.LinkedList;
22 import java.util.List;
23 import java.util.TimeZone;
24
25 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
26
27 /**
28 * <p>
29 * A class {@link Serializable} {@link Parent} class implements
30 * <code>writeObject()</code> and holds a {@link Child} class that also
31 * implements <code>writeObject()</code>
32 * </p>
33 *
34 * @author <a href="mailto:cleclerc@pobox.com">Cyrille Le Clerc</a>
35 */
36 public class SerializationNestedWriteObjectsTest extends AbstractAcceptanceTest {
37
38 public static class Child implements Serializable {
39
40 private int i = 3;
41
42 public Child(int i) {
43 this.i = i;
44 }
45
46 public int getI() {
47 return i;
48 }
49
50 private void readObject(java.io.ObjectInputStream in) throws IOException,
51 ClassNotFoundException {
52 in.defaultReadObject();
53 }
54
55 private void writeObject(ObjectOutputStream out) throws IOException {
56 out.defaultWriteObject();
57 }
58 }
59
60 public static class Parent implements Serializable {
61
62 private String name;
63
64 private transient Child child;
65
66 public Parent(String name, Child child) {
67 this.name = name;
68 this.child = child;
69 }
70
71 public Child getChild() {
72 return child;
73 }
74
75 public String getName() {
76 return name;
77 }
78
79 private void readObject(java.io.ObjectInputStream in) throws IOException,
80 ClassNotFoundException {
81 this.child = (Child) in.readObject();
82 in.defaultReadObject();
83 }
84
85 private void writeObject(ObjectOutputStream out) throws IOException {
86 out.writeObject(this.child);
87 out.defaultWriteObject();
88 }
89 }
90
91 public void testObjectInputStream() throws Exception {
92 xstream.alias("parent", Parent.class);
93 xstream.alias("child", Child.class);
94
95 String sourceXml = ""
96 + "<object-stream>\n"
97 + " <parent serialization=\"custom\">\n"
98 + " <parent>\n"
99 + " <child serialization=\"custom\">\n"
100 + " <child>\n"
101 + " <default>\n"
102 + " <i>1</i>\n"
103 + " </default>\n"
104 + " </child>\n"
105 + " </child>\n"
106 + " <default>\n"
107 + " <name>ze-name</name>\n"
108 + " </default>\n"
109 + " </parent>\n"
110 + " </parent>\n"
111 + "</object-stream>";
112
113 ObjectInputStream objectInputStream = xstream.createObjectInputStream(new StringReader(
114 sourceXml));
115
116 Parent parent = (Parent) objectInputStream.readObject();
117
118 assertEquals("ze-name", parent.getName());
119 assertEquals(1, parent.getChild().getI());
120 }
121
122 public void testObjectOutputStream() throws Exception {
123 xstream.alias("parent", Parent.class);
124 xstream.alias("child", Child.class);
125
126 String expectedXml = ""
127 + "<object-stream>\n"
128 + " <parent serialization=\"custom\">\n"
129 + " <parent>\n"
130 + " <child serialization=\"custom\">\n"
131 + " <child>\n"
132 + " <default>\n"
133 + " <i>1</i>\n"
134 + " </default>\n"
135 + " </child>\n"
136 + " </child>\n"
137 + " <default>\n"
138 + " <name>ze-name</name>\n"
139 + " </default>\n"
140 + " </parent>\n"
141 + " </parent>\n"
142 + "</object-stream>";
143
144 Parent parent = new Parent("ze-name", new Child(1));
145 StringWriter stringWriter = new StringWriter();
146 ObjectOutputStream os = xstream.createObjectOutputStream(stringWriter);
147 os.writeObject(parent);
148 os.close();
149 String actualXml = stringWriter.getBuffer().toString();
150 assertEquals(expectedXml, actualXml);
151 }
152
153 public void testToXML() {
154
155 xstream.alias("parent", Parent.class);
156 xstream.alias("child", Child.class);
157
158 String expected = ""
159 + "<parent serialization=\"custom\">\n"
160 + " <parent>\n"
161 + " <child serialization=\"custom\">\n"
162 + " <child>\n"
163 + " <default>\n"
164 + " <i>1</i>\n"
165 + " </default>\n"
166 + " </child>\n"
167 + " </child>\n"
168 + " <default>\n"
169 + " <name>ze-name</name>\n"
170 + " </default>\n"
171 + " </parent>\n"
172 + "</parent>";
173
174 Parent parent = new Parent("ze-name", new Child(1));
175
176 assertBothWays(parent, expected);
177 }
178
179 public static class RawString implements Serializable {
180
181 private String s;
182
183 public RawString(String s) {
184 this.s = s;
185 }
186
187 public String getS() {
188 return s;
189 }
190
191 private void readObject(java.io.ObjectInputStream in) throws IOException {
192 int i = in.read();
193 byte[] b = new byte[i];
194 in.read(b);
195 s = new String(b);
196 }
197
198 private void writeObject(ObjectOutputStream out) throws IOException {
199 byte[] b = s.getBytes();
200 out.write(b.length);
201 out.write(b);
202 }
203 }
204
205 public void testCanHandleRawBytes() throws IOException, ClassNotFoundException {
206 xstream.alias("raw", RawString.class);
207
208 String expectedXml = ""
209 + "<root>\n"
210 + " <raw serialization=\"custom\">\n"
211 + " <raw>\n"
212 + " <byte>7</byte>\n"
213 + " <byte-array>WFN0cmVhbQ==</byte-array>\n"
214 + " </raw>\n"
215 + " </raw>\n"
216 + "</root>";
217
218 StringWriter stringWriter = new StringWriter();
219 ObjectOutputStream os = xstream.createObjectOutputStream(stringWriter, "root");
220 os.writeObject(new RawString("XStream"));
221 os.close();
222 String actualXml = stringWriter.getBuffer().toString();
223 assertEquals(expectedXml, actualXml);
224
225 ObjectInputStream objectInputStream = xstream.createObjectInputStream(new StringReader(actualXml));
226
227 RawString rawString = (RawString) objectInputStream.readObject();
228 assertEquals("XStream", rawString.getS());
229 }
230
231 static class Store implements Serializable {
232 List store;
233 public Store() {
234 store = new ArrayList();
235 }
236 private void writeObject(ObjectOutputStream out) throws IOException {
237 out.defaultWriteObject();
238 }
239 }
240 static class OtherStore extends Store {
241 private Object readResolve() {
242 if (this.store instanceof LinkedList) {
243 Store replacement = new MyStore();
244 replacement.store = store;
245 return replacement;
246 }
247 return this;
248 }
249 }
250 static class MyStore extends OtherStore {
251 public MyStore() {
252 store = new LinkedList();
253 }
254 private Object writeReplace() {
255 Store replacement = new OtherStore();
256 replacement.store = store;
257 return replacement;
258 }
259 }
260
261 public void testCachingInheritedWriteObject() throws Exception {
262 xstream.alias("store", Store.class);
263 xstream.alias("my", MyStore.class);
264 xstream.alias("other", OtherStore.class);
265
266 String expectedXml = ""
267 + "<store-array>\n"
268 + " <my resolves-to=\"other\" serialization=\"custom\">\n"
269 + " <store>\n"
270 + " <default>\n"
271 + " <store class=\"linked-list\">\n"
272 + " <string>one</string>\n"
273 + " </store>\n"
274 + " </default>\n"
275 + " </store>\n"
276 + " </my>\n"
277 + " <other serialization=\"custom\">\n"
278 + " <store>\n"
279 + " <default>\n"
280 + " <store>\n"
281 + " <string>two</string>\n"
282 + " </store>\n"
283 + " </default>\n"
284 + " </store>\n"
285 + " </other>\n"
286 + "</store-array>";
287
288 Store[] stores = new Store[]{
289 new MyStore(),
290 new OtherStore()
291 };
292 stores[0].store.add("one");
293 stores[1].store.add("two");
294
295 assertBothWays(stores, expectedXml);
296 }
297
298 static class MoscowCalendar extends GregorianCalendar {
299 public MoscowCalendar() {
300 super(TimeZone.getTimeZone("Europe/Moscow"));
301 }
302 }
303
304 public void testNestedSerializationOfDefaultType() {
305 Calendar in = new MoscowCalendar();
306 in.setTimeInMillis(44444);
307 String xml = xstream.toXML(in);
308 Calendar out = (Calendar) xstream.fromXML(xml);
309 assertEquals(in.getTime(), out.getTime());
310 }
311 }
0 /*
1 * Copyright (C) 2007, 2014 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.reflection.FieldDictionary;
14 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
15 import com.thoughtworks.xstream.converters.reflection.SortableFieldKeySorter;
16
17 public class SortableFieldListTest extends AbstractAcceptanceTest {
18
19 public void testSortsFieldOrderWithArray() {
20
21 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
22 sorter.registerFieldOrder(MommyBear.class,
23 new String[] { "b", "c", "a" });
24
25 xstream = new XStream(new PureJavaReflectionProvider(new FieldDictionary(sorter)));
26 setupSecurity(xstream);
27 xstream.alias("mommy", MommyBear.class);
28 MommyBear root = new MommyBear();
29 root.c = "ccc";
30 root.b = "bbb";
31 root.a = "aaa";
32 assertBothWays(root, "<mommy>\n" + " <b>bbb</b>\n" + " <c>ccc</c>\n"
33 + " <a>aaa</a>\n" + "</mommy>");
34 }
35
36 public void testSortsFieldOrderWhileUsingInheritance() {
37
38 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
39 sorter.registerFieldOrder(BabyBear.class,
40 new String[] { "b", "d", "c", "a" });
41
42 xstream = new XStream(new PureJavaReflectionProvider(new FieldDictionary(sorter)));
43 setupSecurity(xstream);
44 xstream.alias("baby", BabyBear.class);
45 BabyBear root = new BabyBear();
46 root.c = "ccc";
47 root.b = "bbb";
48 root.a = "aaa";
49 root.d = "ddd";
50 assertBothWays(root, "<baby>\n" + " <b>bbb</b>\n" + " <d>ddd</d>\n"
51 + " <c>ccc</c>\n" + " <a>aaa</a>\n" + "</baby>");
52 }
53
54 public static class MommyBear {
55 protected String c, a, b;
56 }
57
58 public static class BabyBear extends MommyBear {
59 private String d;
60 }
61
62 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2014 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 30. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.core.JVM;
15
16 import javax.swing.DefaultListModel;
17 import javax.swing.JList;
18 import javax.swing.JTable;
19 import javax.swing.LookAndFeel;
20 import javax.swing.plaf.metal.MetalLookAndFeel;
21
22 public class SwingTest extends AbstractAcceptanceTest {
23
24 protected void setupSecurity(XStream xstream) {
25 super.setupSecurity(xstream);
26 xstream.allowTypesByWildcard(new String[]{"javax.swing.**", "java.awt.**", "java.beans.**", "sun.swing.**"});
27 }
28
29 // JTable is one of the nastiest components to serialize. If this works, we're in good shape :)
30 public void testJTable() {
31 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
32 if (!isHeadless || JVM.is15()) {
33 // Note: JTable does not have a sensible .equals() method, so we compare the XML instead.
34 JTable original = new JTable();
35 String originalXml = xstream.toXML(original);
36
37 JTable deserialized = (JTable) xstream.fromXML(originalXml);
38 String deserializedXml = xstream.toXML(deserialized);
39
40 assertEquals(originalXml, deserializedXml);
41 }
42 }
43
44 public void testDefaultListModel() {
45 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
46 if (!isHeadless || JVM.is15()) {
47 final DefaultListModel original = new DefaultListModel();
48 final JList list = new JList();
49 list.setModel(original);
50
51 String originalXml = xstream.toXML(original);
52
53 DefaultListModel deserialized = (DefaultListModel) xstream.fromXML(originalXml);
54 String deserializedXml = xstream.toXML(deserialized);
55
56 assertEquals(originalXml, deserializedXml);
57
58 list.setModel(deserialized);
59 }
60 }
61
62 public void testMetalLookAndFeel() {
63 LookAndFeel plaf = new MetalLookAndFeel();
64 String originalXml = xstream.toXML(plaf);
65 assertBothWays(plaf, originalXml);
66 }
67 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 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 08. May 2005 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13
14 import java.util.ArrayList;
15 import java.util.Comparator;
16 import java.util.TreeMap;
17 import java.util.TreeSet;
18
19 import com.thoughtworks.xstream.core.JVM;
20
21 public class TreeMapAndTreeSetTest extends AbstractAcceptanceTest {
22
23 public static class MyComparator implements Comparator {
24 private String something = "stuff";
25
26 public int compare(Object o1, Object o2) {
27 return ((String) o1).compareTo((String) o2);
28 }
29 }
30
31 public static class UnusedComparator implements Comparator {
32
33 private final static Comparator THROWING_COMPARATOR = new Comparator() {
34
35 public int compare(Object o1, Object o2) {
36 throw new UnsupportedOperationException();
37 }
38
39 };
40
41 public int compare(Object o1, Object o2) {
42 return ((String) o1).compareTo((String) o2);
43 }
44
45 private Object readResolve() {
46 return THROWING_COMPARATOR;
47 }
48 }
49
50 protected void setUp() throws Exception {
51 super.setUp();
52 xstream.alias("my-comparator", MyComparator.class);
53 xstream.alias("unused-comparator", UnusedComparator.class);
54 }
55
56 public void testTreeMapWithComparator() {
57 TreeMap map = new TreeMap(new MyComparator());
58 map.put("benny", "hill");
59 map.put("joe", "walnes");
60
61 String expected = "" +
62 "<tree-map>\n" +
63 " <comparator class=\"my-comparator\">\n" +
64 " <something>stuff</something>\n" +
65 " </comparator>\n" +
66 " <entry>\n" +
67 " <string>benny</string>\n" +
68 " <string>hill</string>\n" +
69 " </entry>\n" +
70 " <entry>\n" +
71 " <string>joe</string>\n" +
72 " <string>walnes</string>\n" +
73 " </entry>\n" +
74 "</tree-map>";
75
76 TreeMap result = (TreeMap) assertBothWays(map, expected);
77 assertEquals(MyComparator.class, result.comparator().getClass());
78 }
79
80 public void testTreeMapWithoutComparator() {
81 TreeMap map = new TreeMap();
82 map.put("benny", "hill");
83 map.put("joe", "walnes");
84
85 String expected = "" +
86 "<tree-map>\n" +
87 " <entry>\n" +
88 " <string>benny</string>\n" +
89 " <string>hill</string>\n" +
90 " </entry>\n" +
91 " <entry>\n" +
92 " <string>joe</string>\n" +
93 " <string>walnes</string>\n" +
94 " </entry>\n" +
95 "</tree-map>";
96
97 TreeMap result = (TreeMap) assertBothWays(map, expected);
98 assertNull(result.comparator());
99 }
100
101 public void testEmptyTreeMap() {
102 TreeMap map = new TreeMap();
103
104 String expected = "<tree-map/>";
105 TreeMap result = (TreeMap) assertBothWays(map, expected);
106 assertNull(result.comparator());
107 }
108
109 public void testTreeMapDoesNotUseComparatorAtDeserialization() {
110 if (JVM.hasOptimizedTreeMapPutAll()) {
111 TreeMap map = new TreeMap(new UnusedComparator());
112 map.put("john", "doe");
113 map.put("benny", "hill");
114 map.put("joe", "walnes");
115
116 String expected = "" +
117 "<tree-map>\n" +
118 " <comparator class=\"unused-comparator\"/>\n" +
119 " <entry>\n" +
120 " <string>benny</string>\n" +
121 " <string>hill</string>\n" +
122 " </entry>\n" +
123 " <entry>\n" +
124 " <string>joe</string>\n" +
125 " <string>walnes</string>\n" +
126 " </entry>\n" +
127 " <entry>\n" +
128 " <string>john</string>\n" +
129 " <string>doe</string>\n" +
130 " </entry>\n" +
131 "</tree-map>";
132
133 assertEquals(expected, xstream.toXML(map));
134 TreeMap result = (TreeMap) xstream.fromXML(expected);
135 assertSame(UnusedComparator.THROWING_COMPARATOR, result.comparator());
136 assertEquals(new ArrayList(map.entrySet()), new ArrayList(result.entrySet()));
137 }
138 }
139
140 public void testTreeSetWithComparator() {
141 TreeSet set = new TreeSet(new MyComparator());
142 set.add("hi");
143 set.add("bye");
144
145 String expected = "" +
146 "<sorted-set>\n" +
147 " <comparator class=\"my-comparator\">\n" +
148 " <something>stuff</something>\n" +
149 " </comparator>\n" +
150 " <string>bye</string>\n" +
151 " <string>hi</string>\n" +
152 "</sorted-set>";
153
154 TreeSet result = (TreeSet) assertBothWays(set, expected);
155 assertEquals(MyComparator.class, result.comparator().getClass());
156 }
157
158 public void testTreeSetWithoutComparator() {
159 TreeSet set = new TreeSet();
160 set.add("hi");
161 set.add("bye");
162
163 String expected = "" +
164 "<sorted-set>\n" +
165 " <string>bye</string>\n" +
166 " <string>hi</string>\n" +
167 "</sorted-set>";
168
169 TreeSet result = (TreeSet)assertBothWays(set, expected);
170 assertNull(result.comparator());
171 }
172
173 public void testEmptyTreeSet() {
174 TreeSet set = new TreeSet();
175
176 String expected = "<sorted-set/>";
177 TreeSet result = (TreeSet)assertBothWays(set, expected);
178 assertNull(result.comparator());
179 }
180
181 public void testTreeSetDoesNotUseComparatorAtDeserialization() {
182 if (JVM.hasOptimizedTreeSetAddAll()) {
183 TreeSet set = new TreeSet(new UnusedComparator());
184 set.add("guy");
185 set.add("hi");
186 set.add("bye");
187
188 String expected = "" +
189 "<sorted-set>\n" +
190 " <comparator class=\"unused-comparator\"/>\n" +
191 " <string>bye</string>\n" +
192 " <string>guy</string>\n" +
193 " <string>hi</string>\n" +
194 "</sorted-set>";
195
196 assertEquals(expected, xstream.toXML(set));
197 TreeSet result = (TreeSet) xstream.fromXML(expected);
198 assertSame(UnusedComparator.THROWING_COMPARATOR, result.comparator());
199 assertEquals(new ArrayList(set), new ArrayList(result));
200 }
201 }
202
203 public void testTreeSetRemoveWorksProperlyAfterDeserialization() {
204 TreeSet set = new TreeSet();
205 set.add("guy");
206 set.add("hi");
207 set.add("bye");
208
209 TreeSet result = (TreeSet) xstream.fromXML(xstream.toXML(set));
210 assertTrue(result.remove("hi"));
211 }
212 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2014, 2015 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. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.Original;
14 import com.thoughtworks.acceptance.objects.Replaced;
15 import com.thoughtworks.acceptance.objects.StandardObject;
16
17 import java.io.ByteArrayInputStream;
18 import java.io.ByteArrayOutputStream;
19 import java.io.Externalizable;
20 import java.io.IOException;
21 import java.io.ObjectInput;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutput;
24 import java.io.ObjectOutputStream;
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.commons.lang.StringUtils;
30
31 public class WriteReplaceTest extends AbstractAcceptanceTest {
32
33 public static class Thing extends StandardObject implements Serializable {
34
35 int a;
36 int b;
37
38 public Thing() {
39 }
40
41 public Thing(int a, int b) {
42 this.a = a;
43 this.b = b;
44 }
45
46 private Object writeReplace() {
47 return new Thing(a * 1000, b * 1000);
48 }
49
50 private Object readResolve() {
51 return new Thing(a / 1000, b / 1000);
52 }
53
54 }
55
56 public void testReplacesAndResolves() throws IOException, ClassNotFoundException {
57 Thing thing = new Thing(3, 6);
58
59 // ensure that Java serialization does not cause endless loop for a Thing
60 ByteArrayOutputStream baos = new ByteArrayOutputStream();
61 ObjectOutputStream oos = new ObjectOutputStream(baos);
62 oos.writeObject(thing);
63 oos.close();
64
65 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
66 ObjectInputStream ios = new ObjectInputStream(bais);
67 assertEquals(thing, ios.readObject());
68 ios.close();
69
70 // ensure that XStream does not cause endless loop for a Thing
71 xstream.alias("thing", Thing.class);
72
73 String expectedXml = ""
74 + "<thing>\n"
75 + " <a>3000</a>\n"
76 + " <b>6000</b>\n"
77 + "</thing>";
78
79 assertBothWays(thing, expectedXml);
80 }
81
82 public void testAllowsDifferentTypeToBeSubstituted() {
83 xstream.alias("original-class", Original.class);
84 xstream.alias("replaced-class", Replaced.class);
85
86 Original in = new Original("hello world");
87
88 String expectedXml = ""
89 + "<original-class resolves-to=\"replaced-class\">\n"
90 + " <replacedValue>HELLO WORLD</replacedValue>\n"
91 + "</original-class>";
92
93 assertBothWays(in, expectedXml);
94 }
95
96 public void testAllowsDifferentTypeToBeSubstitutedInList() {
97 xstream.alias("original-class", Original.class);
98 xstream.alias("replaced-class", Replaced.class);
99
100 List in = new ArrayList();
101 in.add(new Original("hello world"));
102
103 String expectedXml = ""
104 + "<list>\n"
105 + " <original-class resolves-to=\"replaced-class\">\n"
106 + " <replacedValue>HELLO WORLD</replacedValue>\n"
107 + " </original-class>\n"
108 + "</list>";
109
110 assertBothWays(in, expectedXml);
111 }
112
113 public static class Container extends StandardObject {
114 Original original;
115 }
116
117 public void testAllowsDifferentTypeToBeSubstitutedAsMember() {
118 xstream.alias("container", Container.class);
119 xstream.alias("original-class", Original.class);
120 xstream.alias("replaced-class", Replaced.class);
121
122 Container in = new Container();
123 in.original = new Original("hello world");
124
125 String expectedXml = ""
126 + "<container>\n"
127 + " <original resolves-to=\"replaced-class\">\n"
128 + " <replacedValue>HELLO WORLD</replacedValue>\n"
129 + " </original>\n"
130 + "</container>";
131
132 assertBothWays(in, expectedXml);
133 }
134
135 public static class ExternalizableContainer extends StandardObject implements Externalizable {
136 Original original;
137
138 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
139 original = (Original)in.readObject();
140 }
141
142 public void writeExternal(ObjectOutput out) throws IOException {
143 out.writeObject(original);
144 }
145 }
146
147 public void testAllowsDifferentTypeToBeSubstitutedInExternalizable() {
148 xstream.alias("container", ExternalizableContainer.class);
149 xstream.alias("original-class", Original.class);
150 xstream.alias("replaced-class", Replaced.class);
151
152 ExternalizableContainer in = new ExternalizableContainer();
153 in.original = new Original("hello world");
154
155 String expectedXml = ""
156 + "<container>\n"
157 + " <original-class resolves-to=\"replaced-class\">\n"
158 + " <replacedValue>HELLO WORLD</replacedValue>\n"
159 + " </original-class>\n"
160 + "</container>";
161
162 assertBothWays(in, expectedXml);
163 }
164
165 public void testAllowsDifferentTypeToBeSubstitutedWithNonExistingClass() {
166 xstream.alias("original-class", Original.class);
167 xstream.alias("replaced-class", Replaced.class);
168
169 Original in = new Original("hello world");
170
171 String xml = ""
172 + "<original-class resolves-to=\"replaced-class\" class=\"not.Existing\">\n"
173 + " <replacedValue>HELLO WORLD</replacedValue>\n"
174 + "</original-class>";
175
176 assertEquals(in, xstream.fromXML(xml));
177 }
178
179 public void testAllowsDifferentTypeToBeSubstitutedWithNonExistingClassInList() {
180 xstream.alias("original-class", Original.class);
181 xstream.alias("replaced-class", Replaced.class);
182
183 List in = new ArrayList();
184 in.add(new Original("hello world"));
185
186 String xml = ""
187 + "<list>\n"
188 + " <original-class resolves-to=\"replaced-class\" class=\"not.Existing\">\n"
189 + " <replacedValue>HELLO WORLD</replacedValue>\n"
190 + " </original-class>\n"
191 + "</list>";
192
193 assertEquals(in, xstream.fromXML(xml));
194 }
195
196 public void testAllowsDifferentTypeToBeSubstitutedWithNonExistingClassAsMember() {
197 xstream.alias("container", Container.class);
198 xstream.alias("original-class", Original.class);
199 xstream.alias("replaced-class", Replaced.class);
200
201 Container in = new Container();
202 in.original = new Original("hello world");
203
204 String xml = ""
205 + "<container>\n"
206 + " <original resolves-to=\"replaced-class\" class=\"not.Existing\">\n"
207 + " <replacedValue>HELLO WORLD</replacedValue>\n"
208 + " </original>\n"
209 + "</container>";
210
211 assertEquals(in, xstream.fromXML(xml));
212 }
213
214 public void testAllowsDifferentTypeToBeSubstitutedWithNonExistingClassInExternalizable() {
215 xstream.alias("container", ExternalizableContainer.class);
216 xstream.alias("original-class", Original.class);
217 xstream.alias("replaced-class", Replaced.class);
218
219 ExternalizableContainer in = new ExternalizableContainer();
220 in.original = new Original("hello world");
221
222 String xml = ""
223 + "<container>\n"
224 + " <original-class resolves-to=\"replaced-class\" class=\"not.Existing\">\n"
225 + " <replacedValue>HELLO WORLD</replacedValue>\n"
226 + " </original-class>\n"
227 + "</container>";
228
229 assertEquals(in, xstream.fromXML(xml));
230 }
231
232 public static class OriginalSerializable extends StandardObject {
233 String originalValue;
234
235 public OriginalSerializable() {
236 }
237
238 public OriginalSerializable(String originalValue) {
239 this.originalValue = originalValue;
240 }
241
242 private Object writeReplace() {
243 return new ReplacedSerializable(originalValue.toUpperCase());
244 }
245
246 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
247 in.defaultReadObject();
248 }
249 }
250
251 public static class ReplacedSerializable extends StandardObject {
252 String replacedValue;
253
254 public ReplacedSerializable() {
255 }
256
257 public ReplacedSerializable(String replacedValue) {
258 this.replacedValue = replacedValue;
259 }
260
261 private Object readResolve() {
262 return new OriginalSerializable(replacedValue.toLowerCase());
263 }
264
265 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
266 in.defaultReadObject();
267 }
268 }
269
270 public void testAllowsDifferentTypeToBeSubstitutedForCustomSerializableObjects() {
271 xstream.alias("original-serializable-class", OriginalSerializable.class);
272 xstream.alias("replaced-serializable-class", ReplacedSerializable.class);
273
274 OriginalSerializable in = new OriginalSerializable("hello world");
275
276 String expectedXml = ""
277 + "<original-serializable-class resolves-to=\"replaced-serializable-class\" serialization=\"custom\">\n"
278 + " <replaced-serializable-class>\n"
279 + " <default>\n"
280 + " <replacedValue>HELLO WORLD</replacedValue>\n"
281 + " </default>\n"
282 + " </replaced-serializable-class>\n"
283 + "</original-serializable-class>";
284
285 assertBothWays(in, expectedXml);
286 }
287
288 public static class OriginalExternalizable extends StandardObject implements Externalizable {
289 String originalValue;
290
291 public OriginalExternalizable() {
292 }
293
294 public OriginalExternalizable(String originalValue) {
295 this.originalValue = originalValue;
296 }
297
298 private Object writeReplace() {
299 return new ReplacedExternalizable(originalValue.toUpperCase());
300 }
301
302 public void writeExternal(ObjectOutput out) throws IOException {
303 out.writeObject(originalValue);
304 }
305
306 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
307 originalValue = (String)in.readObject();
308 }
309 }
310
311 public static class ReplacedExternalizable extends StandardObject implements Externalizable {
312 String replacedValue;
313
314 public ReplacedExternalizable() {
315 }
316
317 public ReplacedExternalizable(String replacedValue) {
318 this.replacedValue = replacedValue;
319 }
320
321 private Object readResolve() {
322 return new OriginalExternalizable(replacedValue.toLowerCase());
323 }
324
325 public void writeExternal(ObjectOutput out) throws IOException {
326 out.writeObject(StringUtils.reverse(replacedValue));
327 }
328
329 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
330 replacedValue = StringUtils.reverse((String)in.readObject());
331 }
332 }
333
334 public void testAllowsDifferentTypeToBeSubstitutedForCustomExternalizableObjects() {
335 xstream.alias("original-externalizable-class", OriginalExternalizable.class);
336 xstream.alias("replaced-externalizable-class", ReplacedExternalizable.class);
337
338 OriginalExternalizable in = new OriginalExternalizable("hello world");
339
340 String expectedXml = ""
341 + "<original-externalizable-class resolves-to=\"replaced-externalizable-class\">\n"
342 + " <string>DLROW OLLEH</string>\n"
343 + "</original-externalizable-class>";
344
345 assertBothWays(in, expectedXml);
346 }
347 }
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 22. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.io.xml.XStream11XmlFriendlyReplacer;
16 import com.thoughtworks.xstream.io.xml.XppDriver;
17
18 public class XStream11XmlFriendlyTest extends AbstractAcceptanceTest {
19
20 protected XStream createXStream() {
21 XStream xstream = new XStream(new XppDriver(new XStream11XmlFriendlyReplacer())) {
22 protected boolean useXStream11XmlFriendlyMapper() {
23 return true;
24 }
25
26 };
27 setupSecurity(xstream);
28 return xstream;
29 }
30
31 public static class WithDollarCharField extends StandardObject {
32 String $field;
33 String field$;
34 String fi$eld;
35 String fi$$eld;
36 }
37
38 public void testSupportsFieldsWithDollarChar() {
39 xstream.alias("dollar", WithDollarCharField.class);
40
41 WithDollarCharField in = new WithDollarCharField();
42 in.$field = "a";
43 in.field$ = "b";
44 in.fi$eld = "c";
45 in.fi$$eld = "d";
46
47 String expected11 = "" +
48 "<dollar>\n" +
49 " <_DOLLAR_field>a</_DOLLAR_field>\n" +
50 " <field_DOLLAR_>b</field_DOLLAR_>\n" +
51 " <fi_DOLLAR_eld>c</fi_DOLLAR_eld>\n" +
52 " <fi_DOLLAR__DOLLAR_eld>d</fi_DOLLAR__DOLLAR_eld>\n" +
53 "</dollar>";
54
55 String expected12 = "" +
56 "<dollar>\n"
57 + " <_-field>a</_-field>\n"
58 + " <field_->b</field_->\n"
59 + " <fi_-eld>c</fi_-eld>\n"
60 + " <fi_-_-eld>d</fi_-_-eld>\n"
61 + "</dollar>";
62
63 assertWithAsymmetricalXml(in, expected11, expected12);
64 }
65
66 public static class WithUnderscoreCharField extends StandardObject {
67 String _field;
68 String field_;
69 String fi_eld;
70 String fi__eld;
71 }
72
73 public void testSupportsFieldsWithUnderscoreChar() {
74 xstream.alias("underscore", WithUnderscoreCharField.class);
75
76 WithUnderscoreCharField in = new WithUnderscoreCharField();
77 in._field = "a";
78 in.field_ = "b";
79 in.fi_eld = "c";
80 in.fi__eld = "d";
81
82 String expected11 = "" +
83 "<underscore>\n" +
84 " <__field>a</__field>\n" +
85 " <field__>b</field__>\n" +
86 " <fi__eld>c</fi__eld>\n" +
87 " <fi____eld>d</fi____eld>\n" +
88 "</underscore>";
89
90 assertWithAsymmetricalXml(in, expected11, expected11);
91 }
92
93 public void testSupportsAliasWithDashChar() {
94 xstream.alias("under-score", WithUnderscoreCharField.class);
95
96 WithUnderscoreCharField in = new WithUnderscoreCharField();
97 in._field = "a";
98 in.field_ = "b";
99 in.fi_eld = "c";
100 in.fi__eld = "d";
101
102 String expected11 = "" +
103 "<under-score>\n" +
104 " <__field>a</__field>\n" +
105 " <field__>b</field__>\n" +
106 " <fi__eld>c</fi__eld>\n" +
107 " <fi____eld>d</fi____eld>\n" +
108 "</under-score>";
109
110 assertWithAsymmetricalXml(in, expected11, expected11);
111 }
112
113 public static class A_B extends StandardObject {
114 private int x;
115
116 public A_B(int x) {
117 this.x = x;
118 }
119
120 }
121
122 public void testSupportsUnderscoreInShortClassName() {
123 String expected11 = ""
124 + "<com.thoughtworks.acceptance.XStream11XmlFriendlyTest-A_B>\n"
125 + " <x>3</x>\n"
126 + "</com.thoughtworks.acceptance.XStream11XmlFriendlyTest-A_B>";
127
128 String expected12 = ""
129 + "<com.thoughtworks.acceptance.XStream11XmlFriendlyTest_-A__B>\n"
130 + " <x>3</x>\n"
131 + "</com.thoughtworks.acceptance.XStream11XmlFriendlyTest_-A__B>";
132
133 assertWithAsymmetricalXml(new A_B(3), expected11, expected12);
134 }
135
136 }
0 /*
1 * Copyright (C) 2007, 2011 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 27. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.converters.ConverterLookup;
16 import com.thoughtworks.xstream.converters.reflection.FieldDictionary;
17 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
18 import com.thoughtworks.xstream.converters.reflection.XStream12FieldKeySorter;
19 import com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy;
20 import com.thoughtworks.xstream.core.ReferenceByXPathUnmarshaller;
21 import com.thoughtworks.xstream.core.TreeUnmarshaller;
22 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
23 import com.thoughtworks.xstream.mapper.Mapper;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30
31 /**
32 * Test XStream 1.2 compatibility.
33 *
34 * @author J&ouml;rg Schaible
35 */
36 public class XStream12CompatibilityTest extends AbstractAcceptanceTest {
37
38 public static class ParentClass {
39 String name;
40 }
41
42 public static class ChildClass extends ParentClass {
43 String name;
44
45 ChildClass() {
46 this("JDK", "1.3");
47 }
48
49 ChildClass(final String parent, final String child) {
50 ((ParentClass)this).name = parent;
51 name = child;
52 }
53
54 public String toString() {
55 return ((ParentClass)this).name + "/" + name;
56 }
57 }
58
59 public void testCanDeserializeHiddenFieldsWithSameTypeWrittenWithXStream11() {
60 xstream.alias("parent", ParentClass.class);
61 xstream.alias("child", ChildClass.class);
62
63 final String in = "" +
64 "<child>\n" +
65 " <name>CHILD</name>\n" +
66 " <name defined-in=\"parent\">PARENT</name>\n" +
67 "</child>";
68
69 final ChildClass child = (ChildClass)xstream.fromXML(in);
70 assertEquals("PARENT/CHILD", child.toString());
71 }
72
73 public static class ParentA extends StandardObject {
74 private List stuff = new ArrayList();
75
76 public List getParentStuff() {
77 return stuff;
78 }
79 }
80
81 public static class ChildA extends ParentA {
82 private Map stuff = new HashMap();
83
84 public Map getChildStuff() {
85 return stuff;
86 }
87 }
88
89 public void testCanDeserializeHiddenFieldsWithDifferentTypeWrittenWithXStream11() {
90 xstream.alias("child-a", ChildA.class);
91 xstream.alias("parent-a", ParentA.class);
92 String expected = "" +
93 "<child-a>\n" +
94 " <stuff>\n" +
95 " <entry>\n" +
96 " <string>hello</string>\n" +
97 " <string>world</string>\n" +
98 " </entry>\n" +
99 " </stuff>\n" +
100 " <stuff defined-in=\"parent-a\">\n" +
101 " <string>foo</string>\n" +
102 " </stuff>\n" +
103 "</child-a>";
104
105 ChildA childA = (ChildA)xstream.fromXML(expected);
106 assertEquals("world", childA.getChildStuff().get("hello"));
107 assertEquals("foo", childA.getParentStuff().iterator().next());
108 }
109
110 public void testCanWriteInheritanceHierarchiesInOldOrder() {
111 xstream = new XStream(new PureJavaReflectionProvider(new FieldDictionary(new XStream12FieldKeySorter())));
112 OpenSourceSoftware openSourceSoftware = new OpenSourceSoftware("apache", "geronimo", "license");
113 String xml =
114 "<oss>\n" +
115 " <license>license</license>\n" +
116 " <vendor>apache</vendor>\n" +
117 " <name>geronimo</name>\n" +
118 "</oss>";
119
120 xstream.alias("oss", OpenSourceSoftware.class);
121 assertEquals(xml, xstream.toXML(openSourceSoftware));
122 }
123
124 private final class XStream12ReferenceByXPathUnmarshaller extends
125 ReferenceByXPathUnmarshaller {
126 private XStream12ReferenceByXPathUnmarshaller(
127 Object root, HierarchicalStreamReader reader, ConverterLookup converterLookup,
128 Mapper mapper) {
129 super(root, reader, converterLookup, mapper);
130 isNameEncoding = false;
131 }
132 }
133
134 public void testCanReadXmlUnfriendlyXPathReferences() {
135 xstream.setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE) {
136
137 protected TreeUnmarshaller createUnmarshallingContext(Object root,
138 HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) {
139 return new XStream12ReferenceByXPathUnmarshaller(root, reader, converterLookup, mapper);
140 }
141
142 });
143 xstream.alias("foo$bar", StringBuffer.class);
144 xstream.alias("x_y", StringBuffer.class);
145 String xml =
146 "<list>\n" +
147 " <foo_-bar>foo</foo_-bar>\n" +
148 " <foo_-bar reference=\"../foo$bar\"/>\n" +
149 " <x__y>bar</x__y>\n" +
150 " <x__y reference=\"../x_y\"/>\n" +
151 "</list>";
152
153 List list = (List)xstream.fromXML(xml);
154 assertEquals(4, list.size());
155 assertSame(list.get(0), list.get(1));
156 assertEquals("foo", list.get(0).toString());
157 assertSame(list.get(2), list.get(3));
158 assertEquals("bar", list.get(2).toString());
159 }
160 }
0 /*
1 * Copyright (C) 2011 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 04. August 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import java.util.TreeMap;
13 import java.util.TreeSet;
14
15
16 /**
17 * Test XStream 1.3 compatibility.
18 *
19 * @author J&ouml;rg Schaible
20 */
21 public class XStream13CompatibilityTest extends AbstractAcceptanceTest {
22
23 public void testCanReadOldTreeSet() {
24 final String in = ""
25 + "<tree-set>\n"
26 + " <no-comparator/>\n"
27 + " <string>one</string>\n"
28 + " <string>two</string>\n"
29 + "</tree-set>";
30 TreeSet expected = new TreeSet();
31 expected.add("two");
32 expected.add("one");
33 assertEquals(expected, xstream.fromXML(in));
34 }
35
36 public void testCanReadOldTreeMap() {
37 final String in = ""
38 + "<tree-map>\n"
39 + " <no-comparator/>\n"
40 + " <entry>\n"
41 + " <string>one</string>\n"
42 + " <int>1</int>\n"
43 + " </entry>\n"
44 + " <entry>\n"
45 + " <string>two</string>\n"
46 + " <int>2</int>\n"
47 + " </entry>\n"
48 + "</tree-map>";
49 TreeMap expected = new TreeMap();
50 expected.put("two", new Integer(2));
51 expected.put("one", new Integer(1));
52 assertEquals(expected, xstream.fromXML(in));
53 }
54 }
0 <?xml version="1.0"?>
1 <!--
2 Copyright (C) 2006, 2007, 2008, 2014 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 30. March 2006 by Joerg Schaible
10 -->
11 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
12 <xsl:template match="immutableTypes">
13 <xsl:copy>
14 <xsl:apply-templates select="java-class">
15 <xsl:sort/>
16 </xsl:apply-templates>
17 </xsl:copy>
18 </xsl:template>
19 <xsl:template match="names">
20 <xsl:copy>
21 <xsl:apply-templates select="string">
22 <xsl:sort/>
23 </xsl:apply-templates>
24 </xsl:copy>
25 </xsl:template>
26 <xsl:template match="typeToImpl|typeToName|classToName|packageToName">
27 <xsl:copy>
28 <xsl:apply-templates select="entry">
29 <xsl:sort select="java-class[1]|string[1]"/>
30 </xsl:apply-templates>
31 </xsl:copy>
32 </xsl:template>
33 <xsl:template match="@*|node()">
34 <xsl:copy>
35 <xsl:apply-templates select="@*|node()"/>
36 </xsl:copy>
37 </xsl:template>
38 </xsl:stylesheet>
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 01. April 2006 by Joerg Schaible
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.XStreamer;
16 import com.thoughtworks.xstream.converters.ConversionException;
17 import com.thoughtworks.xstream.security.TypePermission;
18
19 import javax.xml.transform.Transformer;
20 import javax.xml.transform.TransformerException;
21 import javax.xml.transform.TransformerFactory;
22 import javax.xml.transform.stream.StreamResult;
23 import javax.xml.transform.stream.StreamSource;
24
25 import java.io.ObjectStreamException;
26 import java.io.StringReader;
27 import java.io.StringWriter;
28 import java.net.URL;
29
30
31 /**
32 * @author J&ouml;rg Schaible
33 */
34 public class XStreamerTest extends AbstractAcceptanceTest {
35
36 private Transformer transformer;
37
38 protected void setUp() throws Exception {
39 super.setUp();
40
41 final TransformerFactory transformerFactory = TransformerFactory.newInstance();
42 final URL url = getClass().getResource("XStreamer.xsl");
43 transformer = transformerFactory.newTransformer(new StreamSource(url.openStream()));
44 }
45
46 final static class ImplicitXStreamContainer {
47 private XStream myXStream;
48 }
49
50 public void testDetectsSelfMarshalling() {
51 ImplicitXStreamContainer c = new ImplicitXStreamContainer();
52 c.myXStream = xstream;
53 try {
54 xstream.toXML(c);
55 fail("Thrown " + ConversionException.class.getName() + " expected");
56 } catch (final ConversionException e) {
57 assertTrue(e.getMessage().indexOf("XStream instance")>=0);
58 }
59 }
60
61 public void testCanConvertAnotherInstance() throws TransformerException {
62 XStream x = createXStream();
63 final String xml = normalizedXStreamXML(xstream.toXML(x));
64 final TypePermission[] permissions = XStreamer.getDefaultPermissions();
65 for(int i = 0; i < permissions.length; ++i)
66 xstream.addPermission(permissions[i]);
67 final XStream serialized = (XStream)xstream.fromXML(xml);
68 final String xmlSerialized = normalizedXStreamXML(xstream.toXML(serialized));
69 assertEquals(xml, xmlSerialized);
70 }
71
72 public void testCanBeUsedAfterSerialization() throws TransformerException {
73 final String xml = xstream.toXML(createXStream());
74 final TypePermission[] permissions = XStreamer.getDefaultPermissions();
75 for(int i = 0; i < permissions.length; ++i)
76 xstream.addPermission(permissions[i]);
77 xstream = (XStream)xstream.fromXML(xml);
78 testCanConvertAnotherInstance();
79 }
80
81 public void testCanSerializeSelfContained() throws ClassNotFoundException, ObjectStreamException {
82 final OpenSourceSoftware oos = new OpenSourceSoftware("Walnes", "XStream", "BSD");
83 xstream.alias("software", OpenSourceSoftware.class);
84 String xml = new XStreamer().toXML(xstream, oos);
85 assertEquals(oos, new XStreamer().fromXML(xml));
86 }
87
88 private String normalizedXStreamXML(String xml) throws TransformerException {
89 final StringWriter writer = new StringWriter();
90 transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(writer));
91 return writer.toString();
92 }
93 }
0 /*
1 * Copyright (C) 2007, 2014 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 12. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
14 import com.thoughtworks.xstream.io.xml.XppDriver;
15
16
17 public class XmlFriendlyDollarOnlyTest extends XmlFriendlyTest {
18
19 protected XStream createXStream() {
20 XStream xstream = new XStream(new XppDriver(new XmlFriendlyNameCoder("_-", "_")));
21 setupSecurity(xstream);
22 xstream.allowTypesByWildcard(new String[]{getClass().getSuperclass().getName()+"$*"});
23 return xstream;
24 }
25
26 protected Object assertBothWays(Object root, String xml) {
27 return super.assertBothWays(root, replaceAll(xml, "__", "_"));
28 }
29
30 // String.replaceAll is JDK 1.4
31 protected String replaceAll(String s, final String occurance, final String replacement) {
32 final int len = occurance.length();
33 final int inc = len - replacement.length();
34 int i = -inc;
35 final StringBuffer buff = new StringBuffer(s);
36 // StringBuffer has no indexOf in JDK 1.3
37 while((i = buff.toString().indexOf(occurance, i + inc)) >= 0) {
38 buff.replace(i, i + len, replacement);
39 }
40 return buff.toString();
41 }
42
43 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 18. April 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.core.JVM;
15
16 import java.text.DecimalFormatSymbols;
17 import java.util.Locale;
18
19
20 public class XmlFriendlyTest extends AbstractAcceptanceTest {
21
22 public static class WithDollarCharField extends StandardObject {
23 String $field;
24 String field$;
25 String fi$eld;
26 String fi$$eld;
27 }
28
29 public void testSupportsFieldsWithDollarChar() {
30 xstream.alias("dollar", WithDollarCharField.class);
31
32 WithDollarCharField in = new WithDollarCharField();
33 in.$field = "a";
34 in.field$ = "b";
35 in.fi$eld = "c";
36 in.fi$$eld = "d";
37
38 String expected = ""
39 + "<dollar>\n"
40 + " <_-field>a</_-field>\n"
41 + " <field_->b</field_->\n"
42 + " <fi_-eld>c</fi_-eld>\n"
43 + " <fi_-_-eld>d</fi_-_-eld>\n"
44 + "</dollar>";
45 assertBothWays(in, expected);
46 }
47
48 public static class WithUnderscoreCharField extends StandardObject {
49 String _field;
50 String field_;
51 String fi_eld;
52 }
53
54 public void testSupportsFieldsWithUnderscoreChar() {
55 xstream.alias("underscore", WithUnderscoreCharField.class);
56
57 WithUnderscoreCharField in = new WithUnderscoreCharField();
58 in._field = "a";
59 in.field_ = "b";
60 in.fi_eld = "c";
61
62 String expected = ""
63 + "<underscore>\n"
64 + " <__field>a</__field>\n"
65 + " <field__>b</field__>\n"
66 + " <fi__eld>c</fi__eld>\n"
67 + "</underscore>";
68 assertBothWays(in, expected);
69 }
70
71 public static class WithDoubleUnderscoreCharField extends StandardObject {
72 String __field;
73 String field__;
74 String fi__eld;
75 }
76
77 public void testSupportsFieldsWithDoubleUnderscoreChar() {
78 xstream.alias("underscore", WithDoubleUnderscoreCharField.class);
79
80 WithDoubleUnderscoreCharField in = new WithDoubleUnderscoreCharField();
81 in.__field = "a";
82 in.field__ = "b";
83 in.fi__eld = "c";
84
85 String expected = ""
86 + "<underscore>\n"
87 + " <____field>a</____field>\n"
88 + " <field____>b</field____>\n"
89 + " <fi____eld>c</fi____eld>\n"
90 + "</underscore>";
91 assertBothWays(in, expected);
92 }
93
94 public static class WithDollarAndUnderscoreCharField extends StandardObject {
95 String $_$field;
96 String field$_$;
97 String fi_$_eld;
98 String fi_$$_eld;
99 String fi$__$eld;
100 }
101
102 public void testSupportsFieldsWithDollarAndUnderScoreChar() {
103 xstream.alias("dollar", WithDollarAndUnderscoreCharField.class);
104
105 WithDollarAndUnderscoreCharField in = new WithDollarAndUnderscoreCharField();
106 in.$_$field = "a";
107 in.field$_$ = "b";
108 in.fi_$_eld = "c";
109 in.fi_$$_eld = "d";
110 in.fi$__$eld = "e";
111
112 String expected = ""
113 + "<dollar>\n"
114 + " <_-___-field>a</_-___-field>\n"
115 + " <field_-___->b</field_-___->\n"
116 + " <fi___-__eld>c</fi___-__eld>\n"
117 + " <fi___-_-__eld>d</fi___-_-__eld>\n"
118 + " <fi_-_____-eld>e</fi_-_____-eld>\n"
119 + "</dollar>";
120 assertBothWays(in, expected);
121 }
122
123 public static class WithUnusualCharacters extends StandardObject {
124 String µ_;
125 String _µ;
126 String ¢¥€£äöüß;
127 }
128
129 public void testSupportsFieldsWithUnusualChars() {
130 xstream.alias("unusual", WithUnusualCharacters.class);
131
132 WithUnusualCharacters in = new WithUnusualCharacters();
133 in.µ_ = "a";
134 in._µ = "b";
135 in.¢¥€£äöüß = "c";
136
137 String expected = ""
138 + "<unusual>\n"
139 + " <_.00b5__>a</_.00b5__>\n"
140 + " <___.00b5>b</___.00b5>\n"
141 + " <_.00a2_.00a5€_.00a3äöüß>c</_.00a2_.00a5€_.00a3äöüß>\n"
142 + "</unusual>";
143 assertBothWays(in, expected);
144 }
145
146 public static class __ {
147 public static class A_B extends StandardObject {
148 private int x;
149
150 public A_B(int x) {
151 this.x = x;
152 }
153
154 }
155 }
156
157 public void testSupportsUnderscoreInShortClassName() {
158 assertBothWays(new __.A_B(3), ""
159 + "<com.thoughtworks.acceptance.XmlFriendlyTest_-_____-A__B>\n"
160 + " <x>3</x>\n"
161 + "</com.thoughtworks.acceptance.XmlFriendlyTest_-_____-A__B>");
162 }
163
164 public void testSlashRSlashSlashSlashN() {
165 String before = "\r\\\n";
166 String xml = xstream.toXML(before);
167 assertEquals(before, xstream.fromXML(xml));
168 }
169
170 public void testCanDealWithUtfText() {
171 assertBothWays("J\u00F6rg", "<string>J\u00F6rg</string>");
172 }
173
174 public void testCanDealWithNullCharactersInText() {
175 assertBothWays("X\0Y", "<string>X&#x0;Y</string>");
176 }
177
178 public void testEscapesXmlUnfriendlyChars() {
179 assertBothWays("<", "<string>&lt;</string>");
180 assertBothWays(">", "<string>&gt;</string>");
181 assertBothWays("<>", "<string>&lt;&gt;</string>");
182 assertBothWays("<=", "<string>&lt;=</string>");
183 assertBothWays(">=", "<string>&gt;=</string>");
184 assertBothWays("&", "<string>&amp;</string>");
185 assertBothWays("'", "<string>&apos;</string>");
186 assertBothWays("\"", "<string>&quot;</string>");
187 }
188
189 public void testDecimalFormatSymbols() {
190 final String xml;
191 if (!JVM.is14()) {
192 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
193 + " <java.text.DecimalFormatSymbols>\n"
194 + " <default>\n"
195 + " <decimalSeparator>,</decimalSeparator>\n"
196 + " <digit>#</digit>\n"
197 + " <exponential>E</exponential>\n"
198 + " <groupingSeparator>.</groupingSeparator>\n"
199 + " <minusSign>-</minusSign>\n"
200 + " <monetarySeparator>,</monetarySeparator>\n"
201 + " <patternSeparator>;</patternSeparator>\n"
202 + " <perMill>\u2030</perMill>\n"
203 + " <percent>%</percent>\n"
204 + " <serialVersionOnStream>1</serialVersionOnStream>\n"
205 + " <zeroDigit>0</zeroDigit>\n"
206 + " <NaN>\ufffd</NaN>\n"
207 + " <currencySymbol>DM</currencySymbol>\n"
208 + " <infinity>\u221e</infinity>\n"
209 + " <intlCurrencySymbol>DEM</intlCurrencySymbol>\n"
210 + " </default>\n"
211 + " </java.text.DecimalFormatSymbols>\n"
212 + "</java.text.DecimalFormatSymbols>";
213 } else if (!JVM.is16()) {
214 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
215 + " <java.text.DecimalFormatSymbols>\n"
216 + " <default>\n"
217 + " <decimalSeparator>,</decimalSeparator>\n"
218 + " <digit>#</digit>\n"
219 + " <exponential>E</exponential>\n"
220 + " <groupingSeparator>.</groupingSeparator>\n"
221 + " <minusSign>-</minusSign>\n"
222 + " <monetarySeparator>,</monetarySeparator>\n"
223 + " <patternSeparator>;</patternSeparator>\n"
224 + " <perMill>\u2030</perMill>\n"
225 + " <percent>%</percent>\n"
226 + " <serialVersionOnStream>2</serialVersionOnStream>\n"
227 + " <zeroDigit>0</zeroDigit>\n"
228 + " <NaN>\ufffd</NaN>\n"
229 + " <currencySymbol>\u20ac</currencySymbol>\n"
230 + " <infinity>\u221e</infinity>\n"
231 + " <intlCurrencySymbol>EUR</intlCurrencySymbol>\n"
232 + " <locale>de_DE</locale>\n"
233 + " </default>\n"
234 + " </java.text.DecimalFormatSymbols>\n"
235 + "</java.text.DecimalFormatSymbols>";
236 } else {
237 xml = "<java.text.DecimalFormatSymbols serialization=\"custom\">\n"
238 + " <java.text.DecimalFormatSymbols>\n"
239 + " <default>\n"
240 + " <decimalSeparator>,</decimalSeparator>\n"
241 + " <digit>#</digit>\n"
242 + " <exponential>E</exponential>\n"
243 + " <groupingSeparator>.</groupingSeparator>\n"
244 + " <minusSign>-</minusSign>\n"
245 + " <monetarySeparator>,</monetarySeparator>\n"
246 + " <patternSeparator>;</patternSeparator>\n"
247 + " <perMill>\u2030</perMill>\n"
248 + " <percent>%</percent>\n"
249 + " <serialVersionOnStream>3</serialVersionOnStream>\n"
250 + " <zeroDigit>0</zeroDigit>\n"
251 + " <NaN>\ufffd</NaN>\n"
252 + " <currencySymbol>\u20ac</currencySymbol>\n"
253 + " <exponentialSeparator>E</exponentialSeparator>\n"
254 + " <infinity>\u221e</infinity>\n"
255 + " <intlCurrencySymbol>EUR</intlCurrencySymbol>\n"
256 + " <locale>de_DE</locale>\n"
257 + " </default>\n"
258 + " </java.text.DecimalFormatSymbols>\n"
259 + "</java.text.DecimalFormatSymbols>";
260 }
261 final DecimalFormatSymbols format = new DecimalFormatSymbols(Locale.GERMANY);
262 assertBothWays(format, xml);
263 }
264
265 }
0 /*
1 * Copyright (C) 2007, 2013 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 23. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.annotations.XStreamAlias;
15 import com.thoughtworks.xstream.annotations.XStreamAliasType;
16 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
17 import com.thoughtworks.xstream.annotations.XStreamConverter;
18 import com.thoughtworks.xstream.converters.ConversionException;
19 import com.thoughtworks.xstream.converters.Converter;
20 import com.thoughtworks.xstream.converters.MarshallingContext;
21 import com.thoughtworks.xstream.converters.SingleValueConverter;
22 import com.thoughtworks.xstream.converters.UnmarshallingContext;
23 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
24 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
25 import com.thoughtworks.xstream.mapper.Mapper;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32
33 /**
34 * Tests annotations defining aliases for classes or fields.
35 *
36 * @author Chung-Onn Cheong
37 * @author Mauro Talevi
38 * @author Guilherme Silveira
39 * @author J&ouml;rg Schaible
40 */
41 public class AliasTest extends AbstractAcceptanceTest {
42
43 @Override
44 protected XStream createXStream() {
45 XStream xstream = super.createXStream();
46 xstream.autodetectAnnotations(true);
47 return xstream;
48 }
49
50 public void testAnnotationForClassWithAnnotatedConverter() {
51 Map<String, Person> map = new HashMap<String, Person>();
52 map.put("first person", new Person("john doe"));
53 map.put("second person", new Person("jane doe"));
54 String xml = ""
55 + "<map>\n"
56 + " <entry>\n"
57 + " <string>second person</string>\n"
58 + " <person>jane doe</person>\n"
59 + " </entry>\n"
60 + " <entry>\n"
61 + " <string>first person</string>\n"
62 + " <person>john doe</person>\n"
63 + " </entry>\n"
64 + "</map>";
65 assertBothWaysNormalized(map, xml, "map", "entry", "string");
66 }
67
68 public void testAnnotationForFieldWithAliasCycle() {
69 Cycle cycle = new Cycle();
70 cycle.internal = cycle;
71 String xml = "" //
72 + "<cycle>\n" //
73 + " <oops reference=\"..\"/>\n" //
74 + "</cycle>";
75 assertBothWays(cycle, xml);
76 }
77
78 @XStreamAlias("cycle")
79 public static class Cycle {
80 @XStreamAlias("oops")
81 private Cycle internal;
82 }
83
84 public void testAnnotationForField() {
85 List<String> nickNames = new ArrayList<String>();
86 nickNames.add("johnny");
87 nickNames.add("jack");
88 CustomPerson person = new CustomPerson("john", "doe", 25, nickNames);
89 String expectedXml = ""
90 + "<person>\n"
91 + " <first-name>john</first-name>\n"
92 + " <last-name>doe</last-name>\n"
93 + " <age-in-years>25</age-in-years>\n"
94 + " <nick-names>\n"
95 + " <string>johnny</string>\n"
96 + " <string>jack</string>\n"
97 + " </nick-names>\n"
98 + "</person>";
99 assertBothWays(person, expectedXml);
100 }
101
102 @XStreamAlias("person")
103 public static class CustomPerson {
104 @XStreamAlias("first-name")
105 String firstName;
106 @XStreamAlias("last-name")
107 String lastName;
108 @XStreamAlias("age-in-years")
109 int ageInYears;
110 @XStreamAlias("nick-names")
111 List<String> nickNames;
112
113 public CustomPerson(
114 String firstName, String lastName, int ageInYears, List<String> nickNames) {
115 this.firstName = firstName;
116 this.lastName = lastName;
117 this.ageInYears = ageInYears;
118 this.nickNames = nickNames;
119 }
120
121 public boolean equals(Object obj) {
122 if ((obj == null) || !(obj instanceof CustomPerson)) return false;
123 return toString().equals(obj.toString());
124 }
125
126 @Override
127 public String toString() {
128 StringBuilder sb = new StringBuilder();
129 sb
130 .append("firstName:")
131 .append(firstName)
132 .append(",lastName:")
133 .append(lastName)
134 .append(",ageInYears:")
135 .append(ageInYears)
136 .append(",nickNames:")
137 .append(nickNames);
138 return sb.toString();
139 }
140
141 }
142
143 @XStreamAlias("person")
144 @XStreamConverter(PersonConverter.class)
145 public static class Person {
146 String name;
147 AddressBookInfo addressBook;
148
149 public Person(String name) {
150 this.name = name;
151 addressBook = new AddressBook();
152 }
153
154 public boolean equals(Object obj) {
155 if ((obj == null) || !(obj instanceof Person)) return false;
156 return addressBook.equals(((Person)obj).addressBook);
157 }
158
159 @Override
160 public String toString() {
161 StringBuilder sb = new StringBuilder();
162 sb.append("name:").append(name).append("addresbook:").append(addressBook);
163 return sb.toString();
164 }
165
166 }
167
168 @XStreamAlias(value = "addressbook-info", impl = AddressBook.class)
169 public interface AddressBookInfo {
170 public List<AddressInfo> getAddresses();
171
172 public void setAddresses(List<AddressInfo> address);
173 }
174
175 @XStreamAlias("addressbookAlias")
176 public static class AddressBook implements AddressBookInfo {
177
178 // @XStreamContainedType
179 private List<AddressInfo> addresses;
180
181 public AddressBook() {
182 addresses = new ArrayList<AddressInfo>();
183 addresses.add(new Address("Home Address", 111));
184 addresses.add(new Address("Office Address", 222));
185 }
186
187 public List<AddressInfo> getAddresses() {
188 return addresses;
189 }
190
191 public void setAddresses(List<AddressInfo> addresses) {
192 this.addresses = addresses;
193
194 }
195
196 public boolean equals(Object obj) {
197 if ((obj == null) || !(obj instanceof AddressBookInfo)) return false;
198 return addresses.containsAll(((AddressBookInfo)obj).getAddresses());
199 }
200
201 }
202
203 @XStreamAlias(value = "addressinfoAlias", impl = Address.class)
204 public interface AddressInfo {
205 public String addr();
206
207 public int zipcode();
208 }
209
210 @XStreamAlias(value = "addressAlias")
211 public static class Address implements AddressInfo {
212
213 private String addr;
214 private int zipcode;
215
216 public Address(String addr, int zipcode) {
217 this.addr = addr;
218 this.zipcode = zipcode;
219 }
220
221 public String addr() {
222 return addr;
223 }
224
225 public int zipcode() {
226 return zipcode;
227 }
228
229 }
230
231 public static class PersonConverter implements Converter {
232 public PersonConverter() {
233 }
234
235 public String toString(Object obj) {
236 return ((Person)obj).name;
237 }
238
239 public Object fromString(String str) {
240 return new Person(str);
241 }
242
243 public boolean canConvert(Class type) {
244 return type == Person.class;
245 }
246
247 public void marshal(Object source, HierarchicalStreamWriter writer,
248 MarshallingContext context) {
249 writer.setValue(toString(source));
250 }
251
252 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
253 return fromString(reader.getValue());
254 }
255 }
256
257 static class Dash {
258
259 @XStreamAlias("camel-case")
260 int camelCase = 5;
261 }
262
263 public void testAnnotationForFieldWithAttributeDefinitionForFieldType() {
264 xstream.alias("dash", Dash.class);
265 xstream.useAttributeFor(int.class);
266 String xml = "<dash camel-case=\"5\"/>";
267 assertBothWays(new Dash(), xml);
268 }
269
270 public static abstract class Aged {
271 @XStreamAlias("age")
272 @XStreamAsAttribute
273 private Integer id;
274
275 Aged(Integer id) {
276 this.id = id;
277 }
278 }
279
280 @XStreamAlias("thing")
281 public static class AgedThing extends Aged {
282
283 @XStreamAsAttribute
284 private String name;
285
286 AgedThing(String name, Integer id) {
287 super(id);
288 this.name = name;
289 }
290 }
291
292 public void testAnnotationIsInheritedTogetherWithAsAttribute() {
293 String xml = "<thing age=\"99\" name=\"Name\"/>";
294 assertBothWays(new AgedThing("Name", 99), xml);
295 }
296
297 @XStreamAliasType("any")
298 public static abstract class Base {
299 String type = getClass().getName();
300 }
301 public static class A extends Base {
302 }
303 public static class B extends Base {
304 }
305 public static class BB extends B {
306 }
307
308 public void testAnnotationForATypeAlias() {
309 xstream.registerConverter(new SingleValueConverter() {
310 Mapper mapper = xstream.getMapper();
311 public boolean canConvert(Class type) {
312 return Base.class.isAssignableFrom(type);
313 }
314 public String toString(Object obj) {
315 return ((Base)obj).type;
316 }
317 public Object fromString(String str) {
318 Class realClass = mapper.realClass(str);
319 try {
320 return realClass.newInstance();
321 } catch (InstantiationException e) {
322 throw new ConversionException(e);
323 } catch (IllegalAccessException e) {
324 throw new ConversionException(e);
325 }
326 }
327 });
328
329 Base[] array = new Base[]{ new A(), new B(), new BB()};
330
331 String expectedXml = ""
332 + "<any-array>\n"
333 + " <any>com.thoughtworks.acceptance.annotations.AliasTest$A</any>\n"
334 + " <any>com.thoughtworks.acceptance.annotations.AliasTest$B</any>\n"
335 + " <any>com.thoughtworks.acceptance.annotations.AliasTest$BB</any>\n"
336 + "</any-array>";
337 assertBothWays(array, expectedXml);
338 }
339 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2014 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 16. September 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance.annotations;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.annotations.XStreamAlias;
16 import com.thoughtworks.xstream.annotations.XStreamInclude;
17
18 import java.io.IOException;
19 import java.io.ObjectInputStream;
20 import java.io.StringReader;
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25 /**
26 * Tests for annotation detection.
27 *
28 * @author Chung-Onn Cheong
29 * @author Mauro Talevi
30 * @author Guilherme Silveira
31 * @author J&ouml;rg Schaible
32 */
33 public class AnnotationsTest extends AbstractAcceptanceTest {
34
35 @Override
36 protected XStream createXStream() {
37 XStream xstream = super.createXStream();
38 xstream.autodetectAnnotations(true);
39 return xstream;
40 }
41
42 @XStreamAlias("param")
43 public static class ParameterizedContainer {
44
45 private ParameterizedType<InternalType> type;
46
47 public ParameterizedContainer() {
48 type = new ParameterizedType<InternalType>(new InternalType());
49 }
50
51 }
52
53 @XStreamAlias("param")
54 public static class DoubleParameterizedContainer {
55
56 private ArrayList<ArrayList<InternalType>> list;
57
58 public DoubleParameterizedContainer() {
59 list = new ArrayList<ArrayList<InternalType>>();
60 list.add(new ArrayList<InternalType>());
61 list.get(0).add(new InternalType());
62 }
63
64 }
65
66 @XStreamAlias("second")
67 public static class InternalType {
68 @XStreamAlias("aliased")
69 private String original = "value";
70
71 @Override
72 public boolean equals(Object obj) {
73 return obj instanceof InternalType
74 ? original.equals(((InternalType)obj).original)
75 : false;
76 }
77
78 }
79
80 @XStreamAlias("typeAlias")
81 public static class ParameterizedType<T> {
82 @XStreamAlias("fieldAlias")
83 private T object;
84
85 public ParameterizedType(T object) {
86 this.object = object;
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 return obj instanceof ParameterizedType ? object
92 .equals(((ParameterizedType)obj).object) : false;
93 }
94 }
95
96 public void testAreDetectedInParameterizedTypes() {
97 String xml = ""
98 + "<param>\n"
99 + " <type>\n"
100 + " <fieldAlias class=\"second\">\n"
101 + " <aliased>value</aliased>\n"
102 + " </fieldAlias>\n"
103 + " </type>\n"
104 + "</param>";
105 assertBothWays(new ParameterizedContainer(), xml);
106 }
107
108 public void testAreDetectedInNestedParameterizedTypes() {
109 String xml = ""
110 + "<param>\n"
111 + " <list>\n"
112 + " <list>\n"
113 + " <second>\n"
114 + " <aliased>value</aliased>\n"
115 + " </second>\n"
116 + " </list>\n"
117 + " </list>\n"
118 + "</param>";
119 assertBothWays(new DoubleParameterizedContainer(), xml);
120 }
121
122 public void testAreDetectedInArrays() {
123 InternalType[] internalTypes = new InternalType[]{
124 new InternalType(), new InternalType()};
125 String xml = ""
126 + "<second-array>\n"
127 + " <second>\n"
128 + " <aliased>value</aliased>\n"
129 + " </second>\n"
130 + " <second>\n"
131 + " <aliased>value</aliased>\n"
132 + " </second>\n"
133 + "</second-array>";
134 assertBothWays(internalTypes, xml);
135 }
136
137 public void testAreDetectedInParametrizedArrays() {
138 ParameterizedType<String>[] types = new ParameterizedType[]{
139 new ParameterizedType<String>("foo"), new ParameterizedType<String>("bar")};
140 String xml = ""
141 + "<typeAlias-array>\n"
142 + " <typeAlias>\n"
143 + " <fieldAlias class=\"string\">foo</fieldAlias>\n"
144 + " </typeAlias>\n"
145 + " <typeAlias>\n"
146 + " <fieldAlias class=\"string\">bar</fieldAlias>\n"
147 + " </typeAlias>\n"
148 + "</typeAlias-array>";
149 assertBothWays(types, xml);
150 }
151
152 public void testAreDetectedInJDKCollection() {
153 List<InternalType> list = new ArrayList<InternalType>();
154 list.add(new InternalType());
155 String xml = ""
156 + "<list>\n"
157 + " <second>\n"
158 + " <aliased>value</aliased>\n"
159 + " </second>\n"
160 + "</list>";
161 assertBothWays(list, xml);
162 }
163
164 public void testForClassIsDetectedAtDeserialization() {
165 // must preprocess annotations here
166 xstream.processAnnotations(InternalType.class);
167 InternalType internalType = new InternalType();
168 String xml = "" //
169 + "<second>\n" //
170 + " <aliased>value</aliased>\n" //
171 + "</second>";
172 assertEquals(internalType, xstream.fromXML(xml));
173 }
174
175 public void testForClassInObjectStreamIsDetectedAtDeserialization() throws IOException, ClassNotFoundException {
176 // must preprocess annotations here
177 xstream.processAnnotations(InternalType.class);
178 xstream.ignoreUnknownElements();
179 InternalType internalType = new InternalType();
180 String xml = ""
181 + "<root>\n"
182 + " <second>\n"
183 + " <aliased>value</aliased>\n"
184 + " <none>1</none>\n"
185 + " </second>\n"
186 + "</root>";
187 ObjectInputStream in = xstream.createObjectInputStream(new StringReader(xml));
188 assertEquals(internalType, in.readObject());
189 in.close();
190 }
191
192 @XStreamInclude({InternalType.class})
193 interface Include {
194 }
195
196 public void testCanBeIncluded() {
197 // must preprocess annotations from marker interface with inclusion
198 xstream.processAnnotations(Include.class);
199 InternalType internalType = new InternalType();
200 String xml = "" //
201 + "<second>\n" //
202 + " <aliased>value</aliased>\n" //
203 + "</second>";
204 assertEquals(internalType, xstream.fromXML(xml));
205 }
206 }
0 /*
1 * Copyright (C) 2007, 2014 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 23. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import java.io.Serializable;
13
14 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.annotations.XStreamAlias;
17 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
18 import com.thoughtworks.xstream.annotations.XStreamConverter;
19 import com.thoughtworks.xstream.converters.extended.ToStringConverter;
20
21
22 /**
23 * Tests annotations defining fields to be rendered as attributes.
24 *
25 * @author Chung-Onn Cheong
26 * @author Mauro Talevi
27 * @author Guilherme Silveira
28 * @author J&ouml;rg Schaible
29 */
30 public class AttributesTest extends AbstractAcceptanceTest {
31
32 @Override
33 protected XStream createXStream() {
34 XStream xstream = super.createXStream();
35 xstream.autodetectAnnotations(true);
36 return xstream;
37 }
38
39 @XStreamAlias("annotated")
40 public static class AnnotatedAttribute {
41 @XStreamAsAttribute
42 private String myField;
43 }
44
45 public void testAnnotation() {
46 AnnotatedAttribute value = new AnnotatedAttribute();
47 value.myField = "hello";
48 String expected = "<annotated myField=\"hello\"/>";
49 assertBothWays(value, expected);
50 }
51
52 @XStreamAlias("annotated")
53 public static class AnnotatedAliasedAttribute {
54 @XStreamAsAttribute
55 @XStreamAlias("field")
56 private String myField;
57 }
58
59 public void testAnnotationInCombinationWithAlias() {
60 AnnotatedAliasedAttribute value = new AnnotatedAliasedAttribute();
61 value.myField = "hello";
62 String expected = "<annotated field=\"hello\"/>";
63 assertBothWays(value, expected);
64 }
65
66 @XStreamAlias("annotated")
67 public static class AnnotatedAttributeParameterized<T> implements Serializable {
68 @XStreamAsAttribute
69 private String myField;
70 }
71
72 public void testAnnotationInParameterizedClass() {
73 AnnotatedAttributeParameterized<String> value = new AnnotatedAttributeParameterized<String>();
74 value.myField = "hello";
75 String expected = "<annotated myField=\"hello\"/>";
76 assertBothWays(value, expected);
77 }
78
79 @XStreamAlias("annotated")
80 public static class AnnotatedGenericAttributeParameterized<T> implements Serializable {
81 @XStreamAsAttribute
82 private T myField;
83 }
84
85 public void testAnnotationAtGenericTypeInParameterizedClass() {
86 AnnotatedGenericAttributeParameterized<String> value = new AnnotatedGenericAttributeParameterized<String>();
87 value.myField = "hello";
88 String expected = ""
89 + "<annotated>\n"
90 + " <myField class=\"string\">hello</myField>\n"
91 + "</annotated>";
92 assertBothWays(value, expected);
93 }
94
95 @XStreamAlias("annotated")
96 public static class AnnotatedGenericAttributeBounded<T extends Serializable> implements Serializable {
97 @XStreamAsAttribute
98 private T myField;
99 }
100
101 public void testAnnotationAtGenericTypeInBoundedClass() {
102 AnnotatedGenericAttributeBounded<String> value = new AnnotatedGenericAttributeBounded<String>();
103 value.myField = "hello";
104 String expected = ""
105 + "<annotated>\n"
106 + " <myField class=\"string\">hello</myField>\n"
107 + "</annotated>";
108 assertBothWays(value, expected);
109 }
110
111 @XStreamAlias("annotated")
112 public static class AnnotatedGenericAttributeAndConverterParameterized<T> implements Serializable {
113 @XStreamAsAttribute
114 @XStreamConverter(value=ToStringConverter.class, useImplicitType=false, types={String.class})
115 private T myField;
116 }
117
118 public void testAnnotationAtGenericTypeWithLocalConverterInParameterizedClass() {
119 AnnotatedGenericAttributeAndConverterParameterized<String> value = new AnnotatedGenericAttributeAndConverterParameterized<String>();
120 value.myField = "hello";
121 String expected = "<annotated myField=\"hello\"/>";
122 assertBothWays(value, expected);
123 }
124 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 02. March 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance.annotations;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
16 import com.thoughtworks.xstream.annotations.XStreamConverter;
17 import com.thoughtworks.xstream.converters.Converter;
18 import com.thoughtworks.xstream.converters.MarshallingContext;
19 import com.thoughtworks.xstream.converters.SingleValueConverter;
20 import com.thoughtworks.xstream.converters.UnmarshallingContext;
21 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
22 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
23
24
25 /**
26 * Tests for using annotations to override field converters
27 *
28 * @author Guilherme Silveira
29 * @author Mauro Talevi
30 * @author J&ouml;rg Schaible
31 */
32 public class FieldConverterTest extends AbstractAcceptanceTest {
33
34 @Override
35 protected XStream createXStream() {
36 XStream xstream = super.createXStream();
37 xstream.autodetectAnnotations(true);
38 return xstream;
39 }
40
41 protected void setUp() throws Exception {
42 super.setUp();
43 xstream.alias("annotatedTask", TaskWithAnnotations.class);
44 xstream.alias("derivedTask", DerivedTask.class);
45 xstream.alias("taskContainer", TaskContainer.class);
46 }
47
48 public void testAnnotationForFieldsOfSameType() {
49 final TaskWithAnnotations task = new TaskWithAnnotations("Tom", "Dick", "Harry");
50 final String xml = ""
51 + "<annotatedTask name2=\"_Dick_\">\n"
52 + " <name1 str=\"Tom\"/>\n"
53 + " <name3>Harry</name3>\n"
54 + "</annotatedTask>";
55 assertBothWays(task, xml);
56 }
57
58 public void testAnnotationForHiddenFields() {
59 final DerivedTask task = new DerivedTask("Tom", "Dick", "Harry");
60 final String xml = ""
61 + "<derivedTask name2=\"_Dick_\">\n"
62 + " <name1 defined-in=\"annotatedTask\" str=\"Tom\"/>\n"
63 + " <name3 defined-in=\"annotatedTask\">Harry</name3>\n"
64 + " <name1>Harry</name1>\n"
65 + " <name3 str=\"Tom\"/>\n"
66 + "</derivedTask>";
67 assertBothWays(task, xml);
68 }
69
70 public void testIsFoundInReferencedTypes() {
71 final TaskContainer taskContainer = new TaskContainer();
72 final String xml = ""
73 + "<taskContainer>\n"
74 + " <task name2=\"_Dick_\">\n"
75 + " <name1 defined-in=\"annotatedTask\" str=\"Tom\"/>\n"
76 + " <name3 defined-in=\"annotatedTask\">Harry</name3>\n"
77 + " <name1>Harry</name1>\n"
78 + " <name3 str=\"Tom\"/>\n"
79 + " </task>\n"
80 + "</taskContainer>";
81 assertEquals(taskContainer, xstream.fromXML(xml));
82 }
83
84 public static class TaskWithAnnotations {
85
86 @XStreamConverter(FirstConverter.class)
87 private final String name1;
88
89 @XStreamConverter(SecondaryConverter.class)
90 @XStreamAsAttribute
91 private final String name2;
92 private final String name3;
93
94 public TaskWithAnnotations(final String name1, final String name2, final String name3) {
95 this.name1 = name1;
96 this.name2 = name2;
97 this.name3 = name3;
98 }
99
100 @Override
101 public boolean equals(final Object obj) {
102 return obj != null
103 && TaskWithAnnotations.class.isAssignableFrom(obj.getClass())
104 && ((TaskWithAnnotations)obj).name1.equals(name1)
105 && ((TaskWithAnnotations)obj).name2.equals(name2)
106 && ((TaskWithAnnotations)obj).name3.equals(name3);
107 }
108 }
109
110 public static class DerivedTask extends TaskWithAnnotations {
111 private final String name1;
112
113 @XStreamConverter(FirstConverter.class)
114 private final String name3;
115
116 public DerivedTask(final String name1, final String name2, final String name3) {
117 super(name1, name2, name3);
118 this.name1 = name3;
119 this.name3 = name1;
120 }
121
122 @Override
123 public boolean equals(final Object obj) {
124 return obj != null
125 && DerivedTask.class.isAssignableFrom(obj.getClass())
126 && ((DerivedTask)obj).name1.equals(name1)
127 && ((DerivedTask)obj).name3.equals(name3)
128 && super.equals(obj);
129 }
130 }
131
132 public static class TaskContainer {
133 private final DerivedTask task = new DerivedTask("Tom", "Dick", "Harry");
134
135 @Override
136 public boolean equals(final Object obj) {
137 return obj != null
138 && TaskContainer.class.equals(obj.getClass())
139 && task.equals(((TaskContainer)obj).task);
140 }
141 }
142
143 public static class FirstConverter implements Converter {
144
145 public void marshal(final Object source, final HierarchicalStreamWriter writer,
146 final MarshallingContext context) {
147 final String str = source.toString();
148 writer.addAttribute("str", str);
149 }
150
151 public Object unmarshal(final HierarchicalStreamReader reader,
152 final UnmarshallingContext context) {
153 final String str = reader.getAttribute("str");
154 return str;
155 }
156
157 public boolean canConvert(final Class type) {
158 return type.equals(String.class);
159 }
160 }
161
162 public static class SecondaryConverter implements SingleValueConverter {
163
164 public boolean canConvert(final Class type) {
165 return type.equals(String.class);
166 }
167
168 public Object fromString(String value) {
169 return value.substring(1, value.length() - 1);
170 }
171
172 public String toString(Object source) {
173 return "_" + source.toString() + "_";
174 }
175 }
176
177 public static class CustomConverter implements Converter {
178
179 private static int total = 0;
180
181 public CustomConverter() {
182 total++ ;
183 }
184
185 public void marshal(Object source, HierarchicalStreamWriter writer,
186 MarshallingContext context) {
187 }
188
189 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
190 return null;
191 }
192
193 public boolean canConvert(Class type) {
194 return type.equals(Double.class);
195 }
196
197 }
198
199 public static class Account {
200 @XStreamConverter(CustomConverter.class)
201 private Double value;
202
203 public Account() {
204 this.value = Math.random();
205 }
206 }
207
208 public static class Client {
209 @XStreamConverter(CustomConverter.class)
210 private Double value;
211
212 public Client() {
213 this.value = Math.random();
214 }
215 }
216
217 public void testAreCachedPerField() {
218 int before = CustomConverter.total;
219 toXML(new Account());
220 int after = CustomConverter.total;
221 assertEquals(before + 1, after);
222 }
223
224 public void testAreCachedPerFieldInDifferentContexts() {
225 int before = CustomConverter.total;
226 toXML(new Account());
227 toXML(new Client());
228 int after = CustomConverter.total;
229 assertEquals(before + 1, after);
230 }
231
232 }
0 /*
1 * Copyright (C) 2011 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 30. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.annotations.XStreamAlias;
15 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
16 import com.thoughtworks.xstream.annotations.XStreamImplicit;
17
18
19 /**
20 * Test for annotations mapping implicit arrays.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class ImplicitArrayTest extends AbstractAcceptanceTest {
25
26 @Override
27 protected XStream createXStream() {
28 XStream xstream = super.createXStream();
29 xstream.autodetectAnnotations(true);
30 return xstream;
31 }
32
33 public void testAnnotation() {
34 String expected = ""
35 + "<root>\n"
36 + " <string>one</string>\n"
37 + " <string>two</string>\n"
38 + "</root>";
39 ImplicitRootOne implicitRoot = new ImplicitRootOne();
40 implicitRoot.values = new String[]{
41 "one", "two"
42 };
43 assertBothWays(implicitRoot, expected);
44 }
45
46 public void testAnnotationWithItemFieldName() {
47 String expected = ""
48 + "<root>\n"
49 + " <value>one</value>\n"
50 + " <value>two</value>\n"
51 + "</root>";
52 ImplicitRootTwo implicitRoot = new ImplicitRootTwo();
53 implicitRoot.values = new String[]{
54 "one", "two"
55 };
56 assertBothWays(implicitRoot, expected);
57 }
58
59 @XStreamAlias("root")
60 public static class ImplicitRootOne {
61 @XStreamImplicit()
62 String[] values;
63 }
64
65 @XStreamAlias("root")
66 public static class ImplicitRootTwo {
67 @XStreamImplicit(itemFieldName = "value")
68 String[] values;
69 }
70
71 @XStreamAlias("component")
72 public static class ParameterizedComponentType {
73 @XStreamImplicit(itemFieldName = "line")
74 private Point[][] signatureLines;
75 }
76
77 @XStreamAlias("point")
78 public static class Point {
79 @XStreamAsAttribute
80 private int x;
81 @XStreamAsAttribute
82 private int y;
83
84 public Point(int x, int y) {
85 this.x = x;
86 this.y = y;
87 }
88 }
89
90 public void testAnnotationHandlesParameterizedComponentTypes() {
91 String xml = ""
92 + "<component>\n"
93 + " <line>\n"
94 + " <point x=\"33\" y=\"11\"/>\n"
95 + " </line>\n"
96 + "</component>";
97 ParameterizedComponentType root = new ParameterizedComponentType();
98 root.signatureLines = new Point[][] {
99 new Point[] { new Point(33, 11) }
100 };
101 assertBothWays(root, xml);
102 }
103
104 @XStreamAlias("point3d")
105 public static class Point3D extends Point {
106 @XStreamAsAttribute
107 private int z;
108
109 public Point3D(int x, int y, int z) {
110 super(x,y);
111 this.z = z;
112 }
113 }
114
115 @XStreamAlias("root")
116 public static class VariantArray {
117 @XStreamImplicit
118 private Point[] points;
119 }
120
121 public void testCanHandleVariantArrays()
122 {
123 VariantArray array = new VariantArray();
124 array.points = new Point[] {
125 new Point(1, 2),
126 new Point3D(3, 4, 5),
127 new Point(6, 7)
128 };
129 String xml = "" //
130 + "<root>\n" //
131 + " <point x=\"1\" y=\"2\"/>\n"
132 + " <point3d x=\"3\" y=\"4\" z=\"5\"/>\n"
133 + " <point x=\"6\" y=\"7\"/>\n"
134 + "</root>";
135 assertBothWays(array, xml);
136 }
137
138 @XStreamAlias("primitives")
139 public static class PrimitiveArrays {
140 @XStreamImplicit()
141 private char[] chars;
142 }
143
144 public void testWorksForTypesThatArePrimitiveArrays() {
145 PrimitiveArrays type = new PrimitiveArrays();
146 type.chars = new char[]{'f', 'o', 'o'};
147 String xml = "" //
148 + "<primitives>\n" //
149 + " <char>f</char>\n" //
150 + " <char>o</char>\n" //
151 + " <char>o</char>\n" //
152 + "</primitives>";
153 assertBothWays(type, xml);
154 }
155 }
0 /*
1 * Copyright (C) 2006, 2007 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 01. December 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.InitializationException;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.annotations.XStreamAlias;
16 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
17 import com.thoughtworks.xstream.annotations.XStreamImplicit;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23
24 /**
25 * Test for annotations mapping implicit collections.
26 *
27 * @author Lucio Benfante
28 * @author J&ouml;rg Schaible
29 */
30 public class ImplicitCollectionTest extends AbstractAcceptanceTest {
31
32 @Override
33 protected XStream createXStream() {
34 XStream xstream = super.createXStream();
35 xstream.autodetectAnnotations(true);
36 return xstream;
37 }
38
39 public void testAnnotation() {
40 String expected = ""
41 + "<root>\n"
42 + " <string>one</string>\n"
43 + " <string>two</string>\n"
44 + "</root>";
45 ImplicitRootOne implicitRoot = new ImplicitRootOne();
46 implicitRoot.getValues().add("one");
47 implicitRoot.getValues().add("two");
48 assertBothWays(implicitRoot, expected);
49 }
50
51 public void testAnnotationWithItemFieldName() {
52 String expected = ""
53 + "<root>\n"
54 + " <value>one</value>\n"
55 + " <value>two</value>\n"
56 + "</root>";
57 ImplicitRootTwo implicitRoot = new ImplicitRootTwo();
58 implicitRoot.getValues().add("one");
59 implicitRoot.getValues().add("two");
60 assertBothWays(implicitRoot, expected);
61 }
62
63 public void testAnnotationFailsForInvalidFieldType() {
64 try {
65 xstream.processAnnotations(InvalidImplicitRoot.class);
66 fail("Thrown " + InitializationException.class.getName() + " expected");
67 } catch (final InitializationException e) {
68 assertTrue(e.getMessage().indexOf("\"value\"") > 0);
69 }
70 }
71
72 @XStreamAlias("root")
73 public static class ImplicitRootOne {
74 @XStreamImplicit()
75 private List<String> values = new ArrayList<String>();
76
77 public List<String> getValues() {
78 return values;
79 }
80
81 public void setValues(List<String> values) {
82 this.values = values;
83 }
84 }
85
86 @XStreamAlias("root")
87 public static class ImplicitRootTwo {
88 @XStreamImplicit(itemFieldName = "value")
89 private List<String> values = new ArrayList<String>();
90
91 public List<String> getValues() {
92 return values;
93 }
94
95 public void setValues(List<String> values) {
96 this.values = values;
97 }
98 }
99
100 @XStreamAlias("root")
101 public static class InvalidImplicitRoot {
102 @XStreamImplicit(itemFieldName = "outch")
103 private String value;
104
105 public String getValue() {
106 return value;
107 }
108
109 public void setValue(String value) {
110 this.value = value;
111 }
112 }
113
114 @XStreamAlias("implicit")
115 public static class ImplicitParameterizedType {
116 @XStreamImplicit(itemFieldName = "line")
117 private ArrayList<ArrayList<Point>> signatureLines;
118 }
119
120 @XStreamAlias("point")
121 public static class Point {
122 @XStreamAsAttribute
123 private int x;
124 @XStreamAsAttribute
125 private int y;
126
127 public Point(int x, int y) {
128 this.x = x;
129 this.y = y;
130 }
131 }
132
133 public void testAnnotationHandlesParameterizedTypes() {
134 String xml = ""
135 + "<implicit>\n"
136 + " <line>\n"
137 + " <point x=\"33\" y=\"11\"/>\n"
138 + " </line>\n"
139 + "</implicit>";
140 ImplicitParameterizedType root = new ImplicitParameterizedType();
141 root.signatureLines = new ArrayList<ArrayList<Point>>();
142 root.signatureLines.add(new ArrayList<Point>());
143 root.signatureLines.get(0).add(new Point(33, 11));
144 assertBothWays(root, xml);
145 }
146
147 @XStreamAlias("type")
148 public static class ParametrizedTypeIsInterface {
149 @XStreamImplicit()
150 private ArrayList<Map> list = new ArrayList<Map>();
151 }
152
153 public void testWorksForTypesThatAreInterfaces() {
154 ParametrizedTypeIsInterface type = new ParametrizedTypeIsInterface();
155 type.list = new ArrayList<Map>();
156 type.list.add(new HashMap());
157 String xml = "" //
158 + "<type>\n" //
159 + " <map/>\n" //
160 + "</type>";
161 assertBothWays(type, xml);
162 }
163
164 @XStreamAlias("untyped")
165 private static class Untyped {
166 @XStreamImplicit
167 private List list = new ArrayList();
168
169 public Untyped() {
170 list.add("1");
171 }
172 }
173
174 public void testCanHandleUntypedCollections() {
175 Untyped untyped = new Untyped();
176 String xml = "" //
177 + "<untyped>\n" //
178 + " <string>1</string>\n" //
179 + "</untyped>";
180 assertBothWays(untyped, xml);
181 }
182 }
0 /*
1 * Copyright (C) 2011 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 05. August 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.annotations.XStreamAlias;
16 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
17 import com.thoughtworks.xstream.annotations.XStreamImplicit;
18
19 import java.util.HashMap;
20 import java.util.LinkedHashMap;
21 import java.util.Map;
22
23
24 /**
25 * Test for annotations mapping implicit maps.
26 *
27 * @author J&ouml;rg Schaible
28 */
29 public class ImplicitMapTest extends AbstractAcceptanceTest {
30
31 @Override
32 protected XStream createXStream() {
33 XStream xstream = super.createXStream();
34 xstream.autodetectAnnotations(true);
35 xstream.addDefaultImplementation(LinkedHashMap.class, Map.class);
36 return xstream;
37 }
38
39 public void testAnnotation() {
40 String expected = ""
41 + "<root>\n"
42 + " <software>\n"
43 + " <vendor>Microsoft</vendor>\n"
44 + " <name>Windows</name>\n"
45 + " </software>\n"
46 + " <software>\n"
47 + " <vendor>Red Hat</vendor>\n"
48 + " <name>Linux</name>\n"
49 + " </software>\n"
50 + "</root>";
51 ImplicitRootOne implicitRoot = new ImplicitRootOne();
52 implicitRoot.getValues().put("Windows", new Software("Microsoft", "Windows"));
53 implicitRoot.getValues().put("Linux", new Software("Red Hat", "Linux"));
54 assertBothWays(implicitRoot, expected);
55 }
56
57 public void testAnnotationWithItemFieldName() {
58 String expected = ""
59 + "<root>\n"
60 + " <value>\n"
61 + " <vendor>Microsoft</vendor>\n"
62 + " <name>Windows</name>\n"
63 + " </value>\n"
64 + " <value>\n"
65 + " <vendor>Red Hat</vendor>\n"
66 + " <name>Linux</name>\n"
67 + " </value>\n"
68 + "</root>";
69 ImplicitRootTwo implicitRoot = new ImplicitRootTwo();
70 implicitRoot.getValues().put("Windows", new Software("Microsoft", "Windows"));
71 implicitRoot.getValues().put("Linux", new Software("Red Hat", "Linux"));
72 assertBothWays(implicitRoot, expected);
73 }
74
75 @XStreamAlias("root")
76 public static class ImplicitRootOne {
77 @XStreamImplicit(keyFieldName = "name")
78 private Map<String, Software> values = new LinkedHashMap<String, Software>();
79
80 public Map<String, Software> getValues() {
81 return values;
82 }
83
84 public void setValues(Map<String, Software> values) {
85 this.values = values;
86 }
87 }
88
89 @XStreamAlias("root")
90 public static class ImplicitRootTwo {
91 @XStreamImplicit(keyFieldName = "name", itemFieldName = "value")
92 private Map<String, Software> values = new LinkedHashMap<String, Software>();
93
94 public Map<String, Software> getValues() {
95 return values;
96 }
97
98 public void setValues(Map<String, Software> values) {
99 this.values = values;
100 }
101 }
102
103 @XStreamAlias("implicit")
104 public static class ImplicitParameterizedType<T> {
105 @XStreamImplicit(itemFieldName = "line", keyFieldName="id")
106 private LinkedHashMap<T,Point<T>> signatureLines;
107 }
108
109 @XStreamAlias("point")
110 public static class Point<T> {
111 @XStreamAsAttribute
112 private int x;
113 @XStreamAsAttribute
114 private int y;
115 private final T id;
116
117 public Point(T id, int x, int y) {
118 this.id = id;
119 this.x = x;
120 this.y = y;
121 }
122 }
123
124 public void testAnnotationHandlesParameterizedTypes() {
125 String xml = ""
126 + "<implicit>\n"
127 + " <line x=\"33\" y=\"11\">\n"
128 + " <id class=\"long\">42</id>\n"
129 + " </line>\n"
130 + "</implicit>";
131 ImplicitParameterizedType<Long> root = new ImplicitParameterizedType<Long>();
132 root.signatureLines = new LinkedHashMap<Long, Point<Long>>();
133 root.signatureLines.put(42L, new Point<Long>(42L, 33, 11));
134 assertBothWays(root, xml);
135 }
136
137 @XStreamAlias("type")
138 public static class ParametrizedTypeIsInterface {
139 @XStreamImplicit(keyFieldName="name")
140 private Map<String, Code> map = new LinkedHashMap<String, Code>();
141 }
142
143 public void testWorksForTypesThatAreInterfaces() {
144 ParametrizedTypeIsInterface type = new ParametrizedTypeIsInterface();
145 type.map.put("Windows", new Software("Microsoft", "Windows"));
146 String xml = "" //
147 + "<type>\n" //
148 + " <software>\n"
149 + " <vendor>Microsoft</vendor>\n"
150 + " <name>Windows</name>\n"
151 + " </software>\n"
152 + "</type>";
153 assertBothWays(type, xml);
154 }
155
156 @XStreamAlias("untyped")
157 private static class Untyped {
158 @XStreamImplicit(keyFieldName="name")
159 private Map map = new HashMap();
160
161 public Untyped() {
162 map.put("Windows", new Software("Microsoft", "Windows"));
163 }
164 }
165
166 public void testCanHandleUntypedCollections() {
167 Untyped untyped = new Untyped();
168 String xml = "" //
169 + "<untyped>\n" //
170 + " <software>\n"
171 + " <vendor>Microsoft</vendor>\n"
172 + " <name>Windows</name>\n"
173 + " </software>\n"
174 + "</untyped>";
175 assertBothWays(untyped, xml);
176 }
177
178 public interface Code {}
179
180 @XStreamAlias("software")
181 public static class Software extends StandardObject implements Code {
182
183 public String vendor;
184 public String name;
185
186 public Software() {
187 }
188
189 public Software(String vendor, String name) {
190 this.vendor = vendor;
191 this.name = name;
192 }
193 }
194 }
0 /*
1 * Copyright (C) 2007 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 23. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.annotations.XStreamAlias;
15 import com.thoughtworks.xstream.annotations.XStreamOmitField;
16
17
18 /**
19 * Tests annotation to omit a field.
20 *
21 * @author Chung-Onn Cheong
22 * @author Mauro Talevi
23 * @author Guilherme Silveira
24 * @author J&ouml;rg Schaible
25 */
26 public class OmitFieldTest extends AbstractAcceptanceTest {
27
28 @Override
29 protected XStream createXStream() {
30 XStream xstream = super.createXStream();
31 xstream.autodetectAnnotations(true);
32 return xstream;
33 }
34
35 @XStreamAlias("apartment")
36 public static class Apartment {
37
38 @XStreamOmitField
39 int size;
40
41 protected Apartment(int size) {
42 this.size = size;
43 }
44 }
45
46 public void testAnnotation() {
47 Apartment ap = new Apartment(5);
48 String expectedXml = "<apartment/>";
49 assertBothWays(ap, expectedXml);
50 }
51 }
0 /*
1 * Copyright (C) 2008, 2009, 2011, 2012, 2013 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import java.math.BigDecimal;
13 import java.util.HashMap;
14 import java.util.LinkedHashMap;
15 import java.util.Map;
16
17 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
18 import com.thoughtworks.acceptance.objects.StandardObject;
19 import com.thoughtworks.xstream.XStream;
20 import com.thoughtworks.xstream.annotations.XStreamAlias;
21 import com.thoughtworks.xstream.annotations.XStreamConverter;
22 import com.thoughtworks.xstream.annotations.XStreamConverters;
23 import com.thoughtworks.xstream.annotations.XStreamInclude;
24 import com.thoughtworks.xstream.converters.basic.BooleanConverter;
25 import com.thoughtworks.xstream.converters.collections.MapConverter;
26 import com.thoughtworks.xstream.converters.extended.NamedMapConverter;
27 import com.thoughtworks.xstream.converters.extended.ToAttributedValueConverter;
28 import com.thoughtworks.xstream.converters.extended.ToStringConverter;
29 import com.thoughtworks.xstream.converters.javabean.JavaBeanConverter;
30 import com.thoughtworks.xstream.mapper.Mapper;
31
32
33 /**
34 * Tests for using annotations for classes.
35 *
36 * @author Chung-Onn, Cheong
37 * @author J&ouml;rg Schaible
38 * @author Jason Greanya
39 */
40 public class ParametrizedConverterTest extends AbstractAcceptanceTest {
41
42 @Override
43 protected XStream createXStream() {
44 XStream xstream = super.createXStream();
45 xstream.autodetectAnnotations(true);
46 return xstream;
47 }
48
49 protected void setUp() throws Exception {
50 super.setUp();
51 xstream.alias("my-map", MyMap.class);
52 xstream.alias("decimal", Decimal.class);
53 xstream.alias("type", Type.class);
54 xstream.processAnnotations(MyMap.class);
55 xstream.processAnnotations(DerivedType.class);
56 xstream.processAnnotations(SimpleBean.class);
57 xstream.processAnnotations(ContainsMap.class);
58 }
59
60 public void testAnnotationForConvertersWithParameters() {
61 final MyMap value = new MyMap();
62 value.put("key1", "value1");
63 String expected = ""
64 + "<my-map>\n"
65 + " <entry>\n"
66 + " <string>key1</string>\n"
67 + " <string>value1</string>\n"
68 + " </entry>\n"
69 + "</my-map>";
70 assertBothWays(value, expected);
71 }
72
73 @XStreamConverters({
74 @XStreamConverter(value = MyMapConverter.class, priority = XStream.PRIORITY_NORMAL + 1, types = {MyMap.class})
75 })
76 public static class MyMap extends HashMap<String, Object> {
77 }
78
79 public static class MyMapConverter extends MapConverter {
80
81 private final Class<?> myType;
82
83 public MyMapConverter(Mapper classMapper, Class<?> myType) {
84 super(classMapper);
85 this.myType = myType;
86 }
87
88 public boolean canConvert(Class type) {
89 return type.equals(myType);
90 }
91
92 }
93
94 /**
95 * Tests a class-level XStreamConverter annotation subclassed from BigDecimal
96 */
97 public void testCanUseCurrentTypeAsParameter() {
98 final Decimal value = new Decimal("5.5");
99 String expected = "<decimal>5.5</decimal>";
100
101 assertBothWays(value, expected);
102 }
103
104 /**
105 * Tests three field-level XStreamConverter annotations for different types, which guarantees
106 * the internal converterCache on AnnotationMapper is functioning properly.
107 */
108 public void testSameConverterWithDifferentType() {
109 final Type value = new Type(new Decimal("1.5"), new Boolean(true));
110 String expected = ""
111 + "<type>\n"
112 + " <decimal>1.5</decimal>\n"
113 + " <boolean>true</boolean>\n"
114 + " <agreement>yes</agreement>\n"
115 + "</type>";
116
117 assertBothWays(value, expected);
118 }
119
120 @XStreamConverter(ToStringConverter.class)
121 public static class Decimal extends BigDecimal {
122 public Decimal(String str) {
123 super(str);
124 }
125 }
126
127 public static class Type {
128 @XStreamConverter(ToStringConverter.class)
129 private Decimal decimal = null;
130 @XStreamConverter(ToStringConverter.class)
131 @XStreamAlias("boolean")
132 private Boolean bool = null;
133 @XStreamConverter(value=BooleanConverter.class, booleans={true}, strings={"yes", "no"})
134 private Boolean agreement = null;
135
136 public Type(Decimal decimal, Boolean bool) {
137 this.decimal = decimal;
138 this.bool = bool;
139 this.agreement = bool;
140 }
141 }
142
143 public void testConverterWithSecondTypeParameter() {
144 final Type value = new DerivedType(new Decimal("1.5"), new Boolean(true), DerivedType.E.FOO);
145 String expected = "<dtype boolean='true' agreement='yes' enum='FOO'>1.5</dtype>".replace('\'', '"');
146 assertBothWays(value, expected);
147 }
148
149 @XStreamAlias("dtype")
150 @XStreamConverter(value=ToAttributedValueConverter.class, types={Type.class}, strings={"decimal"})
151 public static class DerivedType extends Type {
152 public enum E { FOO, BAR };
153 @XStreamAlias("enum")
154 private E e;
155
156 public DerivedType(Decimal decimal, Boolean bool, E e) {
157 super(decimal, bool);
158 this.e = e;
159 }
160 }
161
162 public void testAnnotatedJavaBeanConverter() {
163 final SimpleBean value = new SimpleBean();
164 value.setName("joe");
165 String expected = ""
166 + "<bean>\n"
167 + " <name>joe</name>\n"
168 + "</bean>";
169 assertBothWays(value, expected);
170 }
171
172 @XStreamAlias("bean")
173 @XStreamConverter(JavaBeanConverter.class)
174 public static class SimpleBean extends StandardObject {
175 private String myName;
176
177 public String getName() {
178 return myName;
179 }
180
181 public void setName(String name) {
182 myName = name;
183 }
184 }
185
186 public void testAnnotatedNamedMapConverter() {
187 Map<ContainsMap.E, String> map = new MyEnumMap();
188 map.put(ContainsMap.E.FOO, "foo");
189 map.put(ContainsMap.E.BAR, "bar");
190 final ContainsMap value = new ContainsMap(map);
191 String expected = (""
192 + "<container>\n"
193 + " <map class='my-enums'>\n"
194 + " <issue key='FOO'>foo</issue>\n"
195 + " <issue key='BAR'>bar</issue>\n"
196 + " </map>\n"
197 + "</container>").replace('\'', '"');
198 assertBothWays(value, expected);
199 }
200
201 @XStreamInclude({MyEnumMap.class})
202 @XStreamAlias("container")
203 public static class ContainsMap extends StandardObject {
204 public enum E {
205 FOO, BAR
206 };
207
208 @XStreamConverter(value = NamedMapConverter.class, strings = {"issue", "key", ""}, types = {
209 MyEnumMap.class, E.class, String.class}, booleans = {true, false}, useImplicitType = false)
210 private Map<E, String> map;
211
212 public ContainsMap(Map<E, String> map) {
213 this.map = map;
214 }
215 }
216
217 @XStreamAlias("my-enums")
218 public static class MyEnumMap extends LinkedHashMap<ContainsMap.E, String> {
219 }
220 }
0 /*
1 * Copyright (C) 2007 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 10. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.annotations;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.annotations.AnnotationProvider;
15 import com.thoughtworks.xstream.annotations.AnnotationReflectionConverter;
16 import com.thoughtworks.xstream.annotations.Annotations;
17
18
19 /**
20 * Tests XStream 1.2.x annotation compatibility.
21 * @author J&ouml;rg Schaible
22 */
23 public class XStream12AnnotationCompatibilityTest extends AbstractAcceptanceTest {
24
25 @Override
26 protected void setUp() throws Exception {
27 super.setUp();
28 xstream = new XStream();
29 xstream.registerConverter(
30 new AnnotationReflectionConverter(xstream.getMapper(), xstream
31 .getReflectionProvider(), new AnnotationProvider()), XStream.PRIORITY_VERY_LOW);
32 xstream.alias("annotatedTask", FieldConverterTest.TaskWithAnnotations.class);
33 }
34
35 public void testDifferentConverterCanBeAnnotatedForFieldsOfSameType() {
36 final FieldConverterTest.TaskWithAnnotations task = new FieldConverterTest.TaskWithAnnotations(
37 "Tom", "Dick", "Harry");
38 final String xml = ""
39 + "<annotatedTask>\n"
40 + " <name1 str=\"Tom\"/>\n"
41 + " <name2>_Dick_</name2>\n"
42 + " <name3>Harry</name3>\n"
43 + "</annotatedTask>";
44 assertBothWays(task, xml);
45 }
46
47 public void testImplicitCollection() {
48 String expected = ""
49 + "<root>\n"
50 + " <string>one</string>\n"
51 + " <string>two</string>\n"
52 + "</root>";
53 Annotations.configureAliases(xstream, ImplicitCollectionTest.ImplicitRootOne.class);
54 ImplicitCollectionTest.ImplicitRootOne implicitRoot = new ImplicitCollectionTest.ImplicitRootOne();
55 implicitRoot.getValues().add("one");
56 implicitRoot.getValues().add("two");
57 assertBothWays(implicitRoot, expected);
58 }
59
60 }
0 /*
1 * Copyright (C) 2007 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 30. April 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.objects;
11
12 import java.util.List;
13
14 public class Category {
15
16 String name;
17 String id;
18 List products;
19
20 public Category() {} // JDK 1.3
21
22 public Category(String name, String id) {
23 super();
24 this.name = name;
25 this.id = id;
26 }
27
28 public String getId() {
29 return id;
30 }
31
32 public void setId(String id) {
33 this.id = id;
34 }
35
36 public String getName() {
37 return name;
38 }
39
40 public void setName(String name) {
41 this.name = name;
42 }
43
44 public List getProducts() {
45 return products;
46 }
47
48 public void setProducts(List products) {
49 this.products = products;
50 }
51
52 public String toString() {
53 String ret = "[" + name + ", " + id;
54 if (products != null) {
55 ret += "\n{";
56 for (java.util.Iterator it = products.iterator(); it.hasNext();) {
57 Product product = (Product) it.next();
58 ret += product + "\n";
59 }
60 ret += "}";
61 }
62 ret += "]";
63 return ret;
64 }
65
66 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13
14 public class Hardware extends StandardObject {
15 public String arch;
16 public String name;
17
18 public Hardware() {
19 }
20
21 public Hardware(String arch, String name) {
22 this.arch = arch;
23 this.name = name;
24 }
25
26 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13 public class OpenSourceSoftware extends Software {
14
15 private String license;
16
17 public OpenSourceSoftware() {
18 }
19
20 public OpenSourceSoftware(String vendor, String name, String license) {
21 super(vendor, name);
22 this.license = license;
23 }
24
25 }
0 /*
1 * Copyright (C) 2008 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 22. October 2008 by Joerg Schaible
9 */
10
11 /**
12 * @author Joe Walnes
13 */
14 package com.thoughtworks.acceptance.objects;
15
16
17 public class Original extends StandardObject {
18 String originalValue;
19
20 public Original() {
21 }
22
23 public Original(String originalValue) {
24 this.originalValue = originalValue;
25 }
26
27 private Object writeReplace() {
28 return new Replaced(originalValue.toUpperCase());
29 }
30 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011 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 05. July 2011 by Joerg Schaible, factored out of ExternalizableTest.
10 */
11 package com.thoughtworks.acceptance.objects;
12
13
14 public class OwnerOfExternalizable extends StandardObject {
15 public SomethingExternalizable target;
16 }
0 /*
1 * Copyright (C) 2007, 2013 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 30. April 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.objects;
11
12 import java.util.ArrayList;
13
14
15 public class Product {
16
17 String name;
18 String id;
19 double price;
20 ArrayList tags;
21
22 public Product(String name, String id, double price) {
23 super();
24 this.name = name;
25 this.id = id;
26 this.price = price;
27 }
28
29 public String getId() {
30 return id;
31 }
32
33 public void setId(String id) {
34 this.id = id;
35 }
36
37 public String getName() {
38 return name;
39 }
40
41 public void setName(String name) {
42 this.name = name;
43 }
44
45 public double getPrice() {
46 return price;
47 }
48
49 public void setPrice(double price) {
50 this.price = price;
51 }
52
53 public ArrayList getTags() {
54 return tags;
55 }
56
57 public void setTags(ArrayList tags) {
58 this.tags = tags;
59 }
60
61 public int hashCode() {
62 final int prime = 31;
63 int result = 1;
64 result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
65 result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
66 long temp;
67 temp = Double.doubleToLongBits(this.price);
68 result = prime * result + (int)(temp ^ (temp >>> 32));
69 result = prime * result + ((this.tags == null) ? 0 : this.tags.hashCode());
70 return result;
71 }
72
73 public boolean equals(Object obj) {
74 if (this == obj) return true;
75 if (obj == null) return false;
76 if (getClass() != obj.getClass()) return false;
77 Product other = (Product)obj;
78 if (this.id == null) {
79 if (other.id != null) return false;
80 } else if (!this.id.equals(other.id)) return false;
81 if (this.name == null) {
82 if (other.name != null) return false;
83 } else if (!this.name.equals(other.name)) return false;
84 if (Double.doubleToLongBits(this.price) != Double.doubleToLongBits(other.price))
85 return false;
86 if (this.tags == null) {
87 if (other.tags != null) return false;
88 } else if (!this.tags.equals(other.tags)) return false;
89 return true;
90 }
91
92 public String toString() {
93 String ret = "[" + name + ", " + id + ", " + price;
94 if (tags != null) {
95 ret += "\n{";
96 for (java.util.Iterator it = tags.iterator(); it.hasNext();) {
97 String tag = (String)it.next();
98 ret += tag + "\n";
99 }
100 ret += "}";
101 }
102 ret += "]";
103 return ret;
104 }
105
106 }
0 /*
1 * Copyright (C) 2008 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 22. October 2008 by Joerg Schaible
9 */
10
11 /**
12 * @author Joe Walnes
13 */
14 package com.thoughtworks.acceptance.objects;
15
16
17 public class Replaced extends StandardObject {
18 String replacedValue;
19
20 public Replaced() {
21 }
22
23 public Replaced(String replacedValue) {
24 this.replacedValue = replacedValue;
25 }
26
27 private Object readResolve() {
28 return new Original(replacedValue.toLowerCase());
29 }
30 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010 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 25. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13 import java.lang.reflect.InvocationHandler;
14 import java.lang.reflect.Method;
15 import java.lang.reflect.Proxy;
16
17 public class SampleDynamicProxy implements InvocationHandler {
18
19 private Object aField;
20 private transient boolean recursion;
21
22 private SampleDynamicProxy(Object value) {
23 aField = value;
24 }
25
26 public static interface InterfaceOne {
27 Object doSomething();
28 }
29
30 public static interface InterfaceTwo {
31 Object doSomething();
32 }
33
34 public static Object newInstance() {
35 return newInstance("hello");
36 }
37
38 public static Object newInstance(Object value) {
39 return Proxy.newProxyInstance(InterfaceOne.class.getClassLoader(),
40 new Class[]{InterfaceOne.class, InterfaceTwo.class},
41 new SampleDynamicProxy(value));
42 }
43
44 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
45 if (method.getName().equals("equals")) {
46 return (recursion || equals(args[0])) ? Boolean.TRUE : Boolean.FALSE;
47 } else if (method.getName().equals("hashCode")) {
48 return new Integer(System.identityHashCode(proxy));
49 } else {
50 return aField;
51 }
52 }
53
54 public boolean equals(Object obj) {
55 try {
56 recursion = true;
57 return equalsInterfaceOne(obj) && equalsInterfaceTwo(obj);
58 } finally {
59 recursion = false;
60 }
61 }
62
63 private boolean equalsInterfaceOne(Object o) {
64 if (o instanceof InterfaceOne) {
65 InterfaceOne interfaceOne = (InterfaceOne) o;
66 return aField.equals(interfaceOne.doSomething());
67 } else {
68 return false;
69 }
70 }
71
72 private boolean equalsInterfaceTwo(Object o) {
73 if (o instanceof InterfaceTwo) {
74 InterfaceTwo interfaceTwo = (InterfaceTwo) o;
75 return aField.equals(interfaceTwo.doSomething());
76 } else {
77 return false;
78 }
79 }
80 }
0 /*
1 * Copyright (C) 2003 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17
18 public class SampleLists extends StandardObject {
19 public List good = new ArrayList();
20 public Collection bad = new ArrayList();
21
22 }
0 /*
1 * Copyright (C) 2011 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 05. August 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.objects;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15
16 public class SampleMaps extends StandardObject {
17 public Map good = new HashMap();
18 public Map bad = new HashMap();
19 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13
14 public class Software extends StandardObject {
15
16 public String vendor;
17 public String name;
18
19 public Software() {
20 }
21
22 public Software(String vendor, String name) {
23 this.vendor = vendor;
24 this.name = name;
25 }
26 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2010, 2011 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 05. July 2011 by Joerg Schaible, factored out of ExternalizableTest.
10 */
11 package com.thoughtworks.acceptance.objects;
12
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17
18
19 public class SomethingExternalizable extends StandardObject implements Externalizable {
20
21 private String first;
22 private String last;
23 private String nothing = null;
24 private String constant = "XStream";
25
26 public SomethingExternalizable() {
27 }
28
29 public SomethingExternalizable(String first, String last) {
30 this.first = first;
31 this.last = last;
32 }
33
34 public void writeExternal(ObjectOutput out) throws IOException {
35 out.writeInt(first.length());
36 out.writeObject(first + last);
37 out.writeObject(nothing);
38 out.writeObject(constant);
39 }
40
41 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
42 int offset = in.readInt();
43 String full = (String) in.readObject();
44 first = full.substring(0, offset);
45 last = full.substring(offset);
46 nothing = (String) in.readObject();
47 constant = (String) in.readObject();
48 }
49 }
0 /*
1 * Copyright (C) 2003, 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 25. October 2003 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13 import org.apache.commons.lang.builder.CompareToBuilder;
14 import org.apache.commons.lang.builder.EqualsBuilder;
15 import org.apache.commons.lang.builder.HashCodeBuilder;
16 import org.apache.commons.lang.builder.ToStringBuilder;
17
18 import java.io.Serializable;
19
20 public class StandardObject implements Serializable, Comparable {
21 public boolean equals(Object obj) {
22 return EqualsBuilder.reflectionEquals(this, obj);
23 }
24
25 public int hashCode() {
26 return HashCodeBuilder.reflectionHashCode(this);
27 }
28
29 public String toString() {
30 return ToStringBuilder.reflectionToString(this);
31 }
32
33 public int compareTo(Object obj) {
34 return CompareToBuilder.reflectionCompare(this, obj);
35 }
36 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 30. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.objects;
12
13 import java.io.Serializable;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.List;
17
18 public class StatusEnum implements Serializable, Comparable {
19
20 private static int nextOrdinal = 0;
21 private int ordinal = nextOrdinal++;
22
23 public static final StatusEnum STARTED = new StatusEnum("STARTED");
24
25 public static final StatusEnum FINISHED = new StatusEnum("FINISHED");
26
27 private static final StatusEnum[] PRIVATE_VALUES = {STARTED, FINISHED};
28
29 public static final List VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
30
31 private String name; // for debug only
32
33 private StatusEnum() {
34 }
35
36 private StatusEnum(String name) {
37 this.name = name;
38 }
39
40 public String toString() {
41 return name;
42 }
43
44 public int compareTo(Object o) {
45 return ordinal - ((StatusEnum) o).ordinal;
46 }
47
48 private Object readResolve() {
49 return PRIVATE_VALUES[ordinal]; //Canonicalize
50 }
51 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class FunnyConstructor extends StandardObject {
16 public int i;
17
18 public FunnyConstructor(int i) {
19 this.i = i;
20 }
21
22 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 /**
14 *
15 *
16 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
17 *
18 * @version $Id: Handler.java 2034 2013-03-12 22:15:00Z joehni $
19 */
20 public class Handler
21 {
22 private Protocol protocol;
23
24 public Handler(Protocol p) {
25 protocol = p;
26 }
27
28 public Protocol getProtocol()
29 {
30 return protocol;
31 }
32 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import java.util.List;
14
15 /**
16 *
17 *
18 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
19 *
20 * @version $Id: HandlerManager.java 1345 2007-12-11 01:50:12Z joehni $
21 */
22 public class HandlerManager
23 {
24 List handlers;
25
26 public List getHandlers()
27 {
28 return handlers;
29 }
30 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 /**
14 *
15 *
16 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
17 *
18 * @version $Id: Protocol.java 2034 2013-03-12 22:15:00Z joehni $
19 */
20 public class Protocol
21 {
22 private String id;
23
24 public Protocol(String id) {
25 this.id = id;
26 }
27
28 public String getId()
29 {
30 return id;
31 }
32 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. October 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class U extends StandardObject {
16 public String aStr;
17 public String a_Str;
18 public U() {
19 }
20
21 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 public class WithList extends StandardObject {
19
20 public List things = new ArrayList();
21
22 }
0 /*
1 * Copyright (C) 2006, 2007 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 15. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.acceptance.someobjects;
11
12
13 public class WithNamedList extends WithList {
14 private String name;
15
16 public WithNamedList(final String name) {
17 this.name = name;
18 }
19
20 public String getName() {
21 return name;
22 }
23 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class X extends StandardObject {
16 public String aStr;
17 public int anInt;
18 public Y innerObj;
19
20 public X() {
21 }
22
23 public X(int anInt) {
24 this.anInt = anInt;
25 }
26 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class Y extends StandardObject {
16 public String yField;
17 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 19. December 2004 by Mauro Talevi
10 */
11 package com.thoughtworks.acceptance.someobjects;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14
15 public class Z extends StandardObject {
16 public String field;
17
18 public Z(String z){
19 this.field = z;
20 }
21
22 }
0 /*
1 * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2014 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 26. September 2003 by Joe Walnes
10 */
11 package com.thoughtworks.xstream;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.acceptance.objects.StandardObject;
15 import com.thoughtworks.acceptance.someobjects.FunnyConstructor;
16 import com.thoughtworks.acceptance.someobjects.Handler;
17 import com.thoughtworks.acceptance.someobjects.HandlerManager;
18 import com.thoughtworks.acceptance.someobjects.Protocol;
19 import com.thoughtworks.acceptance.someobjects.U;
20 import com.thoughtworks.acceptance.someobjects.WithList;
21 import com.thoughtworks.acceptance.someobjects.X;
22 import com.thoughtworks.acceptance.someobjects.Y;
23 import com.thoughtworks.xstream.converters.Converter;
24 import com.thoughtworks.xstream.converters.MarshallingContext;
25 import com.thoughtworks.xstream.converters.UnmarshallingContext;
26 import com.thoughtworks.xstream.core.JVM;
27 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
28 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
29 import com.thoughtworks.xstream.io.StreamException;
30 import com.thoughtworks.xstream.io.xml.AbstractDocumentReader;
31 import com.thoughtworks.xstream.io.xml.Dom4JDriver;
32 import com.thoughtworks.xstream.security.NoTypePermission;
33
34 import junit.framework.TestCase;
35
36 import org.dom4j.Element;
37
38 import java.io.File;
39 import java.io.FileNotFoundException;
40 import java.io.FileOutputStream;
41 import java.io.IOException;
42 import java.io.ObjectOutputStream;
43 import java.io.StringReader;
44 import java.io.StringWriter;
45 import java.io.UnsupportedEncodingException;
46
47 public class XStreamTest extends TestCase {
48
49 private transient XStream xstream;
50
51 protected void setUp() throws Exception {
52 super.setUp();
53 xstream = new XStream();
54 xstream.addPermission(NoTypePermission.NONE); // clear out defaults
55 xstream.allowTypesByWildcard(new String[]{
56 AbstractAcceptanceTest.class.getPackage().getName()+".*objects.**",
57 this.getClass().getName()+"$*"
58 });
59 xstream.alias("x", X.class);
60 xstream.alias("y", Y.class);
61 xstream.alias("funny", FunnyConstructor.class);
62 xstream.alias("with-list", WithList.class);
63 }
64
65 public void testUnmarshalsObjectFromXmlWithUnderscores() {
66 String xml =
67 "<u-u>" +
68 " <u-f>foo</u-f>" +
69 " <u_f>_foo</u_f>" +
70 "</u-u>";
71
72 xstream.alias("u-u", U.class);
73 xstream.aliasField("u-f", U.class, "aStr");
74 xstream.aliasField("u_f", U.class, "a_Str");
75 U u = (U) xstream.fromXML(xml);
76
77 assertEquals("foo", u.aStr);
78 assertEquals("_foo", u.a_Str);
79 }
80
81 public void testUnmarshalsObjectFromXmlWithClassContainingUnderscores() {
82 String xml =
83 "<com.thoughtworks.xstream.XStreamTest_-U_U>" +
84 " <aStr>custom value</aStr>" +
85 "</com.thoughtworks.xstream.XStreamTest_-U_U>";
86
87 U_U u = (U_U) xstream.fromXML(xml);
88
89 assertEquals("custom value", u.aStr);
90 }
91
92
93 public void testUnmarshalsObjectFromXmlWithUnderscoresWithoutAliasingFields() {
94 String xml =
95 "<u-u>" +
96 " <a_Str>custom value</a_Str>" +
97 "</u-u>";
98
99 xstream.alias("u-u", U.class);
100
101 U u = (U) xstream.fromXML(xml);
102
103 assertEquals("custom value", u.a_Str);
104 }
105
106 public static class U_U {
107 String aStr;
108 }
109
110 public void testUnmarshalsObjectFromXml() {
111
112 String xml =
113 "<x>" +
114 " <aStr>joe</aStr>" +
115 " <anInt>8</anInt>" +
116 " <innerObj>" +
117 " <yField>walnes</yField>" +
118 " </innerObj>" +
119 "</x>";
120
121 X x = (X) xstream.fromXML(xml);
122
123 assertEquals("joe", x.aStr);
124 assertEquals(8, x.anInt);
125 assertEquals("walnes", x.innerObj.yField);
126 }
127
128 public void testMarshalsObjectToXml() {
129 X x = new X();
130 x.anInt = 9;
131 x.aStr = "zzz";
132 x.innerObj = new Y();
133 x.innerObj.yField = "ooo";
134
135 String expected =
136 "<x>\n" +
137 " <aStr>zzz</aStr>\n" +
138 " <anInt>9</anInt>\n" +
139 " <innerObj>\n" +
140 " <yField>ooo</yField>\n" +
141 " </innerObj>\n" +
142 "</x>";
143
144 assertEquals(xstream.fromXML(expected), x);
145 }
146
147 public void testUnmarshalsClassWithoutDefaultConstructor() {
148 if (!JVM.is14()) return;
149
150 String xml =
151 "<funny>" +
152 " <i>999</i>" +
153 "</funny>";
154
155 FunnyConstructor funnyConstructor = (FunnyConstructor) xstream.fromXML(xml);
156
157 assertEquals(999, funnyConstructor.i);
158 }
159
160 public void testHandlesLists() {
161 WithList original = new WithList();
162 Y y = new Y();
163 y.yField = "a";
164 original.things.add(y);
165 original.things.add(new X(3));
166 original.things.add(new X(1));
167
168 String xml = xstream.toXML(original);
169
170 String expected =
171 "<with-list>\n" +
172 " <things>\n" +
173 " <y>\n" +
174 " <yField>a</yField>\n" +
175 " </y>\n" +
176 " <x>\n" +
177 " <anInt>3</anInt>\n" +
178 " </x>\n" +
179 " <x>\n" +
180 " <anInt>1</anInt>\n" +
181 " </x>\n" +
182 " </things>\n" +
183 "</with-list>";
184
185 assertEquals(expected, xml);
186
187 WithList result = (WithList) xstream.fromXML(xml);
188 assertEquals(original, result);
189
190 }
191
192 public void testCanHandleNonStaticPrivateInnerClass() {
193 if (!JVM.is14()) return;
194
195 NonStaticInnerClass obj = new NonStaticInnerClass();
196 obj.field = 3;
197
198 xstream.alias("inner", NonStaticInnerClass.class);
199
200 String xml = xstream.toXML(obj);
201
202 String expected = ""
203 + "<inner>\n"
204 + " <field>3</field>\n"
205 + " <outer-class>\n"
206 + " <fName>testCanHandleNonStaticPrivateInnerClass</fName>\n"
207 + " </outer-class>\n"
208 + "</inner>";
209
210 assertEquals(xstream.fromXML(expected), obj);
211
212 NonStaticInnerClass result = (NonStaticInnerClass) xstream.fromXML(xml);
213 assertEquals(obj.field, result.field);
214 }
215
216 public void testClassWithoutMappingUsesFullyQualifiedName() {
217 Person obj = new Person();
218
219 String xml = xstream.toXML(obj);
220
221 String expected = "<com.thoughtworks.xstream.XStreamTest_-Person/>";
222
223 assertEquals(expected, xml);
224
225 Person result = (Person) xstream.fromXML(xml);
226 assertEquals(obj, result);
227 }
228
229 private class NonStaticInnerClass extends StandardObject {
230 int field;
231 }
232
233 public void testCanBeBeUsedMultipleTimesWithSameInstance() {
234 Y obj = new Y();
235 obj.yField = "x";
236
237 assertEquals(xstream.toXML(obj), xstream.toXML(obj));
238 }
239
240 public void testAccessToUnderlyingDom4JImplementation()
241 throws Exception {
242
243 String xml =
244 "<person>" +
245 " <firstName>jason</firstName>" +
246 " <lastName>van Zyl</lastName>" +
247 " <element>" +
248 " <foo>bar</foo>" +
249 " </element>" +
250 "</person>";
251
252 xstream.registerConverter(new ElementConverter());
253 xstream.alias("person", Person.class);
254
255 Dom4JDriver driver = new Dom4JDriver();
256 Person person = (Person) xstream.unmarshal(driver.createReader(new StringReader(xml)));
257
258 assertEquals("jason", person.firstName);
259 assertEquals("van Zyl", person.lastName);
260 assertNotNull(person.element);
261 assertEquals("bar", person.element.element("foo").getText());
262 }
263
264 public static class Person extends StandardObject {
265 String firstName;
266 String lastName;
267 Element element;
268 }
269
270 private class ElementConverter implements Converter {
271
272 public boolean canConvert(Class type) {
273 return Element.class.isAssignableFrom(type);
274 }
275
276 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
277 }
278
279 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
280
281 AbstractDocumentReader documentReader = (AbstractDocumentReader)reader.underlyingReader();
282 Element element = (Element) documentReader.getCurrent();
283
284 while (reader.hasMoreChildren()) {
285 reader.moveDown();
286 reader.moveUp();
287 }
288
289 return element;
290 }
291 }
292
293 public void testPopulationOfAnObjectGraphStartingWithALiveRootObject()
294 throws Exception {
295
296 String xml =
297 "<component>" +
298 " <host>host</host>" +
299 " <port>8000</port>" +
300 "</component>";
301
302 xstream.alias("component", Component.class);
303
304 Component component0 = new Component();
305 Component component1 = (Component) xstream.fromXML(xml, component0);
306 assertSame(component0, component1);
307 assertEquals("host", component0.host);
308 assertEquals(8000, component0.port);
309 }
310
311 static class Component {
312 String host;
313 int port;
314 }
315
316 public void testPopulationOfThisAsRootObject()
317 throws Exception {
318
319 String xml =""
320 + "<component>\n"
321 + " <host>host</host>\n"
322 + " <port>8000</port>\n"
323 + "</component>";
324
325 xstream.alias("component", SelfSerializingComponent.class);
326 SelfSerializingComponent component = new SelfSerializingComponent();
327 component.host = "host";
328 component.port = 8000;
329 assertEquals(xml, component.toXML(xstream));
330 component.host = "foo";
331 component.port = -1;
332 component.fromXML(xstream, xml);
333 assertEquals("host", component.host);
334 assertEquals(8000, component.port);
335 }
336
337 static class SelfSerializingComponent extends Component {
338 String toXML(XStream xstream) {
339 return xstream.toXML(this);
340 }
341 void fromXML(XStream xstream, String xml) {
342 xstream.fromXML(xml, this);
343 }
344 }
345
346 public void testUnmarshalsWhenAllImplementationsAreSpecifiedUsingAClassIdentifier()
347 throws Exception {
348
349 String xml =
350 "<handlerManager class='com.thoughtworks.acceptance.someobjects.HandlerManager'>" +
351 " <handlers>" +
352 " <handler class='com.thoughtworks.acceptance.someobjects.Handler'>" +
353 " <protocol class='com.thoughtworks.acceptance.someobjects.Protocol'>" +
354 " <id>foo</id> " +
355 " </protocol> " +
356 " </handler>" +
357 " </handlers>" +
358 "</handlerManager>";
359
360 HandlerManager hm = (HandlerManager) xstream.fromXML(xml);
361 Handler h = (Handler) hm.getHandlers().get(0);
362 Protocol p = h.getProtocol();
363 assertEquals("foo", p.getId());
364 }
365
366 public void testObjectOutputStreamCloseTwice() throws IOException {
367 ObjectOutputStream oout = xstream.createObjectOutputStream(new StringWriter());
368 oout.writeObject(new Integer(1));
369 oout.close();
370 oout.close();
371 }
372
373 public void testObjectOutputStreamCloseAndFlush() throws IOException {
374 ObjectOutputStream oout = xstream.createObjectOutputStream(new StringWriter());
375 oout.writeObject(new Integer(1));
376 oout.close();
377 try {
378 oout.flush();
379 fail("Closing and flushing should throw a StreamException");
380 } catch (StreamException e) {
381 // ok
382 }
383 }
384
385 public void testObjectOutputStreamCloseAndWrite() throws IOException {
386 ObjectOutputStream oout = xstream.createObjectOutputStream(new StringWriter());
387 oout.writeObject(new Integer(1));
388 oout.close();
389 try {
390 oout.writeObject(new Integer(2));
391 fail("Closing and writing should throw a StreamException");
392 } catch (StreamException e) {
393 // ok
394 }
395 }
396
397 public void testUnmarshalsFromFile() throws IOException {
398 File file = createTestFile();
399 xstream.registerConverter(new ElementConverter());
400 xstream.alias("component", Component.class);
401 Component person = (Component)xstream.fromXML(file);
402 assertEquals(8000, person.port);
403 }
404
405 public void testUnmarshalsFromURL() throws IOException {
406 File file = createTestFile();
407 xstream.alias("component", Component.class);
408 Component person = (Component)xstream.fromXML(file);
409 assertEquals(8000, person.port);
410 }
411
412 private File createTestFile()
413 throws FileNotFoundException, IOException, UnsupportedEncodingException {
414 String xml =""
415 + "<component>\n"
416 + " <host>host</host>\n"
417 + " <port>8000</port>\n"
418 + "</component>";
419
420 File dir = new File("target/test-data");
421 dir.mkdirs();
422 File file = new File(dir, "test.xml");
423 FileOutputStream fos = new FileOutputStream(file);
424 fos.write(xml.getBytes("UTF-8"));
425 fos.close();
426 return file;
427 }
428 }
0 /*
1 * Copyright (C) 2006, 2007 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 07. November 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters;
11
12 import com.thoughtworks.xstream.mapper.CannotResolveClassException;
13
14 import junit.framework.TestCase;
15
16 import java.util.StringTokenizer;
17
18 /**
19 * @author J&ouml;rg Schaible
20 */
21 public class ConversionExceptionTest extends TestCase {
22
23 public void testDebugMessageIsNotNested() {
24 Exception ex = new CannotResolveClassException("JUnit");
25 ConversionException innerEx = new ConversionException("Inner", ex);
26 ConversionException outerEx = new ConversionException("Outer", innerEx);
27 StringTokenizer tokenizer = new StringTokenizer(outerEx.getMessage(), "\n\r");
28 int ends = 0;
29 while(tokenizer.hasMoreTokens()) {
30 if (tokenizer.nextToken().startsWith("---- Debugging information ----")) {
31 ++ends;
32 }
33 }
34 assertEquals(1, ends);
35 }
36
37 public void testInfoRetainsOrder() {
38 ConversionException ex = new ConversionException("Message");
39 ex.add("1st", "first");
40 ex.add("2nd", "second");
41 ex.add("3rd", "third");
42 StringTokenizer tokenizer = new StringTokenizer(ex.getMessage(), "\n\r");
43 tokenizer.nextToken();
44 tokenizer.nextToken();
45 assertEquals("1st : first", tokenizer.nextToken());
46 assertEquals("2nd : second", tokenizer.nextToken());
47 assertEquals("3rd : third", tokenizer.nextToken());
48 }
49 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2012, 2014, 2015 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 22. February 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.core.JVM;
15 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
16
17 import junit.framework.TestCase;
18
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Calendar;
24 import java.util.Collections;
25 import java.util.Date;
26 import java.util.GregorianCalendar;
27 import java.util.List;
28 import java.util.Locale;
29 import java.util.TimeZone;
30
31
32 public class DateConverterTest extends TestCase {
33
34 private DateConverter converter = new DateConverter();
35
36 protected void setUp() throws Exception {
37 super.setUp();
38
39 // Ensure that this test always run as if it were in the IST timezone.
40 // This prevents failures when running the tests in different zones.
41 // Note: 'IST' has no relevance - it was just a randomly chosen zone
42 // without daylight saving.
43 TimeZoneChanger.change("IST");
44 }
45
46 protected void tearDown() throws Exception {
47 TimeZoneChanger.reset();
48 super.tearDown();
49 }
50
51 public void testRetainsDetailDownToMillisecondLevel() {
52 // setup
53 Date in = new Date();
54
55 // execute
56 String text = converter.toString(in);
57 Date out = (Date)converter.fromString(text);
58
59 // verify
60 assertEquals(in, out);
61 assertEquals(in.toString(), out.toString());
62 assertEquals(in.getTime(), out.getTime());
63 }
64
65 public void testUnmarshalsOldXStreamDatesThatLackMillisecond() {
66 converter = new DateConverter((TimeZone)null); // use default TZ
67 Date expected = (Date)converter.fromString("2004-02-22 15:16:04.0 EST");
68
69 assertEquals(expected, converter.fromString("2004-02-22 15:16:04.0 EST"));
70 assertEquals(expected, converter.fromString("2004-02-22 15:16:04 EST"));
71 assertEquals(expected, converter.fromString("2004-02-22 15:16:04EST"));
72
73 TimeZone.setDefault(TimeZone.getTimeZone("EST")); // Need correct local time, no TZ info in string
74 assertEquals(expected, converter.fromString("2004-02-22 15:16:04.0 PM"));
75 assertEquals(expected, converter.fromString("2004-02-22 15:16:04PM"));
76 }
77
78 public void testUnmarshalsDatesWithDifferentTimeZones() {
79 converter = new DateConverter(true); // Needed by JDK 5 running on Codehaus' Bamboo installation
80 Date expected = (Date)converter.fromString("2004-02-22 15:16:04.0 EST");
81
82 assertEquals(expected, converter.fromString("2004-02-22 15:16:04.0 EST"));
83 assertEquals(expected, converter.fromString("2004-02-22 15:16:04.0 GMT-05:00"));
84 assertEquals(expected, converter.fromString("2004-02-22 20:16:04.0 UTC"));
85 assertEquals(expected, converter.fromString("2004-02-23 01:46:04.0 IST"));
86 assertEquals(expected, converter.fromString("2004-02-23 01:46:04.0 GMT+05:30"));
87
88 if (JVM.canParseISO8601TimeZoneInDateFormat()) {
89 // W3C subset of ISO 8601 date time representations
90 assertEquals(expected, converter.fromString("2004-02-22T15:16:04-05:00"));
91 assertEquals(expected, converter.fromString("2004-02-22T20:16:04Z"));
92 assertEquals(expected, converter.fromString("2004-02-22T20:16:04.0Z"));
93 expected.setTime(expected.getTime()-4000);
94 assertEquals(expected, converter.fromString("2004-02-22T15:16-05:00"));
95 }
96 }
97
98 public void testUnmarshalsDateWithDifferentDefaultTimeZones() throws ParseException {
99 converter = new DateConverter((TimeZone)null); // use default TZ
100 Calendar cal = Calendar.getInstance();
101 cal.clear();
102 cal.set(2004, Calendar.FEBRUARY, 23, 1, 46, 4);
103 Date date = cal.getTime();
104 String strIST = converter.toString(date);
105 assertEquals("2004-02-23 01:46:04.0 IST", strIST);
106 // select arbitrary TZ
107 TimeZone.setDefault(TimeZone.getTimeZone("EST"));
108 // compare parsed date with JDK implementation
109 Date dateRetrieved = (Date)converter.fromString(strIST);
110 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
111 Date simpleDate = f.parse(strIST);
112 assertEquals(simpleDate, dateRetrieved);
113 // DateConverter does not get influenced by change of current TZ ...
114 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
115 dateRetrieved = (Date)converter.fromString(strIST);
116 assertEquals(simpleDate, dateRetrieved);
117 // ... as well as the SimpleDateFormat
118 f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
119 simpleDate = f.parse(strIST);
120 assertEquals(simpleDate, dateRetrieved);
121 assertEquals(date, f.parse("2004-02-22 20:16:04.0 UTC"));
122 // 'date' was created for IST time zone, so let parser return in IST
123 f.setTimeZone(TimeZone.getTimeZone("IST"));
124 simpleDate = f.parse(strIST);
125 assertEquals(date, simpleDate);
126 assertEquals(date, f.parse("2004-02-22 20:16:04.0 UTC"));
127 }
128
129 public void testIsThreadSafe() throws InterruptedException {
130 final List results = Collections.synchronizedList(new ArrayList());
131 final DateConverter converter = new DateConverter();
132 final Object monitor = new Object();
133 final int numberOfCallsPerThread = 20;
134 final int numberOfThreads = 20;
135
136 // spawn some concurrent threads, that hammer the converter
137 Runnable runnable = new Runnable() {
138 public void run() {
139 for (int i = 0; i < numberOfCallsPerThread; i++) {
140 try {
141 converter.fromString("2004-02-22 15:16:04.0 EST");
142 results.add("PASS");
143 } catch (ConversionException e) {
144 results.add("FAIL");
145 } finally {
146 synchronized (monitor) {
147 monitor.notifyAll();
148 }
149 }
150 }
151 }
152 };
153 for (int i = 0; i < numberOfThreads; i++) {
154 new Thread(runnable).start();
155 }
156
157 // wait for all results
158 while (results.size() < numberOfThreads * numberOfCallsPerThread) {
159 synchronized (monitor) {
160 monitor.wait(100);
161 }
162 }
163
164 assertTrue("Nothing suceeded", results.contains("PASS"));
165 assertFalse("At least one attempt failed", results.contains("FAIL"));
166 }
167
168 public void testDatesInNonLenientMode() {
169 String[] dateFormats = new String[] { "yyyyMMdd", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd" };
170 converter = new DateConverter("yyyy-MM-dd'T'HH:mm:ss.S'Z'", dateFormats);
171 Date expected = (Date)converter.fromString("2004-02-22T15:16:04.0Z");
172 assertEquals(expected, converter.fromString("2004-02-22T15:16:04Z"));
173 }
174
175 public void testDatesInLenientMode() {
176 converter = new DateConverter("yyyy-MM-dd HH:mm:ss.S z", new String[0], true);
177 Date expected = (Date)converter.fromString("2004-02-22 15:16:04.0 IST");
178 assertEquals(expected, converter.fromString("2004-02-21 39:16:04.0 IST"));
179 }
180
181 public void testDatesIn70sInTimeZoneGMT() throws ParseException {
182 converter = new DateConverter((TimeZone)null); // use default TZ
183
184 final String pattern = "yyyy-MM-dd HH:mm:ss.S z";
185 final SimpleDateFormat format;
186
187 format = new SimpleDateFormat(pattern, Locale.UK);
188 format.setTimeZone(TimeZone.getTimeZone("GMT"));
189
190 final String[] expected = new String[]{
191 "1970-01-01 11:20:34.0 GMT",
192 "1971-01-01 11:20:34.0 GMT",
193 "1972-01-01 11:20:34.0 GMT",
194 "1973-01-01 11:20:34.0 GMT",
195 "1974-01-01 11:20:34.0 GMT",
196 };
197
198 final String[] actual = new String[expected.length];
199 for (int i = 0; i < actual.length; i++ ) {
200 final String converted = converter.toString(format.parseObject(expected[i]));
201 // Note, XStream's string representation of the date is in IST
202 actual[i] = format.format(converter.fromString(converted));
203 }
204
205 assertEquals(Arrays.asList(expected).toString(), Arrays.asList(actual).toString());
206 }
207
208 public void testDatesWithAmbiguous3LetterTimeZones() {
209 TimeZone.setDefault(TimeZone.getTimeZone("Australia/Brisbane")); // EST also used e.g. for America/Toronto
210 Date expected = new Date(0);
211 assertEquals(expected, converter.fromString(converter.toString(expected)));
212 }
213
214 public void testDatesWithEpoche() {
215 Calendar cal = Calendar.getInstance();
216 cal.setTimeZone(TimeZone.getTimeZone("UTC"));
217 assertEquals(GregorianCalendar.AD, cal.get(Calendar.ERA));
218 cal.clear();
219 cal.set(1, Calendar.JANUARY, 1);
220 cal.add(Calendar.MILLISECOND, -1);
221 Date date = cal.getTime();
222 assertEquals("0001-12-31 BC 23:59:59.999 UTC", converter.toString(date));
223 assertEquals(date, converter.fromString("0001-12-31 BC 23:59:59.999 UTC"));
224 cal.add(Calendar.MILLISECOND, 1);
225 assertEquals(cal.getTime(), converter.fromString("0001-01-01 AD 00:00:00.000 UTC"));
226 }
227
228 public void testDatesWithEnglishLocaleOfDefault() {
229 converter = new DateConverter(null, "EEEE, dd MMMM yyyy z",
230 null, Locale.ENGLISH, TimeZone.getTimeZone("UTC"), false);
231 Calendar cal = Calendar.getInstance();
232 cal.setTimeZone(TimeZone.getTimeZone("UTC"));
233 cal.clear();
234 cal.set(2000, Calendar.JANUARY, 1);
235 Date date = cal.getTime();
236 assertEquals("Saturday, 01 January 2000 UTC", converter.toString(date));
237 assertEquals(date, converter.fromString("Saturday, 01 January 2000 UTC"));
238 }
239
240 public void testDatesWithGermanLocale() {
241 converter = new DateConverter(null, "EEEE, dd MMMM yyyy z",
242 null, Locale.GERMAN, TimeZone.getTimeZone("UTC"), false);
243 Calendar cal = Calendar.getInstance();
244 cal.setTimeZone(TimeZone.getTimeZone("UTC"));
245 cal.clear();
246 cal.set(2000, Calendar.JANUARY, 1);
247 Date date = cal.getTime();
248 assertEquals("Samstag, 01 Januar 2000 UTC", converter.toString(date));
249 assertEquals(date, converter.fromString("Samstag, 01 Januar 2000 UTC"));
250 }
251 }
0 /*
1 * Copyright (C) 2010 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 3. August 2010 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.basic;
11
12 import java.net.URI;
13
14 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.io.xml.DomDriver;
17
18 /**
19 * @author Carlos Roman
20 */
21 public class URIConverterTest extends AbstractAcceptanceTest {
22
23 private static final String TEST_URI_STRING = "rtmp://cp12345.edgefcs.net/od/public/file.flv";
24 private static URI TEST_URI;
25
26 public URIConverterTest() {
27 }
28
29 public void setUp() throws Exception{
30 xstream = new XStream(new DomDriver("UTF-8"));
31 xstream.registerConverter(new URIConverter());
32 TEST_URI = new URI(TEST_URI_STRING);
33 assertNotNull(xstream);
34 assertNotNull(TEST_URI);
35 }
36
37 /**
38 * Test of canConvert method, of class URIConverter.
39 */
40 public void testCanConvert() {
41 final Class type = URI.class;
42 final URIConverter instance = new URIConverter();
43 final boolean expResult = true;
44 final boolean result = instance.canConvert(type);
45 assertEquals(expResult, result);
46 }
47
48 /**
49 * Test of fromString method, of class URIConverter.
50 */
51 public void testFromString() throws Exception{
52 final URIConverter instance = new URIConverter();
53 final Object expResult = new URI(TEST_URI_STRING);
54 final Object result = instance.fromString(TEST_URI_STRING);
55 assertEquals(expResult, result);
56 }
57 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 25. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.basic;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 import java.net.MalformedURLException;
16 import java.net.URL;
17
18 public class URLConverterTest extends AbstractAcceptanceTest {
19
20 public void testConvertsToSingleString() throws MalformedURLException {
21
22 assertBothWays(
23 new URL("http://www.apple.com:2020/path/blah.html?abc#2"),
24 "<url>http://www.apple.com:2020/path/blah.html?abc#2</url>");
25
26 assertBothWays(
27 new URL("file:/c:/winnt/blah.txt"),
28 "<url>file:/c:/winnt/blah.txt</url>");
29 }
30
31 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 import java.util.BitSet;
16
17 public class BitSetConverterTest extends AbstractAcceptanceTest {
18
19 public void testConvertsToSingleCommaDelimitedString() {
20 BitSet bitSet = new BitSet();
21 bitSet.set(0);
22 bitSet.set(1);
23 bitSet.set(3);
24 bitSet.set(5);
25 bitSet.set(6);
26 bitSet.set(8);
27 bitSet.set(10);
28
29 String expected = "<bit-set>0,1,3,5,6,8,10</bit-set>";
30
31 assertBothWays(bitSet, expected);
32 }
33 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 25. April 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 public class ByteArrayConverterTest extends AbstractAcceptanceTest {
16
17
18 public void testMarshallByteArrays() {
19 Dummy input = new Dummy(new byte[0]);
20
21 String expected = "<dummy>\n <data></data>\n</dummy>";
22 assertBothWays(input, expected);
23 }
24
25 public static class Dummy {
26 byte[] data;
27
28 private Dummy() {
29 }
30
31 public Dummy(byte[] data) {
32 this.data = data;
33 }
34
35 public byte[] getData() {
36 return data;
37 }
38
39 public boolean equals(Object that) {
40 if (that instanceof Dummy) {
41 return equals((Dummy) that);
42 }
43 return false;
44 }
45
46 public boolean equals(Dummy that) {
47 if (this.data == that.data) {
48 return true;
49 }
50 if (this.data != null && that.data != null) {
51 if (this.data.length == that.data.length) {
52 for (int i = 0; i < data.length; i++) {
53 byte b1 = data[i];
54 byte b2 = that.data[i];
55 if (b1 != b2) {
56 return false;
57 }
58 }
59 return true;
60 }
61 }
62 return false;
63
64 }
65 }
66
67 protected void setUp() throws Exception {
68 super.setUp();
69 xstream.alias("dummy", Dummy.class);
70 }
71 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 public class CharArrayConverterTest extends AbstractAcceptanceTest {
16
17 public void testMarshallsCharArrayAsSingleString() {
18 char[] input = new char[] {'h','e','l','l','o'};
19
20 String expected = "<char-array>hello</char-array>";
21 assertBothWays(input, expected);
22 }
23 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 23. February 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.collections;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import junit.framework.TestCase;
16
17 import java.util.Properties;
18
19 public class PropertiesConverterTest extends TestCase {
20
21 public void testConvertsPropertiesObjectToShortKeyValueElements() {
22 Properties in = new Properties();
23 in.setProperty("hello", "world");
24 in.setProperty("foo", "cheese");
25
26 String expectedXML = "" +
27 "<properties>\n" +
28 " <property name=\"hello\" value=\"world\"/>\n" +
29 " <property name=\"foo\" value=\"cheese\"/>\n" +
30 "</properties>";
31 XStream xstream = new XStream();
32 String actualXML = xstream.toXML(in);
33 assertEquals(expectedXML, actualXML);
34
35 Properties expectedOut = new Properties();
36 expectedOut.setProperty("hello", "world");
37 expectedOut.setProperty("foo", "cheese");
38 Properties actualOut = (Properties) xstream.fromXML(actualXML);
39 assertEquals(in, actualOut);
40 assertEquals(in.toString(), actualOut.toString());
41
42 }
43
44 public void testIncludesDefaultProperties() {
45 Properties defaults = new Properties();
46 defaults.setProperty("host", "localhost");
47 defaults.setProperty("port", "80");
48
49 Properties override = new Properties(defaults);
50 override.setProperty("port", "999");
51
52 // sanity check
53 assertEquals("Unexpected overriden property", "999", override.getProperty("port"));
54 assertEquals("Unexpected default property", "localhost", override.getProperty("host"));
55
56 String expectedXML = "" +
57 "<properties>\n" +
58 " <property name=\"port\" value=\"999\"/>\n" +
59 " <defaults>\n" +
60 " <property name=\"port\" value=\"80\"/>\n" +
61 " <property name=\"host\" value=\"localhost\"/>\n" +
62 " </defaults>\n" +
63 "</properties>";
64
65 XStream xstream = new XStream();
66 String actualXML = xstream.toXML(override);
67 assertEquals(expectedXML, actualXML);
68
69 Properties out = (Properties) xstream.fromXML(actualXML);
70 assertEquals("Unexpected overriden property", "999", out.getProperty("port"));
71 assertEquals("Unexpected default property", "localhost", out.getProperty("host"));
72 assertEquals(override, out);
73 }
74
75 public void testCanSortElements() {
76 Properties defaults = new Properties();
77 defaults.setProperty("host", "localhost");
78 defaults.setProperty("port", "80");
79
80 Properties override = new Properties(defaults);
81 override.setProperty("port", "999");
82 override.setProperty("domain", "codehaus.org");
83
84 String expectedXML = "" +
85 "<properties>\n" +
86 " <property name=\"domain\" value=\"codehaus.org\"/>\n" +
87 " <property name=\"port\" value=\"999\"/>\n" +
88 " <defaults>\n" +
89 " <property name=\"host\" value=\"localhost\"/>\n" +
90 " <property name=\"port\" value=\"80\"/>\n" +
91 " </defaults>\n" +
92 "</properties>";
93
94 XStream xstream = new XStream();
95 xstream.registerConverter(new PropertiesConverter(true));
96 String actualXML = xstream.toXML(override);
97 assertEquals(expectedXML, actualXML);
98
99 Properties out = (Properties) xstream.fromXML(actualXML);
100 assertEquals("Unexpected overriden property", "999", out.getProperty("port"));
101 assertEquals("Unexpected default property", "localhost", out.getProperty("host"));
102 assertEquals(override, out);
103 }
104 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 enum BigEnum {
14 A1, B1, C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1, S1, T1, U1, V1, W1, X1, Y1, Z1,
15 A2, B2, C2, D2, E2, F2, G2, H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, V2, W2, X2, Y2, Z2,
16 A3, B3, C3, D3, E3, F3, G3, H3, I3, J3, K3, L3, M3, N3, O3, P3, Q3, R3, S3, T3, U3, V3, W3, X3, Y3, Z3;
17 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 18. March 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 import com.thoughtworks.xstream.XStream;
14 import junit.framework.TestCase;
15
16 // ***** READ THIS *****
17 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
18 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
19
20 /**
21 * @author Joe Walnes
22 * @author Bryan Coleman
23 */
24 public class EnumConverterTest extends TestCase {
25
26 private XStream xstream;
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 xstream = new XStream();
31 xstream.alias("simple", SimpleEnum.class);
32 xstream.alias("polymorphic", PolymorphicEnum.class);
33 }
34
35 public void testRepresentsEnumAsSingleStringValue() {
36 String expectedXml = "<simple>GREEN</simple>";
37 SimpleEnum in = SimpleEnum.GREEN;
38 assertEquals(expectedXml, xstream.toXML(in));
39 assertEquals(in, xstream.fromXML(expectedXml));
40 }
41
42 public void testRepresentsPolymorphicEnumAsSingleStringValue() {
43 String expectedXml = "<polymorphic>B</polymorphic>";
44 PolymorphicEnum in = PolymorphicEnum.B;
45 assertEquals(expectedXml, xstream.toXML(in));
46 assertEquals(in, xstream.fromXML(expectedXml));
47 }
48
49 public void testDeserializedEnumIsTheSameNotJustEqual() {
50 assertSame(SimpleEnum.GREEN, xstream.fromXML(xstream.toXML(SimpleEnum.GREEN)));
51 assertSame(PolymorphicEnum.B, xstream.fromXML(xstream.toXML(PolymorphicEnum.B)));
52 }
53
54 public void testResolvesSpecializedPolymorphicEnum() {
55 PolymorphicEnum in;
56 PolymorphicEnum out;
57
58 in = PolymorphicEnum.A;
59 out = (PolymorphicEnum) xstream.fromXML(xstream.toXML(in));
60 assertEquals("apple", ((Fruit)out).fruit()); // see Bug ID: 6522780
61
62 in = PolymorphicEnum.B;
63 out = (PolymorphicEnum) xstream.fromXML(xstream.toXML(in));
64 assertEquals("banana", ((Fruit)out).fruit()); // see Bug ID: 6522780
65 }
66
67 }
0 /*
1 * Copyright (C) 2008 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 08. October 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.enums.EnumMapperTest.TypeWithEnums;
14
15 import junit.framework.TestCase;
16
17
18 // ***** READ THIS *****
19 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
20 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
21
22 /**
23 * @author J&ouml;rg Schaible
24 */
25 public class EnumCustomConverterTest extends TestCase {
26
27 private XStream xstream;
28
29 protected void setUp() throws Exception {
30 super.setUp();
31 xstream = new XStream();
32 xstream.alias("simple", SimpleEnum.class);
33 xstream.alias("polymorphic", PolymorphicEnum.class);
34 }
35
36 public void testCanBeUsedDirectly() {
37 xstream.registerConverter(new PolymorphicEnumConverter(PolymorphicEnum.class));
38 String expectedXml = "<polymorphic>b</polymorphic>";
39 PolymorphicEnum in = PolymorphicEnum.B;
40 assertEquals(expectedXml, xstream.toXML(in));
41 assertEquals(in, xstream.fromXML(expectedXml));
42 }
43
44 public void testCanBeUsedForMember() {
45 xstream.registerConverter(new PolymorphicEnumConverter(PolymorphicEnum.class));
46 xstream.alias("type", TypeWithEnums.class);
47 xstream.autodetectAnnotations(true);
48 String expectedXml = "" // force format
49 + "<type simple=\"GREEN\">\n"
50 + " <poly>b</poly>\n"
51 + " <big>C3</big>\n"
52 + "</type>";
53 TypeWithEnums in = new TypeWithEnums();
54 in.poly = PolymorphicEnum.B;
55 in.simple = SimpleEnum.GREEN;
56 in.big = BigEnum.C3;
57 assertEquals(expectedXml, xstream.toXML(in));
58 TypeWithEnums out = (TypeWithEnums)xstream.fromXML(expectedXml);
59 assertSame(out.poly, PolymorphicEnum.B);
60 assertSame(out.simple, SimpleEnum.GREEN);
61 }
62
63 public void testCanBeUsedForAttribute() {
64 xstream.registerConverter(new PolymorphicEnumConverter(PolymorphicEnum.class));
65 xstream.alias("type", TypeWithEnums.class);
66 xstream.useAttributeFor(PolymorphicEnum.class);
67 xstream.autodetectAnnotations(true);
68 String expectedXml = "" // force format
69 + "<type poly=\"b\" simple=\"GREEN\">\n"
70 + " <big>C3</big>\n"
71 + "</type>";
72 TypeWithEnums in = new TypeWithEnums();
73 in.poly = PolymorphicEnum.B;
74 in.simple = SimpleEnum.GREEN;
75 in.big = BigEnum.C3;
76 assertEquals(expectedXml, xstream.toXML(in));
77 TypeWithEnums out = (TypeWithEnums)xstream.fromXML(expectedXml);
78 assertSame(out.poly, PolymorphicEnum.B);
79 assertSame(out.simple, SimpleEnum.GREEN);
80 }
81
82 public void testCanBeUsedLocallyForAttribute() {
83 xstream.registerLocalConverter(
84 TypeWithEnums.class, "poly", new PolymorphicEnumConverter(PolymorphicEnum.class));
85 xstream.alias("type", TypeWithEnums.class);
86 xstream.useAttributeFor(PolymorphicEnum.class);
87 xstream.autodetectAnnotations(true);
88 String expectedXml = "" // force format
89 + "<type poly=\"b\" simple=\"GREEN\">\n"
90 + " <big>C3</big>\n"
91 + "</type>";
92 TypeWithEnums in = new TypeWithEnums();
93 in.poly = PolymorphicEnum.B;
94 in.simple = SimpleEnum.GREEN;
95 in.big = BigEnum.C3;
96 assertEquals(expectedXml, xstream.toXML(in));
97 TypeWithEnums out = (TypeWithEnums)xstream.fromXML(expectedXml);
98 assertSame(out.poly, PolymorphicEnum.B);
99 assertSame(out.simple, SimpleEnum.GREEN);
100 }
101
102 private final static class PolymorphicEnumConverter extends EnumSingleValueConverter {
103 private PolymorphicEnumConverter(Class type) {
104 super(type);
105 }
106
107 @Override
108 public Object fromString(String str) {
109 return super.fromString(str.toUpperCase());
110 }
111
112 @Override
113 public String toString(Object obj) {
114 return super.toString(obj).toLowerCase();
115 }
116 }
117 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import junit.framework.TestCase;
16
17 import java.util.EnumMap;
18
19 public class EnumMapConverterTest extends TestCase {
20
21 private XStream xstream;
22
23 protected void setUp() throws Exception {
24 super.setUp();
25 xstream = new XStream();
26 }
27
28 public void testIncludesEnumTypeInSerializedForm() {
29 xstream.alias("simple", SimpleEnum.class);
30 EnumMap map = new EnumMap<SimpleEnum,String>(SimpleEnum.class);
31 map.put(SimpleEnum.BLUE, "sky");
32 map.put(SimpleEnum.GREEN, "grass");
33
34 String expectedXml = "" +
35 "<enum-map enum-type=\"simple\">\n" +
36 " <entry>\n" +
37 " <simple>GREEN</simple>\n" +
38 " <string>grass</string>\n" +
39 " </entry>\n" +
40 " <entry>\n" +
41 " <simple>BLUE</simple>\n" +
42 " <string>sky</string>\n" +
43 " </entry>\n" +
44 "</enum-map>";
45
46 assertEquals(expectedXml, xstream.toXML(map));
47 assertEquals(map, xstream.fromXML(expectedXml));
48 }
49
50 }
0 /*
1 * Copyright (C) 2008 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 12. February 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
14
15 import junit.framework.TestCase;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21 // ***** READ THIS *****
22 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
23 // If you are using an earlier version of Java, just don't try to build this class. XStream
24 // should work fine without it.
25
26 /**
27 * @author J&ouml;rg Schaible
28 */
29 public class EnumMapperTest extends TestCase {
30
31 private XStream xstream;
32
33 protected void setUp() throws Exception {
34 super.setUp();
35 xstream = new XStream();
36 xstream.alias("simple", SimpleEnum.class);
37 xstream.alias("polymorphic", PolymorphicEnum.class);
38 }
39
40 static class Bowl {
41 Fruit fruit;
42 }
43
44 public void testSupportsDefaultImplementationToBeAnEnum() {
45 xstream.alias("bowl", Bowl.class);
46 xstream.addDefaultImplementation(PolymorphicEnum.class, Fruit.class);
47 String expectedXml = "" // force format
48 + "<bowl>\n"
49 + " <fruit>B</fruit>\n"
50 + "</bowl>";
51 Bowl in = new Bowl();
52 in.fruit = PolymorphicEnum.B;
53 assertEquals(expectedXml, xstream.toXML(in));
54 Bowl out = (Bowl)xstream.fromXML(expectedXml);
55 assertSame(out.fruit, PolymorphicEnum.B);
56 }
57
58 static class TypeWithEnums {
59 PolymorphicEnum poly;
60 @XStreamAsAttribute
61 SimpleEnum simple;
62 BigEnum big;
63 }
64
65 public void testSupportsEnumAsAttribute() {
66 xstream.alias("type", TypeWithEnums.class);
67 xstream.useAttributeFor(PolymorphicEnum.class);
68 xstream.autodetectAnnotations(true);
69 String expectedXml = "" // force format
70 + "<type poly=\"B\" simple=\"GREEN\">\n"
71 + " <big>C3</big>\n"
72 + "</type>";
73 TypeWithEnums in = new TypeWithEnums();
74 in.poly = PolymorphicEnum.B;
75 in.simple = SimpleEnum.GREEN;
76 in.big = BigEnum.C3;
77 assertEquals(expectedXml, xstream.toXML(in));
78 TypeWithEnums out = (TypeWithEnums)xstream.fromXML(expectedXml);
79 assertSame(out.poly, PolymorphicEnum.B);
80 assertSame(out.simple, SimpleEnum.GREEN);
81 }
82
83 public void testEnumsAreImmutable() {
84 List in = new ArrayList();
85 in.add(SimpleEnum.GREEN);
86 in.add(SimpleEnum.GREEN);
87 in.add(PolymorphicEnum.A);
88 in.add(PolymorphicEnum.A);
89 String expectedXml = ""
90 + "<list>\n"
91 + " <simple>GREEN</simple>\n"
92 + " <simple>GREEN</simple>\n"
93 + " <polymorphic>A</polymorphic>\n"
94 + " <polymorphic>A</polymorphic>\n"
95 + "</list>";
96 assertEquals(expectedXml, xstream.toXML(in));
97 assertEquals(in, xstream.fromXML(expectedXml));
98 }
99 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 06. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 import com.thoughtworks.xstream.XStream;
14 import junit.framework.TestCase;
15
16 import java.util.EnumSet;
17
18 public class EnumSetConverterTest extends TestCase {
19
20 private XStream xstream;
21
22 protected void setUp() throws Exception {
23 super.setUp();
24 xstream = new XStream();
25 }
26
27 public void testPutsEnumsInCompactCommaSeparatedString() {
28 xstream.alias("simple", SimpleEnum.class);
29 EnumSet<SimpleEnum> set = EnumSet.of(SimpleEnum.GREEN, SimpleEnum.BLUE);
30
31 String expectedXml = "<enum-set enum-type=\"simple\">GREEN,BLUE</enum-set>";
32
33 assertEquals(expectedXml, xstream.toXML(set));
34 assertEquals(set, xstream.fromXML(expectedXml));
35 }
36
37 public void testSupportsJumboEnumSetsForMoreThan64Elements() {
38 xstream.alias("big", BigEnum.class);
39 EnumSet<BigEnum> jumboSet = EnumSet.allOf(BigEnum.class);
40
41 String expectedXml = "<enum-set enum-type=\"big\">" +
42 "A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1," +
43 "A2,B2,C2,D2,E2,F2,G2,H2,I2,J2,K2,L2,M2,N2,O2,P2,Q2,R2,S2,T2,U2,V2,W2,X2,Y2,Z2," +
44 "A3,B3,C3,D3,E3,F3,G3,H3,I3,J3,K3,L3,M3,N3,O3,P3,Q3,R3,S3,T3,U3,V3,W3,X3,Y3,Z3" +
45 "</enum-set>";
46
47 assertEquals(expectedXml, xstream.toXML(jumboSet));
48 assertEquals(jumboSet, xstream.fromXML(expectedXml));
49 }
50
51 public void testSupportsPolymorphicEnums() {
52 xstream.alias("poly", PolymorphicEnum.class);
53 EnumSet<PolymorphicEnum> set = EnumSet.allOf(PolymorphicEnum.class);
54
55 String expectedXml = "<enum-set enum-type=\"poly\">A,B,C</enum-set>";
56
57 assertEquals(expectedXml, xstream.toXML(set));
58 assertEquals(set, xstream.fromXML(expectedXml));
59 }
60
61 public void testEmptyEnumSet() {
62 xstream.alias("simple", SimpleEnum.class);
63 EnumSet<SimpleEnum> set = EnumSet.noneOf(SimpleEnum.class);
64
65 String expectedXml = "<enum-set enum-type=\"simple\"></enum-set>";
66
67 assertEquals(expectedXml, xstream.toXML(set));
68 assertEquals(set, xstream.fromXML(expectedXml));
69 }
70
71 }
0 /*
1 * Copyright (C) 2013 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 14. March 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 import java.util.HashMap;
13 import java.util.Map;
14
15 import com.thoughtworks.xstream.XStream;
16 import junit.framework.TestCase;
17
18
19 // ***** READ THIS *****
20 // This class will only compile with JDK 1.5.0 or above as it test Java enums.
21 // If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it.
22
23 /**
24 * @author J&ouml;rg Schaible
25 */
26 public class EnumToStringConverterTest extends TestCase {
27
28 private XStream xstream;
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 xstream = new XStream();
33 xstream.alias("simple", SimpleEnum.class);
34 xstream.alias("big", BigEnum.class);
35 xstream.alias("polymorphic", PolymorphicEnum.class);
36
37 Map<String, SimpleEnum> map = new HashMap<String, SimpleEnum>();
38 map.put("0xff0000", SimpleEnum.RED);
39 map.put("0x00ff00", SimpleEnum.GREEN);
40 map.put("0x0000ff", SimpleEnum.BLUE);
41 xstream.registerConverter(new EnumToStringConverter<SimpleEnum>(SimpleEnum.class, map));
42 xstream.registerConverter(new EnumToStringConverter<BigEnum>(BigEnum.class));
43 xstream.registerConverter(new EnumToStringConverter<PolymorphicEnum>(
44 PolymorphicEnum.class));
45 }
46
47 public void testMapsEnumToProvidedStringValue() {
48 String expectedXml = "<simple>0x00ff00</simple>";
49 SimpleEnum in = SimpleEnum.GREEN;
50 assertEquals(expectedXml, xstream.toXML(in));
51 assertEquals(in, xstream.fromXML(expectedXml));
52 }
53
54 public void testMapsEnumToStringDefaultValue() {
55 String expectedXml = "<big>C3</big>";
56 BigEnum in = BigEnum.C3;
57 assertEquals(expectedXml, xstream.toXML(in));
58 assertEquals(in, xstream.fromXML(expectedXml));
59 }
60
61 public void testMapsToPolymorphicStringValue() {
62 String expectedXml = "<polymorphic>banana</polymorphic>";
63 PolymorphicEnum in = PolymorphicEnum.B;
64 assertEquals(expectedXml, xstream.toXML(in));
65 assertEquals(in, xstream.fromXML(expectedXml));
66 }
67
68 }
0 /*
1 * Copyright (C) 2008 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 11. February 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.enums;
11
12 /**
13 * A fruit used as base for the polymorphic enum.
14 *
15 * @author J&ouml;rg Schaible
16 */
17 public interface Fruit {
18
19 String fruit();
20 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2013 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 06. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 enum PolymorphicEnum implements Fruit {
14 A() {
15 public String fruit() {
16 return "apple";
17 }
18 },
19 B() {
20 public String fruit() {
21 return "banana";
22 }
23 },
24 C;
25
26 public String fruit() {
27 return "unknown";
28 }
29
30 @Override
31 public String toString() {
32 return fruit();
33 }
34 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.enums;
12
13 enum SimpleEnum {
14 RED, GREEN, BLUE;
15 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 28. July 2006 by Guilerme Silveira
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.nio.charset.Charset;
14
15 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
16
17 public class CharsetConverterTest extends AbstractAcceptanceTest {
18
19 public void testHandlesSimpleCharset() {
20 assertBothWays(Charset.forName("US-ASCII"), "<charset>US-ASCII</charset>");
21 }
22
23 }
0 /*
1 * Copyright (C) 2007 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. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.converters.SingleValueConverter;
13
14 import junit.framework.TestCase;
15
16 import javax.xml.datatype.DatatypeFactory;
17 import javax.xml.datatype.Duration;
18
19
20 /**
21 * @author John Kristian
22 */
23 public class DurationConverterTest extends TestCase {
24 private static final String[] STRINGS = {"-P1Y2M3DT4H5M6.7S", "P1Y", "PT1H2M"};
25
26 public void testConversion() throws Exception {
27 final SingleValueConverter converter = new DurationConverter();
28 DatatypeFactory factory = DatatypeFactory.newInstance();
29 for (int i = 0; i < STRINGS.length; i++) {
30 final String s = STRINGS[i];
31 Duration o = factory.newDuration(s);
32 assertEquals(s, converter.toString(o));
33 assertEquals(o, converter.fromString(s));
34 }
35 }
36
37 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.acceptance.objects.StandardObject;
15
16 public class EncodedByteArrayConverterTest extends AbstractAcceptanceTest {
17
18 public void testMarshallsCharArrayAsSingleString() {
19 byte[] input = {0, 120, -124, 22, 33, 0, 5};
20 String expected = "<byte-array>AHiEFiEABQ==</byte-array>";
21
22 assertBothWays(input, expected);
23 }
24
25 public void testUnmarshallsOldByteArraysThatHaveNotBeenEncoding() {
26 // for backwards compatability
27 String input = ""
28 + "<byte-array>\n"
29 + " <byte>0</byte>\n"
30 + " <byte>120</byte>\n"
31 + " <byte>-124</byte>\n"
32 + " <byte>22</byte>\n"
33 + " <byte>33</byte>\n"
34 + " <byte>0</byte>\n"
35 + " <byte>5</byte>\n"
36 + "</byte-array>";
37
38 byte[] expected = {0, 120, -124, 22, 33, 0, 5};
39 assertByteArrayEquals(expected, (byte[])xstream.fromXML(input));
40 }
41
42 public void testUnmarshallsEmptyByteArrays() {
43 byte[] input = {};
44 String expected = "<byte-array></byte-array>";
45
46 assertBothWays(input, expected);
47 }
48
49 public static class TestObject extends StandardObject {
50 private byte[] data;
51 private boolean something;
52 }
53
54 public void testUnmarshallsEmptyByteArrayAsFieldOfAnotherObject() {
55 // exposes a weird bug that was in the XML pull readers.
56 TestObject in = new TestObject();
57 in.data = new byte[0];
58
59 xstream.alias("TestObject", TestObject.class);
60 String expectedXml = "" +
61 "<TestObject>\n" +
62 " <data></data>\n" +
63 " <something>false</something>\n" +
64 "</TestObject>";
65 assertBothWays(in, expectedXml);
66 }
67
68 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 08. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
15 import com.thoughtworks.xstream.core.JVM;
16
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 import java.awt.Font;
22 import java.awt.Toolkit;
23 import java.awt.font.TextAttribute;
24 import java.util.Map;
25
26 public class FontConverterTest extends TestCase {
27 private XStream xstream;
28 private Font in;
29
30 public static Test suite() {
31 // Only try to run this test case if graphics environment is available
32 try {
33 new Font("Arial", Font.BOLD, 20);
34 return new TestSuite(FontConverterTest.class);
35 } catch (Throwable t) {
36 return new TestSuite();
37 }
38 }
39
40 protected void setUp() throws Exception {
41 super.setUp();
42 // fonts should be serializable also with pure Java
43 xstream = new XStream(new PureJavaReflectionProvider());
44 in = new Font("Arial", Font.BOLD, 20);
45 }
46
47 public void testConvertsToFontThatEqualsOriginal() {
48 // execute
49 Font out = (Font) xstream.fromXML(xstream.toXML(in));
50
51 // assert
52 assertEquals(in, out);
53 }
54
55 public void testProducesFontThatHasTheSameAttributes() {
56 // execute
57 Font out = (Font) xstream.fromXML(xstream.toXML(in));
58
59 // assert
60 Map inAttributes = in.getAttributes();
61 Map outAttributes = out.getAttributes();
62
63 // these attributes don't have a valid .equals() method (bad Sun!), so we can't use them in the test.
64 if (!JVM.is16()) { // it seems even old 1.5 JDKs fail here (Codehaus Bamboo)
65 inAttributes.remove(TextAttribute.TRANSFORM);
66 outAttributes.remove(TextAttribute.TRANSFORM);
67 }
68
69 assertEquals(inAttributes, outAttributes);
70 }
71
72 public void testUnmarshalsCurrentFormat() {
73 // XML representation since 1.4.5
74 String xml= (""
75 + "<awt-font>\n"
76 + " <posture class='null'/>\n"
77 + " <weight class='float'>2.0</weight>\n"
78 + " <superscript class='null'/>\n"
79 + " <transform class='null'/>\n"
80 + " <size class='float'>20.0</size>\n"
81 + " <width class='null'/>\n"
82 + " <family class='string'>Arial</family>\n"
83 + "</awt-font>").replace('\'', '"');
84 Font out = (Font) xstream.fromXML(xml);
85
86 // assert
87 assertEquals(in, out);
88 }
89
90 public void testUnmarshalsOldFormat() {
91 // XML representation pre 1.4.5
92 String xml = ""
93 + "<awt-font>\n"
94 + " <attributes>\n"
95 + " <entry>\n"
96 + " <awt-text-attribute>posture</awt-text-attribute>\n"
97 + " <null/>\n"
98 + " </entry>\n"
99 + " <entry>\n"
100 + " <awt-text-attribute>weight</awt-text-attribute>\n"
101 + " <float>2.0</float>\n"
102 + " </entry>\n"
103 + " <entry>\n"
104 + " <awt-text-attribute>superscript</awt-text-attribute>\n"
105 + " <null/>\n"
106 + " </entry>\n"
107 + " <entry>\n"
108 + " <awt-text-attribute>transform</awt-text-attribute>\n"
109 + " <null/>\n"
110 + " </entry>\n"
111 + " <entry>\n"
112 + " <awt-text-attribute>size</awt-text-attribute>\n"
113 + " <float>20.0</float>\n"
114 + " </entry>\n"
115 + " <entry>\n"
116 + " <awt-text-attribute>width</awt-text-attribute>\n"
117 + " <null/>\n"
118 + " </entry>\n"
119 + " <entry>\n"
120 + " <awt-text-attribute>family</awt-text-attribute>\n"
121 + " <string>Arial</string>\n"
122 + " </entry>\n"
123 + " </attributes>\n"
124 + "</awt-font>";
125 Font out = (Font) xstream.fromXML(xml);
126
127 // assert
128 assertEquals(in, out);
129 }
130
131 public void testCorrectlyInitializesFontToPreventJvmCrash() {
132 // If a font has not been constructed in the correct way, the JVM crashes horribly through some internal
133 // native code, whenever the font is rendered to screen.
134
135 // execute
136 Font out = (Font) xstream.fromXML(xstream.toXML(in));
137
138 Toolkit.getDefaultToolkit().getFontMetrics(out);
139 // if the JVM hasn't crashed yet, we're good.
140 }
141 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 14. May 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import junit.framework.TestCase;
16
17 import java.util.Calendar;
18 import java.util.TimeZone;
19
20 /**
21 * @author J&ouml;rg Schaible
22 */
23 public class GregorianCalendarConverterTest extends TestCase {
24
25 public void testCalendar() {
26 final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
27 final XStream xstream = new XStream();
28 final String xml = xstream.toXML(cal);
29 final Calendar serialized = (Calendar)xstream.fromXML(xml);
30 assertEquals(cal, serialized);
31 }
32
33 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 22. November 2004 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
14
15 import junit.framework.TestCase;
16
17 import java.text.ParseException;
18 import java.text.SimpleDateFormat;
19 import java.util.Calendar;
20 import java.util.Date;
21
22 public class ISO8601DateConverterTest extends TestCase {
23
24 private ISO8601DateConverter converter;
25
26 protected void setUp() throws Exception {
27 super.setUp();
28 converter = new ISO8601DateConverter();
29
30 // Ensure that this test always run as if it were in the EST timezone.
31 // This prevents failures when running the tests in different zones.
32 // Note: 'EST' has no relevance - it was just a randomly chosen zone.
33 TimeZoneChanger.change("EST");
34 }
35
36 protected void tearDown() throws Exception {
37 TimeZoneChanger.reset();
38 super.tearDown();
39 }
40
41 public void testUnmashallsInCorrectTimeZone() {
42 // setup
43 Date in = new Date();
44
45 // execute
46 String text = converter.toString(in);
47 Date out = (Date) converter.fromString(text);
48
49 // verify
50 assertEquals(in, out);
51 assertEquals(in.toString(), out.toString());
52 assertEquals(in.getTime(), out.getTime());
53 }
54
55 public void testUnmarshallsISOFormatInUTC() throws ParseException {
56 // setup
57 String isoFormat = "1993-02-14T13:10:30-05:00";
58 String simpleFormat = "1993-02-14 13:10:30EST";
59 // execute
60 Date out = (Date) converter.fromString(isoFormat);
61 Date control = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(simpleFormat);
62 // verify for EST
63 assertEquals("Sun Feb 14 13:10:30 EST 1993", out.toString());
64 assertEquals(control, out);
65 }
66
67 public void testUnmarshallsISOFormatInLocalTime() {
68 // setup
69 String isoFormat = "1993-02-14T13:10:30";
70 // execute
71 Date out = (Date) converter.fromString(isoFormat);
72 // verify for EST
73 Calendar calendar = Calendar.getInstance();
74 calendar.set(1993, 1, 14, 13, 10, 30);
75 assertEquals(calendar.getTime().toString(), out.toString());
76 }
77 }
0 /*
1 * 2013 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. June 2013 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
13
14 import junit.framework.TestCase;
15
16 import java.util.Calendar;
17 import java.util.GregorianCalendar;
18 import java.util.Locale;
19
20 public class ISO8601GregorianCalendarConverter17Test extends TestCase {
21
22 protected void setUp() throws Exception {
23 super.setUp();
24
25 // Ensure that this test always run as if it were in the timezone of Panama.
26 // This prevents failures when running the tests in different zones.
27 // Note: 'America/Panama' has no relevance - it was just a randomly chosen zone.
28 TimeZoneChanger.change("America/Panama");
29 }
30
31 protected void tearDown() throws Exception {
32 TimeZoneChanger.reset();
33 super.tearDown();
34 }
35
36 public void testCanLoadTimeWithDefaultDifferentLocaleForFormat() {
37 final ISO8601GregorianCalendarConverter converter = new ISO8601GregorianCalendarConverter();
38
39 Locale defaultLocale = Locale.getDefault();
40 Locale defaultLocaleForFormat = Locale.getDefault(Locale.Category.FORMAT);
41 try {
42 Locale.setDefault(Locale.US);
43 Locale.setDefault(Locale.Category.FORMAT, Locale.GERMANY);
44 Calendar in = new GregorianCalendar(2013, Calendar.JUNE, 17, 16, 0, 0);
45
46 String converterXML = converter.toString(in);
47 Calendar out = (Calendar) converter.fromString(converterXML);
48 assertEquals(in, out);
49 } finally {
50 Locale.setDefault(defaultLocale);
51 Locale.setDefault(defaultLocaleForFormat);
52 }
53 }
54 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 03. October 2005 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
15
16 import junit.framework.TestCase;
17
18 import org.joda.time.DateTime;
19
20 import java.util.ArrayList;
21 import java.util.Calendar;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.TimeZone;
25
26 public class ISO8601GregorianCalendarConverterTest extends TestCase {
27
28 private ISO8601GregorianCalendarConverter converter;
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 converter = new ISO8601GregorianCalendarConverter();
33
34 // Ensure that this test always run as if it were in the timezone of Panama.
35 // This prevents failures when running the tests in different zones.
36 // Note: 'America/Panama' has no relevance - it was just a randomly chosen zone.
37 TimeZoneChanger.change("America/Panama");
38 }
39
40 protected void tearDown() throws Exception {
41 TimeZoneChanger.reset();
42 super.tearDown();
43 }
44
45 public void testRetainsDetailDownToMillisecondLevel() {
46 // setup
47 Calendar in = Calendar.getInstance();
48
49 // execute
50 String text = converter.toString(in);
51 Calendar out = (Calendar) converter.fromString(text);
52
53 // verify
54 assertEquals(in, out);
55 }
56
57 public void testSavedTimeIsInUTC() {
58 Calendar in = Calendar.getInstance();
59 final String iso8601;
60 iso8601 = new DateTime(in).toString();
61 String converterXML = converter.toString(in);
62 assertEquals(iso8601, converterXML);
63
64 Calendar out = (Calendar) converter.fromString(converterXML);
65 assertEquals(in, out);
66 }
67
68 public void testCanLoadTimeInDifferentTimeZone() {
69 Calendar in = Calendar.getInstance();
70 String converterXML = converter.toString(in);
71
72 TimeZone.setDefault(TimeZone.getTimeZone("Europe/Moscow"));
73 Calendar timeInMoscow = Calendar.getInstance();
74 timeInMoscow.setTime(in.getTime());
75 Calendar out = (Calendar) converter.fromString(converterXML);
76 assertEquals(timeInMoscow, out);
77 }
78
79 public void testCalendarWithExplicitTimeZone() {
80 Calendar timeInMoscow = Calendar.getInstance();
81 timeInMoscow.set(2010, 6, 3, 10, 20, 36);
82 timeInMoscow.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));
83
84 String converterXML = converter.toString(timeInMoscow);
85 Calendar out = (Calendar) converter.fromString(converterXML);
86 assertEquals(timeInMoscow.getTimeInMillis(), out.getTimeInMillis());
87
88 out.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));
89 assertEquals(timeInMoscow, out);
90 }
91
92 public void testIsThreadSafe() throws InterruptedException {
93 final List results = Collections.synchronizedList(new ArrayList());
94 final ISO8601GregorianCalendarConverter converter = new ISO8601GregorianCalendarConverter();
95 final Object monitor = new Object();
96 final int numberOfCallsPerThread = 20;
97 final int numberOfThreads = 20;
98
99 // spawn some concurrent threads, that hammer the converter
100 Runnable runnable = new Runnable() {
101 public void run() {
102 for (int i = 0; i < numberOfCallsPerThread; i++) {
103 try {
104 converter.fromString("1993-02-14T13:10:30");
105 results.add("PASS");
106 } catch (ConversionException e) {
107 results.add("FAIL");
108 } finally {
109 synchronized (monitor) {
110 monitor.notifyAll();
111 }
112 }
113 }
114 }
115 };
116 for (int i = 0; i < numberOfThreads; i++) {
117 new Thread(runnable).start();
118 }
119
120 // wait for all results
121 while (results.size() < numberOfThreads * numberOfCallsPerThread) {
122 synchronized (monitor) {
123 monitor.wait(100);
124 }
125 }
126
127 assertTrue("Nothing succeded", results.contains("PASS"));
128 assertFalse("At least one attempt failed", results.contains("FAIL"));
129 }
130 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. October 2005 by Joerg Schaible
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
15
16 import junit.framework.TestCase;
17
18 import java.sql.Timestamp;
19
20
21 /**
22 * @author Chung-Onn Cheong
23 * @author J&ouml;rg Schaible
24 */
25 public class ISO8601SqlTimestampConverterTest extends TestCase {
26 private ISO8601SqlTimestampConverter converter;
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 converter = new ISO8601SqlTimestampConverter();
31
32 // Ensure that this test always run as if it were in the EST timezone.
33 // This prevents failures when running the tests in different zones.
34 // Note: 'EST' has no relevance - it was just a randomly chosen zone.
35 TimeZoneChanger.change("EST");
36 }
37
38 protected void tearDown() throws Exception {
39 TimeZoneChanger.reset();
40 super.tearDown();
41 }
42
43 public void testISO8601SqlTimestamp() {
44 XStream xs = new XStream();
45 xs.registerConverter(converter);
46
47 long currentTime = System.currentTimeMillis();
48
49 Timestamp ts1 = new Timestamp(currentTime);
50 String xmlString = xs.toXML(ts1);
51
52 Timestamp ts2 = (Timestamp)xs.fromXML(xmlString);
53
54 assertEquals("ISO Timestamp Converted is not the same ", ts1, ts2);
55 assertEquals(
56 "Current time not equal to converted timestamp", currentTime,
57 (ts2.getTime() / 1000) * 1000 + ts2.getNanos() / 1000000);
58 }
59
60 public void testISO8601SqlTimestampWith1Milli() {
61 XStream xs = new XStream();
62 xs.registerConverter(converter);
63
64 long currentTime = (System.currentTimeMillis() / 1000 * 1000) + 1;
65
66 Timestamp ts1 = new Timestamp(currentTime);
67 String xmlString = xs.toXML(ts1);
68
69 Timestamp ts2 = (Timestamp)xs.fromXML(xmlString);
70
71 assertEquals("ISO Timestamp Converted is not the same ", ts1, ts2);
72 assertEquals(
73 "Current time not equal to converted timestamp", currentTime,
74 (ts2.getTime() / 1000) * 1000 + ts2.getNanos() / 1000000);
75 }
76
77 public void testISO8601SqlTimestampWithNanos() {
78 XStream xs = new XStream();
79 xs.registerConverter(converter);
80
81 Timestamp ts1 = new Timestamp(System.currentTimeMillis());
82 ts1.setNanos(987654321);
83 String xmlString = xs.toXML(ts1);
84
85 Timestamp ts2 = (Timestamp)xs.fromXML(xmlString);
86
87 assertEquals("ISO Timestamp Converted is not the same ", ts1, ts2);
88 assertEquals("Nanos are not equal", ts1.getNanos(), ts2.getNanos());
89 }
90
91 public void testTimestampWithoutFraction() {
92 String isoFormat = "1993-02-14T13:10:30-05:00";
93 Timestamp out = (Timestamp)converter.fromString(isoFormat);
94 assertEquals("1993-02-14T13:10:30.000000000-05:00", converter.toString(out));
95 }
96 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2014 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 16. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 public class JavaClassConverterTest extends AbstractAcceptanceTest {
16
17 public void testHandlesPrimitivesAndWrappers() {
18 assertBothWays(int.class, "<java-class>int</java-class>");
19 assertBothWays(Integer.class, "<java-class>java.lang.Integer</java-class>");
20
21 assertBothWays(boolean.class, "<java-class>boolean</java-class>");
22 assertBothWays(Boolean.class, "<java-class>java.lang.Boolean</java-class>");
23
24 assertBothWays(void.class, "<java-class>void</java-class>");
25 assertBothWays(Void.class, "<java-class>java.lang.Void</java-class>");
26 }
27
28 public static class A {}
29
30 public void testHandlesArrays() {
31 assertBothWays(A[].class,
32 "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
33 assertBothWays(int[].class,
34 "<java-class>[I</java-class>");
35 }
36
37 public void testHandlesMultidimensioanlArrays() {
38 assertBothWays(A[][].class,
39 "<java-class>[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
40 assertBothWays(A[][][][].class,
41 "<java-class>[[[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
42
43 assertBothWays(int[][].class,
44 "<java-class>[[I</java-class>");
45 assertBothWays(int[][][][].class,
46 "<java-class>[[[[I</java-class>");
47 }
48
49 public static class B {}
50
51 public void testResolvesUnloadedClassThatIsAnArray() {
52 // subtleties in classloaders make this an awkward one
53 String input = "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;</java-class>";
54 Class result = (Class) xstream.fromXML(input);
55 assertEquals("[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;", result.getName());
56 assertTrue("Should be an array", result.isArray());
57 assertEquals("com.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B", result.getComponentType().getName());
58 }
59
60 public void testHandlesJavaClassArray() {
61 xstream.registerConverter(new JavaClassConverter(xstream.getMapper()){});
62
63 Class[] classes = new Class[] {
64 Object.class,
65 Comparable.class,
66 null,
67 Throwable.class
68 };
69
70 assertBothWays(classes, ""
71 + "<java-class-array>\n"
72 + " <java-class>object</java-class>\n"
73 + " <java-class>java.lang.Comparable</java-class>\n"
74 + " <null/>\n"
75 + " <java-class>java.lang.Throwable</java-class>\n"
76 + "</java-class-array>");
77 }
78 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 23. December 2004 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.Method;
17
18 public class JavaMethodConverterTest extends AbstractAcceptanceTest {
19
20 public void testSupportsPublicMethods() throws Exception {
21 Method method = AnIntClass.class.getDeclaredMethod("setValue", new Class[]{Integer.TYPE});
22 String expected =
23 "<method>\n" +
24 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
25 " <name>setValue</name>\n" +
26 " <parameter-types>\n" +
27 " <class>int</class>\n" +
28 " </parameter-types>\n" +
29 "</method>";
30 assertBothWays(method, expected);
31 }
32
33 public void testSupportsPrivateMethods() throws NoSuchMethodException {
34 Method method = AnIntClass.class.getDeclaredMethod("privateMethod", new Class[]{});
35 String expected =
36 "<method>\n" +
37 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
38 " <name>privateMethod</name>\n" +
39 " <parameter-types/>\n" +
40 "</method>";
41 assertBothWays(method, expected);
42 }
43
44 public void testSupportsConstructor() throws NoSuchMethodException {
45 Constructor constructor = AnIntClass.class.getDeclaredConstructor(new Class[] { int.class });
46 String expected =
47 "<constructor>\n" +
48 " <class>com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest$AnIntClass</class>\n" +
49 " <parameter-types>\n" +
50 " <class>int</class>\n" +
51 " </parameter-types>\n" +
52 "</constructor>";
53 assertBothWays(constructor, expected);
54 }
55
56 static class AnIntClass {
57 private int value = 0;
58
59 protected AnIntClass(int integer) {
60 this.value = integer;
61 }
62
63 public int getValue() {
64 return value;
65 }
66
67 public void setValue(int integer) {
68 this.value = integer;
69 }
70
71 private void privateMethod() {
72 }
73 }
74 }
0 /*
1 * Copyright (C) 2007 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 20. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.extended;
11
12 import com.thoughtworks.acceptance.objects.Software;
13 import com.thoughtworks.xstream.converters.SingleValueConverter;
14
15 import junit.framework.TestCase;
16
17 import java.beans.PropertyEditorSupport;
18 import java.util.HashMap;
19 import java.util.Map;
20
21
22 /**
23 * @author J&ouml;rg Schaible
24 */
25 public class PropertyEditorCapableConverterTest extends TestCase {
26
27 public static class SoftwarePropertyEditor extends PropertyEditorSupport {
28
29 public String getAsText() {
30 Software software = (Software)getValue();
31 return software.vendor + ":" + software.name;
32 }
33
34 public void setAsText(String text) throws IllegalArgumentException {
35 int idx = text.indexOf(':');
36 setValue(new Software(text.substring(0, idx), text.substring(idx + 1)));
37 }
38
39 }
40
41 public void testCanBeUsedForCustomTypes() {
42 Software software = new Software("Joe Walnes", "XStream");
43 SingleValueConverter converter = new PropertyEditorCapableConverter(
44 SoftwarePropertyEditor.class, Software.class);
45 assertTrue(converter.canConvert(Software.class));
46 assertEquals("Joe Walnes:XStream", converter.toString(software));
47 assertEquals(software, converter.fromString("Joe Walnes:XStream"));
48 }
49
50 public void testConcurrentConversion() throws InterruptedException {
51 final SingleValueConverter converter = new PropertyEditorCapableConverter(
52 SoftwarePropertyEditor.class, Software.class);
53
54 final Map exceptions = new HashMap();
55 final ThreadGroup tg = new ThreadGroup(getName()) {
56 public void uncaughtException(Thread t, Throwable e) {
57 exceptions.put(e, t.getName());
58 super.uncaughtException(t, e);
59 }
60 };
61
62 final Map references = new HashMap();
63 final int[] counter = new int[1];
64 counter[0] = 0;
65 final Thread[] threads = new Thread[10];
66 for (int i = 0; i < threads.length; ++i) {
67 final String name = "JUnit Thread:" + i;
68 references.put(name, new Software("JUnit Thread", Integer.toString(i)));
69 threads[i] = new Thread(tg, name) {
70
71 public void run() {
72 int i = 0;
73 try {
74 synchronized (this) {
75 notifyAll();
76 wait();
77 }
78 final Software software = (Software)references.get(Thread
79 .currentThread()
80 .getName());
81 while (i < 1000 && !interrupted()) {
82 String formatted = converter.toString(software);
83 Thread.yield();
84 assertEquals(software, converter.fromString(formatted));
85 ++i;
86 }
87 } catch (InterruptedException e) {
88 fail("Unexpected InterruptedException");
89 }
90 synchronized (counter) {
91 counter[0] += i;
92 }
93 }
94
95 };
96 }
97
98 for (int i = 0; i < threads.length; ++i) {
99 synchronized (threads[i]) {
100 threads[i].start();
101 threads[i].wait();
102 }
103 }
104
105 for (int i = 0; i < threads.length; ++i) {
106 synchronized (threads[i]) {
107 threads[i].notifyAll();
108 }
109 }
110
111 Thread.sleep(1000);
112
113 for (int i = 0; i < threads.length; ++i) {
114 threads[i].interrupt();
115 }
116 for (int i = 0; i < threads.length; ++i) {
117 synchronized (threads[i]) {
118 threads[i].join();
119 }
120 }
121
122 assertEquals("Exceptions have been thrown: " + exceptions, 0, exceptions.size());
123 assertTrue(
124 "Each thread should have made at least 1 conversion", counter[0] >= threads.length);
125 }
126
127 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 28. July 2006 by Guilerme Silveira
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.util.regex.Pattern;
14
15 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
16
17 public class RegexPatternConverterTest extends AbstractAcceptanceTest {
18
19 public void testHandlesSimplePattern() {
20 Pattern root = Pattern.compile(".*");
21 String xml = "<java.util.regex.Pattern>\n"
22 + " <pattern>.*</pattern>\n" + " <flags>0</flags>\n"
23 + "</java.util.regex.Pattern>";
24 assertBothWays(root, xml);
25 }
26
27 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 29. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 /**
16 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
17 * @author Joe Walnes
18 */
19 public class StackTraceElementConverterTest extends AbstractAcceptanceTest {
20
21 private StackTraceElementFactory factory = new StackTraceElementFactory();
22
23 public void testSerializesStackTraceElement() {
24 StackTraceElement trace = factory.unknownSourceElement("com.blah.SomeClass", "someMethod");
25 String expectedXml = "<trace>com.blah.SomeClass.someMethod(Unknown Source)</trace>";
26 assertBothWays(trace, expectedXml);
27 }
28
29 public void testIncludesDebugInformation() {
30 StackTraceElement trace = factory.element("com.blah.SomeClass", "someMethod", "SomeClass.java", 22);
31 String expectedXml = "<trace>com.blah.SomeClass.someMethod(SomeClass.java:22)</trace>";
32 assertBothWays(trace, expectedXml);
33 }
34
35 public void testIncludesPartialDebugInformation() {
36 StackTraceElement trace = factory.element("com.blah.SomeClass", "someMethod", "SomeClass.java");
37 String expectedXml = "<trace>com.blah.SomeClass.someMethod(SomeClass.java)</trace>";
38 assertBothWays(trace, expectedXml);
39 }
40
41 public void testIncludesNativeMethods() {
42 StackTraceElement trace = factory.nativeMethodElement("com.blah.SomeClass", "someMethod");
43 String expectedXml = "<trace>com.blah.SomeClass.someMethod(Native Method)</trace>";
44 assertBothWays(trace, expectedXml);
45 }
46
47 public void testSupportsInnerClasses() {
48 StackTraceElement trace = factory.unknownSourceElement("com.blah.SomeClass$Inner$2", "someMethod");
49 String expectedXml = "<trace>com.blah.SomeClass$Inner$2.someMethod(Unknown Source)</trace>";
50 assertBothWays(trace, expectedXml);
51 }
52
53 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 29. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.xstream.XStream;
15
16 import java.math.BigDecimal;
17
18 /**
19 * @author <a href="mailto:boxley@thoughtworks.com">B. K. Oxley (binkley)</a>
20 */
21 public class ThrowableConverterTest extends AbstractAcceptanceTest {
22
23 public void testDeserializesThrowable() {
24 Throwable expected = new Throwable();
25 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(expected));
26 assertThrowableEquals(expected, result);
27 }
28
29 public void testDeserializesException() {
30 Exception expected = new Exception();
31 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(expected));
32 assertThrowableEquals(expected, result);
33 }
34
35 public void testIncludesMessage() {
36 Throwable expected = new Throwable("A MESSAGE");
37 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(expected));
38 assertThrowableEquals(expected, result);
39 }
40
41 public void testIncludesCause() {
42 Throwable expected = new Throwable(new Throwable());
43 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(expected));
44 assertThrowableEquals(expected, result);
45 }
46
47 public void testIncludesCauseAndMessage() {
48 Throwable expected = new Throwable("MESSAGE", new Throwable("CAUSE MESSAGE"));
49 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(expected));
50 assertThrowableEquals(expected, result);
51 }
52
53 public void testIncludesStackTrace() {
54 try {
55 throw new Exception();
56 } catch (Exception exception) {
57 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(exception));
58 assertThrowableEquals(exception, result);
59 }
60 }
61
62 public static class MyException extends Exception {
63 private BigDecimal number;
64
65 public MyException(String msg, BigDecimal number) {
66 super(msg);
67 this.number = number;
68 }
69
70 public boolean equals(Object o) {
71 return super.equals(o) && o instanceof MyException && number.equals(((MyException)o).number);
72 }
73
74 }
75
76 public void testSerializesExtraFields() {
77 try {
78 throw new MyException("A MESSAGE", new BigDecimal(123.4));
79 } catch (MyException exception) {
80 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(exception));
81 assertThrowableEquals(exception, result);
82 }
83 }
84
85 public void testSerializesWithNoSelfReferenceForUninitializedCauseInJdk14() {
86 xstream.setMode(XStream.NO_REFERENCES);
87 try {
88 throw new RuntimeException("Without cause");
89 } catch (RuntimeException exception) {
90 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(exception));
91 assertThrowableEquals(exception, result);
92 assertNull(exception.getCause());
93 assertNull(result.getCause());
94 }
95 }
96
97 public void testSerializesWithInitializedCauseInJdk14() {
98 xstream.setMode(XStream.NO_REFERENCES);
99 try {
100 throw new RuntimeException("Without cause", null);
101 } catch (RuntimeException exception) {
102 Throwable result = (Throwable) xstream.fromXML(xstream.toXML(exception));
103 assertThrowableEquals(exception, result);
104 assertNull(exception.getCause());
105 assertNull(result.getCause());
106 }
107 }
108
109 private static void assertThrowableEquals(final Throwable a,
110 final Throwable b) {
111 assertBoth(a, b, new MoreAssertions() {
112 public void assertMoreSafely(final Object a,
113 final Object b) {
114 final Throwable ta = (Throwable) a, tb = (Throwable) b;
115 assertEquals(ta.getClass(), tb.getClass());
116 assertEquals(ta.getMessage(), tb.getMessage());
117 assertThrowableEquals(ta.getCause(), tb.getCause());
118 assertArrayEquals(ta.getStackTrace(), tb.getStackTrace());
119 }
120 });
121 }
122
123 private static void assertArrayEquals(final Object[] expected, final Object[] actual) {
124 StringBuffer expectedJoined = new StringBuffer();
125 StringBuffer actualJoined = new StringBuffer();
126 for (int i = 0; i < expected.length; i++) {
127 expectedJoined.append(expected[i]).append('\n');
128 }
129 for (int i = 0; i < actual.length; i++) {
130 // JRockit adds ":???" for invalid line number
131 actualJoined.append(actual[i].toString().replaceFirst(":\\?\\?\\?", "")).append('\n');
132 }
133 assertEquals(expectedJoined.toString(), actualJoined.toString());
134 }
135
136 private static void assertBoth(Object a, Object b, MoreAssertions moreAssertions) {
137 if (null == a) {
138 if (null == b) {
139 return;
140 } else {
141 fail("Expected null, but was <" + b + ">");
142 }
143 } else if (null == b) {
144 fail("Expected <" + a + "> but was null");
145 } else {
146 moreAssertions.assertMoreSafely(a, b);
147 }
148 }
149
150 private interface MoreAssertions {
151 void assertMoreSafely(final Object a, final Object b);
152 }
153
154 }
0 /*
1 * Copyright (C) 2011, 2013, 2014 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 30. July 2011 by Joerg Schaible
9 */
10
11 package com.thoughtworks.xstream.converters.extended;
12
13 import java.io.StringReader;
14 import java.io.StringWriter;
15
16 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
17 import com.thoughtworks.acceptance.objects.Software;
18 import com.thoughtworks.acceptance.someobjects.X;
19 import com.thoughtworks.acceptance.someobjects.Y;
20 import com.thoughtworks.xstream.converters.ConversionException;
21 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
22 import com.thoughtworks.xstream.converters.basic.IntConverter;
23 import com.thoughtworks.xstream.converters.basic.StringConverter;
24 import com.thoughtworks.xstream.converters.collections.ArrayConverter;
25 import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
26 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
27 import com.thoughtworks.xstream.converters.reflection.SunUnsafeReflectionProvider;
28 import com.thoughtworks.xstream.core.ClassLoaderReference;
29 import com.thoughtworks.xstream.core.DefaultConverterLookup;
30 import com.thoughtworks.xstream.core.TreeMarshaller;
31 import com.thoughtworks.xstream.core.TreeUnmarshaller;
32 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
33 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
34 import com.thoughtworks.xstream.io.xml.CompactWriter;
35 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
36 import com.thoughtworks.xstream.io.xml.XppDriver;
37 import com.thoughtworks.xstream.mapper.ArrayMapper;
38 import com.thoughtworks.xstream.mapper.ClassAliasingMapper;
39 import com.thoughtworks.xstream.mapper.DefaultImplementationsMapper;
40 import com.thoughtworks.xstream.mapper.DefaultMapper;
41 import com.thoughtworks.xstream.mapper.Mapper;
42
43 import junit.framework.TestCase;
44
45
46 /**
47 * Tests {@link ToAttributedValueConverter}.
48 *
49 * @author jos / last modified by $Author: joehni $
50 */
51 public class ToAttributedValueConverterTest extends TestCase {
52 private HierarchicalStreamDriver driver;
53 private DefaultConverterLookup converterLookup;
54 private ReflectionProvider reflectionProvider;
55 private Mapper mapper;
56
57 protected void setUp() throws Exception {
58 super.setUp();
59
60 final ClassAliasingMapper classAliasingMapper = new ClassAliasingMapper(
61 new DefaultMapper(new ClassLoaderReference(getClass().getClassLoader())));
62 classAliasingMapper.addClassAlias("x", X.class);
63 classAliasingMapper.addClassAlias("software", Software.class);
64 classAliasingMapper.addClassAlias("open-source", OpenSourceSoftware.class);
65 mapper = new DefaultImplementationsMapper(new ArrayMapper(classAliasingMapper));
66
67 reflectionProvider = new SunUnsafeReflectionProvider();
68 driver = new XppDriver();
69
70 converterLookup = new DefaultConverterLookup();
71 converterLookup.registerConverter(
72 new SingleValueConverterWrapper(new StringConverter()), 0);
73 converterLookup.registerConverter(
74 new SingleValueConverterWrapper(new IntConverter()), 0);
75 converterLookup.registerConverter(new ArrayConverter(mapper), 0);
76 converterLookup.registerConverter(
77 new ReflectionConverter(mapper, reflectionProvider), -1);
78 }
79
80 /**
81 * Tests conversion with field defined in converted class.
82 */
83 public void testWithValueInConvertedClass() {
84 converterLookup.registerConverter(new ToAttributedValueConverter(
85 Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
86
87 final Software name = new Software(null, "XStream");
88 final StringWriter writer = new StringWriter();
89 final CompactWriter compactWriter = new CompactWriter(writer);
90 new TreeMarshaller(compactWriter, converterLookup, mapper).start(name, null);
91 compactWriter.flush();
92 assertEquals("<software>XStream</software>", writer.toString());
93
94 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
95 writer.toString()));
96 assertEquals(
97 name, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
98 }
99
100 /**
101 * Tests conversion with field defined in superclass.
102 */
103 public void testWithValueInSuperclass() {
104 converterLookup.registerConverter(new ToAttributedValueConverter(
105 OpenSourceSoftware.class, mapper, reflectionProvider, converterLookup, "name",
106 Software.class), 0);
107
108 final Software software = new OpenSourceSoftware("Codehaus", "XStream", "BSD");
109 final StringWriter writer = new StringWriter();
110 final CompactWriter compactWriter = new CompactWriter(writer);
111 new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
112 compactWriter.flush();
113 assertEquals(
114 "<open-source vendor=\"Codehaus\" license=\"BSD\">XStream</open-source>",
115 writer.toString());
116
117 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
118 writer.toString()));
119 assertEquals(
120 software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
121 }
122
123 /**
124 * Tests conversion distinguishes between different types.
125 */
126 public void testWillDistinguishBetweenDifferentTypes() {
127 converterLookup.registerConverter(new ToAttributedValueConverter(
128 Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
129 converterLookup.registerConverter(
130 new ToAttributedValueConverter(
131 OpenSourceSoftware.class, mapper, reflectionProvider, converterLookup,
132 "license"), 0);
133
134 final Software[] software = new Software[]{
135 new Software("Microsoft", "Windows"),
136 new OpenSourceSoftware("Codehaus", "XStream", "BSD")};
137 final StringWriter writer = new StringWriter();
138 final PrettyPrintWriter prettyPrintWriter = new PrettyPrintWriter(writer);
139 new TreeMarshaller(prettyPrintWriter, converterLookup, mapper).start(software, null);
140 prettyPrintWriter.flush();
141 assertEquals(""
142 + "<software-array>\n"
143 + " <software vendor=\"Microsoft\">Windows</software>\n"
144 + " <open-source vendor=\"Codehaus\" name=\"XStream\">BSD</open-source>\n"
145 + "</software-array>", writer.toString());
146
147 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
148 writer.toString()));
149 Software[] array = (Software[])new TreeUnmarshaller(
150 null, reader, converterLookup, mapper).start(null);
151 assertEquals(software[0], array[0]);
152 assertEquals(software[1], array[1]);
153 }
154
155 /**
156 * Tests conversion with null in field value.
157 */
158 public void testWithNullValueDeserializedAsEmptyString() {
159 converterLookup.registerConverter(new ToAttributedValueConverter(
160 Software.class, mapper, reflectionProvider, converterLookup, "name"), 0);
161
162 final Software software = new Software(null, null);
163 final StringWriter writer = new StringWriter();
164 final CompactWriter compactWriter = new CompactWriter(writer);
165 new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
166 compactWriter.flush();
167 assertEquals("<software/>", writer.toString());
168
169 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
170 writer.toString()));
171 assertEquals(
172 "",
173 ((Software)new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null)).name);
174 }
175
176 /**
177 * Tests conversion with null in field value.
178 */
179 public void testWithoutValueField() {
180 converterLookup.registerConverter(new ToAttributedValueConverter(
181 Software.class, mapper, reflectionProvider, converterLookup, null), 0);
182
183 final Software software = new Software("Codehaus", "XStream");
184 final StringWriter writer = new StringWriter();
185 final CompactWriter compactWriter = new CompactWriter(writer);
186 new TreeMarshaller(compactWriter, converterLookup, mapper).start(software, null);
187 compactWriter.flush();
188 assertEquals("<software vendor=\"Codehaus\" name=\"XStream\"/>", writer.toString());
189
190 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
191 writer.toString()));
192 assertEquals(
193 software, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
194 }
195
196 /**
197 * Tests conversion with complex value field.
198 */
199 public void testWithComplexValueField() {
200 converterLookup.registerConverter(new ToAttributedValueConverter(
201 X.class, mapper, reflectionProvider, converterLookup, "innerObj"), 0);
202
203 final X x = new X(42);
204 x.aStr = "xXx";
205 x.innerObj = new Y();
206 x.innerObj.yField = "inner";
207 final StringWriter writer = new StringWriter();
208 final CompactWriter compactWriter = new CompactWriter(writer);
209 new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
210 compactWriter.flush();
211 assertEquals(
212 "<x aStr=\"xXx\" anInt=\"42\"><yField>inner</yField></x>", writer.toString());
213
214 final HierarchicalStreamReader reader = driver.createReader(new StringReader(
215 writer.toString()));
216 assertEquals(x, new TreeUnmarshaller(null, reader, converterLookup, mapper).start(null));
217 }
218
219 public void testFailsWhenFieldCannotBeWrittenAsAttribute() {
220 converterLookup.registerConverter(new ToAttributedValueConverter(
221 X.class, mapper, reflectionProvider, converterLookup, "aStr"), 0);
222
223 final X x = new X(42);
224 x.aStr = "xXx";
225 x.innerObj = new Y();
226 x.innerObj.yField = "inner";
227 final StringWriter writer = new StringWriter();
228 final CompactWriter compactWriter = new CompactWriter(writer);
229 try {
230 new TreeMarshaller(compactWriter, converterLookup, mapper).start(x, null);
231 fail("Thrown " + ConversionException.class.getName() + " expected");
232 } catch (final ConversionException e) {
233 assertTrue(e.getMessage().indexOf("innerObj") >= 0);
234 }
235 }
236 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.extended;
12
13 import com.thoughtworks.xstream.converters.ConversionException;
14 import com.thoughtworks.xstream.converters.SingleValueConverter;
15
16 import junit.framework.TestCase;
17
18 import java.util.Map;
19
20 /**
21 *
22 * @author Paul Hammant
23 */
24 public class ToStringConverterTest extends TestCase {
25
26 public void testClaimsCanConvertRightType() throws NoSuchMethodException {
27 SingleValueConverter converter = new ToStringConverter(Foo.class);
28 assertTrue(converter.canConvert(Foo.class));
29 }
30
31 public void testClaimsCantConvertWrongType() throws NoSuchMethodException {
32 SingleValueConverter converter = new ToStringConverter(Foo.class);
33 assertFalse(converter.canConvert(Map.class));
34 }
35
36 public void testClaimsCantConvertWrongType2() {
37 try {
38 new ToStringConverter(Map.class);
39 fail("shoulda barfed");
40 } catch (NoSuchMethodException e) {
41 // expected.
42 }
43 }
44
45 public void testCanConvertRightType() throws NoSuchMethodException {
46 SingleValueConverter converter = new ToStringConverter(Foo.class);
47 assertTrue(converter.fromString("hello") instanceof Foo);
48 assertEquals("hello", ((Foo) converter.fromString("hello")).foo);
49 }
50
51 public void testCanInnocentlyConvertWrongTypeToString() throws NoSuchMethodException {
52 SingleValueConverter converter = new ToStringConverter(Foo.class);
53 assertEquals("whoa", converter.toString("whoa"));
54 }
55
56 public void testCantConvertWrongType() throws NoSuchMethodException {
57 SingleValueConverter converter = new ToStringConverter(BadFoo1.class);
58 try {
59 converter.fromString("whoa");
60 fail("shoulda barfed");
61 } catch (ConversionException e) {
62 assertTrue(e.getMessage().startsWith("Unable to target single String param constructor"));
63 assertTrue(e.getCause() instanceof NullPointerException);
64 }
65 }
66
67
68 public static class Foo {
69 final String foo;
70
71 public Foo(String foo) {
72 this.foo = foo;
73 }
74
75 public String toString() {
76 return foo;
77 }
78 }
79
80 public static class BadFoo1 {
81 public BadFoo1(String string) {
82 throw new NullPointerException("abc");
83 }
84 }
85
86
87 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import junit.framework.TestCase;
14
15 import java.util.Comparator;
16
17 import com.thoughtworks.acceptance.objects.StandardObject;
18 import com.thoughtworks.xstream.XStream;
19
20
21 public class JavaBeanConverterTest extends TestCase {
22
23 // Different JDK versions deliver properties in different order - so sort them!
24 static class StringComparator implements Comparator {
25
26 public int compare(Object o1, Object o2) {
27 return ((String)o1).compareToIgnoreCase((String)o2);
28 }
29
30 }
31
32 public static class World extends StandardObject {
33
34 int anInt = 1;
35 Integer anInteger = new Integer(2);
36 char aChar = 'a';
37 Character aCharacter = new Character('w');
38 boolean aBool = true;
39 Boolean aBoolean = new Boolean(false);
40 byte aByte = 4;
41 Byte aByteClass = new Byte("5");
42 short aShort = 6;
43 Short aShortClass = new Short("7");
44 float aFloat = 8f;
45 Float aFloatClass = new Float("9");
46 long aLong = 10;
47 Long aLongClass = new Long("11");
48 String aString = new String("XStream programming!");
49
50 public byte getAByte() {
51 return aByte;
52 }
53
54 public void setAByte(byte byte1) {
55 aByte = byte1;
56 }
57
58 public Byte getAByteClass() {
59 return aByteClass;
60 }
61
62 public void setAByteClass(Byte byteClass) {
63 aByteClass = byteClass;
64 }
65
66 public float getAFloat() {
67 return aFloat;
68 }
69
70 public void setAFloat(float float1) {
71 aFloat = float1;
72 }
73
74 public Float getAFloatClass() {
75 return aFloatClass;
76 }
77
78 public void setAFloatClass(Float floatClass) {
79 aFloatClass = floatClass;
80 }
81
82 public long getALong() {
83 return aLong;
84 }
85
86 public void setALong(long long1) {
87 aLong = long1;
88 }
89
90 public Long getALongClass() {
91 return aLongClass;
92 }
93
94 public void setALongClass(Long longClass) {
95 aLongClass = longClass;
96 }
97
98 public boolean isABool() {
99 return aBool;
100 }
101
102 public void setABool(boolean aBool) {
103 this.aBool = aBool;
104 }
105
106 public Boolean getABoolean() {
107 return aBoolean;
108 }
109
110 public void setABoolean(Boolean aBoolean) {
111 this.aBoolean = aBoolean;
112 }
113
114 public char getAChar() {
115 return aChar;
116 }
117
118 public void setAChar(char aChar) {
119 this.aChar = aChar;
120 }
121
122 public Character getACharacter() {
123 return aCharacter;
124 }
125
126 public void setACharacter(Character aCharacter) {
127 this.aCharacter = aCharacter;
128 }
129
130 public int getAnInt() {
131 return anInt;
132 }
133
134 public void setAnInt(int anInt) {
135 this.anInt = anInt;
136 }
137
138 public Integer getAnInteger() {
139 return anInteger;
140 }
141
142 public void setAnInteger(Integer anInteger) {
143 this.anInteger = anInteger;
144 }
145
146 public String getAString() {
147 return aString;
148 }
149
150 public void setAString(String aString) {
151 this.aString = aString;
152 }
153
154 public short getAShort() {
155 return aShort;
156 }
157
158 public void setAShort(short short1) {
159 aShort = short1;
160 }
161
162 public Short getAShortClass() {
163 return aShortClass;
164 }
165
166 public void setAShortClass(Short shortClass) {
167 aShortClass = shortClass;
168 }
169 }
170
171 public void testSerializesAllPrimitiveFieldsInACustomObject() {
172 World world = new World();
173
174 XStream xstream = new XStream();
175 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(), new BeanProvider(
176 new StringComparator())), XStream.PRIORITY_LOW);
177 xstream.alias("world", World.class);
178
179 String expected = ""
180 + "<world>\n"
181 + " <ABool>true</ABool>\n"
182 + " <ABoolean>false</ABoolean>\n"
183 + " <AByte>4</AByte>\n"
184 + " <AByteClass>5</AByteClass>\n"
185 + " <AChar>a</AChar>\n"
186 + " <ACharacter>w</ACharacter>\n"
187 + " <AFloat>8.0</AFloat>\n"
188 + " <AFloatClass>9.0</AFloatClass>\n"
189 + " <ALong>10</ALong>\n"
190 + " <ALongClass>11</ALongClass>\n"
191 + " <anInt>1</anInt>\n"
192 + " <anInteger>2</anInteger>\n"
193 + " <AShort>6</AShort>\n"
194 + " <AShortClass>7</AShortClass>\n"
195 + " <AString>XStream programming!</AString>\n"
196 + "</world>";
197
198 String result = xstream.toXML(world);
199
200 assertEquals(expected, result);
201 }
202
203 /**
204 * Only normal and trans are serializable properties, the field modifiers do not matter
205 */
206 public static class TypesOfFields extends StandardObject {
207 String normal = "normal";
208
209 transient String trans = "transient";
210
211 final String fin = "final";
212
213 static String stat = "stat";
214
215 public static String getStat() {
216 return stat;
217 }
218
219 public static void setStat(String stat) {
220 TypesOfFields.stat = stat;
221 }
222
223 public String getFin() {
224 return fin;
225 }
226
227 public String getNormal() {
228 return normal;
229 }
230
231 public void setNormal(String normal) {
232 this.normal = normal;
233 }
234
235 public String getTrans() {
236 return trans;
237 }
238
239 public void setTrans(String trans) {
240 this.trans = trans;
241 }
242 }
243
244 public void testDoesNotSerializeStaticFields() {
245 TypesOfFields fields = new TypesOfFields();
246 String expected = ""
247 + "<types>\n"
248 + " <normal>normal</normal>\n"
249 + " <trans>transient</trans>\n"
250 + "</types>";
251
252 XStream xstream = new XStream();
253 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper(), new BeanProvider(
254 new StringComparator())), -20);
255 xstream.alias("types", TypesOfFields.class);
256
257 String xml = xstream.toXML(fields);
258 assertEquals(expected, xml);
259
260 }
261
262 public static class SimpleBean extends StandardObject {
263 private Object member;
264
265 public Object getMember() {
266 return this.member;
267 }
268
269 public void setMember(Object member) {
270 this.member = member;
271 }
272 }
273
274 public void testSupportsTypeAlias() {
275 SimpleBean innerBean = new SimpleBean();
276 SimpleBean bean = new SimpleBean();
277 bean.setMember(innerBean);
278 innerBean.setMember("foo");
279
280 String expected = ""
281 + "<bean>\n"
282 + " <member class=\"bean\">\n"
283 + " <member class=\"string\">foo</member>\n"
284 + " </member>\n"
285 + "</bean>";
286
287 XStream xstream = new XStream();
288 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
289 xstream.alias("bean", SimpleBean.class);
290
291 String xml = xstream.toXML(bean);
292 assertEquals(expected, xml);
293 }
294
295 public void testDoesNotSerializeOmittedFields() {
296 TypesOfFields fields = new TypesOfFields();
297 String expected = "<types/>";
298
299 XStream xstream = new XStream();
300 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
301 xstream.alias("types", TypesOfFields.class);
302 xstream.omitField(TypesOfFields.class, "trans");
303 xstream.omitField(TypesOfFields.class, "foo");
304 xstream.omitField(TypesOfFields.class, "normal");
305
306 String xml = xstream.toXML(fields);
307 assertEquals(expected, xml);
308 }
309
310 public void testDoesNotDeserializeOmittedFields() {
311 TypesOfFields fields = new TypesOfFields();
312 String xml = ""
313 + "<types>\n"
314 + " <normal>foo</normal>\n"
315 + " <foo>bar</foo>\n"
316 + "</types>";
317
318 XStream xstream = new XStream();
319 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
320 xstream.alias("types", TypesOfFields.class);
321 xstream.omitField(TypesOfFields.class, "foo");
322 xstream.omitField(TypesOfFields.class, "normal");
323
324 TypesOfFields unmarshalledFields = (TypesOfFields)xstream.fromXML(xml);
325 assertEquals(fields, unmarshalledFields);
326 }
327
328 public static class UnsafeBean {
329 public String getUnsafe() {
330 throw new RuntimeException("Do not call");
331 }
332 public void setUnsafe(String value) {
333 // ignore
334 }
335 }
336
337 public void testDoesNotGetValueOfOmittedFields() {
338 UnsafeBean bean = new UnsafeBean();
339 String expected = "<unsafeBean/>";
340
341 XStream xstream = new XStream();
342 xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
343 xstream.alias("unsafeBean", UnsafeBean.class);
344 xstream.omitField(UnsafeBean.class, "unsafe");
345
346 String xml = xstream.toXML(bean);
347 assertEquals(expected, xml);
348 }
349
350 public static class Person {
351 private String fName;
352 private String lName;
353
354 public Person() {
355 // Bean constructor
356 }
357
358 public Person(String firstName, String lastName) {
359 this.fName = firstName;
360 this.lName = lastName;
361 }
362
363 public String getFirstName() {
364 return fName;
365 }
366
367 public void setFirstName(String name) {
368 fName = name;
369 }
370
371 public String getLastName() {
372 return lName;
373 }
374
375 public void setLastName(String name) {
376 lName = name;
377 }
378 }
379
380 public static class Man extends Person {
381
382 public Man() {
383 // Bean constructor
384 super();
385 }
386
387 public Man(String firstName, String lastName) {
388 super(firstName, lastName);
389 }
390
391 }
392
393 public void testDoesNotSerializeOmittedInheritedFields() {
394 XStream xstream = new XStream();
395 xstream.registerConverter(
396 new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
397 xstream.omitField(Person.class, "lastName");
398 xstream.alias("man", Man.class);
399
400 Man man = new Man("John", "Doe");
401 String expected = ""
402 + "<man>\n"
403 + " <firstName>John</firstName>\n"
404 + "</man>";
405
406 assertEquals(expected, xstream.toXML(man));
407 }
408
409 public void testUseAliasInheritedFields() {
410 XStream xstream = new XStream();
411 xstream.registerConverter(
412 new JavaBeanConverter(xstream.getMapper(), new BeanProvider(
413 new StringComparator())), XStream.PRIORITY_LOW);
414 xstream.aliasField("first-name", Person.class, "firstName");
415 xstream.aliasField("last-name", Person.class, "lastName");
416 xstream.alias("man", Man.class);
417
418 Man man = new Man("John", "Doe");
419 String expected = ""
420 + "<man>\n"
421 + " <first-name>John</first-name>\n"
422 + " <last-name>Doe</last-name>\n"
423 + "</man>";
424
425 assertEquals(expected, xstream.toXML(man));
426 }
427
428 public void testFailsFastIfPropertyIsDefinedTwice() {
429 XStream xstream = new XStream();
430 xstream.registerConverter(
431 new JavaBeanConverter(xstream.getMapper()), XStream.PRIORITY_LOW);
432 String input = ""
433 + "<types>\n"
434 + " <normal>foo</normal>\n"
435 + " <normal>bar</normal>\n"
436 + "</types>";
437 xstream.alias("types", TypesOfFields.class);
438
439 try {
440
441 xstream.fromXML(input);
442 fail("Expected exception");
443
444 } catch (JavaBeanConverter.DuplicatePropertyException expected) {
445 assertEquals("normal", expected.get("property"));
446 }
447 }
448 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 12. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.javabean;
12
13 import junit.framework.TestCase;
14
15 import java.beans.PropertyDescriptor;
16 import java.util.Iterator;
17
18 public class PropertyDictionaryTest extends TestCase {
19
20 private PropertyDictionary propertyDictionary;
21
22 protected void setUp() throws Exception {
23 super.setUp();
24 propertyDictionary = new PropertyDictionary();
25 }
26
27 /**
28 * Test class: three serializable properties, one with a all capital name,
29 * two others non serializable, one readable, one writable, and another and
30 * a lonely field
31 */
32 class SomeClass {
33 private String a;
34
35 private String URL;
36
37 private String c;
38
39 private String d;
40
41 private String e;
42
43 private String f;
44
45 public String getA() {
46 return a;
47 }
48
49 public void setA(String a) {
50 this.a = a;
51 }
52
53 public String getURL() {
54 return URL;
55 }
56
57 public void setURL(String url) {
58 this.URL = url;
59 }
60
61 public String getC() {
62 return c;
63 }
64
65 public void setC(String c) {
66 this.c = c;
67 }
68
69 public String getD() {
70 return d;
71 }
72
73 public void setE(String e) {
74 this.e = e;
75 }
76 }
77
78 public void testListsFieldsInClassInDefinitionOrder() {
79 Iterator properties = propertyDictionary.serializablePropertiesFor(SomeClass.class);
80 assertEquals("URL", ((BeanProperty) properties.next()).getName());
81 assertEquals("a", ((BeanProperty) properties.next()).getName());
82 assertEquals("c", ((BeanProperty) properties.next()).getName());
83 assertFalse("No more fields should be present", properties.hasNext());
84
85 properties = propertyDictionary.propertiesFor(SomeClass.class);
86 assertEquals("URL", ((PropertyDescriptor) properties.next()).getName());
87 assertEquals("a", ((PropertyDescriptor) properties.next()).getName());
88 assertEquals("c", ((PropertyDescriptor) properties.next()).getName());
89 assertEquals("d", ((PropertyDescriptor) properties.next()).getName());
90 assertEquals("e", ((PropertyDescriptor) properties.next()).getName());
91 assertFalse("No more fields should be present", properties.hasNext());
92 }
93
94 /**
95 * Test subclassing and private properties
96 */
97 class SpecialClass extends SomeClass {
98 private String brilliant;
99
100 public String getBrilliant() {
101 return brilliant;
102 }
103
104 public void setBrilliant(String brilliant) {
105 this.brilliant = brilliant;
106 }
107
108 public String getPrivate() {
109 return null;
110 }
111
112 private void setPrivate(String string) {
113
114 }
115 }
116
117 public void testIncludesFieldsInSuperClasses() {
118 Iterator properties = propertyDictionary.serializablePropertiesFor(SpecialClass.class);
119 assertEquals("URL", ((BeanProperty) properties.next()).getName());
120 assertEquals("a", ((BeanProperty) properties.next()).getName());
121 assertEquals("brilliant", ((BeanProperty) properties.next()).getName());
122 assertEquals("c", ((BeanProperty) properties.next()).getName());
123 assertFalse("No more fields should be present", properties.hasNext());
124
125 properties = propertyDictionary.propertiesFor(SpecialClass.class);
126 assertEquals("URL", ((PropertyDescriptor) properties.next()).getName());
127 assertEquals("a", ((PropertyDescriptor) properties.next()).getName());
128 assertEquals("brilliant", ((PropertyDescriptor) properties.next()).getName());
129 assertEquals("c", ((PropertyDescriptor) properties.next()).getName());
130 assertEquals("d", ((PropertyDescriptor) properties.next()).getName());
131 assertEquals("e", ((PropertyDescriptor) properties.next()).getName());
132 assertEquals("private", ((PropertyDescriptor) properties.next()).getName());
133 assertFalse("No more fields should be present", properties.hasNext());
134 }
135 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 14. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import org.jmock.Mock;
14 import org.jmock.MockObjectTestCase;
15
16 public abstract class AbstractReflectionProviderTest extends MockObjectTestCase {
17
18 protected ReflectionProvider reflectionProvider;
19
20 public abstract ReflectionProvider createReflectionProvider();
21
22 protected void setUp() throws Exception {
23 super.setUp();
24 reflectionProvider = createReflectionProvider();
25 }
26
27 public void testConstructsStandardClass() {
28 assertCanCreate(OuterClass.class);
29 }
30
31 public void testConstructsStaticInnerClass() {
32 assertCanCreate(PublicStaticInnerClass.class);
33 }
34
35 public static class WithFields {
36 private int a;
37 private int b = 2;
38
39 public int getParentB() {
40 return b;
41 }
42 }
43
44 public void testVisitsEachFieldInClass() {
45 // setup
46 Mock mockBlock = new Mock(ReflectionProvider.Visitor.class);
47
48 // expect
49 mockBlock.expects(once())
50 .method("visit")
51 .with(eq("a"), eq(int.class), eq(WithFields.class), ANYTHING);
52 mockBlock.expects(once())
53 .method("visit")
54 .with(eq("b"), eq(int.class), eq(WithFields.class), ANYTHING);
55
56 // execute
57 reflectionProvider.visitSerializableFields(new WithFields(), (ReflectionProvider.Visitor) mockBlock.proxy());
58
59 // verify
60 mockBlock.verify();
61 }
62
63 public static class SubClassWithFields extends WithFields {
64 private int c;
65 }
66
67 public void testVisitsEachFieldInHeirarchy() {
68 // setup
69 Mock mockBlock = new Mock(ReflectionProvider.Visitor.class);
70
71 // expect
72 mockBlock.expects(once())
73 .method("visit")
74 .with(eq("a"), eq(int.class), eq(WithFields.class), ANYTHING);
75 mockBlock.expects(once())
76 .method("visit")
77 .with(eq("b"), eq(int.class), eq(WithFields.class), ANYTHING);
78 mockBlock.expects(once())
79 .method("visit")
80 .with(eq("c"), eq(int.class), eq(SubClassWithFields.class), ANYTHING);
81
82 // execute
83 reflectionProvider.visitSerializableFields(new SubClassWithFields(), (ReflectionProvider.Visitor) mockBlock.proxy());
84
85 // verify
86 mockBlock.verify();
87 }
88
89 public static class SubClassWithHiddenFields extends WithFields {
90 private int b = 3;
91
92 public int getChildB() {
93 return b;
94 }
95 }
96
97 public void testVisitsFieldsHiddenBySubclass() {
98 // setup
99 Mock mockBlock = new Mock(ReflectionProvider.Visitor.class);
100
101 // expect
102 mockBlock.expects(once())
103 .method("visit")
104 .with(eq("b"), eq(int.class), eq(WithFields.class), ANYTHING)
105 .id("first");
106 mockBlock.expects(once())
107 .method("visit")
108 .with(eq("b"), eq(int.class), eq(SubClassWithHiddenFields.class), ANYTHING)
109 .after("first");
110 mockBlock.expects(once())
111 .method("visit")
112 .with(eq("a"), ANYTHING, ANYTHING, ANYTHING);
113
114 // execute
115 reflectionProvider.visitSerializableFields(new SubClassWithHiddenFields(), (ReflectionProvider.Visitor) mockBlock.proxy());
116
117 // verify
118 mockBlock.verify();
119 }
120
121 public void testWritesHiddenFields() {
122 SubClassWithHiddenFields o = new SubClassWithHiddenFields();
123 reflectionProvider.writeField(o, "b", new Integer(10), null);
124 reflectionProvider.writeField(o, "b", new Integer(20), WithFields.class);
125 assertEquals(10, o.getChildB());
126 assertEquals(20, o.getParentB());
127 }
128
129 protected void assertCanCreate(Class type) {
130 Object result = reflectionProvider.newInstance(type);
131 assertEquals(type, result.getClass());
132 }
133
134 protected void assertCannotCreate(Class type) {
135 try {
136 reflectionProvider.newInstance(type);
137 fail("Should not have been able to newInstance " + type);
138 } catch (ObjectAccessException goodException) {
139 }
140 }
141
142 public static class PublicStaticInnerClass {
143 }
144
145 }
146
147 class OuterClass {
148 }
149
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 14. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import junit.framework.TestCase;
14
15 import java.lang.reflect.Field;
16 import java.lang.reflect.Modifier;
17 import java.util.Iterator;
18
19 public class FieldDictionaryTest extends TestCase {
20
21 private FieldDictionary fieldDictionary;
22
23 protected void setUp() throws Exception {
24 super.setUp();
25 fieldDictionary = new FieldDictionary();
26 }
27
28 static class SomeClass {
29 private String a;
30 private String c;
31 private transient String b;
32 private static String d;
33 private String e;
34 }
35
36 public void testListsFieldsInClassInDefinitionOrder() {
37 Iterator fields = fieldDictionary.fieldsFor(SomeClass.class);
38 assertEquals("a", getNonStaticFieldName(fields));
39 assertEquals("c", getNonStaticFieldName(fields));
40 assertEquals("b", getNonStaticFieldName(fields));
41 assertEquals("e", getNonStaticFieldName(fields));
42 assertFalse("No more fields should be present", fields.hasNext());
43 }
44
45 static class SpecialClass extends SomeClass {
46 private String brilliant;
47 }
48
49 public void testIncludesFieldsInSuperClasses() {
50 Iterator fields = fieldDictionary.fieldsFor(SpecialClass.class);
51 assertEquals("a", getNonStaticFieldName(fields));
52 assertEquals("c", getNonStaticFieldName(fields));
53 assertEquals("b", getNonStaticFieldName(fields));
54 assertEquals("e", getNonStaticFieldName(fields));
55 assertEquals("brilliant", getNonStaticFieldName(fields));
56 assertFalse("No more fields should be present", fields.hasNext());
57 }
58
59 class InnerClass { // note: no static makes this an inner class, not nested class.
60 private String someThing;
61 }
62
63 public void testIncludesOuterClassReferenceForInnerClass() {
64 Iterator fields = fieldDictionary.fieldsFor(InnerClass.class);
65 assertEquals("someThing", getNonStaticFieldName(fields));
66 Field innerField = ((Field)fields.next());
67 assertEquals("this$0", innerField.getName());
68 assertEquals(FieldDictionaryTest.class, innerField.getType());
69 assertFalse("No more fields should be present", fields.hasNext());
70 }
71
72 private static String getNonStaticFieldName(Iterator fields) {
73 final Field field = (Field)fields.next();
74 // JRockit declares static fields first, XStream will ignore them anyway
75 if ((field.getModifiers() & Modifier.STATIC) > 0) {
76 return getNonStaticFieldName(fields);
77 }
78 return field.getName();
79 }
80 }
0 /*
1 * Copyright (C) 2007 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 17. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
13
14 import junit.framework.TestCase;
15
16 import java.lang.reflect.Field;
17 import java.util.Map;
18
19
20 public class NativeFieldKeySorterTest extends TestCase {
21
22 static class Base {
23 String yyy;
24 String ccc;
25 String bbb;
26 }
27
28 static class First extends Base {
29 String aaa;
30 }
31
32 static class Second extends First {
33 String xxx;
34 String zzz;
35 }
36
37 public void testDoesSortInDeclarationOrderWithFieldsOfBaseClassFirst() {
38 String[] fieldOrder = new String[]{"yyy", "ccc", "bbb", "aaa", "xxx", "zzz"};
39 FieldKeySorter sorter = new NativeFieldKeySorter();
40 Map originalMap = buildMap(Second.class);
41 Map map = sorter.sort(Second.class, originalMap);
42 Field[] fields = (Field[])map.values().toArray(new Field[map.size()]);
43 assertEquals(fieldOrder.length, fields.length);
44 for (int i = 0; i < fieldOrder.length; i++) {
45 assertEquals("Field[" + i + ']', fieldOrder[i], fields[i].getName());
46 }
47 }
48
49 private Map buildMap(Class type) {
50 Map map = new OrderRetainingMap();
51 Class cls = type;
52 while (!cls.equals(Object.class)) {
53 Field[] fields = cls.getDeclaredFields();
54 for (int i = 0; i < fields.length; i++) {
55 Field field = fields[i];
56 map.put(new FieldKey(field.getName(), cls, i), field);
57 }
58 cls = cls.getSuperclass();
59 }
60 return map;
61 }
62 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 08. February 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12
13 public class PureJavaReflectionProvider15Test extends AbstractReflectionProviderTest {
14
15 // inherits tests from superclass
16
17 public ReflectionProvider createReflectionProvider() {
18 return new PureJavaReflectionProvider();
19 }
20
21
22 // ---------------------------------------------------------
23
24
25 public static class WithFinalField {
26 private final String s;
27 private WithFinalField() {
28 this.s = "";
29 }
30 String getFinal() {
31 return s;
32 }
33 }
34
35 public void testCanCreateWithFinalField() {
36 assertCanCreate(WithFinalField.class);
37 }
38
39 public void testWriteToFinalField() {
40 Object result = reflectionProvider.newInstance(WithFinalField.class);
41 reflectionProvider.writeField(result, "s", "foo", WithFinalField.class);
42 WithFinalField withFinalField = (WithFinalField)result;
43 assertEquals("foo", withFinalField.getFinal());
44 }
45
46 }
47
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import java.io.Serializable;
14
15 public class PureJavaReflectionProviderTest extends AbstractReflectionProviderTest {
16
17 // inherits tests from superclass
18
19 public ReflectionProvider createReflectionProvider() {
20 return new PureJavaReflectionProvider();
21 }
22
23
24 // ---------------------------------------------------------
25
26
27 private static class PrivateStaticInnerClass {
28 }
29
30 public void testCanCreatePrivateStaticInnerClasses() {
31 assertCanCreate(PrivateStaticInnerClass.class);
32 }
33
34
35 // ---------------------------------------------------------
36
37
38 public class PublicNonStaticInnerClass {
39 }
40
41 private class PrivateNonStaticInnerClass {
42 }
43
44 public void testIsNotCapableOfConstructingNonStaticInnerClasses() {
45 assertCannotCreate(PublicNonStaticInnerClass.class);
46 assertCannotCreate(PrivateNonStaticInnerClass.class);
47 }
48
49
50 // ---------------------------------------------------------
51
52
53 public static class WithConstructorThatDoesStuff {
54 public WithConstructorThatDoesStuff() {
55 throw new UnsupportedOperationException("constructor called");
56 }
57 }
58
59 public void testUnfortunatelyExecutesCodeInsideConstructor() {
60 try {
61 reflectionProvider.newInstance(WithConstructorThatDoesStuff.class);
62 fail("Expected code in constructor to be executed and throw an exception");
63 } catch (UnsupportedOperationException expectedException) {
64 // good
65 }
66 }
67
68
69 // ---------------------------------------------------------
70
71
72 public static class WithoutDefaultConstructor {
73 public WithoutDefaultConstructor(String arg) {
74 }
75 }
76
77 public void testIsNotCapableOfConstructingClassesWithoutDefaultConstructor() {
78 assertCannotCreate(WithoutDefaultConstructor.class);
79 }
80
81
82 // ---------------------------------------------------------
83
84
85 public static class WithPrivateDefaultConstructor {
86 private WithPrivateDefaultConstructor(String thing) {
87 throw new UnsupportedOperationException("wrong constructor called");
88 }
89
90 private WithPrivateDefaultConstructor() {
91 }
92 }
93
94 public void testUsesPrivateConstructorIfNecessary() {
95 assertCanCreate(WithPrivateDefaultConstructor.class);
96 }
97
98
99 // ---------------------------------------------------------
100
101
102 private static class SerializableWithoutDefaultConstructor implements Serializable {
103 private int field1, field2;
104 public SerializableWithoutDefaultConstructor(String thing) {
105 throw new UnsupportedOperationException("constructor called");
106 }
107 }
108
109 private class NonStaticSerializableWithoutDefaultConstructor implements Serializable {
110 public NonStaticSerializableWithoutDefaultConstructor(String thing) {
111 throw new UnsupportedOperationException("constructor called");
112 }
113 }
114
115 public void testBypassesConstructorForSerializableObjectsWithNoDefaultConstructor() {
116 assertCanCreate(SerializableWithoutDefaultConstructor.class);
117 assertCanCreate(NonStaticSerializableWithoutDefaultConstructor.class);
118 }
119
120
121 }
122
0 /*
1 * Copyright (C) 2004, 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 import com.thoughtworks.acceptance.objects.StandardObject;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.converters.Converter;
16 import com.thoughtworks.xstream.core.ClassLoaderReference;
17 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
18 import com.thoughtworks.xstream.io.xml.XppDriver;
19 import com.thoughtworks.xstream.mapper.AttributeMapper;
20 import com.thoughtworks.xstream.mapper.DefaultMapper;
21 import com.thoughtworks.xstream.mapper.Mapper;
22
23 import junit.framework.TestCase;
24
25 public class ReflectionConverterTest extends TestCase {
26
27 public static class World extends StandardObject {
28 int anInt = 1;
29 Integer anInteger = new Integer(2);
30 char anChar = 'a';
31 Character anCharacter = new Character('w');
32 boolean anBool = true;
33 Boolean anBoolean = new Boolean(false);
34 byte aByte = 4;
35 Byte aByteClass = new Byte("5");
36 short aShort = 6;
37 Short aShortClass = new Short("7");
38 float aFloat = 8f;
39 Float aFloatClass = new Float("9");
40 long aLong = 10;
41 Long aLongClass = new Long("11");
42 String anString = new String("XStream programming!");
43 }
44
45 public void testSerializesAllPrimitiveFieldsInACustomObject() {
46 World world = new World();
47
48 XStream xstream = new XStream(new XppDriver());
49 xstream.alias("world", World.class);
50
51 String expected =
52 "<world>\n" +
53 " <anInt>1</anInt>\n" +
54 " <anInteger>2</anInteger>\n" +
55 " <anChar>a</anChar>\n" +
56 " <anCharacter>w</anCharacter>\n" +
57 " <anBool>true</anBool>\n" +
58 " <anBoolean>false</anBoolean>\n" +
59 " <aByte>4</aByte>\n" +
60 " <aByteClass>5</aByteClass>\n" +
61 " <aShort>6</aShort>\n" +
62 " <aShortClass>7</aShortClass>\n" +
63 " <aFloat>8.0</aFloat>\n" +
64 " <aFloatClass>9.0</aFloatClass>\n" +
65 " <aLong>10</aLong>\n" +
66 " <aLongClass>11</aLongClass>\n" +
67 " <anString>XStream programming!</anString>\n" +
68 "</world>";
69
70 assertEquals(expected, xstream.toXML(world));
71 }
72
73 public static class TypesOfFields extends StandardObject {
74 String normal = "normal";
75 transient String trans = "transient";
76 static String stat = "stat";
77 }
78
79 public void testDoesNotSerializeTransientOrStaticFields() {
80 TypesOfFields fields = new TypesOfFields();
81 String expected = "" +
82 "<types>\n" +
83 " <normal>normal</normal>\n" +
84 "</types>";
85
86 XStream xstream = new XStream(new XppDriver());
87 xstream.alias("types", TypesOfFields.class);
88
89 String xml = xstream.toXML(fields);
90 assertEquals(expected, xml);
91
92 }
93
94 public void testCanBeOverloadedToDeserializeTransientFields() {
95 XStream xstream = new XStream(new XppDriver());
96 xstream.alias("types", TypesOfFields.class);
97 xstream.registerConverter(new ReflectionConverter(xstream.getMapper(), xstream
98 .getReflectionProvider()) {
99
100 public boolean canConvert(Class type) {
101 return type == TypesOfFields.class;
102 }
103
104 protected boolean shouldUnmarshalTransientFields() {
105 return true;
106 }
107 });
108
109 String xml = ""
110 + "<types>\n"
111 + " <normal>normal</normal>\n"
112 + " <trans>foo</trans>\n"
113 + "</types>";
114
115 TypesOfFields fields = (TypesOfFields)xstream.fromXML(xml);
116 assertEquals("foo", fields.trans);
117 }
118
119 public void testCustomConverterCanBeInstantiatedAndRegisteredWithDesiredPriority() {
120 XStream xstream = new XStream(new XppDriver());
121 // using default mapper instead of XStream#buildMapper()
122 Mapper mapper = new DefaultMapper(new ClassLoaderReference(new CompositeClassLoader()));
123 // AttributeMapper required by ReflectionConverter
124 mapper = new AttributeMapper(mapper, xstream.getConverterLookup(), xstream.getReflectionProvider());
125 Converter converter = new CustomReflectionConverter(mapper, new PureJavaReflectionProvider());
126 xstream.registerConverter(converter, -20);
127 xstream.alias("world", World.class);
128 World world = new World();
129
130 String expected =
131 "<world>\n" +
132 " <anInt class=\"java.lang.Integer\">1</anInt>\n" +
133 " <anInteger>2</anInteger>\n" +
134 " <anChar class=\"java.lang.Character\">a</anChar>\n" +
135 " <anCharacter>w</anCharacter>\n" +
136 " <anBool class=\"java.lang.Boolean\">true</anBool>\n" +
137 " <anBoolean>false</anBoolean>\n" +
138 " <aByte class=\"java.lang.Byte\">4</aByte>\n" +
139 " <aByteClass>5</aByteClass>\n" +
140 " <aShort class=\"java.lang.Short\">6</aShort>\n" +
141 " <aShortClass>7</aShortClass>\n" +
142 " <aFloat class=\"java.lang.Float\">8.0</aFloat>\n" +
143 " <aFloatClass>9.0</aFloatClass>\n" +
144 " <aLong class=\"java.lang.Long\">10</aLong>\n" +
145 " <aLongClass>11</aLongClass>\n" +
146 " <anString>XStream programming!</anString>\n" +
147 "</world>";
148 assertEquals(expected, xstream.toXML(world));
149
150 }
151
152 static class CustomReflectionConverter extends ReflectionConverter {
153
154 public CustomReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
155 super(mapper, reflectionProvider);
156 }
157 }
158
159 }
0 /*
1 * Copyright (C) 2007, 2014 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 29. July 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import com.thoughtworks.acceptance.objects.StandardObject;
13 import com.thoughtworks.xstream.XStream;
14
15 import junit.framework.TestCase;
16
17 import java.io.IOException;
18 import java.io.ObjectInputStream;
19 import java.io.ObjectOutputStream;
20 import java.io.ObjectStreamField;
21 import java.io.Serializable;
22
23
24 /**
25 * @author J&ouml;rg Schaible
26 */
27 public class SerializableConverterTest extends TestCase {
28
29 static class SimpleType extends StandardObject {
30 private String one;
31 private String two;
32
33 public String getOne() {
34 return this.one;
35 }
36
37 public void setOne(String one) {
38 this.one = one;
39 }
40
41 public String getTwo() {
42 return this.two;
43 }
44
45 public void setTwo(String two) {
46 this.two = two;
47 }
48
49 private void writeObject(final ObjectOutputStream out) throws IOException {
50 out.defaultWriteObject();
51 }
52
53 private void readObject(final ObjectInputStream in)
54 throws IOException, ClassNotFoundException {
55 in.defaultReadObject();
56 }
57 }
58
59 public void testCanOmitFieldAtSerialization() {
60 XStream xstream = new XStream();
61 xstream.alias("simple", SimpleType.class);
62 xstream.omitField(SimpleType.class, "two");
63
64 String expected = ""
65 + "<simple serialization=\"custom\">\n"
66 + " <simple>\n"
67 + " <default>\n"
68 + " <one>one</one>\n"
69 + " </default>\n"
70 + " </simple>\n"
71 + "</simple>";
72
73 SimpleType simple = new SimpleType();
74 simple.setOne("one");
75 simple.setTwo("two");
76
77 String xml = xstream.toXML(simple);
78 assertEquals(expected, xml);
79 }
80
81 public void testCanOmitFieldAtDeserialization() {
82 XStream xstream = new XStream();
83 xstream.alias("simple", SimpleType.class);
84 xstream.omitField(SimpleType.class, "two");
85 xstream.omitField(SimpleType.class, "x");
86
87 String xml = ""
88 + "<simple serialization=\"custom\">\n"
89 + " <simple>\n"
90 + " <default>\n"
91 + " <one>one</one>\n"
92 + " <x>x</x>\n"
93 + " </default>\n"
94 + " </simple>\n"
95 + "</simple>";
96
97 SimpleType simple = new SimpleType();
98 simple.setOne("one");
99
100 SimpleType serialized = (SimpleType)xstream.fromXML(xml);
101 assertEquals(simple, serialized);
102 }
103
104 static class ExtendedType extends SimpleType {
105 private String three;
106
107 public String getThree() {
108 return this.three;
109 }
110
111 public void setThree(String three) {
112 this.three = three;
113 }
114
115 private void writeObject(final ObjectOutputStream out) throws IOException {
116 out.defaultWriteObject();
117 }
118
119 private void readObject(final ObjectInputStream in)
120 throws IOException, ClassNotFoundException {
121 in.defaultReadObject();
122 }
123 }
124
125 public void testCanOmitInheritedFieldAtSerialization() {
126 XStream xstream = new XStream();
127 xstream.alias("extended", ExtendedType.class);
128 xstream.alias("simple", SimpleType.class);
129 xstream.omitField(SimpleType.class, "two");
130
131 String expected = ""
132 + "<extended serialization=\"custom\">\n"
133 + " <simple>\n"
134 + " <default>\n"
135 + " <one>one</one>\n"
136 + " </default>\n"
137 + " </simple>\n"
138 + " <extended>\n"
139 + " <default>\n"
140 + " <three>three</three>\n"
141 + " </default>\n"
142 + " </extended>\n"
143 + "</extended>";
144
145 ExtendedType extended = new ExtendedType();
146 extended.setOne("one");
147 extended.setTwo("two");
148 extended.setThree("three");
149
150 String xml = xstream.toXML(extended);
151 assertEquals(expected, xml);
152 }
153
154 public void testCanOmitInheritedFieldAtDeserialization() {
155 XStream xstream = new XStream();
156 xstream.alias("extended", ExtendedType.class);
157 xstream.alias("simple", SimpleType.class);
158 xstream.omitField(SimpleType.class, "two");
159 xstream.omitField(SimpleType.class, "x");
160
161 String xml = ""
162 + "<extended serialization=\"custom\">\n"
163 + " <simple>\n"
164 + " <default>\n"
165 + " <one>one</one>\n"
166 + " <x>x</x>\n"
167 + " </default>\n"
168 + " </simple>\n"
169 + " <extended>\n"
170 + " <default>\n"
171 + " <three>three</three>\n"
172 + " </default>\n"
173 + " </extended>\n"
174 + "</extended>";
175
176 ExtendedType extended = new ExtendedType();
177 extended.setOne("one");
178 extended.setThree("three");
179
180 SimpleType serialized = (SimpleType)xstream.fromXML(xml);
181 assertEquals(extended, serialized);
182 }
183
184 public static class SimpleNamedFieldsType extends StandardObject implements Serializable {
185
186 private String one;
187 private String two;
188
189 public String getOne() {
190 return this.one;
191 }
192
193 public void setOne(String one) {
194 this.one = one;
195 }
196
197 public String getTwo() {
198 return this.two;
199 }
200
201 public void setTwo(String two) {
202 this.two = two;
203 }
204
205 private static final ObjectStreamField[] serialPersistentFields = {
206 new ObjectStreamField("s1", String.class),
207 new ObjectStreamField("s2", String.class),
208 };
209
210 private void writeObject(ObjectOutputStream out) throws IOException {
211 // don't call defaultWriteObject()
212 ObjectOutputStream.PutField fields = out.putFields();
213 fields.put("s1", one);
214 fields.put("s2", two);
215 out.writeFields();
216 }
217
218 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
219 // don't call defaultReadObject()
220 ObjectInputStream.GetField fields = in.readFields();
221 one = (String) fields.get("s1", "1");
222 two = (String) fields.get("s2", "2");
223 }
224 }
225
226 public void testCanOmitNamedFieldAtSerialization() {
227 XStream xstream = new XStream();
228 xstream.alias("simple", SimpleNamedFieldsType.class);
229 xstream.omitField(SimpleNamedFieldsType.class, "s2");
230
231 String expected = ""
232 + "<simple serialization=\"custom\">\n"
233 + " <simple>\n"
234 + " <default>\n"
235 + " <s1>one</s1>\n"
236 + " </default>\n"
237 + " </simple>\n"
238 + "</simple>";
239
240 SimpleNamedFieldsType simple = new SimpleNamedFieldsType();
241 simple.setOne("one");
242 simple.setTwo("two");
243
244 String xml = xstream.toXML(simple);
245 assertEquals(expected, xml);
246 }
247
248 public void testCanOmitNamedFieldAtDeserialization() {
249 XStream xstream = new XStream();
250 xstream.alias("simple", SimpleNamedFieldsType.class);
251 xstream.omitField(SimpleNamedFieldsType.class, "s2");
252 xstream.omitField(SimpleNamedFieldsType.class, "x");
253
254 String xml = ""
255 + "<simple serialization=\"custom\">\n"
256 + " <simple>\n"
257 + " <default>\n"
258 + " <s1>one</s1>\n"
259 + " <x>x</x>\n"
260 + " </default>\n"
261 + " </simple>\n"
262 + "</simple>";
263
264 SimpleNamedFieldsType simple = new SimpleNamedFieldsType();
265 simple.setOne("one");
266 simple.setTwo("2");
267
268 SimpleNamedFieldsType serialized = (SimpleNamedFieldsType)xstream.fromXML(xml);
269 assertEquals(simple, serialized);
270 }
271
272 public void testCanAliasField() {
273 XStream xstream = new XStream();
274 xstream.alias("simple", SimpleType.class);
275 xstream.aliasField("s2", SimpleType.class, "two");
276
277 String expected = ""
278 + "<simple serialization=\"custom\">\n"
279 + " <simple>\n"
280 + " <default>\n"
281 + " <one>one</one>\n"
282 + " <s2>two</s2>\n"
283 + " </default>\n"
284 + " </simple>\n"
285 + "</simple>";
286
287 SimpleType simple = new SimpleType();
288 simple.setOne("one");
289 simple.setTwo("two");
290
291 String xml = xstream.toXML(simple);
292 assertEquals(expected, xml);
293 SimpleType serialized = (SimpleType)xstream.fromXML(xml);
294 assertEquals(simple, serialized);
295 }
296
297 public void testCanAliasNamedField() {
298 XStream xstream = new XStream();
299 xstream.alias("simple", SimpleNamedFieldsType.class);
300 xstream.aliasField("two", SimpleNamedFieldsType.class, "s2");
301
302 String expected = ""
303 + "<simple serialization=\"custom\">\n"
304 + " <simple>\n"
305 + " <default>\n"
306 + " <s1>one</s1>\n"
307 + " <two>two</two>\n"
308 + " </default>\n"
309 + " </simple>\n"
310 + "</simple>";
311
312 SimpleNamedFieldsType simple = new SimpleNamedFieldsType();
313 simple.setOne("one");
314 simple.setTwo("two");
315
316 String xml = xstream.toXML(simple);
317 assertEquals(expected, xml);
318 SimpleNamedFieldsType serialized = (SimpleNamedFieldsType)xstream.fromXML(xml);
319 assertEquals(simple, serialized);
320 }
321
322 public static class SerializableType implements Serializable {
323 public Serializable serializable;
324 }
325
326 public void testCanHandleFieldsDeclaredWithSerializableInterface() {
327 XStream xstream = new XStream();
328 xstream.alias("sertype", SerializableType.class);
329 xstream.useAttributeFor(SerializableType.class, "serializable");
330
331 String expected = ""
332 + "<sertype>\n"
333 + " <serializable class=\"string\">String</serializable>\n"
334 + "</sertype>";
335
336 SerializableType s = new SerializableType();
337 s.serializable = "String";
338
339 String xml = xstream.toXML(s);
340 assertEquals(expected, xml);
341 SerializableType serialized = (SerializableType)xstream.fromXML(xml);
342 assertEquals(s.serializable, serialized.serializable);
343 }
344 }
0 /*
1 * Copyright (C) 2007 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 10. April 2007 by Guilherme Silveira
9 */
10 package com.thoughtworks.xstream.converters.reflection;
11
12 import java.lang.reflect.Field;
13 import java.util.Map;
14
15 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
16 import com.thoughtworks.xstream.io.StreamException;
17
18 import junit.framework.TestCase;
19
20
21 public class SortableFieldKeySorterTest extends TestCase {
22
23 public void testDoesNotAffectUnregisteredTypes() {
24 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
25 sorter.registerFieldOrder(Mother.class, new String[]{"field2", "field1"});
26 sorter.registerFieldOrder(Child.class, new String[]{"field2", "field1"});
27 Map originalMap = buildMap(Base.class);
28 Map map = sorter.sort(Base.class, originalMap);
29 assertEquals(originalMap, map);
30 }
31
32 public void testIgnoresUnknownFields() {
33 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
34 String[] fieldOrder = new String[]{"whatever", "field2", "field1", "field3"};
35 sorter.registerFieldOrder(Child.class, fieldOrder);
36 Map originalMap = buildMap(Child.class);
37 Map map = sorter.sort(Child.class, originalMap);
38 Field[] fields = (Field[])map.values().toArray(new Field[map.size()]);
39 assertEquals(fieldOrder.length - 1, fields.length);
40 for (int i = 1; i < fieldOrder.length; i++) {
41 assertEquals(fieldOrder[i], fields[i - 1].getName());
42 }
43 }
44
45 public void testComplainsIfSomeFieldIsNotSpecified() {
46 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
47 sorter.registerFieldOrder(Base.class, new String[]{"field3"});
48 try {
49 sorter.sort(Base.class, buildMap(Base.class));
50 fail();
51 } catch (StreamException ex) {
52 // ok
53 }
54 }
55
56 public void testSortsMapAccordingToDefinedFieldOrder() {
57 SortableFieldKeySorter sorter = new SortableFieldKeySorter();
58 String[] fieldOrder = new String[]{"field2", "field1", "field3"};
59 sorter.registerFieldOrder(Child.class, fieldOrder);
60 Map originalMap = buildMap(Child.class);
61 Map map = sorter.sort(Child.class, originalMap);
62 Field[] fields = (Field[])map.values().toArray(new Field[map.size()]);
63 assertEquals(fieldOrder.length, fields.length);
64 for (int i = 0; i < fieldOrder.length; i++) {
65 assertEquals(fieldOrder[i], fields[i].getName());
66 }
67 }
68
69 private Map buildMap(Class type) {
70 Map map = new OrderRetainingMap();
71 Class cls = type;
72 while (!cls.equals(Object.class)) {
73 Field[] fields = cls.getDeclaredFields();
74 for (int i = 0; i < fields.length; i++) {
75 Field field = fields[i];
76 map.put(new FieldKey(field.getName(), cls, i), field);
77 }
78 cls = cls.getSuperclass();
79 }
80 return map;
81 }
82
83 static class Base extends Mother {
84 String field3;
85 }
86
87 static class Child extends Base {
88 }
89
90 static class Mother {
91 String field1, field2;
92 }
93
94 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers.
3 * All rights reserved.
4 *
5 * Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProviderTest
6 */
7 package com.thoughtworks.xstream.converters.reflection;
8
9 public class SunLimitedUnsafeReflectionProviderTest extends SunUnsafeReflectionProviderTest {
10
11 // inherits tests from superclass
12
13 public ReflectionProvider createReflectionProvider() {
14 return new SunLimitedUnsafeReflectionProvider();
15 }
16 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013, 2014 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 08. January 2014 by Joerg Schaible, renamed from Sun14RelfectrionProviderTest.
10 */
11 package com.thoughtworks.xstream.converters.reflection;
12
13 public class SunUnsafeReflectionProviderTest extends AbstractReflectionProviderTest {
14
15 // inherits tests from superclass
16
17 public ReflectionProvider createReflectionProvider() {
18 return new SunUnsafeReflectionProvider();
19 }
20
21 protected static class WithFinalFields {
22 final String finalField;
23 final int finalInt;
24 final long finalLong;
25 final short finalShort;
26 final char finalChar;
27 final byte finalByte;
28 final float finalFloat;
29 final double finalDouble;
30 final boolean finalBoolean;
31
32 private WithFinalFields() {
33 finalField = null;
34 finalChar = '\0';
35 finalInt = 0;
36 finalLong = 0;
37 finalShort = 0;
38 finalByte = 0;
39 finalFloat = 0.0f;
40 finalDouble = 0.0;
41 finalBoolean = false;
42 }
43
44 }
45
46 public void testCanWriteFinalFields() {
47 WithFinalFields thingy = new WithFinalFields();
48 reflectionProvider.writeField(thingy, "finalField", "zero", WithFinalFields.class);
49 assertEquals("zero", thingy.finalField);
50
51 reflectionProvider.writeField(thingy, "finalInt", new Integer(1), WithFinalFields.class);
52 assertEquals(1, thingy.finalInt);
53
54 reflectionProvider.writeField(thingy, "finalLong", new Long(2), WithFinalFields.class);
55 assertEquals(2, thingy.finalLong);
56
57 reflectionProvider.writeField(thingy, "finalShort", new Short((short)3), WithFinalFields.class);
58 assertEquals(3, thingy.finalShort);
59
60 reflectionProvider.writeField(thingy, "finalChar", new Character('4'), WithFinalFields.class);
61 assertEquals('4', thingy.finalChar);
62
63 reflectionProvider.writeField(thingy, "finalByte", new Byte((byte)5), WithFinalFields.class);
64 assertEquals(5, thingy.finalByte);
65
66 reflectionProvider.writeField(thingy, "finalFloat", new Float(0.6), WithFinalFields.class);
67 assertEquals(0.6f, thingy.finalFloat, 0.0);
68
69 reflectionProvider.writeField(thingy, "finalDouble", new Double(0.7), WithFinalFields.class);
70 assertEquals(0.7, thingy.finalDouble, 0.0);
71
72 reflectionProvider.writeField(thingy, "finalBoolean", new Boolean(true), WithFinalFields.class);
73 assertEquals(true, thingy.finalBoolean);
74
75 reflectionProvider.writeField(thingy, "finalBoolean", new Boolean(false), null);
76 assertEquals(false, thingy.finalBoolean);
77 }
78
79 protected static class Unistantiatable {
80 {
81 if (true) {
82 throw new IllegalStateException("<init>");
83 }
84 }
85
86 public Unistantiatable() {
87 throw new IllegalStateException("ctor");
88 }
89
90 public Unistantiatable(String s) {
91 throw new IllegalStateException("ctor(String)");
92 }
93 }
94
95 public void testCanInstantiateWithoutInitializer() {
96 assertCanCreate(Unistantiatable.class);
97 }
98 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. March 2004 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.core;
12
13 import java.util.BitSet;
14
15 import junit.framework.TestCase;
16
17 import com.thoughtworks.xstream.XStream;
18 import com.thoughtworks.xstream.converters.Converter;
19 import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
20 import com.thoughtworks.xstream.converters.basic.StringConverter;
21 import com.thoughtworks.xstream.converters.collections.BitSetConverter;
22
23 /**
24 * @author Guilherme Silveira
25 */
26 public class DefaultConverterLookupTest extends TestCase {
27
28 public void testCanReplaceWithHigherPriority() {
29
30 // this test actually depends on the keyset implementation of the corresponding cache map.
31 final DefaultConverterLookup lookup = new DefaultConverterLookup();
32 Converter currentConverter = new SingleValueConverterWrapper(new StringConverter());
33 lookup.registerConverter(new BitSetConverter(), XStream.PRIORITY_VERY_HIGH);
34 lookup.registerConverter(currentConverter, -100);
35 lookup.lookupConverterForType(String.class);
36 lookup.lookupConverterForType(BitSet.class);
37 assertEquals(lookup.lookupConverterForType(String.class), currentConverter);
38 Converter newConverter = new SingleValueConverterWrapper(new StringConverter());
39 lookup.registerConverter(newConverter, 100);
40 assertEquals(lookup.lookupConverterForType(String.class), newConverter);
41 }
42
43 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2012, 2013 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 23. July 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import junit.framework.TestCase;
14
15 public class JVMTest extends TestCase {
16
17 public void testDoesIgnoreLinkageErrors() {
18 try {
19 assertNull(JVM.loadClassForName("com.thoughtworks.xstream.core.EvilClass"));
20 } catch (LinkageError error) {
21 fail("Error thrown");
22 }
23 }
24 }
25
26 class EvilClass {
27
28 static {
29 evil();
30 }
31
32 static void evil() {
33 throw new RuntimeException("Evil");
34 }
35 }
0 /*
1 * Copyright (C) 2006, 2007, 2009 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 07. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.acceptance.someobjects.WithNamedList;
14 import com.thoughtworks.xstream.XStream;
15
16 import java.util.ArrayList;
17
18
19 public class ReferenceByIDMarshallingStrategyTest extends AbstractAcceptanceTest {
20
21 protected void setUp() throws Exception {
22 super.setUp();
23 xstream.setMode(XStream.ID_REFERENCES);
24 }
25
26 public void testIgnoresImplicitCollection() {
27 xstream.alias("strings", WithNamedList.class);
28 xstream.addImplicitCollection(WithNamedList.class, "things");
29 WithNamedList wl = new WithNamedList("foo");
30 wl.things.add("Hello");
31 wl.things.add("Daniel");
32
33 final String expected = ""
34 + "<strings id=\"1\">\n"
35 + " <string>Hello</string>\n"
36 + " <string>Daniel</string>\n"
37 + " <name>foo</name>\n"
38 + "</strings>";
39
40 assertBothWays(wl, expected);
41 }
42
43 static class List {
44 public Object o;
45 public ArrayList list = new ArrayList();
46 }
47
48 public void testIgnoresImplicitCollectionAtAnyFieldPosition() {
49 final List another = new List();
50 another.o = new Object();
51 another.list.add(new Object());
52 xstream.addImplicitCollection(List.class, "list");
53 xstream.alias("list", List.class);
54
55 final String expected = ""
56 + "<list id=\"1\">\n"
57 + " <o id=\"2\"/>\n"
58 + " <object id=\"3\"/>\n"
59 + "</list>";
60
61 assertBothWays(another, expected);
62 }
63 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. April 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.acceptance.objects.StandardObject;
15 import com.thoughtworks.xstream.XStream;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21 public class ReferenceByXPathMarshallingStrategyTest extends AbstractAcceptanceTest {
22
23 protected void setUp() throws Exception {
24 super.setUp();
25 xstream.alias("thing", Thing.class);
26 }
27
28 public static class Thing extends StandardObject {
29 private String name;
30
31 public Thing() {
32 }
33
34 public Thing(String name) {
35 this.name = name;
36 }
37 }
38
39 public void testStoresReferencesUsingRelativeXPath() {
40 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
41
42 Thing a = new Thing("a");
43 Thing b = new Thing("b");
44 Thing c = b;
45
46 List list = new ArrayList();
47 list.add(a);
48 list.add(b);
49 list.add(c);
50
51 String expected = "" +
52 "<list>\n" +
53 " <thing>\n" +
54 " <name>a</name>\n" +
55 " </thing>\n" +
56 " <thing>\n" +
57 " <name>b</name>\n" +
58 " </thing>\n" +
59 " <thing reference=\"../thing[2]\"/>\n" + // xpath
60 "</list>";
61
62 assertBothWays(list, expected);
63 }
64
65 public void testStoresReferencesUsingAbsoluteXPath() {
66 xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
67
68 Thing a = new Thing("a");
69 Thing b = new Thing("b");
70 Thing c = b;
71
72 List list = new ArrayList();
73 list.add(a);
74 list.add(b);
75 list.add(c);
76
77 String expected = "" +
78 "<list>\n" +
79 " <thing>\n" +
80 " <name>a</name>\n" +
81 " </thing>\n" +
82 " <thing>\n" +
83 " <name>b</name>\n" +
84 " </thing>\n" +
85 " <thing reference=\"/list/thing[2]\"/>\n" + // xpath
86 "</list>";
87
88 assertBothWays(list, expected);
89 }
90 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 25. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.xstream.XStream;
15
16 public class TreeMarshallerTest extends AbstractAcceptanceTest {
17
18 static class Thing {
19 Thing thing;
20 }
21
22 protected void setUp() throws Exception {
23 super.setUp();
24 xstream.setMode(XStream.NO_REFERENCES);
25 }
26
27 public void testThrowsExceptionWhenDetectingCircularReferences() {
28 Thing a = new Thing();
29 Thing b = new Thing();
30 a.thing = b;
31 b.thing = a;
32
33 try {
34 xstream.toXML(a);
35 fail("expected exception");
36 } catch (TreeMarshaller.CircularReferenceException expected) {
37 // good
38 }
39 }
40 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 10. April 2005 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.core;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 public class TreeUnmarshallerTest extends AbstractAcceptanceTest {
19
20 protected void setUp() throws Exception {
21 super.setUp();
22 }
23
24 public void testUnmarshallingOfAliasedInterfaces() {
25 xstream.alias("addressBookInfo", AddressBookInfo.class, AddressBook.class);
26 xstream.alias("addressInfo", AddressInfo.class, Address.class);
27 AddressBookInfo initialObject = new AddressBook();
28 String marshalledXML = xstream.toXML(initialObject);
29 AddressBookInfo unmarshalledObject = (AddressBookInfo) xstream.fromXML(marshalledXML);
30 assertEquals(marshalledXML, xstream.toXML(unmarshalledObject));
31 }
32
33 public interface AddressBookInfo {
34 public List getAddresses();
35
36 public void setAddresses(List address);
37 }
38
39 public static class AddressBook implements AddressBookInfo {
40 private List addresses;
41
42 public AddressBook() {
43 addresses = new ArrayList();
44 AddressInfo addr = new Address("Home", "Home");
45 AddressInfo addr1 = new Address("Office", "Office");
46 addresses.add(addr);
47 addresses.add(addr1);
48 }
49
50 public List getAddresses() {
51 return addresses;
52 }
53
54 public void setAddresses(List addresses) {
55 this.addresses = addresses;
56 }
57 }
58
59 public interface AddressInfo {
60 public String getAddr1();
61
62 public String getAddr2();
63
64 public void setAddr1(String addr1);
65
66 public void setAddr2(String addr2);
67 }
68
69 public static class Address implements AddressInfo {
70 private String addr1 = "addr1";
71
72 private String addr2 = "addr2";
73
74 private Address() {
75 }
76
77 public Address(String addr1, String addr2) {
78 this.addr1 = addr1;
79 this.addr2 = addr2;
80 }
81
82 public String getAddr1() {
83 return addr1;
84 }
85
86 public String getAddr2() {
87 return addr2;
88 }
89
90 public void setAddr1(String addr1) {
91 this.addr1 = addr1;
92 }
93
94 public void setAddr2(String addr2) {
95 this.addr2 = addr2;
96 }
97 }
98 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14
15 public class Base64EncoderTest extends AbstractAcceptanceTest {
16
17 private Base64Encoder encoder = new Base64Encoder();
18
19 public void testEncodesEntireByteArrayAsString() {
20 byte input[] = "hello world".getBytes();
21 String expected = "aGVsbG8gd29ybGQ=";
22 assertEquals(expected, encoder.encode(input));
23 assertByteArrayEquals(input, encoder.decode(expected));
24 }
25
26 public void testWrapsLinesAt76Chars() {
27 byte input[] = ("hello world. hello world. hello world. hello world. hello world. hello world. hello world. "
28 + "hello world. hello world. hello world. hello world. hello world. hello world. hello world. ").getBytes();
29 String expected = "aGVsbG8gd29ybGQuIGhlbGxvIHdvcmxkLiBoZWxsbyB3b3JsZC4gaGVsbG8gd29ybGQuIGhlbGxv\n"
30 + "IHdvcmxkLiBoZWxsbyB3b3JsZC4gaGVsbG8gd29ybGQuIGhlbGxvIHdvcmxkLiBoZWxsbyB3b3Js\n"
31 + "ZC4gaGVsbG8gd29ybGQuIGhlbGxvIHdvcmxkLiBoZWxsbyB3b3JsZC4gaGVsbG8gd29ybGQuIGhl\n"
32 + "bGxvIHdvcmxkLiA=";
33 assertEquals(expected, encoder.encode(input));
34 assertByteArrayEquals(input, encoder.decode(expected));
35 }
36
37 public void testPadsSingleMissingByteWhenNotMultipleOfThree() {
38 byte input[] = { 1, 2, 3, 4, 5 };
39 String expected = "AQIDBAU=";
40 assertEquals(expected, encoder.encode(input));
41 assertByteArrayEquals(input, encoder.decode(expected));
42 }
43
44 public void testPadsDoubleMissingByteWhenNotMultipleOfThree() {
45 byte input[] = { 1, 2, 3, 4 };
46 String expected = "AQIDBA==";
47 assertEquals(expected, encoder.encode(input));
48 assertByteArrayEquals(input, encoder.decode(expected));
49 }
50
51 public void testDoesNotPadWhenMultipleOfThree() {
52 byte input[] = { 1, 2, 3, 4, 5, 6 };
53 String expected = "AQIDBAUG";
54 assertEquals(expected, encoder.encode(input));
55 assertByteArrayEquals(input, encoder.decode(expected));
56 }
57
58 public void testHandlesAllPositiveBytes() {
59 byte input[] = new byte[127];
60 for (int i = 0; i < 126; i++) input[i] = (byte) (i + 1);
61 String expected = "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5\n"
62 + "Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFy\n"
63 + "c3R1dnd4eXp7fH1+AA==";
64 assertEquals(expected, encoder.encode(input));
65 assertByteArrayEquals(input, encoder.decode(expected));
66 }
67
68 public void testHandlesAllNegativeBytes() {
69 byte input[] = new byte[128];
70 for (int i = 0; i < 127; i++) input[i] = (byte) (-1 - i);
71 String expected = "//79/Pv6+fj39vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQz87NzMvKycjH\n"
72 + "xsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGgn56dnJuamZiXlpWUk5KRkI+O\n"
73 + "jYyLiomIh4aFhIOCgQA=";
74 assertEquals(expected, encoder.encode(input));
75 assertByteArrayEquals(input, encoder.decode(expected));
76 }
77
78 public void testHandlesZeroByte() {
79 byte input[] = { 0, 0, 0, 0 };
80 String expected = "AAAAAA==";
81 assertEquals(expected, encoder.encode(input));
82 assertByteArrayEquals(input, encoder.decode(expected));
83 }
84
85 public void testProducesEmptyStringWhenNoBytesGiven() {
86 byte input[] = new byte[0];
87 String expected = "";
88 assertEquals(expected, encoder.encode(input));
89 assertByteArrayEquals(input, encoder.decode(expected));
90 }
91
92 }
0 /*
1 * Copyright (C) 2010 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 18.11.2010 by Joerg Schaible.
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.util.Arrays;
13
14 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
15
16 import junit.framework.TestCase;
17
18
19 public class CloneablesTest extends TestCase {
20 public void testCloneOfCloneable() {
21 final TypedNull stringNull = new CloneableTypedNull(String.class);
22 final TypedNull stringNullClone = (TypedNull)Cloneables.clone(stringNull);
23 assertSame(String.class, stringNullClone.getType());
24 }
25
26 public void testCloneOfNotCloneable() {
27 final TypedNull stringNull = new TypedNull(String.class);
28 assertNull(Cloneables.clone(stringNull));
29 }
30
31 public void testCloneOfUncloneable() {
32 final TypedNull stringNull = new UncloneableTypedNull(String.class);
33 try {
34 Cloneables.clone(stringNull);
35 fail("Thrown " + ObjectAccessException.class.getName() + " expected");
36 } catch (final ObjectAccessException e) {
37 assertTrue(e.getCause() instanceof NoSuchMethodException);
38 }
39 }
40
41 public void testPossibleCloneOfCloneable() {
42 final TypedNull stringNull = new CloneableTypedNull(String.class);
43 final TypedNull stringNullClone = (TypedNull)Cloneables.cloneIfPossible(stringNull);
44 assertSame(String.class, stringNullClone.getType());
45 }
46
47 public void testCloneOfStringArray() {
48 assertEquals(
49 Arrays.asList(new String[]{"string"}),
50 Arrays.asList((String[])Cloneables.clone(new String[]{"string"})));
51 }
52
53 public void testCloneOfPrimitiveArray() {
54 int[] clone = (int[])Cloneables.clone(new int[]{1});
55 assertEquals(1, clone.length);
56 assertEquals(1, clone[0]);
57 }
58
59 public void testPossibleCloneOfNotCloneable() {
60 final TypedNull stringNull = new TypedNull(String.class);
61 assertSame(stringNull, Cloneables.cloneIfPossible(stringNull));
62 }
63
64 static final class CloneableTypedNull extends TypedNull implements Cloneable {
65 CloneableTypedNull(final Class type) {
66 super(type);
67 }
68
69 public Object clone() throws CloneNotSupportedException {
70 return super.clone();
71 }
72 }
73
74 static final class UncloneableTypedNull extends TypedNull implements Cloneable {
75 UncloneableTypedNull(final Class type) {
76 super(type);
77 }
78 }
79 }
0 /*
1 * Copyright (C) 2007, 2009, 2010, 2011, 2012 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 30. March 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;
13
14 import junit.framework.TestCase;
15
16 import java.util.BitSet;
17
18
19 public class DependencyInjectionFactoryTest extends TestCase {
20 public void testDependencyInjectionWithMatchingParameterSequence() {
21 final BitSet used = new BitSet();
22 final Exception exception = (Exception)DependencyInjectionFactory.newInstance(
23 ObjectAccessException.class, new Object[]{
24 "The message", this, new RuntimeException("JUnit")}, used);
25 assertTrue(exception instanceof ObjectAccessException);
26 assertEquals("The message : JUnit", exception.getMessage());
27 assertEquals("JUnit", ((ObjectAccessException)exception).getCause().getMessage());
28 assertTrue(used.get(0));
29 assertFalse(used.get(1));
30 assertTrue(used.get(2));
31 }
32
33 public void testWillUseDefaultConstructor() {
34 final BitSet used = new BitSet();
35 final String string = (String)DependencyInjectionFactory.newInstance(
36 String.class, new Object[]{this}, used);
37 assertEquals("", string);
38 assertFalse(used.get(0));
39 }
40
41 public void testWillMatchNullValue() {
42 final BitSet used = new BitSet();
43 final Exception exception = (Exception)DependencyInjectionFactory.newInstance(
44 ObjectAccessException.class, new Object[]{
45 new TypedNull(String.class), this, new RuntimeException("JUnit")}, used);
46 assertTrue(exception instanceof ObjectAccessException);
47 assertEquals("null : JUnit", exception.getMessage());
48 assertTrue(used.get(0));
49 assertFalse(used.get(1));
50 assertTrue(used.get(2));
51 }
52
53 public void testWillMatchPrimitives() {
54 final BitSet used = new BitSet();
55 final String string = (String)DependencyInjectionFactory.newInstance(
56 String.class,
57 new Object[]{"JUnit".getBytes(), new Integer(1), this, new Integer(4)}, used);
58 assertEquals("Unit", string);
59 assertTrue(used.get(0));
60 assertTrue(used.get(1));
61 assertFalse(used.get(2));
62 assertTrue(used.get(3));
63 }
64
65 public void testWillUseArbitraryOrder() {
66 final BitSet used = new BitSet();
67 final Exception exception = (Exception)DependencyInjectionFactory.newInstance(
68 ObjectAccessException.class, new Object[]{
69 new RuntimeException("JUnit"), this, "The message"}, used);
70 assertTrue(exception instanceof ObjectAccessException);
71 assertEquals("The message : JUnit", exception.getMessage());
72 assertTrue(used.get(0));
73 assertFalse(used.get(1));
74 assertTrue(used.get(2));
75 }
76
77 public void testWillMatchMostSpecificDependency() {
78 final BitSet used = new BitSet();
79 final Exception exception = (Exception)DependencyInjectionFactory.newInstance(
80 ObjectAccessException.class, new Object[]{
81 new RuntimeException("JUnit"), new IllegalArgumentException("foo"), this,
82 "The message"}, used);
83 assertTrue(exception instanceof ObjectAccessException);
84 assertEquals("The message : foo", exception.getMessage());
85 assertFalse(used.get(0));
86 assertTrue(used.get(1));
87 assertFalse(used.get(2));
88 assertTrue(used.get(3));
89 }
90
91 public void testWillMatchFirstMatchingDependency() {
92 final BitSet used = new BitSet();
93 final Exception exception = (Exception)DependencyInjectionFactory.newInstance(
94 ObjectAccessException.class, new Object[]{
95 new RuntimeException("JUnit"), "The message", "bar",
96 new IllegalArgumentException("foo"), this}, used);
97 assertTrue(exception instanceof ObjectAccessException);
98 assertEquals("The message : foo", exception.getMessage());
99 assertFalse(used.get(0));
100 assertTrue(used.get(1));
101 assertFalse(used.get(2));
102 assertTrue(used.get(3));
103 assertFalse(used.get(4));
104 }
105
106 static class Thing {
107 final TestCase testCase;
108 final int first;
109 final int second;
110
111 public Thing() {
112 this(1, 2, null);
113 }
114
115 public Thing(Number num) {
116 this(num.intValue(), 8 * num.intValue(), null);
117 }
118
119 public Thing(String str, TestCase testCase) {
120 this(str.length(), 4 * str.length(), testCase);
121 }
122
123 public Thing(Number num, TestCase testCase) {
124 this(num.intValue(), 4 * num.intValue(), testCase);
125 }
126
127 public Thing(int first, int second, TestCase testCase) {
128 this.first = first;
129 this.second = second;
130 this.testCase = testCase;
131 }
132
133 TestCase getTestCase() {
134 return testCase;
135 }
136
137 int getFirst() {
138 return first;
139 }
140
141 int getSecond() {
142 return second;
143 }
144 }
145
146 public void testWillMatchArbitraryOrderForOneAvailableConstructorOnly() {
147 final BitSet used = new BitSet();
148 final Thing thing = (Thing)DependencyInjectionFactory.newInstance(
149 Thing.class, new Object[]{this, new Integer(1), new Integer(2)}, used);
150 assertSame(this, thing.getTestCase());
151 assertEquals(1, thing.getFirst());
152 assertEquals(2, thing.getSecond());
153 assertTrue(used.get(0));
154 assertTrue(used.get(1));
155 assertTrue(used.get(2));
156 }
157
158 public void testWillSelectMatchingConstructor() {
159 BitSet used = new BitSet();
160 Thing thing = (Thing)DependencyInjectionFactory.newInstance(
161 Thing.class, new Object[]{this, new Integer(1)}, used);
162 assertSame(this, thing.getTestCase());
163 assertEquals(1, thing.getFirst());
164 assertEquals(4, thing.getSecond());
165 assertTrue(used.get(0));
166 assertTrue(used.get(1));
167
168 used = new BitSet();
169 thing = (Thing)DependencyInjectionFactory.newInstance(
170 Thing.class, new Object[]{this, "a"}, used);
171 assertSame(this, thing.getTestCase());
172 assertEquals(1, thing.getFirst());
173 assertEquals(4, thing.getSecond());
174 assertTrue(used.get(0));
175 assertTrue(used.get(1));
176 }
177
178 public void testWillSelectMatchingConstructorForFirstMatchingArguments() {
179 BitSet used = new BitSet();
180 Thing thing = (Thing)DependencyInjectionFactory.newInstance(
181 Thing.class, new Object[]{this, new Integer(1), "foo"}, used);
182 assertSame(this, thing.getTestCase());
183 assertEquals(1, thing.getFirst());
184 assertEquals(4, thing.getSecond());
185 assertTrue(used.get(0));
186 assertTrue(used.get(1));
187 assertFalse(used.get(2));
188
189 used = new BitSet();
190 thing = (Thing)DependencyInjectionFactory.newInstance(
191 Thing.class, new Object[]{this, "foo", new Integer(1)}, used);
192 assertSame(this, thing.getTestCase());
193 assertEquals(3, thing.getFirst());
194 assertEquals(12, thing.getSecond());
195 assertTrue(used.get(0));
196 assertTrue(used.get(1));
197 assertFalse(used.get(2));
198 }
199 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import junit.framework.TestCase;
14
15 public class FastStackTest extends TestCase {
16
17 public void test() {
18 FastStack stack = new FastStack(2);
19
20 stack.push("a");
21 stack.push("b");
22 stack.push("c");
23 stack.push("d");
24
25 assertEquals("d", stack.peek());
26 assertEquals("d", stack.peek());
27 assertEquals("d", stack.pop());
28 assertEquals("c", stack.pop());
29 stack.popSilently();
30 assertEquals("a", stack.peek());
31 assertEquals("a", stack.pop());
32 }
33 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2010, 2011 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 30. May 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import junit.framework.TestCase;
14
15 public class ObjectIdDictionaryTest extends TestCase {
16
17 public void testMapsIdsToObjectReferences() {
18 final ObjectIdDictionary dict = new ObjectIdDictionary();
19 final Object a = new Object();
20 final Object b = new Object();
21 final Object c = new Object();
22 dict.associateId(a, "id a");
23 dict.associateId(b, "id b");
24 dict.associateId(c, "id c");
25 assertEquals("id a", dict.lookupId(a));
26 assertEquals("id b", dict.lookupId(b));
27 assertEquals("id c", dict.lookupId(c));
28 }
29
30 public void testTreatsObjectsThatAreEqualButNotSameInstanceAsDifferentReference() {
31 final ObjectIdDictionary dict = new ObjectIdDictionary();
32 final Integer a = new Integer(3);
33 final Integer b = new Integer(3);
34 dict.associateId(a, "id a");
35 dict.associateId(b, "id b");
36 assertEquals("id a", dict.lookupId(a));
37 assertEquals("id b", dict.lookupId(b));
38 }
39
40 public void testEntriesAreGarbageCollected() throws InterruptedException {
41 final ObjectIdDictionary dict = new ObjectIdDictionary();
42
43 int counter = 0;
44 for (; counter < 1000; ++counter) {
45 final String s = new String("JUnit " + counter); // enforce new object
46 assertFalse("Failed in (" + counter + ")", dict.containsId(s));
47 dict.associateId(s, "X");
48 if (counter % 50 == 49) {
49 System.gc();
50 Thread.sleep(10);
51 }
52 }
53 int size = dict.size();
54 assertTrue("Dictionary did not shrink; "
55 + counter
56 + " distinct objects; "
57 + size
58 + " size", dict.size() < 250);
59 }
60 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import junit.framework.TestCase;
14
15 import java.util.Iterator;
16 import java.util.Map;
17
18 public class OrderRetainingMapTest extends TestCase {
19 private Map map;
20
21 private void assertNextEquals(Object expected, Iterator iterator) {
22 assertTrue("Expected to pull of another item from iterator : " + expected, iterator.hasNext());
23 assertEquals(expected, iterator.next());
24 }
25
26 private void assertNextEntryEquals(Object expectedKey, Object expectedValue, Iterator iterator) {
27 assertTrue("Expected to pull of another item from iterator : " + expectedKey + "=" + expectedValue, iterator.hasNext());
28 Map.Entry actual = (Map.Entry) iterator.next();
29 assertEquals(expectedKey, actual.getKey());
30 assertEquals(expectedValue, actual.getValue());
31 }
32
33 private void assertNoMore(Iterator iterator) {
34 assertFalse("Should be no more items in iterator", iterator.hasNext());
35 }
36
37 protected void setUp() throws Exception {
38 super.setUp();
39 map = new OrderRetainingMap();
40 map.put("one", "ONE");
41 map.put("two", "TWO");
42 map.put("three", "THREE");
43 map.put("four", "FOUR");
44 }
45
46 public void testMaintainsOrderOfKeySet() {
47 Iterator keySetIterator = map.keySet().iterator();
48 assertNextEquals("one", keySetIterator);
49 assertNextEquals("two", keySetIterator);
50 assertNextEquals("three", keySetIterator);
51 assertNextEquals("four", keySetIterator);
52 assertNoMore(keySetIterator);
53 }
54
55 public void testMaintainsOrderOfValues() {
56 Iterator valuesIterator = map.values().iterator();
57 assertNextEquals("ONE", valuesIterator);
58 assertNextEquals("TWO", valuesIterator);
59 assertNextEquals("THREE", valuesIterator);
60 assertNextEquals("FOUR", valuesIterator);
61 assertNoMore(valuesIterator);
62 }
63
64 public void testMaintainsOrderOfEntries() {
65 Iterator entrySetIterator = map.entrySet().iterator();
66 assertNextEntryEquals("one", "ONE", entrySetIterator);
67 assertNextEntryEquals("two", "TWO", entrySetIterator);
68 assertNextEntryEquals("three", "THREE", entrySetIterator);
69 assertNextEntryEquals("four", "FOUR", entrySetIterator);
70 assertNoMore(entrySetIterator);
71 }
72
73 public void testMaintainsOrderOfEntriesAfterCopyCtor() {
74 Iterator entrySetIterator = new OrderRetainingMap(map).entrySet().iterator();
75 assertNextEntryEquals("one", "ONE", entrySetIterator);
76 assertNextEntryEquals("two", "TWO", entrySetIterator);
77 assertNextEntryEquals("three", "THREE", entrySetIterator);
78 assertNextEntryEquals("four", "FOUR", entrySetIterator);
79 assertNoMore(entrySetIterator);
80 }
81
82 }
0 /*
1 * Copyright (C) 2005, 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 06. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.core.util;
12
13 import junit.framework.TestCase;
14
15 import java.util.Iterator;
16
17 public class PrioritizedListTest extends TestCase {
18
19 private void assertNextEquals(Object expected, Iterator iterator) {
20 assertTrue("Expected to pull of another item from iterator : " + expected, iterator.hasNext());
21 assertEquals(expected, iterator.next());
22 }
23
24 private void assertNoMore(Iterator iterator) {
25 assertFalse("Should be no more items in iterator", iterator.hasNext());
26 }
27
28 public void testIteratesOverElementsInReverseOrderTheyWereAdded() {
29 PrioritizedList list = new PrioritizedList();
30 list.add("one", 0);
31 list.add("two", 0);
32 list.add("three", 0);
33
34 Iterator iterator = list.iterator();
35 assertNextEquals("three", iterator);
36 assertNextEquals("two", iterator);
37 assertNextEquals("one", iterator);
38 assertNoMore(iterator);
39 }
40
41 public void testHandlesMultipleIsolatedIterators() {
42 PrioritizedList list = new PrioritizedList();
43 list.add("one", 0);
44 list.add("two", 0);
45
46 Iterator iteratorOne = list.iterator();
47 assertNextEquals("two", iteratorOne);
48
49 Iterator iteratorTwo = list.iterator();
50 assertNextEquals("one", iteratorOne);
51
52 assertNextEquals("two", iteratorTwo);
53 assertNextEquals("one", iteratorTwo);
54
55 assertNoMore(iteratorTwo);
56 assertNoMore(iteratorOne);
57 }
58
59 public void testIteratesOverHighestPriorityItemsFirst() {
60 PrioritizedList list = new PrioritizedList();
61 list.add("medium one", 0);
62 list.add("high one", 1);
63 list.add("low one", -1);
64 list.add("very high", 4);
65 list.add("low two", -1);
66 list.add("medium two", 0);
67 list.add("VERY VERY high", 100);
68 list.add("high two", 1);
69 list.add("very low", -4);
70 list.add("VERY VERY low", -100);
71
72 Iterator iterator = list.iterator();
73 assertNextEquals("VERY VERY high", iterator);
74 assertNextEquals("very high", iterator);
75 assertNextEquals("high two", iterator);
76 assertNextEquals("high one", iterator);
77 assertNextEquals("medium two", iterator);
78 assertNextEquals("medium one", iterator);
79 assertNextEquals("low two", iterator);
80 assertNextEquals("low one", iterator);
81 assertNextEquals("very low", iterator);
82 assertNextEquals("VERY VERY low", iterator);
83 assertNoMore(iterator);
84 }
85 }
0 /*
1 * Copyright (C) 2009 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 01. September 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.io.StringWriter;
13
14 import junit.framework.TestCase;
15
16
17 /**
18 * @author J&ouml;rg Schaible
19 */
20 public class QuickWriterTest extends TestCase {
21
22 public void testUnbuffered() {
23 StringWriter stringWriter = new StringWriter();
24 QuickWriter writer = new QuickWriter(stringWriter, 0);
25 writer.write("Joe");
26 assertEquals(stringWriter.toString(), "Joe");
27 writer.write(' ');
28 assertEquals(stringWriter.toString(), "Joe ");
29 writer.write("Walnes".toCharArray());
30 assertEquals(stringWriter.toString(), "Joe Walnes");
31 }
32 }
0 /*
1 * Copyright (C) 2006, 2007, 2009 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 14. October 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import junit.framework.TestCase;
13
14 import java.text.ParseException;
15 import java.util.Date;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.TimeZone;
19
20 /**
21 * @author J&ouml;rg Schaible
22 */
23 public class ThreadSafeSimpleDateFormatTest extends TestCase {
24 public void testConcurrentDateFormatting() throws InterruptedException {
25
26 final ThreadSafeSimpleDateFormat format = new ThreadSafeSimpleDateFormat(
27 "yyyy-MM-dd HH:mm:ss,S z", TimeZone.getTimeZone("UTC"), 2, 4, false);
28 final Date now = new Date();
29
30 final Map exceptions = new HashMap();
31 final ThreadGroup tg = new ThreadGroup(getName()) {
32 public void uncaughtException(Thread t, Throwable e) {
33 exceptions.put(e, t.getName());
34 super.uncaughtException(t, e);
35 }
36 };
37
38 final int[] counter = new int[1];
39 counter[0] = 0;
40 final Thread[] threads = new Thread[10];
41 for (int i = 0; i < threads.length; ++i) {
42 threads[i] = new Thread(tg, "JUnit Thread " + i) {
43
44 public void run() {
45 int i = 0;
46 try {
47 synchronized (this) {
48 notifyAll();
49 wait();
50 }
51 while (i < 1000 && !interrupted()) {
52 String formatted = format.format(now);
53 Thread.yield();
54 assertEquals(now, format.parse(formatted));
55 ++i;
56 }
57 } catch (InterruptedException e) {
58 fail("Unexpected InterruptedException");
59 } catch (ParseException e) {
60 fail("Unexpected ParseException");
61 }
62 synchronized (counter) {
63 counter[0] += i;
64 }
65 }
66
67 };
68 }
69
70 for (int i = 0; i < threads.length; ++i) {
71 synchronized (threads[i]) {
72 threads[i].start();
73 threads[i].wait();
74 }
75 }
76
77 for (int i = 0; i < threads.length; ++i) {
78 synchronized (threads[i]) {
79 threads[i].notifyAll();
80 }
81 }
82
83 Thread.sleep(1500);
84
85 for (int i = 0; i < threads.length; ++i) {
86 threads[i].interrupt();
87 }
88 for (int i = 0; i < threads.length; ++i) {
89 synchronized (threads[i]) {
90 threads[i].join();
91 }
92 }
93
94 assertEquals("Exceptions have been thrown: " + exceptions, 0, exceptions.size());
95 assertTrue("Each thread should have made at least 1 conversion", counter[0] >= threads.length);
96 }
97
98 }
0 /*
1 * Copyright (C) 2011 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 13. July 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.io.File;
13 import java.lang.ref.PhantomReference;
14 import java.lang.ref.Reference;
15 import java.lang.ref.ReferenceQueue;
16 import java.lang.reflect.Field;
17 import java.net.MalformedURLException;
18 import java.net.URL;
19 import java.net.URLClassLoader;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Set;
24 import java.util.TreeMap;
25
26 import junit.framework.TestCase;
27
28 /**
29 * @author J&ouml;rg Schaible
30 */
31 public class WeakCacheTest extends TestCase {
32
33 public void testIsAMap() {
34 Map map = new WeakCache();
35 assertEquals(0, map.size());
36 assertNull(map.put("key", "value"));
37 assertEquals(1, map.size());
38 assertEquals("value", map.get("key"));
39 assertTrue(map.containsKey(new String("key")));
40 assertTrue(map.containsValue(new String("value")));
41 assertEquals("value", map.values().iterator().next());
42 assertEquals("key", map.keySet().iterator().next());
43 assertEquals("value", ((Map.Entry)map.entrySet().iterator().next()).getValue());
44 assertEquals("key", ((Map.Entry)map.entrySet().iterator().next()).getKey());
45 assertEquals("value", map.put("key", "test"));
46 Map copy = new HashMap(map);
47 assertEquals("test", map.remove("key"));
48 assertEquals(0, map.size());
49 map.putAll(copy);
50 assertEquals(1, map.size());
51 assertEquals("test", map.get("key"));
52 map.clear();
53 assertEquals(0, map.size());
54 }
55
56 public void testEntriesAreRemovedIfKeyIsGarbageCollected() throws InterruptedException {
57 String key = new String("key");
58 ReferenceQueue refQueue = new ReferenceQueue();
59 Reference ref = new PhantomReference(key, refQueue);
60
61 Map map = new WeakCache();
62 map.put(key, "value");
63 key = null;
64
65 int i = 0;
66 while (refQueue.poll() == null) {
67 ref.get(); // always null
68 assertTrue("Key still alive even after "+i+" forced garbage collections", i++ < 5);
69 Thread.sleep(10);
70 System.gc();
71 }
72 assertEquals(0, map.size());
73 }
74
75 public void testSelfReferencingEntriesAreRemovedIfKeyIsGarbageCollected() throws InterruptedException {
76 String key = new String("key");
77 ReferenceQueue refQueue = new ReferenceQueue();
78 Reference ref = new PhantomReference(key, refQueue);
79
80 Map map = new WeakCache();
81 map.put(key, Collections.singleton(key));
82 key = null;
83
84 int i = 0;
85 while (refQueue.poll() == null) {
86 ref.get(); // always null
87 assertTrue("Key still alive even after "+i+" forced garbage collections", i++ < 5);
88 Thread.sleep(10);
89 System.gc();
90 }
91 assertEquals(0, map.size());
92 }
93
94 public void testEntriesAreRemovedIfValueIsGarbageCollected() throws InterruptedException {
95 String value = new String("value");
96 ReferenceQueue refQueue = new ReferenceQueue();
97 Reference ref = new PhantomReference(value, refQueue);
98
99 Map map = new WeakCache();
100 map.put("key", value);
101 value = null;
102
103 int i = 0;
104 while (refQueue.poll() == null) {
105 ref.get(); // always null
106 assertTrue("Value still alive even after "+i+" forced garbage collections", i++ < 5);
107 Thread.sleep(10);
108 System.gc();
109 }
110 assertEquals(0, map.size());
111 }
112
113 public void testSelfReferencingEntriesAreRemovedIfValueIsGarbageCollected() throws InterruptedException {
114 String key = new String("key");
115 Set value = Collections.singleton(key);
116 ReferenceQueue refQueue = new ReferenceQueue();
117 Reference ref = new PhantomReference(value, refQueue);
118
119 Map map = new WeakCache();
120 map.put(key, value);
121 value = null;
122
123 int i = 0;
124 while (refQueue.poll() == null) {
125 ref.get(); // always null
126 assertTrue("Value still alive even after "+i+" forced garbage collections", i++ < 5);
127 Thread.sleep(10);
128 System.gc();
129 }
130 assertEquals(0, map.size());
131 }
132
133 public void testSelfReferencingEntriesWithObjectsFromPermSpace() throws MalformedURLException, ClassNotFoundException, SecurityException, NoSuchFieldException, InterruptedException {
134 File proxyToys = new File("target/lib/proxytoys-0.2.1.jar");
135 ClassLoader classLoader = new URLClassLoader(new URL[]{proxyToys.toURI().toURL()}, getClass().getClassLoader());
136 Class simpleReferenceType = Class.forName("com.thoughtworks.proxy.kit.SimpleReference", true, classLoader);
137 Field instance = simpleReferenceType.getDeclaredField("instance");
138
139 ReferenceQueue refQueue = new ReferenceQueue();
140 Reference ref = new PhantomReference(instance, refQueue);
141
142 Map map = new WeakCache();
143 map.put(simpleReferenceType, instance);
144 simpleReferenceType = null;
145 instance = null;
146
147 int i = 0;
148 while (refQueue.poll() == null) {
149 ref.get(); // always null
150 //assertTrue("Value still alive even after "+i+" forced garbage collections", i++ < 5);
151 if (i++ >= 10) {
152 // actually never reached - unfortunately
153 break;
154 }
155 Thread.sleep(10);
156 System.gc();
157 }
158 // wanted is 1 :-/
159 //assertEquals(1, map.size());
160 assertEquals(0, map.size());
161 }
162
163 public void testCanUseDifferentMapImplementation() throws InterruptedException {
164 String value = new String("value");
165 ReferenceQueue refQueue = new ReferenceQueue();
166 Reference ref = new PhantomReference(value, refQueue);
167
168 Map map = new WeakCache(new TreeMap());
169 map.put("key", value);
170 value = null;
171
172 int i = 0;
173 while (refQueue.poll() == null) {
174 ref.get(); // always null
175 assertTrue("Value still alive even after "+i+" forced garbage collections", i++ < 5);
176 Thread.sleep(10);
177 System.gc();
178 }
179 assertEquals(0, map.size());
180 }
181 }
0 /*
1 * Copyright (C) 2007, 2008, 2010 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.core.util;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.InputStreamReader;
16 import java.io.LineNumberReader;
17 import java.io.PushbackInputStream;
18
19 import junit.framework.TestCase;
20
21
22 /**
23 * @author J&ouml;rg Schaible
24 */
25 public class XmlHeaderAwareReaderTest extends TestCase {
26
27 public void testKeepsAllBytesInStream() throws IOException {
28 ByteArrayInputStream in = new ByteArrayInputStream("\n<!-- no header --><html/>".getBytes("us-ascii"));
29 LineNumberReader reader = new LineNumberReader(new XmlHeaderAwareReader(in));
30 assertEquals("", reader.readLine());
31 assertEquals("<!-- no header --><html/>", reader.readLine());
32 }
33
34 public void testDefaultValues() throws IOException {
35 ByteArrayInputStream in = new ByteArrayInputStream("\n<?xml ?>".getBytes("us-ascii"));
36 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(in);
37 assertEquals(1.0, reader.getVersion(), 0.001);
38 assertEquals(new InputStreamReader(in, "utf-8").getEncoding(), reader.getEncoding());
39 }
40
41 public void testEvaluatesVersion() throws IOException {
42 ByteArrayInputStream in = new ByteArrayInputStream("\n<?xml foo=\"bar\" version='1.1' ?>".getBytes("us-ascii"));
43 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(in);
44 assertEquals(1.1, reader.getVersion(), 0.001);
45 }
46
47 public void testEvaluatesEncoding() throws IOException {
48 ByteArrayInputStream in = new ByteArrayInputStream("<?xml encoding=\"iso-8859-15\" ?>".getBytes("us-ascii"));
49 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(in);
50 assertEquals(new InputStreamReader(in, "iso-8859-15").getEncoding(), reader.getEncoding());
51 }
52
53 public void testValueEscaping() throws IOException {
54 ByteArrayInputStream in = new ByteArrayInputStream("<?xml version='1.\\1' ?>".getBytes("us-ascii"));
55 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(in);
56 assertEquals(1.1, reader.getVersion(), 0.001);
57 }
58
59 public void testCanHandleImproperSizedPushbackInputStream() throws IOException {
60 InputStream in = new ByteArrayInputStream("<?xml version='1.\\1' ?>".getBytes("us-ascii"));
61 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(new PushbackInputStream(in, 1));
62 assertEquals(1.1, reader.getVersion(), 0.001);
63 }
64
65 public void testSkipsUtf8BOM() throws IOException {
66 byte[] bytes = "<?xml encoding=\"utf-8\" ?>".getBytes("us-ascii");
67 byte[] inBytes = new byte[bytes.length+3];
68 inBytes[0] = (byte)0xEF;
69 inBytes[1] = (byte)0xBB;
70 inBytes[2] = (byte)0xBF;
71 System.arraycopy(bytes, 0, inBytes, 3, bytes.length);
72 ByteArrayInputStream in = new ByteArrayInputStream(bytes);
73 XmlHeaderAwareReader reader = new XmlHeaderAwareReader(in);
74 assertEquals(new InputStreamReader(in, "utf-8").getEncoding(), reader.getEncoding());
75 }
76 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013 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 30. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io;
12
13 import java.io.ByteArrayInputStream;
14 import java.io.ByteArrayOutputStream;
15 import java.util.ArrayList;
16
17 import com.thoughtworks.acceptance.objects.SampleLists;
18 import com.thoughtworks.xstream.XStream;
19 import com.thoughtworks.xstream.converters.UnmarshallingContext;
20 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
21 import com.thoughtworks.xstream.core.JVM;
22 import com.thoughtworks.xstream.io.binary.BinaryStreamDriver;
23 import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
24 import com.thoughtworks.xstream.io.xml.Dom4JDriver;
25 import com.thoughtworks.xstream.io.xml.DomDriver;
26 import com.thoughtworks.xstream.io.xml.JDomDriver;
27 import com.thoughtworks.xstream.io.xml.KXml2DomDriver;
28 import com.thoughtworks.xstream.io.xml.KXml2Driver;
29 import com.thoughtworks.xstream.io.xml.StaxDriver;
30 import com.thoughtworks.xstream.io.xml.WstxDriver;
31 import com.thoughtworks.xstream.io.xml.XomDriver;
32 import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;
33 import com.thoughtworks.xstream.io.xml.Xpp3Driver;
34 import com.thoughtworks.xstream.io.xml.XppDomDriver;
35 import com.thoughtworks.xstream.io.xml.XppDriver;
36
37 import junit.framework.Assert;
38 import junit.framework.AssertionFailedError;
39 import junit.framework.Test;
40 import junit.framework.TestCase;
41 import junit.framework.TestSuite;
42
43 public class DriverEndToEndTestSuite extends TestSuite {
44
45 public static Test suite() {
46 return new DriverEndToEndTestSuite();
47 }
48
49 public DriverEndToEndTestSuite() {
50 super(DriverEndToEndTestSuite.class.getName());
51 addDriverTest(new BEAStaxDriver());
52 addDriverTest(new BinaryStreamDriver());
53 addDriverTest(new Dom4JDriver());
54 addDriverTest(new DomDriver());
55 addDriverTest(new JDomDriver());
56 if (JVM.is15()) {
57 Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.JDom2Driver");
58 try {
59 addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
60 } catch (InstantiationException e) {
61 throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
62 } catch (IllegalAccessException e) {
63 throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
64 }
65 }
66 addDriverTest(new KXml2DomDriver());
67 addDriverTest(new KXml2Driver());
68 addDriverTest(new StaxDriver());
69 if (JVM.is16()) {
70 Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.xml.StandardStaxDriver");
71 try {
72 addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
73 } catch (InstantiationException e) {
74 throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
75 } catch (IllegalAccessException e) {
76 throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
77 }
78 }
79 addDriverTest(new WstxDriver());
80 addDriverTest(new XomDriver());
81 addDriverTest(new Xpp3DomDriver());
82 addDriverTest(new Xpp3Driver());
83 addDriverTest(new XppDomDriver());
84 addDriverTest(new XppDriver());
85 if (JVM.is14()) {
86 Class driverType = JVM.loadClassForName("com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver");
87 try {
88 addDriverTest((HierarchicalStreamDriver)driverType.newInstance());
89 } catch (InstantiationException e) {
90 throw new AssertionFailedError("Cannot instantiate " + driverType.getName());
91 } catch (IllegalAccessException e) {
92 throw new AssertionFailedError("Cannot access default constructor of " + driverType.getName());
93 }
94 }
95 }
96
97 private void test(HierarchicalStreamDriver driver) {
98 XStream xstream = new XStream(driver);
99 xstream.registerConverter(new CollectionConverter(xstream.getMapper()) {
100
101 public Object unmarshal(HierarchicalStreamReader reader,
102 UnmarshallingContext context) {
103 ExtendedHierarchicalStreamReader exReader = (ExtendedHierarchicalStreamReader)reader;
104 if (exReader.peekNextChild() == null) {
105 return new ArrayList();
106 }
107 return super.unmarshal(reader, context);
108 }
109
110 });
111
112 SampleLists in = new SampleLists();
113 in.good.add("one");
114 in.good.add("two");
115 in.good.add("three");
116 in.bad.add(Boolean.TRUE);
117 in.bad.add(Boolean.FALSE);
118 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
119 xstream.toXML(in, buffer);
120 Object out = xstream.fromXML(new ByteArrayInputStream(buffer.toByteArray()));
121
122 Assert.assertEquals(in, out);
123 }
124
125 private void addDriverTest(final HierarchicalStreamDriver driver) {
126 String testName = getShortName(driver);
127 addTest(new TestCase(testName) {
128 protected void runTest() throws Throwable {
129 test(driver);
130 }
131 });
132 }
133
134 private String getShortName(HierarchicalStreamDriver driver) {
135 String result = driver.getClass().getName();
136 result = result.substring(result.lastIndexOf('.') + 1);
137 return result;
138 }
139
140 }
0 /*
1 * Copyright (C) 2006, 2007 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 15. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io;
11
12 import com.thoughtworks.xstream.io.xml.CompactWriter;
13
14 import junit.framework.TestCase;
15
16 import java.io.IOException;
17 import java.io.StringWriter;
18
19
20 /**
21 * @author J&ouml;rg Schaible
22 */
23 public class StatefulWriterTest extends TestCase {
24
25 private StatefulWriter writer;
26 private StringWriter stringWriter;
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 stringWriter = new StringWriter();
31 writer = new StatefulWriter(new CompactWriter(stringWriter));
32 }
33
34 public void testDelegatesAllCalls() {
35 writer.startNode("junit");
36 writer.addAttribute("test", "true");
37 writer.setValue("foo");
38 writer.endNode();
39 writer.close();
40 assertEquals("<junit test=\"true\">foo</junit>", stringWriter.toString());
41 }
42
43 public void testKeepsBlance() {
44 writer.startNode("junit");
45 writer.endNode();
46 try {
47 writer.endNode();
48 fail("Thrown " + StreamException.class.getName() + " expected");
49 } catch (final StreamException e) {
50 assertTrue(e.getCause() instanceof IllegalStateException);
51 }
52 }
53
54 public void testCanOnlyWriteAttributesToOpenNode() {
55 try {
56 writer.addAttribute("test", "true");
57 fail("Thrown " + StreamException.class.getName() + " expected");
58 } catch (final StreamException e) {
59 assertTrue(e.getCause() instanceof IllegalStateException);
60 }
61 writer.startNode("junit");
62 writer.setValue("text");
63 try {
64 writer.addAttribute("test", "true");
65 fail("Thrown " + StreamException.class.getName() + " expected");
66 } catch (final StreamException e) {
67 assertTrue(e.getCause() instanceof IllegalStateException);
68 }
69 writer.endNode();
70 try {
71 writer.addAttribute("test", "true");
72 fail("Thrown " + StreamException.class.getName() + " expected");
73 } catch (final StreamException e) {
74 assertTrue(e.getCause() instanceof IllegalStateException);
75 }
76 }
77
78 public void testCanWriteAttributesOnlyOnce() {
79 writer.startNode("junit");
80 writer.addAttribute("test", "true");
81 try {
82 writer.addAttribute("test", "true");
83 fail("Thrown " + StreamException.class.getName() + " expected");
84 } catch (final StreamException e) {
85 assertTrue(e.getCause() instanceof IllegalStateException);
86 }
87 writer.endNode();
88 }
89
90 public void testCanWriteValueOnlyToOpenNode() {
91 try {
92 writer.setValue("test");
93 fail("Thrown " + StreamException.class.getName() + " expected");
94 } catch (final StreamException e) {
95 assertTrue(e.getCause() instanceof IllegalStateException);
96 }
97 writer.startNode("junit");
98 writer.endNode();
99 try {
100 writer.setValue("test");
101 fail("Thrown " + StreamException.class.getName() + " expected");
102 } catch (final StreamException e) {
103 assertTrue(e.getCause() instanceof IllegalStateException);
104 }
105 }
106
107 public void testCannotOpenNodeInValue() {
108 writer.startNode("junit");
109 writer.setValue("test");
110 try {
111 writer.startNode("junit");
112 fail("Thrown " + StreamException.class.getName() + " expected");
113 } catch (final StreamException e) {
114 assertTrue(e.getCause() instanceof IllegalStateException);
115 }
116 }
117
118 public void testCanCloseInFinally() {
119 try {
120 writer.endNode();
121 fail("Thrown " + StreamException.class.getName() + " expected");
122 } catch (final StreamException e) {
123 writer.close();
124 }
125 }
126
127 public void testCannotWriteAfterClose() {
128 writer.close();
129 try {
130 writer.startNode("junit");
131 fail("Thrown " + StreamException.class.getName() + " expected");
132 } catch (final StreamException e) {
133 assertTrue(e.getCause() instanceof IOException);
134 }
135 try {
136 writer.addAttribute("junit", "test");
137 fail("Thrown " + StreamException.class.getName() + " expected");
138 } catch (final StreamException e) {
139 assertTrue(e.getCause() instanceof IOException);
140 }
141 try {
142 writer.setValue("test");
143 fail("Thrown " + StreamException.class.getName() + " expected");
144 } catch (final StreamException e) {
145 assertTrue(e.getCause() instanceof IOException);
146 }
147 try {
148 writer.endNode();
149 fail("Thrown " + StreamException.class.getName() + " expected");
150 } catch (final StreamException e) {
151 assertTrue(e.getCause() instanceof IOException);
152 }
153 try {
154 writer.flush();
155 fail("Thrown " + StreamException.class.getName() + " expected");
156 } catch (final StreamException e) {
157 assertTrue(e.getCause() instanceof IOException);
158 }
159 }
160
161 public void testCanCloseTwice() {
162 writer.close();
163 writer.close();
164 }
165
166 public void testCaresAboutNestingLevelWritingAttributes() {
167 writer.startNode("junit");
168 writer.addAttribute("test", "true");
169 writer.startNode("junit");
170 writer.addAttribute("test", "true");
171 writer.endNode();
172 writer.endNode();
173 }
174 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier;
16 import com.thoughtworks.xstream.io.xml.AbstractXMLReaderTest;
17 import com.thoughtworks.xstream.io.xml.Xpp3Driver;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.StringReader;
21 import java.io.ByteArrayInputStream;
22
23 public class BinaryStreamTest extends AbstractXMLReaderTest {
24
25 private HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
26
27 protected void setUp() throws Exception {
28 super.setUp();
29 }
30
31 // factory method
32 protected HierarchicalStreamReader createReader(String xml) throws Exception {
33 // Transmogrify XML input into binary format.
34 HierarchicalStreamReader xmlReader =
35 new Xpp3Driver().createReader(new StringReader(xml));
36
37 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
38 HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
39 copier.copy(xmlReader, binaryWriter);
40
41 return new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
42 }
43
44 public void testHandlesMoreThan256Ids() {
45 int count = 500;
46
47 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
48 HierarchicalStreamWriter binaryWriter = new BinaryStreamWriter(buffer);
49 binaryWriter.startNode("root");
50 for (int i = 0; i < count; i++) {
51 binaryWriter.startNode("node" + i);
52 binaryWriter.endNode();
53 }
54 for (int i = 0; i < count; i++) {
55 binaryWriter.startNode("node" + i);
56 binaryWriter.endNode();
57 }
58 binaryWriter.endNode();
59
60 HierarchicalStreamReader binaryReader
61 = new BinaryStreamReader(new ByteArrayInputStream(buffer.toByteArray()));
62 assertEquals("root", binaryReader.getNodeName());
63 for (int i = 0; i < count; i++) {
64 assertTrue("Expected child " + i, binaryReader.hasMoreChildren());
65 binaryReader.moveDown();
66 assertEquals("node" + i, binaryReader.getNodeName());
67 binaryReader.moveUp();
68 }
69 for (int i = 0; i < count; i++) {
70 assertTrue("Expected child " + i, binaryReader.hasMoreChildren());
71 binaryReader.moveDown();
72 assertEquals("node" + i, binaryReader.getNodeName());
73 binaryReader.moveUp();
74 }
75
76 }
77
78 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.binary;
12
13 import junit.framework.TestCase;
14
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.DataInputStream;
18 import java.io.DataOutput;
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 public class TokenTest extends TestCase {
23
24 private Token.Formatter tokenFormatter;
25 private ByteArrayOutputStream buffer;
26 private DataOutput out;
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 tokenFormatter = new Token.Formatter();
31 buffer = new ByteArrayOutputStream();
32 out = new DataOutputStream(buffer);
33 }
34
35 public void testDoesNotSupportNegativeIds() {
36 Token.StartNode token = new Token.StartNode(-5);
37 try {
38 writeOneToken(token);
39 fail("Expected exception");
40 } catch (IOException expectedException) {
41 // expected exception
42 }
43 }
44
45 public void testUsesOneExtraByteForIdsThatCanBeRepresentedAsByte() throws IOException {
46 Token.StartNode token = new Token.StartNode(255);
47 writeOneToken(token);
48 assertEquals(2, buffer.size()); // One byte already written for token type.
49 assertEquals(token, readOneToken());
50 }
51
52 public void testUsesTwoExtraBytesForIdsThatCanBeRepresentedAsShort() throws IOException {
53 Token.StartNode token = new Token.StartNode(30000);
54 writeOneToken(token);
55 assertEquals(3, buffer.size()); // One byte already written for token type.
56 assertEquals(token, readOneToken());
57 }
58
59 public void testUsesFourExtraBytesForIdsThatCanBeRepresentedAsShort() throws IOException {
60 Token.StartNode token = new Token.StartNode(Integer.MAX_VALUE);
61 writeOneToken(token);
62 assertEquals(5, buffer.size()); // One byte already written for token type.
63 assertEquals(token, readOneToken());
64 }
65
66 public void testUsesEightExtraBytesForIdsThatCanBeRepresentedAsLong() throws IOException {
67 Token.StartNode token = new Token.StartNode(324234325543L);
68 writeOneToken(token);
69 assertEquals(9, buffer.size()); // One byte already written for token type.
70 assertEquals(token, readOneToken());
71 }
72
73 public void testUsesOneExtraByteForUtf8StringsWith1ByteCharacters() throws IOException {
74 Token.Value token = new Token.Value("12345");
75 writeOneToken(token);
76 assertEquals(8, buffer.size()); // One byte already written for token type and two for the length.
77 assertEquals(token, readOneToken());
78 }
79
80 public void testUsesOneExtraByteForUtf8StringsWith2ByteCharacters() throws IOException {
81 Token.Value token = new Token.Value("\u0391\u03b8\u03ae\u03bd\u03b1"); // Athens
82 writeOneToken(token);
83 assertEquals(13, buffer.size()); // One byte already written for token type and two for the length.
84 assertEquals(token, readOneToken());
85 }
86
87 public void testUsesIdForStringsWithMoreThen64KBytes() throws IOException {
88 StringBuffer builder = new StringBuffer();
89 for(int i = 0; i++ < 8000;) {
90 builder.append("\u0391\u03b8\u03ae\u03bd\u03b1"); // Athens
91 }
92 String string = builder.toString();
93 assertEquals(40000, string.length()); // 5 chars, but each char 2 bytes in UTF-8
94 Token.Value token = new Token.Value(string);
95 writeOneToken(token);
96 assertEquals(80014, buffer.size()); // > 65k
97 assertEquals(token, readOneToken());
98 }
99
100 private Token readOneToken() throws IOException {
101 return tokenFormatter.read(new DataInputStream(new ByteArrayInputStream(buffer.toByteArray())));
102 }
103
104 private void writeOneToken(Token token) throws IOException {
105 tokenFormatter.write(out, token);
106 }
107
108 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 04. June 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.copy;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
15 import com.thoughtworks.xstream.io.xml.AbstractXMLReaderTest;
16 import com.thoughtworks.xstream.io.xml.CompactWriter;
17 import com.thoughtworks.xstream.io.xml.Xpp3Driver;
18 import com.thoughtworks.xstream.io.xml.XppReader;
19 import com.thoughtworks.xstream.io.xml.xppdom.XppFactory;
20
21 import org.xmlpull.v1.XmlPullParserException;
22
23 import java.io.StringReader;
24 import java.io.StringWriter;
25
26 public class HierarchicalStreamCopierTest extends AbstractXMLReaderTest {
27
28 private HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
29
30 // This test leverages the existing (comprehensive) tests for the XML readers
31 // and adds an additional stage of copying in.
32
33 // factory method - overriding base class.
34 protected HierarchicalStreamReader createReader(String xml) throws Exception {
35 HierarchicalStreamReader sourceReader =
36 new Xpp3Driver().createReader(new StringReader(xml));
37
38 StringWriter buffer = new StringWriter();
39 HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);
40
41 copier.copy(sourceReader, destinationWriter);
42
43 return new XppReader(new StringReader(buffer.toString()), XppFactory.createDefaultParser());
44 }
45
46 public void testSkipsValueIfEmpty() throws XmlPullParserException {
47 String input = "<root><empty1/><empty2></empty2><not-empty>blah</not-empty></root>";
48 String expected = "<root><empty1/><empty2/><not-empty>blah</not-empty></root>";
49 HierarchicalStreamReader sourceReader = new XppReader(
50 new StringReader(input), XppFactory.createDefaultParser());
51
52 StringWriter buffer = new StringWriter();
53 HierarchicalStreamWriter destinationWriter = new CompactWriter(buffer);
54
55 copier.copy(sourceReader, destinationWriter);
56
57 assertEquals(expected, buffer.toString());
58 }
59
60 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013 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 30. April 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import com.thoughtworks.acceptance.objects.Category;
13 import com.thoughtworks.acceptance.objects.OwnerOfExternalizable;
14 import com.thoughtworks.acceptance.objects.Product;
15 import com.thoughtworks.acceptance.objects.SomethingExternalizable;
16 import com.thoughtworks.acceptance.objects.StandardObject;
17 import com.thoughtworks.xstream.XStream;
18 import com.thoughtworks.xstream.core.JVM;
19 import com.thoughtworks.xstream.testutil.TimeZoneChanger;
20
21 import junit.framework.TestCase;
22
23 import org.codehaus.jettison.mapped.Configuration;
24
25 import java.io.IOException;
26 import java.io.ObjectInputStream;
27 import java.io.ObjectOutputStream;
28 import java.io.StringReader;
29 import java.io.StringWriter;
30 import java.lang.reflect.InvocationTargetException;
31 import java.lang.reflect.Method;
32 import java.sql.Timestamp;
33 import java.util.ArrayList;
34 import java.util.Date;
35
36
37 /**
38 * Testing serialization to and from JSON with Jettison driver.
39 *
40 * @author Dejan Bosanac
41 */
42 public class JettisonMappedXmlDriverTest extends TestCase {
43
44 private final static String SIMPLE = "{'product':{'name':'Banana','id':123,'price':23}}"
45 .replace('\'', '"');
46 private final static String HIERARCHY = (JVM.is15()
47 ? "{'category':{'name':'fruit','id':111,'products':[{'product':[{'name':'Banana','id':123,'price':23.01,'tags':[{'string':['yellow','fresh','tasty']}]},{'name':'Mango','id':124,'price':34.01}]}]}}"
48 : "{'category':{'name':'fruit','id':111,'products':{'product':[{'name':'Banana','id':123,'price':23.01,'tags':{'string':['yellow','fresh','tasty']}},{'name':'Mango','id':124,'price':34.01}]}}}")
49 .replace('\'', '"');
50
51 private XStream xstream;
52
53 /**
54 * @see junit.framework.TestCase#setUp()
55 */
56 protected void setUp() throws Exception {
57 super.setUp();
58 TimeZoneChanger.change("UTC");
59 xstream = new XStream(new JettisonMappedXmlDriver());
60 xstream.alias("category", Category.class);
61 xstream.alias("product", Product.class);
62 }
63
64 protected void tearDown() throws Exception {
65 TimeZoneChanger.reset();
66 super.tearDown();
67 }
68
69 public void testReadSimple() {
70 Product product = (Product)xstream.fromXML(SIMPLE);
71 assertEquals(product.getName(), "Banana");
72 assertEquals(product.getId(), "123");
73 assertEquals("" + product.getPrice(), "" + 23.00);
74 }
75
76 public void testWriteSimple() {
77 Product product = new Product("Banana", "123", 23.00);
78 String result = xstream.toXML(product);
79 assertEquals(SIMPLE, result);
80 }
81
82 public void testJettisonConfigured()
83 throws ClassNotFoundException, InstantiationException, IllegalAccessException,
84 NoSuchMethodException, InvocationTargetException {
85 if (JVM.is15()) {
86 Object typeConverter = Class.class.forName(
87 "org.codehaus.jettison.mapped.SimpleConverter").newInstance();
88 Method setTypeConverter = Configuration.class.getMethod(
89 "setTypeConverter", new Class[]{typeConverter.getClass().getInterfaces()[0]});
90 Configuration config = new Configuration();
91 setTypeConverter.invoke(config, new Object[]{typeConverter});
92 xstream = new XStream(new JettisonMappedXmlDriver(config));
93 xstream.alias("product", Product.class);
94 Product product = new Product("Banana", "123", 23.00);
95 String result = xstream.toXML(product);
96 assertEquals(
97 "{'product':{'name':'Banana','id':'123','price':'23.0'}}".replace('\'', '"'),
98 result);
99 assertEquals(product, xstream.fromXML(result));
100 }
101 }
102
103 public void testWriteHierarchy() {
104 Category category = new Category("fruit", "111");
105 ArrayList products = new ArrayList();
106 Product banana = new Product("Banana", "123", 23.01);
107 ArrayList bananaTags = new ArrayList();
108 bananaTags.add("yellow");
109 bananaTags.add("fresh");
110 bananaTags.add("tasty");
111 banana.setTags(bananaTags);
112 products.add(banana);
113 Product mango = new Product("Mango", "124", 34.01);
114 products.add(mango);
115 category.setProducts(products);
116 String result = xstream.toXML(category);
117 assertEquals(HIERARCHY, result);
118 }
119
120 public void testHierarchyRead() {
121 Category parsedCategory = (Category)xstream.fromXML(HIERARCHY);
122 Product parsedBanana = (Product)parsedCategory.getProducts().get(0);
123 assertEquals("Banana", parsedBanana.getName());
124 assertEquals(3, parsedBanana.getTags().size());
125 assertEquals("yellow", parsedBanana.getTags().get(0));
126 assertEquals("tasty", parsedBanana.getTags().get(2));
127 }
128
129 public void testObjectStream() throws IOException, ClassNotFoundException {
130 Product product = new Product("Banana", "123", 23.00);
131 StringWriter writer = new StringWriter();
132 ObjectOutputStream oos = xstream.createObjectOutputStream(writer, "oos");
133 oos.writeObject(product);
134 oos.close();
135 String json = writer.toString();
136 assertEquals("{\"oos\":" + SIMPLE + "}", json);
137 ObjectInputStream ois = xstream.createObjectInputStream(new StringReader(json));
138 Product parsedProduct = (Product)ois.readObject();
139 assertEquals(product.toString(), parsedProduct.toString());
140 }
141
142 public void testDoesHandleQuotesAndEscapes() {
143 String[] strings = new String[]{
144 "last\"", "\"first", "\"between\"", "around \"\" it", "back\\slash",
145 "forward/slash"};
146 String expected = (""
147 + (JVM.is15() ? "{#string-array#:[{#string#:[" : "{#string-array#:{#string#:[")
148 + "#last\\\"#,"
149 + "#\\\"first#,"
150 + "#\\\"between\\\"#,"
151 + "#around \\\"\\\" it#,"
152 + "#back\\\\slash#,"
153 + "#forward\\/slash#" + (JVM.is15() ? "]}]}" : "]}}")).replace('#', '"');
154 assertEquals(expected, xstream.toXML(strings));
155 }
156
157 public void testDoesEscapeValuesAccordingRfc4627() {
158 String expected = "{'string':'\\u0000\\u0001\\u001f \uffee'}".replace('\'', '"');
159 assertEquals(expected, xstream.toXML("\u0000\u0001\u001f\u0020\uffee"));
160 }
161
162 public void testSingletonListWithSimpleObject() {
163 ArrayList list1 = new ArrayList();
164 list1.add("one");
165 String json = xstream.toXML(list1);
166 assertEquals((JVM.is15()
167 ? "{'list':[{'string':'one'}]}"
168 : "{'list':{'string':['one']}}").replace('\'', '"'), json);
169 ArrayList list2 = (ArrayList)xstream.fromXML(json);
170 assertEquals(json, xstream.toXML(list2));
171 }
172
173 public void testListWithSimpleObjects() {
174 ArrayList list1 = new ArrayList();
175 list1.add("one");
176 list1.add("two");
177 list1.add("three");
178 String json = xstream.toXML(list1);
179 assertEquals((JVM.is15()
180 ? "{'list':[{'string':['one','two','three']}]}"
181 : "{'list':{'string':['one','two','three']}}").replace('\'', '"'), json);
182 ArrayList list2 = (ArrayList)xstream.fromXML(json);
183 assertEquals(json, xstream.toXML(list2));
184 }
185
186 public void testSingletonListWithComplexObject() {
187 Product product = new Product("Banana", "123", 23.00);
188 ArrayList list1 = new ArrayList();
189 list1.add(product);
190 String json = xstream.toXML(list1);
191 assertEquals((JVM.is15()
192 ? "{'list':[{'product':{'name':'Banana','id':123,'price':23}}]}"
193 : "{'list':{'product':[{'name':'Banana','id':123,'price':23}]}}")
194 .replace('\'', '"'), json);
195 ArrayList list2 = (ArrayList)xstream.fromXML(json);
196 assertEquals(json, xstream.toXML(list2));
197 }
198
199 public void testListWithComplexNestedObjects() {
200 ArrayList list1 = new ArrayList();
201 list1.add(new Product("Banana", "123", 23.00));
202 list1.add(new Product("Apple", "47", 11.00));
203 list1.add(new Product("Orange", "100", 42.00));
204 ArrayList tags = new ArrayList();
205 ((Product)list1.get(1)).setTags(tags);
206 tags.add(new Product("Braeburn", "47.1", 10.00));
207 String json = xstream.toXML(list1);
208 assertEquals(
209 (JVM.is15()
210 ? "{'list':[{'product':[{'name':'Banana','id':123,'price':23},{'name':'Apple','id':47,'price':11,'tags':[{'product':{'name':'Braeburn','id':47.1,'price':10}}]},{'name':'Orange','id':100,'price':42}]}]}"
211 : "{'list':{'product':[{'name':'Banana','id':123,'price':23},{'name':'Apple','id':47,'price':11,'tags':{'product':[{'name':'Braeburn','id':47.1,'price':10}]}},{'name':'Orange','id':100,'price':42}]}}")
212 .replace('\'', '"'), json);
213 ArrayList list2 = (ArrayList)xstream.fromXML(json);
214 assertEquals(json, xstream.toXML(list2));
215 }
216
217 public void todoTestEmptyList() {
218 ArrayList list1 = new ArrayList();
219 String json = xstream.toXML(list1);
220 assertEquals("{'list':[]}".replace('\'', '"'), json);
221 ArrayList list2 = (ArrayList)xstream.fromXML(json);
222 assertEquals(json, xstream.toXML(list2));
223 }
224
225 public static class Topic extends StandardObject {
226 long id;
227 String description;
228 Date createdOn;
229 }
230
231 public void testDefaultValue() {
232 Topic topic1 = new Topic();
233 topic1.id = 4711;
234 topic1.description = "JSON";
235 topic1.createdOn = new Timestamp(1000);
236 xstream.alias("topic", Topic.class);
237 String json = xstream.toXML(topic1);
238 assertEquals(
239 "{'topic':{'id':4711,'description':'JSON','createdOn':{'@class':'sql-timestamp','$':'1970-01-01 00:00:01.0'}}}"
240 .replace('\'', '"'), json);
241 Topic topic2 = (Topic)xstream.fromXML(json);
242 assertEquals(json, xstream.toXML(topic2));
243 }
244
245 public void testLongValueWithHighPrecision() {
246 Topic topic1 = new Topic();
247 topic1.id = Long.MAX_VALUE;
248 topic1.description = "JSON";
249 xstream.alias("topic", Topic.class);
250 String json = xstream.toXML(topic1);
251 assertEquals(
252 "{'topic':{'id':9223372036854775807,'description':'JSON'}}"
253 .replace('\'', '"'), json);
254 Topic topic2 = (Topic)xstream.fromXML(json);
255 assertEquals(json, xstream.toXML(topic2));
256 }
257
258 public void testEmbeddedXml() {
259 ArrayList list1 = new ArrayList();
260 list1.add("<xml attribute=\"foo\"><![CDATA[&quot;\"\'<>]]></xml>");
261 String json = xstream.toXML(list1);
262 assertEquals(
263 (JVM.is15()
264 ? "{\"list\":[{\"string\":\"<xml attribute=\\\"foo\\\"><![CDATA[&quot;\\\"'<>]]><\\/xml>\"}]}"
265 : "{\"list\":{\"string\":[\"<xml attribute=\\\"foo\\\"><![CDATA[&quot;\\\"'<>]]><\\/xml>\"]}}"),
266 json);
267 ArrayList list2 = (ArrayList)xstream.fromXML(json);
268 assertEquals(json, xstream.toXML(list2));
269 }
270
271 public void testArrayList() {
272 if (JVM.is15()) {
273 ArrayList list1 = new ArrayList();
274 list1.clear();
275 list1.add(new Integer(12));
276
277 list1.add("string");
278 list1.add(new Integer(13));
279 String json = xstream.toXML(list1);
280
281 ArrayList list2 = (ArrayList)xstream.fromXML(json);
282 assertEquals(json, xstream.toXML(list2));
283 }
284 }
285
286 private static class SpecialCharacters extends StandardObject {
287 String _foo__$_;
288 }
289
290 public void testSpecialNames() {
291 SpecialCharacters sc = new SpecialCharacters();
292 sc._foo__$_ = "bar";
293 String json = xstream.toXML(sc);
294 assertEquals(
295 "{'com.thoughtworks.xstream.io.json.JettisonMappedXmlDriverTest$SpecialCharacters':{'_foo__$_':'bar'}}"
296 .replace('\'', '"'), json);
297 SpecialCharacters sc2 = (SpecialCharacters)xstream.fromXML(json);
298 assertEquals(json, xstream.toXML(sc2));
299 }
300
301 public void todoTestCanMarshalEmbeddedExternalizable() {
302 xstream.alias("owner", OwnerOfExternalizable.class);
303
304 OwnerOfExternalizable in = new OwnerOfExternalizable();
305 in.target = new SomethingExternalizable("Joe", "Walnes");
306 String json = xstream.toXML(in);
307 // already wrong, Jettison reorders elements ...
308 assertEquals("{'owner':{'target':{'int':3,'string':['JoeWalnes','XStream'],'null':''}}}".replace('\'', '"'), json);
309 OwnerOfExternalizable owner = (OwnerOfExternalizable)xstream.fromXML(json);
310 assertEquals(json, xstream.toXML(owner));
311 assertEquals(in.target, owner.target);
312 }
313 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 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 22. June 2006 by Mauro Talevi
10 */
11 package com.thoughtworks.xstream.io.json;
12
13 import java.awt.Color;
14 import java.io.InputStream;
15 import java.io.Reader;
16 import java.math.BigDecimal;
17 import java.math.BigInteger;
18 import java.net.MalformedURLException;
19 import java.net.URL;
20 import java.util.ArrayList;
21 import java.util.Calendar;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Properties;
28 import java.util.Set;
29 import java.util.TimeZone;
30 import java.util.TreeMap;
31
32 import com.thoughtworks.acceptance.objects.Original;
33 import com.thoughtworks.acceptance.objects.OwnerOfExternalizable;
34 import com.thoughtworks.acceptance.objects.Replaced;
35 import com.thoughtworks.acceptance.objects.SomethingExternalizable;
36 import com.thoughtworks.xstream.XStream;
37 import com.thoughtworks.xstream.core.JVM;
38
39 import junit.framework.TestCase;
40
41
42 /**
43 * Some of these test cases are taken from example JSON listed at
44 * http://www.json.org/example.html
45 *
46 * @author Paul Hammant
47 * @author J&ouml;rg Schaible
48 */
49 public class JsonHierarchicalStreamDriverTest extends TestCase {
50 protected XStream xstream;
51
52 /**
53 * @see junit.framework.TestCase#setUp()
54 */
55 protected void setUp() throws Exception {
56 super.setUp();
57 xstream = new XStream(createDriver());
58 }
59
60 protected JsonHierarchicalStreamDriver createDriver() {
61 return new JsonHierarchicalStreamDriver();
62 }
63
64 protected String normalizeExpectation(String expected) {
65 return expected.replace('\'', '"');
66 }
67
68 public void testDoesNotSupportReader() {
69 try {
70 new JsonHierarchicalStreamDriver().createReader((Reader)null);
71 fail("should have barfed");
72 } catch (UnsupportedOperationException uoe) {
73 // expected
74 }
75 }
76
77 public void testDoesNotSupportInputStream() {
78 try {
79 new JsonHierarchicalStreamDriver().createReader((InputStream)null);
80 fail("should have barfed");
81 } catch (UnsupportedOperationException uoe) {
82 // expected
83 }
84 }
85
86 public void testCanMarshalSimpleTypes() {
87
88 String expected = normalizeExpectation(""
89 + "{'innerMessage': {\n"
90 + " 'long1': 5,\n"
91 + " 'long2': 42,\n"
92 + " 'greeting': 'hello',\n"
93 + " 'int1': 2,\n"
94 + " 'int2': 3,\n"
95 + " 'short1': 6,\n"
96 + " 'short2': 7,\n"
97 + " 'byte1': 8,\n"
98 + " 'byte2': 9,\n"
99 + " 'bool1': true,\n"
100 + " 'bool2': false,\n"
101 + " 'char1': 'A',\n"
102 + " 'char2': 'B',\n"
103 + " 'float1': 1.1,\n"
104 + " 'float2': 1.2,\n"
105 + " 'double1': 2.1,\n"
106 + " 'double2': 2.2,\n"
107 + " 'bigInt': 511,\n"
108 + " 'bigDec': 3.14,\n"
109 + " 'innerMessage': {\n"
110 + " 'long1': 0,\n"
111 + " 'greeting': 'bonjour',\n"
112 + " 'int1': 3,\n"
113 + " 'short1': 0,\n"
114 + " 'byte1': 0,\n"
115 + " 'bool1': false,\n"
116 + " 'char1': '\\u0000',\n"
117 + " 'float1': 0.0,\n"
118 + " 'double1': 0.0\n"
119 + " }\n"
120 + "}}");
121
122 xstream.alias("innerMessage", Message.class);
123
124 Message message = new Message("hello");
125 message.long1 = 5L;
126 message.long2 = new Long(42);
127 message.int1 = 2;
128 message.int2 = new Integer(3);
129 message.short1 = (short)6;
130 message.short2 = new Short((short)7);
131 message.byte1 = (byte)8;
132 message.byte2 = new Byte((byte)9);
133 message.bool1 = true;
134 message.bool2 = Boolean.FALSE;
135 message.char1 = 'A';
136 message.char2 = new Character('B');
137 message.float1 = 1.1f;
138 message.float2 = new Float(1.2f);
139 message.double1 = 2.1;
140 message.double2 = new Double(2.2);
141 message.bigInt = new BigInteger(new byte[]{(byte)1, (byte)0xFF});
142 message.bigDec = new BigDecimal(314).divide(
143 new BigDecimal(100), 2, BigDecimal.ROUND_FLOOR);
144
145 Message message2 = new Message("bonjour");
146 message2.int1 = 3;
147
148 message.innerMessage = message2;
149
150 assertEquals(expected, xstream.toXML(message));
151 }
152
153 public static class Message {
154 long long1;
155 Long long2;
156 String greeting;
157 int int1;
158 Integer int2;
159 short short1;
160 Short short2;
161 byte byte1;
162 Byte byte2;
163 boolean bool1;
164 Boolean bool2;
165 char char1;
166 Character char2;
167 float float1;
168 Float float2;
169 double double1;
170 Double double2;
171 BigInteger bigInt;
172 BigDecimal bigDec;
173 Message innerMessage;
174
175 public Message(String greeting) {
176 this.greeting = greeting;
177 }
178 }
179
180 protected String expectedMenuStart = ""
181 + "{'menu': {\n"
182 + " 'id': 'file',\n"
183 + " 'value': 'File:',\n"
184 + " 'popup': {\n"
185 + " 'menuitem': [";
186 protected String expectedNew = ""
187 + " {\n"
188 + " 'value': 'New',\n"
189 + " 'onclick': 'CreateNewDoc()'\n"
190 + " }";
191 protected String expectedOpen = ""
192 + " {\n"
193 + " 'value': 'Open',\n"
194 + " 'onclick': 'OpenDoc()'\n"
195 + " }";
196 protected String expectedClose = ""
197 + " {\n"
198 + " 'value': 'Close',\n"
199 + " 'onclick': 'CloseDoc()'\n"
200 + " }";
201 protected String expectedMenuEnd = "" + " ]\n" + " }\n" + "}}";
202 protected String expected = "" //
203 + expectedMenuStart
204 + "\n"
205 + expectedNew
206 + ",\n"
207 + expectedOpen
208 + ",\n"
209 + expectedClose
210 + "\n" + expectedMenuEnd;
211
212 public void testCanMarshalLists() {
213
214 // This from http://www.json.org/example.html
215
216 xstream.alias("menu", MenuWithList.class);
217 xstream.alias("menuitem", MenuItem.class);
218
219 MenuWithList menu = new MenuWithList();
220
221 assertEquals(normalizeExpectation(expected), xstream.toXML(menu));
222 }
223
224 public void testCanMarshalArrays() {
225
226 xstream.alias("menu", MenuWithArray.class);
227 xstream.alias("menuitem", MenuItem.class);
228
229 MenuWithArray menu = new MenuWithArray();
230
231 assertEquals(normalizeExpectation(expected), xstream.toXML(menu));
232 }
233
234 public void testCanMarshalSets() {
235
236 // This from http://www.json.org/example.html
237
238 xstream.alias("menu", MenuWithSet.class);
239 xstream.alias("menuitem", MenuItem.class);
240
241 MenuWithSet menu = new MenuWithSet();
242
243 String json = xstream.toXML(menu);
244 assertTrue(json.startsWith(normalizeExpectation(expectedMenuStart)));
245 assertTrue(json.indexOf(expectedNew.replace('\'', '"')) > 0);
246 assertTrue(json.indexOf(expectedOpen.replace('\'', '"')) > 0);
247 assertTrue(json.indexOf(expectedClose.replace('\'', '"')) > 0);
248 assertTrue(json.endsWith(expectedMenuEnd.replace('\'', '"')));
249 }
250
251 public static class MenuWithList {
252 String id = "file";
253 String value = "File:";
254 PopupWithList popup = new PopupWithList();
255 }
256
257 public static class PopupWithList {
258 List menuitem;
259 {
260 menuitem = new ArrayList();
261 menuitem.add(new MenuItem("New", "CreateNewDoc()"));
262 menuitem.add(new MenuItem("Open", "OpenDoc()"));
263 menuitem.add(new MenuItem("Close", "CloseDoc()"));
264 }
265 }
266
267 public static class MenuWithArray {
268 String id = "file";
269 String value = "File:";
270 PopupWithArray popup = new PopupWithArray();
271 }
272
273 public static class PopupWithArray {
274 MenuItem[] menuitem = new MenuItem[]{
275 new MenuItem("New", "CreateNewDoc()"), new MenuItem("Open", "OpenDoc()"),
276 new MenuItem("Close", "CloseDoc()")};
277 }
278
279 public static class MenuWithSet {
280 String id = "file";
281 String value = "File:";
282 PopupWithSet popup = new PopupWithSet();
283 }
284
285 public static class PopupWithSet {
286 Set menuitem;
287 {
288 menuitem = new HashSet();
289 menuitem.add(new MenuItem("New", "CreateNewDoc()"));
290 menuitem.add(new MenuItem("Open", "OpenDoc()"));
291 menuitem.add(new MenuItem("Close", "CloseDoc()"));
292 }
293
294 }
295
296 public static class MenuItem {
297 public String value; // assume unique
298 public String onclick;
299
300 public MenuItem(String value, String onclick) {
301 this.value = value;
302 this.onclick = onclick;
303 }
304
305 public int hashCode() {
306 return value.hashCode();
307 }
308
309 }
310
311 public void testCanMarshalTypesWithPrimitives() {
312
313 // This also from http://www.expected.org/example.html
314
315 String expected = normalizeExpectation("" //
316 + "{'widget': {\n"
317 + " 'debug': 'on',\n"
318 + " 'window': {\n"
319 + " 'title': 'Sample Konfabulator Widget',\n"
320 + " 'name': 'main_window',\n"
321 + " 'width': 500,\n"
322 + " 'height': 500\n"
323 + " },\n"
324 + " 'image': {\n"
325 + " 'src': 'Images/Sun.png',\n"
326 + " 'name': 'sun1',\n"
327 + " 'hOffset': 250,\n"
328 + " 'vOffset': 250,\n"
329 + " 'alignment': 'center'\n"
330 + " },\n"
331 + " 'text': {\n"
332 + " 'data': 'Click Here',\n"
333 + " 'size': 36,\n"
334 + " 'style': 'bold',\n"
335 + " 'name': 'text1',\n"
336 + " 'hOffset': 250,\n"
337 + " 'vOffset': 100,\n"
338 + " 'alignment': 'center',\n"
339 + " 'onMouseUp': 'sun1.opacity = (sun1.opacity / 100) * 90;'\n"
340 + " }\n"
341 + "}}");
342
343 xstream.alias("widget", Widget.class);
344 xstream.alias("window", Window.class);
345 xstream.alias("image", Image.class);
346 xstream.alias("text", Text.class);
347
348 Widget widget = new Widget();
349
350 assertEquals(expected, xstream.toXML(widget));
351
352 }
353
354 public static class Widget {
355 String debug = "on";
356 Window window = new Window();
357 Image image = new Image();
358 Text text = new Text();
359 }
360
361 public static class Window {
362 String title = "Sample Konfabulator Widget";
363 String name = "main_window";
364 int width = 500;
365 int height = 500;
366 }
367
368 public static class Image {
369 String src = "Images/Sun.png";
370 String name = "sun1";
371 int hOffset = 250;
372 int vOffset = 250;
373 String alignment = "center";
374 }
375
376 public static class Text {
377 String data = "Click Here";
378 int size = 36;
379 String style = "bold";
380 String name = "text1";
381 int hOffset = 250;
382 int vOffset = 100;
383 String alignment = "center";
384 String onMouseUp = "sun1.opacity = (sun1.opacity / 100) * 90;";
385 }
386
387 public void testColor() {
388 boolean isHeadless = Boolean.valueOf(System.getProperty("java.awt.headless", "false")).booleanValue();
389 if (!isHeadless || JVM.is15()) {
390 Color color = Color.black;
391 String expected = normalizeExpectation("" //
392 + "{'awt-color': {\n"
393 + " 'red': 0,\n"
394 + " 'green': 0,\n"
395 + " 'blue': 0,\n"
396 + " 'alpha': 255\n"
397 + "}}");
398 assertEquals(expected, xstream.toXML(color));
399 }
400 }
401
402 public void testDoesHandleQuotesAndEscapes() {
403 String[] strings = new String[]{
404 "last\"", "\"first", "\"between\"", "around \"\" it", "back\\slash",};
405 String expected = normalizeExpectation(""
406 + "{'string-array': [\n"
407 + " 'last\\\"',\n"
408 + " '\\\"first',\n"
409 + " '\\\"between\\\"',\n"
410 + " 'around \\\"\\\" it',\n"
411 + " 'back\\\\slash'\n"
412 + "]}");
413 assertEquals(expected, xstream.toXML(strings));
414 }
415
416 public void testDoesEscapeValuesAccordingRfc4627() {
417 String expected = normalizeExpectation("{'string': '\\u0000\\u0001\\u001f \uffee'}");
418 assertEquals(expected, xstream.toXML("\u0000\u0001\u001f\u0020\uffee"));
419 }
420
421 public void testSimpleInteger() {
422 String expected = normalizeExpectation("{'int': 123}");
423 assertEquals(expected, xstream.toXML(new Integer(123)));
424 }
425
426 public void testBracesAndSquareBracketsAreNotEscaped() {
427 String expected = normalizeExpectation("{'string': '..{}[],,'}");
428 assertEquals(expected, xstream.toXML("..{}[],,"));
429 }
430
431 public void testCanMarshalSimpleTypesWithNullMembers() {
432 Msg message = new Msg("hello");
433 Msg message2 = new Msg(null);
434 message.innerMessage = message2;
435
436 xstream.alias("innerMessage", Msg.class);
437
438 String expected = normalizeExpectation(""
439 + "{'innerMessage': {\n"
440 + " 'greeting': 'hello',\n"
441 + " 'innerMessage': {}\n"
442 + "}}");
443 assertEquals(expected, xstream.toXML(message));
444 }
445
446 public static class Msg {
447 String greeting;
448 Msg innerMessage;
449
450 public Msg(String greeting) {
451 this.greeting = greeting;
452 }
453 }
454
455 public void testCanMarshalElementWithEmptyArray() {
456 xstream.alias("element", ElementWithEmptyArray.class);
457
458 String expected = normalizeExpectation("" //
459 + "{'element': {\n"
460 + " 'array': []\n"
461 + "}}");
462 assertEquals(expected, xstream.toXML(new ElementWithEmptyArray()));
463 }
464
465 public static class ElementWithEmptyArray {
466 String[] array = new String[0];
467 }
468
469 public void testCanMarshalJavaMap() {
470 String entry1 = "" // entry 1
471 + " [\n"
472 + " 'one',\n"
473 + " 1\n"
474 + " ]";
475 String entry2 = "" // entry 2
476 + " [\n"
477 + " 'two',\n"
478 + " 2\n"
479 + " ]";
480
481 final Map map = new HashMap();
482 map.put("one", new Integer(1));
483 map.put("two", new Integer(2));
484 String actual = xstream.toXML(map);
485 int idx1 = actual.indexOf("one");
486 int idx2 = actual.indexOf("two");
487
488 String expected = normalizeExpectation(""
489 + "{'map': [\n"
490 + ((idx1 < idx2 ? entry1 : entry2) + ",\n")
491 + ((idx1 < idx2 ? entry2 : entry1) + "\n") // no comma
492 + "]}");
493 assertEquals(expected, actual);
494 }
495
496 public void testCanMarshalProperties() {
497 String entry1 = "" // entry 1
498 + " {\n"
499 + " '@name': 'one',\n"
500 + " '@value': '1'\n"
501 + " }";
502 String entry2 = "" // entry 2
503 + " {\n"
504 + " '@name': 'two',\n"
505 + " '@value': '2'\n"
506 + " }";
507
508 final Properties properties = new Properties();
509 properties.setProperty("one", "1");
510 properties.setProperty("two", "2");
511 String actual = xstream.toXML(properties);
512 int idx1 = actual.indexOf("one");
513 int idx2 = actual.indexOf("two");
514
515 String expected = normalizeExpectation(""
516 + "{'properties': [\n"
517 + ((idx1 < idx2 ? entry1 : entry2) + ",\n")
518 + ((idx1 < idx2 ? entry2 : entry1) + "\n") // no comma
519 + "]}");
520 assertEquals(expected, actual);
521 }
522
523 final static class MapHolder {
524 private Map map = new HashMap();
525 }
526
527 public void testCanMarshalNestedMap() {
528 xstream.alias("holder", MapHolder.class);
529 String entry1 = "" // entry 1
530 + " [\n"
531 + " 'one',\n"
532 + " 1\n"
533 + " ]";
534 String entry2 = "" // entry 2
535 + " [\n"
536 + " 'two',\n"
537 + " 2\n"
538 + " ]";
539
540 final MapHolder holder = new MapHolder();
541 holder.map.put("one", new Integer(1));
542 holder.map.put("two", new Integer(2));
543 String actual = xstream.toXML(holder);
544 int idx1 = actual.indexOf("one");
545 int idx2 = actual.indexOf("two");
546
547 String expected = normalizeExpectation(""
548 + "{'holder': {\n"
549 + " 'map': [\n"
550 + ((idx1 < idx2 ? entry1 : entry2) + ",\n")
551 + ((idx1 < idx2 ? entry2 : entry1) + "\n")
552 + " ]\n" // no comma
553 + "}}");
554 assertEquals(expected, actual);
555 }
556
557 static class CollectionKeeper {
558 Collection coll = new ArrayList();
559 }
560
561 public void testIgnoresAttributeForCollectionMember() {
562 xstream.alias("keeper", CollectionKeeper.class);
563 String expected = normalizeExpectation("" //
564 + "{'keeper': {\n"
565 + " 'coll': [\n"
566 + " 'one',\n"
567 + " 'two'\n"
568 + " ]\n"
569 + "}}");
570
571 final CollectionKeeper holder = new CollectionKeeper();
572 holder.coll.add("one");
573 holder.coll.add("two");
574 assertEquals(expected, xstream.toXML(holder));
575 }
576
577 // Writing attributes, the writer has no clue about their original type.
578 public void testDoesWriteAttributesAsStringValues() {
579 xstream.alias("window", Window.class);
580 xstream.useAttributeFor("width", int.class);
581 xstream.useAttributeFor("height", int.class);
582 String expected = normalizeExpectation(""
583 + "{'window': {\n"
584 + " '@width': '500',\n"
585 + " '@height': '500',\n"
586 + " 'title': 'JUnit'\n"
587 + "}}");
588
589 final Window window = new Window();
590 window.title = "JUnit";
591 window.name = null;
592 assertEquals(expected, xstream.toXML(window));
593 }
594
595 static class Person {
596 String firstName;
597 String lastName;
598 Calendar dateOfBirth;
599 Map titles = new TreeMap();
600 }
601
602 public void testCanWriteEmbeddedCalendar() {
603 xstream.alias("person", Person.class);
604 String expected = normalizeExpectation(""
605 + "{'list': [\n"
606 + " {\n"
607 + " 'firstName': 'Joe',\n"
608 + " 'lastName': 'Walnes',\n"
609 + " 'dateOfBirth': {\n"
610 + " 'time': -2177539200000,\n"
611 + " 'timezone': 'Europe/London'\n"
612 + " },\n"
613 + " 'titles': [\n"
614 + " [\n"
615 + " '1',\n"
616 + " 'Mr'\n"
617 + " ]\n"
618 + " ]\n"
619 + " }\n"
620 + "]}");
621
622 Person person = new Person();
623 person.firstName = "Joe";
624 person.lastName = "Walnes";
625 person.dateOfBirth = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"));
626 person.dateOfBirth.clear();
627 person.dateOfBirth.set(1900, Calendar.DECEMBER, 31);
628 person.titles.put("1", "Mr");
629 List list = new ArrayList();
630 list.add(person);
631 assertEquals(expected, xstream.toXML(list));
632 }
633
634 static class SingleValue {
635 long l;
636 URL url;
637 }
638
639 public void testSupportsAllConvertersWithASingleValue() throws MalformedURLException {
640 xstream.alias("sv", SingleValue.class);
641 String expected = normalizeExpectation(""
642 + "{'sv': {\n"
643 + " 'l': 4711,\n"
644 + " 'url': 'http://localhost:8888'\n"
645 + "}}");
646
647 SingleValue value = new SingleValue();
648 value.l = 4711;
649 value.url = new URL("http://localhost:8888");
650 assertEquals(expected, xstream.toXML(value));
651 }
652
653 static class SystemAttributes {
654 String name;
655 Object object;
656 Original original;
657 }
658
659 public void testWillWriteTagValueAsDefaultValueIfNecessary() {
660 xstream.alias("sa", SystemAttributes.class);
661 xstream.alias("original", Original.class);
662 xstream.alias("replaced", Replaced.class);
663
664 SystemAttributes sa = new SystemAttributes();
665 sa.name = "joe";
666 sa.object = "walnes";
667 sa.original = new Original("hello world");
668
669 String expected = normalizeExpectation(""
670 + "{'sa': {\n"
671 + " 'name': 'joe',\n"
672 + " 'object': {\n"
673 + " '@class': 'string',\n"
674 + " '$': 'walnes'\n"
675 +" },\n"
676 + " 'original': {\n"
677 + " '@resolves-to': 'replaced',\n"
678 + " 'replacedValue': 'HELLO WORLD'\n"
679 + " }\n"
680 + "}}");
681
682 assertEquals(expected, xstream.toXML(sa));
683 }
684
685 public void testRealTypeIsHonoredWhenWritingTheValue() {
686 xstream.alias("sa", SystemAttributes.class);
687
688 List list = new ArrayList();
689 list.add("joe");
690 list.add("mauro");
691 SystemAttributes[] sa = new SystemAttributes[2];
692 sa[0] = new SystemAttributes();
693 sa[0].name = "year";
694 sa[0].object = new Integer(2000);
695 sa[1] = new SystemAttributes();
696 sa[1].name = "names";
697 sa[1].object = list;
698
699 String expected = normalizeExpectation(""
700 + "{'sa-array': [\n"
701 + " {\n"
702 + " 'name': 'year',\n"
703 + " 'object': {\n"
704 + " '@class': 'int',\n"
705 + " '$': 2000\n"
706 + " }\n"
707 + " },\n"
708 + " {\n"
709 + " 'name': 'names',\n"
710 + " 'object': [\n"
711 + " 'joe',\n"
712 + " 'mauro'\n"
713 + " ]\n"
714 + " }\n"
715 + "]}");
716
717 assertEquals(expected, xstream.toXML(sa));
718 }
719
720 public void testCanMarshalExternalizable() {
721 xstream.alias("ext", SomethingExternalizable.class);
722
723 SomethingExternalizable in = new SomethingExternalizable("Joe", "Walnes");
724 String expected = normalizeExpectation(""
725 + "{'ext': [\n"
726 + " 3,\n"
727 + " 'JoeWalnes',\n"
728 + " {},\n"
729 + " 'XStream'\n"
730 + "]}");
731
732 assertEquals(expected, xstream.toXML(in));
733 }
734
735 public void testCanMarshalEmbeddedExternalizable() {
736 xstream.alias("owner", OwnerOfExternalizable.class);
737
738 OwnerOfExternalizable in = new OwnerOfExternalizable();
739 in.target = new SomethingExternalizable("Joe", "Walnes");
740 String expected = normalizeExpectation(""
741 + "{'owner': {\n"
742 + " 'target': [\n"
743 + " 3,\n"
744 + " 'JoeWalnes',\n"
745 + " {},\n"
746 + " 'XStream'\n"
747 + " ]\n"
748 + "}}");
749
750 assertEquals(expected, xstream.toXML(in));
751 }
752 }
0 /*
1 * Copyright (C) 2009, 2010, 2011, 2013 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 02. September 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import java.io.StringWriter;
13 import java.io.Writer;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.LinkedList;
18 import java.util.Map;
19 import java.util.Properties;
20 import java.util.TreeSet;
21
22 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
23 import com.thoughtworks.acceptance.objects.SampleLists;
24 import com.thoughtworks.acceptance.someobjects.Handler;
25 import com.thoughtworks.acceptance.someobjects.Protocol;
26 import com.thoughtworks.acceptance.someobjects.X;
27 import com.thoughtworks.acceptance.someobjects.Y;
28 import com.thoughtworks.xstream.XStream;
29 import com.thoughtworks.xstream.converters.Converter;
30 import com.thoughtworks.xstream.converters.MarshallingContext;
31 import com.thoughtworks.xstream.converters.UnmarshallingContext;
32 import com.thoughtworks.xstream.converters.extended.ToStringConverter;
33 import com.thoughtworks.xstream.core.util.OrderRetainingMap;
34 import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
35 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
36 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
37 import com.thoughtworks.xstream.io.json.JsonWriter.Format;
38
39 import junit.framework.AssertionFailedError;
40 import junit.framework.Test;
41 import junit.framework.TestCase;
42 import junit.framework.TestSuite;
43
44
45 /**
46 * Tests the {@link JsonWriter} formats.
47 *
48 * @author J&ouml;rg Schaible
49 */
50 public class JsonWriterFormatTest extends TestCase {
51
52 private XStream xstream;
53 private Object target;
54 private final int mode;
55 private final Format format;
56 private final String json;
57
58 public static class YString extends Y {
59 public YString(String y) {
60 this.yField = y;
61 }
62 public String toString() {
63 return yField;
64 }
65 }
66
67 private final static class HandlerConverter implements Converter {
68 public boolean canConvert(Class type) {
69 return type == Handler.class;
70 }
71
72 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
73 Handler h = (Handler)source;
74 writer.startNode("str");
75 writer.setValue("test");
76 writer.endNode();
77 writer.startNode("protocol");
78 context.convertAnother(h.getProtocol());
79 writer.endNode();
80 ExtendedHierarchicalStreamWriterHelper.startNode(writer, "i", int.class);
81 writer.setValue("42");
82 writer.endNode();
83 }
84
85 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
86 reader.moveDown();
87 reader.moveUp();
88 reader.moveDown();
89 Protocol p = (Protocol)context.convertAnother(null, Protocol.class);
90 reader.moveUp();
91 reader.moveDown();
92 reader.moveUp();
93 return new Handler(p);
94 }
95 }
96
97 public JsonWriterFormatTest(
98 String name, Object target, String json, int writerMode, JsonWriter.Format format) {
99 super(name);
100 this.target = target;
101 this.json = json;
102 this.mode = writerMode;
103 this.format = format;
104
105 xstream = new XStream();
106 xstream.setMode(name.endsWith("+ID") ? XStream.ID_REFERENCES : XStream.NO_REFERENCES);
107 xstream.alias("chseq", CharSequence.class);
108 xstream.alias("oss", OpenSourceSoftware.class);
109 xstream.alias("collections", SampleLists.class);
110 xstream.alias("x", X.class);
111 xstream.alias("ys", YString.class);
112 xstream.alias("h", Handler.class);
113 xstream.useAttributeFor(OpenSourceSoftware.class, "license");
114 try {
115 xstream.registerConverter(new ToStringConverter(YString.class));
116 } catch (NoSuchMethodException e) {
117 throw new AssertionFailedError(e.getMessage());
118 }
119 xstream.registerConverter(new HandlerConverter());
120 }
121
122 protected void runTest() throws Throwable {
123 assertEquals(json, toJSON(mode, format));
124 }
125
126 private String toJSON(int mode, JsonWriter.Format format) {
127 final StringWriter writer = new StringWriter(1024);
128 try {
129 writeJSON(writer, mode, format);
130 return writer.toString();
131 } finally {
132 //System.out.println(writer.toString() + " ---> " + getName());
133 }
134 }
135
136 private void writeJSON(Writer writer, int mode, JsonWriter.Format format) {
137 JsonWriter jsonWriter = new JsonWriter(writer, mode, format, 0);
138 try {
139 xstream.marshal(target, jsonWriter);
140 } finally {
141 jsonWriter.flush();
142 }
143 }
144
145 public static Test suite() {
146 final Map modes = new OrderRetainingMap();
147 modes.put("optimized", new Integer(0));
148 modes.put("noRoot", new Integer(AbstractJsonWriter.DROP_ROOT_MODE));
149 modes.put("explicit", new Integer(AbstractJsonWriter.EXPLICIT_MODE));
150
151 final Map formats = new OrderRetainingMap();
152 formats.put("Minimal", new JsonWriter.Format(
153 new char[0], new char[0], JsonWriter.Format.COMPACT_EMPTY_ELEMENT));
154 formats.put("Pretty", new JsonWriter.Format(
155 " ".toCharArray(), "\n".toCharArray(), JsonWriter.Format.SPACE_AFTER_LABEL));
156 formats.put("Compact", new JsonWriter.Format(
157 " ".toCharArray(), "\n".toCharArray(), JsonWriter.Format.SPACE_AFTER_LABEL
158 | JsonWriter.Format.COMPACT_EMPTY_ELEMENT));
159
160 final Properties properties = new Properties();
161 properties.put("one", "1");
162 final X x = new X();
163 x.anInt = 42;
164 x.aStr = "X";
165 x.innerObj = new YString("Y");
166 final X emptyX = new X();
167 emptyX.innerObj = new Y();
168 final SampleLists lists = new SampleLists();
169 lists.good = new LinkedList();
170 lists.good.add("XStream");
171 lists.bad = new TreeSet();
172 lists.bad.add(new X());
173 final Map targets = new OrderRetainingMap();
174 targets.put("String", "text");
175 targets.put("CharSequenceArray", new CharSequence[]{"text", new StringBuffer("buffer"), null});
176 targets.put("CharSequenceArray+ID", new CharSequence[]{"text", new StringBuffer("buffer"), null});
177 targets.put("EmptyStringArray", new String[][]{new String[0]});
178 targets.put("EmptyStringArray+ID", new String[][]{new String[0]});
179 targets.put("Properties", properties);
180 targets.put("Object", new OpenSourceSoftware("Codehaus", "XStream", "BSD"));
181 targets.put("AttributeOnly", new OpenSourceSoftware(null, null, "BSD"));
182 targets.put("X", x);
183 targets.put("EmptyX", emptyX);
184 targets.put("Collections", lists);
185 targets.put("EmptyList", new ArrayList());
186 targets.put("CustomConverter", new Handler(new Protocol("ldap")));
187
188 final Map results = new HashMap();
189 results.put("optimizedMinimalString", "{'string':'text'}");
190 results.put("optimizedPrettyString", "{'string': 'text'}");
191 results.put("optimizedCompactString", "{'string': 'text'}");
192 results.put("noRootMinimalString", "'text'");
193 results.put("noRootPrettyString", "'text'");
194 results.put("noRootCompactString", "'text'");
195 results.put("explicitMinimalString", "{'string':[[],['text']]}");
196 results.put("explicitPrettyString", "{'string': [\n [\n ],\n [\n 'text'\n ]\n]}");
197 results.put("explicitCompactString", "{'string': [\n [],\n [\n 'text'\n ]\n]}");
198 results.put("optimizedMinimalCharSequenceArray", "{'chseq-array':['text','buffer',null]}");
199 results.put("optimizedPrettyCharSequenceArray", "{'chseq-array': [\n 'text',\n 'buffer',\n null\n]}");
200 results.put("optimizedCompactCharSequenceArray", "{'chseq-array': [\n 'text',\n 'buffer',\n null\n]}");
201 results.put("noRootMinimalCharSequenceArray", "['text','buffer',null]");
202 results.put("noRootPrettyCharSequenceArray", "[\n 'text',\n 'buffer',\n null\n]");
203 results.put("noRootCompactCharSequenceArray", "[\n 'text',\n 'buffer',\n null\n]");
204 results.put("explicitMinimalCharSequenceArray", "{'chseq-array':[[],[{'string':[[],['text']]},{'string-buffer':[[],['buffer']]},{'null':[[],[null]]}]]}");
205 results.put("explicitPrettyCharSequenceArray", "{'chseq-array': [\n [\n ],\n [\n {\n 'string': [\n [\n ],\n [\n 'text'\n ]\n ]\n },\n {\n 'string-buffer': [\n [\n ],\n [\n 'buffer'\n ]\n ]\n },\n {\n 'null': [\n [\n ],\n [\n null\n ]\n ]\n }\n ]\n]}");
206 results.put("explicitCompactCharSequenceArray", "{'chseq-array': [\n [],\n [\n {\n 'string': [\n [],\n [\n 'text'\n ]\n ]\n },\n {\n 'string-buffer': [\n [],\n [\n 'buffer'\n ]\n ]\n },\n {\n 'null': [\n [],\n [\n null\n ]\n ]\n }\n ]\n]}");
207 results.put("optimizedMinimalCharSequenceArray+ID", "{'chseq-array':['text',{'@id':'2','$':'buffer'},null]}");
208 results.put("optimizedPrettyCharSequenceArray+ID", "{'chseq-array': [\n 'text',\n {\n '@id': '2',\n '$': 'buffer'\n },\n null\n]}");
209 results.put("optimizedCompactCharSequenceArray+ID", "{'chseq-array': [\n 'text',\n {\n '@id': '2',\n '$': 'buffer'\n },\n null\n]}");
210 results.put("noRootMinimalCharSequenceArray+ID", "['text',{'@id':'2','$':'buffer'},null]");
211 results.put("noRootPrettyCharSequenceArray+ID", "[\n 'text',\n {\n '@id': '2',\n '$': 'buffer'\n },\n null\n]");
212 results.put("noRootCompactCharSequenceArray+ID", "[\n 'text',\n {\n '@id': '2',\n '$': 'buffer'\n },\n null\n]");
213 results.put("explicitMinimalCharSequenceArray+ID", "{'chseq-array':[[{'id':'1'}],[{'string':[[],['text']]},{'string-buffer':[[{'id':'2'}],['buffer']]},{'null':[[],[null]]}]]}");
214 results.put("explicitPrettyCharSequenceArray+ID", "{'chseq-array': [\n [\n {\n 'id': '1'\n }\n ],\n [\n {\n 'string': [\n [\n ],\n [\n 'text'\n ]\n ]\n },\n {\n 'string-buffer': [\n [\n {\n 'id': '2'\n }\n ],\n [\n 'buffer'\n ]\n ]\n },\n {\n 'null': [\n [\n ],\n [\n null\n ]\n ]\n }\n ]\n]}");
215 results.put("explicitCompactCharSequenceArray+ID", "{'chseq-array': [\n [\n {\n 'id': '1'\n }\n ],\n [\n {\n 'string': [\n [],\n [\n 'text'\n ]\n ]\n },\n {\n 'string-buffer': [\n [\n {\n 'id': '2'\n }\n ],\n [\n 'buffer'\n ]\n ]\n },\n {\n 'null': [\n [],\n [\n null\n ]\n ]\n }\n ]\n]}");
216 results.put("optimizedMinimalEmptyStringArray", "{'string-array-array':[[]]}");
217 results.put("optimizedPrettyEmptyStringArray", "{'string-array-array': [\n [\n ]\n]}");
218 results.put("optimizedCompactEmptyStringArray", "{'string-array-array': [\n []\n]}");
219 results.put("noRootMinimalEmptyStringArray", "[[]]");
220 results.put("noRootPrettyEmptyStringArray", "[\n [\n ]\n]");
221 results.put("noRootCompactEmptyStringArray", "[\n []\n]");
222 results.put("explicitMinimalEmptyStringArray", "{'string-array-array':[[],[{'string-array':[[],[]]}]]}");
223 results.put("explicitPrettyEmptyStringArray", "{'string-array-array': [\n [\n ],\n [\n {\n 'string-array': [\n [\n ],\n [\n ]\n ]\n }\n ]\n]}");
224 results.put("explicitCompactEmptyStringArray", "{'string-array-array': [\n [],\n [\n {\n 'string-array': [\n [],\n []\n ]\n }\n ]\n]}");
225 results.put("optimizedMinimalEmptyStringArray+ID", "{'string-array-array':[[]]}");
226 results.put("optimizedPrettyEmptyStringArray+ID", "{'string-array-array': [\n [\n ]\n]}");
227 results.put("optimizedCompactEmptyStringArray+ID", "{'string-array-array': [\n []\n]}");
228 results.put("noRootMinimalEmptyStringArray+ID", "[[]]");
229 results.put("noRootPrettyEmptyStringArray+ID", "[\n [\n ]\n]");
230 results.put("noRootCompactEmptyStringArray+ID", "[\n []\n]");
231 results.put("explicitMinimalEmptyStringArray+ID", "{'string-array-array':[[{'id':'1'}],[{'string-array':[[{'id':'2'}],[]]}]]}");
232 results.put("explicitPrettyEmptyStringArray+ID", "{'string-array-array': [\n [\n {\n 'id': '1'\n }\n ],\n [\n {\n 'string-array': [\n [\n {\n 'id': '2'\n }\n ],\n [\n ]\n ]\n }\n ]\n]}");
233 results.put("explicitCompactEmptyStringArray+ID", "{'string-array-array': [\n [\n {\n 'id': '1'\n }\n ],\n [\n {\n 'string-array': [\n [\n {\n 'id': '2'\n }\n ],\n []\n ]\n }\n ]\n]}");
234 results.put("optimizedMinimalProperties", "{'properties':[{'@name':'one','@value':'1'}]}");
235 results.put("optimizedPrettyProperties", "{'properties': [\n {\n '@name': 'one',\n '@value': '1'\n }\n]}");
236 results.put("optimizedCompactProperties", "{'properties': [\n {\n '@name': 'one',\n '@value': '1'\n }\n]}");
237 results.put("noRootMinimalProperties", "[{'@name':'one','@value':'1'}]");
238 results.put("noRootPrettyProperties", "[\n {\n '@name': 'one',\n '@value': '1'\n }\n]");
239 results.put("noRootCompactProperties", "[\n {\n '@name': 'one',\n '@value': '1'\n }\n]");
240 results.put("explicitMinimalProperties", "{'properties':[[],[{'property':[[{'name':'one','value':'1'}],[]]}]]}");
241 results.put("explicitPrettyProperties", "{'properties': [\n [\n ],\n [\n {\n 'property': [\n [\n {\n 'name': 'one',\n 'value': '1'\n }\n ],\n [\n ]\n ]\n }\n ]\n]}");
242 results.put("explicitCompactProperties", "{'properties': [\n [],\n [\n {\n 'property': [\n [\n {\n 'name': 'one',\n 'value': '1'\n }\n ],\n []\n ]\n }\n ]\n]}");
243 results.put("optimizedMinimalObject", "{'oss':{'@license':'BSD','vendor':'Codehaus','name':'XStream'}}");
244 results.put("optimizedPrettyObject", "{'oss': {\n '@license': 'BSD',\n 'vendor': 'Codehaus',\n 'name': 'XStream'\n}}");
245 results.put("optimizedCompactObject", "{'oss': {\n '@license': 'BSD',\n 'vendor': 'Codehaus',\n 'name': 'XStream'\n}}");
246 results.put("noRootMinimalObject", "{'@license':'BSD','vendor':'Codehaus','name':'XStream'}");
247 results.put("noRootPrettyObject", "{\n '@license': 'BSD',\n 'vendor': 'Codehaus',\n 'name': 'XStream'\n}");
248 results.put("noRootCompactObject", "{\n '@license': 'BSD',\n 'vendor': 'Codehaus',\n 'name': 'XStream'\n}");
249 results.put("explicitMinimalObject", "{'oss':[[{'license':'BSD'}],[{'vendor':[[],['Codehaus']]},{'name':[[],['XStream']]}]]}");
250 results.put("explicitPrettyObject", "{'oss': [\n [\n {\n 'license': 'BSD'\n }\n ],\n [\n {\n 'vendor': [\n [\n ],\n [\n 'Codehaus'\n ]\n ]\n },\n {\n 'name': [\n [\n ],\n [\n 'XStream'\n ]\n ]\n }\n ]\n]}");
251 results.put("explicitCompactObject", "{'oss': [\n [\n {\n 'license': 'BSD'\n }\n ],\n [\n {\n 'vendor': [\n [],\n [\n 'Codehaus'\n ]\n ]\n },\n {\n 'name': [\n [],\n [\n 'XStream'\n ]\n ]\n }\n ]\n]}");
252 results.put("optimizedMinimalAttributeOnly", "{'oss':{'@license':'BSD'}}");
253 results.put("optimizedPrettyAttributeOnly", "{'oss': {\n '@license': 'BSD'\n}}");
254 results.put("optimizedCompactAttributeOnly", "{'oss': {\n '@license': 'BSD'\n}}");
255 results.put("noRootMinimalAttributeOnly", "{'@license':'BSD'}");
256 results.put("noRootPrettyAttributeOnly", "{\n '@license': 'BSD'\n}");
257 results.put("noRootCompactAttributeOnly", "{\n '@license': 'BSD'\n}");
258 results.put("explicitMinimalAttributeOnly", "{'oss':[[{'license':'BSD'}],[]]}");
259 results.put("explicitPrettyAttributeOnly", "{'oss': [\n [\n {\n 'license': 'BSD'\n }\n ],\n [\n ]\n]}");
260 results.put("explicitCompactAttributeOnly", "{'oss': [\n [\n {\n 'license': 'BSD'\n }\n ],\n []\n]}");
261 results.put("optimizedMinimalX", "{'x':{'aStr':'X','anInt':42,'innerObj':{'@class':'ys','$':'Y'}}}");
262 results.put("optimizedPrettyX", "{'x': {\n 'aStr': 'X',\n 'anInt': 42,\n 'innerObj': {\n '@class': 'ys',\n '$': 'Y'\n }\n}}");
263 results.put("optimizedCompactX", "{'x': {\n 'aStr': 'X',\n 'anInt': 42,\n 'innerObj': {\n '@class': 'ys',\n '$': 'Y'\n }\n}}");
264 results.put("noRootMinimalX", "{'aStr':'X','anInt':42,'innerObj':{'@class':'ys','$':'Y'}}");
265 results.put("noRootPrettyX", "{\n 'aStr': 'X',\n 'anInt': 42,\n 'innerObj': {\n '@class': 'ys',\n '$': 'Y'\n }\n}");
266 results.put("noRootCompactX", "{\n 'aStr': 'X',\n 'anInt': 42,\n 'innerObj': {\n '@class': 'ys',\n '$': 'Y'\n }\n}");
267 results.put("explicitMinimalX", "{'x':[[],[{'aStr':[[],['X']]},{'anInt':[[],[42]]},{'innerObj':[[{'class':'ys'}],['Y']]}]]}");
268 results.put("explicitPrettyX", "{'x': [\n [\n ],\n [\n {\n 'aStr': [\n [\n ],\n [\n 'X'\n ]\n ]\n },\n {\n 'anInt': [\n [\n ],\n [\n 42\n ]\n ]\n },\n {\n 'innerObj': [\n [\n {\n 'class': 'ys'\n }\n ],\n [\n 'Y'\n ]\n ]\n }\n ]\n]}");
269 results.put("explicitCompactX", "{'x': [\n [],\n [\n {\n 'aStr': [\n [],\n [\n 'X'\n ]\n ]\n },\n {\n 'anInt': [\n [],\n [\n 42\n ]\n ]\n },\n {\n 'innerObj': [\n [\n {\n 'class': 'ys'\n }\n ],\n [\n 'Y'\n ]\n ]\n }\n ]\n]}");
270 results.put("optimizedMinimalEmptyX", "{'x':{'anInt':0,'innerObj':{}}}");
271 results.put("optimizedPrettyEmptyX", "{'x': {\n 'anInt': 0,\n 'innerObj': {\n }\n}}");
272 results.put("optimizedCompactEmptyX", "{'x': {\n 'anInt': 0,\n 'innerObj': {}\n}}");
273 results.put("noRootMinimalEmptyX", "{'anInt':0,'innerObj':{}}");
274 results.put("noRootPrettyEmptyX", "{\n 'anInt': 0,\n 'innerObj': {\n }\n}");
275 results.put("noRootCompactEmptyX", "{\n 'anInt': 0,\n 'innerObj': {}\n}");
276 results.put("explicitMinimalEmptyX", "{'x':[[],[{'anInt':[[],[0]]},{'innerObj':[[],[]]}]]}");
277 results.put("explicitPrettyEmptyX", "{'x': [\n [\n ],\n [\n {\n 'anInt': [\n [\n ],\n [\n 0\n ]\n ]\n },\n {\n 'innerObj': [\n [\n ],\n [\n ]\n ]\n }\n ]\n]}");
278 results.put("explicitCompactEmptyX", "{'x': [\n [],\n [\n {\n 'anInt': [\n [],\n [\n 0\n ]\n ]\n },\n {\n 'innerObj': [\n [],\n []\n ]\n }\n ]\n]}");
279 results.put("optimizedMinimalCollections", "{'collections':{'good':['XStream'],'bad':[{'anInt':0}]}}");
280 results.put("optimizedPrettyCollections", "{'collections': {\n 'good': [\n 'XStream'\n ],\n 'bad': [\n {\n 'anInt': 0\n }\n ]\n}}");
281 results.put("optimizedCompactCollections", "{'collections': {\n 'good': [\n 'XStream'\n ],\n 'bad': [\n {\n 'anInt': 0\n }\n ]\n}}");
282 results.put("noRootMinimalCollections", "{'good':['XStream'],'bad':[{'anInt':0}]}");
283 results.put("noRootPrettyCollections", "{\n 'good': [\n 'XStream'\n ],\n 'bad': [\n {\n 'anInt': 0\n }\n ]\n}");
284 results.put("noRootCompactCollections", "{\n 'good': [\n 'XStream'\n ],\n 'bad': [\n {\n 'anInt': 0\n }\n ]\n}");
285 results.put("explicitMinimalCollections", "{'collections':[[],[{'good':[[{'class':'linked-list'}],[{'string':[[],['XStream']]}]]},{'bad':[[{'class':'sorted-set'}],[{'x':[[],[{'anInt':[[],[0]]}]]}]]}]]}");
286 results.put("explicitPrettyCollections", "{'collections': [\n [\n ],\n [\n {\n 'good': [\n [\n {\n 'class': 'linked-list'\n }\n ],\n [\n {\n 'string': [\n [\n ],\n [\n 'XStream'\n ]\n ]\n }\n ]\n ]\n },\n {\n 'bad': [\n [\n {\n 'class': 'sorted-set'\n }\n ],\n [\n {\n 'x': [\n [\n ],\n [\n {\n 'anInt': [\n [\n ],\n [\n 0\n ]\n ]\n }\n ]\n ]\n }\n ]\n ]\n }\n ]\n]}");
287 results.put("explicitCompactCollections", "{'collections': [\n [],\n [\n {\n 'good': [\n [\n {\n 'class': 'linked-list'\n }\n ],\n [\n {\n 'string': [\n [],\n [\n 'XStream'\n ]\n ]\n }\n ]\n ]\n },\n {\n 'bad': [\n [\n {\n 'class': 'sorted-set'\n }\n ],\n [\n {\n 'x': [\n [],\n [\n {\n 'anInt': [\n [],\n [\n 0\n ]\n ]\n }\n ]\n ]\n }\n ]\n ]\n }\n ]\n]}");
288 results.put("optimizedMinimalEmptyList", "{'list':[]}");
289 results.put("optimizedPrettyEmptyList", "{'list': [\n]}");
290 results.put("optimizedCompactEmptyList", "{'list': []}");
291 results.put("noRootMinimalEmptyList", "[]");
292 results.put("noRootPrettyEmptyList", "[\n]");
293 results.put("noRootCompactEmptyList", "[]");
294 results.put("explicitMinimalEmptyList", "{'list':[[],[]]}");
295 results.put("explicitPrettyEmptyList", "{'list': [\n [\n ],\n [\n ]\n]}");
296 results.put("explicitCompactEmptyList", "{'list': [\n [],\n []\n]}");
297 results.put("optimizedMinimalCustomConverter", "{'h':{'str':'test','protocol':{'id':'ldap'},'i':42}}");
298 results.put("optimizedPrettyCustomConverter", "{'h': {\n 'str': 'test',\n 'protocol': {\n 'id': 'ldap'\n },\n 'i': 42\n}}");
299 results.put("optimizedCompactCustomConverter", "{'h': {\n 'str': 'test',\n 'protocol': {\n 'id': 'ldap'\n },\n 'i': 42\n}}");
300 results.put("noRootMinimalCustomConverter", "{'str':'test','protocol':{'id':'ldap'},'i':42}");
301 results.put("noRootPrettyCustomConverter", "{\n 'str': 'test',\n 'protocol': {\n 'id': 'ldap'\n },\n 'i': 42\n}");
302 results.put("noRootCompactCustomConverter", "{\n 'str': 'test',\n 'protocol': {\n 'id': 'ldap'\n },\n 'i': 42\n}");
303 results.put("explicitMinimalCustomConverter", "{'h':[[],[{'str':[[],['test']]},{'protocol':[[],[{'id':[[],['ldap']]}]]},{'i':[[],[42]]}]]}");
304 results.put("explicitPrettyCustomConverter", "{'h': [\n [\n ],\n [\n {\n 'str': [\n [\n ],\n [\n 'test'\n ]\n ]\n },\n {\n 'protocol': [\n [\n ],\n [\n {\n 'id': [\n [\n ],\n [\n 'ldap'\n ]\n ]\n }\n ]\n ]\n },\n {\n 'i': [\n [\n ],\n [\n 42\n ]\n ]\n }\n ]\n]}");
305 results.put("explicitCompactCustomConverter", "{'h': [\n [],\n [\n {\n 'str': [\n [],\n [\n 'test'\n ]\n ]\n },\n {\n 'protocol': [\n [],\n [\n {\n 'id': [\n [],\n [\n 'ldap'\n ]\n ]\n }\n ]\n ]\n },\n {\n 'i': [\n [],\n [\n 42\n ]\n ]\n }\n ]\n]}");
306
307 TestSuite suite = new TestSuite(JsonWriterFormatTest.class.getName());
308 for (final Iterator iterMode = modes.entrySet().iterator(); iterMode.hasNext();) {
309 final Map.Entry entryMode = (Map.Entry)iterMode.next();
310 final String modeName = (String)entryMode.getKey();
311 final int mode = ((Integer)entryMode.getValue()).intValue();
312 for (final Iterator iterFormat = formats.entrySet().iterator(); iterFormat.hasNext();) {
313 final Map.Entry entryFormat = (Map.Entry)iterFormat.next();
314 final String formatName = (String)entryFormat.getKey();
315 final JsonWriter.Format format = (JsonWriter.Format)entryFormat.getValue();
316 for (final Iterator iterTarget = targets.entrySet().iterator(); iterTarget.hasNext();) {
317 final Map.Entry entryTarget = (Map.Entry)iterTarget.next();
318 final String targetName = (String)entryTarget.getKey();
319 final Object target = entryTarget.getValue();
320 final String name = modeName + formatName + targetName;
321 final String result = ((String)results.get(name)).replace('\'', '"');
322
323 suite.addTest(new JsonWriterFormatTest(name, target, result, mode, format));
324 }
325 }
326 }
327
328 return suite;
329 }
330 }
0 /*
1 * Copyright (C) 2008, 2011, 2012 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 06. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import com.thoughtworks.acceptance.objects.Original;
13 import com.thoughtworks.acceptance.objects.Replaced;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.converters.ConversionException;
16 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
17
18 import java.io.Writer;
19 import java.util.ArrayList;
20 import java.util.List;
21
22
23 /**
24 * Some of these test cases are taken from example JSON listed at
25 * http://www.json.org/example.html
26 *
27 * @author Paul Hammant
28 * @author J&ouml;rg Schaible
29 */
30 public class JsonWriterModeDroppingRootTest extends JsonHierarchicalStreamDriverTest {
31
32 protected void setUp() throws Exception {
33 super.setUp();
34 xstream.aliasSystemAttribute(null, "class");
35 xstream.aliasSystemAttribute(null, "resolves-to");
36 xstream.aliasSystemAttribute(null, "defined-in");
37 }
38
39 protected JsonHierarchicalStreamDriver createDriver() {
40 return new JsonHierarchicalStreamDriver() {
41
42 public HierarchicalStreamWriter createWriter(Writer out) {
43 // no root and allow invalid JSON for single values as root object
44 return new JsonWriter(out, JsonWriter.DROP_ROOT_MODE);
45 }
46 };
47 }
48
49 protected String normalizeExpectation(final String expected) {
50 return super.normalizeExpectation(expected.substring(
51 expected.indexOf(": ") + 2, expected.length() - 1));
52 }
53
54 public void testCanMarshalSets() {
55 // This from http://www.json.org/example.html
56 xstream.alias("menu", MenuWithSet.class);
57 xstream.alias("menuitem", MenuItem.class);
58
59 final MenuWithSet menu = new MenuWithSet();
60
61 final String json = xstream.toXML(menu);
62 assertTrue(json.startsWith(normalizeExpectation(expectedMenuStart)));
63 assertTrue(json.indexOf(expectedNew.replace('\'', '"')) > 0);
64 assertTrue(json.indexOf(expectedOpen.replace('\'', '"')) > 0);
65 assertTrue(json.indexOf(expectedClose.replace('\'', '"')) > 0);
66 assertTrue(json.endsWith(expectedMenuEnd.replace('\'', '"').substring(
67 0, expectedMenuEnd.length() - 1)));
68 }
69
70 public void testBracesAndSquareBracketsAreNotEscaped() {
71 final String expected = ("" //
72 + "[\n"
73 + " '..{}[],,'\n"
74 + "]").replace('\'', '"');
75 assertEquals(expected, xstream.toXML(new String[]{"..{}[],,"}));
76 }
77
78 public void testWillWriteTagValueAsDefaultValueIfNecessary() {
79 xstream.alias("sa", SystemAttributes.class);
80 xstream.alias("original", Original.class);
81 xstream.alias("replaced", Replaced.class);
82
83 SystemAttributes sa = new SystemAttributes();
84 sa.name = "joe";
85 sa.object = "walnes";
86 sa.original = new Original("hello world");
87
88 String expected = normalizeExpectation(""
89 + "{'sa': {\n"
90 + " 'name': 'joe',\n"
91 + " 'object': 'walnes',\n"
92 + " 'original': {\n"
93 + " 'replacedValue': 'HELLO WORLD'\n"
94 + " }\n"
95 + "}}");
96
97 assertEquals(expected, xstream.toXML(sa));
98 }
99
100 public void testRealTypeIsHonoredWhenWritingTheValue() {
101 xstream.alias("sa", SystemAttributes.class);
102
103 List list = new ArrayList();
104 list.add("joe");
105 list.add("mauro");
106 SystemAttributes[] sa = new SystemAttributes[2];
107 sa[0] = new SystemAttributes();
108 sa[0].name = "year";
109 sa[0].object = new Integer(2000);
110 sa[1] = new SystemAttributes();
111 sa[1].name = "names";
112 sa[1].object = list;
113
114 String expected = normalizeExpectation(""
115 + "{'sa-array': [\n"
116 + " {\n"
117 + " 'name': 'year',\n"
118 + " 'object': 2000\n"
119 + " },\n"
120 + " {\n"
121 + " 'name': 'names',\n"
122 + " 'object': [\n"
123 + " 'joe',\n"
124 + " 'mauro'\n"
125 + " ]\n"
126 + " }\n"
127 + "]}");
128
129 assertEquals(expected, xstream.toXML(sa));
130 }
131
132 public void testStrictJSON() {
133 xstream = new XStream(new JsonHierarchicalStreamDriver() {
134
135 public HierarchicalStreamWriter createWriter(Writer out) {
136 // do not allow invalid JSON
137 return new JsonWriter(out, JsonWriter.DROP_ROOT_MODE | JsonWriter.STRICT_MODE);
138 }
139 });
140 try {
141 xstream.toXML(new Integer(123));
142 fail("Thrown " + ConversionException.class.getName() + " expected");
143 } catch (final ConversionException e) {
144 // OK
145 }
146 }
147 }
0 /*
1 * Copyright (C) 2009, 2011, 2013 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 01. September 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.json;
11
12 import java.io.IOException;
13 import java.io.OutputStreamWriter;
14 import java.io.StringWriter;
15 import java.io.Writer;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.HashSet;
19
20 import com.thoughtworks.acceptance.someobjects.X;
21 import com.thoughtworks.acceptance.someobjects.Y;
22 import com.thoughtworks.xstream.XStream;
23 import com.thoughtworks.xstream.io.json.JsonWriter.Format;
24
25 import org.json.JSONArray;
26 import org.json.JSONException;
27 import org.json.JSONObject;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32
33
34 /**
35 * Tests the {@link JsonWriter} formats.
36 *
37 * @author J&ouml;rg Schaible
38 */
39 public class JsonWriterModeTest extends TestCase {
40
41 private XStream xstream;
42 private Object target;
43 private final int mode;
44 private final Format format;
45
46 public JsonWriterModeTest(
47 String name, int xstreamMode, int writerMode, JsonWriter.Format format) {
48 super(name);
49 this.mode = writerMode;
50 this.format = format;
51
52 X x = new X(42);
53 x.aStr = "Codehaus";
54 x.innerObj = new Y();
55 x.innerObj.yField = "Y";
56
57 target = new ArrayList(Arrays
58 .asList(new Object[]{
59 new Object[][]{new Object[0]},
60 null,
61 new Integer(42),
62 new Long(Long.MAX_VALUE),
63 new Y(),
64 x.innerObj,
65 new ArrayList(),
66 new CharSequence[]{
67 "JUnit", "XStream", new StringBuffer("JSON"), new StringBuffer("JScript")},
68 x,}));
69
70 xstream = new XStream();
71 xstream.setMode(xstreamMode);
72 xstream.alias("X", X.class);
73 xstream.alias("Y", Y.class);
74 xstream.alias("CharSequence", CharSequence.class);
75 }
76
77 protected void runTest() throws Throwable {
78 // toConsole(mode, format);
79 String json = toJSON(mode, format);
80 assertValidJSON(json);
81 }
82
83 private static void assertValidJSON(String json) throws JSONException {
84 JSONObject jsonObject = new JSONObject(json);
85 assertTrue(equals(jsonObject, new JSONObject(jsonObject.toString())));
86 }
87
88 private static boolean equals(JSONObject object1, JSONObject object2) {
89 String[] names = JSONObject.getNames(object1);
90 try {
91 if (names == null) {
92 return JSONObject.getNames(object2) == null;
93 }
94 if (new HashSet(Arrays.asList(names)).equals(new HashSet(Arrays.asList(JSONObject.getNames(object2))))) {
95 for (int i = 0; i < names.length; i++) {
96 if (!equals(object1.get(names[i]), object2.get(names[i]))) {
97 return false;
98 }
99 }
100 return true;
101 }
102 } catch (JSONException e) {
103 // ignore - return false
104 }
105 return false;
106 }
107
108 private static boolean equals(JSONArray array1, JSONArray array2) {
109 int length = array1.length();
110 if (length == array2.length()) {
111 try {
112 while (length-- > 0) {
113 if (!equals(array1.get(length), array2.get(length))) {
114 return false;
115 }
116 }
117 return true;
118 } catch (JSONException e) {
119 // ignore - return false
120 }
121 }
122 return false;
123 }
124
125 private static boolean equals(Object o1, Object o2) {
126 if (o1 == null && o2 == null) {
127 return true;
128 } else if ((o1 == null && o2 != null) || (o1 != null && o2 == null)) {
129 return false;
130 }
131 Class type = o1.getClass();
132 if (type != o2.getClass()) {
133 return false;
134 }
135 if (type == JSONObject.class) {
136 return equals((JSONObject)o1, (JSONObject)o2);
137 } else if (type == JSONArray.class) {
138 return equals((JSONArray)o1, (JSONArray)o2);
139 }
140 return o1.equals(o2);
141 }
142
143 private String toJSON(int mode, JsonWriter.Format format) {
144 final StringWriter writer = new StringWriter(1024);
145 writeJSON(writer, mode, format);
146 return writer.toString();
147 }
148
149 private void toConsole(int mode, JsonWriter.Format format) {
150 System.out.println(xstream.toXML(target));
151 try {
152 writeJSON(new OutputStreamWriter(System.err, "UTF-8"), mode, format);
153 System.err.println();
154 } catch (IOException e) {
155 e.printStackTrace();
156 }
157 }
158
159 private void writeJSON(Writer writer, int mode, JsonWriter.Format format) {
160 JsonWriter jsonWriter = new JsonWriter(writer, mode, format, 0);
161 xstream.marshal(target, jsonWriter);
162 jsonWriter.flush();
163 }
164
165 public static Test suite() {
166 JsonWriter.Format compactFormat = new JsonWriter.Format(
167 new char[0], new char[0], JsonWriter.Format.COMPACT_EMPTY_ELEMENT);
168 JsonWriter.Format prettyFormat = new JsonWriter.Format(" ".toCharArray(), "\n"
169 .toCharArray(), JsonWriter.Format.SPACE_AFTER_LABEL);
170
171 TestSuite suite = new TestSuite(JsonWriterModeTest.class.getName());
172 suite.addTest(new JsonWriterModeTest(
173 "optimizedCompact", XStream.NO_REFERENCES, 0, compactFormat));
174 suite.addTest(new JsonWriterModeTest(
175 "optimizedPretty", XStream.NO_REFERENCES, 0, prettyFormat));
176 suite.addTest(new JsonWriterModeTest(
177 "optimizedCompactIEEE754", XStream.NO_REFERENCES, AbstractJsonWriter.IEEE_754_MODE,
178 compactFormat));
179 suite.addTest(new JsonWriterModeTest(
180 "explicitCompact", XStream.NO_REFERENCES, AbstractJsonWriter.EXPLICIT_MODE,
181 compactFormat));
182 suite.addTest(new JsonWriterModeTest(
183 "explicitCompactIEEE754", XStream.NO_REFERENCES, AbstractJsonWriter.EXPLICIT_MODE
184 | AbstractJsonWriter.IEEE_754_MODE, compactFormat));
185 suite.addTest(new JsonWriterModeTest(
186 "explicitPretty", XStream.NO_REFERENCES, AbstractJsonWriter.EXPLICIT_MODE,
187 prettyFormat));
188 suite.addTest(new JsonWriterModeTest(
189 "optimizedCompactWithIds", XStream.ID_REFERENCES, 0, compactFormat));
190 suite.addTest(new JsonWriterModeTest(
191 "optimizedPrettyWithIds", XStream.ID_REFERENCES, 0, prettyFormat));
192 suite.addTest(new JsonWriterModeTest(
193 "explicitCompactWithIds", XStream.ID_REFERENCES, AbstractJsonWriter.EXPLICIT_MODE,
194 compactFormat));
195 suite.addTest(new JsonWriterModeTest(
196 "explicitPrettyWithIds", XStream.ID_REFERENCES, AbstractJsonWriter.EXPLICIT_MODE,
197 prettyFormat));
198
199 return suite;
200 }
201 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import junit.framework.Test;
14 import junit.framework.TestCase;
15 import junit.framework.TestSuite;
16
17 public class PathTest extends TestCase {
18
19 public static Test suite() {
20 TestSuite result = new TestSuite(PathTest.class.getName());
21
22 addTest(result,
23 "/a/b/c",
24 "/a/b/c",
25 ".",
26 ".",
27 true);
28
29 addTest(result,
30 "/a",
31 "/a/b/c",
32 "b/c",
33 "b[1]/c[1]",
34 true);
35
36 addTest(result,
37 "/a/b/c",
38 "/a",
39 "../..",
40 "../..",
41 false);
42
43 addTest(result,
44 "/a/b/c",
45 "/a/b/X",
46 "../X",
47 "../X[1]",
48 false);
49
50 addTest(result,
51 "/a/b/c",
52 "/a/X/c",
53 "../../X/c",
54 "../../X[1]/c[1]",
55 false);
56
57 addTest(result,
58 "/a/b/c/d",
59 "/a/X/c",
60 "../../../X/c",
61 "../../../X[1]/c[1]",
62 false);
63
64 addTest(result,
65 "/a/b/c",
66 "/a/X/c/d",
67 "../../X/c/d",
68 "../../X[1]/c[1]/d[1]",
69 false);
70
71 addTest(result,
72 "/a/b/c[2]",
73 "/a/b/c[3]",
74 "../c[3]",
75 "../c[3]",
76 false);
77
78 addTest(result,
79 "/a",
80 "/a[1]",
81 ".",
82 ".",
83 true);
84
85 return result;
86 }
87
88 private static void addTest(TestSuite suite, final String from, final String to, final String relative, final String explicit, final boolean isAncestor) {
89 String testName = from + " - " + to;
90 suite.addTest(new TestCase(testName) {
91 protected void runTest() throws Throwable {
92 assertEquals(new Path(relative), new Path(from).relativeTo(new Path(to)));
93 assertEquals(new Path(to), new Path(from).apply(new Path(relative)));
94 assertEquals(isAncestor, new Path(from).isAncestor(new Path(to)));
95 assertEquals(new Path(relative), new Path(explicit));
96 assertEquals(new Path(relative).explicit(), explicit);
97 assertEquals(relative, new Path(explicit).toString());
98 }
99 });
100 }
101
102
103 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import junit.framework.TestCase;
14
15 public class PathTrackerTest extends TestCase {
16
17 private PathTracker pathTracker;
18
19 protected void setUp() throws Exception {
20 super.setUp();
21 // small initial capacity to ensure resizing works
22 pathTracker = new PathTracker(1);
23 }
24
25 public void testExposesXpathLikeExpressionOfLocationInWriter() {
26
27 assertEquals(new Path(""), pathTracker.getPath());
28 assertEquals(0, pathTracker.depth());
29
30 // <root>
31 pathTracker.pushElement("root");
32 assertEquals(new Path("/root"), pathTracker.getPath());
33 assertEquals(1, pathTracker.depth());
34 assertEquals("root", pathTracker.peekElement());
35
36 // <childA>
37 pathTracker.pushElement("childA");
38 assertEquals(new Path("/root/childA"), pathTracker.getPath());
39 assertEquals(2, pathTracker.depth());
40 assertEquals("childA", pathTracker.peekElement());
41 // </childA>
42 pathTracker.popElement();
43 assertEquals(new Path("/root"), pathTracker.getPath());
44 assertEquals(1, pathTracker.depth());
45 assertEquals("root", pathTracker.peekElement());
46
47 // <childB>
48 pathTracker.pushElement("childB");
49 assertEquals(new Path("/root/childB"), pathTracker.getPath());
50 assertEquals(2, pathTracker.depth());
51 assertEquals("childB", pathTracker.peekElement());
52
53 // <grandchild>
54 pathTracker.pushElement("grandchild");
55 assertEquals(new Path("/root/childB/grandchild"), pathTracker.getPath());
56 assertEquals(3, pathTracker.depth());
57 assertEquals("grandchild", pathTracker.peekElement(0));
58 assertEquals("childB", pathTracker.peekElement(-1));
59 assertEquals("root", pathTracker.peekElement(-2));
60 // </grandchild>
61 pathTracker.popElement();
62 assertEquals(new Path("/root/childB"), pathTracker.getPath());
63 assertEquals(2, pathTracker.depth());
64 assertEquals("childB", pathTracker.peekElement());
65
66 // </childB>
67 pathTracker.popElement();
68 assertEquals(new Path("/root"), pathTracker.getPath());
69 assertEquals(1, pathTracker.depth());
70 assertEquals("root", pathTracker.peekElement());
71
72 // </root>
73 pathTracker.popElement();
74 assertEquals(new Path(""), pathTracker.getPath());
75 assertEquals(0, pathTracker.depth());
76
77 }
78
79 public void testAddsIndexIfSiblingOfSameTypeAlreadyExists() {
80
81 // <root>
82 pathTracker.pushElement("root");
83
84 // <child>
85 pathTracker.pushElement("child");
86 assertEquals(new Path("/root/child"), pathTracker.getPath());
87 // </child>
88 pathTracker.popElement();
89
90 // <child>
91 pathTracker.pushElement("child");
92 assertEquals(new Path("/root/child[2]"), pathTracker.getPath());
93 assertEquals("child[2]", pathTracker.peekElement());
94 // </child>
95 pathTracker.popElement();
96
97 // <another>
98 pathTracker.pushElement("another");
99 assertEquals(new Path("/root/another"), pathTracker.getPath());
100 // </another>
101 pathTracker.popElement();
102
103 // <child>
104 pathTracker.pushElement("child");
105 assertEquals(new Path("/root/child[3]"), pathTracker.getPath());
106 assertEquals("child[3]", pathTracker.peekElement());
107 // </child>
108 pathTracker.popElement();
109
110 // ...
111 }
112
113 public void testAssociatesIndexOnlyWithDirectParent() {
114
115 // <root>
116 pathTracker.pushElement("root");
117
118 // <child>
119 pathTracker.pushElement("child");
120
121 // <child>
122 pathTracker.pushElement("child");
123 assertEquals(new Path("/root/child/child"), pathTracker.getPath());
124 // </child>
125 pathTracker.popElement();
126
127 // <child>
128 pathTracker.pushElement("child");
129 assertEquals(new Path("/root/child/child[2]"), pathTracker.getPath());
130 // </child>
131 pathTracker.popElement();
132
133 // </child>
134 pathTracker.popElement();
135
136 // <child>
137 pathTracker.pushElement("child");
138
139 // <child>
140 pathTracker.pushElement("child");
141 assertEquals(new Path("/root/child[2]/child"), pathTracker.getPath());
142 // </child>
143 pathTracker.popElement();
144
145 // <child>
146 pathTracker.pushElement("child");
147 assertEquals(new Path("/root/child[2]/child[2]"), pathTracker.getPath());
148
149 // ...
150 }
151
152 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 03. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.xml.XppReader;
15
16 import junit.framework.TestCase;
17
18 import org.xmlpull.mxp1.MXParser;
19
20 import java.io.Reader;
21 import java.io.StringReader;
22
23 public class PathTrackingReaderTest extends TestCase {
24
25 public void testDecoratesReaderAndTracksPath() {
26 Reader input = new StringReader("" +
27 "<a>" +
28 " <b><c/></b>" +
29 " <b/>" +
30 " <d/>" +
31 "</a>");
32 HierarchicalStreamReader reader = new XppReader(input, new MXParser());
33 PathTracker pathTracker = new PathTracker();
34
35 reader = new PathTrackingReader(reader, pathTracker);
36 assertEquals(new Path("/a"), pathTracker.getPath());
37
38 reader.moveDown();
39 assertEquals(new Path("/a/b"), pathTracker.getPath());
40
41 reader.moveDown();
42 assertEquals(new Path("/a/b/c"), pathTracker.getPath());
43
44 reader.moveUp();
45 assertEquals(new Path("/a/b"), pathTracker.getPath());
46
47 reader.moveUp();
48 reader.moveDown();
49 assertEquals(new Path("/a/b[2]"), pathTracker.getPath());
50
51 reader.moveUp();
52 reader.moveDown();
53 assertEquals(new Path("/a/d"), pathTracker.getPath());
54
55 reader.moveUp();
56 assertEquals(new Path("/a"), pathTracker.getPath());
57 }
58
59 public void testPathsAreDecodedInTracker() {
60 Reader input = new StringReader("" +
61 "<a>" +
62 " <b__1/>" +
63 "</a>");
64 HierarchicalStreamReader reader = new XppReader(input, new MXParser());
65 PathTracker pathTracker = new PathTracker();
66
67 reader = new PathTrackingReader(reader, pathTracker);
68 assertEquals(new Path("/a"), pathTracker.getPath());
69
70 reader.moveDown();
71 assertEquals(new Path("/a/b_1"), pathTracker.getPath());
72 assertEquals("b_1", pathTracker.peekElement());
73
74 reader.moveUp();
75 assertEquals(new Path("/a"), pathTracker.getPath());
76 }
77 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 03. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.path;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
14 import com.thoughtworks.xstream.io.xml.CompactWriter;
15
16 import junit.framework.TestCase;
17
18 import java.io.StringWriter;
19
20 public class PathTrackingWriterTest extends TestCase {
21 private StringWriter out;
22 private HierarchicalStreamWriter writer;
23 private PathTracker pathTracker;
24
25 protected void setUp() throws Exception {
26 super.setUp();
27 pathTracker = new PathTracker();
28 out = new StringWriter();
29 HierarchicalStreamWriter originalWriter = new CompactWriter(out);
30
31 writer = new PathTrackingWriter(originalWriter, pathTracker);
32 }
33
34 public void testDecoratesXmlWriterProxyingAllInvocations() {
35
36 writer.startNode("foo");
37 writer.addAttribute("att", "something");
38 writer.setValue("getValue");
39 writer.endNode();
40
41 assertEquals("<foo att=\"something\">getValue</foo>", out.toString());
42 }
43
44 public void testInterceptsWhenWriterMovesLocationInDocumentAndUpdatesPathTracker() {
45
46 assertEquals(new Path(""), pathTracker.getPath());
47
48 writer.startNode("foo");
49 assertEquals(new Path("/foo"), pathTracker.getPath());
50
51 writer.startNode("do");
52 assertEquals(new Path("/foo/do"), pathTracker.getPath());
53
54 writer.endNode();
55 assertEquals(new Path("/foo"), pathTracker.getPath());
56
57 writer.endNode();
58 assertEquals(new Path(""), pathTracker.getPath());
59 }
60
61 public void testEncodesPathInTracker() {
62 assertEquals(new Path(""), pathTracker.getPath());
63
64 writer.startNode("foo");
65 assertEquals(new Path("/foo"), pathTracker.getPath());
66
67 writer.startNode("b_1");
68 assertEquals(new Path("/foo/b__1"), pathTracker.getPath());
69 assertEquals("b__1", pathTracker.peekElement());
70
71 writer.endNode();
72 assertEquals(new Path("/foo"), pathTracker.getPath());
73
74 writer.endNode();
75 assertEquals(new Path(""), pathTracker.getPath());
76 }
77 }
0 /*
1 * Copyright (C) 2006, 2007, 2008, 2009 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 19. October 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier;
13 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
14
15 import junit.framework.TestCase;
16
17 import java.util.Arrays;
18 import java.util.HashSet;
19 import java.util.Set;
20
21
22 public abstract class AbstractDocumentWriterTest extends TestCase {
23
24 private final HierarchicalStreamCopier copier = new HierarchicalStreamCopier();
25 protected DocumentWriter writer;
26
27 protected abstract DocumentReader createDocumentReaderFor(Object node);
28
29 protected void assertDocumentProducedIs(final XppDom expected) {
30 assertDocumentProducedIs(new XppDom[]{expected});
31 }
32
33 protected boolean equals(final XppDom node1, final XppDom node2) {
34 if (node1.getName().equals(node2.getName())) {
35 final String value1 = node1.getValue();
36 final String value2 = node2.getValue();
37 if ((value1 == null && value2 == null) || value1.equals(value2)) {
38 final Set set1 = new HashSet(Arrays.asList(node1.getAttributeNames()));
39 final Set set2 = new HashSet(Arrays.asList(node2.getAttributeNames()));
40 if (set1.equals(set2)) {
41 final XppDom[] children1 = node1.getChildren();
42 final XppDom[] children2 = node2.getChildren();
43 if (children1.length == children2.length) {
44 for (int i = 0; i < children1.length; i++) {
45 if (!equals(children1[i], children2[i])) {
46 return false;
47 }
48 }
49 return true;
50 }
51 }
52 }
53 }
54 return false;
55 }
56
57 protected void assertDocumentProducedIs(final XppDom[] expected) {
58 for (int i = 0; i < expected.length; i++) {
59 copier.copy(new XppDomReader(expected[i]), writer);
60 }
61 final Object[] nodes = writer.getTopLevelNodes().toArray(new Object[0]);
62 assertEquals(expected.length, nodes.length);
63 for (int i = 0; i < nodes.length; i++) {
64 final XppDomWriter xpp3 = new XppDomWriter();
65 copier.copy(createDocumentReaderFor(nodes[i]), xpp3);
66 assertTrue(equals(expected[i], xpp3.getConfiguration()));
67 }
68 }
69
70 public void testProducesDomElements() {
71 final XppDom root = new XppDom("hello");
72 root.setValue("world");
73 assertDocumentProducedIs(root);
74 }
75
76 public void testSupportsNestedElements() {
77 final XppDom a = new XppDom("a");
78
79 XppDom b = new XppDom("b");
80 b.setValue("one");
81 a.addChild(b);
82
83 b = new XppDom("b");
84 b.setValue("two");
85 a.addChild(b);
86
87 final XppDom c = new XppDom("c");
88 a.addChild(c);
89 final XppDom d = new XppDom("d");
90 d.setValue("three");
91 c.addChild(d);
92
93 assertDocumentProducedIs(a);
94 }
95
96 public void testSupportsAttributes() {
97 final XppDom person = new XppDom("person");
98 person.setAttribute("firstname", "Joe");
99 person.setAttribute("lastname", "Walnes");
100 assertDocumentProducedIs(person);
101 }
102
103 public void testAttributesAreResettedForNewNode() {
104 final XppDom[] roots = new XppDom[2];
105 final XppDom person = roots[0] = new XppDom("person");
106 person.setAttribute("firstname", "Joe");
107 person.setAttribute("lastname", "Walnes");
108 final XppDom project = roots[1] = new XppDom("project");
109 project.setAttribute("XStream", "Codehaus");
110
111 assertDocumentProducedIs(roots);
112 }
113
114 public void testSupportsEmptyNestedTags() {
115 final XppDom parent = new XppDom("parent");
116 parent.addChild(new XppDom("child"));
117
118 assertDocumentProducedIs(parent);
119 }
120
121 protected void assertDocumentProducedIs(final XppDom expected, final XppDom tree)
122 {
123 copier.copy(new XppDomReader(tree), writer);
124
125 final Object[] nodes = writer.getTopLevelNodes().toArray(new Object[0]);
126 assertEquals(1, nodes.length);
127 for (int i = 0; i < nodes.length; i++) {
128 final XppDomWriter xpp3 = new XppDomWriter();
129 copier.copy(createDocumentReaderFor(nodes[i]), xpp3);
130 assertTrue(equals(expected, xpp3.getConfiguration()));
131 }
132 }
133 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 03. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.acceptance.someobjects.X;
13 import com.thoughtworks.acceptance.someobjects.Y;
14 import com.thoughtworks.xstream.XStream;
15
16 import org.apache.oro.text.perl.Perl5Util;
17
18 import javax.xml.namespace.QName;
19
20 import java.io.StringWriter;
21
22 public abstract class AbstractStaxWriterTest extends AbstractXMLWriterTest {
23
24 protected StringWriter buffer;
25 protected Perl5Util perlUtil;
26 protected StaxDriver staxDriver;
27 private X testInput;
28
29 protected abstract String getXMLHeader();
30
31 protected abstract StaxDriver getStaxDriver();
32
33 protected void setUp() throws Exception {
34 super.setUp();
35 staxDriver = getStaxDriver();
36 staxDriver.setRepairingNamespace(false);
37 buffer = new StringWriter();
38 writer = staxDriver.createWriter(buffer);
39 perlUtil = new Perl5Util();
40
41 testInput = new X();
42 testInput.anInt = 9;
43 testInput.aStr = "zzz";
44 testInput.innerObj = new Y();
45 testInput.innerObj.yField = "ooo";
46 }
47
48 public void testNamespacedXmlWithPrefix() throws Exception {
49 QNameMap qnameMap = new QNameMap();
50 QName qname = new QName("http://foo.com", "alias", "foo");
51 qnameMap.registerMapping(qname, X.class);
52
53 String expected = "<foo:alias xmlns:foo=\"http://foo.com\"><aStr xmlns=\"\">zzz</aStr><anInt xmlns=\"\">9</anInt><innerObj xmlns=\"\"><yField>ooo</yField></innerObj></foo:alias>";
54 marshalWithBothRepairingModes(qnameMap, expected);
55 }
56
57 public void testNamespacedXmlWithoutPrefix() throws Exception {
58 QNameMap qnameMap = new QNameMap();
59 QName qname = new QName("http://foo.com", "bar");
60 qnameMap.registerMapping(qname, X.class);
61
62 String expected = "<bar xmlns=\"http://foo.com\"><aStr xmlns=\"\">zzz</aStr><anInt xmlns=\"\">9</anInt><innerObj xmlns=\"\"><yField>ooo</yField></innerObj></bar>";
63 marshalWithBothRepairingModes(qnameMap, expected);
64 }
65
66 public void testNamespacedXmlWithPrefixTwice() throws Exception {
67 QNameMap qnameMap = new QNameMap();
68 QName qname = new QName("http://foo.com", "alias", "foo");
69 qnameMap.registerMapping(qname, X.class);
70
71 qname = new QName("http://bar.com", "alias1", "bar");
72 qnameMap.registerMapping(qname, "aStr");
73
74 qname = new QName("http://bar.com", "alias2", "bar");
75 qnameMap.registerMapping(qname, "anInt");
76
77 String expected = "<foo:alias xmlns:foo=\"http://foo.com\"><bar:alias1 xmlns:bar=\"http://bar.com\">zzz</bar:alias1><bar:alias2 xmlns:bar=\"http://bar.com\">9</bar:alias2><innerObj xmlns=\"\"><yField>ooo</yField></innerObj></foo:alias>";
78 marshalWithBothRepairingModes(qnameMap, expected);
79 }
80
81 protected void marshalWithBothRepairingModes(QNameMap qnameMap, String expected) {
82 marshalNonRepairing(qnameMap, expected);
83 marshalRepairing(qnameMap, expected);
84 }
85
86 protected void marshalRepairing(QNameMap qnameMap, String expected) {
87 marshall(qnameMap, true);
88 assertXmlProducedIs(expected);
89 }
90
91 protected void marshalNonRepairing(QNameMap qnameMap, String expected) {
92 marshall(qnameMap, false);
93 assertXmlProducedIs(expected);
94 }
95
96 protected void marshall(QNameMap qnameMap, boolean repairNamespaceMode) {
97 staxDriver.setRepairingNamespace(repairNamespaceMode);
98 staxDriver.setQnameMap(qnameMap);
99 XStream xstream = new XStream(staxDriver);
100 buffer = new StringWriter();
101 xstream.toXML(testInput, buffer);
102 }
103
104 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011, 2012, 2013 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import junit.framework.TestCase;
16
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.Set;
20
21 public abstract class AbstractXMLReaderTest extends TestCase {
22
23 // factory method
24 protected abstract HierarchicalStreamReader createReader(String xml) throws Exception;
25
26 public void testStartsAtRootTag() throws Exception {
27 HierarchicalStreamReader xmlReader = createReader("<hello/>");
28 assertEquals("hello", xmlReader.getNodeName());
29 }
30
31 public void testCanNavigateDownChildTagsByIndex() throws Exception {
32 HierarchicalStreamReader xmlReader = createReader("<a><b><ooh/></b><b><aah/></b></a>");
33
34 assertEquals("a", xmlReader.getNodeName());
35
36 assertTrue(xmlReader.hasMoreChildren());
37
38 xmlReader.moveDown(); // /a/b
39
40 assertEquals("b", xmlReader.getNodeName());
41
42 assertTrue(xmlReader.hasMoreChildren());
43
44 xmlReader.moveDown(); // a/b/ooh
45 assertEquals("ooh", xmlReader.getNodeName());
46 assertFalse(xmlReader.hasMoreChildren());
47 xmlReader.moveUp(); // a/b
48
49 assertFalse(xmlReader.hasMoreChildren());
50
51 xmlReader.moveUp(); // /a
52
53 assertTrue(xmlReader.hasMoreChildren());
54
55 xmlReader.moveDown(); // /a/b[2]
56
57 assertEquals("b", xmlReader.getNodeName());
58
59 assertTrue(xmlReader.hasMoreChildren());
60
61 xmlReader.moveDown(); // a/b[2]/aah
62
63 assertEquals("aah", xmlReader.getNodeName());
64 assertFalse(xmlReader.hasMoreChildren());
65
66 xmlReader.moveUp(); // a/b[2]
67
68 assertFalse(xmlReader.hasMoreChildren());
69
70 xmlReader.moveUp(); // a
71
72 assertFalse(xmlReader.hasMoreChildren());
73 }
74
75 public void testChildTagsCanBeMixedWithOtherNodes() throws Exception {
76 HierarchicalStreamReader xmlReader = createReader("<!-- xx --><a> <hello/> <!-- x --> getValue <world/></a>");
77
78 assertTrue(xmlReader.hasMoreChildren());
79 xmlReader.moveDown();
80 assertEquals("hello", xmlReader.getNodeName());
81 xmlReader.moveUp();
82
83 assertTrue(xmlReader.hasMoreChildren());
84 xmlReader.moveDown();
85 assertEquals("world", xmlReader.getNodeName());
86 xmlReader.moveUp();
87
88 assertFalse(xmlReader.hasMoreChildren());
89 }
90
91 public void testAttributesCanBeFetchedFromTags() throws Exception {
92 HierarchicalStreamReader xmlReader = createReader("" +
93 "<hello one=\"1\" two=\"2\">" +
94 " <child three=\"3\"/>" +
95 "</hello>"); // /hello
96
97 assertEquals("1", xmlReader.getAttribute("one"));
98 assertEquals("2", xmlReader.getAttribute("two"));
99 assertNull(xmlReader.getAttribute("three"));
100
101 xmlReader.moveDown(); // /hello/child
102 assertNull(xmlReader.getAttribute("one"));
103 assertNull(xmlReader.getAttribute("two"));
104 assertEquals("3", xmlReader.getAttribute("three"));
105
106 }
107
108 public void testTextCanBeExtractedFromTag() throws Exception {
109 HierarchicalStreamReader xmlReader = createReader(
110 "<root><a>some<!-- ignore me --> getValue!</a><b><![CDATA[more&&more;]]></b></root>");
111
112 xmlReader.moveDown();
113 assertEquals("some getValue!", xmlReader.getValue());
114 xmlReader.moveUp();
115
116 xmlReader.moveDown();
117 assertEquals("more&&more;", xmlReader.getValue());
118 xmlReader.moveUp();
119 }
120
121 public void testDoesNotIgnoreWhitespaceAroundText() throws Exception {
122 HierarchicalStreamReader xmlReader = createReader("<root> hello world </root>");
123
124 assertEquals(" hello world ", xmlReader.getValue());
125 }
126
127 public void testReturnsEmptyStringForEmptyTags() throws Exception {
128 HierarchicalStreamReader xmlReader = createReader("<root></root>");
129
130 String text = xmlReader.getValue();
131 assertNotNull(text);
132 assertEquals("", text);
133 }
134
135 public void testReturnsLastResultForHasMoreChildrenIfCalledRepeatedlyWithoutMovingNode() throws Exception {
136 HierarchicalStreamReader xmlReader = createReader("<row><cells></cells></row>");
137
138 assertEquals("row", xmlReader.getNodeName());
139 assertTrue(xmlReader.hasMoreChildren()); // this is OK
140 assertTrue(xmlReader.hasMoreChildren()); // this fails
141 }
142
143 public void testExposesAttributesKeysAndValuesByIndex() throws Exception {
144 HierarchicalStreamReader xmlReader = createReader("<node hello='world' a='b' c='d'><empty/></node>");
145
146 assertEquals(3, xmlReader.getAttributeCount());
147
148 assertEquals("hello", xmlReader.getAttributeName(0));
149 assertEquals("a", xmlReader.getAttributeName(1));
150 assertEquals("c", xmlReader.getAttributeName(2));
151
152 assertEquals("world", xmlReader.getAttribute(0));
153 assertEquals("b", xmlReader.getAttribute(1));
154 assertEquals("d", xmlReader.getAttribute(2));
155
156 xmlReader.moveDown();
157 assertEquals("empty", xmlReader.getNodeName());
158 assertEquals(0, xmlReader.getAttributeCount());
159 }
160
161 public void testExposesAttributesKeysAsIterator() throws Exception {
162 HierarchicalStreamReader xmlReader = createReader("<node hello='world' a='b' c='d'><empty/></node>");
163
164 Set expected = new HashSet();
165 expected.add("hello");
166 expected.add("a");
167 expected.add("c");
168
169 Set actual = new HashSet();
170 Iterator iterator;
171
172 iterator = xmlReader.getAttributeNames();
173 while(iterator.hasNext()) {
174 actual.add(iterator.next());
175 }
176 assertEquals(expected, actual);
177
178 // again, to check iteration is repeatable
179 iterator = xmlReader.getAttributeNames();
180 while(iterator.hasNext()) {
181 actual.add(iterator.next());
182 }
183 assertEquals(expected, actual);
184 }
185
186 public void testAllowsValueToBeReadWithoutDisturbingChildren() throws Exception {
187 HierarchicalStreamReader xmlReader
188 = createReader("<root><child></child><sibling>text2</sibling></root>"); // at: /root
189
190 assertEquals("root", xmlReader.getNodeName());
191 assertEquals("", xmlReader.getValue());
192 assertTrue(xmlReader.hasMoreChildren());
193
194 xmlReader.moveDown(); // at: /root/child
195 assertEquals("child", xmlReader.getNodeName());
196 assertEquals(null, xmlReader.getAttribute("something"));
197 assertEquals("", xmlReader.getValue());
198
199 assertFalse(xmlReader.hasMoreChildren()); // <--- This is an awkward one for pull parsers
200
201 xmlReader.moveUp(); // at: /root
202
203 assertTrue(xmlReader.hasMoreChildren());
204
205 xmlReader.moveDown(); // at: /root/sibling
206 assertEquals("sibling", xmlReader.getNodeName());
207 assertEquals("text2", xmlReader.getValue());
208 assertFalse(xmlReader.hasMoreChildren());
209 xmlReader.moveUp(); // at: /root
210
211 assertFalse(xmlReader.hasMoreChildren());
212 }
213
214 public void testExposesTextValueOfCurrentElementButNotChildren() throws Exception {
215 HierarchicalStreamReader xmlReader
216 = createReader("<root>hello<child>FNARR</child></root>");
217
218 assertEquals("hello", xmlReader.getValue());
219 xmlReader.moveDown();
220 assertEquals("FNARR", xmlReader.getValue());
221 }
222
223 public void testCanReadLineFeedInString() throws Exception {
224 HierarchicalStreamReader xmlReader = createReader("<string>a\nb</string>");
225 assertEquals("a\nb", xmlReader.getValue());
226 }
227
228 public void testCanReadEncodedAttribute() throws Exception {
229 HierarchicalStreamReader xmlReader = createReader("<string __attr='value'/>");
230 assertEquals("value", xmlReader.getAttribute("_attr"));
231 }
232
233 public void testCanReadAttributeWithEncodedWhitespace() throws Exception {
234 HierarchicalStreamReader xmlReader = createReader("<string attr=' A\r\t\nB C&#x9;&#xa;&#xd; '/>");
235 assertEquals(" A B C\t\n\r ", xmlReader.getAttribute("attr"));
236 }
237
238 public void testCanReadCDATAWithEmbeddedTags() throws Exception {
239 String content = "<tag>the content</tag>";
240 HierarchicalStreamReader xmlReader = createReader("<string><![CDATA[" + content + "]]></string>");
241 assertEquals(content, xmlReader.getValue());
242 }
243
244 // TODO: See XSTR-473
245 public void todoTestCanReadNullValueInString() throws Exception {
246 HierarchicalStreamReader xmlReader = createReader("<string>&#x0;</string>");
247 assertEquals("\u0000", xmlReader.getValue());
248 }
249 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2011 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 05. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
14
15 import junit.framework.TestCase;
16
17 public abstract class AbstractXMLWriterTest extends TestCase {
18
19 protected HierarchicalStreamWriter writer;
20
21 protected abstract void assertXmlProducedIs(String expected);
22
23 // String.replaceAll is JDK 1.4
24 protected String replaceAll(String s, final String occurance, final String replacement) {
25 final int len = occurance.length();
26 final int inc = len - replacement.length();
27 int i = -inc;
28 final StringBuffer buff = new StringBuffer(s);
29 // StringBuffer has no indexOf in JDK 1.3
30 while((i = buff.toString().indexOf(occurance, i + inc)) >= 0) {
31 buff.replace(i, i + len, replacement);
32 }
33 return buff.toString();
34 }
35
36 public void testProducesXmlElements() {
37 writer.startNode("hello");
38 writer.setValue("world");
39 writer.endNode();
40
41 assertXmlProducedIs("<hello>world</hello>");
42 }
43
44 public void testSupportsNestedElements() {
45
46 writer.startNode("a");
47
48 writer.startNode("b");
49 writer.setValue("one");
50 writer.endNode();
51
52 writer.startNode("b");
53 writer.setValue("two");
54 writer.endNode();
55
56 writer.startNode("c");
57 writer.startNode("d");
58 writer.setValue("three");
59 writer.endNode();
60 writer.endNode();
61
62 writer.endNode();
63
64 assertXmlProducedIs("<a><b>one</b><b>two</b><c><d>three</d></c></a>");
65 }
66
67 public void testSupportsEmptyTags() {
68 writer.startNode("empty");
69 writer.endNode();
70
71 assertXmlProducedIs("<empty/>");
72 }
73
74 public void testSupportsAttributes() {
75 writer.startNode("person");
76 writer.addAttribute("firstname", "Joe");
77 writer.addAttribute("lastname", "Walnes");
78 writer.endNode();
79
80 assertXmlProducedIs("<person firstname=\"Joe\" lastname=\"Walnes\"/>");
81 }
82
83 public void testAttributesAreResettedForNewNode() {
84 writer.startNode("work");
85 writer.startNode("person");
86 writer.addAttribute("firstname", "Joe");
87 writer.addAttribute("lastname", "Walnes");
88 writer.endNode();
89 writer.startNode("project");
90 writer.addAttribute("XStream", "Codehaus");
91 writer.endNode();
92 writer.endNode();
93
94 assertXmlProducedIs("<work><person firstname=\"Joe\" lastname=\"Walnes\"/><project XStream=\"Codehaus\"/></work>");
95 }
96
97 public void testEscapesXmlUnfriendlyCharacters() {
98 writer.startNode("evil");
99 writer.addAttribute("attr", "w0000 $ <x\"x> &!;");
100 writer.setValue("w0000 $ <xx> &!;");
101 writer.endNode();
102
103 assertXmlProducedIs("<evil attr=\"w0000 $ &lt;x&quot;x&gt; &amp;!;\">w0000 $ &lt;xx&gt; &amp;!;</evil>");
104 }
105
106 public void testEscapesWhitespaceCharactersInValue() {
107 writer.startNode("evil");
108 writer.setValue(" one\ntwo\rthree\r\nfour\n\r five\tsix ");
109 writer.endNode();
110
111 assertXmlProducedIs("<evil> one\n"
112 + "two&#xd;three&#xd;\n"
113 + "four\n"
114 + "&#xd; five\tsix </evil>");
115 }
116
117 public void testEscapesWhitespaceCharactersInAttribute() {
118 writer.startNode("evil");
119 writer.addAttribute("attr", " one\ntwo\rthree\r\nfour\n\r five\tsix ");
120 writer.endNode();
121
122 assertXmlProducedIs("<evil attr=\" one&#xa;two&#xd;three&#xd;&#xa;four&#xa;&#xd; five&#x9;six \"/>");
123 }
124
125 public void testSupportsEmptyNestedTags() {
126 writer.startNode("parent");
127 writer.startNode("child");
128 writer.endNode();
129 writer.endNode();
130
131 assertXmlProducedIs("<parent><child/></parent>");
132 }
133 }
0 /*
1 * Copyright (C) 2011 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 30. September 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class BEAStaxReaderTest extends AbstractXMLReaderTest {
18
19 private HierarchicalStreamDriver driver = new BEAStaxDriver();
20
21 // factory method
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 return driver.createReader(new StringReader(xml));
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011 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 03. November 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 public final class BEAStaxWriterTest extends AbstractStaxWriterTest {
13 protected void assertXmlProducedIs(String expected) {
14 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
15 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2></$1>#g", expected);
16 expected = replaceAll(expected, "&#xd;", "&#13;");
17 expected = replaceAll(expected, "&#xa;", "&#10;");
18 expected = replaceAll(expected, "&#x9;", "&#9;");
19 expected = getXMLHeader() + expected;
20 assertEquals(expected, buffer.toString());
21 }
22
23 protected String getXMLHeader() {
24 return "<?xml version='1.0' encoding='utf-8'?>";
25 }
26
27 protected StaxDriver getStaxDriver() {
28 return new BEAStaxDriver();
29 }
30
31 protected void marshalRepairing(QNameMap qnameMap, String expected) {
32 // repairing mode fails for BEA's reference implementation in this case
33 if (!getName().equals("testNamespacedXmlWithPrefixTwice"))
34 super.marshalRepairing(qnameMap, expected);
35 }
36 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.core.util.QuickWriter;
14
15 import java.io.StringWriter;
16 import java.io.Writer;
17
18 public class CompactWriterTest extends AbstractXMLWriterTest {
19 private Writer buffer;
20
21 protected void setUp() throws Exception {
22 super.setUp();
23 buffer = new StringWriter();
24 writer = new CompactWriter(buffer);
25 }
26
27 protected void assertXmlProducedIs(String expected) {
28 assertEquals(expected, buffer.toString());
29 }
30
31 public void testXmlIsIndented() {
32 writer.startNode("hello");
33 writer.startNode("world");
34
35 writer.startNode("one");
36 writer.setValue("potato");
37 writer.endNode();
38
39 writer.startNode("two");
40 writer.setValue("potatae");
41 writer.endNode();
42
43 writer.endNode();
44 writer.endNode();
45
46 String expected = "<hello><world><one>potato</one><two>potatae</two></world></hello>";
47 assertXmlProducedIs(expected);
48 }
49
50 public void testEncodesFunnyXmlChars() {
51 writer.startNode("tag");
52 writer.setValue("hello & this isn't \"really\" <good>");
53 writer.endNode();
54
55 String expected = "<tag>hello &amp; this isn&apos;t &quot;really&quot; &lt;good&gt;</tag>";
56
57 assertXmlProducedIs(expected);
58 }
59
60 public void testWriteTextAsCDATA() {
61 writer = new CompactWriter(buffer) {
62 protected void writeText(QuickWriter writer, String text) {
63 writer.write("<![CDATA[");
64 writer.write(text);
65 writer.write("]]>");
66 }
67 };
68
69 writer.startNode("tag");
70 writer.setValue("hello & this isn't \"really\" <good>");
71 writer.endNode();
72
73 String expected = "<tag><![CDATA[hello & this isn't \"really\" <good>]]></tag>";
74
75 assertXmlProducedIs(expected);
76 }
77
78 public void testAttributesCanBeWritten() {
79 writer.startNode("tag");
80 writer.addAttribute("hello", "world");
81 writer.startNode("inner");
82 writer.addAttribute("foo", "bar");
83 writer.addAttribute("poo", "par");
84 writer.setValue("hi");
85 writer.endNode();
86 writer.endNode();
87
88 String expected = "" +
89 "<tag hello=\"world\">" +
90 "<inner foo=\"bar\" poo=\"par\">hi</inner>" +
91 "</tag>";
92
93 assertXmlProducedIs(expected);
94 }
95 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import org.dom4j.Document;
16 import org.dom4j.DocumentException;
17 import org.dom4j.DocumentHelper;
18 import org.dom4j.Element;
19
20 public class Dom4JReaderTest extends AbstractXMLReaderTest {
21
22 // factory method
23 protected HierarchicalStreamReader createReader(String xml) throws Exception {
24 return new Dom4JReader(DocumentHelper.parseText(xml));
25 }
26
27 public void testCanReadFromElementOfLargerDocument() throws DocumentException {
28 Document document = DocumentHelper.parseText("" +
29 "<big>" +
30 " <small>" +
31 " <tiny/>" +
32 " </small>" +
33 " <small-two>" +
34 " </small-two>" +
35 "</big>");
36 Element small = document.getRootElement().element("small");
37
38 HierarchicalStreamReader xmlReader = new Dom4JReader(small);
39 assertEquals("small", xmlReader.getNodeName());
40 xmlReader.moveDown();
41 assertEquals("tiny", xmlReader.getNodeName());
42 }
43
44 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 05. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import org.dom4j.Element;
14
15 public class Dom4JWriterTest extends AbstractDocumentWriterTest {
16
17 protected void setUp() throws Exception {
18 super.setUp();
19 writer = new Dom4JWriter();
20 }
21
22 protected DocumentReader createDocumentReaderFor(final Object node) {
23 return new Dom4JReader((Element)node);
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011 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 05. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import org.dom4j.io.OutputFormat;
14
15 import java.io.StringWriter;
16
17 public class Dom4JXmlWriterTest extends AbstractXMLWriterTest {
18
19 private StringWriter out;
20
21 protected void setUp() throws Exception {
22 super.setUp();
23
24 Dom4JDriver driver = new Dom4JDriver();
25
26 OutputFormat format = OutputFormat.createCompactFormat();
27 format.setTrimText(false);
28 format.setSuppressDeclaration(true);
29 driver.setOutputFormat(format);
30
31 out = new StringWriter();
32 writer = driver.createWriter(out);
33 }
34
35 protected void assertXmlProducedIs(String expected) {
36 writer.close();
37 expected = replaceAll(expected, "&#xd;", "\r");
38 // attributes are not properly escaped
39 expected = replaceAll(expected, "&#xa;", "\n");
40 expected = replaceAll(expected, "&#x9;", "\t");
41 assertEquals(expected, out.toString());
42 }
43 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import org.w3c.dom.Document;
16 import org.w3c.dom.Element;
17
18 import javax.xml.parsers.DocumentBuilder;
19 import javax.xml.parsers.DocumentBuilderFactory;
20
21 import java.io.ByteArrayInputStream;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 public class DomReaderTest extends AbstractXMLReaderTest {
26
27 // factory method
28 protected HierarchicalStreamReader createReader(String xml) throws Exception {
29 return new DomReader(buildDocument(xml));
30 }
31
32 private Document buildDocument(String xml) throws Exception {
33 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
34 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
35 ByteArrayInputStream inputStream = new ByteArrayInputStream(xml.getBytes());
36 Document document = documentBuilder.parse(inputStream);
37 return document;
38 }
39
40 public void testCanReadFromElementOfLargerDocument() throws Exception {
41 Document document = buildDocument("" +
42 "<big>" +
43 " <small>" +
44 " <tiny/>" +
45 " </small>" +
46 " <small-two>" +
47 " </small-two>" +
48 "</big>");
49 Element small = (Element) document.getDocumentElement().getElementsByTagName("small").item(0);
50
51 HierarchicalStreamReader xmlReader = new DomReader(small);
52 assertEquals("small", xmlReader.getNodeName());
53 xmlReader.moveDown();
54 assertEquals("tiny", xmlReader.getNodeName());
55 }
56
57 public void testExposesAttributesKeysAndValuesByIndex() throws Exception {
58
59 // overrides test in superclass, because DOM does not retain order of actualAttributes.
60
61 HierarchicalStreamReader xmlReader = createReader("<node hello='world' a='b' c='d'><empty/></node>");
62
63 assertEquals(3, xmlReader.getAttributeCount());
64
65 Map expectedAttributes = new HashMap();
66 expectedAttributes.put("hello", "world");
67 expectedAttributes.put("a", "b");
68 expectedAttributes.put("c", "d");
69
70 Map actualAttributes = new HashMap();
71 for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
72 String name = xmlReader.getAttributeName(i);
73 String value = xmlReader.getAttribute(i);
74 actualAttributes.put(name, value);
75 }
76
77 assertEquals(expectedAttributes, actualAttributes);
78
79 xmlReader.moveDown();
80 assertEquals("empty", xmlReader.getNodeName());
81 assertEquals(0, xmlReader.getAttributeCount());
82 }
83
84 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 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 05. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import javax.xml.parsers.DocumentBuilder;
14 import javax.xml.parsers.DocumentBuilderFactory;
15
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18
19 import com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier;
20 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
21
22 public class DomWriterTest extends AbstractDocumentWriterTest {
23
24 private Document document;
25
26 protected void setUp() throws Exception {
27 super.setUp();
28 final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
29 final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
30 document = documentBuilder.newDocument();
31 writer = new DomWriter(document);
32 }
33
34 protected DocumentReader createDocumentReaderFor(final Object node) {
35 return new DomReader((Element)node);
36 }
37
38 // inherits tests from superclass
39
40 public void testCanWriteIntoArbitraryNode() {
41 Element root = document.createElement("root");
42 document.appendChild(root);
43 Element a = document.createElement("a");
44 root.appendChild(a);
45 writer = new DomWriter(a, document, new XmlFriendlyNameCoder());
46
47 final XppDom xppRoot = new XppDom("root");
48 XppDom xppA = new XppDom("a");
49 xppRoot.addChild(xppA);
50 XppDom xppB = new XppDom("b");
51 xppA.addChild(xppB);
52 xppB.setAttribute("attr", "foo");
53
54 assertDocumentProducedIs(xppA, xppB);
55 XppDomWriter xppDomWriter = new XppDomWriter();
56 new HierarchicalStreamCopier().copy(createDocumentReaderFor(document.getDocumentElement()), xppDomWriter);
57 assertTrue(equals(xppRoot, xppDomWriter.getConfiguration()));
58 }
59
60 public void testCanWriteIntoArbitraryNodeAgain() {
61 Element root = document.createElement("root");
62 document.appendChild(root);
63 Element a = document.createElement("a");
64 root.appendChild(a);
65 writer = new DomWriter(a);
66
67 final XppDom xppRoot = new XppDom("root");
68 XppDom xppA = new XppDom("a");
69 xppRoot.addChild(xppA);
70 XppDom xppB = new XppDom("b");
71 xppA.addChild(xppB);
72 xppB.setAttribute("attr", "foo");
73
74 assertDocumentProducedIs(xppA, xppB);
75 XppDomWriter xppDomWriter = new XppDomWriter();
76 new HierarchicalStreamCopier().copy(createDocumentReaderFor(document.getDocumentElement()), xppDomWriter);
77 assertTrue(equals(xppRoot, xppDomWriter.getConfiguration()));
78 }
79 }
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import java.io.StringReader;
13 import java.util.List;
14
15 import junit.framework.TestCase;
16
17 import org.jdom2.Document;
18 import org.jdom2.input.SAXBuilder;
19 import org.jdom2.output.Format;
20 import org.jdom2.output.XMLOutputter;
21
22 import com.thoughtworks.acceptance.someobjects.X;
23 import com.thoughtworks.acceptance.someobjects.Y;
24 import com.thoughtworks.xstream.XStream;
25
26 public class JDom2AcceptanceTest extends TestCase {
27
28 private XStream xstream;
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 xstream = new XStream();
33 xstream.alias("x", X.class);
34 }
35
36 public void testUnmarshalsObjectFromJDOM() throws Exception {
37 String xml =
38 "<x>" +
39 " <aStr>joe</aStr>" +
40 " <anInt>8</anInt>" +
41 " <innerObj>" +
42 " <yField>walnes</yField>" +
43 " </innerObj>" +
44 "</x>";
45
46 Document doc = new SAXBuilder().build(new StringReader(xml));
47
48 X x = (X) xstream.unmarshal(new JDom2Reader(doc));
49
50 assertEquals("joe", x.aStr);
51 assertEquals(8, x.anInt);
52 assertEquals("walnes", x.innerObj.yField);
53 }
54
55 public void testMarshalsObjectToJDOM() {
56 X x = new X();
57 x.anInt = 9;
58 x.aStr = "zzz";
59 x.innerObj = new Y();
60 x.innerObj.yField = "ooo";
61
62 String expected =
63 "<x>\n" +
64 " <aStr>zzz</aStr>\n" +
65 " <anInt>9</anInt>\n" +
66 " <innerObj>\n" +
67 " <yField>ooo</yField>\n" +
68 " </innerObj>\n" +
69 "</x>";
70
71 JDom2Writer writer = new JDom2Writer();
72 xstream.marshal(x, writer);
73 List result = writer.getTopLevelNodes();
74
75 assertEquals("Result list should contain exactly 1 element",
76 1, result.size());
77
78 XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setLineSeparator("\n"));
79
80 assertEquals(expected, outputter.outputString(result));
81 }
82 }
83
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
13
14 import org.jdom2.Document;
15 import org.jdom2.input.SAXBuilder;
16
17 import java.io.StringReader;
18
19 public class JDom2ReaderTest extends AbstractXMLReaderTest {
20
21 // factory method
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 Document document = new SAXBuilder().build(new StringReader(xml));
24 return new JDom2Reader(document);
25 }
26
27 // inherits tests from superclass
28
29 }
0 /*
1 * Copyright (C) 2013 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 24. June 2012 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import org.jdom2.Element;
13
14 public class JDom2WriterTest extends AbstractDocumentWriterTest {
15
16 protected void setUp() throws Exception {
17 super.setUp();
18 writer = new JDom2Writer();
19 }
20
21 protected DocumentReader createDocumentReaderFor(final Object node) {
22 return new JDom2Reader((Element)node);
23 }
24
25 // inherits tests from superclass
26 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import java.io.StringReader;
14 import java.util.List;
15
16 import junit.framework.TestCase;
17
18 import org.jdom.Document;
19 import org.jdom.input.SAXBuilder;
20 import org.jdom.output.Format;
21 import org.jdom.output.XMLOutputter;
22
23 import com.thoughtworks.acceptance.someobjects.X;
24 import com.thoughtworks.acceptance.someobjects.Y;
25 import com.thoughtworks.xstream.XStream;
26
27 public class JDomAcceptanceTest extends TestCase {
28
29 private XStream xstream;
30
31 protected void setUp() throws Exception {
32 super.setUp();
33 xstream = new XStream();
34 xstream.alias("x", X.class);
35 }
36
37 public void testUnmarshalsObjectFromJDOM() throws Exception {
38 String xml =
39 "<x>" +
40 " <aStr>joe</aStr>" +
41 " <anInt>8</anInt>" +
42 " <innerObj>" +
43 " <yField>walnes</yField>" +
44 " </innerObj>" +
45 "</x>";
46
47 Document doc = new SAXBuilder().build(new StringReader(xml));
48
49 X x = (X) xstream.unmarshal(new JDomReader(doc));
50
51 assertEquals("joe", x.aStr);
52 assertEquals(8, x.anInt);
53 assertEquals("walnes", x.innerObj.yField);
54 }
55
56 public void testMarshalsObjectToJDOM() {
57 X x = new X();
58 x.anInt = 9;
59 x.aStr = "zzz";
60 x.innerObj = new Y();
61 x.innerObj.yField = "ooo";
62
63 String expected =
64 "<x>\n" +
65 " <aStr>zzz</aStr>\n" +
66 " <anInt>9</anInt>\n" +
67 " <innerObj>\n" +
68 " <yField>ooo</yField>\n" +
69 " </innerObj>\n" +
70 "</x>";
71
72 JDomWriter writer = new JDomWriter();
73 xstream.marshal(x, writer);
74 List result = writer.getTopLevelNodes();
75
76 assertEquals("Result list should contain exactly 1 element",
77 1, result.size());
78
79 XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setLineSeparator("\n"));
80
81 assertEquals(expected, outputter.outputString(result));
82 }
83 }
84
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 09. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import org.jdom.Document;
16 import org.jdom.input.SAXBuilder;
17
18 import java.io.StringReader;
19
20 public class JDomReaderTest extends AbstractXMLReaderTest {
21
22 // factory method
23 protected HierarchicalStreamReader createReader(String xml) throws Exception {
24 Document document = new SAXBuilder().build(new StringReader(xml));
25 return new JDomReader(document);
26 }
27
28 // inherits tests from superclass
29
30 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 09. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import org.jdom.Element;
14
15 public class JDomWriterTest extends AbstractDocumentWriterTest {
16
17 protected void setUp() throws Exception {
18 super.setUp();
19 writer = new JDomWriter();
20 }
21
22 protected DocumentReader createDocumentReaderFor(final Object node) {
23 return new JDomReader((Element)node);
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2011 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 30. September 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class KXml2ReaderTest extends AbstractXMLReaderTest {
18
19 private HierarchicalStreamDriver driver = new KXml2Driver();
20
21 // factory method
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 // fails to replace tab characters in attributes to space as required by XML spec
24 if(xml.indexOf('\t')>=0) {
25 xml = xml.replace('\t', ' ');
26 }
27 return driver.createReader(new StringReader(xml));
28 }
29
30 // inherits tests from superclass
31 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.core.util.QuickWriter;
14 import com.thoughtworks.xstream.io.StreamException;
15
16 import java.io.StringWriter;
17
18
19 public class PrettyPrintWriterTest extends AbstractXMLWriterTest {
20 private StringWriter buffer;
21
22 protected void setUp() throws Exception {
23 super.setUp();
24 buffer = new StringWriter();
25 writer = new PrettyPrintWriter(buffer, " ");
26 }
27
28 protected void assertXmlProducedIs(String expected) {
29 assertEquals(expected, buffer.toString());
30 }
31
32 public void testSupportsNestedElements() { // Note: This overrides a test in superclass to
33 // include indentation
34
35 writer.startNode("hello");
36 writer.startNode("world");
37 writer.addAttribute("id", "one");
38
39 writer.startNode("one");
40 writer.setValue("potato");
41 writer.endNode();
42
43 writer.startNode("two");
44 writer.addAttribute("id", "two");
45 writer.setValue("potatae");
46 writer.endNode();
47
48 writer.endNode();
49
50 writer.startNode("empty");
51 writer.endNode();
52
53 writer.endNode();
54
55 String expected = ""
56 + "<hello>\n"
57 + " <world id=\"one\">\n"
58 + " <one>potato</one>\n"
59 + " <two id=\"two\">potatae</two>\n"
60 + " </world>\n"
61 + " <empty/>\n"
62 + "</hello>";
63
64 assertXmlProducedIs(expected);
65 }
66
67 public void testAttributesAreResettedForNewNode() { // Note: This overrides a test in
68 // superclass to include indentation
69 writer.startNode("work");
70 writer.startNode("person");
71 writer.addAttribute("firstname", "Joe");
72 writer.addAttribute("lastname", "Walnes");
73 writer.endNode();
74 writer.startNode("project");
75 writer.addAttribute("XStream", "Codehaus");
76 writer.endNode();
77 writer.endNode();
78
79 String expected = ""
80 + "<work>\n"
81 + " <person firstname=\"Joe\" lastname=\"Walnes\"/>\n"
82 + " <project XStream=\"Codehaus\"/>\n"
83 + "</work>";
84
85 assertXmlProducedIs(expected);
86 }
87
88 public void testAllowsUserToOverrideTextAndAttributeEscapingRules() {
89 writer = new PrettyPrintWriter(buffer, " ") {
90 protected void writeAttributeValue(QuickWriter writer, String text) {
91 writer.write(replace(text, '&', "_&_"));
92 }
93
94 protected void writeText(QuickWriter writer, String text) {
95 writer.write(replace(text, '&', "AND"));
96 }
97 };
98
99 writer.startNode("evil");
100 writer.addAttribute("attr", "hello & stuff");
101 writer.setValue("bye & stuff");
102 writer.endNode();
103
104 assertXmlProducedIs("<evil attr=\"hello _&_ stuff\">bye AND stuff</evil>");
105 }
106
107 public void testSupportsUserDefinedEOL() {
108 writer = new PrettyPrintWriter(buffer, "\t", "\r");
109
110 writer.startNode("element");
111 writer.startNode("empty");
112 writer.endNode();
113 writer.endNode();
114
115 assertXmlProducedIs("<element>\r\t<empty/>\r</element>");
116 }
117
118 public void testSupportsEmptyNestedTags() {
119 writer.startNode("parent");
120 writer.startNode("child");
121 writer.endNode();
122 writer.endNode();
123
124 assertXmlProducedIs("<parent>\n <child/>\n</parent>");
125 }
126
127 public void testSupportsNullInQuirksMode() {
128 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_QUIRKS);
129 writer.startNode("tag");
130 writer.setValue("\u0000");
131 writer.endNode();
132
133 assertXmlProducedIs("<tag>&#x0;</tag>");
134 }
135
136 public void testThrowsForNullInXml1_0Mode() {
137 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_0);
138 writer.startNode("tag");
139 try {
140 writer.setValue("\u0000");
141 fail("Thrown " + StreamException.class.getName() + " expected");
142 } catch (final StreamException e) {
143 assertTrue(e.getMessage().indexOf('0') > 0);
144 }
145 }
146
147 public void testThrowsForNullInXml1_1Mode() {
148 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_1);
149 writer.startNode("tag");
150 try {
151 writer.setValue("\u0000");
152 fail("Thrown " + StreamException.class.getName() + " expected");
153 } catch (final StreamException e) {
154 assertTrue(e.getMessage().indexOf('0') > 0);
155 }
156 }
157
158 public void testSupportsOnlyValidControlCharactersInXml1_0Mode() {
159 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_0);
160 writer.startNode("tag");
161 String ctrl = ""
162 + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007"
163 + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f"
164 + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"
165 + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"
166 + "\u007f"
167 + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087"
168 + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f"
169 + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097"
170 + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f"
171 + "";
172 for (int i = 0; i < ctrl.length(); i++ ) {
173 char c = ctrl.charAt(i);
174 try {
175 writer.setValue(new Character(c).toString());
176 if (c != '\t' && c != '\n' && c != '\r' && c < '\u007f') {
177 fail("Thrown " + StreamException.class.getName() + " expected");
178 }
179 } catch (final StreamException e) {
180 assertTrue(e.getMessage().indexOf(Integer.toHexString(c)) > 0);
181 }
182 }
183 writer.endNode();
184 assertXmlProducedIs("<tag>\t\n&#xd;&#x7f;"
185 + "&#x80;&#x81;&#x82;&#x83;&#x84;&#x85;&#x86;&#x87;"
186 + "&#x88;&#x89;&#x8a;&#x8b;&#x8c;&#x8d;&#x8e;&#x8f;"
187 + "&#x90;&#x91;&#x92;&#x93;&#x94;&#x95;&#x96;&#x97;"
188 + "&#x98;&#x99;&#x9a;&#x9b;&#x9c;&#x9d;&#x9e;&#x9f;</tag>");
189 }
190
191 public void testSupportsOnlyValidControlCharactersInXml1_1Mode() {
192 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_1);
193 writer.startNode("tag");
194 String ctrl = ""
195 + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007"
196 + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f"
197 + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"
198 + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"
199 + "\u007f"
200 + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087"
201 + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f"
202 + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097"
203 + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f"
204 + "";
205 for (int i = 0; i < ctrl.length(); i++ ) {
206 char c = ctrl.charAt(i);
207 try {
208 writer.setValue(new Character(c).toString());
209 if (c == 0) {
210 fail("Thrown " + StreamException.class.getName() + " expected");
211 }
212 } catch (final StreamException e) {
213 assertTrue(e.getMessage().indexOf(Integer.toHexString(c)) > 0);
214 }
215 }
216 writer.endNode();
217 assertXmlProducedIs("<tag>&#x1;&#x2;&#x3;&#x4;&#x5;&#x6;&#x7;"
218 + "&#x8;\t\n&#xb;&#xc;&#xd;&#xe;&#xf;"
219 + "&#x10;&#x11;&#x12;&#x13;&#x14;&#x15;&#x16;&#x17;"
220 + "&#x18;&#x19;&#x1a;&#x1b;&#x1c;&#x1d;&#x1e;&#x1f;&#x7f;"
221 + "&#x80;&#x81;&#x82;&#x83;&#x84;&#x85;&#x86;&#x87;"
222 + "&#x88;&#x89;&#x8a;&#x8b;&#x8c;&#x8d;&#x8e;&#x8f;"
223 + "&#x90;&#x91;&#x92;&#x93;&#x94;&#x95;&#x96;&#x97;"
224 + "&#x98;&#x99;&#x9a;&#x9b;&#x9c;&#x9d;&#x9e;&#x9f;</tag>");
225 }
226
227 public void testSupportsInvalidUnicodeCharacterslInQuirksMode() {
228 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_QUIRKS);
229 writer.startNode("tag");
230 String ctrl = "\ud7ff\ud800\udfff\ue000\ufffd\ufffe\uffff";
231 for (int i = 0; i < ctrl.length(); i++ ) {
232 char c = ctrl.charAt(i);
233 writer.setValue(new Character(c).toString());
234 }
235 writer.endNode();
236 assertXmlProducedIs("<tag>&#xd7ff;\ud800\udfff\ue000\ufffd&#xfffe;&#xffff;</tag>");
237 }
238
239 public void testThrowsForInvalidUnicodeCharacterslInXml1_0Mode() {
240 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_0);
241 writer.startNode("tag");
242 String ctrl = "\ud7ff\ud800\udfff\ue000\ufffd\ufffe\uffff";
243 for (int i = 0; i < ctrl.length(); i++ ) {
244 char c = ctrl.charAt(i);
245 try {
246 writer.setValue(new Character(c).toString());
247 if ((c >= '\ud800' && c < '\udfff') || c == '\ufffe' || c == '\uffff') {
248 fail("Thrown "
249 + StreamException.class.getName()
250 + " for character value "
251 + Integer.toHexString(c)
252 + " expected");
253 }
254 } catch (final StreamException e) {
255 assertTrue(e.getMessage().indexOf(Integer.toHexString(c)) > 0);
256 }
257 }
258 writer.endNode();
259 assertXmlProducedIs("<tag>&#xd7ff;\ue000\ufffd</tag>");
260 }
261
262 public void testThrowsForInvalidUnicodeCharacterslInXml1_1Mode() {
263 writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_1);
264 writer.startNode("tag");
265 String ctrl = "\ud7ff\ud800\udfff\ue000\ufffd\ufffe\uffff";
266 for (int i = 0; i < ctrl.length(); i++ ) {
267 char c = ctrl.charAt(i);
268 try {
269 writer.setValue(new Character(c).toString());
270 if ((c >= '\ud800' && c < '\udfff') || c == '\ufffe' || c == '\uffff') {
271 fail("Thrown "
272 + StreamException.class.getName()
273 + " for character value "
274 + Integer.toHexString(c)
275 + " expected");
276 }
277 } catch (final StreamException e) {
278 assertTrue(e.getMessage().indexOf(Integer.toHexString(c)) > 0);
279 }
280 }
281 writer.endNode();
282 assertXmlProducedIs("<tag>&#xd7ff;\ue000\ufffd</tag>");
283 }
284
285 private String replace(String in, char what, String with) {
286 int pos = in.indexOf(what);
287 if (pos == -1) {
288 return in;
289 } else {
290 return in.substring(0, pos) + with + in.substring(pos + 1);
291 }
292 }
293 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 14. August 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.megginson.sax.DataWriter;
14 import com.thoughtworks.acceptance.someobjects.X;
15 import com.thoughtworks.acceptance.someobjects.Y;
16 import com.thoughtworks.xstream.XStream;
17
18 import junit.framework.TestCase;
19
20 import javax.xml.transform.ErrorListener;
21 import javax.xml.transform.Templates;
22 import javax.xml.transform.Transformer;
23 import javax.xml.transform.TransformerException;
24 import javax.xml.transform.TransformerFactory;
25 import javax.xml.transform.stream.StreamResult;
26 import javax.xml.transform.stream.StreamSource;
27
28 import java.io.StringReader;
29 import java.io.StringWriter;
30 import java.io.Writer;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.List;
35
36 /*
37 * @author Laurent Bihanic
38 */
39 public class SaxWriterTest extends TestCase {
40
41 private final static String IDENTITY_STYLESHEET =
42 "<xsl:stylesheet version=\"1.0\"" +
43 " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
44 "\n" +
45 " <xsl:output method=\"xml\"" +
46 " omit-xml-declaration=\"yes\" indent=\"no\"/>\n" +
47 "\n" +
48 " <xsl:template" +
49 " match=\"*|@*|comment()|processing-instruction()|text()\">\n" +
50 " <xsl:copy>\n" +
51 " <xsl:apply-templates" +
52 " select=\"*|@*|comment()|processing-instruction()|text()\"/>\n" +
53 " </xsl:copy>\n" +
54 " </xsl:template>\n" +
55 "</xsl:stylesheet>";
56
57 private XStream xstream;
58 private X testInput;
59 private Templates identityStylesheet;
60
61 protected void setUp() throws Exception {
62 super.setUp();
63 xstream = new XStream();
64 xstream.alias("x", X.class);
65 xstream.alias("y", Y.class);
66
67 testInput = new X();
68 testInput.anInt = 9;
69 testInput.aStr = "zzz";
70 testInput.innerObj = new Y();
71 testInput.innerObj.yField = "ooo";
72
73 identityStylesheet = TransformerFactory.newInstance().newTemplates(new StreamSource(new StringReader(IDENTITY_STYLESHEET)));
74 }
75
76 public void testMarshalsObjectToSAX() {
77 String expected =
78 "<?xml version=\"1.0\" standalone=\"yes\"?>\n\n" +
79 "<x>\n" +
80 " <aStr>zzz</aStr>\n" +
81 " <anInt>9</anInt>\n" +
82 " <innerObj>\n" +
83 " <yField>ooo</yField>\n" +
84 " </innerObj>\n" +
85 "</x>\n\n";
86
87 Writer buffer = new StringWriter();
88 SaxWriter writer = new SaxWriter();
89 DataWriter outputter = new DataWriter(writer, buffer);
90 outputter.setIndentStep(2);
91
92 writer.setContentHandler(outputter);
93
94 xstream.marshal(testInput, writer);
95
96 assertEquals(expected, buffer.toString());
97 }
98
99 public void testAllowsStartAndEndDocCallbacksToBeSkipped() {
100 String expected =
101 "<int>1</int>\n" +
102 "<int>2</int>\n" +
103 "<int>3</int>\n";
104
105 Writer buffer = new StringWriter();
106 SaxWriter writer = new SaxWriter(false);
107 DataWriter outputter = new DataWriter(writer, buffer);
108 outputter.setIndentStep(2);
109
110 writer.setContentHandler(outputter);
111
112 xstream.marshal(new Integer(1), writer);
113 xstream.marshal(new Integer(2), writer);
114 xstream.marshal(new Integer(3), writer);
115
116 assertEquals(expected, buffer.toString());
117 }
118
119 public void testMarshalsObjectToTrAX() throws Exception {
120 String expected =
121 "<x><aStr>zzz</aStr><anInt>9</anInt>" +
122 "<innerObj><yField>ooo</yField></innerObj>" +
123 "</x>" +
124 "<y><yField>ooo</yField></y>";
125
126 TraxSource traxSource = new TraxSource();
127 traxSource.setXStream(xstream);
128 traxSource.setSourceAsList(Arrays.asList(new Object[]{testInput, testInput.innerObj}));
129
130 Writer buffer = new StringWriter();
131 Transformer transformer = identityStylesheet.newTransformer();
132
133 transformer.transform(traxSource, new StreamResult(buffer));
134
135 assertEquals(expected, buffer.toString());
136 }
137
138 public void testNullSourceObject() {
139 TraxSource traxSource = new TraxSource();
140
141 try {
142 traxSource.setSource(null);
143 fail("Null source object not rejected");
144 } catch (IllegalArgumentException e) { /* good! */
145 }
146 }
147
148 public void testNullSourceList() {
149 TraxSource traxSource = new TraxSource();
150
151 try {
152 traxSource.setSourceAsList(null);
153 fail("Null source list not rejected");
154 } catch (IllegalArgumentException e) { /* good! */
155 }
156 }
157
158 public void testEmptySourceList() {
159 TraxSource traxSource = new TraxSource();
160
161 try {
162 traxSource.setSourceAsList(Collections.EMPTY_LIST);
163 fail("Empty source list not rejected");
164 } catch (IllegalArgumentException e) { /* good! */
165 }
166 }
167
168 /**
169 * This method tests a quite insidious side-effect of
170 * XStreamSource delaying the allocation and configuration of
171 * the SAXWriter until the XSLT processor requests it.
172 * <p/>
173 * SAXWriter performs a copy of the source list contents upon
174 * property setting to avoid objects being added or removed from
175 * the list during the parse.</p>
176 * <p/>
177 * To avoid just another list copy, XStreamSource does not
178 * protect itself against list changes. Hence, it is possible
179 * for an application to configure the XStreamSource and then
180 * empty the list prior triggering the XSL transformation.</p>.
181 * <p/>
182 * This method ensures SAXWriter indeed checks the list content
183 * prior starting the parse.</p>
184 */
185 public void testEmptySourceListAtParse() throws Exception {
186 TraxSource traxSource = new TraxSource();
187 Writer buffer = new StringWriter();
188
189 List list = new ArrayList();
190 list.add(testInput);
191
192 traxSource.setSourceAsList(list);
193 list.clear();
194
195 Transformer transformer = identityStylesheet.newTransformer();
196 transformer.setErrorListener(new TrAXErrorListener());
197
198 try {
199 transformer.transform(traxSource, new StreamResult(buffer));
200
201 fail("Empty source list not rejected");
202 } catch (Exception expectedException) {
203 if (expectedException.getMessage().endsWith("shall not be an empty list")) {
204 // Good!
205 } else {
206 throw expectedException;
207 }
208 }
209 }
210
211 private static class TrAXErrorListener implements ErrorListener {
212 public TrAXErrorListener() {
213 super();
214 }
215
216 public void warning(TransformerException e) {
217 /* Ignore... */
218 }
219
220 public void error(TransformerException e) {
221 /* Ignore... */
222 }
223
224 public void fatalError(TransformerException e)
225 throws TransformerException {
226 throw e;
227 }
228 }
229 }
230
0 /*
1 * Copyright (C) 2011 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 30. September 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import junit.framework.Test;
16 import junit.framework.TestCase;
17 import junit.framework.TestResult;
18 import junit.framework.TestSuite;
19
20 import java.io.StringReader;
21
22 public class SjsxpReaderTest extends AbstractXMLReaderTest {
23 final static String className = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
24
25 public static Test suite() {
26 try {
27 Class.forName(className);
28 return new TestSuite(SjsxpReaderTest.class);
29 } catch (ClassNotFoundException e) {
30 return new TestCase(SjsxpReaderTest.class.getName() + ": not available") {
31
32 public int countTestCases() {
33 return 1;
34 }
35
36 public void run(TestResult result) {
37 }
38 };
39 }
40 }
41
42 private HierarchicalStreamDriver driver = new SjsxpDriver();
43
44 // factory method
45 protected HierarchicalStreamReader createReader(String xml) throws Exception {
46 return driver.createReader(new StringReader(xml));
47 }
48
49 // inherits tests from superclass
50 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011 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 30. September 2011 by Joerg Schaible, renamed from SjsxpStaxWriterTest
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import junit.framework.Test;
13 import junit.framework.TestCase;
14 import junit.framework.TestResult;
15 import junit.framework.TestSuite;
16
17 public final class SjsxpWriterTest extends AbstractStaxWriterTest {
18 final static String className = "com.sun.xml.internal.stream.XMLOutputFactoryImpl";
19
20 public static Test suite() {
21 try {
22 Class.forName(className);
23 return new TestSuite(SjsxpWriterTest.class);
24 } catch (ClassNotFoundException e) {
25 return new TestCase(SjsxpWriterTest.class.getName() + ": not available") {
26
27 public int countTestCases() {
28 return 1;
29 }
30
31 public void run(TestResult result) {
32 }
33 };
34 }
35 }
36
37 protected void assertXmlProducedIs(String expected) {
38 if (!staxDriver.isRepairingNamespace()) {
39 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
40 }
41 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2></$1>#g", expected);
42 expected = replaceAll(expected, "&#xd;", "\r");
43 // attributes are not properly escaped
44 expected = replaceAll(expected, "&#xa;", "\n");
45 expected = replaceAll(expected, "&#x9;", "\t");
46 expected = getXMLHeader() + expected;
47 assertEquals(expected, buffer.toString());
48 }
49
50 protected String getXMLHeader() {
51 return "<?xml version=\"1.0\" ?>";
52 }
53
54 protected StaxDriver getStaxDriver() {
55 return new SjsxpDriver();
56 }
57 }
0 /*
1 * Copyright (C) 2006, 2007 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 07. July 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.bea.xml.stream.MXParserFactory;
13 import com.bea.xml.stream.XMLOutputFactoryBase;
14 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15 import com.thoughtworks.xstream.XStream;
16 import com.thoughtworks.xstream.io.StreamException;
17
18 import javax.xml.stream.XMLInputFactory;
19 import javax.xml.stream.XMLOutputFactory;
20 import javax.xml.stream.XMLStreamException;
21 import javax.xml.stream.XMLStreamReader;
22 import javax.xml.stream.XMLStreamWriter;
23
24
25 /**
26 * @author J&ouml;rg Schaible
27 */
28 public class StaxDriverTest extends AbstractAcceptanceTest {
29 private static class MyStaxDriver extends StaxDriver {
30 public boolean createStaxWriterCalled = false;
31 public boolean createStaxReaderCalled = false;
32
33 public StaxWriter createStaxWriter(XMLStreamWriter out) throws StreamException {
34 createStaxWriterCalled = true;
35 try {
36 return super.createStaxWriter(out);
37 } catch (XMLStreamException e) {
38 throw new StreamException(e);
39 }
40 }
41
42 public AbstractPullReader createStaxReader(XMLStreamReader in) {
43 createStaxReaderCalled = true;
44 return super.createStaxReader(in);
45 }
46 }
47
48 public void testCanOverloadStaxReaderAndWriterInstantiation() {
49 System.setProperty(XMLInputFactory.class.getName(), MXParserFactory.class.getName());
50 System.setProperty(XMLOutputFactory.class.getName(), XMLOutputFactoryBase.class.getName());
51 final MyStaxDriver driver = new MyStaxDriver();
52 xstream = new XStream(driver);
53 assertBothWays("Hi", "<?xml version='1.0' encoding='utf-8'?><string>Hi</string>");
54 assertTrue(driver.createStaxReaderCalled);
55 assertTrue(driver.createStaxWriterCalled);
56 }
57 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 29. September 2004 by James Strachan
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class StaxReaderTest extends AbstractXMLReaderTest {
18 protected HierarchicalStreamReader createReader(String xml) throws Exception {
19 StaxDriver driver = new StaxDriver();
20 return driver.createReader(new StringReader(xml));
21 }
22
23 // inherits tests from superclass
24 }
0 /*
1 * Copyright (C) 2011 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 30. September 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class WstxReaderTest extends AbstractXMLReaderTest {
18
19 private HierarchicalStreamDriver driver = new WstxDriver();
20
21 // factory method
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 return driver.createReader(new StringReader(xml));
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 29. September 2011 by Joerg Schaible, renamed from WoodstoxStaxWriterTest
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.ctc.wstx.stax.WstxOutputFactory;
13
14 import javax.xml.stream.XMLOutputFactory;
15
16 public final class WstxWriterTest extends AbstractStaxWriterTest {
17 protected void assertXmlProducedIs(String expected) {
18 if (!staxDriver.isRepairingNamespace() || perlUtil.match("#<\\w+:\\w+(>| xmlns:\\w+=)#", expected)) {
19 expected = perlUtil.substitute("s# xmlns=\"\"##g", expected);
20 }
21 expected = perlUtil.substitute("s#<(\\w+)([^>]*)/>#<$1$2 />#g", expected);
22 expected = replaceAll(expected, "&#x0D;", "&#xd;");
23 expected = replaceAll(expected, "&gt;", ">"); // Woodstox bug !!
24 expected = getXMLHeader() + expected;
25 assertEquals(expected, buffer.toString());
26 }
27
28 protected String getXMLHeader() {
29 return "<?xml version='1.0' encoding='UTF-8'?>";
30 }
31
32 protected XMLOutputFactory getOutputFactory() {
33 return new WstxOutputFactory();
34 }
35
36 protected StaxDriver getStaxDriver() {
37 return new WstxDriver();
38 }
39 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 02. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import nu.xom.Builder;
16 import nu.xom.Document;
17
18 import java.io.StringReader;
19
20 public class XomReaderTest extends AbstractXMLReaderTest {
21
22 // factory method
23 protected HierarchicalStreamReader createReader(String xml) throws Exception {
24 Document document = new Builder().build(new StringReader(xml));
25 return new XomReader(document);
26 }
27
28 // inherits tests from superclass
29
30 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 03. September 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import nu.xom.Element;
14
15 public class XomWriterTest extends AbstractDocumentWriterTest {
16
17 protected void setUp() throws Exception {
18 super.setUp();
19 writer = new XomWriter();
20 }
21
22 protected DocumentReader createDocumentReaderFor(final Object node) {
23 return new XomReader((Element)node);
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2011 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 30. September 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class Xpp3ReaderTest extends AbstractXMLReaderTest {
18
19 private HierarchicalStreamDriver driver = new Xpp3Driver();
20
21 // factory method
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 return driver.createReader(new StringReader(xml));
24 }
25
26 // inherits tests from superclass
27 }
0 /*
1 * Copyright (C) 2004, 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009, 2011 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 07. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
15 import com.thoughtworks.xstream.io.xml.xppdom.XppFactory;
16
17 import java.io.StringReader;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 public class XppDomReaderTest extends AbstractXMLReaderTest {
22 protected HierarchicalStreamReader createReader(String xml) throws Exception {
23 return new Xpp3DomDriver().createReader(new StringReader(xml));
24 }
25
26 public void testCanReadFromElementOfLargerDocument()
27 throws Exception {
28 String xml =
29 "<big>" +
30 " <small>" +
31 " <tiny/>" +
32 " </small>" +
33 " <small-two>" +
34 " </small-two>" +
35 "</big>";
36
37 XppDom document = XppFactory.buildDom(xml);
38
39 XppDom small = document.getChild("small");
40
41 HierarchicalStreamReader xmlReader = new XppDomReader(small);
42
43 assertEquals("small", xmlReader.getNodeName());
44
45 xmlReader.moveDown();
46
47 assertEquals("tiny", xmlReader.getNodeName());
48 }
49
50 public void testExposesAttributesKeysAndValuesByIndex() throws Exception {
51
52 // overrides test in superclass, because XppDom does not retain order of actualAttributes.
53
54 HierarchicalStreamReader xmlReader = createReader("<node hello='world' a='b' c='d'><empty/></node>");
55
56 assertEquals(3, xmlReader.getAttributeCount());
57
58 Map expectedAttributes = new HashMap();
59 expectedAttributes.put("hello", "world");
60 expectedAttributes.put("a", "b");
61 expectedAttributes.put("c", "d");
62
63 Map actualAttributes = new HashMap();
64 for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
65 String name = xmlReader.getAttributeName(i);
66 String value = xmlReader.getAttribute(i);
67 actualAttributes.put(name, value);
68 }
69
70 assertEquals(expectedAttributes, actualAttributes);
71
72 xmlReader.moveDown();
73 assertEquals("empty", xmlReader.getNodeName());
74 assertEquals(0, xmlReader.getAttributeCount());
75 }
76
77 }
0 /*
1 * Copyright (C) 2006, 2007, 2009 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 19. October 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.io.xml;
11
12 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
13
14 /**
15 * @author J&ouml;rg Schaible
16 */
17 public class XppDomWriterTest extends AbstractDocumentWriterTest {
18
19 protected void setUp() throws Exception {
20 super.setUp();
21 writer = new XppDomWriter();
22 }
23
24 protected DocumentReader createDocumentReaderFor(Object node) {
25 return new XppDomReader((XppDom)node);
26 }
27
28 // inherits tests from superclass
29 }
0 /*
1 * Copyright (C) 2004 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 08. March 2004 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.io.xml;
12
13 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
14
15 import java.io.StringReader;
16
17 public class XppReaderTest extends AbstractXMLReaderTest {
18 protected HierarchicalStreamReader createReader(String xml) throws Exception {
19 return new XppReader(new StringReader(xml));
20 }
21
22 // inherits tests from superclass
23 }
0 /*
1 * Copyright (C) 2011 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 11. August 2011 by Joerg Schaible.
9 */
10
11 package com.thoughtworks.xstream.io.xml.xppdom;
12
13 import java.util.Comparator;
14
15 import com.thoughtworks.xstream.io.xml.xppdom.XppDom;
16 import com.thoughtworks.xstream.io.xml.xppdom.XppFactory;
17
18 import junit.framework.TestCase;
19
20
21 /**
22 * Tests {@link XppDomComparator}.
23 *
24 * @author J&ouml;rg Schaible
25 */
26 public class XppDomComparatorTest extends TestCase {
27 // ~ Instance fields --------------------------------------------------------
28
29 private ThreadLocal xpath;
30 private XppDomComparator comparator;
31
32 // ~ Methods ----------------------------------------------------------------
33
34 protected void setUp() throws Exception {
35 super.setUp();
36 xpath = new ThreadLocal();
37 comparator = new XppDomComparator(xpath);
38 }
39
40 private void assertEquals(Comparator comparator, Object o1, Object o2) {
41 if (comparator.compare(o1, o2) != 0) {
42 fail("Cpmarator claims '" + o1 + "' to be different from '" + o2 + "'");
43 }
44 }
45
46 /**
47 * Tests comparison of empty document.
48 *
49 * @throws Exception unexpected
50 */
51 public void testEqualsEmptyDocuments() throws Exception {
52 final String xml = "<dom/>";
53 XppDom dom1 = XppFactory.buildDom(xml);
54 XppDom dom2 = XppFactory.buildDom(xml);
55 assertEquals(comparator, dom1, dom2);
56 assertNull(xpath.get());
57 }
58
59 /**
60 * Tests comparison of different values.
61 *
62 * @throws Exception unexpected
63 */
64 public void testSortsElementsWithDifferentValue() throws Exception {
65 XppDom dom1 = XppFactory.buildDom("<dom>value1</dom>");
66 XppDom dom2 = XppFactory.buildDom("<dom>value2</dom>");
67 assertEquals(-1, comparator.compare(dom1, dom2));
68 assertEquals("/dom::text()", xpath.get());
69 assertEquals(1, comparator.compare(dom2, dom1));
70 assertEquals("/dom::text()", xpath.get());
71 }
72
73 /**
74 * Tests comparison of a value and null.
75 *
76 * @throws Exception unexpected
77 */
78 public void testSortsElementsWithValueAndNull() throws Exception {
79 XppDom dom1 = XppFactory.buildDom("<dom/>");
80 XppDom dom2 = XppFactory.buildDom("<dom>value</dom>");
81 assertEquals(-1, comparator.compare(dom1, dom2));
82 assertEquals("/dom::text()", xpath.get());
83 assertEquals(1, comparator.compare(dom2, dom1));
84 assertEquals("/dom::text()", xpath.get());
85 }
86
87 /**
88 * Tests comparison of attributes.
89 *
90 * @throws Exception unexpected
91 */
92 public void testEqualsAttributes() throws Exception {
93 final String xml = "<dom a='1' b='2'/>";
94 XppDom dom1 = XppFactory.buildDom(xml);
95 XppDom dom2 = XppFactory.buildDom(xml);
96 assertEquals(comparator, dom1, dom2);
97 assertNull(xpath.get());
98 }
99
100 /**
101 * Tests comparison of attributes in different order.
102 *
103 * @throws Exception unexpected
104 */
105 public void testEqualsAttributesInDifferentOrder() throws Exception {
106 XppDom dom1 = XppFactory.buildDom("<dom a='1' b='2'/>");
107 XppDom dom2 = XppFactory.buildDom("<dom b='2' a='1'/>");
108 assertEquals(comparator, dom1, dom2);
109 assertNull(xpath.get());
110 }
111
112 /**
113 * Tests comparison of same attributes with different values.
114 *
115 * @throws Exception unexpected
116 */
117 public void testSortsSameAttributes() throws Exception {
118 XppDom dom1 = XppFactory.buildDom("<dom a='1' b='2'/>");
119 XppDom dom2 = XppFactory.buildDom("<dom a='2' b='1'/>");
120 assertEquals(-1, comparator.compare(dom1, dom2));
121 assertEquals("/dom[@a]", xpath.get());
122 assertEquals(1, comparator.compare(dom2, dom1));
123 assertEquals("/dom[@a]", xpath.get());
124 }
125
126 /**
127 * Tests comparison of different attributes.
128 *
129 * @throws Exception unexpected
130 */
131 public void testSortsDifferentAttributes() throws Exception {
132 XppDom dom1 = XppFactory.buildDom("<dom a='1'/>");
133 XppDom dom2 = XppFactory.buildDom("<dom b='1'/>");
134 assertEquals(-1, comparator.compare(dom1, dom2));
135 assertEquals("/dom[@a?]", xpath.get());
136 assertEquals(1, comparator.compare(dom2, dom1));
137 assertEquals("/dom[@b?]", xpath.get());
138 }
139
140 /**
141 * Tests comparison of different number of attributes.
142 *
143 * @throws Exception unexpected
144 */
145 public void testSortsAccordingNumberOfAttributes() throws Exception {
146 XppDom dom1 = XppFactory.buildDom("<dom/>");
147 XppDom dom2 = XppFactory.buildDom("<dom a='1'/>");
148 assertEquals(-1, comparator.compare(dom1, dom2));
149 assertEquals("/dom::count(@*)", xpath.get());
150 assertEquals(1, comparator.compare(dom2, dom1));
151 assertEquals("/dom::count(@*)", xpath.get());
152 }
153
154 /**
155 * Tests comparison of document with children.
156 *
157 * @throws Exception unexpected
158 */
159 public void testEqualsDocumentsWithChildren() throws Exception {
160 final String xml = "<dom><a/></dom>";
161 XppDom dom1 = XppFactory.buildDom(xml);
162 XppDom dom2 = XppFactory.buildDom(xml);
163 assertEquals(comparator, dom1, dom2);
164 assertNull(xpath.get());
165 }
166
167 /**
168 * Tests comparison of different number of children.
169 *
170 * @throws Exception unexpected
171 */
172 public void testSortsAccordingNumberOfChildren() throws Exception {
173 XppDom dom1 = XppFactory.buildDom("<dom/>");
174 XppDom dom2 = XppFactory.buildDom("<dom><a/></dom>");
175 assertEquals(-1, comparator.compare(dom1, dom2));
176 assertEquals("/dom::count(*)", xpath.get());
177 assertEquals(1, comparator.compare(dom2, dom1));
178 assertEquals("/dom::count(*)", xpath.get());
179 }
180
181 /**
182 * Tests comparison of different elements.
183 *
184 * @throws Exception unexpected
185 */
186 public void testSortsElementsByName() throws Exception {
187 XppDom dom1 = XppFactory.buildDom("<dom><a/></dom>");
188 XppDom dom2 = XppFactory.buildDom("<dom><b/></dom>");
189 assertEquals(-1, comparator.compare(dom1, dom2));
190 assertEquals("/dom/a[0]?", xpath.get());
191 assertEquals(1, comparator.compare(dom2, dom1));
192 assertEquals("/dom/b[0]?", xpath.get());
193 }
194
195 /**
196 * Tests comparison of different nth elements.
197 *
198 * @throws Exception unexpected
199 */
200 public void testSortsElementsByNthName() throws Exception {
201 XppDom dom1 = XppFactory.buildDom("<dom><a/><b/><c/><a/></dom>");
202 XppDom dom2 = XppFactory.buildDom("<dom><a/><b/><c/><b/></dom>");
203 assertEquals(-1, comparator.compare(dom1, dom2));
204 assertEquals("/dom/a[1]?", xpath.get());
205 assertEquals(1, comparator.compare(dom2, dom1));
206 assertEquals("/dom/b[1]?", xpath.get());
207 }
208
209 /**
210 * Tests comparison sorts attributes before elements.
211 *
212 * @throws Exception unexpected
213 */
214 public void testSortsAttributesBeforeElements() throws Exception {
215 XppDom dom1 = XppFactory.buildDom("<dom x='a'><a/></dom>");
216 XppDom dom2 = XppFactory.buildDom("<dom x='b'><b/></dom>");
217 assertEquals(-1, comparator.compare(dom1, dom2));
218 assertEquals("/dom[@x]", xpath.get());
219 assertEquals(1, comparator.compare(dom2, dom1));
220 assertEquals("/dom[@x]", xpath.get());
221 }
222
223 /**
224 * Tests comparison will reset XPath after recursion.
225 *
226 * @throws Exception unexpected
227 */
228 public void testWillResetXPathAfterRecursion() throws Exception {
229 XppDom dom1 = XppFactory.buildDom("<dom><a><b>foo</b></a><c x='1'/></dom>");
230 XppDom dom2 = XppFactory.buildDom("<dom><a><b>foo</b></a><c x='2'/></dom>");
231 assertEquals(-1, comparator.compare(dom1, dom2));
232 assertEquals("/dom/c[0][@x]", xpath.get());
233 assertEquals(1, comparator.compare(dom2, dom1));
234 assertEquals("/dom/c[0][@x]", xpath.get());
235 }
236
237 /**
238 * Tests comparison of empty document.
239 *
240 * @throws Exception unexpected
241 */
242 public void testCompareWithoutReference() throws Exception {
243 comparator = new XppDomComparator();
244 final String xml = "<dom/>";
245 XppDom dom1 = XppFactory.buildDom(xml);
246 XppDom dom2 = XppFactory.buildDom(xml);
247 assertEquals(comparator, dom1, dom2);
248 assertNull(xpath.get());
249 }
250 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 23. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.xstream.core.ClassLoaderReference;
14 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
15
16 import junit.framework.TestCase;
17
18 public class DefaultClassMapperTest extends TestCase {
19 private Mapper mapper;
20
21 protected void setUp() throws Exception {
22 super.setUp();
23 mapper = new ArrayMapper(new DefaultMapper(new ClassLoaderReference(
24 new CompositeClassLoader())));
25 }
26
27 public void testAppendsArraySuffixOnArrays() {
28 Class arrayCls = new String[0].getClass();
29 assertEquals("java.lang.String-array", mapper.serializedClass(arrayCls));
30 }
31
32 public void testAppendsMultipleArraySuffixesOnMultidimensionalArrays() {
33 Class arrayCls = new String[0][0][0].getClass();
34 assertEquals("java.lang.String-array-array-array", mapper.serializedClass(arrayCls));
35 }
36
37 public void testCreatesInstancesOfArrays() {
38 Class arrayType = mapper.realClass("java.lang.String-array");
39 assertTrue(arrayType.isArray());
40 assertEquals(String.class, arrayType.getComponentType());
41 }
42
43 public void testSupportsAllPrimitiveArrayTypes() {
44 assertEquals(int.class, mapper.realClass("int-array").getComponentType());
45 assertEquals(short.class, mapper.realClass("short-array").getComponentType());
46 assertEquals(long.class, mapper.realClass("long-array").getComponentType());
47 assertEquals(char.class, mapper.realClass("char-array").getComponentType());
48 assertEquals(boolean.class, mapper.realClass("boolean-array").getComponentType());
49 assertEquals(float.class, mapper.realClass("float-array").getComponentType());
50 assertEquals(double.class, mapper.realClass("double-array").getComponentType());
51 assertEquals(byte.class, mapper.realClass("byte-array").getComponentType());
52 }
53
54 public void testCreatesInstancesOfMultidimensionalArrays() {
55 Class arrayType = mapper.realClass("java.lang.String-array-array-array");
56 assertTrue(arrayType.isArray());
57 assertTrue(arrayType.getComponentType().isArray());
58 assertTrue(arrayType.getComponentType().getComponentType().isArray());
59
60 assertFalse(arrayType.getComponentType().getComponentType().getComponentType().isArray());
61 assertEquals(String.class, arrayType.getComponentType().getComponentType().getComponentType());
62
63 Class primitiveArrayType = mapper.realClass("int-array-array-array");
64 assertTrue(primitiveArrayType.isArray());
65 assertTrue(primitiveArrayType.getComponentType().isArray());
66 assertTrue(primitiveArrayType.getComponentType().getComponentType().isArray());
67
68 assertFalse(primitiveArrayType.getComponentType().getComponentType().getComponentType().isArray());
69 assertEquals(int.class, primitiveArrayType.getComponentType().getComponentType().getComponentType());
70 }
71 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 09. April 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
14 import com.thoughtworks.acceptance.objects.Software;
15
16 public class FieldAliasingMapperTest extends AbstractAcceptanceTest {
17
18 public void testAllowsIndividualFieldsToBeAliased() {
19 Software in = new Software("ms", "word");
20 xstream.alias("software", Software.class);
21 xstream.aliasField("CUSTOM-VENDOR", Software.class, "vendor");
22 xstream.aliasField("CUSTOM-NAME", Software.class, "name");
23
24 String expectedXml = "" +
25 "<software>\n" +
26 " <CUSTOM-VENDOR>ms</CUSTOM-VENDOR>\n" +
27 " <CUSTOM-NAME>word</CUSTOM-NAME>\n" +
28 "</software>";
29
30 assertBothWays(in, expectedXml);
31 }
32 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2011, 2013 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 16. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.mapper;
12
13 import java.util.Map;
14
15 import com.thoughtworks.acceptance.objects.Hardware;
16 import com.thoughtworks.acceptance.objects.OpenSourceSoftware;
17 import com.thoughtworks.acceptance.objects.Product;
18 import com.thoughtworks.acceptance.objects.SampleLists;
19 import com.thoughtworks.acceptance.objects.SampleMaps;
20 import com.thoughtworks.acceptance.objects.Software;
21 import com.thoughtworks.xstream.core.ClassLoaderReference;
22
23 import junit.framework.TestCase;
24
25 public class ImplicitCollectionMapperTest extends TestCase {
26
27 private ImplicitCollectionMapper implicitCollections = new ImplicitCollectionMapper(
28 new DefaultMapper(new ClassLoaderReference(null)));
29
30 public void testAllowsFieldsToBeMarkedAsImplicitCollectionsToBeAdded() {
31 implicitCollections.add(SampleLists.class, "good", null);
32 assertNotNull(implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "good"));
33 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, null));
34 }
35
36 public void testDoesNotMarkFieldsAsImplicitCollectionByDefault() {
37 assertNull(implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "good"));
38 assertEquals(null, implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, null));
39 }
40
41 public void testAllowsFieldsToBeMarkedBasedOnItemType() {
42 implicitCollections.add(SampleLists.class, "good", Software.class);
43 implicitCollections.add(SampleLists.class, "bad", Hardware.class);
44 assertNotNull(implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "bad"));
45 assertNotNull(implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "good"));
46 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Software.class, null));
47 assertEquals("bad", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Hardware.class, null));
48 }
49
50 public void testIncludesSubClassesWhenCheckingItemType() {
51 implicitCollections.add(SampleLists.class, "good", Software.class);
52 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, OpenSourceSoftware.class, null));
53 assertEquals(null, implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Hardware.class, null));
54 }
55
56 public void testAllowsFieldsToBeMarkedAsNamedImplicitCollectionsToBeAdded() {
57 implicitCollections.add(SampleLists.class, "good", "good-item", Object.class);
58 implicitCollections.add(SampleLists.class, "bad", null);
59 Mapper.ImplicitCollectionMapping mappingGood = implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "good");
60 assertNotNull(mappingGood);
61 assertEquals("good-item", mappingGood.getItemFieldName());
62 assertEquals(Object.class, mappingGood.getItemType());
63 assertEquals("good", mappingGood.getFieldName());
64
65 Mapper.ImplicitCollectionMapping mappingBad = implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "bad");
66 assertNotNull(mappingBad);
67 assertNull(mappingBad.getItemFieldName());
68 assertNull(mappingBad.getItemType());
69
70 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, "good-item"));
71 assertEquals("bad", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, null));
72 }
73
74 public void testAllowsFieldsToBeMarkedBasedOnItemFieldName() {
75 implicitCollections.add(SampleLists.class, "good", "good-item", Object.class);
76 implicitCollections.add(SampleLists.class, "bad", "bad-item", Object.class);
77 Mapper.ImplicitCollectionMapping mappingGood = implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "good");
78 assertNotNull(mappingGood);
79 assertEquals("good-item", mappingGood.getItemFieldName());
80 assertEquals(Object.class, mappingGood.getItemType());
81 assertEquals("good", mappingGood.getFieldName());
82
83 Mapper.ImplicitCollectionMapping mappingBad = implicitCollections.getImplicitCollectionDefForFieldName(SampleLists.class, "bad");
84 assertNotNull(mappingBad);
85 assertEquals("bad-item", mappingBad.getItemFieldName());
86 assertEquals(Object.class, mappingBad.getItemType());
87 assertEquals("bad", mappingBad.getFieldName());
88
89 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, "good-item"));
90 assertEquals("bad", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Object.class, "bad-item"));
91 }
92
93 public void testIncludesSubClassesWhenCheckingItemTypeForNamedImplicitCollections() {
94 implicitCollections.add(SampleLists.class, "good", "good-item", Software.class);
95 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, OpenSourceSoftware.class, "good-item"));
96 assertEquals(null, implicitCollections.getFieldNameForItemTypeAndName(SampleLists.class, Hardware.class, null));
97 }
98
99 public void testGetItemTypeForItemFieldName() {
100 implicitCollections.add(SampleLists.class, "good", "good-item", Software.class);
101 implicitCollections.add(SampleLists.class, "bad", "bad-item", Product.class);
102
103 assertEquals(Software.class, implicitCollections.getItemTypeForItemFieldName(SampleLists.class, "good-item"));
104 assertEquals(Product.class, implicitCollections.getItemTypeForItemFieldName(SampleLists.class, "bad-item"));
105 }
106
107 public void testAllowsFieldsToBeMarkedAsImplicitMapsToBeAdded() {
108 implicitCollections.add(SampleMaps.class, "good", null);
109 assertNotNull(implicitCollections.getImplicitCollectionDefForFieldName(SampleMaps.class, "good"));
110 assertEquals("good", implicitCollections.getFieldNameForItemTypeAndName(SampleMaps.class, Map.Entry.class, null));
111 }
112
113 public void testGetKeyFieldNameForItemFieldName() {
114 implicitCollections.add(SampleMaps.class, "good", "good-item", Software.class, "name");
115 implicitCollections.add(SampleMaps.class, "bad", "bad-item", Software.class, "vendor");
116
117 assertEquals("name", implicitCollections.getImplicitCollectionDefForFieldName(SampleMaps.class, "good").getKeyFieldName());
118 assertEquals("vendor", implicitCollections.getImplicitCollectionDefForFieldName(SampleMaps.class, "bad").getKeyFieldName());
119 }
120 }
0 /*
1 * Copyright (C) 2014 XStream Committers.
2 * All rights reserved.
3 *
4 * Created on 09. January 2014 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.mapper;
7
8 import java.net.URL;
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13 import com.thoughtworks.xstream.core.JVM;
14 import com.thoughtworks.xstream.core.util.QuickWriter;
15 import com.thoughtworks.xstream.security.AnyTypePermission;
16 import com.thoughtworks.xstream.security.ArrayTypePermission;
17 import com.thoughtworks.xstream.security.ExplicitTypePermission;
18 import com.thoughtworks.xstream.security.ForbiddenClassException;
19 import com.thoughtworks.xstream.security.NoTypePermission;
20 import com.thoughtworks.xstream.security.NullPermission;
21 import com.thoughtworks.xstream.security.PrimitiveTypePermission;
22 import com.thoughtworks.xstream.security.RegExpTypePermission;
23 import com.thoughtworks.xstream.security.TypePermission;
24 import com.thoughtworks.xstream.security.WildcardTypePermission;
25
26 import junit.framework.TestCase;
27
28
29 /**
30 * Tests the {@link SecurityMapper} and the {@link TypePermission} implementations.
31 *
32 * @author J&ouml;rg Schaible
33 */
34 public class SecurityMapperTest extends TestCase {
35
36 private SecurityMapper mapper;
37 private Map classMap;
38
39 protected void setUp() throws Exception {
40 super.setUp();
41
42 classMap = new HashMap();
43 mapper = new SecurityMapper(new MapperWrapper(null) {
44 public Class realClass(final String elementName) {
45 return (Class)classMap.get(elementName);
46 }
47 });
48 }
49
50 private void register(final Class[] types) {
51 for (int i = 0; i < types.length; ++i) {
52 classMap.put(types[i].getName(), types[i]);
53 }
54 }
55
56 public void testAnyType() {
57 register(new Class[]{String.class, URL.class, List.class});
58 mapper.addPermission(NoTypePermission.NONE);
59 mapper.addPermission(AnyTypePermission.ANY);
60 assertSame(String.class, mapper.realClass(String.class.getName()));
61 assertSame(List.class, mapper.realClass(List.class.getName()));
62 assertNull(mapper.realClass(null));
63 }
64
65 public void testNoType() {
66 register(new Class[]{String.class, URL.class, List.class});
67 mapper.addPermission(NoTypePermission.NONE);
68 try {
69 mapper.realClass(String.class.getName());
70 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
71 } catch (final ForbiddenClassException e) {
72 assertEquals(String.class.getName(), e.getMessage());
73 }
74 try {
75 mapper.realClass(null);
76 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
77 } catch (final ForbiddenClassException e) {
78 assertEquals("null", e.getMessage());
79 }
80 }
81
82 public void testNullType() {
83 register(new Class[]{String.class, Mapper.Null.class});
84 mapper.addPermission(NullPermission.NULL);
85 assertSame(Mapper.Null.class, mapper.realClass(Mapper.Null.class.getName()));
86 assertNull(mapper.realClass(null));
87 try {
88 mapper.realClass(String.class.getName());
89 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
90 } catch (final ForbiddenClassException e) {
91 assertEquals(String.class.getName(), e.getMessage());
92 }
93 }
94
95 public void testPrimitiveTypes() {
96 register(new Class[]{String.class, int.class, Integer.class, char[].class, Character[].class});
97 mapper.addPermission(PrimitiveTypePermission.PRIMITIVES);
98 assertSame(int.class, mapper.realClass(int.class.getName()));
99 assertSame(Integer.class, mapper.realClass(Integer.class.getName()));
100 try {
101 mapper.realClass(String.class.getName());
102 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
103 } catch (final ForbiddenClassException e) {
104 assertEquals(String.class.getName(), e.getMessage());
105 }
106 try {
107 mapper.realClass(null);
108 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
109 } catch (final ForbiddenClassException e) {
110 assertEquals("null", e.getMessage());
111 }
112 try {
113 mapper.realClass(char[].class.getName());
114 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
115 } catch (final ForbiddenClassException e) {
116 assertEquals(char[].class.getName(), e.getMessage());
117 }
118 }
119
120 public void testArrayTypes() {
121 register(new Class[]{String.class, int.class, Integer.class, char[].class, Character[].class});
122 mapper.addPermission(ArrayTypePermission.ARRAYS);
123 assertSame(char[].class, mapper.realClass(char[].class.getName()));
124 assertSame(Character[].class, mapper.realClass(Character[].class.getName()));
125 try {
126 mapper.realClass(String.class.getName());
127 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
128 } catch (final ForbiddenClassException e) {
129 assertEquals(String.class.getName(), e.getMessage());
130 }
131 try {
132 mapper.realClass(null);
133 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
134 } catch (final ForbiddenClassException e) {
135 assertEquals("null", e.getMessage());
136 }
137 try {
138 mapper.realClass(int.class.getName());
139 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
140 } catch (final ForbiddenClassException e) {
141 assertEquals(int.class.getName(), e.getMessage());
142 }
143 }
144
145 public void testExplicitTypes() {
146 register(new Class[]{String.class, List.class});
147 mapper.addPermission(new ExplicitTypePermission(new String[]{String.class.getName(), List.class.getName()}));
148 assertSame(String.class, mapper.realClass(String.class.getName()));
149 assertSame(List.class, mapper.realClass(List.class.getName()));
150 try {
151 mapper.realClass(null);
152 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
153 } catch (final ForbiddenClassException e) {
154 assertEquals("null", e.getMessage());
155 }
156 }
157
158 public void testNamesWithRegExps() {
159 class Foo$_0 {}
160 final Class anonymous = new Object() {}.getClass();
161 register(new Class[]{
162 String.class, JVM.class, QuickWriter.class, Foo$_0.class, anonymous, DefaultClassMapperTest.class});
163 mapper.addPermission(new RegExpTypePermission(new String[]{
164 ".*Test", ".*\\.core\\..*", ".*SecurityMapperTest\\$.+"}));
165 assertSame(DefaultClassMapperTest.class, mapper.realClass(DefaultClassMapperTest.class.getName()));
166 assertSame(JVM.class, mapper.realClass(JVM.class.getName()));
167 assertSame(QuickWriter.class, mapper.realClass(QuickWriter.class.getName()));
168 assertSame(Foo$_0.class, mapper.realClass(Foo$_0.class.getName()));
169 assertSame(anonymous, mapper.realClass(anonymous.getName()));
170 try {
171 mapper.realClass(String.class.getName());
172 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
173 } catch (final ForbiddenClassException e) {
174 assertEquals(String.class.getName(), e.getMessage());
175 }
176 }
177
178 public void testNamesWithWildcardPatterns() {
179 class Foo$_0 {}
180 class Foo$_1 {}
181 final Class anonymous = new Object() {}.getClass();
182 register(new Class[]{String.class, JVM.class, QuickWriter.class, Foo$_0.class, Foo$_1.class, anonymous});
183 mapper
184 .addPermission(new WildcardTypePermission(new String[]{"**.*_0", "**.core.*", "**.SecurityMapperTest$?"}));
185 assertSame(JVM.class, mapper.realClass(JVM.class.getName()));
186 assertSame(Foo$_0.class, mapper.realClass(Foo$_0.class.getName()));
187 assertSame(anonymous, mapper.realClass(anonymous.getName()));
188 try {
189 mapper.realClass(String.class.getName());
190 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
191 } catch (final ForbiddenClassException e) {
192 assertEquals(String.class.getName(), e.getMessage());
193 }
194 try {
195 mapper.realClass(QuickWriter.class.getName());
196 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
197 } catch (final ForbiddenClassException e) {
198 assertEquals(QuickWriter.class.getName(), e.getMessage());
199 }
200 try {
201 mapper.realClass(Foo$_1.class.getName());
202 fail("Thrown " + ForbiddenClassException.class.getName() + " expected");
203 } catch (final ForbiddenClassException e) {
204 assertEquals(Foo$_1.class.getName(), e.getMessage());
205 }
206 }
207 }
0 /*
1 * Copyright (C) 2006, 2007, 2013 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 13. February 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.mapper;
11
12 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
13
14 import junit.framework.TestCase;
15
16 public class XmlFriendlyMapperTest extends TestCase {
17
18 private Mapper mapper;
19
20 public void testPrefixesIllegalXmlElementNamesWithValue() throws ClassNotFoundException {
21 mapper = new XmlFriendlyMapper(new DefaultMapper(new CompositeClassLoader()));
22 Class clsInDefaultPackage = Class.forName("$Package");
23 String aliasedName = mapper.serializedClass(clsInDefaultPackage);
24 assertTrue("Does not start with 'default-Package' : <" + aliasedName + ">",
25 aliasedName.startsWith("default-Package"));
26 assertEquals(clsInDefaultPackage, mapper.realClass(aliasedName));
27 }
28
29 }
0 /*
1 * Copyright (C) 2008, 2009 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. November 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.persistence;
11
12 import java.io.File;
13 import java.net.MalformedURLException;
14 import java.net.URL;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.Map;
18
19 import junit.framework.TestCase;
20
21
22 /**
23 * @author J&ouml;rg Schaible
24 * @author Guilherme Silveira
25 */
26 public class FilePersistenceStrategyTest extends TestCase {
27
28 private final File baseDir = new File("target/tmp");
29
30 protected void setUp() throws Exception {
31 super.setUp();
32 if (baseDir.exists()) {
33 clear(baseDir);
34 }
35 baseDir.mkdirs();
36 }
37
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 clear(baseDir);
41 }
42
43 private void clear(File dir) {
44 File[] files = dir.listFiles();
45 for (int i = 0; i < files.length; i++ ) {
46 if (files[i].isFile()) {
47 boolean deleted = files[i].delete();
48 if (!deleted) {
49 throw new RuntimeException(
50 "Unable to continue testing: unable to remove file "
51 + files[i].getAbsolutePath());
52 }
53 }
54 }
55 dir.delete();
56 }
57
58 public void testConcatenatesXmlExtensionWhileGettingAFilename() {
59 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
60 assertEquals("string@guilherme.xml", strategy.getName("guilherme"));
61 }
62
63 public void testConcatenatesXmlExtensionWhileExtractingAKey() {
64 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
65 assertEquals("guilherme", strategy.extractKey("string@guilherme.xml"));
66 }
67
68 public void testEscapesNonAcceptableCharacterWhileExtractingAKey() {
69 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
70 assertEquals("../guilherme", strategy.extractKey("string@..%2Fguilherme.xml"));
71 }
72
73 public void testEscapesNonAcceptableCharacterWhileGettingAFilename() {
74 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
75 assertEquals("string@..%2Fguilherme.xml", strategy.getName("../guilherme"));
76 }
77
78 public void testEscapesUTF8NonAcceptableCharacterWhileGettingAFilename() {
79 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
80 assertEquals("string@\u5377guilherme.xml", strategy.getName("\u5377guilherme"));
81 }
82
83 public void testEscapesUTF8NonAcceptableCharacterWhileExtractingAKey() {
84 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
85 assertEquals("\u5377guilherme", strategy.extractKey("string@\u5377guilherme.xml"));
86 }
87
88 public void testEscapesPercentageWhileGettingAFilename() {
89 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
90 assertEquals("string@%25guilherme.xml", strategy.getName("%guilherme"));
91 }
92
93 public void testEscapesPercentageWhileExtractingAKey() {
94 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
95 assertEquals("%guilherme", strategy.extractKey("string@%25guilherme.xml"));
96 }
97
98 public void testEscapesNullKeyWhileGettingAFileName() {
99 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
100 assertEquals("null@null.xml", strategy.getName(null));
101 }
102
103 public void testRestoresTypeOfKey() throws MalformedURLException {
104 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
105 assertEquals(new URL("http://xstream.codehaus.org"), strategy
106 .extractKey("url@http%3A%2F%2Fxstream.codehaus.org.xml"));
107 }
108
109 public void testEscapesNullKeyWhileExtractingKey() {
110 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
111 assertNull(strategy.extractKey("null@null.xml"));
112 }
113
114 public void testWritesASingleFile() {
115 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
116 strategy.put("guilherme", "aCuteString");
117 File file = new File(baseDir, "string@guilherme.xml");
118 assertTrue(file.isFile());
119 }
120
121 public void testWritesTwoFiles() {
122 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
123 strategy.put("guilherme", "aCuteString");
124 strategy.put("silveira", "anotherCuteString");
125 assertTrue(new File(baseDir, "string@guilherme.xml").isFile());
126 assertTrue(new File(baseDir, "string@silveira.xml").isFile());
127 }
128
129 public void testRemovesAWrittenFile() {
130 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
131 strategy.put("guilherme", "aCuteString");
132 assertTrue(new File(baseDir, "string@guilherme.xml").isFile());
133 String aCuteString = (String)strategy.remove("guilherme");
134 assertEquals("aCuteString", aCuteString);
135 assertFalse(new File(baseDir, "string@guilherme.xml").exists());
136 }
137
138 public void testRemovesAnInvalidFile() {
139 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
140 String aCuteString = (String)strategy.remove("guilherme");
141 assertNull(aCuteString);
142 }
143
144 public void testHasZeroLength() {
145 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
146 assertEquals(0, strategy.size());
147 }
148
149 public void testHasOneItem() {
150 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
151 strategy.put("guilherme", "aCuteString");
152 assertEquals(1, strategy.size());
153 }
154
155 public void testHasTwoItems() {
156 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
157 strategy.put("guilherme", "aCuteString");
158 strategy.put("silveira", "anotherCuteString");
159 assertEquals(2, strategy.size());
160 }
161
162 public void testIsNotEmpty() {
163 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
164 strategy.put("guilherme", "aCuteString");
165 assertEquals("Map should not be empty", 1, strategy.size());
166 }
167
168 public void testDoesNotContainKey() {
169 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
170 assertFalse(strategy.containsKey("guilherme"));
171 }
172
173 public void testContainsKey() {
174 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
175 strategy.put("guilherme", "aCuteString");
176 assertTrue(strategy.containsKey("guilherme"));
177 }
178
179 public void testGetsAFile() {
180 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
181 strategy.put("guilherme", "aCuteString");
182 assertTrue(new File(baseDir, "string@guilherme.xml").isFile());
183 String aCuteString = (String)strategy.get("guilherme");
184 assertEquals("aCuteString", aCuteString);
185 }
186
187 public void testGetsAnInvalidFile() {
188 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
189 String aCuteString = (String)strategy.get("guilherme");
190 assertNull(aCuteString);
191 }
192
193 public void testRewritesASingleFile() {
194 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
195 strategy.put("guilherme", "aCuteString");
196 File file = new File(baseDir, "string@guilherme.xml");
197 assertTrue(file.isFile());
198 strategy.put("guilherme", "anotherCuteString");
199 assertEquals("anotherCuteString", strategy.get("guilherme"));
200 }
201
202 public void testIsEmpty() {
203 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
204 assertEquals("Map should be empty", 0, strategy.size());
205 }
206
207 public void testContainsAllItems() {
208 Map original = new HashMap();
209 original.put("guilherme", "aCuteString");
210 original.put("silveira", "anotherCuteString");
211 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
212 strategy.put("guilherme", "aCuteString");
213 strategy.put("silveira", "anotherCuteString");
214 for (Iterator iter = original.keySet().iterator(); iter.hasNext();) {
215 assertTrue(strategy.containsKey(iter.next()));
216 }
217 }
218
219 public void testIteratesOverEntryAndChecksItsKeyWithAnotherInstance() {
220 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
221 strategy.put("guilherme", "aCuteString");
222 strategy.put("silveira", "anotherCuteString");
223 FilePersistenceStrategy built = new FilePersistenceStrategy(baseDir);
224 for (Iterator iter = strategy.iterator(); iter.hasNext();) {
225 Map.Entry entry = (Map.Entry)iter.next();
226 assertTrue(built.containsKey(entry.getKey()));
227 }
228 }
229
230 public void testRemovesAnItemThroughIteration() {
231 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
232 strategy.put("guilherme", "aCuteString");
233 strategy.put("silveira", "anotherCuteString");
234 for (Iterator iter = strategy.iterator(); iter.hasNext();) {
235 Map.Entry entry = (Map.Entry)iter.next();
236 if (entry.getKey().equals("guilherme")) {
237 iter.remove();
238 }
239 }
240 assertFalse(strategy.containsKey("guilherme"));
241 }
242
243 public void testRewritesAFile() {
244 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
245 strategy.put("guilherme", "aCuteString");
246 strategy.put("guilherme", "anotherCuteString");
247 assertEquals("anotherCuteString", strategy.get("guilherme"));
248 }
249
250 public void testPutReturnsTheOldValueWhenRewritingAFile() {
251 FilePersistenceStrategy strategy = new FilePersistenceStrategy(baseDir);
252 strategy.put("guilherme", "aCuteString");
253 assertEquals("aCuteString", strategy.put("guilherme", "anotherCuteString"));
254 }
255
256 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008, 2009 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 17. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.io.File;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.Map;
17
18 import junit.framework.TestCase;
19
20
21 /**
22 * @author Guilherme Silveira
23 */
24 public class FileStreamStrategyTest extends TestCase {
25
26 private final File baseDir = new File("target/tmp");
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 if (baseDir.exists()) {
31 clear(baseDir);
32 }
33 baseDir.mkdirs();
34 }
35
36 protected void tearDown() throws Exception {
37 super.tearDown();
38 clear(baseDir);
39 }
40
41 private void clear(File dir) {
42 File[] files = dir.listFiles();
43 for (int i = 0; i < files.length; i++ ) {
44 if (files[i].isFile()) {
45 boolean deleted = files[i].delete();
46 if (!deleted) {
47 throw new RuntimeException(
48 "Unable to continue testing: unable to remove file "
49 + files[i].getAbsolutePath());
50 }
51 }
52 }
53 dir.delete();
54 }
55
56 public void testConcatenatesXmlExtensionWhileGettingAFilename() {
57 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
58 assertEquals("guilherme.xml", strategy.getName("guilherme"));
59 }
60
61 public void testConcatenatesXmlExtensionWhileExtractingAKey() {
62 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
63 assertEquals("guilherme", strategy.extractKey("guilherme.xml"));
64 }
65
66 public void testEscapesNonAcceptableCharacterWhileExtractingAKey() {
67 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
68 assertEquals("../guilherme", strategy.extractKey("_2e__2e__2f_guilherme.xml"));
69 }
70
71 public void testEscapesNonAcceptableCharacterWhileGettingAFilename() {
72 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
73 assertEquals("_2e__2e__2f_guilherme.xml", strategy.getName("../guilherme"));
74 }
75
76 public void testEscapesUTF8NonAcceptableCharacterWhileGettingAFilename() {
77 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
78 assertEquals("_5377_guilherme.xml", strategy.getName("\u5377guilherme"));
79 }
80
81 public void testEscapesUTF8NonAcceptableCharacterWhileExtractingAKey() {
82 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
83 assertEquals("\u5377guilherme", strategy.extractKey("_5377_guilherme.xml"));
84 }
85
86 public void testEscapesUnderlineWhileGettingAFilename() {
87 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
88 assertEquals("__guilherme.xml", strategy.getName("_guilherme"));
89 }
90
91 public void testEscapesUnderlineWhileExtractingAKey() {
92 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
93 assertEquals("_guilherme", strategy.extractKey("__guilherme.xml"));
94 }
95
96 public void testEscapesNullKeyWhileGettingAFileName() {
97 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
98 assertEquals("_0_.xml", strategy.getName(null));
99 }
100
101 public void testEscapesNullKeyWhileExtractingKey() {
102 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
103 assertNull(strategy.extractKey("_0_.xml"));
104 }
105
106 public void testWritesASingleFile() {
107 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
108 strategy.put("guilherme", "aCuteString");
109 File file = new File(baseDir, "guilherme.xml");
110 assertTrue(file.exists());
111 }
112
113 public void testWritesTwoFiles() {
114 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
115 strategy.put("guilherme", "aCuteString");
116 strategy.put("silveira", "anotherCuteString");
117 assertTrue(new File(baseDir, "guilherme.xml").exists());
118 assertTrue(new File(baseDir, "silveira.xml").exists());
119 }
120
121 public void testRemovesAWrittenFile() {
122 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
123 strategy.put("guilherme", "aCuteString");
124 assertTrue(new File(baseDir, "guilherme.xml").exists());
125 String aCuteString = (String)strategy.remove("guilherme");
126 assertEquals("aCuteString", aCuteString);
127 assertFalse(new File(baseDir, "guilherme.xml").exists());
128 }
129
130 public void testRemovesAnInvalidFile() {
131 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
132 String aCuteString = (String)strategy.remove("guilherme");
133 assertNull(aCuteString);
134 }
135
136 public void testHasZeroLength() {
137 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
138 assertEquals(0, strategy.size());
139 }
140
141 public void testHasOneItem() {
142 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
143 strategy.put("guilherme", "aCuteString");
144 assertEquals(1, strategy.size());
145 }
146
147 public void testHasTwoItems() {
148 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
149 strategy.put("guilherme", "aCuteString");
150 strategy.put("silveira", "anotherCuteString");
151 assertEquals(2, strategy.size());
152 }
153
154 public void testIsNotEmpty() {
155 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
156 strategy.put("guilherme", "aCuteString");
157 assertEquals("Map should not be empty", 1, strategy.size());
158 }
159
160 public void testDoesNotContainKey() {
161 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
162 assertFalse(strategy.containsKey("guilherme"));
163 }
164
165 public void testContainsKey() {
166 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
167 strategy.put("guilherme", "aCuteString");
168 assertTrue(strategy.containsKey("guilherme"));
169 }
170
171 public void testGetsAFile() {
172 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
173 strategy.put("guilherme", "aCuteString");
174 assertTrue(new File(baseDir, "guilherme.xml").exists());
175 String aCuteString = (String)strategy.get("guilherme");
176 assertEquals("aCuteString", aCuteString);
177 }
178
179 public void testGetsAnInvalidFile() {
180 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
181 String aCuteString = (String)strategy.get("guilherme");
182 assertNull(aCuteString);
183 }
184
185 public void testRewritesASingleFile() {
186 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
187 strategy.put("guilherme", "aCuteString");
188 File file = new File(baseDir, "guilherme.xml");
189 assertTrue(file.exists());
190 strategy.put("guilherme", "anotherCuteString");
191 assertEquals("anotherCuteString", strategy.get("guilherme"));
192 }
193
194 public void testIsEmpty() {
195 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
196 assertEquals("Map should be empty", 0, strategy.size());
197 }
198
199 public void testContainsAllItems() {
200 Map original = new HashMap();
201 original.put("guilherme", "aCuteString");
202 original.put("silveira", "anotherCuteString");
203 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
204 strategy.put("guilherme", "aCuteString");
205 strategy.put("silveira", "anotherCuteString");
206 for (Iterator iter = original.keySet().iterator(); iter.hasNext();) {
207 assertTrue(strategy.containsKey(iter.next()));
208 }
209 }
210
211 // actually an acceptance test?
212 public void testIteratesOverEntryAndChecksItsKeyWithAnotherInstance() {
213 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
214 strategy.put("guilherme", "aCuteString");
215 strategy.put("silveira", "anotherCuteString");
216 FileStreamStrategy built = new FileStreamStrategy(baseDir);
217 for (Iterator iter = strategy.iterator(); iter.hasNext();) {
218 Map.Entry entry = (Map.Entry)iter.next();
219 assertTrue(built.containsKey(entry.getKey()));
220 }
221 }
222
223 public void testRemovesAnItemThroughIteration() {
224 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
225 strategy.put("guilherme", "aCuteString");
226 strategy.put("silveira", "anotherCuteString");
227 for (Iterator iter = strategy.iterator(); iter.hasNext();) {
228 Map.Entry entry = (Map.Entry)iter.next();
229 if (entry.getKey().equals("guilherme")) {
230 iter.remove();
231 }
232 }
233 assertFalse(strategy.containsKey("guilherme"));
234 }
235
236 public void testRewritesAFile() {
237 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
238 strategy.put("guilherme", "aCuteString");
239 strategy.put("guilherme", "anotherCuteString");
240 assertEquals("anotherCuteString", strategy.get("guilherme"));
241 }
242
243 public void testPutReturnsTheOldValueWhenRewritingAFile() {
244 FileStreamStrategy strategy = new FileStreamStrategy(baseDir);
245 strategy.put("guilherme", "aCuteString");
246 assertEquals("aCuteString", strategy.put("guilherme", "anotherCuteString"));
247 }
248
249 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008, 2009 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 06. July 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Set;
20
21 import junit.framework.TestCase;
22
23 public class XmlArrayListTest extends TestCase {
24 private MockedStrategy strategy;
25
26 public void setUp() throws Exception {
27 super.setUp();
28 strategy = new MockedStrategy();
29 }
30
31 public void testWritesASingleObject() {
32 XmlArrayList xmlList = new XmlArrayList(this.strategy);
33 xmlList.add("guilherme");
34 assertTrue(strategy.map.containsValue("guilherme"));
35 }
36
37 public void testWritesASingleObjectInANegativePosition() {
38 XmlArrayList xmlList = new XmlArrayList(this.strategy);
39 try {
40 xmlList.add(-1, "guilherme");
41 fail();
42 } catch (IndexOutOfBoundsException ex) {
43 // ok
44 }
45 }
46
47 public void testWritesASingleObjectInFirstPosition() {
48 XmlArrayList xmlList = new XmlArrayList(this.strategy);
49 xmlList.add("guilherme");
50 assertTrue(strategy.map.containsKey(new Integer(0)));
51 }
52
53 public void testWritesTwoObjects() {
54 XmlArrayList xmlList = new XmlArrayList(this.strategy);
55 xmlList.add("guilherme");
56 xmlList.add("silveira");
57 assertTrue(strategy.map.containsValue("guilherme"));
58 assertTrue(strategy.map.containsValue("silveira"));
59 assertTrue(strategy.map.containsKey(new Integer(0)));
60 assertTrue(strategy.map.containsKey(new Integer(1)));
61 }
62
63 public void testWritesTwoObjectsGuaranteesItsEnumerationOrder() {
64 XmlArrayList xmlList = new XmlArrayList(this.strategy);
65 xmlList.add("guilherme");
66 xmlList.add("silveira");
67 assertEquals("guilherme", strategy.map.get(new Integer(0)));
68 assertEquals("silveira", strategy.map.get(new Integer(1)));
69 }
70
71 public void testWritesASecondObjectInAPositionHigherThanTheListsSize() {
72 XmlArrayList xmlList = new XmlArrayList(this.strategy);
73 try {
74 xmlList.add("silveira");
75 xmlList.add(3, "guilherme");
76 fail();
77 } catch (IndexOutOfBoundsException ex) {
78 // ok
79 }
80 }
81
82 public void testRemovesAWrittenObject() {
83 XmlArrayList xmlList = new XmlArrayList(this.strategy);
84 xmlList.add("guilherme");
85 assertTrue(xmlList.remove("guilherme"));
86 assertFalse(strategy.map.containsValue("guilherme"));
87 }
88
89 public void testRemovesAWrittenObjectImplyingInAChangeInTheList() {
90 XmlArrayList xmlList = new XmlArrayList(this.strategy);
91 xmlList.add("guilherme");
92 boolean changed = xmlList.remove("guilherme");
93 assertTrue(changed);
94 }
95
96 public void testRemovesAnInvalidObjectWithoutAffectingTheList() {
97 XmlArrayList xmlList = new XmlArrayList(this.strategy);
98 boolean removed = xmlList.remove("guilherme");
99 assertFalse(removed);
100 }
101
102 public void testHasZeroLengthWhenInstantiated() {
103 XmlArrayList xmlList = new XmlArrayList(this.strategy);
104 assertEquals(0, xmlList.size());
105 }
106
107 public void testHasOneItem() {
108 XmlArrayList xmlList = new XmlArrayList(this.strategy);
109 xmlList.add("guilherme");
110 assertEquals(1, xmlList.size());
111 }
112
113 public void testHasTwoItems() {
114 XmlArrayList xmlList = new XmlArrayList(this.strategy);
115 xmlList.add("guilherme");
116 xmlList.add("silveira");
117 assertEquals(2, xmlList.size());
118 }
119
120 public void testIsNotEmpty() {
121 XmlArrayList xmlList = new XmlArrayList(this.strategy);
122 xmlList.add("guilherme");
123 assertFalse(xmlList.isEmpty());
124 }
125
126 public void testDoesNotContainKey() {
127 XmlArrayList xmlList = new XmlArrayList(this.strategy);
128 assertFalse(xmlList.contains("guilherme"));
129 }
130
131 public void testContainsKey() {
132 XmlArrayList xmlList = new XmlArrayList(this.strategy);
133 xmlList.add("guilherme");
134 assertTrue(xmlList.contains("guilherme"));
135 }
136
137 public void testGetsAnObject() {
138 XmlArrayList xmlList = new XmlArrayList(this.strategy);
139 xmlList.add("guilherme");
140 Object onlyValue = xmlList.iterator().next();
141 assertEquals("guilherme", onlyValue);
142 }
143
144 public void testGetsTheFirstObject() {
145 XmlArrayList xmlList = new XmlArrayList(this.strategy);
146 xmlList.add("guilherme");
147 assertEquals("guilherme", xmlList.get(0));
148 }
149
150 public void testGetsTheSecondObject() {
151 XmlArrayList xmlList = new XmlArrayList(this.strategy);
152 xmlList.add("guilherme");
153 xmlList.add("silveira");
154 assertEquals("silveira", xmlList.get(1));
155 }
156
157 public void testInsertsAnObjectInTheMiddleOfTheList() {
158 XmlArrayList xmlList = new XmlArrayList(this.strategy);
159 xmlList.add("guilherme");
160 xmlList.add("silveira");
161 xmlList.add(1, "de azevedo");
162 assertEquals("guilherme", xmlList.get(0));
163 assertEquals("de azevedo", xmlList.get(1));
164 assertEquals("silveira", xmlList.get(2));
165 }
166
167 public void testIteratingGuaranteesItsEnumeration() {
168 XmlArrayList xmlList = new XmlArrayList(this.strategy);
169 xmlList.add("guilherme");
170 xmlList.add("silveira");
171 Iterator it = xmlList.iterator();
172 assertEquals("guilherme", it.next());
173 assertEquals("silveira", it.next());
174 }
175
176 public void testIsEmpty() {
177 XmlArrayList xmlList = new XmlArrayList(this.strategy);
178 assertTrue(xmlList.isEmpty());
179 }
180
181 public void testClearsItsObjects() {
182 XmlArrayList xmlList = new XmlArrayList(this.strategy);
183 xmlList.add("guilherme");
184 xmlList.add("silveira");
185 xmlList.clear();
186 assertEquals(0, xmlList.size());
187 }
188
189 public void testPutsAllAddsTwoItems() {
190 Set original = new HashSet();
191 original.add("guilherme");
192 original.add("silveira");
193 XmlArrayList xmlList = new XmlArrayList(this.strategy);
194 xmlList.addAll(original);
195 assertEquals(2, xmlList.size());
196 }
197
198 public void testContainsASpecificValue() {
199 XmlArrayList xmlList = new XmlArrayList(this.strategy);
200 xmlList.add("guilherme");
201 assertTrue(xmlList.contains("guilherme"));
202 }
203
204 public void testDoesNotContainASpecificValue() {
205 XmlArrayList xmlList = new XmlArrayList(this.strategy);
206 assertFalse(xmlList.contains("zzzz"));
207 }
208
209 public void testEntrySetContainsAllItems() {
210 Set original = new HashSet();
211 original.add("guilherme");
212 original.add("silveira");
213 XmlArrayList xmlList = new XmlArrayList(this.strategy);
214 xmlList.add("guilherme");
215 xmlList.add("silveira");
216 assertTrue(xmlList.containsAll(original));
217 }
218
219 // actually an acceptance test?
220 public void testIteratesOverEntryAndChecksWithAnotherInstance() {
221 XmlArrayList xmlList = new XmlArrayList(this.strategy);
222 xmlList.add("guilherme");
223 xmlList.add("silveira");
224 XmlArrayList built = new XmlArrayList(this.strategy);
225 for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
226 Object entry = iter.next();
227 assertTrue(built.contains(entry));
228 }
229 }
230
231 public void testIteratesOverEntrySetContainingTwoItems() {
232 XmlArrayList xmlList = new XmlArrayList(this.strategy);
233 xmlList.add("guilherme");
234 xmlList.add("silveira");
235 List built = new ArrayList();
236 for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
237 Object entry = iter.next();
238 built.add(entry);
239 }
240 assertEquals(xmlList, built);
241 }
242
243 public void testRemovesAnItemThroughIteration() {
244 XmlArrayList xmlList = new XmlArrayList(this.strategy);
245 xmlList.add("guilherme");
246 xmlList.add("silveira");
247 for (Iterator iter = xmlList.iterator(); iter.hasNext();) {
248 Object entry = iter.next();
249 if (entry.equals("guilherme")) {
250 iter.remove();
251 }
252 }
253 assertFalse(xmlList.contains("guilherme"));
254 }
255
256 private static class MockedStrategy implements PersistenceStrategy {
257
258 private Map map = new HashMap();
259
260 public Iterator iterator() {
261 return map.entrySet().iterator();
262 }
263
264 public int size() {
265 return map.size();
266 }
267
268 public Object get(Object key) {
269 return map.get(key);
270 }
271
272 public Object put(Object key, Object value) {
273 return map.put(key, value);
274 }
275
276 public Object remove(Object key) {
277 return map.remove(key);
278 }
279
280 }
281
282 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008 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 13. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.HashMap;
14 import java.util.Iterator;
15 import java.util.Map;
16 import java.util.Set;
17
18 import junit.framework.TestCase;
19
20 public class XmlMapTest extends TestCase {
21
22 private MockedStrategy strategy;
23
24 public void setUp() throws Exception {
25 super.setUp();
26 strategy = new MockedStrategy();
27 }
28
29 public void testWritesASingleObject() {
30 XmlMap map = new XmlMap(this.strategy);
31 map.put("guilherme", "aCuteString");
32 assertTrue(strategy.map.containsKey("guilherme"));
33 }
34
35 public void testWritesTwoObjects() {
36 XmlMap map = new XmlMap(this.strategy);
37 map.put("guilherme", "aCuteString");
38 map.put("silveira", "anotherCuteString");
39 assertTrue(strategy.map.containsKey("guilherme"));
40 assertTrue(strategy.map.containsKey("silveira"));
41 }
42
43 public void testRemovesAWrittenObject() {
44 XmlMap map = new XmlMap(this.strategy);
45 map.put("guilherme", "aCuteString");
46 assertTrue(strategy.map.containsKey("guilherme"));
47 String aCuteString = (String) map.remove("guilherme");
48 assertEquals("aCuteString", aCuteString);
49 assertFalse(strategy.map.containsKey("guilherme"));
50 }
51
52 public void testRemovesAnInvalidObject() {
53 XmlMap map = new XmlMap(this.strategy);
54 String aCuteString = (String) map.remove("guilherme");
55 assertNull(aCuteString);
56 }
57
58 public void testHasZeroLength() {
59 XmlMap map = new XmlMap(this.strategy);
60 assertEquals(0, map.size());
61 }
62
63 public void testHasOneItem() {
64 XmlMap map = new XmlMap(this.strategy);
65 map.put("guilherme", "aCuteString");
66 assertEquals(1, map.size());
67 }
68
69 public void testHasTwoItems() {
70 XmlMap map = new XmlMap(this.strategy);
71 map.put("guilherme", "aCuteString");
72 map.put("silveira", "anotherCuteString");
73 assertEquals(2, map.size());
74 }
75
76 public void testIsNotEmpty() {
77 XmlMap map = new XmlMap(this.strategy);
78 map.put("guilherme", "aCuteString");
79 assertFalse("Map should not be empty", map.isEmpty());
80 }
81
82 public void testDoesNotContainKey() {
83 XmlMap map = new XmlMap(this.strategy);
84 assertFalse(map.containsKey("guilherme"));
85 }
86
87 public void testContainsKey() {
88 XmlMap map = new XmlMap(this.strategy);
89 map.put("guilherme", "aCuteString");
90 assertTrue(map.containsKey("guilherme"));
91 }
92
93 public void testGetsAnObject() {
94 XmlMap map = new XmlMap(this.strategy);
95 this.strategy.map.put("guilherme", "aCuteString");
96 String aCuteString = (String) map.get("guilherme");
97 assertEquals("aCuteString", aCuteString);
98 }
99
100 public void testGetsAnInvalidObject() {
101 XmlMap map = new XmlMap(this.strategy);
102 String aCuteString = (String) map.get("guilherme");
103 assertNull(aCuteString);
104 }
105
106 public void testRewritesASingleObject() {
107 XmlMap map = new XmlMap(this.strategy);
108 map.put("guilherme", "aCuteString");
109 assertEquals("aCuteString", map.get("guilherme"));
110 map.put("guilherme", "anotherCuteString");
111 assertEquals("anotherCuteString", map.get("guilherme"));
112 }
113
114 public void testIsEmpty() {
115 XmlMap map = new XmlMap(this.strategy);
116 assertTrue("Map should be empty", map.isEmpty());
117 }
118
119 public void testClearsItsObjects() {
120 XmlMap map = new XmlMap(this.strategy);
121 map.put("guilherme", "aCuteString");
122 map.put("silveira", "anotherCuteString");
123 map.clear();
124 assertEquals(0, map.size());
125 }
126
127 public void testPutsAllAddsTwoItems() {
128 Map original = new HashMap();
129 original.put("guilherme", "aCuteString");
130 original.put("silveira", "anotherCuteString");
131 XmlMap map = new XmlMap(this.strategy);
132 map.putAll(original);
133 assertEquals(2, map.size());
134 }
135
136 public void testContainsASpecificValue() {
137 XmlMap map = new XmlMap(this.strategy);
138 String value = "aCuteString";
139 map.put("guilherme", value);
140 assertTrue(map.containsValue(value));
141 }
142
143 public void testDoesNotContainASpecificValue() {
144 XmlMap map = new XmlMap(this.strategy);
145 assertFalse(map.containsValue("zzzz"));
146 }
147
148 public void testEntrySetContainsAllItems() {
149 Map original = new HashMap();
150 original.put("guilherme", "aCuteString");
151 original.put("silveira", "anotherCuteString");
152 Set originalSet = original.entrySet();
153 XmlMap map = new XmlMap(this.strategy);
154 map.put("guilherme", "aCuteString");
155 map.put("silveira", "anotherCuteString");
156 Set set = map.entrySet();
157 assertTrue(set.containsAll(originalSet));
158 }
159
160 // actually an acceptance test?
161 public void testIteratesOverEntryAndChecksItsKeyWithAnotherInstance() {
162 XmlMap map = new XmlMap(this.strategy);
163 map.put("guilherme", "aCuteString");
164 map.put("silveira", "anotherCuteString");
165 XmlMap built = new XmlMap(this.strategy);
166 for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
167 Map.Entry entry = (Map.Entry) iter.next();
168 assertTrue(built.containsKey(entry.getKey()));
169 }
170 }
171
172 // actually an acceptance test?
173 public void testIteratesOverEntryAndChecksItsValueWithAnotherInstance() {
174 XmlMap map = new XmlMap(this.strategy);
175 map.put("guilherme", "aCuteString");
176 map.put("silveira", "anotherCuteString");
177 XmlMap built = new XmlMap(this.strategy);
178 for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
179 Map.Entry entry = (Map.Entry) iter.next();
180 assertTrue(built.containsValue(entry.getValue()));
181 }
182 }
183
184 public void testIteratesOverEntrySetContainingTwoItems() {
185 XmlMap map = new XmlMap(this.strategy);
186 map.put("guilherme", "aCuteString");
187 map.put("silveira", "anotherCuteString");
188 Map built = new HashMap();
189 for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
190 Map.Entry entry = (Map.Entry) iter.next();
191 built.put(entry.getKey(), entry.getValue());
192 }
193 assertEquals(map, built);
194 }
195
196 public void testRemovesAnItemThroughIteration() {
197 XmlMap map = new XmlMap(this.strategy);
198 map.put("guilherme", "aCuteString");
199 map.put("silveira", "anotherCuteString");
200 for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
201 Map.Entry entry = (Map.Entry) iter.next();
202 if (entry.getKey().equals("guilherme")) {
203 iter.remove();
204 }
205 }
206 assertFalse(map.containsKey("guilherme"));
207 }
208
209 public void testRewritesAObject() {
210 XmlMap map = new XmlMap(this.strategy);
211 map.put("guilherme", "aCuteString");
212 map.put("guilherme", "anotherCuteString");
213 assertEquals("anotherCuteString", map.get("guilherme"));
214 }
215
216 public void testPutReturnsTheOldValueWhenRewritingAObject() {
217 XmlMap map = new XmlMap(this.strategy);
218 map.put("guilherme", "aCuteString");
219 assertEquals("aCuteString", map.put("guilherme", "anotherCuteString"));
220 }
221
222 private static class MockedStrategy implements PersistenceStrategy {
223
224 private Map map = new HashMap();
225
226 public Iterator iterator() {
227 return map.entrySet().iterator();
228 }
229
230 public int size() {
231 return map.size();
232 }
233
234 public Object get(Object key) {
235 return map.get(key);
236 }
237
238 public Object put(Object key, Object value) {
239 return map.put(key, value);
240 }
241
242 public Object remove(Object key) {
243 return map.remove(key);
244 }
245
246 }
247
248 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2007, 2008 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 28. June 2006 by Guilherme Silveira
10 */
11 package com.thoughtworks.xstream.persistence;
12
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.Map;
17 import java.util.Set;
18
19 import junit.framework.TestCase;
20
21 public class XmlSetTest extends TestCase {
22 private MockedStrategy strategy;
23 public void setUp() throws Exception {
24 super.setUp();
25 strategy = new MockedStrategy();
26 }
27
28 public void testWritesASingleObject() {
29 XmlSet set = new XmlSet(this.strategy);
30 set.add("guilherme");
31 assertTrue(strategy.map.containsValue("guilherme"));
32 }
33
34 public void testWritesTwoObjects() {
35 XmlSet set = new XmlSet(this.strategy);
36 set.add("guilherme");
37 set.add("silveira");
38 assertTrue(strategy.map.containsValue("guilherme"));
39 assertTrue(strategy.map.containsValue("silveira"));
40 }
41
42 public void testRemovesAWrittenObject() {
43 XmlSet set = new XmlSet(this.strategy);
44 set.add("guilherme");
45 assertTrue(strategy.map.containsValue("guilherme"));
46 boolean changed = set.remove("guilherme");
47 assertTrue(changed);
48 assertFalse(strategy.map.containsValue("guilherme"));
49 }
50
51 public void testRemovesAnInvalidObject() {
52 XmlSet set = new XmlSet(this.strategy);
53 boolean removed= set.remove("guilherme");
54 assertFalse(removed);
55 }
56
57 public void testHasZeroLength() {
58 XmlSet set = new XmlSet(this.strategy);
59 assertEquals(0, set.size());
60 }
61
62 public void testHasOneItem() {
63 XmlSet set = new XmlSet(this.strategy);
64 set.add("guilherme");
65 assertEquals(1, set.size());
66 }
67
68 public void testHasTwoItems() {
69 XmlSet set = new XmlSet(this.strategy);
70 set.add("guilherme");
71 set.add("silveira");
72 assertEquals(2, set.size());
73 }
74
75 public void testIsNotEmpty() {
76 XmlSet set = new XmlSet(this.strategy);
77 set.add("guilherme");
78 assertFalse("set should not be empty", set.isEmpty());
79 }
80
81 public void testDoesNotContainKey() {
82 XmlSet set = new XmlSet(this.strategy);
83 assertFalse(set.contains("guilherme"));
84 }
85
86 public void testContainsKey() {
87 XmlSet set = new XmlSet(this.strategy);
88 set.add("guilherme");
89 assertTrue(set.contains("guilherme"));
90 }
91
92 public void testGetsAnObject() {
93 XmlSet set = new XmlSet(this.strategy);
94 set.add("guilherme");
95 Object onlyValue = set.iterator().next();
96 assertEquals("guilherme", onlyValue);
97 }
98
99 public void testIsEmpty() {
100 XmlSet set = new XmlSet(this.strategy);
101 assertTrue("set should be empty", set.isEmpty());
102 }
103
104 public void testClearsItsObjects() {
105 XmlSet set = new XmlSet(this.strategy);
106 set.add("guilherme");
107 set.add("silveira");
108 set.clear();
109 assertEquals(0, set.size());
110 }
111
112 public void testPutsAllAddsTwoItems() {
113 Set original = new HashSet();
114 original.add("guilherme");
115 original.add("silveira");
116 XmlSet set = new XmlSet(this.strategy);
117 set.addAll(original);
118 assertEquals(2, set.size());
119 }
120
121 public void testContainsASpecificValue() {
122 XmlSet set = new XmlSet(this.strategy);
123 set.add("guilherme");
124 assertTrue(set.contains("guilherme"));
125 }
126
127 public void testDoesNotContainASpecificValue() {
128 XmlSet set = new XmlSet(this.strategy);
129 assertFalse(set.contains("zzzz"));
130 }
131
132 public void testEntrySetContainsAllItems() {
133 Set original = new HashSet();
134 original.add("guilherme");
135 original.add("silveira");
136 XmlSet set = new XmlSet(this.strategy);
137 set.add("guilherme");
138 set.add("silveira");
139 assertTrue(set.containsAll(original));
140 }
141
142 // actually an acceptance test?
143 public void testIteratesOverEntryAndChecksWithAnotherInstance() {
144 XmlSet set = new XmlSet(this.strategy);
145 set.add("guilherme");
146 set.add("silveira");
147 XmlSet built = new XmlSet(this.strategy);
148 for (Iterator iter = set.iterator(); iter.hasNext();) {
149 Object entry = iter.next();
150 assertTrue(built.contains(entry));
151 }
152 }
153
154 public void testIteratesOverEntrySetContainingTwoItems() {
155 XmlSet set = new XmlSet(this.strategy);
156 set.add("guilherme");
157 set.add("silveira");
158 Set built = new HashSet();
159 for (Iterator iter = set.iterator(); iter.hasNext();) {
160 Object entry = iter.next();
161 built.add(entry);
162 }
163 assertEquals(set, built);
164 }
165
166 public void testRemovesAnItemThroughIteration() {
167 XmlSet set = new XmlSet(this.strategy);
168 set.add("guilherme");
169 set.add("silveira");
170 for (Iterator iter = set.iterator(); iter.hasNext();) {
171 Object entry = iter.next();
172 if (entry.equals("guilherme")) {
173 iter.remove();
174 }
175 }
176 assertFalse(set.contains("guilherme"));
177 }
178
179 private static class MockedStrategy implements PersistenceStrategy {
180
181 private Map map = new HashMap();
182
183 public Iterator iterator() {
184 return map.entrySet().iterator();
185 }
186
187 public int size() {
188 return map.size();
189 }
190
191 public Object get(Object key) {
192 return map.get(key);
193 }
194
195 public Object put(Object key, Object value) {
196 return map.put(key, value);
197 }
198
199 public Object remove(Object key) {
200 return map.remove(key);
201 }
202
203 }
204
205 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 02. February 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.testutil;
12
13 import junit.framework.Assert;
14
15 public class CallLog {
16
17 private StringBuffer expected = new StringBuffer();
18 private StringBuffer actual = new StringBuffer();
19
20 public void expect(String message) {
21 expected.append(message).append('\n');
22 }
23
24 public void actual(String message) {
25 actual.append(message).append('\n');
26 }
27
28 public void verify() {
29 Assert.assertEquals(expected.toString(), actual.toString());
30 reset();
31 }
32
33 public void reset() {
34 expected = new StringBuffer();
35 actual = new StringBuffer();
36 }
37
38 }
0 /*
1 * Copyright (C) 2006, 2007, 2009, 2010 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 14. March 2006 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.testutil;
11
12 import java.io.FilePermission;
13 import java.security.AccessControlContext;
14 import java.security.CodeSource;
15 import java.security.Permission;
16 import java.security.PermissionCollection;
17 import java.security.Permissions;
18 import java.security.ProtectionDomain;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25
26
27 /**
28 * @author J&ouml;rg Schaible
29 */
30 public class DynamicSecurityManager extends SecurityManager {
31
32 private Map permissions = new HashMap();
33 private AccessControlContext acc = null;
34 private List failedPermissions = new ArrayList();
35
36 public void addPermission(final CodeSource codeSource, final Permission permission) {
37 PermissionCollection permissionCollection = (PermissionCollection)permissions
38 .get(codeSource);
39 if (permissionCollection == null) {
40 permissionCollection = new Permissions();
41 permissions.put(codeSource, permissionCollection);
42 }
43 permissionCollection.add(permission);
44 // updateACC();
45 }
46
47 public void setPermissions(
48 final CodeSource codeSource, final PermissionCollection permissionCollection) {
49 if (permissionCollection == null) {
50 if (permissions.remove(codeSource) != null) {
51 // updateACC();
52 }
53 } else {
54 if (permissions.put(codeSource, permissionCollection) != null) {
55 // updateACC();
56 }
57 }
58 }
59
60 private void updateACC() {
61 if (permissions.size() == 0) {
62 acc = null;
63 } else {
64 final ProtectionDomain[] domains = new ProtectionDomain[permissions.size()];
65 int i = 0;
66 for (final Iterator iter = permissions.keySet().iterator(); iter.hasNext();) {
67 final CodeSource codeSource = (CodeSource)iter.next();
68 final PermissionCollection permissionCollection = (PermissionCollection)permissions
69 .get(codeSource);
70 domains[i++] = new ProtectionDomain(codeSource, permissionCollection);
71 }
72 acc = new AccessControlContext(domains);
73 }
74 }
75
76 public void setReadOnly() {
77 updateACC();
78 }
79
80 public void checkPermission(Permission perm) {
81 if (acc != null) {
82 // Ughhh. Eclipse class path leak :-/
83 if (perm instanceof FilePermission && "read".equals(perm.getActions())) {
84 String name = perm.getName();
85 if (name.indexOf("org.eclipse.osgi") > 0
86 && (name.endsWith("javax.xml.parsers.DocumentBuilderFactory")
87 || name.endsWith("javax.xml.datatype.DatatypeFactory"))) {
88 return;
89 }
90 }
91 try {
92 checkPermission(perm, acc);
93 } catch (final SecurityException e) {
94 failedPermissions.add(perm);
95 throw e;
96 }
97 }
98 }
99
100 public List getFailedPermissions() {
101 return Collections.unmodifiableList(failedPermissions);
102 }
103 }
0 /*
1 * Copyright (C) 2005 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. January 2005 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.testutil;
12
13 import java.util.TimeZone;
14
15 public class TimeZoneChanger {
16
17 private static final TimeZone originalTimeZone = TimeZone.getDefault();
18
19 public static void change(String timeZone) {
20 TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
21 }
22
23 public static void reset() {
24 TimeZone.setDefault(originalTimeZone);
25 }
26
27 }
0 <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">
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2009, 2011, 2012, 2013 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 18. October 2006 by Mauro Talevi
11 -->
12 <modelVersion>4.0.0</modelVersion>
13 <parent>
14 <groupId>com.thoughtworks.xstream</groupId>
15 <artifactId>xstream-parent</artifactId>
16 <version>1.4.8</version>
17 </parent>
18 <artifactId>xstream-benchmark</artifactId>
19 <packaging>jar</packaging>
20 <name>XStream Benchmark</name>
21 <description>Benchmark suite of XStream.</description>
22
23 <profiles>
24 <profile>
25 <id>jdk18-ge</id>
26 <activation>
27 <jdk>[1.8,)</jdk>
28 </activation>
29 <build>
30 <plugins>
31 <plugin>
32 <groupId>org.apache.maven.plugins</groupId>
33 <artifactId>maven-javadoc-plugin</artifactId>
34 <configuration>
35 <excludePackageNames>com.thoughtworks.xstream.tools.benchmark.model</excludePackageNames>
36 </configuration>
37 </plugin>
38 </plugins>
39 </build>
40 <reporting>
41 <plugins>
42 <plugin>
43 <groupId>org.apache.maven.plugins</groupId>
44 <artifactId>maven-javadoc-plugin</artifactId>
45 <version>${version.plugin.maven.javadoc}</version>
46 <configuration>
47 <excludePackageNames>com.thoughtworks.xstream.tools.benchmark.model</excludePackageNames>
48 <additionalparam>${javadoc.xdoclint}</additionalparam>
49 <detectJavaApiLink>false</detectJavaApiLink>
50 <source>${version.java.source}</source>
51 <links>
52 <link>${link.javadoc.javase}</link>
53 </links>
54 </configuration>
55 </plugin>
56 </plugins>
57 </reporting>
58 </profile>
59 <profile>
60 <id>jdk15-ge</id>
61 <activation>
62 <jdk>[1.5,)</jdk>
63 </activation>
64 <build>
65 <plugins>
66 <plugin>
67 <groupId>org.apache.maven.plugins</groupId>
68 <artifactId>maven-jar-plugin</artifactId>
69 <configuration>
70 <archive combine.children="append">
71 <manifestFile>${project.build.directory}/OSGi/MANIFEST.MF</manifestFile>
72 </archive>
73 </configuration>
74 </plugin>
75 <plugin>
76 <groupId>org.apache.felix</groupId>
77 <artifactId>maven-bundle-plugin</artifactId>
78 <configuration>
79 <instructions combine.children="append">
80 <Export-Package>!com.thoughtworks.xstream.tools.benchmark.model,com.thoughtworks.xstream.tools.benchmark.*;-noimport:=true</Export-Package>
81 </instructions>
82 </configuration>
83 </plugin>
84 </plugins>
85 </build>
86 </profile>
87 </profiles>
88
89 <build>
90 <plugins>
91 <plugin>
92 <groupId>org.apache.maven.plugins</groupId>
93 <artifactId>maven-source-plugin</artifactId>
94 </plugin>
95 <plugin>
96 <groupId>org.apache.maven.plugins</groupId>
97 <artifactId>maven-surefire-plugin</artifactId>
98 <configuration>
99 <skip>true</skip>
100 </configuration>
101 </plugin>
102 </plugins>
103 </build>
104
105 <dependencies>
106 <dependency>
107 <groupId>com.thoughtworks.xstream</groupId>
108 <artifactId>xstream</artifactId>
109 </dependency>
110 <dependency>
111 <groupId>net.sf.kxml</groupId>
112 <artifactId>kxml2-min</artifactId>
113 <scope>test</scope>
114 </dependency>
115 <dependency>
116 <groupId>commons-lang</groupId>
117 <artifactId>commons-lang</artifactId>
118 <scope>test</scope>
119 </dependency>
120 <dependency>
121 <groupId>commons-cli</groupId>
122 <artifactId>commons-cli</artifactId>
123 <scope>test</scope>
124 </dependency>
125 <dependency>
126 <groupId>commons-io</groupId>
127 <artifactId>commons-io</artifactId>
128 <scope>test</scope>
129 </dependency>
130 <dependency>
131 <groupId>junit</groupId>
132 <artifactId>junit</artifactId>
133 </dependency>
134 </dependencies>
135 </project>
0 <html>
1 <head>
2 <title>XmlFriendlyReplacer Benchmark</title>
3 <style type="text/css">
4 body, h1, h2, h3, td { font-family: arial; }
5 h1 { text-align: center; }
6 table, h3 { margin-left: 40px; }
7 table, td, th { border: 1px solid #999; border-collapse: collapse; font-size: smaller; }
8 .success { color: #090; }
9 .fail { color: #900; }
10 </style>
11 </head>
12 <body>
13 <h1>XmlFriendlyReplacer Benchmark</h1>
14 <h2>Size of serialized data</h2>
15 <h3>Field Target</h3>
16 <table>
17 <tr>
18 <th>Product</th>
19 <th>bytes</th>
20 </tr>
21 <tr>
22 <td></td>
23 <td class="success">353514.0</td>
24 <td style="width: 400px;">
25 <div style="height: 100%; width: 100%; background-color: blue;"></div>
26 </td>
27 </tr>
28 </table>
29 <h3>Field with underscores Target</h3>
30 <table>
31 <tr>
32 <th>Product</th>
33 <th>bytes</th>
34 </tr>
35 <tr>
36 <td></td>
37 <td class="success">353914.0</td>
38 <td style="width: 400px;">
39 <div style="height: 100%; width: 100%; background-color: blue;"></div>
40 </td>
41 </tr>
42 </table>
43 <h3>Field with dollars Target</h3>
44 <table>
45 <tr>
46 <th>Product</th>
47 <th>bytes</th>
48 </tr>
49 <tr>
50 <td></td>
51 <td class="success">353914.0</td>
52 <td style="width: 400px;">
53 <div style="height: 100%; width: 100%; background-color: blue;"></div>
54 </td>
55 </tr>
56 </table>
57 <h2>Character count for &apos;$&apos;</h2>
58 <h3>Field Target</h3>
59 <table>
60 <tr>
61 <th>Product</th>
62 <th>characters</th>
63 </tr>
64 <tr>
65 <td></td>
66 <td class="success">0.0</td>
67 <td style="width: 400px;">
68 <div style="height: 100%; width: 0%; background-color: blue;"></div>
69 </td>
70 </tr>
71 </table>
72 <h3>Field with underscores Target</h3>
73 <table>
74 <tr>
75 <th>Product</th>
76 <th>characters</th>
77 </tr>
78 <tr>
79 <td></td>
80 <td class="success">0.0</td>
81 <td style="width: 400px;">
82 <div style="height: 100%; width: 0%; background-color: blue;"></div>
83 </td>
84 </tr>
85 </table>
86 <h3>Field with dollars Target</h3>
87 <table>
88 <tr>
89 <th>Product</th>
90 <th>characters</th>
91 </tr>
92 <tr>
93 <td></td>
94 <td class="success">100200.0</td>
95 <td style="width: 400px;">
96 <div style="height: 100%; width: 100%; background-color: blue;"></div>
97 </td>
98 </tr>
99 </table>
100 <h2>Character count for &apos;_&apos;</h2>
101 <h3>Field Target</h3>
102 <table>
103 <tr>
104 <th>Product</th>
105 <th>characters</th>
106 </tr>
107 <tr>
108 <td></td>
109 <td class="success">0.0</td>
110 <td style="width: 400px;">
111 <div style="height: 100%; width: 0%; background-color: blue;"></div>
112 </td>
113 </tr>
114 </table>
115 <h3>Field with underscores Target</h3>
116 <table>
117 <tr>
118 <th>Product</th>
119 <th>characters</th>
120 </tr>
121 <tr>
122 <td></td>
123 <td class="success">100200.0</td>
124 <td style="width: 400px;">
125 <div style="height: 100%; width: 100%; background-color: blue;"></div>
126 </td>
127 </tr>
128 </table>
129 <h3>Field with dollars Target</h3>
130 <table>
131 <tr>
132 <th>Product</th>
133 <th>characters</th>
134 </tr>
135 <tr>
136 <td></td>
137 <td class="success">0.0</td>
138 <td style="width: 400px;">
139 <div style="height: 100%; width: 0%; background-color: blue;"></div>
140 </td>
141 </tr>
142 </table>
143 <h2>Serialization speed (50 iterations)</h2>
144 <h3>Field Target</h3>
145 <table>
146 <tr>
147 <th>Product</th>
148 <th>ms</th>
149 </tr>
150 <tr>
151 <td>XStream 1.2.2 Replacer</td>
152 <td class="success">7788.0</td>
153 <td style="width: 400px;">
154 <div style="height: 100%; width: 85%; background-color: blue;"></div>
155 </td>
156 </tr>
157 <tr>
158 <td>Combined Lookup Appending</td>
159 <td class="success">9173.0</td>
160 <td style="width: 400px;">
161 <div style="height: 100%; width: 100%; background-color: blue;"></div>
162 </td>
163 </tr>
164 <tr>
165 <td>Combined Lookup Appending (16)</td>
166 <td class="success">7628.0</td>
167 <td style="width: 400px;">
168 <div style="height: 100%; width: 83%; background-color: blue;"></div>
169 </td>
170 </tr>
171 <tr>
172 <td>Combined Lookup Replacer</td>
173 <td class="success">7806.0</td>
174 <td style="width: 400px;">
175 <div style="height: 100%; width: 85%; background-color: blue;"></div>
176 </td>
177 </tr>
178 <tr>
179 <td>Combined Lookup Replacer (16)</td>
180 <td class="success">7817.0</td>
181 <td style="width: 400px;">
182 <div style="height: 100%; width: 85%; background-color: blue;"></div>
183 </td>
184 </tr>
185 <tr>
186 <td>Iterative Appender</td>
187 <td class="success">7634.0</td>
188 <td style="width: 400px;">
189 <div style="height: 100%; width: 83%; background-color: blue;"></div>
190 </td>
191 </tr>
192 <tr>
193 <td>Iterative Appender (16)</td>
194 <td class="success">7785.0</td>
195 <td style="width: 400px;">
196 <div style="height: 100%; width: 85%; background-color: blue;"></div>
197 </td>
198 </tr>
199 <tr>
200 <td>Iterative Replacer</td>
201 <td class="success">7787.0</td>
202 <td style="width: 400px;">
203 <div style="height: 100%; width: 85%; background-color: blue;"></div>
204 </td>
205 </tr>
206 <tr>
207 <td>Iterative Replacer (16)</td>
208 <td class="success">7937.0</td>
209 <td style="width: 400px;">
210 <div style="height: 100%; width: 87%; background-color: blue;"></div>
211 </td>
212 </tr>
213 <tr>
214 <td>Separate Lookup Replacer</td>
215 <td class="success">7779.0</td>
216 <td style="width: 400px;">
217 <div style="height: 100%; width: 85%; background-color: blue;"></div>
218 </td>
219 </tr>
220 <tr>
221 <td>Separate Lookup Replacer (16)</td>
222 <td class="success">7765.0</td>
223 <td style="width: 400px;">
224 <div style="height: 100%; width: 85%; background-color: blue;"></div>
225 </td>
226 </tr>
227 </table>
228 <h3>Field with underscores Target</h3>
229 <table>
230 <tr>
231 <th>Product</th>
232 <th>ms</th>
233 </tr>
234 <tr>
235 <td>XStream 1.2.2 Replacer</td>
236 <td class="success">7971.0</td>
237 <td style="width: 400px;">
238 <div style="height: 100%; width: 84%; background-color: blue;"></div>
239 </td>
240 </tr>
241 <tr>
242 <td>Combined Lookup Appending</td>
243 <td class="success">8416.0</td>
244 <td style="width: 400px;">
245 <div style="height: 100%; width: 89%; background-color: blue;"></div>
246 </td>
247 </tr>
248 <tr>
249 <td>Combined Lookup Appending (16)</td>
250 <td class="success">8197.0</td>
251 <td style="width: 400px;">
252 <div style="height: 100%; width: 86%; background-color: blue;"></div>
253 </td>
254 </tr>
255 <tr>
256 <td>Combined Lookup Replacer</td>
257 <td class="success">8477.0</td>
258 <td style="width: 400px;">
259 <div style="height: 100%; width: 89%; background-color: blue;"></div>
260 </td>
261 </tr>
262 <tr>
263 <td>Combined Lookup Replacer (16)</td>
264 <td class="success">8673.0</td>
265 <td style="width: 400px;">
266 <div style="height: 100%; width: 91%; background-color: blue;"></div>
267 </td>
268 </tr>
269 <tr>
270 <td>Iterative Appender</td>
271 <td class="success">7818.0</td>
272 <td style="width: 400px;">
273 <div style="height: 100%; width: 82%; background-color: blue;"></div>
274 </td>
275 </tr>
276 <tr>
277 <td>Iterative Appender (16)</td>
278 <td class="success">9497.0</td>
279 <td style="width: 400px;">
280 <div style="height: 100%; width: 100%; background-color: blue;"></div>
281 </td>
282 </tr>
283 <tr>
284 <td>Iterative Replacer</td>
285 <td class="success">8003.0</td>
286 <td style="width: 400px;">
287 <div style="height: 100%; width: 84%; background-color: blue;"></div>
288 </td>
289 </tr>
290 <tr>
291 <td>Iterative Replacer (16)</td>
292 <td class="success">8010.0</td>
293 <td style="width: 400px;">
294 <div style="height: 100%; width: 84%; background-color: blue;"></div>
295 </td>
296 </tr>
297 <tr>
298 <td>Separate Lookup Replacer</td>
299 <td class="success">8422.0</td>
300 <td style="width: 400px;">
301 <div style="height: 100%; width: 89%; background-color: blue;"></div>
302 </td>
303 </tr>
304 <tr>
305 <td>Separate Lookup Replacer (16)</td>
306 <td class="success">8528.0</td>
307 <td style="width: 400px;">
308 <div style="height: 100%; width: 90%; background-color: blue;"></div>
309 </td>
310 </tr>
311 </table>
312 <h3>Field with dollars Target</h3>
313 <table>
314 <tr>
315 <th>Product</th>
316 <th>ms</th>
317 </tr>
318 <tr>
319 <td>XStream 1.2.2 Replacer</td>
320 <td class="success">8038.0</td>
321 <td style="width: 400px;">
322 <div style="height: 100%; width: 87%; background-color: blue;"></div>
323 </td>
324 </tr>
325 <tr>
326 <td>Combined Lookup Appending</td>
327 <td class="success">9266.0</td>
328 <td style="width: 400px;">
329 <div style="height: 100%; width: 100%; background-color: blue;"></div>
330 </td>
331 </tr>
332 <tr>
333 <td>Combined Lookup Appending (16)</td>
334 <td class="success">9174.0</td>
335 <td style="width: 400px;">
336 <div style="height: 100%; width: 99%; background-color: blue;"></div>
337 </td>
338 </tr>
339 <tr>
340 <td>Combined Lookup Replacer</td>
341 <td class="success">8888.0</td>
342 <td style="width: 400px;">
343 <div style="height: 100%; width: 96%; background-color: blue;"></div>
344 </td>
345 </tr>
346 <tr>
347 <td>Combined Lookup Replacer (16)</td>
348 <td class="success">8926.0</td>
349 <td style="width: 400px;">
350 <div style="height: 100%; width: 96%; background-color: blue;"></div>
351 </td>
352 </tr>
353 <tr>
354 <td>Iterative Appender</td>
355 <td class="success">8337.0</td>
356 <td style="width: 400px;">
357 <div style="height: 100%; width: 90%; background-color: blue;"></div>
358 </td>
359 </tr>
360 <tr>
361 <td>Iterative Appender (16)</td>
362 <td class="success">8402.0</td>
363 <td style="width: 400px;">
364 <div style="height: 100%; width: 91%; background-color: blue;"></div>
365 </td>
366 </tr>
367 <tr>
368 <td>Iterative Replacer</td>
369 <td class="success">9186.0</td>
370 <td style="width: 400px;">
371 <div style="height: 100%; width: 99%; background-color: blue;"></div>
372 </td>
373 </tr>
374 <tr>
375 <td>Iterative Replacer (16)</td>
376 <td class="success">8299.0</td>
377 <td style="width: 400px;">
378 <div style="height: 100%; width: 90%; background-color: blue;"></div>
379 </td>
380 </tr>
381 <tr>
382 <td>Separate Lookup Replacer</td>
383 <td class="success">8540.0</td>
384 <td style="width: 400px;">
385 <div style="height: 100%; width: 92%; background-color: blue;"></div>
386 </td>
387 </tr>
388 <tr>
389 <td>Separate Lookup Replacer (16)</td>
390 <td class="success">8617.0</td>
391 <td style="width: 400px;">
392 <div style="height: 100%; width: 93%; background-color: blue;"></div>
393 </td>
394 </tr>
395 </table>
396 <h2>Deserialization speed (50 iterations)</h2>
397 <h3>Field Target</h3>
398 <table>
399 <tr>
400 <th>Product</th>
401 <th>ms</th>
402 </tr>
403 <tr>
404 <td>XStream 1.2.2 Replacer</td>
405 <td class="success">15346.0</td>
406 <td style="width: 400px;">
407 <div style="height: 100%; width: 100%; background-color: blue;"></div>
408 </td>
409 </tr>
410 <tr>
411 <td>Combined Lookup Appending</td>
412 <td class="success">13864.0</td>
413 <td style="width: 400px;">
414 <div style="height: 100%; width: 90%; background-color: blue;"></div>
415 </td>
416 </tr>
417 <tr>
418 <td>Combined Lookup Appending (16)</td>
419 <td class="success">13438.0</td>
420 <td style="width: 400px;">
421 <div style="height: 100%; width: 88%; background-color: blue;"></div>
422 </td>
423 </tr>
424 <tr>
425 <td>Combined Lookup Replacer</td>
426 <td class="success">13480.0</td>
427 <td style="width: 400px;">
428 <div style="height: 100%; width: 88%; background-color: blue;"></div>
429 </td>
430 </tr>
431 <tr>
432 <td>Combined Lookup Replacer (16)</td>
433 <td class="success">13700.0</td>
434 <td style="width: 400px;">
435 <div style="height: 100%; width: 89%; background-color: blue;"></div>
436 </td>
437 </tr>
438 <tr>
439 <td>Iterative Appender</td>
440 <td class="success">14062.0</td>
441 <td style="width: 400px;">
442 <div style="height: 100%; width: 92%; background-color: blue;"></div>
443 </td>
444 </tr>
445 <tr>
446 <td>Iterative Appender (16)</td>
447 <td class="success">13926.0</td>
448 <td style="width: 400px;">
449 <div style="height: 100%; width: 91%; background-color: blue;"></div>
450 </td>
451 </tr>
452 <tr>
453 <td>Iterative Replacer</td>
454 <td class="success">13634.0</td>
455 <td style="width: 400px;">
456 <div style="height: 100%; width: 89%; background-color: blue;"></div>
457 </td>
458 </tr>
459 <tr>
460 <td>Iterative Replacer (16)</td>
461 <td class="success">13496.0</td>
462 <td style="width: 400px;">
463 <div style="height: 100%; width: 88%; background-color: blue;"></div>
464 </td>
465 </tr>
466 <tr>
467 <td>Separate Lookup Replacer</td>
468 <td class="success">13630.0</td>
469 <td style="width: 400px;">
470 <div style="height: 100%; width: 89%; background-color: blue;"></div>
471 </td>
472 </tr>
473 <tr>
474 <td>Separate Lookup Replacer (16)</td>
475 <td class="success">13985.0</td>
476 <td style="width: 400px;">
477 <div style="height: 100%; width: 91%; background-color: blue;"></div>
478 </td>
479 </tr>
480 </table>
481 <h3>Field with underscores Target</h3>
482 <table>
483 <tr>
484 <th>Product</th>
485 <th>ms</th>
486 </tr>
487 <tr>
488 <td>XStream 1.2.2 Replacer</td>
489 <td class="success">15547.0</td>
490 <td style="width: 400px;">
491 <div style="height: 100%; width: 93%; background-color: blue;"></div>
492 </td>
493 </tr>
494 <tr>
495 <td>Combined Lookup Appending</td>
496 <td class="success">14747.0</td>
497 <td style="width: 400px;">
498 <div style="height: 100%; width: 88%; background-color: blue;"></div>
499 </td>
500 </tr>
501 <tr>
502 <td>Combined Lookup Appending (16)</td>
503 <td class="success">14816.0</td>
504 <td style="width: 400px;">
505 <div style="height: 100%; width: 89%; background-color: blue;"></div>
506 </td>
507 </tr>
508 <tr>
509 <td>Combined Lookup Replacer</td>
510 <td class="success">16730.0</td>
511 <td style="width: 400px;">
512 <div style="height: 100%; width: 100%; background-color: blue;"></div>
513 </td>
514 </tr>
515 <tr>
516 <td>Combined Lookup Replacer (16)</td>
517 <td class="success">15099.0</td>
518 <td style="width: 400px;">
519 <div style="height: 100%; width: 90%; background-color: blue;"></div>
520 </td>
521 </tr>
522 <tr>
523 <td>Iterative Appender</td>
524 <td class="success">13857.0</td>
525 <td style="width: 400px;">
526 <div style="height: 100%; width: 83%; background-color: blue;"></div>
527 </td>
528 </tr>
529 <tr>
530 <td>Iterative Appender (16)</td>
531 <td class="success">13982.0</td>
532 <td style="width: 400px;">
533 <div style="height: 100%; width: 84%; background-color: blue;"></div>
534 </td>
535 </tr>
536 <tr>
537 <td>Iterative Replacer</td>
538 <td class="success">16226.0</td>
539 <td style="width: 400px;">
540 <div style="height: 100%; width: 97%; background-color: blue;"></div>
541 </td>
542 </tr>
543 <tr>
544 <td>Iterative Replacer (16)</td>
545 <td class="success">16218.0</td>
546 <td style="width: 400px;">
547 <div style="height: 100%; width: 97%; background-color: blue;"></div>
548 </td>
549 </tr>
550 <tr>
551 <td>Separate Lookup Replacer</td>
552 <td class="success">15496.0</td>
553 <td style="width: 400px;">
554 <div style="height: 100%; width: 93%; background-color: blue;"></div>
555 </td>
556 </tr>
557 <tr>
558 <td>Separate Lookup Replacer (16)</td>
559 <td class="success">15151.0</td>
560 <td style="width: 400px;">
561 <div style="height: 100%; width: 91%; background-color: blue;"></div>
562 </td>
563 </tr>
564 </table>
565 <h3>Field with dollars Target</h3>
566 <table>
567 <tr>
568 <th>Product</th>
569 <th>ms</th>
570 </tr>
571 <tr>
572 <td>XStream 1.2.2 Replacer</td>
573 <td class="success">14163.0</td>
574 <td style="width: 400px;">
575 <div style="height: 100%; width: 81%; background-color: blue;"></div>
576 </td>
577 </tr>
578 <tr>
579 <td>Combined Lookup Appending</td>
580 <td class="success">14140.0</td>
581 <td style="width: 400px;">
582 <div style="height: 100%; width: 81%; background-color: blue;"></div>
583 </td>
584 </tr>
585 <tr>
586 <td>Combined Lookup Appending (16)</td>
587 <td class="success">14360.0</td>
588 <td style="width: 400px;">
589 <div style="height: 100%; width: 82%; background-color: blue;"></div>
590 </td>
591 </tr>
592 <tr>
593 <td>Combined Lookup Replacer</td>
594 <td class="success">14938.0</td>
595 <td style="width: 400px;">
596 <div style="height: 100%; width: 85%; background-color: blue;"></div>
597 </td>
598 </tr>
599 <tr>
600 <td>Combined Lookup Replacer (16)</td>
601 <td class="success">14771.0</td>
602 <td style="width: 400px;">
603 <div style="height: 100%; width: 84%; background-color: blue;"></div>
604 </td>
605 </tr>
606 <tr>
607 <td>Iterative Appender</td>
608 <td class="success">13549.0</td>
609 <td style="width: 400px;">
610 <div style="height: 100%; width: 77%; background-color: blue;"></div>
611 </td>
612 </tr>
613 <tr>
614 <td>Iterative Appender (16)</td>
615 <td class="success">13679.0</td>
616 <td style="width: 400px;">
617 <div style="height: 100%; width: 78%; background-color: blue;"></div>
618 </td>
619 </tr>
620 <tr>
621 <td>Iterative Replacer</td>
622 <td class="success">14890.0</td>
623 <td style="width: 400px;">
624 <div style="height: 100%; width: 85%; background-color: blue;"></div>
625 </td>
626 </tr>
627 <tr>
628 <td>Iterative Replacer (16)</td>
629 <td class="success">15030.0</td>
630 <td style="width: 400px;">
631 <div style="height: 100%; width: 86%; background-color: blue;"></div>
632 </td>
633 </tr>
634 <tr>
635 <td>Separate Lookup Replacer</td>
636 <td class="success">15437.0</td>
637 <td style="width: 400px;">
638 <div style="height: 100%; width: 88%; background-color: blue;"></div>
639 </td>
640 </tr>
641 <tr>
642 <td>Separate Lookup Replacer (16)</td>
643 <td class="success">17536.0</td>
644 <td style="width: 400px;">
645 <div style="height: 100%; width: 100%; background-color: blue;"></div>
646 </td>
647 </tr>
648 </table>
649 <p>Fri Sep 14 23:41:12 CEST 2007 - Sun JDK 1.6.0_02/Linux x86 - AMD Athlon XP 2700+ (2.1Ghz)</p>
650 </body>
651 </html>
0 ======================================================================
1 Size of serialized data
2 ======================================================================
3 * Field Target
4 - .................................................. 353514.0 bytes
5 * Field with underscores Target
6 - .................................................. 353914.0 bytes
7 * Field with dollars Target
8 - .................................................. 353914.0 bytes
9
10 ======================================================================
11 Character count for '$'
12 ======================================================================
13 * Field Target
14 - .................................................. 0.0 characters
15 * Field with underscores Target
16 - .................................................. 0.0 characters
17 * Field with dollars Target
18 - .................................................. 100200.0 characters
19
20 ======================================================================
21 Character count for '_'
22 ======================================================================
23 * Field Target
24 - .................................................. 0.0 characters
25 * Field with underscores Target
26 - .................................................. 100200.0 characters
27 * Field with dollars Target
28 - .................................................. 0.0 characters
29
30 ======================================================================
31 Serialization speed (50 iterations)
32 ======================================================================
33 * Field Target
34 - XStream 1.2.2 Replacer............................ 7788.0 ms
35 - Combined Lookup Appending......................... 9173.0 ms
36 - Combined Lookup Appending (16).................... 7628.0 ms
37 - Combined Lookup Replacer.......................... 7806.0 ms
38 - Combined Lookup Replacer (16)..................... 7817.0 ms
39 - Iterative Appender................................ 7634.0 ms
40 - Iterative Appender (16)........................... 7785.0 ms
41 - Iterative Replacer................................ 7787.0 ms
42 - Iterative Replacer (16)........................... 7937.0 ms
43 - Separate Lookup Replacer.......................... 7779.0 ms
44 - Separate Lookup Replacer (16)..................... 7765.0 ms
45 * Field with underscores Target
46 - XStream 1.2.2 Replacer............................ 7971.0 ms
47 - Combined Lookup Appending......................... 8416.0 ms
48 - Combined Lookup Appending (16).................... 8197.0 ms
49 - Combined Lookup Replacer.......................... 8477.0 ms
50 - Combined Lookup Replacer (16)..................... 8673.0 ms
51 - Iterative Appender................................ 7818.0 ms
52 - Iterative Appender (16)........................... 9497.0 ms
53 - Iterative Replacer................................ 8003.0 ms
54 - Iterative Replacer (16)........................... 8010.0 ms
55 - Separate Lookup Replacer.......................... 8422.0 ms
56 - Separate Lookup Replacer (16)..................... 8528.0 ms
57 * Field with dollars Target
58 - XStream 1.2.2 Replacer............................ 8038.0 ms
59 - Combined Lookup Appending......................... 9266.0 ms
60 - Combined Lookup Appending (16).................... 9174.0 ms
61 - Combined Lookup Replacer.......................... 8888.0 ms
62 - Combined Lookup Replacer (16)..................... 8926.0 ms
63 - Iterative Appender................................ 8337.0 ms
64 - Iterative Appender (16)........................... 8402.0 ms
65 - Iterative Replacer................................ 9186.0 ms
66 - Iterative Replacer (16)........................... 8299.0 ms
67 - Separate Lookup Replacer.......................... 8540.0 ms
68 - Separate Lookup Replacer (16)..................... 8617.0 ms
69
70 ======================================================================
71 Deserialization speed (50 iterations)
72 ======================================================================
73 * Field Target
74 - XStream 1.2.2 Replacer............................ 15346.0 ms
75 - Combined Lookup Appending......................... 13864.0 ms
76 - Combined Lookup Appending (16).................... 13438.0 ms
77 - Combined Lookup Replacer.......................... 13480.0 ms
78 - Combined Lookup Replacer (16)..................... 13700.0 ms
79 - Iterative Appender................................ 14062.0 ms
80 - Iterative Appender (16)........................... 13926.0 ms
81 - Iterative Replacer................................ 13634.0 ms
82 - Iterative Replacer (16)........................... 13496.0 ms
83 - Separate Lookup Replacer.......................... 13630.0 ms
84 - Separate Lookup Replacer (16)..................... 13985.0 ms
85 * Field with underscores Target
86 - XStream 1.2.2 Replacer............................ 15547.0 ms
87 - Combined Lookup Appending......................... 14747.0 ms
88 - Combined Lookup Appending (16).................... 14816.0 ms
89 - Combined Lookup Replacer.......................... 16730.0 ms
90 - Combined Lookup Replacer (16)..................... 15099.0 ms
91 - Iterative Appender................................ 13857.0 ms
92 - Iterative Appender (16)........................... 13982.0 ms
93 - Iterative Replacer................................ 16226.0 ms
94 - Iterative Replacer (16)........................... 16218.0 ms
95 - Separate Lookup Replacer.......................... 15496.0 ms
96 - Separate Lookup Replacer (16)..................... 15151.0 ms
97 * Field with dollars Target
98 - XStream 1.2.2 Replacer............................ 14163.0 ms
99 - Combined Lookup Appending......................... 14140.0 ms
100 - Combined Lookup Appending (16).................... 14360.0 ms
101 - Combined Lookup Replacer.......................... 14938.0 ms
102 - Combined Lookup Replacer (16)..................... 14771.0 ms
103 - Iterative Appender................................ 13549.0 ms
104 - Iterative Appender (16)........................... 13679.0 ms
105 - Iterative Replacer................................ 14890.0 ms
106 - Iterative Replacer (16)........................... 15030.0 ms
107 - Separate Lookup Replacer.......................... 15437.0 ms
108 - Separate Lookup Replacer (16)..................... 17536.0 ms
109
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2013 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark;
12
13 import java.util.List;
14 import java.util.ArrayList;
15 import java.util.Iterator;
16
17 /**
18 * A simple harness for running benchmarks over object serialization products.
19 *
20 * <p>
21 * There are three dimensions that can be added:
22 * </p>
23 * <ul>
24 * <li>{@link Product} (e.g. DOM, SAX, XPP...)</li>
25 * <li>{@link Metric} (e.g. time taken, memory usage, output size...)</li>
26 * <li>{@link Target} (e.g. a small object, large object, list of objects...)</li>
27 * </ul>
28 * <p>
29 * The Harness will then across every permutation of these
30 * (in order of product, metric, target), and write the results to a {@link Reporter}.
31 * </p>
32 *
33 * <h3>Example usage</h3>
34 * <pre>
35 * Harness harness = new Harness();
36 *
37 * // Compare speed of serialization/deserialization metrics...
38 * harness.addMetric(new SerializationSpeedMetric());
39 * harness.addMetric(new DeserializationSpeedMetric());
40 *
41 * // Using a simple String and a JTree instance...
42 * harness.addTarget(new StringTarget());
43 * harness.addTarget(new JTreeTarget());
44 *
45 * // Across XStream with different XML drivers.
46 * harness.addProduct(new XStreamDom());
47 * harness.addProduct(new XStreamXpp());
48 * harness.addProduct(new XStreamSax());
49 *
50 * // Now do it, and report the results as text to the console.
51 * harness.run(new TextReporter());
52 * </pre>
53 *
54 * @author Joe Walnes
55 */
56 public class Harness {
57
58 private List products = new ArrayList();
59 private List targets = new ArrayList();
60 private List metrics = new ArrayList();
61
62 public synchronized void addProduct(Product product) {
63 products.add(product);
64 }
65
66 public synchronized void addTarget(Target target) {
67 targets.add(target);
68 }
69
70 public synchronized void addMetric(Metric metric) {
71 metrics.add(metric);
72 }
73
74 public synchronized void run(Reporter reporter) {
75 // Nested loop galore.
76 reporter.startBenchmark();
77 for (Iterator metricsIt = metrics.iterator(); metricsIt.hasNext();) {
78 Metric metric = (Metric) metricsIt.next();
79 reporter.startMetric(metric);
80 for (Iterator targetIt = targets.iterator(); targetIt.hasNext();) {
81 Target target = (Target) targetIt.next();
82 reporter.startTarget(target);
83 for (Iterator productsIt = products.iterator(); productsIt.hasNext();) {
84 Product product = (Product) productsIt.next();
85 run(reporter, metric, target, product);
86 }
87 reporter.endTarget(target);
88 }
89 reporter.endMetric(metric);
90 }
91 reporter.endBenchmark();
92 }
93
94 private void run(Reporter reporter, Metric metric, Target target, Product product) {
95 try {
96 double result = metric.run(product, target);
97 reporter.metricRecorded(product, result);
98 } catch (Exception e) {
99 reporter.metricFailed(product, e);
100 }
101 }
102
103 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark;
12
13 /**
14 * A metric is what's actually recorded. This provides a strategy
15 * for what to do with an object for a given product and should
16 * return a measurable result. For example it could serialize an
17 * object against a product and return how long it took to complete
18 * the operation.
19 *
20 * @author Joe Walnes
21 * @author J&ouml;rg Schaible
22 * @see Harness
23 */
24 public interface Metric {
25
26 /**
27 * Run the test and produce a metric.
28 *
29 * @param product Product to use in test.
30 * @param object A object to use against the product.
31 * @return The resulting metric (e.g. 12.22).
32 * @throws Exception If this metric could not be obtained. This will
33 * be reported back to the {@link Reporter}.
34 * @deprecated since 1.3
35 */
36 double run(Product product, Object object) throws Exception;
37
38 /**
39 * Run the test and produce a metric.
40 *
41 * @param product Product to use in test.
42 * @param target A target to use against the product.
43 * @return The resulting metric (e.g. 12.22).
44 * @throws Exception If this metric could not be obtained. This will
45 * be reported back to the {@link Reporter}.
46 * @since 1.3
47 */
48 double run(Product product, Target target) throws Exception;
49
50 /**
51 * The unit the metric is recorded in (for reporting purposes).
52 * e.g. "ms" or "bytes".
53 */
54 String unit();
55
56 /**
57 * Whether a big result is better for this metric.
58 */
59 boolean biggerIsBetter();
60
61 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark;
12
13 import java.io.OutputStream;
14 import java.io.InputStream;
15
16 /**
17 * Provides an abstraction above the product used to perform the serialization/deserialization
18 * in the benchmarks.
19 *
20 * @author Joe Walnes
21 * @see Harness
22 */
23 public interface Product {
24
25 /**
26 * Serialize an object to a stream.
27 */
28 void serialize(Object object, OutputStream output) throws Exception;
29
30 /**
31 * Deserialize an object from a stream.
32 */
33 Object deserialize(InputStream input) throws Exception;
34
35 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark;
12
13 /**
14 * A listener to what the {@link Harness} is doing that should report the results.
15 *
16 * The sequence of methods is:
17 * <pre>
18 * startBenchmark,
19 * (
20 * startMetric,
21 * (
22 * startTarget,
23 * ( metricRecorded | metricFailed ),
24 * endTarget
25 * ) * ,
26 * endMetric
27 * ) * ,
28 * endBenchmark
29 * </pre>
30 *
31 * @author Joe Walnes
32 * @see Harness
33 */
34 public interface Reporter {
35
36 /**
37 * Benchmark has started. This will always be called ONCE (and only once) BEFORE everything else.
38 */
39 void startBenchmark();
40
41 void startMetric(Metric metric);
42
43 void startTarget(Target target);
44
45 void metricRecorded(Product product, double result);
46
47 void metricFailed(Product product, Exception e);
48
49 void endTarget(Target target);
50
51 void endMetric(Metric metric);
52
53 /**
54 * Benchmark has ended. This will always be called ONCE (and only once) AFTER everything else.
55 */
56 void endBenchmark();
57
58 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark;
12
13 /**
14 * Provides a target object to use in the metric. This could be a very small object or a large
15 * complicated graph.
16 *
17 * Also used to test if the object is equal to another instance (as some object's don't provide
18 * sensible equals() methods.
19 *
20 * @author Joe Walnes
21 * @see Harness
22 */
23 public interface Target {
24
25 /**
26 * The target to use in the metric.
27 */
28 Object target();
29
30 /**
31 * Check whether the object for this target is equal to another one.
32 */
33 boolean isEqual(Object other);
34
35 }
0 /*
1 * Copyright (C) 2007, 2008, 2009, 2011 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 14. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.metrics;
11
12 import com.thoughtworks.xstream.tools.benchmark.Metric;
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14 import com.thoughtworks.xstream.tools.benchmark.Target;
15
16 import java.io.ByteArrayOutputStream;
17
18 /**
19 * Determines the amount of a special characters.
20 *
21 * @author J&ouml;rg Schaible
22 * @since 1.4
23 */
24 public class CharacterCountMetric implements Metric {
25
26 private final char ch;
27
28 public CharacterCountMetric(char ch) {
29 this.ch = ch;
30 }
31
32 public double run(Product product, Target target) throws Exception {
33 return run(product, target.target());
34 }
35
36 /**
37 *@deprecated since 1.3
38 */
39 public double run(Product product, Object object) throws Exception {
40 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
41 product.serialize(object, buffer);
42 String s = buffer.toString();
43 int counter = 0;
44 for (int i = 0; i < s.length(); i++) {
45 if (s.charAt(i) == ch) {
46 ++counter;
47 }
48 }
49 return counter;
50 }
51
52 public String toString() {
53 return "Character count for '" + ch + "'";
54 }
55
56 public String unit() {
57 return "characters";
58 }
59
60 public boolean biggerIsBetter() {
61 return false;
62 }
63 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008, 2009 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.metrics;
12
13 import com.thoughtworks.xstream.tools.benchmark.Metric;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.Target;
16
17 import java.io.ByteArrayOutputStream;
18 import java.io.ByteArrayInputStream;
19
20 /**
21 * Determines how long it takes to deserialize an object (in ms).
22 *
23 * @author Joe Walnes
24 * @author J&ouml;rg Schaible
25 * @see com.thoughtworks.xstream.tools.benchmark.Harness
26 * @see Metric
27 */
28 public class DeserializationSpeedMetric implements Metric {
29
30 private final int iterations;
31 private final boolean validate;
32
33 /**
34 * Measure deserialization speed.
35 *
36 * @param iterations
37 * @deprecated since 1.3, use {@link #DeserializationSpeedMetric(int, boolean)}
38 */
39 public DeserializationSpeedMetric(int iterations) {
40 this(iterations, false);
41 }
42
43 /**
44 * Measure deserialization speed.
45 * @param iterations
46 * @param validate flag to compare result of last iteration with original data
47 * @since 1.3
48 */
49 public DeserializationSpeedMetric(int iterations, boolean validate) {
50 this.iterations = iterations;
51 this.validate = validate;
52 }
53
54 public double run(Product product, Target target) throws Exception {
55
56 // Serialize once (because we need something to deserialize).
57 ByteArrayOutputStream output = new ByteArrayOutputStream();
58 product.serialize(target.target(), output);
59 byte[] data = output.toByteArray();
60
61 // Deserialize once, to warm up.
62 product.deserialize(new ByteArrayInputStream(data));
63
64 // Now lots of times
65 Object lastResult = null;
66 long start = System.currentTimeMillis();
67 for (int i = 0; i < iterations; i++) {
68 lastResult = product.deserialize(new ByteArrayInputStream(data));
69 }
70 long end = System.currentTimeMillis();
71 if (validate && iterations > 0) {
72 if (!target.isEqual(lastResult)) {
73 throw new RuntimeException("Deserialized object is not equal");
74 }
75 }
76
77 return (end - start);
78 }
79
80 /**
81 *@deprecated since 1.3
82 */
83 public double run(Product product, Object object) throws Exception {
84
85 // Serialize once (because we need something to deserialize).
86 ByteArrayOutputStream output = new ByteArrayOutputStream();
87 product.serialize(object, output);
88 byte[] data = output.toByteArray();
89
90 // Deserialize once, to warm up.
91 product.deserialize(new ByteArrayInputStream(data));
92
93 // Now lots of times
94 long start = System.currentTimeMillis();
95 for (int i = 0; i < iterations; i++) {
96 product.deserialize(new ByteArrayInputStream(data));
97 }
98 long end = System.currentTimeMillis();
99
100 return (end - start);
101 }
102
103 public String unit() {
104 return "ms";
105 }
106
107 public boolean biggerIsBetter() {
108 return false;
109 }
110
111 public String toString() {
112 return "Deserialization speed (" + iterations + " iteration" + (iterations == 1 ? "" : "s") + ")";
113 }
114 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.metrics;
12
13 import com.thoughtworks.xstream.tools.benchmark.Metric;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.Target;
16
17 import java.io.ByteArrayOutputStream;
18
19 /**
20 * Determines how long it takes to serialize an object (in ms).
21 *
22 * @author Joe Walnes
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Metric
25 */
26 public class SerializationSpeedMetric implements Metric {
27
28 private int iterations;
29
30 public SerializationSpeedMetric(int iterations) {
31 this.iterations = iterations;
32 }
33
34 public double run(Product product, Target target) throws Exception {
35 return run(product, target.target());
36 }
37
38 /**
39 *@deprecated since 1.3
40 */
41 public double run(Product product, Object object) throws Exception {
42 // Do it once to warm up.
43 product.serialize(object, new ByteArrayOutputStream());
44
45 // Now lots of times
46 long start = System.currentTimeMillis();
47 for (int i = 0; i < iterations; i++) {
48 product.serialize(object, new ByteArrayOutputStream());
49 }
50 long end = System.currentTimeMillis();
51
52 return (end - start);
53 }
54
55 public String unit() {
56 return "ms";
57 }
58
59 public boolean biggerIsBetter() {
60 return false;
61 }
62
63 public String toString() {
64 return "Serialization speed (" + iterations + " iteration" + (iterations == 1 ? "" : "s") + ")";
65 }
66 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2008 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.metrics;
12
13 import com.thoughtworks.xstream.tools.benchmark.Metric;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.Target;
16
17 import java.io.ByteArrayOutputStream;
18
19 /**
20 * Determines the size of the serialized form of an object (in bytes).
21 *
22 * @author Joe Walnes
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Metric
25 */
26 public class SizeMetric implements Metric {
27
28 public double run(Product product, Target target) throws Exception {
29 return run(product, target.target());
30 }
31
32 /**
33 *@deprecated since 1.3
34 */
35 public double run(Product product, Object object) throws Exception {
36 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
37 product.serialize(object, buffer);
38 return buffer.size();
39 }
40
41 public String toString() {
42 return "Size of serialized data";
43 }
44
45 public String unit() {
46 return "bytes";
47 }
48
49 public boolean biggerIsBetter() {
50 return false;
51 }
52 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 25. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 /**
13 * Class with 100 fields.
14 *
15 * @since 1.4
16 */
17 public class A100Fields {
18
19 String field000;
20 String field001;
21 String field002;
22 String field003;
23 String field004;
24 String field005;
25 String field006;
26 String field007;
27 String field008;
28 String field009;
29 String field010;
30 String field011;
31 String field012;
32 String field013;
33 String field014;
34 String field015;
35 String field016;
36 String field017;
37 String field018;
38 String field019;
39 String field020;
40 String field021;
41 String field022;
42 String field023;
43 String field024;
44 String field025;
45 String field026;
46 String field027;
47 String field028;
48 String field029;
49 String field030;
50 String field031;
51 String field032;
52 String field033;
53 String field034;
54 String field035;
55 String field036;
56 String field037;
57 String field038;
58 String field039;
59 String field040;
60 String field041;
61 String field042;
62 String field043;
63 String field044;
64 String field045;
65 String field046;
66 String field047;
67 String field048;
68 String field049;
69 String field050;
70 String field051;
71 String field052;
72 String field053;
73 String field054;
74 String field055;
75 String field056;
76 String field057;
77 String field058;
78 String field059;
79 String field060;
80 String field061;
81 String field062;
82 String field063;
83 String field064;
84 String field065;
85 String field066;
86 String field067;
87 String field068;
88 String field069;
89 String field070;
90 String field071;
91 String field072;
92 String field073;
93 String field074;
94 String field075;
95 String field076;
96 String field077;
97 String field078;
98 String field079;
99 String field080;
100 String field081;
101 String field082;
102 String field083;
103 String field084;
104 String field085;
105 String field086;
106 String field087;
107 String field088;
108 String field089;
109 String field090;
110 String field091;
111 String field092;
112 String field093;
113 String field094;
114 String field095;
115 String field096;
116 String field097;
117 String field098;
118 String field099;
119 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 25. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 /**
13 * Class with 100 parents.
14 *
15 * @since 1.4
16 */
17 public class A100Parents {
18
19 public static class Parent000 { String field000; }
20 public static class Parent001 extends Parent000 { String field001; }
21 public static class Parent002 extends Parent001 { String field002; }
22 public static class Parent003 extends Parent002 { String field003; }
23 public static class Parent004 extends Parent003 { String field004; }
24 public static class Parent005 extends Parent004 { String field005; }
25 public static class Parent006 extends Parent005 { String field006; }
26 public static class Parent007 extends Parent006 { String field007; }
27 public static class Parent008 extends Parent007 { String field008; }
28 public static class Parent009 extends Parent008 { String field009; }
29 public static class Parent010 extends Parent009 { String field010; }
30 public static class Parent011 extends Parent010 { String field011; }
31 public static class Parent012 extends Parent011 { String field012; }
32 public static class Parent013 extends Parent012 { String field013; }
33 public static class Parent014 extends Parent013 { String field014; }
34 public static class Parent015 extends Parent014 { String field015; }
35 public static class Parent016 extends Parent015 { String field016; }
36 public static class Parent017 extends Parent016 { String field017; }
37 public static class Parent018 extends Parent017 { String field018; }
38 public static class Parent019 extends Parent018 { String field019; }
39 public static class Parent020 extends Parent019 { String field020; }
40 public static class Parent021 extends Parent020 { String field021; }
41 public static class Parent022 extends Parent021 { String field022; }
42 public static class Parent023 extends Parent022 { String field023; }
43 public static class Parent024 extends Parent023 { String field024; }
44 public static class Parent025 extends Parent024 { String field025; }
45 public static class Parent026 extends Parent025 { String field026; }
46 public static class Parent027 extends Parent026 { String field027; }
47 public static class Parent028 extends Parent027 { String field028; }
48 public static class Parent029 extends Parent028 { String field029; }
49 public static class Parent030 extends Parent029 { String field030; }
50 public static class Parent031 extends Parent030 { String field031; }
51 public static class Parent032 extends Parent031 { String field032; }
52 public static class Parent033 extends Parent032 { String field033; }
53 public static class Parent034 extends Parent033 { String field034; }
54 public static class Parent035 extends Parent034 { String field035; }
55 public static class Parent036 extends Parent035 { String field036; }
56 public static class Parent037 extends Parent036 { String field037; }
57 public static class Parent038 extends Parent037 { String field038; }
58 public static class Parent039 extends Parent038 { String field039; }
59 public static class Parent040 extends Parent039 { String field040; }
60 public static class Parent041 extends Parent040 { String field041; }
61 public static class Parent042 extends Parent041 { String field042; }
62 public static class Parent043 extends Parent042 { String field043; }
63 public static class Parent044 extends Parent043 { String field044; }
64 public static class Parent045 extends Parent044 { String field045; }
65 public static class Parent046 extends Parent045 { String field046; }
66 public static class Parent047 extends Parent046 { String field047; }
67 public static class Parent048 extends Parent047 { String field048; }
68 public static class Parent049 extends Parent048 { String field049; }
69 public static class Parent050 extends Parent049 { String field050; }
70 public static class Parent051 extends Parent050 { String field051; }
71 public static class Parent052 extends Parent051 { String field052; }
72 public static class Parent053 extends Parent052 { String field053; }
73 public static class Parent054 extends Parent053 { String field054; }
74 public static class Parent055 extends Parent054 { String field055; }
75 public static class Parent056 extends Parent055 { String field056; }
76 public static class Parent057 extends Parent056 { String field057; }
77 public static class Parent058 extends Parent057 { String field058; }
78 public static class Parent059 extends Parent058 { String field059; }
79 public static class Parent060 extends Parent059 { String field060; }
80 public static class Parent061 extends Parent060 { String field061; }
81 public static class Parent062 extends Parent061 { String field062; }
82 public static class Parent063 extends Parent062 { String field063; }
83 public static class Parent064 extends Parent063 { String field064; }
84 public static class Parent065 extends Parent064 { String field065; }
85 public static class Parent066 extends Parent065 { String field066; }
86 public static class Parent067 extends Parent066 { String field067; }
87 public static class Parent068 extends Parent067 { String field068; }
88 public static class Parent069 extends Parent068 { String field069; }
89 public static class Parent070 extends Parent069 { String field070; }
90 public static class Parent071 extends Parent070 { String field071; }
91 public static class Parent072 extends Parent071 { String field072; }
92 public static class Parent073 extends Parent072 { String field073; }
93 public static class Parent074 extends Parent073 { String field074; }
94 public static class Parent075 extends Parent074 { String field075; }
95 public static class Parent076 extends Parent075 { String field076; }
96 public static class Parent077 extends Parent076 { String field077; }
97 public static class Parent078 extends Parent077 { String field078; }
98 public static class Parent079 extends Parent078 { String field079; }
99 public static class Parent080 extends Parent079 { String field080; }
100 public static class Parent081 extends Parent080 { String field081; }
101 public static class Parent082 extends Parent081 { String field082; }
102 public static class Parent083 extends Parent082 { String field083; }
103 public static class Parent084 extends Parent083 { String field084; }
104 public static class Parent085 extends Parent084 { String field085; }
105 public static class Parent086 extends Parent085 { String field086; }
106 public static class Parent087 extends Parent086 { String field087; }
107 public static class Parent088 extends Parent087 { String field088; }
108 public static class Parent089 extends Parent088 { String field089; }
109 public static class Parent090 extends Parent089 { String field090; }
110 public static class Parent091 extends Parent090 { String field091; }
111 public static class Parent092 extends Parent091 { String field092; }
112 public static class Parent093 extends Parent092 { String field093; }
113 public static class Parent094 extends Parent093 { String field094; }
114 public static class Parent095 extends Parent094 { String field095; }
115 public static class Parent096 extends Parent095 { String field096; }
116 public static class Parent097 extends Parent096 { String field097; }
117 public static class Parent098 extends Parent097 { String field098; }
118 public static class Parent099 extends Parent098 { String field099; }
119 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 /**
13 * Class with inner classes 50 levels deep.
14 *
15 * @since 1.4
16 */
17 public class A50InnerClasses {
18
19 public class L00 { String field000;
20 public class L01 { String field001;
21 public class L02 { String field002;
22 public class L03 { String field003;
23 public class L04 { String field004;
24 public class L05 { String field005;
25 public class L06 { String field006;
26 public class L07 { String field007;
27 public class L08 { String field008;
28 public class L09 { String field009;
29 public class L10 { String field010;
30 public class L11 { String field011;
31 public class L12 { String field012;
32 public class L13 { String field013;
33 public class L14 { String field014;
34 public class L15 { String field015;
35 public class L16 { String field016;
36 public class L17 { String field017;
37 public class L18 { String field018;
38 public class L19 { String field019;
39 public class L20 { String field020;
40 public class L21 { String field021;
41 public class L22 { String field022;
42 public class L23 { String field023;
43 public class L24 { String field024;
44 public class L25 { String field025;
45 public class L26 { String field026;
46 public class L27 { String field027;
47 public class L28 { String field028;
48 public class L29 { String field029;
49 public class L30 { String field030;
50 public class L31 { String field031;
51 public class L32 { String field032;
52 public class L33 { String field033;
53 public class L34 { String field034;
54 public class L35 { String field035;
55 public class L36 { String field036;
56 public class L37 { String field037;
57 public class L38 { String field038;
58 public class L39 { String field039;
59 public class L40 { String field040;
60 public class L41 { String field041;
61 public class L42 { String field042;
62 public class L43 { String field043;
63 public class L44 { String field044;
64 public class L45 { String field045;
65 public class L46 { String field046;
66 public class L47 { String field047;
67 public class L48 { String field048;
68 public class L49 { String field049;
69 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
70 }
0 /*
1 * Copyright (C) 2007, 2009, 2011 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 15. August 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 /**
13 * Class with static inner classes 50 levels deep.
14 *
15 * @since 1.4
16 */
17 public class A50StaticInnerClasses {
18
19 public static class L00 { String field000;
20 public static class L01 { String field001;
21 public static class L02 { String field002;
22 public static class L03 { String field003;
23 public static class L04 { String field004;
24 public static class L05 { String field005;
25 public static class L06 { String field006;
26 public static class L07 { String field007;
27 public static class L08 { String field008;
28 public static class L09 { String field009;
29 public static class L10 { String field010;
30 public static class L11 { String field011;
31 public static class L12 { String field012;
32 public static class L13 { String field013;
33 public static class L14 { String field014;
34 public static class L15 { String field015;
35 public static class L16 { String field016;
36 public static class L17 { String field017;
37 public static class L18 { String field018;
38 public static class L19 { String field019;
39 public static class L20 { String field020;
40 public static class L21 { String field021;
41 public static class L22 { String field022;
42 public static class L23 { String field023;
43 public static class L24 { String field024;
44 public static class L25 { String field025;
45 public static class L26 { String field026;
46 public static class L27 { String field027;
47 public static class L28 { String field028;
48 public static class L29 { String field029;
49 public static class L30 { String field030;
50 public static class L31 { String field031;
51 public static class L32 { String field032;
52 public static class L33 { String field033;
53 public static class L34 { String field034;
54 public static class L35 { String field035;
55 public static class L36 { String field036;
56 public static class L37 { String field037;
57 public static class L38 { String field038;
58 public static class L39 { String field039;
59 public static class L40 { String field040;
60 public static class L41 { String field041;
61 public static class L42 { String field042;
62 public static class L43 { String field043;
63 public static class L44 { String field044;
64 public static class L45 { String field045;
65 public static class L46 { String field046;
66 public static class L47 { String field047;
67 public static class L48 { String field048;
68 public static class L49 { String field049;
69 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
70 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12
13 /**
14 * Class containing 5 basic types.
15 *
16 * @since 1.4
17 */
18 public class Five extends One {
19
20 private int two;
21 private boolean three;
22 private char four;
23 private StringBuffer five;
24
25 public Five(String one, int two, boolean three, char four, StringBuffer five) {
26 super(one);
27 this.two = two;
28 this.three = three;
29 this.four = four;
30 this.five = five;
31 }
32
33 public boolean equals(Object obj) {
34 Five five = (Five)obj;
35 return super.equals(obj) && two == five.two && three == five.three && four == five.four && this.five.toString().equals(five.five.toString());
36 }
37
38 public int hashCode() {
39 return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
40 }
41 }
0 /*
1 * Copyright (C) 2009, 2011 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 05. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12
13 /**
14 * JavaBean class containing 5 basic types.
15 *
16 * @since 1.4
17 */
18 public class FiveBean extends OneBean {
19
20 private int two;
21 private boolean three;
22 private char four;
23 private StringBuffer five;
24
25 public int getTwo() {
26 return this.two;
27 }
28
29 public void setTwo(int two) {
30 this.two = two;
31 }
32
33 public boolean isThree() {
34 return this.three;
35 }
36
37 public void setThree(boolean three) {
38 this.three = three;
39 }
40
41 public char getFour() {
42 return this.four;
43 }
44
45 public void setFour(char four) {
46 this.four = four;
47 }
48
49 public StringBuffer getFive() {
50 return this.five;
51 }
52
53 public void setFive(StringBuffer five) {
54 this.five = five;
55 }
56
57 public boolean equals(Object obj) {
58 FiveBean five = (FiveBean)obj;
59 return super.equals(obj) && two == five.two && three == five.three && four == five.four && this.five.toString().equals(five.five.toString());
60 }
61
62 public int hashCode() {
63 return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
64 }
65 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12
13 /**
14 * Class containing one basic type.
15 *
16 * @since 1.4
17 */
18 public class One {
19
20 private String one;
21
22 public One(String one) {
23 this.one = one;
24 }
25
26 public boolean equals(Object obj) {
27 return one.equals(((One)obj).one);
28 }
29
30 public int hashCode() {
31 return one.hashCode() >>> 1;
32 }
33 }
0 /*
1 * Copyright (C) 2009, 2011 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 05. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12
13 /**
14 * JavaBean class containing one basic type.
15 *
16 * @since 1.4
17 */
18 public class OneBean {
19
20 private String one;
21
22 public String getOne() {
23 return this.one;
24 }
25
26 public void setOne(String one) {
27 this.one = one;
28 }
29
30 public boolean equals(Object obj) {
31 return one.equals(((OneBean)obj).one);
32 }
33
34 public int hashCode() {
35 return one.hashCode() >>> 1;
36 }
37 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15
16 /**
17 * Serializable class containing 5 basic types.
18 *
19 * @since 1.4
20 */
21 public class SerializableFive extends SerializableOne {
22
23 private static final long serialVersionUID = 1L;
24 private int two;
25 private boolean three;
26 private char four;
27 private StringBuffer five;
28
29 public SerializableFive(String one, int two, boolean three, char four, StringBuffer five) {
30 super(one);
31 this.two = two;
32 this.three = three;
33 this.four = four;
34 this.five = five;
35 }
36
37 private void writeObject(final ObjectOutputStream out) throws IOException {
38 out.defaultWriteObject();
39 }
40
41 private void readObject(final ObjectInputStream in)
42 throws IOException, ClassNotFoundException {
43 in.defaultReadObject();
44 }
45
46 public boolean equals(Object obj) {
47 SerializableFive five = (SerializableFive)obj;
48 return super.equals(obj) && two == five.two && three == five.three && four == five.four && this.five.toString().equals(five.five.toString());
49 }
50
51 public int hashCode() {
52 return super.hashCode() + two + new Boolean(three).hashCode() + five.toString().hashCode();
53 }
54 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.model;
11
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.io.Serializable;
16
17 /**
18 * Serializable class containing one basic types.
19 *
20 * @since 1.4
21 */
22 public class SerializableOne implements Serializable {
23
24 private static final long serialVersionUID = 1L;
25
26 private String one;
27
28 public SerializableOne(String one) {
29 this.one = one;
30 }
31
32 private void writeObject(final ObjectOutputStream out) throws IOException {
33 out.defaultWriteObject();
34 }
35
36 private void readObject(final ObjectInputStream in)
37 throws IOException, ClassNotFoundException {
38 in.defaultReadObject();
39 }
40
41 public boolean equals(Object obj) {
42 return one.equals(((SerializableOne)obj).one);
43 }
44
45 public int hashCode() {
46 return one.hashCode() >>> 1;
47 }
48 }
0 <!--
1 Copyright (C) 2006 Joe Walnes.
2 Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 -->
11 <body>
12 A simple harness for running benchmarks. See <a href="Harness.html">Harness</a>
13 </body>
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14
15 import java.io.OutputStream;
16 import java.io.InputStream;
17 import java.io.ObjectOutputStream;
18 import java.io.ObjectInputStream;
19
20 /**
21 * Standard Java Object Serialization product.
22 *
23 * @author Joe Walnes
24 * @see com.thoughtworks.xstream.tools.benchmark.Harness
25 * @see Product
26 * @see ObjectOutputStream
27 * @see ObjectInputStream
28 */
29 public class JavaObjectSerialization implements Product {
30
31 public void serialize(Object object, OutputStream output) throws Exception {
32 ObjectOutputStream objectOutputStream = new ObjectOutputStream(output);
33 objectOutputStream.writeObject(object);
34 }
35
36 public Object deserialize(InputStream input) throws Exception {
37 ObjectInputStream objectInputStream = new ObjectInputStream(input);
38 return objectInputStream.readObject();
39 }
40
41 public String toString() {
42 return "Java object serialization";
43 }
44
45 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.BEAStaxDriver;
13
14 /**
15 * Uses XStream with the BEA StAX driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see BEAStaxDriver
23 */
24 public class XStreamBEAStax extends XStreamDriver {
25
26 public XStreamBEAStax() {
27 super(new BEAStaxDriver(), "XML with BEA StAX parser");
28 }
29 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.io.binary.BinaryStreamWriter;
16 import com.thoughtworks.xstream.io.binary.BinaryStreamReader;
17
18 import java.io.OutputStream;
19 import java.io.InputStream;
20
21 /**
22 * Uses XStream with binary format instead of XML.
23 *
24 * @author Joe Walnes
25 * @see com.thoughtworks.xstream.tools.benchmark.Harness
26 * @see Product
27 * @see XStream
28 * @see BinaryStreamReader
29 * @see BinaryStreamWriter
30 */
31 public class XStreamBinary implements Product {
32
33 private final XStream xstream;
34
35 public XStreamBinary() {
36 this.xstream = new XStream();
37 }
38
39 public void serialize(Object object, OutputStream output) throws Exception {
40 xstream.marshal(object, new BinaryStreamWriter(output));
41 }
42
43 public Object deserialize(InputStream input) throws Exception {
44 return xstream.unmarshal(new BinaryStreamReader(input));
45 }
46
47 public String toString() {
48 return "XStream (binary format)";
49 }
50
51 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14 import com.thoughtworks.xstream.XStream;
15 import com.thoughtworks.xstream.io.xml.XppDriver;
16 import com.thoughtworks.xstream.io.xml.CompactWriter;
17
18 import java.io.OutputStream;
19 import java.io.InputStream;
20 import java.io.OutputStreamWriter;
21
22 /**
23 * Uses XStream with a compact XML output format.
24 *
25 * @author Joe Walnes
26 * @see com.thoughtworks.xstream.tools.benchmark.Harness
27 * @see Product
28 * @see XStream
29 * @see CompactWriter
30 */
31 public class XStreamCompact implements Product {
32
33 private final XStream xstream;
34
35 public XStreamCompact() {
36 this.xstream = new XStream(new XppDriver());
37 }
38
39 public void serialize(Object object, OutputStream output) throws Exception {
40 xstream.marshal(object, new CompactWriter(new OutputStreamWriter(output)));
41 }
42
43 public Object deserialize(InputStream input) throws Exception {
44 return xstream.fromXML(input);
45 }
46
47 public String toString() {
48 return "XStream (Compact XML)";
49 }
50
51 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.io.xml.DomDriver;
14
15 /**
16 * Uses XStream with the DOM driver for parsing XML.
17 *
18 * @author Joe Walnes
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see DomDriver
23 */
24 public class XStreamDom extends XStreamDriver {
25
26 public XStreamDom() {
27 super(new DomDriver(), "XML with DOM parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
13 import com.thoughtworks.xstream.io.xml.Dom4JDriver;
14 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
15
16 import java.io.Writer;
17
18 /**
19 * Uses XStream with the DOM4J driver for parsing XML.
20 *
21 * @author Joe Walnes
22 * @author J&ouml;rg Schaible
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see com.thoughtworks.xstream.tools.benchmark.Product
25 * @see com.thoughtworks.xstream.XStream
26 * @see Dom4JDriver
27 */
28 public class XStreamDom4J extends XStreamDriver {
29
30 public XStreamDom4J() {
31 super(new Dom4JDriver() {
32
33 public HierarchicalStreamWriter createWriter(Writer out) {
34 return new PrettyPrintWriter(out);
35 }
36
37 }, "XML with DOM4J parser");
38 }
39 }
0 /*
1 * Copyright (C) 2009, 2011 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 19.02.2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.javabean.JavaBeanConverter;
14 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
15 import com.thoughtworks.xstream.tools.benchmark.Product;
16 import com.thoughtworks.xstream.tools.benchmark.model.FiveBean;
17 import com.thoughtworks.xstream.tools.benchmark.model.OneBean;
18
19 import java.io.InputStream;
20 import java.io.OutputStream;
21
22
23 /**
24 * Generic XStream product based on an arbitrary driver.
25 *
26 * @see XStream
27 * @see Product
28 * @see HierarchicalStreamDriver
29 * @author Joe Walnes
30 * @author J&ouml;rg Schaible
31 * @since 1.4
32 */
33 public class XStreamDriver implements Product {
34
35 private final XStream xstream;
36 private final String desc;
37
38 /**
39 * Create a XStream product based on a driver.
40 *
41 * @param driver the driver to use for serialization/deserialization
42 * @param desc the driver description
43 *
44 * @since 1.4
45 */
46 public XStreamDriver(HierarchicalStreamDriver driver, String desc) {
47 this.xstream = new XStream(driver);
48 this.xstream.registerConverter(new JavaBeanConverter(this.xstream.getMapper()) {
49
50 public boolean canConvert(Class type) {
51 return type == OneBean.class || type == FiveBean.class;
52 }
53
54 });
55 this.desc = desc;
56 }
57
58 public void serialize(Object object, OutputStream output) throws Exception {
59 xstream.toXML(object, output);
60 }
61
62 public Object deserialize(InputStream input) throws Exception {
63 return xstream.fromXML(input);
64 }
65
66 public String toString() {
67 return "XStream (" + desc + ")";
68 }
69
70 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.JDomDriver;
13
14 /**
15 * Uses XStream with the JDOM driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see JDomDriver
23 */
24 public class XStreamJDom extends XStreamDriver {
25
26 public XStreamJDom() {
27 super(new JDomDriver(), "XML with JDOM parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.KXml2Driver;
13
14 /**
15 * Uses XStream with the kXML2 driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see KXml2Driver
23 */
24 public class XStreamKXml2 extends XStreamDriver {
25
26 public XStreamKXml2() {
27 super(new KXml2Driver(), "XML with kXML2 parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 05. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.KXml2DomDriver;
13
14 /**
15 * Uses XStream with the Xpp3 DOM driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see KXml2DomDriver
23 */
24 public class XStreamKXml2DOM extends XStreamDriver {
25
26 public XStreamKXml2DOM() {
27 super(new KXml2DomDriver(), "XML with kXML2 DOM parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.SjsxpDriver;
13
14 /**
15 * Uses XStream with the SJSXP StAX driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see SjsxpDriver
23 */
24 public class XStreamSjsxp extends XStreamDriver {
25
26 public XStreamSjsxp() {
27 super(new SjsxpDriver(), "XML with SJSXP StAX parser");
28 }
29 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.io.xml.StaxDriver;
14
15 /**
16 * Uses XStream with the default StAX driver for parsing XML.
17 *
18 * @author Joe Walnes
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see StaxDriver
23 */
24 public class XStreamStax extends XStreamDriver {
25
26 public XStreamStax() {
27 super(new StaxDriver(), "XML with default StAX parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.WstxDriver;
13
14 /**
15 * Uses XStream with the Woodstox StAX driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see WstxDriver
23 */
24 public class XStreamWoodstox extends XStreamDriver {
25
26 public XStreamWoodstox() {
27 super(new WstxDriver(), "XML with Woodstox StAX parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.XomDriver;
13
14 /**
15 * Uses XStream with the XOM driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see XomDriver
23 */
24 public class XStreamXom extends XStreamDriver {
25
26 public XStreamXom() {
27 super(new XomDriver(), "XML with XOM parser");
28 }
29 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007, 2009 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.products;
12
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14
15
16 /**
17 * Uses XStream with the default XPP driver for parsing XML.
18 *
19 * @author Joe Walnes
20 * @see com.thoughtworks.xstream.tools.benchmark.Harness
21 * @see com.thoughtworks.xstream.tools.benchmark.Product
22 * @see com.thoughtworks.xstream.XStream
23 * @see XppDriver
24 */
25 public class XStreamXpp extends XStreamDriver {
26
27 public XStreamXpp() {
28 super(new XppDriver(), "XML with default XPP parser");
29 }
30
31 }
0 /*
1 * Copyright (C) 2009 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 30. April 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.Xpp3Driver;
13
14 /**
15 * Uses XStream with the Xpp3 driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see Xpp3Driver
23 */
24 public class XStreamXpp3 extends XStreamDriver {
25
26 public XStreamXpp3() {
27 super(new Xpp3Driver(), "XML with Xpp3 parser");
28 }
29 }
0 /*
1 * Copyright (C) 2009 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 05. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.products;
11
12 import com.thoughtworks.xstream.io.xml.Xpp3DomDriver;
13
14 /**
15 * Uses XStream with the kXML2 DOM driver for parsing XML.
16 *
17 * @author Joe Walnes
18 * @author J&ouml;rg Schaible
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see com.thoughtworks.xstream.tools.benchmark.Product
21 * @see com.thoughtworks.xstream.XStream
22 * @see Xpp3DomDriver
23 */
24 public class XStreamXpp3DOM extends XStreamDriver {
25
26 public XStreamXpp3DOM() {
27 super(new Xpp3DomDriver(), "XML with Xpp3 DOM parser");
28 }
29 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 22. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.reporters;
12
13 import com.thoughtworks.xstream.tools.benchmark.Reporter;
14 import com.thoughtworks.xstream.tools.benchmark.Metric;
15 import com.thoughtworks.xstream.tools.benchmark.Target;
16 import com.thoughtworks.xstream.tools.benchmark.Product;
17 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
18
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.Date;
26
27 public class HtmlReporter implements Reporter {
28
29 private final PrettyPrintWriter out;
30 private final String title;
31
32 private Metric currentMetric;
33 private double largestMetricForTarget;
34 private List resultsForTarget;
35
36 public HtmlReporter(File htmlFile, String title) throws IOException {
37 this.title = title;
38 out = new PrettyPrintWriter(new FileWriter(htmlFile));
39 }
40
41 public void startBenchmark() {
42 out.startNode("html");
43
44 out.startNode("head");
45 writeTag("title", title);
46 writeTag("style", css(), "type", "text/css");
47 out.endNode();
48
49 out.startNode("body");
50
51 writeTag("h1", title);
52 }
53
54 private String css() {
55 StringBuffer css = new StringBuffer("\n");
56 css.append("body, h1, h2, h3, td { font-family: arial; }\n");
57 css.append("h1 { text-align: center; }\n");
58 css.append("table, h3 { margin-left: 40px; }\n");
59 css.append("table, td, th { border: 1px solid #999; border-collapse: collapse; font-size: smaller; }\n");
60 css.append(".success { color: #090; }\n");
61 css.append(".fail { color: #900; }\n");
62 return css.toString();
63 }
64
65 public void startMetric(Metric metric) {
66 writeTag("h2", metric.toString());
67 currentMetric = metric;
68 }
69
70 public void startTarget(Target target) {
71 writeTag("h3", target.toString());
72 out.flush(); // Flush now, so progress can be seen with slow benchmarks.
73 largestMetricForTarget = 0;
74 resultsForTarget = new ArrayList();
75 }
76
77 public void metricRecorded(Product product, double result) {
78 // Keep a look out for the largest result.
79 if (result > largestMetricForTarget) {
80 largestMetricForTarget = result;
81 }
82 resultsForTarget.add(new MetricResult(product, result));
83 }
84
85 public void metricFailed(Product product, Exception e) {
86 resultsForTarget.add(new MetricResult(product, e));
87 }
88
89 public void endTarget(Target target) {
90 out.startNode("table");
91 out.startNode("tr");
92
93 writeTag("th", "Product");
94 writeTag("th", currentMetric.unit());
95
96 out.endNode();
97 for (Iterator iterator = resultsForTarget.iterator(); iterator.hasNext();) {
98 MetricResult metricResult = (MetricResult) iterator.next();
99 out.startNode("tr");
100
101 writeTag("td", metricResult.product.toString());
102
103 if (metricResult.exception == null) {
104 writeTag("td", String.valueOf(metricResult.result), "class", "success");
105
106 long percentage = Math.round(Math.abs(metricResult.result / largestMetricForTarget) * 100.0);
107 out.startNode("td");
108 out.addAttribute("style", "width: 400px;");
109 writeTag("div", "", "style", "height: 100%; width: " + percentage + "%; background-color: blue;");
110 out.endNode();
111 } else {
112 writeTag("td", "FAIL", "class", "fail");
113 writeTag("td", metricResult.exception.toString());
114 }
115
116 out.endNode();
117 }
118 out.endNode();
119 out.flush(); // Flush now, so progress can be seen with slow benchmarks.
120 }
121
122 private void writeTag(String tag, String value) {
123 out.startNode(tag);
124 out.setValue(value);
125 out.endNode();
126 }
127
128 private void writeTag(String tag, String value, String attributeName, String attributeValue) {
129 out.startNode(tag);
130 out.addAttribute(attributeName, attributeValue);
131 out.setValue(value);
132 out.endNode();
133 }
134
135 public void endMetric(Metric metric) {
136 }
137
138 public void endBenchmark() {
139 writeTag("p", new Date().toString());
140 out.endNode();
141 out.endNode();
142 out.close();
143 }
144
145 private static class MetricResult {
146 private final Product product;
147 private final double result;
148 private final Exception exception;
149
150 public MetricResult(Product product, double result) {
151 this.result = result;
152 this.product = product;
153 this.exception = null;
154 }
155
156 public MetricResult(Product product, Exception exception) {
157 this.product = product;
158 this.result = 0;
159 this.exception = exception;
160 }
161 }
162 }
0 /*
1 * Copyright (C) 2007, 2008 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 14. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reporters;
11
12 import com.thoughtworks.xstream.tools.benchmark.Metric;
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14 import com.thoughtworks.xstream.tools.benchmark.Reporter;
15 import com.thoughtworks.xstream.tools.benchmark.Target;
16
17 /**
18 * A reporter multiplexing the results to other Reporters.
19 *
20 * @author J&ouml;rg Schaible
21 * @since 1.3
22 */
23 public class MultiReporter implements Reporter {
24
25 private final Reporter[] reporter;
26
27 public MultiReporter(Reporter[] reporter) {
28 this.reporter = reporter;
29 }
30
31 public void endBenchmark() {
32 for (int i = 0; i < reporter.length; i++) {
33 reporter[i].endBenchmark();
34 }
35 }
36
37 public void endMetric(Metric metric) {
38 for (int i = 0; i < reporter.length; i++) {
39 reporter[i].endMetric(metric);
40 }
41 }
42
43 public void endTarget(Target target) {
44 for (int i = 0; i < reporter.length; i++) {
45 reporter[i].endTarget(target);
46 }
47 }
48
49 public void metricFailed(Product product, Exception e) {
50 for (int i = 0; i < reporter.length; i++) {
51 reporter[i].metricFailed(product, e);
52 }
53 }
54
55 public void metricRecorded(Product product, double result) {
56 for (int i = 0; i < reporter.length; i++) {
57 reporter[i].metricRecorded(product, result);
58 }
59 }
60
61 public void startBenchmark() {
62 for (int i = 0; i < reporter.length; i++) {
63 reporter[i].startBenchmark();
64 }
65 }
66
67 public void startMetric(Metric metric) {
68 for (int i = 0; i < reporter.length; i++) {
69 reporter[i].startMetric(metric);
70 }
71 }
72
73 public void startTarget(Target target) {
74 for (int i = 0; i < reporter.length; i++) {
75 reporter[i].startTarget(target);
76 }
77 }
78
79 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.reporters;
12
13 import com.thoughtworks.xstream.tools.benchmark.Metric;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.Reporter;
16 import com.thoughtworks.xstream.tools.benchmark.Target;
17
18 import java.io.PrintWriter;
19 import java.io.Writer;
20
21 /**
22 * Reports results of Harness in text form designed for human reading.
23 *
24 * @author Joe Walnes
25 * @see com.thoughtworks.xstream.tools.benchmark.Harness
26 * @see Reporter
27 */
28 public class TextReporter implements Reporter {
29
30 private final PrintWriter out;
31 private Metric currentMetric;
32
33 public TextReporter(PrintWriter out) {
34 this.out = out;
35 }
36
37 public TextReporter(Writer out) {
38 this(new PrintWriter(out));
39 }
40
41 /**
42 * Reports to System.out.
43 */
44 public TextReporter() {
45 this(new PrintWriter(System.out, true));
46 }
47
48 public void startBenchmark() {
49 }
50
51 public void startMetric(Metric metric) {
52 currentMetric = metric;
53 out.println("======================================================================");
54 out.println(metric);
55 out.println("======================================================================");
56 }
57
58 public void startTarget(Target target) {
59 out.println("* " + target + "");
60 }
61
62 public void metricRecorded(Product product, double result) {
63 out.println(" - " + pad(product.toString()) + " " + result + " " + currentMetric.unit());
64 }
65
66 public void metricFailed(Product product, Exception e) {
67 out.println(" - " + pad(product.toString()) + " FAILED (" + e + ")");
68 }
69
70 public void endTarget(Target target) {
71 }
72
73 public void endMetric(Metric metric) {
74 out.println();
75 currentMetric = null;
76 }
77
78 public void endBenchmark() {
79 out.flush();
80 }
81
82 private String pad(String value) {
83 StringBuffer result = new StringBuffer();
84 result.append(value);
85 while (result.length() < 50) {
86 result.append('.');
87 }
88 return result.toString();
89 }
90 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13
14 import java.io.File;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Locale;
18
19 /**
20 * Target containing basic types.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class BasicTarget implements Target {
26
27 private List list;
28
29 public BasicTarget() {
30 list = new ArrayList();
31 list.add(new Integer(1));
32 list.add(new Byte((byte)2));
33 list.add(new Short((short)3));
34 list.add(new Long(4));
35 list.add("Profile");
36 list.add(Boolean.TRUE);
37 list.add(new Float(1.2f));
38 list.add(new Double(1.2f));
39 list.add(new File("profile.txt"));
40 list.add(Locale.ENGLISH);
41 }
42
43 public boolean isEqual(Object other) {
44 return list.equals(other);
45 }
46
47 public Object target() {
48 return list;
49 }
50
51 public String toString() {
52 return "SingleValue Converters";
53 }
54 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13
14 import java.awt.Color;
15 import java.lang.reflect.Field;
16 import java.lang.reflect.InvocationHandler;
17 import java.lang.reflect.Method;
18 import java.lang.reflect.Proxy;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Properties;
22
23 /**
24 * Target containing extended types.
25 *
26 * @author J&ouml;rg Schaible
27 * @since 1.4
28 */
29 public class ExtendedTarget implements Target {
30
31 private final static Method EQUALS;
32 private final static Field LIST;
33 static {
34 Method method;
35 Field field;
36 try {
37 method = Object.class.getMethod("equals", new Class[]{Object.class});
38 field = ExtendedTarget.class.getDeclaredField("list");
39 } catch (NoSuchMethodException e) {
40 throw new ExceptionInInitializerError(e);
41 } catch (NoSuchFieldException e) {
42 throw new ExceptionInInitializerError(e);
43 }
44 EQUALS = method;
45 LIST = field;
46 }
47
48 private List list;
49
50 public ExtendedTarget() {
51 list = new ArrayList();
52 list.add(new Color(128, 0, 255));
53 Object proxy = Proxy
54 .newProxyInstance(
55 getClass().getClassLoader(), new Class[]{
56 Runnable.class, Cloneable.class, Comparable.class},
57 new RunnableInvocationHandler());
58 list.add(proxy);
59 list.add(ExtendedTarget.class);
60 list.add(EQUALS);
61 list.add(LIST);
62 Properties properties = new Properties();
63 properties.put("1", "one");
64 properties.put("2", "two");
65 properties.put("3", "three");
66 list.add(properties);
67 }
68
69 public boolean isEqual(Object other) {
70 return list.equals(other);
71 }
72
73 public Object target() {
74 return list;
75 }
76
77 public String toString() {
78 return "Standard Converters";
79 }
80
81 static class RunnableInvocationHandler implements InvocationHandler {
82
83 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
84 if (method.equals(EQUALS)) {
85 return new Boolean(args[0] instanceof Runnable);
86 } else if (method.getName().equals("hashCode")) {
87 return new Integer(System.identityHashCode(proxy));
88 } else if (method.getName().equals("toString")) {
89 return "Proxy" + System.identityHashCode(proxy);
90 } else if (method.getName().equals("getClass")) {
91 return proxy.getClass();
92 }
93 return null;
94 }
95
96 }
97 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.targets;
12
13 import com.thoughtworks.xstream.tools.benchmark.Target;
14
15 import javax.swing.*;
16
17 /**
18 * A Swing JTree instance, which is a suitably complex object graph.
19 *
20 * @author Joe Walnes
21 * @see com.thoughtworks.xstream.tools.benchmark.Harness
22 * @see Target
23 * @see JTree
24 */
25 public class JTreeTarget implements Target {
26
27 private JTree jTree = new JTree();
28
29 public String toString() {
30 return "JTree";
31 }
32
33 public Object target() {
34 return jTree;
35 }
36
37 public boolean isEqual(Object other) {
38 // TODO: Check if JTrees are equal. -Joe
39 return true;
40 }
41
42 }
0 /*
1 * Copyright (C) 2009, 2011 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 05. May 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.FiveBean;
14 import com.thoughtworks.xstream.tools.benchmark.model.OneBean;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 /**
20 * Target containing basic types using the JavaBeanConverter.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class JavaBeanTarget implements Target {
26
27 private List list;
28
29 public JavaBeanTarget() {
30 list = new ArrayList();
31 for (int i = 0; i < 5; ++i) {
32 OneBean one = new OneBean();
33 one.setOne(Integer.toString(i));
34 list.add(one);
35 }
36 FiveBean five = new FiveBean();
37 five.setOne("1");
38 five.setTwo(2);
39 five.setThree(true);
40 five.setFour('4');
41 five.setFive(new StringBuffer("5"));
42 list.add(five);
43 }
44
45 public boolean isEqual(Object other) {
46 return list.equals(other);
47 }
48
49 public Object target() {
50 return list;
51 }
52
53 public String toString() {
54 return "JavaBean Converter";
55 }
56 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.targets;
12
13 import com.thoughtworks.xstream.tools.benchmark.Target;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 /**
19 * An ArrayList of user defined class ({@link Person}) instances to serialize.
20 *
21 * @author Joe Walnes
22 * @see com.thoughtworks.xstream.tools.benchmark.Harness
23 * @see Target
24 */
25 public class ListTarget implements Target {
26
27 private List list = new ArrayList();
28
29 public ListTarget(int size) {
30 for (int i = 0; i < size; i++) {
31 Person person = new Person();
32 person.firstName = "First name " + i;
33 person.lastName = "Last name " + i;
34 list.add(person);
35 }
36 }
37
38 public String toString() {
39 return "List of " + list.size() + " user defined objects";
40 }
41
42 public Object target() {
43 return list;
44 }
45
46 public boolean isEqual(Object other) {
47 return list.equals(other);
48 }
49 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.targets;
12
13 import java.util.Date;
14 import java.io.Serializable;
15
16 /**
17 * @see UserDefinedClassTarget
18 */
19 public class Person implements Serializable {
20
21 public String firstName;
22 public String lastName;
23 public Date dateOfBirth;
24
25 public boolean equals(Object o) {
26 if (this == o) return true;
27 if (o == null || getClass() != o.getClass()) return false;
28
29 final Person person = (Person) o;
30
31 if (dateOfBirth != null ? !dateOfBirth.equals(person.dateOfBirth) : person.dateOfBirth != null) return false;
32 if (firstName != null ? !firstName.equals(person.firstName) : person.firstName != null) return false;
33 return !(lastName != null ? !lastName.equals(person.lastName) : person.lastName != null);
34 }
35
36 public int hashCode() {
37 int result;
38 result = (firstName != null ? firstName.hashCode() : 0);
39 result = 29 * result + (lastName != null ? lastName.hashCode() : 0);
40 result = 29 * result + (dateOfBirth != null ? dateOfBirth.hashCode() : 0);
41 return result;
42 }
43 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.Five;
14 import com.thoughtworks.xstream.tools.benchmark.model.One;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 /**
20 * Target containing basic types using the ReflectionConverter.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class ReflectionTarget implements Target {
26
27 private List list;
28
29 public ReflectionTarget() {
30 list = new ArrayList();
31 for (int i = 0; i < 5; ++i) {
32 list.add(new One(Integer.toString(i)));
33 }
34 list.add(new Five("1", 2, true, '4', new StringBuffer("5")));
35 }
36
37 public boolean isEqual(Object other) {
38 return list.equals(other);
39 }
40
41 public Object target() {
42 return list;
43 }
44
45 public String toString() {
46 return "Reflection Converter";
47 }
48 }
0 /*
1 * Copyright (C) 2008, 2009, 2011 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.SerializableFive;
14 import com.thoughtworks.xstream.tools.benchmark.model.SerializableOne;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 /**
20 * Target containing basic types using the SerializableConverter.
21 *
22 * @author J&ouml;rg Schaible
23 * @since 1.4
24 */
25 public class SerializableTarget implements Target {
26
27 private List list;
28
29 public SerializableTarget() {
30 list = new ArrayList();
31 for (int i = 0; i < 5; ++i) {
32 list.add(new SerializableOne(Integer.toString(i)));
33 }
34 list.add(new SerializableFive("1", 2, true, '4', new StringBuffer("5")));
35 }
36
37 public boolean isEqual(Object other) {
38 return list.equals(other);
39 }
40
41 public Object target() {
42 return list;
43 }
44
45 public String toString() {
46 return "Serializable types";
47 }
48 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.targets;
12
13 import com.thoughtworks.xstream.tools.benchmark.Target;
14
15 /**
16 * A small java.lang.String target.
17 *
18 * @author Joe Walnes
19 * @see com.thoughtworks.xstream.tools.benchmark.Harness
20 * @see Target
21 */
22 public class StringTarget implements Target {
23
24 private final String string = "Hello World!";
25
26 public String toString() {
27 return "Simple string";
28 }
29
30 public Object target() {
31 return string;
32 }
33
34 public boolean isEqual(Object other) {
35 return string.equals(other);
36 }
37
38 }
0 /*
1 * Copyright (C) 2006 Joe Walnes.
2 * Copyright (C) 2006, 2007 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 15. July 2006 by Joe Walnes
10 */
11 package com.thoughtworks.xstream.tools.benchmark.targets;
12
13 import com.thoughtworks.xstream.tools.benchmark.Target;
14
15 import java.util.Date;
16
17 /**
18 * A user defined class ({@link Person}) to serialize that contains a few simple fields.
19 *
20 * @author Joe Walnes
21 * @see com.thoughtworks.xstream.tools.benchmark.Harness
22 * @see Target
23 */
24 public class UserDefinedClassTarget implements Target {
25
26 private final Person person;
27
28 public UserDefinedClassTarget() {
29 person = new Person();
30 person.firstName = "Joe";
31 person.lastName = "Walnes";
32 person.dateOfBirth = new Date();
33 }
34
35 public String toString() {
36 return "User defined class";
37 }
38
39 public Object target() {
40 return person;
41 }
42
43 public boolean isEqual(Object other) {
44 return person.equals(other);
45 }
46 }
0 /*
1 * Copyright (C) 2008, 2009 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache;
11
12 import com.thoughtworks.xstream.tools.benchmark.Harness;
13 import com.thoughtworks.xstream.tools.benchmark.Product;
14 import com.thoughtworks.xstream.tools.benchmark.cache.products.AliasedAttributeCache;
15 import com.thoughtworks.xstream.tools.benchmark.cache.products.Cache122;
16 import com.thoughtworks.xstream.tools.benchmark.cache.products.DefaultImplementationCache;
17 import com.thoughtworks.xstream.tools.benchmark.cache.products.NoCache;
18 import com.thoughtworks.xstream.tools.benchmark.cache.products.RealClassCache;
19 import com.thoughtworks.xstream.tools.benchmark.cache.products.SerializedClassCache;
20 import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
21 import com.thoughtworks.xstream.tools.benchmark.metrics.SerializationSpeedMetric;
22 import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
23 import com.thoughtworks.xstream.tools.benchmark.targets.BasicTarget;
24 import com.thoughtworks.xstream.tools.benchmark.targets.ExtendedTarget;
25 import com.thoughtworks.xstream.tools.benchmark.targets.ReflectionTarget;
26 import com.thoughtworks.xstream.tools.benchmark.targets.SerializableTarget;
27
28 import org.apache.commons.cli.CommandLine;
29 import org.apache.commons.cli.Options;
30 import org.apache.commons.cli.ParseException;
31 import org.apache.commons.cli.Parser;
32 import org.apache.commons.cli.PosixParser;
33
34 import java.io.PrintWriter;
35
36
37 /**
38 * Main application to run harness for Profile benchmark.
39 *
40 * @author J&ouml;rg Schaible
41 */
42 public class CacheBenchmark {
43 public static void main(String[] args) {
44 int counter = 10000;
45 Product product = null;
46
47 Options options = new Options();
48 options.addOption("p", "product", true, "Class name of the product to use for benchmark");
49 options.addOption("n", true, "Number of repetitions");
50
51 Parser parser = new PosixParser();
52 try {
53 CommandLine commandLine = parser.parse(options, args);
54 if (commandLine.hasOption('p')) {
55 product = (Product)Class.forName(commandLine.getOptionValue('p')).newInstance();
56 }
57 if (commandLine.hasOption('n')) {
58 counter = Integer.parseInt(commandLine.getOptionValue('n'));
59 }
60 } catch (ParseException e) {
61 e.printStackTrace();
62 } catch (InstantiationException e) {
63 e.printStackTrace();
64 } catch (IllegalAccessException e) {
65 e.printStackTrace();
66 } catch (ClassNotFoundException e) {
67 e.printStackTrace();
68 }
69
70 Harness harness = new Harness();
71 // harness.addMetric(new SerializationSpeedMetric(1) {
72 // public String toString() {
73 // return "Initial run serialization";
74 // }
75 // });
76 // harness.addMetric(new DeserializationSpeedMetric(1, false) {
77 // public String toString() {
78 // return "Initial run deserialization";
79 // }
80 // });
81 harness.addMetric(new SerializationSpeedMetric(counter));
82 harness.addMetric(new DeserializationSpeedMetric(counter, false));
83 if (product == null) {
84 harness.addProduct(new NoCache());
85 harness.addProduct(new Cache122());
86 harness.addProduct(new RealClassCache());
87 harness.addProduct(new SerializedClassCache());
88 harness.addProduct(new AliasedAttributeCache());
89 harness.addProduct(new DefaultImplementationCache());
90 harness.addProduct(new NoCache());
91 } else {
92 harness.addProduct(product);
93 }
94 harness.addTarget(new BasicTarget());
95 harness.addTarget(new ExtendedTarget());
96 harness.addTarget(new ReflectionTarget());
97 harness.addTarget(new SerializableTarget());
98 harness.run(new TextReporter(new PrintWriter(System.out, true)));
99 System.out.println("Done.");
100 }
101 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 02. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.mapper.Mapper;
13 import com.thoughtworks.xstream.mapper.MapperWrapper;
14
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
20
21 /**
22 * Uses XStream with a CachingMapper caching the aliasForAttribute method.
23 *
24 * @author J&ouml;rg Schaible
25 */
26 public class AliasedAttributeCache extends XStreamCache {
27
28 protected List getMappers() {
29 List list = super.getMappers();
30 list.add(CachingMapper.class);
31 return list;
32 }
33
34 public String toString() {
35 return "Aliased Attribute Cache";
36 }
37
38 public static class CachingMapper extends MapperWrapper {
39
40 private transient Map attributeAliasCache;
41
42 public CachingMapper(Mapper wrapped) {
43 super(wrapped);
44 readResolve();
45 }
46
47 public String aliasForAttribute(String attribute) {
48 String alias = (String) attributeAliasCache.get(attribute);
49 if (alias != null) {
50 return alias;
51 }
52
53 String result = super.aliasForAttribute(attribute);
54 attributeAliasCache.put(attribute, alias);
55 return result;
56 }
57
58 private Object readResolve() {
59 attributeAliasCache = Collections.synchronizedMap(new HashMap(256));
60 return this;
61 }
62
63 }
64 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.core.JVM;
13 import com.thoughtworks.xstream.mapper.ImplicitCollectionMapper;
14 import com.thoughtworks.xstream.mapper.Mapper;
15 import com.thoughtworks.xstream.mapper.MapperWrapper;
16
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22
23 /**
24 * Uses XStream with the CachingMapper of 1.2.2.
25 *
26 * @author J&ouml;rg Schaible
27 */
28 public class Cache122 extends XStreamCache {
29
30 protected List getMappers() {
31 List list = super.getMappers();
32 Object cglibMapper = list.remove(1);
33 Object dynProxyMapper = null;
34 if (JVM.loadClassForName("net.sf.cglib.proxy.Enhancer") != null) {
35 dynProxyMapper = list.remove(1);
36 }
37 int idx = list.indexOf(ImplicitCollectionMapper.class);
38 if (JVM.loadClassForName("net.sf.cglib.proxy.Enhancer") != null) {
39 list.add(idx+1, dynProxyMapper);
40 }
41 list.add(idx+1, cglibMapper);
42 list.add(CachingMapper.class);
43 return list;
44 }
45
46 public String toString() {
47 return "XStream 1.2.2 Cache";
48 }
49
50 public static class CachingMapper extends MapperWrapper {
51
52 private transient Map realClassCache;
53
54 public CachingMapper(Mapper wrapped) {
55 super(wrapped);
56 realClassCache = Collections.synchronizedMap(new HashMap());
57 }
58
59 public Class realClass(String elementName) {
60 Class cached = (Class)realClassCache.get(elementName);
61 if (cached != null) {
62 return cached;
63 }
64
65 Class result = super.realClass(elementName);
66 realClassCache.put(elementName, result);
67 return result;
68 }
69
70 private Object readResolve() {
71 realClassCache = Collections.synchronizedMap(new HashMap());
72 return this;
73 }
74
75 }
76 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.mapper.Mapper;
13 import com.thoughtworks.xstream.mapper.MapperWrapper;
14
15 import java.lang.ref.WeakReference;
16 import java.util.Collections;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.WeakHashMap;
20
21
22 /**
23 * Uses XStream with a CachingMapper caching the aliasForAttribute method.
24 *
25 * @author J&ouml;rg Schaible
26 */
27 public class DefaultImplementationCache extends XStreamCache {
28
29 protected List getMappers() {
30 List list = super.getMappers();
31 list.add(CachingMapper.class);
32 return list;
33 }
34
35 public String toString() {
36 return "Default Implementation Cache";
37 }
38
39 public static class CachingMapper extends MapperWrapper {
40
41 private transient Map defaultImplementationCache;
42
43 public CachingMapper(Mapper wrapped) {
44 super(wrapped);
45 readResolve();
46 }
47
48 public Class defaultImplementationOf(Class type) {
49 WeakReference reference = (WeakReference) defaultImplementationCache.get(type);
50 if (reference != null) {
51 Class cached = (Class) reference.get();
52 if (cached != null) {
53 return cached;
54 }
55 }
56
57 Class result = super.defaultImplementationOf(type);
58 defaultImplementationCache.put(type, new WeakReference(result));
59 return result;
60 }
61
62 private Object readResolve() {
63 defaultImplementationCache = Collections.synchronizedMap(new WeakHashMap(128));
64 return this;
65 }
66
67 }
68 }
0 /*
1 * Copyright (C) 2008, 2009 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12
13
14 /**
15 * Uses XStream with the CachingMapper of 1.2.2.
16 *
17 * @author J&ouml;rg Schaible
18 */
19 public class NoCache extends XStreamCache {
20
21 public String toString() {
22 return "No Cache";
23 }
24 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 02. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.mapper.Mapper;
13 import com.thoughtworks.xstream.mapper.MapperWrapper;
14
15 import java.lang.ref.WeakReference;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22 /**
23 * Uses XStream with a CachingMapper caching the realClass method.
24 *
25 * @author J&ouml;rg Schaible
26 */
27 public class RealClassCache extends XStreamCache {
28
29 protected List getMappers() {
30 List list = super.getMappers();
31 list.add(CachingMapper.class);
32 return list;
33 }
34
35 public String toString() {
36 return "Real Class Cache";
37 }
38
39 public static class CachingMapper extends MapperWrapper {
40
41 private transient Map realClassCache;
42
43 public CachingMapper(Mapper wrapped) {
44 super(wrapped);
45 readResolve();
46 }
47
48 public Class realClass(String elementName) {
49 WeakReference reference = (WeakReference) realClassCache.get(elementName);
50 if (reference != null) {
51 Class cached = (Class) reference.get();
52 if (cached != null) {
53 return cached;
54 }
55 }
56
57 Class result = super.realClass(elementName);
58 realClassCache.put(elementName, new WeakReference(result));
59 return result;
60 }
61
62 private Object readResolve() {
63 realClassCache = Collections.synchronizedMap(new HashMap(128));
64 return this;
65 }
66
67 }
68 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 04. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.mapper.Mapper;
13 import com.thoughtworks.xstream.mapper.MapperWrapper;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.WeakHashMap;
19
20
21 /**
22 * Uses XStream with a CachingMapper caching the aliasForAttribute method.
23 *
24 * @author J&ouml;rg Schaible
25 */
26 public class SerializedClassCache extends XStreamCache {
27
28 protected List getMappers() {
29 List list = super.getMappers();
30 list.add(CachingMapper.class);
31 return list;
32 }
33
34 public String toString() {
35 return "Serialized Class Cache";
36 }
37
38 public static class CachingMapper extends MapperWrapper {
39
40 private transient Map serializedClassCache;
41
42 public CachingMapper(Mapper wrapped) {
43 super(wrapped);
44 readResolve();
45 }
46
47 public String serializedClass(Class type) {
48 String alias = (String) serializedClassCache.get(type);
49 if (alias != null) {
50 return alias;
51 }
52
53 String result = super.serializedClass(type);
54 serializedClassCache.put(type, alias);
55 return result;
56 }
57
58 private Object readResolve() {
59 serializedClassCache = Collections.synchronizedMap(new WeakHashMap(128));
60 return this;
61 }
62
63 }
64 }
0 /*
1 * Copyright (C) 2008, 2009, 2013 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 01. January 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.cache.products;
11
12 import com.thoughtworks.xstream.InitializationException;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.converters.ConverterLookup;
15 import com.thoughtworks.xstream.core.ClassLoaderReference;
16 import com.thoughtworks.xstream.core.DefaultConverterLookup;
17 import com.thoughtworks.xstream.core.JVM;
18 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
19 import com.thoughtworks.xstream.core.util.DependencyInjectionFactory;
20 import com.thoughtworks.xstream.core.util.TypedNull;
21 import com.thoughtworks.xstream.io.xml.XppDriver;
22 import com.thoughtworks.xstream.mapper.ArrayMapper;
23 import com.thoughtworks.xstream.mapper.AttributeAliasingMapper;
24 import com.thoughtworks.xstream.mapper.AttributeMapper;
25 import com.thoughtworks.xstream.mapper.ClassAliasingMapper;
26 import com.thoughtworks.xstream.mapper.DefaultImplementationsMapper;
27 import com.thoughtworks.xstream.mapper.DefaultMapper;
28 import com.thoughtworks.xstream.mapper.DynamicProxyMapper;
29 import com.thoughtworks.xstream.mapper.FieldAliasingMapper;
30 import com.thoughtworks.xstream.mapper.ImmutableTypesMapper;
31 import com.thoughtworks.xstream.mapper.ImplicitCollectionMapper;
32 import com.thoughtworks.xstream.mapper.LocalConversionMapper;
33 import com.thoughtworks.xstream.mapper.Mapper;
34 import com.thoughtworks.xstream.mapper.OuterClassMapper;
35 import com.thoughtworks.xstream.tools.benchmark.Product;
36 import com.thoughtworks.xstream.tools.benchmark.model.Five;
37 import com.thoughtworks.xstream.tools.benchmark.model.One;
38 import com.thoughtworks.xstream.tools.benchmark.model.SerializableFive;
39 import com.thoughtworks.xstream.tools.benchmark.model.SerializableOne;
40
41 import java.io.InputStream;
42 import java.io.OutputStream;
43 import java.util.ArrayList;
44 import java.util.Iterator;
45 import java.util.List;
46
47
48 /**
49 * Uses XStream with the XPP driver.
50 *
51 * @author J&ouml;rg Schaible
52 */
53 public abstract class XStreamCache implements Product {
54
55 private final XStream xstream;
56
57 public XStreamCache() {
58 ClassLoaderReference classLoaderReference = new ClassLoaderReference(
59 new CompositeClassLoader());
60 DefaultConverterLookup converterLookup = new DefaultConverterLookup();
61 xstream = new XStream(
62 JVM.newReflectionProvider(), new XppDriver(), classLoaderReference, buildMapper(
63 getMappers(), classLoaderReference, converterLookup), converterLookup, converterLookup);
64 xstream.alias("one", One.class);
65 xstream.alias("five", Five.class);
66 xstream.alias("ser-one", SerializableOne.class);
67 xstream.alias("ser-five", SerializableFive.class);
68 }
69
70 public void serialize(Object object, OutputStream output) throws Exception {
71 xstream.toXML(object, output);
72 }
73
74 public Object deserialize(InputStream input) throws Exception {
75 return xstream.fromXML(input);
76 }
77
78 protected List getMappers() {
79 List mappers = new ArrayList();
80 mappers.add(DefaultMapper.class);
81 if (JVM.loadClassForName("net.sf.cglib.proxy.Enhancer") != null) {
82 mappers.add(JVM.loadClassForName("com.thoughtworks.xstream.mapper.CGLIBMapper"));
83 }
84 mappers.add(DynamicProxyMapper.class);
85 mappers.add(ClassAliasingMapper.class);
86 mappers.add(FieldAliasingMapper.class);
87 mappers.add(AttributeAliasingMapper.class);
88 mappers.add(ImplicitCollectionMapper.class);
89 mappers.add(OuterClassMapper.class);
90 mappers.add(ArrayMapper.class);
91 mappers.add(LocalConversionMapper.class);
92 mappers.add(DefaultImplementationsMapper.class);
93 if (JVM.is15()) {
94 mappers.add(JVM.loadClassForName("com.thoughtworks.xstream.mapper.EnumMapper"));
95 } else {
96 mappers.add(AttributeMapper.class);
97 }
98 mappers.add(ImmutableTypesMapper.class);
99 if (JVM.is15()) {
100 mappers.add(JVM.loadClassForName("com.thoughtworks.xstream.mapper.AnnotationMapper"));
101 }
102 return mappers;
103 }
104
105 private Mapper buildMapper(List mappers, ClassLoaderReference classLoaderReference,
106 ConverterLookup converterLookup) {
107 final Object[] arguments = new Object[]{
108 new TypedNull(Mapper.class), converterLookup, classLoaderReference,
109 JVM.newReflectionProvider()};
110 for (final Iterator iter = mappers.iterator(); iter.hasNext();) {
111 final Class mapperType = (Class)iter.next();
112 try {
113 arguments[0] = DependencyInjectionFactory.newInstance(mapperType, arguments);
114 } catch (Exception e) {
115 throw new InitializationException("Could not instantiate mapper : "
116 + mapperType.getName(), e);
117 }
118 }
119 return (Mapper)arguments[0];
120 }
121 }
0 /*
1 * Copyright (C) 2009 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 18. February 2009 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.parsers;
11
12 import com.thoughtworks.xstream.core.JVM;
13 import com.thoughtworks.xstream.tools.benchmark.Harness;
14 import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
15 import com.thoughtworks.xstream.tools.benchmark.products.XStreamDom;
16 import com.thoughtworks.xstream.tools.benchmark.products.XStreamDom4J;
17 import com.thoughtworks.xstream.tools.benchmark.products.XStreamBEAStax;
18 import com.thoughtworks.xstream.tools.benchmark.products.XStreamJDom;
19 import com.thoughtworks.xstream.tools.benchmark.products.XStreamKXml2;
20 import com.thoughtworks.xstream.tools.benchmark.products.XStreamKXml2DOM;
21 import com.thoughtworks.xstream.tools.benchmark.products.XStreamSjsxp;
22 import com.thoughtworks.xstream.tools.benchmark.products.XStreamWoodstox;
23 import com.thoughtworks.xstream.tools.benchmark.products.XStreamXom;
24 import com.thoughtworks.xstream.tools.benchmark.products.XStreamXpp3;
25 import com.thoughtworks.xstream.tools.benchmark.products.XStreamXpp3DOM;
26 import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
27 import com.thoughtworks.xstream.tools.benchmark.targets.BasicTarget;
28 import com.thoughtworks.xstream.tools.benchmark.targets.ExtendedTarget;
29 import com.thoughtworks.xstream.tools.benchmark.targets.JavaBeanTarget;
30 import com.thoughtworks.xstream.tools.benchmark.targets.ReflectionTarget;
31 import com.thoughtworks.xstream.tools.benchmark.targets.SerializableTarget;
32 import com.thoughtworks.xstream.tools.model.targets.FieldReflection;
33 import com.thoughtworks.xstream.tools.model.targets.HierarchyLevelReflection;
34 import com.thoughtworks.xstream.tools.model.targets.InnerClassesReflection;
35 import com.thoughtworks.xstream.tools.model.targets.StaticInnerClassesReflection;
36
37 import org.apache.commons.cli.CommandLine;
38 import org.apache.commons.cli.Options;
39 import org.apache.commons.cli.ParseException;
40 import org.apache.commons.cli.Parser;
41 import org.apache.commons.cli.PosixParser;
42
43 import java.io.PrintWriter;
44
45
46 /**
47 * Main application to run harness for Profile benchmark.
48 *
49 * @author J&ouml;rg Schaible
50 */
51 public class ParserBenchmark {
52 public static void main(String[] args) {
53 int counter = 1000;
54
55 Options options = new Options();
56 options.addOption("p", "product", true, "Class name of the product to use for benchmark");
57 options.addOption("n", true, "Number of repetitions");
58
59 Harness harness = new Harness();
60 harness.addMetric(new DeserializationSpeedMetric(0, false) {
61 public String toString() {
62 return "Initial run deserialization";
63 }
64 });
65
66 Parser parser = new PosixParser();
67 try {
68 CommandLine commandLine = parser.parse(options, args);
69 String name = null;
70 if (commandLine.hasOption('p')) {
71 name = commandLine.getOptionValue('p');
72 }
73 if (name == null || name.equals("DOM")) {
74 harness.addProduct(new XStreamDom());
75 }
76 if (name == null || name.equals("JDOM")) {
77 harness.addProduct(new XStreamJDom());
78 }
79 if (name == null || name.equals("DOM4J")) {
80 harness.addProduct(new XStreamDom4J());
81 }
82 if (name == null || name.equals("XOM")) {
83 harness.addProduct(new XStreamXom());
84 }
85 if (name == null || name.equals("BEAStAX")) {
86 harness.addProduct(new XStreamBEAStax());
87 }
88 if (name == null || name.equals("Woodstox")) {
89 harness.addProduct(new XStreamWoodstox());
90 }
91 if (JVM.is16() && (name == null || name.equals("SJSXP"))) {
92 harness.addProduct(new XStreamSjsxp());
93 }
94 if (name == null || name.equals("Xpp3")) {
95 harness.addProduct(new XStreamXpp3());
96 }
97 if (name == null || name.equals("kXML2")) {
98 harness.addProduct(new XStreamKXml2());
99 }
100 if (name == null || name.equals("Xpp3DOM")) {
101 harness.addProduct(new XStreamXpp3DOM());
102 }
103 if (name == null || name.equals("kXML2DOM")) {
104 harness.addProduct(new XStreamKXml2DOM());
105 }
106 if (commandLine.hasOption('n')) {
107 counter = Integer.parseInt(commandLine.getOptionValue('n'));
108 }
109 } catch (ParseException e) {
110 e.printStackTrace();
111 }
112
113 harness.addMetric(new DeserializationSpeedMetric(counter, false));
114 harness.addTarget(new BasicTarget());
115 harness.addTarget(new ExtendedTarget());
116 harness.addTarget(new ReflectionTarget());
117 harness.addTarget(new SerializableTarget());
118 harness.addTarget(new JavaBeanTarget());
119 if (false) {
120 harness.addTarget(new FieldReflection());
121 harness.addTarget(new HierarchyLevelReflection());
122 harness.addTarget(new InnerClassesReflection());
123 harness.addTarget(new StaticInnerClassesReflection());
124 }
125 harness.run(new TextReporter(new PrintWriter(System.out, true)));
126 System.out.println("Done.");
127 }
128 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reflection;
11
12 import com.thoughtworks.xstream.tools.benchmark.Harness;
13 import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
14 import com.thoughtworks.xstream.tools.benchmark.metrics.SerializationSpeedMetric;
15 import com.thoughtworks.xstream.tools.benchmark.reflection.products.XStreamClassAliases;
16 import com.thoughtworks.xstream.tools.benchmark.reflection.products.XStreamFieldAliases;
17 import com.thoughtworks.xstream.tools.benchmark.reflection.products.XStreamLocalAttributeAliases;
18 import com.thoughtworks.xstream.tools.benchmark.reflection.products.XStreamPlain;
19 import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
20 import com.thoughtworks.xstream.tools.model.targets.FieldReflection;
21 import com.thoughtworks.xstream.tools.model.targets.HierarchyLevelReflection;
22 import com.thoughtworks.xstream.tools.model.targets.InnerClassesReflection;
23 import com.thoughtworks.xstream.tools.model.targets.StaticInnerClassesReflection;
24
25
26 /**
27 * Main application to run harness for Reflection benchmark.
28 *
29 * @author J&ouml;rg Schaible
30 */
31 public class ReflectionBenchmark {
32 public static void main(String[] args) {
33 Harness harness = new Harness();
34 harness.addMetric(new SerializationSpeedMetric(10));
35 harness.addMetric(new DeserializationSpeedMetric(10, true));
36 harness.addProduct(new XStreamPlain());
37 harness.addProduct(new XStreamClassAliases());
38 harness.addProduct(new XStreamFieldAliases());
39 harness.addProduct(new XStreamLocalAttributeAliases());
40 harness.addTarget(new FieldReflection());
41 harness.addTarget(new HierarchyLevelReflection());
42 harness.addTarget(new InnerClassesReflection());
43 harness.addTarget(new StaticInnerClassesReflection());
44 harness.run(new TextReporter());
45 }
46 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reflection.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.model.A100Parents;
16
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 /**
21 * Uses XStream with the XPP driver for parsing XML with aliases for field names.
22 *
23 * @author J&ouml;rg Schaible
24 * @author Joe Walnes
25 * @see com.thoughtworks.xstream.tools.benchmark.Harness
26 * @see Product
27 * @see XStream#alias(String, Class)
28 */
29 public class XStreamClassAliases implements Product {
30
31 private final XStream xstream;
32
33 public XStreamClassAliases() {
34 this.xstream = new XStream(new XppDriver());
35 for(int i = 0; i < 100; ++i) {
36 String no = "00" + i;
37 no = no.substring(no.length() - 3);
38 try {
39 Class cls = Class.forName(A100Parents.class.getName() + "$Parent" + no);
40 xstream.alias("p" + no, cls);
41 } catch (ClassNotFoundException e) {
42 throw new RuntimeException(e);
43 }
44 }
45 }
46
47 public void serialize(Object object, OutputStream output) throws Exception {
48 xstream.toXML(object, output);
49 }
50
51 public Object deserialize(InputStream input) throws Exception {
52 return xstream.fromXML(input);
53 }
54
55 public String toString() {
56 return "XStream (class aliases)";
57 }
58
59 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reflection.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.model.A100Fields;
16 import com.thoughtworks.xstream.tools.benchmark.model.A100Parents;
17
18 import java.io.InputStream;
19 import java.io.OutputStream;
20
21
22 /**
23 * Uses XStream with the XPP driver for parsing XML with aliases for fields.
24 *
25 * @author J&ouml;rg Schaible
26 * @author Joe Walnes
27 * @see com.thoughtworks.xstream.tools.benchmark.Harness
28 * @see Product
29 * @see XStream#aliasField(String, Class, String)
30 */
31 public class XStreamFieldAliases implements Product {
32
33 private final XStream xstream;
34
35 public XStreamFieldAliases() {
36 this.xstream = new XStream(new XppDriver());
37 try {
38 Class clsFields = Class.forName(A100Fields.class.getName());
39 for (int i = 0; i < 100; ++i) {
40 String no = "00" + i;
41 no = no.substring(no.length() - 3);
42 xstream.aliasField("f" + no, clsFields, "field" + no);
43 Class cls = Class.forName(A100Parents.class.getName() + "$Parent" + no);
44 xstream.aliasField("f" + no, cls, "field" + no);
45 }
46 } catch (ClassNotFoundException e) {
47 throw new RuntimeException(e);
48 }
49 }
50
51 public void serialize(Object object, OutputStream output) throws Exception {
52 xstream.toXML(object, output);
53 }
54
55 public Object deserialize(InputStream input) throws Exception {
56 return xstream.fromXML(input);
57 }
58
59 public String toString() {
60 return "XStream (field aliases)";
61 }
62
63 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reflection.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15 import com.thoughtworks.xstream.tools.benchmark.model.A100Fields;
16 import com.thoughtworks.xstream.tools.benchmark.model.A100Parents;
17
18 import java.io.InputStream;
19 import java.io.OutputStream;
20
21 /**
22 * Uses XStream with the XPP driver for parsing XML with local attribute aliases for fields.
23 *
24 * @author J&ouml;rg Schaible
25 * @author Joe Walnes
26 * @see com.thoughtworks.xstream.tools.benchmark.Harness
27 * @see Product
28 * @see XStream#aliasAttribute(Class, String, String)
29 */
30 public class XStreamLocalAttributeAliases implements Product {
31
32 private final XStream xstream;
33
34 public XStreamLocalAttributeAliases() {
35 this.xstream = new XStream(new XppDriver());
36 try {
37 Class clsFields = Class.forName(A100Fields.class.getName());
38 for (int i = 0; i < 100; ++i) {
39 String no = "00" + i;
40 no = no.substring(no.length() - 3);
41 xstream.useAttributeFor(clsFields, "field" + no);
42 xstream.aliasAttribute(clsFields, "field" + no, "f" + no);
43 Class cls = Class.forName(A100Parents.class.getName() + "$Parent" + no);
44 xstream.useAttributeFor(cls, "field" + no);
45 xstream.aliasAttribute(cls, "field" + no, "f" + no);
46 }
47 } catch (ClassNotFoundException e) {
48 throw new RuntimeException(e);
49 }
50 }
51
52 public void serialize(Object object, OutputStream output) throws Exception {
53 xstream.toXML(object, output);
54 }
55
56 public Object deserialize(InputStream input) throws Exception {
57 return xstream.fromXML(input);
58 }
59
60 public String toString() {
61 return "XStream (local attribute aliases)";
62 }
63
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.reflection.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Uses XStream with the XPP driver for parsing XML and no additional setup.
21 *
22 * @author Joe Walnes
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Product
25 * @see XStream
26 * @see XppDriver
27 */
28 public class XStreamPlain implements Product {
29
30 private final XStream xstream;
31
32 public XStreamPlain() {
33 this.xstream = new XStream(new XppDriver());
34 }
35
36 public void serialize(Object object, OutputStream output) throws Exception {
37 xstream.toXML(object, output);
38 }
39
40 public Object deserialize(InputStream input) throws Exception {
41 return xstream.fromXML(input);
42 }
43
44 public String toString() {
45 return "XStream (plain)";
46 }
47
48 }
0 /*
1 * Copyright (C) 2007, 2009 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 04. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings;
11
12 import com.thoughtworks.xstream.tools.benchmark.Harness;
13 import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
14 import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
15 import com.thoughtworks.xstream.tools.benchmark.strings.products.StringInternConverter;
16 import com.thoughtworks.xstream.tools.benchmark.strings.products.StringNonCachingConverter;
17 import com.thoughtworks.xstream.tools.benchmark.strings.products.StringWithSynchronizedWeakHashMapConverter;
18 import com.thoughtworks.xstream.tools.benchmark.strings.products.StringWithWeakHashMapConverter;
19 import com.thoughtworks.xstream.tools.benchmark.strings.targets.BigString;
20 import com.thoughtworks.xstream.tools.benchmark.strings.targets.StringArray;
21
22
23 /**
24 * Main application to run harness for StringConverter benchmark.
25 *
26 * @author J&ouml;rg Schaible
27 */
28 public class StringsBenchmark {
29 public static void main(String[] args) {
30 Harness harness = new Harness();
31 harness.addMetric(new DeserializationSpeedMetric(10, true));
32 harness.addProduct(new StringNonCachingConverter());
33 harness.addProduct(new StringInternConverter());
34 harness.addProduct(new StringWithWeakHashMapConverter());
35 harness.addProduct(new StringWithSynchronizedWeakHashMapConverter());
36 harness.addTarget(new BigString());
37 harness.addTarget(new StringArray(1024, 1024, 128));
38 harness.addTarget(new StringArray(64 * 1024, 8, 32));
39 harness.run(new TextReporter());
40 }
41 }
0 /*
1 * Copyright (C) 2007, 2009 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 04. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14 import com.thoughtworks.xstream.io.xml.XppDriver;
15 import com.thoughtworks.xstream.tools.benchmark.Product;
16
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 /**
21 * Uses String.intern() for StringConverter (and allocates PermSpace).
22 *
23 * @author J&ouml;rg Schaible
24 * @see com.thoughtworks.xstream.tools.benchmark.Harness
25 * @see Product
26 */
27 public class StringInternConverter implements Product {
28
29 private final XStream xstream;
30
31 public StringInternConverter() {
32 xstream = new XStream(new XppDriver());
33 xstream.registerConverter(new StringConverter());
34 }
35
36 public void serialize(Object object, OutputStream output) throws Exception {
37 xstream.toXML(object, output);
38 }
39
40 public Object deserialize(InputStream input) throws Exception {
41 return xstream.fromXML(input);
42 }
43
44 public String toString() {
45 return "StringConverter using intern() allocating perm space";
46 }
47
48 /**
49 * Converts a String to a String ;). Well ok, it doesn't
50 * <i>actually</i> do any conversion.
51 * <p>The converter always calls intern() on the returned
52 * String to encourage the JVM to reuse instances.</p>
53 *
54 * @author Joe Walnes
55 * @see String#intern()
56 */
57 public static class StringConverter extends AbstractSingleValueConverter {
58
59 public boolean canConvert(Class type) {
60 return type.equals(String.class);
61 }
62
63 public Object fromString(String str) {
64 return str.intern();
65 }
66
67 }
68
69 }
0 /*
1 * Copyright (C) 2007, 2009 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 18. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14 import com.thoughtworks.xstream.io.xml.XppDriver;
15 import com.thoughtworks.xstream.tools.benchmark.Product;
16
17 import java.io.InputStream;
18 import java.io.OutputStream;
19
20 /**
21 * Uses no cache at all StringConverter.
22 *
23 * @author J&ouml;rg Schaible
24 * @see com.thoughtworks.xstream.tools.benchmark.Harness
25 * @see Product
26 */
27 public class StringNonCachingConverter implements Product {
28
29 private final XStream xstream;
30
31 public StringNonCachingConverter() {
32 xstream = new XStream(new XppDriver());
33 xstream.registerConverter(new StringConverter());
34 }
35
36 public void serialize(Object object, OutputStream output) throws Exception {
37 xstream.toXML(object, output);
38 }
39
40 public Object deserialize(InputStream input) throws Exception {
41 return xstream.fromXML(input);
42 }
43
44 public String toString() {
45 return "StringConverter using no cache at all";
46 }
47
48 /**
49 * Converts a String to a String ;).
50 *
51 * @author J&ouml;rg Schaible
52 * @see String#intern()
53 */
54 public static class StringConverter extends AbstractSingleValueConverter {
55
56 public boolean canConvert(Class type) {
57 return type.equals(String.class);
58 }
59
60 public Object fromString(String str) {
61 return str;
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 04. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18 import java.util.Collections;
19 import java.util.WeakHashMap;
20
21
22 /**
23 * Uses WeakHashMap for StringConverter.
24 *
25 * @author J&ouml;rg Schaible
26 * @see com.thoughtworks.xstream.tools.benchmark.Harness
27 * @see Product
28 */
29 public class StringWithSynchronizedWeakHashMapConverter implements Product {
30
31 private final XStream xstream;
32
33 public StringWithSynchronizedWeakHashMapConverter() {
34 xstream = new XStream(new XppDriver());
35 xstream.registerConverter(new StringWithWeakHashMapConverter.StringConverter(Collections.synchronizedMap(new WeakHashMap())));
36 }
37
38 public void serialize(Object object, OutputStream output) throws Exception {
39 xstream.toXML(object, output);
40 }
41
42 public Object deserialize(InputStream input) throws Exception {
43 return xstream.fromXML(input);
44 }
45
46 public String toString() {
47 return "StringConverter using synchronized WeakHashMap";
48 }
49 }
0 /*
1 * Copyright (C) 2007, 2009 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 04. May 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
14 import com.thoughtworks.xstream.io.xml.XppDriver;
15 import com.thoughtworks.xstream.tools.benchmark.Product;
16
17 import java.io.InputStream;
18 import java.io.OutputStream;
19 import java.util.Map;
20 import java.util.WeakHashMap;
21 import java.lang.ref.WeakReference;
22
23
24 /**
25 * Uses WeakHashMap for StringConverter.
26 *
27 * @author J&ouml;rg Schaible
28 * @see com.thoughtworks.xstream.tools.benchmark.Harness
29 * @see Product
30 */
31 public class StringWithWeakHashMapConverter implements Product {
32
33 private final XStream xstream;
34
35 public StringWithWeakHashMapConverter() {
36 xstream = new XStream(new XppDriver());
37 xstream.registerConverter(new StringConverter());
38 }
39
40 public void serialize(Object object, OutputStream output) throws Exception {
41 xstream.toXML(object, output);
42 }
43
44 public Object deserialize(InputStream input) throws Exception {
45 return xstream.fromXML(input);
46 }
47
48 public String toString() {
49 return "StringConverter using WeakHashMap";
50 }
51
52 /**
53 * Converts a String to a String.
54 * <p>
55 * Well ok, it doesn't <i>actually</i> do any conversion. The converter uses a map to reuse
56 * instances. This map is by default a {@link WeakHashMap}.
57 * </p>
58 *
59 * @author Rene Schwietzke
60 * @author J&ouml;rg Schaible
61 * @see WeakHashMap
62 */
63 public static class StringConverter extends AbstractSingleValueConverter {
64 /**
65 * A Map to store strings as long as needed to map similar strings onto the same
66 * instance and conserve memory. The map can be set from the outside during
67 * construction, so it can be a LRU map or a weak map, sychronized or not.
68 */
69 private final Map cache;
70
71 public StringConverter(Map map) {
72 this.cache = map;
73 }
74
75 public StringConverter() {
76 this(new WeakHashMap());
77 }
78
79 public boolean canConvert(Class type) {
80 return type.equals(String.class);
81 }
82
83 public Object fromString(String str) {
84 WeakReference ref = (WeakReference)cache.get(str);
85 String s = (String)(ref == null ? null : ref.get());
86
87 if (s == null) {
88 // fill cache
89 cache.put(str, new WeakReference(str));
90
91 s = str;
92 }
93
94 return s;
95 }
96 }
97 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13
14 import org.apache.commons.io.IOUtils;
15
16 import java.io.IOException;
17
18
19 /**
20 * A small java.lang.String target.
21 *
22 * @author J&ouml;rg Schaible
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Target
25 */
26 public class BigString implements Target {
27
28 private final String string;
29
30 public BigString() {
31 try {
32 string = IOUtils.toString(getClass().getResourceAsStream("eclipse-build-log.txt"));
33 } catch (IOException e) {
34 throw new RuntimeException("Cannot create big String target", e);
35 }
36 }
37
38 public String toString() {
39 return "Big string";
40 }
41
42 public Object target() {
43 return string;
44 }
45
46 public boolean isEqual(Object other) {
47 return string.equals(other);
48 }
49 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.strings.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13
14 import java.util.Arrays;
15
16
17 /**
18 * A target with an array of java.lang.String objects.
19 *
20 * @author J&ouml;rg Schaible
21 * @see com.thoughtworks.xstream.tools.benchmark.Harness
22 * @see Target
23 */
24 public class StringArray implements Target {
25
26 private final String[] strings;
27 private final int unique;
28
29 public StringArray(int elements, int length, int unique) {
30 this.unique = unique;
31 char[] zero = new char[length];
32 Arrays.fill(zero, '0');
33
34 strings = new String[elements];
35 for (int i = 0; i < strings.length; i++) {
36 String hex = Integer.toHexString(i % unique);
37 strings[i] = new String(zero, 0, zero.length - hex.length()) + hex;
38 }
39 }
40
41 public String toString() {
42 return "String array with "
43 + strings.length
44 + " elements of "
45 + strings[0].length()
46 + " chars and "
47 + unique
48 + " unique entries";
49 }
50
51 public Object target() {
52 return strings;
53 }
54
55 public boolean isEqual(Object other) {
56 return Arrays.equals(strings, (Object[])other);
57 }
58 }
0 * Checking for at least 768MBytes RAM ...
1  [ ok ]
2 * Using: sun-jdk-1.4
3 >>> Unpacking source...
4 >>> Unpacking eclipse-sourceBuild-srcIncluded-3.2.zip to /volatile/portage/eclipse-sdk-3.2/work
5 >>> Unpacking eclipse-sdk-3.2-patches.tar.bz2 to /volatile/portage/eclipse-sdk-3.2/work
6 * Enabling embedded Mozilla support
7 * Enabling CAIRO support
8 * Enabling OpenGL support
9 * Applying eclipse-sdk-3.2-build.patch ...
10  [ ok ]
11 * Applying eclipse-sdk-3.2-libupdatebuild.patch ...
12  [ ok ]
13 * Applying eclipse-sdk-3.2-libupdatebuild2.patch ...
14  [ ok ]
15 * Applying eclipse-sdk-3.2-swttools.patch ...
16  [ ok ]
17 * Applying eclipse-sdk-3.2-updatehomedir.patch ...
18  [ ok ]
19 * Applying eclipse-sdk-3.2-fileinitializer.patch ...
20  [ ok ]
21 * Applying eclipse-sdk-3.2-bz162177.patch ...
22  [ ok ]
23 * Applying eclipse-sdk-3.2-genjavadocoutput.patch ...
24  [ ok ]
25 * Applying eclipse-sdk-3.2-helpindexbuilder.patch ...
26  [ ok ]
27 * Applying eclipse-sdk-3.2-usebuiltlauncher.patch ...
28  [ ok ]
29 * Applying eclipse-sdk-3.2-launcher-link.patch ...
30  [ ok ]
31 * Applying eclipse-sdk-3.2-launcher-link.patch ...
32  [ ok ]
33 * Applying eclipse-sdk-3.2-javadoclinks.patch ...
34  [ ok ]
35 * Applying eclipse-sdk-3.2-pde.build-add-package-build.patch ...
36  [ ok ]
37 * Applying eclipse-sdk-3.2-swt-rm-ON_TOP.patch ...
38  [ ok ]
39 * Applying eclipse-sdk-3.2-disable-junit4-apt.patch ...
40  [ ok ]
41 >>> Source unpacked.
42 >>> Compiling source in /volatile/portage/eclipse-sdk-3.2/work ...
43 * Using bootclasspath /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar:/opt/sun-jdk-1.4.2.12/jre/lib/i18n.jar:/opt/sun-jdk-1.4.2.12/jre/lib/sunrsasign.jar:/opt/sun-jdk-1.4.2.12/jre/lib/jsse.jar:/opt/sun-jdk-1.4.2.12/jre/lib/jce.jar:/opt/sun-jdk-1.4.2.12/jre/lib/charsets.jar
44 * Using JVM library path /opt/sun-jdk-1.4.2.12/jre/lib/i386
45 * Will compile embedded seamonkey support against www-client/seamonkey
46 * Using /opt/sun-jdk-1.6.0 for java5home
47 [echo] TARGET: compiler
48 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/core/JDTCompilerAdapter.java]
49 [javac] [parsing completed 83ms]
50 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/core/compiler/CategorizedProblem.java]
51 [javac] [parsing completed 2ms]
52 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/core/compiler/CharOperation.java]
53 [javac] [parsing completed 61ms]
54 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/core/compiler/IProblem.java]
55 [javac] [parsing completed 37ms]
56 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/core/compiler/InvalidInputException.java]
57 [javac] [parsing completed 1ms]
58 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/antadapter/AntAdapterMessages.java]
59 [javac] [parsing completed 1ms]
60 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ASTVisitor.java]
61 [javac] [parsing completed 11ms]
62 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ClassFile.java]
63 [javac] [parsing completed 219ms]
64 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ClassFilePool.java]
65 [javac] [parsing completed 1ms]
66 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/CompilationResult.java]
67 [javac] [parsing completed 4ms]
68 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/Compiler.java]
69 [javac] [parsing completed 11ms]
70 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ConfigurableOption.java]
71 [javac] [parsing completed 1ms]
72 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.java]
73 [javac] [parsing completed 0ms]
74 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ICompilerRequestor.java]
75 [javac] [parsing completed 1ms]
76 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/IDebugRequestor.java]
77 [javac] [parsing completed 1ms]
78 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.java]
79 [javac] [parsing completed 3ms]
80 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/IProblemFactory.java]
81 [javac] [parsing completed 2ms]
82 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java]
83 [javac] [parsing completed 7ms]
84 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ASTNode.java]
85 [javac] [parsing completed 6ms]
86 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java]
87 [javac] [parsing completed 5ms]
88 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AbstractVariableDeclaration.java]
89 [javac] [parsing completed 6ms]
90 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java]
91 [javac] [parsing completed 3ms]
92 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Annotation.java]
93 [javac] [parsing completed 3ms]
94 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AnnotationMethodDeclaration.java]
95 [javac] [parsing completed 2ms]
96 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Argument.java]
97 [javac] [parsing completed 1ms]
98 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java]
99 [javac] [parsing completed 2ms]
100 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java]
101 [javac] [parsing completed 7ms]
102 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.java]
103 [javac] [parsing completed 6ms]
104 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ArrayReference.java]
105 [javac] [parsing completed 2ms]
106 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.java]
107 [javac] [parsing completed 1ms]
108 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java]
109 [javac] [parsing completed 7ms]
110 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Assignment.java]
111 [javac] [parsing completed 4ms]
112 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/BinaryExpression.java]
113 [javac] [parsing completed 202ms]
114 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Block.java]
115 [javac] [parsing completed 1ms]
116 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/BranchStatement.java]
117 [javac] [parsing completed 0ms]
118 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java]
119 [javac] [parsing completed 1ms]
120 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java]
121 [javac] [parsing completed 2ms]
122 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/CastExpression.java]
123 [javac] [parsing completed 10ms]
124 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/CharLiteral.java]
125 [javac] [parsing completed 2ms]
126 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java]
127 [javac] [parsing completed 6ms]
128 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Clinit.java]
129 [javac] [parsing completed 2ms]
130 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java]
131 [javac] [parsing completed 3ms]
132 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/CompoundAssignment.java]
133 [javac] [parsing completed 8ms]
134 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java]
135 [javac] [parsing completed 3ms]
136 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java]
137 [javac] [parsing completed 11ms]
138 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ContinueStatement.java]
139 [javac] [parsing completed 1ms]
140 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/DoStatement.java]
141 [javac] [parsing completed 5ms]
142 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/DoubleLiteral.java]
143 [javac] [parsing completed 0ms]
144 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.java]
145 [javac] [parsing completed 0ms]
146 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java]
147 [javac] [parsing completed 3ms]
148 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java]
149 [javac] [parsing completed 10ms]
150 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Expression.java]
151 [javac] [parsing completed 5ms]
152 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ExtendedStringLiteral.java]
153 [javac] [parsing completed 1ms]
154 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/FalseLiteral.java]
155 [javac] [parsing completed 1ms]
156 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java]
157 [javac] [parsing completed 9ms]
158 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/FieldReference.java]
159 [javac] [parsing completed 3ms]
160 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/FloatLiteral.java]
161 [javac] [parsing completed 1ms]
162 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ForStatement.java]
163 [javac] [parsing completed 3ms]
164 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java]
165 [javac] [parsing completed 10ms]
166 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/IfStatement.java]
167 [javac] [parsing completed 10ms]
168 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ImportReference.java]
169 [javac] [parsing completed 1ms]
170 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Initializer.java]
171 [javac] [parsing completed 4ms]
172 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java]
173 [javac] [parsing completed 4ms]
174 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/IntLiteral.java]
175 [javac] [parsing completed 6ms]
176 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/IntLiteralMinValue.java]
177 [javac] [parsing completed 3ms]
178 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Javadoc.java]
179 [javac] [parsing completed 6ms]
180 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.java]
181 [javac] [parsing completed 1ms]
182 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocArgumentExpression.java]
183 [javac] [parsing completed 1ms]
184 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocArrayQualifiedTypeReference.java]
185 [javac] [parsing completed 1ms]
186 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocArraySingleTypeReference.java]
187 [javac] [parsing completed 2ms]
188 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.java]
189 [javac] [parsing completed 0ms]
190 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocImplicitTypeReference.java]
191 [javac] [parsing completed 3ms]
192 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocImportReference.java]
193 [javac] [parsing completed 0ms]
194 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocMessageSend.java]
195 [javac] [parsing completed 2ms]
196 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocQualifiedTypeReference.java]
197 [javac] [parsing completed 1ms]
198 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.java]
199 [javac] [parsing completed 3ms]
200 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocSingleNameReference.java]
201 [javac] [parsing completed 1ms]
202 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/JavadocSingleTypeReference.java]
203 [javac] [parsing completed 1ms]
204 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/LabeledStatement.java]
205 [javac] [parsing completed 3ms]
206 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Literal.java]
207 [javac] [parsing completed 0ms]
208 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java]
209 [javac] [parsing completed 3ms]
210 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/LongLiteral.java]
211 [javac] [parsing completed 2ms]
212 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/LongLiteralMinValue.java]
213 [javac] [parsing completed 3ms]
214 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/MagicLiteral.java]
215 [javac] [parsing completed 1ms]
216 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/MarkerAnnotation.java]
217 [javac] [parsing completed 3ms]
218 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.java]
219 [javac] [parsing completed 3ms]
220 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java]
221 [javac] [parsing completed 5ms]
222 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java]
223 [javac] [parsing completed 6ms]
224 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/NameReference.java]
225 [javac] [parsing completed 1ms]
226 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/NormalAnnotation.java]
227 [javac] [parsing completed 1ms]
228 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/NullLiteral.java]
229 [javac] [parsing completed 1ms]
230 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/NumberLiteral.java]
231 [javac] [parsing completed 1ms]
232 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java]
233 [javac] [parsing completed 2ms]
234 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/OperatorExpression.java]
235 [javac] [parsing completed 16ms]
236 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/OperatorIds.java]
237 [javac] [parsing completed 1ms]
238 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java]
239 [javac] [parsing completed 9ms]
240 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java]
241 [javac] [parsing completed 4ms]
242 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/PostfixExpression.java]
243 [javac] [parsing completed 0ms]
244 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/PrefixExpression.java]
245 [javac] [parsing completed 0ms]
246 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java]
247 [javac] [parsing completed 3ms]
248 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java]
249 [javac] [parsing completed 8ms]
250 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/QualifiedSuperReference.java]
251 [javac] [parsing completed 1ms]
252 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java]
253 [javac] [parsing completed 1ms]
254 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.java]
255 [javac] [parsing completed 8ms]
256 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Reference.java]
257 [javac] [parsing completed 1ms]
258 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java]
259 [javac] [parsing completed 2ms]
260 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SingleMemberAnnotation.java]
261 [javac] [parsing completed 4ms]
262 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java]
263 [javac] [parsing completed 9ms]
264 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java]
265 [javac] [parsing completed 5ms]
266 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Statement.java]
267 [javac] [parsing completed 1ms]
268 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/StringLiteral.java]
269 [javac] [parsing completed 3ms]
270 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/StringLiteralConcatenation.java]
271 [javac] [parsing completed 0ms]
272 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SubRoutineStatement.java]
273 [javac] [parsing completed 0ms]
274 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SuperReference.java]
275 [javac] [parsing completed 1ms]
276 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java]
277 [javac] [parsing completed 8ms]
278 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java]
279 [javac] [parsing completed 1ms]
280 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ThisReference.java]
281 [javac] [parsing completed 2ms]
282 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/ThrowStatement.java]
283 [javac] [parsing completed 0ms]
284 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/TrueLiteral.java]
285 [javac] [parsing completed 0ms]
286 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/TryStatement.java]
287 [javac] [parsing completed 8ms]
288 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java]
289 [javac] [parsing completed 11ms]
290 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/TypeParameter.java]
291 [javac] [parsing completed 145ms]
292 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/TypeReference.java]
293 [javac] [parsing completed 1ms]
294 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java]
295 [javac] [parsing completed 2ms]
296 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java]
297 [javac] [parsing completed 6ms]
298 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/ast/Wildcard.java]
299 [javac] [parsing completed 1ms]
300 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java]
301 [javac] [parsing completed 1ms]
302 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java]
303 [javac] [parsing completed 0ms]
304 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java]
305 [javac] [parsing completed 0ms]
306 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.java]
307 [javac] [parsing completed 4ms]
308 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java]
309 [javac] [parsing completed 0ms]
310 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/FileFinder.java]
311 [javac] [parsing completed 44ms]
312 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/FileSystem.java]
313 [javac] [parsing completed 2ms]
314 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/batch/Main.java]
315 [javac] [parsing completed 27ms]
316 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.java]
317 [javac] [parsing completed 6ms]
318 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationMethodInfo.java]
319 [javac] [parsing completed 1ms]
320 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/AnnotationMethodInfoWithAnnotations.java]
321 [javac] [parsing completed 0ms]
322 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.java]
323 [javac] [parsing completed 1ms]
324 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java]
325 [javac] [parsing completed 4ms]
326 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileStruct.java]
327 [javac] [parsing completed 2ms]
328 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFormatException.java]
329 [javac] [parsing completed 2ms]
330 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/ElementValuePairInfo.java]
331 [javac] [parsing completed 1ms]
332 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java]
333 [javac] [parsing completed 5ms]
334 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.java]
335 [javac] [parsing completed 1ms]
336 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/InnerClassInfo.java]
337 [javac] [parsing completed 1ms]
338 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java]
339 [javac] [parsing completed 6ms]
340 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithAnnotations.java]
341 [javac] [parsing completed 1ms]
342 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java]
343 [javac] [parsing completed 0ms]
344 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/AttributeNamesConstants.java]
345 [javac] [parsing completed 0ms]
346 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java]
347 [javac] [parsing completed 7ms]
348 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/CachedIndexEntry.java]
349 [javac] [parsing completed 0ms]
350 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/CaseLabel.java]
351 [javac] [parsing completed 2ms]
352 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/CharArrayCache.java]
353 [javac] [parsing completed 1ms]
354 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java]
355 [javac] [parsing completed 36ms]
356 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java]
357 [javac] [parsing completed 20ms]
358 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/DoubleCache.java]
359 [javac] [parsing completed 2ms]
360 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/ExceptionLabel.java]
361 [javac] [parsing completed 1ms]
362 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/FieldNameAndTypeCache.java]
363 [javac] [parsing completed 2ms]
364 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/FloatCache.java]
365 [javac] [parsing completed 1ms]
366 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/IntegerCache.java]
367 [javac] [parsing completed 2ms]
368 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/Label.java]
369 [javac] [parsing completed 1ms]
370 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/LongCache.java]
371 [javac] [parsing completed 1ms]
372 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/MethodNameAndTypeCache.java]
373 [javac] [parsing completed 1ms]
374 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/ObjectCache.java]
375 [javac] [parsing completed 2ms]
376 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/Opcodes.java]
377 [javac] [parsing completed 5ms]
378 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrame.java]
379 [javac] [parsing completed 5ms]
380 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java]
381 [javac] [parsing completed 19ms]
382 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/codegen/VerificationTypeInfo.java]
383 [javac] [parsing completed 2ms]
384 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/AccessRestriction.java]
385 [javac] [parsing completed 2ms]
386 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/AccessRule.java]
387 [javac] [parsing completed 1ms]
388 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java]
389 [javac] [parsing completed 2ms]
390 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ClassSignature.java]
391 [javac] [parsing completed 3ms]
392 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/EnumConstantSignature.java]
393 [javac] [parsing completed 1ms]
394 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryAnnotation.java]
395 [javac] [parsing completed 1ms]
396 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryElementValuePair.java]
397 [javac] [parsing completed 1ms]
398 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryField.java]
399 [javac] [parsing completed 1ms]
400 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryMethod.java]
401 [javac] [parsing completed 1ms]
402 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryNestedType.java]
403 [javac] [parsing completed 1ms]
404 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IBinaryType.java]
405 [javac] [parsing completed 1ms]
406 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.java]
407 [javac] [parsing completed 2ms]
408 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IDependent.java]
409 [javac] [parsing completed 1ms]
410 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IGenericField.java]
411 [javac] [parsing completed 4ms]
412 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IGenericMethod.java]
413 [javac] [parsing completed 1ms]
414 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/IGenericType.java]
415 [javac] [parsing completed 1ms]
416 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/INameEnvironment.java]
417 [javac] [parsing completed 3ms]
418 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ISourceField.java]
419 [javac] [parsing completed 1ms]
420 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ISourceImport.java]
421 [javac] [parsing completed 2ms]
422 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ISourceMethod.java]
423 [javac] [parsing completed 2ms]
424 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/ISourceType.java]
425 [javac] [parsing completed 2ms]
426 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/env/NameEnvironmentAnswer.java]
427 [javac] [parsing completed 2ms]
428 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java]
429 [javac] [parsing completed 2ms]
430 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.java]
431 [javac] [parsing completed 4ms]
432 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java]
433 [javac] [parsing completed 6ms]
434 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/FlowContext.java]
435 [javac] [parsing completed 5ms]
436 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java]
437 [javac] [parsing completed 2ms]
438 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/InitializationFlowContext.java]
439 [javac] [parsing completed 1ms]
440 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.java]
441 [javac] [parsing completed 2ms]
442 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/LabelFlowContext.java]
443 [javac] [parsing completed 2ms]
444 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java]
445 [javac] [parsing completed 3ms]
446 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.java]
447 [javac] [parsing completed 3ms]
448 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.java]
449 [javac] [parsing completed 1ms]
450 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java]
451 [javac] [parsing completed 17ms]
452 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/BooleanConstant.java]
453 [javac] [parsing completed 4ms]
454 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/ByteConstant.java]
455 [javac] [parsing completed 1ms]
456 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/CharConstant.java]
457 [javac] [parsing completed 2ms]
458 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java]
459 [javac] [parsing completed 19ms]
460 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/Constant.java]
461 [javac] [parsing completed 209ms]
462 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/DoubleConstant.java]
463 [javac] [parsing completed 0ms]
464 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/FloatConstant.java]
465 [javac] [parsing completed 0ms]
466 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/ITypeRequestor.java]
467 [javac] [parsing completed 1ms]
468 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/IntConstant.java]
469 [javac] [parsing completed 1ms]
470 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/LongConstant.java]
471 [javac] [parsing completed 1ms]
472 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.java]
473 [javac] [parsing completed 0ms]
474 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/ShortConstant.java]
475 [javac] [parsing completed 0ms]
476 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/impl/StringConstant.java]
477 [javac] [parsing completed 1ms]
478 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/AnnotationBinding.java]
479 [javac] [parsing completed 4ms]
480 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/AnnotationHolder.java]
481 [javac] [parsing completed 1ms]
482 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java]
483 [javac] [parsing completed 2ms]
484 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/BaseTypeBinding.java]
485 [javac] [parsing completed 2ms]
486 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java]
487 [javac] [parsing completed 8ms]
488 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/Binding.java]
489 [javac] [parsing completed 2ms]
490 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java]
491 [javac] [parsing completed 9ms]
492 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java]
493 [javac] [parsing completed 4ms]
494 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java]
495 [javac] [parsing completed 8ms]
496 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java]
497 [javac] [parsing completed 4ms]
498 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.java]
499 [javac] [parsing completed 3ms]
500 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.java]
501 [javac] [parsing completed 1ms]
502 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java]
503 [javac] [parsing completed 2ms]
504 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ImportBinding.java]
505 [javac] [parsing completed 1ms]
506 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ImportConflictBinding.java]
507 [javac] [parsing completed 1ms]
508 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/InnerEmulationDependency.java]
509 [javac] [parsing completed 1ms]
510 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/InvocationSite.java]
511 [javac] [parsing completed 13ms]
512 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java]
513 [javac] [parsing completed 3ms]
514 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.java]
515 [javac] [parsing completed 2ms]
516 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java]
517 [javac] [parsing completed 10ms]
518 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/MemberTypeBinding.java]
519 [javac] [parsing completed 1ms]
520 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java]
521 [javac] [parsing completed 4ms]
522 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java]
523 [javac] [parsing completed 6ms]
524 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java]
525 [javac] [parsing completed 17ms]
526 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java]
527 [javac] [parsing completed 3ms]
528 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.java]
529 [javac] [parsing completed 1ms]
530 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java]
531 [javac] [parsing completed 2ms]
532 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedFieldBinding.java]
533 [javac] [parsing completed 1ms]
534 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java]
535 [javac] [parsing completed 2ms]
536 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java]
537 [javac] [parsing completed 1ms]
538 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java]
539 [javac] [parsing completed 19ms]
540 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemBinding.java]
541 [javac] [parsing completed 1ms]
542 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemFieldBinding.java]
543 [javac] [parsing completed 0ms]
544 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemMethodBinding.java]
545 [javac] [parsing completed 3ms]
546 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemPackageBinding.java]
547 [javac] [parsing completed 4ms]
548 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java]
549 [javac] [parsing completed 1ms]
550 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.java]
551 [javac] [parsing completed 0ms]
552 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.java]
553 [javac] [parsing completed 1ms]
554 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java]
555 [javac] [parsing completed 9ms]
556 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java]
557 [javac] [parsing completed 33ms]
558 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/SignatureWrapper.java]
559 [javac] [parsing completed 1ms]
560 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java]
561 [javac] [parsing completed 10ms]
562 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/Substitution.java]
563 [javac] [parsing completed 2ms]
564 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticArgumentBinding.java]
565 [javac] [parsing completed 2ms]
566 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticFieldBinding.java]
567 [javac] [parsing completed 1ms]
568 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java]
569 [javac] [parsing completed 3ms]
570 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/TagBits.java]
571 [javac] [parsing completed 1ms]
572 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java]
573 [javac] [parsing completed 19ms]
574 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java]
575 [javac] [parsing completed 1ms]
576 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/TypeIds.java]
577 [javac] [parsing completed 3ms]
578 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java]
579 [javac] [parsing completed 3ms]
580 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedAnnotationBinding.java]
581 [javac] [parsing completed 1ms]
582 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java]
583 [javac] [parsing completed 1ms]
584 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/UpdatedMethodBinding.java]
585 [javac] [parsing completed 1ms]
586 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/VariableBinding.java]
587 [javac] [parsing completed 1ms]
588 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java]
589 [javac] [parsing completed 3ms]
590 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java]
591 [javac] [parsing completed 20ms]
592 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java]
593 [javac] [parsing completed 5ms]
594 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.java]
595 [javac] [parsing completed 2ms]
596 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/NLSTag.java]
597 [javac] [parsing completed 1ms]
598 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/Parser.java]
599 [javac] [parsing completed 80ms]
600 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/ParserBasicInformation.java]
601 [javac] [parsing completed 0ms]
602 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java]
603 [javac] [parsing completed 3ms]
604 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.java]
605 [javac] [parsing completed 2ms]
606 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredField.java]
607 [javac] [parsing completed 2ms]
608 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredImport.java]
609 [javac] [parsing completed 1ms]
610 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java]
611 [javac] [parsing completed 2ms]
612 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.java]
613 [javac] [parsing completed 2ms]
614 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java]
615 [javac] [parsing completed 3ms]
616 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.java]
617 [javac] [parsing completed 1ms]
618 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredType.java]
619 [javac] [parsing completed 4ms]
620 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.java]
621 [javac] [parsing completed 2ms]
622 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveryScanner.java]
623 [javac] [parsing completed 2ms]
624 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/RecoveryScannerData.java]
625 [javac] [parsing completed 1ms]
626 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/Scanner.java]
627 [javac] [parsing completed 20ms]
628 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.java]
629 [javac] [parsing completed 3ms]
630 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/TerminalTokens.java]
631 [javac] [parsing completed 2ms]
632 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.java]
633 [javac] [parsing completed 26ms]
634 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.java]
635 [javac] [parsing completed 2ms]
636 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.java]
637 [javac] [parsing completed 1ms]
638 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.java]
639 [javac] [parsing completed 2ms]
640 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/AbortCompilationUnit.java]
641 [javac] [parsing completed 2ms]
642 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/AbortMethod.java]
643 [javac] [parsing completed 1ms]
644 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/AbortType.java]
645 [javac] [parsing completed 1ms]
646 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java]
647 [javac] [parsing completed 4ms]
648 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/DefaultProblemFactory.java]
649 [javac] [parsing completed 2ms]
650 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java]
651 [javac] [parsing completed 2ms]
652 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java]
653 [javac] [parsing completed 316ms]
654 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.java]
655 [javac] [parsing completed 2ms]
656 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/problem/ShouldNotImplement.java]
657 [javac] [parsing completed 2ms]
658 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/CompoundNameVector.java]
659 [javac] [parsing completed 2ms]
660 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/FloatUtil.java]
661 [javac] [parsing completed 2ms]
662 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfInt.java]
663 [javac] [parsing completed 2ms]
664 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfIntValues.java]
665 [javac] [parsing completed 2ms]
666 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfLong.java]
667 [javac] [parsing completed 1ms]
668 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObject.java]
669 [javac] [parsing completed 4ms]
670 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.java]
671 [javac] [parsing completed 2ms]
672 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToIntArray.java]
673 [javac] [parsing completed 2ms]
674 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfPackage.java]
675 [javac] [parsing completed 2ms]
676 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/HashtableOfType.java]
677 [javac] [parsing completed 2ms]
678 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/Messages.java]
679 [javac] [parsing completed 2ms]
680 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/ObjectVector.java]
681 [javac] [parsing completed 1ms]
682 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/SimpleLookupTable.java]
683 [javac] [parsing completed 4ms]
684 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/SimpleNameVector.java]
685 [javac] [parsing completed 1ms]
686 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/SimpleSet.java]
687 [javac] [parsing completed 1ms]
688 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/SuffixConstants.java]
689 [javac] [parsing completed 1ms]
690 [javac] [parsing started /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/src/org/eclipse/jdt/internal/compiler/util/Util.java]
691 [javac] [parsing completed 6ms]
692 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/File.class)]
693 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/IOException.class)]
694 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/PrintWriter.class)]
695 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/Constructor.class)]
696 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/InvocationTargetException.class)]
697 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/Method.class)]
698 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/ArrayList.class)]
699 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Arrays.class)]
700 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Comparator.class)]
701 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/HashMap.class)]
702 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/List.class)]
703 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Map.class)]
704 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/BuildException.class)]
705 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/Project.class)]
706 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/taskdefs/Javac.class)]
707 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.class)]
708 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/types/Commandline.class)]
709 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/types/Path.class)]
710 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/types/Commandline$Argument.class)]
711 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/util/JavaEnvUtils.class)]
712 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.class)]
713 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Object.class)]
714 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/String.class)]
715 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Class.class)]
716 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Exception.class)]
717 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Throwable.class)]
718 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/Serializable.class)]
719 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/text/MessageFormat.class)]
720 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Locale.class)]
721 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/MissingResourceException.class)]
722 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/ResourceBundle.class)]
723 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/StringBuffer.class)]
724 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/CharConversionException.class)]
725 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/StringWriter.class)]
726 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/ByteArrayInputStream.class)]
727 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/InputStreamReader.class)]
728 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/UnsupportedEncodingException.class)]
729 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Hashtable.class)]
730 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Iterator.class)]
731 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Set.class)]
732 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Cloneable.class)]
733 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/HashSet.class)]
734 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/BufferedOutputStream.class)]
735 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileOutputStream.class)]
736 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/StringTokenizer.class)]
737 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Collections.class)]
738 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/RuntimeException.class)]
739 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/CloneNotSupportedException.class)]
740 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/NoSuchElementException.class)]
741 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Enumeration.class)]
742 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/zip/ZipEntry.class)]
743 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/zip/ZipFile.class)]
744 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileNotFoundException.class)]
745 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FilenameFilter.class)]
746 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/LineNumberReader.class)]
747 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/StringReader.class)]
748 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/Field.class)]
749 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/text/DateFormat.class)]
750 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Date.class)]
751 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/PrintStream.class)]
752 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Comparable.class)]
753 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/InputStream.class)]
754 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/DataInputStream.class)]
755 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/Modifier.class)]
756 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Properties.class)]
757 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ClassLoader.class)]
758 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Dictionary.class)]
759 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileInputStream.class)]
760 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Boolean.class)]
761 [javac] [checking org.eclipse.jdt.core.JDTCompilerAdapter]
762 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Error.class)]
763 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/taskdefs/MatchingTask.class)]
764 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/Task.class)]
765 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/ProjectComponent.class)]
766 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/System.class)]
767 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/Writer.class)]
768 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FilterOutputStream.class)]
769 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/OutputStream.class)]
770 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/reflect/AccessibleObject.class)]
771 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ClassNotFoundException.class)]
772 [javac] [loading /usr/share/ant-core/lib/ant.jar(org/apache/tools/ant/types/DataType.class)]
773 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/NoSuchMethodException.class)]
774 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/IllegalAccessException.class)]
775 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Collection.class)]
776 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/Map$Entry.class)]
777 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/net/URI.class)]
778 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/AbstractMap.class)]
779 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/AbstractList.class)]
780 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/AbstractCollection.class)]
781 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/SecurityException.class)]
782 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/InstantiationException.class)]
783 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/IllegalArgumentException.class)]
784 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/NoClassDefFoundError.class)]
785 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/LinkageError.class)]
786 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/JDTCompilerAdapter$1.class]
787 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/JDTCompilerAdapter.class]
788 [javac] [checking org.eclipse.jdt.core.compiler.CategorizedProblem]
789 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.class]
790 [javac] [checking org.eclipse.jdt.core.compiler.IProblem]
791 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/compiler/IProblem.class]
792 [javac] [checking org.eclipse.jdt.core.compiler.CharOperation]
793 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Character.class)]
794 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Math.class)]
795 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/compiler/CharOperation.class]
796 [javac] [checking org.eclipse.jdt.core.compiler.InvalidInputException]
797 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/core/compiler/InvalidInputException.class]
798 [javac] [checking org.eclipse.jdt.internal.antadapter.AntAdapterMessages]
799 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/text/Format.class)]
800 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/antadapter/AntAdapterMessages.class]
801 [javac] [checking org.eclipse.jdt.internal.compiler.ASTVisitor]
802 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.class]
803 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AllocationExpression]
804 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Double.class)]
805 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Integer.class)]
806 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.class]
807 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Expression]
808 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.class]
809 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Statement]
810 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.class]
811 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ASTNode]
812 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.class]
813 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.TypeConstants]
814 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.class]
815 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.TypeIds]
816 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeIds.class]
817 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.InvocationSite]
818 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/InvocationSite.class]
819 [javac] [checking org.eclipse.jdt.internal.compiler.ast.TypeReference]
820 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.class]
821 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.MethodBinding]
822 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ClassCastException.class)]
823 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.class]
824 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.Binding]
825 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.class]
826 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.TypeBinding]
827 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.class]
828 [javac] [checking org.eclipse.jdt.internal.compiler.ast.FieldDeclaration]
829 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.class]
830 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration]
831 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractVariableDeclaration.class]
832 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.BlockScope]
833 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/AbstractSet.class)]
834 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.class]
835 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.Scope]
836 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.class]
837 [javac] [checking org.eclipse.jdt.internal.compiler.flow.FlowContext]
838 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.class]
839 [javac] [checking org.eclipse.jdt.internal.compiler.flow.FlowInfo]
840 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.class]
841 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding]
842 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding$1.class]
843 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding$2.class]
844 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding$3.class]
845 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.class]
846 [javac] [checking org.eclipse.jdt.internal.compiler.env.IDependent]
847 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IDependent.class]
848 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.CodeStream]
849 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Number.class)]
850 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Float.class)]
851 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.class]
852 [javac] [checking org.eclipse.jdt.internal.compiler.impl.Constant]
853 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/Constant.class]
854 [javac] [checking org.eclipse.jdt.internal.compiler.ast.OperatorIds]
855 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/OperatorIds.class]
856 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.BranchLabel]
857 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.class]
858 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.Label]
859 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/Label.class]
860 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding]
861 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalVariableBinding.class]
862 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.VariableBinding]
863 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/VariableBinding.class]
864 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ClassScope]
865 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.class]
866 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope]
867 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.class]
868 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SwitchStatement]
869 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.class]
870 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.FieldBinding]
871 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.class]
872 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Annotation]
873 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Annotation.class]
874 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding]
875 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding$1.class]
876 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.class]
877 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.PackageBinding]
878 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.class]
879 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment]
880 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.class]
881 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemReasons]
882 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.class]
883 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding]
884 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationBinding.class]
885 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration]
886 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.class]
887 [javac] [checking org.eclipse.jdt.internal.compiler.problem.ProblemSeverities]
888 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.class]
889 [javac] [checking org.eclipse.jdt.internal.compiler.impl.ReferenceContext]
890 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.class]
891 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ElementValuePair]
892 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ElementValuePair.class]
893 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding]
894 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/BaseTypeBinding.class]
895 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding]
896 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.class]
897 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Javadoc]
898 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Javadoc.class]
899 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.MethodScope]
900 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.class]
901 [javac] [checking org.eclipse.jdt.internal.compiler.ast.CaseStatement]
902 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.class]
903 [javac] [checking org.eclipse.jdt.internal.compiler.ast.TypeDeclaration]
904 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.class]
905 [javac] [checking org.eclipse.jdt.internal.compiler.ast.LocalDeclaration]
906 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.class]
907 [javac] [checking org.eclipse.jdt.internal.compiler.problem.ProblemReporter]
908 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/IndexOutOfBoundsException.class)]
909 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.class]
910 [javac] [checking org.eclipse.jdt.internal.compiler.problem.ProblemHandler]
911 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.class]
912 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.Substitution]
913 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/Substitution.class]
914 [javac] [checking org.eclipse.jdt.internal.compiler.impl.CompilerOptions]
915 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/nio/charset/CharsetDecoder.class)]
916 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/nio/charset/Charset.class)]
917 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/Reader.class)]
918 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/NumberFormatException.class)]
919 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.class]
920 [javac] [checking org.eclipse.jdt.internal.compiler.ast.TypeParameter]
921 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/TypeParameter.class]
922 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ArrayBinding]
923 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.class]
924 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding]
925 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.class]
926 [javac] [checking org.eclipse.jdt.internal.compiler.util.ObjectVector]
927 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/ObjectVector.class]
928 [javac] [checking org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration]
929 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration$1.class]
930 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.class]
931 [javac] [checking org.eclipse.jdt.internal.compiler.flow.NullInfoRegistry]
932 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/NullInfoRegistry.class]
933 [javac] [checking org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo]
934 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo$AssertionFailedException.class]
935 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.class]
936 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Reference]
937 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Reference.class]
938 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SubRoutineStatement]
939 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SubRoutineStatement.class]
940 [javac] [checking org.eclipse.jdt.internal.compiler.util.SimpleLookupTable]
941 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/SimpleLookupTable.class]
942 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.AnnotationHolder]
943 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationHolder$MethodHolder.class]
944 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationHolder$AnnotationMethodHolder.class]
945 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/AnnotationHolder.class]
946 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding]
947 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticArgumentBinding.class]
948 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel]
949 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/ExceptionLabel.class]
950 [javac] [checking org.eclipse.jdt.internal.compiler.CompilationResult]
951 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/CompilationResult$1.class]
952 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/CompilationResult.class]
953 [javac] [checking org.eclipse.jdt.internal.compiler.ClassFile]
954 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileDescriptor.class)]
955 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ClassFile.class]
956 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.ConstantPool]
957 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.class]
958 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants]
959 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Long.class)]
960 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileConstants.class]
961 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding]
962 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.class]
963 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.CaseLabel]
964 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/CaseLabel.class]
965 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding]
966 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.class]
967 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.NestedTypeBinding]
968 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/NestedTypeBinding.class]
969 [javac] [checking org.eclipse.jdt.internal.compiler.env.AccessRestriction]
970 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/AccessRestriction.class]
971 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ImportBinding]
972 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ImportBinding.class]
973 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfObject]
974 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfObject.class]
975 [javac] [checking org.eclipse.jdt.internal.compiler.util.CompoundNameVector]
976 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/CompoundNameVector.class]
977 [javac] [checking org.eclipse.jdt.internal.compiler.util.SimpleNameVector]
978 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/SimpleNameVector.class]
979 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfType]
980 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfType.class]
981 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.MethodVerifier]
982 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.class]
983 [javac] [checking org.eclipse.jdt.internal.compiler.ast.MemberValuePair]
984 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/MemberValuePair.class]
985 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfPackage]
986 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfPackage.class]
987 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemPackageBinding]
988 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemPackageBinding.class]
989 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding]
990 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReferenceBinding.class]
991 [javac] [checking org.eclipse.jdt.internal.compiler.env.INameEnvironment]
992 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/INameEnvironment.class]
993 [javac] [checking org.eclipse.jdt.internal.compiler.ClassFilePool]
994 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ClassFilePool.class]
995 [javac] [checking org.eclipse.jdt.internal.compiler.impl.ITypeRequestor]
996 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/ITypeRequestor.class]
997 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryType]
998 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryType.class]
999 [javac] [checking org.eclipse.jdt.internal.compiler.env.IGenericType]
1000 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IGenericType.class]
1001 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding]
1002 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/IllegalStateException.class)]
1003 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.class]
1004 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding]
1005 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/RawTypeBinding.class]
1006 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding]
1007 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.class]
1008 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding]
1009 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.class]
1010 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding]
1011 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding$1.class]
1012 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding$2.class]
1013 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.class]
1014 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.WildcardBinding]
1015 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.class]
1016 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.SignatureWrapper]
1017 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/SignatureWrapper.class]
1018 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Argument]
1019 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Argument.class]
1020 [javac] [checking org.eclipse.jdt.internal.compiler.flow.InitializationFlowContext]
1021 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/InitializationFlowContext.class]
1022 [javac] [checking org.eclipse.jdt.internal.compiler.flow.ExceptionHandlingFlowContext]
1023 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/ExceptionHandlingFlowContext.class]
1024 [javac] [checking org.eclipse.jdt.internal.compiler.parser.Parser]
1025 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ExceptionInInitializerError.class)]
1026 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/BufferedWriter.class)]
1027 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileWriter.class)]
1028 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/OutputStreamWriter.class)]
1029 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/BufferedInputStream.class)]
1030 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FilterInputStream.class)]
1031 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/Parser$1MethodVisitor.class]
1032 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/Parser$1TypeVisitor.class]
1033 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.class]
1034 [javac] [checking org.eclipse.jdt.internal.compiler.parser.ParserBasicInformation]
1035 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/ParserBasicInformation.class]
1036 [javac] [checking org.eclipse.jdt.internal.compiler.parser.TerminalTokens]
1037 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/TerminalTokens.class]
1038 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocSingleNameReference]
1039 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocSingleNameReference.class]
1040 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SingleNameReference]
1041 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.class]
1042 [javac] [checking org.eclipse.jdt.internal.compiler.ast.NameReference]
1043 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/NameReference.class]
1044 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference]
1045 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocSingleTypeReference.class]
1046 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SingleTypeReference]
1047 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.class]
1048 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocReturnStatement]
1049 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocReturnStatement.class]
1050 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ReturnStatement]
1051 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.class]
1052 [javac] [checking org.eclipse.jdt.internal.compiler.ast.MethodDeclaration]
1053 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.class]
1054 [javac] [checking org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression]
1055 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.class]
1056 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration]
1057 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.class]
1058 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.MemberTypeBinding]
1059 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/MemberTypeBinding.class]
1060 [javac] [checking org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy]
1061 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/IErrorHandlingPolicy.class]
1062 [javac] [checking org.eclipse.jdt.internal.compiler.IProblemFactory]
1063 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/IProblemFactory.class]
1064 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration]
1065 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AnnotationMethodDeclaration.class]
1066 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Assignment]
1067 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.class]
1068 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression]
1069 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.class]
1070 [javac] [checking org.eclipse.jdt.internal.compiler.ast.MessageSend]
1071 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.class]
1072 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ImportReference]
1073 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.class]
1074 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall]
1075 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.class]
1076 [javac] [checking org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit]
1077 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilationUnit.class]
1078 [javac] [checking org.eclipse.jdt.internal.compiler.problem.AbortCompilation]
1079 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/AbortCompilation.class]
1080 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ThrowStatement]
1081 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ThrowStatement.class]
1082 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ConditionalExpression]
1083 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.class]
1084 [javac] [checking org.eclipse.jdt.internal.compiler.ast.OperatorExpression]
1085 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/OperatorExpression$1Decode.class]
1086 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/OperatorExpression.class]
1087 [javac] [checking org.eclipse.jdt.internal.compiler.ast.NumberLiteral]
1088 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/NumberLiteral.class]
1089 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Literal]
1090 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Literal.class]
1091 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ThisReference]
1092 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ThisReference.class]
1093 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Block]
1094 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Block.class]
1095 [javac] [checking org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference]
1096 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedTypeReference.class]
1097 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Initializer]
1098 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Initializer.class]
1099 [javac] [checking org.eclipse.jdt.internal.compiler.ast.FieldReference]
1100 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.class]
1101 [javac] [checking org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference]
1102 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.class]
1103 [javac] [checking org.eclipse.jdt.internal.compiler.ast.BinaryExpression]
1104 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ArithmeticException.class)]
1105 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/BinaryExpression.class]
1106 [javac] [checking org.eclipse.jdt.internal.compiler.ast.CompoundAssignment]
1107 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CompoundAssignment.class]
1108 [javac] [checking org.eclipse.jdt.internal.compiler.ast.UnaryExpression]
1109 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.class]
1110 [javac] [checking org.eclipse.jdt.internal.compiler.ast.EqualExpression]
1111 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.class]
1112 [javac] [checking org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression]
1113 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.class]
1114 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ArrayReference]
1115 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayReference.class]
1116 [javac] [checking org.eclipse.jdt.internal.compiler.ast.CastExpression]
1117 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression$1.class]
1118 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.class]
1119 [javac] [checking org.eclipse.jdt.internal.compiler.ast.BranchStatement]
1120 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/BranchStatement.class]
1121 [javac] [checking org.eclipse.jdt.internal.compiler.ast.LabeledStatement]
1122 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/LabeledStatement.class]
1123 [javac] [checking org.eclipse.jdt.internal.compiler.ast.TryStatement]
1124 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.class]
1125 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.SyntheticFieldBinding]
1126 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticFieldBinding.class]
1127 [javac] [checking org.eclipse.jdt.internal.compiler.parser.NLSTag]
1128 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/NLSTag.class]
1129 [javac] [checking org.eclipse.jdt.internal.compiler.ast.StringLiteral]
1130 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/StringLiteral.class]
1131 [javac] [checking org.eclipse.jdt.internal.compiler.env.ICompilationUnit]
1132 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.class]
1133 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveryScannerData]
1134 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveryScannerData.class]
1135 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.DoubleCache]
1136 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/DoubleCache.class]
1137 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.FloatCache]
1138 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/FloatCache.class]
1139 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.IntegerCache]
1140 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/IntegerCache.class]
1141 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.LongCache]
1142 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/LongCache.class]
1143 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.CharArrayCache]
1144 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/CharArrayCache.class]
1145 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.InnerEmulationDependency]
1146 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/InnerEmulationDependency.class]
1147 [javac] [checking org.eclipse.jdt.internal.compiler.env.AccessRule]
1148 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/AccessRule.class]
1149 [javac] [checking org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer]
1150 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/NameEnvironmentAnswer.class]
1151 [javac] [checking org.eclipse.jdt.internal.compiler.env.ISourceType]
1152 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ISourceType.class]
1153 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryNestedType]
1154 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryNestedType.class]
1155 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryField]
1156 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryField.class]
1157 [javac] [checking org.eclipse.jdt.internal.compiler.env.IGenericField]
1158 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IGenericField.class]
1159 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryMethod]
1160 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryMethod.class]
1161 [javac] [checking org.eclipse.jdt.internal.compiler.env.IGenericMethod]
1162 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IGenericMethod.class]
1163 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation]
1164 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryAnnotation.class]
1165 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.ObjectCache]
1166 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/ObjectCache.class]
1167 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredElement]
1168 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredElement.class]
1169 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveryScanner]
1170 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/ArrayIndexOutOfBoundsException.class)]
1171 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveryScanner.class]
1172 [javac] [checking org.eclipse.jdt.internal.compiler.parser.Scanner]
1173 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.class]
1174 [javac] [checking org.eclipse.jdt.internal.compiler.parser.JavadocParser]
1175 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.class]
1176 [javac] [checking org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser]
1177 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.class]
1178 [javac] [checking org.eclipse.jdt.internal.compiler.parser.JavadocTagConstants]
1179 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/JavadocTagConstants.class]
1180 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference]
1181 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.class]
1182 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference]
1183 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayQualifiedTypeReference.class]
1184 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredType]
1185 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredType.class]
1186 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredStatement]
1187 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredStatement.class]
1188 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ArrayInitializer]
1189 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.class]
1190 [javac] [checking org.eclipse.jdt.internal.compiler.ast.CharLiteral]
1191 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/CharLiteral.class]
1192 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral]
1193 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ExtendedStringLiteral.class]
1194 [javac] [checking org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation]
1195 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/StringLiteralConcatenation.class]
1196 [javac] [checking org.eclipse.jdt.internal.compiler.env.ISourceField]
1197 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ISourceField.class]
1198 [javac] [checking org.eclipse.jdt.internal.compiler.env.ISourceMethod]
1199 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ISourceMethod.class]
1200 [javac] [checking org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair]
1201 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/IBinaryElementValuePair.class]
1202 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredBlock]
1203 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.class]
1204 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredInitializer]
1205 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.class]
1206 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredField]
1207 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredField.class]
1208 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredMethod]
1209 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.class]
1210 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredLocalVariable]
1211 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredLocalVariable.class]
1212 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression]
1213 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.class]
1214 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference]
1215 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayTypeReference.class]
1216 [javac] [checking org.eclipse.jdt.internal.compiler.ast.AssertStatement]
1217 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.class]
1218 [javac] [checking org.eclipse.jdt.internal.compiler.ast.BreakStatement]
1219 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.class]
1220 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess]
1221 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.class]
1222 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Clinit]
1223 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.class]
1224 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ContinueStatement]
1225 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ContinueStatement.class]
1226 [javac] [checking org.eclipse.jdt.internal.compiler.ast.DoStatement]
1227 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.class]
1228 [javac] [checking org.eclipse.jdt.internal.compiler.ast.DoubleLiteral]
1229 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/DoubleLiteral.class]
1230 [javac] [checking org.eclipse.jdt.internal.compiler.ast.EmptyStatement]
1231 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/EmptyStatement.class]
1232 [javac] [checking org.eclipse.jdt.internal.compiler.ast.FalseLiteral]
1233 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/FalseLiteral.class]
1234 [javac] [checking org.eclipse.jdt.internal.compiler.ast.MagicLiteral]
1235 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/MagicLiteral.class]
1236 [javac] [checking org.eclipse.jdt.internal.compiler.ast.FloatLiteral]
1237 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/FloatLiteral.class]
1238 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ForeachStatement]
1239 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.class]
1240 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ForStatement]
1241 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.class]
1242 [javac] [checking org.eclipse.jdt.internal.compiler.ast.IfStatement]
1243 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.class]
1244 [javac] [checking org.eclipse.jdt.internal.compiler.ast.IntLiteral]
1245 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/IntLiteral.class]
1246 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression]
1247 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocArgumentExpression.class]
1248 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocArrayQualifiedTypeReference]
1249 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocArrayQualifiedTypeReference.class]
1250 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference]
1251 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocQualifiedTypeReference.class]
1252 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocArraySingleTypeReference]
1253 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocArraySingleTypeReference.class]
1254 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference]
1255 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocFieldReference.class]
1256 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend]
1257 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocMessageSend.class]
1258 [javac] [checking org.eclipse.jdt.internal.compiler.ast.LongLiteral]
1259 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/LongLiteral.class]
1260 [javac] [checking org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation]
1261 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/MarkerAnnotation.class]
1262 [javac] [checking org.eclipse.jdt.internal.compiler.ast.NormalAnnotation]
1263 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/NormalAnnotation.class]
1264 [javac] [checking org.eclipse.jdt.internal.compiler.ast.NullLiteral]
1265 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/NullLiteral.class]
1266 [javac] [checking org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression]
1267 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.class]
1268 [javac] [checking org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference]
1269 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.class]
1270 [javac] [checking org.eclipse.jdt.internal.compiler.ast.PostfixExpression]
1271 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/PostfixExpression.class]
1272 [javac] [checking org.eclipse.jdt.internal.compiler.ast.PrefixExpression]
1273 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/PrefixExpression.class]
1274 [javac] [checking org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference]
1275 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedSuperReference.class]
1276 [javac] [checking org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference]
1277 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.class]
1278 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation]
1279 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SingleMemberAnnotation.class]
1280 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SuperReference]
1281 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SuperReference.class]
1282 [javac] [checking org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement]
1283 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.class]
1284 [javac] [checking org.eclipse.jdt.internal.compiler.ast.TrueLiteral]
1285 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/TrueLiteral.class]
1286 [javac] [checking org.eclipse.jdt.internal.compiler.ast.WhileStatement]
1287 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.class]
1288 [javac] [checking org.eclipse.jdt.internal.compiler.ast.Wildcard]
1289 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/Wildcard.class]
1290 [javac] [checking org.eclipse.jdt.internal.compiler.Compiler]
1291 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/Compiler$1.class]
1292 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/Compiler.class]
1293 [javac] [checking org.eclipse.jdt.internal.compiler.ICompilerRequestor]
1294 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ICompilerRequestor.class]
1295 [javac] [checking org.eclipse.jdt.internal.compiler.IDebugRequestor]
1296 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/IDebugRequestor.class]
1297 [javac] [checking org.eclipse.jdt.internal.compiler.ConfigurableOption]
1298 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ConfigurableOption.class]
1299 [javac] [checking org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies]
1300 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies$1.class]
1301 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies$2.class]
1302 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies$3.class]
1303 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies$4.class]
1304 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/DefaultErrorHandlingPolicies.class]
1305 [javac] [checking org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue]
1306 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/IntLiteralMinValue.class]
1307 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression]
1308 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocAllocationExpression.class]
1309 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference]
1310 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocImplicitTypeReference.class]
1311 [javac] [checking org.eclipse.jdt.internal.compiler.ast.JavadocImportReference]
1312 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/JavadocImportReference.class]
1313 [javac] [checking org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue]
1314 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/ast/LongLiteralMinValue.class]
1315 [javac] [checking org.eclipse.jdt.internal.compiler.batch.ClasspathDirectory]
1316 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.class]
1317 [javac] [checking org.eclipse.jdt.internal.compiler.batch.ClasspathLocation]
1318 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.class]
1319 [javac] [checking org.eclipse.jdt.internal.compiler.batch.FileSystem]
1320 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/FileSystem$Classpath.class]
1321 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/FileSystem.class]
1322 [javac] [checking org.eclipse.jdt.internal.compiler.util.SuffixConstants]
1323 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/SuffixConstants.class]
1324 [javac] [checking org.eclipse.jdt.internal.compiler.env.AccessRuleSet]
1325 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.class]
1326 [javac] [checking org.eclipse.jdt.internal.compiler.batch.ClasspathJar]
1327 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/util/zip/ZipException.class)]
1328 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.class]
1329 [javac] [checking org.eclipse.jdt.internal.compiler.batch.ClasspathSourceJar]
1330 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.class]
1331 [javac] [checking org.eclipse.jdt.internal.compiler.batch.CompilationUnit]
1332 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.class]
1333 [javac] [checking org.eclipse.jdt.internal.compiler.batch.FileFinder]
1334 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/FileFinder.class]
1335 [javac] [checking org.eclipse.jdt.internal.compiler.batch.Main]
1336 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/BufferedReader.class)]
1337 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/FileFilter.class)]
1338 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/Main$Logger.class]
1339 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/Main$1.class]
1340 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/Main$2.class]
1341 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/Main$3.class]
1342 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/batch/Main.class]
1343 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.AnnotationInfo]
1344 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/io/ByteArrayOutputStream.class)]
1345 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/AnnotationInfo.class]
1346 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct]
1347 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileStruct.class]
1348 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.ElementValuePairInfo]
1349 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/ElementValuePairInfo.class]
1350 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException]
1351 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFormatException.class]
1352 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.AnnotationMethodInfo]
1353 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/AnnotationMethodInfo.class]
1354 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.MethodInfo]
1355 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.class]
1356 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.AnnotationMethodInfoWithAnnotations]
1357 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/AnnotationMethodInfoWithAnnotations.class]
1358 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader]
1359 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.class]
1360 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.FieldInfo]
1361 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Byte.class)]
1362 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/Short.class)]
1363 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.class]
1364 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.InnerClassInfo]
1365 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/InnerClassInfo.class]
1366 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.FieldInfoWithAnnotation]
1367 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfoWithAnnotation.class]
1368 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.MethodInfoWithAnnotations]
1369 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithAnnotations.class]
1370 [javac] [checking org.eclipse.jdt.internal.compiler.classfmt.MethodInfoWithParameterAnnotations]
1371 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.class]
1372 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants]
1373 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/AttributeNamesConstants.class]
1374 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.CachedIndexEntry]
1375 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/CachedIndexEntry.class]
1376 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.FieldNameAndTypeCache]
1377 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/FieldNameAndTypeCache.class]
1378 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.MethodNameAndTypeCache]
1379 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/MethodNameAndTypeCache.class]
1380 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.Opcodes]
1381 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/Opcodes.class]
1382 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.StackMapFrame]
1383 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrame.class]
1384 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.VerificationTypeInfo]
1385 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/VerificationTypeInfo.class]
1386 [javac] [checking org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream]
1387 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.class]
1388 [javac] [checking org.eclipse.jdt.internal.compiler.env.ClassSignature]
1389 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ClassSignature.class]
1390 [javac] [checking org.eclipse.jdt.internal.compiler.env.EnumConstantSignature]
1391 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/EnumConstantSignature.class]
1392 [javac] [checking org.eclipse.jdt.internal.compiler.env.ISourceImport]
1393 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/env/ISourceImport.class]
1394 [javac] [checking org.eclipse.jdt.internal.compiler.flow.ConditionalFlowInfo]
1395 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.class]
1396 [javac] [checking org.eclipse.jdt.internal.compiler.flow.FinallyFlowContext]
1397 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.class]
1398 [javac] [checking org.eclipse.jdt.internal.compiler.flow.InsideSubRoutineFlowContext]
1399 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/InsideSubRoutineFlowContext.class]
1400 [javac] [checking org.eclipse.jdt.internal.compiler.flow.LabelFlowContext]
1401 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/LabelFlowContext.class]
1402 [javac] [checking org.eclipse.jdt.internal.compiler.flow.SwitchFlowContext]
1403 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/SwitchFlowContext.class]
1404 [javac] [checking org.eclipse.jdt.internal.compiler.flow.LoopingFlowContext]
1405 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.class]
1406 [javac] [checking org.eclipse.jdt.internal.compiler.impl.BooleanConstant]
1407 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/BooleanConstant.class]
1408 [javac] [checking org.eclipse.jdt.internal.compiler.impl.ByteConstant]
1409 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/ByteConstant.class]
1410 [javac] [checking org.eclipse.jdt.internal.compiler.impl.CharConstant]
1411 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/CharConstant.class]
1412 [javac] [checking org.eclipse.jdt.internal.compiler.impl.DoubleConstant]
1413 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/DoubleConstant.class]
1414 [javac] [checking org.eclipse.jdt.internal.compiler.impl.FloatConstant]
1415 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/FloatConstant.class]
1416 [javac] [checking org.eclipse.jdt.internal.compiler.impl.IntConstant]
1417 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/IntConstant.class]
1418 [javac] [checking org.eclipse.jdt.internal.compiler.impl.LongConstant]
1419 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/LongConstant.class]
1420 [javac] [checking org.eclipse.jdt.internal.compiler.impl.ShortConstant]
1421 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/ShortConstant.class]
1422 [javac] [checking org.eclipse.jdt.internal.compiler.impl.StringConstant]
1423 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/impl/StringConstant.class]
1424 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.CaptureBinding]
1425 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.class]
1426 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers]
1427 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtraCompilerModifiers.class]
1428 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ImportConflictBinding]
1429 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ImportConflictBinding.class]
1430 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15]
1431 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.class]
1432 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ParameterizedFieldBinding]
1433 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedFieldBinding.class]
1434 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemBinding]
1435 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemBinding.class]
1436 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding]
1437 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemFieldBinding.class]
1438 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding]
1439 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemMethodBinding.class]
1440 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.TagBits]
1441 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.class]
1442 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding]
1443 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedAnnotationBinding.class]
1444 [javac] [checking org.eclipse.jdt.internal.compiler.lookup.UpdatedMethodBinding]
1445 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/lookup/UpdatedMethodBinding.class]
1446 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredImport]
1447 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredImport.class]
1448 [javac] [checking org.eclipse.jdt.internal.compiler.parser.RecoveredUnit]
1449 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredUnit.class]
1450 [javac] [checking org.eclipse.jdt.internal.compiler.parser.ScannerHelper]
1451 [javac] [loading /opt/sun-jdk-1.4.2.12/jre/lib/rt.jar(java/lang/NullPointerException.class)]
1452 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/ScannerHelper.class]
1453 [javac] [checking org.eclipse.jdt.internal.compiler.parser.diagnose.DiagnoseParser]
1454 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser$RepairCandidate.class]
1455 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser$PrimaryRepairInfo.class]
1456 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser$SecondaryRepairInfo.class]
1457 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser$StateInfo.class]
1458 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/DiagnoseParser.class]
1459 [javac] [checking org.eclipse.jdt.internal.compiler.parser.diagnose.LexStream]
1460 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream$Token.class]
1461 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/LexStream.class]
1462 [javac] [checking org.eclipse.jdt.internal.compiler.parser.diagnose.RangeUtil]
1463 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil$RangeResult.class]
1464 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/parser/diagnose/RangeUtil.class]
1465 [javac] [checking org.eclipse.jdt.internal.compiler.problem.AbortMethod]
1466 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/AbortMethod.class]
1467 [javac] [checking org.eclipse.jdt.internal.compiler.problem.AbortType]
1468 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/AbortType.class]
1469 [javac] [checking org.eclipse.jdt.internal.compiler.problem.DefaultProblem]
1470 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.class]
1471 [javac] [checking org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory]
1472 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblemFactory.class]
1473 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfInt]
1474 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfInt.class]
1475 [javac] [checking org.eclipse.jdt.internal.compiler.problem.ShouldNotImplement]
1476 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/problem/ShouldNotImplement.class]
1477 [javac] [checking org.eclipse.jdt.internal.compiler.util.FloatUtil]
1478 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/FloatUtil.class]
1479 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfIntValues]
1480 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfIntValues.class]
1481 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfLong]
1482 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfLong.class]
1483 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt]
1484 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToInt.class]
1485 [javac] [checking org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToIntArray]
1486 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/HashtableOfObjectToIntArray.class]
1487 [javac] [checking org.eclipse.jdt.internal.compiler.util.Messages]
1488 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/Messages$MessagesProperties.class]
1489 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/Messages.class]
1490 [javac] [checking org.eclipse.jdt.internal.compiler.util.SimpleSet]
1491 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/SimpleSet.class]
1492 [javac] [checking org.eclipse.jdt.internal.compiler.util.Util]
1493 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/Util$Displayable.class]
1494 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/Util$1.class]
1495 [javac] [wrote /volatile/portage/eclipse-sdk-3.2/work/jdtcoresrc/compiler/org/eclipse/jdt/internal/compiler/util/Util.class]
1496 [javac] [total 10900ms]
1497 [echo] UPDATE ecj.jar
1498
1499 BUILD SUCCESSFUL
1500 Total time: 16 seconds
1501 [echo] TARGET: compiler2
1502 [echo] compilerArg -encoding ISO-8859-1
1503 [echo] build compiler org.eclipse.jdt.core.JDTCompilerAdapter
1504 [echo] UPDATE ecj.jar
1505
1506 BUILD SUCCESSFUL
1507 Total time: 13 seconds
1508 [echo] Deleting jars to recompile...
1509 [echo] Compiling...
1510 [echo] Copying source from org.eclipse.swt project to folder /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.ia64/src folder /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.ia64/temp.folder.
1511 [javac] ----------
1512 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.ia64/src/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1513 [javac] (at line 1101)
1514 [javac] Control control = null;
1515 [javac] ^^^^^^^
1516 [javac] The local variable control is never read
1517 [javac] ----------
1518 [javac] 1 problem (1 warning)
1519 [javac] ----------
1520 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1521 [javac] (at line 1101)
1522 [javac] Control control = null;
1523 [javac] ^^^^^^^
1524 [javac] The local variable control is never read
1525 [javac] ----------
1526 [javac] 1 problem (1 warning)
1527 [javac] ----------
1528 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1529 [javac] (at line 1101)
1530 [javac] Control control = null;
1531 [javac] ^^^^^^^
1532 [javac] The local variable control is never read
1533 [javac] ----------
1534 [javac] 1 problem (1 warning)
1535 [javac] ----------
1536 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1537 [javac] (at line 1101)
1538 [javac] Control control = null;
1539 [javac] ^^^^^^^
1540 [javac] The local variable control is never read
1541 [javac] ----------
1542 [javac] 1 problem (1 warning)
1543 [javac] ----------
1544 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1545 [javac] (at line 1101)
1546 [javac] Control control = null;
1547 [javac] ^^^^^^^
1548 [javac] The local variable control is never read
1549 [javac] ----------
1550 [javac] 1 problem (1 warning)
1551 [javac] ----------
1552 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/AbstractBundle.java
1553 [javac] (at line 1449)
1554 [javac] boolean noMoreElements = false;
1555 [javac] ^^^^^^^^^^^^^^
1556 [javac] The field new Enumeration(){}.noMoreElements is never read locally
1557 [javac] ----------
1558 [javac] ----------
1559 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleRepository.java
1560 [javac] (at line 38)
1561 [javac] private PackageAdminImpl packageAdmin;
1562 [javac] ^^^^^^^^^^^^
1563 [javac] The field BundleRepository.packageAdmin is never read locally
1564 [javac] ----------
1565 [javac] ----------
1566 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FrameworkSecurityManager.java
1567 [javac] (at line 30)
1568 [javac] Class c;
1569 [javac] ^
1570 [javac] The local variable c is never read
1571 [javac] ----------
1572 [javac] ----------
1573 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SecurePermissionStorage.java
1574 [javac] (at line 26)
1575 [javac] private String[] infos;
1576 [javac] ^^^^^
1577 [javac] The field SecurePermissionStorage.infos is never read locally
1578 [javac] ----------
1579 [javac] ----------
1580 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
1581 [javac] (at line 701)
1582 [javac] int bundlestate = bundle.getState();
1583 [javac] ^^^^^^^^^^^
1584 [javac] The local variable bundlestate is never read
1585 [javac] ----------
1586 [javac] ----------
1587 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/launcher/Launcher.java
1588 [javac] (at line 242)
1589 [javac] String cmd = tok.nextToken();
1590 [javac] ^^^
1591 [javac] The local variable cmd is never read
1592 [javac] ----------
1593 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/launcher/Launcher.java
1594 [javac] (at line 258)
1595 [javac] String cmd = tok.getToken(":"); //$NON-NLS-1$
1596 [javac] ^^^
1597 [javac] The local variable cmd is never read
1598 [javac] ----------
1599 [javac] ----------
1600 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/BaseData.java
1601 [javac] (at line 97)
1602 [javac] path = path = '/' + path;
1603 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
1604 [javac] The assignment to variable path has no effect
1605 [javac] ----------
1606 [javac] ----------
1607 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/loader/ClasspathManager.java
1608 [javac] (at line 42)
1609 [javac] private static final int BUF_SIZE = 8 * 1024;
1610 [javac] ^^^^^^^^
1611 [javac] The field ClasspathManager.BUF_SIZE is never read locally
1612 [javac] ----------
1613 [javac] ----------
1614 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java
1615 [javac] (at line 121)
1616 [javac] private static final String CONTEXTCLASSLOADER_PARENT_CCL = "ccl"; //$NON-NLS-1$
1617 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1618 [javac] The field EclipseStarter.CONTEXTCLASSLOADER_PARENT_CCL is never read locally
1619 [javac] ----------
1620 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java
1621 [javac] (at line 124)
1622 [javac] private static final String FILE_PROTOCOL = "file"; //$NON-NLS-1$
1623 [javac] ^^^^^^^^^^^^^
1624 [javac] The field EclipseStarter.FILE_PROTOCOL is never read locally
1625 [javac] ----------
1626 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java
1627 [javac] (at line 570)
1628 [javac] URL child = new URL(name);
1629 [javac] ^^^^^
1630 [javac] The local variable child is never read
1631 [javac] ----------
1632 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java
1633 [javac] (at line 1305)
1634 [javac] private static String buildCommandLine(String arg, String value) {
1635 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1636 [javac] The method buildCommandLine(String, String) from the type EclipseStarter is never used locally
1637 [javac] ----------
1638 [javac] 13 problems (13 warnings)
1639 [javac] ----------
1640 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
1641 [javac] (at line 34)
1642 [javac] import org.eclipse.update.configurator.IPlatformConfiguration.ISitePolicy;
1643 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1644 [javac] The import org.eclipse.update.configurator.IPlatformConfiguration.ISitePolicy is never used
1645 [javac] ----------
1646 [javac] ----------
1647 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/VersionedIdentifier.java
1648 [javac] (at line 16)
1649 [javac] import org.osgi.framework.Version;
1650 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
1651 [javac] The import org.osgi.framework.Version is never used
1652 [javac] ----------
1653 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/VersionedIdentifier.java
1654 [javac] (at line 88)
1655 [javac] private void parseVersion(String v) {
1656 [javac] ^^^^^^^^^^^^^^^^^^^^^^
1657 [javac] The method parseVersion(String) from the type VersionedIdentifier is never used locally
1658 [javac] ----------
1659 [javac] 3 problems (3 warnings)
1660 [echo] Copying source from org.eclipse.swt project to folder /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.x86_64/src folder /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.x86_64/temp.folder.
1661 [javac] ----------
1662 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.gtk.linux.x86_64/src/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
1663 [javac] (at line 1101)
1664 [javac] Control control = null;
1665 [javac] ^^^^^^^
1666 [javac] The local variable control is never read
1667 [javac] ----------
1668 [javac] 1 problem (1 warning)
1669 [javac] ----------
1670 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java
1671 [javac] (at line 386)
1672 [javac] private ContentReference continueOrErrorOrRethrow(String archiveID, CoreException coreException) throws CoreException {
1673 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1674 [javac] The method continueOrErrorOrRethrow(String, CoreException) from the type FeaturePackagedContentProvider is never used locally
1675 [javac] ----------
1676 [javac] ----------
1677 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/src/org/eclipse/update/internal/core/InstallConfiguration.java
1678 [javac] (at line 54)
1679 [javac] import org.eclipse.update.internal.configurator.IConfigurationConstants;
1680 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1681 [javac] The import org.eclipse.update.internal.configurator.IConfigurationConstants is never used
1682 [javac] ----------
1683 [javac] ----------
1684 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/src/org/eclipse/update/internal/core/JarDeltaInstallHandler.java
1685 [javac] (at line 52)
1686 [javac] ContentReference[] oldReferences = oldFeature.getFeatureContentProvider().getPluginEntryContentReferences(oldPlugin, null);
1687 [javac] ^^^^^^^^^^^^^
1688 [javac] The local variable oldReferences is never read
1689 [javac] ----------
1690 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/src/org/eclipse/update/internal/core/JarDeltaInstallHandler.java
1691 [javac] (at line 53)
1692 [javac] ContentReference[] newReferences = feature.getFeatureContentProvider().getPluginEntryContentReferences(newPlugin, null);
1693 [javac] ^^^^^^^^^^^^^
1694 [javac] The local variable newReferences is never read
1695 [javac] ----------
1696 [javac] ----------
1697 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/src/org/eclipse/update/search/UpdateSearchRequest.java
1698 [javac] (at line 13)
1699 [javac] import java.io.File;
1700 [javac] ^^^^^^^^^^^^
1701 [javac] The import java.io.File is never used
1702 [javac] ----------
1703 [javac] 5 problems (5 warnings)
1704 [javac] ----------
1705 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
1706 [javac] (at line 20)
1707 [javac] import org.eclipse.core.internal.content.XMLContentDescriber;
1708 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1709 [javac] Discouraged access: The type XMLContentDescriber is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.core.contenttype/@dot
1710 [javac] ----------
1711 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
1712 [javac] (at line 44)
1713 [javac] public final class AntBuildfileContentDescriber extends XMLContentDescriber implements IExecutableExtension {
1714 [javac] ^^^^^^^^^^^^^^^^^^^
1715 [javac] Discouraged access: The type XMLContentDescriber is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.core.contenttype/@dot
1716 [javac] ----------
1717 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
1718 [javac] (at line 90)
1719 [javac] if (super.describe(contents, description) == INVALID) {
1720 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1721 [javac] Discouraged access: The method describe(InputStream, IContentDescription) from the type XMLContentDescriber is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.core.contenttype/@dot
1722 [javac] ----------
1723 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/contentDescriber/AntBuildfileContentDescriber.java
1724 [javac] (at line 104)
1725 [javac] if (super.describe(contents, description) == INVALID) {
1726 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1727 [javac] Discouraged access: The method describe(Reader, IContentDescription) from the type XMLContentDescriber is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.core.contenttype/@dot
1728 [javac] ----------
1729 [javac] 4 problems (4 warnings)
1730 [javac] ----------
1731 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1732 [javac] (at line 21)
1733 [javac] import org.eclipse.swt.internal.Callback;
1734 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1735 [javac] Discouraged access: The type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1736 [javac] ----------
1737 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1738 [javac] (at line 22)
1739 [javac] import org.eclipse.swt.internal.carbon.HICommand;
1740 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1741 [javac] Discouraged access: The type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1742 [javac] ----------
1743 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1744 [javac] (at line 23)
1745 [javac] import org.eclipse.swt.internal.carbon.OS;
1746 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1747 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1748 [javac] ----------
1749 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1750 [javac] (at line 150)
1751 [javac] int windowHandle = OS.GetControlOwner(shell.handle);
1752 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1753 [javac] Discouraged access: The method GetControlOwner(int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1754 [javac] ----------
1755 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1756 [javac] (at line 150)
1757 [javac] int windowHandle = OS.GetControlOwner(shell.handle);
1758 [javac] ^^
1759 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1760 [javac] ----------
1761 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1762 [javac] (at line 151)
1763 [javac] OS.ChangeWindowAttributes(windowHandle,
1764 [javac] OS.kWindowToolbarButtonAttribute, 0);
1765 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1766 [javac] Discouraged access: The method ChangeWindowAttributes(int, int, int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1767 [javac] ----------
1768 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1769 [javac] (at line 151)
1770 [javac] OS.ChangeWindowAttributes(windowHandle,
1771 [javac] ^^
1772 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1773 [javac] ----------
1774 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1775 [javac] (at line 152)
1776 [javac] OS.kWindowToolbarButtonAttribute, 0);
1777 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1778 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1779 [javac] ----------
1780 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1781 [javac] (at line 152)
1782 [javac] OS.kWindowToolbarButtonAttribute, 0);
1783 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1784 [javac] Discouraged access: The field kWindowToolbarButtonAttribute from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1785 [javac] ----------
1786 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1787 [javac] (at line 164)
1788 [javac] int toolbarProc (int nextHandler, int theEvent, int userData) {
1789 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1790 [javac] The method toolbarProc(int, int, int) from the type new Object(){} is never used locally
1791 [javac] ----------
1792 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1793 [javac] (at line 165)
1794 [javac] int eventKind = OS.GetEventKind (theEvent);
1795 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
1796 [javac] Discouraged access: The method GetEventKind(int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1797 [javac] ----------
1798 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1799 [javac] (at line 165)
1800 [javac] int eventKind = OS.GetEventKind (theEvent);
1801 [javac] ^^
1802 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1803 [javac] ----------
1804 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1805 [javac] (at line 166)
1806 [javac] if (eventKind != OS.kEventWindowToolbarSwitchMode)
1807 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1808 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1809 [javac] ----------
1810 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1811 [javac] (at line 166)
1812 [javac] if (eventKind != OS.kEventWindowToolbarSwitchMode)
1813 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1814 [javac] Discouraged access: The field kEventWindowToolbarSwitchMode from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1815 [javac] ----------
1816 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1817 [javac] (at line 167)
1818 [javac] return OS.eventNotHandledErr;
1819 [javac] ^^^^^^^^^^^^^^^^^^^^^
1820 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1821 [javac] ----------
1822 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1823 [javac] (at line 167)
1824 [javac] return OS.eventNotHandledErr;
1825 [javac] ^^^^^^^^^^^^^^^^^^
1826 [javac] Discouraged access: The field eventNotHandledErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1827 [javac] ----------
1828 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1829 [javac] (at line 170)
1830 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1831 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1832 [javac] Discouraged access: The method GetEventParameter(int, int, int, int[], int, int[], int[]) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1833 [javac] ----------
1834 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1835 [javac] (at line 170)
1836 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1837 [javac] ^^
1838 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1839 [javac] ----------
1840 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1841 [javac] (at line 170)
1842 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1843 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
1844 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1845 [javac] ----------
1846 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1847 [javac] (at line 170)
1848 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1849 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
1850 [javac] Discouraged access: The field kEventParamDirectObject from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1851 [javac] ----------
1852 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1853 [javac] (at line 170)
1854 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1855 [javac] ^^^^^^^^^^^^^^^^
1856 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1857 [javac] ----------
1858 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1859 [javac] (at line 170)
1860 [javac] OS.GetEventParameter (theEvent, OS.kEventParamDirectObject, OS.typeWindowRef, null, 4, null, theWindow);
1861 [javac] ^^^^^^^^^^^^^
1862 [javac] Discouraged access: The field typeWindowRef from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1863 [javac] ----------
1864 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1865 [javac] (at line 173)
1866 [javac] OS.GetRootControl (theWindow [0], theRoot);
1867 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1868 [javac] Discouraged access: The method GetRootControl(int, int[]) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1869 [javac] ----------
1870 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1871 [javac] (at line 173)
1872 [javac] OS.GetRootControl (theWindow [0], theRoot);
1873 [javac] ^^
1874 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1875 [javac] ----------
1876 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1877 [javac] (at line 177)
1878 [javac] return OS.eventNotHandledErr;
1879 [javac] ^^^^^^^^^^^^^^^^^^^^^
1880 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1881 [javac] ----------
1882 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1883 [javac] (at line 177)
1884 [javac] return OS.eventNotHandledErr;
1885 [javac] ^^^^^^^^^^^^^^^^^^
1886 [javac] Discouraged access: The field eventNotHandledErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1887 [javac] ----------
1888 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1889 [javac] (at line 190)
1890 [javac] return OS.eventNotHandledErr;
1891 [javac] ^^^^^^^^^^^^^^^^^^^^^
1892 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1893 [javac] ----------
1894 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1895 [javac] (at line 190)
1896 [javac] return OS.eventNotHandledErr;
1897 [javac] ^^^^^^^^^^^^^^^^^^
1898 [javac] Discouraged access: The field eventNotHandledErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1899 [javac] ----------
1900 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1901 [javac] (at line 203)
1902 [javac] return OS.noErr;
1903 [javac] ^^^^^^^^
1904 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1905 [javac] ----------
1906 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1907 [javac] (at line 203)
1908 [javac] return OS.noErr;
1909 [javac] ^^^^^
1910 [javac] Discouraged access: The field noErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1911 [javac] ----------
1912 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1913 [javac] (at line 206)
1914 [javac] return OS.eventNotHandledErr;
1915 [javac] ^^^^^^^^^^^^^^^^^^^^^
1916 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1917 [javac] ----------
1918 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1919 [javac] (at line 206)
1920 [javac] return OS.eventNotHandledErr;
1921 [javac] ^^^^^^^^^^^^^^^^^^
1922 [javac] Discouraged access: The field eventNotHandledErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1923 [javac] ----------
1924 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1925 [javac] (at line 211)
1926 [javac] final Callback commandCallback = new Callback(target, "toolbarProc", 3); //$NON-NLS-1$
1927 [javac] ^^^^^^^^
1928 [javac] Discouraged access: The type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1929 [javac] ----------
1930 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1931 [javac] (at line 211)
1932 [javac] final Callback commandCallback = new Callback(target, "toolbarProc", 3); //$NON-NLS-1$
1933 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1934 [javac] Discouraged access: The constructor Callback(Object, String, int) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1935 [javac] ----------
1936 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1937 [javac] (at line 211)
1938 [javac] final Callback commandCallback = new Callback(target, "toolbarProc", 3); //$NON-NLS-1$
1939 [javac] ^^^^^^^^
1940 [javac] Discouraged access: The type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1941 [javac] ----------
1942 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1943 [javac] (at line 212)
1944 [javac] int commandProc = commandCallback.getAddress();
1945 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1946 [javac] Discouraged access: The method getAddress() from the type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1947 [javac] ----------
1948 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1949 [javac] (at line 214)
1950 [javac] commandCallback.dispose();
1951 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
1952 [javac] Discouraged access: The method dispose() from the type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1953 [javac] ----------
1954 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1955 [javac] (at line 218)
1956 [javac] int[] mask = new int[] { OS.kEventClassWindow, OS.kEventWindowToolbarSwitchMode };
1957 [javac] ^^^^^^^^^^^^^^^^^^^^
1958 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1959 [javac] ----------
1960 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1961 [javac] (at line 218)
1962 [javac] int[] mask = new int[] { OS.kEventClassWindow, OS.kEventWindowToolbarSwitchMode };
1963 [javac] ^^^^^^^^^^^^^^^^^
1964 [javac] Discouraged access: The field kEventClassWindow from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1965 [javac] ----------
1966 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1967 [javac] (at line 218)
1968 [javac] int[] mask = new int[] { OS.kEventClassWindow, OS.kEventWindowToolbarSwitchMode };
1969 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1970 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1971 [javac] ----------
1972 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1973 [javac] (at line 218)
1974 [javac] int[] mask = new int[] { OS.kEventClassWindow, OS.kEventWindowToolbarSwitchMode };
1975 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1976 [javac] Discouraged access: The field kEventWindowToolbarSwitchMode from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1977 [javac] ----------
1978 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1979 [javac] (at line 219)
1980 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
1981 [javac] mask.length / 2, mask, 0, null);
1982 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1983 [javac] Discouraged access: The method InstallEventHandler(int, int, int, int[], int, int[]) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1984 [javac] ----------
1985 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1986 [javac] (at line 219)
1987 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
1988 [javac] ^^
1989 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1990 [javac] ----------
1991 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1992 [javac] (at line 219)
1993 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
1994 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1995 [javac] Discouraged access: The method GetApplicationEventTarget() from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
1996 [javac] ----------
1997 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
1998 [javac] (at line 219)
1999 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
2000 [javac] ^^
2001 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2002 [javac] ----------
2003 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2004 [javac] (at line 231)
2005 [javac] int commandProc(int nextHandler, int theEvent, int userData) {
2006 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2007 [javac] The method commandProc(int, int, int) from the type new Object(){} is never used locally
2008 [javac] ----------
2009 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2010 [javac] (at line 232)
2011 [javac] if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
2012 [javac] ^^
2013 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2014 [javac] ----------
2015 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2016 [javac] (at line 232)
2017 [javac] if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
2018 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2019 [javac] Discouraged access: The method GetEventKind(int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2020 [javac] ----------
2021 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2022 [javac] (at line 232)
2023 [javac] if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
2024 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2025 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2026 [javac] ----------
2027 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2028 [javac] (at line 232)
2029 [javac] if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
2030 [javac] ^^^^^^^^^^^^^^^^^^^^
2031 [javac] Discouraged access: The field kEventProcessCommand from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2032 [javac] ----------
2033 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2034 [javac] (at line 233)
2035 [javac] HICommand command = new HICommand();
2036 [javac] ^^^^^^^^^
2037 [javac] Discouraged access: The type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2038 [javac] ----------
2039 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2040 [javac] (at line 233)
2041 [javac] HICommand command = new HICommand();
2042 [javac] ^^^^^^^^^^^^^^^
2043 [javac] Discouraged access: The constructor HICommand() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2044 [javac] ----------
2045 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2046 [javac] (at line 233)
2047 [javac] HICommand command = new HICommand();
2048 [javac] ^^^^^^^^^
2049 [javac] Discouraged access: The type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2050 [javac] ----------
2051 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2052 [javac] (at line 234)
2053 [javac] OS.GetEventParameter(theEvent, OS.kEventParamDirectObject,
2054 [javac] OS.typeHICommand, null, HICommand.sizeof, null, command);
2055 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2056 [javac] Discouraged access: The method GetEventParameter(int, int, int, int[], int, int[], HICommand) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2057 [javac] ----------
2058 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2059 [javac] (at line 234)
2060 [javac] OS.GetEventParameter(theEvent, OS.kEventParamDirectObject,
2061 [javac] ^^
2062 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2063 [javac] ----------
2064 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2065 [javac] (at line 234)
2066 [javac] OS.GetEventParameter(theEvent, OS.kEventParamDirectObject,
2067 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
2068 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2069 [javac] ----------
2070 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2071 [javac] (at line 234)
2072 [javac] OS.GetEventParameter(theEvent, OS.kEventParamDirectObject,
2073 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2074 [javac] Discouraged access: The field kEventParamDirectObject from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2075 [javac] ----------
2076 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2077 [javac] (at line 235)
2078 [javac] OS.typeHICommand, null, HICommand.sizeof, null, command);
2079 [javac] ^^^^^^^^^^^^^^^^
2080 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2081 [javac] ----------
2082 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2083 [javac] (at line 235)
2084 [javac] OS.typeHICommand, null, HICommand.sizeof, null, command);
2085 [javac] ^^^^^^^^^^^^^
2086 [javac] Discouraged access: The field typeHICommand from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2087 [javac] ----------
2088 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2089 [javac] (at line 235)
2090 [javac] OS.typeHICommand, null, HICommand.sizeof, null, command);
2091 [javac] ^^^^^^^^^^^^^^^^
2092 [javac] Discouraged access: The type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2093 [javac] ----------
2094 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2095 [javac] (at line 235)
2096 [javac] OS.typeHICommand, null, HICommand.sizeof, null, command);
2097 [javac] ^^^^^^
2098 [javac] Discouraged access: The field sizeof from the type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2099 [javac] ----------
2100 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2101 [javac] (at line 236)
2102 [javac] switch (command.commandID) {
2103 [javac] ^^^^^^^^^
2104 [javac] Discouraged access: The field commandID from the type HICommand is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2105 [javac] ----------
2106 [javac] 63. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2107 [javac] (at line 245)
2108 [javac] return OS.eventNotHandledErr;
2109 [javac] ^^^^^^^^^^^^^^^^^^^^^
2110 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2111 [javac] ----------
2112 [javac] 64. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2113 [javac] (at line 245)
2114 [javac] return OS.eventNotHandledErr;
2115 [javac] ^^^^^^^^^^^^^^^^^^
2116 [javac] Discouraged access: The field eventNotHandledErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2117 [javac] ----------
2118 [javac] 65. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2119 [javac] (at line 249)
2120 [javac] final Callback commandCallback = new Callback(target, "commandProc", 3); //$NON-NLS-1$
2121 [javac] ^^^^^^^^
2122 [javac] Discouraged access: The type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2123 [javac] ----------
2124 [javac] 66. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2125 [javac] (at line 249)
2126 [javac] final Callback commandCallback = new Callback(target, "commandProc", 3); //$NON-NLS-1$
2127 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2128 [javac] Discouraged access: The constructor Callback(Object, String, int) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2129 [javac] ----------
2130 [javac] 67. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2131 [javac] (at line 249)
2132 [javac] final Callback commandCallback = new Callback(target, "commandProc", 3); //$NON-NLS-1$
2133 [javac] ^^^^^^^^
2134 [javac] Discouraged access: The type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2135 [javac] ----------
2136 [javac] 68. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2137 [javac] (at line 250)
2138 [javac] int commandProc = commandCallback.getAddress();
2139 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2140 [javac] Discouraged access: The method getAddress() from the type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2141 [javac] ----------
2142 [javac] 69. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2143 [javac] (at line 252)
2144 [javac] commandCallback.dispose();
2145 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2146 [javac] Discouraged access: The method dispose() from the type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2147 [javac] ----------
2148 [javac] 70. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2149 [javac] (at line 257)
2150 [javac] int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
2151 [javac] ^^^^^^^^^^^^^^^^^^^^^
2152 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2153 [javac] ----------
2154 [javac] 71. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2155 [javac] (at line 257)
2156 [javac] int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
2157 [javac] ^^^^^^^^^^^^^^^^^^
2158 [javac] Discouraged access: The field kEventClassCommand from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2159 [javac] ----------
2160 [javac] 72. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2161 [javac] (at line 257)
2162 [javac] int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
2163 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2164 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2165 [javac] ----------
2166 [javac] 73. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2167 [javac] (at line 257)
2168 [javac] int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
2169 [javac] ^^^^^^^^^^^^^^^^^^^^
2170 [javac] Discouraged access: The field kEventProcessCommand from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2171 [javac] ----------
2172 [javac] 74. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2173 [javac] (at line 258)
2174 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
2175 [javac] mask.length / 2, mask, 0, null);
2176 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2177 [javac] Discouraged access: The method InstallEventHandler(int, int, int, int[], int, int[]) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2178 [javac] ----------
2179 [javac] 75. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2180 [javac] (at line 258)
2181 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
2182 [javac] ^^
2183 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2184 [javac] ----------
2185 [javac] 76. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2186 [javac] (at line 258)
2187 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
2188 [javac] ^^
2189 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2190 [javac] ----------
2191 [javac] 77. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2192 [javac] (at line 258)
2193 [javac] OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
2194 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2195 [javac] Discouraged access: The method GetApplicationEventTarget() from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2196 [javac] ----------
2197 [javac] 78. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2198 [javac] (at line 264)
2199 [javac] if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr
2200 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2201 [javac] Discouraged access: The method GetIndMenuItemWithCommandID(int, int, int, int[], short[]) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2202 [javac] ----------
2203 [javac] 79. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2204 [javac] (at line 264)
2205 [javac] if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr
2206 [javac] ^^
2207 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2208 [javac] ----------
2209 [javac] 80. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2210 [javac] (at line 264)
2211 [javac] if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr
2212 [javac] ^^^^^^^^
2213 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2214 [javac] ----------
2215 [javac] 81. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2216 [javac] (at line 264)
2217 [javac] if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr
2218 [javac] ^^^^^
2219 [javac] Discouraged access: The field noErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2220 [javac] ----------
2221 [javac] 82. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2222 [javac] (at line 271)
2223 [javac] int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l);
2224 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2225 [javac] Discouraged access: The method CFStringCreateWithCharacters(int, char[], int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2226 [javac] ----------
2227 [javac] 83. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2228 [javac] (at line 271)
2229 [javac] int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l);
2230 [javac] ^^
2231 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2232 [javac] ----------
2233 [javac] 84. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2234 [javac] (at line 271)
2235 [javac] int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l);
2236 [javac] ^^^^^^^^^^^^^^^^^^^^^^
2237 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2238 [javac] ----------
2239 [javac] 85. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2240 [javac] (at line 271)
2241 [javac] int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l);
2242 [javac] ^^^^^^^^^^^^^^^^^^^
2243 [javac] Discouraged access: The field kCFAllocatorDefault from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2244 [javac] ----------
2245 [javac] 86. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2246 [javac] (at line 272)
2247 [javac] OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0, kHICommandAbout);
2248 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2249 [javac] Discouraged access: The method InsertMenuItemTextWithCFString(int, int, short, int, int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2250 [javac] ----------
2251 [javac] 87. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2252 [javac] (at line 272)
2253 [javac] OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0, kHICommandAbout);
2254 [javac] ^^
2255 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2256 [javac] ----------
2257 [javac] 88. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2258 [javac] (at line 273)
2259 [javac] OS.CFRelease(str);
2260 [javac] ^^
2261 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2262 [javac] ----------
2263 [javac] 89. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2264 [javac] (at line 273)
2265 [javac] OS.CFRelease(str);
2266 [javac] ^^^^^^^^^^^^^^^^^
2267 [javac] Discouraged access: The method CFRelease(int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2268 [javac] ----------
2269 [javac] 90. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2270 [javac] (at line 276)
2271 [javac] OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0);
2272 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2273 [javac] Discouraged access: The method InsertMenuItemTextWithCFString(int, int, short, int, int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2274 [javac] ----------
2275 [javac] 91. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2276 [javac] (at line 276)
2277 [javac] OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0);
2278 [javac] ^^
2279 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2280 [javac] ----------
2281 [javac] 92. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2282 [javac] (at line 276)
2283 [javac] OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0);
2284 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2285 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2286 [javac] ----------
2287 [javac] 93. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2288 [javac] (at line 276)
2289 [javac] OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0);
2290 [javac] ^^^^^^^^^^^^^^^^^^^^^^
2291 [javac] Discouraged access: The field kMenuItemAttrSeparator from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2292 [javac] ----------
2293 [javac] 94. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2294 [javac] (at line 279)
2295 [javac] OS.EnableMenuCommand(menu, kHICommandPreferences);
2296 [javac] ^^
2297 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2298 [javac] ----------
2299 [javac] 95. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2300 [javac] (at line 279)
2301 [javac] OS.EnableMenuCommand(menu, kHICommandPreferences);
2302 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2303 [javac] Discouraged access: The method EnableMenuCommand(int, int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2304 [javac] ----------
2305 [javac] 96. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2306 [javac] (at line 282)
2307 [javac] OS.DisableMenuCommand(menu, kHICommandServices);
2308 [javac] ^^
2309 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2310 [javac] ----------
2311 [javac] 97. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2312 [javac] (at line 282)
2313 [javac] OS.DisableMenuCommand(menu, kHICommandServices);
2314 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2315 [javac] Discouraged access: The method DisableMenuCommand(int, int) from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2316 [javac] ----------
2317 [javac] 98. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2318 [javac] (at line 288)
2319 [javac] commandCallback.dispose();
2320 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2321 [javac] Discouraged access: The method dispose() from the type Callback is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2322 [javac] ----------
2323 [javac] 99. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2324 [javac] (at line 315)
2325 [javac] return OS.noErr;
2326 [javac] ^^^^^^^^
2327 [javac] Discouraged access: The type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2328 [javac] ----------
2329 [javac] 100. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.carbon/src/org/eclipse/ui/carbon/CarbonUIEnhancer.java
2330 [javac] (at line 315)
2331 [javac] return OS.noErr;
2332 [javac] ^^^^^
2333 [javac] Discouraged access: The field noErr from the type OS is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.swt.carbon.macosx/@dot
2334 [javac] ----------
2335 [javac] 100 problems (100 warnings)
2336 [javac] ----------
2337 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.ui/src/org/eclipse/update/internal/ui/wizards/ReviewPage.java
2338 [javac] (at line 73)
2339 [javac] import org.eclipse.update.internal.core.ExtendedSite;
2340 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2341 [javac] The import org.eclipse.update.internal.core.ExtendedSite is never used
2342 [javac] ----------
2343 [javac] ----------
2344 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.ui/src/org/eclipse/update/internal/ui/wizards/ShowActivitiesDialog.java
2345 [javac] (at line 106)
2346 [javac] url.setText(((InstallConfiguration)SiteManager.getLocalSite().getCurrentConfiguration()).getURL().getFile());
2347 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2348 [javac] Discouraged access: The method getURL() from the type InstallConfigurationModel is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
2349 [javac] ----------
2350 [javac] 2 problems (2 warnings)
2351 [javac] ----------
2352 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
2353 [javac] (at line 154)
2354 [javac] import org.eclipse.ui.internal.EditorPluginAction;
2355 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2356 [javac] Discouraged access: The type EditorPluginAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2357 [javac] ----------
2358 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
2359 [javac] (at line 4080)
2360 [javac] return new EditorPluginAction(element, this, defId, IAction.AS_UNSPECIFIED);
2361 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2362 [javac] Discouraged access: The constructor EditorPluginAction(IConfigurationElement, IEditorPart, String, int) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2363 [javac] ----------
2364 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
2365 [javac] (at line 4080)
2366 [javac] return new EditorPluginAction(element, this, defId, IAction.AS_UNSPECIFIED);
2367 [javac] ^^^^^^^^^^^^^^^^^^
2368 [javac] Discouraged access: The type EditorPluginAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2369 [javac] ----------
2370 [javac] 3 problems (3 warnings)
2371 [javac] ----------
2372 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectAction.java
2373 [javac] (at line 35)
2374 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2375 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2376 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2377 [javac] ----------
2378 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectAction.java
2379 [javac] (at line 190)
2380 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2381 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2382 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2383 [javac] ----------
2384 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectAction.java
2385 [javac] (at line 190)
2386 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2387 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2388 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2389 [javac] ----------
2390 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectAction.java
2391 [javac] (at line 190)
2392 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2393 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2394 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2395 [javac] ----------
2396 [javac] ----------
2397 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectOperation.java
2398 [javac] (at line 37)
2399 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2400 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2401 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2402 [javac] ----------
2403 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectOperation.java
2404 [javac] (at line 160)
2405 [javac] new ProgressMonitorJobsDialog(parentShell).run(true, true, op);
2406 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2407 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2408 [javac] ----------
2409 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectOperation.java
2410 [javac] (at line 160)
2411 [javac] new ProgressMonitorJobsDialog(parentShell).run(true, true, op);
2412 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2413 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2414 [javac] ----------
2415 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/CopyProjectOperation.java
2416 [javac] (at line 160)
2417 [javac] new ProgressMonitorJobsDialog(parentShell).run(true, true, op);
2418 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2419 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2420 [javac] ----------
2421 [javac] ----------
2422 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveProjectAction.java
2423 [javac] (at line 34)
2424 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2425 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2426 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2427 [javac] ----------
2428 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveProjectAction.java
2429 [javac] (at line 115)
2430 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2431 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2432 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2433 [javac] ----------
2434 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveProjectAction.java
2435 [javac] (at line 115)
2436 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2437 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2438 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2439 [javac] ----------
2440 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/MoveProjectAction.java
2441 [javac] (at line 115)
2442 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2443 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2444 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2445 [javac] ----------
2446 [javac] ----------
2447 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2448 [javac] (at line 24)
2449 [javac] import org.eclipse.ui.internal.dialogs.NewWizard;
2450 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2451 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2452 [javac] ----------
2453 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2454 [javac] (at line 28)
2455 [javac] import org.eclipse.ui.internal.registry.WizardsRegistryReader;
2456 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2457 [javac] Discouraged access: The type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2458 [javac] ----------
2459 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2460 [javac] (at line 90)
2461 [javac] NewWizard wizard = new NewWizard();
2462 [javac] ^^^^^^^^^
2463 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2464 [javac] ----------
2465 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2466 [javac] (at line 90)
2467 [javac] NewWizard wizard = new NewWizard();
2468 [javac] ^^^^^^^^^^^^^^^
2469 [javac] Discouraged access: The constructor NewWizard() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2470 [javac] ----------
2471 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2472 [javac] (at line 90)
2473 [javac] NewWizard wizard = new NewWizard();
2474 [javac] ^^^^^^^^^
2475 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2476 [javac] ----------
2477 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2478 [javac] (at line 91)
2479 [javac] wizard
2480 [javac] .setCategoryId(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
2481 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2482 [javac] Discouraged access: The method setCategoryId(String) from the type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2483 [javac] ----------
2484 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2485 [javac] (at line 92)
2486 [javac] .setCategoryId(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
2487 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2488 [javac] Discouraged access: The type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2489 [javac] ----------
2490 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2491 [javac] (at line 92)
2492 [javac] .setCategoryId(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
2493 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2494 [javac] Discouraged access: The field FULL_EXAMPLES_WIZARD_CATEGORY from the type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2495 [javac] ----------
2496 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewExampleAction.java
2497 [javac] (at line 99)
2498 [javac] wizard.init(workbench, selectionToPass);
2499 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2500 [javac] Discouraged access: The method init(IWorkbench, IStructuredSelection) from the type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2501 [javac] ----------
2502 [javac] ----------
2503 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2504 [javac] (at line 23)
2505 [javac] import org.eclipse.ui.internal.dialogs.NewWizard;
2506 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2507 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2508 [javac] ----------
2509 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2510 [javac] (at line 88)
2511 [javac] NewWizard wizard = new NewWizard();
2512 [javac] ^^^^^^^^^
2513 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2514 [javac] ----------
2515 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2516 [javac] (at line 88)
2517 [javac] NewWizard wizard = new NewWizard();
2518 [javac] ^^^^^^^^^^^^^^^
2519 [javac] Discouraged access: The constructor NewWizard() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2520 [javac] ----------
2521 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2522 [javac] (at line 88)
2523 [javac] NewWizard wizard = new NewWizard();
2524 [javac] ^^^^^^^^^
2525 [javac] Discouraged access: The type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2526 [javac] ----------
2527 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2528 [javac] (at line 89)
2529 [javac] wizard.setProjectsOnly(true);
2530 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2531 [javac] Discouraged access: The method setProjectsOnly(boolean) from the type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2532 [javac] ----------
2533 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewProjectAction.java
2534 [javac] (at line 95)
2535 [javac] wizard.init(workbench, selectionToPass);
2536 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2537 [javac] Discouraged access: The method init(IWorkbench, IStructuredSelection) from the type NewWizard is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2538 [javac] ----------
2539 [javac] ----------
2540 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewWizardMenu.java
2541 [javac] (at line 22)
2542 [javac] import org.eclipse.ui.internal.registry.WizardsRegistryReader;
2543 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2544 [javac] Discouraged access: The type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2545 [javac] ----------
2546 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewWizardMenu.java
2547 [javac] (at line 117)
2548 [javac] return registryHasCategory(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
2549 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2550 [javac] Discouraged access: The type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2551 [javac] ----------
2552 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/NewWizardMenu.java
2553 [javac] (at line 117)
2554 [javac] return registryHasCategory(WizardsRegistryReader.FULL_EXAMPLES_WIZARD_CATEGORY);
2555 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2556 [javac] Discouraged access: The field FULL_EXAMPLES_WIZARD_CATEGORY from the type WizardsRegistryReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2557 [javac] ----------
2558 [javac] ----------
2559 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java
2560 [javac] (at line 37)
2561 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2562 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2563 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2564 [javac] ----------
2565 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java
2566 [javac] (at line 298)
2567 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2568 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2569 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2570 [javac] ----------
2571 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java
2572 [javac] (at line 298)
2573 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2574 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2575 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2576 [javac] ----------
2577 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/WorkspaceAction.java
2578 [javac] (at line 298)
2579 [javac] new ProgressMonitorJobsDialog(shell).run(true, true, op);
2580 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2581 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2582 [javac] ----------
2583 [javac] ----------
2584 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/NewFolderDialog.java
2585 [javac] (at line 60)
2586 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2587 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2588 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2589 [javac] ----------
2590 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/NewFolderDialog.java
2591 [javac] (at line 289)
2592 [javac] new ProgressMonitorJobsDialog(getShell())
2593 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2594 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2595 [javac] ----------
2596 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/NewFolderDialog.java
2597 [javac] (at line 289)
2598 [javac] new ProgressMonitorJobsDialog(getShell())
2599 [javac] .run(true, true, operation);
2600 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2601 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2602 [javac] ----------
2603 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/NewFolderDialog.java
2604 [javac] (at line 289)
2605 [javac] new ProgressMonitorJobsDialog(getShell())
2606 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2607 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2608 [javac] ----------
2609 [javac] ----------
2610 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2611 [javac] (at line 58)
2612 [javac] import org.eclipse.ui.internal.misc.UIStats;
2613 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2614 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2615 [javac] ----------
2616 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2617 [javac] (at line 988)
2618 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, file.getName());
2619 [javac] ^^^^^^^
2620 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2621 [javac] ----------
2622 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2623 [javac] (at line 988)
2624 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, file.getName());
2625 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626 [javac] Discouraged access: The method start(int, String) from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2627 [javac] ----------
2628 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2629 [javac] (at line 988)
2630 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, file.getName());
2631 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2632 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2633 [javac] ----------
2634 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2635 [javac] (at line 988)
2636 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, file.getName());
2637 [javac] ^^^^^^^^^^^^^^^^^^^
2638 [javac] Discouraged access: The field CONTENT_TYPE_LOOKUP from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2639 [javac] ----------
2640 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2641 [javac] (at line 997)
2642 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, file.getName());
2643 [javac] ^^^^^^^
2644 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2645 [javac] ----------
2646 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2647 [javac] (at line 997)
2648 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, file.getName());
2649 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2650 [javac] Discouraged access: The method end(int, Object, String) from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2651 [javac] ----------
2652 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2653 [javac] (at line 997)
2654 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, file.getName());
2655 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2656 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2657 [javac] ----------
2658 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2659 [javac] (at line 997)
2660 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, file.getName());
2661 [javac] ^^^^^^^^^^^^^^^^^^^
2662 [javac] Discouraged access: The field CONTENT_TYPE_LOOKUP from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2663 [javac] ----------
2664 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2665 [javac] (at line 1012)
2666 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, fileName);
2667 [javac] ^^^^^^^
2668 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2669 [javac] ----------
2670 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2671 [javac] (at line 1012)
2672 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, fileName);
2673 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2674 [javac] Discouraged access: The method start(int, String) from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2675 [javac] ----------
2676 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2677 [javac] (at line 1012)
2678 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, fileName);
2679 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2680 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2681 [javac] ----------
2682 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2683 [javac] (at line 1012)
2684 [javac] UIStats.start(UIStats.CONTENT_TYPE_LOOKUP, fileName);
2685 [javac] ^^^^^^^^^^^^^^^^^^^
2686 [javac] Discouraged access: The field CONTENT_TYPE_LOOKUP from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2687 [javac] ----------
2688 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2689 [javac] (at line 1018)
2690 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, fileName);
2691 [javac] ^^^^^^^
2692 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2693 [javac] ----------
2694 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2695 [javac] (at line 1018)
2696 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, fileName);
2697 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2698 [javac] Discouraged access: The method end(int, Object, String) from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2699 [javac] ----------
2700 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2701 [javac] (at line 1018)
2702 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, fileName);
2703 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2704 [javac] Discouraged access: The type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2705 [javac] ----------
2706 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java
2707 [javac] (at line 1018)
2708 [javac] UIStats.end(UIStats.CONTENT_TYPE_LOOKUP, file, fileName);
2709 [javac] ^^^^^^^^^^^^^^^^^^^
2710 [javac] Discouraged access: The field CONTENT_TYPE_LOOKUP from the type UIStats is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2711 [javac] ----------
2712 [javac] ----------
2713 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchAdvisor.java
2714 [javac] (at line 59)
2715 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
2716 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2717 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2718 [javac] ----------
2719 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchAdvisor.java
2720 [javac] (at line 374)
2721 [javac] new ProgressMonitorJobsDialog(null).run(true, false, runnable);
2722 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2723 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2724 [javac] ----------
2725 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchAdvisor.java
2726 [javac] (at line 374)
2727 [javac] new ProgressMonitorJobsDialog(null).run(true, false, runnable);
2728 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2729 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2730 [javac] ----------
2731 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchAdvisor.java
2732 [javac] (at line 374)
2733 [javac] new ProgressMonitorJobsDialog(null).run(true, false, runnable);
2734 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
2735 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2736 [javac] ----------
2737 [javac] ----------
2738 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2739 [javac] (at line 32)
2740 [javac] import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
2741 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2742 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2743 [javac] ----------
2744 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2745 [javac] (at line 56)
2746 [javac] import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
2747 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2748 [javac] Discouraged access: The type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2749 [javac] ----------
2750 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2751 [javac] (at line 362)
2752 [javac] IActionBarConfigurer2 actionBarConfigurer = (IActionBarConfigurer2) getActionBarConfigurer();
2753 [javac] ^^^^^^^^^^^^^^^^^^^^^
2754 [javac] Discouraged access: The type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2755 [javac] ----------
2756 [javac] 63. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2757 [javac] (at line 362)
2758 [javac] IActionBarConfigurer2 actionBarConfigurer = (IActionBarConfigurer2) getActionBarConfigurer();
2759 [javac] ^^^^^^^^^^^^^^^^^^^^^
2760 [javac] Discouraged access: The type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2761 [javac] ----------
2762 [javac] 64. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2763 [javac] (at line 371)
2764 [javac] IToolBarManager fileToolBar = actionBarConfigurer.createToolBarManager();
2765 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2766 [javac] Discouraged access: The method createToolBarManager() from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2767 [javac] ----------
2768 [javac] 65. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2769 [javac] (at line 392)
2770 [javac] coolBar.add(actionBarConfigurer.createToolBarContributionItem(fileToolBar,
2771 [javac] IWorkbenchActionConstants.TOOLBAR_FILE));
2772 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2773 [javac] Discouraged access: The method createToolBarContributionItem(IToolBarManager, String) from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2774 [javac] ----------
2775 [javac] 66. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2776 [javac] (at line 400)
2777 [javac] IToolBarManager navToolBar = actionBarConfigurer.createToolBarManager();
2778 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2779 [javac] Discouraged access: The method createToolBarManager() from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2780 [javac] ----------
2781 [javac] 67. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2782 [javac] (at line 411)
2783 [javac] coolBar.add(actionBarConfigurer.createToolBarContributionItem(navToolBar,
2784 [javac] IWorkbenchActionConstants.TOOLBAR_NAVIGATE));
2785 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2786 [javac] Discouraged access: The method createToolBarContributionItem(IToolBarManager, String) from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2787 [javac] ----------
2788 [javac] 68. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2789 [javac] (at line 420)
2790 [javac] IToolBarManager helpToolBar = actionBarConfigurer.createToolBarManager();
2791 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2792 [javac] Discouraged access: The method createToolBarManager() from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2793 [javac] ----------
2794 [javac] 69. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2795 [javac] (at line 426)
2796 [javac] coolBar.add(actionBarConfigurer.createToolBarContributionItem(helpToolBar,
2797 [javac] IWorkbenchActionConstants.TOOLBAR_HELP));
2798 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2799 [javac] Discouraged access: The method createToolBarContributionItem(IToolBarManager, String) from the type IActionBarConfigurer2 is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2800 [javac] ----------
2801 [javac] 70. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2802 [javac] (at line 1580)
2803 [javac] if (!(cbItem instanceof IToolBarContributionItem)) {
2804 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2805 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2806 [javac] ----------
2807 [javac] 71. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2808 [javac] (at line 1585)
2809 [javac] IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
2810 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2811 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2812 [javac] ----------
2813 [javac] 72. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2814 [javac] (at line 1585)
2815 [javac] IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
2816 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2817 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2818 [javac] ----------
2819 [javac] 73. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2820 [javac] (at line 1586)
2821 [javac] IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
2822 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2823 [javac] Discouraged access: The method getToolBarManager() from the type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2824 [javac] ----------
2825 [javac] 74. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2826 [javac] (at line 1628)
2827 [javac] if (!(cbItem instanceof IToolBarContributionItem)) {
2828 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2829 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2830 [javac] ----------
2831 [javac] 75. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2832 [javac] (at line 1634)
2833 [javac] IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
2834 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2835 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2836 [javac] ----------
2837 [javac] 76. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2838 [javac] (at line 1634)
2839 [javac] IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
2840 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
2841 [javac] Discouraged access: The type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2842 [javac] ----------
2843 [javac] 77. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/WorkbenchActionBuilder.java
2844 [javac] (at line 1635)
2845 [javac] IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
2846 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2847 [javac] Discouraged access: The method getToolBarManager() from the type IToolBarContributionItem is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface/@dot
2848 [javac] ----------
2849 [javac] ----------
2850 [javac] 78. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2851 [javac] (at line 18)
2852 [javac] import org.eclipse.ui.internal.dialogs.EditorsPreferencePage;
2853 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2854 [javac] Discouraged access: The type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2855 [javac] ----------
2856 [javac] 79. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2857 [javac] (at line 28)
2858 [javac] public class IDEEditorsPreferencePage extends EditorsPreferencePage {
2859 [javac] ^^^^^^^^^^^^^^^^^^^^^
2860 [javac] Discouraged access: The type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2861 [javac] ----------
2862 [javac] 80. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2863 [javac] (at line 31)
2864 [javac] Composite composite = createComposite(parent);
2865 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2866 [javac] Discouraged access: The method createComposite(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2867 [javac] ----------
2868 [javac] 81. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2869 [javac] (at line 54)
2870 [javac] createEditorHistoryGroup(composite);
2871 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2872 [javac] Discouraged access: The method createEditorHistoryGroup(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2873 [javac] ----------
2874 [javac] 82. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2875 [javac] (at line 56)
2876 [javac] createSpace(composite);
2877 [javac] ^^^^^^^^^^^^^^^^^^^^^^
2878 [javac] Discouraged access: The method createSpace(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2879 [javac] ----------
2880 [javac] 83. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2881 [javac] (at line 57)
2882 [javac] createShowMultipleEditorTabsPref(composite);
2883 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2884 [javac] Discouraged access: The method createShowMultipleEditorTabsPref(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2885 [javac] ----------
2886 [javac] 84. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2887 [javac] (at line 58)
2888 [javac] createEditorReuseGroup(composite);
2889 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2890 [javac] Discouraged access: The method createEditorReuseGroup(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2891 [javac] ----------
2892 [javac] 85. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java
2893 [javac] (at line 62)
2894 [javac] super.setHelpContext(parent);
2895 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2896 [javac] Discouraged access: The method setHelpContext(Composite) from the type EditorsPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2897 [javac] ----------
2898 [javac] ----------
2899 [javac] 86. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2900 [javac] (at line 20)
2901 [javac] import org.eclipse.ui.internal.dialogs.PerspectivesPreferencePage;
2902 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2903 [javac] Discouraged access: The type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2904 [javac] ----------
2905 [javac] 87. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2906 [javac] (at line 32)
2907 [javac] public class IDEPerspectivesPreferencePage extends PerspectivesPreferencePage {
2908 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
2909 [javac] Discouraged access: The type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2910 [javac] ----------
2911 [javac] 88. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2912 [javac] (at line 56)
2913 [javac] Composite composite = createComposite(parent);
2914 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2915 [javac] Discouraged access: The method createComposite(Composite) from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2916 [javac] ----------
2917 [javac] 89. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2918 [javac] (at line 58)
2919 [javac] createOpenPerspButtonGroup(composite);
2920 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2921 [javac] Discouraged access: The method createOpenPerspButtonGroup(Composite) from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2922 [javac] ----------
2923 [javac] 90. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2924 [javac] (at line 59)
2925 [javac] createOpenViewButtonGroup(composite);
2926 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2927 [javac] Discouraged access: The method createOpenViewButtonGroup(Composite) from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2928 [javac] ----------
2929 [javac] 91. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2930 [javac] (at line 61)
2931 [javac] createCustomizePerspective(composite);
2932 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2933 [javac] Discouraged access: The method createCustomizePerspective(Composite) from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2934 [javac] ----------
2935 [javac] 92. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2936 [javac] (at line 103)
2937 [javac] super.performDefaults();
2938 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2939 [javac] Discouraged access: The method performDefaults() from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2940 [javac] ----------
2941 [javac] 93. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEPerspectivesPreferencePage.java
2942 [javac] (at line 114)
2943 [javac] return super.performOk();
2944 [javac] ^^^^^^^^^^^^^^^^^
2945 [javac] Discouraged access: The method performOk() from the type PerspectivesPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2946 [javac] ----------
2947 [javac] ----------
2948 [javac] 94. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2949 [javac] (at line 23)
2950 [javac] import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
2951 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2952 [javac] Discouraged access: The type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2953 [javac] ----------
2954 [javac] 95. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2955 [javac] (at line 36)
2956 [javac] public class IDEStartupPreferencePage extends StartupPreferencePage implements
2957 [javac] ^^^^^^^^^^^^^^^^^^^^^
2958 [javac] Discouraged access: The type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2959 [javac] ----------
2960 [javac] 96. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2961 [javac] (at line 55)
2962 [javac] Composite composite = createComposite(parent);
2963 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2964 [javac] Discouraged access: The method createComposite(Composite) from the type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2965 [javac] ----------
2966 [javac] 97. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2967 [javac] (at line 64)
2968 [javac] createEarlyStartupSelection(composite);
2969 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2970 [javac] Discouraged access: The method createEarlyStartupSelection(Composite) from the type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2971 [javac] ----------
2972 [javac] 98. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2973 [javac] (at line 84)
2974 [javac] super.performDefaults();
2975 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2976 [javac] Discouraged access: The method performDefaults() from the type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2977 [javac] ----------
2978 [javac] 99. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEStartupPreferencePage.java
2979 [javac] (at line 111)
2980 [javac] return super.performOk();
2981 [javac] ^^^^^^^^^^^^^^^^^
2982 [javac] Discouraged access: The method performOk() from the type StartupPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2983 [javac] ----------
2984 [javac] ----------
2985 [javac] 100. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
2986 [javac] (at line 19)
2987 [javac] import org.eclipse.ui.internal.dialogs.WorkbenchPreferencePage;
2988 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2989 [javac] Discouraged access: The type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2990 [javac] ----------
2991 [javac] 101. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
2992 [javac] (at line 28)
2993 [javac] public class IDEWorkbenchPreferencePage extends WorkbenchPreferencePage
2994 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
2995 [javac] Discouraged access: The type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
2996 [javac] ----------
2997 [javac] 102. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
2998 [javac] (at line 41)
2999 [javac] Composite composite = createComposite(parent);
3000 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
3001 [javac] Discouraged access: The method createComposite(Composite) from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3002 [javac] ----------
3003 [javac] 103. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3004 [javac] (at line 43)
3005 [javac] createShowUserDialogPref(composite);
3006 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3007 [javac] Discouraged access: The method createShowUserDialogPref(Composite) from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3008 [javac] ----------
3009 [javac] 104. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3010 [javac] (at line 44)
3011 [javac] createStickyCyclePref(composite);
3012 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3013 [javac] Discouraged access: The method createStickyCyclePref(Composite) from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3014 [javac] ----------
3015 [javac] 105. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3016 [javac] (at line 45)
3017 [javac] createHeapStatusPref(composite);
3018 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3019 [javac] Discouraged access: The method createHeapStatusPref(Composite) from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3020 [javac] ----------
3021 [javac] 106. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3022 [javac] (at line 47)
3023 [javac] createOpenModeGroup(composite);
3024 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3025 [javac] Discouraged access: The method createOpenModeGroup(Composite) from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3026 [javac] ----------
3027 [javac] 107. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3028 [javac] (at line 66)
3029 [javac] super.performDefaults();
3030 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
3031 [javac] Discouraged access: The method performDefaults() from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3032 [javac] ----------
3033 [javac] 108. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEWorkbenchPreferencePage.java
3034 [javac] (at line 73)
3035 [javac] return super.performOk();
3036 [javac] ^^^^^^^^^^^^^^^^^
3037 [javac] Discouraged access: The method performOk() from the type WorkbenchPreferencePage is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3038 [javac] ----------
3039 [javac] ----------
3040 [javac] 109. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ProjectReferencePage.java
3041 [javac] (at line 47)
3042 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
3043 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3044 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3045 [javac] ----------
3046 [javac] 110. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ProjectReferencePage.java
3047 [javac] (at line 245)
3048 [javac] new ProgressMonitorJobsDialog(getControl().getShell()).run(true,
3049 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3050 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3051 [javac] ----------
3052 [javac] 111. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ProjectReferencePage.java
3053 [javac] (at line 245)
3054 [javac] new ProgressMonitorJobsDialog(getControl().getShell()).run(true,
3055 [javac] true, runnable);
3056 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3057 [javac] Discouraged access: The method run(boolean, boolean, IRunnableWithProgress) from the type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3058 [javac] ----------
3059 [javac] 112. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ProjectReferencePage.java
3060 [javac] (at line 245)
3061 [javac] new ProgressMonitorJobsDialog(getControl().getShell()).run(true,
3062 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
3063 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3064 [javac] ----------
3065 [javac] ----------
3066 [javac] 113. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java
3067 [javac] (at line 60)
3068 [javac] import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog;
3069 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3070 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3071 [javac] ----------
3072 [javac] 114. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java
3073 [javac] (at line 818)
3074 [javac] ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog(
3075 [javac] getContainer().getShell());
3076 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3077 [javac] Discouraged access: The constructor ProgressMonitorJobsDialog(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3078 [javac] ----------
3079 [javac] 115. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java
3080 [javac] (at line 818)
3081 [javac] ProgressMonitorDialog dialog = new ProgressMonitorJobsDialog(
3082 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
3083 [javac] Discouraged access: The type ProgressMonitorJobsDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3084 [javac] ----------
3085 [javac] ----------
3086 [javac] 116. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java
3087 [javac] (at line 66)
3088 [javac] import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
3089 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3090 [javac] Discouraged access: The type PerspectiveDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3091 [javac] ----------
3092 [javac] 117. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java
3093 [javac] (at line 530)
3094 [javac] PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]);
3095 [javac] ^^^^^^^^^^^^^^^^^^^^^
3096 [javac] Discouraged access: The type PerspectiveDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3097 [javac] ----------
3098 [javac] 118. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java
3099 [javac] (at line 530)
3100 [javac] PerspectiveDescriptor descriptor = ((PerspectiveDescriptor) perspectives[i]);
3101 [javac] ^^^^^^^^^^^^^^^^^^^^^
3102 [javac] Discouraged access: The type PerspectiveDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3103 [javac] ----------
3104 [javac] 119. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java
3105 [javac] (at line 531)
3106 [javac] if (descriptor.getOriginalId().equals(id)) {
3107 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
3108 [javac] Discouraged access: The method getOriginalId() from the type PerspectiveDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3109 [javac] ----------
3110 [javac] 120. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/src/org/eclipse/ui/wizards/newresource/BasicNewProjectResourceWizard.java
3111 [javac] (at line 532)
3112 [javac] perspectiveIds.add(descriptor.getId());
3113 [javac] ^^^^^^^^^^^^^^^^^^
3114 [javac] Discouraged access: The method getId() from the type PerspectiveDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3115 [javac] ----------
3116 [javac] 120 problems (120 warnings)
3117 [javac] ----------
3118 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3119 [javac] (at line 33)
3120 [javac] import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
3121 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3122 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3123 [javac] ----------
3124 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3125 [javac] (at line 34)
3126 [javac] import org.eclipse.ui.internal.ide.actions.CloseUnrelatedProjectsAction;
3127 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3128 [javac] Discouraged access: The type CloseUnrelatedProjectsAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3129 [javac] ----------
3130 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3131 [javac] (at line 51)
3132 [javac] private CloseUnrelatedProjectsAction closeUnrelatedProjectsAction;
3133 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3134 [javac] Discouraged access: The type CloseUnrelatedProjectsAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3135 [javac] ----------
3136 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3137 [javac] (at line 188)
3138 [javac] closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(shell);
3139 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3140 [javac] Discouraged access: The constructor CloseUnrelatedProjectsAction(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3141 [javac] ----------
3142 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3143 [javac] (at line 188)
3144 [javac] closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(shell);
3145 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3146 [javac] Discouraged access: The type CloseUnrelatedProjectsAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3147 [javac] ----------
3148 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3149 [javac] (at line 206)
3150 [javac] return IDEWorkbenchPlugin.getIDEImageDescriptor(relativePath);
3151 [javac] ^^^^^^^^^^^^^^^^^^
3152 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3153 [javac] ----------
3154 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/actions/ResourceMgmtActionProvider.java
3155 [javac] (at line 206)
3156 [javac] return IDEWorkbenchPlugin.getIDEImageDescriptor(relativePath);
3157 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3158 [javac] Discouraged access: The method getIDEImageDescriptor(String) from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3159 [javac] ----------
3160 [javac] 7 problems (7 warnings)
3161 [javac] ----------
3162 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamAction.java
3163 [javac] (at line 38)
3164 [javac] import org.eclipse.ui.internal.LegacyResourceSupport;
3165 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3166 [javac] Discouraged access: The type LegacyResourceSupport is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3167 [javac] ----------
3168 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamAction.java
3169 [javac] (at line 190)
3170 [javac] return LegacyResourceSupport.getAdaptedContributorResourceMapping(object);
3171 [javac] ^^^^^^^^^^^^^^^^^^^^^
3172 [javac] Discouraged access: The type LegacyResourceSupport is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3173 [javac] ----------
3174 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamAction.java
3175 [javac] (at line 190)
3176 [javac] return LegacyResourceSupport.getAdaptedContributorResourceMapping(object);
3177 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3178 [javac] Discouraged access: The method getAdaptedContributorResourceMapping(Object) from the type LegacyResourceSupport is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3179 [javac] ----------
3180 [javac] ----------
3181 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/PreferencePageContainerDialog.java
3182 [javac] (at line 18)
3183 [javac] import org.eclipse.compare.internal.TabFolderLayout;
3184 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3185 [javac] Discouraged access: The type TabFolderLayout is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3186 [javac] ----------
3187 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/PreferencePageContainerDialog.java
3188 [javac] (at line 158)
3189 [javac] tabFolder.setLayout(new TabFolderLayout());
3190 [javac] ^^^^^^^^^^^^^^^^^^^^^
3191 [javac] Discouraged access: The constructor TabFolderLayout() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3192 [javac] ----------
3193 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/dialogs/PreferencePageContainerDialog.java
3194 [javac] (at line 158)
3195 [javac] tabFolder.setLayout(new TabFolderLayout());
3196 [javac] ^^^^^^^^^^^^^^^
3197 [javac] Discouraged access: The type TabFolderLayout is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3198 [javac] ----------
3199 [javac] ----------
3200 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/registry/RegistryReader.java
3201 [javac] (at line 18)
3202 [javac] import org.eclipse.ui.internal.WorkbenchPlugin;
3203 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3204 [javac] Discouraged access: The type WorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3205 [javac] ----------
3206 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/registry/RegistryReader.java
3207 [javac] (at line 36)
3208 [javac] return WorkbenchPlugin.createExtension(element, classAttribute);
3209 [javac] ^^^^^^^^^^^^^^^
3210 [javac] Discouraged access: The type WorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3211 [javac] ----------
3212 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/registry/RegistryReader.java
3213 [javac] (at line 36)
3214 [javac] return WorkbenchPlugin.createExtension(element, classAttribute);
3215 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3216 [javac] Discouraged access: The method createExtension(IConfigurationElement, String) from the type WorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3217 [javac] ----------
3218 [javac] ----------
3219 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3220 [javac] (at line 13)
3221 [javac] import org.eclipse.compare.internal.INavigatable;
3222 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3223 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3224 [javac] ----------
3225 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3226 [javac] (at line 25)
3227 [javac] private INavigatable nav;
3228 [javac] ^^^^^^^^^^^^
3229 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3230 [javac] ----------
3231 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3232 [javac] (at line 170)
3233 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3234 [javac] ^^^^^^^^^^^^
3235 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3236 [javac] ----------
3237 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3238 [javac] (at line 170)
3239 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3240 [javac] ^^^^^^^^^^^^
3241 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3242 [javac] ----------
3243 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3244 [javac] (at line 172)
3245 [javac] configuration.setProperty(SynchronizePageConfiguration.P_NAVIGATOR, getAdapter(INavigatable.class));
3246 [javac] ^^^^^^^^^^^^
3247 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3248 [javac] ----------
3249 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3250 [javac] (at line 194)
3251 [javac] if(adapter == INavigatable.class) {
3252 [javac] ^^^^^^^^^^^^
3253 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3254 [javac] ----------
3255 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/AbstractTreeViewerAdvisor.java
3256 [javac] (at line 196)
3257 [javac] nav = new INavigatable() {
3258 [javac] ^^^^^^^^^^^^
3259 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3260 [javac] ----------
3261 [javac] ----------
3262 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceTypedElement.java
3263 [javac] (at line 16)
3264 [javac] import org.eclipse.compare.internal.BufferedResourceNode;
3265 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3266 [javac] Discouraged access: The type BufferedResourceNode is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3267 [javac] ----------
3268 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceTypedElement.java
3269 [javac] (at line 92)
3270 [javac] child= new BufferedResourceNode(file);
3271 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3272 [javac] Discouraged access: The constructor BufferedResourceNode(IResource) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3273 [javac] ----------
3274 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceTypedElement.java
3275 [javac] (at line 92)
3276 [javac] child= new BufferedResourceNode(file);
3277 [javac] ^^^^^^^^^^^^^^^^^^^^
3278 [javac] Discouraged access: The type BufferedResourceNode is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3279 [javac] ----------
3280 [javac] ----------
3281 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/NavigationActionGroup.java
3282 [javac] (at line 13)
3283 [javac] import org.eclipse.compare.internal.INavigatable;
3284 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3285 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3286 [javac] ----------
3287 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/NavigationActionGroup.java
3288 [javac] (at line 51)
3289 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3290 [javac] ^^^^^^^^^^^^
3291 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3292 [javac] ----------
3293 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/NavigationActionGroup.java
3294 [javac] (at line 51)
3295 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3296 [javac] ^^^^^^^^^^^^
3297 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3298 [javac] ----------
3299 [javac] ----------
3300 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3301 [javac] (at line 14)
3302 [javac] import org.eclipse.compare.internal.INavigatable;
3303 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3304 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3305 [javac] ----------
3306 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3307 [javac] (at line 15)
3308 [javac] import org.eclipse.compare.internal.IOpenable;
3309 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3310 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3311 [javac] ----------
3312 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3313 [javac] (at line 32)
3314 [javac] public class PartNavigator implements INavigatable {
3315 [javac] ^^^^^^^^^^^^
3316 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3317 [javac] ----------
3318 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3319 [javac] (at line 52)
3320 [javac] INavigatable[] navigators= new INavigatable[4];
3321 [javac] ^^^^^^^^^^^^^^
3322 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3323 [javac] ----------
3324 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3325 [javac] (at line 52)
3326 [javac] INavigatable[] navigators= new INavigatable[4];
3327 [javac] ^^^^^^^^^^^^
3328 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3329 [javac] ----------
3330 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3331 [javac] (at line 61)
3332 [javac] if (navigators[n].gotoDifference(next)) {
3333 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3334 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3335 [javac] ----------
3336 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3337 [javac] (at line 70)
3338 [javac] private static INavigatable getNavigator(Object p) {
3339 [javac] ^^^^^^^^^^^^
3340 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3341 [javac] ----------
3342 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3343 [javac] (at line 84)
3344 [javac] Object data = control.getData(INavigatable.NAVIGATOR_PROPERTY);
3345 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3346 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3347 [javac] ----------
3348 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3349 [javac] (at line 84)
3350 [javac] Object data = control.getData(INavigatable.NAVIGATOR_PROPERTY);
3351 [javac] ^^^^^^^^^^^^^^^^^^
3352 [javac] Discouraged access: The field NAVIGATOR_PROPERTY from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3353 [javac] ----------
3354 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3355 [javac] (at line 85)
3356 [javac] if (data instanceof INavigatable)
3357 [javac] ^^^^^^^^^^^^
3358 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3359 [javac] ----------
3360 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3361 [javac] (at line 86)
3362 [javac] return (INavigatable) data;
3363 [javac] ^^^^^^^^^^^^
3364 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3365 [javac] ----------
3366 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3367 [javac] (at line 88)
3368 [javac] return (INavigatable)((IAdaptable)p).getAdapter(INavigatable.class);
3369 [javac] ^^^^^^^^^^^^
3370 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3371 [javac] ----------
3372 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3373 [javac] (at line 88)
3374 [javac] return (INavigatable)((IAdaptable)p).getAdapter(INavigatable.class);
3375 [javac] ^^^^^^^^^^^^
3376 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3377 [javac] ----------
3378 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3379 [javac] (at line 116)
3380 [javac] IOpenable openable= getOpenable(fPanes[0]);
3381 [javac] ^^^^^^^^^
3382 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3383 [javac] ----------
3384 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3385 [javac] (at line 118)
3386 [javac] openable.openSelected();
3387 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
3388 [javac] Discouraged access: The method openSelected() from the type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3389 [javac] ----------
3390 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3391 [javac] (at line 125)
3392 [javac] private static IOpenable getOpenable(Object p) {
3393 [javac] ^^^^^^^^^
3394 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3395 [javac] ----------
3396 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3397 [javac] (at line 138)
3398 [javac] Object data = control.getData(IOpenable.OPENABLE_PROPERTY);
3399 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3400 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3401 [javac] ----------
3402 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3403 [javac] (at line 138)
3404 [javac] Object data = control.getData(IOpenable.OPENABLE_PROPERTY);
3405 [javac] ^^^^^^^^^^^^^^^^^
3406 [javac] Discouraged access: The field OPENABLE_PROPERTY from the type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3407 [javac] ----------
3408 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3409 [javac] (at line 139)
3410 [javac] if (data instanceof IOpenable)
3411 [javac] ^^^^^^^^^
3412 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3413 [javac] ----------
3414 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/PartNavigator.java
3415 [javac] (at line 140)
3416 [javac] return (IOpenable) data;
3417 [javac] ^^^^^^^^^
3418 [javac] Discouraged access: The type IOpenable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3419 [javac] ----------
3420 [javac] ----------
3421 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3422 [javac] (at line 15)
3423 [javac] import org.eclipse.compare.internal.INavigatable;
3424 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3425 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3426 [javac] ----------
3427 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3428 [javac] (at line 63)
3429 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3430 [javac] ^^^^^^^^^^^^
3431 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3432 [javac] ----------
3433 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3434 [javac] (at line 63)
3435 [javac] INavigatable nav = (INavigatable)configuration.getProperty(SynchronizePageConfiguration.P_NAVIGATOR);
3436 [javac] ^^^^^^^^^^^^
3437 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3438 [javac] ----------
3439 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3440 [javac] (at line 67)
3441 [javac] nav.gotoDifference(next);
3442 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
3443 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3444 [javac] ----------
3445 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3446 [javac] (at line 74)
3447 [javac] private void navigateInView(INavigatable nav) {
3448 [javac] ^^^^^^^^^^^^
3449 [javac] Discouraged access: The type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3450 [javac] ----------
3451 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3452 [javac] (at line 77)
3453 [javac] if(nav.gotoDifference(next)) {
3454 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
3455 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3456 [javac] ----------
3457 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3458 [javac] (at line 89)
3459 [javac] if(! nav.gotoDifference(next)) {
3460 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
3461 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3462 [javac] ----------
3463 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3464 [javac] (at line 105)
3465 [javac] if(! nav.gotoDifference(next)) {
3466 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
3467 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3468 [javac] ----------
3469 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/NavigateAction.java
3470 [javac] (at line 116)
3471 [javac] if(! nav.gotoDifference(next)) {
3472 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
3473 [javac] Discouraged access: The method gotoDifference(boolean) from the type INavigatable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3474 [javac] ----------
3475 [javac] ----------
3476 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3477 [javac] (at line 18)
3478 [javac] import org.eclipse.compare.internal.CompareEditor;
3479 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3480 [javac] Discouraged access: The type CompareEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3481 [javac] ----------
3482 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3483 [javac] (at line 19)
3484 [javac] import org.eclipse.compare.internal.ISavable;
3485 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3486 [javac] Discouraged access: The type ISavable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3487 [javac] ----------
3488 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3489 [javac] (at line 208)
3490 [javac] Object o= cc.getProperty(CompareEditor.CONFIRM_SAVE_PROPERTY);
3491 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3492 [javac] Discouraged access: The type CompareEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3493 [javac] ----------
3494 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3495 [javac] (at line 208)
3496 [javac] Object o= cc.getProperty(CompareEditor.CONFIRM_SAVE_PROPERTY);
3497 [javac] ^^^^^^^^^^^^^^^^^^^^^
3498 [javac] Discouraged access: The field CONFIRM_SAVE_PROPERTY from the type CompareEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3499 [javac] ----------
3500 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3501 [javac] (at line 410)
3502 [javac] if (element instanceof ISavable){
3503 [javac] ^^^^^^^^
3504 [javac] Discouraged access: The type ISavable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3505 [javac] ----------
3506 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3507 [javac] (at line 412)
3508 [javac] ((ISavable)element).save(monitor);
3509 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3510 [javac] Discouraged access: The method save(IProgressMonitor) from the type ISavable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3511 [javac] ----------
3512 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/PageSaveablePart.java
3513 [javac] (at line 412)
3514 [javac] ((ISavable)element).save(monitor);
3515 [javac] ^^^^^^^^
3516 [javac] Discouraged access: The type ISavable is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3517 [javac] ----------
3518 [javac] ----------
3519 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/SaveablePartDialog.java
3520 [javac] (at line 13)
3521 [javac] import org.eclipse.compare.internal.ResizableDialog;
3522 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3523 [javac] Discouraged access: The type ResizableDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3524 [javac] ----------
3525 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/SaveablePartDialog.java
3526 [javac] (at line 29)
3527 [javac] public class SaveablePartDialog extends ResizableDialog {
3528 [javac] ^^^^^^^^^^^^^^^
3529 [javac] Discouraged access: The type ResizableDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3530 [javac] ----------
3531 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/SaveablePartDialog.java
3532 [javac] (at line 41)
3533 [javac] super(shell, null);
3534 [javac] ^^^^^^^^^^^^^^^^^^
3535 [javac] Discouraged access: The constructor ResizableDialog(Shell, ResourceBundle) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3536 [javac] ----------
3537 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.ui/src/org/eclipse/team/ui/SaveablePartDialog.java
3538 [javac] (at line 70)
3539 [javac] return super.close();
3540 [javac] ^^^^^^^^^^^^^
3541 [javac] Discouraged access: The method close() from the type ResizableDialog is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3542 [javac] ----------
3543 [javac] 62 problems (62 warnings)
3544 [javac] ----------
3545 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3546 [javac] (at line 31)
3547 [javac] import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
3548 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3549 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3550 [javac] ----------
3551 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3552 [javac] (at line 32)
3553 [javac] import org.eclipse.ui.internal.registry.EditorDescriptor;
3554 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3555 [javac] Discouraged access: The type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3556 [javac] ----------
3557 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3558 [javac] (at line 340)
3559 [javac] part = page.openEditor(new RemoteAnnotationEditorInput(file, contents), IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
3560 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3561 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3562 [javac] ----------
3563 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3564 [javac] (at line 340)
3565 [javac] part = page.openEditor(new RemoteAnnotationEditorInput(file, contents), IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
3566 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3567 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3568 [javac] ----------
3569 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3570 [javac] (at line 355)
3571 [javac] if (descriptor == null || !(descriptor instanceof EditorDescriptor) || !(((EditorDescriptor)descriptor).isInternal())) {
3572 [javac] ^^^^^^^^^^^^^^^^
3573 [javac] Discouraged access: The type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3574 [javac] ----------
3575 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3576 [javac] (at line 355)
3577 [javac] if (descriptor == null || !(descriptor instanceof EditorDescriptor) || !(((EditorDescriptor)descriptor).isInternal())) {
3578 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3579 [javac] Discouraged access: The method isInternal() from the type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3580 [javac] ----------
3581 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3582 [javac] (at line 355)
3583 [javac] if (descriptor == null || !(descriptor instanceof EditorDescriptor) || !(((EditorDescriptor)descriptor).isInternal())) {
3584 [javac] ^^^^^^^^^^^^^^^^
3585 [javac] Discouraged access: The type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3586 [javac] ----------
3587 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3588 [javac] (at line 356)
3589 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3590 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3591 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3592 [javac] ----------
3593 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3594 [javac] (at line 356)
3595 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3596 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3597 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3598 [javac] ----------
3599 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3600 [javac] (at line 359)
3601 [javac] Object obj = IDEWorkbenchPlugin.createExtension(((EditorDescriptor) descriptor).getConfigurationElement(), "class"); //$NON-NLS-1$
3602 [javac] ^^^^^^^^^^^^^^^^^^
3603 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3604 [javac] ----------
3605 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3606 [javac] (at line 359)
3607 [javac] Object obj = IDEWorkbenchPlugin.createExtension(((EditorDescriptor) descriptor).getConfigurationElement(), "class"); //$NON-NLS-1$
3608 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3609 [javac] Discouraged access: The method createExtension(IConfigurationElement, String) from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3610 [javac] ----------
3611 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3612 [javac] (at line 359)
3613 [javac] Object obj = IDEWorkbenchPlugin.createExtension(((EditorDescriptor) descriptor).getConfigurationElement(), "class"); //$NON-NLS-1$
3614 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3615 [javac] Discouraged access: The method getConfigurationElement() from the type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3616 [javac] ----------
3617 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3618 [javac] (at line 359)
3619 [javac] Object obj = IDEWorkbenchPlugin.createExtension(((EditorDescriptor) descriptor).getConfigurationElement(), "class"); //$NON-NLS-1$
3620 [javac] ^^^^^^^^^^^^^^^^
3621 [javac] Discouraged access: The type EditorDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.workbench/@dot
3622 [javac] ----------
3623 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3624 [javac] (at line 363)
3625 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3626 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3627 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3628 [javac] ----------
3629 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3630 [javac] (at line 363)
3631 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3632 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3633 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3634 [javac] ----------
3635 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3636 [javac] (at line 366)
3637 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3638 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3639 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3640 [javac] ----------
3641 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
3642 [javac] (at line 366)
3643 [javac] id = IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
3644 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3645 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3646 [javac] ----------
3647 [javac] ----------
3648 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoratorPreferencesPage.java
3649 [javac] (at line 21)
3650 [javac] import org.eclipse.compare.internal.TabFolderLayout;
3651 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3652 [javac] Discouraged access: The type TabFolderLayout is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3653 [javac] ----------
3654 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoratorPreferencesPage.java
3655 [javac] (at line 547)
3656 [javac] tabFolder.setLayout(new TabFolderLayout());
3657 [javac] ^^^^^^^^^^^^^^^^^^^^^
3658 [javac] Discouraged access: The constructor TabFolderLayout() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3659 [javac] ----------
3660 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecoratorPreferencesPage.java
3661 [javac] (at line 547)
3662 [javac] tabFolder.setLayout(new TabFolderLayout());
3663 [javac] ^^^^^^^^^^^^^^^
3664 [javac] Discouraged access: The type TabFolderLayout is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.compare/@dot
3665 [javac] ----------
3666 [javac] ----------
3667 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ChangeSetContentProvider.java
3668 [javac] (at line 40)
3669 [javac] import org.eclipse.ui.internal.navigator.extensions.CommonExtensionSite;
3670 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3671 [javac] Discouraged access: The type CommonExtensionSite is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator/@dot
3672 [javac] ----------
3673 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ChangeSetContentProvider.java
3674 [javac] (at line 640)
3675 [javac] INavigatorContentService contentService = ((CommonExtensionSite)getExtensionSite()).getContentService();
3676 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3677 [javac] Discouraged access: The method getContentService() from the type CommonExtensionSite is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator/@dot
3678 [javac] ----------
3679 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ChangeSetContentProvider.java
3680 [javac] (at line 640)
3681 [javac] INavigatorContentService contentService = ((CommonExtensionSite)getExtensionSite()).getContentService();
3682 [javac] ^^^^^^^^^^^^^^^^^^^
3683 [javac] Discouraged access: The type CommonExtensionSite is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.navigator/@dot
3684 [javac] ----------
3685 [javac] ----------
3686 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3687 [javac] (at line 21)
3688 [javac] import org.eclipse.jface.internal.text.revisions.RevisionSelectionProvider;
3689 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3690 [javac] Discouraged access: The type RevisionSelectionProvider is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface.text/@dot
3691 [javac] ----------
3692 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3693 [javac] (at line 48)
3694 [javac] import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
3695 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3696 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3697 [javac] ----------
3698 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3699 [javac] (at line 116)
3700 [javac] final ISelectionProvider provider= (ISelectionProvider) editor.getAdapter(RevisionSelectionProvider.class);
3701 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
3702 [javac] Discouraged access: The type RevisionSelectionProvider is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jface.text/@dot
3703 [javac] ----------
3704 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3705 [javac] (at line 241)
3706 [javac] IEditorPart part = getPart().getSite().getPage().openEditor(new FileEditorInput((IFile) resource), IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID, true, IWorkbenchPage.MATCH_NONE);
3707 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3708 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3709 [javac] ----------
3710 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3711 [javac] (at line 241)
3712 [javac] IEditorPart part = getPart().getSite().getPage().openEditor(new FileEditorInput((IFile) resource), IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID, true, IWorkbenchPage.MATCH_NONE);
3713 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3714 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3715 [javac] ----------
3716 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3717 [javac] (at line 265)
3718 [javac] IEditorPart part = IDE.openEditor(getPart().getSite().getPage(), (IFile) resource, IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
3719 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3720 [javac] Discouraged access: The type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3721 [javac] ----------
3722 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
3723 [javac] (at line 265)
3724 [javac] IEditorPart part = IDE.openEditor(getPart().getSite().getPage(), (IFile) resource, IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
3725 [javac] ^^^^^^^^^^^^^^^^^^^^^^
3726 [javac] Discouraged access: The field DEFAULT_TEXT_EDITOR_ID from the type IDEWorkbenchPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
3727 [javac] ----------
3728 [javac] 30 problems (30 warnings)
3729 [javac] ----------
3730 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParser.java
3731 [javac] (at line 517)
3732 [javac] private boolean jj_semLA;
3733 [javac] ^^^^^^^^
3734 [javac] The field HTMLParser.jj_semLA is never read locally
3735 [javac] ----------
3736 [javac] ----------
3737 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3738 [javac] (at line 239)
3739 [javac] private final void jjCheckNAddStates(int start)
3740 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3741 [javac] The method jjCheckNAddStates(int) from the type HTMLParserTokenManager is never used locally
3742 [javac] ----------
3743 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3744 [javac] (at line 252)
3745 [javac] int[] nextStates;
3746 [javac] ^^^^^^^^^^
3747 [javac] The local variable nextStates is never read
3748 [javac] ----------
3749 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3750 [javac] (at line 257)
3751 [javac] int j, kind = 0x7fffffff;
3752 [javac] ^
3753 [javac] The local variable j is never read
3754 [javac] ----------
3755 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3756 [javac] (at line 265)
3757 [javac] MatchLoop: do
3758 [javac] ^^^^^^^^^
3759 [javac] The label MatchLoop is never explicitly referenced
3760 [javac] ----------
3761 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3762 [javac] (at line 430)
3763 [javac] MatchLoop: do
3764 [javac] ^^^^^^^^^
3765 [javac] The label MatchLoop is never explicitly referenced
3766 [javac] ----------
3767 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3768 [javac] (at line 507)
3769 [javac] MatchLoop: do
3770 [javac] ^^^^^^^^^
3771 [javac] The label MatchLoop is never explicitly referenced
3772 [javac] ----------
3773 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3774 [javac] (at line 558)
3775 [javac] int[] nextStates;
3776 [javac] ^^^^^^^^^^
3777 [javac] The local variable nextStates is never read
3778 [javac] ----------
3779 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3780 [javac] (at line 563)
3781 [javac] int j, kind = 0x7fffffff;
3782 [javac] ^
3783 [javac] The local variable j is never read
3784 [javac] ----------
3785 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3786 [javac] (at line 571)
3787 [javac] MatchLoop: do
3788 [javac] ^^^^^^^^^
3789 [javac] The label MatchLoop is never explicitly referenced
3790 [javac] ----------
3791 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3792 [javac] (at line 600)
3793 [javac] long l = 1L << (curChar & 077);
3794 [javac] ^
3795 [javac] The local variable l is never read
3796 [javac] ----------
3797 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3798 [javac] (at line 601)
3799 [javac] MatchLoop: do
3800 [javac] ^^^^^^^^^
3801 [javac] The label MatchLoop is never explicitly referenced
3802 [javac] ----------
3803 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3804 [javac] (at line 621)
3805 [javac] MatchLoop: do
3806 [javac] ^^^^^^^^^
3807 [javac] The label MatchLoop is never explicitly referenced
3808 [javac] ----------
3809 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3810 [javac] (at line 658)
3811 [javac] private final int jjStartNfa_7(int pos, long active0)
3812 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3813 [javac] The method jjStartNfa_7(int, long) from the type HTMLParserTokenManager is never used locally
3814 [javac] ----------
3815 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3816 [javac] (at line 662)
3817 [javac] private final int jjStartNfaWithStates_7(int pos, int kind, int state)
3818 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3819 [javac] The method jjStartNfaWithStates_7(int, int, int) from the type HTMLParserTokenManager is never used locally
3820 [javac] ----------
3821 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3822 [javac] (at line 682)
3823 [javac] int[] nextStates;
3824 [javac] ^^^^^^^^^^
3825 [javac] The local variable nextStates is never read
3826 [javac] ----------
3827 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3828 [javac] (at line 687)
3829 [javac] int j, kind = 0x7fffffff;
3830 [javac] ^
3831 [javac] The local variable j is never read
3832 [javac] ----------
3833 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3834 [javac] (at line 695)
3835 [javac] MatchLoop: do
3836 [javac] ^^^^^^^^^
3837 [javac] The label MatchLoop is never explicitly referenced
3838 [javac] ----------
3839 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3840 [javac] (at line 711)
3841 [javac] long l = 1L << (curChar & 077);
3842 [javac] ^
3843 [javac] The local variable l is never read
3844 [javac] ----------
3845 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3846 [javac] (at line 712)
3847 [javac] MatchLoop: do
3848 [javac] ^^^^^^^^^
3849 [javac] The label MatchLoop is never explicitly referenced
3850 [javac] ----------
3851 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3852 [javac] (at line 731)
3853 [javac] MatchLoop: do
3854 [javac] ^^^^^^^^^
3855 [javac] The label MatchLoop is never explicitly referenced
3856 [javac] ----------
3857 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3858 [javac] (at line 765)
3859 [javac] int[] nextStates;
3860 [javac] ^^^^^^^^^^
3861 [javac] The local variable nextStates is never read
3862 [javac] ----------
3863 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3864 [javac] (at line 770)
3865 [javac] int j, kind = 0x7fffffff;
3866 [javac] ^
3867 [javac] The local variable j is never read
3868 [javac] ----------
3869 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3870 [javac] (at line 778)
3871 [javac] MatchLoop: do
3872 [javac] ^^^^^^^^^
3873 [javac] The label MatchLoop is never explicitly referenced
3874 [javac] ----------
3875 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3876 [javac] (at line 807)
3877 [javac] long l = 1L << (curChar & 077);
3878 [javac] ^
3879 [javac] The local variable l is never read
3880 [javac] ----------
3881 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3882 [javac] (at line 808)
3883 [javac] MatchLoop: do
3884 [javac] ^^^^^^^^^
3885 [javac] The label MatchLoop is never explicitly referenced
3886 [javac] ----------
3887 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3888 [javac] (at line 828)
3889 [javac] MatchLoop: do
3890 [javac] ^^^^^^^^^
3891 [javac] The label MatchLoop is never explicitly referenced
3892 [javac] ----------
3893 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3894 [javac] (at line 865)
3895 [javac] private final int jjStartNfa_3(int pos, long active0)
3896 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3897 [javac] The method jjStartNfa_3(int, long) from the type HTMLParserTokenManager is never used locally
3898 [javac] ----------
3899 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3900 [javac] (at line 869)
3901 [javac] private final int jjStartNfaWithStates_3(int pos, int kind, int state)
3902 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3903 [javac] The method jjStartNfaWithStates_3(int, int, int) from the type HTMLParserTokenManager is never used locally
3904 [javac] ----------
3905 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3906 [javac] (at line 891)
3907 [javac] int[] nextStates;
3908 [javac] ^^^^^^^^^^
3909 [javac] The local variable nextStates is never read
3910 [javac] ----------
3911 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3912 [javac] (at line 896)
3913 [javac] int j, kind = 0x7fffffff;
3914 [javac] ^
3915 [javac] The local variable j is never read
3916 [javac] ----------
3917 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3918 [javac] (at line 904)
3919 [javac] MatchLoop: do
3920 [javac] ^^^^^^^^^
3921 [javac] The label MatchLoop is never explicitly referenced
3922 [javac] ----------
3923 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3924 [javac] (at line 941)
3925 [javac] long l = 1L << (curChar & 077);
3926 [javac] ^
3927 [javac] The local variable l is never read
3928 [javac] ----------
3929 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3930 [javac] (at line 942)
3931 [javac] MatchLoop: do
3932 [javac] ^^^^^^^^^
3933 [javac] The label MatchLoop is never explicitly referenced
3934 [javac] ----------
3935 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3936 [javac] (at line 963)
3937 [javac] MatchLoop: do
3938 [javac] ^^^^^^^^^
3939 [javac] The label MatchLoop is never explicitly referenced
3940 [javac] ----------
3941 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3942 [javac] (at line 1022)
3943 [javac] private final int jjStartNfaWithStates_6(int pos, int kind, int state)
3944 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3945 [javac] The method jjStartNfaWithStates_6(int, int, int) from the type HTMLParserTokenManager is never used locally
3946 [javac] ----------
3947 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3948 [javac] (at line 1078)
3949 [javac] int[] nextStates;
3950 [javac] ^^^^^^^^^^
3951 [javac] The local variable nextStates is never read
3952 [javac] ----------
3953 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3954 [javac] (at line 1083)
3955 [javac] int j, kind = 0x7fffffff;
3956 [javac] ^
3957 [javac] The local variable j is never read
3958 [javac] ----------
3959 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3960 [javac] (at line 1091)
3961 [javac] MatchLoop: do
3962 [javac] ^^^^^^^^^
3963 [javac] The label MatchLoop is never explicitly referenced
3964 [javac] ----------
3965 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3966 [javac] (at line 1120)
3967 [javac] long l = 1L << (curChar & 077);
3968 [javac] ^
3969 [javac] The local variable l is never read
3970 [javac] ----------
3971 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3972 [javac] (at line 1121)
3973 [javac] MatchLoop: do
3974 [javac] ^^^^^^^^^
3975 [javac] The label MatchLoop is never explicitly referenced
3976 [javac] ----------
3977 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3978 [javac] (at line 1141)
3979 [javac] MatchLoop: do
3980 [javac] ^^^^^^^^^
3981 [javac] The label MatchLoop is never explicitly referenced
3982 [javac] ----------
3983 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3984 [javac] (at line 1176)
3985 [javac] int[] nextStates;
3986 [javac] ^^^^^^^^^^
3987 [javac] The local variable nextStates is never read
3988 [javac] ----------
3989 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3990 [javac] (at line 1181)
3991 [javac] int j, kind = 0x7fffffff;
3992 [javac] ^
3993 [javac] The local variable j is never read
3994 [javac] ----------
3995 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
3996 [javac] (at line 1189)
3997 [javac] MatchLoop: do
3998 [javac] ^^^^^^^^^
3999 [javac] The label MatchLoop is never explicitly referenced
4000 [javac] ----------
4001 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4002 [javac] (at line 1237)
4003 [javac] long l = 1L << (curChar & 077);
4004 [javac] ^
4005 [javac] The local variable l is never read
4006 [javac] ----------
4007 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4008 [javac] (at line 1238)
4009 [javac] MatchLoop: do
4010 [javac] ^^^^^^^^^
4011 [javac] The label MatchLoop is never explicitly referenced
4012 [javac] ----------
4013 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4014 [javac] (at line 1286)
4015 [javac] MatchLoop: do
4016 [javac] ^^^^^^^^^
4017 [javac] The label MatchLoop is never explicitly referenced
4018 [javac] ----------
4019 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4020 [javac] (at line 1327)
4021 [javac] private final int jjStartNfa_2(int pos, long active0)
4022 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4023 [javac] The method jjStartNfa_2(int, long) from the type HTMLParserTokenManager is never used locally
4024 [javac] ----------
4025 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4026 [javac] (at line 1355)
4027 [javac] int[] nextStates;
4028 [javac] ^^^^^^^^^^
4029 [javac] The local variable nextStates is never read
4030 [javac] ----------
4031 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4032 [javac] (at line 1360)
4033 [javac] int j, kind = 0x7fffffff;
4034 [javac] ^
4035 [javac] The local variable j is never read
4036 [javac] ----------
4037 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4038 [javac] (at line 1368)
4039 [javac] MatchLoop: do
4040 [javac] ^^^^^^^^^
4041 [javac] The label MatchLoop is never explicitly referenced
4042 [javac] ----------
4043 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4044 [javac] (at line 1421)
4045 [javac] long l = 1L << (curChar & 077);
4046 [javac] ^
4047 [javac] The local variable l is never read
4048 [javac] ----------
4049 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4050 [javac] (at line 1422)
4051 [javac] MatchLoop: do
4052 [javac] ^^^^^^^^^
4053 [javac] The label MatchLoop is never explicitly referenced
4054 [javac] ----------
4055 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4056 [javac] (at line 1443)
4057 [javac] MatchLoop: do
4058 [javac] ^^^^^^^^^
4059 [javac] The label MatchLoop is never explicitly referenced
4060 [javac] ----------
4061 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4062 [javac] (at line 1576)
4063 [javac] int kind;
4064 [javac] ^^^^
4065 [javac] The local variable kind is never read
4066 [javac] ----------
4067 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.apache.lucene/src/org/apache/lucene/demo/html/HTMLParserTokenManager.java
4068 [javac] (at line 1577)
4069 [javac] Token specialToken = null;
4070 [javac] ^^^^^^^^^^^^
4071 [javac] The local variable specialToken is never read
4072 [javac] ----------
4073 [javac] 57 problems (57 warnings)
4074 [javac] ----------
4075 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/advanced_jsp.java
4076 [javac] (at line 28)
4077 [javac] HttpSession session = null;
4078 [javac] ^^^^^^^
4079 [javac] The local variable session is never read
4080 [javac] ----------
4081 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/advanced_jsp.java
4082 [javac] (at line 30)
4083 [javac] ServletConfig config = null;
4084 [javac] ^^^^^^
4085 [javac] The local variable config is never read
4086 [javac] ----------
4087 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/advanced_jsp.java
4088 [javac] (at line 32)
4089 [javac] Object page = this;
4090 [javac] ^^^^
4091 [javac] The local variable page is never read
4092 [javac] ----------
4093 [javac] ----------
4094 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/askShowAll_jsp.java
4095 [javac] (at line 28)
4096 [javac] HttpSession session = null;
4097 [javac] ^^^^^^^
4098 [javac] The local variable session is never read
4099 [javac] ----------
4100 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/askShowAll_jsp.java
4101 [javac] (at line 30)
4102 [javac] ServletConfig config = null;
4103 [javac] ^^^^^^
4104 [javac] The local variable config is never read
4105 [javac] ----------
4106 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/askShowAll_jsp.java
4107 [javac] (at line 32)
4108 [javac] Object page = this;
4109 [javac] ^^^^
4110 [javac] The local variable page is never read
4111 [javac] ----------
4112 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/askShowAll_jsp.java
4113 [javac] (at line 51)
4114 [javac] String direction = isRTL?"rtl":"ltr";
4115 [javac] ^^^^^^^^^
4116 [javac] The local variable direction is never read
4117 [javac] ----------
4118 [javac] ----------
4119 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksToolbar_jsp.java
4120 [javac] (at line 28)
4121 [javac] HttpSession session = null;
4122 [javac] ^^^^^^^
4123 [javac] The local variable session is never read
4124 [javac] ----------
4125 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksToolbar_jsp.java
4126 [javac] (at line 30)
4127 [javac] ServletConfig config = null;
4128 [javac] ^^^^^^
4129 [javac] The local variable config is never read
4130 [javac] ----------
4131 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksToolbar_jsp.java
4132 [javac] (at line 32)
4133 [javac] Object page = this;
4134 [javac] ^^^^
4135 [javac] The local variable page is never read
4136 [javac] ----------
4137 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksToolbar_jsp.java
4138 [javac] (at line 51)
4139 [javac] String direction = isRTL?"rtl":"ltr";
4140 [javac] ^^^^^^^^^
4141 [javac] The local variable direction is never read
4142 [javac] ----------
4143 [javac] ----------
4144 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksView_jsp.java
4145 [javac] (at line 29)
4146 [javac] HttpSession session = null;
4147 [javac] ^^^^^^^
4148 [javac] The local variable session is never read
4149 [javac] ----------
4150 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksView_jsp.java
4151 [javac] (at line 31)
4152 [javac] ServletConfig config = null;
4153 [javac] ^^^^^^
4154 [javac] The local variable config is never read
4155 [javac] ----------
4156 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/bookmarksView_jsp.java
4157 [javac] (at line 33)
4158 [javac] Object page = this;
4159 [javac] ^^^^
4160 [javac] The local variable page is never read
4161 [javac] ----------
4162 [javac] ----------
4163 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirmShowAll_jsp.java
4164 [javac] (at line 28)
4165 [javac] HttpSession session = null;
4166 [javac] ^^^^^^^
4167 [javac] The local variable session is never read
4168 [javac] ----------
4169 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirmShowAll_jsp.java
4170 [javac] (at line 30)
4171 [javac] ServletConfig config = null;
4172 [javac] ^^^^^^
4173 [javac] The local variable config is never read
4174 [javac] ----------
4175 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirmShowAll_jsp.java
4176 [javac] (at line 32)
4177 [javac] Object page = this;
4178 [javac] ^^^^
4179 [javac] The local variable page is never read
4180 [javac] ----------
4181 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirmShowAll_jsp.java
4182 [javac] (at line 51)
4183 [javac] String direction = isRTL?"rtl":"ltr";
4184 [javac] ^^^^^^^^^
4185 [javac] The local variable direction is never read
4186 [javac] ----------
4187 [javac] ----------
4188 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirm_jsp.java
4189 [javac] (at line 29)
4190 [javac] HttpSession session = null;
4191 [javac] ^^^^^^^
4192 [javac] The local variable session is never read
4193 [javac] ----------
4194 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirm_jsp.java
4195 [javac] (at line 31)
4196 [javac] ServletConfig config = null;
4197 [javac] ^^^^^^
4198 [javac] The local variable config is never read
4199 [javac] ----------
4200 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/confirm_jsp.java
4201 [javac] (at line 33)
4202 [javac] Object page = this;
4203 [javac] ^^^^
4204 [javac] The local variable page is never read
4205 [javac] ----------
4206 [javac] ----------
4207 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/contentToolbar_jsp.java
4208 [javac] (at line 28)
4209 [javac] HttpSession session = null;
4210 [javac] ^^^^^^^
4211 [javac] The local variable session is never read
4212 [javac] ----------
4213 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/contentToolbar_jsp.java
4214 [javac] (at line 30)
4215 [javac] ServletConfig config = null;
4216 [javac] ^^^^^^
4217 [javac] The local variable config is never read
4218 [javac] ----------
4219 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/contentToolbar_jsp.java
4220 [javac] (at line 32)
4221 [javac] Object page = this;
4222 [javac] ^^^^
4223 [javac] The local variable page is never read
4224 [javac] ----------
4225 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/contentToolbar_jsp.java
4226 [javac] (at line 51)
4227 [javac] String direction = isRTL?"rtl":"ltr";
4228 [javac] ^^^^^^^^^
4229 [javac] The local variable direction is never read
4230 [javac] ----------
4231 [javac] ----------
4232 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/content_jsp.java
4233 [javac] (at line 28)
4234 [javac] HttpSession session = null;
4235 [javac] ^^^^^^^
4236 [javac] The local variable session is never read
4237 [javac] ----------
4238 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/content_jsp.java
4239 [javac] (at line 30)
4240 [javac] ServletConfig config = null;
4241 [javac] ^^^^^^
4242 [javac] The local variable config is never read
4243 [javac] ----------
4244 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/content_jsp.java
4245 [javac] (at line 32)
4246 [javac] Object page = this;
4247 [javac] ^^^^
4248 [javac] The local variable page is never read
4249 [javac] ----------
4250 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/content_jsp.java
4251 [javac] (at line 51)
4252 [javac] String direction = isRTL?"rtl":"ltr";
4253 [javac] ^^^^^^^^^
4254 [javac] The local variable direction is never read
4255 [javac] ----------
4256 [javac] ----------
4257 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/err_jsp.java
4258 [javac] (at line 23)
4259 [javac] HttpSession session = null;
4260 [javac] ^^^^^^^
4261 [javac] The local variable session is never read
4262 [javac] ----------
4263 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/err_jsp.java
4264 [javac] (at line 25)
4265 [javac] ServletContext application = null;
4266 [javac] ^^^^^^^^^^^
4267 [javac] The local variable application is never read
4268 [javac] ----------
4269 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/err_jsp.java
4270 [javac] (at line 26)
4271 [javac] ServletConfig config = null;
4272 [javac] ^^^^^^
4273 [javac] The local variable config is never read
4274 [javac] ----------
4275 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/err_jsp.java
4276 [javac] (at line 28)
4277 [javac] Object page = this;
4278 [javac] ^^^^
4279 [javac] The local variable page is never read
4280 [javac] ----------
4281 [javac] ----------
4282 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/fheader_jsp.java
4283 [javac] (at line 23)
4284 [javac] HttpSession session = null;
4285 [javac] ^^^^^^^
4286 [javac] The local variable session is never read
4287 [javac] ----------
4288 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/fheader_jsp.java
4289 [javac] (at line 25)
4290 [javac] ServletConfig config = null;
4291 [javac] ^^^^^^
4292 [javac] The local variable config is never read
4293 [javac] ----------
4294 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/fheader_jsp.java
4295 [javac] (at line 27)
4296 [javac] Object page = this;
4297 [javac] ^^^^
4298 [javac] The local variable page is never read
4299 [javac] ----------
4300 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/fheader_jsp.java
4301 [javac] (at line 45)
4302 [javac] String direction = isRTL?"rtl":"ltr";
4303 [javac] ^^^^^^^^^
4304 [javac] The local variable direction is never read
4305 [javac] ----------
4306 [javac] ----------
4307 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/header_jsp.java
4308 [javac] (at line 23)
4309 [javac] HttpSession session = null;
4310 [javac] ^^^^^^^
4311 [javac] The local variable session is never read
4312 [javac] ----------
4313 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/header_jsp.java
4314 [javac] (at line 25)
4315 [javac] ServletConfig config = null;
4316 [javac] ^^^^^^
4317 [javac] The local variable config is never read
4318 [javac] ----------
4319 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/header_jsp.java
4320 [javac] (at line 27)
4321 [javac] Object page = this;
4322 [javac] ^^^^
4323 [javac] The local variable page is never read
4324 [javac] ----------
4325 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/header_jsp.java
4326 [javac] (at line 45)
4327 [javac] String direction = isRTL?"rtl":"ltr";
4328 [javac] ^^^^^^^^^
4329 [javac] The local variable direction is never read
4330 [javac] ----------
4331 [javac] ----------
4332 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/help_jsp.java
4333 [javac] (at line 28)
4334 [javac] HttpSession session = null;
4335 [javac] ^^^^^^^
4336 [javac] The local variable session is never read
4337 [javac] ----------
4338 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/help_jsp.java
4339 [javac] (at line 30)
4340 [javac] ServletConfig config = null;
4341 [javac] ^^^^^^
4342 [javac] The local variable config is never read
4343 [javac] ----------
4344 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/help_jsp.java
4345 [javac] (at line 32)
4346 [javac] Object page = this;
4347 [javac] ^^^^
4348 [javac] The local variable page is never read
4349 [javac] ----------
4350 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/help_jsp.java
4351 [javac] (at line 51)
4352 [javac] String direction = isRTL?"rtl":"ltr";
4353 [javac] ^^^^^^^^^
4354 [javac] The local variable direction is never read
4355 [javac] ----------
4356 [javac] ----------
4357 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexList_jsp.java
4358 [javac] (at line 29)
4359 [javac] HttpSession session = null;
4360 [javac] ^^^^^^^
4361 [javac] The local variable session is never read
4362 [javac] ----------
4363 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexList_jsp.java
4364 [javac] (at line 31)
4365 [javac] ServletConfig config = null;
4366 [javac] ^^^^^^
4367 [javac] The local variable config is never read
4368 [javac] ----------
4369 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexList_jsp.java
4370 [javac] (at line 33)
4371 [javac] Object page = this;
4372 [javac] ^^^^
4373 [javac] The local variable page is never read
4374 [javac] ----------
4375 [javac] ----------
4376 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexToolbar_jsp.java
4377 [javac] (at line 28)
4378 [javac] HttpSession session = null;
4379 [javac] ^^^^^^^
4380 [javac] The local variable session is never read
4381 [javac] ----------
4382 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexToolbar_jsp.java
4383 [javac] (at line 30)
4384 [javac] ServletConfig config = null;
4385 [javac] ^^^^^^
4386 [javac] The local variable config is never read
4387 [javac] ----------
4388 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexToolbar_jsp.java
4389 [javac] (at line 32)
4390 [javac] Object page = this;
4391 [javac] ^^^^
4392 [javac] The local variable page is never read
4393 [javac] ----------
4394 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexToolbar_jsp.java
4395 [javac] (at line 51)
4396 [javac] String direction = isRTL?"rtl":"ltr";
4397 [javac] ^^^^^^^^^
4398 [javac] The local variable direction is never read
4399 [javac] ----------
4400 [javac] ----------
4401 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexTypein_jsp.java
4402 [javac] (at line 29)
4403 [javac] HttpSession session = null;
4404 [javac] ^^^^^^^
4405 [javac] The local variable session is never read
4406 [javac] ----------
4407 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexTypein_jsp.java
4408 [javac] (at line 31)
4409 [javac] ServletConfig config = null;
4410 [javac] ^^^^^^
4411 [javac] The local variable config is never read
4412 [javac] ----------
4413 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexTypein_jsp.java
4414 [javac] (at line 33)
4415 [javac] Object page = this;
4416 [javac] ^^^^
4417 [javac] The local variable page is never read
4418 [javac] ----------
4419 [javac] ----------
4420 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexView_jsp.java
4421 [javac] (at line 28)
4422 [javac] HttpSession session = null;
4423 [javac] ^^^^^^^
4424 [javac] The local variable session is never read
4425 [javac] ----------
4426 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexView_jsp.java
4427 [javac] (at line 30)
4428 [javac] ServletConfig config = null;
4429 [javac] ^^^^^^
4430 [javac] The local variable config is never read
4431 [javac] ----------
4432 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexView_jsp.java
4433 [javac] (at line 32)
4434 [javac] Object page = this;
4435 [javac] ^^^^
4436 [javac] The local variable page is never read
4437 [javac] ----------
4438 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/indexView_jsp.java
4439 [javac] (at line 51)
4440 [javac] String direction = isRTL?"rtl":"ltr";
4441 [javac] ^^^^^^^^^
4442 [javac] The local variable direction is never read
4443 [javac] ----------
4444 [javac] ----------
4445 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/index_jsp.java
4446 [javac] (at line 28)
4447 [javac] HttpSession session = null;
4448 [javac] ^^^^^^^
4449 [javac] The local variable session is never read
4450 [javac] ----------
4451 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/index_jsp.java
4452 [javac] (at line 30)
4453 [javac] ServletConfig config = null;
4454 [javac] ^^^^^^
4455 [javac] The local variable config is never read
4456 [javac] ----------
4457 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/index_jsp.java
4458 [javac] (at line 32)
4459 [javac] Object page = this;
4460 [javac] ^^^^
4461 [javac] The local variable page is never read
4462 [javac] ----------
4463 [javac] 63. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/index_jsp.java
4464 [javac] (at line 51)
4465 [javac] String direction = isRTL?"rtl":"ltr";
4466 [javac] ^^^^^^^^^
4467 [javac] The local variable direction is never read
4468 [javac] ----------
4469 [javac] ----------
4470 [javac] 64. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksToolbar_jsp.java
4471 [javac] (at line 28)
4472 [javac] HttpSession session = null;
4473 [javac] ^^^^^^^
4474 [javac] The local variable session is never read
4475 [javac] ----------
4476 [javac] 65. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksToolbar_jsp.java
4477 [javac] (at line 30)
4478 [javac] ServletConfig config = null;
4479 [javac] ^^^^^^
4480 [javac] The local variable config is never read
4481 [javac] ----------
4482 [javac] 66. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksToolbar_jsp.java
4483 [javac] (at line 32)
4484 [javac] Object page = this;
4485 [javac] ^^^^
4486 [javac] The local variable page is never read
4487 [javac] ----------
4488 [javac] 67. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksToolbar_jsp.java
4489 [javac] (at line 51)
4490 [javac] String direction = isRTL?"rtl":"ltr";
4491 [javac] ^^^^^^^^^
4492 [javac] The local variable direction is never read
4493 [javac] ----------
4494 [javac] ----------
4495 [javac] 68. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksView_jsp.java
4496 [javac] (at line 29)
4497 [javac] HttpSession session = null;
4498 [javac] ^^^^^^^
4499 [javac] The local variable session is never read
4500 [javac] ----------
4501 [javac] 69. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksView_jsp.java
4502 [javac] (at line 31)
4503 [javac] ServletConfig config = null;
4504 [javac] ^^^^^^
4505 [javac] The local variable config is never read
4506 [javac] ----------
4507 [javac] 70. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/linksView_jsp.java
4508 [javac] (at line 33)
4509 [javac] Object page = this;
4510 [javac] ^^^^
4511 [javac] The local variable page is never read
4512 [javac] ----------
4513 [javac] ----------
4514 [javac] 71. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/livehelp_js_jsp.java
4515 [javac] (at line 23)
4516 [javac] HttpSession session = null;
4517 [javac] ^^^^^^^
4518 [javac] The local variable session is never read
4519 [javac] ----------
4520 [javac] 72. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/livehelp_js_jsp.java
4521 [javac] (at line 25)
4522 [javac] ServletConfig config = null;
4523 [javac] ^^^^^^
4524 [javac] The local variable config is never read
4525 [javac] ----------
4526 [javac] 73. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/livehelp_js_jsp.java
4527 [javac] (at line 27)
4528 [javac] Object page = this;
4529 [javac] ^^^^
4530 [javac] The local variable page is never read
4531 [javac] ----------
4532 [javac] ----------
4533 [javac] 74. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/nav_jsp.java
4534 [javac] (at line 28)
4535 [javac] HttpSession session = null;
4536 [javac] ^^^^^^^
4537 [javac] The local variable session is never read
4538 [javac] ----------
4539 [javac] 75. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/nav_jsp.java
4540 [javac] (at line 30)
4541 [javac] ServletConfig config = null;
4542 [javac] ^^^^^^
4543 [javac] The local variable config is never read
4544 [javac] ----------
4545 [javac] 76. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/nav_jsp.java
4546 [javac] (at line 32)
4547 [javac] Object page = this;
4548 [javac] ^^^^
4549 [javac] The local variable page is never read
4550 [javac] ----------
4551 [javac] 77. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/nav_jsp.java
4552 [javac] (at line 51)
4553 [javac] String direction = isRTL?"rtl":"ltr";
4554 [javac] ^^^^^^^^^
4555 [javac] The local variable direction is never read
4556 [javac] ----------
4557 [javac] ----------
4558 [javac] 78. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchScoped_jsp.java
4559 [javac] (at line 28)
4560 [javac] HttpSession session = null;
4561 [javac] ^^^^^^^
4562 [javac] The local variable session is never read
4563 [javac] ----------
4564 [javac] 79. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchScoped_jsp.java
4565 [javac] (at line 30)
4566 [javac] ServletConfig config = null;
4567 [javac] ^^^^^^
4568 [javac] The local variable config is never read
4569 [javac] ----------
4570 [javac] 80. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchScoped_jsp.java
4571 [javac] (at line 32)
4572 [javac] Object page = this;
4573 [javac] ^^^^
4574 [javac] The local variable page is never read
4575 [javac] ----------
4576 [javac] ----------
4577 [javac] 81. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchSimple_jsp.java
4578 [javac] (at line 28)
4579 [javac] HttpSession session = null;
4580 [javac] ^^^^^^^
4581 [javac] The local variable session is never read
4582 [javac] ----------
4583 [javac] 82. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchSimple_jsp.java
4584 [javac] (at line 30)
4585 [javac] ServletConfig config = null;
4586 [javac] ^^^^^^
4587 [javac] The local variable config is never read
4588 [javac] ----------
4589 [javac] 83. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchSimple_jsp.java
4590 [javac] (at line 32)
4591 [javac] Object page = this;
4592 [javac] ^^^^
4593 [javac] The local variable page is never read
4594 [javac] ----------
4595 [javac] ----------
4596 [javac] 84. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchToolbar_jsp.java
4597 [javac] (at line 28)
4598 [javac] HttpSession session = null;
4599 [javac] ^^^^^^^
4600 [javac] The local variable session is never read
4601 [javac] ----------
4602 [javac] 85. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchToolbar_jsp.java
4603 [javac] (at line 30)
4604 [javac] ServletConfig config = null;
4605 [javac] ^^^^^^
4606 [javac] The local variable config is never read
4607 [javac] ----------
4608 [javac] 86. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchToolbar_jsp.java
4609 [javac] (at line 32)
4610 [javac] Object page = this;
4611 [javac] ^^^^
4612 [javac] The local variable page is never read
4613 [javac] ----------
4614 [javac] 87. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchToolbar_jsp.java
4615 [javac] (at line 51)
4616 [javac] String direction = isRTL?"rtl":"ltr";
4617 [javac] ^^^^^^^^^
4618 [javac] The local variable direction is never read
4619 [javac] ----------
4620 [javac] ----------
4621 [javac] 88. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchView_jsp.java
4622 [javac] (at line 29)
4623 [javac] HttpSession session = null;
4624 [javac] ^^^^^^^
4625 [javac] The local variable session is never read
4626 [javac] ----------
4627 [javac] 89. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchView_jsp.java
4628 [javac] (at line 31)
4629 [javac] ServletConfig config = null;
4630 [javac] ^^^^^^
4631 [javac] The local variable config is never read
4632 [javac] ----------
4633 [javac] 90. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/searchView_jsp.java
4634 [javac] (at line 33)
4635 [javac] Object page = this;
4636 [javac] ^^^^
4637 [javac] The local variable page is never read
4638 [javac] ----------
4639 [javac] ----------
4640 [javac] 91. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/search_jsp.java
4641 [javac] (at line 23)
4642 [javac] HttpSession session = null;
4643 [javac] ^^^^^^^
4644 [javac] The local variable session is never read
4645 [javac] ----------
4646 [javac] 92. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/search_jsp.java
4647 [javac] (at line 25)
4648 [javac] ServletConfig config = null;
4649 [javac] ^^^^^^
4650 [javac] The local variable config is never read
4651 [javac] ----------
4652 [javac] 93. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/search_jsp.java
4653 [javac] (at line 27)
4654 [javac] Object page = this;
4655 [javac] ^^^^
4656 [javac] The local variable page is never read
4657 [javac] ----------
4658 [javac] ----------
4659 [javac] 94. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tabs_jsp.java
4660 [javac] (at line 28)
4661 [javac] HttpSession session = null;
4662 [javac] ^^^^^^^
4663 [javac] The local variable session is never read
4664 [javac] ----------
4665 [javac] 95. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tabs_jsp.java
4666 [javac] (at line 30)
4667 [javac] ServletConfig config = null;
4668 [javac] ^^^^^^
4669 [javac] The local variable config is never read
4670 [javac] ----------
4671 [javac] 96. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tabs_jsp.java
4672 [javac] (at line 32)
4673 [javac] Object page = this;
4674 [javac] ^^^^
4675 [javac] The local variable page is never read
4676 [javac] ----------
4677 [javac] ----------
4678 [javac] 97. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocFragment_jsp.java
4679 [javac] (at line 28)
4680 [javac] HttpSession session = null;
4681 [javac] ^^^^^^^
4682 [javac] The local variable session is never read
4683 [javac] ----------
4684 [javac] 98. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocFragment_jsp.java
4685 [javac] (at line 30)
4686 [javac] ServletConfig config = null;
4687 [javac] ^^^^^^
4688 [javac] The local variable config is never read
4689 [javac] ----------
4690 [javac] 99. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocFragment_jsp.java
4691 [javac] (at line 32)
4692 [javac] Object page = this;
4693 [javac] ^^^^
4694 [javac] The local variable page is never read
4695 [javac] ----------
4696 [javac] ----------
4697 [javac] 100. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocToolbar_jsp.java
4698 [javac] (at line 28)
4699 [javac] HttpSession session = null;
4700 [javac] ^^^^^^^
4701 [javac] The local variable session is never read
4702 [javac] ----------
4703 [javac] 101. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocToolbar_jsp.java
4704 [javac] (at line 30)
4705 [javac] ServletConfig config = null;
4706 [javac] ^^^^^^
4707 [javac] The local variable config is never read
4708 [javac] ----------
4709 [javac] 102. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocToolbar_jsp.java
4710 [javac] (at line 32)
4711 [javac] Object page = this;
4712 [javac] ^^^^
4713 [javac] The local variable page is never read
4714 [javac] ----------
4715 [javac] 103. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocToolbar_jsp.java
4716 [javac] (at line 51)
4717 [javac] String direction = isRTL?"rtl":"ltr";
4718 [javac] ^^^^^^^^^
4719 [javac] The local variable direction is never read
4720 [javac] ----------
4721 [javac] ----------
4722 [javac] 104. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocView_jsp.java
4723 [javac] (at line 29)
4724 [javac] HttpSession session = null;
4725 [javac] ^^^^^^^
4726 [javac] The local variable session is never read
4727 [javac] ----------
4728 [javac] 105. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocView_jsp.java
4729 [javac] (at line 31)
4730 [javac] ServletConfig config = null;
4731 [javac] ^^^^^^
4732 [javac] The local variable config is never read
4733 [javac] ----------
4734 [javac] 106. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/tocView_jsp.java
4735 [javac] (at line 33)
4736 [javac] Object page = this;
4737 [javac] ^^^^
4738 [javac] The local variable page is never read
4739 [javac] ----------
4740 [javac] ----------
4741 [javac] 107. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/toolbar_jsp.java
4742 [javac] (at line 28)
4743 [javac] HttpSession session = null;
4744 [javac] ^^^^^^^
4745 [javac] The local variable session is never read
4746 [javac] ----------
4747 [javac] 108. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/toolbar_jsp.java
4748 [javac] (at line 30)
4749 [javac] ServletConfig config = null;
4750 [javac] ^^^^^^
4751 [javac] The local variable config is never read
4752 [javac] ----------
4753 [javac] 109. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/toolbar_jsp.java
4754 [javac] (at line 32)
4755 [javac] Object page = this;
4756 [javac] ^^^^
4757 [javac] The local variable page is never read
4758 [javac] ----------
4759 [javac] ----------
4760 [javac] 110. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/view_jsp.java
4761 [javac] (at line 28)
4762 [javac] HttpSession session = null;
4763 [javac] ^^^^^^^
4764 [javac] The local variable session is never read
4765 [javac] ----------
4766 [javac] 111. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/view_jsp.java
4767 [javac] (at line 30)
4768 [javac] ServletConfig config = null;
4769 [javac] ^^^^^^
4770 [javac] The local variable config is never read
4771 [javac] ----------
4772 [javac] 112. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/view_jsp.java
4773 [javac] (at line 32)
4774 [javac] Object page = this;
4775 [javac] ^^^^
4776 [javac] The local variable page is never read
4777 [javac] ----------
4778 [javac] 113. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/view_jsp.java
4779 [javac] (at line 51)
4780 [javac] String direction = isRTL?"rtl":"ltr";
4781 [javac] ^^^^^^^^^
4782 [javac] The local variable direction is never read
4783 [javac] ----------
4784 [javac] ----------
4785 [javac] 114. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/views_jsp.java
4786 [javac] (at line 28)
4787 [javac] HttpSession session = null;
4788 [javac] ^^^^^^^
4789 [javac] The local variable session is never read
4790 [javac] ----------
4791 [javac] 115. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/views_jsp.java
4792 [javac] (at line 30)
4793 [javac] ServletConfig config = null;
4794 [javac] ^^^^^^
4795 [javac] The local variable config is never read
4796 [javac] ----------
4797 [javac] 116. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/views_jsp.java
4798 [javac] (at line 32)
4799 [javac] Object page = this;
4800 [javac] ^^^^
4801 [javac] The local variable page is never read
4802 [javac] ----------
4803 [javac] ----------
4804 [javac] 117. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSetManager_jsp.java
4805 [javac] (at line 29)
4806 [javac] HttpSession session = null;
4807 [javac] ^^^^^^^
4808 [javac] The local variable session is never read
4809 [javac] ----------
4810 [javac] 118. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSetManager_jsp.java
4811 [javac] (at line 31)
4812 [javac] ServletConfig config = null;
4813 [javac] ^^^^^^
4814 [javac] The local variable config is never read
4815 [javac] ----------
4816 [javac] 119. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSetManager_jsp.java
4817 [javac] (at line 33)
4818 [javac] Object page = this;
4819 [javac] ^^^^
4820 [javac] The local variable page is never read
4821 [javac] ----------
4822 [javac] ----------
4823 [javac] 120. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSet_jsp.java
4824 [javac] (at line 28)
4825 [javac] HttpSession session = null;
4826 [javac] ^^^^^^^
4827 [javac] The local variable session is never read
4828 [javac] ----------
4829 [javac] 121. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSet_jsp.java
4830 [javac] (at line 30)
4831 [javac] ServletConfig config = null;
4832 [javac] ^^^^^^
4833 [javac] The local variable config is never read
4834 [javac] ----------
4835 [javac] 122. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/advanced/workingSet_jsp.java
4836 [javac] (at line 32)
4837 [javac] Object page = this;
4838 [javac] ^^^^
4839 [javac] The local variable page is never read
4840 [javac] ----------
4841 [javac] ----------
4842 [javac] 123. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/err_jsp.java
4843 [javac] (at line 23)
4844 [javac] HttpSession session = null;
4845 [javac] ^^^^^^^
4846 [javac] The local variable session is never read
4847 [javac] ----------
4848 [javac] 124. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/err_jsp.java
4849 [javac] (at line 25)
4850 [javac] ServletContext application = null;
4851 [javac] ^^^^^^^^^^^
4852 [javac] The local variable application is never read
4853 [javac] ----------
4854 [javac] 125. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/err_jsp.java
4855 [javac] (at line 26)
4856 [javac] ServletConfig config = null;
4857 [javac] ^^^^^^
4858 [javac] The local variable config is never read
4859 [javac] ----------
4860 [javac] 126. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/err_jsp.java
4861 [javac] (at line 28)
4862 [javac] Object page = this;
4863 [javac] ^^^^
4864 [javac] The local variable page is never read
4865 [javac] ----------
4866 [javac] ----------
4867 [javac] 127. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/header_jsp.java
4868 [javac] (at line 23)
4869 [javac] HttpSession session = null;
4870 [javac] ^^^^^^^
4871 [javac] The local variable session is never read
4872 [javac] ----------
4873 [javac] 128. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/header_jsp.java
4874 [javac] (at line 24)
4875 [javac] ServletContext application = null;
4876 [javac] ^^^^^^^^^^^
4877 [javac] The local variable application is never read
4878 [javac] ----------
4879 [javac] 129. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/header_jsp.java
4880 [javac] (at line 25)
4881 [javac] ServletConfig config = null;
4882 [javac] ^^^^^^
4883 [javac] The local variable config is never read
4884 [javac] ----------
4885 [javac] 130. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/header_jsp.java
4886 [javac] (at line 27)
4887 [javac] Object page = this;
4888 [javac] ^^^^
4889 [javac] The local variable page is never read
4890 [javac] ----------
4891 [javac] 131. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/header_jsp.java
4892 [javac] (at line 47)
4893 [javac] String direction = isRTL?"rtl":"ltr";
4894 [javac] ^^^^^^^^^
4895 [javac] The local variable direction is never read
4896 [javac] ----------
4897 [javac] ----------
4898 [javac] 132. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/help_jsp.java
4899 [javac] (at line 28)
4900 [javac] HttpSession session = null;
4901 [javac] ^^^^^^^
4902 [javac] The local variable session is never read
4903 [javac] ----------
4904 [javac] 133. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/help_jsp.java
4905 [javac] (at line 30)
4906 [javac] ServletConfig config = null;
4907 [javac] ^^^^^^
4908 [javac] The local variable config is never read
4909 [javac] ----------
4910 [javac] 134. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/help_jsp.java
4911 [javac] (at line 32)
4912 [javac] Object page = this;
4913 [javac] ^^^^
4914 [javac] The local variable page is never read
4915 [javac] ----------
4916 [javac] 135. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/help_jsp.java
4917 [javac] (at line 53)
4918 [javac] String direction = isRTL?"rtl":"ltr";
4919 [javac] ^^^^^^^^^
4920 [javac] The local variable direction is never read
4921 [javac] ----------
4922 [javac] ----------
4923 [javac] 136. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexToolbar_jsp.java
4924 [javac] (at line 28)
4925 [javac] HttpSession session = null;
4926 [javac] ^^^^^^^
4927 [javac] The local variable session is never read
4928 [javac] ----------
4929 [javac] 137. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexToolbar_jsp.java
4930 [javac] (at line 29)
4931 [javac] ServletContext application = null;
4932 [javac] ^^^^^^^^^^^
4933 [javac] The local variable application is never read
4934 [javac] ----------
4935 [javac] 138. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexToolbar_jsp.java
4936 [javac] (at line 30)
4937 [javac] ServletConfig config = null;
4938 [javac] ^^^^^^
4939 [javac] The local variable config is never read
4940 [javac] ----------
4941 [javac] 139. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexToolbar_jsp.java
4942 [javac] (at line 32)
4943 [javac] Object page = this;
4944 [javac] ^^^^
4945 [javac] The local variable page is never read
4946 [javac] ----------
4947 [javac] 140. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexToolbar_jsp.java
4948 [javac] (at line 53)
4949 [javac] String direction = isRTL?"rtl":"ltr";
4950 [javac] ^^^^^^^^^
4951 [javac] The local variable direction is never read
4952 [javac] ----------
4953 [javac] ----------
4954 [javac] 141. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexView_jsp.java
4955 [javac] (at line 28)
4956 [javac] HttpSession session = null;
4957 [javac] ^^^^^^^
4958 [javac] The local variable session is never read
4959 [javac] ----------
4960 [javac] 142. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexView_jsp.java
4961 [javac] (at line 30)
4962 [javac] ServletConfig config = null;
4963 [javac] ^^^^^^
4964 [javac] The local variable config is never read
4965 [javac] ----------
4966 [javac] 143. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/indexView_jsp.java
4967 [javac] (at line 32)
4968 [javac] Object page = this;
4969 [javac] ^^^^
4970 [javac] The local variable page is never read
4971 [javac] ----------
4972 [javac] ----------
4973 [javac] 144. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/index_jsp.java
4974 [javac] (at line 28)
4975 [javac] HttpSession session = null;
4976 [javac] ^^^^^^^
4977 [javac] The local variable session is never read
4978 [javac] ----------
4979 [javac] 145. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/index_jsp.java
4980 [javac] (at line 30)
4981 [javac] ServletConfig config = null;
4982 [javac] ^^^^^^
4983 [javac] The local variable config is never read
4984 [javac] ----------
4985 [javac] 146. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/index_jsp.java
4986 [javac] (at line 32)
4987 [javac] Object page = this;
4988 [javac] ^^^^
4989 [javac] The local variable page is never read
4990 [javac] ----------
4991 [javac] 147. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/index_jsp.java
4992 [javac] (at line 53)
4993 [javac] String direction = isRTL?"rtl":"ltr";
4994 [javac] ^^^^^^^^^
4995 [javac] The local variable direction is never read
4996 [javac] ----------
4997 [javac] ----------
4998 [javac] 148. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksToolbar_jsp.java
4999 [javac] (at line 28)
5000 [javac] HttpSession session = null;
5001 [javac] ^^^^^^^
5002 [javac] The local variable session is never read
5003 [javac] ----------
5004 [javac] 149. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksToolbar_jsp.java
5005 [javac] (at line 29)
5006 [javac] ServletContext application = null;
5007 [javac] ^^^^^^^^^^^
5008 [javac] The local variable application is never read
5009 [javac] ----------
5010 [javac] 150. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksToolbar_jsp.java
5011 [javac] (at line 30)
5012 [javac] ServletConfig config = null;
5013 [javac] ^^^^^^
5014 [javac] The local variable config is never read
5015 [javac] ----------
5016 [javac] 151. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksToolbar_jsp.java
5017 [javac] (at line 32)
5018 [javac] Object page = this;
5019 [javac] ^^^^
5020 [javac] The local variable page is never read
5021 [javac] ----------
5022 [javac] 152. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksToolbar_jsp.java
5023 [javac] (at line 53)
5024 [javac] String direction = isRTL?"rtl":"ltr";
5025 [javac] ^^^^^^^^^
5026 [javac] The local variable direction is never read
5027 [javac] ----------
5028 [javac] ----------
5029 [javac] 153. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksView_jsp.java
5030 [javac] (at line 28)
5031 [javac] HttpSession session = null;
5032 [javac] ^^^^^^^
5033 [javac] The local variable session is never read
5034 [javac] ----------
5035 [javac] 154. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksView_jsp.java
5036 [javac] (at line 30)
5037 [javac] ServletConfig config = null;
5038 [javac] ^^^^^^
5039 [javac] The local variable config is never read
5040 [javac] ----------
5041 [javac] 155. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/linksView_jsp.java
5042 [javac] (at line 32)
5043 [javac] Object page = this;
5044 [javac] ^^^^
5045 [javac] The local variable page is never read
5046 [javac] ----------
5047 [javac] ----------
5048 [javac] 156. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/livehelp_js_jsp.java
5049 [javac] (at line 23)
5050 [javac] HttpSession session = null;
5051 [javac] ^^^^^^^
5052 [javac] The local variable session is never read
5053 [javac] ----------
5054 [javac] 157. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/livehelp_js_jsp.java
5055 [javac] (at line 25)
5056 [javac] ServletConfig config = null;
5057 [javac] ^^^^^^
5058 [javac] The local variable config is never read
5059 [javac] ----------
5060 [javac] 158. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/livehelp_js_jsp.java
5061 [javac] (at line 27)
5062 [javac] Object page = this;
5063 [javac] ^^^^
5064 [javac] The local variable page is never read
5065 [javac] ----------
5066 [javac] ----------
5067 [javac] 159. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchToolbar_jsp.java
5068 [javac] (at line 28)
5069 [javac] HttpSession session = null;
5070 [javac] ^^^^^^^
5071 [javac] The local variable session is never read
5072 [javac] ----------
5073 [javac] 160. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchToolbar_jsp.java
5074 [javac] (at line 29)
5075 [javac] ServletContext application = null;
5076 [javac] ^^^^^^^^^^^
5077 [javac] The local variable application is never read
5078 [javac] ----------
5079 [javac] 161. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchToolbar_jsp.java
5080 [javac] (at line 30)
5081 [javac] ServletConfig config = null;
5082 [javac] ^^^^^^
5083 [javac] The local variable config is never read
5084 [javac] ----------
5085 [javac] 162. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchToolbar_jsp.java
5086 [javac] (at line 32)
5087 [javac] Object page = this;
5088 [javac] ^^^^
5089 [javac] The local variable page is never read
5090 [javac] ----------
5091 [javac] 163. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchToolbar_jsp.java
5092 [javac] (at line 53)
5093 [javac] String direction = isRTL?"rtl":"ltr";
5094 [javac] ^^^^^^^^^
5095 [javac] The local variable direction is never read
5096 [javac] ----------
5097 [javac] ----------
5098 [javac] 164. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchView_jsp.java
5099 [javac] (at line 29)
5100 [javac] HttpSession session = null;
5101 [javac] ^^^^^^^
5102 [javac] The local variable session is never read
5103 [javac] ----------
5104 [javac] 165. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchView_jsp.java
5105 [javac] (at line 31)
5106 [javac] ServletConfig config = null;
5107 [javac] ^^^^^^
5108 [javac] The local variable config is never read
5109 [javac] ----------
5110 [javac] 166. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchView_jsp.java
5111 [javac] (at line 33)
5112 [javac] Object page = this;
5113 [javac] ^^^^
5114 [javac] The local variable page is never read
5115 [javac] ----------
5116 [javac] 167. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/searchView_jsp.java
5117 [javac] (at line 63)
5118 [javac] LayoutData ldata = new LayoutData(application,request, response);
5119 [javac] ^^^^^
5120 [javac] The local variable ldata is never read
5121 [javac] ----------
5122 [javac] ----------
5123 [javac] 168. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tabs_jsp.java
5124 [javac] (at line 28)
5125 [javac] HttpSession session = null;
5126 [javac] ^^^^^^^
5127 [javac] The local variable session is never read
5128 [javac] ----------
5129 [javac] 169. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tabs_jsp.java
5130 [javac] (at line 30)
5131 [javac] ServletConfig config = null;
5132 [javac] ^^^^^^
5133 [javac] The local variable config is never read
5134 [javac] ----------
5135 [javac] 170. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tabs_jsp.java
5136 [javac] (at line 32)
5137 [javac] Object page = this;
5138 [javac] ^^^^
5139 [javac] The local variable page is never read
5140 [javac] ----------
5141 [javac] ----------
5142 [javac] 171. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocToolbar_jsp.java
5143 [javac] (at line 28)
5144 [javac] HttpSession session = null;
5145 [javac] ^^^^^^^
5146 [javac] The local variable session is never read
5147 [javac] ----------
5148 [javac] 172. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocToolbar_jsp.java
5149 [javac] (at line 29)
5150 [javac] ServletContext application = null;
5151 [javac] ^^^^^^^^^^^
5152 [javac] The local variable application is never read
5153 [javac] ----------
5154 [javac] 173. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocToolbar_jsp.java
5155 [javac] (at line 30)
5156 [javac] ServletConfig config = null;
5157 [javac] ^^^^^^
5158 [javac] The local variable config is never read
5159 [javac] ----------
5160 [javac] 174. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocToolbar_jsp.java
5161 [javac] (at line 32)
5162 [javac] Object page = this;
5163 [javac] ^^^^
5164 [javac] The local variable page is never read
5165 [javac] ----------
5166 [javac] 175. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocToolbar_jsp.java
5167 [javac] (at line 53)
5168 [javac] String direction = isRTL?"rtl":"ltr";
5169 [javac] ^^^^^^^^^
5170 [javac] The local variable direction is never read
5171 [javac] ----------
5172 [javac] ----------
5173 [javac] 176. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocView_jsp.java
5174 [javac] (at line 28)
5175 [javac] HttpSession session = null;
5176 [javac] ^^^^^^^
5177 [javac] The local variable session is never read
5178 [javac] ----------
5179 [javac] 177. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocView_jsp.java
5180 [javac] (at line 30)
5181 [javac] ServletConfig config = null;
5182 [javac] ^^^^^^
5183 [javac] The local variable config is never read
5184 [javac] ----------
5185 [javac] 178. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/tocView_jsp.java
5186 [javac] (at line 32)
5187 [javac] Object page = this;
5188 [javac] ^^^^
5189 [javac] The local variable page is never read
5190 [javac] ----------
5191 [javac] ----------
5192 [javac] 179. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/toolbar_jsp.java
5193 [javac] (at line 28)
5194 [javac] HttpSession session = null;
5195 [javac] ^^^^^^^
5196 [javac] The local variable session is never read
5197 [javac] ----------
5198 [javac] 180. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/toolbar_jsp.java
5199 [javac] (at line 30)
5200 [javac] ServletConfig config = null;
5201 [javac] ^^^^^^
5202 [javac] The local variable config is never read
5203 [javac] ----------
5204 [javac] 181. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/toolbar_jsp.java
5205 [javac] (at line 32)
5206 [javac] Object page = this;
5207 [javac] ^^^^
5208 [javac] The local variable page is never read
5209 [javac] ----------
5210 [javac] ----------
5211 [javac] 182. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/view_jsp.java
5212 [javac] (at line 28)
5213 [javac] HttpSession session = null;
5214 [javac] ^^^^^^^
5215 [javac] The local variable session is never read
5216 [javac] ----------
5217 [javac] 183. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/view_jsp.java
5218 [javac] (at line 30)
5219 [javac] ServletConfig config = null;
5220 [javac] ^^^^^^
5221 [javac] The local variable config is never read
5222 [javac] ----------
5223 [javac] 184. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/view_jsp.java
5224 [javac] (at line 32)
5225 [javac] Object page = this;
5226 [javac] ^^^^
5227 [javac] The local variable page is never read
5228 [javac] ----------
5229 [javac] 185. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/basic/view_jsp.java
5230 [javac] (at line 53)
5231 [javac] String direction = isRTL?"rtl":"ltr";
5232 [javac] ^^^^^^^^^
5233 [javac] The local variable direction is never read
5234 [javac] ----------
5235 [javac] ----------
5236 [javac] 186. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/index_jsp.java
5237 [javac] (at line 23)
5238 [javac] HttpSession session = null;
5239 [javac] ^^^^^^^
5240 [javac] The local variable session is never read
5241 [javac] ----------
5242 [javac] 187. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/index_jsp.java
5243 [javac] (at line 25)
5244 [javac] ServletConfig config = null;
5245 [javac] ^^^^^^
5246 [javac] The local variable config is never read
5247 [javac] ----------
5248 [javac] 188. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.help.webapp/temp.folder/jsp.jar.src/index_jsp.java
5249 [javac] (at line 27)
5250 [javac] Object page = this;
5251 [javac] ^^^^
5252 [javac] The local variable page is never read
5253 [javac] ----------
5254 [javac] 188 problems (188 warnings)
5255 [zip] Warning: skipping zip archive /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi.services/src.zip because no files were included.
5256 [zip] Warning: skipping zip archive /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.osgi.util/src.zip because no files were included.
5257 [exec] javadoc: Error reading file: /usr/share/javadoc/java/package-list
5258 [exec] javadoc: Error reading file: org.eclipse.ant.core/package-list
5259 [exec] Result: 1
5260 [echo] Extract .class file and properties for the batch compiler
5261 [echo] Extract .class file and properties for the ant adapter
5262 [echo] UPDATE ecj.jar
5263 [echo] UPDATE ecjsrc.zip
5264 [javac] ----------
5265 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
5266 [javac] (at line 70)
5267 [javac] import org.eclipse.jdt.internal.core.util.Util;
5268 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5269 [javac] Discouraged access: The type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5270 [javac] ----------
5271 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
5272 [javac] (at line 634)
5273 [javac] bytes= Util.getResourceContentsAsByteArray((IFile) resource);
5274 [javac] ^^^^
5275 [javac] Discouraged access: The type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5276 [javac] ----------
5277 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/hcr/JavaHotCodeReplaceManager.java
5278 [javac] (at line 634)
5279 [javac] bytes= Util.getResourceContentsAsByteArray((IFile) resource);
5280 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5281 [javac] Discouraged access: The method getResourceContentsAsByteArray(IFile) from the type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5282 [javac] ----------
5283 [javac] ----------
5284 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/spy/VerbosePacketStream.java
5285 [javac] (at line 1711)
5286 [javac] String signature= readString(in);
5287 [javac] ^^^^^^^^^
5288 [javac] The local variable signature is never read
5289 [javac] ----------
5290 [javac] ----------
5291 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java
5292 [javac] (at line 17)
5293 [javac] import org.eclipse.jdt.internal.core.util.Util;
5294 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5295 [javac] Discouraged access: The type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5296 [javac] ----------
5297 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java
5298 [javac] (at line 37)
5299 [javac] i = Util.scanTypeSignature(typeSignature, i);
5300 [javac] ^^^^
5301 [javac] Discouraged access: The type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5302 [javac] ----------
5303 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java
5304 [javac] (at line 37)
5305 [javac] i = Util.scanTypeSignature(typeSignature, i);
5306 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5307 [javac] Discouraged access: The method scanTypeSignature(char[], int) from the type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5308 [javac] ----------
5309 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java
5310 [javac] (at line 47)
5311 [javac] i= Util.scanTypeSignature(typeSignature, i);
5312 [javac] ^^^^
5313 [javac] Discouraged access: The type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5314 [javac] ----------
5315 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/SignatureExt.java
5316 [javac] (at line 47)
5317 [javac] i= Util.scanTypeSignature(typeSignature, i);
5318 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5319 [javac] Discouraged access: The method scanTypeSignature(char[], int) from the type Util is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.core/@dot
5320 [javac] ----------
5321 [javac] 9 problems (9 warnings)
5322 [javac] ----------
5323 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/sourcelookup/containers/JavaSourceLookupParticipant.java
5324 [javac] (at line 30)
5325 [javac] import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
5326 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5327 [javac] Discouraged access: The type JavaDebugUtils is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/jdimodel.jar
5328 [javac] ----------
5329 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/sourcelookup/containers/JavaSourceLookupParticipant.java
5330 [javac] (at line 60)
5331 [javac] return JavaDebugUtils.getSourceName(object);
5332 [javac] ^^^^^^^^^^^^^^
5333 [javac] Discouraged access: The type JavaDebugUtils is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/jdimodel.jar
5334 [javac] ----------
5335 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/sourcelookup/containers/JavaSourceLookupParticipant.java
5336 [javac] (at line 60)
5337 [javac] return JavaDebugUtils.getSourceName(object);
5338 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5339 [javac] Discouraged access: The method getSourceName(Object) from the type JavaDebugUtils is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug/jdimodel.jar
5340 [javac] ----------
5341 [javac] 3 problems (3 warnings)
5342 [javac] ----------
5343 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5344 [javac] (at line 40)
5345 [javac] import org.eclipse.ltk.internal.ui.refactoring.history.BrowseRefactoringHistoryControl;
5346 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5347 [javac] Discouraged access: The type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5348 [javac] ----------
5349 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5350 [javac] (at line 69)
5351 [javac] private BrowseRefactoringHistoryControl fHistoryControl= null;
5352 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5353 [javac] Discouraged access: The type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5354 [javac] ----------
5355 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5356 [javac] (at line 102)
5357 [javac] final RefactoringDescriptorProxy[] descriptors= fHistoryControl.getCheckedDescriptors();
5358 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5359 [javac] Discouraged access: The method getCheckedDescriptors() from the type RefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5360 [javac] ----------
5361 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5362 [javac] (at line 115)
5363 [javac] settings.put(SETTING_SORT, fHistoryControl.isSortByProjects());
5364 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5365 [javac] Discouraged access: The method isSortByProjects() from the type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5366 [javac] ----------
5367 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5368 [javac] (at line 147)
5369 [javac] fHistoryControl= new BrowseRefactoringHistoryControl(composite, configuration);
5370 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5371 [javac] Discouraged access: The constructor BrowseRefactoringHistoryControl(Composite, RefactoringHistoryControlConfiguration) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5372 [javac] ----------
5373 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5374 [javac] (at line 147)
5375 [javac] fHistoryControl= new BrowseRefactoringHistoryControl(composite, configuration);
5376 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5377 [javac] Discouraged access: The type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5378 [javac] ----------
5379 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5380 [javac] (at line 148)
5381 [javac] fHistoryControl.createControl();
5382 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5383 [javac] Discouraged access: The method createControl() from the type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5384 [javac] ----------
5385 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5386 [javac] (at line 154)
5387 [javac] fHistoryControl.sortByProjects();
5388 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5389 [javac] Discouraged access: The method sortByProjects() from the type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5390 [javac] ----------
5391 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5392 [javac] (at line 156)
5393 [javac] fHistoryControl.sortByDate();
5394 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5395 [javac] Discouraged access: The method sortByDate() from the type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5396 [javac] ----------
5397 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5398 [javac] (at line 161)
5399 [javac] fHistoryControl.setInput(fHistory);
5400 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5401 [javac] Discouraged access: The method setInput(RefactoringHistory) from the type BrowseRefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5402 [javac] ----------
5403 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
5404 [javac] (at line 162)
5405 [javac] fHistoryControl.setCheckedDescriptors(fData.getRefactoringDescriptors());
5406 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5407 [javac] Discouraged access: The method setCheckedDescriptors(RefactoringDescriptorProxy[]) from the type RefactoringHistoryControl is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5408 [javac] ----------
5409 [javac] ----------
5410 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ProjectActionGroup.java
5411 [javac] (at line 37)
5412 [javac] import org.eclipse.ui.internal.ide.actions.CloseUnrelatedProjectsAction;
5413 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5414 [javac] Discouraged access: The type CloseUnrelatedProjectsAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
5415 [javac] ----------
5416 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ProjectActionGroup.java
5417 [javac] (at line 79)
5418 [javac] fCloseUnrelatedAction= new CloseUnrelatedProjectsAction(shell);
5419 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5420 [javac] Discouraged access: The constructor CloseUnrelatedProjectsAction(Shell) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
5421 [javac] ----------
5422 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ProjectActionGroup.java
5423 [javac] (at line 79)
5424 [javac] fCloseUnrelatedAction= new CloseUnrelatedProjectsAction(shell);
5425 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5426 [javac] Discouraged access: The type CloseUnrelatedProjectsAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.ide/@dot
5427 [javac] ----------
5428 [javac] ----------
5429 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5430 [javac] (at line 48)
5431 [javac] import org.eclipse.ltk.internal.ui.refactoring.ChangeExceptionHandler;
5432 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5433 [javac] Discouraged access: The type ChangeExceptionHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5434 [javac] ----------
5435 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5436 [javac] (at line 143)
5437 [javac] ChangeExceptionHandler handler= new ChangeExceptionHandler(fParent, fRefactoring);
5438 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5439 [javac] Discouraged access: The type ChangeExceptionHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5440 [javac] ----------
5441 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5442 [javac] (at line 143)
5443 [javac] ChangeExceptionHandler handler= new ChangeExceptionHandler(fParent, fRefactoring);
5444 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5445 [javac] Discouraged access: The constructor ChangeExceptionHandler(Shell, Refactoring) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5446 [javac] ----------
5447 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5448 [javac] (at line 143)
5449 [javac] ChangeExceptionHandler handler= new ChangeExceptionHandler(fParent, fRefactoring);
5450 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5451 [javac] Discouraged access: The type ChangeExceptionHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5452 [javac] ----------
5453 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5454 [javac] (at line 146)
5455 [javac] handler.handle(pco.getChange(), (RuntimeException)inner);
5456 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5457 [javac] Discouraged access: The method handle(Change, RuntimeException) from the type ChangeExceptionHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5458 [javac] ----------
5459 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringExecutionHelper.java
5460 [javac] (at line 148)
5461 [javac] handler.handle(pco.getChange(), (CoreException)inner);
5462 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5463 [javac] Discouraged access: The method handle(Change, CoreException) from the type ChangeExceptionHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5464 [javac] ----------
5465 [javac] ----------
5466 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/ApplyRefactoringScriptAction.java
5467 [javac] (at line 48)
5468 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.ApplyRefactoringScriptAction.showApplyScriptWizard(fWindow);
5469 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5470 [javac] Discouraged access: The type ApplyRefactoringScriptAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5471 [javac] ----------
5472 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/ApplyRefactoringScriptAction.java
5473 [javac] (at line 48)
5474 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.ApplyRefactoringScriptAction.showApplyScriptWizard(fWindow);
5475 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5476 [javac] Discouraged access: The method showApplyScriptWizard(IWorkbenchWindow) from the type ApplyRefactoringScriptAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5477 [javac] ----------
5478 [javac] ----------
5479 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/CreateRefactoringScriptAction.java
5480 [javac] (at line 48)
5481 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.CreateRefactoringScriptAction.showCreateScriptWizard(fWindow);
5482 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5483 [javac] Discouraged access: The type CreateRefactoringScriptAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5484 [javac] ----------
5485 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/CreateRefactoringScriptAction.java
5486 [javac] (at line 48)
5487 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.CreateRefactoringScriptAction.showCreateScriptWizard(fWindow);
5488 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5489 [javac] Discouraged access: The method showCreateScriptWizard(IWorkbenchWindow) from the type CreateRefactoringScriptAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5490 [javac] ----------
5491 [javac] ----------
5492 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/ShowRefactoringHistoryAction.java
5493 [javac] (at line 48)
5494 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.ShowRefactoringHistoryAction.showRefactoringHistoryWizard(fWindow);
5495 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5496 [javac] Discouraged access: The type ShowRefactoringHistoryAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5497 [javac] ----------
5498 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/actions/ShowRefactoringHistoryAction.java
5499 [javac] (at line 48)
5500 [javac] org.eclipse.ltk.internal.ui.refactoring.actions.ShowRefactoringHistoryAction.showRefactoringHistoryWizard(fWindow);
5501 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5502 [javac] Discouraged access: The method showRefactoringHistoryWizard(IWorkbenchWindow) from the type ShowRefactoringHistoryAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ltk.ui.refactoring/@dot
5503 [javac] ----------
5504 [javac] 26 problems (26 warnings)
5505 [javac] ----------
5506 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXDebugVMRunner.java
5507 [javac] (at line 16)
5508 [javac] import org.eclipse.jdt.internal.launching.StandardVMDebugger;
5509 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5510 [javac] Discouraged access: The type StandardVMDebugger is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5511 [javac] ----------
5512 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXDebugVMRunner.java
5513 [javac] (at line 19)
5514 [javac] public class MacOSXDebugVMRunner extends StandardVMDebugger {
5515 [javac] ^^^^^^^^^^^^^^^^^^
5516 [javac] Discouraged access: The type StandardVMDebugger is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5517 [javac] ----------
5518 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXDebugVMRunner.java
5519 [javac] (at line 22)
5520 [javac] super(vmInstance);
5521 [javac] ^^^^^^^^^^^^^^^^^
5522 [javac] Discouraged access: The constructor StandardVMDebugger(IVMInstall) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5523 [javac] ----------
5524 [javac] ----------
5525 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstall.java
5526 [javac] (at line 16)
5527 [javac] import org.eclipse.jdt.internal.launching.StandardVMType;
5528 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5529 [javac] Discouraged access: The type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5530 [javac] ----------
5531 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstall.java
5532 [javac] (at line 40)
5533 [javac] File executable= StandardVMType.findJavaExecutable(installLocation);
5534 [javac] ^^^^^^^^^^^^^^
5535 [javac] Discouraged access: The type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5536 [javac] ----------
5537 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstall.java
5538 [javac] (at line 40)
5539 [javac] File executable= StandardVMType.findJavaExecutable(installLocation);
5540 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5541 [javac] Discouraged access: The method findJavaExecutable(File) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5542 [javac] ----------
5543 [javac] ----------
5544 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5545 [javac] (at line 26)
5546 [javac] import org.eclipse.jdt.internal.launching.LaunchingPlugin;
5547 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5548 [javac] Discouraged access: The type LaunchingPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5549 [javac] ----------
5550 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5551 [javac] (at line 27)
5552 [javac] import org.eclipse.jdt.internal.launching.LibraryInfo;
5553 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5554 [javac] Discouraged access: The type LibraryInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5555 [javac] ----------
5556 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5557 [javac] (at line 28)
5558 [javac] import org.eclipse.jdt.internal.launching.StandardVMType;
5559 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5560 [javac] Discouraged access: The type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5561 [javac] ----------
5562 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5563 [javac] (at line 37)
5564 [javac] public class MacOSXVMInstallType extends StandardVMType {
5565 [javac] ^^^^^^^^^^^^^^
5566 [javac] Discouraged access: The type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5567 [javac] ----------
5568 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5569 [javac] (at line 113)
5570 [javac] vm.setLibraryLocations(getDefaultLibraryLocations(home));
5571 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5572 [javac] Discouraged access: The method getDefaultLibraryLocations(File) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5573 [javac] ----------
5574 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5575 [javac] (at line 124)
5576 [javac] LaunchingPlugin.log(e);
5577 [javac] ^^^^^^^^^^^^^^^
5578 [javac] Discouraged access: The type LaunchingPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5579 [javac] ----------
5580 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5581 [javac] (at line 124)
5582 [javac] LaunchingPlugin.log(e);
5583 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5584 [javac] Discouraged access: The method log(Throwable) from the type LaunchingPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5585 [javac] ----------
5586 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5587 [javac] (at line 133)
5588 [javac] LaunchingPlugin.log(e);
5589 [javac] ^^^^^^^^^^^^^^^
5590 [javac] Discouraged access: The type LaunchingPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5591 [javac] ----------
5592 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5593 [javac] (at line 133)
5594 [javac] LaunchingPlugin.log(e);
5595 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5596 [javac] Discouraged access: The method log(Throwable) from the type LaunchingPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5597 [javac] ----------
5598 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5599 [javac] (at line 149)
5600 [javac] protected LibraryInfo getDefaultLibraryInfo(File installLocation) {
5601 [javac] ^^^^^^^^^^^
5602 [javac] Discouraged access: The type LibraryInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5603 [javac] ----------
5604 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5605 [javac] (at line 172)
5606 [javac] return new LibraryInfo("???", libs, dirs, endDirs); //$NON-NLS-1$
5607 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5608 [javac] Discouraged access: The constructor LibraryInfo(String, String[], String[], String[]) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5609 [javac] ----------
5610 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5611 [javac] (at line 172)
5612 [javac] return new LibraryInfo("???", libs, dirs, endDirs); //$NON-NLS-1$
5613 [javac] ^^^^^^^^^^^
5614 [javac] Discouraged access: The type LibraryInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5615 [javac] ----------
5616 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5617 [javac] (at line 181)
5618 [javac] setDefaultRootPath("src");//$NON-NLS-1$
5619 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
5620 [javac] Discouraged access: The method setDefaultRootPath(String) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5621 [javac] ----------
5622 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5623 [javac] (at line 186)
5624 [javac] setDefaultRootPath(""); //$NON-NLS-1$
5625 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5626 [javac] Discouraged access: The method setDefaultRootPath(String) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5627 [javac] ----------
5628 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5629 [javac] (at line 191)
5630 [javac] setDefaultRootPath(""); //$NON-NLS-1$
5631 [javac] ^^^^^^^^^^^^^^^^^^^^^^
5632 [javac] Discouraged access: The method setDefaultRootPath(String) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5633 [javac] ----------
5634 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5635 [javac] (at line 240)
5636 [javac] return super.getDefaultJavadocLocation(installLocation);
5637 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5638 [javac] Discouraged access: The method getDefaultJavadocLocation(File) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5639 [javac] ----------
5640 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMInstallType.java
5641 [javac] (at line 247)
5642 [javac] return super.getVMVersion(javaHome, javaExecutable);
5643 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5644 [javac] Discouraged access: The method getVMVersion(File, File) from the type StandardVMType is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5645 [javac] ----------
5646 [javac] ----------
5647 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMRunner.java
5648 [javac] (at line 16)
5649 [javac] import org.eclipse.jdt.internal.launching.StandardVMRunner;
5650 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5651 [javac] Discouraged access: The type StandardVMRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5652 [javac] ----------
5653 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMRunner.java
5654 [javac] (at line 19)
5655 [javac] public class MacOSXVMRunner extends StandardVMRunner {
5656 [javac] ^^^^^^^^^^^^^^^^
5657 [javac] Discouraged access: The type StandardVMRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5658 [javac] ----------
5659 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching.macosx/macosx/org/eclipse/jdt/internal/launching/macosx/MacOSXVMRunner.java
5660 [javac] (at line 22)
5661 [javac] super(vmInstance);
5662 [javac] ^^^^^^^^^^^^^^^^^
5663 [javac] Discouraged access: The constructor StandardVMRunner(IVMInstall) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
5664 [javac] ----------
5665 [javac] 26 problems (26 warnings)
5666 [javac] ----------
5667 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5668 [javac] (at line 36)
5669 [javac] import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
5670 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5671 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5672 [javac] ----------
5673 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5674 [javac] (at line 282)
5675 [javac] StatusInfo status= new StatusInfo();
5676 [javac] ^^^^^^^^^^
5677 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5678 [javac] ----------
5679 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5680 [javac] (at line 282)
5681 [javac] StatusInfo status= new StatusInfo();
5682 [javac] ^^^^^^^^^^^^^^^^
5683 [javac] Discouraged access: The constructor StatusInfo() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5684 [javac] ----------
5685 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5686 [javac] (at line 282)
5687 [javac] StatusInfo status= new StatusInfo();
5688 [javac] ^^^^^^^^^^
5689 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5690 [javac] ----------
5691 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5692 [javac] (at line 285)
5693 [javac] status.setError(DebugUIMessages.DetailFormatterDialog_Qualified_type_name_must_not_be_empty__3);
5694 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5695 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5696 [javac] ----------
5697 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5698 [javac] (at line 287)
5699 [javac] status.setError(DebugUIMessages.DetailFormatterDialog_A_detail_formatter_is_already_defined_for_this_type_2);
5700 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5701 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5702 [javac] ----------
5703 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5704 [javac] (at line 289)
5705 [javac] status.setError(DebugUIMessages.DetailFormatterDialog_Associated_code_must_not_be_empty_3);
5706 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5707 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5708 [javac] ----------
5709 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/DetailFormatterDialog.java
5710 [javac] (at line 291)
5711 [javac] status.setWarning(DebugUIMessages.No_type_with_the_given_name_found_in_the_workspace__1);
5712 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5713 [javac] Discouraged access: The method setWarning(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5714 [javac] ----------
5715 [javac] ----------
5716 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5717 [javac] (at line 38)
5718 [javac] import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
5719 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5720 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5721 [javac] ----------
5722 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5723 [javac] (at line 667)
5724 [javac] StatusInfo status= new StatusInfo();
5725 [javac] ^^^^^^^^^^
5726 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5727 [javac] ----------
5728 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5729 [javac] (at line 667)
5730 [javac] StatusInfo status= new StatusInfo();
5731 [javac] ^^^^^^^^^^^^^^^^
5732 [javac] Discouraged access: The constructor StatusInfo() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5733 [javac] ----------
5734 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5735 [javac] (at line 667)
5736 [javac] StatusInfo status= new StatusInfo();
5737 [javac] ^^^^^^^^^^
5738 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5739 [javac] ----------
5740 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5741 [javac] (at line 669)
5742 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_16);
5743 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5744 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5745 [javac] ----------
5746 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5747 [javac] (at line 671)
5748 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_17);
5749 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5750 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5751 [javac] ----------
5752 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5753 [javac] (at line 673)
5754 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_18);
5755 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5756 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5757 [javac] ----------
5758 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5759 [javac] (at line 678)
5760 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_19);
5761 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5762 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5763 [javac] ----------
5764 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5765 [javac] (at line 680)
5766 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_20);
5767 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5768 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5769 [javac] ----------
5770 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5771 [javac] (at line 682)
5772 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_21);
5773 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5774 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5775 [javac] ----------
5776 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5777 [javac] (at line 687)
5778 [javac] status.setError(DebugUIMessages.EditLogicalStructureDialog_22);
5779 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5780 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5781 [javac] ----------
5782 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5783 [javac] (at line 692)
5784 [javac] status.setError(MessageFormat.format(DebugUIMessages.EditLogicalStructureDialog_23, new String[] {variable[0]}));
5785 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5786 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5787 [javac] ----------
5788 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5789 [javac] (at line 699)
5790 [javac] if (!status.isError()) {
5791 [javac] ^^^^^^^^^^^^^^^^
5792 [javac] Discouraged access: The method isError() from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5793 [javac] ----------
5794 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EditLogicalStructureDialog.java
5795 [javac] (at line 701)
5796 [javac] status.setWarning(DebugUIMessages.EditLogicalStructureDialog_24);
5797 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5798 [javac] Discouraged access: The method setWarning(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5799 [javac] ----------
5800 [javac] ----------
5801 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5802 [javac] (at line 19)
5803 [javac] import org.eclipse.debug.internal.ui.contexts.DebugContextManager;
5804 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5805 [javac] Discouraged access: The type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5806 [javac] ----------
5807 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5808 [javac] (at line 20)
5809 [javac] import org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener;
5810 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5811 [javac] Discouraged access: The type IDebugContextListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5812 [javac] ----------
5813 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5814 [javac] (at line 39)
5815 [javac] public class EvaluationContextManager implements IWindowListener, IDebugContextListener {
5816 [javac] ^^^^^^^^^^^^^^^^^^^^^
5817 [javac] Discouraged access: The type IDebugContextListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5818 [javac] ----------
5819 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5820 [javac] (at line 59)
5821 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
5822 [javac] ^^^^^^^^^^^^^^^^^^^
5823 [javac] Discouraged access: The type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5824 [javac] ----------
5825 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5826 [javac] (at line 59)
5827 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
5828 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5829 [javac] Discouraged access: The method getDefault() from the type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5830 [javac] ----------
5831 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/EvaluationContextManager.java
5832 [javac] (at line 59)
5833 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
5834 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5835 [javac] Discouraged access: The method addDebugContextListener(IDebugContextListener) from the type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5836 [javac] ----------
5837 [javac] ----------
5838 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5839 [javac] (at line 73)
5840 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
5841 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5842 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5843 [javac] ----------
5844 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5845 [javac] (at line 74)
5846 [javac] import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
5847 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5848 [javac] Discouraged access: The type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5849 [javac] ----------
5850 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5851 [javac] (at line 75)
5852 [javac] import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
5853 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5854 [javac] Discouraged access: The type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5855 [javac] ----------
5856 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5857 [javac] (at line 115)
5858 [javac] private ImageDescriptorRegistry fJavaElementImageRegistry;
5859 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
5860 [javac] Discouraged access: The type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5861 [javac] ----------
5862 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5863 [javac] (at line 861)
5864 [javac] return getJavaElementImageRegistry().get(descriptor);
5865 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5866 [javac] Discouraged access: The method get(ImageDescriptor) from the type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5867 [javac] ----------
5868 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5869 [javac] (at line 1062)
5870 [javac] return EditorUtility.getEditorInput(item);
5871 [javac] ^^^^^^^^^^^^^
5872 [javac] Discouraged access: The type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5873 [javac] ----------
5874 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5875 [javac] (at line 1062)
5876 [javac] return EditorUtility.getEditorInput(item);
5877 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5878 [javac] Discouraged access: The method getEditorInput(Object) from the type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5879 [javac] ----------
5880 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5881 [javac] (at line 1877)
5882 [javac] protected ImageDescriptorRegistry getJavaElementImageRegistry() {
5883 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
5884 [javac] Discouraged access: The type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5885 [javac] ----------
5886 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5887 [javac] (at line 1879)
5888 [javac] fJavaElementImageRegistry = JavaPlugin.getImageDescriptorRegistry();
5889 [javac] ^^^^^^^^^^
5890 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5891 [javac] ----------
5892 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIModelPresentation.java
5893 [javac] (at line 1879)
5894 [javac] fJavaElementImageRegistry = JavaPlugin.getImageDescriptorRegistry();
5895 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5896 [javac] Discouraged access: The method getImageDescriptorRegistry() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5897 [javac] ----------
5898 [javac] ----------
5899 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaDebugHover.java
5900 [javac] (at line 38)
5901 [javac] import org.eclipse.jdt.internal.ui.text.HTMLTextPresenter;
5902 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5903 [javac] Discouraged access: The type HTMLTextPresenter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5904 [javac] ----------
5905 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaDebugHover.java
5906 [javac] (at line 359)
5907 [javac] new HTMLTextPresenter(true),
5908 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5909 [javac] Discouraged access: The constructor HTMLTextPresenter(boolean) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5910 [javac] ----------
5911 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaDebugHover.java
5912 [javac] (at line 359)
5913 [javac] new HTMLTextPresenter(true),
5914 [javac] ^^^^^^^^^^^^^^^^^
5915 [javac] Discouraged access: The type HTMLTextPresenter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
5916 [javac] ----------
5917 [javac] ----------
5918 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaStepFilterPreferencePage.java
5919 [javac] (at line 15)
5920 [javac] import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
5921 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5922 [javac] Discouraged access: The type IInternalDebugUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5923 [javac] ----------
5924 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaStepFilterPreferencePage.java
5925 [javac] (at line 473)
5926 [javac] boolean stepenabled = getPreferenceStore().getDefaultBoolean(IInternalDebugUIConstants.PREF_USE_STEP_FILTERS/*IDebugUIConstants.PREF_USE_STEP_FILTERS*/);
5927 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5928 [javac] Discouraged access: The type IInternalDebugUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5929 [javac] ----------
5930 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JavaStepFilterPreferencePage.java
5931 [javac] (at line 473)
5932 [javac] boolean stepenabled = getPreferenceStore().getDefaultBoolean(IInternalDebugUIConstants.PREF_USE_STEP_FILTERS/*IDebugUIConstants.PREF_USE_STEP_FILTERS*/);
5933 [javac] ^^^^^^^^^^^^^^^^^^^^^
5934 [javac] Discouraged access: The field PREF_USE_STEP_FILTERS from the type IInternalDebugUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5935 [javac] ----------
5936 [javac] ----------
5937 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/TypeNameResolver.java
5938 [javac] (at line 16)
5939 [javac] import org.eclipse.debug.internal.ui.stringsubstitution.ResourceResolver;
5940 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5941 [javac] Discouraged access: The type ResourceResolver is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5942 [javac] ----------
5943 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/TypeNameResolver.java
5944 [javac] (at line 28)
5945 [javac] public class TypeNameResolver extends ResourceResolver {
5946 [javac] ^^^^^^^^^^^^^^^^
5947 [javac] Discouraged access: The type ResourceResolver is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5948 [javac] ----------
5949 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/TypeNameResolver.java
5950 [javac] (at line 33)
5951 [javac] IResource resource = getSelectedResource(variable);
5952 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5953 [javac] Discouraged access: The method getSelectedResource(IDynamicVariable) from the type ResourceResolver is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5954 [javac] ----------
5955 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/TypeNameResolver.java
5956 [javac] (at line 41)
5957 [javac] abort(DebugUIMessages.TypeNameResolver_0, null);
5958 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959 [javac] Discouraged access: The method abort(String, Throwable) from the type ResourceResolver is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5960 [javac] ----------
5961 [javac] ----------
5962 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5963 [javac] (at line 27)
5964 [javac] import org.eclipse.debug.internal.ui.DebugUIPlugin;
5965 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5966 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5967 [javac] ----------
5968 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5969 [javac] (at line 147)
5970 [javac] IStatus status = DebugUIPlugin.newErrorStatus(cause.getMessage(), null);
5971 [javac] ^^^^^^^^^^^^^
5972 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5973 [javac] ----------
5974 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5975 [javac] (at line 147)
5976 [javac] IStatus status = DebugUIPlugin.newErrorStatus(cause.getMessage(), null);
5977 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5978 [javac] Discouraged access: The method newErrorStatus(String, Throwable) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5979 [javac] ----------
5980 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5981 [javac] (at line 150)
5982 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaObjectValueEditor_0, ActionMessages.JavaObjectValueEditor_1, e); //
5983 [javac] ^^^^^^^^^^^^^
5984 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5985 [javac] ----------
5986 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5987 [javac] (at line 150)
5988 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaObjectValueEditor_0, ActionMessages.JavaObjectValueEditor_1, e); //
5989 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5990 [javac] Discouraged access: The method errorDialog(Shell, String, String, Throwable) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5991 [javac] ----------
5992 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5993 [javac] (at line 215)
5994 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaObjectValueEditor_2,
5995 [javac] ^^^^^^^^^^^^^
5996 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
5997 [javac] ----------
5998 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaObjectValueEditor.java
5999 [javac] (at line 215)
6000 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaObjectValueEditor_2,
6001 [javac] ActionMessages.JavaObjectValueEditor_3, status);
6002 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6003 [javac] Discouraged access: The method errorDialog(Shell, String, String, IStatus) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6004 [javac] ----------
6005 [javac] ----------
6006 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java
6007 [javac] (at line 17)
6008 [javac] import org.eclipse.debug.internal.ui.DebugUIPlugin;
6009 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6010 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6011 [javac] ----------
6012 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java
6013 [javac] (at line 69)
6014 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaPrimitiveValueEditor_2, ActionMessages.JavaPrimitiveValueEditor_3, e); //
6015 [javac] ^^^^^^^^^^^^^
6016 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6017 [javac] ----------
6018 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaPrimitiveValueEditor.java
6019 [javac] (at line 69)
6020 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaPrimitiveValueEditor_2, ActionMessages.JavaPrimitiveValueEditor_3, e); //
6021 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6022 [javac] Discouraged access: The method errorDialog(Shell, String, String, Throwable) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6023 [javac] ----------
6024 [javac] ----------
6025 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
6026 [javac] (at line 15)
6027 [javac] import org.eclipse.debug.internal.ui.DebugUIPlugin;
6028 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6029 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6030 [javac] ----------
6031 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
6032 [javac] (at line 34)
6033 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
6034 [javac] ^^^^^^^^^^^^^
6035 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6036 [javac] ----------
6037 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
6038 [javac] (at line 34)
6039 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
6040 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6041 [javac] Discouraged access: The method errorDialog(Shell, String, String, Throwable) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6042 [javac] ----------
6043 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
6044 [javac] (at line 59)
6045 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
6046 [javac] ^^^^^^^^^^^^^
6047 [javac] Discouraged access: The type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6048 [javac] ----------
6049 [javac] 63. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/JavaVariableValueEditor.java
6050 [javac] (at line 59)
6051 [javac] DebugUIPlugin.errorDialog(shell, ActionMessages.JavaVariableValueEditor_0, ActionMessages.JavaVariableValueEditor_1, e); //
6052 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6053 [javac] Discouraged access: The method errorDialog(Shell, String, String, Throwable) from the type DebugUIPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6054 [javac] ----------
6055 [javac] ----------
6056 [javac] 64. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6057 [javac] (at line 35)
6058 [javac] import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
6059 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060 [javac] Discouraged access: The type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6061 [javac] ----------
6062 [javac] 65. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6063 [javac] (at line 36)
6064 [javac] import org.eclipse.jdt.internal.ui.util.OpenTypeHierarchyUtil;
6065 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6066 [javac] Discouraged access: The type OpenTypeHierarchyUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6067 [javac] ----------
6068 [javac] 66. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6069 [javac] (at line 110)
6070 [javac] OpenTypeHierarchyUtil.open((IJavaElement)sourceElement, getWorkbenchWindow());
6071 [javac] ^^^^^^^^^^^^^^^^^^^^^
6072 [javac] Discouraged access: The type OpenTypeHierarchyUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6073 [javac] ----------
6074 [javac] 67. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6075 [javac] (at line 110)
6076 [javac] OpenTypeHierarchyUtil.open((IJavaElement)sourceElement, getWorkbenchWindow());
6077 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6078 [javac] Discouraged access: The method open(IJavaElement, IWorkbenchWindow) from the type OpenTypeHierarchyUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6079 [javac] ----------
6080 [javac] 68. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6081 [javac] (at line 115)
6082 [javac] IEditorPart part= EditorUtility.openInEditor(sourceElement);
6083 [javac] ^^^^^^^^^^^^^
6084 [javac] Discouraged access: The type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6085 [javac] ----------
6086 [javac] 69. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6087 [javac] (at line 115)
6088 [javac] IEditorPart part= EditorUtility.openInEditor(sourceElement);
6089 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6090 [javac] Discouraged access: The method openInEditor(Object) from the type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6091 [javac] ----------
6092 [javac] 70. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6093 [javac] (at line 117)
6094 [javac] EditorUtility.revealInEditor(part, ((IJavaElement)sourceElement));
6095 [javac] ^^^^^^^^^^^^^
6096 [javac] Discouraged access: The type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6097 [javac] ----------
6098 [javac] 71. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/OpenTypeAction.java
6099 [javac] (at line 117)
6100 [javac] EditorUtility.revealInEditor(part, ((IJavaElement)sourceElement));
6101 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6102 [javac] Discouraged access: The method revealInEditor(IEditorPart, IJavaElement) from the type EditorUtility is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6103 [javac] ----------
6104 [javac] ----------
6105 [javac] 72. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupDisplayAction.java
6106 [javac] (at line 17)
6107 [javac] import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
6108 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6109 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6110 [javac] ----------
6111 [javac] 73. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupDisplayAction.java
6112 [javac] (at line 94)
6113 [javac] if (part instanceof JavaEditor) {
6114 [javac] ^^^^^^^^^^
6115 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6116 [javac] ----------
6117 [javac] 74. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupDisplayAction.java
6118 [javac] (at line 95)
6119 [javac] viewer = ((JavaEditor)part).getViewer();
6120 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6121 [javac] Discouraged access: The method getViewer() from the type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6122 [javac] ----------
6123 [javac] 75. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupDisplayAction.java
6124 [javac] (at line 95)
6125 [javac] viewer = ((JavaEditor)part).getViewer();
6126 [javac] ^^^^^^^^^^
6127 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6128 [javac] ----------
6129 [javac] ----------
6130 [javac] 76. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupInspectAction.java
6131 [javac] (at line 18)
6132 [javac] import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
6133 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6134 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6135 [javac] ----------
6136 [javac] 77. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupInspectAction.java
6137 [javac] (at line 37)
6138 [javac] if (part instanceof JavaEditor) {
6139 [javac] ^^^^^^^^^^
6140 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6141 [javac] ----------
6142 [javac] 78. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupInspectAction.java
6143 [javac] (at line 38)
6144 [javac] viewer = ((JavaEditor) part).getViewer();
6145 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6146 [javac] Discouraged access: The method getViewer() from the type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6147 [javac] ----------
6148 [javac] 79. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/PopupInspectAction.java
6149 [javac] (at line 38)
6150 [javac] viewer = ((JavaEditor) part).getViewer();
6151 [javac] ^^^^^^^^^^
6152 [javac] Discouraged access: The type JavaEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6153 [javac] ----------
6154 [javac] ----------
6155 [javac] 80. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ShowStratumAction.java
6156 [javac] (at line 17)
6157 [javac] import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager;
6158 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6159 [javac] Discouraged access: The type SourceLookupManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6160 [javac] ----------
6161 [javac] 81. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ShowStratumAction.java
6162 [javac] (at line 136)
6163 [javac] SourceLookupManager.getDefault().displaySource(frame, fPart.getSite().getPage(), true);
6164 [javac] ^^^^^^^^^^^^^^^^^^^
6165 [javac] Discouraged access: The type SourceLookupManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6166 [javac] ----------
6167 [javac] 82. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ShowStratumAction.java
6168 [javac] (at line 136)
6169 [javac] SourceLookupManager.getDefault().displaySource(frame, fPart.getSite().getPage(), true);
6170 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6171 [javac] Discouraged access: The method getDefault() from the type SourceLookupManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6172 [javac] ----------
6173 [javac] 83. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ShowStratumAction.java
6174 [javac] (at line 136)
6175 [javac] SourceLookupManager.getDefault().displaySource(frame, fPart.getSite().getPage(), true);
6176 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6177 [javac] Discouraged access: The method displaySource(Object, IWorkbenchPage, boolean) from the type SourceLookupManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6178 [javac] ----------
6179 [javac] ----------
6180 [javac] 84. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6181 [javac] (at line 20)
6182 [javac] import org.eclipse.debug.internal.ui.contexts.DebugContextManager;
6183 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6184 [javac] Discouraged access: The type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6185 [javac] ----------
6186 [javac] 85. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6187 [javac] (at line 21)
6188 [javac] import org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener;
6189 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6190 [javac] Discouraged access: The type IDebugContextListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6191 [javac] ----------
6192 [javac] 86. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6193 [javac] (at line 22)
6194 [javac] import org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextManager;
6195 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6196 [javac] Discouraged access: The type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6197 [javac] ----------
6198 [javac] 87. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6199 [javac] (at line 43)
6200 [javac] public class ExceptionInspector implements IDebugContextListener, IPropertyChangeListener {
6201 [javac] ^^^^^^^^^^^^^^^^^^^^^
6202 [javac] Discouraged access: The type IDebugContextListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6203 [javac] ----------
6204 [javac] 88. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6205 [javac] (at line 49)
6206 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
6207 [javac] ^^^^^^^^^^^^^^^^^^^
6208 [javac] Discouraged access: The type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6209 [javac] ----------
6210 [javac] 89. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6211 [javac] (at line 49)
6212 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
6213 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6214 [javac] Discouraged access: The method getDefault() from the type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6215 [javac] ----------
6216 [javac] 90. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6217 [javac] (at line 49)
6218 [javac] DebugContextManager.getDefault().addDebugContextListener(this);
6219 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6220 [javac] Discouraged access: The method addDebugContextListener(IDebugContextListener) from the type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6221 [javac] ----------
6222 [javac] 91. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6223 [javac] (at line 109)
6224 [javac] IDebugContextManager manager = DebugContextManager.getDefault();
6225 [javac] ^^^^^^^^^^^^^^^^^^^^
6226 [javac] Discouraged access: The type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6227 [javac] ----------
6228 [javac] 92. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6229 [javac] (at line 109)
6230 [javac] IDebugContextManager manager = DebugContextManager.getDefault();
6231 [javac] ^^^^^^^^^^^^^^^^^^^
6232 [javac] Discouraged access: The type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6233 [javac] ----------
6234 [javac] 93. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6235 [javac] (at line 109)
6236 [javac] IDebugContextManager manager = DebugContextManager.getDefault();
6237 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6238 [javac] Discouraged access: The method getDefault() from the type DebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6239 [javac] ----------
6240 [javac] 94. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6241 [javac] (at line 111)
6242 [javac] manager.addDebugContextListener(this);
6243 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6244 [javac] Discouraged access: The method addDebugContextListener(IDebugContextListener) from the type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6245 [javac] ----------
6246 [javac] 95. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/breakpoints/ExceptionInspector.java
6247 [javac] (at line 113)
6248 [javac] manager.removeDebugContextListener(this);
6249 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6250 [javac] Discouraged access: The method removeDebugContextListener(IDebugContextListener) from the type IDebugContextManager is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6251 [javac] ----------
6252 [javac] ----------
6253 [javac] 96. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6254 [javac] (at line 19)
6255 [javac] import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
6256 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6257 [javac] Discouraged access: The type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6258 [javac] ----------
6259 [javac] 97. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6260 [javac] (at line 41)
6261 [javac] if (property.equals(IDebugPreferenceConstants.CONSOLE_FONT)) {
6262 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6263 [javac] Discouraged access: The type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6264 [javac] ----------
6265 [javac] 98. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6266 [javac] (at line 41)
6267 [javac] if (property.equals(IDebugPreferenceConstants.CONSOLE_FONT)) {
6268 [javac] ^^^^^^^^^^^^
6269 [javac] Discouraged access: The field CONSOLE_FONT from the type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6270 [javac] ----------
6271 [javac] 99. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6272 [javac] (at line 42)
6273 [javac] setFont(JFaceResources.getFont(IDebugPreferenceConstants.CONSOLE_FONT));
6274 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6275 [javac] Discouraged access: The type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6276 [javac] ----------
6277 [javac] 100. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6278 [javac] (at line 42)
6279 [javac] setFont(JFaceResources.getFont(IDebugPreferenceConstants.CONSOLE_FONT));
6280 [javac] ^^^^^^^^^^^^
6281 [javac] Discouraged access: The field CONSOLE_FONT from the type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6282 [javac] ----------
6283 [javac] 101. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6284 [javac] (at line 49)
6285 [javac] Font font = JFaceResources.getFont(IDebugPreferenceConstants.CONSOLE_FONT);
6286 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6287 [javac] Discouraged access: The type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6288 [javac] ----------
6289 [javac] 102. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceConsole.java
6290 [javac] (at line 49)
6291 [javac] Font font = JFaceResources.getFont(IDebugPreferenceConstants.CONSOLE_FONT);
6292 [javac] ^^^^^^^^^^^^
6293 [javac] Discouraged access: The field CONSOLE_FONT from the type IDebugPreferenceConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6294 [javac] ----------
6295 [javac] ----------
6296 [javac] 103. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6297 [javac] (at line 18)
6298 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
6299 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6300 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6301 [javac] ----------
6302 [javac] 104. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6303 [javac] (at line 19)
6304 [javac] import org.eclipse.jdt.internal.ui.text.java.JavaParameterListValidator;
6305 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6306 [javac] Discouraged access: The type JavaParameterListValidator is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6307 [javac] ----------
6308 [javac] 105. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6309 [javac] (at line 20)
6310 [javac] import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateEngine;
6311 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6312 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6313 [javac] ----------
6314 [javac] 106. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6315 [javac] (at line 41)
6316 [javac] private TemplateEngine fTemplateEngine;
6317 [javac] ^^^^^^^^^^^^^^
6318 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6319 [javac] ----------
6320 [javac] 107. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6321 [javac] (at line 50)
6322 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
6323 [javac] ^^^^^^^^^^
6324 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6325 [javac] ----------
6326 [javac] 108. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6327 [javac] (at line 50)
6328 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
6329 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6330 [javac] Discouraged access: The method getDefault() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6331 [javac] ----------
6332 [javac] 109. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6333 [javac] (at line 50)
6334 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
6335 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6336 [javac] Discouraged access: The method getTemplateContextRegistry() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6337 [javac] ----------
6338 [javac] 110. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6339 [javac] (at line 52)
6340 [javac] fTemplateEngine= new TemplateEngine(contextType);
6341 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6342 [javac] Discouraged access: The constructor TemplateEngine(TemplateContextType) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6343 [javac] ----------
6344 [javac] 111. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6345 [javac] (at line 52)
6346 [javac] fTemplateEngine= new TemplateEngine(contextType);
6347 [javac] ^^^^^^^^^^^^^^
6348 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6349 [javac] ----------
6350 [javac] 112. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6351 [javac] (at line 88)
6352 [javac] fValidator= new JavaParameterListValidator();
6353 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6354 [javac] Discouraged access: The constructor JavaParameterListValidator() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6355 [javac] ----------
6356 [javac] 113. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6357 [javac] (at line 88)
6358 [javac] fValidator= new JavaParameterListValidator();
6359 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
6360 [javac] Discouraged access: The type JavaParameterListValidator is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6361 [javac] ----------
6362 [javac] 114. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6363 [javac] (at line 143)
6364 [javac] fTemplateEngine.reset();
6365 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6366 [javac] Discouraged access: The method reset() from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6367 [javac] ----------
6368 [javac] 115. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6369 [javac] (at line 144)
6370 [javac] fTemplateEngine.complete(viewer, documentOffset, null);
6371 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6372 [javac] Discouraged access: The method complete(ITextViewer, int, ICompilationUnit) from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6373 [javac] ----------
6374 [javac] 116. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/contentassist/JavaDebugContentAssistProcessor.java
6375 [javac] (at line 145)
6376 [javac] IJavaCompletionProposal[] templateResults= fTemplateEngine.getResults();
6377 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6378 [javac] Discouraged access: The method getResults() from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6379 [javac] ----------
6380 [javac] ----------
6381 [javac] 117. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6382 [javac] (at line 27)
6383 [javac] import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
6384 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6385 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6386 [javac] ----------
6387 [javac] 118. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6388 [javac] (at line 28)
6389 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
6390 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6391 [javac] Discouraged access: The type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6392 [javac] ----------
6393 [javac] 119. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6394 [javac] (at line 29)
6395 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
6396 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6397 [javac] Discouraged access: The type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6398 [javac] ----------
6399 [javac] 120. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6400 [javac] (at line 30)
6401 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
6402 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6403 [javac] Discouraged access: The type IDialogFieldListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6404 [javac] ----------
6405 [javac] 121. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6406 [javac] (at line 31)
6407 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
6408 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6409 [javac] Discouraged access: The type IStringButtonAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6410 [javac] ----------
6411 [javac] 122. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6412 [javac] (at line 32)
6413 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
6414 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6415 [javac] Discouraged access: The type StringButtonDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6416 [javac] ----------
6417 [javac] 123. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6418 [javac] (at line 33)
6419 [javac] import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
6420 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6421 [javac] Discouraged access: The type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6422 [javac] ----------
6423 [javac] 124. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6424 [javac] (at line 64)
6425 [javac] private ComboDialogField fVMTypeCombo;
6426 [javac] ^^^^^^^^^^^^^^^^
6427 [javac] Discouraged access: The type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6428 [javac] ----------
6429 [javac] 125. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6430 [javac] (at line 67)
6431 [javac] private StringButtonDialogField fJRERoot;
6432 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6433 [javac] Discouraged access: The type StringButtonDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6434 [javac] ----------
6435 [javac] 126. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6436 [javac] (at line 68)
6437 [javac] private StringDialogField fVMName;
6438 [javac] ^^^^^^^^^^^^^^^^^
6439 [javac] Discouraged access: The type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6440 [javac] ----------
6441 [javac] 127. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6442 [javac] (at line 70)
6443 [javac] private StringDialogField fVMArgs;
6444 [javac] ^^^^^^^^^^^^^^^^^
6445 [javac] Discouraged access: The type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6446 [javac] ----------
6447 [javac] 128. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6448 [javac] (at line 85)
6449 [javac] fStati[i]= new StatusInfo();
6450 [javac] ^^^^^^^^^^^^^^^^
6451 [javac] Discouraged access: The constructor StatusInfo() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6452 [javac] ----------
6453 [javac] 129. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6454 [javac] (at line 85)
6455 [javac] fStati[i]= new StatusInfo();
6456 [javac] ^^^^^^^^^^
6457 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6458 [javac] ----------
6459 [javac] 130. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6460 [javac] (at line 106)
6461 [javac] fVMTypeCombo= new ComboDialogField(SWT.READ_ONLY);
6462 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6463 [javac] Discouraged access: The constructor ComboDialogField(int) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6464 [javac] ----------
6465 [javac] 131. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6466 [javac] (at line 106)
6467 [javac] fVMTypeCombo= new ComboDialogField(SWT.READ_ONLY);
6468 [javac] ^^^^^^^^^^^^^^^^
6469 [javac] Discouraged access: The type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6470 [javac] ----------
6471 [javac] 132. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6472 [javac] (at line 107)
6473 [javac] fVMTypeCombo.setLabelText(JREMessages.addVMDialog_jreType);
6474 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6475 [javac] Discouraged access: The method setLabelText(String) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6476 [javac] ----------
6477 [javac] 133. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6478 [javac] (at line 108)
6479 [javac] fVMTypeCombo.setItems(getVMTypeNames());
6480 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6481 [javac] Discouraged access: The method setItems(String[]) from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6482 [javac] ----------
6483 [javac] 134. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6484 [javac] (at line 110)
6485 [javac] fVMName= new StringDialogField();
6486 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6487 [javac] Discouraged access: The constructor StringDialogField() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6488 [javac] ----------
6489 [javac] 135. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6490 [javac] (at line 110)
6491 [javac] fVMName= new StringDialogField();
6492 [javac] ^^^^^^^^^^^^^^^^^
6493 [javac] Discouraged access: The type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6494 [javac] ----------
6495 [javac] 136. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6496 [javac] (at line 111)
6497 [javac] fVMName.setLabelText(JREMessages.addVMDialog_jreName);
6498 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6499 [javac] Discouraged access: The method setLabelText(String) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6500 [javac] ----------
6501 [javac] 137. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6502 [javac] (at line 113)
6503 [javac] fJRERoot= new StringButtonDialogField(new IStringButtonAdapter() {
6504 [javac] public void changeControlPressed(DialogField field) {
6505 [javac] browseForInstallDir();
6506 [javac] }
6507 [javac] });
6508 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6509 [javac] Discouraged access: The constructor StringButtonDialogField(IStringButtonAdapter) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6510 [javac] ----------
6511 [javac] 138. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6512 [javac] (at line 113)
6513 [javac] fJRERoot= new StringButtonDialogField(new IStringButtonAdapter() {
6514 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6515 [javac] Discouraged access: The type StringButtonDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6516 [javac] ----------
6517 [javac] 139. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6518 [javac] (at line 113)
6519 [javac] fJRERoot= new StringButtonDialogField(new IStringButtonAdapter() {
6520 [javac] ^^^^^^^^^^^^^^^^^^^^
6521 [javac] Discouraged access: The type IStringButtonAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6522 [javac] ----------
6523 [javac] 140. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6524 [javac] (at line 114)
6525 [javac] public void changeControlPressed(DialogField field) {
6526 [javac] ^^^^^^^^^^^
6527 [javac] Discouraged access: The type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6528 [javac] ----------
6529 [javac] 141. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6530 [javac] (at line 118)
6531 [javac] fJRERoot.setLabelText(JREMessages.addVMDialog_jreHome);
6532 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6533 [javac] Discouraged access: The method setLabelText(String) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6534 [javac] ----------
6535 [javac] 142. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6536 [javac] (at line 119)
6537 [javac] fJRERoot.setButtonLabel(JREMessages.addVMDialog_browse1);
6538 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6539 [javac] Discouraged access: The method setButtonLabel(String) from the type StringButtonDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6540 [javac] ----------
6541 [javac] 143. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6542 [javac] (at line 121)
6543 [javac] fVMArgs= new StringDialogField();
6544 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6545 [javac] Discouraged access: The constructor StringDialogField() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6546 [javac] ----------
6547 [javac] 144. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6548 [javac] (at line 121)
6549 [javac] fVMArgs= new StringDialogField();
6550 [javac] ^^^^^^^^^^^^^^^^^
6551 [javac] Discouraged access: The type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6552 [javac] ----------
6553 [javac] 145. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6554 [javac] (at line 122)
6555 [javac] fVMArgs.setLabelText(JREMessages.AddVMDialog_23);
6556 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6557 [javac] Discouraged access: The method setLabelText(String) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6558 [javac] ----------
6559 [javac] 146. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6560 [javac] (at line 126)
6561 [javac] fVMTypeCombo.setDialogFieldListener(new IDialogFieldListener() {
6562 [javac] public void dialogFieldChanged(DialogField field) {
6563 [javac] updateVMType();
6564 [javac] }
6565 [javac] });
6566 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6567 [javac] Discouraged access: The method setDialogFieldListener(IDialogFieldListener) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6568 [javac] ----------
6569 [javac] 147. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6570 [javac] (at line 126)
6571 [javac] fVMTypeCombo.setDialogFieldListener(new IDialogFieldListener() {
6572 [javac] ^^^^^^^^^^^^^^^^^^^^
6573 [javac] Discouraged access: The type IDialogFieldListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6574 [javac] ----------
6575 [javac] 148. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6576 [javac] (at line 127)
6577 [javac] public void dialogFieldChanged(DialogField field) {
6578 [javac] ^^^^^^^^^^^
6579 [javac] Discouraged access: The type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6580 [javac] ----------
6581 [javac] 149. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6582 [javac] (at line 132)
6583 [javac] fVMName.setDialogFieldListener(new IDialogFieldListener() {
6584 [javac] public void dialogFieldChanged(DialogField field) {
6585 [javac] setVMNameStatus(validateVMName());
6586 [javac] updateStatusLine();
6587 [javac] }
6588 [javac] });
6589 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6590 [javac] Discouraged access: The method setDialogFieldListener(IDialogFieldListener) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6591 [javac] ----------
6592 [javac] 150. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6593 [javac] (at line 132)
6594 [javac] fVMName.setDialogFieldListener(new IDialogFieldListener() {
6595 [javac] ^^^^^^^^^^^^^^^^^^^^
6596 [javac] Discouraged access: The type IDialogFieldListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6597 [javac] ----------
6598 [javac] 151. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6599 [javac] (at line 133)
6600 [javac] public void dialogFieldChanged(DialogField field) {
6601 [javac] ^^^^^^^^^^^
6602 [javac] Discouraged access: The type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6603 [javac] ----------
6604 [javac] 152. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6605 [javac] (at line 139)
6606 [javac] fJRERoot.setDialogFieldListener(new IDialogFieldListener() {
6607 [javac] public void dialogFieldChanged(DialogField field) {
6608 [javac] setJRELocationStatus(validateJRELocation());
6609 [javac] updateStatusLine();
6610 [javac] }
6611 [javac] });
6612 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6613 [javac] Discouraged access: The method setDialogFieldListener(IDialogFieldListener) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6614 [javac] ----------
6615 [javac] 153. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6616 [javac] (at line 139)
6617 [javac] fJRERoot.setDialogFieldListener(new IDialogFieldListener() {
6618 [javac] ^^^^^^^^^^^^^^^^^^^^
6619 [javac] Discouraged access: The type IDialogFieldListener is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6620 [javac] ----------
6621 [javac] 154. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6622 [javac] (at line 140)
6623 [javac] public void dialogFieldChanged(DialogField field) {
6624 [javac] ^^^^^^^^^^^
6625 [javac] Discouraged access: The type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6626 [javac] ----------
6627 [javac] 155. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6628 [javac] (at line 149)
6629 [javac] return fVMName.getText();
6630 [javac] ^^^^^^^^^^^^^^^^^
6631 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6632 [javac] ----------
6633 [javac] 156. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6634 [javac] (at line 153)
6635 [javac] return new File(fJRERoot.getText());
6636 [javac] ^^^^^^^^^^^^^^^^^^
6637 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6638 [javac] ----------
6639 [javac] 157. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6640 [javac] (at line 161)
6641 [javac] fVMTypeCombo.doFillIntoGrid(parent, 3);
6642 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6643 [javac] Discouraged access: The method doFillIntoGrid(Composite, int) from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6644 [javac] ----------
6645 [javac] 158. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6646 [javac] (at line 162)
6647 [javac] ((GridData)fVMTypeCombo.getComboControl(null).getLayoutData()).widthHint= convertWidthInCharsToPixels(50);
6648 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6649 [javac] Discouraged access: The method getComboControl(Composite) from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6650 [javac] ----------
6651 [javac] 159. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6652 [javac] (at line 164)
6653 [javac] fVMName.doFillIntoGrid(parent, 3);
6654 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6655 [javac] Discouraged access: The method doFillIntoGrid(Composite, int) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6656 [javac] ----------
6657 [javac] 160. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6658 [javac] (at line 166)
6659 [javac] fJRERoot.doFillIntoGrid(parent, 3);
6660 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6661 [javac] Discouraged access: The method doFillIntoGrid(Composite, int) from the type StringButtonDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6662 [javac] ----------
6663 [javac] 161. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6664 [javac] (at line 168)
6665 [javac] fVMArgs.doFillIntoGrid(parent, 3);
6666 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6667 [javac] Discouraged access: The method doFillIntoGrid(Composite, int) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6668 [javac] ----------
6669 [javac] 162. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6670 [javac] (at line 169)
6671 [javac] ((GridData)fVMArgs.getTextControl(null).getLayoutData()).widthHint= convertWidthInCharsToPixels(50);
6672 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6673 [javac] Discouraged access: The method getTextControl(Composite) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6674 [javac] ----------
6675 [javac] 163. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6676 [javac] (at line 183)
6677 [javac] Text t= fJRERoot.getTextControl(parent);
6678 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6679 [javac] Discouraged access: The method getTextControl(Composite) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6680 [javac] ----------
6681 [javac] 164. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6682 [javac] (at line 195)
6683 [javac] int selIndex= fVMTypeCombo.getSelectionIndex();
6684 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6685 [javac] Discouraged access: The method getSelectionIndex() from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6686 [javac] ----------
6687 [javac] 165. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6688 [javac] (at line 210)
6689 [javac] fVMName.setFocus();
6690 [javac] ^^^^^^^^^^^^^^^^^^
6691 [javac] Discouraged access: The method setFocus() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6692 [javac] ----------
6693 [javac] 166. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6694 [javac] (at line 225)
6695 [javac] fVMTypeCombo.selectItem(i);
6696 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
6697 [javac] Discouraged access: The method selectItem(int) from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6698 [javac] ----------
6699 [javac] 167. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6700 [javac] (at line 232)
6701 [javac] fVMTypeCombo.setItems(getVMTypeNames());
6702 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6703 [javac] Discouraged access: The method setItems(String[]) from the type ComboDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6704 [javac] ----------
6705 [javac] 168. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6706 [javac] (at line 234)
6707 [javac] fVMName.setText(""); //$NON-NLS-1$
6708 [javac] ^^^^^^^^^^^^^^^^^^^
6709 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6710 [javac] ----------
6711 [javac] 169. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6712 [javac] (at line 235)
6713 [javac] fJRERoot.setText(""); //$NON-NLS-1$
6714 [javac] ^^^^^^^^^^^^^^^^^^^^
6715 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6716 [javac] ----------
6717 [javac] 170. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6718 [javac] (at line 237)
6719 [javac] fVMArgs.setText(""); //$NON-NLS-1$
6720 [javac] ^^^^^^^^^^^^^^^^^^^
6721 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6722 [javac] ----------
6723 [javac] 171. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6724 [javac] (at line 239)
6725 [javac] fVMTypeCombo.setEnabled(false);
6726 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6727 [javac] Discouraged access: The method setEnabled(boolean) from the type DialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6728 [javac] ----------
6729 [javac] 172. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6730 [javac] (at line 240)
6731 [javac] fVMName.setText(fEditedVM.getName());
6732 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6733 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6734 [javac] ----------
6735 [javac] 173. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6736 [javac] (at line 241)
6737 [javac] fJRERoot.setText(fEditedVM.getInstallLocation().getAbsolutePath());
6738 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6739 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6740 [javac] ----------
6741 [javac] 174. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6742 [javac] (at line 247)
6743 [javac] fVMArgs.setText(vmArgs);
6744 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6745 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6746 [javac] ----------
6747 [javac] 175. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6748 [javac] (at line 260)
6749 [javac] fVMArgs.setText(buffer.toString());
6750 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6751 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6752 [javac] ----------
6753 [javac] 176. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6754 [javac] (at line 273)
6755 [javac] String locationName= fJRERoot.getText();
6756 [javac] ^^^^^^^^^^^^^^^^^^
6757 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6758 [javac] ----------
6759 [javac] 177. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6760 [javac] (at line 277)
6761 [javac] s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation);
6762 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6763 [javac] Discouraged access: The constructor StatusInfo(int, String) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6764 [javac] ----------
6765 [javac] 178. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6766 [javac] (at line 277)
6767 [javac] s = new StatusInfo(IStatus.INFO, JREMessages.addVMDialog_enterLocation);
6768 [javac] ^^^^^^^^^^
6769 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6770 [javac] ----------
6771 [javac] 179. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6772 [javac] (at line 281)
6773 [javac] s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists);
6774 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6775 [javac] Discouraged access: The constructor StatusInfo(int, String) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6776 [javac] ----------
6777 [javac] 180. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6778 [javac] (at line 281)
6779 [javac] s = new StatusInfo(IStatus.ERROR, JREMessages.addVMDialog_locationNotExists);
6780 [javac] ^^^^^^^^^^
6781 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6782 [javac] ----------
6783 [javac] 181. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6784 [javac] (at line 299)
6785 [javac] String name = fVMName.getText();
6786 [javac] ^^^^^^^^^^^^^^^^^
6787 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6788 [javac] ----------
6789 [javac] 182. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6790 [javac] (at line 317)
6791 [javac] fVMName.setText(genName);
6792 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
6793 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6794 [javac] ----------
6795 [javac] 183. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6796 [javac] (at line 344)
6797 [javac] StatusInfo status= new StatusInfo();
6798 [javac] ^^^^^^^^^^
6799 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6800 [javac] ----------
6801 [javac] 184. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6802 [javac] (at line 344)
6803 [javac] StatusInfo status= new StatusInfo();
6804 [javac] ^^^^^^^^^^^^^^^^
6805 [javac] Discouraged access: The constructor StatusInfo() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6806 [javac] ----------
6807 [javac] 185. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6808 [javac] (at line 344)
6809 [javac] StatusInfo status= new StatusInfo();
6810 [javac] ^^^^^^^^^^
6811 [javac] Discouraged access: The type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6812 [javac] ----------
6813 [javac] 186. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6814 [javac] (at line 345)
6815 [javac] String name= fVMName.getText();
6816 [javac] ^^^^^^^^^^^^^^^^^
6817 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6818 [javac] ----------
6819 [javac] 187. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6820 [javac] (at line 347)
6821 [javac] status.setInfo(JREMessages.addVMDialog_enterName);
6822 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6823 [javac] Discouraged access: The method setInfo(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6824 [javac] ----------
6825 [javac] 188. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6826 [javac] (at line 350)
6827 [javac] status.setError(JREMessages.addVMDialog_duplicateName);
6828 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6829 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6830 [javac] ----------
6831 [javac] 189. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6832 [javac] (at line 354)
6833 [javac] status.setError(MessageFormat.format(JREMessages.AddVMDialog_JRE_name_must_be_a_valid_file_name___0__1, new String[]{s.getMessage()}));
6834 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6835 [javac] Discouraged access: The method setError(String) from the type StatusInfo is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6836 [javac] ----------
6837 [javac] 190. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6838 [javac] (at line 378)
6839 [javac] dialog.setFilterPath(fJRERoot.getText());
6840 [javac] ^^^^^^^^^^^^^^^^^^
6841 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6842 [javac] ----------
6843 [javac] 191. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6844 [javac] (at line 382)
6845 [javac] fJRERoot.setText(newPath);
6846 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
6847 [javac] Discouraged access: The method setText(String) from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6848 [javac] ----------
6849 [javac] 192. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6850 [javac] (at line 414)
6851 [javac] File dir = new File(fJRERoot.getText());
6852 [javac] ^^^^^^^^^^^^^^^^^^
6853 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6854 [javac] ----------
6855 [javac] 193. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6856 [javac] (at line 420)
6857 [javac] vm.setName(fVMName.getText());
6858 [javac] ^^^^^^^^^^^^^^^^^
6859 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6860 [javac] ----------
6861 [javac] 194. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/AddVMDialog.java
6862 [javac] (at line 423)
6863 [javac] String argString = fVMArgs.getText().trim();
6864 [javac] ^^^^^^^^^^^^^^^^^
6865 [javac] Discouraged access: The method getText() from the type StringDialogField is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6866 [javac] ----------
6867 [javac] ----------
6868 [javac] 195. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/InstalledJREsBlock.java
6869 [javac] (at line 26)
6870 [javac] import org.eclipse.debug.internal.ui.SWTUtil;
6871 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6872 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6873 [javac] ----------
6874 [javac] 196. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/InstalledJREsBlock.java
6875 [javac] (at line 533)
6876 [javac] return SWTUtil.createPushButton(parent, label, null);
6877 [javac] ^^^^^^^
6878 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6879 [javac] ----------
6880 [javac] 197. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/InstalledJREsBlock.java
6881 [javac] (at line 533)
6882 [javac] return SWTUtil.createPushButton(parent, label, null);
6883 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6884 [javac] Discouraged access: The method createPushButton(Composite, String, Image) from the type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6885 [javac] ----------
6886 [javac] ----------
6887 [javac] 198. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java
6888 [javac] (at line 25)
6889 [javac] import org.eclipse.debug.internal.ui.SWTUtil;
6890 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6891 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6892 [javac] ----------
6893 [javac] 199. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java
6894 [javac] (at line 332)
6895 [javac] return SWTUtil.createPushButton(parent, label, null);
6896 [javac] ^^^^^^^
6897 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6898 [javac] ----------
6899 [javac] 200. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/JREsComboBlock.java
6900 [javac] (at line 332)
6901 [javac] return SWTUtil.createPushButton(parent, label, null);
6902 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6903 [javac] Discouraged access: The method createPushButton(Composite, String, Image) from the type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6904 [javac] ----------
6905 [javac] ----------
6906 [javac] 201. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6907 [javac] (at line 21)
6908 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
6909 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6910 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6911 [javac] ----------
6912 [javac] 202. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6913 [javac] (at line 22)
6914 [javac] import org.eclipse.jdt.internal.ui.JavaPluginImages;
6915 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6916 [javac] Discouraged access: The type JavaPluginImages is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6917 [javac] ----------
6918 [javac] 203. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6919 [javac] (at line 23)
6920 [javac] import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
6921 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6922 [javac] Discouraged access: The type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6923 [javac] ----------
6924 [javac] 204. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6925 [javac] (at line 37)
6926 [javac] private ImageDescriptorRegistry fRegistry= JavaPlugin.getImageDescriptorRegistry();
6927 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
6928 [javac] Discouraged access: The type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6929 [javac] ----------
6930 [javac] 205. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6931 [javac] (at line 37)
6932 [javac] private ImageDescriptorRegistry fRegistry= JavaPlugin.getImageDescriptorRegistry();
6933 [javac] ^^^^^^^^^^
6934 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6935 [javac] ----------
6936 [javac] 206. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6937 [javac] (at line 37)
6938 [javac] private ImageDescriptorRegistry fRegistry= JavaPlugin.getImageDescriptorRegistry();
6939 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6940 [javac] Discouraged access: The method getImageDescriptorRegistry() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6941 [javac] ----------
6942 [javac] 207. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6943 [javac] (at line 58)
6944 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); // todo: change image
6945 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6946 [javac] Discouraged access: The method get(ImageDescriptor) from the type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6947 [javac] ----------
6948 [javac] 208. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6949 [javac] (at line 58)
6950 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); // todo: change image
6951 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6952 [javac] Discouraged access: The type JavaPluginImages is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6953 [javac] ----------
6954 [javac] 209. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6955 [javac] (at line 58)
6956 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); // todo: change image
6957 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6958 [javac] Discouraged access: The field DESC_OBJS_SOURCE_ATTACH_ATTRIB from the type JavaPluginImages is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6959 [javac] ----------
6960 [javac] 210. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6961 [javac] (at line 60)
6962 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_JAVADOC_LOCATION_ATTRIB); // todo: change image
6963 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6964 [javac] Discouraged access: The method get(ImageDescriptor) from the type ImageDescriptorRegistry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6965 [javac] ----------
6966 [javac] 211. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6967 [javac] (at line 60)
6968 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_JAVADOC_LOCATION_ATTRIB); // todo: change image
6969 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6970 [javac] Discouraged access: The type JavaPluginImages is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6971 [javac] ----------
6972 [javac] 212. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/jres/LibraryLabelProvider.java
6973 [javac] (at line 60)
6974 [javac] return fRegistry.get(JavaPluginImages.DESC_OBJS_JAVADOC_LOCATION_ATTRIB); // todo: change image
6975 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6976 [javac] Discouraged access: The field DESC_OBJS_JAVADOC_LOCATION_ATTRIB from the type JavaPluginImages is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
6977 [javac] ----------
6978 [javac] ----------
6979 [javac] 213. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaContendedMonitorAdapter.java
6980 [javac] (at line 14)
6981 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
6982 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6983 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6984 [javac] ----------
6985 [javac] 214. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaContendedMonitorAdapter.java
6986 [javac] (at line 18)
6987 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
6988 [javac] ^^^^^^^^^^^^^^^^^^^^
6989 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6990 [javac] ----------
6991 [javac] 215. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaContendedMonitorAdapter.java
6992 [javac] (at line 21)
6993 [javac] return EMPTY;
6994 [javac] ^^^^^
6995 [javac] Discouraged access: The field EMPTY from the type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
6996 [javac] ----------
6997 [javac] 216. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaContendedMonitorAdapter.java
6998 [javac] (at line 26)
6999 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7000 [javac] ^^^^^^^^^^^^^^^^^^^^
7001 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7002 [javac] ----------
7003 [javac] ----------
7004 [javac] 217. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwnedMonitorAdapter.java
7005 [javac] (at line 14)
7006 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7007 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7008 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7009 [javac] ----------
7010 [javac] 218. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwnedMonitorAdapter.java
7011 [javac] (at line 18)
7012 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7013 [javac] ^^^^^^^^^^^^^^^^^^^^
7014 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7015 [javac] ----------
7016 [javac] 219. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwnedMonitorAdapter.java
7017 [javac] (at line 22)
7018 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7019 [javac] ^^^^^^^^^^^^^^^^^^^^
7020 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7021 [javac] ----------
7022 [javac] ----------
7023 [javac] 220. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwningThreadAdapter.java
7024 [javac] (at line 14)
7025 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7026 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7027 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7028 [javac] ----------
7029 [javac] 221. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwningThreadAdapter.java
7030 [javac] (at line 18)
7031 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7032 [javac] ^^^^^^^^^^^^^^^^^^^^
7033 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7034 [javac] ----------
7035 [javac] 222. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwningThreadAdapter.java
7036 [javac] (at line 21)
7037 [javac] return EMPTY;
7038 [javac] ^^^^^
7039 [javac] Discouraged access: The field EMPTY from the type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7040 [javac] ----------
7041 [javac] 223. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaOwningThreadAdapter.java
7042 [javac] (at line 26)
7043 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7044 [javac] ^^^^^^^^^^^^^^^^^^^^
7045 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7046 [javac] ----------
7047 [javac] ----------
7048 [javac] 224. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaThreadAdapter.java
7049 [javac] (at line 17)
7050 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7051 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7052 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7053 [javac] ----------
7054 [javac] 225. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaThreadAdapter.java
7055 [javac] (at line 27)
7056 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7057 [javac] ^^^^^^^^^^^^^^^^^^^^
7058 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7059 [javac] ----------
7060 [javac] 226. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaThreadAdapter.java
7061 [javac] (at line 30)
7062 [javac] return EMPTY;
7063 [javac] ^^^^^
7064 [javac] Discouraged access: The field EMPTY from the type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7065 [javac] ----------
7066 [javac] 227. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaThreadAdapter.java
7067 [javac] (at line 66)
7068 [javac] return EMPTY;
7069 [javac] ^^^^^
7070 [javac] Discouraged access: The field EMPTY from the type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7071 [javac] ----------
7072 [javac] 228. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaThreadAdapter.java
7073 [javac] (at line 70)
7074 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7075 [javac] ^^^^^^^^^^^^^^^^^^^^
7076 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7077 [javac] ----------
7078 [javac] ----------
7079 [javac] 229. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaWaitingThreadAdapter.java
7080 [javac] (at line 14)
7081 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7082 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7083 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7084 [javac] ----------
7085 [javac] 230. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaWaitingThreadAdapter.java
7086 [javac] (at line 18)
7087 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7088 [javac] ^^^^^^^^^^^^^^^^^^^^
7089 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7090 [javac] ----------
7091 [javac] 231. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncJavaWaitingThreadAdapter.java
7092 [javac] (at line 22)
7093 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7094 [javac] ^^^^^^^^^^^^^^^^^^^^
7095 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7096 [javac] ----------
7097 [javac] ----------
7098 [javac] 232. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncMonitorAdapter.java
7099 [javac] (at line 13)
7100 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousContentAdapter;
7101 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7102 [javac] Discouraged access: The type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7103 [javac] ----------
7104 [javac] 233. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/AsyncMonitorAdapter.java
7105 [javac] (at line 21)
7106 [javac] public abstract class AsyncMonitorAdapter extends AsynchronousContentAdapter implements IPropertyChangeListener {
7107 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
7108 [javac] Discouraged access: The type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7109 [javac] ----------
7110 [javac] ----------
7111 [javac] 234. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7112 [javac] (at line 14)
7113 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousContentAdapter;
7114 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7115 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7116 [javac] ----------
7117 [javac] 235. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7118 [javac] (at line 23)
7119 [javac] private static IAsynchronousContentAdapter fgThreadAdapter;
7120 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7121 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7122 [javac] ----------
7123 [javac] 236. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7124 [javac] (at line 24)
7125 [javac] private static IAsynchronousContentAdapter fgContendedMonitorAdapter;
7126 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7127 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7128 [javac] ----------
7129 [javac] 237. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7130 [javac] (at line 25)
7131 [javac] private static IAsynchronousContentAdapter fgOwnedMonitorAdapter;
7132 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7133 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7134 [javac] ----------
7135 [javac] 238. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7136 [javac] (at line 26)
7137 [javac] private static IAsynchronousContentAdapter fgOwningThreadAdapter;
7138 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7139 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7140 [javac] ----------
7141 [javac] 239. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7142 [javac] (at line 27)
7143 [javac] private static IAsynchronousContentAdapter fgWaitingThreadAdapter;
7144 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7145 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7146 [javac] ----------
7147 [javac] 240. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7148 [javac] (at line 65)
7149 [javac] private IAsynchronousContentAdapter getOwnedMonitorAdapater() {
7150 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7151 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7152 [javac] ----------
7153 [javac] 241. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7154 [javac] (at line 72)
7155 [javac] private IAsynchronousContentAdapter getContendedMonitorAdapter() {
7156 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7157 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7158 [javac] ----------
7159 [javac] 242. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7160 [javac] (at line 83)
7161 [javac] return new Class[] {IAsynchronousContentAdapter.class};
7162 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7163 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7164 [javac] ----------
7165 [javac] 243. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaDebugElementAdapterFactory.java
7166 [javac] (at line 86)
7167 [javac] private IAsynchronousContentAdapter getThreadAdapter() {
7168 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7169 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7170 [javac] ----------
7171 [javac] ----------
7172 [javac] 244. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7173 [javac] (at line 19)
7174 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
7175 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7176 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7177 [javac] ----------
7178 [javac] 245. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7179 [javac] (at line 20)
7180 [javac] import org.eclipse.jdt.internal.ui.text.java.JavaParameterListValidator;
7181 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7182 [javac] Discouraged access: The type JavaParameterListValidator is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7183 [javac] ----------
7184 [javac] 246. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7185 [javac] (at line 21)
7186 [javac] import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateEngine;
7187 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7188 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7189 [javac] ----------
7190 [javac] 247. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7191 [javac] (at line 22)
7192 [javac] import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal;
7193 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7194 [javac] Discouraged access: The type TemplateProposal is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7195 [javac] ----------
7196 [javac] 248. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7197 [javac] (at line 43)
7198 [javac] private TemplateEngine fTemplateEngine;
7199 [javac] ^^^^^^^^^^^^^^
7200 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7201 [javac] ----------
7202 [javac] 249. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7203 [javac] (at line 51)
7204 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
7205 [javac] ^^^^^^^^^^
7206 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7207 [javac] ----------
7208 [javac] 250. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7209 [javac] (at line 51)
7210 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
7211 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
7212 [javac] Discouraged access: The method getDefault() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7213 [javac] ----------
7214 [javac] 251. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7215 [javac] (at line 51)
7216 [javac] TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType("java"); //$NON-NLS-1$
7217 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7218 [javac] Discouraged access: The method getTemplateContextRegistry() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7219 [javac] ----------
7220 [javac] 252. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7221 [javac] (at line 53)
7222 [javac] fTemplateEngine= new TemplateEngine(contextType);
7223 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7224 [javac] Discouraged access: The constructor TemplateEngine(TemplateContextType) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7225 [javac] ----------
7226 [javac] 253. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7227 [javac] (at line 53)
7228 [javac] fTemplateEngine= new TemplateEngine(contextType);
7229 [javac] ^^^^^^^^^^^^^^
7230 [javac] Discouraged access: The type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7231 [javac] ----------
7232 [javac] 254. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7233 [javac] (at line 78)
7234 [javac] fValidator= new JavaParameterListValidator();
7235 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7236 [javac] Discouraged access: The constructor JavaParameterListValidator() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7237 [javac] ----------
7238 [javac] 255. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7239 [javac] (at line 78)
7240 [javac] fValidator= new JavaParameterListValidator();
7241 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
7242 [javac] Discouraged access: The type JavaParameterListValidator is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7243 [javac] ----------
7244 [javac] 256. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7245 [javac] (at line 116)
7246 [javac] fTemplateEngine.reset();
7247 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
7248 [javac] Discouraged access: The method reset() from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7249 [javac] ----------
7250 [javac] 257. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7251 [javac] (at line 117)
7252 [javac] fTemplateEngine.complete(viewer, position, null);
7253 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7254 [javac] Discouraged access: The method complete(ITextViewer, int, ICompilationUnit) from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7255 [javac] ----------
7256 [javac] 258. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7257 [javac] (at line 119)
7258 [javac] TemplateProposal[] templateResults= fTemplateEngine.getResults();
7259 [javac] ^^^^^^^^^^^^^^^^^^
7260 [javac] Discouraged access: The type TemplateProposal is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7261 [javac] ----------
7262 [javac] 259. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/JavaSnippetCompletionProcessor.java
7263 [javac] (at line 119)
7264 [javac] TemplateProposal[] templateResults= fTemplateEngine.getResults();
7265 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7266 [javac] Discouraged access: The method getResults() from the type TemplateEngine is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7267 [javac] ----------
7268 [javac] ----------
7269 [javac] 260. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SelectImportsDialog.java
7270 [javac] (at line 29)
7271 [javac] import org.eclipse.jdt.internal.ui.util.SWTUtil;
7272 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7273 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7274 [javac] ----------
7275 [javac] 261. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SelectImportsDialog.java
7276 [javac] (at line 203)
7277 [javac] SWTUtil.setButtonDimensionHint(button);
7278 [javac] ^^^^^^^
7279 [javac] Discouraged access: The type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7280 [javac] ----------
7281 [javac] 262. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SelectImportsDialog.java
7282 [javac] (at line 203)
7283 [javac] SWTUtil.setButtonDimensionHint(button);
7284 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7285 [javac] Discouraged access: The method setButtonDimensionHint(Button) from the type SWTUtil is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7286 [javac] ----------
7287 [javac] ----------
7288 [javac] 263. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7289 [javac] (at line 15)
7290 [javac] import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
7291 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7292 [javac] Discouraged access: The type IJavaHelpContextIds is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7293 [javac] ----------
7294 [javac] 264. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7295 [javac] (at line 16)
7296 [javac] import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
7297 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7298 [javac] Discouraged access: The type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7299 [javac] ----------
7300 [javac] 265. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7301 [javac] (at line 45)
7302 [javac] PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION);
7303 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7304 [javac] Discouraged access: The type IJavaHelpContextIds is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7305 [javac] ----------
7306 [javac] 266. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7307 [javac] (at line 45)
7308 [javac] PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION);
7309 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
7310 [javac] Discouraged access: The field SHOW_IN_PACKAGEVIEW_ACTION from the type IJavaHelpContextIds is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7311 [javac] ----------
7312 [javac] 267. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7313 [javac] (at line 64)
7314 [javac] PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
7315 [javac] ^^^^^^^^^^^^^^^^^^^
7316 [javac] Discouraged access: The type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7317 [javac] ----------
7318 [javac] 268. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7319 [javac] (at line 64)
7320 [javac] PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
7321 [javac] ^^^^^^^^^^^^^^^^^^^
7322 [javac] Discouraged access: The type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7323 [javac] ----------
7324 [javac] 269. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7325 [javac] (at line 64)
7326 [javac] PackageExplorerPart view= PackageExplorerPart.openInActivePerspective();
7327 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7328 [javac] Discouraged access: The method openInActivePerspective() from the type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7329 [javac] ----------
7330 [javac] 270. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7331 [javac] (at line 70)
7332 [javac] private boolean reveal(PackageExplorerPart view, Object element) {
7333 [javac] ^^^^^^^^^^^^^^^^^^^
7334 [javac] Discouraged access: The type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7335 [javac] ----------
7336 [javac] 271. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7337 [javac] (at line 74)
7338 [javac] view.selectReveal(new StructuredSelection(element));
7339 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7340 [javac] Discouraged access: The method selectReveal(ISelection) from the type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7341 [javac] ----------
7342 [javac] 272. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7343 [javac] (at line 75)
7344 [javac] IElementComparer comparer= view.getTreeViewer().getComparer();
7345 [javac] ^^^^^^^^^^^^^^^^^^^^
7346 [javac] Discouraged access: The method getTreeViewer() from the type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7347 [javac] ----------
7348 [javac] 273. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/ShowInPackageViewAction.java
7349 [javac] (at line 83)
7350 [javac] private Object getSelectedElement(PackageExplorerPart view) {
7351 [javac] ^^^^^^^^^^^^^^^^^^^
7352 [javac] Discouraged access: The type PackageExplorerPart is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7353 [javac] ----------
7354 [javac] ----------
7355 [javac] 274. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SnippetEditorActionContributor.java
7356 [javac] (at line 15)
7357 [javac] import org.eclipse.jdt.internal.ui.javaeditor.BasicCompilationUnitEditorActionContributor;
7358 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7359 [javac] Discouraged access: The type BasicCompilationUnitEditorActionContributor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7360 [javac] ----------
7361 [javac] 275. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SnippetEditorActionContributor.java
7362 [javac] (at line 25)
7363 [javac] public class SnippetEditorActionContributor extends BasicCompilationUnitEditorActionContributor {
7364 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7365 [javac] Discouraged access: The type BasicCompilationUnitEditorActionContributor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7366 [javac] ----------
7367 [javac] 276. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SnippetEditorActionContributor.java
7368 [javac] (at line 35)
7369 [javac] super();
7370 [javac] ^^^^^^^
7371 [javac] Discouraged access: The constructor BasicCompilationUnitEditorActionContributor() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7372 [javac] ----------
7373 [javac] 277. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SnippetEditorActionContributor.java
7374 [javac] (at line 59)
7375 [javac] super.contributeToMenu(menu);
7376 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7377 [javac] Discouraged access: The method contributeToMenu(IMenuManager) from the type BasicCompilationUnitEditorActionContributor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7378 [javac] ----------
7379 [javac] 278. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/snippeteditor/SnippetEditorActionContributor.java
7380 [javac] (at line 74)
7381 [javac] super.setActiveEditor(part);
7382 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7383 [javac] Discouraged access: The method setActiveEditor(IEditorPart) from the type BasicCompilationUnitEditorActionContributor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
7384 [javac] ----------
7385 [javac] ----------
7386 [javac] 279. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7387 [javac] (at line 14)
7388 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousContentAdapter;
7389 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7390 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7391 [javac] ----------
7392 [javac] 280. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7393 [javac] (at line 15)
7394 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousLabelAdapter;
7395 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7396 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7397 [javac] ----------
7398 [javac] 281. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7399 [javac] (at line 16)
7400 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IModelProxyFactoryAdapter;
7401 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7402 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7403 [javac] ----------
7404 [javac] 282. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7405 [javac] (at line 26)
7406 [javac] private static IAsynchronousLabelAdapter fgThreadGroupLabelAdapter = new JavaThreadGroupLabelAdapter();
7407 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7408 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7409 [javac] ----------
7410 [javac] 283. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7411 [javac] (at line 27)
7412 [javac] private static IAsynchronousContentAdapter fgThreadGroupTreeAdapter = new JavaThreadGroupContentAdapter();
7413 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7414 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7415 [javac] ----------
7416 [javac] 284. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7417 [javac] (at line 28)
7418 [javac] private static IAsynchronousContentAdapter fgTargetTreeAdapter = new JavaDebugTargetContentAdapter();
7419 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7420 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7421 [javac] ----------
7422 [javac] 285. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7423 [javac] (at line 29)
7424 [javac] private static IModelProxyFactoryAdapter fgJavaModelProxyFactory = new JavaModelProxyFactory();
7425 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7426 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7427 [javac] ----------
7428 [javac] 286. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7429 [javac] (at line 35)
7430 [javac] if (adapterType.equals(IAsynchronousLabelAdapter.class)) {
7431 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7432 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7433 [javac] ----------
7434 [javac] 287. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7435 [javac] (at line 40)
7436 [javac] if (adapterType.equals(IAsynchronousContentAdapter.class)) {
7437 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7438 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7439 [javac] ----------
7440 [javac] 288. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7441 [javac] (at line 48)
7442 [javac] if (adapterType.equals(IModelProxyFactoryAdapter.class)) {
7443 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7444 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7445 [javac] ----------
7446 [javac] 289. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7447 [javac] (at line 60)
7448 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IAsynchronousContentAdapter.class, IModelProxyFactoryAdapter.class};
7449 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7450 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7451 [javac] ----------
7452 [javac] 290. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7453 [javac] (at line 60)
7454 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IAsynchronousContentAdapter.class, IModelProxyFactoryAdapter.class};
7455 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7456 [javac] Discouraged access: The type IAsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7457 [javac] ----------
7458 [javac] 291. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugElementLabelAdapterFactory.java
7459 [javac] (at line 60)
7460 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IAsynchronousContentAdapter.class, IModelProxyFactoryAdapter.class};
7461 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7462 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7463 [javac] ----------
7464 [javac] ----------
7465 [javac] 292. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7466 [javac] (at line 15)
7467 [javac] import org.eclipse.debug.internal.ui.elements.adapters.DebugTargetContentAdapter;
7468 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7469 [javac] Discouraged access: The type DebugTargetContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7470 [javac] ----------
7471 [javac] 293. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7472 [javac] (at line 16)
7473 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7474 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7475 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7476 [javac] ----------
7477 [javac] 294. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7478 [javac] (at line 27)
7479 [javac] public class JavaDebugTargetContentAdapter extends DebugTargetContentAdapter {
7480 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7481 [javac] Discouraged access: The type DebugTargetContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7482 [javac] ----------
7483 [javac] 295. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7484 [javac] (at line 29)
7485 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7486 [javac] ^^^^^^^^^^^^^^^^^^^^
7487 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7488 [javac] ----------
7489 [javac] 296. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7490 [javac] (at line 30)
7491 [javac] String id = context.getPart().getSite().getId();
7492 [javac] ^^^^^^^^^^^^^^^^^
7493 [javac] Discouraged access: The method getPart() from the type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7494 [javac] ----------
7495 [javac] 297. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetContentAdapter.java
7496 [javac] (at line 39)
7497 [javac] return super.getChildren(parent, context);
7498 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7499 [javac] Discouraged access: The method getChildren(Object, IPresentationContext) from the type DebugTargetContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7500 [javac] ----------
7501 [javac] ----------
7502 [javac] 298. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7503 [javac] (at line 14)
7504 [javac] import org.eclipse.debug.internal.ui.viewers.update.DebugEventHandler;
7505 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7506 [javac] Discouraged access: The type DebugEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7507 [javac] ----------
7508 [javac] 299. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7509 [javac] (at line 15)
7510 [javac] import org.eclipse.debug.internal.ui.viewers.update.DebugTargetEventHandler;
7511 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7512 [javac] Discouraged access: The type DebugTargetEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7513 [javac] ----------
7514 [javac] 300. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7515 [javac] (at line 16)
7516 [javac] import org.eclipse.debug.internal.ui.viewers.update.DebugTargetProxy;
7517 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7518 [javac] Discouraged access: The type DebugTargetProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7519 [javac] ----------
7520 [javac] 301. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7521 [javac] (at line 22)
7522 [javac] public class JavaDebugTargetProxy extends DebugTargetProxy {
7523 [javac] ^^^^^^^^^^^^^^^^
7524 [javac] Discouraged access: The type DebugTargetProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7525 [javac] ----------
7526 [javac] 302. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7527 [javac] (at line 28)
7528 [javac] super(target);
7529 [javac] ^^^^^^^^^^^^^
7530 [javac] Discouraged access: The constructor DebugTargetProxy(IDebugTarget) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7531 [javac] ----------
7532 [javac] 303. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7533 [javac] (at line 34)
7534 [javac] protected DebugEventHandler[] createEventHandlers() {
7535 [javac] ^^^^^^^^^^^^^^^^^^^
7536 [javac] Discouraged access: The type DebugEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7537 [javac] ----------
7538 [javac] 304. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7539 [javac] (at line 35)
7540 [javac] return new DebugEventHandler[] { new DebugTargetEventHandler(this), new JavaThreadEventHandler(this) };
7541 [javac] ^^^^^^^^^^^^^^^^^
7542 [javac] Discouraged access: The type DebugEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7543 [javac] ----------
7544 [javac] 305. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7545 [javac] (at line 35)
7546 [javac] return new DebugEventHandler[] { new DebugTargetEventHandler(this), new JavaThreadEventHandler(this) };
7547 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7548 [javac] Discouraged access: The constructor DebugTargetEventHandler(AbstractModelProxy) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7549 [javac] ----------
7550 [javac] 306. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaDebugTargetProxy.java
7551 [javac] (at line 35)
7552 [javac] return new DebugEventHandler[] { new DebugTargetEventHandler(this), new JavaThreadEventHandler(this) };
7553 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
7554 [javac] Discouraged access: The type DebugTargetEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7555 [javac] ----------
7556 [javac] ----------
7557 [javac] 307. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7558 [javac] (at line 14)
7559 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IModelProxy;
7560 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7561 [javac] Discouraged access: The type IModelProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7562 [javac] ----------
7563 [javac] 308. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7564 [javac] (at line 15)
7565 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IModelProxyFactoryAdapter;
7566 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7567 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7568 [javac] ----------
7569 [javac] 309. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7570 [javac] (at line 16)
7571 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7572 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7573 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7574 [javac] ----------
7575 [javac] 310. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7576 [javac] (at line 23)
7577 [javac] public class JavaModelProxyFactory implements IModelProxyFactoryAdapter {
7578 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7579 [javac] Discouraged access: The type IModelProxyFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7580 [javac] ----------
7581 [javac] 311. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7582 [javac] (at line 28)
7583 [javac] public IModelProxy createModelProxy(Object element, IPresentationContext context) {
7584 [javac] ^^^^^^^^^^^
7585 [javac] Discouraged access: The type IModelProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7586 [javac] ----------
7587 [javac] 312. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaModelProxyFactory.java
7588 [javac] (at line 28)
7589 [javac] public IModelProxy createModelProxy(Object element, IPresentationContext context) {
7590 [javac] ^^^^^^^^^^^^^^^^^^^^
7591 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7592 [javac] ----------
7593 [javac] ----------
7594 [javac] 313. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7595 [javac] (at line 21)
7596 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
7597 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7598 [javac] Discouraged access: The type AbstractModelProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7599 [javac] ----------
7600 [javac] 314. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7601 [javac] (at line 22)
7602 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IModelDelta;
7603 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7604 [javac] Discouraged access: The type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7605 [javac] ----------
7606 [javac] 315. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7607 [javac] (at line 23)
7608 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.ModelDelta;
7609 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7610 [javac] Discouraged access: The type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7611 [javac] ----------
7612 [javac] 316. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7613 [javac] (at line 24)
7614 [javac] import org.eclipse.debug.internal.ui.viewers.update.ThreadEventHandler;
7615 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7616 [javac] Discouraged access: The type ThreadEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7617 [javac] ----------
7618 [javac] 317. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7619 [javac] (at line 35)
7620 [javac] public class JavaThreadEventHandler extends ThreadEventHandler {
7621 [javac] ^^^^^^^^^^^^^^^^^^
7622 [javac] Discouraged access: The type ThreadEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7623 [javac] ----------
7624 [javac] 318. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7625 [javac] (at line 42)
7626 [javac] public JavaThreadEventHandler(AbstractModelProxy proxy) {
7627 [javac] ^^^^^^^^^^^^^^^^^^
7628 [javac] Discouraged access: The type AbstractModelProxy is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7629 [javac] ----------
7630 [javac] 319. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7631 [javac] (at line 43)
7632 [javac] super(proxy);
7633 [javac] ^^^^^^^^^^^^
7634 [javac] Discouraged access: The constructor ThreadEventHandler(AbstractModelProxy) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7635 [javac] ----------
7636 [javac] 320. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7637 [javac] (at line 46)
7638 [javac] protected ModelDelta addPathToThread(ModelDelta delta, IThread thread) {
7639 [javac] ^^^^^^^^^^
7640 [javac] Discouraged access: The type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7641 [javac] ----------
7642 [javac] 321. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7643 [javac] (at line 46)
7644 [javac] protected ModelDelta addPathToThread(ModelDelta delta, IThread thread) {
7645 [javac] ^^^^^^^^^^
7646 [javac] Discouraged access: The type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7647 [javac] ----------
7648 [javac] 322. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7649 [javac] (at line 48)
7650 [javac] delta = delta.addNode(thread.getLaunch(), IModelDelta.NO_CHANGE);
7651 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7652 [javac] Discouraged access: The method addNode(Object, int) from the type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7653 [javac] ----------
7654 [javac] 323. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7655 [javac] (at line 48)
7656 [javac] delta = delta.addNode(thread.getLaunch(), IModelDelta.NO_CHANGE);
7657 [javac] ^^^^^^^^^^^^^^^^^^^^^
7658 [javac] Discouraged access: The type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7659 [javac] ----------
7660 [javac] 324. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7661 [javac] (at line 48)
7662 [javac] delta = delta.addNode(thread.getLaunch(), IModelDelta.NO_CHANGE);
7663 [javac] ^^^^^^^^^
7664 [javac] Discouraged access: The field NO_CHANGE from the type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7665 [javac] ----------
7666 [javac] 325. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7667 [javac] (at line 49)
7668 [javac] delta = delta.addNode(thread.getDebugTarget(), IModelDelta.NO_CHANGE);
7669 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7670 [javac] Discouraged access: The method addNode(Object, int) from the type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7671 [javac] ----------
7672 [javac] 326. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7673 [javac] (at line 49)
7674 [javac] delta = delta.addNode(thread.getDebugTarget(), IModelDelta.NO_CHANGE);
7675 [javac] ^^^^^^^^^^^^^^^^^^^^^
7676 [javac] Discouraged access: The type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7677 [javac] ----------
7678 [javac] 327. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7679 [javac] (at line 49)
7680 [javac] delta = delta.addNode(thread.getDebugTarget(), IModelDelta.NO_CHANGE);
7681 [javac] ^^^^^^^^^
7682 [javac] Discouraged access: The field NO_CHANGE from the type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7683 [javac] ----------
7684 [javac] 328. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7685 [javac] (at line 63)
7686 [javac] delta = delta.addNode(iterator.next(), IModelDelta.NO_CHANGE);
7687 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7688 [javac] Discouraged access: The method addNode(Object, int) from the type ModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7689 [javac] ----------
7690 [javac] 329. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7691 [javac] (at line 63)
7692 [javac] delta = delta.addNode(iterator.next(), IModelDelta.NO_CHANGE);
7693 [javac] ^^^^^^^^^^^^^^^^^^^^^
7694 [javac] Discouraged access: The type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7695 [javac] ----------
7696 [javac] 330. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7697 [javac] (at line 63)
7698 [javac] delta = delta.addNode(iterator.next(), IModelDelta.NO_CHANGE);
7699 [javac] ^^^^^^^^^
7700 [javac] Discouraged access: The field NO_CHANGE from the type IModelDelta is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7701 [javac] ----------
7702 [javac] 331. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7703 [javac] (at line 67)
7704 [javac] return super.addPathToThread(delta, thread);
7705 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7706 [javac] Discouraged access: The method addPathToThread(ModelDelta, IThread) from the type ThreadEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7707 [javac] ----------
7708 [javac] 332. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadEventHandler.java
7709 [javac] (at line 75)
7710 [javac] if (super.handlesEvent(event)) {
7711 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7712 [javac] Discouraged access: The method handlesEvent(DebugEvent) from the type ThreadEventHandler is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7713 [javac] ----------
7714 [javac] ----------
7715 [javac] 333. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7716 [javac] (at line 14)
7717 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousContentAdapter;
7718 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7719 [javac] Discouraged access: The type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7720 [javac] ----------
7721 [javac] 334. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7722 [javac] (at line 15)
7723 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7724 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7725 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7726 [javac] ----------
7727 [javac] 335. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7728 [javac] (at line 25)
7729 [javac] public class JavaThreadGroupContentAdapter extends AsynchronousContentAdapter {
7730 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
7731 [javac] Discouraged access: The type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7732 [javac] ----------
7733 [javac] 336. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7734 [javac] (at line 27)
7735 [javac] protected Object[] getChildren(Object parent, IPresentationContext context) throws CoreException {
7736 [javac] ^^^^^^^^^^^^^^^^^^^^
7737 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7738 [javac] ----------
7739 [javac] 337. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7740 [javac] (at line 44)
7741 [javac] return EMPTY;
7742 [javac] ^^^^^
7743 [javac] Discouraged access: The field EMPTY from the type AsynchronousContentAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7744 [javac] ----------
7745 [javac] 338. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupContentAdapter.java
7746 [javac] (at line 47)
7747 [javac] protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException {
7748 [javac] ^^^^^^^^^^^^^^^^^^^^
7749 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7750 [javac] ----------
7751 [javac] ----------
7752 [javac] 339. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7753 [javac] (at line 16)
7754 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousLabelAdapter;
7755 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7756 [javac] Discouraged access: The type AsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7757 [javac] ----------
7758 [javac] 340. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7759 [javac] (at line 17)
7760 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7761 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7762 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7763 [javac] ----------
7764 [javac] 341. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7765 [javac] (at line 29)
7766 [javac] public class JavaThreadGroupLabelAdapter extends AsynchronousLabelAdapter {
7767 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
7768 [javac] Discouraged access: The type AsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7769 [javac] ----------
7770 [javac] 342. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7771 [javac] (at line 36)
7772 [javac] protected String[] getLabels(Object element, IPresentationContext context) throws CoreException {
7773 [javac] ^^^^^^^^^^^^^^^^^^^^
7774 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7775 [javac] ----------
7776 [javac] 343. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7777 [javac] (at line 47)
7778 [javac] protected ImageDescriptor[] getImageDescriptors(Object element, IPresentationContext context) throws CoreException {
7779 [javac] ^^^^^^^^^^^^^^^^^^^^
7780 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7781 [javac] ----------
7782 [javac] 344. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7783 [javac] (at line 54)
7784 [javac] protected FontData[] getFontDatas(Object element, IPresentationContext context) throws CoreException {
7785 [javac] ^^^^^^^^^^^^^^^^^^^^
7786 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7787 [javac] ----------
7788 [javac] 345. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7789 [javac] (at line 61)
7790 [javac] protected RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException {
7791 [javac] ^^^^^^^^^^^^^^^^^^^^
7792 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7793 [javac] ----------
7794 [javac] 346. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/threadgroups/JavaThreadGroupLabelAdapter.java
7795 [javac] (at line 68)
7796 [javac] protected RGB[] getBackgrounds(Object element, IPresentationContext context) throws CoreException {
7797 [javac] ^^^^^^^^^^^^^^^^^^^^
7798 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7799 [javac] ----------
7800 [javac] ----------
7801 [javac] 347. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7802 [javac] (at line 14)
7803 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousLabelAdapter;
7804 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7805 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7806 [javac] ----------
7807 [javac] 348. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7808 [javac] (at line 15)
7809 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnEditorFactoryAdapter;
7810 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7811 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7812 [javac] ----------
7813 [javac] 349. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7814 [javac] (at line 16)
7815 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnPresentationFactoryAdapter;
7816 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7817 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7818 [javac] ----------
7819 [javac] 350. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7820 [javac] (at line 27)
7821 [javac] private static final IAsynchronousLabelAdapter fgLabel = new JavaVariableLabelAdapter();
7822 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7823 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7824 [javac] ----------
7825 [javac] 351. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7826 [javac] (at line 28)
7827 [javac] private static final IColumnEditorFactoryAdapter fgColumnEditor = new JavaVariableColumnEditorFactory();
7828 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7829 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7830 [javac] ----------
7831 [javac] 352. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7832 [javac] (at line 29)
7833 [javac] private static final IColumnPresentationFactoryAdapter fgColumnPresentation = new JavaVariableColumnPresentationFactory();
7834 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7835 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7836 [javac] ----------
7837 [javac] 353. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7838 [javac] (at line 36)
7839 [javac] if (IAsynchronousLabelAdapter.class.equals(adapterType)) {
7840 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7841 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7842 [javac] ----------
7843 [javac] 354. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7844 [javac] (at line 39)
7845 [javac] if (IColumnEditorFactoryAdapter.class.equals(adapterType)) {
7846 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7847 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7848 [javac] ----------
7849 [javac] 355. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7850 [javac] (at line 44)
7851 [javac] if (IColumnPresentationFactoryAdapter.class.equals(adapterType)) {
7852 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7853 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7854 [javac] ----------
7855 [javac] 356. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7856 [javac] (at line 55)
7857 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IColumnEditorFactoryAdapter.class, IColumnPresentationFactoryAdapter.class};
7858 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
7859 [javac] Discouraged access: The type IAsynchronousLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7860 [javac] ----------
7861 [javac] 357. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7862 [javac] (at line 55)
7863 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IColumnEditorFactoryAdapter.class, IColumnPresentationFactoryAdapter.class};
7864 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7865 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7866 [javac] ----------
7867 [javac] 358. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/ColumnPresentationAdapterFactory.java
7868 [javac] (at line 55)
7869 [javac] return new Class[]{IAsynchronousLabelAdapter.class, IColumnEditorFactoryAdapter.class, IColumnPresentationFactoryAdapter.class};
7870 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7871 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7872 [javac] ----------
7873 [javac] ----------
7874 [javac] 359. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7875 [javac] (at line 14)
7876 [javac] import org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier;
7877 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7878 [javac] Discouraged access: The type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7879 [javac] ----------
7880 [javac] 360. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7881 [javac] (at line 15)
7882 [javac] import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation;
7883 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7884 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7885 [javac] ----------
7886 [javac] 361. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7887 [javac] (at line 16)
7888 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
7889 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7890 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7891 [javac] ----------
7892 [javac] 362. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7893 [javac] (at line 24)
7894 [javac] public class JavaVariableCellModifier extends DefaultVariableCellModifier {
7895 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
7896 [javac] Discouraged access: The type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7897 [javac] ----------
7898 [javac] 363. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7899 [javac] (at line 31)
7900 [javac] public JavaVariableCellModifier(IPresentationContext context) {
7901 [javac] ^^^^^^^^^^^^^^^^^^^^
7902 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7903 [javac] ----------
7904 [javac] 364. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7905 [javac] (at line 32)
7906 [javac] super(context);
7907 [javac] ^^^^^^^^^^^^^^
7908 [javac] Discouraged access: The constructor DefaultVariableCellModifier(IPresentationContext) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7909 [javac] ----------
7910 [javac] 365. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7911 [javac] (at line 42)
7912 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7913 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7914 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7915 [javac] ----------
7916 [javac] 366. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7917 [javac] (at line 42)
7918 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7919 [javac] ^^^^^^^^^^^^^^^^^^^^^
7920 [javac] Discouraged access: The field COLUMN_VARIABLE_VALUE from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7921 [javac] ----------
7922 [javac] 367. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7923 [javac] (at line 66)
7924 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7925 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7926 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7927 [javac] ----------
7928 [javac] 368. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7929 [javac] (at line 66)
7930 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7931 [javac] ^^^^^^^^^^^^^^^^^^^^^
7932 [javac] Discouraged access: The field COLUMN_VARIABLE_VALUE from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7933 [javac] ----------
7934 [javac] 369. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7935 [javac] (at line 81)
7936 [javac] return super.getValue(element, property);
7937 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7938 [javac] Discouraged access: The method getValue(Object, String) from the type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7939 [javac] ----------
7940 [javac] 370. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7941 [javac] (at line 87)
7942 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7943 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7944 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7945 [javac] ----------
7946 [javac] 371. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7947 [javac] (at line 87)
7948 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) {
7949 [javac] ^^^^^^^^^^^^^^^^^^^^^
7950 [javac] Discouraged access: The field COLUMN_VARIABLE_VALUE from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7951 [javac] ----------
7952 [javac] 372. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7953 [javac] (at line 93)
7954 [javac] super.modify(element, property, Boolean.toString(true));
7955 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7956 [javac] Discouraged access: The method modify(Object, String, Object) from the type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7957 [javac] ----------
7958 [javac] 373. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7959 [javac] (at line 96)
7960 [javac] super.modify(element, property, Boolean.toString(false));
7961 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7962 [javac] Discouraged access: The method modify(Object, String, Object) from the type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7963 [javac] ----------
7964 [javac] 374. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableCellModifier.java
7965 [javac] (at line 102)
7966 [javac] super.modify(element, property, value);
7967 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7968 [javac] Discouraged access: The method modify(Object, String, Object) from the type DefaultVariableCellModifier is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7969 [javac] ----------
7970 [javac] ----------
7971 [javac] 375. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
7972 [javac] (at line 13)
7973 [javac] import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnEditor;
7974 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7975 [javac] Discouraged access: The type VariableColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7976 [javac] ----------
7977 [javac] 376. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
7978 [javac] (at line 14)
7979 [javac] import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation;
7980 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7981 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7982 [javac] ----------
7983 [javac] 377. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
7984 [javac] (at line 28)
7985 [javac] public class JavaVariableColumnEditor extends VariableColumnEditor {
7986 [javac] ^^^^^^^^^^^^^^^^^^^^
7987 [javac] Discouraged access: The type VariableColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7988 [javac] ----------
7989 [javac] 378. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
7990 [javac] (at line 39)
7991 [javac] fModifier = new JavaVariableCellModifier(getPresentationContext());
7992 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
7993 [javac] Discouraged access: The method getPresentationContext() from the type AbstractColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
7994 [javac] ----------
7995 [javac] 379. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
7996 [javac] (at line 55)
7997 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(id)) {
7998 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7999 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8000 [javac] ----------
8001 [javac] 380. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
8002 [javac] (at line 55)
8003 [javac] if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(id)) {
8004 [javac] ^^^^^^^^^^^^^^^^^^^^^
8005 [javac] Discouraged access: The field COLUMN_VARIABLE_VALUE from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8006 [javac] ----------
8007 [javac] 381. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditor.java
8008 [javac] (at line 63)
8009 [javac] return super.getCellEditor(id, element, parent);
8010 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8011 [javac] Discouraged access: The method getCellEditor(String, Object, Composite) from the type VariableColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8012 [javac] ----------
8013 [javac] ----------
8014 [javac] 382. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8015 [javac] (at line 13)
8016 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnEditor;
8017 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8018 [javac] Discouraged access: The type IColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8019 [javac] ----------
8020 [javac] 383. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8021 [javac] (at line 14)
8022 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnEditorFactoryAdapter;
8023 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8024 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8025 [javac] ----------
8026 [javac] 384. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8027 [javac] (at line 15)
8028 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
8029 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8030 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8031 [javac] ----------
8032 [javac] 385. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8033 [javac] (at line 25)
8034 [javac] IColumnEditorFactoryAdapter {
8035 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8036 [javac] Discouraged access: The type IColumnEditorFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8037 [javac] ----------
8038 [javac] 386. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8039 [javac] (at line 30)
8040 [javac] public IColumnEditor createColumnEditor(IPresentationContext context, Object element) {
8041 [javac] ^^^^^^^^^^^^^
8042 [javac] Discouraged access: The type IColumnEditor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8043 [javac] ----------
8044 [javac] 387. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8045 [javac] (at line 30)
8046 [javac] public IColumnEditor createColumnEditor(IPresentationContext context, Object element) {
8047 [javac] ^^^^^^^^^^^^^^^^^^^^
8048 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8049 [javac] ----------
8050 [javac] 388. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8051 [javac] (at line 31)
8052 [javac] IWorkbenchPart part = context.getPart();
8053 [javac] ^^^^^^^^^^^^^^^^^
8054 [javac] Discouraged access: The method getPart() from the type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8055 [javac] ----------
8056 [javac] 389. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8057 [javac] (at line 45)
8058 [javac] public String getColumnEditorId(IPresentationContext context, Object element) {
8059 [javac] ^^^^^^^^^^^^^^^^^^^^
8060 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8061 [javac] ----------
8062 [javac] 390. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnEditorFactory.java
8063 [javac] (at line 46)
8064 [javac] IWorkbenchPart part = context.getPart();
8065 [javac] ^^^^^^^^^^^^^^^^^
8066 [javac] Discouraged access: The method getPart() from the type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8067 [javac] ----------
8068 [javac] ----------
8069 [javac] 391. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentation.java
8070 [javac] (at line 13)
8071 [javac] import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation;
8072 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8073 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8074 [javac] ----------
8075 [javac] 392. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentation.java
8076 [javac] (at line 20)
8077 [javac] public class JavaVariableColumnPresentation extends VariableColumnPresentation {
8078 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
8079 [javac] Discouraged access: The type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8080 [javac] ----------
8081 [javac] 393. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentation.java
8082 [javac] (at line 40)
8083 [javac] String[] basic = super.getAvailableColumns();
8084 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8085 [javac] Discouraged access: The method getAvailableColumns() from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8086 [javac] ----------
8087 [javac] 394. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentation.java
8088 [javac] (at line 55)
8089 [javac] return super.getHeader(id);
8090 [javac] ^^^^^^^^^^^^^^^^^^^
8091 [javac] Discouraged access: The method getHeader(String) from the type VariableColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8092 [javac] ----------
8093 [javac] ----------
8094 [javac] 395. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8095 [javac] (at line 14)
8096 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnPresentation;
8097 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8098 [javac] Discouraged access: The type IColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8099 [javac] ----------
8100 [javac] 396. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8101 [javac] (at line 15)
8102 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IColumnPresentationFactoryAdapter;
8103 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8104 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8105 [javac] ----------
8106 [javac] 397. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8107 [javac] (at line 16)
8108 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
8109 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8110 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8111 [javac] ----------
8112 [javac] 398. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8113 [javac] (at line 26)
8114 [javac] public class JavaVariableColumnPresentationFactory implements IColumnPresentationFactoryAdapter {
8115 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8116 [javac] Discouraged access: The type IColumnPresentationFactoryAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8117 [javac] ----------
8118 [javac] 399. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8119 [javac] (at line 31)
8120 [javac] public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
8121 [javac] ^^^^^^^^^^^^^^^^^^^
8122 [javac] Discouraged access: The type IColumnPresentation is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8123 [javac] ----------
8124 [javac] 400. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8125 [javac] (at line 31)
8126 [javac] public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
8127 [javac] ^^^^^^^^^^^^^^^^^^^^
8128 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8129 [javac] ----------
8130 [javac] 401. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8131 [javac] (at line 41)
8132 [javac] public String getColumnPresentationId(IPresentationContext context, Object element) {
8133 [javac] ^^^^^^^^^^^^^^^^^^^^
8134 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8135 [javac] ----------
8136 [javac] 402. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8137 [javac] (at line 48)
8138 [javac] private boolean isApplicable(IPresentationContext context, Object element) {
8139 [javac] ^^^^^^^^^^^^^^^^^^^^
8140 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8141 [javac] ----------
8142 [javac] 403. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableColumnPresentationFactory.java
8143 [javac] (at line 49)
8144 [javac] IWorkbenchPart part = context.getPart();
8145 [javac] ^^^^^^^^^^^^^^^^^
8146 [javac] Discouraged access: The method getPart() from the type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8147 [javac] ----------
8148 [javac] ----------
8149 [javac] 404. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8150 [javac] (at line 17)
8151 [javac] import org.eclipse.debug.internal.ui.elements.adapters.VariableLabelAdapter;
8152 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8153 [javac] Discouraged access: The type VariableLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8154 [javac] ----------
8155 [javac] 405. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8156 [javac] (at line 18)
8157 [javac] import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext;
8158 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8159 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8160 [javac] ----------
8161 [javac] 406. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8162 [javac] (at line 31)
8163 [javac] public class JavaVariableLabelAdapter extends VariableLabelAdapter {
8164 [javac] ^^^^^^^^^^^^^^^^^^^^
8165 [javac] Discouraged access: The type VariableLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8166 [javac] ----------
8167 [javac] 407. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8168 [javac] (at line 38)
8169 [javac] protected String getValueText(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
8170 [javac] ^^^^^^^^^^^^^^^^^^^^
8171 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8172 [javac] ----------
8173 [javac] 408. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8174 [javac] (at line 40)
8175 [javac] return escapeSpecialChars(fLabelProvider.getFormattedValueText((IJavaValue) value));
8176 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8177 [javac] Discouraged access: The method escapeSpecialChars(String) from the type VariableLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8178 [javac] ----------
8179 [javac] 409. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8180 [javac] (at line 42)
8181 [javac] return super.getValueText(variable, value, context);
8182 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8183 [javac] Discouraged access: The method getValueText(IVariable, IValue, IPresentationContext) from the type VariableLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8184 [javac] ----------
8185 [javac] 410. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8186 [javac] (at line 48)
8187 [javac] protected String getValueTypeName(IVariable variable, IValue value, IPresentationContext context) throws CoreException {
8188 [javac] ^^^^^^^^^^^^^^^^^^^^
8189 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8190 [javac] ----------
8191 [javac] 411. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8192 [javac] (at line 62)
8193 [javac] protected String getVariableTypeName(IVariable variable, IPresentationContext context) throws CoreException {
8194 [javac] ^^^^^^^^^^^^^^^^^^^^
8195 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8196 [javac] ----------
8197 [javac] 412. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8198 [javac] (at line 73)
8199 [javac] private boolean isShowQualfiiedNames(IPresentationContext context) {
8200 [javac] ^^^^^^^^^^^^^^^^^^^^
8201 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8202 [javac] ----------
8203 [javac] 413. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8204 [javac] (at line 74)
8205 [javac] IWorkbenchPart part = context.getPart();
8206 [javac] ^^^^^^^^^^^^^^^^^
8207 [javac] Discouraged access: The method getPart() from the type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8208 [javac] ----------
8209 [javac] 414. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8210 [javac] (at line 84)
8211 [javac] protected String getColumnText(IVariable variable, IValue value, String columnId, IPresentationContext context) throws CoreException {
8212 [javac] ^^^^^^^^^^^^^^^^^^^^
8213 [javac] Discouraged access: The type IPresentationContext is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8214 [javac] ----------
8215 [javac] 415. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/variables/JavaVariableLabelAdapter.java
8216 [javac] (at line 95)
8217 [javac] return super.getColumnText(variable, value, columnId, context);
8218 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8219 [javac] Discouraged access: The method getColumnText(IVariable, IValue, String, IPresentationContext) from the type VariableLabelAdapter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8220 [javac] ----------
8221 [javac] 415 problems (415 warnings)
8222 [javac] ----------
8223 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/AntUtil.java
8224 [javac] (at line 601)
8225 [javac] mementos.add(homeEntry.getMemento());
8226 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8227 [javac] Discouraged access: The method getMemento() from the type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8228 [javac] ----------
8229 [javac] ----------
8230 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/ExternalHyperlink.java
8231 [javac] (at line 27)
8232 [javac] import org.eclipse.ui.internal.editors.text.JavaFileEditorInput;
8233 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8234 [javac] Discouraged access: The type JavaFileEditorInput is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8235 [javac] ----------
8236 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/ExternalHyperlink.java
8237 [javac] (at line 53)
8238 [javac] input = new JavaFileEditorInput(fileStore);
8239 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8240 [javac] Discouraged access: The constructor JavaFileEditorInput(IFileStore) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8241 [javac] ----------
8242 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/ExternalHyperlink.java
8243 [javac] (at line 53)
8244 [javac] input = new JavaFileEditorInput(fileStore);
8245 [javac] ^^^^^^^^^^^^^^^^^^^
8246 [javac] Discouraged access: The type JavaFileEditorInput is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8247 [javac] ----------
8248 [javac] ----------
8249 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/console/JavacMarkerCreator.java
8250 [javac] (at line 30)
8251 [javac] import org.eclipse.debug.internal.ui.views.console.ProcessConsole;
8252 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8253 [javac] Discouraged access: The type ProcessConsole is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8254 [javac] ----------
8255 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/console/JavacMarkerCreator.java
8256 [javac] (at line 74)
8257 [javac] if (fConsole instanceof ProcessConsole) {
8258 [javac] ^^^^^^^^^^^^^^
8259 [javac] Discouraged access: The type ProcessConsole is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8260 [javac] ----------
8261 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/console/JavacMarkerCreator.java
8262 [javac] (at line 75)
8263 [javac] fProcess= ((ProcessConsole) fConsole).getProcess();
8264 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8265 [javac] Discouraged access: The method getProcess() from the type ProcessConsole is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8266 [javac] ----------
8267 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/console/JavacMarkerCreator.java
8268 [javac] (at line 75)
8269 [javac] fProcess= ((ProcessConsole) fConsole).getProcess();
8270 [javac] ^^^^^^^^^^^^^^
8271 [javac] Discouraged access: The type ProcessConsole is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.debug.ui/@dot
8272 [javac] ----------
8273 [javac] ----------
8274 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugModelPresentation.java
8275 [javac] (at line 37)
8276 [javac] import org.eclipse.ui.internal.editors.text.JavaFileEditorInput;
8277 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8278 [javac] Discouraged access: The type JavaFileEditorInput is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8279 [javac] ----------
8280 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugModelPresentation.java
8281 [javac] (at line 155)
8282 [javac] return new JavaFileEditorInput(fileStore);
8283 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8284 [javac] Discouraged access: The constructor JavaFileEditorInput(IFileStore) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8285 [javac] ----------
8286 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugModelPresentation.java
8287 [javac] (at line 155)
8288 [javac] return new JavaFileEditorInput(fileStore);
8289 [javac] ^^^^^^^^^^^^^^^^^^^
8290 [javac] Discouraged access: The type JavaFileEditorInput is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ui.editors/@dot
8291 [javac] ----------
8292 [javac] ----------
8293 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8294 [javac] (at line 13)
8295 [javac] import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction;
8296 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8297 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8298 [javac] ----------
8299 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8300 [javac] (at line 14)
8301 [javac] import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
8302 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8303 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8304 [javac] ----------
8305 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8306 [javac] (at line 18)
8307 [javac] public class AddVariableStringAction extends RuntimeClasspathAction {
8308 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8309 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8310 [javac] ----------
8311 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8312 [javac] (at line 20)
8313 [javac] public AddVariableStringAction(IClasspathViewer viewer) {
8314 [javac] ^^^^^^^^^^^^^^^^
8315 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8316 [javac] ----------
8317 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8318 [javac] (at line 21)
8319 [javac] super(AntLaunchConfigurationMessages.AddVariableStringAction_1, viewer);
8320 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8321 [javac] Discouraged access: The constructor RuntimeClasspathAction(String, IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8322 [javac] ----------
8323 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8324 [javac] (at line 28)
8325 [javac] return ADD;
8326 [javac] ^^^
8327 [javac] Discouraged access: The field ADD from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8328 [javac] ----------
8329 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8330 [javac] (at line 35)
8331 [javac] VariableInputDialog inputDialog = new VariableInputDialog(getShell());
8332 [javac] ^^^^^^^^^^
8333 [javac] Discouraged access: The method getShell() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8334 [javac] ----------
8335 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8336 [javac] (at line 40)
8337 [javac] getViewer().addEntries(new IRuntimeClasspathEntry[] {newEntry});
8338 [javac] ^^^^^^^^^^^
8339 [javac] Discouraged access: The method getViewer() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8340 [javac] ----------
8341 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AddVariableStringAction.java
8342 [javac] (at line 40)
8343 [javac] getViewer().addEntries(new IRuntimeClasspathEntry[] {newEntry});
8344 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8345 [javac] Discouraged access: The method addEntries(IRuntimeClasspathEntry[]) from the type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8346 [javac] ----------
8347 [javac] ----------
8348 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8349 [javac] (at line 18)
8350 [javac] import org.eclipse.jdt.internal.debug.ui.actions.AddExternalJarAction;
8351 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8352 [javac] Discouraged access: The type AddExternalJarAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8353 [javac] ----------
8354 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8355 [javac] (at line 19)
8356 [javac] import org.eclipse.jdt.internal.debug.ui.actions.AddFolderAction;
8357 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8358 [javac] Discouraged access: The type AddFolderAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8359 [javac] ----------
8360 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8361 [javac] (at line 20)
8362 [javac] import org.eclipse.jdt.internal.debug.ui.actions.AddJarAction;
8363 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8364 [javac] Discouraged access: The type AddJarAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8365 [javac] ----------
8366 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8367 [javac] (at line 21)
8368 [javac] import org.eclipse.jdt.internal.debug.ui.actions.MoveDownAction;
8369 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8370 [javac] Discouraged access: The type MoveDownAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8371 [javac] ----------
8372 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8373 [javac] (at line 22)
8374 [javac] import org.eclipse.jdt.internal.debug.ui.actions.MoveUpAction;
8375 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8376 [javac] Discouraged access: The type MoveUpAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8377 [javac] ----------
8378 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8379 [javac] (at line 23)
8380 [javac] import org.eclipse.jdt.internal.debug.ui.actions.RemoveAction;
8381 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8382 [javac] Discouraged access: The type RemoveAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8383 [javac] ----------
8384 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8385 [javac] (at line 24)
8386 [javac] import org.eclipse.jdt.internal.debug.ui.actions.RestoreDefaultEntriesAction;
8387 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8388 [javac] Discouraged access: The type RestoreDefaultEntriesAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8389 [javac] ----------
8390 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8391 [javac] (at line 25)
8392 [javac] import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction;
8393 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8394 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8395 [javac] ----------
8396 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8397 [javac] (at line 26)
8398 [javac] import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathEntry;
8399 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8400 [javac] Discouraged access: The type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8401 [javac] ----------
8402 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8403 [javac] (at line 27)
8404 [javac] import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathModel;
8405 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8406 [javac] Discouraged access: The type ClasspathModel is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8407 [javac] ----------
8408 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8409 [javac] (at line 28)
8410 [javac] import org.eclipse.jdt.internal.debug.ui.classpath.IClasspathEntry;
8411 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8412 [javac] Discouraged access: The type IClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8413 [javac] ----------
8414 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8415 [javac] (at line 29)
8416 [javac] import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
8417 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8418 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8419 [javac] ----------
8420 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8421 [javac] (at line 54)
8422 [javac] createButton(pathButtonComp, new MoveUpAction(fClasspathViewer));
8423 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8424 [javac] Discouraged access: The constructor MoveUpAction(IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8425 [javac] ----------
8426 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8427 [javac] (at line 54)
8428 [javac] createButton(pathButtonComp, new MoveUpAction(fClasspathViewer));
8429 [javac] ^^^^^^^^^^^^
8430 [javac] Discouraged access: The type MoveUpAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8431 [javac] ----------
8432 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8433 [javac] (at line 55)
8434 [javac] createButton(pathButtonComp, new MoveDownAction(fClasspathViewer));
8435 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8436 [javac] Discouraged access: The constructor MoveDownAction(IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8437 [javac] ----------
8438 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8439 [javac] (at line 55)
8440 [javac] createButton(pathButtonComp, new MoveDownAction(fClasspathViewer));
8441 [javac] ^^^^^^^^^^^^^^
8442 [javac] Discouraged access: The type MoveDownAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8443 [javac] ----------
8444 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8445 [javac] (at line 56)
8446 [javac] createButton(pathButtonComp, new RemoveAction(fClasspathViewer));
8447 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8448 [javac] Discouraged access: The constructor RemoveAction(IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8449 [javac] ----------
8450 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8451 [javac] (at line 56)
8452 [javac] createButton(pathButtonComp, new RemoveAction(fClasspathViewer));
8453 [javac] ^^^^^^^^^^^^
8454 [javac] Discouraged access: The type RemoveAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8455 [javac] ----------
8456 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8457 [javac] (at line 57)
8458 [javac] createButton(pathButtonComp, new AddJarAction(fClasspathViewer));
8459 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8460 [javac] Discouraged access: The constructor AddJarAction(IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8461 [javac] ----------
8462 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8463 [javac] (at line 57)
8464 [javac] createButton(pathButtonComp, new AddJarAction(fClasspathViewer));
8465 [javac] ^^^^^^^^^^^^
8466 [javac] Discouraged access: The type AddJarAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8467 [javac] ----------
8468 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8469 [javac] (at line 58)
8470 [javac] createButton(pathButtonComp, new AddExternalJarAction(fClasspathViewer, DIALOG_SETTINGS_PREFIX));
8471 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8472 [javac] Discouraged access: The constructor AddExternalJarAction(IClasspathViewer, String) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8473 [javac] ----------
8474 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8475 [javac] (at line 58)
8476 [javac] createButton(pathButtonComp, new AddExternalJarAction(fClasspathViewer, DIALOG_SETTINGS_PREFIX));
8477 [javac] ^^^^^^^^^^^^^^^^^^^^
8478 [javac] Discouraged access: The type AddExternalJarAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8479 [javac] ----------
8480 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8481 [javac] (at line 59)
8482 [javac] Button button = createButton(pathButtonComp, new AddFolderAction(fClasspathViewer));
8483 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8484 [javac] Discouraged access: The constructor AddFolderAction(IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8485 [javac] ----------
8486 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8487 [javac] (at line 59)
8488 [javac] Button button = createButton(pathButtonComp, new AddFolderAction(fClasspathViewer));
8489 [javac] ^^^^^^^^^^^^^^^
8490 [javac] Discouraged access: The type AddFolderAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8491 [javac] ----------
8492 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8493 [javac] (at line 62)
8494 [javac] RuntimeClasspathAction action= new RestoreDefaultEntriesAction(fClasspathViewer, this);
8495 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8496 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8497 [javac] ----------
8498 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8499 [javac] (at line 62)
8500 [javac] RuntimeClasspathAction action= new RestoreDefaultEntriesAction(fClasspathViewer, this);
8501 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8502 [javac] Discouraged access: The constructor RestoreDefaultEntriesAction(IClasspathViewer, JavaClasspathTab) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8503 [javac] ----------
8504 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8505 [javac] (at line 62)
8506 [javac] RuntimeClasspathAction action= new RestoreDefaultEntriesAction(fClasspathViewer, this);
8507 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8508 [javac] Discouraged access: The type RestoreDefaultEntriesAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8509 [javac] ----------
8510 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8511 [javac] (at line 64)
8512 [javac] action.setEnabled(true);
8513 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
8514 [javac] Discouraged access: The method setEnabled(boolean) from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8515 [javac] ----------
8516 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8517 [javac] (at line 68)
8518 [javac] action.setEnabled(true);
8519 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
8520 [javac] Discouraged access: The method setEnabled(boolean) from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8521 [javac] ----------
8522 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8523 [javac] (at line 92)
8524 [javac] public void entriesChanged(IClasspathViewer viewer) {
8525 [javac] ^^^^^^^^^^^^^^^^
8526 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8527 [javac] ----------
8528 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8529 [javac] (at line 93)
8530 [javac] super.entriesChanged(viewer);
8531 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8532 [javac] Discouraged access: The method entriesChanged(IClasspathViewer) from the type AbstractJavaClasspathTab is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8533 [javac] ----------
8534 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8535 [javac] (at line 117)
8536 [javac] ClasspathModel model= getModel();
8537 [javac] ^^^^^^^^^^^^^^
8538 [javac] Discouraged access: The type ClasspathModel is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8539 [javac] ----------
8540 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8541 [javac] (at line 118)
8542 [javac] IClasspathEntry userEntry= model.getUserEntry();
8543 [javac] ^^^^^^^^^^^^^^^
8544 [javac] Discouraged access: The type IClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8545 [javac] ----------
8546 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8547 [javac] (at line 118)
8548 [javac] IClasspathEntry userEntry= model.getUserEntry();
8549 [javac] ^^^^^^^^^^^^^^^^^^^^
8550 [javac] Discouraged access: The method getUserEntry() from the type ClasspathModel is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8551 [javac] ----------
8552 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8553 [javac] (at line 119)
8554 [javac] IClasspathEntry[] entries= userEntry.getEntries();
8555 [javac] ^^^^^^^^^^^^^^^^^
8556 [javac] Discouraged access: The type IClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8557 [javac] ----------
8558 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8559 [javac] (at line 119)
8560 [javac] IClasspathEntry[] entries= userEntry.getEntries();
8561 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8562 [javac] Discouraged access: The method getEntries() from the type IClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8563 [javac] ----------
8564 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8565 [javac] (at line 121)
8566 [javac] ClasspathEntry entry = (ClasspathEntry) entries[i];
8567 [javac] ^^^^^^^^^^^^^^
8568 [javac] Discouraged access: The type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8569 [javac] ----------
8570 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8571 [javac] (at line 121)
8572 [javac] ClasspathEntry entry = (ClasspathEntry) entries[i];
8573 [javac] ^^^^^^^^^^^^^^
8574 [javac] Discouraged access: The type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8575 [javac] ----------
8576 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java
8577 [javac] (at line 122)
8578 [javac] IRuntimeClasspathEntry runtimeEntry= entry.getDelegate();
8579 [javac] ^^^^^^^^^^^^^^^^^^^
8580 [javac] Discouraged access: The method getDelegate() from the type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8581 [javac] ----------
8582 [javac] ----------
8583 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntHomeClasspathEntry.java
8584 [javac] (at line 25)
8585 [javac] import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
8586 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8587 [javac] Discouraged access: The type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8588 [javac] ----------
8589 [javac] 61. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntHomeClasspathEntry.java
8590 [javac] (at line 37)
8591 [javac] public class AntHomeClasspathEntry extends AbstractRuntimeClasspathEntry {
8592 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8593 [javac] Discouraged access: The type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8594 [javac] ----------
8595 [javac] 62. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntHomeClasspathEntry.java
8596 [javac] (at line 128)
8597 [javac] abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_10, new String[] {antHomeLocation}), null);
8598 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8599 [javac] Discouraged access: The method abort(String, Throwable) from the type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8600 [javac] ----------
8601 [javac] 63. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntHomeClasspathEntry.java
8602 [javac] (at line 131)
8603 [javac] abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_11, new String[] {antHomeLocation}), null);
8604 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8605 [javac] Discouraged access: The method abort(String, Throwable) from the type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8606 [javac] ----------
8607 [javac] ----------
8608 [javac] 64. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8609 [javac] (at line 23)
8610 [javac] import org.eclipse.jdt.internal.debug.ui.jres.JREDescriptor;
8611 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8612 [javac] Discouraged access: The type JREDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8613 [javac] ----------
8614 [javac] 65. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8615 [javac] (at line 24)
8616 [javac] import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
8617 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8618 [javac] Discouraged access: The type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8619 [javac] ----------
8620 [javac] 66. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8621 [javac] (at line 38)
8622 [javac] private VMArgumentsBlock fVMArgumentsBlock= new VMArgumentsBlock();
8623 [javac] ^^^^^^^^^^^^^^^^
8624 [javac] Discouraged access: The type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8625 [javac] ----------
8626 [javac] 67. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8627 [javac] (at line 38)
8628 [javac] private VMArgumentsBlock fVMArgumentsBlock= new VMArgumentsBlock();
8629 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8630 [javac] Discouraged access: The constructor VMArgumentsBlock() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8631 [javac] ----------
8632 [javac] 68. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8633 [javac] (at line 38)
8634 [javac] private VMArgumentsBlock fVMArgumentsBlock= new VMArgumentsBlock();
8635 [javac] ^^^^^^^^^^^^^^^^
8636 [javac] Discouraged access: The type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8637 [javac] ----------
8638 [javac] 69. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8639 [javac] (at line 47)
8640 [javac] Composite comp= (Composite)fJREBlock.getControl();
8641 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8642 [javac] Discouraged access: The method getControl() from the type JREsComboBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8643 [javac] ----------
8644 [javac] 70. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8645 [javac] (at line 51)
8646 [javac] fVMArgumentsBlock.createControl(comp);
8647 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8648 [javac] Discouraged access: The method createControl(Composite) from the type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8649 [javac] ----------
8650 [javac] 71. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8651 [javac] (at line 54)
8652 [javac] fWorkingDirectoryBlock.createControl(comp);
8653 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8654 [javac] Discouraged access: The method createControl(Composite) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8655 [javac] ----------
8656 [javac] 72. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8657 [javac] (at line 61)
8658 [javac] protected JREDescriptor getDefaultJREDescriptor() {
8659 [javac] ^^^^^^^^^^^^^
8660 [javac] Discouraged access: The type JREDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8661 [javac] ----------
8662 [javac] 73. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8663 [javac] (at line 62)
8664 [javac] return new JREDescriptor() {
8665 [javac] ^^^^^^^^^^^^^
8666 [javac] Discouraged access: The type JREDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8667 [javac] ----------
8668 [javac] 74. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8669 [javac] (at line 75)
8670 [javac] protected JREDescriptor getSpecificJREDescriptor() {
8671 [javac] ^^^^^^^^^^^^^
8672 [javac] Discouraged access: The type JREDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8673 [javac] ----------
8674 [javac] 75. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8675 [javac] (at line 76)
8676 [javac] return new JREDescriptor() {
8677 [javac] ^^^^^^^^^^^^^
8678 [javac] Discouraged access: The type JREDescriptor is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8679 [javac] ----------
8680 [javac] 76. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8681 [javac] (at line 90)
8682 [javac] boolean isDefaultJRE = fJREBlock.isDefaultJRE();
8683 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8684 [javac] Discouraged access: The method isDefaultJRE() from the type JREsComboBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8685 [javac] ----------
8686 [javac] 77. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8687 [javac] (at line 92)
8688 [javac] fVMArgumentsBlock.setEnabled(!isDefaultJRE);
8689 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8690 [javac] Discouraged access: The method setEnabled(boolean) from the type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8691 [javac] ----------
8692 [javac] 78. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8693 [javac] (at line 110)
8694 [javac] fVMArgumentsBlock.performApply(configuration);
8695 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8696 [javac] Discouraged access: The method performApply(ILaunchConfigurationWorkingCopy) from the type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8697 [javac] ----------
8698 [javac] 79. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8699 [javac] (at line 111)
8700 [javac] fWorkingDirectoryBlock.performApply(configuration);
8701 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8702 [javac] Discouraged access: The method performApply(ILaunchConfigurationWorkingCopy) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8703 [javac] ----------
8704 [javac] 80. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8705 [javac] (at line 133)
8706 [javac] IVMInstall vm= fJREBlock.getJRE();
8707 [javac] ^^^^^^^^^^^^^^^^^^
8708 [javac] Discouraged access: The method getJRE() from the type JREsComboBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8709 [javac] ----------
8710 [javac] 81. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8711 [javac] (at line 203)
8712 [javac] fVMArgumentsBlock.initializeFrom(configuration);
8713 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8714 [javac] Discouraged access: The method initializeFrom(ILaunchConfiguration) from the type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8715 [javac] ----------
8716 [javac] 82. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8717 [javac] (at line 205)
8718 [javac] boolean separateVM= !fJREBlock.isDefaultJRE();
8719 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8720 [javac] Discouraged access: The method isDefaultJRE() from the type JREsComboBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8721 [javac] ----------
8722 [javac] 83. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8723 [javac] (at line 207)
8724 [javac] fVMArgumentsBlock.setEnabled(separateVM);
8725 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8726 [javac] Discouraged access: The method setEnabled(boolean) from the type VMArgumentsBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8727 [javac] ----------
8728 [javac] 84. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java
8729 [javac] (at line 214)
8730 [javac] return super.isValid(config) && fWorkingDirectoryBlock.isValid(config);
8731 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8732 [javac] Discouraged access: The method isValid(ILaunchConfiguration) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8733 [javac] ----------
8734 [javac] ----------
8735 [javac] 85. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8736 [javac] (at line 18)
8737 [javac] import org.eclipse.jdt.internal.debug.ui.launcher.WorkingDirectoryBlock;
8738 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8739 [javac] Discouraged access: The type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8740 [javac] ----------
8741 [javac] 86. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8742 [javac] (at line 23)
8743 [javac] public class AntWorkingDirectoryBlock extends WorkingDirectoryBlock {
8744 [javac] ^^^^^^^^^^^^^^^^^^^^^
8745 [javac] Discouraged access: The type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8746 [javac] ----------
8747 [javac] 87. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8748 [javac] (at line 40)
8749 [javac] super.setDefaultWorkingDir();
8750 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8751 [javac] Discouraged access: The method setDefaultWorkingDir() from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8752 [javac] ----------
8753 [javac] 88. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8754 [javac] (at line 43)
8755 [javac] setDefaultWorkingDirectoryText(fDefaultWorkingDirPath);
8756 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8757 [javac] Discouraged access: The method setDefaultWorkingDirectoryText(String) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8758 [javac] ----------
8759 [javac] 89. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8760 [javac] (at line 50)
8761 [javac] setLaunchConfiguration(configuration);
8762 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8763 [javac] Discouraged access: The method setLaunchConfiguration(ILaunchConfiguration) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8764 [javac] ----------
8765 [javac] 90. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8766 [javac] (at line 59)
8767 [javac] setOtherWorkingDirectoryText(wd);
8768 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8769 [javac] Discouraged access: The method setOtherWorkingDirectoryText(String) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8770 [javac] ----------
8771 [javac] 91. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java
8772 [javac] (at line 75)
8773 [javac] super.setEnabled(enabled);
8774 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^
8775 [javac] Discouraged access: The method setEnabled(boolean) from the type WorkingDirectoryBlock is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8776 [javac] ----------
8777 [javac] ----------
8778 [javac] 92. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/ContributedClasspathEntriesEntry.java
8779 [javac] (at line 33)
8780 [javac] import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
8781 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8782 [javac] Discouraged access: The type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8783 [javac] ----------
8784 [javac] 93. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/ContributedClasspathEntriesEntry.java
8785 [javac] (at line 48)
8786 [javac] public class ContributedClasspathEntriesEntry extends AbstractRuntimeClasspathEntry {
8787 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8788 [javac] Discouraged access: The type AbstractRuntimeClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.launching/@dot
8789 [javac] ----------
8790 [javac] ----------
8791 [javac] 94. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8792 [javac] (at line 19)
8793 [javac] import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction;
8794 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8795 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8796 [javac] ----------
8797 [javac] 95. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8798 [javac] (at line 20)
8799 [javac] import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathEntry;
8800 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8801 [javac] Discouraged access: The type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8802 [javac] ----------
8803 [javac] 96. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8804 [javac] (at line 21)
8805 [javac] import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
8806 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8807 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8808 [javac] ----------
8809 [javac] 97. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8810 [javac] (at line 33)
8811 [javac] public class EditAntHomeEntryAction extends RuntimeClasspathAction {
8812 [javac] ^^^^^^^^^^^^^^^^^^^^^^
8813 [javac] Discouraged access: The type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8814 [javac] ----------
8815 [javac] 98. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8816 [javac] (at line 41)
8817 [javac] public EditAntHomeEntryAction(IClasspathViewer viewer, AntClasspathTab tab) {
8818 [javac] ^^^^^^^^^^^^^^^^
8819 [javac] Discouraged access: The type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8820 [javac] ----------
8821 [javac] 99. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8822 [javac] (at line 42)
8823 [javac] super(AntLaunchConfigurationMessages.EditAntHomeEntryAction_1, viewer);
8824 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8825 [javac] Discouraged access: The constructor RuntimeClasspathAction(String, IClasspathViewer) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8826 [javac] ----------
8827 [javac] 100. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8828 [javac] (at line 56)
8829 [javac] DirectoryDialog dialog = new DirectoryDialog(getShell());
8830 [javac] ^^^^^^^^^^
8831 [javac] Discouraged access: The method getShell() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8832 [javac] ----------
8833 [javac] 101. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8834 [javac] (at line 71)
8835 [javac] IRuntimeClasspathEntry[] entries = getViewer().getEntries();
8836 [javac] ^^^^^^^^^^^
8837 [javac] Discouraged access: The method getViewer() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8838 [javac] ----------
8839 [javac] 102. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8840 [javac] (at line 71)
8841 [javac] IRuntimeClasspathEntry[] entries = getViewer().getEntries();
8842 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8843 [javac] Discouraged access: The method getEntries() from the type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8844 [javac] ----------
8845 [javac] 103. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8846 [javac] (at line 75)
8847 [javac] IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2)((ClasspathEntry)entry).getDelegate();
8848 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8849 [javac] Discouraged access: The method getDelegate() from the type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8850 [javac] ----------
8851 [javac] 104. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8852 [javac] (at line 75)
8853 [javac] IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2)((ClasspathEntry)entry).getDelegate();
8854 [javac] ^^^^^^^^^^^^^^
8855 [javac] Discouraged access: The type ClasspathEntry is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8856 [javac] ----------
8857 [javac] 105. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8858 [javac] (at line 78)
8859 [javac] getViewer().refresh(entry);
8860 [javac] ^^^^^^^^^^^
8861 [javac] Discouraged access: The method getViewer() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8862 [javac] ----------
8863 [javac] 106. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8864 [javac] (at line 78)
8865 [javac] getViewer().refresh(entry);
8866 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^
8867 [javac] Discouraged access: The method refresh(Object) from the type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8868 [javac] ----------
8869 [javac] 107. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8870 [javac] (at line 79)
8871 [javac] getViewer().notifyChanged();
8872 [javac] ^^^^^^^^^^^
8873 [javac] Discouraged access: The method getViewer() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8874 [javac] ----------
8875 [javac] 108. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8876 [javac] (at line 79)
8877 [javac] getViewer().notifyChanged();
8878 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
8879 [javac] Discouraged access: The method notifyChanged() from the type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8880 [javac] ----------
8881 [javac] 109. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8882 [javac] (at line 85)
8883 [javac] getViewer().addEntries(new IRuntimeClasspathEntry[]{new AntHomeClasspathEntry(path)});
8884 [javac] ^^^^^^^^^^^
8885 [javac] Discouraged access: The method getViewer() from the type RuntimeClasspathAction is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8886 [javac] ----------
8887 [javac] 110. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java
8888 [javac] (at line 85)
8889 [javac] getViewer().addEntries(new IRuntimeClasspathEntry[]{new AntHomeClasspathEntry(path)});
8890 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8891 [javac] Discouraged access: The method addEntries(IRuntimeClasspathEntry[]) from the type IClasspathViewer is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8892 [javac] ----------
8893 [javac] ----------
8894 [javac] 111. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
8895 [javac] (at line 34)
8896 [javac] import org.eclipse.jdt.internal.debug.ui.actions.ArchiveFilter;
8897 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8898 [javac] Discouraged access: The type ArchiveFilter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8899 [javac] ----------
8900 [javac] 112. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
8901 [javac] (at line 289)
8902 [javac] ViewerFilter filter= new ArchiveFilter(allEntries);
8903 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8904 [javac] Discouraged access: The constructor ArchiveFilter(List) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8905 [javac] ----------
8906 [javac] 113. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntClasspathBlock.java
8907 [javac] (at line 289)
8908 [javac] ViewerFilter filter= new ArchiveFilter(allEntries);
8909 [javac] ^^^^^^^^^^^^^
8910 [javac] Discouraged access: The type ArchiveFilter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.debug.ui/@dot
8911 [javac] ----------
8912 [javac] ----------
8913 [javac] 114. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/derived/HTML2TextReader.java
8914 [javac] (at line 30)
8915 [javac] * @see org.eclipse.jdt.internal.ui.text.HTML2TextReader
8916 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8917 [javac] Discouraged access: The type HTML2TextReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
8918 [javac] ----------
8919 [javac] ----------
8920 [javac] 115. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/derived/HTMLPrinter.java
8921 [javac] (at line 21)
8922 [javac] * @see org.eclipse.jdt.internal.ui.text.HTMLPrinter
8923 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8924 [javac] Discouraged access: The type HTMLPrinter is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
8925 [javac] ----------
8926 [javac] ----------
8927 [javac] 116. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/derived/LineBreakingReader.java
8928 [javac] (at line 22)
8929 [javac] * @see org.eclipse.jdt.internal.ui.text.LineBreakingReader
8930 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8931 [javac] Discouraged access: The type LineBreakingReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
8932 [javac] ----------
8933 [javac] ----------
8934 [javac] 117. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/derived/SingleCharReader.java
8935 [javac] (at line 18)
8936 [javac] * @see org.eclipse.jdt.internal.corext.javadoc.SingleCharReader
8937 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8938 [javac] Discouraged access: The type SingleCharReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
8939 [javac] ----------
8940 [javac] ----------
8941 [javac] 118. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/derived/SubstitutionTextReader.java
8942 [javac] (at line 24)
8943 [javac] * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader
8944 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8945 [javac] Discouraged access: The type SubstitutionTextReader is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
8946 [javac] ----------
8947 [javac] 118 problems (118 warnings)
8948 [javac] ----------
8949 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8950 [javac] (at line 23)
8951 [javac] import org.eclipse.update.internal.core.FeatureExecutableFactory;
8952 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8953 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8954 [javac] ----------
8955 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8956 [javac] (at line 415)
8957 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8958 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8959 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8960 [javac] ----------
8961 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8962 [javac] (at line 415)
8963 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8964 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8965 [javac] Discouraged access: The constructor FeatureExecutableFactory() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8966 [javac] ----------
8967 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8968 [javac] (at line 415)
8969 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8970 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8971 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8972 [javac] ----------
8973 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8974 [javac] (at line 419)
8975 [javac] feature = factory.createFeature(featureLocation.toURL(), null, null);
8976 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8977 [javac] Discouraged access: The method createFeature(URL, ISite, IProgressMonitor) from the type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8978 [javac] ----------
8979 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8980 [javac] (at line 459)
8981 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8982 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8983 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8984 [javac] ----------
8985 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8986 [javac] (at line 459)
8987 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8988 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8989 [javac] Discouraged access: The constructor FeatureExecutableFactory() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8990 [javac] ----------
8991 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8992 [javac] (at line 459)
8993 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
8994 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
8995 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
8996 [javac] ----------
8997 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/FetchScriptGenerator.java
8998 [javac] (at line 461)
8999 [javac] feature = factory.createFeature(featureFolder.toURL(), null, null);
9000 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9001 [javac] Discouraged access: The method createFeature(URL, ISite, IProgressMonitor) from the type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9002 [javac] ----------
9003 [javac] ----------
9004 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9005 [javac] (at line 18)
9006 [javac] import org.eclipse.core.internal.runtime.PlatformURLFragmentConnection;
9007 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9008 [javac] Discouraged access: The type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9009 [javac] ----------
9010 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9011 [javac] (at line 19)
9012 [javac] import org.eclipse.core.internal.runtime.PlatformURLPluginConnection;
9013 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9014 [javac] Discouraged access: The type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9015 [javac] ----------
9016 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9017 [javac] (at line 265)
9018 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN))
9019 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9020 [javac] Discouraged access: The type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9021 [javac] ----------
9022 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9023 [javac] (at line 265)
9024 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN))
9025 [javac] ^^^^^^
9026 [javac] Discouraged access: The field PLUGIN from the type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9027 [javac] ----------
9028 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9029 [javac] (at line 268)
9030 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9031 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9032 [javac] Discouraged access: The type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9033 [javac] ----------
9034 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer2_1.java
9035 [javac] (at line 268)
9036 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9037 [javac] ^^^^^^^^
9038 [javac] Discouraged access: The field FRAGMENT from the type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9039 [javac] ----------
9040 [javac] ----------
9041 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9042 [javac] (at line 19)
9043 [javac] import org.eclipse.core.internal.runtime.PlatformURLFragmentConnection;
9044 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9045 [javac] Discouraged access: The type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9046 [javac] ----------
9047 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9048 [javac] (at line 20)
9049 [javac] import org.eclipse.core.internal.runtime.PlatformURLPluginConnection;
9050 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9051 [javac] Discouraged access: The type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9052 [javac] ----------
9053 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9054 [javac] (at line 421)
9055 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN) || urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9056 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9057 [javac] Discouraged access: The type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9058 [javac] ----------
9059 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9060 [javac] (at line 421)
9061 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN) || urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9062 [javac] ^^^^^^
9063 [javac] Discouraged access: The field PLUGIN from the type PlatformURLPluginConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9064 [javac] ----------
9065 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9066 [javac] (at line 421)
9067 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN) || urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9068 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9069 [javac] Discouraged access: The type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9070 [javac] ----------
9071 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/ClasspathComputer3_0.java
9072 [javac] (at line 421)
9073 [javac] if (urlfragments[1].equalsIgnoreCase(PlatformURLPluginConnection.PLUGIN) || urlfragments[1].equalsIgnoreCase(PlatformURLFragmentConnection.FRAGMENT))
9074 [javac] ^^^^^^^^
9075 [javac] Discouraged access: The field FRAGMENT from the type PlatformURLFragmentConnection is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.equinox.common/@dot
9076 [javac] ----------
9077 [javac] ----------
9078 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9079 [javac] (at line 21)
9080 [javac] import org.eclipse.update.internal.core.FeatureExecutableContentProvider;
9081 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9082 [javac] Discouraged access: The type FeatureExecutableContentProvider is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9083 [javac] ----------
9084 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9085 [javac] (at line 22)
9086 [javac] import org.eclipse.update.internal.core.URLEncoder;
9087 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9088 [javac] Discouraged access: The type URLEncoder is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9089 [javac] ----------
9090 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9091 [javac] (at line 40)
9092 [javac] IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(url);
9093 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9094 [javac] Discouraged access: The constructor FeatureExecutableContentProvider(URL) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9095 [javac] ----------
9096 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9097 [javac] (at line 40)
9098 [javac] IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(url);
9099 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9100 [javac] Discouraged access: The type FeatureExecutableContentProvider is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9101 [javac] ----------
9102 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9103 [javac] (at line 43)
9104 [javac] URL resolvedURL = URLEncoder.encode(nonResolvedURL);
9105 [javac] ^^^^^^^^^^
9106 [javac] Discouraged access: The type URLEncoder is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9107 [javac] ----------
9108 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9109 [javac] (at line 43)
9110 [javac] URL resolvedURL = URLEncoder.encode(nonResolvedURL);
9111 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9112 [javac] Discouraged access: The method encode(URL) from the type URLEncoder is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9113 [javac] ----------
9114 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9115 [javac] (at line 88)
9116 [javac] IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(null);
9117 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9118 [javac] Discouraged access: The constructor FeatureExecutableContentProvider(URL) is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9119 [javac] ----------
9120 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/site/BuildTimeFeatureFactory.java
9121 [javac] (at line 88)
9122 [javac] IFeatureContentProvider contentProvider = new FeatureExecutableContentProvider(null);
9123 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9124 [javac] Discouraged access: The type FeatureExecutableContentProvider is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9125 [javac] ----------
9126 [javac] ----------
9127 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9128 [javac] (at line 224)
9129 [javac] int IRDE_StartOffset = imageResourceDirectoryOffset + IMAGE_RESOURCE_DIRECTORY.SIZEOF;
9130 [javac] ^^^^^^^^^^^^^^^^
9131 [javac] The local variable IRDE_StartOffset is never read
9132 [javac] ----------
9133 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9134 [javac] (at line 2462)
9135 [javac] TYPE_GENERIC_8 = 0,
9136 [javac] ^^^^^^^^^^^^^^
9137 [javac] The field IconExe.ImageData.TYPE_GENERIC_8 is never read locally
9138 [javac] ----------
9139 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9140 [javac] (at line 2463)
9141 [javac] TYPE_GENERIC_16_MSB = 1,
9142 [javac] ^^^^^^^^^^^^^^^^^^^
9143 [javac] The field IconExe.ImageData.TYPE_GENERIC_16_MSB is never read locally
9144 [javac] ----------
9145 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9146 [javac] (at line 2464)
9147 [javac] TYPE_GENERIC_16_LSB = 2,
9148 [javac] ^^^^^^^^^^^^^^^^^^^
9149 [javac] The field IconExe.ImageData.TYPE_GENERIC_16_LSB is never read locally
9150 [javac] ----------
9151 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9152 [javac] (at line 2465)
9153 [javac] TYPE_GENERIC_24 = 3,
9154 [javac] ^^^^^^^^^^^^^^^
9155 [javac] The field IconExe.ImageData.TYPE_GENERIC_24 is never read locally
9156 [javac] ----------
9157 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9158 [javac] (at line 2466)
9159 [javac] TYPE_GENERIC_32_MSB = 4,
9160 [javac] ^^^^^^^^^^^^^^^^^^^
9161 [javac] The field IconExe.ImageData.TYPE_GENERIC_32_MSB is never read locally
9162 [javac] ----------
9163 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9164 [javac] (at line 2467)
9165 [javac] TYPE_GENERIC_32_LSB = 5,
9166 [javac] ^^^^^^^^^^^^^^^^^^^
9167 [javac] The field IconExe.ImageData.TYPE_GENERIC_32_LSB is never read locally
9168 [javac] ----------
9169 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9170 [javac] (at line 2469)
9171 [javac] TYPE_INDEX_8 = 6,
9172 [javac] ^^^^^^^^^^^^
9173 [javac] The field IconExe.ImageData.TYPE_INDEX_8 is never read locally
9174 [javac] ----------
9175 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9176 [javac] (at line 2470)
9177 [javac] TYPE_INDEX_4 = 7,
9178 [javac] ^^^^^^^^^^^^
9179 [javac] The field IconExe.ImageData.TYPE_INDEX_4 is never read locally
9180 [javac] ----------
9181 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9182 [javac] (at line 2471)
9183 [javac] TYPE_INDEX_2 = 8,
9184 [javac] ^^^^^^^^^^^^
9185 [javac] The field IconExe.ImageData.TYPE_INDEX_2 is never read locally
9186 [javac] ----------
9187 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9188 [javac] (at line 2472)
9189 [javac] TYPE_INDEX_1_MSB = 9,
9190 [javac] ^^^^^^^^^^^^^^^^
9191 [javac] The field IconExe.ImageData.TYPE_INDEX_1_MSB is never read locally
9192 [javac] ----------
9193 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9194 [javac] (at line 2473)
9195 [javac] TYPE_INDEX_1_LSB = 10;
9196 [javac] ^^^^^^^^^^^^^^^^
9197 [javac] The field IconExe.ImageData.TYPE_INDEX_1_LSB is never read locally
9198 [javac] ----------
9199 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9200 [javac] (at line 2984)
9201 [javac] int xPelsPerMeter = (infoHeader[24] & 0xFF) | ((infoHeader[25] & 0xFF) << 8) | ((infoHeader[26] & 0xFF) << 16) | ((infoHeader[27] & 0xFF) << 24);
9202 [javac] ^^^^^^^^^^^^^
9203 [javac] The local variable xPelsPerMeter is never read
9204 [javac] ----------
9205 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src/org/eclipse/swt/tools/internal/IconExe.java
9206 [javac] (at line 2985)
9207 [javac] int yPelsPerMeter = (infoHeader[28] & 0xFF) | ((infoHeader[29] & 0xFF) << 8) | ((infoHeader[30] & 0xFF) << 16) | ((infoHeader[31] & 0xFF) << 24);
9208 [javac] ^^^^^^^^^^^^^
9209 [javac] The local variable yPelsPerMeter is never read
9210 [javac] ----------
9211 [javac] 43 problems (43 warnings)
9212 [javac] ----------
9213 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildManifestTask.java
9214 [javac] (at line 22)
9215 [javac] import org.eclipse.update.internal.core.FeatureExecutableFactory;
9216 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9217 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9218 [javac] ----------
9219 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildManifestTask.java
9220 [javac] (at line 192)
9221 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
9222 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
9223 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9224 [javac] ----------
9225 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildManifestTask.java
9226 [javac] (at line 192)
9227 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
9228 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9229 [javac] Discouraged access: The constructor FeatureExecutableFactory() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9230 [javac] ----------
9231 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildManifestTask.java
9232 [javac] (at line 192)
9233 [javac] FeatureExecutableFactory factory = new FeatureExecutableFactory();
9234 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^
9235 [javac] Discouraged access: The type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9236 [javac] ----------
9237 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildManifestTask.java
9238 [javac] (at line 193)
9239 [javac] return (Feature) factory.createFeature(root.toFile().toURL(), null, null);
9240 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9241 [javac] Discouraged access: The method createFeature(URL, ISite, IProgressMonitor) from the type FeatureExecutableFactory is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.update.core/@dot
9242 [javac] ----------
9243 [javac] 5 problems (5 warnings)
9244 [javac] ----------
9245 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9246 [javac] (at line 19)
9247 [javac] import org.eclipse.jdt.internal.junit.runner.RemoteTestRunner;
9248 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9249 [javac] Discouraged access: The type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9250 [javac] ----------
9251 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9252 [javac] (at line 25)
9253 [javac] public class RemotePluginTestRunner extends RemoteTestRunner {
9254 [javac] ^^^^^^^^^^^^^^^^
9255 [javac] Discouraged access: The type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9256 [javac] ----------
9257 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9258 [javac] (at line 52)
9259 [javac] * @see RemoteTestRunner
9260 [javac] ^^^^^^^^^^^^^^^^
9261 [javac] Discouraged access: The type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9262 [javac] ----------
9263 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9264 [javac] (at line 58)
9265 [javac] testRunner.run();
9266 [javac] ^^^^^^^^^^^^^^^^
9267 [javac] Discouraged access: The method run() from the type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9268 [javac] ----------
9269 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9270 [javac] (at line 63)
9271 [javac] * @see RemoteTestRunner#getTestClassLoader()
9272 [javac] ^^^^^^^^^^^^^^^^
9273 [javac] Discouraged access: The type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9274 [javac] ----------
9275 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9276 [javac] (at line 63)
9277 [javac] * @see RemoteTestRunner#getTestClassLoader()
9278 [javac] ^^^^^^^^^^^^^^^^^^^^
9279 [javac] Discouraged access: The method getTestClassLoader() from the type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9280 [javac] ----------
9281 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.junit.runtime/src/org/eclipse/pde/internal/junit/runtime/RemotePluginTestRunner.java
9282 [javac] (at line 79)
9283 [javac] defaultInit(args);
9284 [javac] ^^^^^^^^^^^^^^^^^
9285 [javac] Discouraged access: The method defaultInit(String[]) from the type RemoteTestRunner is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit.runtime/junitruntime.jar
9286 [javac] ----------
9287 [javac] 7 problems (7 warnings)
9288 [javac] ----------
9289 [javac] 1. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9290 [javac] (at line 18)
9291 [javac] import org.eclipse.ant.internal.ui.IAntUIConstants;
9292 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9293 [javac] Discouraged access: The type IAntUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9294 [javac] ----------
9295 [javac] 2. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9296 [javac] (at line 19)
9297 [javac] import org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchShortcut;
9298 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9299 [javac] Discouraged access: The type AntLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9300 [javac] ----------
9301 [javac] 3. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9302 [javac] (at line 20)
9303 [javac] import org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants;
9304 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9305 [javac] Discouraged access: The type IAntLaunchConfigurationConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9306 [javac] ----------
9307 [javac] 4. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9308 [javac] (at line 176)
9309 [javac] List configs = AntLaunchShortcut
9310 [javac] ^^^^^^^^^^^^^^^^^
9311 [javac] Discouraged access: The type AntLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9312 [javac] ----------
9313 [javac] 5. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9314 [javac] (at line 176)
9315 [javac] List configs = AntLaunchShortcut
9316 [javac] .findExistingLaunchConfigurations(generatedFile);
9317 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9318 [javac] Discouraged access: The method findExistingLaunchConfigurations(IFile) from the type AntLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9319 [javac] ----------
9320 [javac] 6. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9321 [javac] (at line 180)
9322 [javac] ILaunchConfiguration config = AntLaunchShortcut
9323 [javac] ^^^^^^^^^^^^^^^^^
9324 [javac] Discouraged access: The type AntLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9325 [javac] ----------
9326 [javac] 7. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9327 [javac] (at line 180)
9328 [javac] ILaunchConfiguration config = AntLaunchShortcut
9329 [javac] .createDefaultLaunchConfiguration(generatedFile);
9330 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9331 [javac] Discouraged access: The method createDefaultLaunchConfiguration(IFile) from the type AntLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9332 [javac] ----------
9333 [javac] 8. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9334 [javac] (at line 192)
9335 [javac] IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES,
9336 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9337 [javac] Discouraged access: The type IAntLaunchConfigurationConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9338 [javac] ----------
9339 [javac] 9. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9340 [javac] (at line 192)
9341 [javac] IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES,
9342 [javac] ^^^^^^^^^^^^^^^^^^^
9343 [javac] Discouraged access: The field ATTR_ANT_PROPERTIES from the type IAntLaunchConfigurationConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9344 [javac] ----------
9345 [javac] 10. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9346 [javac] (at line 224)
9347 [javac] IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES,
9348 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9349 [javac] Discouraged access: The type IAntLaunchConfigurationConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9350 [javac] ----------
9351 [javac] 11. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9352 [javac] (at line 224)
9353 [javac] IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES,
9354 [javac] ^^^^^^^^^^^^^^^^^^^
9355 [javac] Discouraged access: The field ATTR_ANT_PROPERTIES from the type IAntLaunchConfigurationConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9356 [javac] ----------
9357 [javac] 12. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9358 [javac] (at line 239)
9359 [javac] IAntUIConstants.ATTR_DEFAULT_VM_INSTALL,
9360 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9361 [javac] Discouraged access: The type IAntUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9362 [javac] ----------
9363 [javac] 13. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/build/BaseBuildAction.java
9364 [javac] (at line 239)
9365 [javac] IAntUIConstants.ATTR_DEFAULT_VM_INSTALL,
9366 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
9367 [javac] Discouraged access: The field ATTR_DEFAULT_VM_INSTALL from the type IAntUIConstants is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.ant.ui/@dot
9368 [javac] ----------
9369 [javac] ----------
9370 [javac] 14. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java
9371 [javac] (at line 12)
9372 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
9373 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9374 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9375 [javac] ----------
9376 [javac] 15. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java
9377 [javac] (at line 77)
9378 [javac] IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
9379 [javac] ^^^^^^^^^^
9380 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9381 [javac] ----------
9382 [javac] 16. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java
9383 [javac] (at line 77)
9384 [javac] IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
9385 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
9386 [javac] Discouraged access: The method getDefault() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9387 [javac] ----------
9388 [javac] 17. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java
9389 [javac] (at line 77)
9390 [javac] IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
9391 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9392 [javac] Discouraged access: The method getCombinedPreferenceStore() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9393 [javac] ----------
9394 [javac] ----------
9395 [javac] 18. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java
9396 [javac] (at line 17)
9397 [javac] import org.eclipse.jdt.internal.ui.JavaPlugin;
9398 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9399 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9400 [javac] ----------
9401 [javac] 19. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java
9402 [javac] (at line 73)
9403 [javac] pstore = JavaPlugin.getDefault().getCombinedPreferenceStore();
9404 [javac] ^^^^^^^^^^
9405 [javac] Discouraged access: The type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9406 [javac] ----------
9407 [javac] 20. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java
9408 [javac] (at line 73)
9409 [javac] pstore = JavaPlugin.getDefault().getCombinedPreferenceStore();
9410 [javac] ^^^^^^^^^^^^^^^^^^^^^^^
9411 [javac] Discouraged access: The method getDefault() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9412 [javac] ----------
9413 [javac] 21. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ColorManager.java
9414 [javac] (at line 73)
9415 [javac] pstore = JavaPlugin.getDefault().getCombinedPreferenceStore();
9416 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9417 [javac] Discouraged access: The method getCombinedPreferenceStore() from the type JavaPlugin is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.ui/@dot
9418 [javac] ----------
9419 [javac] ----------
9420 [javac] 22. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9421 [javac] (at line 36)
9422 [javac] import org.eclipse.jdt.internal.junit.launcher.JUnitBaseLaunchConfiguration;
9423 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9424 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9425 [javac] ----------
9426 [javac] 23. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9427 [javac] (at line 37)
9428 [javac] import org.eclipse.jdt.internal.junit.launcher.TestSearchResult;
9429 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9430 [javac] Discouraged access: The type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9431 [javac] ----------
9432 [javac] 24. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9433 [javac] (at line 66)
9434 [javac] public class JUnitLaunchConfiguration extends JUnitBaseLaunchConfiguration {
9435 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9436 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9437 [javac] ----------
9438 [javac] 25. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9439 [javac] (at line 83)
9440 [javac] TestSearchResult testSearchResult = findTestTypes(configuration, monitor);
9441 [javac] ^^^^^^^^^^^^^^^^
9442 [javac] Discouraged access: The type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9443 [javac] ----------
9444 [javac] 26. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9445 [javac] (at line 83)
9446 [javac] TestSearchResult testSearchResult = findTestTypes(configuration, monitor);
9447 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9448 [javac] Discouraged access: The method findTestTypes(ILaunchConfiguration, IProgressMonitor) from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9449 [javac] ----------
9450 [javac] 27. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9451 [javac] (at line 84)
9452 [javac] IType[] testTypes = testSearchResult.getTypes();
9453 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
9454 [javac] Discouraged access: The method getTypes() from the type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9455 [javac] ----------
9456 [javac] 28. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9457 [javac] (at line 109)
9458 [javac] launch.setAttribute(PORT_ATTR, Integer.toString(port));
9459 [javac] ^^^^^^^^^
9460 [javac] Discouraged access: The field PORT_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9461 [javac] ----------
9462 [javac] 29. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9463 [javac] (at line 110)
9464 [javac] launch.setAttribute(TESTTYPE_ATTR, testTypes[0].getHandleIdentifier());
9465 [javac] ^^^^^^^^^^^^^
9466 [javac] Discouraged access: The field TESTTYPE_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9467 [javac] ----------
9468 [javac] 30. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9469 [javac] (at line 133)
9470 [javac] TestSearchResult testTypes,
9471 [javac] ^^^^^^^^^^^^^^^^
9472 [javac] Discouraged access: The type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9473 [javac] ----------
9474 [javac] 31. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9475 [javac] (at line 179)
9476 [javac] TestSearchResult testSearchResult,
9477 [javac] ^^^^^^^^^^^^^^^^
9478 [javac] Discouraged access: The type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9479 [javac] ----------
9480 [javac] 32. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9481 [javac] (at line 212)
9482 [javac] programArgs.addAll(getBasicArguments(configuration, port, runMode, testSearchResult));
9483 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9484 [javac] Discouraged access: The method getBasicArguments(ILaunchConfiguration, int, String, TestSearchResult) from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9485 [javac] ----------
9486 [javac] 33. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9487 [javac] (at line 295)
9488 [javac] programArgs.add(testSearchResult.getTestKind().getLoaderPluginId());
9489 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9490 [javac] Discouraged access: The method getTestKind() from the type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9491 [javac] ----------
9492 [javac] 34. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9493 [javac] (at line 295)
9494 [javac] programArgs.add(testSearchResult.getTestKind().getLoaderPluginId());
9495 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9496 [javac] Discouraged access: The method getLoaderPluginId() from the type ITestKind is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9497 [javac] ----------
9498 [javac] 35. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9499 [javac] (at line 297)
9500 [javac] String testFailureNames = configuration.getAttribute(JUnitBaseLaunchConfiguration.FAILURES_FILENAME_ATTR, ""); //$NON-NLS-1$
9501 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9502 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9503 [javac] ----------
9504 [javac] 36. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9505 [javac] (at line 297)
9506 [javac] String testFailureNames = configuration.getAttribute(JUnitBaseLaunchConfiguration.FAILURES_FILENAME_ATTR, ""); //$NON-NLS-1$
9507 [javac] ^^^^^^^^^^^^^^^^^^^^^^
9508 [javac] Discouraged access: The field FAILURES_FILENAME_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9509 [javac] ----------
9510 [javac] 37. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9511 [javac] (at line 304)
9512 [javac] IType[] testTypes = testSearchResult.getTypes();
9513 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
9514 [javac] Discouraged access: The method getTypes() from the type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9515 [javac] ----------
9516 [javac] 38. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9517 [javac] (at line 306)
9518 [javac] configuration.getAttribute(JUnitBaseLaunchConfiguration.TESTNAME_ATTR, ""); //$NON-NLS-1$
9519 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9520 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9521 [javac] ----------
9522 [javac] 39. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9523 [javac] (at line 306)
9524 [javac] configuration.getAttribute(JUnitBaseLaunchConfiguration.TESTNAME_ATTR, ""); //$NON-NLS-1$
9525 [javac] ^^^^^^^^^^^^^
9526 [javac] Discouraged access: The field TESTNAME_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9527 [javac] ----------
9528 [javac] 40. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9529 [javac] (at line 318)
9530 [javac] protected IPluginModelBase[] addRequiredPlugins(Map pluginMap, TestSearchResult result)
9531 [javac] ^^^^^^^^^^^^^^^^
9532 [javac] Discouraged access: The type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9533 [javac] ----------
9534 [javac] 41. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9535 [javac] (at line 323)
9536 [javac] addRequiredPlugin(pluginMap, result.getTestKind().getLoaderPluginId());
9537 [javac] ^^^^^^^^^^^^^^^^^^^^
9538 [javac] Discouraged access: The method getTestKind() from the type TestSearchResult is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9539 [javac] ----------
9540 [javac] 42. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitLaunchConfiguration.java
9541 [javac] (at line 323)
9542 [javac] addRequiredPlugin(pluginMap, result.getTestKind().getLoaderPluginId());
9543 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9544 [javac] Discouraged access: The method getLoaderPluginId() from the type ITestKind is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9545 [javac] ----------
9546 [javac] ----------
9547 [javac] 43. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9548 [javac] (at line 16)
9549 [javac] import org.eclipse.jdt.internal.junit.launcher.AssertionVMArg;
9550 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9551 [javac] Discouraged access: The type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9552 [javac] ----------
9553 [javac] 44. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9554 [javac] (at line 17)
9555 [javac] import org.eclipse.jdt.internal.junit.launcher.JUnitMainTab;
9556 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9557 [javac] Discouraged access: The type JUnitMainTab is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9558 [javac] ----------
9559 [javac] 45. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9560 [javac] (at line 32)
9561 [javac] new JUnitMainTab(),
9562 [javac] ^^^^^^^^^^^^^^^^^^
9563 [javac] Discouraged access: The constructor JUnitMainTab() is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9564 [javac] ----------
9565 [javac] 46. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9566 [javac] (at line 32)
9567 [javac] new JUnitMainTab(),
9568 [javac] ^^^^^^^^^^^^
9569 [javac] Discouraged access: The type JUnitMainTab is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9570 [javac] ----------
9571 [javac] 47. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9572 [javac] (at line 55)
9573 [javac] vmArgs = AssertionVMArg.enableAssertInArgString(vmArgs);
9574 [javac] ^^^^^^^^^^^^^^
9575 [javac] Discouraged access: The type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9576 [javac] ----------
9577 [javac] 48. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitTabGroup.java
9578 [javac] (at line 55)
9579 [javac] vmArgs = AssertionVMArg.enableAssertInArgString(vmArgs);
9580 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9581 [javac] Discouraged access: The method enableAssertInArgString(String) from the type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9582 [javac] ----------
9583 [javac] ----------
9584 [javac] 49. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9585 [javac] (at line 21)
9586 [javac] import org.eclipse.jdt.internal.junit.launcher.AssertionVMArg;
9587 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9588 [javac] Discouraged access: The type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9589 [javac] ----------
9590 [javac] 50. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9591 [javac] (at line 22)
9592 [javac] import org.eclipse.jdt.internal.junit.launcher.JUnitBaseLaunchConfiguration;
9593 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9594 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9595 [javac] ----------
9596 [javac] 51. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9597 [javac] (at line 23)
9598 [javac] import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchShortcut;
9599 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9600 [javac] Discouraged access: The type JUnitLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9601 [javac] ----------
9602 [javac] 52. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9603 [javac] (at line 31)
9604 [javac] public class JUnitWorkbenchShortcut extends JUnitLaunchShortcut {
9605 [javac] ^^^^^^^^^^^^^^^^^^^
9606 [javac] Discouraged access: The type JUnitLaunchShortcut is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9607 [javac] ----------
9608 [javac] 53. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9609 [javac] (at line 67)
9610 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.ATTR_KEEPRUNNING, false);
9611 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9612 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9613 [javac] ----------
9614 [javac] 54. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9615 [javac] (at line 67)
9616 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.ATTR_KEEPRUNNING, false);
9617 [javac] ^^^^^^^^^^^^^^^^
9618 [javac] Discouraged access: The field ATTR_KEEPRUNNING from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9619 [javac] ----------
9620 [javac] 55. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9621 [javac] (at line 68)
9622 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.LAUNCH_CONTAINER_ATTR, container);
9623 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9624 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9625 [javac] ----------
9626 [javac] 56. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9627 [javac] (at line 68)
9628 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.LAUNCH_CONTAINER_ATTR, container);
9629 [javac] ^^^^^^^^^^^^^^^^^^^^^
9630 [javac] Discouraged access: The field LAUNCH_CONTAINER_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9631 [javac] ----------
9632 [javac] 57. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9633 [javac] (at line 70)
9634 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.TESTNAME_ATTR, testName);
9635 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9636 [javac] Discouraged access: The type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9637 [javac] ----------
9638 [javac] 58. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9639 [javac] (at line 70)
9640 [javac] wc.setAttribute(JUnitBaseLaunchConfiguration.TESTNAME_ATTR, testName);
9641 [javac] ^^^^^^^^^^^^^
9642 [javac] Discouraged access: The field TESTNAME_ATTR from the type JUnitBaseLaunchConfiguration is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9643 [javac] ----------
9644 [javac] 59. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9645 [javac] (at line 80)
9646 [javac] AssertionVMArg.setArgDefault(wc);
9647 [javac] ^^^^^^^^^^^^^^
9648 [javac] Discouraged access: The type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9649 [javac] ----------
9650 [javac] 60. WARNING in /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/JUnitWorkbenchShortcut.java
9651 [javac] (at line 80)
9652 [javac] AssertionVMArg.setArgDefault(wc);
9653 [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9654 [javac] Discouraged access: The method setArgDefault(ILaunchConfigurationWorkingCopy) from the type AssertionVMArg is not accessible due to restriction on classpath entry /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.jdt.junit/junitsupport.jar
9655 [javac] ----------
9656 [javac] 60 problems (60 warnings)
9657 [echo] Assembling...
9658 [subant] Failure for target 'pre.gather.bin.parts' of: /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.platform.doc.user/customBuildCallbacks.xml
9659 [subant] The following error occurred while executing this line:
9660 [subant] Target `pre.gather.bin.parts' does not exist in this project.
9661 [subant] Failure for target 'pre.gather.bin.parts' of: /volatile/portage/eclipse-sdk-3.2/work/plugins/org.eclipse.platform.doc.isv/customBuildCallbacks.xml
9662 [subant] The following error occurred while executing this line:
9663 [subant] Target `pre.gather.bin.parts' does not exist in this project.
9664 [java] [exec] Result: 1
9665 [java] [exec] Result: 1
9666 [java] [exec] Result: 1
9667 [echo] Done.
9668
9669 BUILD SUCCESSFUL
9670 Total time: 61 minutes 0 seconds
9671 >>> Source compiled.
9672 >>> Test phase [not enabled]: dev-util/eclipse-sdk-3.2
9673
9674 >>> Install eclipse-sdk-3.2 into /volatile/portage/eclipse-sdk-3.2/image/ category dev-util
9675 doexe: warning, skipping directory eclipse
9676 >>> Completed installing eclipse-sdk-3.2 into /volatile/portage/eclipse-sdk-3.2/image/
9677
9678 man:
9679
9680 QA Notice: pre-stripped files found:
9681 /volatile/portage/eclipse-sdk-3.2/image/usr/lib/eclipse-3.2/libcairo-swt.so
9682 strip: i686-pc-linux-gnu-strip --strip-unneeded
9683 usr/lib/eclipse-3.2/eclipse
9684 * Users can now install plugins via Update Manager without any
9685 * tweaking.
9686
9687 * Eclipse plugin packages (ie eclipse-cdt) will likely go away in
9688 * the near future until they can be properly packaged. Update Manager
9689 * is prefered in the meantime.
0 /*
1 * Copyright (C) 2007, 2008, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly;
11
12 import com.thoughtworks.xstream.InitializationException;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
15 import com.thoughtworks.xstream.io.xml.XppDriver;
16 import com.thoughtworks.xstream.tools.benchmark.Harness;
17 import com.thoughtworks.xstream.tools.benchmark.Reporter;
18 import com.thoughtworks.xstream.tools.benchmark.metrics.CharacterCountMetric;
19 import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
20 import com.thoughtworks.xstream.tools.benchmark.metrics.SerializationSpeedMetric;
21 import com.thoughtworks.xstream.tools.benchmark.metrics.SizeMetric;
22 import com.thoughtworks.xstream.tools.benchmark.reporters.HtmlReporter;
23 import com.thoughtworks.xstream.tools.benchmark.reporters.MultiReporter;
24 import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
25 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.CachingIterativeAppenderWithShortcut;
26 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.CombinedLookupAppender;
27 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.CombinedLookupReplacer;
28 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.IterativeAppender;
29 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.IterativeAppenderWithShortcut;
30 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.IterativeReplacer;
31 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.NoReplacer;
32 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products.SeparateLookupReplacer;
33 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.targets.Field$Reflection;
34 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.targets.Field_Reflection;
35 import com.thoughtworks.xstream.tools.model.targets.FieldReflection;
36
37 import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40
41 import java.io.File;
42 import java.io.FileWriter;
43 import java.io.IOException;
44 import java.lang.reflect.Constructor;
45 import java.lang.reflect.InvocationTargetException;
46
47
48 /**
49 * Main application to run harness for Reflection benchmark.
50 *
51 * @author J&ouml;rg Schaible
52 */
53 public class XmlFriendlyBenchmark extends TestSuite {
54
55 public static class __ {
56 public static class UnfriendlyClass {
57 String __a__$$a__;
58 String b__b__;
59 String __c__c;
60
61 public boolean equals(Object obj) {
62 UnfriendlyClass other = (UnfriendlyClass)obj;
63 return __a__$$a__.equals(other.__a__$$a__)
64 && b__b__.equals(other.b__b__)
65 && __c__c.equals(other.__c__c);
66 }
67
68 }
69 }
70
71 private static Class currentType;
72
73 public static class ReplacerTest extends TestCase {
74
75 private final Class type;
76
77 public ReplacerTest(String name) {
78 super(name);
79 type = currentType;
80 }
81
82 public String getName() {
83 return type.getName() + ": " + super.getName();
84 }
85
86 public void testReplacerWithDefaultReplacements() {
87 String xml = ""
88 + "<com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-_____-UnfriendlyClass>\n"
89 + " <____a_____-_-a____>a</____a_____-_-a____>\n"
90 + " <b____b____>b</b____b____>\n"
91 + " <____c____c>c</____c____c>\n"
92 + "</com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-_____-UnfriendlyClass>";
93 performTest("_-", "__", getReference(), xml);
94 }
95
96 public void testReplacerWithDollarReplacementOnly() {
97 String xml = ""
98 + "<com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-___-UnfriendlyClass>\n"
99 + " <__a___-_-a__>a</__a___-_-a__>\n"
100 + " <b__b__>b</b__b__>\n"
101 + " <__c__c>c</__c__c>\n"
102 + "</com.thoughtworks.xstream.benchmark.xmlfriendly.XmlFriendlyBenchmark_-___-UnfriendlyClass>";
103 performTest("_-", "_", getReference(), xml);
104 }
105
106 private void performTest(String dollar, String underscore, __.UnfriendlyClass object,
107 String xml) {
108 XStream xstream = createXStreamWithReplacer(dollar, underscore);
109 assertEquals(xml, xstream.toXML(object));
110 assertEquals(object, xstream.fromXML(xml));
111 }
112
113 private __.UnfriendlyClass getReference() {
114 __.UnfriendlyClass ref = new __.UnfriendlyClass();
115 ref.__a__$$a__ = "a";
116 ref.b__b__ = "b";
117 ref.__c__c = "c";
118 return ref;
119 }
120
121 private XStream createXStreamWithReplacer(String dollar, String underscore) {
122 Exception ex;
123 try {
124 Constructor constructor = type.getConstructor(new Class[]{
125 String.class, String.class, int.class});
126 XmlFriendlyReplacer replacer = (XmlFriendlyReplacer)constructor
127 .newInstance(new Object[]{dollar, underscore, new Integer(0)});
128 return new XStream(new XppDriver(replacer));
129 } catch (NoSuchMethodException e) {
130 ex = e;
131 } catch (InstantiationException e) {
132 ex = e;
133 } catch (IllegalAccessException e) {
134 ex = e;
135 } catch (InvocationTargetException e) {
136 ex = e;
137 }
138 throw new InitializationException("Cannot initialize XmlFriendlyReplacer", ex);
139 }
140 }
141
142 XmlFriendlyBenchmark() {
143 addTestSuite(CombinedLookupReplacer.XmlFriendlyReplacer.class);
144 addTestSuite(CombinedLookupAppender.XmlFriendlyReplacer.class);
145 addTestSuite(SeparateLookupReplacer.XmlFriendlyReplacer.class);
146 addTestSuite(IterativeReplacer.XmlFriendlyReplacer.class);
147 addTestSuite(IterativeAppender.XmlFriendlyReplacer.class);
148 addTestSuite(IterativeAppenderWithShortcut.XmlFriendlyReplacer.class);
149 addTestSuite(CachingIterativeAppenderWithShortcut.XmlFriendlyReplacer.class);
150 }
151
152 public void addTestSuite(Class replacerClass) {
153 currentType = replacerClass;
154 super.addTestSuite(ReplacerTest.class);
155 }
156
157 public static Test suite() {
158 // Ensure the different implementations work
159 return new XmlFriendlyBenchmark();
160 }
161
162 public static void main(String[] args) {
163 new File("target/benchmarks").mkdirs();
164
165 Reporter[] reporters;
166 try {
167 String basename = "target/benchmarks/xmlfriendly-"
168 + System.getProperty("user.name");
169 reporters = new Reporter[]{
170 new TextReporter(), new TextReporter(new FileWriter(basename + ".txt")),
171 new HtmlReporter(new File(basename + ".html"), "XmlFriendlyReplacer Benchmark")};
172 } catch (IOException e) {
173 throw new RuntimeException(e);
174 }
175
176 Harness stats = new Harness();
177 stats.addMetric(new SizeMetric());
178 stats.addMetric(new CharacterCountMetric('$'));
179 stats.addMetric(new CharacterCountMetric('_'));
180 stats.addProduct(new NoReplacer());
181 stats.addTarget(new FieldReflection());
182 stats.addTarget(new Field_Reflection());
183 stats.addTarget(new Field$Reflection());
184 stats.run(new MultiReporter(reporters) {
185
186 public void endBenchmark() {
187 // do nothing
188 }
189
190 });
191
192 Harness harness = new Harness();
193 harness.addMetric(new SerializationSpeedMetric(100));
194 harness.addMetric(new DeserializationSpeedMetric(100, false));
195 harness.addProduct(new CombinedLookupReplacer(0));
196 // harness.addProduct(new CombinedLookupReplacer(32));
197 harness.addProduct(new CombinedLookupAppender(0));
198 // harness.addProduct(new CombinedLookupAppender(32));
199 harness.addProduct(new SeparateLookupReplacer(0));
200 // harness.addProduct(new SeparateLookupReplacer(32));
201 harness.addProduct(new IterativeReplacer(0));
202 // harness.addProduct(new IterativeReplacer(32));
203 harness.addProduct(new IterativeAppender(0));
204 // harness.addProduct(new IterativeAppender(32));
205 harness.addProduct(new IterativeAppenderWithShortcut());
206 harness.addProduct(new CachingIterativeAppenderWithShortcut());
207 harness.addTarget(new FieldReflection());
208 harness.addTarget(new Field_Reflection());
209 harness.addTarget(new Field$Reflection());
210 harness.run(new MultiReporter(reporters) {
211
212 public void startBenchmark() {
213 // do nothing
214 }
215
216 });
217 }
218 }
0 /*
1 * Copyright (C) 2007, 2009 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 14. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.model;
11
12 /**
13 * Class with 100 fields containing each 5 dollars in the name.
14 *
15 * @author J&ouml;rg Schaible
16 */
17 public class A100$Fields {
18
19 String $$$$$000;
20 String $$$$$001;
21 String $$$$$002;
22 String $$$$$003;
23 String $$$$$004;
24 String $$$$$005;
25 String $$$$$006;
26 String $$$$$007;
27 String $$$$$008;
28 String $$$$$009;
29 String $$$$$010;
30 String $$$$$011;
31 String $$$$$012;
32 String $$$$$013;
33 String $$$$$014;
34 String $$$$$015;
35 String $$$$$016;
36 String $$$$$017;
37 String $$$$$018;
38 String $$$$$019;
39 String $$$$$020;
40 String $$$$$021;
41 String $$$$$022;
42 String $$$$$023;
43 String $$$$$024;
44 String $$$$$025;
45 String $$$$$026;
46 String $$$$$027;
47 String $$$$$028;
48 String $$$$$029;
49 String $$$$$030;
50 String $$$$$031;
51 String $$$$$032;
52 String $$$$$033;
53 String $$$$$034;
54 String $$$$$035;
55 String $$$$$036;
56 String $$$$$037;
57 String $$$$$038;
58 String $$$$$039;
59 String $$$$$040;
60 String $$$$$041;
61 String $$$$$042;
62 String $$$$$043;
63 String $$$$$044;
64 String $$$$$045;
65 String $$$$$046;
66 String $$$$$047;
67 String $$$$$048;
68 String $$$$$049;
69 String $$$$$050;
70 String $$$$$051;
71 String $$$$$052;
72 String $$$$$053;
73 String $$$$$054;
74 String $$$$$055;
75 String $$$$$056;
76 String $$$$$057;
77 String $$$$$058;
78 String $$$$$059;
79 String $$$$$060;
80 String $$$$$061;
81 String $$$$$062;
82 String $$$$$063;
83 String $$$$$064;
84 String $$$$$065;
85 String $$$$$066;
86 String $$$$$067;
87 String $$$$$068;
88 String $$$$$069;
89 String $$$$$070;
90 String $$$$$071;
91 String $$$$$072;
92 String $$$$$073;
93 String $$$$$074;
94 String $$$$$075;
95 String $$$$$076;
96 String $$$$$077;
97 String $$$$$078;
98 String $$$$$079;
99 String $$$$$080;
100 String $$$$$081;
101 String $$$$$082;
102 String $$$$$083;
103 String $$$$$084;
104 String $$$$$085;
105 String $$$$$086;
106 String $$$$$087;
107 String $$$$$088;
108 String $$$$$089;
109 String $$$$$090;
110 String $$$$$091;
111 String $$$$$092;
112 String $$$$$093;
113 String $$$$$094;
114 String $$$$$095;
115 String $$$$$096;
116 String $$$$$097;
117 String $$$$$098;
118 String $$$$$099;
119 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.model;
11
12 /**
13 * Class with 100 fields containing each 5 underscores in the name.
14 *
15 * @author J&ouml;rg Schaible
16 */
17 public class A100_Fields {
18
19 String _____000;
20 String _____001;
21 String _____002;
22 String _____003;
23 String _____004;
24 String _____005;
25 String _____006;
26 String _____007;
27 String _____008;
28 String _____009;
29 String _____010;
30 String _____011;
31 String _____012;
32 String _____013;
33 String _____014;
34 String _____015;
35 String _____016;
36 String _____017;
37 String _____018;
38 String _____019;
39 String _____020;
40 String _____021;
41 String _____022;
42 String _____023;
43 String _____024;
44 String _____025;
45 String _____026;
46 String _____027;
47 String _____028;
48 String _____029;
49 String _____030;
50 String _____031;
51 String _____032;
52 String _____033;
53 String _____034;
54 String _____035;
55 String _____036;
56 String _____037;
57 String _____038;
58 String _____039;
59 String _____040;
60 String _____041;
61 String _____042;
62 String _____043;
63 String _____044;
64 String _____045;
65 String _____046;
66 String _____047;
67 String _____048;
68 String _____049;
69 String _____050;
70 String _____051;
71 String _____052;
72 String _____053;
73 String _____054;
74 String _____055;
75 String _____056;
76 String _____057;
77 String _____058;
78 String _____059;
79 String _____060;
80 String _____061;
81 String _____062;
82 String _____063;
83 String _____064;
84 String _____065;
85 String _____066;
86 String _____067;
87 String _____068;
88 String _____069;
89 String _____070;
90 String _____071;
91 String _____072;
92 String _____073;
93 String _____074;
94 String _____075;
95 String _____076;
96 String _____077;
97 String _____078;
98 String _____079;
99 String _____080;
100 String _____081;
101 String _____082;
102 String _____083;
103 String _____084;
104 String _____085;
105 String _____086;
106 String _____087;
107 String _____088;
108 String _____089;
109 String _____090;
110 String _____091;
111 String _____092;
112 String _____093;
113 String _____094;
114 String _____095;
115 String _____096;
116 String _____097;
117 String _____098;
118 String _____099;
119 }
0 /*
1 * Copyright (C) 2007, 2008, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
13
14 import java.lang.ref.WeakReference;
15 import java.util.Map;
16 import java.util.WeakHashMap;
17
18
19 /**
20 * Abstract base class for the XmlFriendlyReplacer with all kind of implementations.
21 *
22 * @author J&ouml;rg Schaible
23 * @author Mauro Talevi
24 * @author Tatu Saloranta
25 */
26 public abstract class AbstractXmlFriendlyReplacer extends XmlFriendlyReplacer {
27
28 private final String dollarReplacement;
29 private final String underscoreReplacement;
30 private final int bufferIncrement;
31 private final Map escapeCache;
32 private final Map unescapeCache;
33
34 /**
35 * Creates an XmlFriendlyReplacer with custom replacements
36 *
37 * @param dollarReplacement the replacement for '$'
38 * @param underscoreReplacement the replacement for '_'
39 * @param bufferIncrement buffer increment for preallocation
40 */
41 public AbstractXmlFriendlyReplacer(
42 final String dollarReplacement, final String underscoreReplacement,
43 final int bufferIncrement) {
44 this.dollarReplacement = dollarReplacement;
45 this.underscoreReplacement = underscoreReplacement;
46 this.bufferIncrement = bufferIncrement;
47 escapeCache = new WeakHashMap();
48 unescapeCache = new WeakHashMap();
49 }
50
51 /**
52 * Escapes name substituting '$' and '_' with replacement strings
53 *
54 * @param name the name of attribute or node
55 * @return The String with the escaped name
56 */
57 public abstract String escapeName(String name);
58
59 /**
60 * Escapes name substituting '$' and '_' with replacement strings
61 *
62 * @param name the name of attribute or node
63 * @return The String with the escaped name
64 */
65 public abstract String unescapeName(String name);
66
67 protected String escapeNoName(final String name) {
68 return name;
69 }
70
71 protected String unescapeNoName(final String name) {
72 return name;
73 }
74
75 protected String escapeIterativelyAppending(final String name) {
76 final int length = name.length();
77 final StringBuffer result = bufferIncrement == 0
78 ? new StringBuffer()
79 : new StringBuffer(length + bufferIncrement);
80 for (int i = 0; i < length; i++) {
81 final char c = name.charAt(i);
82 if (c == '$') {
83 result.append(dollarReplacement);
84 } else if (c == '_') {
85 result.append(underscoreReplacement);
86 } else {
87 result.append(c);
88 }
89 }
90 return result.toString();
91 }
92
93 protected String unescapeIterativelyAppending(final String name) {
94 final int underscoreReplacementInc = underscoreReplacement.length() - 1;
95 final int dollarReplacementInc = dollarReplacement.length() - 1;
96 final int length = name.length();
97 final StringBuffer result = bufferIncrement == 0
98 ? new StringBuffer()
99 : new StringBuffer(length + bufferIncrement);
100 for (int i = 0; i < length; i++) {
101 final char c = name.charAt(i);
102 if (name.startsWith(dollarReplacement, i)) {
103 i += dollarReplacementInc;
104 result.append('$');
105 } else if (name.startsWith(underscoreReplacement, i)) {
106 i += underscoreReplacementInc;
107 result.append('_');
108 } else {
109 result.append(c);
110 }
111 }
112 return result.toString();
113 }
114
115 protected String escapeByCombinedLookupAppending(final String name) {
116 final int length = name.length();
117 final StringBuffer result = bufferIncrement == 0
118 ? new StringBuffer()
119 : new StringBuffer(length + bufferIncrement);
120 int posDollar = 0;
121 int posUnderscore = 0;
122 for (int i = 0; i < length;) {
123 if (posUnderscore >= 0) {
124 posUnderscore = name.indexOf('_', i);
125 }
126 if (posDollar >= 0) {
127 posDollar = name.indexOf('$', i);
128 }
129 if (posDollar == -1 && posUnderscore == -1) {
130 if (i < length) {
131 result.append(name.substring(i));
132 }
133 break;
134 } else if (posDollar >= 0 && (posUnderscore == -1 || posUnderscore >= posDollar)) {
135 result.append(name.substring(i, posDollar));
136 result.append(dollarReplacement);
137 i = posDollar + 1;
138 } else if (posUnderscore >= 0) {
139 result.append(name.substring(i, posUnderscore));
140 result.append(underscoreReplacement);
141 i = posUnderscore + 1;
142 }
143 }
144 return result.toString();
145 }
146
147 protected String unescapeByCombinedLookupAppending(final String name) {
148 final int underscoreReplacementLength = underscoreReplacement.length();
149 final int dollarReplacementLength = dollarReplacement.length();
150 final int length = name.length();
151 final StringBuffer result = bufferIncrement == 0
152 ? new StringBuffer()
153 : new StringBuffer(length + bufferIncrement);
154 int posDollar = 0;
155 int posUnderscore = 0;
156 for (int i = 0; i < length;) {
157 if (posUnderscore >= 0) {
158 posUnderscore = name.indexOf(underscoreReplacement, i);
159 }
160 if (posDollar >= 0) {
161 posDollar = name.indexOf(dollarReplacement, i);
162 }
163 if (posDollar == -1 && posUnderscore == -1) {
164 if (i < length) {
165 result.append(name.substring(i));
166 }
167 break;
168 } else if (posDollar >= 0 && (posUnderscore == -1 || posUnderscore >= posDollar)) {
169 result.append(name.substring(i, posDollar));
170 result.append('$');
171 i = posDollar + dollarReplacementLength;
172 } else if (posUnderscore >= 0) {
173 result.append(name.substring(i, posUnderscore));
174 result.append('_');
175 i = posUnderscore + underscoreReplacementLength;
176 }
177 }
178 return result.toString();
179 }
180
181 protected String escapeByCombinedLookupReplacing(final String name) {
182 final int underscoreReplacementLength = underscoreReplacement.length();
183 final int dollarReplacementLength = dollarReplacement.length();
184 final StringBuffer result;
185 if (bufferIncrement == 0) {
186 result = new StringBuffer(name);
187 } else {
188 result = new StringBuffer(name.length() + bufferIncrement);
189 result.append(name);
190 }
191 int posDollar = 0;
192 int posUnderscore = 0;
193 int i = 0;
194 while (true) {
195 if (posUnderscore >= 0) {
196 posUnderscore = result.indexOf("_", i);
197 }
198 if (posDollar >= 0) {
199 posDollar = result.indexOf("$", i);
200 }
201 if (posDollar == -1 && posUnderscore == -1) {
202 break;
203 } else if (posDollar >= 0 && (posUnderscore == -1 || posUnderscore > posDollar)) {
204 result.replace(posDollar, posDollar + 1, dollarReplacement);
205 i = posDollar + dollarReplacementLength;
206 } else if (posUnderscore >= 0) {
207 result.replace(posUnderscore, posUnderscore + 1, underscoreReplacement);
208 i = posUnderscore + underscoreReplacementLength;
209 }
210 }
211 return result.toString();
212 }
213
214 protected String unescapeByCombinedLookupReplacing(final String name) {
215 final int underscoreReplacementLength = underscoreReplacement.length();
216 final int dollarReplacementLength = dollarReplacement.length();
217 final StringBuffer result;
218 if (bufferIncrement == 0) {
219 result = new StringBuffer(name);
220 } else {
221 result = new StringBuffer(name.length() + bufferIncrement);
222 result.append(name);
223 }
224 int posDollar = 0;
225 int posUnderscore = 0;
226 int i = 0;
227 while (true) {
228 if (posUnderscore >= 0) {
229 posUnderscore = result.indexOf(underscoreReplacement, i);
230 }
231 if (posDollar >= 0) {
232 posDollar = result.indexOf(dollarReplacement, i);
233 }
234 if (posDollar == -1 && posUnderscore == -1) {
235 break;
236 } else if (posDollar >= 0 && (posUnderscore == -1 || posUnderscore >= posDollar)) {
237 result.replace(posDollar, posDollar + dollarReplacementLength, "$");
238 i = posDollar + 1;
239 } else if (posUnderscore >= 0) {
240 result.replace(posUnderscore, posUnderscore + underscoreReplacementLength, "_");
241 i = posUnderscore + 1;
242 }
243 }
244 return result.toString();
245 }
246
247 protected String escapeBySeparateLookupReplacing(final String name) {
248 final StringBuffer result;
249 if (bufferIncrement == 0) {
250 result = new StringBuffer(name);
251 } else {
252 result = new StringBuffer(name.length() + bufferIncrement);
253 result.append(name);
254 }
255 final int underscoreReplacementInc = underscoreReplacement.length();
256 final int dollarReplacementInc = dollarReplacement.length();
257 int inc = 0;
258 int pos = 0;
259
260 while ((pos = result.indexOf("_", pos + inc)) != -1) {
261 result.replace(pos, pos + 1, underscoreReplacement);
262 inc = underscoreReplacementInc;
263 }
264
265 inc = 0;
266 pos = 0;
267 while ((pos = result.indexOf("$", pos + inc)) != -1) {
268 result.replace(pos, pos + 1, dollarReplacement);
269 inc = dollarReplacementInc;
270 }
271 return result.toString();
272 }
273
274 protected String unescapeBySeparateLookupReplacing(final String name) {
275 final StringBuffer result;
276 if (bufferIncrement == 0) {
277 result = new StringBuffer(name);
278 } else {
279 result = new StringBuffer(name.length() + bufferIncrement);
280 result.append(name);
281 }
282 int dollarReplacementLength = dollarReplacement.length();
283 int pos = -dollarReplacementLength;
284 while ((pos = result.indexOf(dollarReplacement, pos + 1)) != -1) {
285 result.replace(pos, pos + dollarReplacementLength, "$");
286 }
287
288 int underscoreReplacementLength = underscoreReplacement.length();
289 pos = -underscoreReplacementLength;
290
291 while ((pos = result.indexOf(underscoreReplacement, pos + 1)) != -1) {
292 result.replace(pos, pos + underscoreReplacementLength, "_");
293 }
294
295 return result.toString();
296 }
297
298 protected String escapeIterativelyReplacing(final String name) {
299 int length = name.length();
300 final int underscoreReplacementInc = underscoreReplacement.length() - 1;
301 final int dollarReplacementInc = dollarReplacement.length() - 1;
302 final StringBuffer result;
303 if (bufferIncrement == 0) {
304 result = new StringBuffer(name);
305 } else {
306 result = new StringBuffer(length + bufferIncrement);
307 result.append(name);
308 }
309 for (int i = 0; i < length; i++) {
310 final char c = result.charAt(i);
311 if (c == '$') {
312 result.replace(i, i + 1, dollarReplacement);
313 length += dollarReplacementInc;
314 i += dollarReplacementInc;
315 } else if (c == '_') {
316 result.replace(i, i + 1, underscoreReplacement);
317 length += underscoreReplacementInc;
318 i += underscoreReplacementInc;
319 }
320 }
321 return result.toString();
322 }
323
324 protected String unescapeIterativelyReplacing(final String name) {
325 final char dollarChar = dollarReplacement.charAt(0);
326 final char underscoreChar = underscoreReplacement.charAt(0);
327 final int underscoreReplacementLength = underscoreReplacement.length();
328 final int dollarReplacementLength = dollarReplacement.length();
329 int length = name.length();
330 final StringBuffer result;
331 if (bufferIncrement == 0) {
332 result = new StringBuffer(name);
333 } else {
334 result = new StringBuffer(length + bufferIncrement);
335 result.append(name);
336 }
337 for (int i = 0; i < length; ++i) {
338 final char c = result.charAt(i);
339 if (c == dollarChar
340 && i + dollarReplacementLength <= length
341 && result.substring(i, i + dollarReplacementLength).equals(dollarReplacement)) {
342 result.replace(i, i + dollarReplacementLength, "$");
343 length -= dollarReplacementLength - 1;
344 } else if (c == underscoreChar
345 && i + underscoreReplacementLength <= length
346 && result.substring(i, i + underscoreReplacementLength).equals(
347 underscoreReplacement)) {
348 result.replace(i, i + underscoreReplacementLength, "_");
349 length -= underscoreReplacementLength - 1;
350 }
351 }
352 return result.toString();
353 }
354
355 protected String escapeIterativelyAppendingWithShortcut(String name) {
356 final int length = name.length();
357
358 // First, fast (common) case: nothing to escape
359 int i = 0;
360
361 for (; i < length; i++) {
362 char c = name.charAt(i);
363 if (c == '$' || c == '_') {
364 break;
365 }
366 }
367
368 if (i == length) {
369 return name;
370 }
371
372 // Otherwise full processing
373 final StringBuffer result = new StringBuffer(length+8);
374
375 // We know first N chars are safe
376 if (i > 0) {
377 result.append(name.substring(0, i));
378 }
379
380 for (; i < length; i++) {
381 char c = name.charAt(i);
382 if (c == '$' ) {
383 result.append(dollarReplacement);
384 } else if (c == '_') {
385 result.append(underscoreReplacement);
386 } else {
387 result.append(c);
388 }
389 }
390 return result.toString();
391 }
392
393 protected String unescapeIterativelyAppendingWithShortcut(String name) {
394 final char dollarReplacementFirstChar = dollarReplacement.charAt(0);
395 final char underscoreReplacementFirstChar = underscoreReplacement.charAt(0);
396 final int length = name.length();
397
398 // First, fast (common) case: nothing to unescape
399 int i = 0;
400
401 for (; i < length; i++) {
402 char c = name.charAt(i);
403 // We'll do a quick check for potential match
404 if (c == dollarReplacementFirstChar
405 || c == underscoreReplacementFirstChar) {
406 // and if it might be a match, just quit, will check later on
407 break;
408 }
409 }
410
411 if (i == length) {
412 return name;
413 }
414
415 // Otherwise full processing
416 final StringBuffer result = new StringBuffer(length+8);
417
418 // We know first N chars are safe
419 if (i > 0) {
420 result.append(name.substring(0, i));
421 }
422
423 for (; i < length; i++) {
424 char c = name.charAt(i);
425 if (c == dollarReplacementFirstChar
426 && name.startsWith(dollarReplacement, i)) {
427 i += dollarReplacement.length()-1;
428 result.append('$');
429 } else if (c == underscoreReplacementFirstChar
430 && name.startsWith(underscoreReplacement, i)) {
431 i += underscoreReplacement.length()-1;
432 result.append('_');
433 } else {
434 result.append(c);
435 }
436 }
437
438 return result.toString();
439 }
440
441 protected String escapeCachingIterativelyAppendingWithShortcut(String name) {
442 final WeakReference ref = (WeakReference)escapeCache.get(name);
443 String s = (String)(ref == null ? null : ref.get());
444
445 if (s == null) {
446 s = escapeIterativelyAppendingWithShortcut(name);
447 escapeCache.put(name, new WeakReference(s));
448 }
449 return s;
450 }
451
452 protected String unescapeCachingIterativelyAppendingWithShortcut(String name) {
453 final WeakReference ref = (WeakReference)unescapeCache.get(name);
454 String s = (String)(ref == null ? null : ref.get());
455
456 if (s == null) {
457 s = unescapeIterativelyAppendingWithShortcut(name);
458 unescapeCache.put(name, new WeakReference(s));
459 }
460 return s;
461 }
462 }
0 /*
1 * Copyright (C) 2008, 2009 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 20. Oktober 2008 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19
20 /**
21 * Special handling for conforming strings, iterates otherwise through the incoming string,
22 * appends the characters and caches the result. Used in XStream [1.3.1; ).
23 *
24 * @author J&ouml;rg Schaible
25 */
26 public class CachingIterativeAppenderWithShortcut implements Product {
27
28 private final XStream xstream;
29
30 public CachingIterativeAppenderWithShortcut() {
31 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer()));
32 }
33
34 public void serialize(Object object, OutputStream output) throws Exception {
35 xstream.toXML(object, output);
36 }
37
38 public Object deserialize(InputStream input) throws Exception {
39 return xstream.fromXML(input);
40 }
41
42 public String toString() {
43 return "Caching Iterative Appender with Shortcut";
44 }
45
46 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
47
48 public XmlFriendlyReplacer() {
49 this("_-", "__", 0);
50 }
51
52 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
53 super(dollarReplacement, underscoreReplacement, bufferIncrement);
54 }
55
56 public String escapeName(String name) {
57 return super.escapeCachingIterativelyAppendingWithShortcut(name);
58 }
59
60 public String unescapeName(String name) {
61 return super.unescapeCachingIterativelyAppendingWithShortcut(name);
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Uses a combined lookup and appends characters.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class CombinedLookupAppender implements Product {
25
26 private final XStream xstream;
27 private final int bufferIncrement;
28
29 public CombinedLookupAppender(int bufferIncrement) {
30 this.bufferIncrement = bufferIncrement;
31 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer(bufferIncrement)));
32 }
33
34 public void serialize(Object object, OutputStream output) throws Exception {
35 xstream.toXML(object, output);
36 }
37
38 public Object deserialize(InputStream input) throws Exception {
39 return xstream.fromXML(input);
40 }
41
42 public String toString() {
43 return "Combined Lookup Appending" + (bufferIncrement == 0 ? "" : (" (" + bufferIncrement + ")"));
44 }
45
46 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
47
48 public XmlFriendlyReplacer(int bufferIncrement) {
49 super("_-", "__", bufferIncrement);
50 }
51
52 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
53 super(dollarReplacement, underscoreReplacement, bufferIncrement);
54 }
55
56 public String escapeName(String name) {
57 return super.escapeByCombinedLookupAppending(name);
58 }
59
60 public String unescapeName(String name) {
61 return super.unescapeByCombinedLookupAppending(name);
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Uses a combined lookup and replaces characters.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class CombinedLookupReplacer implements Product {
25
26 private final XStream xstream;
27 private final int bufferIncrement;
28
29 public CombinedLookupReplacer(int bufferIncrement) {
30 this.bufferIncrement = bufferIncrement;
31 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer(bufferIncrement)));
32 }
33
34 public void serialize(Object object, OutputStream output) throws Exception {
35 xstream.toXML(object, output);
36 }
37
38 public Object deserialize(InputStream input) throws Exception {
39 return xstream.fromXML(input);
40 }
41
42 public String toString() {
43 return "Combined Lookup Replacer" + (bufferIncrement == 0 ? "" : (" (" + bufferIncrement + ")"));
44 }
45
46 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
47
48 public XmlFriendlyReplacer(int bufferIncrement) {
49 super("_-", "__", bufferIncrement);
50 }
51
52 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
53 super(dollarReplacement, underscoreReplacement, bufferIncrement);
54 }
55
56 public String escapeName(String name) {
57 return super.escapeByCombinedLookupReplacing(name);
58 }
59
60 public String unescapeName(String name) {
61 return super.unescapeByCombinedLookupReplacing(name);
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2008, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Iterates through the incoming string and appends the characters.
21 * Used in XStream [1.3; 1.2.2].
22 *
23 * @author J&ouml;rg Schaible
24 */
25 public class IterativeAppender implements Product {
26
27 private final XStream xstream;
28 private final int bufferIncrement;
29
30 public IterativeAppender(int bufferIncrement) {
31 this.bufferIncrement = bufferIncrement;
32 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer(bufferIncrement)));
33 }
34
35 public void serialize(Object object, OutputStream output) throws Exception {
36 xstream.toXML(object, output);
37 }
38
39 public Object deserialize(InputStream input) throws Exception {
40 return xstream.fromXML(input);
41 }
42
43 public String toString() {
44 return "Iterative Appender" + (bufferIncrement == 0 ? "" : (" (" + bufferIncrement + ")"));
45 }
46
47 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
48
49 public XmlFriendlyReplacer(int bufferIncrement) {
50 super("_-", "__", bufferIncrement);
51 }
52
53 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
54 super(dollarReplacement, underscoreReplacement, bufferIncrement);
55 }
56
57 public String escapeName(String name) {
58 return super.escapeIterativelyAppending(name);
59 }
60
61 public String unescapeName(String name) {
62 return super.unescapeIterativelyAppending(name);
63 }
64 }
65 }
0 /*
1 * Copyright (C) 2008, 2009 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 02. September 2008 by Tatu Saloranta
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19
20 /**
21 * Special handling for conforming strings, iterates otherwise through the incoming string and
22 * appends the character.
23 *
24 * @author J&ouml;rg Schaible
25 * @author Tatu Saloranta
26 */
27 public class IterativeAppenderWithShortcut implements Product {
28
29 private final XStream xstream;
30
31 public IterativeAppenderWithShortcut() {
32 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer()));
33 }
34
35 public void serialize(Object object, OutputStream output) throws Exception {
36 xstream.toXML(object, output);
37 }
38
39 public Object deserialize(InputStream input) throws Exception {
40 return xstream.fromXML(input);
41 }
42
43 public String toString() {
44 return "Iterative Appender with Shortcut";
45 }
46
47 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
48
49 public XmlFriendlyReplacer() {
50 this("_-", "__", 0);
51 }
52
53 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
54 super(dollarReplacement, underscoreReplacement, bufferIncrement);
55 }
56
57 public String escapeName(String name) {
58 return super.escapeIterativelyAppendingWithShortcut(name);
59 }
60
61 public String unescapeName(String name) {
62 return super.unescapeIterativelyAppendingWithShortcut(name);
63 }
64 }
65 }
0 /*
1 * Copyright (C) 2007, 2008, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Iterates through the string and replaces characters.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class IterativeReplacer implements Product {
25
26 private final XStream xstream;
27 private final int bufferIncrement;
28
29 public IterativeReplacer(int bufferIncrement) {
30 this.bufferIncrement = bufferIncrement;
31 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer(bufferIncrement)));
32 }
33
34 public void serialize(Object object, OutputStream output) throws Exception {
35 xstream.toXML(object, output);
36 }
37
38 public Object deserialize(InputStream input) throws Exception {
39 return xstream.fromXML(input);
40 }
41
42 public String toString() {
43 return "Iterative Replacer" + (bufferIncrement == 0 ? "" : (" (" + bufferIncrement + ")"));
44 }
45
46 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
47
48 public XmlFriendlyReplacer(int bufferIncrement) {
49 super("_-", "__", bufferIncrement);
50 }
51
52 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
53 super(dollarReplacement, underscoreReplacement, bufferIncrement);
54 }
55
56 public String escapeName(String name) {
57 return super.escapeIterativelyReplacing(name);
58 }
59
60 public String unescapeName(String name) {
61 return super.unescapeIterativelyReplacing(name);
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Uses XmlFriendlyReplacer dummy.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class NoReplacer implements Product {
25
26 private final XStream xstream;
27
28 public NoReplacer() {
29 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer()));
30 }
31
32 public void serialize(Object object, OutputStream output) throws Exception {
33 xstream.toXML(object, output);
34 }
35
36 public Object deserialize(InputStream input) throws Exception {
37 return xstream.fromXML(input);
38 }
39
40 public String toString() {
41 return "";
42 }
43
44 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
45
46 public XmlFriendlyReplacer() {
47 super("_-", "__", 0);
48 }
49
50 public String escapeName(String name) {
51 return name;
52 }
53
54 public String unescapeName(String name) {
55 return name;
56 }
57 }
58 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.products;
11
12 import com.thoughtworks.xstream.XStream;
13 import com.thoughtworks.xstream.io.xml.XppDriver;
14 import com.thoughtworks.xstream.tools.benchmark.Product;
15
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 /**
20 * Uses a combined lookup and replaces characters.
21 *
22 * @author J&ouml;rg Schaible
23 */
24 public class SeparateLookupReplacer implements Product {
25
26 private final XStream xstream;
27 private final int bufferIncrement;
28
29 public SeparateLookupReplacer(int bufferIncrement) {
30 this.bufferIncrement = bufferIncrement;
31 this.xstream = new XStream(new XppDriver(new XmlFriendlyReplacer(bufferIncrement)));
32 }
33
34 public void serialize(Object object, OutputStream output) throws Exception {
35 xstream.toXML(object, output);
36 }
37
38 public Object deserialize(InputStream input) throws Exception {
39 return xstream.fromXML(input);
40 }
41
42 public String toString() {
43 return "Separate Lookup Replacer" + (bufferIncrement == 0 ? "" : (" (" + bufferIncrement + ")"));
44 }
45
46 public static class XmlFriendlyReplacer extends AbstractXmlFriendlyReplacer {
47
48 public XmlFriendlyReplacer(int bufferIncrement) {
49 super("_-", "__", bufferIncrement);
50 }
51
52 public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement, int bufferIncrement) {
53 super(dollarReplacement, underscoreReplacement, bufferIncrement);
54 }
55
56 public String escapeName(String name) {
57 return super.escapeBySeparateLookupReplacing(name);
58 }
59
60 public String unescapeName(String name) {
61 return super.unescapeBySeparateLookupReplacing(name);
62 }
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.model.A100$Fields;
14 import com.thoughtworks.xstream.tools.model.targets.AbstractReflectionTarget;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 /**
20 * A Target for a 100 fields class with each field name containing 5 dollars.
21 *
22 * @author J&ouml;rg Schaible
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Target
25 */
26 public class Field$Reflection extends AbstractReflectionTarget {
27
28 public Field$Reflection() {
29 super(new ArrayList());
30 List list = (List)target();
31 for(int i = 0; i < 100; ++i) {
32 Object o = new A100$Fields();
33 fill(o);
34 list.add(o);
35 }
36 }
37
38 public String toString() {
39 return "Field with dollars Target";
40 }
41
42 }
0 /*
1 * Copyright (C) 2007, 2009 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 13. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.benchmark.xmlfriendly.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.xmlfriendly.model.A100_Fields;
14 import com.thoughtworks.xstream.tools.model.targets.AbstractReflectionTarget;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 /**
20 * A Target for a 100 fields class with each field name containing 5 underscores.
21 *
22 * @author J&ouml;rg Schaible
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Target
25 */
26 public class Field_Reflection extends AbstractReflectionTarget {
27
28 public Field_Reflection() {
29 super(new ArrayList());
30 List list = (List)target();
31 for(int i = 0; i < 100; ++i) {
32 Object o = new A100_Fields();
33 fill(o);
34 list.add(o);
35 }
36 }
37
38 public String toString() {
39 return "Field with underscores Target";
40 }
41
42 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.model.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13
14 import org.apache.commons.lang.builder.EqualsBuilder;
15
16 import java.lang.reflect.Field;
17 import java.util.Arrays;
18
19
20 /**
21 * An abstract Target that fills the fields by reflection.
22 *
23 * @author J&ouml;rg Schaible
24 * @see com.thoughtworks.xstream.tools.benchmark.Harness
25 * @see Target
26 */
27 public abstract class AbstractReflectionTarget implements Target {
28
29 private final Object target;
30
31 public AbstractReflectionTarget(final Object target) {
32 this.target = target;
33 }
34
35 public abstract String toString();
36
37 protected void fill(final Object o) {
38 final char[] zero = new char[8];
39 Arrays.fill(zero, '0');
40 for (Class cls = o.getClass(); cls != Object.class; cls = cls.getSuperclass()) {
41 final Field[] fields = cls.getDeclaredFields();
42 for (int i = 0; i < fields.length; i++) {
43 final Field field = fields[i];
44 field.setAccessible(true);
45 if (field.getType() == String.class) {
46 final String hex = Integer.toHexString(i);
47 try {
48 field.set(o, new String(zero, 0, zero.length - hex.length()) + hex);
49 } catch (final IllegalAccessException e) {
50 throw new RuntimeException(e);
51 }
52 }
53 }
54 }
55 }
56
57 public Object target() {
58 return target;
59 }
60
61 public boolean isEqual(final Object other) {
62 return EqualsBuilder.reflectionEquals(target, other);
63 }
64 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.model.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.A100Fields;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 /**
19 * A Target for a 100 fields class.
20 *
21 * @author J&ouml;rg Schaible
22 * @see com.thoughtworks.xstream.tools.benchmark.Harness
23 * @see Target
24 */
25 public class FieldReflection extends AbstractReflectionTarget {
26
27 public FieldReflection() {
28 super(new ArrayList());
29 List list = (List)target();
30 for(int i = 0; i < 100; ++i) {
31 Object o = new A100Fields();
32 fill(o);
33 list.add(o);
34 }
35 }
36
37 public String toString() {
38 return "Field Target";
39 }
40
41 }
0 /*
1 * Copyright (C) 2007, 2009 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 26. June 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.model.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.A100Parents;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 /**
19 * A Target for multiple hierarchy level classes.
20 *
21 * @author J&ouml;rg Schaible
22 * @see com.thoughtworks.xstream.tools.benchmark.Harness
23 * @see Target
24 */
25 public class HierarchyLevelReflection extends AbstractReflectionTarget {
26
27 public HierarchyLevelReflection() {
28 super(new ArrayList());
29 List list = (List)target();
30 for(int i = 0; i < 100; ++i) {
31 String no = "00" + i;
32 try {
33 Class cls = Class.forName(A100Parents.class.getName() + "$Parent" + no.substring(no.length() - 3));
34 Object o = cls.newInstance();
35 fill(o);
36 list.add(o);
37 } catch (ClassNotFoundException e) {
38 throw new RuntimeException(e);
39 } catch (InstantiationException e) {
40 throw new RuntimeException(e);
41 } catch (IllegalAccessException e) {
42 throw new RuntimeException(e);
43 }
44 }
45 }
46
47 public String toString() {
48 return "HierarchyLevel Target";
49 }
50
51 }
0 /*
1 * Copyright (C) 2007, 2009 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 06. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.model.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.A50InnerClasses;
14
15 import java.lang.reflect.Constructor;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21 /**
22 * A Target for multiple hierarchy level classes.
23 *
24 * @author J&ouml;rg Schaible
25 * @see com.thoughtworks.xstream.tools.benchmark.Harness
26 * @see Target
27 */
28 public class InnerClassesReflection extends AbstractReflectionTarget {
29
30 public InnerClassesReflection() {
31 super(new ArrayList());
32 for (int i = 0; i < 10; ++i) {
33 List list = new ArrayList();
34 list.add(new A50InnerClasses());
35 StringBuffer name = new StringBuffer(A50InnerClasses.class.getName());
36 for (int j = 0; j < 50; ++j) {
37 String no = "0" + j;
38 Object parent = list.get(j);
39 name.append("$L");
40 name.append(no.substring(no.length() - 2));
41 try {
42 Class cls = Class.forName(name.toString());
43 Constructor ctor = cls
44 .getDeclaredConstructor(new Class[]{parent.getClass()});
45 Object o = ctor.newInstance(new Object[]{parent});
46 fill(o);
47 list.add(o);
48 } catch (ClassNotFoundException e) {
49 throw new RuntimeException(e);
50 } catch (InstantiationException e) {
51 throw new RuntimeException(e);
52 } catch (IllegalAccessException e) {
53 throw new RuntimeException(e);
54 } catch (NoSuchMethodException e) {
55 throw new RuntimeException(e);
56 } catch (InvocationTargetException e) {
57 throw new RuntimeException(e);
58 }
59 }
60 list.remove(0);
61 ((List)target()).addAll(list);
62 }
63 }
64
65 public String toString() {
66 return "InnerClasses Target";
67 }
68
69 }
0 /*
1 * Copyright (C) 2007, 2009 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 06. September 2007 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.tools.model.targets;
11
12 import com.thoughtworks.xstream.tools.benchmark.Target;
13 import com.thoughtworks.xstream.tools.benchmark.model.A50StaticInnerClasses;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18
19 /**
20 * A Target for multiple hierarchy level classes.
21 *
22 * @author J&ouml;rg Schaible
23 * @see com.thoughtworks.xstream.tools.benchmark.Harness
24 * @see Target
25 */
26 public class StaticInnerClassesReflection extends AbstractReflectionTarget {
27
28 public StaticInnerClassesReflection() {
29 super(new ArrayList());
30 List list = (List)target();
31 for (int i = 0; i < 10; ++i) {
32 StringBuffer name = new StringBuffer(A50StaticInnerClasses.class.getName());
33 for (int j = 0; j < 50; ++j) {
34 String no = "0" + j;
35 try {
36 name.append("$L");
37 name.append(no.substring(no.length() - 2));
38 Class cls = Class.forName(name.toString());
39 Object o = cls.newInstance();
40 fill(o);
41 list.add(o);
42 } catch (ClassNotFoundException e) {
43 throw new RuntimeException(e);
44 } catch (InstantiationException e) {
45 throw new RuntimeException(e);
46 } catch (IllegalAccessException e) {
47 throw new RuntimeException(e);
48 }
49 }
50 }
51 }
52
53 public String toString() {
54 return "StaticInnerClasses Target";
55 }
56
57 }
0 ==========================================
1 Copyright (C) 2005, 2006 Joe Walnes.
2 Copyright (C) 2006, 2007 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 29. January 2005 by Joe Walnes
10 ==========================================
11
12 (The XStream website is build using XSite - http://xsite.codehaus.org)
13
14 STRUCTURE
15
16 The directories should be self explanatory:
17 ./src/templates: contains the skin HTML and style sheet. Other templates might go here.
18 ./src/content: contains the content in simple HTML.
19
20 BUILDING SITE
21
22 Run the XSite builder using the Maven 2 plugin associated to the install goal:
23
24 mvn install
25
26 The new site will be deployed in target/xsite
27
28 Alternatively, download the standalone xsite distribution from http://xsite.codehaus.org/download
29
30 $XSITE_HOME/bin/xsite src/content/website.xml src/template/skin.html target/xsite
31
32 EDITING THE CONTENT OF THE SITE
33
34 1) Edit the files in ./src/content. These are plain HTML files and can be edited using any old HTML editor
35 (including Mozilla Composer or Word).
36
37 Supporting resources that are relevant to the content (such as images) can be placed in this directory.
38
39 2) If the structure of the navigation requires a change (necessary if adding a new page), update ./src/content/website.xml.
40
41
42 EDITING THE LOOK AND FEEL OF THE SITE
43
44 1) Edit the file ./src/templates/skin.html. This is a FreeMarker template that is applied to each page using SiteMesh.
45
46 Supporting resources that are relevant to the look and feel (such as images or CSS) can be placed in this directory.
47
48
49 DESIGN PRINCIPLES
50
51 The ideas behind site design are as follows:
52
53 1) It implements the design that resulted from the analysis of stereotypical users
54
55 The menu is designed to put what our users most want right up front. Other, less
56 important information can be linked from subpages.
57
58 2) It completely separates content, navigation and style
59
60 This makes it easy to change the "skin" of the site or the style of that skin.
61
62 3) The navigation "skin" is designed to be convenient in browsers that do not
63 process CSS.
64
65 The banner appears first, then the main page content, followed by any side panels on
66 the page. Thus, users of less capable browsers get the most important information
67 first and less important information later.
68
69 4) All content is simple HTML.
70
71 No styles required, although any styles and other media used by the content pages
72 get merged into the final site by the templater. This makes it easy to create
73 content in WYSIWYG editors.
0 <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">
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. July 2006 by Mauro Talevi
11 -->
12 <modelVersion>4.0.0</modelVersion>
13 <parent>
14 <groupId>com.thoughtworks.xstream</groupId>
15 <artifactId>xstream-parent</artifactId>
16 <version>1.4.8</version>
17 </parent>
18 <artifactId>xstream-distribution</artifactId>
19 <packaging>pom</packaging>
20 <name>XStream Distribution</name>
21 <description>
22 Distribution project for XStream to build distributables and documentation.
23 </description>
24
25 <dependencies>
26 <dependency>
27 <groupId>com.thoughtworks.xstream</groupId>
28 <artifactId>xstream</artifactId>
29 <scope>runtime</scope>
30 </dependency>
31 <dependency>
32 <groupId>com.thoughtworks.xstream</groupId>
33 <artifactId>xstream-hibernate</artifactId>
34 <scope>runtime</scope>
35 </dependency>
36 <dependency>
37 <groupId>com.thoughtworks.xstream</groupId>
38 <artifactId>xstream-benchmark</artifactId>
39 <scope>runtime</scope>
40 </dependency>
41 </dependencies>
42
43 <profiles>
44 <profile>
45 <id>jdk18-ge</id>
46 <activation>
47 <jdk>[1.8,)</jdk>
48 </activation>
49 <build>
50 <plugins>
51 <plugin>
52 <groupId>org.codehaus.xsite</groupId>
53 <artifactId>xsite-maven-plugin</artifactId>
54 <configuration>
55 <sourceDirectoryPath>${basedir}/src</sourceDirectoryPath>
56 <sitemapPath>content/website.xml</sitemapPath>
57 <skinPath>templates/skin.html</skinPath>
58 <compositionFilePath>xsite/xsite.xml</compositionFilePath>
59 <resourcePaths>resources</resourcePaths>
60 <outputDirectoryPath>${project.build.directory}/xsite</outputDirectoryPath>
61 </configuration>
62 <executions>
63 <execution>
64 <phase>package</phase>
65 <goals>
66 <goal>run</goal>
67 </goals>
68 </execution>
69 </executions>
70 </plugin>
71 <plugin>
72 <groupId>org.apache.maven.plugins</groupId>
73 <artifactId>maven-antrun-plugin</artifactId>
74 <executions>
75 <execution>
76 <phase>package</phase>
77 <goals>
78 <goal>run</goal>
79 </goals>
80 <configuration>
81 <tasks>
82 <delete includeEmptyDirs="true">
83 <fileset dir="${project.build.directory}/xsite" includes="**/META-INF/*" />
84 <fileset dir="${project.build.directory}/xsite" includes="**/META-INF" />
85 </delete>
86 <mkdir dir="${project.build.directory}/docs" />
87 <copy todir="${project.build.directory}/docs" overwrite="true" failonerror="false">
88 <fileset dir="${basedir}">
89 <include name="target/xsite/**" />
90 <exclude name="target/xsite" />
91 </fileset>
92 <filtermapper>
93 <replacestring from="target${file.separator}xsite${file.separator}" to="${file.separator}" />
94 </filtermapper>
95 </copy>
96 </tasks>
97 </configuration>
98 </execution>
99 </executions>
100 </plugin>
101 </plugins>
102 </build>
103 <dependencies>
104 <dependency>
105 <groupId>com.thoughtworks.xstream</groupId>
106 <artifactId>xstream</artifactId>
107 <classifier>javadoc</classifier>
108 </dependency>
109 <dependency>
110 <groupId>com.thoughtworks.xstream</groupId>
111 <artifactId>xstream-hibernate</artifactId>
112 <classifier>javadoc</classifier>
113 </dependency>
114 <dependency>
115 <groupId>com.thoughtworks.xstream</groupId>
116 <artifactId>xstream-benchmark</artifactId>
117 <classifier>javadoc</classifier>
118 </dependency>
119 </dependencies>
120 </profile>
121 </profiles>
122
123 <build>
124 <plugins>
125 <plugin>
126 <groupId>org.apache.maven.plugins</groupId>
127 <artifactId>maven-dependency-plugin</artifactId>
128 <executions>
129 <execution>
130 <id>collect-xstream-artifacts</id>
131 <phase>package</phase>
132 <goals>
133 <goal>copy-dependencies</goal>
134 </goals>
135 <configuration>
136 <outputDirectory>target/libs</outputDirectory>
137 <includeScope>runtime</includeScope>
138 <excludeTransitive>true</excludeTransitive>
139 </configuration>
140 </execution>
141 <execution>
142 <id>unpack-core</id>
143 <phase>package</phase>
144 <goals>
145 <goal>unpack-dependencies</goal>
146 </goals>
147 <configuration>
148 <outputDirectory>${project.build.directory}/xsite/javadoc</outputDirectory>
149 <overWriteReleases>false</overWriteReleases>
150 <overWriteSnapshots>true</overWriteSnapshots>
151 <includeArtifactIds>xstream</includeArtifactIds>
152 <includeClassifiers>javadoc</includeClassifiers>
153 <includeScope>provided</includeScope>
154 </configuration>
155 </execution>
156 <execution>
157 <id>unpack-hibernate</id>
158 <phase>package</phase>
159 <goals>
160 <goal>unpack-dependencies</goal>
161 </goals>
162 <configuration>
163 <outputDirectory>${project.build.directory}/xsite/hibernate-javadoc</outputDirectory>
164 <overWriteReleases>false</overWriteReleases>
165 <overWriteSnapshots>true</overWriteSnapshots>
166 <includeArtifactIds>xstream-hibernate</includeArtifactIds>
167 <includeClassifiers>javadoc</includeClassifiers>
168 <includeScope>provided</includeScope>
169 </configuration>
170 </execution>
171 <execution>
172 <id>unpack-benchmark</id>
173 <phase>package</phase>
174 <goals>
175 <goal>unpack-dependencies</goal>
176 </goals>
177 <configuration>
178 <outputDirectory>${project.build.directory}/xsite/benchmark-javadoc</outputDirectory>
179 <overWriteReleases>false</overWriteReleases>
180 <overWriteSnapshots>true</overWriteSnapshots>
181 <includeArtifactIds>xstream-benchmark</includeArtifactIds>
182 <includeClassifiers>javadoc</includeClassifiers>
183 <includeScope>provided</includeScope>
184 </configuration>
185 </execution>
186 </executions>
187 </plugin>
188 <plugin>
189 <groupId>org.apache.maven.plugins</groupId>
190 <artifactId>maven-assembly-plugin</artifactId>
191 <executions>
192 <execution>
193 <id>bin</id>
194 <phase>package</phase>
195 <goals>
196 <goal>attached</goal>
197 </goals>
198 <configuration>
199 <descriptors>
200 <descriptor>${basedir}/src/assembly/assembly-bin.xml</descriptor>
201 </descriptors>
202 <finalName>xstream-${project.version}</finalName>
203 <workDirectory>${project.build.directory}/assembly/bin</workDirectory>
204 </configuration>
205 </execution>
206 <execution>
207 <id>src</id>
208 <phase>package</phase>
209 <goals>
210 <goal>attached</goal>
211 </goals>
212 <configuration>
213 <descriptors>
214 <descriptor>${basedir}/src/assembly/assembly-src.xml</descriptor>
215 </descriptors>
216 <finalName>xstream-${project.version}</finalName>
217 <workDirectory>${project.build.directory}/assembly/src</workDirectory>
218 </configuration>
219 </execution>
220 </executions>
221 </plugin>
222 </plugins>
223 </build>
224 </project>
0 <!--
1 Copyright (C) 2006 Joe Walnes.
2 Copyright (C) 2006, 2007, 2011 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 15. October 2006 by Mauro Talevi
10 -->
11 <assembly>
12 <id>bin</id>
13 <formats>
14 <format>zip</format>
15 </formats>
16 <fileSets>
17 <fileSet>
18 <directory>..</directory>
19 <outputDirectory>/</outputDirectory>
20 <includes>
21 <include>LICENSE.txt</include>
22 <include>README.txt</include>
23 </includes>
24 </fileSet>
25 <fileSet>
26 <directory>target/docs</directory>
27 <outputDirectory>docs</outputDirectory>
28 </fileSet>
29 <fileSet>
30 <directory>target/libs</directory>
31 <outputDirectory>lib</outputDirectory>
32 </fileSet>
33 <fileSet>
34 <directory>../xstream/target/dependencies</directory>
35 <outputDirectory>lib/xstream</outputDirectory>
36 </fileSet>
37 <fileSet>
38 <directory>../xstream-hibernate/target/dependencies</directory>
39 <outputDirectory>lib/xstream-hibernate</outputDirectory>
40 </fileSet>
41 </fileSets>
42 </assembly>
0 <!--
1 Copyright (C) 2006 Joe Walnes.
2 Copyright (C) 2006, 2007, 2011, 2012 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 15. October 2006 by Mauro Talevi
10 -->
11 <assembly>
12 <id>src</id>
13 <formats>
14 <format>zip</format>
15 </formats>
16 <fileSets>
17 <fileSet>
18 <directory>..</directory>
19 <outputDirectory>/</outputDirectory>
20 <excludes>
21 <exclude>xstream-builder/**</exclude>
22 <exclude>**/build/**</exclude>
23 <exclude>**/target/**</exclude>
24 <exclude>**/.*/**</exclude>
25 <exclude>**/.*</exclude>
26 <exclude>**/cobertura.ser</exclude>
27 <exclude>**/release.properties</exclude>
28 <exclude>**/surefire*.properties</exclude>
29 <exclude>**/*~</exclude>
30 <exclude>**/*.bak</exclude>
31 <exclude>**/*.classpath</exclude>
32 <exclude>**/*.jps</exclude>
33 <exclude>**/*.releaseBackup</exclude>
34 </excludes>
35 </fileSet>
36 </fileSets>
37 </assembly>
0 <html>
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2011 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 24. March 2006 by Guilherme Silveira
11 -->
12 <head>
13 <title>Alias Tutorial</title>
14 </head>
15 <body>
16 <h2 id="problem">The problem</h2>
17 <p>Suppose that our client has defined a base XML file that we should make XStream read/write:</p>
18 <div class="Source Java"><pre>&lt;blog author=&quot;Guilherme Silveira&quot;&gt;
19 &lt;entry&gt;
20 &lt;title&gt;first&lt;/title&gt;
21 &lt;description&gt;My first blog entry.&lt;/description&gt;
22 &lt;/entry&gt;
23 &lt;entry&gt;
24 &lt;title&gt;tutorial&lt;/title&gt;
25 &lt;description&gt;
26 Today we have developed a nice alias tutorial. Tell your friends! NOW!
27 &lt;/description&gt;
28 &lt;/entry&gt;
29 &lt;/blog&gt;</pre>
30
31 <p>Based on the XML file above we shall create some model classes and configure XStream to write/read from this format.</p></div>
32 <div class="section">
33 <h2 id="model">The model</h2>
34 <p>First things first, the classes which shall represent our xml files are shown next, beginning with a simple Blog:</p>
35 <div class="Source Java"><pre>package com.thoughtworks.xstream;
36
37 public class Blog {
38 private Author writer;
39 private List entries = new ArrayList();
40
41 public Blog(Author writer) {
42 this.writer = writer;
43 }
44
45 public void add(Entry entry) {
46 entries.add(entry);
47 }
48
49 public List getContent() {
50 return entries;
51 }
52 }</pre></div>
53 <p>A basic author with name:</p>
54 <div class="Source Java"><pre>package com.thoughtworks.xstream;
55
56 public class Author {
57 private String name;
58 public Author(String name) {
59 this.name = name;
60 }
61 public String getName() {
62 return name;
63 }
64 }</pre></div>
65 <p>A blog entry contains a title and description:</p>
66 <div class="Source Java"><pre>package com.thoughtworks.xstream;
67
68 public class Entry {
69 private String title, description;
70 public Entry(String title, String description) {
71 this.title = title;
72 this.description = description;
73 }
74 }</pre></div>
75 <p>Although we did not create many getters/setters its up to you to create those you wish or those which make sense.</p></div>
76 <div class="section">
77 <h2 id="test">A simple test</h2>
78 <p>We can easily instantiate a new blog and use it with xstream:</p>
79 <div class="Source Java"><pre>public static void main(String[] args) {
80
81 Blog teamBlog = new Blog(new Author(&quot;Guilherme Silveira&quot;));
82 teamBlog.add(new Entry(&quot;first&quot;,&quot;My first blog entry.&quot;));
83 teamBlog.add(new Entry(&quot;tutorial&quot;,
84 &quot;Today we have developed a nice alias tutorial. Tell your friends! NOW!&quot;));
85
86 XStream xstream = new XStream();
87 System.out.println(xstream.toXML(teamBlog));
88
89 }</pre></div>
90 <p>And the resulting XML is not so nice as we would want it to be:</p>
91 <div class="Source Java"><pre>&lt;com.thoughtworks.xstream.Blog&gt;
92 &lt;writer&gt;
93 &lt;name&gt;Guilherme Silveira&lt;/name&gt;
94 &lt;/writer&gt;
95 &lt;entries&gt;
96 &lt;com.thoughtworks.xstream.Entry&gt;
97 &lt;title&gt;first&lt;/title&gt;
98 &lt;description&gt;My first blog entry.&lt;/description&gt;
99 &lt;/com.thoughtworks.xstream.Entry&gt;
100 &lt;com.thoughtworks.xstream.Entry&gt;
101 &lt;title&gt;tutorial&lt;/title&gt;
102 &lt;description&gt;
103 Today we have developed a nice alias tutorial. Tell your friends! NOW!
104 &lt;/description&gt;
105 &lt;/com.thoughtworks.xstream.Entry&gt;
106 &lt;/entries&gt;
107 &lt;/com.thoughtworks.xstream.Blog&gt;</pre></div></div>
108 <div class="section">
109 <h2 id="class_aliasing">Class aliasing</h2>
110 <p>The first thing we shall change is how XStream refers to the <b>com.thoughtworks.xstream.Blog</b> class.
111 We shall name it simply <i>blog</i>: let's create an alias called <i>blog</i> to the desired class:</p>
112 <div class="Source Java"><pre>xstream.alias(&quot;blog&quot;, Blog.class);</pre></div>
113 <p>Using the same idea, we can alias the 'Entry' class to 'entry':</p>
114 <div class="Source Java"><pre>xstream.alias(&quot;entry&quot;, Entry.class);</pre></div>
115 <p>The result now becomes:</p>
116 <div class="Source Java"><pre>&lt;blog&gt;
117 &lt;writer&gt;
118 &lt;name&gt;Guilherme Silveira&lt;/name&gt;
119 &lt;/writer&gt;
120 &lt;entries&gt;
121 &lt;entry&gt;
122 &lt;title&gt;first&lt;/title&gt;
123 &lt;description&gt;My first blog entry.&lt;/description&gt;
124 &lt;/entry&gt;
125 &lt;entry&gt;
126 &lt;title&gt;tutorial&lt;/title&gt;
127 &lt;description&gt;
128 Today we have developed a nice alias tutorial. Tell your friends! NOW!
129 &lt;/description&gt;
130 &lt;/entry&gt;
131 &lt;/entries&gt;
132 &lt;/blog&gt;</pre></div></div>
133 <div class="section">
134 <h2 id="field_aliasing">Field aliasing</h2>
135 <p>Next we will change the name of the writer tag, but this time we have to use a field alias:</p>
136 <div class="Source Java"><pre>xstream.aliasField(&quot;author&quot;, Blog.class, &quot;writer&quot;);</pre></div>
137 <p>The result now becomes:</p>
138 <div class="Source Java"><pre>&lt;blog&gt;
139 &lt;author&gt;
140 &lt;name&gt;Guilherme Silveira&lt;/name&gt;
141 &lt;/author&gt;
142 &lt;entries&gt;
143 &lt;entry&gt;
144 &lt;title&gt;first&lt;/title&gt;
145 &lt;description&gt;My first blog entry.&lt;/description&gt;
146 &lt;/entry&gt;
147 &lt;entry&gt;
148 &lt;title&gt;tutorial&lt;/title&gt;
149 &lt;description&gt;
150 Today we have developed a nice alias tutorial. Tell your friends! NOW!
151 &lt;/description&gt;
152 &lt;/entry&gt;
153 &lt;/entries&gt;
154 &lt;/blog&gt;</pre></div></div>
155 <div class="section">
156 <h2 id="implicit">Implicit Collections</h2>
157 <p>Now let's implement what was called an <b>implicit collection</b>: whenever you have a collection which doesn't need
158 to display it's root tag, you can map it as an implicit collection.</p>
159 <p>In our example, we do not want to display the <b>entries</b> tag, but simply show the <b>entry</b> tags one after
160 another.</p>
161 <p>A simple call to the <b>addImplicitCollection</b> method shall configure XStream and let it know that we do not want to
162 write the <b>entries</b> tag as described above:</p>
163 <div class="Source Java"><pre>package com.thoughtworks.xstream;
164
165 import java.util.ArrayList;
166 import java.util.List;
167
168 public class Test {
169
170 public static void main(String[] args) {
171
172 Blog teamBlog = new Blog(new Author(&quot;Guilherme Silveira&quot;));
173 teamBlog.add(new Entry(&quot;first&quot;,&quot;My first blog entry.&quot;));
174 teamBlog.add(new Entry(&quot;tutorial&quot;,
175 &quot;Today we have developed a nice alias tutorial. Tell your friends! NOW!&quot;));
176
177 XStream xstream = new XStream();
178 xstream.alias(&quot;blog&quot;, Blog.class);
179 xstream.alias(&quot;entry&quot;, Entry.class);
180
181 xstream.addImplicitCollection(Blog.class, &quot;entries&quot;);
182
183 System.out.println(xstream.toXML(teamBlog));
184
185 }
186 }</pre></div>
187 <p>Pay attention to the <b>addImplicitCollection</b> method call: it describes which class and which member variable
188 shall assume the behaviour we described.</p>
189 <p>The result is almost what we wanted:</p>
190 <div class="Source Java"><pre>&lt;blog&gt;
191 &lt;author&gt;
192 &lt;name&gt;Guilherme Silveira&lt;/name&gt;
193 &lt;/author&gt;
194 &lt;entry&gt;
195 &lt;title&gt;first&lt;/title&gt;
196 &lt;description&gt;My first blog entry.&lt;/description&gt;
197 &lt;/entry&gt;
198 &lt;entry&gt;
199 &lt;title&gt;tutorial&lt;/title&gt;
200 &lt;description&gt;
201 Today we have developed a nice alias tutorial. Tell your friends! NOW!
202 &lt;/description&gt;
203 &lt;/entry&gt;
204 &lt;/blog&gt;</pre></div></div>
205 <p>Just as a side note: An array or a map can also be declared as implicit.</p>
206 <div class="section">
207 <h2 id="attributes">Attribute aliasing</h2>
208 <p>The next step is to set the <b>writer</b> member variable as an XML attribute. In order to do this, we shall tell
209 XStream to alias the <b>writer</b> field of the <b>Blog</b> class as an "author" attribute:</p>
210 <div class="Source Java"><pre> xstream.useAttributeFor(Blog.class, &quot;writer&quot;);
211 xstream.aliasField(&quot;author&quot;, Blog.class, &quot;writer&quot;);</pre></div>
212 <p>And now it leaves us with one problem: how does XStream converts an Author in a String so it can be written as a
213 XML tag attribute?</p>
214 <p>Attributes cannot be written for types that are handled by Converter implementations, we have to use a
215 <b>SingleValueConverter</b> and implement our own converter for the Author:</p>
216 <div class="Source Java"><pre>class AuthorConverter implements SingleValueConverter {
217 }</pre></div>
218 <p>The first method to implement tells XStream which types it can deal with:</p>
219 <div class="Source Java"><pre> public boolean canConvert(Class type) {
220 return type.equals(Author.class);
221 }</pre></div>
222 <p>The second one is used to extract a String from an Author:</p>
223 <div class="Source Java"><pre> public String toString(Object obj) {
224 return ((Author) obj).getName();
225 }</pre></div>
226 <p>And the third one does the opposite job: takes a String and returns an Author:</p>
227 <div class="Source Java"><pre> public Object fromString(String name) {
228 return new Author(name);
229 }</pre></div>
230 <p>Finally, the entire single value converter, responsible for converting Strings to Objects (Authors in this case) is:</p>
231 <div class="Source Java"><pre>class AuthorConverter implements SingleValueConverter {
232
233 public String toString(Object obj) {
234 return ((Author) obj).getName();
235 }
236
237 public Object fromString(String name) {
238 return new Author(name);
239 }
240
241 public boolean canConvert(Class type) {
242 return type.equals(Author.class);
243 }
244
245 }</pre></div>
246 <p>And let's register this converter:</p>
247 <div class="Source Java"><pre>public class Test {
248
249 public static void main(String[] args) {
250
251 Blog teamBlog = new Blog(new Author(&quot;Guilherme Silveira&quot;));
252 teamBlog.add(new Entry(&quot;first&quot;,&quot;My first blog entry.&quot;));
253 teamBlog.add(new Entry(&quot;tutorial&quot;,
254 &quot;Today we have developed a nice alias tutorial. Tell your friends! NOW!&quot;));
255
256 XStream xstream = new XStream();
257 xstream.alias(&quot;blog&quot;, Blog.class);
258 xstream.alias(&quot;entry&quot;, Entry.class);
259
260 xstream.addImplicitCollection(Blog.class, &quot;entries&quot;);
261
262 xstream.useAttributeFor(Blog.class, &quot;author&quot;);
263 xstream.registerConverter(new AuthorConverter());
264
265 System.out.println(xstream.toXML(teamBlog));
266
267 }
268 }</pre></div>
269 <p>The result?</p>
270 <div class="Source Java"><pre>&lt;blog author=&quot;Guilherme Silveira&quot;&gt;
271 &lt;entry&gt;
272 &lt;title&gt;first&lt;/title&gt;
273 &lt;description&gt;My first blog entry.&lt;/description&gt;
274 &lt;/entry&gt;
275 &lt;entry&gt;
276 &lt;title&gt;tutorial&lt;/title&gt;
277 &lt;description&gt;
278 Today we have developed a nice alias tutorial. Tell your friends! NOW!
279 &lt;/description&gt;
280 &lt;/entry&gt;
281 &lt;/blog&gt;</pre></div>
282 </div>
283
284 <p class=highlight>You have to be aware, that attribute values normally have to be normalized by the XML parser as
285 required by the <a href="http://www.w3.org/TR/REC-xml/#AVNormalize">W3C spec</a>. Leading and trailing whitespaces
286 are normally removed as well as sequential ones! Therefore a deserialized string might differ from the value visible in
287 the XML representation.</p>
288
289 <div class="section">
290 <h2 id="packages">Package aliasing</h2>
291
292 <p>In the example above we have so far always used class aliases for the Blog and Entry type. Sometimes it is necessary to
293 map existing class types to others simply by changing the package name. Let us go back to the first attempt of our tutorial,
294 but this time we alias the package name instead of the individual classes:</p>
295 <div class="Source Java"><pre>public static void main(String[] args) {
296
297 Blog teamBlog = new Blog(new Author(&quot;Guilherme Silveira&quot;));
298 teamBlog.add(new Entry(&quot;first&quot;,&quot;My first blog entry.&quot;));
299 teamBlog.add(new Entry(&quot;tutorial&quot;,
300 &quot;Today we have developed a nice alias tutorial. Tell your friends! NOW!&quot;));
301
302 XStream xstream = new XStream();
303 xstream.aliasPackage("my.company", "org.thoughtworks");
304 System.out.println(xstream.toXML(teamBlog));
305
306 }</pre></div>
307 <p>And the resulting XML contains now the classes with the aliased package names:</p>
308 <div class="Source Java"><pre>&lt;my.company.xstream.Blog&gt;
309 &lt;author&gt;
310 &lt;name&gt;Guilherme Silveira&lt;/name&gt;
311 &lt;/author&gt;
312 &lt;entries&gt;
313 &lt;my.company.xstream.Entry&gt;
314 &lt;title&gt;first&lt;/title&gt;
315 &lt;description&gt;My first blog entry.&lt;/description&gt;
316 &lt;/my.company.xstream.Entry&gt;
317 &lt;my.company.xstream.Entry&gt;
318 &lt;title&gt;tutorial&lt;/title&gt;
319 &lt;description&gt;
320 Today we have developed a nice alias tutorial. Tell your friends! NOW!
321 &lt;/description&gt;
322 &lt;/my.company.xstream.Entry&gt;
323 &lt;/entries&gt;
324 &lt;/my.company.xstream.Blog&gt;</pre></div>
325 <p>Please recognize that the package name alias works also for sub packages in this example.</p>
326 </div>
327
328 <div class="section">
329 <h2 id="summary">Summing up</h2>
330 <p>To recap:</p>
331 <ul>
332 <li>You can use class aliases to change tag names</li>
333 <li>You can use field aliases to change tag names</li>
334 <li>You can use package aliases to change tag names</li>
335 <li>Fields can be written as attributes if the field type is handled by a SingleValueConverter</li>
336 </ul>
337 <p>Don't forget to read the <a href="converter-tutorial.html">converter tutorial</a> to see other type of converters that you can create using XStream.
338 Or look into the condensed overview how to configure XStream to <a href="manual-tweaking-output.html">tweak the output</a>.</p>
339 </div>
340
341 </body>
342 </html>
0 <html>
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2011 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 28. July 2006 by Guilherme Silveira
11 -->
12 <head>
13 <title>Annotations Tutorial</title>
14 </head>
15 <body>
16
17 <!-- ...................................................... -->
18 <h2 id="Motivation">Motivation</h2>
19 <p>Sometimes it can get tedious to call all those XStream aliases/register converter methods or you might simply like
20 the new trend on configuring POJOs: Java annotations.</p>
21 <p>This tutorial will show you how to use some of the annotations provided by XStream in order to make configuration
22 easier. Let's start with a custom Message class:</p>
23 <div class="Source Java"><pre>package com.thoughtworks.xstream;
24 package com.thoughtworks.xstream;
25 public class RendezvousMessage {
26
27 private int messageType;
28
29 public RendezvousMessage(int messageType) {
30 this.messageType = messageType;
31 }
32
33 }</pre></div>
34 <p>Let's code the XStream calls which generate the XML file:</p>
35 <div class="Source Java"><pre>
36 package com.thoughtworks.xstream;
37 public class Tutorial {
38
39 public static void main(String[] args) {
40 XStream stream = new XStream();
41 RendezvousMessage msg = new RendezvousMessage(15);
42 System.out.println(stream.toXML(msg));
43 }
44
45 }
46 </pre></div>
47 <p>Results in the following XML:</p>
48 <div class="Source Java"><pre>
49 &lt;com.thoughtworks.xstream.RendezvousMessage&gt;
50 &lt;messageType&gt;15&lt;/messageType&gt;
51 &lt;/com.thoughtworks.xstream.RendezvousMessage&gt;
52 </pre></div>
53
54 <!-- ...................................................... -->
55 <h2 id="Aliasing">Aliasing Annotation</h2>
56 <p>The most basic annotation is the one responsible for type and field aliasing: @XStreamAlias. Let's annotate both
57 our type and field and run the tutorial method again:</p>
58 <div class="Source Java"><pre>
59 @XStreamAlias("message")
60 class RendezvousMessage {
61
62 @XStreamAlias("type")
63 private int messageType;
64
65 public RendezvousMessage(int messageType) {
66 this.messageType = messageType;
67 }
68
69 }
70 </pre></div>
71 <p>In some strange way, the result is the same. What happened here? XStream does not read this annotation by default
72 as it would be impossible to deserialize the XML code. Therefore we need to tell XStream to read the annotations from
73 this type:</p>
74 <div class="Source Java"><pre>
75 public static void main(String[] args) {
76 XStream stream = new XStream();
77 xstream.processAnnotations(RendezvousMessage.class);
78 RendezvousMessage msg = new RendezvousMessage(15);
79 System.out.println(stream.toXML(msg));
80 }
81 </pre></div>
82 <p>Note that we have called the processAnnotations method of XStream. This method registers all aliases annotations in
83 the XStream instance passed as first argument. You may also use the overloaded version of this method taking an array
84 of types. The resulting XML is now what we have expected:</p>
85 <div class="Source Java"><pre>
86 &lt;message&gt;
87 &lt;type&gt;15&lt;/type&gt;
88 &lt;/message&gt;
89 </pre></div>
90 <p>If you let XStream process the annotations of a type, it will also process all annotations of the related types i.e.
91 all super types, implemented interfaces, the class types of the members and all their generic types.</p>
92
93 <!-- ...................................................... -->
94 <h2 id="ImplicitCollections">Implicit Collections</h2>
95 <p>Let's add a List of content to our RendezvousMessage. We desire the same functionality obtained with implicit
96 collections:</p>
97 <div class="Source Java"><pre>
98 @XStreamAlias("message")
99 class RendezvousMessage {
100
101 @XStreamAlias("type")
102 private int messageType;
103
104 private List&lt;String&gt; content;
105
106 public RendezvousMessage(int messageType, String ... content) {
107 this.messageType = messageType;
108 this.content = Arrays.asList(content);
109 }
110
111 }
112 </pre></div>
113 <div class="Source Java"><pre>
114 public static void main(String[] args) {
115 XStream stream = new XStream();
116 xstream.processAnnotations(RendezvousMessage.class);
117 RendezvousMessage msg = new RendezvousMessage(15, "firstPart","secondPart");
118 System.out.println(stream.toXML(msg));
119 }
120 </pre></div>
121 <p>The resulting XML shows the collection name before its elements:</p>
122 <div class="Source Java"><pre>
123 &lt;message&gt;
124 &lt;type&gt;15&lt;/type&gt;
125 &lt;content class="java.util.Arrays$ArrayList"&gt;
126 &lt;a class="string-array"&gt;
127 &lt;string&gt;firstPart&lt;/string&gt;
128 &lt;string&gt;secondPart&lt;/string&gt;
129 &lt;/a&gt;
130 &lt;/content&gt;
131 &lt;/message&gt;
132 </pre></div>
133 <p>This is not what we desire therefore we will annotate the content list to be recognized as an implicit collection:</p>
134 <div class="Source Java"><pre>
135 @XStreamAlias("message")
136 class RendezvousMessage {
137
138 @XStreamAlias("type")
139 private int messageType;
140
141 @XStreamImplicit
142 private List&lt;String&gt; content;
143
144 public RendezvousMessage(int messageType, String... content) {
145 this.messageType = messageType;
146 this.content = Arrays.asList(content);
147 }
148
149 }
150 </pre></div>
151 <p>Resulting in an XML which ignores the field name (content) of the list:</p>
152 <div class="Source Java"><pre>
153 &lt;message&gt;
154 &lt;type&gt;15&lt;/type&gt;
155 &lt;a class="string-array"&gt;
156 &lt;string&gt;firstPart&lt;/string&gt;
157 &lt;string&gt;secondPart&lt;/string&gt;
158 &lt;/a&gt;
159 &lt;/message&gt;
160 </pre></div>
161 <p>We are almost there... we still want to remove the 'a' tag, and define each content part with the tag 'part'. In
162 order to do so, let's add another attribute to our implicit collection annotation. The attribute field defines the
163 name of the tag used for data contained inside this collection:</p>
164 <div class="Source Java"><pre>
165 @XStreamAlias("message")
166 class RendezvousMessage {
167
168 @XStreamAlias("type")
169 private int messageType;
170
171 @XStreamImplicit(itemFieldName="part")
172 private List&lt;String&gt; content;
173
174 public RendezvousMessage(int messageType, String... content) {
175 this.messageType = messageType;
176 this.content = Arrays.asList(content);
177 }
178
179 }
180 </pre></div>
181 <p>Resulting in a cleaner XML:</p>
182 <div class="Source Java"><pre>
183 &lt;message&gt;
184 &lt;type&gt;15&lt;/type&gt;
185 &lt;part&gt;firstPart&lt;/part&gt;
186 &lt;part&gt;secondPart&lt;/part&gt;
187 &lt;/message&gt;
188 </pre></div>
189
190 <p>The implicit annotation can also be used for arrays and maps. In the latter case you should provide the field name
191 of the values that are used as key of the map.</p>
192
193 <!-- ...................................................... -->
194 <h2 id="LocalConverters">Local Converters</h2>
195 <p>Let's create another attribute which defines the timestamp when the message was created and one to flag special
196 importance of the message:</p>
197 <div class="Source Java"><pre>
198 @XStreamAlias("message")
199 class RendezvousMessage {
200
201 @XStreamAlias("type")
202 private int messageType;
203
204 @XStreamImplicit(itemFieldName="part")
205 private List&lt;String&gt; content;
206
207 private boolean important;
208
209 private Calendar created = new GregorianCalendar();
210
211 public RendezvousMessage(int messageType, boolean important, String... content) {
212 this.messageType = messageType;
213 this.important = important;
214 this.content = Arrays.asList(content);
215 }
216
217 }
218 </pre></div>
219 <p>Resulting in the following xml:</p>
220 <div class="Source Java"><pre>
221 &lt;message&gt;
222 &lt;type&gt;15&lt;/type&gt;
223 &lt;part&gt;firstPart&lt;/part&gt;
224 &lt;part&gt;secondPart&lt;/part&gt;
225 &lt;important&gt;false&lt;/important&gt;
226 &lt;created&gt;
227 &lt;time&gt;1154097812245&lt;/time&gt;
228 &lt;timezone&gt;America/Sao_Paulo&lt;/timezone&gt;
229 &lt;/created&gt;
230 &lt;/message&gt;
231 </pre></div>
232 <p>Now we face the following problem: We want to use a custom converter locally for this Calendar, but only for this
233 Calendar, this exact field in this exact type. Easy... let's annotate it with the custom converter annotation:</p>
234 <div class="Source Java"><pre>
235 @XStreamAlias("message")
236 class RendezvousMessage {
237
238 @XStreamAlias("type")
239 private int messageType;
240
241 @XStreamImplicit(itemFieldName="part")
242 private List&lt;String&gt; content;
243
244 private boolean important;
245
246 @XStreamConverter(SingleValueCalendarConverter.class)
247 private Calendar created = new GregorianCalendar();
248
249 public RendezvousMessage(int messageType, String... content) {
250 this.messageType = messageType;
251 this.content = Arrays.asList(content);
252 }
253
254 }
255 </pre></div>
256 <p>Let's create the custom converter:</p>
257 <div class="Source Java"><pre>
258 public class SingleValueCalendarConverter implements Converter {
259
260 public void marshal(Object source, HierarchicalStreamWriter writer,
261 MarshallingContext context) {
262 Calendar calendar = (Calendar) source;
263 writer.setValue(String.valueOf(calendar.getTime().getTime()));
264 }
265
266 public Object unmarshal(HierarchicalStreamReader reader,
267 UnmarshallingContext context) {
268 GregorianCalendar calendar = new GregorianCalendar();
269 calendar.setTime(new Date(Long.parseLong(reader.getValue())));
270 return calendar;
271 }
272
273 public boolean canConvert(Class type) {
274 return type.equals(GregorianCalendar.class);
275 }
276 }
277 </pre></div>
278 <p>And we end up with the converter being used and generating the following XML:</p>
279 <div class="Source Java"><pre>
280 &lt;message&gt;
281 &lt;type&gt;15&lt;/type&gt;
282 &lt;part&gt;firstPart&lt;/part&gt;
283 &lt;part&gt;secondPart&lt;/part&gt;
284 &lt;important&gt;false&lt;/important&gt;
285 &lt;created&gt;1154097812245&lt;/created&gt;
286 &lt;/message&gt;
287 </pre></div>
288
289 <p>Additionally we want to format the importance flag not with a technical <em>true</em> or <em>false</em>, but with a
290 natural <em>yes</em> or <em>no</em>. Fortunately the BooleanConverter supports alternate format styles, but how can we
291 use an annotation to register a new instance locally? The XStreamConverter annotation uses some lightweight dependency
292 injection mechanism to match given arguments with the parameters of available constructors. That way we can write now:</p>
293 <div class="Source Java"><pre>
294 @XStreamAlias("message")
295 class RendezvousMessage {
296
297 @XStreamAlias("type")
298 private int messageType;
299
300 @XStreamImplicit(itemFieldName="part")
301 private List&lt;String&gt; content;
302
303 @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"})
304 private boolean important;
305
306 @XStreamConverter(SingleValueCalendarConverter.class)
307 private Calendar created = new GregorianCalendar();
308
309 public RendezvousMessage(int messageType, boolean important, String... content) {
310 this.messageType = messageType;
311 this.important = important;
312 this.content = Arrays.asList(content);
313 }
314
315 }
316 </pre></div>
317
318 <p>The BooleanConverter has an additional constructor with two string values expressing <em>true</em> and
319 <em>false</em> and a third argument to ignore case of these values. Therefore we have added all 3 arguments to the
320 annotation. The sequence of the arguments is only important for same types. As result we have now:</p>
321 <div class="Source Java"><pre>
322 &lt;message&gt;
323 &lt;type&gt;15&lt;/type&gt;
324 &lt;part&gt;firstPart&lt;/part&gt;
325 &lt;part&gt;secondPart&lt;/part&gt;
326 &lt;important&gt;no&lt;/important&gt;
327 &lt;created&gt;1154097812245&lt;/created&gt;
328 &lt;/message&gt;
329 </pre></div>
330
331 <p>See the Javadoc of the XStreamConverter annotation what more arguments are provided implicitly.</p>
332
333 <!-- ...................................................... -->
334 <h2 id="Attributes">Attributes</h2>
335 <p>The client may asks for the type tag and the importance flag to be an attribute inside the message tag, as follows:</p>
336 <div class="Source Java"><pre>
337 &lt;message type="15" important="no"&gt;
338 &lt;part&gt;firstPart&lt;/part&gt;
339 &lt;part&gt;secondPart&lt;/part&gt;
340 &lt;created&gt;1154097812245&lt;/created&gt;
341 &lt;/message&gt;
342 </pre></div>
343 <p>All you need to do is add the @XStreamAsAttribute annotation:</p>
344 <div class="Source Java"><pre>
345 @XStreamAlias("message")
346 class RendezvousMessage {
347
348 @XStreamAlias("type")
349 @XStreamAsAttribute
350 private int messageType;
351
352 @XStreamImplicit(itemFieldName="part")
353 private List&lt;String&gt; content;
354
355 @XStreamAsAttribute
356 @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"})
357 private boolean important;
358
359 @XStreamConverter(SingleValueCalendarConverter.class)
360 private Calendar created = new GregorianCalendar();
361
362 public RendezvousMessage(int messageType, boolean important, String... content) {
363 this.messageType = messageType;
364 this.important = important;
365 this.content = Arrays.asList(content);
366 }
367 }
368 </pre></div>
369
370 <!-- ...................................................... -->
371 <h2 id="FieldAsText">Field as Text Value</h2>
372
373 <p>Sometimes it is desirable to use a single field as text value for a XML element and all other fields should be
374 written as attributes. XStream delivers the ToAttributedValueConverter, that will write a type with this form:</p>
375 <div class="Source Java"><pre>
376 @XStreamAlias("message")
377 @XStreamConverter(value=ToAttributedValueConverter.class, strings={"content"})
378 class RendezvousMessage {
379
380 @XStreamAlias("type")
381 private int messageType;
382
383 private List&lt;String&gt; content;
384
385 @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"})
386 private boolean important;
387
388 @XStreamConverter(SingleValueCalendarConverter.class)
389 private Calendar created = new GregorianCalendar();
390
391 public RendezvousMessage(int messageType, boolean important, String... content) {
392 this.messageType = messageType;
393 this.important = important;
394 this.content = Arrays.asList(content);
395 }
396 }
397 </pre></div>
398
399 <p>Unfortunately our little example <strong>does not work</strong>! Although we register the converter with the
400 XStreamConverter annotation and provide with its arguments the field name, the conversion will fail later on. To use
401 this converter you have to respect the implicit requirement: Any field (derived or not) has to be expressed as a
402 single string i.e. technically XStream has to use a SingleValueConverter. In our case we have a list of strings that
403 prevent the conversion. Therefore we have to use either a custom converter that transforms this list into a single
404 string or we use for simplicity a simple string here:</p>
405 <div class="Source Java"><pre>
406 @XStreamAlias("message")
407 @XStreamConverter(value=ToAttributedValueConverter.class, strings={"content"})
408 class RendezvousMessage {
409
410 @XStreamAlias("type")
411 private int messageType;
412
413 private String content;
414
415 @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"})
416 private boolean important;
417
418 @XStreamConverter(SingleValueCalendarConverter.class)
419 private Calendar created = new GregorianCalendar();
420
421 public RendezvousMessage(int messageType, boolean important, String content) {
422 this.messageType = messageType;
423 this.important = important;
424 this.content = content;
425 }
426 }
427 </pre></div>
428
429 <p>Now it is possible to generate this XML:</p>
430 <div class="Source Java"><pre>
431 &lt;message type="15" important="no" created="1154097812245"&gt;This is the message content.&lt;/message&gt;
432 </pre></div>
433
434 <p>Note, that no XStreamAsAttribute annotations were necessary. The converter assumes it implicitly.</p>
435
436 <!-- ...................................................... -->
437 <h2 id="OmitField">Omitting Fields</h2>
438 <p>Sometimes a class may contain elements that should not be part of the resulting XML. In our case we may now drop
439 the 'messageType', since we are only interested at the content. This is easy using the @XStreamOmitField annotation:</p>
440 <div class="Source Java"><pre>
441 @XStreamAlias("message")
442 class RendezvousMessage {
443
444 @XStreamOmitField
445 private int messageType;
446
447 @XStreamImplicit(itemFieldName="part")
448 private List&lt;String&gt; content;
449
450 @XStreamConverter(value=BooleanConverter.class, booleans={false}, strings={"yes", "no"})
451 private boolean important;
452
453 @XStreamConverter(SingleValueCalendarConverter.class)
454 private Calendar created = new GregorianCalendar();
455
456 public RendezvousMessage(int messageType, boolean important, String... content) {
457 this.messageType = messageType;
458 this.important = important;
459 this.content = Arrays.asList(content);
460 }
461 }
462 </pre></div>
463 <p>The resulting XML does not contain the type of the message anymore:</p>
464 <div class="Source Java"><pre>
465 &lt;message&gt;
466 &lt;part&gt;firstPart&lt;/part&gt;
467 &lt;part&gt;secondPart&lt;/part&gt;
468 &lt;important&gt;no&lt;/important&gt;
469 &lt;created&gt;1154097812245&lt;/created&gt;
470 &lt;/message&gt;
471 </pre></div>
472
473 <!-- ...................................................... -->
474 <h2 id="AutoDetect">Auto-detect Annotations</h2>
475 <p>Until now we have always told you, that you have to call processAnnotation to configure the XStream instance with
476 the present annotations in the different classes. However, this is only half the truth. You can run XStream also in a
477 lazy mode, where it auto-detects the annotations while processing the object graph and configure the XStream instance
478 on-the-fly:</p>
479 <div class="Source Java"><pre>
480 package com.thoughtworks.xstream;
481 public class Tutorial {
482
483 public static void main(String[] args) {
484 XStream stream = new XStream();
485 xstream.autodetectAnnotations(true);
486 RendezvousMessage msg = new RendezvousMessage(15);
487 System.out.println(stream.toXML(msg));
488 }
489
490 }
491 </pre></div>
492 <p>The resulting XML will look as expected! Nevertheless you have to understand the implications, therefore some words
493 of warning:</p>
494 <ol>
495 <li><strong>Chicken-and-egg problem</strong>
496 <p>An XStream instance caches all class types processed for annotations. Every time XStream converts an object it will
497 in auto-detection mode first process the object's type and all the types related (as explained
498 <a href="#Aliasing">above</a>). Therefore it is no problem to serialize an object graph into XML, since XStream will
499 know of all types in advance. This is no longer true at deserialization time. XStream has to know the alias to turn
500 it into the proper type, but it can find the annotation for the alias only if it has processed the type in advance.
501 Therefore deserialization will fail if the type has not already been processed either by having called XStream's
502 processAnnotations method or by already having serialized this type. However, @XStreamAlias is the only annotation
503 that may fail in this case.</p></li>
504 <li><strong>Concurrency</strong>
505 <p>XStream is not thread-safe while it is configured, thread-safety is only guaranteed during marshalling and
506 unmarshalling. Unfortunately an annotation is defining a change in configuration that is now applied while object
507 marshalling is processed. Therefore will the auto-detection mode turn XStream's marshalling process in a thread-unsafe
508 operation. While XStream synchronizes the configuration modification, it cannot guard concurrent reads and you may run
509 under certain circumstances into concurrency problems. If you abolutely have to rely on annotation processing on the
510 fly, you will have to use separate XStream instances for each thread - either by using everytime a new instance or by a
511 shared pool.</p></li>
512 <li><strong>Exceptions</strong>
513 <p>XStream uses a well-defined exception hierarchy. Normally an InitializationException is only thrown while XStream
514 is configured. If annotations are processed on the fly they can be thrown obviously also in a marshalling process.</p></li>
515 <li><strong>Performance</strong>
516 <p>In auto-detection mode XStream will have to examine any unknown class type for annotations. This will slow down the
517 marshalling process until all processed types have been examined once.</p></li>
518 </ol>
519 <p>Please note, that any call to XStream.processAnnotations will turn off the auto-detection mode.</p>
520
521 <!-- ...................................................... -->
522 <h2 id="Summary">Summing up</h2>
523 <p>The XStream annotations support might help you configuring your class mappings in some ways, as the custom
524 configuration will appear in your types, but might not be the solution for other problems, i.e. when you need to map
525 the same type to two different XML 'standards'. Others might claim that the configuration should be clearly stated in
526 a Java class and not mixed with your model, its up to you to pick the best approach in your case: Annotations or
527 direct method calls to the XStream instance. Annotations do not provide more functionality, but may improve
528 convenience.</p>
529
530 </body>
531 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Architecture Overview</title>
14 </head>
15 <body>
16
17 <p>The architecture of XStream consists of the four main components:</p>
18
19 <ul>
20 <li><b>Converters</b></li>
21 <!-- TODO: Mappers -->
22 <li><b>Drivers (Writer and Reader)</b></li>
23 <li><b>Context</b></li>
24 <li><b>Facade</b></li>
25 </ul>
26
27 <!-- ************ -->
28
29 <h1 id="Converters">Converters</h1>
30
31 <p>Whenever XStream encounters an object that needs to be converted to/from XML, it delegates to a suitable
32 <a href="javadoc/com/thoughtworks/xstream/converters/Converter.html">Converter</a> implementation associated
33 with the class of that Object.</p>
34
35 <p>XStream comes <a href="converters.html">bundled with many converters</a> for common types, including primitives,
36 String, Collections, arrays, null, Date, etc.</p>
37
38 <p>XStream also has a <i>default Converter</i>, that is used when no other Converters match a type. This uses
39 reflection to automatically generate the XML for all the fields in an object.</p>
40
41 <p>If an object is composed of other objects, the Converter may delegate to other Converters.</p>
42
43 <p class="highlight">To customize the XML for particular object type a new Converter should be implemented.</p>
44
45
46 <!-- ************ -->
47
48 <h1 id="Drivers">Drivers (Writer and Reader)</h1>
49
50 <p>XStream is abstracted from the underlying XML data using the
51 <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamWriter.html">HierarchicalStreamWriter</a>
52 and <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamReader.html">HierarchicalStreamReader</a>
53 interfaces for serializing and deserializing respectively.</p>
54
55 <p>This abstraction allows XStream to read XML from direct streams using an XML parser or directly manipulate
56 existing structures (such as DOM). This prevents the overhead of having to reparse if XStream is working from
57 XML that has been partially processed by other libraries (for instance a SOAP library). It also avoids tying XStream
58 to a particular library.</p>
59
60 <p>XStream comes bundled with
61 <a href="javadoc/com/thoughtworks/xstream/io/xml/package-summary.html">reader and writer implementations</a> for
62 most major XML libraries.</p>
63
64 <p class="highlight">Writer and Readers can be implemented allowing XStream to serialize to most XML APIs.
65 Writers and Readers can also be created around tree based non XML structures.</p>
66
67 <!--
68 note: one reader/writer per context
69 note: why not sax
70 -->
71
72 <!-- ************ -->
73
74 <h1 id="Context">Context</h1>
75
76 <p>When XStream serializes or deserializes some objects, it creates a
77 <a href="javadoc/com/thoughtworks/xstream/converters/MarshallingContext.html">MarshallingContext</a> or
78 <a href="javadoc/com/thoughtworks/xstream/converters/UnmarshallingContext">UnmarshallingContext</a>,
79 which handle the traversing of the data and delegation to the necessary Converters.</p>
80
81 <p class="highlight">The MarshallingContext/UnmarshallingContext is made available to converters allowing them
82 to tell XStream to process objects contained within other objects.</p>
83
84 <p>XStream provides three pairs of context implementations that traverse the object graph with slightly
85 different behaviors. The default can be changed using
86 <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream.setMode()</a>, passing in one of
87 the following parameters:</p>
88
89 <ul>
90 <li>
91 <b>XStream.XPATH_RELATIVE_REFERENCES</b><br/>
92 <i>(Default)</i> Uses relative XPath references to signify duplicate references. This produces XML with
93 the least clutter.
94 </li>
95 <li>
96 <b>XStream.XPATH_ABSOLUTE_REFERENCES</b><br/>
97 Uses absolute XPath references to signify duplicate references. This might produce for some situations
98 better readable XML. <i>Note, that XStream will read XML with relative paths as well as with absolute
99 paths independent of the XPATH mode.</i>
100 </li>
101 <li>
102 <b>XStream.ID_REFERENCES</b><br/>
103 Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written
104 XML, this is easier to work with.
105 </li>
106 <li>
107 <b>XStream.NO_REFERENCES</b><br/>
108 This disables object graph support and treats the object structure like a tree. Duplicate references are
109 treated as two separate objects and circular references cause an exception. This is slightly faster and
110 uses less memory than the other two modes.
111 </li>
112 </ul>
113
114 <p class="highlight">A new context is created for each object graph that is serialized. Both the
115 <a href="javadoc/com/thoughtworks/xstream/converters/MarshallingContext.html">MarshallingContext</a> and
116 <a href="javadoc/com/thoughtworks/xstream/converters/UnmarshallingContext.html">UnmarshallingContext</a>
117 implement <a href="javadoc/com/thoughtworks/xstream/converters/DataHolder.html">DataHolder</a>,
118 a hash table passed around whilst processing the object graph that can be used as the user sees fit (in a similar
119 way that the HttpServletRequest attributes are used in a web-application).</p>
120
121
122 <!-- ************ -->
123
124 <h1 id="Facade">XStream facade</h1>
125
126 <p>The main <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream</a> class is typically used as the
127 entry point. This assembles the necessary components of XStream (as described above; Context, Converter,
128 Writer/Reader and ClassMapper) and provides a simple to use API for common operations.</p>
129
130 <p class="highlight">Remember, the XStream class is just a facade - it can always be bypassed for more advanced
131 operations.</p>
132
133
134 </body>
135 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Change History</title>
14 </head>
15 <body>
16
17 <p>Changes are split into three categories:</p>
18
19 <ul>
20 <li><b>Major changes</b>: The major new features that all users should know about.</li>
21 <li><b>Minor changes</b>: Any smaller changes, including bugfixes.</li>
22 <li><b>API changes</b>: Any changes to the API that could impact existing users.</li>
23 </ul>
24
25 <p>Full details can be found in Jira's
26 <a href="http://jira.codehaus.org/browse/XSTR?report=com.atlassian.jira.plugin.system.project:roadmap-panel">Roadmap</a> and
27 <a href="http://jira.codehaus.org/browse/XSTR?report=com.atlassian.jira.plugin.system.project:changelog-panel">Change Log</a>.
28 </p>
29 <!--
30 <h1 id="upcoming-1.4.x">Upcoming 1.4.x maintenance release</h1>
31
32 <p>Not yet released.</p>
33 -->
34 <h1 id="1.4.8">1.4.8</h1>
35
36 <p>Released February 18, 2015.</p>
37
38 <h2>Major changes</h2>
39
40 <ul>
41 <li>Support for serializable lambda expressions and handling of non-serializable ones.</li>
42 </ul>
43
44 <h2>Minor changes</h2>
45
46 <ul>
47 <li>Detect Java 9 runtime.</li>
48 <li>XSTR-767: Deserialization of referenced lambda expressions fail.</li>
49 <li>XSTR-762: Private method readResolve() called on base classes.</li>
50 <li>XSTR-761: Support ignored serialPersistentField at deserialization time.</li>
51 <li>XSTR-755: ExternalizableConverter does not respect writeReplace and readResolve.</li>
52 <li>XSTR-757: Deserialized TreeSet does not honor remove(Object) return value contract.</li>
53 <li>XSTR-759: Support deserialization of <a href="http://www.w3.org/TR/NOTE-datetime">W3C datetime format</a>
54 in DateConverter with Java 7 runtime.</li>
55 <li>Fix: DateConverter ignores provided locale.</li>
56 <li>XSTR-768: ISO8601GregorianCalendarConverter may set invalid time zone for Joda-Time.</li>
57 <li>Fix: WeakCache.entrySet().iterator().next.setValue(value) returns the reference instead of the old value.</li>
58 <li>Fix: SqlTimestampConverter throws IllegalArgumentException instead of ConversionException on fromString().</li>
59 <li>Fix: CGLIBEnhancedConverter does not initialize transient members of parent after deserialization.</li>
60 <li>XSTR-763: Set scope of org.json:json to test instead declaring the dependency as optional.</li>
61 </ul>
62
63 <h2>API changes</h2>
64
65 <ul>
66 <li>Added c.t.x.util.JVM.is19().</li>
67 <li>Added c.t.x.converter.reflection.LambdaConverter and c.t.x.mapper.LambdaMapper.</li>
68 <li>Declare c.t.x.XStream.ignoreUnknownElements(Pattern) as public.</li>
69 <li>c.t.x.converters.reflection.AbstractReflectionConverter.readResolve() is protected now.</li>
70 <li>c.t.x.mapper.AbstractAttributeAliasingMapper.readResolve() is protected now.</li>
71 <li>Deprecated c.t.x.converters.extended.StackTraceElementFactory, it is an internal helper class.</li>
72 <li>Deprecated c.t.x.converters.reflection.SerializationMethodInvoker, it is an internal helper class.</li>
73 <li>Deprecated c.t.x.io.AttributeNameIterator, it is an internal helper class.</li>
74 <li>Deprecated c.t.x.XStream.useXStream11XmlFriendlyMapper(), corresponding
75 c.t.x.mapper.XStream11XmlFriendlyMapper has been deprecated long ago.</li>
76 <li>Deprecated c.t.x.converter.basic.BooleanConverter.shouldConvert(Class,Object), undetected remainder of
77 ancient XStream version.</li>
78 </ul>
79
80 <h1 id="1.4.7">1.4.7</h1>
81
82 <p>Released February 8, 2014.</p>
83
84 <p class="highlight">This maintenance release addresses mainly the security vulnerability CVE-2013-7285, an
85 arbitrary execution of commands when unmarshalling.</p>
86
87 <h2>Major changes</h2>
88
89 <ul>
90 <li>Add <a href="security.html#framework">security framework</a> to limit handled types while unmarshalling.</li>
91 <li>java.bean.EventHandler no longer handled automatically because of severe security vulnerability.</li>
92 <li>JIRA:XSTR-751: New SunLimitedUnsafeReflectionProvider that uses undocumented features only to allocate new
93 instances as required on Dalvik.</li>
94 <li>Fix instantiation of AnnotationMapper that requires ConverterLookup and ConverterRegistry to be the same
95 instance.</li>
96 </ul>
97
98 <h2>Minor changes</h2>
99
100 <ul>
101 <li>XSTR-749: NPE if ReflectionConverter.canConvert(type) is called with null as argument.</li>
102 <li>XSTR-753: NPE if SerializationConverter.canConvert(type) is called with an interface type as argument that
103 extends Serializable.</li>
104 <li>Add constructor to ReflectionConverter taking an additional type to create an instance that is
105 dedicated to a specific type only.</li>
106 <li>The ConverterLookup used by default cannot be casted to a ConverterRegistry anymore.</li>
107 </ul>
108
109 <h2>API changes</h2>
110
111 <ul>
112 <li>Added package c.t.x.security with interface TypePermission, all its implementations and
113 ForbiddenClassException.</li>
114 <li>Added c.t.x.mapper.SecurityMapper handling the new type permissions.</li>
115 <li>Added methods addPermission, denyPermission, allowTypesXXX and denyTypesXXX to c.t.x.XStream to setup
116 security at unmarshalling time.</li>
117 <li>Added c.t.x.converters.reflection.SunLimitedUnsafeReflectionProvider.</li>
118 <li>Deprecated c.t.x.converters.reflection.Sun14ReflectionProvider in favor of new
119 c.t.x.converters.reflection.SunUnsafeReflectionProvider.</li>
120 <li>Added c.t.x.converters.reflection.ReflectionConverter(Mapper,ReflectionProvider,Class).</li>
121 </ul>
122
123 <h1 id="1.4.6">1.4.6</h1>
124
125 <p>Released December 12, 2013.</p>
126
127 <h2>Major changes</h2>
128
129 <ul>
130 <li>JIRA:XSTR-566 and JIRA:XSTR-200: Better compatibility with GAE and environments with active SecurityManager (i.e. in an
131 Applet). XStream converters try now to ensure already in the canConvert methods that they can handle the requested type in
132 practice and not only theoretically. Additionally the implementations even better take care, that the initialization of a
133 converter will not break the setup of XStream itself. Following modifications have been done for these topics:
134 <ul>
135 <li>ReflectionConverter, SerializationConverter and LookAndFieldConverter will check if they can access the fields by
136 reflection for a requested type.</li>
137 <li>SerializationConverter and ExternalizableConverter will check if they can create an instance of a derived
138 OutputObjectStream first.</li>
139 <li>BeanProvider does no longer use reflection to locate default constructor.</li>
140 <li>AbstractAttributedCharacterIteratorAttributeConverter (and therefore TextAttributeConverter) will check first if it
141 can access the possible constants of the type by reflection.</li>
142 <li>NoClassDefFoundError raised in GAE accessing the fields of restricted types by reflection will be handled.</li>
143 <li>StackTraceElementConverter uses constructor for StackTraceElement instances in Java 5 and GEA.</li>
144 </ul>
145 </li>
146 <li>JIRA:XSTR-739 and JIRA:XSTR-746: OrderRetainingMap fails if HashMap.putAll(Map) of Java Runtime is not
147 implemented calling put for every element within the map.</li>
148 <li>New NamedArrayConverter to define names of inner elements.</li>
149 </ul>
150
151 <h2>Minor changes</h2>
152
153 <ul>
154 <li>JIRA:XSTR-747: All constructors of StaxDriver derived classes take erroneously a XmlFriendlyNameCoder
155 instead of a plain NameCoder.</li>
156 </ul>
157
158 <h2>API changes</h2>
159
160 <ul>
161 <li>Added c.t.x.converters.extended.NamedArrayConverter for free element names in arrays.</li>
162 <li>Added constructors to c.t.x.io.xml.StandardStaxDriver taking NameCoder instead of XmlFriendlyNameCoder.</li>
163 <li>Deprecated constructors of c.t.x.io.xml.StandardStaxDriver taking a XmlFriendlyNameCoder.</li>
164 <li>Added constructors to c.t.x.io.xml.BEAStaxDriver taking NameCoder instead of XmlFriendlyNameCoder.</li>
165 <li>Deprecated constructors of c.t.x.io.xml.BEAStaxDriver taking a XmlFriendlyNameCoder.</li>
166 <li>Added constructors to c.t.x.io.xml.WstxDriver taking NameCoder instead of XmlFriendlyNameCoder.</li>
167 <li>Deprecated constructors of c.t.x.io.xml.WstxDriver taking a XmlFriendlyNameCoder.</li>
168 <li>Added method canAccess to c.t.x.converter.reflection.AbstractReflectionConverter.</li>
169 <li>Added static method canCreateDerivedObjectOutputStream to c.t.x.core.JVM.</li>
170 <li>Deprecated unused member c.t.x.converter.javabean.BeanProvider.NO_PARAMS.</li>
171 <li>Deprecated unused method c.t.x.converter.javabean.BeanProvider.getDefaultConstrutor(Class).</li>
172 </ul>
173
174
175 <h1 id="1.4.5">1.4.5</h1>
176
177 <p>Released September 18, 2013.</p>
178
179 <h2>Major changes</h2>
180
181 <ul>
182 <li>JIRA:XSTR-732: Use a referencing implementation for the ClassLoader to support environments where no new
183 ClassLoader can be instantiated due to security restrictions.</li>
184 <li>JIRA:XSTR-691: Allow unknown XML elements to be ignored using new method XStream.ignoreUnknownElements.</li>
185 <li>JIRA:XSTR-728: XStream creates invalid JSON with JsonHierarchicalStreamDriver for custom converters since
186 XStream 1.4.</li>
187 <li>JIRA:XSTR-300: New EnumToStringConverter to support custom string representations of Enum values.</li>
188 <li>JIRA:XSTR-292 and JIRA:XSTR-405: New NamedMapConverter and NamedCollectionConverter to define names of
189 inner elements.</li>
190 <li>JIRA:XSTR-726: New annotation XStreamAliasType to support declarative definition of XStream.aliasType().</li>
191 <li>JIRA:XSTR-735: Support for JDOM2 with JDom2Driver, JDom2Reader and JDom2Writer.</li>
192 <li>Optimized XML structure for java.awt.Font.</li>
193 <li>Fix: ToAttributedValueConverter silently appends fields without attribute support to the value producing mixed-mode XML.</li>
194 <li>JIRA:XSTR-566 and JIRA:XSTR-249: Better compatibility with Google AppEngine and J2ME, setup no longer fails for unavailable converters.</li>
195 </ul>
196
197 <h2>Minor changes</h2>
198
199 <ul>
200 <li>Fix missing manifest information.</li>
201 <li>JIRA:XSTR-729: Add OSGi information to manifests.</li>
202 <li>JIRA:XSTR-723: XStream will now detect a working enhanced mode dynamically instead using lists of known
203 vendors. This allows enhanced support for JamVM if it is bundled with OpenJDK. It will currently fail on a
204 runtime based on GNU Classpath (at least up to version 0.98).</li>
205 <li>JIRA:XSTR-541: JavaScript compatibility problem with 64-bit integers in JSON.</li>
206 <li>JIRA:XSTR-719: Support replacement of default converter in any case.</li>
207 <li>JIRA:XSTR-725: processAnnotation performance improvement in concurrent situation.</li>
208 <li>JIRA:XSTR-721: EnumConverter is more lenient while parsing constants.</li>
209 <li>New constructors for CollectionConverter and MapConverter to allow registration for an individual type.</li>
210 <li>JIRA:XSTR-724: Cache class name lookup failures.</li>
211 <li>Current IBM JDK for Java 1.4.2 no longer has a reverse field ordering.</li>
212 <li>LongConverter supports now positive hex and octal numbers over Long.MAX_VALUE within 64 bit.</li>
213 <li>Fix: Sun14RefectionProvider ignores a provided FieldDictionary.</li>
214 <li>JIRA:XSTR-457: Do not write 'defined-in' attribute it not needed.</li>
215 <li>JettisonMappedXmlDriver provides better support to overwrite its create methods.</li>
216 <li>JIRA:XSTR-685: StAX based drivers (StaxDriver and JettisonMappedXmlDriver) are not closing internal input
217 stream reading from file or URL.</li>
218 <li>JIRA:XSTR-736: XStream.unmarshal may throw NPE if version info of manifest is missing.</li>
219 <li>JIRA:XSTR-733: Implicit elements that match multiple defined implicit collections will be assigned to the
220 map with the nearest matching element type.</li>
221 <li>JIRA:XSTR-740: ISO8601GregorianCalendarConverter creates Calendar instance with wrong Locale in Java 7 if
222 the Locale for the LocaleCategory.FORMAT is different to the global default Locale.</li>
223 <li>JIRA:XSTR-578: Implement support for aliasing in JavaClasConverter, JavaFieldConverter and
224 JavaMethodConverter. While it is not possible to enable this in general, new constructors have been added to
225 these converters and an example in the acceptance tests (AliasTest).</li>
226 <li>JIRA:XSTR-742: Register CompositeClassLoader in Java 7 as parallel capable.</li>
227 <li>JIRA:XSTR-743: Support proxy collections of Hibernate Envers.</li>
228 <li>Fix NPE in AttributeMapper.shouldLookForSingleValueConverter if parameters fieldName and definedIn are null.</li>
229 <li>Implicit type argument can be omitted when registering converters with @XStreamConverter annotation.</li>
230 </ul>
231
232 <h2>API changes</h2>
233
234 <ul>
235 <li>Added c.t.x.converters.extended.NamedCollectionConverter for free element names in collections.</li>
236 <li>Added c.t.x.converters.extended.NamedMapConverter for free element names in maps.</li>
237 <li>Added c.t.x.io.xml.StandardStaxDriver to use the StAX implementation delivered with the Java 6 runtime.</li>
238 <li>Deprecated c.t.x.io.xml.SjsxpStaxDriver to select the internal StAX implementation of Oracle.</li>
239 <li>Added static methods getStaxInputFactory and getStaxOutputFactory to c.t.x.core.JVM as returning the
240 implementations of javax.xml.stream.XMLInputFactory (resp. javax.xml.stream.XMLOutputFactory) delivered with
241 the Java Runtime since Java 6.</li>
242 <li>Added c.t.x.core.ClassLoaderReference.</li>
243 <li>Added constructors taking an additional Class argument for c.t.x.converters.collections.CollectionConverter
244 and c.t.x.converters.collections.MapConverter.</li>
245 <li>Added constructors taking a ClassLoaderReference instead of a ClassLoader and deprecated the ones taking the ClassLoader:
246 <ul>
247 <li>c.t.x.XStream</li>
248 <li>c.t.x.converters.extended.DynamicProxyConverter</li>
249 <li>c.t.x.converters.extended.JavaClassConverter</li>
250 <li>c.t.x.converters.extended.JavaFieldConverter</li>
251 <li>c.t.x.converters.extended.JavaMethodConverter</li>
252 <li>c.t.x.converters.reflection.CGLIBEnhancedConverter</li>
253 <li>c.t.x.converters.reflection.ExternalizableConverter</li>
254 <li>c.t.x.converters.reflection.SerializableConverter</li>
255 <li>c.t.x.mapper.AnnotationMapper</li>
256 <li>c.t.x.mapper.DefaultMapper</li>
257 </ul>
258 </li>
259 <li>Added static methods newReflectionProvider, isAWTAvailable, isSQLAvailable and isSwingAvailable to
260 c.t.x.core.JVM as replacement for the deprecated non-static methods.</li>
261 <li>Deprecated c.t.x.core.JVM() and all non-static methods.</li>
262 <li>Added method useImplicitType to c.t.x.annotations.XStreamConverter.</li>
263 <li>JIRA:XSTR-722: Added
264 c.t.x.converters.reflection.ReflectionProvider.getFieldOrNull(Class, String).</li>
265 <li>Deprecated
266 c.t.x.converters.reflection.ReflectionProvider.fieldDefinedInClass(Class, String) in
267 favor of new c.t.x.converters.reflection.ReflectionProvider.getFieldOrNull(Class,
268 String).</li>
269 <li>Deprecated constructor c.t.x.converters.extended.RegexPatternConverter(Converter)
270 in favor of c.t.x.converters.extended.RegexPatternConverter().</li>
271 <li>Deprecated default constructor of c.t.x.converters.extended.FontConverter in favor of
272 c.t.x.converters.extended.FontConverter(Mapper).</li>
273 <li>Deprecated constructor c.t.x.converters.extended.ThrowableConverter(Converter)
274 in favor of c.t.x.converters.extended.ThrowableConverter(ConverterLookup).</li>
275 <li>Deprecated class c.t.x.converters.reflection.SelfStreamingInstanceChecker and moved
276 original implementation into c.t.x.core.util, since it is internal.</li>
277 <li>Deprecated interface c.t.x.mapper.AnnotationConfiguration.</li>
278 </ul>
279
280 <h1 id="1.4.4">1.4.4</h1>
281
282 <p>Released January 19, 2013.</p>
283
284 <h2>Minor changes</h2>
285
286 <ul>
287 <li>JIRA:XSTR-709: Locks up on Mac with Apple JVM due to unwanted initialization of AWT.</li>
288 <li>JIRA:XSTR-711: DateConverter cannot handle dates in different era.</li>
289 <li>JIRA:XSTR-741: ToAttributedValueConverter fails to write enums as attributes.</li>
290 <li>JIRA:XSTR-712: HibernateMapper throws NPE if a collection contains null.</li>
291 <li>DateConverter supports now localized formats.</li>
292 <li>JIRA:XSTR-710: JsonWriter does not write BigInteger and BigDecimal as number values.</li>
293 <li>JIRA:XSTR-708: SqlTimestampConverter does not ignore timezone.</li>
294 <li>JIRA:XSTR-707: Creation of XmllPullParser with the XmlPullParserFactory may fail in OSGi environment.</li>
295 <li>JIRA:XSTR-705: Unnecessary synchronization accessing the field cache decreases performance.</li>
296 <li>JIRA:XSTR-714: Fields not found when XStream12FieldKeySorter used.</li>
297 </ul>
298
299 <h2>API changes</h2>
300
301 <ul>
302 <li>Deprecated method c.t.x.core.util.JVM.is14(), c.t.x.core.util.JVM.is15() and c.t.x.core.util.JVM.is16().</li>
303 </ul>
304
305 <h1 id="1.4.3">1.4.3</h1>
306
307 <p>Released July 17, 2012.</p>
308
309 <h2>Major changes</h2>
310
311 <ul>
312 <li>Support java.util.concurrent.ConcurrentHashMap with the MapConverter. This will also avoid a bug in JRockit
313 JDK reported in JIRA:XSTR-608.</li>
314 <li>JIRA:XSTR-699: Support for Hibernate 4 with XStream's Hibernate module as default for Java 6 or higher.</li>
315 </ul>
316
317 <h2>Minor changes</h2>
318
319 <ul>
320 <li>JVM.loadClass will now also initialize the loaded class and ignore any occurring LinkageError.</li>
321 <li>JIRA:XSTR-596: SubjectConverter will be no longer registered if initialization of javax.security.auth.Subject fails.</li>
322 <li>JIRA:XSTR-683: Inheritance of implicit collections, arrays or maps is dependent on declaration sequence.</li>
323 <li>Inherited implicit collections, arrays or maps can be overwritten with own definition in subtype.</li>
324 <li>JIRA:XSTR-688: Cannot omit XML elements from derived fields.</li>
325 <li>JIRA:XSTR-696: Ill-formed JSON generated, because JSON writer is fed with type of declaring field instead of
326 the real object's type.</li>
327 <li>JIRA:XSTR-685: Deserialization from file or URL keeps stream open.</li>
328 <li>JIRA:XSTR-684: XML 1.0 character validation fails for characters from 0x10 to 0x1f.</li>
329 <li>JavaBeanConverter supports now instantiation for a specific type and can therefore be used in
330 @XStreamConverter annotation.</li>
331 <li>SerializableConverter is broken if the serialized type is the default implementation.</li>
332 <li>Method marshalUnserializableParent of SerializableConverter is protected now to skip the default mechanism
333 in a derived converter that uses the default constructor to create the original type (as an alternative for
334 JIRA:XSTR-695).</li>
335 <li>FieldDictionary may call sort of FieldKeySorter implementation with wrong type as key.</li>
336 <li>Sometimes DependencyInjectionFactory tries to instantiate objects with mismatching constructor arguments.</li>
337 <li>HSQLDB has to be a test dependency only for XStream's Hibernate module.</li>
338 </ul>
339
340 <h1 id="1.4.2">1.4.2</h1>
341
342 <p>Released November 3, 2011.</p>
343
344 <h2>Major changes</h2>
345
346 <ul>
347 <li>XStream libraries can be used now directly in Android, therefore support of Java 1.4.2 has been stopped with the delivery.
348 Anyone who needs a version for Java 1.4.2 can build it easily from source, this build is still supported and part of CI.</li>
349 <li>JIRA:XSTR-675: New extended HierarchicalStreamReader interface with peekNextChild method. All XStream
350 readers implement the new interface (by Nikita Levyankov).</li>
351 <li>JIRA:XSTR-673: Collections.EMPTY_LIST, Collections.EMPTY_SET and Collections.EMPTY_MAP supported with own
352 alias and defined as immutable.</li>
353 <li>JIRA:XSTR-631: Collections.singletonList(), Collections.singletonSet() and Collections.singletonMap()
354 supported with own alias and own converters.</li>
355 <li>JIRA:XSTR-406 + JIRA:XSTR-663: Support additional parameters for XStreamConverter annotation (e.g. to declare a
356 ToAttributedValueConverter).</li>
357 </ul>
358
359 <h2>Minor changes</h2>
360
361 <ul>
362 <li>WstxDriver did not trigger Woodstox, but BEA StAX implementation.</li>
363 <li>JIRA:XSTR-260: PrettyPrintWriter does not handle tab and new line characters in attributes.</li>
364 <li>JIRA:XSTR-667: Cannot serialize empty list with JsonHierarchicalStreamDriver.</li>
365 <li>JIRA:XSTR-661: TreeMarshaller.CircularReference is not a ConversionException.</li>
366 <li>JIRA:XSTR-562: StAX: Namespace attribute is not written in non-repairing mode for second sibling.</li>
367 <li>JIRA:XSTR-664: ClassCastException in HibernatePersistentSortedSetConverter and
368 HibernatePersistentSortedMapConverter.</li>
369 <li>JIRA:XSTR-674: Recreate binary compatibility with 1.3.x series for method
370 CustomObjectInputStream.getInstance(...).</li>
371 <li>JIRA:XSTR-671: CannotResolveClassException should accept cause.</li>
372 <li>JIRA:XSTR-672: Collections.EMPTY_LIST, Collections.EMPTY_SET and Collections.EMPTY_MAP used for in implicit
373 collection should not throw ReferencedImplicitElementException.</li>
374 <li>JIRA:XSTR-676: Introduce MissingFieldException thrown at deserialization time indicating a missing field or
375 property (by Nikita Levyankov).</li>
376 <li>Add length limit for cached strings in StringConverter, 38 characters by default.</li>
377 <li>The JsonHierarchicalStreamDriver and the JsonWriter did not support the inherited NameCoder instance.</li>
378 <li>Add BinaryStreamDriver.</li>
379 <li>NPE in XppDomComparator.</li>
380 <li>Dom4JXmlWriter fails to flush the underlying writer.</li>
381 <li>Known control characters are not encoded with JsonWriter as proposed at json.org.</li>
382 <li>Detect duplicate property processing in JavaBeanConverter and throw DuplicatePropertyException instead of
383 clobbering silently.</li>
384 <li>Allow access to Mapper and JavaBeanProvider in derived instances of JavaBeanConverter.</li>
385 <li>DependencyInjectionFactory failed to create instance when a matching constructor was found, but a default
386 constructor was also present.</li>
387 </ul>
388
389 <h2>API changes</h2>
390
391 <ul>
392 <li>Added interface c.t.x.io.ExtendedHierarchicalStreamReader extending c.t.x.io.HierarchicalStreamReader. All
393 implementations of c.t.x.io.HierarchicalStreamReader will implement also the extended interface.</li>
394 <li>Added c.t.x.converters.reflection.MissingFieldException derived from
395 c.t.x.converters.reflection.ObjectAccessException and used instead when the unmarshalling process should write
396 a field or property that is missing and does not exist.</li>
397 <li>Added methods c.t.x.io.path.PathTracker.peekElement(), c.t.x.io.path.PathTracker.peekElement(int), and
398 c.t.x.io.path.PathTracker.depth().</li>
399 <li>Deprecated method c.t.x.core.ReferencingMarshallingContext.currentPath(). Wrong approach.</li>
400 </ul>
401
402 <h1 id="1.4.1">1.4.1</h1>
403
404 <p>Released August 11, 2011.</p>
405
406 <h2>Major changes</h2>
407
408 <ul>
409 <li>JIRA:XSTR-659: Use again Xpp3 as default parser, now with additional XmlPullParser API as regular
410 dependency for the XPP factory. Only standard kXML2 package contains the XPP factory, but not the minimal kXML2
411 version.</li>
412 </ul>
413
414 <h2>Minor changes</h2>
415
416 <ul>
417 <li>Add utility class c.t.x.io.xml.xppdom.XppFactory and a path tracking comparator for XppDom.</li>
418 </ul>
419
420 <h1 id="1.4">1.4</h1>
421
422 <p>Released August 6, 2011.</p>
423
424 <h2>Major changes</h2>
425
426 <ul>
427 <li>Java 7 is detected and supported.</li>
428 <li>JIRA:XSTR-542: The XppDriver uses now the official XmlPullParser API to locate an available parser using
429 the XmlPullParserFactory. This allows the usage of XPP technology with XStream in Android.</li>
430 <li>Additional explicit XPP drivers for the Xpp3 and kXML2 implementations.</li>
431 <li>Additional explicit XPP DOM drivers for the Xpp3 and kXML2 implementations.</li>
432 <li>kXML2 is now the preferred parser implementation, Xpp3 is optional.</li>
433 <li>Additional explicit StAX drivers for Woodstox, BEA StAX and SJSXP of the JDK 6 implementations.</li>
434 <li>JDK 1.3 is no longer officially supported.</li>
435 <li>JIRA:XSTR-377+JIRA:XSTR-226: New artifact xstream-hibernate with converters and mapper to process Hibernate
436 object graphs (by Costin Leau, Konstantin Pribluda and in special Jaime Metcher).</li>
437 <li>New NameCoder interface and implementations to support a generic name translation between names from the
438 object graph and a target format. The new XmlFriendlyNameCoder replaces the XmlFriendlyReplacer used for XML
439 only.</li>
440 <li>JIRA:XSTR-553: Support annotations in Android.</li>
441 <li>JIRA:XSTR-556: DateConverter uses format with 3-letter time zones that are ambiguous. Therefore it will now
442 always use UTC to write dates. Unmarshalled dates are not affected as long as they contain a time zone.</li>
443 <li>The type java.lang.reflect.Field is now handled by an own converter, that can still read the old format.</li>
444 <li>JIRA:XSTR-490: Provide path in Converter for contexts that track the path.</li>
445 <li>JIRA:XSTR-592+JIRA:XSTR-579: OmitField respected at deserialization time even for existing fields.</li>
446 <li>JIRA:XSTR-593: Direct support for java.net.URI instances (by Carlos Roman).</li>
447 <li>JIRA:XSTR-615+JIRA:XSTR-580: Dynamic proxies cannot be referenced recursively.</li>
448 <li>JIRA:XSTR-547: Wrong class loader used for Serializable types deserialized with an ObjectInputStream.</li>
449 <li>JIRA:XSTR-341: Support of implicit arrays.</li>
450 <li>JIRA:XSTR-306+JIRA:XSTR-406: Support of implicit maps.</li>
451 <li>JIRA:XSTR-344: New ToAttributedValueConverter to allow conversion of an element with string body and
452 attributes.</li>
453 <li>JIRA:XSTR-573: SortedSet added with TreeSet as the default implementation.</li>
454 <li>JIRA:XSTR-576: TreeMap and TreeSet no longer add an element without comparator (by Jason Greanya),
455 solves also invalid format with JSON for such objects (JIRA:XSTR-640).</li>
456 </ul>
457
458 <h2>Minor changes</h2>
459
460 <ul>
461 <li>JIRA:XSTR-612: Improve extensibility of c.t.x.javabean.* package by reintroducing a PropertyDictionary with
462 the additional interface PropertySorter.</li>
463 <li>JIRA:XSTR-591: EnumSingleValueConverter did use toString() instead of name() to create the String
464 representation of an enum value.</li>
465 <li>JIRA:XSTR-618: Add Oracle as vendor used for recent JRockit versions and former Sun JDK.</li>
466 <li>JIRA:XSTR-656: DomReader and Dom4JReader do not escape attribute names retrieving their values.</li>
467 <li>JIRA:XSTR-604: StringConverter's cache may cause an OutOfMemoryException.</li>
468 <li>JIRA:XSTR-577: Skip UTF-8 BOM in XmlHeaderAwareReader.</li>
469 <li>The XppReader no longer uses a BufferedReader.</li>
470 <li>JIRA:XSTR-543: Better deserialization support of the defined-in system attribute in combination with field
471 aliases.</li>
472 <li>JIRA:XSTR-551: Deprecated XStream.InitializationException still thrown instead of InitializationException.</li>
473 <li>JIRA:XSTR-655: JsonWriter generates invalid JSON for Externalizable types.</li>
474 <li>JIRA:XSTR-540: Support Jettison-based configuration of JettisonMappedXmlDriver (by Doug Daniels).</li>
475 <li>JIRA:XSTR-633: JettisonMappedXmlDriver escaped property names according escape rules for XML tag names.</li>
476 <li>JIRA:XSTR-625: Optionally ignore XStream's hints for Jettison to generate JSON arrays (by Dejan Bosanac).</li>
477 <li>JIRA:XSTR-605: Upgrade to Jettison 1.2 (for Java 5 or higher).</li>
478 <li>New JsonWriter.EXPLICIT_MODE generating JSON that enforces property sequence.</li>
479 <li>JIRA:XSTR-552: Improve performance of ReflectionProvider (by Keith Kowalczykowski).</li>
480 <li>JIRA:XSTR-559: Improve performance of Sun14ReflectionProvider (by Keith Kowalczykowski).</li>
481 <li>JIRA:XSTR-564: Improve performance of AnnotationMapper (by Keith Kowalczykowski).</li>
482 <li>JIRA:XSTR-563: Use ReferenceQueue for cleaning-up WeakReferences in ObjectIdDictionary (by Keith
483 Kowalczykowski).</li>
484 <li>JIRA:XSTR-646: Cache of Sun14ReflectionProvider consumes more PermGen space than necessary.</li>
485 <li>JIRA:XSTR-636: Ineffective cache in FieldDictionary using WeakHashMap with WeakReference values.</li>
486 <li>Ineffective cache for SerializationMethodInvoker (related to JIRA:XSTR-636).</li>
487 <li>Introduction of Caching interface implemented by all types in XStream that create local caches that may
488 have to be flushed manually.</li>
489 <li>Avoid excessive creation of AbstractPullReader.Event objects by using a pool.</li>
490 <li>Possibility to generate XPath expressions that select always a single node instead of a node list.</li>
491 <li>Cannot reference replaced object using ID references.</li>
492 <li>Implicit collection functionality will no longer use custom collection converters that may write tags that are not
493 recognized at deserialization time again.</li>
494 <li>JIRA:XSTR-654: Unmarshal fails when an implicit collection is defined and an element is named equal to the field.</li>
495 <li>JIRA:XSTR-574: AbstractReferenceUnmarshaller cannot handle null values for references.</li>
496 <li>Improve exception output in case of a missing field.</li>
497 <li>JIRA:XSTR-555: StAX driver tests do not honor repairing mode.</li>
498 <li>JIRA:XSTR-570: The @XStreamConverter provides now also the current type as possible constructor argument.</li>
499 <li>JIRA:XSTR-629: Deserialization of Externalizable with non-accessible default constructor fails.</li>
500 <li>JIRA:XSTR-571: Cannot serialize synchronized RandomAccessList types.</li>
501 <li>JIRA:XSTR-583: BinaryDriver fails to handle Strings with more than 64K bytes.</li>
502 <li>JIRA:XSTR-639: Cannot omit field at deserialization if the field has a class attribute.</li>
503 <li>JIRA:XSTR-599: EncodedByteArrayConverter should implement SingleValueConverter.</li>
504 <li>JIRA:XSTR-584: Race condition in XmlFriendlyReplacer.</li>
505 <li>JIRA:XSTR-623: XmlFriendlyReplacer may write illegal name characters (by Michael Schnell).</li>
506 <li>The ConversionException hides information if its ErrorWriter contains the added key already.</li>
507 <li>JIRA:XSTR-598: Attribute &quot;defined-in&quot; was wrongly evaluated for other attributes.</li>
508 <li>JIRA:XSTR-650: Possible NullPointerException at initialization on platforms like Android that do not
509 support all types of the JDK.</li>
510 <li>JIRA:XSTR-652: Initialization of XStream fails if DurationConverter constructor throws a
511 javax.xml.datatype.DatatypeConfigurationException. Converter will no longer handle Duration types if no
512 instance of the internal DatatypeFactory can be created.</li>
513 <li>Constructor DocumentWriter(Element) forgets the provided element.</li>
514 <li>JIRA:XSTR-597: Optimize AbstractReflectionConverter.</li>
515 <li>Introduce Caching interface to flush the internal cache of specific components.</li>
516 <li>Support JIRA:XSTR-407 also for IBM JRE 1.6 and greater.</li>
517 <li>java.nio.charset.Charset's converter was added as immutable type instead of the type itself.</li>
518 <li>java.util.Currency added as immutable type.</li>
519 <li>Fix selection of same parameter types in DependencyInjectionFactory.</li>
520 <li>Deprecation of c.t.x.javabean.PropertyDictionary has been countermanded.</li>
521 </ul>
522
523 <h2>API changes</h2>
524
525 <ul>
526 <li>Any deprecated stuff of the 1.2.x releases has been removed.</li>
527 <li>Deprecated constructors of c.t.x.converters.reflection.SerializableConverter, c.t.x.converters.reflection.ExternalizableConverter
528 and c.t.x.converters.reflection.CGLIBEnhancedConverter; new versions take an additional argument for class loader (as a result
529 for JIRA:XSTR-547).</li>
530 <li>Deprecated constructors of c.t.x.io.xml.XppReader, new versions take an additional argument for the XmlPullParser.</li>
531 <li>Deprecated c.t.x.io.xml.XppReader.createParser(), the XPP parser is now created by the driver.</li>
532 <li>Package c.t.x.io.xml.xppdom is now part of the official API.</li>
533 <li>c.t.x.io.xml.xppdom.Xpp3Dom and c.t.x.io.xmlxpp.dom.Xpp3DomBuilder have been deprecated. Functionality is
534 merged in c.t.x.io.xml.xppdom.XppDom.</li>
535 <li>Deprecated c.t.x.mapper.XStream11XmlFriendlyMapper and c.t.x.mapper.AbstractXmlFriendlyMapper.</li>
536 <li>Added interface c.t.x.core.ReferencingMarshallingContext which is implemented by all referencing marshallers.</li>
537 <li>Added interface c.t.x.io.naming.NameCoder and implementations.</li>
538 <li>Deprecated c.t.x.io.xml.XmlFriendlyReplacer, c.t.x.io.xml.XmlFriendlyReader and c.t.x.io.xml.XmlFriendlyWriter.</li>
539 <li>Deprecated c.t.x.io.xml.AbstractXmlDriver, c.t.x.io.xml.AbstractXmlReader and c.t.x.io.xml.AbstractXmlWriter, added
540 c.t.x.io.AbstractDriver, c.t.x.io.AbstractReader and c.t.x.io.AbstractWriter instead.</li>
541 <li>Deprecated all constructors of Driver, Reader and Writer implementations that take a XmlFriendlyReplacer as argument,
542 added constructors taking a NameCoder instead.</li>
543 <li>Added interface com.thoughtworks.xstream.converters.ErrorReporter to allow other types to report
544 also errors (apart from a HierarchicalStreamReader). Any converter and the parent object of the currently deserialized
545 element may provide additional error information now.</li>
546 </ul>
547
548 <h1 id="1.3.1">1.3.1</h1>
549
550 <p>Released December 6, 2008.</p>
551
552 <p class="highlight">CGLIB support must be explicitly activated now. The decision has been made due to possible problems using an own
553 classloader and because of ongoing complaints about occurring exceptions in the CGLIBEnhancedConverter at XStream initialization although
554 they are caused by incompatible ASM versions on the user's classpath (JIRA:XSTR-469, JIRA:XSTR-513 and JIRA:XSTR-518).</p>
555
556 <p class="highlight">XStream uses some attributes on its own. Until now it was possible to use XStream.aliasAttribute to define a different
557 name. This does still work but is deprecated for system attributes. Use the new call XStream.aliasSystemAttribute for such an alias.</p>
558
559 <h2>Major changes</h2>
560
561 <ul>
562 <li>JIRA:XSTR-515: CGLIB support is no longer activated automatically and has to be
563 <a href="faq.html#Serialization_CGLIB">explicitly turned on</a>.</li>
564 <li>JIRA:XSTR-448: Separated system attributes and user defined attributes for aliases.</li>
565 <li>JIRA:XSTR-55: Ability to alias a package name.</li>
566 <li>JIRA:XSTR-434: New JsonWriter instead of JsonHierarchicalStreamWriter with mode to strip root node of generated JSON (by Paul Hammant).</li>
567 <li>Support for Diablo JDK on FreeBSD (by Reto Bachmann-Gm&uuml;r).</li>
568 <li>JIRA:XSTR-495: New PersistenceStrategy instead of StreamStrategy (based on the code and comments by Alexander Radzin).</li>
569 </ul>
570
571 <h2>Minor changes</h2>
572
573 <ul>
574 <li>Support special Jettison functionality for JSON to detect collections or arrays with one element introduced with Jettison 1.0.</li>
575 <li>JIRA:XSTR-493: Using attributes for fields with XML-unfriendly names results in NPE at deserialization.</li>
576 <li>JIRA:XSTR-497: Unsafe operation with WeakHashMap can raise a NPE in Sun14ReflectionProvider.</li>
577 <li>JIRA:XSTR-423: Support of CGLIB enhanced proxies with multiple callbacks if the proxy uses a factory (CGLIB default).</li>
578 <li>JIRA:XSTR-536: XStream silently ignores unknown elements.</li>
579 <li>JIRA:XSTR-503: Omitted properties in JavaBeans are requested at serialization (by Kevin Conaway).</li>
580 <li>Fix possible memory leak in ObjectIdMap for JVMs that provide real distinct identity hash codes (happened on amd64 system).</li>
581 <li>JIRA:XSTR-480: Aliasing of array types.</li>
582 <li>JIRA:XSTR-515: The SubjectConverter and DurationConverter are only registered if the converted class is part of the JDK,
583 otherwise they must be registered now explicitly.</li>
584 <li>JIRA:XSTR-504: XmlHeaderAwareReader fails with improper sized PushbackInputStream.</li>
585 <li>JIRA:XSTR-489: @XStreamConverter supports now also SingleValueConverter implementations.</li>
586 <li>JIRA:XSTR-481: @XStreamConverter and @XStreamAsAttribute can be used together (as a result of JIRA:XSTR-489).</li>
587 <li>JIRA:XSTR-519: New annotation @XStreamInclude to force annotation detection of included types (by Seven Sparling).</li>
588 <li>JIRA:XSTR-469: Support custom converters for enum types.</li>
589 <li>JIRA:XSTR-502: ClassNotFoundException even if writeReplace returns proper object.</li>
590 <li>JIRA:XSTR-529: NullPointerException for null elements in implicit lists.</li>
591 <li>JIRA:XSTR-517: Miscellaneous performance improvements (by Tatu Saloranta).</li>
592 <li>JIRA:XSTR-525: JsonHierarchicalStreamDriver writes invalid JSON in case of system attribute.</li>
593 <li>JIRA:XSTR-535: Mode to allow plain values as result for JSON without root node.</li>
594 <li>JIRA:XSTR-531: Possibility to omit system attributes.</li>
595 <li>JIRA:XSTR-508: Fix marshalling error for nested serializable objects with own writeReplace/readResolve methods.</li>
596 <li>JIRA:XSTR-507: Advanced ReferenceByIdMarshaller uses id of the current object if available.</li>
597 <li>JIRA:XSTR-485: Check reference for valid object when deserializing.</li>
598 <li>Fix classloader problem, Xpp3 parser cannot be loaded within a web application.</li>
599 <li>Dependencies have been updated to latest versions of JDOM, Jettison, Joda Time, and Woodstox. Note for Maven
600 builds that the <em>groupId</em> of JDOM has changed.</li>
601 <li>Fix possible IndexOutOfBoundsException creating returning the message for a ConversionException.</li>
602 <li>JIRA:XSTR-495: StreamStrategy cannot handle key with value <em>null</em>.</li>
603 </ul>
604
605 <h2>API changes</h2>
606
607 <ul>
608 <li>Deprecated c.t.x.io.json.JsonHierarchicalStreamWriter in favour of c.t.x.io.json.JsonWriter.</li>
609 <li>c.t.x.mapper.EnumMapper no longer derives from the c.t.x.mapper.AttributeMapper as it has been before version 1.3. Therefore the new
610 constructor has been deprecated in favour of the old one.</li>
611 <li>c.t.x.mapper.Mapper.getConverterFromAttribute(Class, String) has been deprecated in favour of
612 c.t.x.mapper.Mapper.getConverterFromAttribute(Class, String, Class) taking the type as third argument that should be handled by the
613 converter.</li>
614 <li>c.t.x.core.ReferenceByIdMarshaller.IdGenerator.next() has now the current object as argument.</li>
615 <li>New c.t.x.persistence.PersistenceStrategy and c.t.x.persistence.FilePersistenceStrategy.</li>
616 <li>Deprecated c.t.x.persistence.StreamStrategy and c.t.x.persistence.FileStreamStrategy.</li>
617 </ul>
618
619 <h1 id="1.3">1.3</h1>
620
621 <p>Released February 27, 2008.</p>
622
623 <h2>Major changes</h2>
624
625 <ul>
626 <li>ReflectionConverter writes now the fields of the parent classes first.</li>
627 <li>Support for Converter definition at field level.</li>
628 <li>Refactoring of Annotation support, invent auto-detection mode.</li>
629 <li>Annotated converters are no longer detected automatically, all annotations are now handled in the same way.</li>
630 <li>JIRA:XSTR-334: XStream will deserialize directly from a file or URL. Some parser take advantage of these objects to
631 define a SystemId used to resolve further references in XML, schema or DTD. Appropriate createReader methods have been
632 added to c.t.x.io.HierarchicalStreamDriver.</li>
633 <li>JIRA:XSTR-261: All c.t.x.io.HierarchicalStreamDriver implementations respect now the encoding of an XML header
634 if read from an InputStream.</li>
635 <li>DomDriver does no longer use explicitly UTF-8 by default, DomReader will therefore respect the encoding defined
636 in the XML header or use native encoding</li>
637 <li>JIRA:XSTR-415: JavaBeanConverter uses now BeanIntrospection (by Hinse ter Schuur).</li>
638 <li>JIRA:XSTR-424: DateConverter uses now by default SimpleDateFormat instances in non-lenient mode.</li>
639 <li>JIRA:XSTR-386: SingleValueConverter that utilizes PropertyEditor implementations (by Jukka Lindstr&ouml;m).</li>
640 <li>JIRA:XSTR-427: Converter for javax.xml.datatype.Duration (by John Kristian).</li>
641 <li>JIRA:XSTR-305: Field alias inheritance (by David Blevins).</li>
642 <li>XStream failed to initialize in environments without AWT or SQL classes.</li>
643 <li>JIRA:XSTR-420: XPath of references are not XmlFriendly encoded.</li>
644 <li>JIRA:XSTR-473: String &quot;\0&quot; serialized as invalid XML, support compliant behaviour according XML version.</li>
645 <li>JIRA:XSTR-431: Direct support of enhanced mode for SAP JVM (thanks to Norbert Kuck by SAP).</li>
646 <li>JIRA:XSTR-437: Static cache in annotation processing causes failing OSGi bundles.</li>
647 <li>JIRA:XSTR-279+JIRA:XSTR-335: Annotations are not inherited from parent class.</li>
648 <li>Fix StringConverter using a WeakHashMap with strong references in its value.</li>
649 <li>JIRA:XSTR-403: Attributes are no longer written with JSONHierarchicalStreamDriver if current object is a collection.</li>
650 <li>JIRA:XSTR-456: New LookAndFeelConverter handling LookAndFeel implementations with reflection.</li>
651 <li>JIRA:XSTR-462: CachingMapper keeps direct class references.</li>
652 <li>JIRA:XSTR-411: JsonHierarchicalStreamDriver does not escape characters according RFC 4627.</li>
653 <li>JsonHierarchicalStreamDriver writes wrong brackets around complex Java types with a single value.</li>
654 <li>JsonHierarchicalStreamDriver writes attribute names with a leading '@'.</li>
655 <li>JsonHierarchicalStreamDriver supports Map implementations.</li>
656 </ul>
657
658 <h2>Minor changes</h2>
659
660 <ul>
661 <li>Added converter for java.lang.StringBuilder instances.</li>
662 <li>Added converter for java.util.UUID instances.</li>
663 <li>JIRA:XSTR-430: Fields written as attributes could not be omitted.</li>
664 <li>JIRA:XSTR-407: Comparator might access uninitialized elements for TreeSet and TreeMap. A deserialized
665 Comparator is no longer called, the converters expect the elements now in a sorted order.</li>
666 <li>JIRA:XSTR-404, @XStreamImplicit() for ArrayList&lt;ArrayList&lt;Type&gt;&gt; throws ClassCastException.</li>
667 <li>@XStreamContainedType() for ArrayList&lt;ArrayList&lt;Type&gt;&gt; throws ClassCastException.</li>
668 <li>XStreamer did not persist a FieldKeySorter instance.</li>
669 <li>JIRA:XSTR-241: JavaBeanConverter now supports customized BeanProvider.</li>
670 <li>JIRA:XSTR-280: JavaBeanConverter now supports aliasField and omitField (by Hinse ter Schuur).</li>
671 <li>JIRA:XSTR-280: SerializationConverter now supports aliasField and omitField.</li>
672 <li>JIRA:XSTR-429: XmlFriendlyReplacer support for SaxWriter and TraxSource (by Adrian Wilkens).</li>
673 <li>JIRA:XSTR-421: Characters cannot be written as attribute.</li>
674 <li>JIRA:XSTR-426: java.swt.KeyStroke not properly serialized because of a character undefined in unicode.</li>
675 <li>JIRA:XSTR-352: Strings with arbitrary ISO control characters are not properly serialized.</li>
676 <li>JIRA:XSTR-428: An attribute named like a transient field did abort deserialization of following fields.</li>
677 <li>JIRA:XSTR-443: XStream.createObjectOutputStream does not use the given driver to create the HierarchicalStreamWriter.</li>
678 <li>JIRA:XSTR-440: Implicit collections can be declared for fields that are not of Collection type.</li>
679 <li>JIRA:XSTR-446: Handle all primitives and their boxed counterpart for JsonHierarchicalStreamDriver.</li>
680 <li>JIRA:XSTR-447: Fix deserialization of Array class types in JDK 6 (see JDK bug 6500212).</li>
681 <li>JIRA:XSTR-450: @XStreamAlias is ignored if attributes should be used for the field type.</li>
682 <li>JIRA:XSTR-418: Inherited @XStreamAlias is ignored if field should be rendered as attribute.</li>
683 <li>JIRA:XSTR-393: Annotation processing is not consistent.</li>
684 <li>JIRA:XSTR-412: @XStreamImplicit throws NPE for untyped collections.</li>
685 <li>JIRA:XSTR-463: Cannot provide own default Mapper chain.</li>
686 <li>JIRA:XSTR-464: Cannot provide a ClassLoader that is used in all cases.</li>
687 <li>JIRA:XSTR-394: Allow enums as attributes.</li>
688 <li>JIRA:XSTR-413: Support @XStreamAsAttribute for enums.</li>
689 <li>JIRA:XSTR-478: Cannot specify default implementation for polymorphic enum.</li>
690 <li>JIRA:XSTR-419: Treat enums as immutable types.</li>
691 <li>Update annotation tutorial, explain limitations of auto-detection mode.</li>
692 <li>Added copyright notices to all files.</li>
693 <li>StaxWriter.flush did close Stax' XMLStreamWriter instead of flushing it.</li>
694 <li>JIRA:XSTR-471: XStream POMs do no longer declare a repository at all.</li>
695 <li>Calendar object could not be rendered with JSONHierarchicalStreamDriver.</li>
696 <li>JIRA:XSTR-476: Properties can be sorted by key.</li>
697 <li>XStream.createObjectInputStream and XStream.createObjectOutputStream
698 overloaded to support a binary InputStream or OutputStream.</li>
699 <li>JIRA:XSTR-470: Allow transient fields to be optionally deserialized.</li>
700 </ul>
701
702 <h2>API changes</h2>
703
704 <ul>
705 <li>c.t.x.annotation.Annotations, c.t.x.annotation.AnnotationReflectionConverter and c.t.x.annotation.AnnotationProvider deprecated.
706 Functionality is integrated in new c.t.x.mapper.AnnotationMapper and accessible with new methods c.t.x.XStream.processAnnotations().</li>
707 <li>New auto-detection mode for annotations, that can be turned on with c.t.x.XStream.autodetectAnnotations()</li>
708 <li>c.t.x.annotation.@XStreamContainedType deprecated, the behaviour is now always active and the annotation therefore superfluous.</li>
709 <li>Due to JIRA:XSTR-421 null characters are no longer written as tag with an attribute (&lt;char null=&quot;true&quot;/&gt;),
710 but as empty tag. The old representation is still supported at deserialization.</li>
711 <li>Characters that are not defined in unicode or ISO control characters (expect TAB and LF) are written as numerical entity now.</li>
712 <li>XPath references are now also XML-friendly encoded to match the path exactly. Unencoded references will normally work anyway,
713 but in special cases the exact behaviour of XStream 1.2.x might be necessary. See acceptance tests for XStream 1.2.x compatibility.</li>
714 <li>c.t.x.core.BaseException deprecated in favour of c.t.x.XStreamException as base exception for all exceptions XStream throws.</li>
715 <li>c.t.x.XStream.InitializerException deprecated in favour of c.t.x.InitializerException.</li>
716 <li>New methods get() and keys() in interface c.t.x.converter.ErrorWriter.</li>
717 <li>c.t.x.mapper.XmlFriendlyMapper deprecated, technology is replaced since version 1.2 by c.t.x.io.xml.XmlFriendlyReplacer as part of the
718 different XmlWriter implementations.</li>
719 <li>c.t.x.mapper.Mapper.aliasForAttribute() and c.t.x.mapper.Mapper.attributeForAlias() deprecated, since it provided in reality the combined
720 functionality of c.t.x.mapper.Mapper.serializedMember()/realMember() and c.t.x.mapper.Mapper.getConverterFromItemType().</li>
721 <li>c.t.x.XStream(ReflectionProvider, Mapper, HierarchicalStreamDriver) deprecated, in favour of
722 c.t.x.XStream(ReflectionProvider, HierarchicalStreamDriver, Mapper, ClassLoader).</li>
723 <li>New interface c.t.x.converter.ConverterRegistry to express explicit functionality managing the converters.</li>
724 <li>c.t.x.core.DefaultConverterLookup no longer uses a c.t.x.mapper.Mapper. Therefore the old constructor has been deprecated in favour
725 of a default constructor.</li>
726 <li>Overloaded methods of c.t.x.mapper.Mapper.getConverterFromItemType and c.t.x.mapper.Mapper.getConverterFromAttribute have been
727 deprecated. Only one version has been kept, the implementation can handle all cases now at once and therefore multiple calls to the mapper chain
728 are avoided.</li>
729 <li>c.t.x.mapper.EnumMapper derives now from the c.t.x.mapper.AttributeMapper to support enums as attributes. Therefore the old constructor
730 has been deprecated in favour of one taking an additional c.t.x.converters.ConverterLookup that has to be passed to the new parent.</li>
731 </ul>
732
733 <p class="highlight">Note, to support a representation of null values in some way, it is absolutely necessary that each converter can handle a null
734 value in its marshalling methods. If you have implemented your own custom converters, try to handle such a case also to prevent incompatibilities
735 in case XStream will provide such values with its next major version.</p>
736
737 <h1 id="1.2.2">Version 1.2.2</h1>
738
739 <p>Released May 24, 2007.</p>
740
741 <p class="hightlight">Note, that next version of XStream will behave slightly different by default. XStream emits
742 all fields in declaration order like Java serialization. But in contrast to Java it will omit the fields of parent
743 classes last while Java serialization emits them first. This makes it difficult to match a given XML schema that
744 defined inherited types or leads sometimes to obscure initialization problems. However, XStream itself will not be
745 affected by the changed order of elements in the XML, any deserialization of current XML representations will work
746 fine. Anyway we will provide with XStream 1.3 a FieldKeySorter implementation that mimics the old behaviour. In
747 the meanwhile you can enforce the new field sorting by installing the NaturalFieldKeySorter.</p>
748
749 <h2>Major changes</h2>
750
751 <ul>
752 <li>JIRA:XSTR-391, Support for writing (and reading) JSON by the new JettisonMappedXmlDriver (by Dejan Bosanac).</li>
753 <li>New FieldKeySorter interface allows a custom sort order of the XML elements.</li>
754 <li>JIRA:XSTR-68 and JIRA:XSTR-210, OmitField is now respected at deserialization to ignore removed fields.</li>
755 </ul>
756
757 <h2>Minor changes</h2>
758
759 <ul>
760 <li>JIRA:XSTR-387, Fix aliasing of inherited fields.</li>
761 <li>JIRA:XSTR-395, Fix StringConverter allocating PermGen space.</li>
762 <li>JIRA:XSTR-368, @XStreamConverter converters should be cached inside the AnnotationReflectionConverter.</li>
763 <li>JIRA:XSTR-392, @XStreamOmitField can be used to omit fields from the resulting XML (contributed by Chung-Onn Cheong).</li>
764 <li>JIRA:XSTR-371, Fix JSONWriter that omits a closing bracket for for fields with null value.</li>
765 <li>JIRA:XSTR-398, DomDriver ignores given XmlFriendlyReplacer.</li>
766 <li>JIRA:XSTR-370, Buildable with JDK 6, fix FontConverter for JDK 6.</li>
767 <li>JIRA:XSTR-382, Support hex and octal number values.</li>
768 <li>DateConverter did not respect change in TimeZone after first usage.</li>
769 <li>JIRA:XSTR-375, Support for aliasing native types.</li>
770 <li>JIRA:XSTR-243 again, XML elements for transient fields are now ignored completely at deserialization.</li>
771 <li>Release unused object references to keep memory print low.</li>
772 <li>Support for AWT and SQL is now optional: XStream now works on embedded virtual machines lacking such APIs (by Nicolas Gros d'Aillon).</li>
773 <li>Support raw bytes read from the ObjectInputStream.</li>
774 <li>JIRA:XSTR-373, Support for Hitachi JVM (tested by Yuji Yamano).</li>
775 <li>JIRA:XSTR-378 and JIRA:XSTR-379, Fix TextAttributeConverter and EnumSetConverter failing on Apache Harmony.</li>
776 <li>JIRA:XSTR-363, Support of native field order i.e. fields are processed in declaration order base classes first.</li>
777 <li>JIRA:XSTR-320, Static field in child may hide non-static field in parent.</li>
778 </ul>
779
780 <h2>API changes</h2>
781
782 <ul>
783 <li>JIRA:XSTR-365, Multiple implicit collections with annotations. Deprecated @XStreamImclicitCollection in favour of @XStreamImplicit
784 declared at field level.</li>
785 </ul>
786
787 <h1 id="1.2.1">Version 1.2.1</h1>
788
789 <p>Released November 11, 2006.</p>
790
791 <h2>Major changes</h2>
792
793 <ul>
794 <li>Introduced DocumentWriter interface and generalized functionality for all writer implementations
795 creating a DOM structure (DOM4J, DOM, JDom, Xom, Xpp3Dom).</li>
796 <li>Refactored build system to use Maven 2. Ant still supported on XStream Core.</li>
797 <li>Created separate XStream Benchmark module</li>
798 </ul>
799
800 <h2>Minor changes</h2>
801
802 <ul>
803 <li>JIRA:XSTR-346, XStream.getClassMapper() does not return a ClassMapper for the current Mapper.</li>
804 <li>Fix problem with fields containing a double underscore.</li>
805 <li>JIRA:XSTR-345, Dom4JWriter adds up attributes.</li>
806 <li>JIRA:XSTR-336, XStream fails to reference an implicit element.</li>
807 <li>JIRA:XSTR-337, Annotation cycle bug.</li>
808 <li>Fix packaging error for the resulting jar building with Maven2.</li>
809 <li>JIRA:XSTR-339, NPE for attribute null values.</li>
810 <li>JIRA:XSTR-338, NPE in JSON writer for converters using non-extended HierarchicalStreamWriter.</li>
811 <li>JIRA:XSTR-357, Fix escaping of values in JSON writer.</li>
812 <li>JIRA:XSTR-356, Fix unmarshaling error for fields containing proxies.</li>
813 <li>JIRA:XSTR-349, Fix backward compatibility of Dom4jWriter.</li>
814 <li>JIRA:XSTR-309, More versatile boolean conversion options (contributed by David Blevins).</li>
815 <li>Add XStream.getReflectionProvider() to retrieve ReflectionProvider in use.</li>
816 <li>JIRA:XSTR-358, @XStreamConverter annotation does not call converter constructor.</li>
817 <li>Website generated using <a href="http://xsite.codehaus.org">XSite</a></li>
818 </ul>
819
820 <h2>API changes</h2>
821
822 <ul>
823 <li>Deprecate JDomWriter.getResult() in favour of DocumentWriter.getTopLevelNodes().</li>
824 <li>Deprecate ThreadSafeSimpleDateFormat, since this is an internal helper and not part of XStream API.</li>
825 </ul>
826
827 <h1 id="1.2">Version 1.2</h1>
828
829 <p>Released August 18, 2006.</p>
830
831 <h2>Major changes</h2>
832
833 <ul>
834 <li>JIRA:XSTR-269, Using attributes for fields (contributed by Paul Hammant and Ian Cartwright).</li>
835 <li>Aliasing of arbitrary attributes.</li>
836 <li>JIRA:XSTR-50, XStream can now serialize another XStream instance.</li>
837 <li>JIRA:XSTR-227, XStream has now the XStreamer, that serializes an object together with its XStream instance.</li>
838 <li>JIRA:XSTR-278, AnnotationConverter for fields (contributed by Guilherme Silveira).</li>
839 <li>JIRA:XSTR-256, PureJavaReflectionProvider supports now final fields starting with JDK 1.5</li>
840 <li>JIRA:XSTR-258, Any Collection type can now be declared implicit, the default implementation will be respected for unmarshaling.</li>
841 <li>JIRA:XSTR-88, XStream can now write all references as absolute XPath expression.</li>
842 <li>JIRA:XSTR-62 and JIRA:XSTR-211, New SingeValueConverter allows light weight converters if the value can be represented by a unique string.</li>
843 <li>Aliasing of classes of a specific type.</li>
844 <li>JIRA:XSTR-239, Support for certain types of proxies generated with the CGLIB Enhancer.</li>
845 <li>JIRA:XSTR-90 and JIRA:XSTR-311, Support for BEA JRockit starting with R25.1.0 (contributed by Henrik St&aring;hl of BEA).</li>
846 </ul>
847
848 <h2>Technology preview</h2>
849
850 <ul>
851 <li>Experimental binary reader and writer.</li>
852 <li>Experimental HierarichicalStreamCopier allows streams to be copied from one format to another without the overhead of serialization.</li>
853 <li>Experimental JSON support allows streams to be copied from one format to another without the overhead of serialization (contributed by Paul Hammant).</li>
854 </ul>
855
856 <h2>Minor changes</h2>
857
858 <ul>
859 <li>JIRA:XSTR-266, XStream fails to serialize elements of a unserializable class, that is a base class of a derived class</li>
860 <li>JIRA:XSTR-236, Priority constants for converter registration are now public</li>
861 <li>JIRA:XSTR-215, XStream writes now fields in declaration order even for JVMs reporting them in reverse order like IBM JDK.</li>
862 <li>JIRA:XSTR-276 and JIRA:XSTR-283, XStream does no longer attempt to create references to implicit element.</li>
863 <li>JIRA:XSTR-244, Closing a Writer can now be done twice, but any write attempt will later on fail.</li>
864 <li>JIRA:XSTR-243, Transient fields were unmarshalled from XML.</li>
865 <li>JIRA:XSTR-250, Providing a mapper to the XStream constructor will no longer result in a NPE.</li>
866 <li>JIRA:XSTR-281, After registering a new converter, the internal converter cache is now cleared.</li>
867 <li>JIRA:XSTR-284, XStream checks the object returned by a converter for compatibility.</li>
868 <li>XStream no longer fails serializing a Throwable without cause when no references shall be written.</li>
869 <li>Converter for java.awt.font.TextAttribute.</li>
870 <li>Converter for java.nio.charset.Charset.</li>
871 <li>JIRA:XSTR-286, XStream detects impossible self serialization and throws now an appropriate ConversionException.</li>
872 <li>JIRA:XSTR-291, XomDriver implementation added.</li>
873 <li>JIRA:XSTR-299, Fix for implicit collections with items using the same name as the field name of the underlying collection.</li>
874 <li>JIRA:XSTR-245, Broken XML with custom serialization in certain cases (patch contributed by Cyrille Le Clerc).</li>
875 <li>JIRA:XSTR-304, Bad handling of repairing namespace flag for StaxDriver (patch contributed by John Kristian).</li>
876 </ul>
877
878 <h2>API changes</h2>
879
880 <ul>
881 <li>JIRA:XSTR-252, Refactored support for XML friendly character mapping.</li>
882 <li>JIRA:XSTR-69, Refactored ReflectionConverter allows simpler subclassing.</li>
883 <li>Unmarshalling context has now an overloaded version of the method convertAnother to provide the Converter directly.</li>
884 <li>Deprecate ClassMapper for Mapper. All methods with a ClassMapper parameter have now a duplicate taking only a Mapper. The variant with the ClassMapper is deprecated.</li>
885 <li>Deprecate c.t.x.alias.CannotResolveClassException for c.t.x.mapper.CannotResolveClassException.</li>
886 <li>Deprecate NameMapper (was not used within XStream anymore anyway).</li>
887 <li>Deprecate constructor of DefaultMapper taking an alternative name for the class attribute. Use the aliasAttribute method.</li>
888 <li>Deprecate attributeForImplementationClass, attributeForClassDefiningField, attributeForReadResolveField, and attributeForEnumType in favour of the generalized aliasForAttribute in the Mapper interface.</li>
889 <li>Removed all deprecated stuff from 1.1.x and 1.0.x</li>
890 <li>JIRA:XSTR-211, A lot of existing (basic) Converters have been refactored to use the new SingleValueConverter interface.</li>
891 <li>Dom4JWriter uses now a DocumentFactory and a XMLWriter as constructor arguments.</li>
892 </ul>
893
894 <h1 id="1.1.3">Version 1.1.3</h1>
895
896 <p>Released January 13, 2006.</p>
897
898 <h2>Major changes</h2>
899
900 <ul>
901 <li>Added XStream.toXML(OutputStream) and XStream.fromXML(InputStream).</li>
902 <li>Ability to prevent fields from being serialized by calling XStream.omitField() or by implementing Mapper.shouldSerializeMember().</li>
903 <li>Added Converter for Enum, EnumMap and EnumSet</li>
904 <li>JIRA:XSTR-186, Added BeanConverter (contributed by Andrea Aime)</li>
905 <li>JIRA:XSTR-246, Added ISO8601SqlTimestampConverter (contributed by Cheong, Chung-Onn)</li>
906 <li>Added ISO8601GregorianCaledarConverter</li>
907 <li>JIRA:XSTR-215, Fixed support for IBM JVM (contributed by Gabor Liptak)</li>
908 <li>Enhanced mode support for Blackdown JDK</li>
909 <li>JIRA:XSTR-265, support for javax.security.auth.Subject</li>
910 <li>JIRA:XSTR-233, support for Integer[] arrays</li>
911 </ul>
912
913 <h2>Minor changes</h2>
914
915 <ul>
916 <li>Remove unnecessary PrintWriter wrapper in default writers (pointed out by Mathieu Champlon)</li>
917 <li>Bugfix: EnumSet converter can now deal with empty sets (contributed by Baba Buehler)</li>
918 <li>Update ISO8601DateConverter to use Joda 1.0</li>
919 <li>JIRA:XSTR-242, GregorianCalenderConverter saves now the timezone</li>
920 <li>JIRA:XSTR-247, ISO8601DateConverter now independent on timezone</li>
921 <li>JIRA:XSTR-263, Circular references with Externalizable objects fail</li>
922 </ul>
923
924 <h2>API changes</h2>
925
926 <ul>
927 <li>None.</li>
928 </ul>
929
930 <h1 id="1.1.2">Version 1.1.2</h1>
931
932 <p>Released April 30, 2005. Most popular feature requests implemented. Java 5 Enum support. Serialization of JavaBeans
933 using accessors. Aliasing of fields. StAX integration, with namespaces. Improved support on JDK 1.3 and IBM JDK. </p>
934
935 <h2>Major changes</h2>
936
937 <ul>
938 <li>JIRA:XSTR-186, Option to serialize JavaBeans using public accessors, rather than private fields (contributed by Andrea Aime).</li>
939 <li>Ability to alias fields as well as classes, using XStream.addFieldAlias().</li>
940 <li>JIRA:XSTR-70, JIRA:XSTR-204 Support for JDK 5 enums (contributed by Eric Snell and Bryan Coleman).</li>
941 <li>JIRA:XSTR-206 Clean representation of JDK 5 EnumMap and EnumSet.</li>
942 <li>XStream can now be built using JDK 1.3 (previously it required JDK 1.4 to compile, but 1.3 to run).</li>
943 <li>JIRA:XSTR-215, Enhanced mode is now supported on the IBM 1.4 JDK.</li>
944 <li>The default HierarchicalStreamWriter implementation is supplied by the HierarichicalStreamDriver (as well as the reader).</li>
945 </ul>
946
947 <h2>Minor changes</h2>
948
949 <ul>
950 <li>JIRA:XSTR-104 HierarchicalStreamReader now exposes all available attributes to the Converter implementations (contributed by Trygve Laugstol).</li>
951 <li>Bugfix: Externalizable deserialization supported for objects not at the root of tree.</li>
952 <li>JavaMethodConverter handles non public methods/constructors (contributed by Kevin Ring).</li>
953 <li>PropertiesConverter also serializes default properties, if present (contributed by Kevin Ring).</li>
954 <li>Bugfix: In some cases, XppReader and StaxReader would get confused when calling hasMoreChildren() and getValue() on the same node.</li>
955 <li>JIRA:XSTR-217, ISO8601DateConverter now requires joda-time-1.2.1</li>
956 <li>PrettyPrintWriter and CompactWriter may have their text/attribute escaping rules customized by overriding writeText() and writeAttributeValue().</li>
957 </ul>
958
959 <h2>API changes</h2>
960
961 <ul>
962 <li>HierarchicalStreamDriver implementations now require a createWriter() method. The simplest implementation is to return a new PrettyPrintWriter.</li>
963 <li>Introduced ReaderWrapper/WriterWrapper classes to make it easier to wrap (decorate) HierarchicalStreamReader/Writer instances.</li>
964 </ul>
965
966 <h1 id="1.1.1">Version 1.1.1</h1>
967
968 <p>Released March 7, 2005. Mostly bugfixes and minor feature enhancements.</p>
969
970 <h2>Major changes</h2>
971
972 <ul>
973 <li>Converters can be registered with a priority, allowing more <i>generic</i> filters to handle classes that don't have more specific converters.</li>
974 <li>Converters can now access underlying HierarchicalStreamReader/Writer implementations to make implementation specific calls.</li>
975 <li>Improved support for classes using ObjectInputFields to follow the serialization specification.</li>
976 <li>JIRA:XSTR-179 Support for ObjectInputStream.registerValidation(ObjectInputValidation).</li>
977 <li>JIRA:XSTR-178 Serialized inner class now maintains reference to outer class.</li>
978 <li>JIRA:XSTR-199 Default ClassLoader may be changed using XStream.setClassLoader().</li>
979 </ul>
980
981 <h2>Minor changes</h2>
982
983 <ul>
984 <li>Bugfix: Thread context classloader is loaded by the correct thread. (Thanks to Padraic Renaghan for pointing this out).</li>
985 <li>Bugfix: Default implementations of aliased classes were not being deserialized by SerializableConverter.</li>
986 <li>Bugfix: JIRA:XSTR-180 Serializable objects support defaultReadObject() even when no default fields available.</li>
987 <li>Bugfix: For serialized objects class hierarchy is serialized starting with superclass (as per Java Object Serialization).</li>
988 <li>Bugfix: readObject() is now called for classes containing only transient fields.</li>
989 <li>Bugfix: Order of fields are maintained when calling ObjectOutputStream.putFields().</li>
990 <li>Bugfix: FontConverter extended to support FontUIResource which does some awkward native calls.</li>
991 <li>Bugfix: Deserialization of very complicated graphs (such as Swing components) sometimes resulted in broken object references. Now fixed.</li>
992 <li>Bugfix: JIRA:XSTR-188 Classes that use readResolve()/writeReplace() can now return different types.</li>
993 <li>Bugfix: JIRA:XSTR-185, JIRA:XSTR-195 Support for loading of array classes for classes that have not yet been loaded. (Thanks to Henri Tremblay and Simon Daniel)</li>
994 <li>Bugfix: JIRA:XSTR-190 PrettyPrintWriter and CompactWriter escape characters in XML attributes.</li>
995 <li>Bugfix: JIRA:XSTR-176, JIRA:XSTR-196 The XStream ObjectInputStream and ObjectOutputStream implementations now propegate the flush() and close() events to the underlying streams.</li>
996 <li>Bugfix: JIRA:XSTR-192 Implicit collection mappings are now supported in inheritance hierarchies.</li>
997 </ul>
998
999 <h2>API changes</h2>
1000
1001 <ul>
1002 <li>ClassMapper is now deprecated. Replaced with MapperWrapper.</li>
1003 <li>HierarchicalStreamWriter implementations must now implement close(), flush() and underlyingWriter().</li>
1004 <li>HierarchicalStreamReader implementations must now implement close() and underlyingReader().</li>
1005 </ul>
1006
1007 <h1 id="1.1">Version 1.1</h1>
1008
1009 <p>Released January 15, 2005. Focus on support for objects defining custom serialization using the standard
1010 <a href="http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/serialTOC.html">Java serialization</a> mechanism.</p>
1011
1012 <h2>Major changes</h2>
1013
1014 <ul>
1015 <li>Provides drop in replacement for ObjectInputStream and ObjectOutputStream, using XStream.createObjectInputStream() and
1016 XStream.createObjectOutputStream() and XStream.createObjectInputStream(). This provides support for streaming objects.</li>
1017 <li>Support for objects that specify their own serialization schemes by implementing readObject() and writeObject()
1018 (as in Java serialization spec). This includes support for ObjectInputStream.getFields() and ObjectOuputStream.putFields().</li>
1019 <li>Support for objects to serialize other objects to the stream by implementing writeReplace() (as in Java serialization spec).</li>
1020 <li>Support for any object that performs custom serialization by implementing java.io.Externalizable (as in Java serialization spec).</li>
1021 <li>Implicit collections can be specified for classes, allowing the element wrapping the collection to be skipped.</li>
1022 <li>New writer implementations to allow XStream to serialize directly to a SAX stream or TrAX pipeline.</li>
1023 <li>The MarshallingContext and UnmarshallingContext interfaces now extend DataHolder, allowing arbitrary data to be stored
1024 by the user whilst walking the object graph and passed around to Converters. DataHolders can also be passed into
1025 XStream from the outside.</li>
1026 <li>Includes new DomWriter implementation to serialize directly to a W3C DOM tree (to complement the existing DomReader).</li>
1027 <li>Better support for instantiating objects on non Sun 1.4+ JVMs, including non-public constructors, private static inner classes and
1028 ANY class that implements java.io.Serializable.</li>
1029 <li>DOM, DOM4J, JDOM, XOM, Electric-XML, SAX, STAX</li>
1030 <li>Specific ClassLoaders can be passed into XStream, to allow for greater compatibility in J2EE containers.</li>
1031 <li>Ability to change the default converter</li>
1032 <li>Added optional ISO8601DateConverter for full ISO8601 date format support. The converter is not registered by default
1033 as it requires the joda-time dependency (http://joda-time.sf.net). To use, ensure joda-time is in classpath and register explicitly.</li>
1034 <li>Enhanced mode is now supported on the Apple 1.4 JDK.</li>
1035 </ul>
1036
1037 <h2>Minor changes</h2>
1038
1039 <ul>
1040 <li>PrettyPrintWriter only flushes stream when necessary - large performance improvement for serialization.</li>
1041 <li>Added XStream.fromXml(xml, root) convenience methods for deserializing into an existing root object.</li>
1042 <li>JDK 1.3 compatibility: Added mechanism for accessing nested exception.</li>
1043 <li>JDK 1.3 compatibility: GregorianCalendarConverter only calls Calendar.getTimeInMillis() the JDK supports it.</li>
1044 <li>Bugfix: All caches are now synchronized - there were some thread safety issues.</li>
1045 <li>Bugfix: Only <i>immutable</i> basic types will have references ignored in XML (for clarity).</li>
1046 <li>Bugfix: Class names can contain underscores.</li>
1047 <li>Bugfix: Support for '\0' char.</li>
1048 <li>Bugfix: PropertyConverter no longer attempts to serialize subclasses of Properties.</li>
1049 <li>Bugfix: JVM detection uses system properties, which is more accurate than searching the classpath.</li>
1050 </ul>
1051
1052 <h2>API changes</h2>
1053
1054 <ul>
1055 <li>XStream.addDefaultCollection() has been deprecated. Use XStream.addImplicitCollection() instead.</li>
1056 </ul>
1057
1058 <h1 id="1.0.2">Version 1.0.2</h1>
1059
1060 <p>Released August 7, 2004. Focus on improving the converters bundled with XStream to support a wider range of types.</p>
1061
1062 <h2>Major changes</h2>
1063
1064 <ul>
1065 <li>XML elements are written in order they are defined in class, rather than alphabetical.</li>
1066 <li>Converters for java.io.File, java.sql.Timestamp, java.awt.Color, and dynamic proxies are now
1067 registered by default.</li>
1068 <li>EncodedByteArrayConverter is now registered by default and uses a single Base64 string to store the contents
1069 of a byte[]. This now works on all JVMs as it no longer relies on Sun specific classes. This converter will also
1070 unmarshal byte[] that have been serialized without it, for backwards compatability.</li>
1071 <li>New converters for java.sql.Time, java.sql.Date, java.util.Locale, java.util.Currency, java.util.Calendar
1072 and java.awt.Font.</li>
1073 <li>All caching is done in XStream instance instead of statics, allowing applications that use hot redeployment
1074 of classes to use XStream in a parent classloader.</li>
1075 <li>XStream will fail fast if a field value is defined more than once in XML when deserializing.</li>
1076 </ul>
1077
1078 <h2>Minor changes</h2>
1079
1080 <ul>
1081 <li>The &lt;entry&gt; element used in Maps can now be specified by creating an alias for java.util.Map.Entry.</li>
1082 <li>Bugfix: Fields with characters that generate invalid XML (such as $ signs) are now escaped.</li>
1083 <li>Bugfix: Pre-instantiated objects can be unmarshalled through multiple levels.</li>
1084 </ul>
1085
1086 <h2>API changes</h2>
1087
1088 <ul>
1089 <li>None.</li>
1090 </ul>
1091
1092 <h1 id="1.0.1">Version 1.0.1</h1>
1093
1094 <p>Released May 30, 2004. Misc features and bugfixes.</p>
1095
1096 <h2>Major changes</h2>
1097
1098 <ul>
1099 <li>Support for multidimensional arrays.</li>
1100 <li>Object with readResolve() method will be treated the same way native serialization treats them.</li>
1101 </ul>
1102
1103 <h2>Minor changes</h2>
1104
1105 <ul>
1106 <li>New converters for Throwable and StackTraceElement that retain stack trace (JDK 1.4 only)</li>
1107 <li>Bugfix: System.identityHashCode() is not guaranteed to be unique. Ensure reference checking is used as well.</li>
1108 <li>Bugfix: Allows user classes to be defined in WEB-INF/classes in Servlet environments. Tries to use context classloader if available.</li>
1109 <li>Support for java.util.Currency (through readResolve()).</li>
1110 <li>Instances of Jakarta Commons Lang Enum are now reused (through readResolve()).</li>
1111 <li>Bugfix: JavaClassConverter handles primitive type classes (contributed by Matthew Sandoz).</li>
1112 </ul>
1113
1114 <h2>API changes</h2>
1115
1116 <ul>
1117 <li>Additional method: ConverterLookup.defaultConverter(). Custom implementations of this class should implement
1118 this new method.</li>
1119 </ul>
1120
1121 <h1 id="1.0">Version 1.0</h1>
1122
1123 <p>Released May 14, 2004. Focusses on finalizing the API for 1.0 release.</p>
1124
1125 <h2>Major changes</h2>
1126
1127 <ul>
1128 <li>Supports fields of same name, hidden by inheritance.</li>
1129 </ul>
1130
1131 <h2>Minor changes</h2>
1132
1133 <ul>
1134 <li>JavaDoc for most important parts of API.</li>
1135 </ul>
1136
1137 <h2>API changes</h2>
1138
1139 <ul>
1140 <li>The ReflectionConverter and ReflectionProviders have had an overhaul to support
1141 hidden fields. Most methods now take an extra argument to specify which class a field
1142 is declared in.</li>
1143 </ul>
1144
1145 <h1 id="1.0RC1">Version 1.0 (release candidate 1)</h1>
1146
1147 <p>Released May 9, 2004. Focusses on finalizing the API for 1.0 release.</p>
1148
1149 <h2>Major changes</h2>
1150
1151 <ul>
1152 <li>JDK 1.3 compatibility.</li>
1153 <li>Informative error messages.</li>
1154 <li>Defaults to using faster XPP based parser.</li>
1155 <li>Serializes final field under JDK 1.4.</li>
1156 <li>Fail fast when trying to serialize final field if not Sun 1.4 JRE.</li>
1157 </ul>
1158
1159 <h2>Minor changes</h2>
1160
1161 <ul>
1162 <li>Misc performance improvements.</li>
1163 <li>Converters for TreeMap and TreeSet that store the Comparator.</li>
1164 </ul>
1165
1166 <h2>API changes</h2>
1167
1168 <ul>
1169 <li>Default constructor for XStream class uses XppDriver instead of DomDriver.
1170 To use DomDriver, explicitly pass it in to the constructor.</li>
1171 <li>Exception is thrown if trying to serialize an object that contains a
1172 final field if not Sun 1.4 JRE.</li>
1173 </ul>
1174
1175 <p><a href="versioning.html">About XStream version numbers...</a></p>
1176
1177 <h1 id="0.6">Version 0.6</h1>
1178
1179 <p>Released May 7, 2004. Focusses on providing full object graph support.</p>
1180
1181 <h2>Major changes</h2>
1182
1183 <ul>
1184 <li>None.</li>
1185 </ul>
1186
1187 <h2>Minor changes</h2>
1188
1189 <ul>
1190 <li>Bugfix: Objects that had no children could not be derefenced properly (thanks to Brian Slesinsky and Nick Pomfret).</li>
1191 <li>Bugfix: DateConverter is now thread safe.</li>
1192 <li>Optimization: String instances are reused as much as possible.</li>
1193 <li>Converters for BigInteger and BigDecimal.</li>
1194 <li>IntConverter now recognises hexadecimal and octal notations (thanks to Konstantin Pribluda).</li>
1195 </ul>
1196
1197 <h2>API changes</h2>
1198
1199 <ul>
1200 <li>None.</li>
1201 </ul>
1202
1203 <h1 id="0.6RC1">Version 0.6 (release candidate 1)</h1>
1204
1205 <p>Released April 19, 2004. Focusses on providing full object graph support.</p>
1206
1207 <h2>Major changes</h2>
1208
1209 <ul>
1210 <li>Full support for object graphs, including duplicate references of same object and
1211 circular references.</li>
1212 <li>References can be identified using XPath (default), unique-IDs or disabled.</li>
1213 </ul>
1214
1215 <h2>Minor changes</h2>
1216
1217 <ul>
1218 <li>Release includes Ant build file.</li>
1219 <li>Converters for non standard collections such as Collections.EMPTY_LIST, syncronizedList(), unmodifiableMap(), etc.</li>
1220 <li>Converter for nulls.</li>
1221 <li>Converter for dynamic proxies.</li>
1222 <li>Converter for java.net.URL.</li>
1223 <li>Converters for java.util.LinkedHashMap and java.util.LinkedHashSet.</li>
1224 <li>Converters for java.lang.reflect.Method and java.lang.reflect.Constructor.</li>
1225 <li>If duplicate reference support is disabled and a circular reference is encountered, an exception will be thrown.</li>
1226 </ul>
1227
1228 <h2>API changes</h2>
1229
1230 <ul>
1231 <li>None.</li>
1232 </ul>
1233
1234 <h1 id="0.5">Version 0.5</h1>
1235
1236 <p>Released March 8, 2004. Focussed on performance.</p>
1237
1238 <h2>Major changes</h2>
1239
1240 <ul>
1241 <li>Massive performance improvements. Up to 3 times faster for serialization and 22
1242 times faster for deserialization!</li>
1243 <li>Non-DOM building pull parser based reader. Results in much smaller memory footprint,
1244 particularly when deserializing large object models.</li>
1245 </ul>
1246
1247 <h2>Minor changes</h2>
1248
1249 <ul>
1250 <li>Misc performance improvements.</li>
1251 <li>Misc bugfixes.</li>
1252 <li>Alternate encodings can be used with DomDriver.</li>
1253 </ul>
1254
1255 <h2>API changes</h2>
1256
1257 <ul>
1258 <li>Renamed XMLReader/Writer to HierarchicalStreamReader/Writer as XStream is not
1259 actually coupled to serializing just to XML.</li>
1260 <li>Cleaned up the public API.</li>
1261 <li>Moved internal XStream implementation classes to core package.</li>
1262 <li>Misc package/class renames to make more sense. Dumped lots of dead code.</li>
1263 </ul>
1264
1265 <h1 id="0.4">Version 0.4</h1>
1266
1267 <p>This version was never publicly released. All changes were made available in 0.5. Focussed on making it easier to create custom converters.</p>
1268
1269 <h2>Major changes</h2>
1270
1271 <ul>
1272 <li>Overhaul of interface for Converters. Makes Converters much cleaner to write.</li>
1273 </ul>
1274
1275 <h2>Minor changes</h2>
1276
1277 <ul>
1278 <li>Added custom converters for java.io.File, java.util.Properties, java.util.Vector, java.util.Hashtable, java.util.BitSet
1279 byte[] (Base64 encoded), char[].</li>
1280 <li>Misc bugfixes.</li>
1281 </ul>
1282
1283 <h2>API changes</h2>
1284
1285 <ul>
1286 <li>New interface to be implemented by custom converters.</li>
1287 </ul>
1288
1289 <h1 id="0.3">Version 0.3</h1>
1290
1291 <p>Released January 1, 2004.</p>
1292
1293 <h2>Major changes</h2>
1294
1295 <ul>
1296 <li>Added ElementMapper interface and default implementations to allow fine
1297 grained control over element name to class mapper operations.</li>
1298 <li>Added an XPP based reader and writer that uses a pull-parser to create a lightweight DOM tree.</li>
1299 </ul>
1300
1301 <h2>Minor changes</h2>
1302
1303 <ul>
1304 <li>Added XStream.fromXML(XMLReader xmlReader,Object root) method to
1305 allow the population of an object graph starting with a live object root.</li>
1306 <li>Added XMLReader.peek() method to allow access to the underlying hierarchical
1307 object being unmarshalled.</li>
1308 </ul>
1309
1310 <h2>API changes</h2>
1311
1312 <ul>
1313 <li>Aligned the the methods in XStream to use the specified ObjectFactory in the constructor
1314 instead of creating a SunReflectionObjectFactory.</li>
1315 </ul>
1316
1317 <h1 id="older">Older versions</h1>
1318
1319 <p>Changes in XStream prior to version 0.3 were not logged.</p>
1320
1321 </body>
1322 </html>
0 <html>
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2013 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 10. February 2006 by Mauro Talevi
11 -->
12 <head>
13 <title>Converter Tutorial</title>
14 </head>
15 <body>
16
17 <h1 id="SimpleConverter">Simple Converter</h1>
18 <h2>Setting up a simple example</h2>
19
20 <p>This is the most basic converter... let's start with a simple Person:</p>
21 <div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
22
23 public class Person {
24
25 private String name;
26
27 public String getName() {
28 return name;
29 }
30
31 public void setName(String name) {
32 this.name = name;
33 }
34
35 }</pre></div><p>So let's create a person and convert it to
36 XML...</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
37
38 import com.thoughtworks.xstream.XStream;
39 import com.thoughtworks.xstream.io.xml.DomDriver;
40
41 public class PersonTest {
42
43 public static void main(String[] args) {
44 Person person = new Person();
45 person.setName(&quot;Guilherme&quot;);
46
47 XStream xStream = new XStream(new DomDriver());
48 System.out.println(xStream.toXML(person));
49 }
50
51 }</pre></div><p>This results in a really ugly XML code which contains the full
52 class name (including
53 package)...</p><div class="Source Java"><pre>&lt;com.thoughtworks.xstream.examples.Person&gt;
54 &lt;name&gt;Guilherme&lt;/name&gt;
55 &lt;/com.thoughtworks.xstream.examples.Person&gt;</pre></div><p>So we make use
56 of an 'alias' to change this full class name to something more 'human', for
57 example
58 'person'.</p><div class="Source Java"><pre>XStream xStream = new XStream(new DomDriver());
59 xStream.alias(&quot;person&quot;, Person.class);
60 System.out.println(xStream.toXML(person));</pre></div><p>And the outcome is
61 much easier to read (and
62 smaller):</p><div class="Source Java"><pre>&lt;person&gt;
63 &lt;name&gt;Guilherme&lt;/name&gt;
64 &lt;/person&gt;</pre></div><p>Now that we have configured a simple class to
65 play with, let's see what XStream converters can do for us...</p>
66
67 <h2 id="CreatingPersonConverter">Creating a PersonConverter</h2>
68 <p>Let's create a simple converter capable
69 of:</p><ol style="list-style-type: decimal">
70 <li>telling its capable of converting Person's</li>
71 <li>translating a Person instance in XML</li>
72 <li>translate XML into a new Person</li>
73 </ol><p>We begin creating the PersonConverter class and implementing the
74 Converter
75 interface:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
76
77 import com.thoughtworks.xstream.converters.Converter;
78 import com.thoughtworks.xstream.converters.MarshallingContext;
79 import com.thoughtworks.xstream.converters.UnmarshallingContext;
80 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
81 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
82
83 public class PersonConverter implements Converter {
84
85 public boolean canConvert(Class clazz) {
86 return false;
87 }
88
89 public void marshal(Object value, HierarchicalStreamWriter writer,
90 MarshallingContext context) {
91 }
92
93 public Object unmarshal(HierarchicalStreamReader reader,
94 UnmarshallingContext context) {
95 return null;
96 }
97
98 }</pre></div><p>Now we tell whoever calls us that we can handle only Person's
99 (and <b>nothing</b> else, including those classes which extends
100 Person).</p><div class="Source Java"><pre>public boolean canConvert(Class clazz) {
101 return clazz.equals(Person.class);
102 }</pre></div><p>The second step is usually quite clean, unless you are dealing
103 with generic converters.</p><p>The marshal method is responsible for
104 translating an object to XML. It receives three
105 arguments:</p><ol style="list-style-type: decimal">
106 <li>the object we are trying to convert</li>
107 <li>the writer were we should output the data</li>
108 <li>the current marshalling context</li>
109 </ol><p>We start casting the object to
110 person:</p><div class="Source Java"><pre>Person person = (Person) value;</pre></div><p>Now
111 we can output the data... let's start creating a node called <i>fullname</i>
112 and adding the person's name to
113 it:</p><div class="Source Java"><pre>writer.startNode(&quot;fullname&quot;);
114 writer.setValue(person.getName());
115 writer.endNode();</pre></div><p>Quite simple
116 huh?</p><div class="Source Java"><pre>public void marshal(Object value, HierarchicalStreamWriter writer,
117 MarshallingContext context) {
118 Person person = (Person) value;
119 writer.startNode(&quot;fullname&quot;);
120 writer.setValue(person.getName());
121 writer.endNode();
122 }</pre></div><p>We could have called start/end node as many times as we would
123 like (but remember to close everything you open)... and conversion usually
124 takes place when calling the <i>setValue</i> method.</p><p>And now let's go to
125 the unmarshal. We use the <i>moveDown</i> and <i>moveUp</i> methods to move
126 in the tree hierarchy, so we can simply <i>moveDown</i>, read the value and
127 <i>moveUp</i>.</p><div class="Source Java"><pre> Person person = new Person();
128 reader.moveDown();
129 person.setName(reader.getValue());
130 reader.moveUp();</pre></div><p>Which gives us the following
131 converter:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
132
133 import com.thoughtworks.xstream.converters.Converter;
134 import com.thoughtworks.xstream.converters.MarshallingContext;
135 import com.thoughtworks.xstream.converters.UnmarshallingContext;
136 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
137 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
138
139 public class PersonConverter implements Converter {
140
141 public boolean canConvert(Class clazz) {
142 return clazz.equals(Person.class);
143 }
144
145 public void marshal(Object value, HierarchicalStreamWriter writer,
146 MarshallingContext context) {
147 Person person = (Person) value;
148 writer.startNode(&quot;fullname&quot;);
149 writer.setValue(person.getName());
150 writer.endNode();
151 }
152
153 public Object unmarshal(HierarchicalStreamReader reader,
154 UnmarshallingContext context) {
155 Person person = new Person();
156 reader.moveDown();
157 person.setName(reader.getValue());
158 reader.moveUp();
159 return person;
160 }
161
162 }</pre></div><p>Now let's register our converter and see how our application
163 <i>main</i> method looks
164 like:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
165
166 import com.thoughtworks.xstream.XStream;
167 import com.thoughtworks.xstream.io.xml.DomDriver;
168
169 public class PersonTest {
170
171 public static void main(String[] args) {
172 Person person = new Person();
173 person.setName(&quot;Guilherme&quot;);
174
175 XStream xStream = new XStream(new DomDriver());
176 xStream.registerConverter(new PersonConverter());
177 xStream.alias(&quot;person&quot;, Person.class);
178 System.out.println(xStream.toXML(person));
179 }
180
181 }</pre></div><p>Did you notice how we registered our converter? It's a simple
182 call to
183 <i>registerConverter</i>:</p><div class="Source Java"><pre>xStream.registerConverter(new PersonConverter());</pre></div><p>The
184 final result
185 is:</p><div class="Source Java"><pre>&lt;person&gt;
186 &lt;fullname&gt;Guilherme&lt;/fullname&gt;
187 &lt;/person&gt;</pre></div><p>So you might say... that only changed my tree, I
188 want to convert data!</p><p>Try using an attribute called <i>fullname</i> in
189 the <i>person</i> tag instead of creating a new child node.</p>
190
191 <h2 id="SingleValueConverter">An alternative for types with String representation</h2>
192
193 <p>Let's enhance the Person with a String representation, that contains all necessary
194 text to recreate the instance:</p>
195 <div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
196
197 public class Person {
198
199 private String name;
200
201 public String getName() {
202 return name;
203 }
204
205 public void setName(String name) {
206 this.name = name;
207 }
208
209 public String toString() {
210 return getName();
211 }
212 }</pre></div><p>In this case we can simplify our Converter to</p>
213 <div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
214
215 import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
216
217 public class PersonConverter extends AbstractSingleValueConverter {
218
219 public boolean canConvert(Class clazz) {
220 return clazz.equals(Person.class);
221 }
222
223 public Object fromString(String str) {
224 Person person = new Person();
225 person.setName(string);
226 return person;
227 }
228
229 }</pre></div><p>But even nicer, our XML is also simplified (using the alias for the
230 Person class). Since the String representation is complete, a nested element is not
231 necessary anymore:</p>
232 <div class="Source Java"><pre>&lt;person&gt;Guilherme&lt;/person&gt;</pre></div>
233
234 <p class=highlight>Note, that in implementation of a SingleValueConverter is required for
235 attributes, since these objects have to be represented by a single string only.</p>
236
237 <h1 id="CustomConverter">Date Converter</h1>
238 <p>Now that we know how the <i>Converter</i> interface works, let's create a
239 simple calendar converter which uses the locale to convert the
240 information.</p><p>Our converter will receive the Locale in its constructor
241 and we will keep a reference to it in a member
242 variable:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
243
244 import java.util.Locale;
245
246 import com.thoughtworks.xstream.converters.Converter;
247 import com.thoughtworks.xstream.converters.MarshallingContext;
248 import com.thoughtworks.xstream.converters.UnmarshallingContext;
249 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
250 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
251
252 public class DateConverter implements Converter {
253
254 private Locale locale;
255
256 public DateConverter(Locale locale) {
257 super();
258 this.locale = locale;
259 }
260
261 public boolean canConvert(Class clazz) {
262 return false;
263 }
264
265 public void marshal(Object value, HierarchicalStreamWriter writer,
266 MarshallingContext context) {
267 }
268
269 public Object unmarshal(HierarchicalStreamReader reader,
270 UnmarshallingContext context) {
271 return null;
272 }
273
274 }</pre></div><p>Now let's convert anything which extends <i>Calendar</i>:
275 means if instances of class <i>clazz</i> can be assigned to the
276 <i>Calendar</i> class, they extends the abstract class
277 <i>Calendar</i>:</p><div class="Source Java"><pre>public boolean canConvert(Class clazz) {
278 return Calendar.class.isAssignableFrom(clazz);
279 }</pre></div><p>Let's go for converting a <i>Calendar</i> in a localized
280 string... we first cast the object to <i>Calendar</i>, extract its <i>Date</i>
281 and then use a <i>DateFormat</i> factory method to get a date converter to our
282 localized
283 string.</p><div class="Source Java"><pre>public void marshal(Object value, HierarchicalStreamWriter writer,
284 MarshallingContext context) {
285
286 Calendar calendar = (Calendar) value;
287
288 // grabs the date
289 Date date = calendar.getTime();
290
291 // grabs the formatter
292 DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL,
293 this.locale);
294
295 // formats and sets the value
296 writer.setValue(formatter.format(date));
297
298 }</pre></div><p>And the other way around... in order to unmarshall, we create
299 a <i>GregorianCalendar</i>, retrieves the localized <i>DateFormat</i>
300 instance, parses the string into a <i>Date</i> and puts this date in the
301 original
302 <i>GregorianCalendar</i>:</p><div class="Source Java"><pre>public Object unmarshal(HierarchicalStreamReader reader,
303 UnmarshallingContext context) {
304
305 // creates the calendar
306 GregorianCalendar calendar = new GregorianCalendar();
307
308 // grabs the converter
309 DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL,
310 this.locale);
311
312 // parses the string and sets the time
313 try {
314 calendar.setTime(formatter.parse(reader.getValue()));
315 } catch (ParseException e) {
316 throw new ConversionException(e.getMessage(), e);
317 }
318
319 // returns the new object
320 return calendar;
321
322 }</pre></div><p>Note 1: remember that some <i>DateFormat</i> implementations
323 are not thread-safe, therefore don't put your formatter as a member of your
324 converter.</p><p>Note 2: this implementation <b>will</b> convert other types
325 of Calendar's to GregorianCalendar after save/load. If this is not what you
326 want, change your <i>canConvert</i> method to return <i>true</i> only if
327 <i>class</i> equals <i>GregorianCalendar</i>.</p><p>So we get the following
328 converter:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
329
330 import java.text.DateFormat;
331 import java.text.ParseException;
332 import java.util.Calendar;
333 import java.util.Date;
334 import java.util.GregorianCalendar;
335 import java.util.Locale;
336
337 import com.thoughtworks.xstream.converters.ConversionException;
338 import com.thoughtworks.xstream.converters.Converter;
339 import com.thoughtworks.xstream.converters.MarshallingContext;
340 import com.thoughtworks.xstream.converters.UnmarshallingContext;
341 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
342 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
343
344 public class DateConverter implements Converter {
345
346 private Locale locale;
347
348 public DateConverter(Locale locale) {
349 super();
350 this.locale = locale;
351 }
352
353 public boolean canConvert(Class clazz) {
354 return Calendar.class.isAssignableFrom(clazz);
355 }
356
357 public void marshal(Object value, HierarchicalStreamWriter writer,
358 MarshallingContext context) {
359 Calendar calendar = (Calendar) value;
360 Date date = calendar.getTime();
361 DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL,
362 this.locale);
363 writer.setValue(formatter.format(date));
364 }
365
366 public Object unmarshal(HierarchicalStreamReader reader,
367 UnmarshallingContext context) {
368 GregorianCalendar calendar = new GregorianCalendar();
369 DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL,
370 this.locale);
371 try {
372 calendar.setTime(formatter.parse(reader.getValue()));
373 } catch (ParseException e) {
374 throw new ConversionException(e.getMessage(), e);
375 }
376 return calendar;
377 }
378
379 }</pre></div><p>And let's try it out. We create a <i>DateTest</i> class with a
380 <i>main</i> method:</p><ol style="list-style-type: decimal">
381 <li>creates a calendar (current date)</li>
382 <li>creates the XStream object</li>
383 <li>registers the converter with a Brazilian Portuguese locale</li>
384 <li>translates the object in XML</li>
385 </ol>
386 <p>Well, we already know how to do all those steps... so let's go:</p>
387 <div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
388
389 import java.util.Calendar;
390 import java.util.GregorianCalendar;
391 import java.util.Locale;
392
393 import com.thoughtworks.xstream.XStream;
394 import com.thoughtworks.xstream.io.xml.DomDriver;
395
396 public class DateTest {
397
398 public static void main(String[] args) {
399
400 // grabs the current date from the virtual machine
401 Calendar calendar = new GregorianCalendar();
402
403 // creates the xstream
404 XStream xStream = new XStream(new DomDriver());
405
406 // brazilian portuguese locale
407 xStream.registerConverter(new DateConverter(new Locale(&quot;pt&quot;, &quot;br&quot;)));
408
409 // prints the result
410 System.out.println(xStream.toXML(calendar));
411
412 }
413
414 }</pre></div><p>The result? Well... it depends, but it will be something
415 like:</p><div class="Source Java"><pre>&lt;gregorian-calendar&gt;Sexta-feira, 10 de Fevereiro de 2006&lt;/gregorian-calendar&gt;</pre></div><p>Note:
416 we did not put any alias as <i>gregorian-calendar</i> is the default alias for
417 <i>GregorianCalendar</i>.</p><p>And now let's try to unmarshal the result
418 shown
419 above:</p><div class="Source Java"><pre>// loads the calendar from the string
420 Calendar loaded = (Calendar) xStream
421 .fromXML(&quot;&lt;gregorian-calendar&gt;Sexta-feira, 10 de Fevereiro de 2006&lt;/gregorian-calendar&gt;&quot;);</pre></div><p>And
422 print it using the system locale, short date
423 format:</p><div class="Source Java"><pre>// prints using the system defined locale
424 System.out.println(DateFormat.getDateInstance(DateFormat.SHORT).format(
425 loaded.getTime()));</pre></div><p>The result might be
426 something like (if your system locale is American
427 English):</p><div class="Source Java"><pre>2/10/06</pre></div>
428
429 <h1 id="ComplexConverter">Complex Converter</h1>
430 <h2>Setting up another example</h2>
431
432 <p>We already defined some classes, so let them glue together:</p>
433 <div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
434
435 public class Birthday {
436
437 private Person person;
438 private Calendar date;
439 private char gender;
440
441 public Person getPerson() {
442 return person;
443 }
444
445 public void setPerson(Person person) {
446 this.person = person;
447 }
448
449 public Calendar getDate() {
450 return date;
451 }
452
453 public void setDate(Calendar date) {
454 this.date = date;
455 }
456
457 public char getGender() {
458 return gender;
459 }
460
461 public void setGenderMale() {
462 this.gender = 'm';
463 }
464
465 public void setGenderFemale() {
466 this.gender = 'f';
467 }
468
469 }</pre></div><p>While XStream is capable of converting this class without any problem, we write our own custom converter
470 just for demonstration. This time we want to reuse our already written converters for the Person and the Calendar and add an
471 own attribute for the gender. The <code>canConvert</code> method is plain simple. We convert no derived classes this time,
472 since they might have additional fields. But we reuse the converters registered in XStream for our member fields and handle
473 <code>null</code> values:
474 </p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
475
476 import java.util.Calendar;
477
478 import com.thoughtworks.xstream.converters.ConversionException;
479 import com.thoughtworks.xstream.converters.Converter;
480 import com.thoughtworks.xstream.converters.MarshallingContext;
481 import com.thoughtworks.xstream.converters.UnmarshallingContext;
482 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
483 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
484
485 public class BirthdayConverter implements Converter {
486
487 public boolean canConvert(Class clazz) {
488 return Birthday.class == clazz;
489 }
490
491 public void marshal(Object value, HierarchicalStreamWriter writer,
492 MarshallingContext context) {
493 Birthday birthday = (Birthday)value;
494 if (birthday.getGender() != '\0') {
495 writer.addAttribute("gender", Character.toString(birthday.getGender()));
496 }
497 if (birthday.getPerson() != null) {
498 writer.startNode("person");
499 context.convertAnother(birthday.getPerson());
500 writer.endNode();
501 }
502 if (birthday.getDate() != null) {
503 writer.startNode("birth");
504 context.convertAnother(birthday.getDate());
505 writer.endNode();
506 }
507 }
508
509 public Object unmarshal(HierarchicalStreamReader reader,
510 UnmarshallingContext context) {
511 Birthday birthday = new Birthday();
512 String gender = reader.getAttribute("gender");
513 if (gender != null) {
514 if (gender.length() &gt; 0) {
515 if (gender.char(0) == 'f') {
516 birthday.setGenderFemale();
517 } else if (gender.char(0) == 'm') {
518 birthday.setFemale();
519 } else {
520 throw new ConversionException("Invalid gender value: " + gender);
521 }
522 } else {
523 throw new ConversionException("Empty string is invalid gender value");
524 }
525 }
526 while (reader.hasMoreChildren()) {
527 reader.moveDown();
528 if ("person".equals(reader.getNodeName())) {
529 Person person = (Person)context.convertAnother(birthday, Person.class);
530 birthday.setPerson(person);
531 } else if ("birth".equals(reader.getNodeName())) {
532 Calendar date = (Calendar)context.convertAnother(birthday, Calendar.class);
533 birthday.setDate(date);
534 }
535 reader.moveUp();
536 }
537 return birthday;
538 }
539
540 }</pre></div><p>The unmarshal method ensures the valid value for the gender by throwing a
541 ConversionException for invalid entries.</p>
542
543 <p class=highlight>Note, that attributes will always have to be written and read first. You work on a stream and
544 accessing the value of a tag or its members will close the surrounding tag (that is still active when the method is
545 called).</p>
546
547 <p>If the implementation of <code>Birthday</code> ensures, that none of its fields
548 could hold a <code>null</code> value and gender contains a valid value, then we could drop the
549 <code>null</code> condition in the <code>marshal</code> method and in <code>unmarshal</code>
550 we could omit the loop as well as the comparison of the tag names:</p><div class="Source Java"><pre>package com.thoughtworks.xstream.examples;
551
552 import java.util.Calendar;
553
554 import com.thoughtworks.xstream.converters.Converter;
555 import com.thoughtworks.xstream.converters.MarshallingContext;
556 import com.thoughtworks.xstream.converters.UnmarshallingContext;
557 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
558 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
559
560 public class BirthdayConverter implements Converter {
561
562 public boolean canConvert(Class clazz) {
563 return Birthday.class == clazz;
564 }
565
566 public void marshal(Object value, HierarchicalStreamWriter writer,
567 MarshallingContext context) {
568 Birthday birthday = (Birthday)value;
569 writer.addAttribute("gender", Character.toString(birthday.getGender()));
570 writer.startNode("person");
571 context.convertAnother(birthday.getPerson());
572 writer.endNode();
573 writer.startNode("birth");
574 context.convertAnother(birthday.getDate());
575 writer.endNode();
576 }
577
578 public Object unmarshal(HierarchicalStreamReader reader,
579 UnmarshallingContext context) {
580 Birthday birthday = new Birthday();
581 if (reader.getAttribute("gender").charAt(0) == 'm') {
582 birthday.setGenderMale();
583 } else {
584 birthday.setGenderFemale();
585 }
586 reader.moveDown();
587 Person person = (Person)context.convertAnother(birthday, Person.class);
588 birthday.setPerson(person);
589 reader.moveUp();
590 reader.moveDown();
591 Calendar date = (Calendar)context.convertAnother(birthday, Calendar.class);
592 birthday.setDate(date);
593 reader.moveUp();
594 return birthday;
595 }
596
597 }</pre></div>
598 </body>
599 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Converters</title>
14 <style type="text/css">
15 .example { font-family: courier; font-size: 8pt; }
16 #content td { border-top: thin solid #5c5 ;}
17 #content .headerRow { background-color: white; }
18 </style>
19 </head>
20 <body>
21
22 <p>The core of XStream consists of a registry of
23 <a href="javadoc/com/thoughtworks/xstream/converters/Converter.html"><b>Converters</b></a>. The responsibility
24 of a Converter is to provide a strategy for converting particular types of objects found in the object graph,
25 to and from XML.</p>
26
27 <p>XStream is provided with Converters for common types such as primitives, String, File, Collections, arrays,
28 and Dates. The following table lists any converter delivered with XStream and documents, if they are
29 registered by default with which priority.</p>
30
31
32 <table class="examplesTable" summary="Overview over all Converters delivered with XStream">
33 <!-- .................................................................................................. -->
34 <tr>
35 <td colspan="5" class="headerRow"><h1 id="java.lang">java.lang (and core special types)</h1></td>
36 </tr>
37 <tr>
38 <th>Converter</th>
39 <th>Supported types</th>
40 <th>Example</th>
41 <th>Notes</th>
42 <th>Prio</th>
43 </tr>
44 <tr>
45 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/NullConverter.html">NullConverter</a></td>
46 <td>null values</td>
47 <td class="example">&lt;null/&gt;</td>
48 <td>Usually, null fields are left out of the XML, however when used in arrays or the root object they
49 have to be explicitly marked.</td>
50 <td>very high</td>
51 </tr>
52 <tr>
53 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/ArrayConverter.html">ArrayConverter</a></td>
54 <td>any kind of array</td>
55 <td class="example">
56 &lt;<i>string</i>-array&gt;<br/>
57 &nbsp;&nbsp;&lt;<i>string</i>&gt;apple&lt;/<i>string</i>&gt;<br/>
58 &nbsp;&nbsp;&lt;<i>string</i>&gt;banana&lt;/<i>string</i>&gt;<br/>
59 &nbsp;&nbsp;&lt;<i>string</i>&gt;cabbage&lt;/<i>string</i>&gt;<br/>
60 &lt;<i>string</i>-array&gt;
61 </td>
62 <td>This supports arrays of primitives as well as objects. It also supports multi-dimensional arrays, even if
63 they are non-rectangular.</td>
64 <td>normal</td>
65 </tr>
66 <tr>
67 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/BooleanConverter.html">BooleanConverter</a></td>
68 <td>boolean<br/>java.lang.Boolean</td>
69 <td class="example">&lt;boolean&gt;true&lt;/boolean&gt;</td>
70 <td>Can also be registered locally using different values.</td>
71 <td>normal</td>
72 </tr>
73 <tr>
74 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/ByteConverter.html">ByteConverter</a></td>
75 <td>byte<br/>java.lang.Byte</td>
76 <td class="example">&lt;byte&gt;22&lt;/byte&gt;</td>
77 <td>The byte is represented as an integer.</td>
78 <td>normal</td>
79 </tr>
80 <tr>
81 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/EncodedByteArrayConverter.html">EncodedByteArrayConverter</a></td>
82 <td>byte[]</td>
83 <td class="example">&lt;byte-array&gt;AHiEFiEABQ==&lt;/byte-array&gt;</td>
84 <td>Uses Base64 encoding to store binary data in XML. Converter can be registered globally or locally.</td>
85 <td>normal</td>
86 </tr>
87 <tr>
88 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/CharConverter.html">CharConverter</a></td>
89 <td>char<br/>java.lang.Character</td>
90 <td class="example">&lt;char&gt;X&lt;/char&gt;<br/>&lt;char null=&quot;true&quot;/&gt;</td>
91 <td>The '\0' character is invalid in XML.</td>
92 <td>normal</td>
93 </tr>
94 <tr>
95 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/CharArrayConverter.html">CharArrayConverter</a></td>
96 <td>char[]</td>
97 <td class="example">&lt;char-array&gt;hello&lt;char-array&gt;</td>
98 <td>Joins all characters into a single String.</td>
99 <td>normal</td>
100 </tr>
101 <tr>
102 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/DoubleConverter.html">DoubleConverter</a></td>
103 <td>double<br/>java.lang.Double</td>
104 <td class="example">&lt;double&gt;456774543443.4553435&lt;/double&gt;</td>
105 <td>&nbsp;</td>
106 <td>normal</td>
107 </tr>
108 <tr>
109 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/FloatConverter.html">FloatConverter</a></td>
110 <td>float<br/>java.lang.Float</td>
111 <td class="example">&lt;float&gt;4563443.435&lt;/float&gt;</td>
112 <td>&nbsp;</td>
113 <td>normal</td>
114 </tr>
115 <tr>
116 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/IntConverter.html">IntConverter</a></td>
117 <td>int<br/>java.lang.Integer</td>
118 <td class="example">&lt;int&gt;12345678&lt;/int&gt;</td>
119 <td>&nbsp;</td>
120 <td>normal</td>
121 </tr>
122 <tr>
123 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/LongConverter.html">LongConverter</a></td>
124 <td>long<br/>java.lang.Long</td>
125 <td class="example">&lt;long&gt;2344556678888786&lt;/long&gt;</td>
126 <td>&nbsp;</td>
127 <td>normal</td>
128 </tr>
129 <tr>
130 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/NamedCollectionConverter.html">NamedArrayConverter</a></td>
131 <td>any kind of array</td>
132 <td class="example">
133 &lt;<i>string</i>-array&gt;<br/>
134 &nbsp;&nbsp;&lt;<i>product</i>&gt;apple&lt;/<i>product</i>&gt;<br/>
135 &nbsp;&nbsp;&lt;<i>product</i>&gt;banana&lt;/<i>product</i>&gt;<br/>
136 &nbsp;&nbsp;&lt;<i>product</i>&gt;cabbage&lt;/<i>product</i>&gt;<br/>
137 &lt;<i>string</i>-array&gt;
138 </td>
139 <td>This supports arrays of primitives as well as objects. It also supports multi-dimensional arrays, even if
140 they are non-rectangular. Should be registered locally or for an individual array type.</td>
141 <td>&nbsp;</td>
142 </tr>
143 <tr>
144 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/ShortConverter.html">ShortConverter</a></td>
145 <td>short<br/>java.lang.Short</td>
146 <td class="example">&lt;short&gt;1445&lt;/short&gt;</td>
147 <td>&nbsp;</td>
148 <td>normal</td>
149 </tr>
150 <tr>
151 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/StringConverter.html">StringConverter</a></td>
152 <td>java.lang.String</td>
153 <td class="example">&lt;string&gt;hello world&lt;/string&gt;</td>
154 <td>This converter can be registered with different caching strategies.</td>
155 <td>normal</td>
156 </tr>
157 <tr>
158 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/StringBufferConverter.html">StringBufferConverter</a></td>
159 <td>java.lang.StringBuffer</td>
160 <td class="example">&lt;string-buffer&gt;hello world&lt;/string-buffer&gt;</td>
161 <td>&nbsp;</td>
162 <td>normal</td>
163 </tr>
164 <tr>
165 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/StringBuildererConverter.html">StringBuilderConverter</a></td>
166 <td>java.lang.StringBuilder</td>
167 <td class="example">&lt;string-builder&gt;hello world&lt;/string-builder&gt;</td>
168 <td>Available under Java 1.5 or greater.</td>
169 <td>normal</td>
170 </tr>
171 <tr>
172 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ThrowableConverter.html">ThrowableConverter</a></td>
173 <td>java.lang.Throwable<br/>java.lang.Exception<br/>java.lang.RuntimeException<br/>java.lang.Error<br/>...and all subclasses
174 of these.</td>
175 <td class="example">
176 &lt;java.io.IOException&gt;<br/>
177 &nbsp;&nbsp;&lt;detailMessage&gt;No file&lt;/detailMessage&gt;<br/>
178 &nbsp;&nbsp;&lt;stack-trace&gt;<br/>
179 &nbsp;&nbsp;&nbsp;&nbsp;&lt;trace&gt;com.x.Foo.stuff(Foo.java:22)&lt;/trace&gt;<br/>
180 &nbsp;&nbsp;&nbsp;&nbsp;&lt;trace&gt;com.x.Foo.blah(Foo.java:31)&lt;/trace&gt;<br/>
181 &nbsp;&nbsp;&nbsp;&nbsp;&lt;trace&gt;com.x.Foo.main(Foo.java:43)&lt;/trace&gt;<br/>
182 &nbsp;&nbsp;&lt;/stack-trace&gt;<br/>
183 &lt;/java.io.IOException&gt;
184 </td>
185 <td>This is only available under Java 1.4 or greater. It retains the full stack trace, including that of any
186 nested exceptions. The stack trace elements are handled by the
187 <a href="javadoc/com/thoughtworks/xstream/converters/extended/StackTraceElementConverter.html">StackTraceElementConverter</a>.</td>
188 <td>normal</td>
189 </tr>
190 <tr>
191 <td><a href="javadoc/com/thoughtworks/xstream/converters/enums/EnumConverter.html">EnumConverter</a></td>
192 <td>java.lang.Enum</td>
193 <td class="example">&lt;java.lang.annotation.RetentionPolicy&gt;<br/>CLASS<br/>&lt;/java.lang.annotation.RetentionPolicy&gt;</td>
194 <td>Available under Java 1.5 or greater.</td>
195 <td>normal</td>
196 </tr>
197 <tr>
198 <td><a href="javadoc/com/thoughtworks/xstream/converters/enums/EnumToStringConverter.html">EnumToStringConverter</a></td>
199 <td>java.lang.Enum</td>
200 <td>The Converter must be initialized with an Enum type and an optional mapping between strings and enum values. By default
201 it will use the Enum's string representation as value.</td>
202 <td>Available under Java 1.5 or greater. Must be registered explicitly for the Enum type or locally.</td>
203 <td>&nbsp;</td>
204 </tr>
205
206 <!-- .................................................................................................. -->
207 <tr>
208 <td colspan="5" class="headerRow"><h1 id="java.util">java.util</h1></td>
209 </tr>
210 <tr>
211 <th>Converter</th>
212 <th>Supported types</th>
213 <th>Example</th>
214 <th>Notes</th>
215 <th>Prio</th>
216 </tr>
217 <tr>
218 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/CollectionConverter.html">CollectionConverter</a></td>
219 <td>java.util.ArrayList<br/>java.util.LinkedList<br/>java.util.HashSet<br/>java.util.Vector<br/>java.util.LinkedHashSet</td>
220 <td class="example">
221 &lt;linked-list&gt;<br/>
222 &nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
223 &nbsp;&nbsp;&lt;string&gt;banana&lt;/string&gt;<br/>
224 &nbsp;&nbsp;&lt;big-decimal&gt;12345.4555&lt;/big-decimal&gt;<br/>
225 &lt;/linked-list&gt;
226 </td>
227 <td>The objects inside the collection can be any type of objects, including nested collections. Can be
228 registered for an individual Collection type or locally, suppression of implicit type might be
229 necessary.</td>
230 <td>normal</td>
231 </tr>
232 <tr>
233 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/MapConverter.html">MapConverter</a></td>
234 <td>java.util.HashMap<br/>java.util.Hashtable<br/>java.util.LinkedHashMap<br/>java.util.concurrent.ConcurrentHashMap</td>
235 <td class="example">
236 &lt;map&gt;<br/>
237 &nbsp;&nbsp;&lt;entry&gt;<br/>
238 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
239 &nbsp;&nbsp;&nbsp;&nbsp;&lt;float&gt;123.553&lt;/float&gt;<br/>
240 &nbsp;&nbsp;&lt;/entry&gt;<br/>
241 &nbsp;&nbsp;&lt;entry&gt;<br/>
242 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;orange&lt;/string&gt;<br/>
243 &nbsp;&nbsp;&nbsp;&nbsp;&lt;float&gt;55.4&lt;/float&gt;<br/>
244 &nbsp;&nbsp;&lt;/entry&gt;<br/>
245 &lt;/map&gt;
246 </td>
247 <td>Both key and values can be any type of objects. Can be registered for an individual Map type or
248 locally, suppression of implicit type might be necessary.</td>
249 <td>normal</td>
250 </tr>
251 <tr>
252 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/NamedCollectionConverter.html">NamedCollectionConverter</a></td>
253 <td>java.util.ArrayList<br/>java.util.LinkedList<br/>java.util.HashSet<br/>java.util.Vector<br/>java.util.LinkedHashSet</td>
254 <td class="example">
255 &lt;linked-list&gt;<br/>
256 &nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
257 &nbsp;&nbsp;&lt;string&gt;banana&lt;/string&gt;<br/>
258 &nbsp;&nbsp;&lt;big-decimal&gt;12345.4555&lt;/big-decimal&gt;<br/>
259 &lt;/linked-list&gt;
260 </td>
261 <td>The objects inside the collection can be any type of objects, including nested collections. Should
262 be registered locally or for an individual Collection type.</td>
263 <td>&nbsp;</td>
264 </tr>
265 <tr>
266 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/NamedMapConverter.html">NamedMapConverter</a></td>
267 <td>java.util.HashMap<br/>java.util.Hashtable<br/>java.util.LinkedHashMap<br/>java.util.concurrent.ConcurrentHashMap</td>
268 <td class="example">
269 &lt;map&gt;<br/>
270 &nbsp;&nbsp;&lt;fruit&gt;<br/>
271 &nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;apple&lt;/name&gt;<br/>
272 &nbsp;&nbsp;&nbsp;&nbsp;&lt;price&gt;123.553&lt;/price&gt;<br/>
273 &nbsp;&nbsp;&lt;/fruit&gt;<br/>
274 &nbsp;&nbsp;&lt;fruit&gt;<br/>
275 &nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;orange&lt;/name&gt;<br/>
276 &nbsp;&nbsp;&nbsp;&nbsp;&lt;price&gt;55.4&lt;/price&gt;<br/>
277 &nbsp;&nbsp;&lt;/fruit&gt;<br/>
278 &lt;/map&gt;
279 </td>
280 <td>Both key and values can be any type of objects. If key or value are written as attributes or if
281 the value is written as text of the entry element, those types must be handled by a
282 SingleValueConverter. Should be registered locally or for an individual Map type.</td>
283 <td>&nbsp;</td>
284 </tr>
285 <tr>
286 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/PropertiesConverter.html">PropertiesConverter</a></td>
287 <td>java.util.Properties</td>
288 <td class="example">
289 &lt;properties&gt;<br/>
290 &nbsp;&nbsp;&lt;property name=&quot;host&quot; value=&quot;localhost&quot;/&gt;<br/>
291 &nbsp;&nbsp;&lt;property name=&quot;port&quot; value=&quot;888&quot;/&gt;<br/>
292 &lt;/properties&gt;
293 </td>
294 <td>Because the Properties class only accepts Strings for keys and values, the XML can be more concise.
295 If the Properties instance includes a set of default Properties, these are serialized in a nested <code>&lt;defaults&gt;</code> element.</td>
296 <td>normal</td>
297 </tr>
298 <tr>
299 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/SingletonCollectionConverter.html">SingletonCollectionConverter</a></td>
300 <td>java.util.Collections.singletonList().getClass()<br/>java.util.Collections.singleton().getClass()</td>
301 <td class="example">
302 &lt;singleton-set&gt;<br/>
303 &nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
304 &lt;/singleton-set&gt;
305 </td>
306 <td>The objects inside the singleton collection can be any type of objects, including nested collections.</td>
307 <td>normal</td>
308 </tr>
309 <tr>
310 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/SingletonMapConverter.html">SingletonMapConverter</a></td>
311 <td>java.util.Collections.singletonMap().getClass()</td>
312 <td class="example">
313 &lt;singleton-map&gt;<br/>
314 &nbsp;&nbsp;&lt;entry&gt;<br/>
315 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
316 &nbsp;&nbsp;&nbsp;&nbsp;&lt;float&gt;123.553&lt;/float&gt;<br/>
317 &nbsp;&nbsp;&lt;/entry&gt;<br/>
318 &lt;/singleton-map&gt;
319 </td>
320 <td>The objects inside the singleton collection can be any type of objects, including nested collections.</td>
321 <td>normal</td>
322 </tr>
323 <tr>
324 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/TreeMapConverter.html">TreeMapConverter</a></td>
325 <td>java.util.TreeMap</td>
326 <td class="example">
327 &lt;tree-map&gt;<br/>
328 &nbsp;&nbsp;&lt;comparator class=&quot;com.blah.MyComparator&quot;/&gt;<br/>
329 &nbsp;&nbsp;&lt;entry&gt;<br/>
330 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
331 &nbsp;&nbsp;&nbsp;&nbsp;&lt;float&gt;123.553&lt;/float&gt;<br/>
332 &nbsp;&nbsp;&lt;/entry&gt;<br/>
333 &nbsp;&nbsp;&lt;entry&gt;<br/>
334 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;orange&lt;/string&gt;<br/>
335 &nbsp;&nbsp;&nbsp;&nbsp;&lt;float&gt;55.4&lt;/float&gt;<br/>
336 &nbsp;&nbsp;&lt;/entry&gt;<br/>
337 &lt;/tree-map&gt;
338 </td>
339 <td>This is similar to MapConverter with an additional field for storing the java.util.Comparator associated with the TreeMap.</td>
340 <td>normal</td>
341 </tr>
342 <tr>
343 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/TreeSetConverter.html">TreeSetConverter</a></td>
344 <td>java.util.TreeSet</td>
345 <td class="example">
346 &lt;tree-set&gt;<br/>
347 &nbsp;&nbsp;&lt;comparator class=&quot;com.blah.MyComparator&quot;/&gt;<br/>
348 &nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
349 &nbsp;&nbsp;&lt;string&gt;banana&lt;/string&gt;<br/>
350 &nbsp;&nbsp;&lt;string&gt;cabbage&lt;/string&gt;<br/>
351 &lt;/tree-set&gt;
352 </td>
353 <td>This is similar to CollectionConverter with an additional field for storing the java.util.Comparator associated with the TreeSet.</td>
354 <td>normal</td>
355 </tr>
356 <tr>
357 <td><a href="javadoc/com/thoughtworks/xstream/converters/collections/BitSetConverter.html">BitSetConverter</a></td>
358 <td>java.util.BitSet</td>
359 <td class="example">
360 &lt;bit-set&gt;0,1,3,5,6,8,10&lt;/bit-set&gt;
361 </td>
362 <td>Stores a comma separated list of which bits are set. Designed to be readable without taking up too much space.</td>
363 <td>normal</td>
364 </tr>
365 <tr>
366 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/DateConverter.html">DateConverter</a></td>
367 <td>java.util.Date</td>
368 <td class="example">&lt;date&gt;2004-02-22 15:16:04.0 UTC&lt;/date&gt;</td>
369 <td>Can be registered with different formats, locales or time zone globally or locally.</td>
370 <td>normal</td>
371 </tr>
372 <tr>
373 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/GregorianCalendarConverter.html">GregorianCalendarConverter</a></td>
374 <td>java.util.Calendar<br/>java.util.GregorianCalendar</td>
375 <td class="example">
376 &lt;gregorian-calendar&gt;<br/>
377 &nbsp;&nbsp;&lt;time&gt;555454646&lt;/time&gt;<br/>
378 &lt;/gregorian-calendar&gt;
379 </td>
380 <td>&nbsp;</td>
381 <td>normal</td>
382 </tr>
383 <tr>
384 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ISO8601DateConverter.html">ISO8601DateConverter</a></td>
385 <td>java.util.Date</td>
386 <td class="example">&lt;date&gt;2006-07-28T12:06:17.654-03:00&lt;/date&gt;</td>
387 <td>Not automatically registered, can be used globally or locally. Implementation needs joda-time.</td>
388 <td>&nbsp;</td>
389 </tr>
390 <tr>
391 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.html">ISO8601GregorianCalendarConverter</a></td>
392 <td>java.util.GregorianCalendar</td>
393 <td class="example">
394 &lt;gregorian-calendar&gt;<br/>
395 2006-07-28T12:07:02.788-03:00<br/>
396 &lt;/gregorian-calendar&gt;
397 </td>
398 <td>Not automatically registered, can be used globally or locally. Implementation needs joda-time.</td>
399 <td>&nbsp;</td>
400 </tr>
401 <tr>
402 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/LocaleConverter.html">LocaleConverter</a></td>
403 <td>java.util.Locale</td>
404 <td class="example">&lt;locale&gt;en_GB&lt;/locale&gt;</td>
405 <td>&nbsp;</td>
406 <td>normal</td>
407 </tr>
408 <tr>
409 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/CurrencyConverter.html">CurrencyConverter</a></td>
410 <td>java.util.Currency</td>
411 <td class="example">&lt;currency&gt;USD&lt;/currency&gt;</td>
412 <td>Available under Java 1.4 or greater.</td>
413 <td>normal</td>
414 </tr>
415 <tr>
416 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/UUIDConverter.html">UUIDConverter</a></td>
417 <td>java.util.UUID</td>
418 <td class="example">&lt;uuid&gt;ca05f023-e07f-4956-a6ef-14ddd23df47b&lt;/uuid&gt;</td>
419 <td>Available under Java 1.5 or greater.</td>
420 <td>normal</td>
421 </tr>
422 <tr>
423 <td><a href="javadoc/com/thoughtworks/xstream/converters/enums/EnumMapConverter.html">EnumMapConverter</a></td>
424 <td>java.util.EnumMap</td>
425 <td class="example">
426 &lt;enum-map enum-type="simple"&gt;<br/>
427 &nbsp;&nbsp;&lt;entry&gt;<br/>
428 &nbsp;&nbsp;&nbsp;&nbsp;&lt;simple&gt;GREEN&lt;/simple&gt;<br/>
429 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;grass&lt;/string&gt;<br/>
430 &nbsp;&nbsp;&lt;/entry&gt;<br/>
431 &nbsp;&nbsp;&lt;entry&gt;<br/>
432 &nbsp;&nbsp;&nbsp;&nbsp;&lt;simple&gt;BLUE&lt;/simple&gt;<br/>
433 &nbsp;&nbsp;&nbsp;&nbsp;&lt;string&gt;sky&lt;/string&gt;<br/>
434 &nbsp;&nbsp;&lt;/entry&gt;<br/>
435 &lt;/enum-map&gt;</td>
436 <td>Available under Java 1.5 or greater.</td>
437 <td>normal</td>
438 </tr>
439 <tr>
440 <td><a href="javadoc/com/thoughtworks/xstream/converters/enums/EnumSetConverter.html">EnumSetConverter</a></td>
441 <td>java.util.EnumSet</td>
442 <td class="example">
443 &lt;enum-set enum-type=&quot;simple&quot;&gt;<br/>
444 &nbsp;&nbsp;GREEN,BLUE<br/>
445 &lt;/enum-set&gt;</td>
446 <td>Available under Java 1.5 or greater.</td>
447 <td>normal</td>
448 </tr>
449 <tr>
450 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/RegexPatternConverter.html">RegexPatternConverter</a></td>
451 <td>java.util.regex.Pattern</td>
452 <td class="example">
453 &lt;java.util.regex.Pattern&gt;<br/>
454 &nbsp;&nbsp;&lt;pattern&gt;.*&lt;/pattern&gt;<br/>
455 &nbsp;&nbsp;&lt;flags&gt;0&lt;/flags&gt;<br/>
456 &lt;/java.util.regex.Pattern&gt;
457 </td>
458 <td>Available under Java 1.4 or greater.</td>
459 <td>normal</td>
460 </tr>
461
462 <!-- .................................................................................................. -->
463 <tr>
464 <td colspan="5" class="headerRow"><h1 id="java.sql">java.sql</h1></td>
465 </tr>
466 <tr>
467 <th>Converter</th>
468 <th>Supported types</th>
469 <th>Example</th>
470 <th>Notes</th>
471 <th>Prio</th>
472 </tr>
473 <tr>
474 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/SqlDateConverter.html">SqlDateConverter</a></td>
475 <td>java.sql.Date</td>
476 <td class="example">&lt;sql-date&gt;1978-08-25&lt;/sql-date&gt;</td>
477 <td>Only automatically registered if runtime has JDBC support.</td>
478 <td>normal</td>
479 </tr>
480 <tr>
481 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/SqlTimeConverter.html">SqlTimeConverter</a></td>
482 <td>java.sql.Time</td>
483 <td class="example">&lt;sql-time&gt;14:07:33&lt;/sql-time&gt;</td>
484 <td>Only automatically registered if runtime has JDBC support.</td>
485 <td>normal</td>
486 </tr>
487 <tr>
488 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/SqlTimestampConverter.html">SqlTimestampConverter</a></td>
489 <td>java.sql.Timestamp</td>
490 <td class="example">&lt;sql-timestamp&gt;1970-01-01 00:00:01.234&lt;/sql-timestamp&gt;</td>
491 <td>Only automatically registered if runtime has JDBC support.</td>
492 <td>normal</td>
493 </tr>
494 <tr>
495 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ISO8601SqlTimestampConverter.html">ISO8601SqlTimestampConverter</a></td>
496 <td>java.sql.Timestamp</td>
497 <td class="example">&lt;sql-timestamp&gt;2006-07-28T12:06:17.654000000-03:00&lt;/sql-timestamp&gt;</td>
498 <td>Not automatically registered, can be used globally or locally. Implementation needs joda-time.</td>
499 <td>&nbsp;</td>
500 </tr>
501
502 <!-- .................................................................................................. -->
503 <tr>
504 <td colspan="5" class="headerRow"><h1 id="java.math">java.math</h1></td>
505 </tr>
506 <tr>
507 <th>Converter</th>
508 <th>Supported types</th>
509 <th>Example</th>
510 <th>Notes</th>
511 <th>Prio</th>
512 </tr>
513 <tr>
514 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/BigDecimalConverter.html">BigDecimalConverter</a></td>
515 <td>java.math.BigDecimal</td>
516 <td class="example">&lt;big-decimal&gt;342346.445332&lt;/big-decimal&gt;</td>
517 <td>&nbsp;</td>
518 <td>normal</td>
519 </tr>
520 <tr>
521 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/BigIntegerConverter.html">BigIntegerConverter</a></td>
522 <td>java.math.BigInteger</td>
523 <td class="example">&lt;big-int&gt;23434224556&lt;/big-int&gt;</td>
524 <td>&nbsp;</td>
525 <td>normal</td>
526 </tr>
527
528 <!-- .................................................................................................. -->
529 <tr>
530 <td colspan="5" class="headerRow"><h1 id="java.net">java.net</h1></td>
531 </tr>
532 <tr>
533 <th>Converter</th>
534 <th>Supported types</th>
535 <th>Example</th>
536 <th>Notes</th>
537 <th>Prio</th>
538 </tr>
539 <tr>
540 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/URIConverter.html">URIConverter</a></td>
541 <td>java.net.URI</td>
542 <td class="example">&lt;uri&gt;mailto:xstream-user.codehaus.org&lt;/uri&gt;</td>
543 <td>&nbsp;</td>
544 <td>normal</td>
545 </tr>
546 <tr>
547 <td><a href="javadoc/com/thoughtworks/xstream/converters/basic/URLConverter.html">URLConverter</a></td>
548 <td>java.net.URL</td>
549 <td class="example">&lt;url&gt;http://codehaus.org/blah&lt;/url&gt;</td>
550 <td>&nbsp;</td>
551 <td>normal</td>
552 </tr>
553
554 <!-- .................................................................................................. -->
555 <tr>
556 <td colspan="5" class="headerRow"><h1 id="java.io">java.io</h1></td>
557 </tr>
558 <tr>
559 <th>Converter</th>
560 <th>Supported types</th>
561 <th>Example</th>
562 <th>Notes</th>
563 <th>Prio</th>
564 </tr>
565 <tr>
566 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/FileConverter.html">FileConverter</a></td>
567 <td>java.io.File</td>
568 <td class="example">&lt;file&gt;/stuff/hello.txt&lt;/file&gt;</td>
569 <td>&nbsp;</td>
570 <td>normal</td>
571 </tr>
572 <tr>
573 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/SerializableConverter.html">SerializableConverter</a></td>
574 <td>java.io.Serializable</td>
575 <td>&nbsp;</td>
576 <td>See description at Generalized Converters.</td>
577 <td>low</td>
578 </tr>
579 <tr>
580 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/ExternalizableConverter.html">ExternalizableConverter</a></td>
581 <td>java.io.Externalizable</td>
582 <td class="example">
583 &lt;<i>externalizable-type</i>&gt;<br/>
584 &nbsp;&nbsp;&lt;string&gt;apple&lt;/string&gt;<br/>
585 &nbsp;&nbsp;&lt;int&gt;42&lt;/int&gt;<br/>
586 &nbsp;&nbsp;&lt;big-decimal&gt;12345.4555&lt;/big-decimal&gt;<br/>
587 &lt;/<i>externalizable-type</i>&gt;
588 </td>
589 <td>See description at Generalized Converters.</td>
590 <td>low</td>
591 </tr>
592
593 <!-- .................................................................................................. -->
594 <tr>
595 <td colspan="5" class="headerRow"><h1 id="java.nio">java.nio</h1></td>
596 </tr>
597 <tr>
598 <th>Converter</th>
599 <th>Supported types</th>
600 <th>Example</th>
601 <th>Notes</th>
602 <th>Prio</th>
603 </tr>
604 <tr>
605 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/CharsetConverter.html">CharsetConverter</a></td>
606 <td>java.nio.charset.Charset</td>
607 <td class="example">&lt;charset&gt;US-ASCII&lt;/charset&gt;</td>
608 <td>Available under Java 1.4 or greater.</td>
609 <td>normal</td>
610 </tr>
611
612 <!-- .................................................................................................. -->
613 <tr>
614 <td colspan="5" class="headerRow"><h1 id="java.lang.reflect">java.lang.reflect</h1></td>
615 </tr>
616 <tr>
617 <th>Converter</th>
618 <th>Supported types</th>
619 <th>Example</th>
620 <th>Notes</th>
621 <th>Prio</th>
622 </tr>
623 <tr>
624 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/JavaClassConverter.html">JavaClassConverter</a></td>
625 <td>java.lang.Class</td>
626 <td class="example">&lt;class&gt;com.foo.MyThing&lt;/class&gt;</td>
627 <td>This converter uses the ClassLoaderReference of the XStream insatance. Can be regisreted with
628 Mapper globally or locally to respect type aliases.</td>
629 <td>normal</td>
630 </tr>
631 <tr>
632 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/JavaFieldConverter.html">JavaFieldConverter</a></td>
633 <td>java.lang.reflect.Field</td>
634 <td class="example">
635 &lt;field&gt;<br/>
636 &nbsp;&nbsp;&lt;name&gt;myField&lt;/name&gt;<br/>
637 &nbsp;&nbsp;&lt;class&gt;com.foo.MyThing&lt;/class&gt;<br/>
638 &lt;/field&gt;
639 </td>
640 <td>This converter uses the ClassLoaderReference of the XStream insatance. Can be regisreted with
641 Mapper globally or locally to respect type aliases.</td>
642 <td>normal</td>
643 </tr>
644 <tr>
645 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/JavaMethodConverter.html">JavaMethodConverter</a></td>
646 <td>java.lang.reflect.Method<br/>java.lang.reflect.Constructor</td>
647 <td class="example">
648 &lt;method&gt;<br/>
649 &nbsp;&nbsp;&lt;class&gt;com.foo.MyThing&lt;/class&gt;<br/>
650 &nbsp;&nbsp;&lt;name&gt;doStuff&lt;/name&gt;<br/>
651 &nbsp;&nbsp;&lt;parameter-types&gt;<br/>
652 &nbsp;&nbsp;&nbsp;&nbsp;&lt;class&gt;java.lang.String&lt;/class&gt;<br/>
653 &nbsp;&nbsp;&nbsp;&nbsp;&lt;class&gt;java.util.Iterator&lt;/class&gt;<br/>
654 &nbsp;&nbsp;&lt;/parameter-types&gt;<br/>
655 &lt;/method&gt;
656 </td>
657 <td>The enclosing element for this tag will either by &lt;method&gt; or &lt;constructor&gt;. This converter uses the ClassLoaderReference of the XStream insatance. Can be regisreted with
658 Mapper globally or locally to respect type aliases.</td>
659 <td>normal</td>
660 </tr>
661 <tr>
662 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/DynamicProxyConverter.html">DynamicProxyConverter</a></td>
663 <td>Any dynamic proxy generated by java.lang.reflect.Proxy</td>
664 <td class="example">
665 &lt;dynamic-proxy&gt;<br/>
666 &nbsp;&nbsp;&lt;interface&gt;com.foo.Blah&lt;/interface&gt;<br/>
667 &nbsp;&nbsp;&lt;interface&gt;com.foo.Woo&lt;/interface&gt;<br/>
668 &nbsp;&nbsp;&lt;handler class=&quot;com.foo.MyHandler&quot;&gt;<br/>
669 &nbsp;&nbsp;&nbsp;&nbsp;&lt;something&gt;blah&lt;/something&gt;<br/>
670 &nbsp;&nbsp;&lt;/handler&gt;<br/>
671 &lt;/dynamic-proxy&gt;
672 </td>
673 <td>The dynamic proxy itself is not serialized, however the interfaces it implements and the actual InvocationHandler
674 instance are serialized. This allows the proxy to be reconstructed after deserialization.</td>
675 <td>normal</td>
676 </tr>
677
678 <!-- .................................................................................................. -->
679 <tr>
680 <td colspan="5" class="headerRow"><h1 id="java.awt">java.awt</h1></td>
681 </tr>
682 <tr>
683 <th>Converter</th>
684 <th>Supported types</th>
685 <th>Example</th>
686 <th>Notes</th>
687 <th>Prio</th>
688 </tr>
689 <tr>
690 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ColorConverter.html">ColorConverter</a></td>
691 <td>java.awt.Color</td>
692 <td class="example">
693 &lt;awt-color&gt;<br/>
694 &nbsp;&nbsp;&lt;red&gt;255&lt;/red&gt;<br/>
695 &nbsp;&nbsp;&lt;green&gt;255&lt;/green&gt;<br/>
696 &nbsp;&nbsp;&lt;blue&gt;255&lt;/blue&gt;<br/>
697 &nbsp;&nbsp;&lt;alpha&gt;255&lt;/alpha&gt;<br/>
698 &lt;/awt-color&gt;
699 </td>
700 <td>Only automatically registered if runtime has AWT support.<br/>
701 <b>Warning:</b> The AWT toolkit is definitely initialized when a Color is deserialized.</td>
702 <td>normal</td>
703 </tr>
704 <tr>
705 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/FontConverter.html">FontConverter</a></td>
706 <td>java.awt.Font<br/>
707 javax.swing.plaf.FontUIResource</td>
708 <td class="example">
709 &lt;awt-font&gt;<br/>
710 &nbsp;&nbsp;&lt;family class=&quot;string&quot;&gt;Arial&lt;/family&gt;<br/>
711 &nbsp;&nbsp;&lt;size class=&quot;float&quot;&gt;20.0&lt;/size&gt;<br/>
712 &nbsp;&nbsp;&lt;width class=&quot;null&quot;/&gt;<br/>
713 &nbsp;&nbsp;&lt;posture class=&quot;null&quot;/&gt;<br/>
714 &nbsp;&nbsp;&lt;weight class=&quot;float&quot;&gt;2.0&lt;/weight&gt;<br/>
715 &nbsp;&nbsp;&lt;superscript class=&quot;null&quot;/&gt;<br/>
716 &lt;/awt-font&gt;
717 </td>
718 <td>Only automatically registered if runtime has AWT support.<br/>
719 <b>Warning:</b> The AWT toolkit is definitely initialized when a Font is deserialized.</td>
720 <td>normal</td>
721 </tr>
722
723 <!-- .................................................................................................. -->
724 <tr>
725 <td colspan="5" class="headerRow"><h1 id="java.awt.font">java.awt.font</h1></td>
726 </tr>
727 <tr>
728 <th>Converter</th>
729 <th>Supported types</th>
730 <th>Example</th>
731 <th>Notes</th>
732 <th>Prio</th>
733 </tr>
734 <tr>
735 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/TextAttributeConverter.html">TextAttributeConverter</a></td>
736 <td>java.awt.font.TextAttribute</td>
737 <td class="example">
738 &lt;awt-text-attribute&gt;family&lt;/awt-text-attribute&gt;
739 </td>
740 <td>Only automatically registered if runtime has AWT support.<br/>
741 <b>Warning:</b> The AWT toolkit is definitely initialized when a TextAttribute is deserialized.</td>
742 <td>normal</td>
743 </tr>
744
745 <!-- .................................................................................................. -->
746 <tr>
747 <td colspan="5" class="headerRow"><h1 id="javax.swing">javax.swing</h1></td>
748 </tr>
749 <tr>
750 <th>Converter</th>
751 <th>Supported types</th>
752 <th>Example</th>
753 <th>Notes</th>
754 <th>Prio</th>
755 </tr>
756 <tr>
757 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/LookAndFeelConverter.html">LookAndFeelConverter</a></td>
758 <td>javax.swing.LookAndFeel implementations</td>
759 <td class="example">&nbsp;</td>
760 <td>Only automatically registered if runtime has Swing support.</td>
761 <td>normal</td>
762 </tr>
763
764 <!-- .................................................................................................. -->
765 <tr>
766 <td colspan="5" class="headerRow"><h1 id="javax.security.auth">javax.security.auth</h1></td>
767 </tr>
768 <tr>
769 <th>Converter</th>
770 <th>Supported types</th>
771 <th>Example</th>
772 <th>Notes</th>
773 <th>Prio</th>
774 </tr>
775 <tr>
776 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/SubjectConverter.html">SubjectConverter</a></td>
777 <td>javax.security.auth.Subject</td>
778 <td class="example">
779 &lt;auth-subject&gt;<br/>
780 &nbsp;&nbsp;&lt;principals&gt;<br/>
781 &nbsp;&nbsp;&nbsp;&nbsp;&lt;com.thoughtworks.xstream.Admin/&gt;<br/>
782 &nbsp;&nbsp;&lt;/principals&gt;<br/>
783 &nbsp;&nbsp;&lt;readOnly&gt;false&lt;/readOnly&gt;<br/>
784 &lt;/auth-subject&gt;<br/>
785 </td>
786 <td>Available under Java 1.4 or greater. This converter does not serialize any credentials but only the principals.</td>
787 <td>normal</td>
788 </tr>
789
790 <!-- .................................................................................................. -->
791 <tr>
792 <td colspan="5" class="headerRow"><h1 id="javax.xml.datatype">javax.xml.datatype</h1></td>
793 </tr>
794 <tr>
795 <th>Converter</th>
796 <th>Supported types</th>
797 <th>Example</th>
798 <th>Notes</th>
799 <th>Prio</th>
800 </tr>
801 <tr>
802 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/DurationConverter.html">DurationConverter</a></td>
803 <td>javax.xml.datatype.Duration</td>
804 <td class="example">&lt;duration&gt;PT1H2M&lt;/duration&gt;</td>
805 <td>Available under Java 1.5 or greater.</td>
806 <td>normal</td>
807 </tr>
808
809 <!-- .................................................................................................. -->
810 <tr>
811 <td colspan="5" class="headerRow"><h1 id="generic">Generalized Converters</h1></td>
812 </tr>
813 <tr>
814 <th>Converter</th>
815 <th>Supported types</th>
816 <th>Explanation</th>
817 <th>Notes</th>
818 <th>Prio</th>
819 </tr>
820 <tr>
821 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/ReflectionConverter.html">ReflectionConverter</a></td>
822 <td>Any type</td>
823 <td>The Converter is used as fallback. It uses reflection to examine the class and will serialize its fields.</td>
824 <td>&nbsp;</td>
825 <td>very low</td>
826 </tr>
827 <tr>
828 <td><a href="javadoc/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.html">AnnotationReflectionConverter</a></td>
829 <td>Any type</td>
830 <td>The Converter is used as fallback. It uses reflection to examine the class and will serialize its fields and supports annotations for
831 local converters.</td>
832 <td>Needs JDK 1.5, default for JDK 1.5. Deprecated since XStream 1.3 and must be registered now explicitly.</td>
833 <td>&nbsp;</td>
834 </tr>
835 <tr>
836 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/SerializableConverter.html">SerializableConverter</a></td>
837 <td>java.io.Serializable or types with one of the serializable methods readObject or writeObject</td>
838 <td>The Converter is used for any JDK-serializable types, if not handled by a specialized Converter.</td>
839 <td>&nbsp;</td>
840 <td>low</td>
841 </tr>
842 <tr>
843 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/ExternalizableConverter.html">ExternalizableConverter</a></td>
844 <td>java.io.Externalizable</td>
845 <td>The Converter is used for any JDK-externalizable types, if not handled by a specialized Converter.</td>
846 <td>&nbsp;</td>
847 <td>low</td>
848 </tr>
849 <tr>
850 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/LambdaConverter.html">LambdaConverter</a></td>
851 <td>For serializable and non-serializable lambda types. Noon-serialzable lambda instances will be mapped to null, since they
852 contain no information for recreation. Serializable lambda types have such info, but it is specific to compiler vendor and
853 occurrence in the code. Never assume that you can deserialize such an element when you use a different version of your code
854 or a different compiler.</td>
855 <td>&nbsp;</td>
856 <td>Only automatically registered for Java 8.</td>
857 <td>normal</td>
858 </tr>
859 <tr>
860 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.html">ToAttributedValueConverter</a></td>
861 <td>Any type with all fields to be represented by a single string but one.</td>
862 <td>The Converter is used to write all but one fields of the type as attributes. The left over field is then used as current value.</td>
863 <td>Must be registered globally or locally for the appropriate type.</td>
864 <td>&nbsp;</td>
865 </tr>
866 <tr>
867 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/ToStringConverter.html">ToStringConverter</a></td>
868 <td>Any type with natural String representation</td>
869 <td>The Converter must be initialized with a type, that provides a complete String representation with its toString() method
870 and is able to be recreated by a constructor taking a single String argument.</td>
871 <td>Must be registered globally or locally for the appropriate type.</td>
872 <td>&nbsp;</td>
873 </tr>
874 <tr>
875 <td><a href="javadoc/com/thoughtworks/xstream/converters/javabean/JavaBeanConverter.html">JavaBeanConverter</a></td>
876 <td>Java beans</td>
877 <td>The Converter handles any type as Java bean. It expects the type to convert to have a public default constructor and
878 appropriate getter and setters.</td>
879 <td>Must be registered globally or locally. Can be used as fallback with priority <b>very low</b>.</td>
880 <td>&nbsp;</td>
881 </tr>
882 <tr>
883 <td><a href="javadoc/com/thoughtworks/xstream/converters/extended/PropertyEditorCapableConverter.html">PropertyEditorCapableConverter</a></td>
884 <td>Any type with a PropertyEditor implementation</td>
885 <td>The Converter can handles any type that provides a PropertyEditor implementation. The PropertyEditor's methods getAsText() and
886 setAsText() are used to convert between object and string representation.</td>
887 <td>Must be registered globally or locally for the appropriate type.</td>
888 <td>&nbsp;</td>
889 </tr>
890
891 <!-- .................................................................................................. -->
892 <tr>
893 <td colspan="5" class="headerRow"><h1 id="3rdParty">Converters for 3rd party classes</h1></td>
894 </tr>
895 <tr>
896 <th>Converter</th>
897 <th>Supported types</th>
898 <th>Explanation</th>
899 <th>Notes</th>
900 <th>Add-On</th>
901 </tr>
902 <tr>
903 <td><a href="javadoc/com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter.html">CGLIBEnhancedConverter</a></td>
904 <td>Proxies generated by the CGLIB Enhancer</td>
905 <td>The Converter handles proxies generated by the CGLIB Enhancer, if there were not multiple callbacks registered.
906 A proxy with multiple callbacks can currently not be handled at all.</td>
907 <td>Must be registered globally and in combination with the CGLIBMapper. See <a href="faq.html#Serialization_CGLIB">FAQ</a>.</td>
908 <td>xstream</td>
909 </tr>
910 <tr>
911 <td><a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentCollectionConverter.html">HibernatePersistentCollectionConverter</a></td>
912 <td>org.hibernate.collection.internal.PersistentBag<br/>
913 org.hibernate.collection.internal.PersistentList<br/>
914 org.hibernate.collection.internal.PersistentSet<br/>
915 org.hibernate.envers.entities.mapper.relation.lazy.proxy.ListProxy<br/>
916 org.hibernate.envers.entities.mapper.relation.lazy.proxy.SetProxy</td>
917 <td>The Converter handles Hibernate 4 (or 3) standard collections and Envers proxies. It will handle any element of the collection.</td>
918 <td>Must be registered explicitly in combination with the HibernateMapper and all the other Hibernate converters. See <a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/package-summary.html">package description</a>.</td>
919 <td>xstream-hibernate</td>
920 </tr>
921 <tr>
922 <td><a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentMapConverter.html">HibernatePersistentMapConverter</a></td>
923 <td>org.hibernate.collection.internal.PersistentMap<br/>
924 org.hibernate.envers.entities.mapper.relation.lazy.proxy.MapProxy</td>
925 <td>The Converter handles unsorted Hibernate 4 (or 3) maps or Envers proxy. It will handle any key and value of the map.</td>
926 <td>Must be registered explicitly in combination with the HibernateMapper and all the other Hibernate converters. See <a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/package-summary.html">package description</a>.</td>
927 <td>xstream-hibernate</td>
928 </tr>
929 <tr>
930 <td><a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedMapConverter.html">HibernatePersistentSortedMapConverter</a></td>
931 <td>org.hibernate.collection.internal.PersistentSortedMap<br/>
932 org.hibernate.envers.entities.mapper.relation.lazy.proxy.SortedMapProxy</td>
933 <td>The Converter handles sorted Hibernate 4 (or 3) maps or Envers proxy. It will handle any key and value of the map.</td>
934 <td>Must be registered explicitly in combination with the HibernateMapper and all the other Hibernate converters. See <a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/package-summary.html">package description</a>.</td>
935 <td>xstream-hibernate</td>
936 </tr>
937 <tr>
938 <td><a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/converter/HibernatePersistentSortedSetConverter.html">HibernatePersistentSortedSetConverter</a></td>
939 <td>org.hibernate.collection.intrernal.PersistentSortedSet<br/>
940 org.hibernate.envers.entities.mapper.relation.lazy.proxy.SortedSetProxy</td>
941 <td>The Converter handles sorted Hibernate 4 (or 3) sets or Envers proxy. It will handle any element of the set.</td>
942 <td>Must be registered explicitly in combination with the HibernateMapper and all the other Hibernate converters. See <a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/package-summary.html">package description</a>.</td>
943 <td>xstream-hibernate</td>
944 </tr>
945 <tr>
946 <td><a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/converter/HibernateProxyConverter.html">HibernateProxyConverter</a></td>
947 <td>org.hibernate.proxy.HibernateProxy</td>
948 <td>The Converter handle any element that is wrapped by a Hibernate proxy.</td>
949 <td>Must be registered explicitly in combination with the HibernateMapper and all the other Hibernate converters. See <a href="hibernate-javadoc/com/thoughtworks/xstream/hibernate/package-summary.html">package description</a>.</td>
950 <td>xstream-hibernate</td>
951 </tr>
952
953 </table>
954
955 </body>
956 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Download</title>
14 </head>
15
16 <body>
17
18 <p><a href="versioning.html">About XStream version numbers...</a></p>
19
20 <h1 id="stable">Stable Version: <span class="version">1.4.8</span></h1>
21
22 <ul>
23 <li><b><a href="https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-distribution/1.4.8/xstream-distribution-1.4.8-bin.zip">Binary distribution:</a></b>
24 Contains the XStream jar files, the Hibernate and Benchmark modules and all the dependencies.</li>
25 <li><b><a href="https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-distribution/1.4.8/xstream-distribution-1.4.8-src.zip">Source distribution:</a></b>
26 Contains the complete XStream project as if checked out from the Subversion version tag.</li>
27 <li><b><a href="https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream/1.4.8/xstream-1.4.8.jar">XStream Core only:</a>
28 The xstream.jar only as it is downloaded automatically when it is referenced as Maven dependency.</b></li>
29 <li><b><a href="https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-hibernate/1.4.8/xstream-hibernate-1.4.8.jar">XStream Hibernate module:</a></b>
30 The xstream-hibernate.jar as it is downloaded automatically when it is referenced as Maven dependency.</li>
31 <li><b><a href="https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-benchmark/1.4.8/xstream-benchmark-1.4.8.jar">XStream Benchmark module:</a></b>
32 The xstream-benchmark.jar as it is downloaded automatically when it is referenced as Maven dependency.</li>
33 </ul>
34
35 <h1 id="snapshot">Latest Snapshot HEAD revision</h1>
36
37 <p>Below are builds of the latest HEAD version of XStream from the <a href="repository.html">repository</a>.</p>
38
39 <ul>
40 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-distribution/1.5.0-SNAPSHOT/">Complete distributions</a></li>
41 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream/1.5.0-SNAPSHOT/">XStream Core only</a></li>
42 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-hibernate/1.5.0-SNAPSHOT/">XStream Hibernate module</a></li>
43 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-benchmark/1.5.0-SNAPSHOT/">XStream Benchmark module</a></li>
44 </ul>
45
46 <h1 id="snapshot-1.4.x">Latest Snapshot 1.4.x BRANCH revision</h1>
47
48 <p>Below are builds of the latest 1.4.x branch version of XStream from the <a href="repository.html">repository</a>.</p>
49
50 <ul>
51 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-distribution/1.4.9-SNAPSHOT/">Complete distributions (1.4.x)</a></li>
52 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream/1.4.9-SNAPSHOT/">XStream Core only (1.4.x)</a></li>
53 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-hibernate/1.4.9-SNAPSHOT/">XStream Hibernate module (1.4.x)</a></li>
54 <li><a href="https://nexus.codehaus.org/content/groups/public/com/thoughtworks/xstream/xstream-benchmark/1.4.9-SNAPSHOT/">XStream Benchmark module (1.4.x)</a></li>
55 </ul>
56
57 <h1 id="previous-releases">Previous Releases</h1>
58
59 <p>Previous releases of XStream are also available. However, use of the latest stable version is recommended.</p>
60
61 <ul>
62 <li><a href="http://repo.maven.apache.org/maven2/com/thoughtworks/xstream/xstream/">Previous releases (&gt;= 1.2)</a></li>
63 <li><a href="http://repo.maven.apache.org/maven2/xstream/xstream/">Previous releases (&lt;= 1.2)</a></li>
64 </ul>
65
66 <h1 id="optional-deps">Optional Dependencies</h1>
67
68 <ul>
69 <li>Supported XML parsers and packages:
70 <ul>
71 <li><a href="http://repo.maven.apache.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar">XmlPull</a>, the <a href="http://www.xmlpull.org/">XML pull parser API</a> and factory to detect available implementations.</li>
72 <li><a href="http://www.extreme.indiana.edu/dist/java-repository/xpp3/jars/xpp3_min-1.1.4c.jar">Xpp3</a>, an XML pull parser (recommended).</li>
73 <li><a href="http://downloads.sourceforge.net/kxml/kxml2-2.3.0.jar">kXML2</a> or <a href="http://downloads.sourceforge.net/kxml/kxml2-min-2.3.0.jar">kXML2-min</a>, an XML pull parser.</li>
74 <li><a href="http://downloads.sourceforge.net/dom4j/dom4j-1.6.1.zip">DOM4J</a>, easy XML representation and manipulation framework.</li>
75 <li><a href="http://www.jdom.org/dist/binary/archive/jdom-1.1.3.zip">JDOM</a>, easy XML representation and manipulation (requires Java 1.2, superseded by JDOM2).</li>
76 <li><a href="http://www.jdom.org/dist/binary/jdom2-2.0.5.zip">JDOM2</a>, easy XML representation and manipulation, successor of JDOM (requires Java 5).</li>
77 <li>StaX, the <a href="http://dist.codehaus.org/stax/jars/stax-1.2.0.jar">reference implementation</a> of the <a href="http://dist.codehaus.org/stax/jars/stax-api-1.0.1.jar">Streaming API for XML</a>.</li>
78 <li><a href="http://woodstox.codehaus.org/3.2.7/wstx-asl-3.2.7.jar">Woodstox</a>, an alternate open source StaX implementation.</li>
79 <li><a href="http://www.cafeconleche.org/XOM/xom-1.1.jar">XOM</a>, another alternative XML API.</li>
80 </ul>
81 </li>
82 <li>Other optional 3rd party dependencies:
83 <ul>
84 <li><a href="http://downloads.sourceforge.net/joda-time/joda-time-1.6.zip">Joda Time</a> for optional ISO8601 date/time formats.</li>
85 <li><a href="http://downloads.sourceforge.net/cglib/cglib-nodep-2.2.jar">CGLIB</a> for optional support of some proxies generated with the CGLIB Enhancer.</li>
86 <li><a href="http://repository.codehaus.org/org/codehaus/jettison/jettison/1.2/jettison-1.2.jar">Jettison</a> for serialization and deserialization support with JSON. Note, that newer versions 1.3.x are no longer compatible with XStream.</li>
87 <li><a href="http://repository.codehaus.org/org/codehaus/jettison/jettison/1.0.1/jettison-1.0.1.jar">Jettison 1.0.1</a> for serialization and deserialization support with JSON in JDK 1.4. Note, that newer version 1.1 is not compatible with XStream.</li>
88 </ul>
89 </li>
90 </ul>
91
92 <h1 id="hibernate">Dependencies Hibernate Module</h1>
93
94 <ul>
95 <li>Supported Hibernate versions:
96 <ul>
97 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/4.2.5.Final/hibernate-core-4.2.5.Final.jar">Hibernate Core 4.2.5</a>, for Java 6 or higher.</li>
98 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/3.6.6.Final/hibernate-core-3.6.6.Final.jar">Hibernate Core 3.6.6</a>, for Java 5.</li>
99 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar">Hibernate Core 3.3.2</a>, for Java 1.4.</li>
100 </ul>
101 </li>
102 <li>Supported Hibernate Envers versions:
103 <ul>
104 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-envers/4.2.5.Final/hibernate-envers-4.2.5.Final.jar">Hibernate Envers 4.2.5</a>, for Java 6 or higher.</li>
105 <li><a href="http://repo.maven.apache.org/maven2/org/hibernate/hibernate-envers/3.6.6.Final/hibernate-envers-3.6.6.Final.jar">Hibernate Envers 3.6.6</a>, for Java 5.</li>
106 </ul>
107 </li>
108 </ul>
109
110 </body>
111 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Frequently Asked Questions</title>
14 </head>
15
16 <body>
17
18 <ol>
19 <li><a href="#Compatibility">Compatibility</a></li>
20 <li><a href="#Serialization">Serialization</a></li>
21 <li><a href="#XML">XML specifics</a></li>
22 <li><a href="#JSON">JSON specifics</a></li>
23 <li><a href="#Security">Security aspects</a></li>
24 <li><a href="#Other_Products">Comparison to other products</a></li>
25 <li><a href="#Scalability">Scalability</a></li>
26 <li><a href="#Uses">Uses of XStream</a></li>
27 </ol>
28
29 <!-- ****************************************************** -->
30 <h1 id="Compatibility">Compatibility</h1>
31
32 <!-- ...................................................... -->
33 <h2 id="Compatibility_JDK">Which JDK is required to use XStream?</h2>
34 <p>1.4 or later.</p>
35
36 <!-- ...................................................... -->
37 <h2 id="Compatibility_Dependencies">Which dependencies are required to run XStream?</h2>
38 <p>All dependencies are optional, XStream uses since version 1.4.1 by default xpp3:xpp3_min and xmlpull:xmlpull.
39 However it depends on the use case. XStream will run without dependencies using the DOM driver on all Java runtimes
40 or the StAX driver in combination with Java 6 or greater. See the list of <a
41 href="download.html#optional-deps">optional dependencies</a>.</p>
42
43 <!-- ...................................................... -->
44 <h2 id="Compatibility_JVMs">Does XStream behave differently across different JVMs?</h2>
45
46 <p>XStream has two modes of operation: <b>Pure Java</b> and <b>Enhanced</b>. In pure Java mode,
47 XStream behaves in the same way across different JVMs, however its features are limited to what
48 reflection allows, meaning it cannot serialize certain classes or fields. In <b>enhanced</b> mode,
49 XStream does not have these limitations, however this mode of operation is not available to all JVMs.</p>
50
51 <!-- ...................................................... -->
52 <h2 id="Compatibility_enhanced_mode_jvm">Which JVMs allow XStream to operate in enhanced mode?</h2>
53
54 <p>XStream will check since version 1.4.5 a working enhanced mode dynamically if it is available based on
55 undocumented internal Java runtime classes. This enhanced mode is known to be working on the Oracle/Sun, Apple, HP,
56 IBM and Blackdown 1.4 JVMs and onwards, for IcedTea 6 and onwards, for Hitachi, SAP and Diablo from 1.5 and
57 onwards, for BEA JRockit starting with R25.1.0. Generally it works for all modern Java runtimes based on OpenJDK.
58 Android basically supports the enhanced mode as well as the Google ApplicationEngine, but the latter's security
59 model limits the types that can be handled. Note, that an active SecurityManager might prevent the usage of the
60 enhanced mode also.</p>
61
62 <!-- ...................................................... -->
63 <h2 id="Compatibility_enhanced_mode_advantage">What are the advantages of using enhanced mode over pure Java mode?</h2>
64
65 <p>Currently it is not possible to recreate every instance of a type using the official Java API only. The enhanced mode uses some undocumented, but wide-spread
66 available functionality to recreate such instances nevertheless. However, in a secured secured environment, older Java run times or a limited Java environment might
67 prevent the usage of the enhanced mode and XStream uses the plain Java API as fallback. This mode has some restrictions though:</p>
68
69 <table summary="Comparison of pure Java and enhanced mode">
70 <tr><th>Feature</th><th>Pure Java</th><th>Enhanced Mode</th></tr>
71 <tr><td>Public classes</td><td>Yes</td><td>Yes</td></tr>
72 <tr><td>Non public classes</td><td>No</td><td>Yes</td></tr>
73 <tr><td>Static inner classes</td><td>Yes</td><td>Yes</td></tr>
74 <tr><td>Non-static inner classes</td><td>No</td><td>Yes</td></tr>
75 <tr><td>Anonymous inner classes</td><td>No</td><td>Yes</td></tr>
76 <tr><td>With default constructor</td><td>Yes</td><td>Yes</td></tr>
77 <tr><td>Without default constructor</td><td>No</td><td>Yes</td></tr>
78 <tr><td>Private fields</td><td>Yes</td><td>Yes</td></tr>
79 <tr><td>Final fields</td><td>Yes &gt;= JDK 1.5</td><td>Yes</td></tr>
80 </table>
81
82 <!-- ...................................................... -->
83 <h2 id="Compatibility_XPP">Why is my application not able to create a XmlPullParser with the XppDriver since XStream 1.4?</h2>
84
85 <p>The <a href="http://www.xmlpull.org/">XML Pull Parser API</a> defines an own mechanism to load the factory for
86 the available XPP implementation. XStream's XppDriver never used this lookup mechanism automatically before version
87 1.4, now it will. Therefore you will have to add a <a href="download.html#optional-deps">dependency to xmlpull</a>
88 if the XPP implementation does not deliver the classes on its own. This dependency is necessary for Xpp3 in
89 contrast to kXML2 that contains the classes. Use the Xpp3Driver or the KXml2Driver if you want to select one of the
90 directly supported XPP implementation on your own without using the XPP factory. Note, that the minimal version of
91 kXML2 does not support the XPP factory, but can be used by the KXml2Driver.</p>
92
93 <!-- ...................................................... -->
94 <h2 id="Compatibility_Android">Can I use XStream in an Android application?</h2>
95
96 <p>XStream does work in Android 1.0, but is reported to have limited capabilities. Since XStream 1.4 Android is
97 treated at least as JDK 5 platform, but it e.g. does not include the java.beans package. Therefore you cannot use
98 the JavaBeanConverter. Note, that Android provides an XML Pull Parser, therefore XStream can work without
99 additional dependencies.</p>
100
101 <!-- ...................................................... -->
102 <h2 id="Compatibility_GAE">Which limits exists for XStream in Google's Application Engine (GAE)?</h2>
103
104 <p>Starting with XStream 1.4.6 it is possible to instantiate an XStream instance in a GAE environment. Nevertheless
105 does GAE set some severe restrictions for XStream and therefore XStream will behave differently. Actually a
106 reflection-based converter cannot handle any type from the JDK itself. Nor is it possible to create an
107 ObjectInputStream or an ObjectOutputStream. It is not possible to define a field alias for any type within the JDK.
108 XStream will typically work as general rule, if you process your own objects.</p>
109
110 <!-- ...................................................... -->
111 <h2 id="Compatibility_Harmony">Why does XStream fail on Apache Harmony?</h2>
112
113 <p>Since JDK 5 it is possible according the Java specification to write into final fields using reflection. This is not yet
114 supported by Harmony and therefore the PureJavaReflectionProvider fails. We have also already investigated into
115 enhanced mode in Harmony, but the Harmony JVM crashed running the unit tests. However, Harmony has been retired,
116 we will no longer make any efforts in this direction.</p>
117
118 <!-- ...................................................... -->
119 <h2 id="Compatibility_unsupported_JVM">Are there plans to provide enhanced mode support to other JVMs?</h2>
120 <p>Yes. <a href="list-user.html">Let us know</a> which JVM you would like supported.</p>
121
122 <!-- ...................................................... -->
123 <h2 id="Compatibility_no_enhanced_mode">When should I use XStream not in enhanced mode?</h2>
124
125 <p>Running XStream in a secured environment can prevent XStream from running in enhanced mode. This is
126 especially true when running XStream in an applet. You may also try to use the JavaBeanConverter as alternative to
127 the ReflectionConverter running in enhanced or pure Java mode.</p>
128
129 <!-- ...................................................... -->
130 <h2 id="Compatibility_SecurityManager">Which permissions does XStream need when running with an active SecurityManager?</h2>
131
132 <p>This depends on the mode XStream is running in. Refer to the
133 <a href="http://svn.xstream.codehaus.org/browse/xstream/trunk/xstream/src/test/com/thoughtworks/acceptance/SecurityManagerTest.java">SecurityManagerTest</a>
134 for details. Actually XStream's converters try to check since version 1.4.6 any critical operation, before they
135 claim to be able to handle a type. As consequence XStream can behave differently running under a SecurityManager.
136 E.g. if the SecurityManager does not permit to create an instance for a derived class of ObjectOutputStream, the
137 SerializationConverter will not handle any type and the ReflecitonConverter will take over (as long it has proper
138 rights for its own reflection-based operations).</p>
139
140 <!-- ...................................................... -->
141 <h2 id="Compatibility_XStream11">Why does XStream 1.2 no longer read XML generated with XStream 1.1.x?</h2>
142
143 <p>The architecture in XStream has slightly changed. Starting with XStream 1.2 the
144 <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamDriver.html">HierarchicalStreamDriver</a>
145 implementation is responsible to ensure that XML tags and attributes are valid names in XML, in XStream 1.1.x
146 this responsibility was part of the ClassMapper implementations. Under some rare circumstances this will result in
147 an unreadable XML due to the different processing order in the workflow of such problematic tag names.</p>
148
149 <p>You can run XStream in 1.1 compatibility mode though:</p>
150
151 <div class="Source Java"><pre>XStream xstream = new XStream(new XppDriver(new XStream11XmlFriendlyReplacer())) {
152 protected boolean useXStream11XmlFriendlyMapper() {
153 return true;
154 }
155 };</pre></div>
156
157 <!-- ...................................................... -->
158 <h2 id="Compatibility_ConverterAnnotations">XStream 1.3 ignores suddenly annotated converters (@XStreamConverter and @XStreamConverters)?</h2>
159
160 <p>XStream treats now all annotations the same and therefore it no longer auto-detects any annotation by
161 default. You can configure XStream to run in auto-detection mode, but be aware if the
162 <a href="annotations-tutorial.html#AutoDetect">implications</a>. As alternative you might register the
163 deprecated AnnotationReflectionConverter, that was used for XStream pre 1.3.x, but as drawback the functionality
164 to register a local converter with XStream.registerLocalConverter will no longer work.</p>
165
166 <!-- ...................................................... -->
167 <h2 id="Compatibility_element_sequence">XStream 1.3 suddenly has a different field order?</h2>
168
169 <p>Yes. This was announced with the last 1.2.x release and was done to support the type inheritance of XML schemas. However, XStream is delivered with the
170 <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamDriver.html">XStream12FieldKeySorter</a> that can be used to
171 <a href="#Serialization_sort_fields">sort the fields</a> according XStream 1.2.2.</p>
172
173
174 <!-- ****************************************************** -->
175 <h1 id="Serialization">Serialization</h1>
176
177 <!-- ...................................................... -->
178 <h2 id="Serialization_types">Which class types can be serialized by XStream?</h2>
179
180 <p>In contrast to the JDK XStream is not tied to a marker interface to serialize a class. XStream ships with some specialized <a href="converters.html">converters</a>,
181 but will use reflection by default for &quot;unknown&quot; classes to examine, read and write the class' data. Therefore XStream can handle quite any class, especially
182 the ones referred as POJO (Plain Old Java Object).</p>
183
184 <p>However, some types of classes exist with typical characteristics, that cannot be handled - at least not out of the box:</p>
185
186 <ol>
187 <li>Objects that are based on threads or thread local data: Thread, Timer, ThreadLocal and so on. These classes keep different data for different threads and there's
188 no possibility to recreate a thread in a generic way nor recreating thread specific data. There might be special use cases, but this will always involve a custom converter
189 where threads can be recreated in a specific way tied to that use case.</li>
190 <li>Class types that are based on generated classes. Such types have often names that are unique to the current process and will have no meaning
191 in a different process. A custom converter might help to write the appropriate data into the serializing stream to be able to recreate a equivalent class at deserialization
192 time.</li>
193 <li>Types that keep and use system resources like file handles, sockets, pipes and so on. ClassLoader, FileInputStream, FileOutputStream, Socket and so on. To
194 deserialize such a class the converter must be able to claim the appropriate resource from the system again. With the help of a custom converter this might be
195 possible, but with the reflection converter the deserialized class might refer a system resource that is no longer valid or belongs to somebody else. Behavior is
196 undefined then.</li>
197 <li>A very special case of such allocated system resources are those classes that keep handles to system memory directly, because they are partly implemented native.
198 It is known to be true for the Linux version of Sun's JDK that the BufferedImage references some system specific types of the JDK that themselves have member fields
199 with such memory handles. While it is possible at first sight to serialize and deserialize a BufferedImage, the reflection converter will also duplicate the memory handle.
200 As a result the JVM might crash easily because of freeing unallocated memory or freeing the same memory twice. It might be possible to create a custom converter,
201 but the data structure is really complex in this area and nobody has been investigating so far to such an extent. However, <strong>do not use the reflection converter
202 for these types! You have been warned!</strong></li>
203 <li>Inner class types of the JDK can often vary in implementation details between JDK versions and vendors and are therefore only compatible for the same JDK. This
204 includes collection types returned by the methods of the Collections class that wrap another one (like unmodifiableList) or the collections that are returned by the
205 different Map implementations for the keySet(), entrySet() and values() methods.</li>
206 <li><a href="#Serialization_lambda_null">Non-serializable lambda expressions</a> cannot be deserialized at all and <a href="#Serialization_lambda_fails">serializable
207 lambda</a> expression contain compiler and vendor specific information that might cause deserialization to fail.</li>
208 </ol>
209
210 <!-- ...................................................... -->
211 <h2 id="Serialization_omit_field">How do I specify that a field should not be serialized?</h2>
212 <p>Make it <code>transient</code>, specify it with <code>XStream.omitField()</code> or
213 annotate it with @XStreamOmitField</p>
214
215 <!-- ...................................................... -->
216 <h2 id="Serialization_initialize_transient">How do I initialize a transient field at deserialization?</h2>
217
218 <p>XStream uses the same mechanism as the JDK serialization. Example:</p>
219
220 <div class="Source Java"><pre>class ThreadAwareComponent {
221 private transient ThreadLocal component;
222 // ...
223 private Object readResolve() {
224 component = new ThreadLocal();
225 return this;
226 }
227 }</pre></div>
228 <p>or</p>
229 <div class="Source Java"><pre>class ThreadAwareComponent {
230 private transient ThreadLocal component;
231 // ...
232 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
233 in.defaultReadObject();
234 component = new ThreadLocal();
235 }
236 }</pre></div>
237 <p>Use the latter in class hierarchies, readResolve is not called for base classes.</p>
238
239 <!-- ...................................................... -->
240 <h2 id="Serialization_no_ctor_running">XStream is not calling the default constructor during deserialization.</h2>
241
242 <p>This is, in fact, the same case as above. XStream uses the same mechanism as the JDK serialization. When using
243 the enhanced mode with the optimized reflection API, it does not invoke the default constructor. The solution is to
244 implement the readResolve or readObject as demonstrated with the last question.</p>
245
246 <!-- ...................................................... -->
247 <h2 id="Serialization_collections">What do serialized collections look like?</h2>
248
249 <p>See example for the <a href="converters.html#java.util">CollectionConverter</a>.</p>
250 <p>Note, that it is possible to configure XStream to omit the container element <i>toys</i> using implicit collections.</p>
251
252 <!-- ...................................................... -->
253 <h2 id="Serialization_reflection_types">Why do serialized types, fields or methods do not use aliasing for the names?</h2>
254
255 <p>XStream normally has no to separate between a primitive and its boxed type. The complete reflection API works
256 always with the boxed types and converts to primitives types on the fly. However, for method and field type
257 signatures the difference is essential. Nevertheless it is possible to register derived versions of the converters
258 that are able to respect the aliasing with some minor effort. Following lines are taken from the AliasTest in the
259 acceptence tests:</p>
260 <div class="Source Java"><pre>XStream xstream = new XStream();
261 Mapper mapper = new MapperWrapper(xstream.getMapper().lookupMapperOfType(ArrayMapper.class)) {
262 public Class realClass(String elementName) {
263 Class primitiveType = Primitives.primitiveType(elementName);
264 return primitiveType != null ? primitiveType : super.realClass(elementName);
265 }
266 };
267 SingleValueConverter javaClassConverter = new JavaClassConverter(mapper) {};
268 xstream.registerConverter(javaClassConverter);
269 xstream.registerConverter(new JavaMethodConverter(javaClassConverter){});
270 xstream.registerConverter(new JavaFieldConverter(javaClassConverter, mapper){});</pre></div>
271
272 <!-- ...................................................... -->
273 <h2 id="Serialization_implicit_null">My implicit collection is suddenly null after deserialization instead of empty!</h2>
274
275 <p>By declaring a collection as implicit, the result will have no direct representation of the collection container
276 itself anymore. Therefore, if the collection was empty at serialization time, the serialized result does not
277 contain a trace of the collection anymore. At deserialization time it will therefore not know anything about the
278 collection and will not initialize it. XStream cannot decide anyway at deserialization time, if the collection was
279 empty or null.</p>
280
281 <!-- ...................................................... -->
282 <h2 id="Serialization_implicit_different_type">The type of my implicit collection is different after deserialization.</h2>
283
284 <p>By declaring a collection as implicit, the result will have no direct representation of the collection container
285 itself anymore. Therefore XStream cannot track the original type of the collection. At deserialization time it will
286 therefore look at the declaration type of the field that holds the collection and use this type's default
287 implementation, e.g. for a List this is by default an ArrayList.</p>
288
289 <p>Beware, that this also means that collections with additional information (e.g. a TreeSet with a Comparator)
290 cannot be restored, since the comparator was already omitted at serialization time.</p>
291
292 <!-- ...................................................... -->
293 <h2 id="Serialization_Serializable">Do my classes have to implement Serializable if XStream is to serialize them?</h2>
294 <p>No (except for lambda expressions), but XStream respects the Java serialization methods even for types not declared as Serializable.</p>
295
296 <!-- ...................................................... -->
297 <h2 id="Serialization_proxies">Can dynamic proxies be serialized?</h2>
298 <p>Yes.</p>
299
300 <!-- ...................................................... -->
301 <h2 id="Serialization_lambda_null">My lambda expression is serialized to null!</h2>
302 <p>Non-serializable lambda expressions to not contain any information at all to recreate the instance at a later time again. These instances are treated as temporary
303 objects and as such XStream has no other possibility as to serialize null instead.</p>
304
305 <!-- ...................................................... -->
306 <h2 id="Serialization_lambda_fails">Suddenly the deserialization of my (serializable) lambda expression fails!</h2>
307 <p>Serializable lambda expressions contain information that is specific for compiler and vendor. Even worse, the compiler is free to add information related to the location
308 of the lambda expression in the source i.e. you may not be able to deserialize a lambda expression after source code changes. XStream has no control over this information
309 and how it is used by native functionality in the JDK. Therefore Oracle strongly discourages the usage of serializable lambda expressions in the JDK documentation.</p>
310
311 <!-- ...................................................... -->
312 <h2 id="Serialization_CGLIB">Can CGLIB proxies be serialized?</h2>
313 <p>Only limitedly. A proxy generated with the CGLIB Enhancer is supported, if the proxy uses either a factory or
314 only one callback. Then it is possible to recreate the proxy instance at unmarshalling time. Starting with XStream 1.3.1
315 CGLIB support is no longer automatically installed because of possible classloader problems and side-effects,
316 because of incompatible ASM versions. You can enable CGLIB support with:</p>
317 <div class="Source Java"><pre>XStream xstream = new XStream() {
318 protected MapperWrapper wrapMapper(MapperWrapper next) {
319 return new CGLIBMapper(next);
320 }
321 };
322 xstream.registerConverter(new CGLIBEnhancedConverter(xstream.getMapper(), xstream.getReflectionProvider()));
323 </pre></div>
324
325 <!-- ...................................................... -->
326 <h2 id="Serialization_CGLIB_ExceptionInInitializerError">CGLIBEnhancedConverter fails at initialization with ExceptionInInitializerError</h2>
327 <p>This is not a problem of XStream. You have incompatible ASM versions in your classpath. CGLIB 2.1.x and below is based on
328 ASM 1.5.x which is incompatible to newer versions that are used by common packages like Hibernate, Groovy or Guice. Check
329 your dependencies and ensure that you are using either using cglib-nodep-2.x.jar instead of cglib-2.x.jar or update to
330 cglib-2.2.x that depends on ASM 3.1. However, the <em>nodep</em> version contains a copy of the ASM classes with private
331 packages and will therefore not raise class incompatibilities at all.</p>
332
333 <!-- ...................................................... -->
334 <h2 id="Serialization_CGLIB_2.0.1">Serialization fails with NoSuchMethodError: net.sf.cglib.proxy.Enhancer.isEnhanced(Ljava/lang/Class;)Z</h2>
335 <p>XStream uses this method to detect a CGLIB-enhanced proxy. Unfortunately the method is not available in the
336 cglib-2.0 version. Since this version is many years old and the method is available starting with cglib-2.0.1, please
337 consider an upgrade of the dependency, it works usually smoothly.</p>
338
339 <!-- ...................................................... -->
340 <h2 id="Serialization_Hibernate">How do I use XStream's Hibernate package to serialize my objects?</h2>
341 <p>Support of Hibernate enhanced collections and proxied types. To drop the internals of Hibernate when marshalling
342 such objects to XStream, all converters and the mapper has to be registered for the XStream instance:</p>
343 <div class="Source Java"><pre>final XStream xstream = new XStream() {
344 protected MapperWrapper wrapMapper(final MapperWrapper next) {
345 return new HibernateMapper(next);
346 }
347 };
348 xstream.registerConverter(new HibernateProxyConverter());
349 xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
350 xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
351 xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
352 xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));
353 </pre></div>
354
355 <!-- ...................................................... -->
356 <h2 id="Serialization_Hibernate_Envers">Does XStream's Hibernate package support Envers?</h2>
357 <p>Yes. Hibernate Envers is an optional dependency for XStream and it is automatically supported by XStream's
358 Hibernate package when the proxy collection types of Envers are available on the classpath.</p>
359
360 <!-- ...................................................... -->
361 <h2 id="Serialization_system_attributes">My attributes are interpreted by XStream itself and cause unexpected behavior</h2>
362 <p>XStream's generic converters and the marshalling strategies use a number of attributes on their own. Especially the attributes named
363 <em>id</em>, <em>class</em> and <em>reference</em> are likely to cause such collisions. Main reason is XStream's history, because
364 originally user defined attributes were not supported and all attribute were system generated. Starting with XStream 1.3.1 you can redefine
365 those attributes to allow the names to be used for your own ones. The following snippet defines XStream to use different system attributes
366 for <em>id</em> and <em>class</em> while the field <em>id</em> of YourClass is written into the attribute <em>class</em>:</p>
367 <div class="Source Java"><pre>XStream xstream = new XStream() {
368 xstream.useAttributeFor(YourClass.class, "id");
369 xstream.aliasAttribute("class", "id");
370 xstream.aliasSystemAttribute("type", "class");
371 xstream.aliasSystemAttribute("refid", "id");
372 </pre></div>
373
374 <!-- ...................................................... -->
375 <h2 id="Serialization_sort_fields">Can I select the field order in which XStream serializes objects?</h2>
376 <p>Yes. XStream's ReflectionConverter uses the defined field order by default. You can override it by using an specific FieldKeySorter:</p>
377 <div class="Source Java"><pre>SortableFieldKeySorter sorter = new SortableFieldKeySorter();
378 sorter.registerFieldOrder(MyType.class, new String[] { "firstToSerialize", "secondToSerialize", "thirdToSerialize" });
379 xstream = new XStream(new Sun14ReflectionProvider(new FieldDictionary(sorter)));
380 </pre></div>
381
382 <!-- ...................................................... -->
383 <h2 id="Serialization_newer_class_versions">How does XStream deal with newer versions of classes?</h2>
384
385 <ul>
386 <li>If a new field is added to the class, deserializing an old version will leave the field uninitialized.</li>
387 <li>If a field is removed from the class, deserializing an old version that contains the field will cause an exception.
388 Leaving the field in place but declaring it as transient will avoid the exception, but XStream will not try to deserialize it.</li>
389 <li>If a class is renamed, aliases can be used to create an abstraction between the name used in XML and the real class name.</li>
390 <li>If a field is renamed, this should be treated as adding a field and removing a field.</li>
391 </ul>
392
393 <p>For more advanced class migrations, you may</p>
394 <ul>
395 <li>have to do custom pre-processing of the XML before sending it to XStream (for example, with XSLT or DOM manipulations)</li>
396 <li>declare new fields as transient</li>
397 <li>implement your own converter, that can handle the situation</li>
398 <li>add a readResolve() method to your class, that initializes the object accordingly</li>
399 <li>implement a custom mapper to ignore unknown fields automatically
400 (see acceptance test CustomMapperTest.testCanBeUsedToOmitUnexpectedElements())</li>
401 </ul>
402
403 <p>Future versions of XStream will include features to make these type of migrations easier.</p>
404
405 <!-- ...................................................... -->
406 <h2 id="Serialization_classloader">How does XStream cope with isolated class loaders?</h2>
407
408 <p>Serializing an object graph is never a problem, even if the classes of those objects have been loaded by
409 a different class loader. The situation changes completely at deserialization time. In this case you must set the
410 class loader to use with:</p>
411
412 <div class="Source Java"><pre>xstream.setClassLoader(yourClassLoader);</pre></div>
413
414 <p>Although XStream caches a lot of type related information to gain speed, it keeps those information in
415 tables with weak references that should be cleaned by the garbage collector when the class loader is freed.</p>
416
417 <p>Note, that this call should be made quite immediately after creating the XStream and before any other
418 configuration is done. Otherwise configuration based on special types might refer classes loaded with the wrong
419 classloader.</p>
420
421 <!-- ****************************************************** -->
422 <h1 id="XML">XML specifics</h1>
423
424 <!-- ...................................................... -->
425 <h2 id="XML_respect_encoding">Why does XStream not respect the encoding in the XML declaration?</h2>
426
427 <p>XStream architecture is based on IO Readers and Writers, while the XML declaration is the responsibility of XML
428 parsers. All <a href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamDriver.html">HierarchicalStreamDriver</a>
429 implementations respect the encoding since version 1.3, but only if you provide an
430 <a href="http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html">InputStream</a>. If XStream consumes a
431 <a href="http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html">Reader</a> you have to initialize the reader with
432 the appropriate encoding yourself, since it is now the reader's task to perform the encoding and no XML parser can
433 change the encoding of a Reader and any encoding definition in the XML header will be ignored.</p>
434
435 <!-- ...................................................... -->
436 <h2 id="XML_write_XML_declaration">Why does XStream not write an XML declaration?</h2>
437
438 <p>XStream is designed to write XML snippets, so you can embed its output into an existing stream or string.
439 You can write the XML declaration yourself into the Writer before using it to call XStream.toXML(writer).</p>
440
441 <!-- ...................................................... -->
442 <h2 id="XML_write_UTF8">Why does XStream not write XML in UTF-8?</h2>
443
444 <p>XStream does no character encoding by itself, it relies on the configuration of the underlying XML writer.
445 By default it uses its own PrettyPrintWriter which writes into the default encoding of the current locale. To write
446 UTF-8 you have to provide a <a href="http://docs.oracle.com/javase/7/docs/api/java/io/Writer.html">Writer</a>
447 with the appropriate encoding yourself.</p>
448
449 <!-- ...................................................... -->
450 <h2 id="XML_double_underscores">Why do field names suddenly have double underscores in the generated XML?</h2>
451
452 <p>XStream maps Java class names and field names to XML tags or attributes. Unfortunately this mapping cannot
453 be 1:1, since some characters used for <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.8">
454 identifiers in Java</a> are invalid in <a href="http://www.w3.org/TR/REC-xml/#dt-name">XML names</a>. Therefore
455 XStream uses an <a href="javadoc/com/thoughtworks/xstream/io/xml/XmlFriendlyNameCoder.html">XmlFriendlyNameCoder</a>
456 to replace these characters with a replacement. By default this
457 <a href="javadoc/com/thoughtworks/xstream/io/naming/NameCoder.html">NameCoder</a> uses an underscore as escape
458 character and has therefore to escape the underscore itself also. You may provide a different configured instance
459 of the XmlFriendlyNameCoder or a complete different implementation like the
460 <a href="javadoc/com/thoughtworks/xstream/io/xml/XmlFriendlyNameCoder.html">NoNameCoder</a> to prevent name coding
461 at all. However it is your responsibility then to ensure, that the resulting names are valid for XML.</p>
462
463 <!-- ...................................................... -->
464 <h2 id="XML_unmarshalling_fails">XStream fails to unmarshal my given XML and I do not know why?</h2>
465
466 <p>By default XStream is written for persistence i.e. it will read the XML it can write. If you have to transform
467 a given XML into an object graph, you should go the other way round. Use XStream to transfer your objects into XML.
468 If the written XML matches your schema, XStream is also able to read it. This way is much easier, since you can
469 spot the differences in the XML much more easy than to interpret the exceptions XStream will throw if it cannot
470 match the XML into your objects.</p>
471
472 <!-- ...................................................... -->
473 <h2 id="XML_null_char">My parser claims the &amp;#x0; character to be invalid, but it was written with XStream!</h2>
474
475 <p>Your parser is basically right! A character of value 0 is not valid as part of XML according the XML specification (see
476 version <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#charsets">1.0</a> or
477 <a href="http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets">1.1</a>), neither directly nor as character
478 entity nor within CDATA. But not every parser respects this part of the specification (e.g. Xpp3 will ignore it and read
479 character entities). If you expect such characters in your strings and you do not use the Xpp3 parser, you should consider
480 to use a converter that writes the string as byte array in Base64 code. As alternative you may force the
481 <a href="javadoc/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.html">PrettyPrintWriter</a> or derived writers
482 to be XML 1.0 or 1.1. compliant, i.e. in this mode a StreamException is thrown.</p>
483
484 <!-- ...................................................... -->
485 <h2 id="XML_control_char">My parser claims a control character to be invalid, but it was written with XStream!</h2>
486
487 <p>Your parser is probably right! Control characters are only valid as part of XML 1.1. You should add an XML header
488 declaring this version or use a parser that does not care about this part of the specification (e.g. Xpp3 parser).</p>
489
490 <!-- ...................................................... -->
491 <h2 id="XML_attributes">Why is my element not written as XML attribute although I have configured it?</h2>
492
493 <p>You can only write types as attributes that are represented as a single String value and are handled therefore
494 by SingleValueConverter implementations. If your type is handled by a Converter implementation, the configuration
495 of XStream to write an attribute (using XStream.useAttributeFor() or @XStreamAsAttribute) is simply ignored.</p>
496
497 <!-- ...................................................... -->
498 <h2 id="XML_attribute_normalization">Why are whitespace characters wrong in my attribute values after deserialization?</h2>
499
500 <p>This is part of the XML specification and a required functionality for any XML parser called
501 <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#AVNormalize">attribute value normalization</a>. It cannot
502 be influenced by XStream. A compliant XML parser will replace by default real tab, carriage return and line feed
503 characters with normal spaces. If you want to keep these characters you will have to encode them with entities.</p>
504
505 <!-- ...................................................... -->
506 <h2 id="XML_namespaces">Why does XStream not have any namespace support?</h2>
507
508 <p>Not every XML parser supports namespaces and not every XML parser that supports namespaces can be configured
509 within XStream to use those. Basically namespaces must be supported individually for the different XML parsers and the
510 only support for namespaces that has currently been implemented in XStream is for the StAX paser. Therefore use and
511 configure the StaxDriver of XStream to use namespaces.</p>
512
513 <!-- ...................................................... -->
514 <h2 id="XML_xpath_limits">My XML contains XPath expressions in the references, but they seem not to work?</h2>
515
516 <p>XStream generates only XPath compliant expressions. These have a very limited syntax and they are the only ones
517 that can be interpreted at deserialization again, since XStream does not use an XPath interpreter. Therefore there
518 is no support for attribute selectors, qualified element access with axis names or functions. For real XPath
519 support you will have to implement your own MarshallingStrategy.</p>
520
521 <!-- ...................................................... -->
522 <h2 id="XML_xpath_nodelist">The XPath expressions in the references do select a list, but not a single node!</h2>
523
524 <p>Yes, this is right. However, the result type of an
525 <a href="http://docs.oracle.com/javase/7/docs/api/javax/xml/xpath/XPathExpression.html">XPath expression</a>
526 evaluation can be defined. A node result from a node list is the lists first node, therefore the XPath of XStream
527 is compliant. Since XStream does not use a real XPath engine, you do not have to worry about memory consumption or
528 wasted evaluation time, XStream will always operate on a single node anyway. Since XStream 1.4 you can force
529 XStream to write XPath expressions that select explicit the single node by using the new modes
530 XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES or SINGLE_NODE_XPATH_RELATIVE_REFERENCES. Instead of generating a
531 path like "/doc/list/elem/field" XStream will then generate "/doc[1]/list[1]/elem[1]/field[1]". The two notations
532 are transparent at deserialization time.</p>
533
534
535 <!-- ****************************************************** -->
536 <h1 id="JSON">JSON specifics</h1>
537
538 <!-- ...................................................... -->
539 <h2 id="JSON_2_drivers">Why are there two JSON driver implementations?</h2>
540
541 <p>As always, first for historical reasons! Main difference is that the
542 <a href="javadoc/com/thoughtworks/xstream/io/json/JettisonMappedXmlDriver.html">JettisonMappedXmlDriver</a> is a
543 thin wrapper around <a href="http://jettison.codehaus.org">Jettison</a> in combination with the
544 <a href="javadoc/com/thoughtworks/xstream/io/xml/StaxDriver.html">StaxDriver</a>, while the
545 <a href="javadoc/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamDriver.html">JsonHierarchicalStreamDriver</a>
546 uses an own more flexible implementation, but can only be used to generate JSON, deserialization is not implemented.</p>
547
548 <!-- ...................................................... -->
549 <h2 id="JSON_Jettison_version">Which versions of Jettison are supported?</h2>
550
551 <p>Users of Java 5 or higher can use Jettison 1.2, users of Java 1.4.2 have to use Jettison 1.0.1. Jettison 1.1
552 nor Jettison 1.3 or higher is supported.</p>
553
554 <!-- ...................................................... -->
555 <h2 id="JSON_deserialize_top_level_array">Why is it not possible to deserialize a JSON string starting with an array?</h2>
556
557 <p>XStream's implementation to deserialize JSON is based on Jettison and StAX. Jettison implements a XMLStreamReader
558 of StaX and transforms the processed JSON virtually into XML first. However, if the JSON string starts with an array it is not
559 possible for Jettison to create a valid root element, since it has no name.</p>
560
561 <!-- ...................................................... -->
562 <h2 id="JSON_unmarshalling_fails">XStream fails to unmarshal my JSON string and I do not know why?</h2>
563
564 <p>Deserialization of JSON is currently done by Jettison, that transforms the JSON string into a StAX stream.
565 XStream itself does nothing know about the JSON format here. If your JSON string reaches some kind of
566 complexity and you do not know how to design your Java objects and configure XStream to match those,
567 you should have a look at the intermediate XML that is processed by XStream in the end. This might help to
568 identify the problematic spots. Also consider then <a href="#XML_unmarshalling_fails">marshalling your Java
569 objects into XML first</a>. You can use following code to generate the XML:</p>
570
571 <div class="Source Java"><pre>String json = "{\"string\": \"foo\"}";
572 HierarchicalStreamDriver driver = new JettisonMappedXmlDriver();
573 StringReader reader = new StringReader(json);
574 HierarchicalStreamReader hsr = driver.createReader(reader);
575 StringWriter writer = new StringWriter();
576 new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer));
577 writer.close();
578 System.out.println(writer.toString());
579 </pre></div>
580
581 <!-- ...................................................... -->
582 <h2 id="JSON_limitations">What limitations has XStream's JSON support?</h2>
583
584 <p>JSON represents a very simple data model for easy data transfer. Especially it has no equivalent for XML
585 attributes. Those are written with a leading &quot;@&quot; character, but this is not always possible without
586 violating the syntax (e.g. for array types). Those may silently dropped (and makes it therefore difficult to
587 implement deserialization). References are another issue in the serialized object graph, since JSON has no
588 possibility to express such a construct. You should therefore always set the NO_REFERENCES mode of XStream.
589 Additionally you cannot use implicit collections, since the properties in a JSON object must have unique names.</p>
590
591 <!-- ...................................................... -->
592 <h2 id="JSON_JavaScript_Long">Why are my Long values incorrect in JavaScript?</h2>
593
594 <p>JavaScript does not know about integer values. All numbers are represented with double precition floats using
595 64 bits (IEEE 754). These types cannot represent technically the complete value range of 64-bit integers like
596 Java's Long. With the JsonWriter you have the possibility since XStream 1.4.5 to set
597 <a href="javadoc/com/thoughtworks/xstream/io/json/AbstractJsonWriter.html#IEEE_754_MODE">IEEE_754_MODE</a> to force
598 any long value that is not representable as JavaScript number to be written as string value in JSON. With the
599 Jettison-based JettisonMappedXmlDriver you may either set a different TypeConverter or force the default converter
600 to write integer values out of the range of 32-bit always as string setting the system property
601 <strong>jettison.mapped.typeconverter.enforce_32bit_integer</strong> to <strong>true</strong> (not available for
602 Jettison 1.0.1 and Java 1.4).</p>
603
604 <!-- ...................................................... -->
605 <h2 id="JSON_encoding">Why are there invalid characters in my JSON representation?</h2>
606
607 <p>The JSON spec requires any JSON string to be in UTF-8 encoding. However, XStream ensures this only if you
608 provide an InputStream or an OutputStream. If you provide a Reader or Writer you have to ensure this requirement
609 on your own.</p>
610
611 <!-- ...................................................... -->
612 <h2 id="JSON_dashes">The generated JSON is invalid, it contains a dash in the label!</h2>
613
614 <p>Well, no, the JSON is valid! Please check yourself with the <a href="http://www.jslint.com/">JSON syntax checker</a>.
615 However, some JavaScript libraries silently assume that the JSON labels are valid JavaScript identifiers, because JavaScript
616 supports a convenient way to address an element, <strong>if</strong> the label is a valid JavaScript identifier:</p>
617
618 <div class="Source JavaScript"><pre>var json = {"label": "foo", "label-with-dash": "bar"};
619 var fooVar = json.label; // works for labels that are JavaScript identifiers
620 var barVar = json["label-with-dash"]; // using an array index works always
621 </pre></div>
622
623 <p>As alternative you may wrap the JsonWriter and replace any dash with an underscore:</p>
624
625 <div class="Source Java"><pre>HierarchicalStreamDriver driver = new JsonHierarchicalStreamDriver() {
626 public HierarchicalStreamWriter createWriter(Writer out) {
627 return new WriterWrapper(super.createWriter(out)) {
628 public void startNode(String name) {
629 startNode(name, null);
630 }
631 public void startNode(String name, Class clazz) {
632 wrapped.startNode(name.replace('-', '_'), clazz);
633 }
634 }
635 }
636 };
637 XStream xstream = new XStream(driver);
638 </pre></div>
639
640 <!-- ****************************************************** -->
641 <h1 id="Security">Security Aspects</h1>
642
643 <!-- ...................................................... -->
644 <h2 id="Security_EventHandler">Why does XStream not convert an java.beans.EventHandler?</h2>
645
646 <p>Since XStream verison 1.4.7 it does no longer handle an
647 <a href="http://docs.oracle.com/javase/7/docs/api/java/beans/EventHandler.html">EventHandler</a> automatically.
648 Such an instance can be used to initiate calls on arbitray instances at deserialization time e.g.
649 <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#start()">ProcessBuilder.start()</a>
650 You can register a ReflectionConverter instance explicitly for the EventHandler if you need support for such
651 instances.</p>
652
653 <!-- ...................................................... -->
654 <h2 id="Security_ArbitraryDeserialization">XStream deserializes arbitrary objects!</h2>
655
656 <p>Yes, XStream is designed to convert any object form Java to XML and back out of the box. In consequence it is
657 possible to adjust the processed XML manually to inject arbitrary objects into the deserialized object graph. To
658 avoid such a behavior, you have several options:</p>
659
660 <ul>
661 <li>Prevent the usage of the reflection-based converters. Register an own converter with priority LOW that claims
662 to handle any type and throw a ConversionException in the marshal and unmarshal methods.</li>
663 <li>Overload XStream.setupConverters() and register only converters for the types that are allowd in your object
664 graph.</li>
665 <li>Provide own implementations for ConverterLookup and ConverterRegistry constructing the XStream. Your
666 implementation can then select the appropriate converter at lookup time on its own or prevent the registration of
667 specific converters.</li>
668 </ul>
669
670 <!-- ****************************************************** -->
671 <h1 id="Other_Products">Comparison to other products</h1>
672
673 <!-- ...................................................... -->
674 <h2 id="Other_Products_XMLBeanEncoder">How does XStream compare to java.beans.XMLEncoder?</h2>
675
676 <p>XStream is designed for serializing <i>objects</i> using internal fields, whereas
677 <a href="http://docs.oracle.com/javase/7/docs/api/java/beans/XMLEncoder.html">XMLEncoder</a> is designed for
678 serializing <i>JavaBeans</i> using public API methods (typically in the form
679 of <code>getXXX()</code>, <code>setXXX()</code>, <code>addXXX()</code> and <code>removeXXX()</code> methods.</p>
680
681 <h2 id="Other_Products_JAXB">How does XStream compare to JAXB (Java API for XML Binding)?</h2>
682
683 <p>JAXB is a Java binding tool. It generates Java code from a schema and you are able to transform from those classes into
684 XML matching the processed schema and back. Note, that you cannot use your own objects, you have to use what is
685 generated.</p>
686
687 <!-- ****************************************************** -->
688 <h1 id="Scalability">Scalability</h1>
689
690 <!-- ...................................................... -->
691 <h2 id="Scalability_Thread_safety">Is XStream thread safe?</h2>
692
693 <p>Yes. Once the XStream instance has been created and configured, it may be shared across multiple threads
694 allowing objects to be serialized/deserialized concurrently (unless you enable the
695 <a href="annotations-tutorial.html#AutoDetect">auto-detection</a> to process annotations on-the-fly). Actually the
696 creation and initialization of XStream is quite expensive, therefore it is recommended to keep the XStream instance
697 itself. If you abolutely have to rely on annotation processing on the fly, you will have to use separate XStream
698 instances for each thread - either by using everytime a new instance or by a shared pool.</p>
699
700 <!-- ...................................................... -->
701 <h2 id="Scalability_Memory">How much memory does XStream consume?</h2>
702
703 <p>This cannot be answered in general, but following topics have impact on the memory:</p>
704
705 <ol>
706 <li>XML parser technology in use: You should use a streaming parser like Xpp3 or StAX. DOM-based
707 parsers process the complete XML and create their document model in memory before the first converter of XStream
708 is called.</li>
709 <li>Your object model: Is it necessary to keep the complete object graph in memory at once? As alternative you might
710 use <a href="objectstream.html">object streams</a> or write custom converters that can load and save objects of your
711 object model on the fly without adding them to the object graph physically. As example see the implementation of the
712 <a href="javadoc/com/thoughtworks/xstream/persistence/XmlArrayList.html">XmlArrayList</a> in combination with the
713 <a href="javadoc/com/thoughtworks/xstream/persistence/FileStreamStrategy.html">FileStreamStrategy</a> from
714 XStream's persistence package to keep parts of the object graph separate.</li>
715 <li>References: By default XStream supports references to the same object in an object graph. This implies that XStream
716 keeps track of all serialized and deserialized objects internally. These references are kept with WeakReferences, so that the
717 memory can be freed as soon as nobody references these objects anymore.</li>
718 <li>XML values: Any tag and attribute value that is converted into a Java String in the object graph will use by default the
719 same String instance unless it exceeds 38 characters (length of a UUID string representation).</li>
720 <li>XStream caches: To increase performance XStream caches quite a lot like classes, converters to use, aliasing, tag names.
721 All those caches make usage of WeakReferences or will exist only while marshalling one object graph resp. unmarshalling one
722 input stream.</li>
723 </ol>
724
725 <!-- ...................................................... -->
726 <h2 id="Scalability_Performance">Can the performance of XStream be increased?</h2>
727
728 <p>XStream is a generalizing library, it inspects and handles your types on the fly. Therefore it will normally be slower than
729 a piece of optimized Java code generated out of a schema. However, it is possible to increase the performance anyway:</p>
730
731 <ul>
732 <li>Write custom converters for those of your types that occur very often in your XML.</li>
733 <li>Keep a configured XStream instance for multiple usage. Creation and initialization is quite expensive compared to the
734 overhead of XStream when calling marshall or unmarshal.</li>
735 <li>Use Xpp3 or StAX parsers.</li>
736 </ul>
737
738 <p>Note, you should never try to optimize code for performance simply because you <strong>believe</strong> that you
739 have detected a bottle neck. Always use proper tools like a profiler to verify where your hotspots are and whether your
740 optimization was really successful or not.</p>
741
742
743 <!-- ****************************************************** -->
744 <h1 id="Uses">Uses of XStream</h1>
745
746 <!-- ...................................................... -->
747 <h2 id="Uses_Data_Binding">Is XStream a data binding tool?</h2>
748
749 <p>No. It is a serialization tool.</p>
750
751 <!-- ...................................................... -->
752 <h2 id="Uses_Generate_Code">Can XStream generate classes from XSD?</h2>
753
754 <p>No. For this kind of work a data binding tool such as <a href="http://xmlbeans.apache.org">XMLBeans</a> is appropriate.</p>
755
756 <!-- ...................................................... -->
757 <h2 id="Uses_No_SAX_Reader">Why is there no SaxReader?</h2>
758
759 <p>XStream works on a stream-based parser model, while SAX is event-based. The stream based model implies, that the
760 caller consumes the individual tokens from the XML parser on demand, while in an event-based model the parser
761 controls the application flow on its own and will use callbacks to support client processing. The different
762 architecture makes it therefore impossible for XStream to use an event-driven XML parser.</p>
763
764 </body>
765 </html>
766
0 <html>
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2009 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 03. April 2006 by Guilherme Silveira
11 -->
12 <head>
13 <title>Object references</title>
14 </head>
15
16 <body>
17
18 <!-- ...................................................... -->
19 <h2 id="references">How does XStream deals with duplicate and circular references?</h2>
20 <p>It depends on XStream's mode, the default is uses XPath to allow serialized objects to be treated as graphs instead of simple trees (typical XML usage).</p>
21
22 <p>Sometimes it's not desirable to work this way, let's take a look in a simple example in order to switch between XStream's modes and see what its capable of.</p>
23 <p>We start with a simple compact-disc class, with id and a bonus cd fields:</p>
24
25 <div class="Source Java"><pre>package com.thoughtworks.xstream;
26 public class Cd {
27 private String id;
28
29 private Cd bonusCd;
30
31 Cd(String id, Cd bonusCd) {
32 this.id = id;
33 this.bonusCd = bonusCd;
34 }
35
36 Cd(String id) {
37 this.id = id;
38 }
39
40 public String getId() {
41 return id;
42 }
43
44 public Cd getBonusCd() {
45 return bonusCd;
46 }
47 }</pre></div>
48
49 <p>And let's create an order with the same cd twice and the order itself, so we can simulate
50 two references to the same object and a back-reference.</p>
51
52 <div class="Source Java"><pre>Cd bj = new Cd("basement_jaxx_singles");
53
54 List order = new ArrayList();
55 // adds the same cd twice (two references to the same object)
56 order.add(bj);
57 order.add(bj);
58
59 // adds itself (cycle)
60 order.add(order);
61
62 XStream xstream = new XStream();
63 xstream.alias("cd", Cd.class);
64 System.out.println(xstream.toXML(order));
65 </pre></div>
66
67 <p>If we execute the above code, XStream's uses its <b>default mode</b> called XPATH_RELATIVE_REFERENCES
68 based on the W3C XPath specification. Cross and back references are treated in a way that it's (almost) human
69 readable:</p>
70
71 <div class="Source Java"><pre>
72 &lt;list&gt;
73 &lt;cd&gt;
74 &lt;id&gt;maria rita&lt;/id&gt;
75 &lt;/cd&gt;
76 &lt;cd&gt;
77 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
78 &lt;/cd&gt;
79 &lt;cd reference="../cd[2]"/&gt;
80 &lt;list reference=".."/&gt;
81 &lt;/list&gt;
82 </pre></div>
83
84 <p>The second reference to the Basement Jaxx cd was serialized as "../cd[2]" while the order inside
85 itself used the ".." path. The XPath Relative mode allows any type of graphs to be used as both cross and
86 back-references are supported.</p>
87
88 <p>In order to make use of the XPath Relative mode one can implicitly call:</p>
89
90 <div class="Source Java"><pre>
91 xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);
92 </pre></div>
93
94 <!-- ...................................................... -->
95 <h2 id="rel-abs">Relative x Absolute</h2>
96
97 <p>There is an absolute mode which is easy to use and understand. It works
98 using the same XPath specification and also supports all types of graphs.</p>
99
100 <div class="Source Java"><pre>
101 xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
102 </pre></div>
103
104 <p>The changes in the resulting xml is a little more 'clutter':</p>
105
106 <div class="Source Java"><pre>
107 &lt;list&gt;
108 &lt;cd&gt;
109 &lt;id&gt;maria rita&lt;/id&gt;
110 &lt;/cd&gt;
111 &lt;cd&gt;
112 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
113 &lt;/cd&gt;
114 &lt;cd reference="/list/cd[2]"/&gt;
115 &lt;list reference="/list"/&gt;
116 &lt;/list&gt;
117 </pre></div>
118
119
120 <!-- ...................................................... -->
121 <h2 id="single-node">Single Node Selectors</h2>
122
123 <p>In some cases where the XML is used later on or is generated by someone else, the
124 XPath selectors can be forced to select always a single node instead of a node list where
125 the first element is taken. Therefore two more modes exist:</p>
126
127 <div class="Source Java"><pre>
128 xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);
129 xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);
130 </pre></div>
131
132 <p>The changes in the resulting xml is even more 'clutter':</p>
133
134 <div class="Source Java"><pre>
135 &lt;list&gt;
136 &lt;cd&gt;
137 &lt;id&gt;maria rita&lt;/id&gt;
138 &lt;/cd&gt;
139 &lt;cd&gt;
140 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
141 &lt;/cd&gt;
142 &lt;cd reference="/list[1]/cd[2]"/&gt;
143 &lt;list reference="/list[1]"/&gt;
144 &lt;/list&gt;
145 </pre></div>
146
147 <p>For XStream is the notation with the single node selectors absolutely equivalent to the
148 one without. These two notations are completely transparent at deserialization time.</p>
149
150 <!-- ...................................................... -->
151 <h2 id="ids">Id mode</h2>
152
153 <p>Both modes displayed until now are not so easy to write by hand. XStream has another
154 mode which makes it is easier to read/write by a human being:</p>
155
156 <div class="Source Java"><pre>
157 xstream.setMode(XStream.ID_REFERENCES);
158 </pre></div>
159
160 <p>The result is a XML which generates an "id" attribute for each new object marshaled,
161 and whenever it finds back or cross-references, it uses a "reference" attribute to so
162 it doesn't copy the entire object.</p>
163
164 <p>In our example, the list has id 1, the Maria Rita cd 2, and the Basement Jaxx 3. Therefore
165 the cross-reference to our cd should contain a reference attribute to object number 2 and
166 the back-reference to our order a reference to object 1. The result is:</p>
167
168 <div class="Source Java"><pre>
169 &lt;list id="1"&gt;
170 &lt;cd id="2"&gt;
171 &lt;id&gt;maria rita&lt;/id&gt;
172 &lt;/cd&gt;
173 &lt;cd id="3"&gt;
174 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
175 &lt;/cd&gt;
176 &lt;cd reference="3"/&gt;
177 &lt;list reference="1"/&gt;
178 &lt;/list&gt;
179 </pre></div>
180
181 <!-- ...................................................... -->
182 <h2>No references</h2>
183
184 <p>For some uses of XStream we do not desire any kind of back or cross references like a graph, but a simple
185 tree. The most famous example is when using XStream to generate XML for B2B services.</p>
186
187 <p>In such scenarios it's impossible to represent a graph cycle (remember: no tree contains such structure), therefore
188 we have to remove the last <b>add</b> call from our example:</p>
189
190 <div class="Source Java"><pre>Cd bj = new Cd("basement_jaxx_singles");
191
192 List order = new ArrayList();
193 // adds the same cd twice (two references to the same object)
194 order.add(bj);
195 order.add(bj);
196
197 XStream xstream = new XStream();
198 xstream.alias("cd", Cd.class);
199 System.out.println(xstream.toXML(order));
200 </pre></div>
201
202 <p>Now if we add the NO_REFERENCES option, every reference shall be completed serialized.</p>
203
204 <div class="Source Java"><pre>
205 xstream.setMode(XStream.NO_REFERENCES);
206 </pre></div>
207
208 <p>The result are three references:</p>
209
210 <div class="Source Java"><pre>
211 &lt;list&gt;
212 &lt;cd&gt;
213 &lt;id&gt;maria rita&lt;/id&gt;
214 &lt;/cd&gt;
215 &lt;cd&gt;
216 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
217 &lt;/cd&gt;
218 &lt;cd&gt;
219 &lt;id&gt;basement_jaxx_singles&lt;/id&gt;
220 &lt;/cd&gt;
221 &lt;/list&gt;
222 </pre></div>
223
224 <p>After reading from the above XML, you will get three <b>different</b> Cd instances.</p>
225
226 <p>Remember: it's impossible to support back-references (cycles) with NO_REFERENCES mode activated therefore
227 a CircularReferenceException is thrown if you ever try to do so.</p>
228
229 </body>
230 </html>
231
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2013 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>How to Contribute</title>
14 </head>
15
16 <body>
17
18 <p>XStream is nothing without contributions from the user community. There are many ways to
19 contribute. We are constantly working on the software and documentation, so it's a good
20 idea to contact the team. For normal question about usage or possible misbehavior, please contact
21 us on the <a href="list-user.html">user</a> mailing list. To discuss further development of XStream,
22 you may contact us on <a href="list-dev.html">development</a> mailing lists to avoid duplicating effort.</p>
23
24 <h2 id="help">Help</h2>
25 <p>The correct place if you are looking for help is the <a href="list-user.html">user</a> mailing list. You
26 get there a much wider audience from other users and also the developers are reading and answering there
27 your questions.</p>
28
29 <h2 id="documentation">Documentation</h2>
30 <p>One of the traditional weak points of open source software is the documentation. Any
31 help with this aspect of the project will be welcomed with open arms, or at the very least
32 with open email clients!</p>
33
34 <h2 id="examples">Examples</h2>
35 <p>We are working on one or two examples of using XStream, but we can always do with more.</p>
36
37 <h2 id="feature-requests">Feature Requests</h2>
38 <p>We eat our own dogfood, but we're also happy to feed other people's dogs (if you'll excuse
39 a stretched <span style="text-decoration:line-through">dachshund</span> metaphor!). If you want to
40 request a new feature you can either make a request through the <a href="issues.html">issue tracker</a>
41 or by sending a message to the <a href="list-dev.html">development mailing list</a>. The benefit of any
42 new features will be discussed on the mailing list, so its a good idea to sign up so that you can stick your
43 oar in.</p>
44
45 <h2 id="bug-reports">Bug Reports</h2>
46 <p>You can report bugs through the <a href="issues.html">issue tracker</a> interface or in case you are
47 in doubt whether it is really a bug or just a wrong usage, you may ask first posting to the
48 <a href="list-user.html">user mailing list</a>. Additional brownie points are awarded for bug reports that
49 include a failing unit test.</p>
50
51 <h2 id="patches">Bug Fixes</h2>
52 <p>If you want <em>lots</em> of brownie points, send a fix along with your bug report
53 and failing unit test. Bug fixes are best sent as patches that we can apply to the
54 codebase. Remember to tell us which version the patch should be applied against, or
55 we'll get very confused. To be accepted into the codebase, patches must be released
56 under the <a href="license.html">same license as XStream itself</a>.</p>
57
58 <h2 id="new-code">New Code</h2>
59 <p>If you have a new feature request, then we'll listen extra hard if you show us how it
60 works. A new feature might be best implemented as a patch to an existing class
61 or as a new class. The XStream API contains many extension points that allow new functionality
62 to be integrated into the framework. We are rather anal about testing, so if you send us
63 some code without any tests we will probably ask you to write the tests tests as well
64 before we add it to the codebase.</p>
65
66 <h2 id="your-own-extension">Write Your Own XStream Extension</h2>
67 <p>If you have a project that builds upon XStream we will be happy to announce your
68 project on the XStream site.</p>
69
70 <h2 id="become-committer">Become a Committer</h2>
71 <p>We follow the <a href="http://www.codehaus.org/customs/manifesto.html">Codehaus manifesto</a>
72 when it comes to expanding the core team.</p>
73
74 </body>
75 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2011, 2012, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Java to XML serialization, and back again</title>
14 <meta name="short" content="About XStream"/>
15 </head>
16
17 <body>
18
19 <p>XStream is a simple library to serialize objects to XML and back again.</p>
20
21 <h1 id="features">Features</h1>
22
23 <ul>
24 <li><b>Ease of use.</b> A high level facade is supplied that simplifies common use cases.</li>
25 <li><b>No mappings required.</b> Most objects can be serialized without need for specifying mappings.</li>
26 <li><b>Performance.</b> Speed and low memory footprint are a crucial part of the design, making it suitable for
27 large object graphs or systems with high message throughput.</li>
28 <li><b>Clean XML.</b> No information is duplicated that can be obtained via reflection. This results
29 in XML that is easier to read for humans and more compact than native Java serialization.</li>
30 <li><b>Requires no modifications to objects.</b> Serializes internal fields, including private and
31 final. Supports non-public and inner classes. Classes are not required to have default constructor.</li>
32 <li><b>Full object graph support.</b> Duplicate references encountered in the object-model will
33 be maintained. Supports circular references.</li>
34 <li><b>Integrates with other XML APIs.</b> By implementing an interface, XStream can serialize
35 directly to/from any tree structure (not just XML).</li>
36 <li><b>Customizable conversion strategies.</b> Strategies can be registered allowing customization of how
37 particular types are represented as XML.</li>
38 <li><b>Security framework.</b> Fine-control about the unmarshalled types to prevent security issues with
39 manipulated input.</li>
40 <li><b>Error messages.</b> When an exception occurs due to malformed XML, detailed diagnostics are provided
41 to help isolate and fix the problem.</li>
42 <li><b>Alternative output format.</b> The modular design allows other output formats. XStream ships currently
43 with JSON support and morphing.</li>
44 </ul>
45
46 <h1 id="use-cases">Typical Uses</h1>
47
48 <ul>
49 <li><b>Transport</b></li>
50 <li><b>Persistence</b></li>
51 <li><b>Configuration</b></li>
52 <li><b>Unit Tests</b></li>
53 </ul>
54
55 <h1 id="limitations">Known Limitations</h1>
56
57 <p>If using the enhanced mode, XStream can re-instantiate classes that do not have a default constructor.
58 However, if using a different JVM like an old JRockit version, a JDK 1.4 or you have restrictions because of a
59 SecurityManager, a default constructor is required.</p>
60
61 <p>The enhanced mode is also necessary to restore final fields for any JDK &lt; 1.5. This implies deserialization of
62 instances of an inner class.</p>
63
64 <p>Auto-detection of annotations may cause race conditions. Preprocessing annotations is safe though.</p>
65
66 <h1 id="getting-started">Getting Started</h1>
67
68 <ul>
69 <li><a href="download.html">Download it</a>.</li>
70 <li><a href="tutorial.html">Use it</a>.</li>
71 </ul>
72
73 <h1 id="news">Latest News</h1>
74
75 <h2 id="1.4.8"><b>February 18, 2015</b> XStream 1.4.8 released</h2>
76
77 <p>Maintenance release 1.4.8 of XStream with bug fixes and improvements running with Java 8.</p>
78
79 <p>XStream supports now serializable lambda types for a Java 9 runtime.</p>
80
81 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
82
83 <p>Note, the next major release 1.5 will require Java 6.</p>
84
85 <p>Thanks to this impressive list of <a href="team.html#contributors">contributors</a>.</p>
86
87 </body>
88 </html>
0 <html>
1 <!--
2 Copyright (C) 2007, 2008, 2013 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 20. March 2007 by Joerg Schaible
10 -->
11 <head>
12 <title>Reporting Issues</title>
13 </head>
14 <body>
15
16 <p>XStream tracks and manages its issues in <a href="http://www.atlassian.com/software/jira/">JIRA of Atlassian</a>,
17 that is supported by the Codehaus infrastructure and is free for open source development.</p>
18
19 <h2 id="account">JIRA Account</h2>
20
21 <p>Before you can report, comment or vote for an issue you need an account for the Codehaus. This account is then also used for
22 Codehaus' JIRA installation. Simply sign up at <a href="http://xircles.codehaus.org">xircles</a> and on top you're able to manage all
23 the mailing list subscriptions at Codehaus inclusive XStream's lists also. This is necessary to reduce spam in the system and as benefit
24 you can be notified if work is done on your reported issues.</p>
25
26 <h2 id="policy">Policy</h2>
27
28 <p>Please, before opening a new issue look through the open or resolved ones, you may already find your problem. Also do not
29 use the system to ask questions, for that purpose we have a <a href="list-user.html">user list</a>. We read the list continuously.
30 If you are unsure whether the problem is caused by a bug or your usage of XStream, use the user's list first. If we can confirm a bug,
31 you may still open an issue. Also do not report on the list that you have created a new issue, we are already notified by the system.</p>
32
33 <p>If you like to contribute code, we prefer a patch/diff in contrast to the complete modified file - unless the file itself is new. Please
34 provide also unit tests, XStream has a high test coverage and we like to keep this. Additionally, if you provide new files, please also add
35 a header with the copyright. It must be a BSD license, simply take the header of any other file in the distribution as template. Otherwise
36 we might not be able to add any code of you.</p>
37
38 <p>Browse XStream in <a href="http://jira.codehaus.org/browse/XSTR">JIRA</a> now.</p>
39 </body>
40 </html>
0 <html>
1 <!--
2 Copyright (C) 2007, 2008, 2010, 2012, 2013 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 22. May 2007 by Joerg Schaible
10 -->
11 <head>
12 <title>JSON Tutorial</title>
13 </head>
14 <body>
15
16 <p>Due to XStream's flexible architecture, handling of JSON mappings is as easy as handling of XML documents. All you
17 have to do is to initialize XStream object with an appropriate driver and you are ready to serialize your objects to
18 (and from) JSON.</p>
19
20 <p>XStream currently delivers two drivers for JSON: The
21 <a href="javadoc/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamDriver.html">JsonHierarchicalStreamDriver</a>
22 and the <a href="javadoc/com/thoughtworks/xstream/io/json/JettisonMappedXmlDriver.html">JettisonMappedXmlDriver</a>.
23 The first one does not have an additional dependency, but can only be used to write XML, while the second one is based
24 on Jettison and can also deserialize JSON to Java objects again. However, since the JettisonMappedXmlDriver transforms
25 plain XML into JSON, you might get better JSON strings with the JsonHierarchicalStreamDriver, because this driver knows
26 often about the type of the written data and can act properly.</p>
27
28 <p class="highlight">One word of warning. JSON is made for an easy data transfer between systems and languages. It's
29 syntax offers much less possibilities to express certain data structures. It supports name/value pairs of primitive
30 data types, arrays and lists and allows to nest them - but that's it! No references, no possibility for meta data
31 (attributes), no properties with same names (as generated for implicit collections), etc. Therefore do not expect
32 wonders. XStream (and Jettison) try their best, but the procedure to convert any kind of object into JSON is a lossy
33 transformation and especially deserialization will not be possible for any construct. See also
34 <a href="faq.html#JSON_limitations">FAQ for JSON limitations</a>. Also note that any number value in JavaScript is a
35 64-bit double precision float value according IEEE 754 standard. In consequence it is not possible to represent all
36 values of a Java long type without loss of precision. See again <a href="faq.html#JSON_JavaScript_Long">FAQ for JSON
37 and JavaScript</a>.</p>
38
39 <p>Since JSON has no possibility to express references, you should always set the NO_REFERENCES mode writing JSON.</p>
40
41 <h1 id="jettison">Jettison driver</h1>
42
43 <p>Jettison driver uses <a href="http://jettison.codehaus.org/">Jettison</a> StAX parser to read and write data in JSON
44 format. It is available in XStream since version 1.2.2 and is implemented in
45 <code>com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver</code> class. To successfully use this driver you need
46 to have the Jettison project and <a href="http://stax.codehaus.org/">StAX API</a> in your classpath (see reference for
47 <a href="download.html#optional-deps">optional dependencies</a>).</p>
48
49 <p>Alternatively you can download JARs manually.</p>
50
51 <p>Here are a few simple examples:</p>
52
53 <h2 id="jettison-write">Write to JSON with the Jettison-based implementation</h2>
54
55 <p>The following example:</p>
56
57 <div class="Source Java"><pre>package com.thoughtworks.xstream.json.test;
58
59 import com.thoughtworks.xstream.XStream;
60 import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
61
62 public class WriteTest {
63
64 public static void main(String[] args) {
65
66 Product product = new Product("Banana", "123", 23.00);
67 XStream xstream = new XStream(new JettisonMappedXmlDriver());
68 xstream.setMode(XStream.NO_REFERENCES);
69 xstream.alias("product", Product.class);
70
71 System.out.println(xstream.toXML(product));
72
73 }
74
75 }</pre></div>
76
77 <p>produces the following JSON document:</p>
78
79 <div class="Source Java"><pre>{"product":{"name":"Banana","id":123,"price":23.0}}</pre></div>
80
81 <p>As you can see, all standard XStream features (such as aliases) can be used with this driver.</p>
82
83 <p class="highlight">Note that Jettison will try to detect numerical values and omit the quotes. Since Jettison
84 cannot know about the original data type, it has to guess. Hence it will therefore also write the value of the id
85 field as numeric value in future.</p>
86
87 <h2 id="json-write">Write to JSON with the self-contained JSON driver</h2>
88
89 <p>The only difference to the example above is the line with the initialization:</p>
90
91 <div class="Source Java"><pre>XStream xstream = new XStream(new JsonHierarchicalStreamDriver());</pre></div>
92
93 <p>The output is as follows:</p>
94
95 <div class="Source Java"><pre>{"product": {
96 "name": "Banana",
97 "id": "123",
98 "price": 23.0
99 }}</pre></div>
100
101 <p>While the difference because of line feeds is immediately obvious, you have to note also the value of the
102 <em>id</em> element. This time the driver knew about the string value and therefore quotes were generated.</p>
103
104 <h2 id="json-dropping-root">Write to JSON with the self-contained JSON driver dropping the root</h2>
105
106 <p>Sometimes the root node in the generated JSON is superfluous, since its name is caused by the Java type
107 of the written object that has no meaning in JSON and increases only the nesting level of the structure. Therefore
108 it is possible to drop this root by initializing the internally used
109 <a href="javadoc/com/thoughtworks/xstream/io/json/JsonWriter.html">JsonWriter</a> in a different mode.
110 Again, the only difference to the example above is the line with the initialization:</p>
111
112 <div class="Source Java"><pre>XStream xstream = new XStream(new JsonHierarchicalStreamDriver() {
113 public HierarchicalStreamWriter createWriter(Writer writer) {
114 return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
115 }
116 });</pre></div>
117
118 <p>The output is as follows:</p>
119
120 <div class="Source Java"><pre>{
121 "name": "Banana",
122 "id": "123",
123 "price": 23.0
124 }</pre></div>
125
126 <p class="highlight">Note, that it is now possible to create invalid JSON if XStream should marshal a single object
127 with a single value to JSON (like String, int, URL, ...). JSON requires that the root is actually an object, but by
128 dropping the root all that is generated is a single value. You can force the JsonWriter to throw a ConversionException
129 in this case, see Javadoc of the JsonWriter.</p>
130
131 <h2 id="jettison-read">Read from JSON</h2>
132
133 <p>The following code:</p>
134
135 <div class="Source Java"><pre>package com.thoughtworks.xstream.json.test;
136
137 import com.thoughtworks.xstream.XStream;
138 import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
139
140 public class ReadTest {
141
142 public static void main(String[] args) {
143 String json = "{\"product\":{\"name\":\"Banana\",\"id\":123"
144 + ",\"price\":23.0}}";
145
146 XStream xstream = new XStream(new JettisonMappedXmlDriver());
147 xstream.alias("product", Product.class);
148 Product product = (Product)xstream.fromXML(json);
149 System.out.println(product.getName());
150 }
151
152 }</pre></div>
153
154 <p>serializes JSON document created with preceding example back to Java object. It prints:</p>
155
156 <div class="Source Java"><pre>Banana</pre></div>
157
158 <p>as a result.</p>
159
160 </body>
161 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2009, 2011 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>License</title>
14 </head>
15 <body>
16
17 <p>XStream is open source software, made available under a BSD license.</p>
18
19 <div class="Source Java"><pre>Copyright (c) 2003-2006, Joe Walnes
20 Copyright (c) 2006-2009, 2011 XStream Committers
21 All rights reserved.
22
23 Redistribution and use in source and binary forms, with or without
24 modification, are permitted provided that the following conditions are met:
25
26 1. Redistributions of source code must retain the above copyright notice, this list of
27 conditions and the following disclaimer.
28
29 2. Redistributions in binary form must reproduce the above copyright notice, this list of
30 conditions and the following disclaimer in the documentation and/or other materials provided
31 with the distribution.
32
33 3. Neither the name of XStream nor the names of its contributors may be used to endorse
34 or promote products derived from this software without specific prior written
35 permission.
36
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
38 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
40 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
41 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
42 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
45 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
46 DAMAGE.
47 </pre></div>
48
49 </body>
50 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Developers' Mailing List</title>
14 </head>
15 <body>
16
17 <p>General discussion and support for anyone who wants to get involved in the development of XStream.</p>
18
19 <p>Note, if you just have questions about using XStream, you should use the <a href="list-user.html">user's mailing list</a>.</p>
20
21 <table summary="Links to subscribe and unsubscribe">
22 <tr>
23 <th>Post</th>
24 <th>(Un-)Subscribe</th>
25 </tr>
26 <tr>
27 <td><a href="mailto:dev@xstream.codehaus.org">dev@xstream.codehaus.org</a></td>
28 <td><a href="http://xircles.codehaus.org/manage_email">Manage Email</a></td>
29 </tr>
30 </table>
31
32 <p>Due to massive abuse by spammers the subscriptions is centralized for email lists of all projects hosted on Codehaus.
33 After following the link above just register with your email address and you can manage all subscriptions at once.</p>
34
35 <h2 id="archives">Archives</h2>
36
37 <iframe src="http://news.gmane.org/gmane.comp.java.xstream.devel">
38 <p>View <a href="http://news.gmane.org/gmane.comp.java.xstream.devel">archives</a>, provided by Gmane.org</p>
39 </iframe>
40
41 </body>
42 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Users' Mailing List</title>
14 </head>
15 <body>
16
17 <p align="left">General discussion and support for anyone using or evaluating XStream.</p>
18
19 <table summary="Links to subscribe and unsubscribe">
20 <tr>
21 <th>Post</th>
22 <th>(Un-)Subscribe</th>
23 </tr>
24 <tr>
25 <td><a href="mailto:user@xstream.codehaus.org">user@xstream.codehaus.org</a></td>
26 <td><a href="http://xircles.codehaus.org/manage_email">Manage Email</a></td>
27 </tr>
28 </table>
29
30 <p>Due to massive abuse by spammers the subscriptions is centralized for email lists of all projects hosted on Codehaus.
31 After following the link above just register with your email address and you can manage all subscriptions at once.</p>
32
33 <h2 id="archives">Archives</h2>
34
35 <iframe src="http://news.gmane.org/gmane.comp.java.xstream.user">
36 <p>View <a href="http://news.gmane.org/gmane.comp.java.xstream.user">archives</a>, provided by Gmane.org</p>
37 </iframe>
38
39 </body>
40 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2011, 2013 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Tweaking the Output</title>
14 </head>
15 <body>
16
17 <p>Out of the box, XStream is able to serialize most objects without the need for custom mappings to be setup.
18 The XML produced is clean, however sometimes it's desirable to make tweaks to it. The most common use for this is
19 when using XStream to read configuration files and some more human-friendly XML is needed.</p>
20
21 <!-- ************ -->
22
23 <h1 id="Configuration">Modification by configuration</h1>
24
25 <p>A big part of the standard output of XStream can be configured. It is possible to set aliases for class types
26 and field names that are mapped to XML tag or attribute names. Objects that can be represented as simple string
27 value can be written as attributes. It is possible to omit fields or to flatten the structure for collections.</p>
28
29 <!-- .................. -->
30
31 <h2 id="Configuration_Aliases">Aliases</h2>
32
33 <p>Aliases offer a simple way to use different tag or attribute names in the XML. The simplest and most commonly
34 used tweak in XStream is to alias a fully qualified class to a shorter name. Another use case is a different field name
35 for a class member. Aliases can be set for following elements:</p>
36
37 <ul>
38 <li>Class types mapped to XML tags</li>
39 <li>Package names mapped to XML tags</li>
40 <li>Field names mapped to XML tags</li>
41 <li>Internal attributes names of XStream</li>
42 </ul>
43
44 <p>The bold elements in the following example are affected:</p>
45
46 <div class="Source XML"><pre>&lt;<b>cat</b>&gt;
47 &lt;<b>age</b>&gt;4&lt;/<b>age</b>&gt;
48 &lt;<b>name</b>&gt;Garfield&lt;/<b>name</b>&gt;
49 &lt;<b>owner</b> <b>type</b>="<b>StandardPerson</b>"&gt;
50 &lt;<b>name</b>&gt;Jon Arbuckle&lt;/<b>name</b>&gt;
51 &lt;/<b>owner</b>&gt;
52 &lt;/<b>cat</b>&gt;</pre></div>
53
54 <p>Have a look at the <a href="alias-tutorial.html">Alias Tutorial</a> for examples.</p>
55
56 <!-- .................. -->
57
58 <h2 id="Configuration_Attributes">Attributes</h2>
59
60 <p>XML is quite clumsy to read for fields in separate tags that can represent their content in a short single
61 string value. In such a case attributes can help to shorten the XML and increase readability:</p>
62
63 <div class="Source XML"><pre>&lt;cat <b>age="4" name="Garfield"</b>&gt;
64 &lt;owner class="StandardPerson" <b>name="Jon Arbuckle"</b>/&gt;
65 &lt;/cat&gt;</pre></div>
66
67 <p>Attributes are also presented in the <a href="alias-tutorial.html">Alias Tutorial</a>.</p>
68
69 <!-- .................. -->
70
71 <h2 id="Configuration_OmitField">Omitted Fields</h2>
72
73 <p>For a proper deserialization XStream has to write the complete object graph into XML that is referenced by a
74 single object. Therefore XStream has to find a representation that contains all aspects to recreate the
75 objects.</p>
76
77 <p>However, some parts might be superfluous e.g. if a member field is lazy initialized and its content
78 can be easily recreated. In such a case a field can be omitted using
79 <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream.omitField(Class, String)</a>.</p>
80
81 <!-- .................. -->
82
83 <h2 id="Configuration_ImplicitCollection">Implicit Collections, Arrays and Maps</h2>
84
85 <p>Another use case are collections, arrays and maps. If a class has a field that is a one of those types, by
86 default all of its elements are embedded in an element that represents the container object itself. By
87 configuring the XStream with the
88 <a href="javadoc/com/thoughtworks/xstream/XStream.html#addImplicitCollection">XStream.addImplicitCollection()</a>,
89 <a href="javadoc/com/thoughtworks/xstream/XStream.html#addImplicitArray">XStream.addImplicitArray()</a>, and
90 <a href="javadoc/com/thoughtworks/xstream/XStream.html#addImplicitMap">XStream.addImplicitMap()</a> methods it
91 is possible to keep the elements directly as child of the class and the surrounding tag for the container object
92 is omitted. It is even possible to declare more than one implicit collection, array or map for a class, but
93 the elements must then be distinguishable to populate the different containers correctly at deserialization.</p>
94
95 <p>In the following example the Java type representing the farm may have two containers, one for cats and one
96 for dogs:</p>
97
98 <div class="Source XML"><pre>&lt;farm&gt;
99 &lt;<b>cat</b>&gt;Garfield&lt;/<b>cat</b>&gt;
100 &lt;<b>cat</b>&gt;Arlene&lt;/<b>cat</b>&gt;
101 &lt;<b>cat</b>&gt;Nermal&lt;/<b>cat</b>&gt;
102 &lt;<b>dog</b>&gt;Odie&lt;/<b>dog</b>&gt;
103 &lt;/farm&gt;</pre></div>
104
105 <p>The container might be a Collection, Array, or even a Map. In the latter case a member field of the value
106 must have been defined, that is used as key in the deserialized map.</p>
107
108 <!-- .................. -->
109
110 <h2 id="Configuration_FieldOrder">Field order</h2>
111
112 <p>XStream is delivered with a lot of <a href="converters.html">converters</a> for standard types.
113 Nevertheless most objects are processed by converters based on reflection. They will write the fields of a
114 class in the sequence they are defined. It is possible to implement an algorithm for a different sequence or
115 use an implementation that allows to define the sequence for each type separately using a
116 <a href="javadoc/com/thoughtworks/xstream/converters/reflection/FieldKeySorter.html">FieldKeySorter</a>.
117 Similar functionality exists for Java Beans with the
118 <a href="javadoc/com/thoughtworks/xstream/converters/javabean/PropertySorter.html">PropertySorter</a>.</p>
119
120 <!-- .................. -->
121
122 <h2 id="Configuration_Format">Output Format</h2>
123
124 <p>XStream writes and reads XML by default. However, the I/O layer is separated from the model and you can
125 use implementations for other formats as well. A reader/writer pair is typically managed by a <a
126 href="javadoc/com/thoughtworks/xstream/io/HierarchicalStreamDriver.html">HierarchicalStreamDriver</a>. XStream
127 is delivering additional drivers for <a href="json-tutorial.html">JSON</a> and a compact binary format (see <a
128 href="javadoc/com/thoughtworks/xstream/io/binary/BinaryStreamDriver.html">BinaryStreamDriver</a>). There are
129 also drivers to write an object graph into a DOM structure instead of a text based stream (available for W3C
130 DOM, DOM4J, JDOM, XOM, and XPP DOM).</p>
131
132 <!-- ************ -->
133
134 <h1 id="Enhancing">Enhancing XStream</h1>
135
136 <p>Sometimes customization is simply not enough to tweak the output. Depending on the use case it is fortunate to
137 use specialized converters for own types, mapper implementations that control naming of things more globally or
138 use specialized writers to influence the complete output.</p>
139
140 <!-- .................. -->
141
142 <h2 id="Specialized_Converters">Specialized Converters</h2>
143
144 <p>Not all converters that are part of the XStream package are automatically registered. Some will only make
145 sense for special types, others have parameters to tweak the behaviour and are often most effective if
146 registered as local converter only. Most useful in the table of <a href="converters.html">converters</a> are
147 the JavaBeanConverter, NamedArrayConverter, NamedCollectionConverter, NamedMapConverter, ToStringConverter, and
148 ToAttributedValueConverter. Not to mention the separate Hibernate package of XStream.</p>
149
150 <p>As example can the ToAttributedValueConverter be used to define the owner's name directly as text value:</p>
151
152 <div class="Source XML"><pre>&lt;cat age="4" name="Garfield"&gt;
153 &lt;owner class="StandardPerson"&gt;<b>Jon Arbuckle</b>&lt;/&gt;
154 &lt;/cat&gt;</pre></div>
155
156 <p>Attributes are also presented in the <a href="alias-tutorial.html">Alias Tutorial</a>.</p>
157
158 <!-- .................. -->
159
160 <h2 id="Enhancing_Converters">Custom Converters</h2>
161
162 <p>Sometimes the object to serialize contains fields or elements, that have no friendly representation for
163 human beings e.g. if a long value represents in reality a time stamp. In such cases XStream supports custom
164 converters for arbitrary types. Have a look at the <a href="converter-tutorial.html">Converter Tutorial</a>
165 for advanced possibilities. Note, that a custom converter is not different to one that is delivered by
166 XStream. It's simply your code.</p>
167
168 <!-- .................. -->
169
170 <h2 id="Enhancing_Mappers">Custom Mappers</h2>
171
172 <p>In case of global adjustments it can be helpful to implement an own mapper. A mapper is used to name things
173 and map between the name in the Java world to the name used in the XML representation. The alias mechanism
174 described above is implemented as such a mapper that can be configured. A typical use case is dropping all
175 prefixes for field names like underscores in the resulting XML or omitting the package part of class names.</p>
176
177 <p class="highlight">However, keep in mind that the algorithm must work in both directions to support deserialization.</p>
178
179 <!-- .................. -->
180
181 <h2 id="Enhancing_Name_Coder">Custom Name Coders</h2>
182
183 <p>Names used e.g. in XML for attributes and element tags might contain characters or character sequences that
184 violate the syntax of the output format. Instead of using different aliases for such names that depend on the
185 output format, you may use a NameCoder implementation that transforms an internally used name to an external
186 form. For XML we use e.g. a NameCoder that encodes '$' characters, while the one used in JSON performs no
187 operation at all.</p>
188
189 <p class="highlight">Again, keep in mind that the algorithm of the name coder must support encoding and
190 decoding of the names.</p>
191
192 <!-- .................. -->
193
194 <h2 id="Enhancing_Writer">Custom Writer</h2>
195
196 <p>A custom writer can be used to affect the output completely. XStream itself delivers solutions for different
197 use cases like the <a href="javadoc/com/thoughtworks/xstream/io/xml/CompactWriter.html">CompactWriter</a>
198 that does not insert any white spaces between the XML tags.</p>
199
200 <p>Another use case for such a writer is a wrapper to drop unwanted XML elements that XStream omits on its own.
201 Especially if the written XML is not used for deserialization it can be useful to ignore internal attributes by
202 a custom writer</p>
203
204 <!-- ************ -->
205
206 <h1 id="OwnCode">Tweaking the own implementation</h1>
207
208 <p>As shown, XStream can be configured and enhanced in multiple way, but sometimes it is easier to tweak the
209 implementation of the serialized classes:</p>
210
211 <ul>
212 <li>Declaring a field transparent will omit it automatically from the processing</li>
213 <li>Implementing a readResolve method that can be used to initialize additional fields</li>
214 <li>Usage of annotations</li>
215 </ul>
216
217 <!-- ************ -->
218
219 <h1 id="Processing">Preprocessing or postprocessing</h1>
220
221 <h2 id="Processing_XSLT">XML Transformations</h2>
222
223 <p>Never forget, you're dealing with XML! It is easy to transform XML with an XSLT. XStream is delivered with a SAXSource
224 implementation, that allows an XStream instance to be the source of a XML transformer.</p>
225
226 <h3>Example</h3>
227 <p>Look at the following stylesheet:</p>
228
229 <div class="Source XML"><pre>
230 &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
231 &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="no"/&gt;
232 &lt;xsl:template match="/cat"&gt;
233 &lt;xsl:copy&gt;
234 &lt;xsl:apply-templates select="mName"/&gt;
235 &lt;/xsl:copy&gt;
236 &lt;/xsl:template&gt;
237 &lt;/xsl:stylesheet&gt;</pre></div>
238
239 <p>It is used here to remove the age of the cat on the fly (assuming XSLT is a string with the stylesheet above):</p>
240
241 <div class="Source Java"><pre>
242 XStream xstream = new XStream();
243 xstream.alias("cat", Cat.class);
244
245 TraxSource <b>traxSource</b> = new TraxSource(new Cat(4, "Garfield"), <b>xstream</b>);
246 Writer buffer = new StringWriter();
247 Transformer transformer = TransformerFactory.newInstance().newTransformer(
248 new StreamSource(new StringReader(XSLT)));
249 transformer.transform(<b>traxSource</b>, new StreamResult(buffer));</pre></div>
250
251 <p>The result in the buffer:</p>
252
253 <div class="Source XML"><pre>&lt;cat&gt;
254 &lt;mName&gt;Garfield&lt;/mName&gt;
255 &lt;/cat&gt;</pre></div>
256
257 <h2 id="Processing_Copier">Format Conversion</h2>
258
259 <p>XStream is designed to transform Java objects into a specific format and recreate these objects again.
260 However, XStream's readers and writers are based on an event model that can be used easily to convert the pure
261 data between formats. XStream contains the <a href="javadoc/com/thoughtworks/xstream/io/copy/HierarchicalStreamCopier.html">HierarchicalStreamCopier</a>
262 tool that utilizes a reader and a writer of XStream to perform the conversion:</p>
263
264 <div class="Source Java"><pre>
265 HierarchicalStreamCopier copier = new HierarchicalStreramCopier();
266 HierarchicalStreamDriver binaryDriver = new BinaryDriver();
267 HierarchicalStreamDriver jsonDriver = new JettisonMappedXmlDriver();
268
269 // transform a org.dom4j.Document into a binary stream of XStream
270 ByteArrayOutputStream baos = new ByteArrayOutputStream();
271 copier.copy(new Dom4JDriver.createReader(dom4JDocument), binaryDriver.createWriter(baos));
272 byte[] data = baos.getBytes();
273
274 // transform binary XStream data into JSON
275 StringWriter strWriter = new StringWriter();
276 copier.copy(binaryDriver.createReader(data), jsonDriver.createWriter(strWriter));
277 String json = strWriter.toString();
278
279 // transform JSON into XML:
280 strWriter = new StringWriter();
281 copier.copy(jsonDriver.createReader(new StringReader(json)), new PrettyPrintWriter(strWriter));
282 String xml = strWriter.toString();</pre></div>
283
284 </body>
285 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Documentation</title>
14 </head>
15 <body>
16
17 <h2>Essentials</h2>
18
19 <ul>
20 <li>Uses of XStream</li>
21 <li>Architecture Overview</li>
22 </ul>
23
24 </body>
25 </html>
26 <!--
27 X * Two minute tutorial
28
29 * Essentials
30 + Uses of XStream (when to use, when not to)
31 X + Design overview
32 / + Tweaking output (alias, implicit collections)
33 * Converters
34 + What they do (include context and inheritance questions, lookup, default, implementation guidelines (threads/state))
35 + Registering a new one
36 + Creating a basic converter
37 + Creating a more complicated converter
38 + Composite converters
39 + The default converter (reflectionprovider, enhanced mode)
40 * IO
41 + Overview
42 + Drivers for convenience
43 + Document based IO: DOM, JDOM, DOM4J, ElectricXML, XOM
44 + Stream based IO: JAXP, TrAX, XPP, StAX, SAX (write only)
45 + Why no SAX reader
46 + XStream and XSLT integration
47 + Non XML
48 * Advanced usage
49 + Thread safety (reusing xstream, shared/isolated objects, dataholder)
50 + ClassLoader
51 + SecurityManagers
52 * Usage hints
53 + Configuration (serialize first)
54
55 -->
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>News</title>
14 </head>
15
16 <body>
17
18 <h2 id="1.4.8"><b>February 18, 2015</b> XStream 1.4.8 released</h2>
19
20 <p>Maintenance release 1.4.8 of XStream with bug fixes and improvements running with Java 8.</p>
21
22 <p>XStream supports now serializable lambda types for a Java 8 runtime.</p>
23
24 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
25
26 <p>Note, the next major release 1.5 will require Java 6.</p>
27
28 <h2 id="1.4.7"><b>February 8, 2014</b> XStream 1.4.7 released</h2>
29
30 <p class="highlight">This maintenance release addresses mainly the security vulnerability CVE-2013-7285, an
31 arbitrary execution of commands when unmarshalling. All previous versions are affected running at least Java 5.</p>
32
33 <p>XStream contains now a security framework to fine-control the unmarshalled types.</p>
34
35 <p>View the complete <a href="changes.html">change log</a> and <a href="download.html">download</a>.</p>
36
37 <h2 id="1.4.6"><b>December 12, 2013</b> XStream 1.4.6 released</h2>
38
39 <p>Maintenance release 1.4.6 of XStream with bug fixes and improvements running with Java 8, in a GAE runtime
40 environment and under an active SecurityManager.</p>
41
42 <p>View the complete <a href="changes.html#1.4.6">change log</a> and <a href="download.html">download</a>.</p>
43
44 <h2 id="1.4.5"><b>September 28, 2013</b> XStream 1.4.5 released</h2>
45
46 <p>Maintenance release 1.4.5 of XStream with bug fixes and small improvements.</p>
47
48 <ul>
49 <li>Allow unknown XML elements to be ignored using new method XStream.ignoreUnknownElements.</li>
50 <li>Support for JDOM2 with JDom2Driver, JDom2Reader and JDom2Writer.</li>
51 <li>Optimized XML structure for java.awt.Font.</li>
52 <li>Referencing implementation for the ClassLoader to support environments where no new ClassLoader can be
53 instantiated due to security restrictions.</li>
54 </ul>
55
56 <p>View the complete <a href="changes.html#1.4.5">change log</a> and <a href="download.html">download</a>.</p>
57
58 <h2 id="decade"><b>September 26, 2013</b> A Decade of XStream</h2>
59
60 <p>Joe Walnes made his initial commit to the XStream project at Codehaus in 26th September 2003.
61 10 years passed by and XStream celebrates its 10th birthday!</p>
62
63 <h2 id="1.4.4"><b>January 19, 2013</b> XStream 1.4.4 released</h2>
64
65 <p>Maintenance release 1.4.4 of XStream with bug fixes and small improvements.</p>
66
67 <ul>
68 <li>DateConverter supports now localized formats.</li>
69 </ul>
70
71 <p>View the complete <a href="changes.html#1.4.4">change log</a> and <a href="download.html">download</a>.</p>
72
73 <h2 id="1.4.3"><b>July 17, 2012</b> XStream 1.4.3 released</h2>
74
75 <p>Maintenance release 1.4.3 of XStream with bug fixes and small improvements. Main changes:</p>
76
77 <ul>
78 <li>Support java.util.concurrent.ConcurrentHashMap with the MapConverter.</li>
79 <li>Support for Hibernate 4 with XStream's Hibernate module as default for Java 6 or higher.</li>
80 </ul>
81
82 <p>View the complete <a href="changes.html#1.4.3">change log</a> and <a href="download.html">download</a>.</p>
83
84
85 <h2 id="1.4.2"><b>November 3, 2011</b> XStream 1.4.2 released</h2>
86
87 <p>Maintenance release 1.4.2 of XStream with bug fixes and small improvements. Main changes:</p>
88
89 <ul>
90 <li>XStream libraries can be used now directly in Android, therefore support of Java 1.4.2 has been stopped with the delivery.
91 Anyone who needs a version for Java 1.4.2 can build it easily from source, this build is still supported and part of CI.</li>
92 <li>New extended HierarchicalStreamReader interface with peekNextChild method. All XStream readers implement the new
93 interface (by Nikita Levyankov).</li>
94 <li>Special support for Collections.EMPTY_LIST, Collections.EMPTY_SET and Collections.EMPTY_MAP and collections created
95 with Collections.singletonList(), Collections.singletonSet() and Collections.singletonMap().</li>
96 <li>Support additional parameters for XStreamConverter annotation (e.g. to declare a ToAttributedValueConverter).</li>
97 </ul>
98
99 <p>View the complete <a href="changes.html#1.4.2">change log</a> and <a href="download.html">download</a>.</p>
100
101 <h2 id="1.4.1"><b>August 11, 2011</b> XStream 1.4.1 released</h2>
102
103 <p>Maintenance release 1.4.1 of XStream after turning out that it did not work in 1.4 with the new default
104 dependencies. Therefore XStream is back with Xpp3 as default parser and refers additionally the XmlPullParser
105 API to enable the XppDriver that is used by default.</p>
106
107 <p>View the complete <a href="changes.html#1.4.1">change log</a> and <a href="download.html">download</a>.</p>
108
109 <h2 id="1.4"><b>August 6, 2011</b> XStream 1.4 released</h2>
110
111 <p>Finally - XStream 1.4 is ready for delivery. A lot of things have changed and improved, new features added.
112 Nevertheless we have maintain compatibility to the old versions:</p>
113
114 <ul>
115 <li>Detection of Java 7 and Android i.e. enabled enhanced mode and annotations for both environments out of the box</li>
116 <li>Direct support of XmlPullParser factory and alternate kXML2 implementation</li>
117 <li>Explicit drivers to select the StAX implementation</li>
118 <li>New separate Hibernate module to support those managed instances (special thanks to Jaime Metcher)</li>
119 <li>Support of implicit arrays and maps additionally to already existing implicit collection support</li>
120 <li>Performance improvements (special thanks to Keith Kowalczykowski)</li>
121 <li>Some new converters (for URI and one to write all fields but one as attributes)</li>
122 <li>A lot of other enhancements and bug fixes</li>
123 </ul>
124
125 <p>View the complete <a href="changes.html#1.4">change log</a> and <a href="download.html">download</a>.</p>
126
127 <p>Thanks to this impressive list of <a href="team.html#contributors">contributors</a>.</p>
128
129 <p class="hightlight">Note, that with version 1.4 the default parser has been changed from
130 <a href="faq.html#Compatibility_kXML2">Xpp3 to kXML2</a>.</p>
131
132 <p class="hightlight">Note, that JDK 1.3 support has been officially dropped. Nothing special has been done to
133 enforce this, but there is no longer any support.</p>
134
135 <p class="highlight">Note, to support a representation of null values in some way, it is absolutely necessary that each converter can handle a null
136 value in its marshalling methods. If you have implemented your own custom converters, try to handle such a case also to prevent incompatibilities
137 in case XStream will provide such values with its next major version.</p>
138
139 <h2 id="1.3.1"><b>December 6, 2008</b> XStream 1.3.1 released</h2>
140
141 <p>A new XStream maintenance version has been released. The release contains some
142 bug fixes, some minor enhancements and support of new JDKs:</p>
143
144 <ul>
145 <li>Ability to alias package names</li>
146 <li>Converters are only registered by default for types delivered with the JDK in use preventing
147 unexpected incompatibilities</li>
148 <li>Separation between user defined attributes and XStream attributes</li>
149 <li>New mode for JSONWriter to drop JSON root node</li>
150 <li>Support for FreeBSD's Diablo JDK.</li>
151 <li>Enhanced persistence package and extended tutorial.</li>
152 </ul>
153
154 <p>View the complete <a href="changes.html#1.3.1">change log</a> and <a href="download.html">download</a>.</p>
155
156 <p class="hightlight">Note, that XStream really supports by default now only types of the JDK in use. Especially for
157 CGLIB this means that support of those proxies will have to be <a href="faq.html#Serialization_CGLIB">explicitly activated</a>
158 first. However, support for CGLIB proxies has been enhanced.</p>
159
160 <p class="highlight">Note, to support a representation of null values in some way, it is absolutely necessary that each converter can handle a null
161 value in its marshalling methods. If you have implemented your own custom converters, try to handle such a case also to prevent incompatibilities
162 in case XStream will provide such values with its next major version.</p>
163
164 <h2 id="1.3"><b>February 27, 2008</b> XStream 1.3 released</h2>
165
166 <p>The XStream committers proudly present XStream 1.3. This release contains some major
167 refactorings concerning Java annotations, improved XML support regarding encoding and
168 character sets, some minor new features, deprecations and a lot of bug fixes:</p>
169
170 <ul>
171 <li>Annotation support is now implemented as Mapper and Annotations can either be processed
172 in advance or on-the-fly (see <a href="annotations-tutorial.html#AutoDetect">Annotations tutorial</a>
173 for limitations).</li>
174 <li>Improved encoding support for JSON and XML (including automated support for XML headers).
175 Enforceable check for valid XML characters in the written stream.</li>
176 <li>Dedicated converters can now be configured for individual fields also using the XStream facade.</li>
177 <li>New converters for java.lang.StringBuilder, java.util.UUID, javax.xml.datatype.Duration,
178 and javax.swing.LookAndFeel. New generic converter for types using a java.beans.PropertyEditor.
179 Auto-instantiated SingleValueConverter for Java enums to support enum values as attributes.</li>
180 <li>XML elements are now sorted by default according their declaration with the fields defined in parent
181 classes first to improve support for type hierarchies in XML schemata.</li>
182 <li>A lot of bug fixes to improve JSON support for arbitrary types. Added section in
183 <a href="faq.html#JSON">FAQ</a> for limitations and operation modes.</li>
184 <li>Native support for SAP VM.</li>
185 <li>All text-based files are now shipped with an appropriate license header to clean-up legal issues.</li>
186 </ul>
187
188 <p>View the complete <a href="changes.html#1.3">change log</a> and <a href="download.html">download</a>.</p>
189
190 <p class="highlight">Note, to support a representation of null values in some way, it is absolutely necessary that each converter can handle a null
191 value in its marshalling methods. If you have implemented your own custom converters, try to handle such a case also to prevent incompatibilities
192 in case XStream will provide such values with its next major version.</p>
193
194 <h2 id="1.2.2"><b>May 24, 2007</b> XStream 1.2.2 released</h2>
195
196 <p>A maintenance release of XStream that contains a lot of bug fixes and has some minor highlights:
197
198 <ul>
199 <li>JSON serialization and deserialization support with the help of the new JettisonMappedXmlDriver</li>
200 <li>Supports customized field sorting</li>
201 <li>Omitting fields at deserialization time</li>
202 </ul>
203 <p>View the complete <a href="changes.html#1.2.2">change log</a> and <a href="download.html">download</a>.</p>
204
205 <p class="hightlight">Note, that next version of XStream will behave slightly different by default. XStream emits
206 all fields in declaration order like Java serialization. But in contrast to Java it will omit the fields of parent
207 classes last while Java serialization emits them first. This makes it difficult to match a given XML schema that
208 defined inherited types or leads sometimes to obscure initialization problems. However, XStream itself will not be
209 affected by the changed order of elements in the XML, any deserialization of current XML representations will work
210 fine. Anyway we will provide with XStream 1.3 a FieldKeySorter implementation that mimics the old behaviour. In
211 the meanwhile you can enforce the new field sorting by installing the NaturalFieldKeySorter.</p>
212
213 <h2 id="1.2.1"><b>November 11, 2006</b> XStream 1.2.1 released</h2>
214 <ul>
215 <li>Introduced DocumentWriter interface and generalized functionality for all writer implementations
216 creating a DOM structure (DOM4J, DOM, JDom, Xom, Xpp3Dom).</li>
217 <li>Refactor of build system to use Maven 2. Ant still supported on XStream Core.</li>
218 <li>Created separate XStream Benchmark module</li>
219 </ul>
220 <p>View the complete <a href="changes.html#1.2.1">change log</a> and <a href="download.html">download</a>.</p>
221
222 <h2 id="project-lead-joehni"><b>Oct 10, 2006</b>Joe Walness announcing new XStream Project Lead</h2>
223 <p>I have been the XStream project lead, since it was open sourced 3 years ago. In that time, it has attracted some
224 excellent developers who have formed the foundations of the user community, made all kinds of significant improvements
225 and pushed out new releases. It's now approaching its 1000th commit.</p>
226
227 <p>The development community that has formed around XStream has been outstanding - more than I could ever have
228 imagined. In particular, the following people have invested a lot of time into XStream, both from a technical and social point of
229 view:</p>
230 <ul>
231 <li>J&ouml;rg Schaible</li>
232 <li>Mauro Talevi</li>
233 <li>Guilherme Silveira</li>
234 <li>Jason van Zyl</li>
235 <li>Me (well I have!)</li>
236 </ul>
237
238 <p>Recently I have been turning my attention to other things and XStream has been very much a self sustaining project. I've
239 decided that the project would benefit from have a project lead who can invest a lot more time than I can currently offer.</p>
240
241 <p>So, the new XStream project lead will be J&ouml;rg Schaible, who along with Mauro Talevi and Guilherme Silveira will carry
242 XStream forward. This has been happening for a long while anyway, it's just none of us ever realised or acknowledged it.</p>
243
244 <p>Of course, I'll still be lurking around, helping the transition, having loud mouth opinions and generally annoying people in any
245 way I can... you haven't got rid of me that easily. ;) </p>
246
247 <p>I know J&ouml;rg, Mauro and Guilherme will be able carry XStream into the next generation (we have a lot of ambitious plans
248 for XStream 2).</p>
249
250 <p>I'd also like to thank the 45(!) other <a href="team.html">contributers</a> to the XStream project, who have all helped
251 make it what it is today. Finally, thanks to Graham Glass, who's Electric XML library formed a lot of the inspiration for XStream.</p>
252
253 <h2 id="1.2"><b>August 18, 2006</b> XStream 1.2 released</h2>
254 <ul>
255 <li>Using attributes for fields (contributed by Paul Hammant and Ian Cartwright).</li>
256 <li>Aliasing of arbitrary attributes.</li>
257 <li>XStream can now serialize another XStream instance.</li>
258 <li>XStream has now the XStreamer, that serializes an object together with its XStream instance.</li>
259 <li>AnnotationConverter for fields (contributed by Guilherme Silveira).</li>
260 <li>PureJavaReflectionProvider supports now final fields starting with JDK 1.5</li>
261 <li>Any Collection type can now be declared implicit, the default implementation will be respected for unmarshalling.</li>
262 <li>XStream can now write all references as absolute XPath expression.</li>
263 <li>New SingeValueConverter allows light weight converters if the value can be represented by a unique string.</li>
264 <li>Aliasing of classes of a specific type.</li>
265 <li>Support for certain types of proxies generated with the CGLIB Enhancer.</li>
266 <li>Support for BEA JRockit starting with R25.1.0 (contributed by Henrik St&aring;hl of BEA).</li>
267 <li>Experimental binary reader and writer.</li>
268 <li>Experimental HierarichicalStreamCopier allows streams to be copied from one format to another without the overhead of serialization.</li>
269 <li>Experimental JSON support allows streams to be copied from one format to another without the overhead of serialization (contributed by Paul Hammant).</li>
270 </ul>
271 <p>View the complete <a href="changes.html#1.2">change log</a> and <a href="download.html">download</a>.</p>
272
273 <h2 id="1.1.3"><b>January 13, 2006</b> XStream 1.1.3 released</h2>
274 <ul>
275 <li>Added XStream.toXML(OutputStream) and XStream.fromXML(InputStream).</li>
276 <li>Ability to prevent fields from being serialized by calling XStream.omitField() or by implementing Mapper.shouldSerializeMember().</li>
277 <li>Added Converter for Enum, EnumMap and EnumSet</li>
278 <li>Added BeanConverter and ISO8601SqlTimestampConverter</li>
279 <li>Fixed support for IBM JVM (contributed by Gabor Liptak)</li>
280 <li>Enhanced mode support for Blackdown JDK.</li>
281 </ul>
282 <p>View the complete <a href="changes.html#1.1.3">change log</a> and <a href="download.html">download</a>.</p>
283
284 <h2 id="1.1.2"><b>April 30, 2005</b> XStream 1.1.2 released</h2>
285 <p>Most popular feature requests implemented.</p>
286 <ul>
287 <li>Java 5 Enum support.</li>
288 <li>JavaBeanConverter for serialization using getters and setters.</li>
289 <li>Aliasing of fields.</li>
290 <li>StAX integration, with namespaces.</li>
291 <li>Improved support on JDK 1.3 and IBM JDK.</li>
292 </ul>
293 <p>View the complete <a href="changes.html#1.1.2">change log</a> and <a href="download.html">download</a>.</p>
294
295 <h2 id="1.1.1"><b>March 7, 2005</b> XStream 1.1.1 released</h2>
296 <ul>
297 <li>Converters can be registered with a priority, allowing more <i>generic</i> filters to handle classes that don't have more specific converters.</li>
298 <li>Converters can now access underlying HierarchicalStreamReader/Writer implementations to make implementation specific calls.</li>
299 <li>Improved support for classes using ObjectInputFields and ObjectInputValidation to follow the serialization specification.</li>
300 <li>Default ClassLoader may be changed using XStream.setClassLoader().</li>
301 <li>Many bugfixes and performance enhancements.</li>
302 </ul>
303 <p>View the complete <a href="changes.html#1.1.1">change log</a> and <a href="download.html">download</a>.</p>
304
305 <h2 id="1.1"><b>January 15, 2005</b> XStream 1.1 released</h2>
306 <ul>
307 <li>Improved support for serializing objects as per the <a href="http://java.sun.com/j2se/1.4.2/docs/guide/serialization/spec/serialTOC.html">Java Serialization</a> Specification:
308 <ul>
309 <li>Calls custom serialization methods, readObject(), writeObject(), readResolve() and writeReplace() in class, if defined.</li>
310 <li>Supports ObjectInputStream.getFields() and ObjectOutputStream.putFields() in custom serialization.</li>
311 </ul></li>
312 <li>Provides implementations of ObjectInputStream and ObjectOutputStream, allowing drop in replacements for standard serialization,
313 including support for streams of objects. [<a href="objectstream.html">More...</a>]</li>
314 <li>Reads and writes directly to most XML Java APIs: DOM, DOM4J, JDOM, XOM, Electric XML, StAX, Trax (write only), SAX (write only).
315 [<a href="javadoc/com/thoughtworks/xstream/io/xml/package-summary.html">More...</a>]</li>
316 </ul>
317 <p>View the complete <a href="changes.html#1.1">change log</a> and <a href="download.html">download</a>.</p>
318
319 </body>
320 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Object Streams Tutorial</title>
14 <style type="text/css">.highlight {}</style>
15 </head>
16 <body>
17
18 <p>XStream provides alternative implementations of <code>java.io.ObjectInputStream</code> and
19 <code>java.io.ObjectOutputStream</code>,
20 allowing streams of objects to be serialized or deserialized from XML.</p>
21 <p>This is useful when processing large sets of objects, as only one needs to be in memory
22 at a time.</p>
23 <p>Obviously you should use also a stream-based XML parser reading the XML. A DOM-based XML parser
24 will process the complete XML and build the object model before XStream is able to to handle the first
25 element.</p>
26
27 <!-- ************ -->
28
29 <h1 id="using">Using the Object Streams</h1>
30
31 <p>The interface to the object streaming capabilities of XStream is through the standard
32 <code>java.io.ObjectOutputStream</code> and <code>java.io.ObjectInputStream</code> objects.</p>
33
34 <h2>Example</h2>
35
36 <p>To serialize a stream of objects to XML:</p>
37
38 <div class="Source Java"><pre>ObjectOutputStream out = xstream.createObjectOutputStream(someWriter);
39
40 out.writeObject(new Person("Joe", "Walnes"));
41 out.writeObject(new Person("Someone", "Else"));
42 out.writeObject("hello");
43 out.writeInt(12345);
44
45 out.close();</pre></div>
46
47 <p>The resulting XML:</p>
48
49 <div class="Source XML"><pre>&lt;object-stream&gt;
50 &lt;com.blah.Person&gt;
51 &lt;firstname&gt;Joe&lt;/firstname&gt;
52 &lt;lastname&gt;Walnes&lt;/lastname&gt;
53 &lt;/com.blah.Person&gt;
54 &lt;com.blah.Person&gt;
55 &lt;firstname&gt;Someone&lt;/firstname&gt;
56 &lt;lastname&gt;Else&lt;/lastname&gt;
57 &lt;/com.blah.Person&gt;
58 &lt;string&gt;hello&lt;/string&gt;
59 &lt;int&gt;123&lt;/int&gt;
60 &lt;/object-stream&gt;</pre></div>
61
62 <p>To deserialze the stream of objects from the XML:</p>
63
64 <div class="Source Java"><pre>ObjectInputStream in = xstream.createObjectInputStream(someReader);
65
66 Person a = (Person)in.readObject();
67 Person b = (Person)in.readObject();
68 String c = (String)in.readObject();
69 int d = in.readInt();</pre></div>
70
71 <!-- ************ -->
72
73 <h1 id="considerations">Considerations</h1>
74
75 <h2>Root node</h2>
76
77 <p>Because an XML document can only have a single root node, all the serialized elements must be wrapped in an
78 additional root node. This root node defaults to <code>&lt;object-stream&gt;</code>, as shown in the example above.</p>
79
80 <p>This can be changed by using the overloaded method:
81 <code>xstream.createObjectOutputStream(Writer writer, String rootNodeName);</code></p>
82
83 <h2>Close the ObjectOutputStream</h2>
84
85 <p>Remember to call <code>ObjectOutputStream.close()</code>, otherwise the stream will contain incomplete XML.</p>
86
87 <h2>Detecting the end of the ObjectInputStream</h2>
88
89 <p>When there are no more objects left to read in the stream, <code>ObjectInputStream.readObject()</code> (or primitive
90 equivalent) will throw <code>java.io.EOFException</code>.</p>
91
92 <h2>References</h2>
93
94 <p>Normally XStream will not know about references between the different objects that are written individually in the ObjectStream.
95 Nevertheless there is an example in the acceptance tests (MultipleObjectsInOneStreamTest) where such a functionality is realized with
96 the help of a custom MarshallingStrategy. Note, that this implementation is not for general use, since it will ignore some parameters at
97 second invocation, but they do not matter in the demonstrated use case. Additionally those references prevent the objects from being
98 garbage collected, which is a bit counter-productive for the use case of ObjectStreams as described above. So you have to know what
99 you do!</p>
100
101 </body>
102 </html>
0 <html>
1 <!--
2 Copyright (C) 2009, 2011 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 03. May 2009 by Joerg Schaible
10 -->
11 <head>
12 <title>Parser Benchmarks</title>
13 <style type="text/css">
14 #content td { text-align: right;}
15 #content dt { font-weight: bold;}
16 </style>
17 </head>
18
19 <body>
20 <p>Benchmark results are always dependent on a very individual setup. Normally it is not useful to generalize such results
21 for every use case, but it can give you a hint. However, if you're really in the need of maximum performance, you should
22 probably create an own benchmark with your objects or even use a profiler to detect the real hot spots in your application.</p>
23
24 <h2 id="values">Benchmark Values</h2>
25
26 <table summary="Benchmark for all XML parsers supported by XStream using different converter types">
27 <tr>
28 <th>Parser</th>
29 <th>Single Value Converters</th>
30 <th>Standard Converters</th>
31 <th>Reflection Converter</th>
32 <th>Serializable Converter</th>
33 </tr>
34 <tr>
35 <th>W3C DOM</th>
36 <td>1823.0</td>
37 <td>1495.0</td>
38 <td>1437.0</td>
39 <td>1758.0</td>
40 </tr>
41 <tr>
42 <th>JDOM</th>
43 <td>2620.0</td>
44 <td>1796.0</td>
45 <td>1776.0</td>
46 <td>2030.0</td>
47 </tr>
48 <tr>
49 <th>DOM4J</th>
50 <td>1824.0</td>
51 <td>1811.0</td>
52 <td>2636.0</td>
53 <td>2177.0</td>
54 </tr>
55 <tr>
56 <th>XOM</th>
57 <td>571.0</td>
58 <td>716.0</td>
59 <td>995.0</td>
60 <td>958.0</td>
61 </tr>
62 <tr>
63 <th>StAX (BEA)</th>
64 <td>430.0</td>
65 <td>359.0</td>
66 <td>531.0</td>
67 <td>737.0</td>
68 </tr>
69 <tr>
70 <th>StAX (Woodstox)</th>
71 <td>357.0</td>
72 <td>344.0</td>
73 <td>535.0</td>
74 <td>725.0</td>
75 </tr>
76 <tr>
77 <th>StAX (SJSXP)</th>
78 <td>332.0</td>
79 <td>445.0</td>
80 <td>491.0</td>
81 <td>667.0</td>
82 </tr>
83 <tr>
84 <th>XPP (Xpp3)</th>
85 <td>351.0</td>
86 <td>395.0</td>
87 <td>544.0</td>
88 <td>743.0</td>
89 </tr>
90 <tr>
91 <th>XPP (kXML2)</th>
92 <td>299.0</td>
93 <td>353.0</td>
94 <td>517.0</td>
95 <td>761.0</td>
96 </tr>
97 <tr>
98 <th>XppDom (Xpp3)</th>
99 <td>351.0</td>
100 <td>395.0</td>
101 <td>544.0</td>
102 <td>743.0</td>
103 </tr>
104 <tr>
105 <th>XppDom (kXML2)</th>
106 <td>299.0</td>
107 <td>353.0</td>
108 <td>517.0</td>
109 <td>761.0</td>
110 </tr>
111 </table>
112
113 <h2 id="setup">Setup</h2>
114
115 <p>The values have been generated running the ParserBenchmark harness of the XStream benchmark module's test code.</p>
116
117 <dl>
118 <dt>Single Value Converters</dt>
119 <dd>A list with a set of 10 objects of different types (like String, int, File, Locale, Double, ...) that will
120 be all handled by a SingleValueConverter.</dd>
121 <dt>Standard Converters</dt>
122 <dd>A list with a set of 6 objects of different types (like Properties, Color, Class, Method, ...) that will
123 be all handled by a specialized converter processing nested XML elements.</dd>
124 <dt>Reflection Converter</dt>
125 <dd>A list with a set of 6 objects of different types (One, Five of the XStream benchmark package) that will be
126 all handled by the ReflectionConverter.</dd>
127 <dt>Serializable Converter</dt>
128 <dd>A list with a set of 6 objects of different types (SerializableOne, SerializableFive of the XStream
129 benchmark package) that will be all handled by the SerializableConverter.</dd>
130 <dt>JavaBean Converter</dt>
131 <dd>A list with a set of 6 objects of different types (OneBean, FiveBean of the XStream benchmark package) that
132 will be all handled by the JavaBeanConverter. This converter has been registered especially for this two types.</dd>
133 </dl>
134
135 <h2 id="environment">Environment</h2>
136
137 <p>The values above's unit is ms measured after 1000 unmarshalling operations with the object graphs described in
138 the setup using XStream 1.4. The benchmark was run on an AMD Athlon with 2.1GHz running a JVM of Sun JDK 1.6.0_13
139 (32-bit) in Gentoo Linux. Note again, that these values are no replacement for real profiler results and they may
140 vary from run to run for ~100ms due to this machine's background processes on a single CPU. However, it can give
141 you some idea of what you can expect using different parser technologies.</p>
142 </body>
143 </html>
144
0 <html>
1 <!--
2 Copyright (C) 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 28. July 2006 by Guilherme Silveira
11 -->
12 <head>
13 <title>Persistence API Tutorial</title>
14 </head>
15 <body>
16 <h2 id="challenge">Challenge</h2>
17 <p>Suppose that you need a easy way to persist some objects in the file system. Not just one, but a whole collection.
18 The real problem arrives when you start using java.io API in order to create one output stream for each object, showing
19 itself to be really painful - although simple.</p>
20 <p>Imagine that you have the following Java class, a basic Author class (stolen from some other tutorial):</p>
21 <div class="Source Java"><pre>package com.thoughtworks.xstream;
22
23 public class Author {
24 private String name;
25 public Author(String name) {
26 this.name = name;
27 }
28 public String getName() {
29 return name;
30 }
31 }</pre></div>
32 <p>By using the XmlArrayList implementation of java.util.List you get an easy way to write all authors to disk</p>
33 <p>The XmlArrayList (and related collections) receives a PersistenceStrategy during its construction. This Strategy decides
34 what to do with each of its elements. The basic implementation - our need - is the FilePersistenceStrategy, capable of
35 writing different files to a base directory.</p>
36 <div class="Source Java"><pre>
37 // prepares the file strategy to directory /tmp
38 PersistenceStrategy strategy = new FilePersistenceStrategy(new File("/tmp"));
39 </pre></div>
40 <p>We can easily create an XmlArrayList from that strategy:</p>
41 <div class="Source Java"><pre>
42 // prepares the file strategy to directory /tmp
43 PersistenceStrategy strategy = new FilePersistenceStrategy(new File("/tmp"));
44 // creates the list:
45 List list = new XmlArrayList(strategy);
46 </pre></div>
47 <h2 id="adding-elements">Adding elements</h2>
48 <p>Now that we have an XmlArrayList object in our hands, we are able to add, remove and search for objects as usual.
49 Let's add five authors and play around with our list:</p>
50 <div class="Source Java"><pre>package org.codehaus.xstream.examples;
51
52 public class AddAuthors {
53
54 public static void main(String[] args) {
55
56 // prepares the file strategy to directory /tmp
57 PersistenceStrategy strategy = new FilePersistenceStrategy(new File("/tmp"));
58 // creates the list:
59 List list = new XmlArrayList(strategy);
60
61 // adds four authors
62 list.add(new Author("joe walnes"));
63 list.add(new Author("joerg schaible"));
64 list.add(new Author("mauro talevi"));
65 list.add(new Author("guilherme silveira"));
66
67 // adding an extra author
68 Author mistake = new Author("mama");
69 list.add(mistake);
70
71 }
72 }
73 </pre></div>
74 <p>If we check the /tmp directory, there are five files: int@1.xml, int@2.xml, int@3.xml, int@4.xml, int@5.xml, each
75 one containing the XML serialized form of our authors.</p>
76 <h2 id="playing">Playing around</h2>
77 <p>Let's remove mama from the list and iterate over all authors:</p>
78 <div class="Source Java"><pre>package org.codehaus.xstream.examples;
79
80 public class RemoveMama {
81
82 public static void main(String[] args) {
83
84 // prepares the file strategy to directory /tmp
85 PersistenceStrategy strategy = new FilePersistenceStrategy(new File("/tmp"));
86 // looks up the list:
87 List list = new XmlArrayList(strategy);
88
89 // remember the list is still there! the files int@[1-5].xml are still in /tmp!
90 // the list was persisted!
91
92 for(Iterator it = list.iterator(); it.hasNext(); ) {
93 Author author = (Author) it.next();
94 if(author.getName().equals("mama")) {
95 System.out.println("Removing mama...");
96 it.remove();
97 } else {
98 System.out.println("Keeping " + author.getName());
99 }
100 }
101
102 }
103 }
104 </pre></div>
105 <p>The result?</p>
106 <div class="Source Java"><pre>Keeping joe walnes
107 Keeping joerg schaible
108 Keeping mauro talevi
109 Keeping guilherme silveira
110 Removing mama...
111 </pre></div>
112 <h2 id="converter">Local Converter</h2>
113 <p>Another use case is to split the XML into master/detail documents by declaring a local converter for a collection
114 (or map) based on the collection types in XStream's persistence package. Think about a volume grouping different type of documents:</p>
115 <div class="Source Java"><pre>public abstract class AbstractDocument {
116 String title;
117 }
118 public class TextDocument extends AbstractDocument {
119 List chapters = new ArrayList();
120 }
121 public class ScannedDocument {
122 List images = new ArrayList();
123 }
124 public Volume {
125 List documents = new ArrayList();
126 }
127 </pre></div>
128 <p>The documents might be big (especially the ones with the scanned pages), therefore it might be nice to separate each
129 document into an own file. With the help of a local converter utilizing an XmlArrayList this is straight forward:</p>
130 <div class="Source Java"><pre>public final class PersistenceArrayListConverter implements Converter {
131 private XStream xstream;
132
133 public PersistenceArrayListConverter(XStream xstream) {
134 this.xstream = xstream;
135 }
136
137 public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
138 File dir = new File(System.getProperty("user.home"), "documents");
139 XmlArrayList list = new XmlArrayList(new FilePersistenceStrategy(dir, xstream));
140 context.convertAnother(dir);
141 list.addAll((Collection)source); // generate the external files
142 }
143
144 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
145 File directory = (File)context.convertAnother(null, File.class);
146 XmlArrayList persistentList = new XmlArrayList(new FilePersistenceStrategy(directory, xstream));
147 ArrayList list = new ArrayList(persistentList); // read all files
148 persistentList.clear(); // remove files
149 return list;
150 }
151
152 public boolean canConvert(Class type) {
153 return type == ArrayList.class;
154 }
155 }
156 </pre></div>
157 <p>This converter will use a given XStream to store each element of an ArrayList into an own file located in the user's home
158 directory in the folder <em>documents</em>. The <em>master</em> XML will now contain the name of the target folder
159 instead of the marshalled documents. In our case those documents are destroyed if the volume is unmarshalled again. See the
160 initialization of the XStream:</p>
161 <div class="Source Java"><pre>XStream = new XStream();
162 xstream.alias("volume", Volume.class);
163 xstream.registerLocalConverter(Volume.class, "documents", new PersistenceArrayListConverter(xstream));
164
165 Volume volume = new Volume();
166 volume.documents.addAll(...); // add a lot of documents
167 String xml = xstream.toXML(volume);
168 </pre></div>
169 <p>The resulting XML will be very simple:</p>
170 <div class="Source XML"><pre>&lt;volume&gt;~/documents&lt;/volume&gt;
171 </pre></div>
172 <p>The documents can be found in individual files in the target folder with names like <em>int@&lt;index&gt;.xml</em>.</p>
173
174 <h2 id="further">Going further</h2>
175 <p>From this point on, you can implement different PersistentStrategy algorithms in order to generate other behaviour (e.g.
176 persisting the objects in a database) using your XmlArrayList collection, or try the other implementations: XmlSet and XmlMap
177 and you may create your own local converters. As an alternative to a converter you might use the persistent collection type
178 directly as member instance, the effect is similar - give it a try!</p>
179
180 <p>See also <a href="http://code.google.com/p/xbird/">XBird</a> that makes usage of this XStream API to support object
181 persistence.</p>
182
183 </body>
184 </html>
0 <html>
1 <!--
2 Copyright (C) 2006, 2007, 2008, 2009, 2011 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 17. November 2006 by Joerg Schaible
10 -->
11 <head>
12 <title>References</title>
13 </head>
14 <body>
15
16 <p>XStream is used in a lot of commercial and open source projects and is used in production since years.</p>
17
18 <!-- ************ -->
19
20 <h1 id="core-tech">XStream used for Core Technology</h1>
21
22 <h2 id="bamboo">Atlassian Bamboo</h2>
23
24 <p><a href="http://www.atlassian.com/software/bamboo/">Bamboo</a> is build server for continuous integration
25 and release management. Note, XStream itself uses <a href="http://bamboo.ci.codehaus.org/browse/XSTREAM">Bamboo
26 at Codehaus</a> for continuous integration.</p>
27
28 <h2 id="confluence">Atlassian Confluence</h2>
29
30 <p><a href="http://www.atlassian.com/software/confluence/">Confluence</a> is an enterprise wiki that makes it
31 easy for your team to collaborate and share knowledge.</p>
32
33 <h2 id="confluence">Oracle Hudson CI</h2>
34
35 <p><a href="http://www.atlassian.com/software/confluence/">Hudson CI</a> is also a build server for continuous
36 integration and release management.</p>
37
38 <h2 id="muse">Apache Muse</h2>
39
40 <p>The <a href="http://ws.apache.org/muse">Apache Muse Project</a> is a Java-based implementation of the
41 WS-ResourceFramework (<a href="http://www.oasis-open.org/committees/wsrf">WSRF</a>),
42 WS-BaseNotification (<a href="http://www.oasis-open.org/committees/wsn">WSN</a>), and
43 WS-DistributedManagement (<a href="http://www.oasis-open.org/committees/wsdm">WSDM</a>) specifications.
44 It is a framework upon which users can build web service interfaces for manageable resources without having to
45 implement all of the "plumbing" described by the aforementioned standards. Applications built with Muse can be
46 deployed in both Apache Axis2 and OSGi environments, and the project includes a set of command line tools that
47 can generate the proper artifacts for your deployment scenario.</p>
48
49 <h2 id="nanocontainer">NanoContainer</h2>
50
51 <p>The scope of the <a href="http://www.nanocotnainer.org">NanoContainer</a> project is to complement the
52 <a href="http://www.picocontainer.org">PicoContainer</a> project, providing it with additional functionality. The
53 project comprises of several components which can either be adoptions in various guises of PicoContainer (e.g.
54 composition by-class-name rather than by-class), or adaptations to external components bringing them closer to the
55 <a href="http://docs.codehaus.org/display/PICO/Dependency+Injection">Dependency Injection</a> ideal - particularly
56 <a href="http://docs.codehaus.org/display/PICO/Constructor+Injection">Constructor Injection</a>.</p>
57
58 <h2 id="murq">Murq</h2>
59
60 <p><a href="http://murq.binaryfantasy.com">Murq</a> is a persistence framework with an emphasis on simplicity.
61 It is also capable of storing binary data and meta data, supports search functionality and makes internationalization
62 seamless.</p>
63
64 <h2 id="xbird">XBird</h2>
65
66 <p><a href="http://code.google.com/p/xbird/">XBird</a> is a light-weight XQuery processor and database system
67 written in Java. The light-weight means reasonably fast and embeddable. It uses the
68 <a href="persistence-tutorial.html">XStream persistence API</a> for
69 <a href="http://code.google.com/p/xbird/wiki/XmlObjectBinding">object persistence</a></p>
70
71 <h2 id="ejoe">EJOE</h2>
72
73 <p><a href="http://ejoe.sourceforge.net/">EJOE</a> is a lightweight Java remoting framework built to send
74 and receive objects through pluggable (de)serialization mechanisms. XStream provides the
75 <a href="http://ejoe.sourceforge.net/035/faq.html#how-serialize">default (de)serialization mechanism</a>.</p>
76
77 <h2 id="opencraft">OpenCraft</h2>
78
79 <p><a href="http://opencraft.sourceforge.net/">OpenCraft</a> is an alternative/custom Minecraft server, written
80 in Java, compatible with the original protocol. XStream provides the persistence layer.</p>
81
82 <h1 id="support">XStream Support</h1>
83
84 <h2 id="jbossesb">jBoss ESB</h2>
85
86 <p><a href="http://www.jboss.org/jbossesb">jBossESB</a> is the next generation of EAI - better and without the
87 vendor-lockin characteristics of old. It uses a flexible architecture based on SOA principles such as loose-coupling
88 and asynchronous message passing, emphasizing an incremental approach to adopting and deploying an SOI. XStream
89 can be used as one possibility for the messaging part.</p>
90
91 <h2 id="restlet">Restlet</h2>
92
93 <p><a href="http://www.restlet.org/docs_2.0">Restlet</a> is a lightweight REST framework for Java that lets you embrace
94 the architecture of the Web and benefit from its simplicity and scalability. By leveraging our innovative REST engine,
95 you can start blending your Web Sites and Web Services into uniform Web Applications!</p>
96
97 <p>The framework uses <a href="http://www.restlet.org/docs_2.0/13-restlet/28-restlet/264-restlet.html">XStream as
98 extension</a> for a representation of objects in XML or JSON and a ConverterService based on this functionality.</p>
99
100 <h2 id="activesoap">ActiveSOAP</h2>
101
102 <p><a href="http://activesoap.codehaus.org">ActiveSOAP</a> is a lightweight &amp; easily embeddable
103 <a href="http://activesoap.codehaus.org/REST">REST</a> and SOAP stack based on
104 <a href="http://activesoap.codehaus.org/StAX">StAX</a> with support for
105 <a href="http://activesoap.codehaus.org/WS-Addressing">WS-Addressing</a> and
106 <a href="http://activesoap.codehaus.org/WSIF">WSIF</a>. ActiveSOAP uses StAX (the Standard API for pull parsing)
107 to implement the SOAP protocols and then it delegates to plugin
108 <a href="http://activesoap.codehaus.org/maven/apidocs/org/codehaus/activesoap/Handler.html">Handler</a> objects
109 for the heavy duty processing of the XML payloads. This means that you only need to pay for what you need; use fast
110 pull based event parsing or full data binding mechanisms like JAXB or XStream or DOMish APIs like XMLBeans when they
111 make sense.</p>
112
113 <h2 id="mule">Mule</h2>
114
115 <p><a href="http://mule.codehaus.org">Mule</a> is the leading open source ESB (Enterprise Service Bus) and integration
116 platform. It is a scalable, highly distributable object broker that can seamlessly handle interactions with services and
117 applications using disparate transport and messaging technologies. Transformers are used to convert inbound data to an
118 object type required by the UMO Component or outbound to an object type required by the transport such as a JmsMessage.
119 Mule uses <a href="http://mule.codehaus.org/display/MULE/Transformers">Transformers</a> to convert event data between
120 the different endpoints. They can be configured on endpoints that receive data to ensure that the expected object type is
121 always received by a Mule Component. XStream is used for standard XML to Java object transformation.</p>
122
123 <h2 id="blojsom">Blojsom</h2>
124
125 <p><a href="http://wiki.blojsom.com">Blojsom</a> is Java-based, full-featured, multi-blog, multi-user software package
126 that was inspired by blosxom. blojsom aims to retain a simplicity in design while adding flexibility in areas such as the flavors,
127 templating, plugins, and the ability to run multiple blogs with a single blojsom installation. XStream is used for export.</p>
128
129 <h2 id="flattree">FlatTree</h2>
130
131 <p><a href="http://flattree.sourceforge.net/adapters.html#XStream">FlatTree</a> is a Java library for reading and
132 writing of flat files: CSV, FLR (fixed length record) or mixed structures. It features a tree-style processing API, adapters
133 for SAX, Stax and <a href="http://flattree.sourceforge.net/adapters.html#XStream">XStream</a> for transformation,
134 data binding or serialization.</p>
135
136 <h1 id="blogs">Blogs and Articles</h1>
137
138 <ul>
139 <li>November 11th, 2011: <a href="http://www.wappworks.com/2011/11/11/using-xstream-with-google-app-engine/">Using XStream with Google App Engine</a> by Chris Khoo</li>
140 <li>January 22th, 2010: <a href="http://www.openscope.net/2010/01/22/java-xml-and-xstream/">Java, XML and XStream</a> by Antonio Gonzalez</li>
141 <li>September 1st, 2009: <a href="http://www.ibm.com/developerworks/java/library/x-xstrmfo/index.html">Generate PDFs with XStream and XSL-FO</a> by Brian J. Stewart</li>
142 <li>January 13th, 2009: [German article] <a href="http://www.zdnet.de/anwendungsentwicklung_mit_xstream_lassen_sich_objekte_einfach_und_schnell_serialisieren_story-20000201-39201013-1.htm">Mit XStream lassen sich Objekte einfach und schnell serialisieren</a> by David Petersheim</li>
143 <li>April 8th, 2008: <a href="http://www.ibm.com/developerworks/java/library/x-xstream/index.html">Use XStream to serialize Java objects into XML</a> by Rajiv Bangalore (updated on July 23th, 2008)</li>
144 <li>February 12th, 2008: <a href="http://www.ibm.com/developerworks/library/x-restfulsoa/">RESTful SOA using XML</a> by Adriaan de Jonge</li>
145 <li>February 7th, 2007: <a href="http://codeforfun.wordpress.com/2007/02/07/to-the-xstream/">To the XStream</a> by Cliff</li>
146 <li>May 21th, 2006: <a href="http://paulhammant.com/blog/xstream-json.html">Inversionism by Paul Hammant: <i>Using XStream to forward JSON to a browser</i></a></li>
147 <li>May 21th, 2006: <a href="http://paulhammant.com/blog/xstream-rss.html">Inversionism by Paul Hammant: <i>Using XStream to process standardized XML documents</i></a></li>
148 <li>May 12th, 2006: <a href="http://www.infoq.com/articles/REST-INTEROP">Paul Hammant and Ian Cartwright: <i>Simple JAVA and .NET SOA interoperability</i></a></li>
149 <li>January 30th, 2006: <a href="http://www.j2eegeek.com/blog/2006/01/30/life-is-beautiful-with-xmlbeans-and-xstream/">Vinny Carpenter's Blog: <i>Life is beautiful with XMLBeans and XStream</i></a></li>
150 <li>September 15th, 2005: <a href="http://weblogs.java.net/blog/scottschram/archive/2005/09/the_xstream_lib.html">Scott Schram's Blog: <i>The XStream library offers clean, easy XML serialization of POJOs.</i></a></li>
151 <li>August 5th, 2005: <a href="http://entzi.blogspot.com/2005/08/xstream-jdk15-annotations.html">Emil Kirschner: <i>xstream &amp; jdk 1.5 annotations</i></a></li>
152 <li>April 27th, 2005: <a href="http://www.jroller.com/CoBraLorD/entry/net_transparent_xml_serialization_xstream">Arne Vandamme's weblog: <i>.NET: transparent XML serialization, XStream for .NET</i></a></li>
153 <li>December 18th, 2004: <a href="http://jroller.com/page/rickard/20041218">Random Thoughts by Rickard &Ouml;berg: <i>XStream + Xindice = !</i></a></li>
154 <li>August 19th, 2004: <a href="http://www.theserverside.com/news/thread.tss?thread_id=28187">TheServerSide.com by Dion Almaer: <i>Serializing Java Objects with XStream</i></a></li>
155 <li>August 18th, 2004: <a href="http://www.xml.com/lpt/a/1462">XML.com by Michael Fitzgerald: <i>Serializing Java Objects with XStream</i></a></li>
156 <!--
157 <li>June 4th, 2004: <a href="http://uppertank.net/blog/?p=72">Elliot's Nonsense: <i>Deserializing with XStream</i></a></li>
158 <li>June 4th, 2004: <a href="http://blog.rossmason.com/archives/2004/06/three_reasons_why_i_like_xstream.html">Ross Mason: <i>Three Reasons why I like XStream</i></a></li>
159 -->
160 <li>Mai 14th, 2004: <a href="http://www.theserverside.com/news/thread.tss?thread_id=25923">TheServerSide.com by Joe Walnes: <i>XStream: Java to XML serialization, and back again</i></a></li>
161 </ul>
162
163 </body>
164 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2010, 2011 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Source Repository</title>
14 </head>
15 <body>
16
17 <h2 id="modules">Modules</h2>
18
19 XStream project consists of several modules:
20 <ol>
21 <li>xstream - the core module</li>
22 <li>xstream-benchmark - the benchmark tool</li>
23 <li>xstream-distribution - the module contains the documentation and assembles the src and bin distributions</li>
24 </ol>
25 When you checkout the trunk you'll get all the modules, but you can just add the module you are interested in to the URL, e.g.
26 <div class="Source"><pre>svn co http://svn.codehaus.org/xstream/trunk/[module]</pre></div>
27 to checkout out the single module separately.
28
29 <h2 id="browser">Browser</h2>
30
31 <p>You can use the browser to navigate within the sources <a href="http://fisheye.codehaus.org/browse/xstream/trunk/">online</a>
32 with the help of the FishEye installation on Codehaus.</p>
33
34 <h2 id="subversion">Subversion</h2>
35
36 XStream uses Subversion as the SCM. See <a href="http://subversion.apache.org">Subversion website</a> for details and documentation on IDE integration.
37
38 <h2 id="webdav">WebDav Access</h2>
39
40 WebDav is an access protocol supported by SVN and being http-based is often allowed by corporate firewalls.
41
42 <h3 id="webdav-anon">Anonymous Access</h3>
43
44 <div class="Source"><pre>svn co http://svn.codehaus.org/xstream/trunk</pre></div>
45
46 <p>
47 You might also use this URL to <a href="http://svn.codehaus.org/xstream/trunk">browse the repository</a> in a simple manner.
48 </p>
49
50 <h3 id="webdav-auth">Committer Access</h3>
51
52 <div class="Source"><pre>svn co https://svn.codehaus.org/xstream/trunk</pre></div>
53
54 <p>
55 This access protocol is available to all, but only developers can commit changes.
56 </p>
57 <p>
58 Developers require a LDAP password for Codehaus username (contact Bob at the Haus to get assigned a password if you don't have one).
59 </p>
60
61 </body>
62 </html>
0 <html>
1 <!--
2 Copyright (C) 2014 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 09. January 2014 by Joerg Schaible
10 -->
11 <head>
12 <title>Security Aspects</title>
13 </head>
14
15 <body>
16 <p>XStream is designed to be an easy to use library. It takes its main task seriously: converting Java objects to
17 XML, and XML to Java objects. As a result, it is possible to create an instance of XStream with the default
18 constructor, call a method to convert an object into XML, then call another method to turn the XML back into an
19 equivalent Java object. By design, there are few limits to the type of objects XStream can handle.</p>
20
21 <p>This flexibility comes at a price. XStream applies various techniques under the hood to ensure it is able to
22 handle all types of objects. This includes using undocumented Java features and reflection. The XML generated by
23 XStream includes all information required to build objects of almost any type. This introduces a potential
24 security problem.</p>
25
26 <p>The XML provided to XStream for conversion to a Java object can be manipulated to inject objects into the
27 unmarshalled object graph, which were not present at marshalling time. An attacker could exploit this to execute
28 arbitrary code or shell commands in the context of the server running the XStream process. This issue is
29 identified by CVE-2013-7285.</p>
30
31 <p>Note that the XML data could be manipulated on different levels. For example, manipulating values on existing
32 objects (such as a price value), or breaking the format and causing the XML parser to fail. The latter case will
33 raise an exception, but the former case must be handled by validity checks in any application which processes
34 user-supplied XML. The worst case scenario is injection of arbitrary code or shell commands, as noted above.</p>
35
36 <h2 id="external">External Security</h2>
37
38 <p>An active Java Security Manager can prevent actions required by XStream components or converters. The same
39 applies to environments such as Google Application Engine. XStream tries to some extent to check the functionality
40 of a converter before it claims to handle a type.</p>
41         
42 <p>Therefore it is possible that XStream behaves differently in such an environment, because a converter suddenly
43 no longer handles a special type or any type at all. It is essential that an application that will have to run in
44 such an environment is tested at an early stage to prevent nasty surprises.</p>
45
46 <h2 id="implicit">Implicit Security</h2>
47
48 <p>As explained above, it is possible to inject other object instances if an attacker is able to define the data
49 used to deserialize the Java objects (typically XML, but XStream supports other formats like JSON). A known
50 exploit can be created with the help of the Java runtime library using the Java Bean
51 <a href="http://docs.oracle.com/javase/7/docs/api/java/beans/EventHandler.html">EventHandler</a>. As an instance
52 for the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/InvocationHandler.html">InvocationHandler</a>
53 of a dynamic proxy, it can be used to install a redirect for an arbitrary call to the original object to the method
54 of a completely different instance of an embedded object of the EventHandler itself.</p>
55         
56 <p>This scenario can be used perfectly to replace/inject a dynamic proxy with such an EventHandler at any location
57 in the XML where its parent expects an object of such an interface's type or a simple object instance (any list
58 element will suffice). The usage of a ProcessBuilder as an embedded element, coupled with the redirection of any
59 call to the ProcessBuilder's <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#start()">start()</a>
60 method allows an attacker to call shell commands. Knowing how to define such an attack is the only prerequisite.</p>
61         
62 <p>Starting with XStream 1.4.7, an instance of the EventHandler is no longer handled by default. You have to
63 explicitly register a ReflectionConverter for the EventHandler type, if your application has the requirement to
64 persist such an object. However, you still have to take special care regarding the location of the persisted data,
65 and how your application can ensure its integrity.</p>
66         
67 <p class=highlight>Note: this vulnerability is not even a special problem of XStream. XML being deserialized by
68 XStream acts here like a script, and the scenario above can be created with any script that is executed within a
69 Java runtime (e.g. using its JavaScript interpreter) if someone is able to manipulate it externally. The key
70 message for application developers is that deserializing arbitrary user-supplied content is a dangerous proposition
71 in all cases.</p>
72
73 <h2 id="explicit">Explicit Security</h2>
74
75 <p>While XStream implicitly avoids the vulnerability scenario with the EventHandler class, there might be other
76 combinations with types from well-known and commonly-used Java libraries such as ASM, CGLIB, Groovy, or even in
77 the Java runtime, that are currently simply unknown.</p>
78     
79 <p>Starting with XStream 1.4.7, it is possible to define <a href="#framework">permissions</a> for types, to check
80 the type of an object that should be unmarshalled. Those permissions can be used to allow or deny types explicitly.
81 With these permissions it is at least not possible to inject unexpected types into an object graph. Any application
82 that deserializes data from an external source should at least use this feature to limit the danger of arbitrary
83 command execution.</p>
84         
85 <p class=highlight>Apart from value manipulations, this implementation still allows the injection of allowed
86 objects at wrong locations, e.g. inserting an integer into a list of strings.</p>
87         
88 <p>Separate to the XStream security framework, it has always been possible to overwrite the setupConverter method
89 of XStream to register only the required converters.</p>
90
91 <h2 id="validation">XML Validation</h2>
92
93 <p>XML itself supports input validation using a schema and a validating parser. With XStream, you can use e.g. a
94 StAX parser for validation, but it will take some effort to ensure that the XML read and written by XStream matches
95 the schema in first place. Typically you will have to write some custom converters, but it can be worth the effort
96 depending on the use case.</p>
97
98 <h1 id="framework">Security Framework</h1>
99
100 <p>Noted above, it might be possible that other combinations are found with the Java runtime itself, or other
101 commonly-used Java libraries that allow a similar vulnerability like the known case using the Java Beans
102 EventHandler. To prevent such a possibility at all, XStream version 1.4.7 and above contains a security framework,
103 allowing application developers to define which types are allowed to be unmarshalled with XStream.</p>
104         
105 <p>The core interface is <a href="javadoc/com/thoughtworks/xstream/security/TypePermission.html">TypePermission</a>.
106 The <a href="javadoc/com/thoughtworks/xstream/mapper/SecurityMapper.html">SecurityMapper</a> will evaluate a list
107 of registered instances for every type that will be required while unmarshalling input data. The interface has one
108 simple method:</p><div class="Source Java"><pre>boolean allow(Class&lt;?&gt;);</pre></div>
109         
110 <p>The <a href="javadoc/com/thoughtworks/xstream/XStream.html">XStream</a> facade provides the following methods to
111 register such type permissions within the SecurityMapper:</p><div class="Source Java">
112 <pre>XStream.addPermission(TypePermission);
113 XStream.allowTypes(Class[]);
114 XStream.allowTypes(String[]);
115 XStream.allowTypesByRegExp(String[]);
116 XStream.allowTypesByRegExp(Pattern[]);
117 XStream.allowTypesByWildcard(String[]);
118 XStream.allowTypeHierary(Class);
119 XStream.denyPermission(TypePermission);
120 XStream.denyTypes(Class[]);
121 XStream.denyTypes(String[]);
122 XStream.denyTypesByRegExp(String[]);
123 XStream.denyTypesByRegExp(Pattern[]);
124 XStream.denyTypesByWildcard(String[]);
125 XStream.denyTypeHierary(Class);</pre></div>
126
127 <p>The sequence of registration is essential. The most recently registered permission will be evaluated first.</p>
128         
129 <p>Every TypePermission has three options to implement the allow method and make decisions on the provided type:<p>
130 <ul>
131 <li>if the method returns <i>true</i>, the type is accepted and no other permissions are evaluated</li>
132 <li>if the method returns <i>false</i>, the implementation cannot judge over the type and the SecurityMapper will
133 continue with the next permission instance in its registration list</li>
134 <li>the method throws a <a href="javadoc/com/thoughtworks/xstream/security/ForbiddenClassException.html">ForbiddenClassException</a>
135 to stop the unmarshalling process</li>
136 </ul>
137         
138 <h2 id="predefined">Predefined Permission Types</h2>
139
140 <p>XStream provides some TypePermission implementations to allow any or no type at all, to allow primitive types
141 and their counterpart, null, array types, implementations match the name of the type by regular or wildcard
142 expression and one to invert a permission.</p>
143
144 <table class="examplesTable" summary="Overview over all type permissions delivered with XStream">
145 <!-- .................................................................................................. -->
146 <tr>
147 <th>Permission</th>
148 <th>Description</th>
149 <th>Example</th>
150 <th>Default</th>
151 </tr>
152 <tr>
153 <td><a href="javadoc/com/thoughtworks/xstream/security/AnyTypePermission.html">AnyTypePermission</a></td>
154 <td>Allow any type. You may use the ANY instance directly. A registration of this permission will wipe any
155 prior one.</td>
156 <td>&nbsp;</td>
157 <td>yes</td>
158 </tr>
159 <tr>
160 <td><a href="javadoc/com/thoughtworks/xstream/security/ArrayTypePermission.html">ArrayTypePermission</a></td>
161 <td>Allow any array type. You may use the ARRAYS instance directly.</td>
162 <td>&nbsp;</td>
163 <td>no</td>
164 </tr>
165 <tr>
166 <td><a href="javadoc/com/thoughtworks/xstream/security/CGLIBProxyTypePermission.html">CGLIBProxyTypePermission</a></td>
167 <td>Allow any CGLIB proxy type. You may use the PROXIES instance directly.</td>
168 <td>&nbsp;</td>
169 <td>no</td>
170 </tr>
171 <tr>
172 <td><a href="javadoc/com/thoughtworks/xstream/security/ExplicitTypePermission.html">ExplicitTypePermission</a></td>
173 <td>Allow types explicitly by name.</td>
174 <td>&nbsp;</td>
175 <td>&ndash;</td>
176 </tr>
177 <tr>
178 <td><a href="javadoc/com/thoughtworks/xstream/security/InterfaceTypePermission.html">InterfaceTypePermission</a></td>
179 <td>Allow any interface type. You may use the INTERFACES instance directly.</td>
180 <td>&nbsp;</td>
181 <td>no</td>
182 </tr>
183 <tr>
184 <td><a href="javadoc/com/thoughtworks/xstream/security/NoPermission.html">NoPermission</a></td>
185 <td>Invert any other permission. Instances of this type are used by XStream in the deny methods.</td>
186 <td>&nbsp;</td>
187 <td>no</td>
188 </tr>
189 <tr>
190 <td><a href="javadoc/com/thoughtworks/xstream/security/NoTypePermission.html">NoTypePermission</a></td>
191 <td>Allow no type. You may use the NONE instance directly. A registration of this permission will wipe any
192 prior one.</td>
193 <td>&nbsp;</td>
194 <td>&ndash;</td>
195 </tr>
196 <tr>
197 <td><a href="javadoc/com/thoughtworks/xstream/security/NullPermission.html">NullPermission</a></td>
198 <td>Allow null as type. You may use the NULL instance directly.</td>
199 <td>&nbsp;</td>
200 <td>no</td>
201 </tr>
202 <tr>
203 <td><a href="javadoc/com/thoughtworks/xstream/security/PrimitiveTypePermission.html">PrimitiveTypePermission</a></td>
204 <td>Allow any primitive type and its boxed counterpart (incl void). You may use the PROXIES instance directly.</td>
205 <td>&nbsp;</td>
206 <td>no</td>
207 </tr>
208 <tr>
209 <td><a href="javadoc/com/thoughtworks/xstream/security/ProxyTypePermission.html">ProxyTypePermission</a></td>
210 <td>Allow any Java proxy type. You may use the PROXIES instance directly.</td>
211 <td>&nbsp;</td>
212 <td>no</td>
213 </tr>
214 <tr>
215 <td><a href="javadoc/com/thoughtworks/xstream/security/RegExpTypePermission.html">RegExpTypePermission</a></td>
216 <td>Allow any type that matches with its name a regular expression.</td>
217 <td class="example">.*\\.core\\..*<br/>[^$]+</td>
218 <td>&ndash;</td>
219 </tr>
220 <tr>
221 <td><a href="javadoc/com/thoughtworks/xstream/security/TypeHierarchyPermission.html">TypeHierarchyPermission</a></td>
222 <td>Allow types of a hierarchy.</td>
223 <td>&nbsp;</td>
224 <td>&ndash;</td>
225 </tr>
226 <tr>
227 <td><a href="javadoc/com/thoughtworks/xstream/security/WildcardTypePermission.html">WildcardTypePermission</a></td>
228 <td>Allow any type that matches with its name a wildcard expression.</td>
229 <td class="example">java.lang.*<br/>java.util.**</td>
230 <td>&ndash;</td>
231 </tr>
232 </table>
233
234 <h2 id="example">Example Code</h2>
235
236 <p>XStream uses the AnyTypePermission by default, i.e. any type is accepted. You have to clear out this default
237 and register your own permissions to activate the security framework (the Blog type is from the
238 <a href="alias-tutorial.html">Alias Tutorial</a>):</p>
239 <div class="Source Java"><pre>XStream xstream = new XStream();
240 // clear out existing permissions and set own ones
241 xstream.addPermission(NoPermissionType.NONE);
242 // allow some basics
243 xstream.addPermission(NullPermission.NULL);
244 xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
245 xstream.allowTypeHierarchy(Collection.class);
246 // allow any type from the same package
247 xstream.allowTypesByWildcard(new String[] {
248 Blog.class.getPackage().getName()+".*"
249 });
250 </pre></div>
251
252 <p>You may have a further look at XStream's acceptance tests, the security framework is enabled there in general.</p>
253 </body>
254 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Development Team</title>
14 </head>
15 <body>
16
17 <h2 id="founder">Project Founder</h2>
18
19 <ul>
20 <li><b>Joe Walnes</b></li>
21 </ul>
22
23 <h2 id="lead">Project Lead</h2>
24
25 <ul>
26 <li><b>J&ouml;rg Schaible</b></li>
27 </ul>
28
29 <h2 id="committers">Active Committers</h2>
30
31 <ul>
32 <li>Joe Walnes</li>
33 <li>Mauro Talevi</li>
34 <li>J&ouml;rg Schaible</li>
35 <li>Guilherme Silveira</li>
36 </ul>
37
38 <h2 id="hibernate">Hibernating Committers</h2>
39
40 <ul>
41 <li>Jason van Zyl</li>
42 <li>Nat Pryce</li>
43 <li>Dan North</li>
44 </ul>
45
46 <h2 id="contributors">Contributors</h2>
47
48 <p>List in sequence of first contribution to XStream.</p>
49
50 <ul>
51 <li>Tim Mackinnon</li>
52 <li>James Strachan</li>
53 <li>Jon Tirs&eacute;n</li>
54 <li>Marcos Tarruella</li>
55 <li>Khurram Chaudhary</li>
56 <li>Brock Bulger</li>
57 <li>Paul Hammant</li>
58 <li>Nicky Sandhu</li>
59 <li>J. Matthew Pryor</li>
60 <li>Aslak Helles&oslash;y</li>
61 <li>Nick Pomfret</li>
62 <li>Brian Slesinsky</li>
63 <li>Konstantin Pribluda</li>
64 <li>Ben Smith</li>
65 <li>Brian Oxley</li>
66 <li>Chris Kelly</li>
67 <li>Matthew Sandoz</li>
68 <li>Veaceslav Chicu</li>
69 <li>Jose A. Illescas</li>
70 <li>Laurent Bihanic</li>
71 <li>Martin Weindel</li>
72 <li>Michael Kopp</li>
73 <li>Brian Selinsky</li>
74 <li>Daniel Sheppard</li>
75 <li>Chris Nokleberg</li>
76 <li>Henri Tremblay</li>
77 <li>Simon Daniel</li>
78 <li>Eric Snell</li>
79 <li>Andrea Aime</li>
80 <li>Bryan Coleman</li>
81 <li>Kevin Ring</li>
82 <li>Trygve Laugst&oslash;l</li>
83 <li>Hannes Havel</li>
84 <li>G&aacute;bor Lipt&aacute;k</li>
85 <li>Baba Buehler</li>
86 <li>Emil Kirschner</li>
87 <li>Chung-Onn Cheong</li>
88 <li>Ian Cartwright</li>
89 <li>Costin Leau</li>
90 <li>Stefano Girotti</li>
91 <li>David Blevins</li>
92 <li>Henrik St&aring;hl of BEA</li>
93 <li>Cyrille Le Clerc</li>
94 <li>John Kristian</li>
95 <li>Chris Winters</li>
96 <li>Lucio Benfante</li>
97 <li>Nicolas Gros d'Aillon</li>
98 <li>Dejan Bosanac</li>
99 <li>Rene Schwietzke</li>
100 <li>Hinse ter Schuur</li>
101 <li>Adrian Wilkens</li>
102 <li>Jukka Lindstr&ouml;m</li>
103 <li>Kevin Conaway</li>
104 <li>Kevin Bowman</li>
105 <li>Tatu Saloranta</li>
106 <li>Jerome Lacoste</li>
107 <li>Reto Bachmann-Gm&uuml;r</li>
108 <li>Steven Sparling</li>
109 <li>Alexander Radzin</li>
110 <li>Doug Daniels</li>
111 <li>Jason Greanya</li>
112 <li>Carlos Roman</li>
113 <li>Jaime Metcher</li>
114 <li>Michael Schnell</li>
115 <li>Nikita Levyankov</li>
116 <li>Kohsuke Kawaguchi</li>
117 <li>Peter Abeles</li>
118 <li>Edison Guo</li>
119 <li>Rico Neubauer</li>
120 <li>David Jorm</li>
121 </ul>
122
123 <p>Please direct all correspondence about XStream to the <a href="list-user.html">users' mailing lists</a>
124 rather than directly to one of the team.</p>
125
126 </body>
127 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007, 2011, 2012 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>Two Minute Tutorial</title>
14 </head>
15 <body>
16
17 <p>This is a very quick introduction to XStream.
18 Skim read it to get an idea of how simple it is to convert objects to XML and back again.
19 I'm sure you'll have questions afterwards.</p>
20
21 <h1 id="create-classes">Create classes to be serialized</h1>
22
23 <p>Here's a couple of simple classes. XStream can convert instances of these to XML and back again.</p>
24
25 <div class="Source Java"><pre>public class Person {
26 private String firstname;
27 private String lastname;
28 private PhoneNumber phone;
29 private PhoneNumber fax;
30 // ... constructors and methods
31 }
32
33 public class PhoneNumber {
34 private int code;
35 private String number;
36 // ... constructors and methods
37 }</pre></div>
38
39 <p><b>Note:</b> Notice that the fields are private. XStream doesn't care about the
40 visibility of the fields. No getters or setters are needed. Also, XStream
41 does not limit you to having a default constructor.</p>
42
43 <h1 id="init">Initializing XStream</h1>
44
45 <p>To use XStream, simply instantiate the <code>XStream</code> class:</p>
46
47 <div class="Source Java"><pre>XStream xstream = new XStream();</pre></div>
48
49 <p>You require <code>xstream-[version].jar</code>, <code>xpp3-[version].jar</code> and
50 <code>xmlpull-[version].jar</code> in the classpath. <a href="http://www.extreme.indiana.edu/xgws/xsoap/xpp/">Xpp3</a>
51 is a very fast XML pull-parser implementation. If you do not want to include these dependencies, you can use a standard
52 JAXP DOM parser or since Java 6 the integrated StAX parser instead:</p>
53
54 <div class="Source Java"><pre>XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library</pre></div>
55 <div class="Source Java"><pre>XStream xstream = new XStream(new StaxDriver()); // does not require XPP3 library starting with Java 6</pre></div>
56
57 <p><b>Note:</b> This class is a simple facade designed for common operations. For more flexibility you
58 may choose to create your own facade that behaves differently.</p>
59
60 <p>Now, to make the XML outputted by XStream more concise, you can create aliases for your custom class names
61 to XML element names. This is the <b>only</b> type of mapping required to use XStream and even this is optional.</p>
62
63 <div class="Source Java"><pre>xstream.alias("person", Person.class);
64 xstream.alias("phonenumber", PhoneNumber.class);</pre></div>
65
66 <p><b>Note:</b> This is an optional step. Without it XStream would work fine, but the XML element names would
67 contain the fully qualified name of each class (including package) which would bulk up the XML a bit. See the
68 <a href="alias-tutorial.html">Alias Tutorial</a> a more complete introduction.</p>
69
70 <h1 id="to-xml">Serializing an object to XML</h1>
71
72 <p>Let's create an instance of Person and populate its fields:</p>
73
74 <div class="Source Java"><pre>Person joe = new Person("Joe", "Walnes");
75 joe.setPhone(new PhoneNumber(123, "1234-456"));
76 joe.setFax(new PhoneNumber(123, "9999-999"));</pre></div>
77
78 <p>Now, to convert it to XML, all you have to do is make a simple call to XStream:</p>
79
80 <div class="Source Java"><pre>String xml = xstream.toXML(joe);</pre></div>
81
82 <p>The resulting XML looks like this:</p>
83
84 <div class="Source XML"><pre>&lt;person&gt;
85 &lt;firstname&gt;Joe&lt;/firstname&gt;
86 &lt;lastname&gt;Walnes&lt;/lastname&gt;
87 &lt;phone&gt;
88 &lt;code&gt;123&lt;/code&gt;
89 &lt;number&gt;1234-456&lt;/number&gt;
90 &lt;/phone&gt;
91 &lt;fax&gt;
92 &lt;code&gt;123&lt;/code&gt;
93 &lt;number&gt;9999-999&lt;/number&gt;
94 &lt;/fax&gt;
95 &lt;/person&gt;</pre></div>
96
97 <p>It's that simple. Look at how clean the XML is.</p>
98
99 <h1 id="from-xml">Deserializing an object back from XML</h1>
100
101 <p>To reconstruct an object, purely from the XML:</p>
102
103 <div class="Source Java"><pre>Person newJoe = (Person)xstream.fromXML(xml);</pre></div>
104
105 <p>And that's how simple XStream is!</p>
106
107 <h1 id="summary">Summary</h1>
108
109 <p>To recap:</p>
110
111 <ul>
112 <li>Create element name to class name aliases for any custom classes using <code style="white-space: nowrap">xstream.alias(String elementName, Class cls);</code></li>
113 <li>Convert an object to XML using <code style="white-space: nowrap">xstream.toXML(Object obj);</code></li>
114 <li>Convert XML back to an object using <code style="white-space: nowrap">xstream.fromXML(String xml);</code></li>
115 </ul>
116
117 <p>maybe you like to read the <a href="alias-tutorial.html">alias tutorial</a> to see more possibilities how you can rename things using XStream.
118 Or look into the condensed overview how to configure XStream to <a href="manual-tweaking-output.html">tweak the output</a>.</p>
119
120 </body>
121 </html>
0 <html>
1 <!--
2 Copyright (C) 2005, 2006 Joe Walnes.
3 Copyright (C) 2006, 2007 XStream committers.
4 All rights reserved.
5
6 The software in this package is published under the terms of the BSD
7 style license a copy of which has been included with this distribution in
8 the LICENSE.txt file.
9
10 Created on 29. January 2005 by Joe Walnes
11 -->
12 <head>
13 <title>About Versioning</title>
14 </head>
15 <body>
16
17 <p>The XStream project follows strict rules that govern its use of version
18 numbers. The version number of a release indicates how that release
19 is compatible with previous and future releases.</p>
20
21 <p>Version numbers have the form
22 <var>major</var>.<var>minor</var>.<var>patch</var>. A major
23 version identifies the product stage of the project. Two libraries with
24 different major version are designed to work together in the same
25 application. This implies a major change in the API - either by not
26 sharing the same types or using a different package name.</p>
27
28 <p>The minor version number identifies the API version. A release that
29 changes the API in a way that breaks backwards compatibility will increment
30 the minor version number and reset the patch version to zero. The patch
31 version number identifies the backwards compatible revision of the API. A
32 change in the minor version will still be mostly backward compatible, but
33 may need some compatibility settings or slight migration adjustments. The
34 patch version number identifies revisions that do not change the API
35 although new API elements may occur or existing API may be deprecated to
36 prepare users for the next release with a change in the minor version. A
37 release that fixes bugs or refactors implementation details without changing
38 the API will have the same minor and major versions as the previous release
39 and increment the patch number.</p>
40
41 <p>A hypothetical example:</p>
42 <table summary="Hypothetical examples for version numbering">
43 <tr><td>1.0.0</td><td>First release</td></tr>
44 <tr><td>1.0.1</td><td>Improves Javadoc comments, fixes bug</td></tr>
45 <tr><td>1.1.0</td><td>Adds new API elements, may cause some migration</td></tr>
46 <tr><td>1.1.1</td><td>Adds new API elements, deprecates some API elements</td></tr>
47 <tr><td>1.1.2</td><td>Fixes bugs</td></tr>
48 <tr><td>1.2.0</td><td>Adds new API, needs some migration effort and removes deprecated elements</td></tr>
49 <tr><td>2.0.0</td><td>Complete API redesign, can be used simultanly with 1.x series.</td></tr>
50 <tr><td>2.0.1</td><td>Deprecates API, fixes bugs</td></tr>
51 <tr><td>2.1.0</td><td>Adds new API elements</td></tr>
52 <tr><td>etc.</td><td>etc.</td></tr>
53 </table>
54
55 <h2 id="rc">Release Candidates</h2>
56
57 <p>Before a new major or minor release, XStream will make release
58 candidate (RC) packages available so that users can test them against
59 their own code. There will be one or more release candidates given the
60 version <var>major</var>.<var>minor</var>.0 RC<var>n</var>, where the
61 major and minor version numbers identify the upcoming release and RC1
62 identifies the first candidate release, RC2 the second, and so on.</p>
63
64 <p>A release candidate does not guarantee backward compatibility with
65 new API features introduced by any previous RC of the same upcoming
66 version.
67 A major version RC can change/remove API features introduced in a
68 previous RC for the same major version; a minor version RC can change
69 API features introduced by any previous RC of the same upcoming minor
70 version but guarantees backward compatibility with the previous minor
71 version.</p>
72
73 <h2 id="snapshots">Development Snapshots</h2>
74
75 <p>During development, the the developers may publish snapshot packages
76 from time to time. These are not guaranteed to be complete:
77 Although the unit tests will all pass the snapshot will probably contain
78 failing acceptance tests that describe planned or requested features that
79 have not yet been implemented. Snapshots are identified by the UTC time
80 at which the package was built. The timestamp has the form
81 <var>VERSION-YYYYMMDD.hhmmss-n</var>, where VERSION is the upcoming
82 version, YYYY is the (four-digit) year, MM the month, DD the day, hh the
83 hour, mm the minute, ss the second and n a sequential number.</p>
84
85 <h2 id="internal">Internal Classes</h2>
86
87 <p>Many classes are for internal use only and not designed to be used by
88 end users. These are exempt from the versioning rules above.</p>
89
90 <p>Such classes are clearly marked as internal in the source code
91 headers and are excluded from the published JavaDoc.</p>
92
93 <h2 id="versioning">Versioning and Deprecation</h2>
94
95 <p>A patch release might deprecate some API features. Deprecated features
96 will not actually be removed until the next minor release.
97 A release will never remove API features that have not been deprecated in
98 a previous release.
99 </p>
100
101 </body>
102 </html>
0 <!--
1 Copyright (C) 2005, 2006 Joe Walnes.
2 Copyright (C) 2006, 2007, 2010, 2011, 2014, 2015 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 29. January 2005 by Joe Walnes
10 -->
11 <sitemap>
12 <section>
13 <name>Software</name>
14 <page>index.html</page>
15 <page>news.html</page>
16 <page>changes.html</page>
17 <page>versioning.html</page>
18 </section>
19 <section>
20 <name>Evaluating XStream</name>
21 <page>tutorial.html</page>
22 <page>graphs.html</page>
23 <page>manual-tweaking-output.html</page>
24 <page>license.html</page>
25 <page>download.html</page>
26 <page>references.html</page>
27 <page>parser-benchmarks.html</page>
28 <link title="Code Statistics">https://www.openhub.net/p/xstream</link>
29 </section>
30 <section>
31 <name>Using XStream</name>
32 <page>architecture.html</page>
33 <page>converters.html</page>
34 <page>security.html</page>
35 <page>faq.html</page>
36 <page>list-user.html</page>
37 <page>issues.html</page>
38 </section>
39 <section>
40 <name>Javadoc</name>
41 <link title="XStream Core">javadoc/index.html</link>
42 <link title="Hibernate Extensions">hibernate-javadoc/index.html</link>
43 <link title="Benchmark Module">benchmark-javadoc/index.html</link>
44 </section>
45 <section>
46 <name>Tutorials</name>
47 <page>tutorial.html</page>
48 <page>alias-tutorial.html</page>
49 <page>annotations-tutorial.html</page>
50 <page>converter-tutorial.html</page>
51 <page>objectstream.html</page>
52 <page>persistence-tutorial.html</page>
53 <page>json-tutorial.html</page>
54 <link title="StudyTrails">http://www.studytrails.com/java/xml/xstream/xstream-introduction.jsp</link>
55 </section>
56 <section>
57 <name>Developing XStream</name>
58 <page>how-to-contribute.html</page>
59 <page>list-dev.html</page>
60 <page>team.html</page>
61 <page>repository.html</page>
62 <link title="Continuous Integration">http://bamboo.ci.codehaus.org/browse/XSTREAM</link>
63 </section>
64 </sitemap>
0 /*
1 Copyright (C) 2005, 2006 Joe Walnes.
2 Copyright (C) 2006, 2007 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 29. January 2005 by Joe Walnes
10 */
11
12 /*---------------------------------------------------------------------------
13 * Two- and three-column layout
14 */
15
16 #banner {
17 top: 0px;
18 left: 0px;
19 right: 0px;
20 height: 116px;
21 }
22
23 #left {
24 position: absolute;
25 z-index: 2;
26 left: 8px;
27 width: 184px;
28 top: 125px;
29 bottom: 8px;
30 margin: 0px;
31 padding: 0px;
32 }
33
34 #right {
35 position: absolute;
36 z-index: 1;
37 right: 8px;
38 width: 184px;
39 top: 125px;
40 bottom: 8px;
41 margin: 0px;
42 padding: 0px;
43 }
44
45 .Content3Column {
46 position: absolute;
47 top: 125px;
48 bottom: 8px;
49 left: 208px;
50 right: 216px;
51 }
52
53 .Content2Column {
54 position: absolute;
55 top: 125px;
56 bottom: 8px;
57 left: 208px;
58 right: 16px;
59 }
60
61 #center {
62 z-index: 3;
63 margin: 0px;
64 border: none;
65 padding-bottom: 8px;
66 }
67
68
69 /*---------------------------------------------------------------------------
70 * Default element styles
71 */
72
73 body {
74 padding: 0px;
75 margin: 0px;
76 border: 0px;
77
78 font-family: helvetica, arial, sans-serif;
79 font-size: 12px;
80
81 background-color: white;
82 color: black;
83 }
84
85 h1, h2, h3, h4, h5, h6 {
86 margin: 0px;
87 border: 0px;
88 padding: 0px;
89 font-weight: normal;
90 }
91
92 a:link { color: #0a0; }
93 a:active { color: red; }
94 a:hover { color: red; }
95 a:visited { color: black; }
96
97 iframe {
98 width:100%;
99 height: 800px;
100 border: 0px;
101 }
102
103 img {
104 border: 0px;
105 padding: 0px;
106 margin: 0px;
107 }
108
109 p {
110 border: 0px;
111 padding: 0px;
112 margin: 0px;
113 margin-bottom: 10px;
114 }
115
116 blockquote {
117 margin-bottom: 10px;
118 }
119
120 td {
121 font-size: 12px;
122 padding: 2px;
123 }
124
125 th {
126 font-size: 12px;
127 font-weight: bold;
128 white-space: nowrap;
129 padding: 2px;
130 }
131
132 th.Row {
133 text-align: left;
134 vertical-align: top;
135 }
136
137 ul, ol {
138 border: 0px;
139 padding: 0px;
140 margin-top: 0px;
141 margin-bottom: 12px;
142 margin-left: 20px;
143 }
144
145
146 /*---------------------------------------------------------------------------
147 * Page banner
148 */
149
150 #banner {
151 margin: 0px;
152 border: 0px;
153 border-bottom: 1px solid #afa;
154 padding: 0px;
155 background-color: #e0f0e0;
156 color: #060;
157 vertical-align: bottom;
158 }
159
160 #banner a { text-decoration: none; }
161 #banner a:visited { color: #0a0; }
162 #banner a:hover { color: red; }
163 #banner a:active { color: red; }
164
165 #logo {
166 position: absolute;
167 top: 5px;
168 left: 8px;
169 }
170
171 #versions {
172 position: absolute;
173 width: auto;
174 right: 0px;
175 top: 0px;
176 margin: 8px;
177 font-weight: normal;
178 }
179
180 /*---------------------------------------------------------------------------
181 * Page content
182 */
183
184 #content {
185 margin: 0px;
186 background-color: white;
187 color: black;
188 height: 100%;
189 }
190
191 #content h1 {
192 width: 100%;
193 font-size: 18px;
194 background-color: #060;
195 color: white;
196 padding: 2px;
197 padding-left: 6px;
198 margin-top: 24px;
199 margin-bottom: 12px;
200 }
201
202 #content .FirstChild { /* IE doesn't understand first-child pseudoelement */
203 margin-top: 0px;
204 }
205
206 #content a { text-decoration: underline; }
207 #content a:link { color: #060; }
208 #content a:visited { color: #060; }
209 #content a:active { color: red; }
210 #content a:hover { color: red; }
211
212 #content h2 {
213 margin-top: 24px;
214 border-top: 1px solid #060;
215 margin-bottom: 16px;
216 font-size: 15px;
217 font-weight: bold;
218 background-color: #e0f0e0;
219 padding: 2px;
220 }
221
222 #content li {
223 margin-bottom: 6px;
224 }
225
226 #content th {
227 background-color: #afa;
228 }
229
230 #content td {
231 background-color: #dfd;
232 }
233
234 .Source pre {
235 padding: 4px;
236 font-family: courier new, monospace;
237 font-size: 11px;
238 border: 1px solid #080;
239 background-color: #cfc;
240 color: black;
241 }
242
243 .Source:before {
244 margin: 0px;
245 padding: 0px;
246 border: 0px;
247 font-size: inherit;
248 line-spacing: 100%;
249 }
250
251 .highlight {
252 background-color: #e0f0e0;
253 border: 1px dotted #060;
254 padding: 5px;
255 }
256
257 /* The following are for images, but can also apply to div's containing images. */
258
259 #content .Float {
260 float: right;
261 margin-left: 8px;
262 margin-right: 0px;
263 margin-top: 8px;
264 margin-bottom: 8px;
265 }
266
267 #content .Diagram {
268 display: block;
269 margin-left: auto;
270 margin-right: auto;
271 margin-top: 8px;
272 margin-bottom: 8px;
273 }
274
275
276 #content .Inline {
277 display: inline;
278 }
279
280 .RuleOfThumb {
281 font-weight: bold;
282 }
283
284 #content h1[id]:hover:after, #content h2[id]:hover:after {
285 content: " #" attr(id) " ";
286 font-size: 90%;
287 color: #aaa;
288 text-decoration: none;
289 }
290
291 /*---------------------------------------------------------------------------
292 * Side panels
293 */
294
295 .SidePanel {
296 background-color: white;
297 padding: 0px;
298 font-size: 11px;
299 }
300
301 .SidePanel h1 {
302 margin: 0px;
303 border: 0px;
304 padding: 4px;
305
306 color: #060;
307
308 font-size: 12px;
309 font-weight: bold;
310 }
311
312
313 .SidePanel a { text-decoration: none; }
314 .SidePanel a:link { color: #060; }
315 .SidePanel a:visited { color: #060; }
316 .SidePanel a:active { color: red; }
317 .SidePanel a:hover { color: red; }
318
319 /*---------------------------------------------------------------------------
320 * Menus
321 */
322
323 .MenuGroup {
324 border-left: 1px solid #afa;
325 border-top: 1px solid #afa;
326 border-bottom: 1px solid white; /* IE work-around */
327
328 margin-bottom: 8px;
329 background-color: white;
330 color: #060;
331 }
332
333 .MenuGroup ul {
334 margin: 0px;
335 padding-left: 4px;
336 list-style-type: none;
337 }
338
339 .MenuGroup li {
340 padding: 2px;
341 }
342
343 .MenuGroup .currentLink {
344 /* background-color: #060;*/
345 background-color: #e0f0e0;
346 color: #000;
347 }
348
349
350 /*---------------------------------------------------------------------------
351 * News panel
352 */
353
354 .NewsGroup {
355 border-left: 1px solid #afa;
356 border-top: 1px solid #afa;
357 border-bottom: 1px solid white; /* IE workaround */
358 margin-bottom: 8px;
359
360 color: #060;
361 }
362
363 .NewsItem {
364 margin: 4px;
365 }
366
367 .NewsDate {
368 font-weight: bold;
369 margin: 0px;
370 padding: 0px;
371 }
372
373 .NewsText {
374 padding: 0px;
375 margin: 0px;
376 margin-bottom: 8px;
377 }
378
379 .NewsText a { text-decoration: underline; }
380 .NewsText a:link { color: #060; }
381 .NewsText a:visited { color: #060; }
382 .NewsText a:active { color: red; }
383 .NewsText a:hover { color: red; }
384
385 .NewsMore {
386 font-size: smaller;
387 margin: 4px;
388 margin-top: 8px;
389 text-align: left;
390 }
391
392 .NewsGroup td {
393 font-size: 12px;
394 }
395
396 /*---------------------------------------------------------------------------
397 * Document meta-information
398 */
399
400 .Meta {
401 margin-top: 64px;
402 font-size: smaller;
403 color: #C0C0C0;
404 text-align: right;
405 }
406
407 .Meta a { text-decoration: underline; }
408 .Meta a:link { color: #C0C0C0; }
409 .Meta a:visited { color: #C0C0C0; }
410 .Meta a:active { color: red; }
411 .Meta a:hover { color: red; }
0 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <!--
3 Copyright (C) 2005, 2006 Joe Walnes.
4 Copyright (C) 2006, 2007, 2008 XStream committers.
5 All rights reserved.
6
7 The software in this package is published under the terms of the BSD
8 style license a copy of which has been included with this distribution in
9 the LICENSE.txt file.
10
11 Created on 29. January 2005 by Joe Walnes
12 -->
13 <head>
14 <title>XStream - ${title}</title>
15 <link rel="stylesheet" type="text/css" href="style.css"/>
16 ${head}
17
18 <!-- Google analytics -->
19 <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
20 </script>
21 <script type="text/javascript">
22 _uacct = "UA-110973-2";
23 urchinTracker();
24 </script>
25
26 </head>
27 <body>
28
29 <div id="banner">
30 <a href="index.html"><img id="logo" src="logo.gif" alt="XStream"/></a>
31 </div>
32
33 <div id="center" class="Content2Column"> <!-- Content3Column for index -->
34 <div id="content">
35 <h1 class="FirstChild">${title}</h1>
36
37 ${body}
38
39 <br/>
40
41 </div>
42 </div>
43
44 <div class="SidePanel" id="left">
45 <#list sitemap.sections as section>
46 <div class="MenuGroup">
47 <h1>${section.name}</h1>
48 <ul>
49 <#list section.entries as entry>
50 <#if entry = page>
51 <li class="currentLink">${entry.title}</li>
52 <#else>
53 <li><a href="${entry.href}">${entry.title}</a></li>
54 </#if>
55 </#list>
56 </ul>
57 </div>
58 </#list>
59 </div>
60
61 </body>
62 </html>
0 <!--
1 Copyright (C) 2006, 2007, 2008, 2010 XSite committers.
2 Copyright (C) 2011 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 28. September 2011 by Joerg Schaible, copied from XSite project
10 -->
11 <container component-instance-factory='org.picocontainer.script.xml.XStreamComponentInstanceFactory'>
12 <component-instance key="org.codehaus.xsite.XSiteConfiguration">
13 <org.codehaus.xsite.XSiteConfiguration>
14 <validateLinks>true</validateLinks>
15 </org.codehaus.xsite.XSiteConfiguration>
16 </component-instance>
17 <component-implementation class="org.codehaus.xsite.XSite"/>
18 <component-implementation class="com.thoughtworks.xstream.io.xml.DomDriver"/>
19 <component-implementation class="com.thoughtworks.xstream.XStream"/>
20 <component-implementation key="org.codehaus.xsite.FileSystem" class="org.codehaus.xsite.io.CommonsFileSystem"/>
21 <component-implementation key="org.codehaus.xsite.SitemapLoader" class="org.codehaus.xsite.loaders.XStreamSitemapLoader"/>
22 <component-implementation key="org.codehaus.xsite.Skin" class="org.codehaus.xsite.skins.FreemarkerSkin"/>
23 <component-implementation key="org.codehaus.xsite.PageExtractor" class="org.codehaus.xsite.extractors.SiteMeshPageExtractor"/>
24 <component-implementation class="org.codehaus.xsite.extractors.sitemesh.rules.AddFirstChildClassToHeader"/>
25 <component-implementation class="com.opensymphony.module.sitemesh.html.rules.RegexReplacementTextFilter">
26 <parameter><string>JIRA:([A-Z]+)-([0-9]+)</string></parameter>
27 <parameter><string><![CDATA[<a href=\"http://jira.codehaus.org/browse/$1-$2\">$1-$2</a>]]></string></parameter>
28 </component-implementation>
29 <component-implementation key="email-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
30 <parameter><string>mailto:</string></parameter>
31 </component-implementation>
32 <component-implementation key="javascript-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
33 <parameter><string>javascript:</string></parameter>
34 </component-implementation>
35 <component-implementation key="http-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
36 <parameter><string>http://</string></parameter>
37 </component-implementation>
38 <component-implementation key="https-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
39 <parameter><string>https://</string></parameter>
40 </component-implementation>
41 <component-implementation key="news-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
42 <parameter><string>nntp://</string></parameter>
43 </component-implementation>
44 <component-implementation key="apidocs-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
45 <parameter><string>hibernate-javadoc/</string></parameter>
46 </component-implementation>
47 <component-implementation key="javadoc-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
48 <parameter><string>javadoc/</string></parameter>
49 </component-implementation>
50 <component-implementation key="code-coverage-link-validator" class="org.codehaus.xsite.validators.StartsWithLinkValidator">
51 <parameter><string>code-coverage/</string></parameter>
52 </component-implementation>
53 </container>
0 <?xml version="1.0"?><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">
1 <!--
2 Copyright (C) 2011, 2012, 2013, 2015 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 5. April 2011 by Joerg Schaible
10 -->
11 <modelVersion>4.0.0</modelVersion>
12 <parent>
13 <groupId>com.thoughtworks.xstream</groupId>
14 <artifactId>xstream-parent</artifactId>
15 <version>1.4.8</version>
16 </parent>
17 <artifactId>xstream-hibernate</artifactId>
18 <packaging>jar</packaging>
19 <name>XStream Hibernate Extension</name>
20 <description>
21 XStream extension for Hibernate 3/4 to untie Java objects from Hibernate.
22 </description>
23
24 <profiles>
25 <profile>
26 <id>jdk18-ge</id>
27 <activation>
28 <jdk>[1.8,)</jdk>
29 </activation>
30 <build>
31 <plugins>
32 <plugin>
33 <groupId>org.apache.maven.plugins</groupId>
34 <artifactId>maven-javadoc-plugin</artifactId>
35 </plugin>
36 </plugins>
37 </build>
38 <reporting>
39 <plugins>
40 <plugin>
41 <groupId>org.apache.maven.plugins</groupId>
42 <artifactId>maven-javadoc-plugin</artifactId>
43 <version>${version.plugin.maven.javadoc}</version>
44 <configuration>
45 <additionalparam>${javadoc.xdoclint}</additionalparam>
46 <detectJavaApiLink>false</detectJavaApiLink>
47 <source>${version.java.source}</source>
48 <links>
49 <link>${link.javadoc.javase}</link>
50 </links>
51 </configuration>
52 </plugin>
53 </plugins>
54 </reporting>
55 </profile>
56 <profile>
57 <id>jdk16-ge</id>
58 <activation>
59 <jdk>[1.6,)</jdk>
60 </activation>
61 <build>
62 <plugins>
63 <plugin>
64 <groupId>org.apache.maven.plugins</groupId>
65 <artifactId>maven-jar-plugin</artifactId>
66 <configuration>
67 <archive combine.children="append">
68 <manifestFile>${project.build.directory}/OSGi/MANIFEST.MF</manifestFile>
69 </archive>
70 </configuration>
71 </plugin>
72 <plugin>
73 <groupId>org.apache.felix</groupId>
74 <artifactId>maven-bundle-plugin</artifactId>
75 <configuration>
76 <instructions combine.children="append">
77 <Export-Package>!com.thoughtworks.xstream.hibernate.util,com.thoughtworks.xstream.hibernate.*;-noimport:=true</Export-Package>
78 </instructions>
79 </configuration>
80 </plugin>
81 </plugins>
82 </build>
83 </profile>
84 </profiles>
85
86 <build>
87 <plugins>
88 <plugin>
89 <groupId>org.apache.maven.plugins</groupId>
90 <artifactId>maven-compiler-plugin</artifactId>
91 </plugin>
92 <plugin>
93 <groupId>org.apache.maven.plugins</groupId>
94 <artifactId>maven-source-plugin</artifactId>
95 </plugin>
96 <plugin>
97 <groupId>org.apache.maven.plugins</groupId>
98 <artifactId>maven-dependency-plugin</artifactId>
99 <executions>
100 <execution>
101 <id>collect-dependencies</id>
102 <phase>package</phase>
103 <goals>
104 <goal>copy-dependencies</goal>
105 </goals>
106 <configuration>
107 <outputDirectory>target/dependencies</outputDirectory>
108 <includeScope>runtime</includeScope>
109 <excludeArtifactIds>xstream,xpp3_min,xmlpull</excludeArtifactIds>
110 </configuration>
111 </execution>
112 </executions>
113 </plugin>
114 </plugins>
115 </build>
116
117 <reporting>
118 <plugins>
119 <plugin>
120 <groupId>org.apache.maven.plugins</groupId>
121 <artifactId>maven-surefire-report-plugin</artifactId>
122 <version>${version.plugin.maven.surefire}</version>
123 </plugin>
124 <plugin>
125 <groupId>org.codehaus.mojo</groupId>
126 <artifactId>cobertura-maven-plugin</artifactId>
127 <version>${version.plugin.mojo.cobertura}</version>
128 </plugin>
129 </plugins>
130 </reporting>
131
132 <dependencies>
133 <dependency>
134 <groupId>com.thoughtworks.xstream</groupId>
135 <artifactId>xstream</artifactId>
136 <classifier>tests</classifier>
137 <type>test-jar</type>
138 </dependency>
139 <dependency>
140 <groupId>com.thoughtworks.xstream</groupId>
141 <artifactId>xstream</artifactId>
142 </dependency>
143 <dependency>
144 <groupId>org.hibernate</groupId>
145 <artifactId>hibernate-core</artifactId>
146 </dependency>
147 <dependency>
148 <groupId>org.hibernate</groupId>
149 <artifactId>hibernate-envers</artifactId>
150 <optional>true</optional>
151 </dependency>
152 <dependency>
153 <groupId>org.hsqldb</groupId>
154 <artifactId>hsqldb</artifactId>
155 <scope>test</scope>
156 </dependency>
157 <dependency>
158 <groupId>org.slf4j</groupId>
159 <artifactId>slf4j-simple</artifactId>
160 <scope>provided</scope>
161 </dependency>
162 <dependency>
163 <groupId>javassist</groupId>
164 <artifactId>javassist</artifactId>
165 <scope>provided</scope>
166 </dependency>
167 <dependency>
168 <groupId>cglib</groupId>
169 <artifactId>cglib-nodep</artifactId>
170 <scope>provided</scope>
171 </dependency>
172 <dependency>
173 <groupId>junit</groupId>
174 <artifactId>junit</artifactId>
175 </dependency>
176 </dependencies>
177 </project>
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 19. April 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.hibernate.converter;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.CollectionConverter;
15 import com.thoughtworks.xstream.hibernate.util.Hibernate;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 /**
21 * A converter for Hibernate's PersistentBag, PersistentList and PersistentSet and for ListProxy
22 * and SetProxy from Hibernate's Envers add-on. The converter will drop any reference to the
23 * Hibernate collection and emit at serialization time an equivalent JDK collection instead.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4
27 */
28 public class HibernatePersistentCollectionConverter extends CollectionConverter {
29
30 /**
31 * Construct a HibernatePersistentCollectionConverter.
32 *
33 * @param mapper
34 * @since 1.4
35 */
36 public HibernatePersistentCollectionConverter(final Mapper mapper) {
37 super(mapper);
38 }
39
40 public boolean canConvert(final Class type) {
41 return type != null
42 && (
43 type == Hibernate.PersistentBag
44 || type == Hibernate.PersistentList
45 || type == Hibernate.PersistentSet
46 || type == Hibernate.EnversList
47 || type == Hibernate.EnversSet
48 );
49 }
50
51 public Object unmarshal(final HierarchicalStreamReader reader,
52 final UnmarshallingContext context) {
53 throw new ConversionException("Cannot deserialize Hibernate collection");
54 }
55 }
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 19. April 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.hibernate.converter;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.MapConverter;
15 import com.thoughtworks.xstream.hibernate.util.Hibernate;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 /**
21 * A converter for Hibernate's PersistentMap and for the MapProxy from Hibernate's Envers
22 * add-on. The converter will drop any reference to the Hibernate collection and emit at
23 * serialization time an equivalent JDK collection instead.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4
27 */
28 public class HibernatePersistentMapConverter extends MapConverter {
29
30 /**
31 * Construct a HibernatePersistentMapConverter.
32 *
33 * @param mapper
34 * @since 1.4
35 */
36 public HibernatePersistentMapConverter(final Mapper mapper) {
37 super(mapper);
38 }
39
40 public boolean canConvert(final Class type) {
41 return type != null && (type == Hibernate.PersistentMap || type == Hibernate.EnversMap);
42 }
43
44 public Object unmarshal(final HierarchicalStreamReader reader,
45 final UnmarshallingContext context) {
46 throw new ConversionException("Cannot deserialize Hibernate collection");
47 }
48 }
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 19. April 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.hibernate.converter;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.TreeMapConverter;
15 import com.thoughtworks.xstream.hibernate.util.Hibernate;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 /**
21 * A converter for Hibernate's PersistentSortedMap and for the SortedMapProxy from Hibernate's
22 * Envers add-on. The converter will drop any reference to the Hibernate collection and emit at
23 * serialization time an equivalent JDK collection instead.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4
27 */
28 public class HibernatePersistentSortedMapConverter extends TreeMapConverter {
29
30 /**
31 * Construct a HibernatePersistentSortedMapConverter.
32 *
33 * @param mapper
34 * @since 1.4
35 */
36 public HibernatePersistentSortedMapConverter(final Mapper mapper) {
37 super(mapper);
38 }
39
40 public boolean canConvert(final Class type) {
41 return type != null && (type == Hibernate.PersistentSortedMap || type == Hibernate.EnversSortedMap);
42 }
43
44 public Object unmarshal(final HierarchicalStreamReader reader,
45 final UnmarshallingContext context) {
46 throw new ConversionException("Cannot deserialize Hibernate collection");
47 }
48 }
0 /*
1 * Copyright (C) 2011, 2012, 2013 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 19. April 2011 by Joerg Schaible
9 */
10 package com.thoughtworks.xstream.hibernate.converter;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.UnmarshallingContext;
14 import com.thoughtworks.xstream.converters.collections.TreeSetConverter;
15 import com.thoughtworks.xstream.hibernate.util.Hibernate;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.mapper.Mapper;
18
19
20 /**
21 * A converter for Hibernate's PersistentSortedSet and for the SortedSetProxy from Hibernate's
22 * Envers add-on. The converter will drop any reference to the Hibernate collection and emit at
23 * serialization time an equivalent JDK collection instead.
24 *
25 * @author J&ouml;rg Schaible
26 * @since 1.4
27 */
28 public class HibernatePersistentSortedSetConverter extends TreeSetConverter {
29
30 /**
31 * Construct a HibernatePersistentSortedSetConverter.
32 *
33 * @param mapper
34 * @since 1.4
35 */
36 public HibernatePersistentSortedSetConverter(final Mapper mapper) {
37 super(mapper);
38 }
39
40 public boolean canConvert(final Class type) {
41 return type != null && (type == Hibernate.PersistentSortedSet || type == Hibernate.EnversSortedSet);
42 }
43
44 public Object unmarshal(final HierarchicalStreamReader reader,
45 final UnmarshallingContext context) {
46 throw new ConversionException("Cannot deserialize Hibernate collection");
47 }
48 }
0 /*
1 * Copyright (C) 2007, 2011 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 11. January 2007 by Konstantin Pribluda
9 */
10 package com.thoughtworks.xstream.hibernate.converter;
11
12 import com.thoughtworks.xstream.converters.ConversionException;
13 import com.thoughtworks.xstream.converters.Converter;
14 import com.thoughtworks.xstream.converters.MarshallingContext;
15 import com.thoughtworks.xstream.converters.UnmarshallingContext;
16 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
17 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
18
19 import org.hibernate.proxy.HibernateProxy;
20
21
22 /**
23 * Converter for Hibernate proxy instances. The converter will effectively remove any trace of
24 * the proxy.
25 *
26 * @author Konstantin Pribluda
27 * @author J&ouml;rg Schaible
28 */
29 public class HibernateProxyConverter implements Converter {
30 public boolean canConvert(final Class clazz) {
31 // be responsible for Hibernate proxy.
32 return HibernateProxy.class.isAssignableFrom(clazz);
33 }
34
35 public void marshal(final Object object, final HierarchicalStreamWriter writer,
36 final MarshallingContext context) {
37 final Object item = ((HibernateProxy)object)
38 .getHibernateLazyInitializer()
39 .getImplementation();
40 context.convertAnother(item);
41 }
42
43 public Object unmarshal(final HierarchicalStreamReader reader,
44 final UnmarshallingContext context) {
45 throw new ConversionException("Cannot deserialize Hibernate proxy");
46 }
47 }
0 /*
1 * Copyright (C) 2007, 2011, 2012, 2013 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 11. January 2007 by Konstantin Pribluda
9 */
10 package com.thoughtworks.xstream.hibernate.mapper;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.Map;
16 import java.util.TreeMap;
17 import java.util.TreeSet;
18
19 import com.thoughtworks.xstream.hibernate.util.Hibernate;
20 import com.thoughtworks.xstream.mapper.MapperWrapper;
21
22 import org.hibernate.proxy.HibernateProxy;
23
24
25 /**
26 * Mapper for Hibernate types. It will map the class names of the Hibernate collections and
27 * Envers collection proxies with equivalents of the JDK at serialization time. It will also map
28 * the names of the proxy types to the names of the proxies element's type.
29 *
30 * @author Konstantin Pribluda
31 * @author J&ouml;rg Schaible
32 * @since 1.4
33 */
34 public class HibernateMapper extends MapperWrapper {
35
36 final private Map collectionMap = new HashMap();
37
38 public HibernateMapper(final MapperWrapper mapper) {
39 super(mapper);
40 collectionMap.put(Hibernate.PersistentBag, ArrayList.class);
41 collectionMap.put(Hibernate.PersistentList, ArrayList.class);
42 collectionMap.put(Hibernate.PersistentMap, HashMap.class);
43 collectionMap.put(Hibernate.PersistentSet, HashSet.class);
44 collectionMap.put(Hibernate.PersistentSortedMap, TreeMap.class);
45 collectionMap.put(Hibernate.PersistentSortedSet, TreeSet.class);
46 collectionMap.put(Hibernate.EnversList, ArrayList.class);
47 collectionMap.put(Hibernate.EnversMap, HashMap.class);
48 collectionMap.put(Hibernate.EnversSet, HashSet.class);
49 collectionMap.put(Hibernate.EnversSortedMap, TreeMap.class);
50 collectionMap.put(Hibernate.EnversSortedSet, TreeSet.class);
51 collectionMap.remove(null);
52 }
53
54 public Class defaultImplementationOf(final Class clazz) {
55 if (collectionMap.containsKey(clazz)) {
56 return super.defaultImplementationOf((Class)collectionMap.get(clazz));
57 }
58
59 return super.defaultImplementationOf(clazz);
60 }
61
62 public String serializedClass(final Class clazz) {
63 if (clazz != null) {
64 if (collectionMap.containsKey(clazz)) {
65 // Pretend this is the underlying collection class and map that instead
66 return super.serializedClass((Class)collectionMap.get(clazz));
67 }
68 // check whether we are Hibernate proxy and substitute real name
69 if (HibernateProxy.class.isAssignableFrom(clazz)) {
70 return super.serializedClass(clazz.getSuperclass());
71 }
72 }
73 return super.serializedClass(clazz);
74 }
75 }
0 <!--
1 Copyright (C) 2011, 2013 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 11. August 2011 by Joerg Schaible
9 -->
10 <body>
11 <p>Support of Hibernate enhanced collections and proxied types and Hibernate's
12 collection proxies from the Envers add-on. To drop the internals of Hibernate
13 when marshalling such objects to XStream, all converters and the mapper have to
14 be registered for the XStream instance:</p>
15 <p><code><pre>final XStream xstream = new XStream() {
16 protected MapperWrapper wrapMapper(final MapperWrapper next) {
17 return new HibernateMapper(next);
18 }
19 };
20 xstream.registerConverter(new HibernateProxyConverter());
21 xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream.getMapper()));
22 xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
23 xstream.registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
24 xstream.registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));
25 </pre></code></p>
26 </body>
0 /*
1 * Copyright (C) 2012, 2013 Joerg Schaible.
2 * All rights reserved.
3 *
4 * Created on 08.06.2012 by Joerg Schaible
5 */
6 package com.thoughtworks.xstream.hibernate.util;
7
8 import com.thoughtworks.xstream.core.JVM;
9
10 import org.hibernate.proxy.HibernateProxy;
11
12
13 /**
14 * Utility class for Hibernate support.
15 *
16 * @author J&ouml;rg Schaible
17 * @since 1.4.3
18 */
19 public class Hibernate {
20 public final static Class PersistentBag = loadHibernateType("org.hibernate.collection.internal.PersistentBag");
21 public final static Class PersistentList = loadHibernateType("org.hibernate.collection.internal.PersistentList");
22 public final static Class PersistentMap = loadHibernateType("org.hibernate.collection.internal.PersistentMap");
23 public final static Class PersistentSet = loadHibernateType("org.hibernate.collection.internal.PersistentSet");
24 public final static Class PersistentSortedMap = loadHibernateType("org.hibernate.collection.internal.PersistentSortedMap");
25 public final static Class PersistentSortedSet = loadHibernateType("org.hibernate.collection.internal.PersistentSortedSet");
26 public final static Class EnversList = loadHibernateEnversType("org.hibernate.envers.entities.mapper.relation.lazy.proxy.ListProxy");
27 public final static Class EnversMap = loadHibernateEnversType("org.hibernate.envers.entities.mapper.relation.lazy.proxy.MapProxy");
28 public final static Class EnversSet = loadHibernateEnversType("org.hibernate.envers.entities.mapper.relation.lazy.proxy.SetProxy");
29 public final static Class EnversSortedMap = loadHibernateEnversType("org.hibernate.envers.entities.mapper.relation.lazy.proxy.SortedMapProxy");
30 public final static Class EnversSortedSet = loadHibernateEnversType("org.hibernate.envers.entities.mapper.relation.lazy.proxy.SortedSetProxy");
31
32 private static Class loadHibernateType(String name) {
33 Class type = null;
34 try {
35 try {
36 type = HibernateProxy.class.getClassLoader().loadClass(name);
37 } catch (ClassNotFoundException e) {
38 type = HibernateProxy.class.getClassLoader().loadClass(
39 name.replaceFirst("\\.internal\\.", "."));
40 }
41 } catch (ClassNotFoundException e) {
42 // not available
43 }
44 return type;
45 }
46
47 private static Class loadHibernateEnversType(String name) {
48 Class type = null;
49 if (JVM.is15()) {
50 try {
51 type = HibernateProxy.class.getClassLoader().loadClass(name);
52 } catch (ClassNotFoundException e) {
53 // not available
54 }
55 }
56 return type;
57 }
58 }
0 /*
1 * Copyright (C) 2011 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. April 2011 by Joerg Schaible
9 */
10 package acceptance.hibernate;
11
12 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
13 import com.thoughtworks.xstream.XStream;
14 import com.thoughtworks.xstream.hibernate.converter.HibernatePersistentCollectionConverter;
15 import com.thoughtworks.xstream.hibernate.converter.HibernatePersistentMapConverter;
16 import com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedMapConverter;
17 import com.thoughtworks.xstream.hibernate.converter.HibernatePersistentSortedSetConverter;
18 import com.thoughtworks.xstream.hibernate.converter.HibernateProxyConverter;
19 import com.thoughtworks.xstream.hibernate.mapper.HibernateMapper;
20 import com.thoughtworks.xstream.mapper.MapperWrapper;
21
22 import org.hibernate.SessionFactory;
23 import org.hibernate.cfg.Configuration;
24
25
26 /**
27 * @author J&ouml;rg Schaible
28 * @author Jaime Metcher
29 */
30 public abstract class AbstractHibernateAcceptanceTest extends AbstractAcceptanceTest {
31
32 private static final SessionFactory sessionFactory;
33 static {
34 try {
35 // Create the SessionFactory from hibernate.cfg.xml
36 sessionFactory = new Configuration().configure().buildSessionFactory();
37 } catch (final Throwable ex) {
38 // Make sure you log the exception, as it might be swallowed
39 System.err.println("Initial SessionFactory creation failed." + ex);
40 throw new ExceptionInInitializerError(ex);
41 }
42 }
43
44 /**
45 * Construct a AbstractHibernateAcceptanceTest.
46 */
47 public AbstractHibernateAcceptanceTest() {
48 super();
49 }
50
51 protected XStream createXStream() {
52 final XStream xstream = new XStream() {
53
54 protected MapperWrapper wrapMapper(final MapperWrapper next) {
55 return new HibernateMapper(next);
56 }
57
58 };
59 xstream.registerConverter(new HibernateProxyConverter());
60 xstream.registerConverter(new HibernatePersistentCollectionConverter(xstream
61 .getMapper()));
62 xstream.registerConverter(new HibernatePersistentMapConverter(xstream.getMapper()));
63 xstream
64 .registerConverter(new HibernatePersistentSortedMapConverter(xstream.getMapper()));
65 xstream
66 .registerConverter(new HibernatePersistentSortedSetConverter(xstream.getMapper()));
67
68 return xstream;
69 }
70
71 public static SessionFactory getSessionFactory() {
72 return sessionFactory;
73 }
74 }
0 /*
1 * Copyright (C) 2011, 2012 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 11. October 2011 by Joerg Schaible
9 */
10
11 package acceptance.hibernate;
12
13 import java.lang.reflect.Constructor;
14 import java.lang.reflect.InvocationTargetException;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.TreeMap;
20 import java.util.TreeSet;
21
22 import com.thoughtworks.xstream.hibernate.util.Hibernate;
23
24
25 /**
26 * @author J&ouml;rg Schaible
27 */
28 public class HibernateCollectionsTypeCompatibilityTest extends AbstractHibernateAcceptanceTest {
29
30 public void testPersistentBag() {
31 assertXmlEquals(new ArrayList(), newHibernateCollection(Hibernate.PersistentBag, Collections.EMPTY_LIST));
32 }
33
34 public void testPersistentList() {
35 assertXmlEquals(new ArrayList(), newHibernateCollection(Hibernate.PersistentList, Collections.EMPTY_LIST));
36 }
37
38 public void testPersistentMap() {
39 assertXmlEquals(new HashMap(), newHibernateCollection(Hibernate.PersistentMap, Collections.EMPTY_MAP));
40 }
41
42 public void testPersistentSet() {
43 assertXmlEquals(new HashSet(), newHibernateCollection(Hibernate.PersistentSet, Collections.EMPTY_SET));
44 }
45
46 public void testPersistentSortedMap() {
47 assertXmlEquals(new TreeMap(), newHibernateCollection(Hibernate.PersistentSortedMap, new TreeMap()));
48 }
49
50 public void testPersistentSortedSet() {
51 assertXmlEquals(new TreeSet(), newHibernateCollection(Hibernate.PersistentSortedSet, new TreeSet()));
52 }
53
54 private Object newHibernateCollection(Class type, Object secondArg) {
55 Object instance = null;
56 Constructor[] ctors = type.getConstructors();
57 for(int i = 0; i < ctors.length; ++i) {
58 if (ctors[i].getParameterTypes().length == 2) {
59 try {
60 instance = ctors[i].newInstance(new Object[]{null, secondArg});
61 } catch (InstantiationException e) {
62 e.printStackTrace();
63 } catch (IllegalAccessException e) {
64 e.printStackTrace();
65 } catch (InvocationTargetException e) {
66 e.printStackTrace();
67 }
68 break;
69 }
70 }
71 assertNotNull(instance);
72 return instance;
73 }
74
75 private void assertXmlEquals(Object reference, Object hibernateCollection) {
76 final String expectedXml = xstream.toXML(reference);
77 final String loadedXml = xstream.toXML(hibernateCollection);
78 assertEquals(expectedXml, loadedXml);
79 }
80 }
0 /*
1 * Copyright (C) 2011, 2012 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 25. March 2011 by Jaime Metcher
9 */
10
11 package acceptance.hibernate;
12
13 import acceptance.hibernate.reference.BaseDomainObject;
14 import acceptance.hibernate.reference.Department;
15 import acceptance.hibernate.reference.Division;
16 import acceptance.hibernate.reference.Person;
17 import acceptance.hibernate.reference.Site;
18
19 import org.hibernate.Session;
20 import org.hibernate.proxy.HibernateProxy;
21
22
23 /**
24 * @author Jaime Metcher
25 * @author J&ouml;rg Schaible
26 */
27 public class HibernateReferenceTest extends AbstractHibernateAcceptanceTest {
28
29 protected void setUp() throws Exception {
30 super.setUp();
31 // don't write the primary keys in this test
32 xstream.omitField(BaseDomainObject.class, "id");
33 xstream.alias("department", Department.class);
34 xstream.alias("division", Division.class);
35 xstream.alias("person", Person.class);
36 xstream.alias("site", Site.class);
37 }
38
39 protected void tearDown() {
40 try {
41 final Session session = getSessionFactory().getCurrentSession();
42 session.beginTransaction();
43 final Division div = (Division)session.createQuery("from Division").uniqueResult();
44 session.delete(div);
45 session.getTransaction().commit();
46 } catch (RuntimeException e) {
47 e.printStackTrace();
48 }
49 }
50
51 public void testObjectGraphWithReferences() {
52 final Division memory = setupNonpersistentDivision();
53 final Division persisted = setupPersistentDivision();
54
55 final String expectedXml = xstream.toXML(memory);
56 final String persistedXml = xstream.toXML(persisted);
57
58 final Session session = getSessionFactory().getCurrentSession();
59 session.beginTransaction();
60 final Division loaded = (Division)session.createQuery("from Division").uniqueResult();
61 final String loadedXml = xstream.toXML(loaded);
62 session.flush();
63 session.getTransaction().commit();
64 assertEquals(expectedXml, persistedXml);
65 assertEquals(expectedXml, loadedXml);
66 }
67
68 public void testLazyProxyWithReferences() {
69 setupPersistentDivision();
70
71 final Session session = getSessionFactory().getCurrentSession();
72 session.beginTransaction();
73 final Division loaded = (Division)session.createQuery("from Division").uniqueResult();
74 final Department dept = (Department)loaded.getDepartments().iterator().next();
75 final Person person = (Person)dept.getPeople().iterator().next();
76 final Site site = person.getSite();
77 assertTrue(HibernateProxy.class.isAssignableFrom(site.getClass()));
78 final String loadedXml = xstream.toXML(site);
79 session.flush();
80 session.getTransaction().commit();
81
82 final String expectedXml = ""
83 + "<site>\n"
84 + " <name>Site1</name>\n"
85 + " <people>\n"
86 + " <person>\n"
87 + " <name>Tom</name>\n"
88 + " <department>\n"
89 + " <name>Dep1</name>\n"
90 + " <division>\n"
91 + " <name>Div1</name>\n"
92 + " <departments>\n"
93 + " <department reference=\"../../..\"/>\n"
94 + " </departments>\n"
95 + " </division>\n"
96 + " <people>\n"
97 + " <person reference=\"../../..\"/>\n"
98 + " </people>\n"
99 + " </department>\n"
100 + " <site reference=\"../../..\"/>\n"
101 + " </person>\n"
102 + " </people>\n"
103 + "</site>";
104 assertEquals(expectedXml, loadedXml);
105 }
106
107 /**
108 * Create the object within a Hibernate session and persist it.
109 */
110 private Division setupPersistentDivision() {
111 final Session session = getSessionFactory().getCurrentSession();
112 session.beginTransaction();
113 final Division div = new Division("Div1");
114 final Department dep = new Department("Dep1", div);
115 final Site site = new Site("Site1");
116 /*
117 * This save is necessitated by the fact that Hibernate's transitive persistence is
118 * depth-first and does not do a full graph analysis. Therefore it would be possible for
119 * Hibernate to try to save the person record before the site record, which would throw
120 * an error if the person.site FK is non-nullable.
121 */
122 session.save(site);
123 new Person("Tom", dep, site);
124 session.save(div);
125 session.flush();
126 session.getTransaction().commit();
127 return div;
128 }
129
130 /**
131 * Create the object graph in-memory without Hibernate.
132 */
133 private Division setupNonpersistentDivision() {
134 final Division div = new Division("Div1");
135 final Department dep = new Department("Dep1", div);
136 final Site site = new Site("Site1");
137 new Person("Tom", dep, site);
138 return div;
139 }
140
141 /**
142 * Load object graph with Hibernate from the database.
143 */
144 private Division getPersistentDivision() {
145 final Session session = getSessionFactory().getCurrentSession();
146 session.beginTransaction();
147 final Division div = (Division)session.createQuery("from Division").uniqueResult();
148 session.getTransaction().commit();
149 return div;
150 }
151 }
0 /*
1 * Copyright (C) 2011 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 25. March 2011 by Jaime Metcher
9 */
10
11 package acceptance.hibernate.reference;
12
13 /**
14 * @author Jaime Metcher
15 */
16 public class BaseDomainObject {
17
18 protected Integer id;
19 protected String name;
20
21 public String getName() {
22 return name;
23 }
24
25 public BaseDomainObject() {
26 super();
27 }
28
29 }
0 <?xml version="1.0"?>
1 <!DOCTYPE hibernate-mapping PUBLIC
2 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4 <!--
5 Copyright (C) 2011 XStream Committers
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 25. March 2011 by Jaime Metcher
13 -->
14 <hibernate-mapping package="acceptance.hibernate.reference">
15 <class name="Department" table="Departments">
16 <id name="id" column="ID" access="field">
17 <generator class="native"/>
18 </id>
19
20 <property name="name" type="string" column="name" access="field"/>
21
22 <many-to-one name="division" class="Division" access="field">
23 <column name="divisionid" />
24 </many-to-one>
25
26 <set name="people" inverse="true" cascade="all-delete-orphan" access="field">
27 <key>
28 <column name="departmentid" />
29 </key>
30 <one-to-many class="Person" />
31 </set>
32
33 </class>
34 </hibernate-mapping>
0 /*
1 * Copyright (C) 2011 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 25. March 2011 by Jaime Metcher
9 */
10 package acceptance.hibernate.reference;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15
16 /**
17 * @author Jaime Metcher
18 */
19 public class Department extends BaseDomainObject {
20
21 private Division division;
22
23 private Set people = new HashSet(0);
24
25 protected Department() {
26 }
27
28 public Department(final String name, final Division division) {
29 this.name = name;
30 this.division = division;
31 division.getDepartments().add(this);
32 }
33
34 public Set getPeople() {
35 return people;
36 }
37 }
0 <?xml version="1.0"?>
1 <!DOCTYPE hibernate-mapping PUBLIC
2 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4 <!--
5 Copyright (C) 2011 XStream Committers
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 25. March 2011 by Jaime Metcher
13 -->
14 <hibernate-mapping package="acceptance.hibernate.reference">
15 <class name="Division" table="divisions">
16 <id name="id" column="ID" access="field">
17 <generator class="identity"/>
18 </id>
19
20 <property name="name" type="string" column="name" access="field"/>
21
22 <set name="departments" inverse="true" cascade="all-delete-orphan" access="field">
23 <key>
24 <column name="divisionid" />
25 </key>
26 <one-to-many class="Department" />
27 </set>
28
29 </class>
30 </hibernate-mapping>
0 /*
1 * Copyright (C) 2011 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 25. March 2011 by Jaime Metcher
9 */
10 package acceptance.hibernate.reference;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15
16 /**
17 * @author Jaime Metcher
18 */
19 public class Division extends BaseDomainObject {
20
21 private Set departments = new HashSet(0);
22
23 protected Division() {
24 }
25
26 public Division(final String name) {
27 this.name = name;
28 }
29
30 public Set getDepartments() {
31 return departments;
32 }
33
34 }
0 <?xml version="1.0"?>
1 <!DOCTYPE hibernate-mapping PUBLIC
2 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4 <!--
5 Copyright (C) 2011 XStream Committers
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 25. March 2011 by Jaime Metcher
13 -->
14 <hibernate-mapping package="acceptance.hibernate.reference">
15 <class name="Person" table="people">
16 <id name="id" column="ID" access="field">
17 <generator class="native"/>
18 </id>
19
20 <property name="name" type="string" column="name" access="field"/>
21
22 <many-to-one name="department" class="Department" access="field">
23 <column name="departmentid" />
24 </many-to-one>
25 <many-to-one name="site" class="Site" access="field">
26 <column name="siteid" />
27 </many-to-one>
28
29
30 </class>
31 </hibernate-mapping>
0 /*
1 * Copyright (C) 2011 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 25. March 2011 by Jaime Metcher
9 */
10 package acceptance.hibernate.reference;
11
12 /**
13 * @author Jaime Metcher
14 */
15 public class Person extends BaseDomainObject {
16
17 private Department department;
18 private Site site;
19
20 protected Person() {
21 }
22
23 public Person(final String name, final Department department, final Site site) {
24 this.name = name;
25 this.department = department;
26 this.site = site;
27
28 department.getPeople().add(this);
29 site.getPeople().add(this);
30 }
31
32 public Site getSite() {
33 return site;
34 }
35
36 public Department getDepartment() {
37 return department;
38 }
39
40 }
0 <?xml version="1.0"?>
1 <!DOCTYPE hibernate-mapping PUBLIC
2 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
4 <!--
5 Copyright (C) 2011 XStream Committers
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 25. March 2011 by Jaime Metcher
13 -->
14 <hibernate-mapping package="acceptance.hibernate.reference">
15 <class name="Site" table="Sites">
16 <id name="id" column="ID" access="field">
17 <generator class="native"/>
18 </id>
19 <property name="name" type="string" column="name" access="field"/>
20 <set name="people" inverse="true" cascade="all-delete-orphan" access="field">
21 <key>
22 <column name="siteid" />
23 </key>
24 <one-to-many class="Person" />
25 </set>
26 </class>
27 </hibernate-mapping>
0 /*
1 * Copyright (C) 2011 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 25. March 2011 by Jaime Metcher
9 */
10 package acceptance.hibernate.reference;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15
16 /**
17 * @author Jaime Metcher
18 */
19 public class Site extends BaseDomainObject {
20
21 private Set people = new HashSet(0);
22
23 protected Site() {
24 }
25
26 public Site(final String name) {
27 this.name = name;
28 }
29
30 public Set getPeople() {
31 return people;
32 }
33
34 }
0 <?xml version='1.0' encoding='utf-8'?>
1 <!DOCTYPE hibernate-configuration PUBLIC
2 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
3 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
4 <!--
5 Copyright (C) 2011 XStream Committers
6 All rights reserved.
7
8 The software in this package is published under the terms of the BSD
9 style license a copy of which has been included with this distribution in
10 the LICENSE.txt file.
11
12 Created on 25. March 2011 by Jaime Metcher
13 -->
14 <hibernate-configuration>
15 <session-factory>
16 <!-- Database connection settings -->
17 <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
18 <property name="connection.url">jdbc:hsqldb:mem:testdb</property>
19 <property name="connection.username">sa</property>
20 <property name="connection.password"></property>
21
22 <!-- JDBC connection pool (use the built-in) -->
23 <property name="connection.pool_size">1</property>
24
25 <!-- SQL dialect -->
26 <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
27
28 <!-- Enable Hibernate's automatic session context management -->
29 <property name="current_session_context_class">thread</property>
30
31 <!-- Disable the second-level cache -->
32 <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
33
34 <!-- Echo all executed SQL to stdout -->
35 <property name="show_sql">false</property>
36
37 <!-- Drop and re-create the database schema on startup -->
38 <property name="hbm2ddl.auto">update</property>
39
40 <mapping resource="acceptance/hibernate/reference/Department.hbm.xml"/>
41 <mapping resource="acceptance/hibernate/reference/Division.hbm.xml"/>
42 <mapping resource="acceptance/hibernate/reference/Site.hbm.xml"/>
43 <mapping resource="acceptance/hibernate/reference/Person.hbm.xml"/>
44 </session-factory>
45 </hibernate-configuration>
46