geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r149447 - in geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator: AbstractValidator.java Messages.java ValidationContext.java ValidationError.java ValidationException.java ValidationFailure.java ValidationResult.java ValidationTest.java ValidationWarning.java Validator.java ejb/
Date Tue, 01 Feb 2005 20:52:11 GMT
Author: dblevins
Date: Tue Feb  1 12:52:06 2005
New Revision: 149447

URL: http://svn.apache.org/viewcvs?view=rev&rev=149447
Log:
Triming down the validation stuff


Added:
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Messages.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationError.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationFailure.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationWarning.java
Removed:
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/AbstractValidator.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationResult.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationTest.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Validator.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ejb/
Modified:
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationContext.java
    geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationException.java

Added: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Messages.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Messages.java?view=auto&rev=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Messages.java (added)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/Messages.java Tue Feb
 1 12:52:06 2005
@@ -0,0 +1,170 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.validator;
+
+import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ *
+ *
+ * @version $Revision: 1.1 $ $Date: 2004/03/01 07:14:43 $
+ */
+public class Messages {
+	static private Hashtable bundles = new Hashtable();
+	static private Hashtable rbFormats = new Hashtable();
+	static private Locale globalLocale;
+
+	private ResourceBundle messages;
+	private Hashtable formats;
+	private Locale locale;
+	private String resourceName;
+
+	public Messages(String resourceName) {
+		synchronized (Messages.class) {
+			locale = globalLocale;
+			this.resourceName = resourceName + ".Messages";
+
+			ResourceBundle rb = (ResourceBundle) bundles.get(this.resourceName);
+			if (rb == null) {
+				init();  // TODO Remove lazy call to init
+			} else {
+				messages = rb;
+				formats = (Hashtable) rbFormats.get(this.resourceName);
+			}
+		}
+
+	}
+
+	protected void init() {
+		try {
+			if (locale == null)
+				messages = ResourceBundle.getBundle(resourceName);
+			else
+				messages = ResourceBundle.getBundle(resourceName, locale);
+		} catch (Exception except) {
+			messages = new EmptyResourceBundle();
+		}
+
+		formats = new Hashtable();
+
+		bundles.put(resourceName, messages);
+		rbFormats.put(resourceName, formats);
+	}
+
+	public String format(String message, Object arg1) {
+		return format(message, new Object[] { arg1 });
+	}
+
+	public String format(String message, Object arg1, Object arg2) {
+		return format(message, new Object[] { arg1, arg2 });
+	}
+
+	public String format(String message, Object arg1, Object arg2, Object arg3) {
+		return format(message, new Object[] { arg1, arg2, arg3 });
+	}
+
+	public String format(String message, Object arg1, Object arg2, Object arg3, Object arg4)
{
+		return format(message, new Object[] { arg1, arg2, arg3, arg4 });
+	}
+
+	public String format(String message, Object arg1, Object arg2, Object arg3, Object arg4,
Object arg5) {
+		return format(message, new Object[] { arg1, arg2, arg3, arg4, arg5 });
+	}
+
+	public String format(String message) {
+		return message(message);
+	}
+
+	public String format(String message, Object[] args) {
+		if (locale != globalLocale) {
+			synchronized (Messages.class) {
+				init();  // TODO Remove lazy call to init
+			}
+		}
+
+		MessageFormat mf;
+		String msg;
+
+		try {
+			mf = (MessageFormat) formats.get(message);
+			if (mf == null) {
+				try {
+					msg = messages.getString(message);
+				} catch (MissingResourceException except) {
+					return message;
+				}
+				mf = new MessageFormat(msg);
+				formats.put(message, mf);
+			}
+			return mf.format(args);
+		} catch (Exception except) {
+			return "An internal error occured while processing message " + message;
+		}
+	}
+
+	public String message(String message) {
+		if (locale != globalLocale) {
+			synchronized (Messages.class) {
+				init();
+			}
+		}
+
+		try {
+			return messages.getString(message);
+		} catch (MissingResourceException except) {
+			return message;
+		}
+	}
+
+	static public void setLocale(Locale locale) {
+		synchronized (Messages.class) {
+			globalLocale = locale;
+			bundles = new Hashtable();
+			rbFormats = new Hashtable();
+		}
+	}
+
+	static {
+		setLocale(Locale.getDefault());
+	}
+
+	private static final class EmptyResourceBundle extends ResourceBundle implements Enumeration
{
+
+		public Enumeration getKeys() {
+			return this;
+		}
+
+		protected Object handleGetObject(String name) {
+			return "[Missing message " + name + "]";
+		}
+
+		public boolean hasMoreElements() {
+			return false;
+		}
+
+		public Object nextElement() {
+			return null;
+		}
+
+	}
+
+}

Modified: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationContext.java?view=diff&r1=149446&r2=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationContext.java
(original)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationContext.java
Tue Feb  1 12:52:06 2005
@@ -14,68 +14,86 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.validator;
 
-import java.io.PrintWriter;
+import java.util.Vector;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
 
-import javax.enterprise.deploy.shared.ModuleType;
+public class ValidationContext {
+    
+    protected Vector failures = new Vector();
+    protected Vector warnings = new Vector();
+    protected Vector errors   = new Vector();
+
+    protected Map attributes = new HashMap();
+
+    protected String jarPath;
+    
+    public ValidationContext(String name){
+        this.jarPath = name;
+    }
 
-import org.apache.xmlbeans.XmlObject;
+    public Set entrySet() {
+        return attributes.entrySet();
+    }
 
-/**
- * Holds all the context information for the current validation process.
- *
- * @version $Rev$ $Date$
- */
-public class ValidationContext {
-    public final PrintWriter out;
-    public final String moduleName;
-    public final ClassLoader loader;
-    public final ModuleType type;
-    public final XmlObject[] standardDD;
-    public final Object[] serverDD;
-    private Object currentStandardDD;
-    private Object currentNode;
-
-    public ValidationContext(ClassLoader loader, String moduleName, PrintWriter out, Object[]
serverDD, XmlObject[] standardDD, ModuleType type) {
-        this.loader = loader;
-        this.moduleName = moduleName;
-        this.out = out;
-        this.serverDD = serverDD;
-        this.standardDD = standardDD;
-        this.type = type;
-    }
-
-    /**
-     * At the moment, this is the standard DD we're validating.
-     */
-    public Object getCurrentStandardDD() {
-        return currentStandardDD;
-    }
-
-    /**
-     * At the moment, this is the standard DD we're validating.
-     */
-    void setCurrentStandardDD(Object currentStandardDD) {
-        this.currentStandardDD = currentStandardDD;
-    }
-
-    /**
-     * At the moment, this is the node on the standard DD that we're
-     * validating.  It corresponds to the XPath that a particular
-     * test is interested in.
-     */
-    public Object getCurrentNode() {
-        return currentNode;
-    }
-
-    /**
-     * At the moment, this is the node on the standard DD that we're
-     * validating.  It corresponds to the XPath that a particular
-     * test is interested in.
-     */
-    void setCurrentNode(Object currentNode) {
-        this.currentNode = currentNode;
+    public Object remove(Object key) {
+        return attributes.remove(key);
+    }
+
+    public Object put(Object key, Object value) {
+        return attributes.put(key, value);
+    }
+
+    public Object get(Object key) {
+        return attributes.get(key);
+    }
+
+    public boolean containsKey(Object key) {
+        return attributes.containsKey(key);
+    }
+
+    public void addWarning( ValidationWarning warning ) {
+        warnings.addElement( warning );
+    }
+    
+    public void addFailure(ValidationFailure failure) {
+        failures.addElement( failure );
+    }
+
+    public void addError(ValidationError error) {
+        errors.addElement( error );
+    }
+
+    public ValidationFailure[] getFailures() {
+        ValidationFailure[] tmp = new ValidationFailure[failures.size()];
+        failures.copyInto( tmp );
+        return tmp;
+    }
+    
+    public ValidationWarning[] getWarnings() {
+        ValidationWarning[] tmp = new ValidationWarning[warnings.size()];
+        warnings.copyInto( tmp );
+        return tmp;
+    }
+    
+    public ValidationError[] getErrors() {
+        ValidationError[] tmp = new ValidationError[errors.size()];
+        errors.copyInto( tmp );
+        return tmp;
+    }
+
+    public boolean hasWarnings(){
+        return warnings.size() > 0;
+    }
+
+    public boolean hasFailures(){
+        return failures.size() > 0;
+    }
+    
+    public boolean hasErrors(){
+        return errors.size() > 0;
     }
 }

Added: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationError.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationError.java?view=auto&rev=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationError.java
(added)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationError.java
Tue Feb  1 12:52:06 2005
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.validator;
+
+public class ValidationError extends ValidationException {
+
+    public ValidationError(String message) {
+        super(message);
+    }
+
+    public String getPrefix() {
+        return "ERROR";
+    }
+
+    public String getCategory() {
+        return "errors";
+    }
+
+}

Modified: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationException.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationException.java?view=diff&r1=149446&r2=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationException.java
(original)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationException.java
Tue Feb  1 12:52:06 2005
@@ -14,33 +14,69 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.validator;
 
-/**
- * Used by the provided validation logic to indicate that a fatal error has
- * occured and the validation has failed.  Typically tests should not use this,
- * instead returning a ValidationResult to indicate an error.  This should only
- * be used when there's an urgent need to abort.
- *
- * It is a runtime exception because no user-provided validation code needs to
- * catch it; it will be trapped by the core validator implementation. 
- *
- * @version $Rev$ $Date$
- */
-public class ValidationException extends RuntimeException {
-    public ValidationException() {
+
+public class ValidationException extends java.lang.Exception {
+
+    protected static Messages messages = new Messages("");
+
+    protected Object[] details;
+    protected String message;
+
+    protected String prefix;
+
+
+    public ValidationException(String message) {
+        this.message = message;
     }
 
-    public ValidationException(Throwable cause) {
-        super(cause);
+    public void setDetails(Object arg1) {
+        this.details = new Object[]{arg1};
     }
 
-    public ValidationException(String message) {
-        super(message);
+    public void setDetails(Object arg1, Object arg2) {
+        this.details = new Object[]{arg1, arg2};
+    }
+
+    public void setDetails(Object arg1, Object arg2, Object arg3) {
+        this.details = new Object[]{arg1, arg2, arg3};
+    }
+
+    public void setDetails(Object arg1, Object arg2, Object arg3, Object arg4) {
+        this.details = new Object[]{arg1, arg2, arg3, arg4};
+    }
+
+    public void setDetails(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
{
+        this.details = new Object[]{arg1, arg2, arg3, arg4, arg5};
+    }
+
+    public void setDetails(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5,
Object arg6) {
+        this.details = new Object[]{arg1, arg2, arg3, arg4, arg5, arg6};
+    }
+
+    public Object[] getDetails() {
+        return details;
+    }
+
+    public String getSummary() {
+        return getMessage(1);
     }
 
-    public ValidationException(String message, Throwable cause) {
-        super(message, cause);
+    public String getMessage() {
+        return getMessage(2);
     }
+
+    public String getMessage(int level) {
+        return messages.format(level + "." + message, details);
+    }
+
+    public String getPrefix() {
+        return "";
+    }
+
+    public String getCategory() {
+        return "";
+    }
+
 }

Added: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationFailure.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationFailure.java?view=auto&rev=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationFailure.java
(added)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationFailure.java
Tue Feb  1 12:52:06 2005
@@ -0,0 +1,32 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.validator;
+
+public class ValidationFailure extends ValidationException {
+
+    public ValidationFailure(String message) {
+        super(message);
+    }
+
+    public String getPrefix() {
+        return "FAIL";
+    }
+
+    public String getCategory() {
+        return "failures";
+    }
+}

Added: geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationWarning.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationWarning.java?view=auto&rev=149447
==============================================================================
--- geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationWarning.java
(added)
+++ geronimo/trunk/modules/core/src/java/org/apache/geronimo/validator/ValidationWarning.java
Tue Feb  1 12:52:06 2005
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.validator;
+
+public class ValidationWarning extends ValidationException {
+
+    public ValidationWarning(String message) {
+        super(message);
+    }
+
+    public String getPrefix() {
+        return "WARN";
+    }
+
+    public String getCategory() {
+        return "warnings";
+    }
+
+
+}



Mime
View raw message