This repository was archived by the owner on Dec 15, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +145
-8
lines changed
java/org/springframework/issues/spr9157 Expand file tree Collapse file tree 10 files changed +145
-8
lines changed Original file line number Diff line number Diff line change 99 <description >SPR-9157 - Spring 3 converter</description >
1010
1111 <properties >
12- <java-version >1.6 </java-version >
12+ <java-version >1.5 </java-version >
1313 <spring .version>3.0.7.RELEASE</spring .version>
1414 <slf4j .version>1.6.4</slf4j .version>
1515 </properties >
Original file line number Diff line number Diff line change 1+ package org .springframework .issues .spr9157 .model ;
2+
3+ /**
4+ * Enhanced environment.
5+ *
6+ * @author ferengra
7+ */
8+ public interface EnhancedEnvironment extends Environment {
9+
10+ String getDescription ();
11+ }
Original file line number Diff line number Diff line change 1+ package org .springframework .issues .spr9157 .model ;
2+
3+ /**
4+ * Enhanced environment implementation.
5+ *
6+ * @author ferengra
7+ */
8+ public class EnhancedEnvironmentImpl extends EnvironmentImpl implements EnhancedEnvironment {
9+ private String description ;
10+
11+ @ SuppressWarnings ("unused" )
12+ private EnhancedEnvironmentImpl () {
13+ // Hibernate
14+ }
15+
16+ public EnhancedEnvironmentImpl (String name , String description ) {
17+ super (name );
18+ this .description = description ;
19+ }
20+
21+ public String getDescription () {
22+ return description ;
23+ }
24+
25+ public void setDescription (String description ) {
26+ this .description = description ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ package org .springframework .issues .spr9157 .model ;
2+
3+ /**
4+ * Environment.
5+ *
6+ * @author ferengra
7+ */
8+ public interface Environment {
9+
10+ String getName ();
11+ }
Original file line number Diff line number Diff line change 1+ package org .springframework .issues .spr9157 .model ;
2+
3+ /**
4+ * Environment implementation.
5+ *
6+ * @author ferengra
7+ */
8+ public class EnvironmentImpl implements Environment {
9+ private Long id ;
10+ private String name ;
11+
12+ protected EnvironmentImpl () {
13+ // Hibernate
14+ }
15+
16+ public EnvironmentImpl (String name ) {
17+ this .name = name ;
18+ }
19+
20+ public String getName () {
21+ return name ;
22+ }
23+
24+ public void setName (String name ) {
25+ this .name = name ;
26+ }
27+
28+ public Long getId () {
29+ return id ;
30+ }
31+
32+ @ Override
33+ public int hashCode () {
34+ final int prime = 31 ;
35+ int result = 1 ;
36+ result = prime * result + ((getName () == null ) ? 0 : getName ().hashCode ());
37+ return result ;
38+ }
39+
40+ @ Override
41+ public boolean equals (Object obj ) {
42+ if (this == obj ) {
43+ return true ;
44+ }
45+ if (!(obj instanceof EnhancedEnvironmentImpl )) {
46+ return false ;
47+ }
48+ EnhancedEnvironmentImpl other = (EnhancedEnvironmentImpl ) obj ;
49+ return getName ().equals (other .getName ());
50+ }
51+
52+ @ Override
53+ public String toString () {
54+ StringBuilder builder = new StringBuilder ();
55+ builder .append ("EnvironmentImpl [id=" ).append (id ).append (", name=" ).append (name ).append ("]" );
56+ return builder .toString ();
57+ }
58+ }
Original file line number Diff line number Diff line change 11package org .springframework .issues .spr9157 .web .controller ;
22
3-
43import org .slf4j .Logger ;
54import org .slf4j .LoggerFactory ;
6- import org .springframework .issues .spr9157 .Environment ;
5+ import org .springframework .issues .spr9157 .model . EnhancedEnvironment ;
76import org .springframework .stereotype .Controller ;
87import org .springframework .web .bind .annotation .RequestMapping ;
98import org .springframework .web .bind .annotation .RequestMethod ;
1211
1312/**
1413 * Controller for managing environment.
14+ *
15+ * @author ferengra
1516 */
1617@ Controller
1718public class EnvironmentController {
@@ -24,7 +25,7 @@ public ModelAndView getEnvironments() {
2425 }
2526
2627 @ RequestMapping (value = "/environment.html" , method = RequestMethod .GET )
27- public ModelAndView getEnvironment (@ RequestParam Environment environment ) {
28+ public ModelAndView getEnvironment (@ RequestParam EnhancedEnvironment environment ) {
2829 LOG .debug ("environment: {}" , environment );
2930 ModelAndView mav = new ModelAndView ("environment" );
3031 mav .addObject ("environment" , environment );
Original file line number Diff line number Diff line change 11package org .springframework .issues .spr9157 .web .util ;
22
3-
43import org .slf4j .Logger ;
54import org .slf4j .LoggerFactory ;
65import org .springframework .core .convert .converter .Converter ;
7- import org .springframework .issues .spr9157 .Environment ;
6+ import org .springframework .issues .spr9157 .model .EnhancedEnvironmentImpl ;
7+ import org .springframework .issues .spr9157 .model .Environment ;
88import org .springframework .util .StringUtils ;
99
1010/**
1111 * Environment converter.
12+ *
13+ * @author ferengra
1214 */
1315public class EnvironmentConverter implements Converter <String , Environment > {
1416 private static final Logger LOG = LoggerFactory .getLogger (EnvironmentConverter .class );
@@ -18,6 +20,6 @@ public Environment convert(String source) {
1820 if (!StringUtils .hasText (source )) {
1921 return null ;
2022 }
21- return new Environment ( source .trim ());
23+ return new EnhancedEnvironmentImpl ( source . trim (), source .trim ());
2224 }
2325}
Original file line number Diff line number Diff line change 4646 </set >
4747 </property >
4848 </bean >
49+
50+ <bean class =" org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
51+ <property name =" defaultErrorView" value =" errorInternal" />
52+ <property name =" warnLogCategory" value =" spr9157" />
53+ </bean >
4954</beans >
Original file line number Diff line number Diff line change 1- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
21<%@ page contentType =" text/html; charset=UTF-8" pageEncoding =" UTF-8" %>
2+ <jsp:text >
3+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
4+ </jsp:text >
35
46<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
57<head >
Original file line number Diff line number Diff line change 1+ <%@ page contentType =" text/html; charset=UTF-8" pageEncoding =" UTF-8" %>
2+ <%@ page isErrorPage =" true" %>
3+ <%@ page import =" org.slf4j.LoggerFactory" %>
4+ <jsp:text >
5+ <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]>
6+ </jsp:text >
7+
8+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9+ <head >
10+ <title >Spring 3 Converter</title >
11+ </head >
12+ <body >
13+ Error<br />
14+ <%
15+ LoggerFactory . getLogger(" InternalError" ). error(" Exception occured: " , exception);
16+ % >
17+ <%= exception. toString() % > <br />
18+ </body >
19+ </html >
You can’t perform that action at this time.
0 commit comments