<html><body><div><div>Okay Wolfgang ... you asked for it. Here's a version which takes it pretty much to the minimum.</div><div><br></div><div>The error I see is "Unable to resolve method using strict-mode: mypackage.CloneMessage.cloneMessage(mypackage.Message)"</div><div><br></div><div>However, the error is only seen when I use mvel dialect. The working Java dialect rule is also included below.</div><div><br></div><div>Note that when I re-wrote the example function to take a common type such as String as argument, then the mvel version worked. It's when the argument is a declared type that it fails.</div><div><br></div><div>Thanks for taking a look,</div><div><br></div><div>Steve</div><div><br></div><div><br></div><div><strong><br></strong></div><div><strong>file - MessageFact.drl</strong></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> package mypackage</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> declare Message</span></div><div><span style="font-family: 'courier new', monospace; "> Text: String</span></div><div><span style="font-family: 'courier new', monospace; "> end</span></div><div><br></div><div><br></div><div><br></div><div><strong>file - CloneMessage.drl</strong></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> package mypackage</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> function Message cloneMessage(Message originalMessage) {</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> Message newMessage = new Message();</span></div><div><span style="font-family: 'courier new', monospace; "> newMessage.setText(originalMessage.getText());</span></div><div><span style="font-family: 'courier new', monospace; "> return newMessage;</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> }</span></div><div><br></div><div><br></div><div><br></div><div><strong>file - SayHelloRuleJava.drl</strong></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> package mypackage</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> rule "Say hello"</span></div><div><span style="font-family: 'courier new', monospace; "> dialect "java"</span></div><div><span style="font-family: 'courier new', monospace; "> lock-on-active true</span></div><div><span style="font-family: 'courier new', monospace; "> when</span></div><div><span style="font-family: 'courier new', monospace; "> # Always</span></div><div><span style="font-family: 'courier new', monospace; "> then</span></div><div><span style="font-family: 'courier new', monospace; "> Message originalMessage = new Message();</span></div><div><span style="font-family: 'courier new', monospace; "> originalMessage.setText("Hello, World!");</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> Message clonedMessage = cloneMessage(originalMessage);</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> insert(clonedMessage);</span></div><div><span style="font-family: 'courier new', monospace; "> end</span></div><div><br></div><div><br></div><div><br></div><div><strong>file - SayHelloRuleMvel.drl</strong></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> package mypackage</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> rule "Say hello"</span></div><div><span style="font-family: 'courier new', monospace; "> dialect "mvel"</span></div><div><span style="font-family: 'courier new', monospace; "> lock-on-active true</span></div><div><span style="font-family: 'courier new', monospace; "> when</span></div><div><span style="font-family: 'courier new', monospace; "> # Always</span></div><div><span style="font-family: 'courier new', monospace; "> then</span></div><div><span style="font-family: 'courier new', monospace; "> Message originalMessage = new Message();</span></div><div><span style="font-family: 'courier new', monospace; "> originalMessage.Text = "Hello, World!";</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> Message clonedMessage = cloneMessage(originalMessage);</span></div><div><br></div><div><span style="font-family: 'courier new', monospace; "> insert(clonedMessage);</span></div><div><span style="font-family: 'courier new', monospace; "> end</span></div></div><div><br></div><div><br></div><div><br>On Jun 19, 2012, at 12:27 PM, Wolfgang Laun <wolfgang.laun@gmail.com> wrote:<br><br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch">Can you please provide an example where and how you import and use a<br> DRL function so that it works/doesn't work with MVEL/Java?<br> <br> -W<br> <br> <br> On 19/06/2012, Stephen Masters <<a href="mailto:stephen.masters@me.com" data-mce-href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>> wrote:<br> > Hi folks,<br> ><br> > Is it possible to refer to DRL functions from a DRL when the dialect is<br> > mvel?<br> ><br> > I have been working on unit tests for a rule that were consistently failing<br> > due to not being able to find the function that should be imported. Having<br> > tried various formats (the documentation is rather unhelpful here) for the<br> > import, I thought I'd see what happened if I just switched to the Java<br> > dialect. Suddenly it worked without even needing an import statement.<br> ><br> > Unfortunately, this forces me to switch from the neat ...<br> > newFact.Property = otherFact.Property<br> > ... to the rather ugly Java-style<br> > newFact.setProperty(otherFact.getProperty())<br> ><br> > So I would quite like to know if there is an undocumented (or<br> > well-hidden-documented) mechanism for using functions when in mvel dialect.<br> > Or am I stuck with switching to Java?<br> ><br> > Thanks in advance for any pointers anybody can provide,<br> ><br> > Steve<br> _______________________________________________<br> rules-users mailing list<br> <a href="mailto:rules-users@lists.jboss.org" data-mce-href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" data-mce-href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></div></div></blockquote></div></body></html>