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.language;
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 import javax.xml.bind.annotation.XmlTransient;
024
025 import org.apache.camel.Expression;
026 import org.apache.camel.Predicate;
027 import org.apache.camel.spi.RouteContext;
028 import org.apache.commons.logging.Log;
029 import org.apache.commons.logging.LogFactory;
030
031 /**
032 * For XQuery expressions and predicates
033 *
034 * @version $Revision: 679483 $
035 */
036 @XmlRootElement(name = "xquery")
037 @XmlAccessorType(XmlAccessType.FIELD)
038 public class XQueryExpression extends NamespaceAwareExpression {
039 private static final transient Log LOG = LogFactory.getLog(XQueryExpression.class);
040
041 @XmlAttribute(required = false)
042 private String type;
043 @XmlTransient
044 private Class resultType;
045
046 public XQueryExpression() {
047 }
048
049 public XQueryExpression(String expression) {
050 super(expression);
051 }
052
053 public String getLanguage() {
054 return "xquery";
055 }
056
057 public String getType() {
058 return type;
059 }
060
061 public void setType(String type) {
062 this.type = type;
063 }
064
065 public Class getResultType() {
066 return resultType;
067 }
068
069 public void setResultType(Class resultType) {
070 this.resultType = resultType;
071 }
072
073 @Override
074 protected void configureExpression(RouteContext routeContext, Expression expression) {
075 super.configureExpression(routeContext, expression);
076 updateResultType();
077 if (resultType != null) {
078 setProperty(expression, "resultType", resultType);
079 }
080 }
081
082 @Override
083 protected void configurePredicate(RouteContext routeContext, Predicate predicate) {
084 super.configurePredicate(routeContext, predicate);
085 updateResultType();
086 if (resultType != null) {
087 setProperty(predicate, "resultType", resultType);
088 }
089 }
090
091 private void updateResultType() {
092 if (resultType == null && type != null) {
093 try {
094 resultType = Class.forName(type);
095 } catch (ClassNotFoundException e) {
096 LOG.error("ClassNotFoundException creating class: " + type);
097 }
098 }
099 }
100 }