diff options
author | wbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-12-02 10:13:09 +0000 |
---|---|---|
committer | wbauer <wbauer@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-12-02 10:13:09 +0000 |
commit | 99134c1be5db0fedadc051922e70c9bf563ce16d (patch) | |
tree | 6745751351777c77ab55e6f11da88adacf27c910 /bkucommon/src/main/java/at/gv/egiz/bku/slcommands | |
parent | dbc87e775dce65e0e048570bd232ef1fa4794fbb (diff) | |
download | mocca-99134c1be5db0fedadc051922e70c9bf563ce16d.tar.gz mocca-99134c1be5db0fedadc051922e70c9bf563ce16d.tar.bz2 mocca-99134c1be5db0fedadc051922e70c9bf563ce16d.zip |
Changed SLCommandFactory configuration mechanism and moved the actual configuration to spring's application context
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@231 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/main/java/at/gv/egiz/bku/slcommands')
4 files changed, 64 insertions, 66 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java index e13b29a1..9c98ef8a 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java @@ -16,40 +16,37 @@ */ package at.gv.egiz.bku.slcommands;
-import java.io.IOException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.XMLConstants;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.UnmarshalException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl;
-import at.gv.egiz.bku.slcommands.impl.InfoboxReadCommandImpl;
-import at.gv.egiz.bku.slcommands.impl.NullOperationCommandImpl;
-import at.gv.egiz.bku.slexceptions.SLCommandException;
-import at.gv.egiz.bku.slexceptions.SLExceptionMessages;
-import at.gv.egiz.bku.slexceptions.SLRequestException;
-import at.gv.egiz.bku.slexceptions.SLRuntimeException;
-import at.gv.egiz.slbinding.RedirectEventFilter;
-import at.gv.egiz.slbinding.RedirectUnmarshallerListener;
+import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.XMLConstants; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.UnmarshalException; +import javax.xml.bind.Unmarshaller; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +import at.gv.egiz.bku.slexceptions.SLCommandException; +import at.gv.egiz.bku.slexceptions.SLExceptionMessages; +import at.gv.egiz.bku.slexceptions.SLRequestException; +import at.gv.egiz.bku.slexceptions.SLRuntimeException; +import at.gv.egiz.slbinding.RedirectEventFilter; +import at.gv.egiz.slbinding.RedirectUnmarshallerListener; public class SLCommandFactory {
@@ -72,29 +69,30 @@ public class SLCommandFactory { /**
* Schema for Security Layer command validation.
*/
- private static Schema slSchema;
+ private Schema slSchema;
/**
* The JAXBContext.
*/
- private static JAXBContext jaxbContext;
+ private JAXBContext jaxbContext;
/**
* The map of <namespaceURI>:<localName> to implementation class of the
* corresponding {@link SLCommand}.
*/
- private static Map<String, Class<? extends SLCommand>> slRequestTypeMap = new HashMap<String, Class<? extends SLCommand>>();
-
-
- static {
-
- // TODO: implement dynamic registration
-
- // register all known implementation classes
- putImplClass(SLCommand.NAMESPACE_URI, "NullOperationRequest",
- NullOperationCommandImpl.class);
- putImplClass(SLCommand.NAMESPACE_URI, "InfoboxReadRequest",
- InfoboxReadCommandImpl.class);
- putImplClass(SLCommand.NAMESPACE_URI, "CreateXMLSignatureRequest",
- CreateXMLSignatureCommandImpl.class);
+ private Map<String, Class<? extends SLCommand>> slRequestTypeMap = new HashMap<String, Class<? extends SLCommand>>();
+ + /** + * Configures the singleton instance with command implementations + * @param commandImplMap + * @throws ClassNotFoundException + */ + @SuppressWarnings("unchecked") + public void setCommandImpl(Map<String, String> commandImplMap) throws ClassNotFoundException { + ClassLoader cl = getClass().getClassLoader(); + for (String key : commandImplMap.keySet()) { + Class<? extends SLCommand> impl = (Class<? extends SLCommand>) cl.loadClass(commandImplMap.get(key)); + log.debug("Registering sl command implementation for :"+key+ "; implementation class: "+impl.getCanonicalName()); + slRequestTypeMap.put(key, impl); + } }
/**
@@ -110,7 +108,7 @@ public class SLCommandFactory { * the implementation class, or <code>null</code> to deregister a
* currently registered class
*/
- public static void putImplClass(String namespaceUri, String localname,
+ public void setImplClass(String namespaceUri, String localname,
Class<? extends SLCommand> slCommandClass) {
if (slCommandClass != null) {
slRequestTypeMap.put(namespaceUri + ":" + localname, slCommandClass);
@@ -128,7 +126,7 @@ public class SLCommandFactory { * @return the implementation class, or <code>null</code> if no class is
* registered for the given <code>name</code>
*/
- public static Class<? extends SLCommand> getImplClass(QName name) {
+ public Class<? extends SLCommand> getImplClass(QName name) {
String namespaceURI = name.getNamespaceURI();
String localPart = name.getLocalPart();
return slRequestTypeMap.get(namespaceURI + ":" + localPart);
@@ -139,14 +137,14 @@ public class SLCommandFactory { *
* @param slSchema the schema to validate Security Layer commands with
*/
- public static void setSLSchema(Schema slSchema) {
- SLCommandFactory.slSchema = slSchema;
+ public void setSLSchema(Schema slSchema) {
+ this.slSchema = slSchema;
}
/**
* @return the jaxbContext
*/
- public static JAXBContext getJaxbContext() {
+ public JAXBContext getJaxbContext() {
ensureJaxbContext();
return jaxbContext;
}
@@ -154,14 +152,14 @@ public class SLCommandFactory { /**
* @param jaxbContext the jaxbContext to set
*/
- public static void setJaxbContext(JAXBContext jaxbContext) {
- SLCommandFactory.jaxbContext = jaxbContext;
+ public void setJaxbContext(JAXBContext jaxbContext) {
+ this.jaxbContext = jaxbContext;
}
/**
* Initialize the JAXBContext.
*/
- private synchronized static void ensureJaxbContext() {
+ private synchronized void ensureJaxbContext() {
if (jaxbContext == null) {
try {
String slPkg = at.buergerkarte.namespaces.securitylayer._1.ObjectFactory.class.getPackage().getName();
@@ -177,7 +175,7 @@ public class SLCommandFactory { /**
* Initialize the security layer schema.
*/
- private synchronized static void ensureSchema() {
+ private synchronized void ensureSchema() {
if (slSchema == null) {
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
@@ -194,7 +192,7 @@ public class SLCommandFactory { }
Schema schema = schemaFactory.newSchema(sources);
log.debug("Schema successfully created.");
- SLCommandFactory.setSLSchema(schema);
+ setSLSchema(schema);
} catch (SAXException e) {
log.error("Failed to load security layer schema.", e);
throw new SLRuntimeException("Failed to load security layer schema.", e);
@@ -211,9 +209,9 @@ public class SLCommandFactory { */
public synchronized static SLCommandFactory getInstance() {
if (instance == null) {
- ensureJaxbContext();
- ensureSchema();
- instance = new SLCommandFactory();
+ instance = new SLCommandFactory();
+ instance.ensureJaxbContext();
+ instance.ensureSchema();
}
return instance;
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java index 092a13c4..4969c85a 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CreateXMLSignatureResultImpl.java @@ -84,7 +84,7 @@ public class CreateXMLSignatureResultImpl extends SLResultImpl { DocumentFragment fragment = doc.createDocumentFragment();
- JAXBContext jaxbContext = SLCommandFactory.getJaxbContext();
+ JAXBContext jaxbContext = SLCommandFactory.getInstance().getJaxbContext();
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(createCreateXMLSignatureResponse, fragment);
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java index 6f41b562..78e2e7fa 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/InfoboxReadResultFileImpl.java @@ -95,7 +95,7 @@ public class InfoboxReadResultFileImpl extends SLResultImpl implements JAXBElement<InfoboxReadResponseType> infoboxReadResponse = factory.createInfoboxReadResponse(infoboxReadResponseType);
- JAXBContext context = SLCommandFactory.getJaxbContext();
+ JAXBContext context = SLCommandFactory.getInstance().getJaxbContext();
try {
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(infoboxReadResponse, doc);
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java index 7306b237..80bbdca8 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/SLResultImpl.java @@ -85,7 +85,7 @@ public abstract class SLResultImpl implements SLResult { private Marshaller getMarshaller() { try { - JAXBContext context = SLCommandFactory.getJaxbContext(); + JAXBContext context = SLCommandFactory.getInstance().getJaxbContext(); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); return marshaller; |