Coverage Report - org.apache.commons.betwixt.schema.SimpleLocalElement

Classes in this File Line Coverage Branch Coverage Complexity
SimpleLocalElement
70% 
80% 
1.375

 1  
 /*
 2  
  * Copyright 2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 
 17  
 package org.apache.commons.betwixt.schema;
 18  
 
 19  
 import java.beans.IntrospectionException;
 20  
 
 21  
 import org.apache.commons.betwixt.ElementDescriptor;
 22  
 
 23  
 /**
 24  
  * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a>
 25  
  * @version $Revision: 155402 $
 26  
  */
 27  
 public class SimpleLocalElement extends LocalElement {
 28  
     
 29  
     private String type;
 30  
     
 31  
     public SimpleLocalElement(String name, String type) {
 32  299
         super(name);
 33  299
         setType(type);
 34  299
     }
 35  
     
 36  
     public SimpleLocalElement(
 37  
                                 TranscriptionConfiguration configuration, 
 38  
                                 ElementDescriptor descriptor, 
 39  
                                 Schema schema) 
 40  
                                     throws IntrospectionException {
 41  715
         super(descriptor, schema);
 42  715
         setType(configuration.getDataTypeMapper().toXMLSchemaDataType(descriptor.getPropertyType()));
 43  715
     }
 44  
     
 45  
     public String getType() {
 46  1248
         return type;
 47  
     }
 48  
 
 49  
     public void setType(String string) {
 50  1014
         type = string;
 51  1014
     }
 52  
 
 53  
     public int hashCode() {
 54  715
         return getName().hashCode();
 55  
     }
 56  
     
 57  
     public boolean equals(Object obj) {
 58  2899
         boolean result = false;
 59  2899
         if (obj instanceof SimpleLocalElement) {
 60  2899
             SimpleLocalElement simpleLocalElement = (SimpleLocalElement) obj;
 61  2899
             result = 
 62  2899
                 isEqual(getName(), simpleLocalElement.getName()) &&
 63  416
                 isEqual(getType(), simpleLocalElement.getType());    
 64  
         }
 65  2899
         return result;
 66  
     }
 67  
     
 68  
     private boolean isEqual(String one, String two) {
 69  3315
         if (one == null) {
 70  0
            return (two == null); 
 71  
         }
 72  
         
 73  3315
         return one.equals(two);
 74  
     }
 75  
     
 76  
     public String toString() {
 77  0
         StringBuffer buffer = new StringBuffer();
 78  0
         buffer.append("<element name='");
 79  0
         buffer.append(getName());
 80  0
         buffer.append("' type='");
 81  0
         buffer.append(getType());
 82  0
         buffer.append("'/>"); 
 83  0
         return buffer.toString();
 84  
     }
 85  
 }