[jboss-svn-commits] JBL Code SVN: r19078 - labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Mar 18 20:57:17 EDT 2008
Author: mingjin
Date: 2008-03-18 20:57:16 -0400 (Tue, 18 Mar 2008)
New Revision: 19078
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
Log:
JBRULES-1095 fixing bad merge
- PackageBuilder.java: added lost method & call to processTypeDeclarations(..)
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-03-19 00:23:11 UTC (rev 19077)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/compiler/PackageBuilder.java 2008-03-19 00:57:16 UTC (rev 19078)
@@ -43,10 +43,12 @@
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.QueryDescr;
import org.drools.lang.descr.RuleDescr;
+import org.drools.lang.descr.TypeDeclarationDescr;
import org.drools.process.core.Process;
import org.drools.rule.ImportDeclaration;
import org.drools.rule.Package;
import org.drools.rule.Rule;
+import org.drools.rule.TypeDeclaration;
import org.drools.rule.builder.RuleBuildContext;
import org.drools.rule.builder.RuleBuilder;
import org.drools.xml.XmlPackageReader;
@@ -367,13 +369,14 @@
final List imports = packageDescr.getImports();
for ( final Iterator it = imports.iterator(); it.hasNext(); ) {
ImportDescr importEntry = (ImportDescr) it.next();
- ImportDeclaration importDecl = new ImportDeclaration( importEntry.getTarget(),
- importEntry.isEvent() );
+ ImportDeclaration importDecl = new ImportDeclaration( importEntry.getTarget() );
pkg.addImport( importDecl );
this.typeResolver.addImport( importDecl.getTarget() );
this.dialectRegistry.addImport( importDecl.getTarget() );
}
+ processTypeDeclarations( packageDescr );
+
for ( final Iterator it = packageDescr.getFunctionImports().iterator(); it.hasNext(); ) {
String importEntry = ((FunctionImportDescr) it.next()).getTarget();
this.dialectRegistry.addStaticImport( importEntry );
@@ -396,8 +399,66 @@
global.getLine() ) );
}
}
+
}
+ /**
+ * @param packageDescr
+ */
+ private void processTypeDeclarations(final PackageDescr packageDescr) {
+ for ( TypeDeclarationDescr typeDescr : packageDescr.getTypeDeclarations() ) {
+ TypeDeclaration type = new TypeDeclaration( typeDescr.getTypeName() );
+
+ // is it a regular fact or an event?
+ String role = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_ROLE );
+ if ( role != null ) {
+ type.setRole( TypeDeclaration.Role.parseRole( role ) );
+ }
+
+ // is it a POJO or a template?
+ String templateName = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_TEMPLATE );
+ if( templateName != null ) {
+ type.setFormat( TypeDeclaration.Format.TEMPLATE );
+ FactTemplate template = this.pkg.getFactTemplate( templateName );
+ if( template != null ) {
+ type.setTypeTemplate( template );
+ } else {
+ this.results.add( new TypeDeclarationError( "Template not found '" + template + "' for type '" + type.getTypeName() + "'",
+ typeDescr.getLine() ) );
+ }
+ } else {
+ String className = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_CLASS );
+ if ( className == null ) {
+ className = type.getTypeName();
+ }
+ type.setFormat( TypeDeclaration.Format.POJO );
+ Class clazz;
+ try {
+ clazz = typeResolver.resolveType( className );
+ type.setTypeClass( clazz );
+ } catch ( final ClassNotFoundException e ) {
+ this.results.add( new TypeDeclarationError( "Class not found '" + className + "' for type '" + type.getTypeName() + "'",
+ typeDescr.getLine() ) );
+ }
+ }
+
+ String clockStrategy = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_CLOCK_STRATEGY );
+ if ( clockStrategy != null ) {
+ type.setClockStrategy( TypeDeclaration.ClockStrategy.parseClockStrategy( clockStrategy ) );
+ }
+ String timestamp = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_TIMESTAMP );
+ if ( timestamp != null ) {
+ type.setTimestampAttribute( timestamp );
+ }
+ String duration = typeDescr.getAttribute( TypeDeclarationDescr.ATTR_DURATION );
+ if ( duration != null ) {
+ type.setDurationAttribute( duration );
+ }
+
+ this.pkg.addTypeDeclaration( type );
+ }
+ }
+
private void addFunction(final FunctionDescr functionDescr) {
this.dialect.addFunction( functionDescr,
getTypeResolver() );
More information about the jboss-svn-commits
mailing list