CAMEL-7999: More components include documentation

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

Branch: refs/heads/master
Commit: 9fc7ceff653637f16f467450a949d0f3dfc83d5c
Parents: 77afa95
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Dec 18 10:56:29 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Dec 18 10:58:56 2014 +0100

----------------------------------------------------------------------
 .../component/validator/jing/JingComponent.java |  20 +--
 .../component/validator/jing/JingEndpoint.java  | 131 +++++++++++++++++++
 .../component/validator/jing/JingValidator.java |  81 +-----------
 .../jing/RelaxNGCompactSyntaxComponent.java     |  10 +-
 4 files changed, 154 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9fc7ceff/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingComponent.java
 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingComponent.java
index 5a98698..59145f2 100644
--- 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingComponent.java
+++ 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingComponent.java
@@ -19,8 +19,7 @@ package org.apache.camel.component.validator.jing;
 import java.util.Map;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.impl.ProcessorEndpoint;
+import org.apache.camel.impl.UriEndpointComponent;
 
 /**
  * A component for validating XML payloads using the
@@ -28,16 +27,17 @@ import org.apache.camel.impl.ProcessorEndpoint;
  *
  * @version 
  */
-public class JingComponent extends DefaultComponent {
+public class JingComponent extends UriEndpointComponent {
 
-    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
-        JingValidator validator = new JingValidator(getCamelContext());
-        validator.setResourceUri(remaining);
-        configureValidator(validator, uri, remaining, parameters);
-        return new ProcessorEndpoint(uri, this, validator);
+    public JingComponent() {
+        super(JingEndpoint.class);
     }
 
-    protected void configureValidator(JingValidator validator, String uri, 
String remaining, Map<String, Object> parameters) throws Exception {
-        setProperties(validator, parameters);
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        JingEndpoint answer = new JingEndpoint(uri, this);
+        answer.setResourceUri(remaining);
+        setProperties(answer, parameters);
+        return answer;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9fc7ceff/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingEndpoint.java
 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingEndpoint.java
new file mode 100644
index 0000000..e3c24bc
--- /dev/null
+++ 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingEndpoint.java
@@ -0,0 +1,131 @@
+/**
+ * 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.validator.jing;
+
+import java.io.InputStream;
+
+import org.xml.sax.InputSource;
+
+import com.thaiopensource.relaxng.SchemaFactory;
+import com.thaiopensource.validate.Schema;
+import com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
+
+@UriEndpoint(scheme = "jing", label = "validation")
+public class JingEndpoint extends DefaultEndpoint {
+
+    @UriPath
+    private String resourceUri;
+    @UriParam
+    private boolean compactSyntax;
+
+    private Schema schema;
+    private SchemaFactory schemaFactory;
+    private InputSource inputSource;
+
+    public JingEndpoint(String endpointUri, Component component) {
+        super(endpointUri, component);
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        JingValidator answer = new JingValidator(this);
+        answer.setSchema(getSchema());
+        return answer;
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException("This endpoint does not 
support consumer");
+    }
+
+    @Override
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public String getResourceUri() {
+        return resourceUri;
+    }
+
+    public void setResourceUri(String resourceUri) {
+        this.resourceUri = resourceUri;
+    }
+
+    public boolean isCompactSyntax() {
+        return compactSyntax;
+    }
+
+    public void setCompactSyntax(boolean compactSyntax) {
+        this.compactSyntax = compactSyntax;
+    }
+
+    public Schema getSchema() {
+        return schema;
+    }
+
+    public void setSchema(Schema schema) {
+        this.schema = schema;
+    }
+
+    public SchemaFactory getSchemaFactory() {
+        return schemaFactory;
+    }
+
+    public void setSchemaFactory(SchemaFactory schemaFactory) {
+        this.schemaFactory = schemaFactory;
+    }
+
+    public InputSource getInputSource() {
+        return inputSource;
+    }
+
+    public void setInputSource(InputSource inputSource) {
+        this.inputSource = inputSource;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (inputSource == null) {
+            ObjectHelper.notEmpty(resourceUri, "resourceUri", this);
+            InputStream inputStream = 
ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(),
 resourceUri);
+            inputSource = new InputSource(inputStream);
+        }
+
+        if (schemaFactory == null) {
+            schemaFactory = new SchemaFactory();
+            schemaFactory.setCompactSyntax(compactSyntax);
+            schemaFactory.setXMLReaderCreator(new Jaxp11XMLReaderCreator());
+        }
+
+        if (schema == null) {
+            schema = schemaFactory.createSchema(inputSource);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9fc7ceff/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingValidator.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingValidator.java
 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingValidator.java
index 13dbe5b..030e00e 100644
--- 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingValidator.java
+++ 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/JingValidator.java
@@ -16,33 +16,24 @@
  */
 package org.apache.camel.component.validator.jing;
 
-import java.io.IOException;
-import java.io.InputStream;
-import javax.xml.XMLConstants;
 import javax.xml.transform.Source;
 import javax.xml.transform.sax.SAXSource;
 
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
-import com.thaiopensource.relaxng.SchemaFactory;
 import com.thaiopensource.util.PropertyMap;
 import com.thaiopensource.util.PropertyMapBuilder;
-import com.thaiopensource.validate.IncorrectSchemaException;
 import com.thaiopensource.validate.Schema;
 import com.thaiopensource.validate.ValidateProperty;
 import com.thaiopensource.validate.Validator;
 import com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator;
-
-import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.processor.validation.DefaultValidationErrorHandler;
 import org.apache.camel.util.ExchangeHelper;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ResourceHelper;
 
 /**
  * A validator which uses the <a
@@ -51,17 +42,11 @@ import org.apache.camel.util.ResourceHelper;
  * 
  * @version 
  */
-public class JingValidator implements Processor {
-    private final CamelContext camelContext;
+public class JingValidator extends DefaultProducer {
     private Schema schema;
-    private SchemaFactory schemaFactory;
-    private String schemaNamespace = XMLConstants.RELAXNG_NS_URI;
-    private String resourceUri;
-    private InputSource inputSource;
-    private boolean compactSyntax;
 
-    public JingValidator(CamelContext camelContext) {
-        this.camelContext = camelContext;
+    public JingValidator(Endpoint endpoint) {
+        super(endpoint);
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -97,65 +82,11 @@ public class JingValidator implements Processor {
     // 
-------------------------------------------------------------------------
 
 
-    public String getResourceUri() {
-        return resourceUri;
-    }
-
-    public void setResourceUri(String resourceUri) {
-        this.resourceUri = resourceUri;
-    }
-
-    public Schema getSchema() throws IOException, IncorrectSchemaException, 
SAXException {
-        if (schema == null) {
-            SchemaFactory factory = getSchemaFactory();
-            schema = factory.createSchema(getInputSource());
-        }
+    public Schema getSchema() {
         return schema;
     }
 
     public void setSchema(Schema schema) {
         this.schema = schema;
     }
-
-    public InputSource getInputSource() throws IOException {
-        if (inputSource == null) {
-            ObjectHelper.notEmpty(resourceUri, "resourceUri", this);
-            InputStream inputStream = 
ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext.getClassResolver(),
 resourceUri);
-            inputSource = new InputSource(inputStream);
-        }
-        return inputSource;
-    }
-
-    public void setInputSource(InputSource inputSource) {
-        this.inputSource = inputSource;
-    }
-
-    public SchemaFactory getSchemaFactory() {
-        if (schemaFactory == null) {
-            schemaFactory = new SchemaFactory();
-            schemaFactory.setCompactSyntax(compactSyntax);
-            schemaFactory.setXMLReaderCreator(new Jaxp11XMLReaderCreator());
-        }
-        return schemaFactory;
-    }
-
-    public void setSchemaFactory(SchemaFactory schemaFactory) {
-        this.schemaFactory = schemaFactory;
-    }
-
-    public String getSchemaNamespace() {
-        return schemaNamespace;
-    }
-
-    public void setSchemaNamespace(String schemaNamespace) {
-        this.schemaNamespace = schemaNamespace;
-    }
-
-    public boolean isCompactSyntax() {
-        return compactSyntax;
-    }
-
-    public void setCompactSyntax(boolean compactSyntax) {
-        this.compactSyntax = compactSyntax;
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9fc7ceff/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/RelaxNGCompactSyntaxComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/RelaxNGCompactSyntaxComponent.java
 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/RelaxNGCompactSyntaxComponent.java
index bc9eb4d..6771888 100644
--- 
a/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/RelaxNGCompactSyntaxComponent.java
+++ 
b/components/camel-jing/src/main/java/org/apache/camel/component/validator/jing/RelaxNGCompactSyntaxComponent.java
@@ -18,6 +18,8 @@ package org.apache.camel.component.validator.jing;
 
 import java.util.Map;
 
+import org.apache.camel.Endpoint;
+
 /**
  * A component for validating the XML payload using
  * <a 
href="http://www.oasis-open.org/committees/relax-ng/compact-20021121.html";>RelaxNG
 Compact Syntax</a> using the
@@ -27,8 +29,10 @@ import java.util.Map;
  */
 public class RelaxNGCompactSyntaxComponent extends JingComponent {
 
-    protected void configureValidator(JingValidator validator, String uri, 
String remaining, Map<String, Object> parameters) throws Exception {
-        validator.setCompactSyntax(true);
-        super.configureValidator(validator, uri, remaining, parameters);
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        JingEndpoint endpoint = (JingEndpoint) super.createEndpoint(uri, 
remaining, parameters);
+        endpoint.setCompactSyntax(true);
+        return endpoint;
     }
 }

Reply via email to