Revision: 12787
http://sourceforge.net/p/foray/code/12787
Author: victormote
Date: 2022-12-06 02:33:22 +0000 (Tue, 06 Dec 2022)
Log Message:
-----------
Convert Namespace classes to singletons.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTreeServer4a.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -122,28 +122,26 @@
*/
private void setupNamespaces() {
// Register the standard Namespaces.
- final NamespaceFo fo = new NamespaceFo();
- registerNamespace(fo);
- this.namespaceFO = fo;
- final NamespaceXml xml = new NamespaceXml();
- registerNamespace(xml);
- this.namespaceXML = xml;
- final NamespaceSvg svg = new NamespaceSvg();
- registerNamespace(svg);
- this.namespaceSVG = svg;
- final MathNamespace math = new MathNamespace();
- this.registerNamespace(math);
- this.namespaceMath = math;
- final NamespaceForay extensions = new NamespaceForay();
- registerNamespace(extensions);
- this.namespaceForay = extensions;
- final NamespaceAxsl namespaceAxsl = new NamespaceAxsl();
- registerNamespace(namespaceAxsl);
- this.namespaceAxsl = namespaceAxsl;
+ registerNamespace(NamespaceFo.getInstance());
+ this.namespaceFO = NamespaceFo.getInstance();
+ registerNamespace(NamespaceXml.getInstance());
+ this.namespaceXML = NamespaceXml.getInstance();
+
+ registerNamespace(NamespaceSvg.getInstance());
+ this.namespaceSVG = NamespaceSvg.getInstance();
+
+ this.registerNamespace(MathNamespace.getInstance());
+ this.namespaceMath = MathNamespace.getInstance();
+
+ registerNamespace(NamespaceForay.getInstance());
+ this.namespaceForay = NamespaceForay.getInstance();
+
+ registerNamespace(NamespaceAxsl.getInstance());
+ this.namespaceAxsl = NamespaceAxsl.getInstance();
+
// Register custom embedded Namespaces from available services
- final List<String> providers = ClassService.providers(
- org.foray.fotree.Namespace.class);
+ final List<String> providers = ClassService.providers(org.foray.fotree.Namespace.class);
if (providers != null) {
for (String str : providers) {
try {
@@ -155,8 +153,7 @@
}
/**
- * Add a Namespace instance to the list of namespaces that we should be
- * able to parse.
+ * Add a Namespace instance to the list of namespaces that we should be able to parse.
* @param namespace A Namespace instance to be added.
*/
public void registerNamespace(final Namespace namespace) {
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/NamespaceAxsl.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -45,14 +45,15 @@
/**
* This class manages the namespace that is used for aXSL extensions to XSL-FO.
*/
-public class NamespaceAxsl extends Namespace {
+public final class NamespaceAxsl extends Namespace {
+ /** The singleton instance. */
+ private static NamespaceAxsl theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public NamespaceAxsl() {
- super();
- }
+ private NamespaceAxsl() { }
@Override
public String getNamespaceURI() {
@@ -92,4 +93,15 @@
return new PropertyList(attlist.getLength());
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static NamespaceAxsl getInstance() {
+ if (NamespaceAxsl.theInstance == null) {
+ NamespaceAxsl.theInstance = new NamespaceAxsl();
+ }
+ return NamespaceAxsl.theInstance;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/NamespaceFo.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -45,14 +45,15 @@
/**
* This class manages the namespace that is used for XSL-FO elements.
*/
-public class NamespaceFo extends Namespace {
+public final class NamespaceFo extends Namespace {
+ /** The singleton instance. */
+ private static NamespaceFo theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public NamespaceFo() {
- super();
- }
+ private NamespaceFo() { }
@Override
public String getNamespaceURI() {
@@ -100,4 +101,15 @@
return new PropertyList(attlist.getLength());
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static NamespaceFo getInstance() {
+ if (NamespaceFo.theInstance == null) {
+ NamespaceFo.theInstance = new NamespaceFo();
+ }
+ return NamespaceFo.theInstance;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/foray/NamespaceForay.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -45,14 +45,15 @@
/**
* This class manages the namespace that is used for FOray extensions to XSL-FO.
*/
-public class NamespaceForay extends Namespace {
+public final class NamespaceForay extends Namespace {
+ /** The singleton instance. */
+ private static NamespaceForay theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public NamespaceForay() {
- super();
- }
+ private NamespaceForay() { }
@Override
public String getNamespaceURI() {
@@ -103,4 +104,15 @@
return new PropertyList(attlist.getLength());
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static NamespaceForay getInstance() {
+ if (NamespaceForay.theInstance == null) {
+ NamespaceForay.theInstance = new NamespaceForay();
+ }
+ return NamespaceForay.theInstance;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/math/MathNamespace.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -47,14 +47,15 @@
* This class manages the namespace that is used for the Math Markup Language
* (MathML).
*/
-public class MathNamespace extends Namespace {
+public final class MathNamespace extends Namespace {
+ /** The singleton instance. */
+ private static MathNamespace theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public MathNamespace() {
- super();
- }
+ private MathNamespace() { }
@Override
public String getNamespaceURI() {
@@ -99,4 +100,15 @@
return new PropertyListUnparsed(attlist);
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static MathNamespace getInstance() {
+ if (MathNamespace.theInstance == null) {
+ MathNamespace.theInstance = new MathNamespace();
+ }
+ return MathNamespace.theInstance;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/svg/NamespaceSvg.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -46,15 +46,17 @@
/**
* This class manages the namespace that is used for SVG.
*/
-public class NamespaceSvg extends Namespace {
+public final class NamespaceSvg extends Namespace {
+ /** The singleton instance. */
+ private static NamespaceSvg theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public NamespaceSvg() {
- super();
- }
+ private NamespaceSvg() { }
+
@Override
public String getNamespaceURI() {
return SvgGraphic.SVG_NS_URI;
@@ -98,4 +100,15 @@
return new PropertyListUnparsed(attlist);
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static NamespaceSvg getInstance() {
+ if (NamespaceSvg.theInstance == null) {
+ NamespaceSvg.theInstance = new NamespaceSvg();
+ }
+ return NamespaceSvg.theInstance;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java 2022-12-06 01:27:53 UTC (rev 12786)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/NamespaceXml.java 2022-12-06 02:33:22 UTC (rev 12787)
@@ -44,18 +44,19 @@
import javax.xml.XMLConstants;
/**
- * This class manages the namespace that is used for elements with the "xml:"
- * prefix.
+ * This class manages the namespace that is used for elements with the "xml:" prefix.
*/
-public class NamespaceXml extends Namespace {
+public final class NamespaceXml extends Namespace {
+ /** The singleton instance. */
+ private static NamespaceXml theInstance;
+
/**
- * Constructor.
+ * Private constructor. To obtain the singleton instance, use {@link #getInstance()}.
*/
- public NamespaceXml() {
- super();
- }
+ private NamespaceXml() { }
+
@Override
public String getNamespaceURI() {
return XMLConstants.XML_NS_URI;
@@ -97,4 +98,15 @@
return new PropertyList(attlist.getLength());
}
+ /**
+ * Returns the singleton instance of this class.
+ * @return The singleton instance of this class.
+ */
+ public static NamespaceXml getInstance() {
+ if (NamespaceXml.theInstance == null) {
+ NamespaceXml.theInstance = new NamespaceXml();
+ }
+ return NamespaceXml.theInstance;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|