lburgazzoli commented on a change in pull request #4998:
URL: https://github.com/apache/camel/pull/4998#discussion_r568703652



##########
File path: 
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesBuilderLoader.java
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.impl.engine;
+
+import java.util.Optional;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+
+public class DefaultRoutesBuilderLoader implements RoutesBuilderLoader, 
CamelContextAware {
+    private CamelContext camelContext;
+
+    public DefaultRoutesBuilderLoader() {
+    }
+
+    public DefaultRoutesBuilderLoader(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public RoutesBuilder loadRoutesBuilder(Resource resource) throws Exception 
{
+        final String location = resource.getLocation();
+        final String language = getLanguage(location);
+
+        if (ObjectHelper.isEmpty(language)) {
+            throw new IllegalArgumentException("Unable to determine language 
for resource: " + location);
+        }
+
+        return getLoader(language).loadRoutesBuilder(resource);
+    }
+
+    private String getLanguage(String location) {
+        String answer = StringHelper.afterLast(location, ":", location);
+        answer = StringHelper.afterLast(answer, ".", answer);

Review comment:
       yep, maybe I'll add something to one of the support classes, like 
`getExtension`

##########
File path: 
core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.xml.jaxb;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRestsDefinition;
+import static 
org.apache.camel.xml.jaxb.JaxbHelper.loadRouteTemplatesDefinition;
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRoutesDefinition;
+
+public class JaxbXmlRoutesBuilderLoader implements RoutesBuilderLoader, 
CamelContextAware {

Review comment:
       does this support directories ? i.e. `@JdkService("loaders/xml")`

##########
File path: 
core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.xml.jaxb;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRestsDefinition;
+import static 
org.apache.camel.xml.jaxb.JaxbHelper.loadRouteTemplatesDefinition;
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRoutesDefinition;
+
+public class JaxbXmlRoutesBuilderLoader implements RoutesBuilderLoader, 
CamelContextAware {

Review comment:
       So the `RoutesBuilderLoader` is not actually discovered using a service 
mechanism but in fact the default implementation is a facade to the real one 
which behind the scene id does:
   
   ```java
       @Override
       public RoutesBuilder loadRoutesBuilder(Resource resource) throws 
Exception {
           // language is derived from the file extension
           final String language = FileUtil.onlyExt(resource.getLocation(), 
true);
   
           return getLoader(language).loadRoutesBuilder(resource);
       }
   
       private RoutesBuilderLoader getLoader(String language) {
           RoutesBuilderLoader answer = 
getCamelContext().getRegistry().lookupByNameAndType(
               language, 
               RoutesBuilderLoader.class);
   
           if (answer == null) {
               // lookup the loader in
               // META-INF/services/org/apache/camel/routes-loaders/${language}
           }
   
           return answer;
       }
   ```
   
   So it looks up the real loader using the file extension, and the real loader 
is supposed to be either bound to the registry or defined through 
`META-INF/services/org/apache/camel/routes-loaders`. I'm not very convinced by 
this patter so I'll split the loader interface from the language specific one.
   

##########
File path: 
core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.xml.jaxb;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRestsDefinition;
+import static 
org.apache.camel.xml.jaxb.JaxbHelper.loadRouteTemplatesDefinition;
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRoutesDefinition;
+
+public class JaxbXmlRoutesBuilderLoader implements RoutesBuilderLoader, 
CamelContextAware {

Review comment:
       So the `RoutesBuilderLoader` is not actually discovered using a service 
mechanism but in fact the default implementation is a facade to the real one 
which behind the scene does something like:
   
   ```java
       @Override
       public RoutesBuilder loadRoutesBuilder(Resource resource) throws 
Exception {
           // language is derived from the file extension
           final String language = FileUtil.onlyExt(resource.getLocation(), 
true);
   
           return getLoader(language).loadRoutesBuilder(resource);
       }
   
       private RoutesBuilderLoader getLoader(String language) {
           RoutesBuilderLoader answer = 
getCamelContext().getRegistry().lookupByNameAndType(
               language, 
               RoutesBuilderLoader.class);
   
           if (answer == null) {
               // lookup the loader in
               // META-INF/services/org/apache/camel/routes-loaders/${language}
           }
   
           return answer;
       }
   ```
   
   So it looks up the real loader using the file extension, and the real loader 
is supposed to be either bound to the registry or defined through 
`META-INF/services/org/apache/camel/routes-loaders`. I'm not very convinced by 
this patter so I'll split the loader interface from the language specific one.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to