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 */
017 package org.apache.camel.model.dataformat;
018
019 import javax.xml.bind.annotation.XmlAccessType;
020 import javax.xml.bind.annotation.XmlAccessorType;
021 import javax.xml.bind.annotation.XmlAttribute;
022 import javax.xml.bind.annotation.XmlRootElement;
023
024 import org.apache.camel.spi.DataFormat;
025 import org.apache.camel.util.ObjectHelper;
026 import org.apache.commons.logging.Log;
027 import org.apache.commons.logging.LogFactory;
028
029 /**
030 * Represents the <a href="http://camel.apache.org/artix-data-services.html">Artix Data Services</a>
031 * {@link DataFormat}
032 *
033 * @version $Revision: 750806 $
034 */
035 @XmlRootElement(name = "artixDS")
036 @XmlAccessorType(XmlAccessType.FIELD)
037 public class ArtixDSDataFormat extends DataFormatDefinition {
038 private static final transient Log LOG = LogFactory.getLog(ArtixDSDataFormat.class);
039
040 @XmlAttribute(required = false)
041 private String elementTypeName;
042 @XmlAttribute(required = false)
043 private String format;
044 @XmlAttribute(required = false)
045 private Class<?> elementType;
046 @XmlAttribute(required = false)
047 private ArtixDSContentType contentType;
048
049 public ArtixDSDataFormat() {
050 super("org.apache.camel.artix.ds.ArtixDSFormat");
051 }
052
053 public ArtixDSDataFormat(Class<?> elementType) {
054 this();
055 this.elementType = elementType;
056 }
057
058 public ArtixDSDataFormat(Class<?> elementType, ArtixDSContentType contentType) {
059 this();
060 this.elementType = elementType;
061 this.contentType = contentType;
062 }
063
064 public ArtixDSDataFormat(ArtixDSContentType contentType) {
065 this();
066 this.contentType = contentType;
067 }
068
069 // Properties
070 //-------------------------------------------------------------------------
071
072 public String getElementTypeName() {
073 return elementTypeName;
074 }
075
076 public void setElementTypeName(String elementTypeName) {
077 this.elementTypeName = elementTypeName;
078 }
079
080 public ArtixDSContentType getContentType() {
081 return contentType;
082 }
083
084 public void setContentType(ArtixDSContentType contentType) {
085 this.contentType = contentType;
086 }
087
088 public Class<?> getElementType() {
089 if (elementType == null) {
090 if (elementTypeName != null) {
091 elementType = ObjectHelper.loadClass(elementTypeName, getClass().getClassLoader());
092 if (elementType == null) {
093 throw new IllegalArgumentException("The ArtixDS Element class " + elementTypeName + " is not on the classpath! Cannot use the dataFormat " + this);
094 }
095 }
096 }
097 return elementType;
098 }
099
100 public void setElementType(Class<?> elementType) {
101 this.elementType = elementType;
102 }
103
104 public String getFormat() {
105 return format;
106 }
107
108 public void setFormat(String format) {
109 this.format = format;
110 }
111
112 // Implementation methods
113 //-------------------------------------------------------------------------
114
115 @Override
116 protected void configureDataFormat(DataFormat dataFormat) {
117 Class<?> type = getElementType();
118 if (type != null) {
119 setProperty(dataFormat, "elementType", type);
120 }
121 ArtixDSContentType content = getContentType();
122 if (content != null) {
123 setProperty(dataFormat, "contentType", content);
124 }
125 }
126 }