001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.model.language;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023import javax.xml.bind.annotation.XmlTransient;
024
025import org.apache.camel.spi.Metadata;
026
027/**
028 * To use JsonPath in Camel expressions or predicates.
029 */
030@Metadata(firstVersion = "2.13.0", label = "language,json", title = "JsonPath")
031@XmlRootElement(name = "jsonpath")
032@XmlAccessorType(XmlAccessType.FIELD)
033public class JsonPathExpression extends ExpressionDefinition {
034
035    @XmlAttribute(name = "resultType")
036    private String resultTypeName;
037    @XmlTransient
038    private Class<?> resultType;
039    @XmlAttribute
040    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
041    private String suppressExceptions;
042    @XmlAttribute
043    @Metadata(defaultValue = "true", javaType = "java.lang.Boolean")
044    private String allowSimple;
045    @XmlAttribute
046    @Metadata(defaultValue = "true", javaType = "java.lang.Boolean")
047    private String allowEasyPredicate;
048    @XmlAttribute
049    @Metadata(defaultValue = "false", javaType = "java.lang.Boolean")
050    private String writeAsString;
051    @XmlAttribute
052    private String headerName;
053
054    public JsonPathExpression() {
055    }
056
057    public JsonPathExpression(String expression) {
058        super(expression);
059    }
060
061    public String getResultTypeName() {
062        return resultTypeName;
063    }
064
065    /**
066     * Sets the class name of the result type (type from output)
067     */
068    public void setResultTypeName(String resultTypeName) {
069        this.resultTypeName = resultTypeName;
070    }
071
072    public Class<?> getResultType() {
073        return resultType;
074    }
075
076    /**
077     * Sets the class of the result type (type from output)
078     */
079    public void setResultType(Class<?> resultType) {
080        this.resultType = resultType;
081    }
082
083    public String getSuppressExceptions() {
084        return suppressExceptions;
085    }
086
087    public String getAllowSimple() {
088        return allowSimple;
089    }
090
091    /**
092     * Whether to allow in inlined simple exceptions in the JsonPath expression
093     */
094    public void setAllowSimple(String allowSimple) {
095        this.allowSimple = allowSimple;
096    }
097
098    public String getAllowEasyPredicate() {
099        return allowEasyPredicate;
100    }
101
102    /**
103     * Whether to allow using the easy predicate parser to pre-parse predicates.
104     */
105    public void setAllowEasyPredicate(String allowEasyPredicate) {
106        this.allowEasyPredicate = allowEasyPredicate;
107    }
108
109    /**
110     * Whether to suppress exceptions such as PathNotFoundException.
111     */
112    public void setSuppressExceptions(String suppressExceptions) {
113        this.suppressExceptions = suppressExceptions;
114    }
115
116    public String getWriteAsString() {
117        return writeAsString;
118    }
119
120    /**
121     * Whether to write the output of each row/element as a JSON String value
122     * instead of a Map/POJO value.
123     */
124    public void setWriteAsString(String writeAsString) {
125        this.writeAsString = writeAsString;
126    }
127
128    public String getHeaderName() {
129        return headerName;
130    }
131
132    /**
133     * Name of header to use as input, instead of the message body
134     */
135    public void setHeaderName(String headerName) {
136        this.headerName = headerName;
137    }
138
139    @Override
140    public String getLanguage() {
141        return "jsonpath";
142    }
143
144}