Skip to content

Commit

Permalink
CAMEL-10042: camel-spring-boot - Add default values to auto configura…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
davsclaus committed Jun 10, 2016
1 parent 8d81593 commit 1fa124d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,25 @@ private void createComponentConfigurationSource(String packageName, ComponentMod
// remove <?> as generic type as Roaster (Eclipse JDT) cannot use that
String type = option.getJavaType();
type = type.replaceAll("\\<\\?\\>", "");
// favor using Boolean types over boolean with Spring Boot
if ("boolean".equals(type)) {
type = "java.lang.Boolean";
}

PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
}
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
if ("java.lang.String".equals(option.getJavaType())) {
prop.getField().setStringInitializer(option.getDefaultValue());
} else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
prop.getField().setLiteralInitializer(option.getDefaultValue());
}
}
}

sortImports(javaClass);
Expand Down Expand Up @@ -266,13 +278,25 @@ private void createDataFormatConfigurationSource(String packageName, DataFormatM
// remove <?> as generic type as Roaster (Eclipse JDT) cannot use that
String type = option.getJavaType();
type = type.replaceAll("\\<\\?\\>", "");
// favor using Boolean types over boolean with Spring Boot
if ("boolean".equals(type)) {
type = "java.lang.Boolean";
}

PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
}
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
if ("java.lang.String".equals(option.getType())) {
prop.getField().setStringInitializer(option.getDefaultValue());
} else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
prop.getField().setLiteralInitializer(option.getDefaultValue());
}
}
}

sortImports(javaClass);
Expand Down Expand Up @@ -734,6 +758,7 @@ private static ComponentModel generateComponentModel(String componentName, Strin
option.setJavaType(getSafeValue("javaType", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setDescription(getSafeValue("description", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
component.addComponentOption(option);
}

Expand Down Expand Up @@ -782,6 +807,7 @@ private static DataFormatModel generateDataFormatModel(String dataFormatName, St
option.setJavaType(getSafeValue("javaType", row));
option.setDeprecated(getSafeValue("deprecated", row));
option.setDescription(getSafeValue("description", row));
option.setDefaultValue(getSafeValue("defaultValue", row));
dataFormat.addDataFormatOption(option);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ComponentOptionModel {
private String javaType;
private String deprecated;
private String description;
private String defaultValue;

public String getName() {
return name;
Expand Down Expand Up @@ -73,6 +74,14 @@ public void setDescription(String description) {
this.description = description;
}

public String getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public String getShortJavaType() {
if (javaType.startsWith("java.util.Map")) {
return "Map";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DataFormatOptionModel {
private String javaType;
private String deprecated;
private String description;
private String defaultValue;

public String getName() {
return name;
Expand Down Expand Up @@ -73,6 +74,14 @@ public void setDescription(String description) {
this.description = description;
}

public String getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public String getShortJavaType() {
if (javaType.startsWith("java.util.Map")) {
return "Map";
Expand Down

0 comments on commit 1fa124d

Please sign in to comment.