[utilities COMMIT] /java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
noreply at shibboleth.net
noreply at shibboleth.net
Tue Mar 17 12:35:28 EDT 2015
Author: scantor
Date: Tue Mar 17 12:35:27 2015
New Revision: 779
URL: http://svn.shibboleth.net/view/utilities?rev=779&view=rev
Log:
JSPT-57 - SchemaBuilder should throw IllegalStateException if called twice
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java?rev=779&r1=778&r2=779&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java Tue Mar 17 12:35:27 2015
@@ -53,7 +53,7 @@
*/
@NotThreadSafe
public class SchemaBuilder {
-
+
/** Language of the schema files. */
public static enum SchemaLanguage {
@@ -106,6 +106,9 @@
/** Properties to set on factory. */
@Nonnull private Map<String,Object> properties;
+ /** One time-init flag. */
+ private boolean alreadyBuilt;
+
/** Constructor. */
public SchemaBuilder() {
schemaLang = SchemaLanguage.XML;
@@ -113,6 +116,7 @@
features = new HashMap<>();
properties = new HashMap<>();
errorHandler = new LoggingErrorHandler(log);
+ alreadyBuilt = false;
}
/**
@@ -287,7 +291,11 @@
* @return the constructed schema
* @throws SAXException thrown if there is a problem converting the schema sources into a schema
*/
- @Nonnull public Schema buildSchema() throws SAXException {
+ @Nonnull public synchronized Schema buildSchema() throws SAXException {
+ if (alreadyBuilt) {
+ throw new IllegalStateException("Schema already built, cannot build a second time");
+ }
+
Constraint.isNotEmpty(sources, "No schema sources specified");
final SchemaFactory schemaFactory = schemaLang.getSchemaFactory();
@@ -323,6 +331,7 @@
if (resourceResolver != null) {
schemaFactory.setResourceResolver(resourceResolver);
}
+ alreadyBuilt = true;
return schemaFactory.newSchema(sources.toArray(new Source[sources.size()]));
}
More information about the commits
mailing list