[jboss-svn-commits] JBL Code SVN: r6818 - labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 16 05:22:12 EDT 2006
Author: mark.little at jboss.com
Date: 2006-10-16 05:22:08 -0400 (Mon, 16 Oct 2006)
New Revision: 6818
Modified:
labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
Log:
added remove.
Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-10-16 03:21:25 UTC (rev 6817)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-10-16 09:22:08 UTC (rev 6818)
@@ -46,99 +46,107 @@
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
/**
- * Allows EPRs to be saved to and loaded from files. Mainly for testing purposes.
+ * Allows EPRs to be saved to and loaded from files. Mainly for testing
+ * purposes.
*
* @author marklittle
- *
+ *
*/
public class EPRManager
{
private static final String ELEMENT_NAME = "EPR";
-
+
/**
* All EPRs are saves in files within the current working directory.
*
* @return the manager for the cwd.
*/
-
- public static final EPRManager getInstance ()
+
+ public static final EPRManager getInstance()
{
return getInstance("");
}
-
+
/**
- * All EPRs are saves in files within a defined directory. Get the right manager
- * for that directory.
+ * All EPRs are saves in files within a defined directory. Get the right
+ * manager for that directory.
*
- * @param domain the name of the directory. If <code>null</code> then the null String
- * is assumed.
- * @return the manager for the directory. If it does not exist, then one will be created.
+ * @param domain
+ * the name of the directory. If <code>null</code> then the
+ * null String is assumed.
+ * @return the manager for the directory. If it does not exist, then one
+ * will be created.
*/
-
- public static final EPRManager getInstance (String domain)
+
+ public static final EPRManager getInstance(String domain)
{
if (domain == null)
domain = "";
-
+
synchronized (_instances)
{
EPRManager theInstance = _instances.get(domain);
-
+
if (theInstance == null)
{
theInstance = new EPRManager(domain);
-
+
_instances.put(domain, theInstance);
}
-
+
return theInstance;
}
}
-
- public final String getDomain ()
+
+ public final String getDomain()
{
return _directory;
}
-
- public boolean equals (Object manager)
+
+ public boolean equals(Object manager)
{
if (manager instanceof EPRManager)
{
EPRManager comp = (EPRManager) manager;
-
+
if (_directory.equals(comp.getDomain()))
return true;
}
-
+
return false;
}
-
+
/**
* Save the EPR into the specified file.
*
- * @param name the name of the file to use (the logical service name).
- * @param address the EPR to save.
+ * @param name
+ * the name of the file to use (the logical service name).
+ * @param address
+ * the EPR to save.
*
- * @throws IOException thrown if there is an error.
+ * @throws IOException
+ * thrown if there is an error.
*/
-
- public final void saveEPR (String name, EPR address) throws IOException
+
+ public final void saveEPR(String name, EPR address) throws IOException
{
if ((name == null) || (address == null))
throw new IllegalArgumentException();
-
+
try
{
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element portReferenceElement = doc.createElement(ELEMENT_NAME);
-
+
doc.appendChild(portReferenceElement);
-
- PortReferenceHelper.toXML(null, doc, portReferenceElement, address.getAddr(), false);
+ PortReferenceHelper.toXML(null, doc, portReferenceElement, address
+ .getAddr(), false);
+
StringWriter sWriter = new StringWriter();
OutputFormat format = new OutputFormat();
format.setIndenting(true);
@@ -150,8 +158,9 @@
String documentAsString = sWriter.toString();
- FileOutputStream output = new FileOutputStream(_directory+File.separator+name);
-
+ FileOutputStream output = new FileOutputStream(_directory
+ + File.separator + name);
+
output.write(documentAsString.getBytes());
output.flush();
output.getFD().sync(); // make sure it's on disk!
@@ -169,36 +178,60 @@
throw new IOException(ex.toString());
}
}
+
+ /**
+ * Remove the EPR-to-file association.
+ *
+ * @param name the logical name for the service.
+ * @throws IOException thrown if there are any errors.
+ */
+ public final void removeEPR(String name) throws IOException
+ {
+ if (name == null)
+ throw new IllegalArgumentException();
+
+ File theFile = new File(_directory + File.separator + name);
+
+ if (theFile.exists())
+ theFile.delete();
+ else
+ throw new FileNotFoundException();
+ }
+
/**
* Get the EPR specified by the logical name.
*
- * @param name the service name.
+ * @param name
+ * the service name.
* @return the EPR, or <code>null</code> if none exists.
- * @throws IOException thrown if there is an error.
+ * @throws IOException
+ * thrown if there is an error.
*/
-
- public final EPR loadEPR (String name) throws IOException
+
+ public final EPR loadEPR(String name) throws IOException
{
if (name == null)
throw new IllegalArgumentException();
-
- File theFile = new File(_directory+File.separator+name);
-
+
+ File theFile = new File(_directory + File.separator + name);
+
try
{
if (theFile.exists())
{
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(theFile);
Element rootElement = doc.getDocumentElement();
-
+
if (rootElement == null)
- throw new IOException("Cannot locate "+ELEMENT_NAME);
-
- PortReference addr = PortReferenceHelper.fromXML(rootElement, false);
+ throw new IOException("Cannot locate " + ELEMENT_NAME);
+ PortReference addr = PortReferenceHelper.fromXML(rootElement,
+ false);
+
return new EPR(addr);
}
else
@@ -218,13 +251,13 @@
}
}
- protected EPRManager (String domain)
+ protected EPRManager(String domain)
{
_directory = domain;
}
-
+
private String _directory;
-
+
private static Hashtable<String, EPRManager> _instances = new Hashtable<String, EPRManager>();
-
-}
\ No newline at end of file
+
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list