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.dataformat;
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;
023
024import org.apache.camel.model.DataFormatDefinition;
025import org.apache.camel.spi.Metadata;
026
027/**
028 * Unmarshal XML payloads to POJOs and back using JAXB2 XML marshalling standard.
029 */
030@Metadata(firstVersion = "1.0.0", label = "dataformat,transformation,xml", title = "JAXB")
031@XmlRootElement(name = "jaxb")
032@XmlAccessorType(XmlAccessType.FIELD)
033public class JaxbDataFormat extends DataFormatDefinition {
034    @XmlAttribute(required = true)
035    private String contextPath;
036    @XmlAttribute
037    @Metadata(javaType = "java.lang.Boolean")
038    private String contextPathIsClassName;
039    @XmlAttribute
040    private String schema;
041    @XmlAttribute
042    @Metadata(javaType = "java.lang.Integer", enums = "0,1,2", defaultValue = "0")
043    private String schemaSeverityLevel;
044    @XmlAttribute
045    @Metadata(javaType = "java.lang.Boolean")
046    private String prettyPrint;
047    @XmlAttribute
048    @Metadata(javaType = "java.lang.Boolean")
049    private String objectFactory;
050    @XmlAttribute
051    @Metadata(javaType = "java.lang.Boolean")
052    private String ignoreJAXBElement;
053    @XmlAttribute
054    @Metadata(javaType = "java.lang.Boolean")
055    private String mustBeJAXBElement;
056    @XmlAttribute
057    @Metadata(javaType = "java.lang.Boolean")
058    private String filterNonXmlChars;
059    @XmlAttribute
060    private String encoding;
061    @XmlAttribute
062    @Metadata(javaType = "java.lang.Boolean")
063    private String fragment;
064    // Partial encoding
065    @XmlAttribute
066    private String partClass;
067    @XmlAttribute
068    private String partNamespace;
069    @XmlAttribute
070    private String namespacePrefixRef;
071    @XmlAttribute
072    @Metadata(label = "advanced")
073    private String xmlStreamWriterWrapper;
074    @XmlAttribute
075    private String schemaLocation;
076    @XmlAttribute
077    private String noNamespaceSchemaLocation;
078    @XmlAttribute
079    @Metadata(label = "advanced")
080    private String jaxbProviderProperties;
081
082    public JaxbDataFormat() {
083        super("jaxb");
084    }
085
086    public JaxbDataFormat(boolean prettyPrint) {
087        this();
088        setPrettyPrint(Boolean.toString(prettyPrint));
089    }
090
091    public String getContextPath() {
092        return contextPath;
093    }
094
095    /**
096     * Package name where your JAXB classes are located.
097     */
098    public void setContextPath(String contextPath) {
099        this.contextPath = contextPath;
100    }
101
102    public String getContextPathIsClassName() {
103        return contextPathIsClassName;
104    }
105
106    /**
107     * This can be set to true to mark that the contextPath is referring to a classname and not a package name.
108     */
109    public void setContextPathIsClassName(String contextPathIsClassName) {
110        this.contextPathIsClassName = contextPathIsClassName;
111    }
112
113    public String getSchema() {
114        return schema;
115    }
116
117    /**
118     * To validate against an existing schema. Your can use the prefix
119     * classpath:, file:* or *http: to specify how the resource should by
120     * resolved. You can separate multiple schema files by using the ','
121     * character.
122     */
123    public void setSchema(String schema) {
124        this.schema = schema;
125    }
126
127    public String getSchemaSeverityLevel() {
128        return schemaSeverityLevel;
129    }
130
131    /**
132     * Sets the schema severity level to use when validating against a schema.
133     * This level determines the minimum severity error that triggers JAXB to
134     * stop continue parsing. The default value of 0 (warning) means that any
135     * error (warning, error or fatal error) will trigger JAXB to stop. There
136     * are the following three levels: 0=warning, 1=error, 2=fatal error.
137     */
138    public void setSchemaSeverityLevel(String schemaSeverityLevel) {
139        this.schemaSeverityLevel = schemaSeverityLevel;
140    }
141
142    public String getPrettyPrint() {
143        return prettyPrint;
144    }
145
146    /**
147     * To enable pretty printing output nicely formatted.
148     * <p/>
149     * Is by default false.
150     */
151    public void setPrettyPrint(String prettyPrint) {
152        this.prettyPrint = prettyPrint;
153    }
154
155    public String getObjectFactory() {
156        return objectFactory;
157    }
158
159    /**
160     * Whether to allow using ObjectFactory classes to create the POJO classes
161     * during marshalling. This only applies to POJO classes that has not been
162     * annotated with JAXB and providing jaxb.index descriptor files.
163     */
164    public void setObjectFactory(String objectFactory) {
165        this.objectFactory = objectFactory;
166    }
167
168    public String getIgnoreJAXBElement() {
169        return ignoreJAXBElement;
170    }
171
172    /**
173     * Whether to ignore JAXBElement elements - only needed to be set to false
174     * in very special use-cases.
175     */
176    public void setIgnoreJAXBElement(String ignoreJAXBElement) {
177        this.ignoreJAXBElement = ignoreJAXBElement;
178    }
179
180    public String getMustBeJAXBElement() {
181        return mustBeJAXBElement;
182    }
183
184    /**
185     * Whether marhsalling must be java objects with JAXB annotations. And if
186     * not then it fails. This option can be set to false to relax that, such as
187     * when the data is already in XML format.
188     */
189    public void setMustBeJAXBElement(String mustBeJAXBElement) {
190        this.mustBeJAXBElement = mustBeJAXBElement;
191    }
192
193    /**
194     * To turn on marshalling XML fragment trees. By default JAXB looks
195     * for @XmlRootElement annotation on given class to operate on whole XML
196     * tree. This is useful but not always - sometimes generated code does not
197     * have @XmlRootElement annotation, sometimes you need unmarshall only part
198     * of tree. In that case you can use partial unmarshalling. To enable this
199     * behaviours you need set property partClass. Camel will pass this class to
200     * JAXB's unmarshaler.
201     */
202    public void setFragment(String fragment) {
203        this.fragment = fragment;
204    }
205
206    public String getFragment() {
207        return fragment;
208    }
209
210    public String getFilterNonXmlChars() {
211        return filterNonXmlChars;
212    }
213
214    /**
215     * To ignore non xml characheters and replace them with an empty space.
216     */
217    public void setFilterNonXmlChars(String filterNonXmlChars) {
218        this.filterNonXmlChars = filterNonXmlChars;
219    }
220
221    public String getEncoding() {
222        return encoding;
223    }
224
225    /**
226     * To overrule and use a specific encoding
227     */
228    public void setEncoding(String encoding) {
229        this.encoding = encoding;
230    }
231
232    public String getPartClass() {
233        return partClass;
234    }
235
236    /**
237     * Name of class used for fragment parsing.
238     * <p/>
239     * See more details at the fragment option.
240     */
241    public void setPartClass(String partClass) {
242        this.partClass = partClass;
243    }
244
245    public String getPartNamespace() {
246        return partNamespace;
247    }
248
249    /**
250     * XML namespace to use for fragment parsing.
251     * <p/>
252     * See more details at the fragment option.
253     */
254    public void setPartNamespace(String partNamespace) {
255        this.partNamespace = partNamespace;
256    }
257
258    public String getNamespacePrefixRef() {
259        return namespacePrefixRef;
260    }
261
262    /**
263     * When marshalling using JAXB or SOAP then the JAXB implementation will
264     * automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To
265     * control this mapping, Camel allows you to refer to a map which contains
266     * the desired mapping.
267     */
268    public void setNamespacePrefixRef(String namespacePrefixRef) {
269        this.namespacePrefixRef = namespacePrefixRef;
270    }
271
272    public String getXmlStreamWriterWrapper() {
273        return xmlStreamWriterWrapper;
274    }
275
276    /**
277     * To use a custom xml stream writer.
278     */
279    public void setXmlStreamWriterWrapper(String xmlStreamWriterWrapperRef) {
280        this.xmlStreamWriterWrapper = xmlStreamWriterWrapperRef;
281    }
282
283    public String getSchemaLocation() {
284        return schemaLocation;
285    }
286
287    /**
288     * To define the location of the schema
289     */
290    public void setSchemaLocation(String schemaLocation) {
291        this.schemaLocation = schemaLocation;
292    }
293
294    public String getNoNamespaceSchemaLocation() {
295        return noNamespaceSchemaLocation;
296    }
297
298    /**
299     * To define the location of the namespaceless schema
300     */
301    public void setNoNamespaceSchemaLocation(String schemaLocation) {
302        this.noNamespaceSchemaLocation = schemaLocation;
303    }
304
305    public String getJaxbProviderProperties() {
306        return jaxbProviderProperties;
307    }
308
309    /**
310     * Refers to a custom java.util.Map to lookup in the registry containing
311     * custom JAXB provider properties to be used with the JAXB marshaller.
312     */
313    public void setJaxbProviderProperties(String jaxbProviderProperties) {
314        this.jaxbProviderProperties = jaxbProviderProperties;
315    }
316
317}