[java-identity-provider COMMIT] in /trunk/idp-attribute-filter-impl/src: main/java/net/shibboleth/idp/attribute/filte...

noreply at shibboleth.net noreply at shibboleth.net
Mon Aug 15 16:10:55 BST 2011


Author: rdw
Date: Mon Aug 15 16:10:55 2011
New Revision: 4017

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4017&view=rev
Log:
ScriptedAttributeMatcher.  Remove parameters from constructor and move to setters.  Make the class an Initializable, Unmodifiable component.

Modified:
    trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filtering/impl/matcher/ScriptedMatcher.java
    trunk/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filtering/impl/matcher/TestScriptedMatcher.java

Modified: trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filtering/impl/matcher/ScriptedMatcher.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filtering/impl/matcher/ScriptedMatcher.java?rev=4017&r1=4016&r2=4017&view=diff
==============================================================================
--- trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filtering/impl/matcher/ScriptedMatcher.java (original)
+++ trunk/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filtering/impl/matcher/ScriptedMatcher.java Mon Aug 15 16:10:55 2011
@@ -35,6 +35,10 @@
 
 import org.opensaml.util.Assert;
 import org.opensaml.util.StringSupport;
+import org.opensaml.util.component.ComponentInitializationException;
+import org.opensaml.util.component.InitializableComponent;
+import org.opensaml.util.component.UnmodifiableComponent;
+import org.opensaml.util.component.UnmodifiableComponentException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,53 +48,68 @@
  * This is just a scripting shim around {@link AttributeValueMatcher#getMatchingValues}.
  */
 @ThreadSafe
-public class ScriptedMatcher implements AttributeValueMatcher {
+public class ScriptedMatcher implements AttributeValueMatcher, InitializableComponent, UnmodifiableComponent {
 
     /** Class logger. */
     private final Logger log = LoggerFactory.getLogger(ScriptedMatcher.class);
 
     /** The scripting language. */
-    private final String scriptLanguage;
+    private String scriptLanguage;
 
     /** The script to execute. */
-    private final String script;
+    private String script;
 
     /** The script engine to execute the script. */
-    private final ScriptEngine scriptEngine;
+    private ScriptEngine scriptEngine;
 
     /** The compiled form of the script, if the script engine supports compiling. */
-    private final CompiledScript compiledScript;
-
-    /**
-     * Constructor.
-     * 
-     * @param theLanguage the scripting language
-     * @param theScript the script to execute
-     */
-    public ScriptedMatcher(final String theLanguage, final String theScript) {
-        scriptLanguage = theLanguage;
-
-        final String trimmedScript = StringSupport.trimOrNull(theScript);
-        Assert.isNotNull(trimmedScript, "Script for ScriptedMatcher must be non-null and non empty");
-        script = trimmedScript;
-
+    private CompiledScript compiledScript;
+
+    /** Initialization state. */
+    private boolean initialized;
+
+    /**
+     * Has initialize been called on this object. {@inheritDoc}.
+     * */
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    /**
+     *  Initialize.  Check parameters and try to compile the script
+     * {@inheritDoc} 
+     */
+    public synchronized void initialize() throws ComponentInitializationException {
+        if (initialized) {
+            throw new ComponentInitializationException("ScriptedMatcher: initialized multiple times.");
+        }
+        
+        if (null == scriptLanguage) {
+            throw new ComponentInitializationException("ScriptedMatcher: No language set.");
+        }
+        
+        if (null == script) {
+            throw new ComponentInitializationException("ScriptedMatcher: No script set.");
+        }
+        
         final ScriptEngineManager sem = new ScriptEngineManager();
         scriptEngine = sem.getEngineByName(scriptLanguage);
+        if (null == scriptEngine) {
+            throw new ComponentInitializationException("ScriptedMatcher: No valid language set.");
+        }
         compiledScript = compileScript();
-
-        // Validate
-        Assert.isNotNull(scriptEngine, "ScriptedMatcher: unable to create scripting engine for the language: "
-                + scriptLanguage);
-    }
-
-    /** private Constructor to maintain the invariants about the script and language being non null. */
-    @SuppressWarnings("unused")
-    private ScriptedMatcher() {
-        scriptLanguage = null;
-        compiledScript = null;
-        scriptEngine = null;
-        script = null;
-        Assert.isFalse(true, "No default constructor");
+        initialized = true;
+    }
+
+    /**
+     * Set the language we are using.
+     * @param theLanguage what we use.
+     */
+    public synchronized void setLanguage(final String theLanguage) {
+        if (initialized) {

[... 148 lines stripped ...]


More information about the commits mailing list