diff --git a/src/main/java/com/github/cameltooling/model/BaseOptionModel.java b/src/main/java/com/github/cameltooling/model/BaseOptionModel.java new file mode 100644 index 0000000..91f00d4 --- /dev/null +++ b/src/main/java/com/github/cameltooling/model/BaseOptionModel.java @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.cameltooling.model; + +/** + * @author lheinema + */ +public class BaseOptionModel { + + private String name; + private String kind; + private String group; + private String required; + private String type; + private String javaType; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getRequired() { + return required; + } + + public void setRequired(String required) { + this.required = required; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getJavaType() { + return javaType; + } + + public void setJavaType(String javaType) { + this.javaType = javaType; + } +} diff --git a/src/main/java/com/github/cameltooling/model/ComponentOptionModel.java b/src/main/java/com/github/cameltooling/model/ComponentOptionModel.java index 7b3e4fd..8f11726 100644 --- a/src/main/java/com/github/cameltooling/model/ComponentOptionModel.java +++ b/src/main/java/com/github/cameltooling/model/ComponentOptionModel.java @@ -16,68 +16,14 @@ */ package com.github.cameltooling.model; -public class ComponentOptionModel { +public class ComponentOptionModel extends BaseOptionModel{ - private String name; - private String kind; - private String group; - private String required; - private String type; - private String javaType; private String deprecated; private String secret; private String description; private String defaultValue; private String enums; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } - - public String getRequired() { - return required; - } - - public void setRequired(String required) { - this.required = required; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - public String getDeprecated() { return deprecated; } diff --git a/src/main/java/com/github/cameltooling/model/EndpointOptionModel.java b/src/main/java/com/github/cameltooling/model/EndpointOptionModel.java index 4037954..01b75d7 100644 --- a/src/main/java/com/github/cameltooling/model/EndpointOptionModel.java +++ b/src/main/java/com/github/cameltooling/model/EndpointOptionModel.java @@ -16,15 +16,9 @@ */ package com.github.cameltooling.model; -public class EndpointOptionModel { +public class EndpointOptionModel extends BaseOptionModel { - private String name; - private String kind; - private String group; private String label; - private String required; - private String type; - private String javaType; private String enums; private String prefix; private String multiValue; @@ -34,29 +28,6 @@ public class EndpointOptionModel { private String description; private String enumValues; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getKind() { - return kind; - } - - public void setKind(String kind) { - this.kind = kind; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } public String getLabel() { return label; @@ -66,30 +37,6 @@ public void setLabel(String label) { this.label = label; } - public String getRequired() { - return required; - } - - public void setRequired(String required) { - this.required = required; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - public String getEnums() { return enums; } @@ -153,5 +100,4 @@ public String getEnumValues() { public void setEnumValues(String enumValues) { this.enumValues = enumValues; } - } diff --git a/src/main/java/com/github/cameltooling/model/diagnostic/CamelDiagnosticEndpointMessage.java b/src/main/java/com/github/cameltooling/model/diagnostic/CamelDiagnosticEndpointMessage.java index e0f827e..86b1997 100644 --- a/src/main/java/com/github/cameltooling/model/diagnostic/CamelDiagnosticEndpointMessage.java +++ b/src/main/java/com/github/cameltooling/model/diagnostic/CamelDiagnosticEndpointMessage.java @@ -28,6 +28,7 @@ public interface CamelDiagnosticEndpointMessage { * * @param endpointValidationResult - The validation result return from the {@link org.apache.camel.catalog.CamelCatalog} validator * @param valueObj - The key and value object validated. + * @return the error message */ String getErrorMessage(EndpointValidationResult endpointValidationResult, T valueObj); diff --git a/src/main/java/com/github/cameltooling/model/util/ModelHelper.java b/src/main/java/com/github/cameltooling/model/util/ModelHelper.java index d871fed..5fe0e5f 100644 --- a/src/main/java/com/github/cameltooling/model/util/ModelHelper.java +++ b/src/main/java/com/github/cameltooling/model/util/ModelHelper.java @@ -29,6 +29,10 @@ public final class ModelHelper { + private static final String DESCRIPTION = "description"; + private static final String DEPRECATED = "deprecated"; + private static final String JAVA_TYPE = "javaType"; + private ModelHelper() { // utility class } @@ -42,12 +46,12 @@ public static ComponentModel generateComponentModel(String json, boolean include component.setAlternativeSyntax(getSafeValue("alternativeSyntax", rows)); component.setAlternativeSchemes(getSafeValue("alternativeSchemes", rows)); component.setTitle(getSafeValue("title", rows)); - component.setDescription(getSafeValue("description", rows)); + component.setDescription(getSafeValue(DESCRIPTION, rows)); component.setLabel(getSafeValue("label", rows)); - component.setDeprecated(getSafeValue("deprecated", rows)); + component.setDeprecated(getSafeValue(DEPRECATED, rows)); component.setConsumerOnly(getSafeValue("consumerOnly", rows)); component.setProducerOnly(getSafeValue("producerOnly", rows)); - component.setJavaType(getSafeValue("javaType", rows)); + component.setJavaType(getSafeValue(JAVA_TYPE, rows)); component.setGroupId(getSafeValue("groupId", rows)); component.setArtifactId(getSafeValue("artifactId", rows)); component.setVersion(getSafeValue("version", rows)); @@ -61,12 +65,12 @@ public static ComponentModel generateComponentModel(String json, boolean include option.setGroup(getSafeValue("group", row)); option.setRequired(getSafeValue("required", row)); option.setType(getSafeValue("type", row)); - option.setJavaType(getSafeValue("javaType", row)); + option.setJavaType(getSafeValue(JAVA_TYPE, row)); option.setEnums(getSafeValue("enum", row)); - option.setDeprecated(getSafeValue("deprecated", row)); + option.setDeprecated(getSafeValue(DEPRECATED, row)); option.setSecret(getSafeValue("secret", row)); option.setDefaultValue(getSafeValue("defaultValue", row)); - option.setDescription(getSafeValue("description", row)); + option.setDescription(getSafeValue(DESCRIPTION, row)); component.addComponentOption(option); } @@ -79,14 +83,14 @@ public static ComponentModel generateComponentModel(String json, boolean include option.setLabel(getSafeValue("label", row)); option.setRequired(getSafeValue("required", row)); option.setType(getSafeValue("type", row)); - option.setJavaType(getSafeValue("javaType", row)); + option.setJavaType(getSafeValue(JAVA_TYPE, row)); option.setEnums(getSafeValue("enum", row)); option.setPrefix(getSafeValue("prefix", row)); option.setMultiValue(getSafeValue("multiValue", row)); - option.setDeprecated(getSafeValue("deprecated", row)); + option.setDeprecated(getSafeValue(DEPRECATED, row)); option.setSecret(getSafeValue("secret", row)); option.setDefaultValue(getSafeValue("defaultValue", row)); - option.setDescription(getSafeValue("description", row)); + option.setDescription(getSafeValue(DESCRIPTION, row)); component.addEndpointOption(option); } } diff --git a/src/main/java/com/github/cameltooling/model/util/StringUtils.java b/src/main/java/com/github/cameltooling/model/util/StringUtils.java index 8ce2238..b3a3fe3 100644 --- a/src/main/java/com/github/cameltooling/model/util/StringUtils.java +++ b/src/main/java/com/github/cameltooling/model/util/StringUtils.java @@ -159,9 +159,7 @@ public static String wrapSeparator(String line, String separator, String newLine * @return wrapped line */ public static String wrapWords(String line, String newLine, int watermark, boolean wrapLongWords) { - if (line == null) { - return null; - } else { + if (line != null) { if (newLine == null) { newLine = System.lineSeparator(); } @@ -170,40 +168,45 @@ public static String wrapWords(String line, String newLine, int watermark, boole watermark = 1; } - int inputLineLength = line.length(); - int offset = 0; - StringBuilder sb = new StringBuilder(inputLineLength + 32); - - while (inputLineLength - offset > watermark) { - if (line.charAt(offset) == 32) { - ++offset; + return doWordWrap(line, newLine, watermark, wrapLongWords); + } + return null; + } + + private static String doWordWrap(String line, String newLine, int watermark, boolean wrapLongWords) { + int inputLineLength = line.length(); + int offset = 0; + StringBuilder sb = new StringBuilder(inputLineLength + 32); + + while (inputLineLength - offset > watermark) { + if (line.charAt(offset) == 32) { + ++offset; + } else { + int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); + if (spaceToWrapAt >= offset) { + sb.append(line.substring(offset, spaceToWrapAt)); + sb.append(newLine); + offset = spaceToWrapAt + 1; + } else if (wrapLongWords) { + sb.append(line.substring(offset, watermark + offset)); + sb.append(newLine); + offset += watermark; } else { - int spaceToWrapAt = line.lastIndexOf(32, watermark + offset); - if (spaceToWrapAt >= offset) { + spaceToWrapAt = line.indexOf(32, watermark + offset); + if (spaceToWrapAt >= 0) { sb.append(line.substring(offset, spaceToWrapAt)); sb.append(newLine); offset = spaceToWrapAt + 1; - } else if (wrapLongWords) { - sb.append(line.substring(offset, watermark + offset)); - sb.append(newLine); - offset += watermark; } else { - spaceToWrapAt = line.indexOf(32, watermark + offset); - if (spaceToWrapAt >= 0) { - sb.append(line.substring(offset, spaceToWrapAt)); - sb.append(newLine); - offset = spaceToWrapAt + 1; - } else { - sb.append(line.substring(offset)); - offset = inputLineLength; - } + sb.append(line.substring(offset)); + offset = inputLineLength; } } } - - sb.append(line.substring(offset)); - return sb.toString(); } + + sb.append(line.substring(offset)); + return sb.toString(); } /**