Clover coverage report - Code Coverage for hivemind release 1.1-alpha-1
Coverage timestamp: Tue Jan 18 2005 07:55:08 EST
file stats: LOC: 94   Methods: 6
NCLOC: 48   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
CreateObjectRule.java - 91.7% 100% 94.4%
coverage coverage
 1   
 // Copyright 2004, 2005 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.schema.rules;
 16   
 
 17   
 import org.apache.hivemind.ApplicationRuntimeException;
 18   
 import org.apache.hivemind.ClassResolver;
 19   
 import org.apache.hivemind.Element;
 20   
 import org.apache.hivemind.HiveMind;
 21   
 import org.apache.hivemind.schema.SchemaProcessor;
 22   
 
 23   
 /**
 24   
  * Basic {@link org.apache.hivemind.schema.Rule} for creating
 25   
  * a new object.   Created from the
 26   
  * the <code>&lt;create-object&gt;</code> element.  Generally, this
 27   
  * is the first rule in a sequence of rules.
 28   
  *
 29   
  * @author Howard Lewis Ship
 30   
  */
 31   
 public class CreateObjectRule extends BaseRule
 32   
 {
 33   
     private String _className;
 34   
 
 35  3228
     public CreateObjectRule()
 36   
     {
 37   
     }
 38   
 
 39  441
     public CreateObjectRule(String className)
 40   
     {
 41  441
         _className = className;
 42   
     }
 43   
 
 44   
     /**
 45   
      * Creates the new object and pushes it onto the processor's stack.  If the
 46   
      * object implement {@link LocationHolder} then
 47   
      * the {@link org.apache.hivemind.Location} of the element is assigned
 48   
      * to the object.
 49   
      */
 50  4712
     public void begin(SchemaProcessor processor, Element element)
 51   
     {
 52  4712
         ClassResolver resolver = processor.getContributingModule().getClassResolver();
 53  4712
         Object object = null;
 54   
 
 55  4712
         try
 56   
         {
 57  4712
             Class objectClass = resolver.findClass(_className);
 58   
 
 59  4712
             object = objectClass.newInstance();
 60   
 
 61   
         }
 62   
         catch (Exception ex)
 63   
         {
 64  0
             throw new ApplicationRuntimeException(
 65   
                 RulesMessages.errorCreatingObject(_className, getLocation(), ex),
 66   
                 getLocation(),
 67   
                 ex);
 68   
         }
 69   
 
 70  4712
         HiveMind.setLocation(object, element.getLocation());
 71   
 
 72  4712
         processor.push(object);
 73   
     }
 74   
 
 75   
     /**
 76   
      * Pops the object off of the processor's stack.
 77   
      */
 78  4711
     public void end(SchemaProcessor processor, Element element)
 79   
     {
 80  4711
         processor.pop();
 81   
     }
 82   
 
 83  82
     public String getClassName()
 84   
     {
 85  82
         return _className;
 86   
     }
 87   
 
 88  3228
     public void setClassName(String string)
 89   
     {
 90  3228
         _className = string;
 91   
     }
 92   
 
 93   
 }
 94