[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jibx-cvs
Subject:    [Jibx-cvs] core/build/src/org/jibx/schema/validation
From:       Dennis Sosnoski <dsosnoski () users ! sourceforge ! net>
Date:       2010-01-20 11:17:53
Message-ID: E1NXYZN-00034r-ID () sfp-cvsdas-3 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Update of /cvsroot/jibx/core/build/src/org/jibx/schema/validation
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv11828/build/src/org/jibx/schema/validation


Modified Files:
	ValidationContext.java 
Log Message:
Add reportProblems() method used in several places, reformat.

Index: ValidationContext.java
===================================================================
RCS file: /cvsroot/jibx/core/build/src/org/jibx/schema/validation/ValidationContext.java,v
 retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ValidationContext.java	30 Mar 2009 11:20:00 -0000	1.6
--- ValidationContext.java	20 Jan 2010 11:17:51 -0000	1.7
***************
*** 1,27 ****
  /*
!  * Copyright (c) 2006-2009, Dennis M. Sosnoski. All rights reserved.
   * 
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
   * 
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer. Redistributions in binary
!  * form must reproduce the above copyright notice, this list of conditions and
!  * the following disclaimer in the documentation and/or other materials provided
!  * with the distribution. Neither the name of JiBX nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
   * 
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
!  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
!  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
!  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
!  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
!  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
!  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
!  * POSSIBILITY OF SUCH DAMAGE.
   */
  
--- 1,21 ----
  /*
!  * Copyright (c) 2006-2010, Dennis M. Sosnoski. All rights reserved.
   * 
!  * Redistribution and use in source and binary forms, with or without modification, \
                are permitted provided that the
!  * following conditions are met:
   * 
!  * Redistributions of source code must retain the above copyright notice, this list \
                of conditions and the following
!  * disclaimer. Redistributions in binary form must reproduce the above copyright \
                notice, this list of conditions and the
!  * following disclaimer in the documentation and/or other materials provided with \
                the distribution. Neither the name of
!  * JiBX nor the names of its contributors may be used to endorse or promote \
                products derived from this software without
!  * specific prior written permission.
   * 
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND \
                ANY EXPRESS OR IMPLIED WARRANTIES,
!  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND \
                FITNESS FOR A PARTICULAR PURPOSE ARE
!  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR \
                ANY DIRECT, INDIRECT, INCIDENTAL,
!  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \
                PROCUREMENT OF SUBSTITUTE GOODS OR
!  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER \
                CAUSED AND ON ANY THEORY OF LIABILITY,
!  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \
                OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
!  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   */
  
***************
*** 35,38 ****
--- 29,33 ----
  import java.util.Set;
  
+ import org.apache.log4j.Logger;
  import org.jibx.runtime.QName;
  import org.jibx.schema.ISkipElements;
***************
*** 48,63 ****
  
  /**
!  * Tracks the schema validation state. This includes order-dependent state
!  * information collected while walking the tree structure of a schema model.
!  * Collects all errors and warnings and maintains a summary of the severity of
!  * the problems found. For ease of use, this also wraps the schema name register
!  * with convenience methods for validation.
   * TODO: separate out a generalized base class and move the base out of the schema \
                package
   * 
   * @author Dennis M. Sosnoski
   */
! public class ValidationContext extends SchemaContextTracker
! implements ISkipElements
  {
      /** Map from identifier to schema. */
      private Map m_idSchemaMap;
--- 43,59 ----
  
  /**
!  * Tracks the schema validation state. This includes order-dependent state \
                information collected while walking the tree
!  * structure of a schema model. Collects all errors and warnings and maintains a \
                summary of the severity of the problems
!  * found. For ease of use, this also wraps the schema name register with \
                convenience methods for validation.
!  * 
   * TODO: separate out a generalized base class and move the base out of the schema \
                package
   * 
   * @author Dennis M. Sosnoski
   */
! public class ValidationContext extends SchemaContextTracker implements \
ISkipElements  {
+     /** Logger for class. */
+     private static final Logger s_logger = \
Logger.getLogger(ValidationContext.class.getName()); +     
      /** Map from identifier to schema. */
      private Map m_idSchemaMap;
***************
*** 109,118 ****
      
      /**
!      * Get schema element by target namespace. The target namespace must be
!      * unique.
!      *
       * @param uri unique namespace URI
!      * @return schema, or <code>null</code> if not loaded or non-unique
!      * namespace
       */
      public SchemaElement getSchemaByNamespace(String uri) {
--- 105,112 ----
      
      /**
!      * Get schema element by target namespace. The target namespace must be unique.
!      * 
       * @param uri unique namespace URI
!      * @return schema, or <code>null</code> if not loaded or non-unique namespace
       */
      public SchemaElement getSchemaByNamespace(String uri) {
***************
*** 121,127 ****
      
      /**
!      * Get schema element by identifier. This uses the unique schema identifier
!      * to locate a loaded schema instance.
!      *
       * @param id
       * @return schema, or <code>null</code> if not loaded
--- 115,120 ----
      
      /**
!      * Get schema element by identifier. This uses the unique schema identifier to \
                locate a loaded schema instance.
!      * 
       * @param id
       * @return schema, or <code>null</code> if not loaded
***************
*** 133,137 ****
      /**
       * Get iterator for all schemas defined in this context.
!      *
       * @return iterator
       */
--- 126,130 ----
      /**
       * Get iterator for all schemas defined in this context.
!      * 
       * @return iterator
       */
***************
*** 141,147 ****
      
      /**
!      * Add schema element with identifier.
!      * TODO: is the namespace handling sufficient?
!      *
       * @param id
       * @param schema
--- 134,139 ----
      
      /**
!      * Add schema element with identifier. TODO: is the namespace handling \
                sufficient?
!      * 
       * @param id
       * @param schema
***************
*** 163,167 ****
      /**
       * Get the number of schemas processed by this context.
!      *
       * @return count
       */
--- 155,159 ----
      /**
       * Get the number of schemas processed by this context.
!      * 
       * @return count
       */
***************
*** 207,212 ****
      
      /**
!      * Register global attribute in the current schema definition. If the name
!      * has already been registered this creates an error for the new definition.
       * 
       * @param qname name
--- 199,204 ----
      
      /**
!      * Register global attribute in the current schema definition. If the name has \
                already been registered this creates
!      * an error for the new definition.
       * 
       * @param qname name
***************
*** 221,227 ****
      
      /**
!      * Register global attribute group in the current schema definition. If the
!      * name has already been registered this creates an error for the new
!      * definition.
       * 
       * @param qname name
--- 213,218 ----
      
      /**
!      * Register global attribute group in the current schema definition. If the \
                name has already been registered this
!      * creates an error for the new definition.
       * 
       * @param qname name
***************
*** 229,234 ****
       */
      public void registerAttributeGroup(QName qname, AttributeGroupElement def) {
!         AttributeGroupElement dupl =
!             m_nameRegister.registerAttributeGroup(qname, def);
          if (dupl != null) {
              addError("Duplicate name " + qname, def);
--- 220,224 ----
       */
      public void registerAttributeGroup(QName qname, AttributeGroupElement def) {
!         AttributeGroupElement dupl = m_nameRegister.registerAttributeGroup(qname, \
def);  if (dupl != null) {
              addError("Duplicate name " + qname, def);
***************
*** 237,242 ****
      
      /**
!      * Register global element in the current schema definition. If the name has
!      * already been registered this creates an error for the new definition.
       * 
       * @param qname name
--- 227,232 ----
      
      /**
!      * Register global element in the current schema definition. If the name has \
                already been registered this creates an
!      * error for the new definition.
       * 
       * @param qname name
***************
*** 244,250 ****
       */
      public void registerElement(QName qname, ElementElement def) {
!         ElementElement dupl =
!             (ElementElement)m_nameRegister.registerElement(qname, def);
!         if (dupl != null)  {
              addError("Duplicate name " + qname, def);
          }
--- 234,239 ----
       */
      public void registerElement(QName qname, ElementElement def) {
!         ElementElement dupl = m_nameRegister.registerElement(qname, def);
!         if (dupl != null) {
              addError("Duplicate name " + qname, def);
          }
***************
*** 252,257 ****
      
      /**
!      * Register global group in the current schema definition. If the name has
!      * already been registered this creates an error for the new definition.
       * 
       * @param qname name
--- 241,246 ----
      
      /**
!      * Register global group in the current schema definition. If the name has \
                already been registered this creates an
!      * error for the new definition.
       * 
       * @param qname name
***************
*** 259,265 ****
       */
      public void registerGroup(QName qname, GroupElement def) {
!         GroupElement dupl =
!             (GroupElement)m_nameRegister.registerGroup(qname, def);
!         if (dupl != null)  {
              addError("Duplicate name " + qname, def);
          }
--- 248,253 ----
       */
      public void registerGroup(QName qname, GroupElement def) {
!         GroupElement dupl = m_nameRegister.registerGroup(qname, def);
!         if (dupl != null) {
              addError("Duplicate name " + qname, def);
          }
***************
*** 267,272 ****
      
      /**
!      * Register global type in the current schema definition. If the name has
!      * already been registered this creates an error for the new definition.
       * 
       * @param qname name
--- 255,260 ----
      
      /**
!      * Register global type in the current schema definition. If the name has \
                already been registered this creates an
!      * error for the new definition.
       * 
       * @param qname name
***************
*** 274,279 ****
       */
      public void registerType(QName qname, CommonTypeDefinition def) {
!         CommonTypeDefinition dupl =
!             (CommonTypeDefinition)m_nameRegister.registerType(qname, def);
          if (dupl != null) {
              addError("Duplicate name " + qname, def);
--- 262,266 ----
       */
      public void registerType(QName qname, CommonTypeDefinition def) {
!         CommonTypeDefinition dupl = m_nameRegister.registerType(qname, def);
          if (dupl != null) {
              addError("Duplicate name " + qname, def);
***************
*** 332,338 ****
      
      /**
!      * Add unimplemented feature item for current element. Adds an unimplemented
!      * feature item to the problem list, reporting a schema feature which is not
!      * supported but does not prevent allows reasonable operation.
       * 
       * @param msg problem description
--- 319,324 ----
      
      /**
!      * Add unimplemented feature item for current element. Adds an unimplemented \
                feature item to the problem list,
!      * reporting a schema feature which is not supported but does not prevent \
                allows reasonable operation.
       * 
       * @param msg problem description
***************
*** 340,350 ****
       */
      public void addUnimplemented(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.UNIMPLEMENTED_LEVEL,
!             msg, obj));
      }
      
      /**
!      * Add warning item. Adds a warning item to the problem list, which is a
!      * possible problem that still allows reasonable operation.
       * 
       * @param msg problem description
--- 326,335 ----
       */
      public void addUnimplemented(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.UNIMPLEMENTED_LEVEL, \
msg, obj));  }
      
      /**
!      * Add warning item. Adds a warning item to the problem list, which is a \
                possible problem that still allows
!      * reasonable operation.
       * 
       * @param msg problem description
***************
*** 352,378 ****
       */
      public void addWarning(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.WARNING_LEVEL, msg,
!             obj));
      }
      
      /**
!      * Add error item. Adds an error item to the problem list, which is a
!      * definite problem that still allows validation to proceed.
       * 
       * @param msg problem description
       * @param obj source object for validation error
!      * @return <code>true</code> if to continue validation, <code>false</code>
!      * if not
       */
      public boolean addError(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.ERROR_LEVEL, msg,
!             obj));
          return true;
      }
      
      /**
!      * Add fatal item. Adds a fatal item to the problem list, which is a severe
!      * problem that blocks further validation within the tree branch involved.
!      * The object associated with a fatal error should always be an element.
       * 
       * @param msg problem description
--- 337,359 ----
       */
      public void addWarning(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.WARNING_LEVEL, msg, \
obj));  }
      
      /**
!      * Add error item. Adds an error item to the problem list, which is a definite \
                problem that still allows validation
!      * to proceed.
       * 
       * @param msg problem description
       * @param obj source object for validation error
!      * @return <code>true</code> if to continue validation, <code>false</code> if \
                not
       */
      public boolean addError(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.ERROR_LEVEL, msg, obj));
          return true;
      }
      
      /**
!      * Add fatal item. Adds a fatal item to the problem list, which is a severe \
                problem that blocks further validation
!      * within the tree branch involved. The object associated with a fatal error \
                should always be an element.
       * 
       * @param msg problem description
***************
*** 380,385 ****
       */
      public void addFatal(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.FATAL_LEVEL, msg,
!             obj));
      }
      
--- 361,365 ----
       */
      public void addFatal(String msg, Object obj) {
!         addProblem(new ValidationProblem(ValidationProblem.FATAL_LEVEL, msg, obj));
      }
      
***************
*** 391,413 ****
      public void addProblem(ValidationProblem problem) {
          m_problemList.add(problem);
!         switch (problem.getSeverity()) {
! 
              case ValidationProblem.ERROR_LEVEL:
                  m_errorCount++;
                  break;
! 
              case ValidationProblem.FATAL_LEVEL:
                  m_fatalCount++;
                  addSkip(problem.getComponent());
                  break;
! 
              case ValidationProblem.UNIMPLEMENTED_LEVEL:
                  m_unimplementedCount++;
                  break;
! 
              case ValidationProblem.WARNING_LEVEL:
                  m_warningCount++;
                  break;
! 
          }
      }
--- 371,394 ----
      public void addProblem(ValidationProblem problem) {
          m_problemList.add(problem);
!         switch (problem.getSeverity())
!         {
!             
              case ValidationProblem.ERROR_LEVEL:
                  m_errorCount++;
                  break;
!             
              case ValidationProblem.FATAL_LEVEL:
                  m_fatalCount++;
                  addSkip(problem.getComponent());
                  break;
!             
              case ValidationProblem.UNIMPLEMENTED_LEVEL:
                  m_unimplementedCount++;
                  break;
!             
              case ValidationProblem.WARNING_LEVEL:
                  m_warningCount++;
                  break;
!             
          }
      }
***************
*** 433,440 ****
      }
      
      //
      // ISkipElements implementation
! 
!     /* (non-Javadoc)
       * @see org.jibx.schema.ISkipElements#isSkipped(java.lang.Object)
       */
--- 414,451 ----
      }
      
+     /**
+      * Report problems using console output. This clears the problem list after \
they've been reported, to avoid multiple +      * reports of the same problems.
+      * 
+      * @return <code>true</code> if one or more errors, <code>false</code> if not
+      */
+     public boolean reportProblems() {
+         ArrayList probs = getProblems();
+         boolean error = false;
+         if (probs.size() > 0) {
+             for (int j = 0; j < probs.size(); j++) {
+                 ValidationProblem prob = (ValidationProblem)probs.get(j);
+                 String text;
+                 if (prob.getSeverity() >= ValidationProblem.ERROR_LEVEL) {
+                     error = true;
+                     text = "Error: " + prob.getDescription();
+                     s_logger.error(text);
+                 } else {
+                     text = "Warning: " + prob.getDescription();
+                     s_logger.info(text);
+                 }
+                 System.out.println(text);
+             }
+         }
+         probs.clear();
+         return error;
+     }
+     
      //
      // ISkipElements implementation
!     
!     /*
!      * (non-Javadoc)
!      * 
       * @see org.jibx.schema.ISkipElements#isSkipped(java.lang.Object)
       */


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Jibx-cvs mailing list
Jibx-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic