Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 77   Methods: 3
NCLOC: 53   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
RedefineJob.java 62,5% 88,5% 66,7% 81,1%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.schema.reader;
 11   
 
 12   
 import java.net.URL;
 13   
 import java.util.Iterator;
 14   
 
 15   
 import org.jbind.xml.base.Ref;
 16   
 import org.jbind.xml.msg.IConstraintViolations;
 17   
 import org.jbind.xml.msg.XmlException;
 18   
 import org.jbind.xml.msg.XmlMessages;
 19   
 import org.jbind.xml.schema.element.IRedefinable;
 20   
 import org.jbind.xml.schema.instantiation.IRedefineJobHelper;
 21   
 import org.jbind.xml.schema.instantiation.ISchemaElement;
 22   
 import org.jbind.xml.schema.instantiation.ITopLevelElement;
 23   
 
 24   
 public class RedefineJob extends SourceJob {
 25   
 
 26  10
   public RedefineJob(IRedefineJobHelper aHelper, ISchemaElement aSchemaElement) {
 27  10
     super(aHelper, aSchemaElement);
 28   
   }
 29   
 
 30  10
   protected void doExecuteCreation(IConstraintViolations aViolations) {
 31  10
     IRedefineJobHelper helper = (IRedefineJobHelper)getHelper();
 32   
 
 33  10
     try {
 34  10
       URL url = getUrl();
 35   
 
 36  10
       if (!getInstantiator().hasBeenParsed(url)) {
 37  10
         ISchemaElement schemaElement = getInstantiator().parseSchema(url, getSchemaElement());
 38   
 
 39  10
         for (Iterator i = helper.iterRedefinables(); i.hasNext(); ) {
 40  14
           IRedefinable redefinable = (IRedefinable)i.next();
 41   
           // Get and remove the element that is to be redefined.
 42  14
           ITopLevelElement referencedElement = schemaElement.removeTopLevelElement(redefinable.getGlobalRef());
 43  14
           if (null != referencedElement) {
 44   
             // Add the redefining element
 45  14
             schemaElement.setTopLevelElement(redefinable);
 46  14
             String newNameBase = "_redefined." + redefinable.getGlobalRef().getLocalPart();
 47  14
             int cnt = 0;
 48  14
             while (true) {
 49  14
               String newName = newNameBase + ((cnt == 0) ? "" : "" + cnt++);
 50  14
               Ref r = new Ref(redefinable.getGlobalRef().getNamespace(), redefinable.getGlobalRef().getSymbolSpace(), newName);
 51  14
               if (null == schemaElement.getTopLevelElement(r)) {
 52  14
                 referencedElement.setName(newName);
 53  14
                 schemaElement.setTopLevelElement(referencedElement);
 54  14
                 break;
 55   
               }
 56   
             }
 57  14
             redefinable.setRedefinedRef(referencedElement.getGlobalRef());
 58  14
             redefinable.redefine(referencedElement, aViolations);
 59   
           } else {
 60  0
             aViolations.add(XmlMessages.unknownElementForRedefinition(redefinable.getGlobalRef(), redefinable));
 61   
           }
 62   
 
 63   
         }
 64   
 
 65  10
         getInstantiator().add(new SchemaJob(getInstantiator(), schemaElement, url));
 66   
       }
 67   
     } catch (XmlException e) {
 68  0
       aViolations.add(e.getXmlMessage());
 69   
     }
 70   
 
 71   
   }
 72   
 
 73  0
   public String getDescription() {
 74  0
     return "redefineJob for: " + getLocation();
 75   
   }
 76   
 }
 77