diff options
| -rw-r--r-- | src/main/java/com/c2kernel/process/Gateway.java | 6 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/utils/CastorXMLUtility.java | 74 | ||||
| -rw-r--r-- | src/test/java/MainTest.java | 11 | ||||
| -rw-r--r-- | src/test/resources/server.conf | 3 |
4 files changed, 39 insertions, 55 deletions
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java index cd76d0e..85262e8 100644 --- a/src/main/java/com/c2kernel/process/Gateway.java +++ b/src/main/java/com/c2kernel/process/Gateway.java @@ -108,7 +108,11 @@ public class Gateway // load kernel mapfiles giving the resourse loader and the properties of
// the application to be able to configure castor
- mMarshaller = new CastorXMLUtility(mResource, props, "mapFiles/");
+ try {
+ mMarshaller = new CastorXMLUtility(mResource, props, mResource.getKernelResourceURL("mapFiles/"));
+ } catch (MalformedURLException e1) {
+ throw new InvalidDataException("Invalid Resource Location", "");
+ }
// init module manager
diff --git a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java index c7d37dd..c5c2499 100644 --- a/src/main/java/com/c2kernel/utils/CastorXMLUtility.java +++ b/src/main/java/com/c2kernel/utils/CastorXMLUtility.java @@ -29,11 +29,11 @@ import com.c2kernel.process.resource.ResourceLoader; * @author $Author: abranson $ $Date: 2004/10/20 14:10:21 $
* @version $Revision: 1.12 $
**************************************************************************/
-public class CastorXMLUtility{
+public class CastorXMLUtility
+{
public static final String CASTOR_XML_SERIALIZER_FACTORY = "org.exolab.castor.xml.serializer.factory";
-
- private XMLContext pCastorContext;
+ private XMLContext mappingContext;
/**
* Looks for a file called 'index.xml' at the given URL, and loads every
@@ -42,89 +42,77 @@ public class CastorXMLUtility{ * @param aResourceLoader
* the resource loader able to return the right class loader
* @param aAppProperties
- * the application properties containint optionnal castor
+ * the application properties containing optional castor
* configuration
- * @param aMapsSubPath
- * the map root sub path (in the kernel path)
+ * @param mapURL
+ * the root URL for the mapfiles
* @throws InvalidDataException
*/
public CastorXMLUtility(final ResourceLoader aResourceLoader,
- final Properties aAppProperties, final String aMapsSubPath)
+ final Properties aAppProperties, final URL mapURL)
throws InvalidDataException {
- // build base url
- URL wMapsURL ;
- try {
- wMapsURL = aResourceLoader.getKernelResourceURL(aMapsSubPath);
- } catch (MalformedURLException e) {
- throw new InvalidDataException(String.format(
- "Invalid Resource Location [%s]. Cause:%s", aMapsSubPath,
- e.getLocalizedMessage()));
- }
-
+
// load index
- Logger.msg(3,String.format( "CastorXMLUtility.<init> Loading maps from [%s]",wMapsURL));
+ Logger.msg(3,String.format( "CastorXMLUtility.<init> Loading maps from [%s]",mapURL));
String index;
try {
- index = FileStringUtility.url2String( new URL(wMapsURL, "index") );
+ index = FileStringUtility.url2String( new URL(mapURL, "index") );
} catch (Exception e) {
- throw new InvalidDataException(String.format("Could not load map index from [%s]",wMapsURL));
+ throw new InvalidDataException(String.format("Could not load map index from [%s]",mapURL));
}
// retrieve the class loader of the class "CastorXMLUtility"
- ClassLoader wKernelClassLoader = aResourceLoader
+ ClassLoader defaultClassLoader = aResourceLoader
.getClassLoader(CastorXMLUtility.class.getName());
Logger.msg(3, String.format(
- "CastorXMLUtility.<init>: iuse KernelClassLoader=[%s]",
- wKernelClassLoader));
+ "CastorXMLUtility.<init>: defaultClassLoader=[%s]",
+ defaultClassLoader));
StringTokenizer sTokenizer = new StringTokenizer(index);
int wNbMap = sTokenizer.countTokens();
// init the castor mapping using the classloader of the class "CastorXMLUtility"
- Mapping wCastorMapping = new Mapping(wKernelClassLoader);
+ Mapping thisMapping = new Mapping(defaultClassLoader);
HashSet<URL> loadedMapURLs = new HashSet<URL>();
try {
int wMapIdx=0;
while( sTokenizer.hasMoreTokens() ) {
- String wCurrentMap = sTokenizer.nextToken();
- URL wCurrentMapURL = new URL(wMapsURL, wCurrentMap);
+ String thisMap = sTokenizer.nextToken();
+ URL thisMapURL = new URL(mapURL, thisMap);
wMapIdx++;
- if( !loadedMapURLs.contains(wCurrentMapURL) ) {
- Logger.msg(
- 3,
- String.format(
- "CastorXMLUtility.<init>: Adding mapping file (%d/%d):[%s]",
- wMapIdx, wNbMap, wCurrentMapURL));
- wCastorMapping.loadMapping( wCurrentMapURL );
- loadedMapURLs.add( wCurrentMapURL );
+ if( !loadedMapURLs.contains(thisMapURL) ) {
+ Logger.msg( 3,
+ String.format("CastorXMLUtility.<init>: Adding mapping file (%d/%d):[%s]", wMapIdx, wNbMap, thisMapURL));
+ thisMapping.loadMapping( thisMapURL );
+ loadedMapURLs.add( thisMapURL );
}
else {
- Logger.msg(3,"Map file already loaded:"+wCurrentMapURL);
+ Logger.msg(3,"Map file already loaded:"+thisMapURL);
}
}
- pCastorContext = new XMLContext();
+ mappingContext = new XMLContext();
- pCastorContext.setClassLoader(wKernelClassLoader);
+ mappingContext.setClassLoader(defaultClassLoader);
// if the aAppProperties contains castor properties then
if (aAppProperties.contains(CASTOR_XML_SERIALIZER_FACTORY)) {
- pCastorContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY,
+ mappingContext.setProperty(CASTOR_XML_SERIALIZER_FACTORY,
aAppProperties
.getProperty(CASTOR_XML_SERIALIZER_FACTORY));
Logger.msg(3, String.format(
"CastorXMLUtility.<init>: castor prop: %s=[%s]",
- CASTOR_XML_SERIALIZER_FACTORY, pCastorContext
+ CASTOR_XML_SERIALIZER_FACTORY, mappingContext
.getProperty(CASTOR_XML_SERIALIZER_FACTORY)));
}
- pCastorContext.addMapping(wCastorMapping);
+ mappingContext.addMapping(thisMapping);
} catch (MappingException ex) {
Logger.error(ex);
throw new InvalidDataException("XML Mapping files are not valid: "+ex.getMessage(), "");
@@ -136,7 +124,7 @@ public class CastorXMLUtility{ throw new InvalidDataException("Could not read XML mapping files: "+ex.getMessage(), "");
}
- Logger.msg(1, String.format("Loaded [%d] maps from [%s]",loadedMapURLs.size(),wMapsURL));
+ Logger.msg(1, String.format("Loaded [%d] maps from [%s]", loadedMapURLs.size(), mapURL));
}
/**************************************************************************
@@ -153,7 +141,7 @@ public class CastorXMLUtility{ if (obj instanceof Outcome)
return ((Outcome)obj).getData();
StringWriter sWriter = new StringWriter();
- Marshaller marshaller = pCastorContext.createMarshaller();
+ Marshaller marshaller = mappingContext.createMarshaller();
marshaller.setWriter(sWriter);
marshaller.setMarshalAsDocument( false );
@@ -174,7 +162,7 @@ public class CastorXMLUtility{ {
if (data.equals("<NULL/>")) return null;
StringReader sReader = new StringReader( data );
- Unmarshaller unmarshaller = pCastorContext.createUnmarshaller();
+ Unmarshaller unmarshaller = mappingContext.createUnmarshaller();
return unmarshaller.unmarshal( sReader );
}
}
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 431c4c0..ccef17a 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -12,7 +12,6 @@ import com.c2kernel.persistency.outcome.SchemaValidator; import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.Script;
import com.c2kernel.utils.CastorXMLUtility;
-import com.c2kernel.scripting.ScriptParsingException;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
@@ -37,16 +36,8 @@ public class MainTest { }
}
- /**
- * @throws Exception
- */
public void testMapFiles() throws Exception {
-
- Properties wAppProperties = new Properties();
- wAppProperties.put(CastorXMLUtility.CASTOR_XML_SERIALIZER_FACTORY,
- "org.exolab.castor.xml.XercesXMLSerializerFactory");
-
- new CastorXMLUtility(Gateway.getResource(), wAppProperties, "mapFiles/");
+ new CastorXMLUtility(Gateway.getResource(), Gateway.getProperties(), Gateway.getResource().getKernelResourceURL("mapFiles/"));
}
public void testBootItems() throws Exception {
diff --git a/src/test/resources/server.conf b/src/test/resources/server.conf index 476aeb0..c8a072a 100644 --- a/src/test/resources/server.conf +++ b/src/test/resources/server.conf @@ -1 +1,2 @@ -ClusterStorage=MemoryOnlyClusterStorage
\ No newline at end of file +ClusterStorage=MemoryOnlyClusterStorage
+org.exolab.castor.xml.serializer.factory=org.exolab.castor.xml.XercesXMLSerializerFactory
\ No newline at end of file |
