[jboss-svn-commits] JBL Code SVN: r15847 - in labs/jbossrules/trunk/drools-core/src: test/java/org/codehaus/jfdi/interpreter and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 15 20:45:20 EDT 2007
Author: michael.neale at jboss.com
Date: 2007-10-15 20:45:20 -0400 (Mon, 15 Oct 2007)
New Revision: 15847
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/TypeResolver.java
labs/jbossrules/trunk/drools-core/src/test/java/org/codehaus/jfdi/interpreter/ClassTypeResolverTest.java
Log:
JBRULES-1271 Test populator.
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java 2007-10-15 19:33:10 UTC (rev 15846)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java 2007-10-16 00:45:20 UTC (rev 15847)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 JBoss Inc
- *
+ *
* Licensed 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.
@@ -73,7 +73,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.drools.semantics.base.Importer#getImports( Class clazz )
*/
/* (non-Javadoc)
@@ -85,7 +85,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.drools.semantics.base.Importer#addImports(org.drools.spi.ImportEntry)
*/
/* (non-Javadoc)
@@ -104,7 +104,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.drools.semantics.base.Importer#importClass(java.lang.ClassLoader,
* java.lang.String)
*/
@@ -136,7 +136,7 @@
}
if ( clazz == null ) {
- // Now try the package object type cache
+ // Now try the package object type cache
clazz = lookupFromCache( className );
}
@@ -149,7 +149,7 @@
}
}
- // Now try the className with each of the given imports
+ // Now try the className with each of the given imports
if ( clazz == null ) {
final Set validClazzCandidates = new HashSet();
@@ -187,7 +187,7 @@
clazz = defaultClass( className );
}
- // If array component class was found, try to resolve the array class of it
+ // If array component class was found, try to resolve the array class of it
if ( isArray ) {
if ( clazz == null && internalNamesMap.containsKey( className ) ) {
arrayClassName.append( internalNamesMap.get( className ) );
@@ -195,7 +195,7 @@
if ( clazz != null ) {
arrayClassName.append( "L" ).append( clazz.getName() ).append( ";" );
} else {
- // we know we will probably not be able to resolve this name, but nothing else we can do.
+ // we know we will probably not be able to resolve this name, but nothing else we can do.
arrayClassName.append( "L" ).append( className ).append( ";" );
}
}
@@ -206,7 +206,7 @@
}
}
- // We still can't find the class so throw an exception
+ // We still can't find the class so throw an exception
if ( clazz == null ) {
throw new ClassNotFoundException( "Unable to find class '" + className + "'" );
}
@@ -281,4 +281,16 @@
public boolean isEmpty() {
return this.imports.isEmpty();
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.drools.base.TypeResolver#getFullTypeName(java.lang.String)
+ */
+ public String getFullTypeName(String shortName) throws ClassNotFoundException {
+
+ Class clz = resolveType(shortName);
+ if (clz == null) throw new IllegalArgumentException("Unable to resolve the full type name for " + shortName);
+ return clz.getName();
+
+ }
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/TypeResolver.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/TypeResolver.java 2007-10-15 19:33:10 UTC (rev 15846)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/TypeResolver.java 2007-10-16 00:45:20 UTC (rev 15847)
@@ -9,4 +9,11 @@
public Class resolveType(String className) throws ClassNotFoundException;
+ /**
+ * This will return the fully qualified type name (including the namespace).
+ * Eg, if it was a pojo org.drools.Cheese, then if you passed in "Cheese" you should get back
+ * "org.drools.Cheese"
+ */
+ public String getFullTypeName(String shortName) throws ClassNotFoundException;
+
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/codehaus/jfdi/interpreter/ClassTypeResolverTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/codehaus/jfdi/interpreter/ClassTypeResolverTest.java 2007-10-15 19:33:10 UTC (rev 15846)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/codehaus/jfdi/interpreter/ClassTypeResolverTest.java 2007-10-16 00:45:20 UTC (rev 15847)
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package org.codehaus.jfdi.interpreter;
@@ -11,6 +11,7 @@
import org.drools.FirstClass;
import org.drools.SecondClass;
import org.drools.base.ClassTypeResolver;
+import org.drools.base.TypeResolver;
/**
* @author fburlet
@@ -91,8 +92,8 @@
resolver.addImport( "org.drools.FirstClass" );
resolver.addImport( "org.drools.FirstClass.AlternativeKey" );
resolver.addImport( "org.drools.SecondClass" );
- resolver.addImport( "org.drools.SecondClass.AlternativeKey" );
-
+ resolver.addImport( "org.drools.SecondClass.AlternativeKey" );
+
assertEquals( String.class,
resolver.resolveType( "String" ) );
assertEquals( String.class,
@@ -111,7 +112,20 @@
assertEquals( SecondClass.AlternativeKey.class,
resolver.resolveType( "org.drools.SecondClass.AlternativeKey" ) );
}
-
+
+ public void testResolveFullTypeName() throws Exception {
+
+ final TypeResolver resolver = new ClassTypeResolver( new HashSet(), Thread.currentThread().getContextClassLoader() );
+ resolver.addImport( "org.drools.Cheese" );
+ resolver.addImport( "org.drools.FirstClass" );
+
+ assertEquals("org.drools.Cheese", resolver.getFullTypeName("Cheese"));
+ assertEquals("org.drools.FirstClass", resolver.getFullTypeName("FirstClass"));
+
+
+
+ }
+
public void testResolveObjectFromImportMultipleClassesDifferentPackages() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver( new HashSet(), Thread.currentThread().getContextClassLoader() );
resolver.addImport( "org.drools.Cheese" );
More information about the jboss-svn-commits
mailing list