camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: CAMEL-8043: camel-saxon is like other components with an endpoint class.
Date Sun, 30 Nov 2014 13:48:45 GMT
Repository: camel
Updated Branches:
  refs/heads/master 829458c70 -> b7eb85123


CAMEL-8043: camel-saxon is like other components with an endpoint class.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8b53d228
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8b53d228
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8b53d228

Branch: refs/heads/master
Commit: 8b53d228ccac64b40f3cd4026768c8d9ba9202b2
Parents: 829458c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Nov 30 13:43:50 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Nov 30 13:43:50 2014 +0100

----------------------------------------------------------------------
 .../camel/component/xquery/XQueryComponent.java |  27 +--
 .../camel/component/xquery/XQueryEndpoint.java  | 199 +++++++++++++++++++
 2 files changed, 210 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8b53d228/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryComponent.java
b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryComponent.java
index d4d8890..2047c4d 100644
--- a/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryComponent.java
+++ b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryComponent.java
@@ -21,34 +21,29 @@ import java.util.Map;
 
 import net.sf.saxon.lib.ModuleURIResolver;
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.impl.ProcessorEndpoint;
+import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.util.ResourceHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * An <a href="http://camel.apache.org/xquery.html">XQuery Component</a>
  * for performing transforming messages
  */
-public class XQueryComponent extends DefaultComponent {
+public class XQueryComponent extends UriEndpointComponent {
 
-    private static final Logger LOG = LoggerFactory.getLogger(XQueryComponent.class);
     private ModuleURIResolver moduleURIResolver = new XQueryModuleURIResolver(this);
 
+    public XQueryComponent() {
+        super(XQueryEndpoint.class);
+    }
+
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        String resourceUri = remaining;
-        URL url = resolveModuleResource(resourceUri);
-        LOG.debug("{} using schema resource: {}", this, resourceUri);
+        XQueryEndpoint answer = new XQueryEndpoint(uri, this);
+        setProperties(answer, parameters);
 
-        XQueryBuilder xslt = XQueryBuilder.xquery(url);
-        xslt.setModuleURIResolver(getModuleURIResolver());
-        configureXslt(xslt, uri, remaining, parameters);
-        return new ProcessorEndpoint(uri, this, xslt);
-    }
+        answer.setResourceUri(remaining);
+        answer.setModuleURIResolver(getModuleURIResolver());
 
-    protected void configureXslt(XQueryBuilder xQueryBuilder, String uri, String remaining,
Map<String, Object> parameters) throws Exception {
-        setProperties(xQueryBuilder, parameters);
+        return answer;
     }
 
     public URL resolveModuleResource(String uri) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/8b53d228/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryEndpoint.java
b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryEndpoint.java
new file mode 100644
index 0000000..b0e3160
--- /dev/null
+++ b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryEndpoint.java
@@ -0,0 +1,199 @@
+/**
+ * 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 org.apache.camel.component.xquery;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import net.sf.saxon.Configuration;
+import net.sf.saxon.lib.ModuleURIResolver;
+import net.sf.saxon.query.StaticQueryContext;
+import org.apache.camel.Component;
+import org.apache.camel.impl.ProcessorEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.ResourceHelper;
+import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@UriEndpoint(scheme = "xquery", label = "transformation")
+public class XQueryEndpoint extends ProcessorEndpoint {
+
+    private static final Logger LOG = LoggerFactory.getLogger(XQueryEndpoint.class);
+
+    private volatile XQueryBuilder xquery;
+
+    @UriPath
+    private String resourceUri;
+    @UriParam
+    private Configuration configuration;
+    @UriParam
+    private StaticQueryContext staticQueryContext;
+    @UriParam
+    private Map<String, Object> parameters = new HashMap<String, Object>();
+    @UriParam
+    private Map<String, String> namespacePrefixes = new HashMap<String, String>();
+    @UriParam(defaultValue = "DOM")
+    private ResultFormat resultsFormat = ResultFormat.DOM;
+    @UriParam
+    private Properties properties = new Properties();
+    @UriParam
+    private Class<?> resultType;
+    @UriParam(defaultValue = "true")
+    private boolean stripsAllWhiteSpace = true;
+    @UriParam
+    private ModuleURIResolver moduleURIResolver;
+    @UriParam(defaultValue = "false")
+    private boolean allowStAX;
+    @UriParam
+    private String headerName;
+
+    public XQueryEndpoint(String endpointUri, Component component) {
+        super(endpointUri, component);
+    }
+
+    public String getResourceUri() {
+        return resourceUri;
+    }
+
+    public void setResourceUri(String resourceUri) {
+        this.resourceUri = resourceUri;
+    }
+
+    public Configuration getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(Configuration configuration) {
+        this.configuration = configuration;
+    }
+
+    public StaticQueryContext getStaticQueryContext() {
+        return staticQueryContext;
+    }
+
+    public void setStaticQueryContext(StaticQueryContext staticQueryContext) {
+        this.staticQueryContext = staticQueryContext;
+    }
+
+    public Map<String, Object> getParameters() {
+        return parameters;
+    }
+
+    public void setParameters(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+
+    public Map<String, String> getNamespacePrefixes() {
+        return namespacePrefixes;
+    }
+
+    public void setNamespacePrefixes(Map<String, String> namespacePrefixes) {
+        this.namespacePrefixes = namespacePrefixes;
+    }
+
+    public ResultFormat getResultsFormat() {
+        return resultsFormat;
+    }
+
+    public void setResultsFormat(ResultFormat resultsFormat) {
+        this.resultsFormat = resultsFormat;
+    }
+
+    public Properties getProperties() {
+        return properties;
+    }
+
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+
+    public Class<?> getResultType() {
+        return resultType;
+    }
+
+    public void setResultType(Class<?> resultType) {
+        this.resultType = resultType;
+    }
+
+    public boolean isStripsAllWhiteSpace() {
+        return stripsAllWhiteSpace;
+    }
+
+    public void setStripsAllWhiteSpace(boolean stripsAllWhiteSpace) {
+        this.stripsAllWhiteSpace = stripsAllWhiteSpace;
+    }
+
+    public ModuleURIResolver getModuleURIResolver() {
+        return moduleURIResolver;
+    }
+
+    public void setModuleURIResolver(ModuleURIResolver moduleURIResolver) {
+        this.moduleURIResolver = moduleURIResolver;
+    }
+
+    public boolean isAllowStAX() {
+        return allowStAX;
+    }
+
+    public void setAllowStAX(boolean allowStAX) {
+        this.allowStAX = allowStAX;
+    }
+
+    public String getHeaderName() {
+        return headerName;
+    }
+
+    public void setHeaderName(String headerName) {
+        this.headerName = headerName;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        LOG.debug("{} using schema resource: {}", this, resourceUri);
+        URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(),
resourceUri);
+        this.xquery = XQueryBuilder.xquery(url);
+
+        xquery.setConfiguration(getConfiguration());
+        xquery.setStaticQueryContext(getStaticQueryContext());
+        xquery.setParameters(getParameters());
+        xquery.setNamespaces(namespacePrefixes);
+        xquery.setResultsFormat(getResultsFormat());
+        xquery.setProperties(getProperties());
+        xquery.setResultType(getResultType());
+        xquery.setStripsAllWhiteSpace(isStripsAllWhiteSpace());
+        xquery.setAllowStAX(isAllowStAX());
+        xquery.setHeaderName(getHeaderName());
+
+        setProcessor(xquery);
+
+        ServiceHelper.startService(xquery);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        ServiceHelper.stopService(xquery);
+    }
+}


Mime
View raw message