Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 125   Methods: 6
NCLOC: 62   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ResourceTypeReader.java 58.3% 63.6% 50% 60%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: ResourceTypeReader.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.core.meta.inline;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.xindice.core.FaultCodes;
 25    import org.apache.xindice.core.data.Value;
 26   
 27    /**
 28    *
 29    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 30    */
 31    public class ResourceTypeReader implements InlineMetaReader {
 32   
 33    private static final Log log = LogFactory.getLog(ResourceTypeReader.class);
 34   
 35    public static final Integer XML = new Integer(1);
 36    public static final Integer BINARY = new Integer(2);
 37   
 38   
 39    /**
 40    * @see org.apache.xindice.core.meta.inline.InlineMetaReader#getVersion()
 41    */
 42  0 public int getVersion() {
 43  0 return 1;
 44    }
 45   
 46    /**
 47    * @see org.apache.xindice.core.meta.inline.InlineMetaReader#read(Value)
 48    */
 49  34455 public InlineMetaMap read(Value data) throws InlineMetaException {
 50  34455 if (log.isDebugEnabled()) {
 51  0 log.debug("ResourceTypeReader.read: data length=" + data.getLength());
 52    }
 53   
 54  34455 if (data.getLength() != 1) {
 55  0 throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED,
 56    "Expecting header length of 1");
 57    }
 58   
 59  34455 Integer type;
 60  34455 type = new Integer(data.byteAt(0));
 61   
 62  34455 if (!XML.equals(type) && !BINARY.equals(type)) {
 63  1 throw new InlineMetaException(FaultCodes.COL_DOCUMENT_MALFORMED,
 64    "Unexpected type value: " + type);
 65    }
 66   
 67  34454 ResourceTypeMap resourceTypeMap = new ResourceTypeMap();
 68  34454 resourceTypeMap.put("type", type);
 69  34454 return resourceTypeMap;
 70    }
 71   
 72    /**
 73    * A simple and efficient Map implementation that holds
 74    * the attributes available from a ResourceType header.
 75    */
 76    public static class ResourceTypeMap implements InlineMetaMap {
 77   
 78    private static String[] keys = new String[]{"type"};
 79   
 80    private Integer type;
 81   
 82    /**
 83    * @see org.apache.xindice.core.meta.inline.InlineMetaMap#containsKey(String)
 84    */
 85  0 public boolean containsKey(String key) {
 86  0 return "type".equals(key);
 87    }
 88   
 89    /**
 90    * @see org.apache.xindice.core.meta.inline.InlineMetaMap#get(String)
 91    */
 92  36437 public Object get(String key) throws InlineMetaException {
 93  36437 if ("type".equals(key)) {
 94  36437 return type;
 95    } else {
 96  0 throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
 97    "ResourceTypeMap does not accept key '" + key + "'");
 98    }
 99    }
 100   
 101    /**
 102    * @see org.apache.xindice.core.meta.inline.InlineMetaMap#keys()
 103    */
 104  0 public String[] keys() {
 105  0 return keys;
 106    }
 107   
 108    /**
 109    * @see org.apache.xindice.core.meta.inline.InlineMetaMap#put(String, Object)
 110    */
 111  36437 public void put(String key, Object value) throws InlineMetaException {
 112  36437 if ("type".equals(key)) {
 113  36437 if (value instanceof Integer) {
 114  36437 type = (Integer) value;
 115    } else {
 116  0 throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
 117    "ResourceTypeMap key 'type' requires an Integer value");
 118    }
 119    } else {
 120  0 throw new InlineMetaException(FaultCodes.GEN_CRITICAL_ERROR,
 121    "ResourceTypeMap does not accept key '" + key + "'");
 122    }
 123    }
 124    }
 125    }