<div dir="ltr">Sorry, in my above example I said the converter is responsible for storing the value, which is not the case. The GraphBinding would be responsible for that.</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, May 5, 2014 at 11:27 AM, Lincoln Baxter, III <span dir="ltr"><<a href="mailto:lincolnbaxter@gmail.com" target="_blank">lincolnbaxter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Sure, take this example:<div><br></div><div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="courier new, monospace"> .addRule()<br>
.when(Selection.exists(XMLFile.<span>class</span>, <span>"xmls"</span>)<br> .with(Element.DOCTYPE, <span>"<a href="http://maven.apache.org/POM/4.0.0" target="_blank">http://maven.apache.org/POM/4.0.0</a>"</span>)<br>
)<br> .perform(Iteration.over(XMLFile.<span>class</span>, <span>"xmls"</span>, <span>"pom"</span>).as(MavenPomFile.<span>class</span>)<br>
.perform(<br> Graph.replace(Selection.current(XMLFile.<span>class</span>))<br> .with(Selection.current(MavenPomFile.<span>class</span>))<br>
)<br> )</font></blockquote>
<p><font face="courier new, monospace"><br></font></p><p><font face="courier new, monospace">Now co</font>nsider what would happen if we were to parameterize the DOCTYPE statement:</p><p><br></p>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="courier new, monospace"> .addRule()<br>
</font><font face="courier new, monospace"> .when(Selection.exists(XMLFile.<span>class</span>, <span>"xmls"</span>)<br></font><font face="courier new, monospace"> .<span>with(Element.DOCTYPE, "http://{domain}/POM/4.0.0"</span>)<br>
</font><font face="courier new, monospace"> )</font></blockquote><p><br></p><p>What if we want to match some domains and not others? Well, we'll need to configure the parameter:</p>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="courier new, monospace"> .addRule()<br>
.when(Selection.exists(XMLFile.<span>class</span>, <span>"xmls"</span>)<br> .<span>with(Element.DOCTYPE, "http://{domain}/POM/4.0.0"</span>)<br>
)<br> .where("domain").matches("(<a href="http://maven.apache.org" target="_blank">maven.apache.org</a>|<a href="http://jboss.org/maven%7Cexample%5C%5C.(com%7Corg%7Cnet)" target="_blank">jboss.org/maven|example\\.(com|org|net)</a>)").convertedBy(new URLDomainConverter()).bindsTo(new GraphBinding("xml>domain"))</font></blockquote>
<p><font face="courier new, monospace"><br></font></p><p><font face="courier new, monospace">T</font>his would both ensure that the parameter matches only what was contained in the regular expression, but also adds a converter which stores the value in the graph (somehow) as a URLDomain (which just for example's sake is a @VertexFrame annotated interface.) Keep in mind that this is just a hypothetical example.</p>
<p>The full battery of parameter configuration options are:</p><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">.where(String param)<br></font><font face="courier new, monospace">.matches(String regex)<br></font><font face="courier new, monospace">.constrainedBy(Constraint constraint)<br></font><font face="courier new, monospace">.convertedBy(Converter converter)<br>
</font><font face="courier new, monospace">.validatedBy(Validator validator)<br></font><font face="courier new, monospace">.bindsTo(Binding binding)<br></font><font face="courier new, monospace">.configuredBy(ParameterConfigurator configurator) // can do any of the above</font></blockquote>
<span class="HOEnZb"><font color="#888888">
<p><br></p><p>~Lincoln</p><p><br></p></font></span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 5, 2014 at 11:05 AM, Jess Sightler <span dir="ltr"><<a href="mailto:jsightle@redhat.com" target="_blank">jsightle@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Could you explain the "where" clause in more detail here? I have
seen this a few times in your examples, but I'm not entirely clear
on what it is doing. :)<div><div><br>
<br>
<br>
<div>On 05/05/2014 10:33 AM, Lincoln Baxter,
III wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div style="font-family:arial,sans-serif;font-size:13px">.addRule() </div>
<div style="font-family:arial,sans-serif;font-size:13px">.when()
// if</div>
<div style="font-family:arial,sans-serif;font-size:13px">
.perform() // then</div>
<div style="font-family:arial,sans-serif;font-size:13px">.otherwise()
// else</div>
<div style="font-family:arial,sans-serif;font-size:13px">.where("paramName1").configuredBy(...).where("paramName2")
// configure parameters</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Mon, May 5, 2014 at 10:23 AM,
Lincoln Baxter, III <span dir="ltr"><<a href="mailto:lincolnbaxter@gmail.com" target="_blank">lincolnbaxter@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div><span style="font-family:arial,sans-serif;font-size:13px">1)
The (when, perform) structure would be basic for all
rules?</span>
<div>
<br>
</div>
</div>
<div>Yes, there are actually a few more structures:</div>
<div><br>
</div>
<div>.addRule() </div>
<div>.when() // if</div>
<div>.perform() // then</div>
<div>.otherwise() // else
<div><br>
<br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">2)
This seems like it will build object tree, which
will then be</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">processed,
right? No space for custom code?</span><br style="font-family:arial,sans-serif;font-size:13px">
<br>
</div>
You can already do exactly what you just suggested :)
Custom code is no problem, it just accepts an object
like any normal Java code - it's just Java.
<div>
<br>
<br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">3)
Isn't that a fluent API overuse? How about something
like:</span></div>
</div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">I don't know what you
are referring to here as overuse, but yes, I am
exaggerating the use of the fluent API to make a
point. The rules could be completely un-fluent and
still use these same APIs. I'm not sure I see the
point/difference of the sample you've shown.<br>
</font>
<div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px">4)
.withDoctype("</span><a href="http://maven.apache.org/POM/4.0.0" style="font-family:arial,sans-serif;font-size:13px" target="_blank">http://maven.apache.org/POM/4.0.0</a><span style="font-family:arial,sans-serif;font-size:13px">") ?</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">doctype
is a property... Better .with(PropNames.DOCTYPE,</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">"</span><a href="http://maven.apache.org/POM/4.0.0" style="font-family:arial,sans-serif;font-size:13px" target="_blank">http://maven.apache.org/POM/4.0.0</a><span style="font-family:arial,sans-serif;font-size:13px">") ?</span></div>
<div><br>
</div>
</div>
<div>I agree, some kind of more general structure here
would probably be better.
<div><br style="font-family:arial,sans-serif;font-size:13px">
<br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">5)
Could the variable be filled outside .when () ?
But perhaps just a</span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">matter
of taste.</span><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div>
</div>
</div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px">Absolutely
you could - and yes, it's all a matter of taste :)</span></div>
</div>
<div class="gmail_extra">
<div>
<div><br>
<br>
<div class="gmail_quote">
On Fri, May 2, 2014 at 7:26 PM, Ondrej Zizka <span dir="ltr"><<a href="mailto:ozizka@redhat.com" target="_blank">ozizka@redhat.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
WRT rules API, as proposed at<br>
<a href="https://github.com/windup/windup/blob/master/engine/config/api/src/main/java/org/jboss/windup/addon/config/example/MavenExampleConfigurationProvider.java#L22" target="_blank">https://github.com/windup/windup/blob/master/engine/config/api/src/main/java/org/jboss/windup/addon/config/example/MavenExampleConfigurationProvider.java#L22</a><br>
<br>
It's nice, with some comments.<br>
<br>
I know it was typed in a hurry, but anyway:<br>
<br>
1) The (when, perform) structure would be basic
for all rules?<br>
<br>
2) This seems like it will build object tree,
which will then be<br>
processed, right? No space for custom code?<br>
<br>
3) Isn't that a fluent API overuse? How about
something like:<br>
<br>
new ConfigBuilder( ... ){{<br>
addRule( new MavenPomRule( this, ... ){<br>
boolean when( ) { return
Selection.exists(XMLFile.class,<br>
"xmls").with("doctype", DOCTYPE_POM); }<br>
void perform( MavenPomInfo mpi ){
... }<br>
}<br>
);<br>
}}.run();<br>
<br>
It's verbose now but with Java 8 lambdas, it would
be less.<br>
<br>
While it's a bit more verbose, it would have
obvious benefits of better<br>
debuggability, and would better leverage Java's
features like<br>
inheritance (imagine AbstractXmlFileRule and it's
subclasses for<br>
whatever one would want to do with a XML file,
having few of its<br>
properties passed as parameters.<br>
<br>
Btw this code above is inspired by Wicket and GWT.<br>
<br>
4) .withDoctype("<a href="http://maven.apache.org/POM/4.0.0" target="_blank">http://maven.apache.org/POM/4.0.0</a>")
?<br>
doctype is a property... Better
.with(PropNames.DOCTYPE,<br>
"<a href="http://maven.apache.org/POM/4.0.0" target="_blank">http://maven.apache.org/POM/4.0.0</a>")
?<br>
<br>
5) Could the variable be filled outside .when () ?
But perhaps just a<br>
matter of taste.<br>
<br>
More later when we have some more examples.<br>
<br>
Nice!<br>
Ondra<br>
_______________________________________________<br>
windup-dev mailing list<br>
<a href="mailto:windup-dev@lists.jboss.org" target="_blank">windup-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/windup-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/windup-dev</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
</div>
</div>
<span><font color="#888888">-- <br>
Lincoln Baxter, III<br>
<a href="http://ocpsoft.org" target="_blank">http://ocpsoft.org</a><br>
"Simpler is better."
</font></span></div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Lincoln Baxter, III<br>
<a href="http://ocpsoft.org" target="_blank">http://ocpsoft.org</a><br>
"Simpler is better."
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
windup-dev mailing list
<a href="mailto:windup-dev@lists.jboss.org" target="_blank">windup-dev@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/windup-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/windup-dev</a></pre>
</blockquote>
<br>
</div></div></div>
<br>_______________________________________________<br>
windup-dev mailing list<br>
<a href="mailto:windup-dev@lists.jboss.org" target="_blank">windup-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/windup-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/windup-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Lincoln Baxter, III<br>
<a href="http://ocpsoft.org" target="_blank">http://ocpsoft.org</a><br>"Simpler is better."
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Lincoln Baxter, III<br><a href="http://ocpsoft.org" target="_blank">http://ocpsoft.org</a><br>"Simpler is better."
</div>