[rules-users] Fact Names in a Model
Esteban Aliverti
esteban.aliverti at gmail.com
Fri Dec 9 07:50:25 EST 2011
Well, there might be a way to do what you want, but you will need to go to
the dark side of drools :) (basically means magical castings)
A KnowwledgeBase contains one or more packages, and inside the packages is
where the Declared Types live.
So, using this code (I didn't test it but it should work), you can access
all your declared types of all the packages in a knowledge base:
Set<String> declaredFactTypes = new HashSet<String>();
Collection<KnowledgePackage> knowledgePackages =
kbase.getKnowledgePackages();
for (KnowledgePackage knowledgePackage : knowledgePackages) {
//the key of this map is the simple name of the declared type
and not the fqn
Map<String, TypeDeclaration> typeDeclarations =
((KnowledgePackageImp)knowledgePackage).pkg.getTypeDeclarations();
//collect all the keys in the set
for (String type : typeDeclarations.keySet()) {
//store the fqn of the declared types to avoid name
collision
declaredFactTypes.add(knowledgePackage.getName()+"."+type);
}
}
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com
On Fri, Dec 9, 2011 at 12:43 PM, srinivasasanda <srinivasasanda at gmail.com>wrote:
> Thanks Lauene for your response.Really Thank you very much.
>
> I've tried with this code,as u said it is being not as much as
> stable.Trying
> to work out it.By the way,Here there is no way to retrieve the fact
> names.My
> requirement is
>
> I'm having a package-----------*PersonDetails*
>
> In that I declared a Model called--------*Person*
>
> In that I declared two facts with two fields called --------------*Man
> (name,age) Women(name,age)*
>
> Now,My objective is to print the factnames in console.It means My output
> should be FactNames are *Man and Women*.Is it possible?
>
> How can I achieve this.....Can you please suggest me please according to my
> requirement.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572703.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111209/0f4ce277/attachment.html
More information about the rules-users
mailing list