Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 86   Methods: 1
NCLOC: 35   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SetCollectionMeta.java 50% 82.4% 100% 75%
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: SetCollectionMeta.java 595817 2007-11-16 20:49:03Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.server.rpc.messages;
 21   
 22    import org.apache.xindice.core.Collection;
 23    import org.apache.xindice.core.meta.MetaData;
 24    import org.apache.xindice.server.rpc.RPCDefaultMessage;
 25    import org.apache.xindice.xml.TextWriter;
 26    import org.apache.xindice.xml.dom.DOMParser;
 27    import org.apache.xindice.xml.dom.DocumentImpl;
 28   
 29    import org.w3c.dom.Document;
 30   
 31    import java.util.Hashtable;
 32    import java.util.Map;
 33    import java.util.HashMap;
 34   
 35    /**
 36    * XML-RPC message to set the meta data associated with a collection
 37    *
 38    * @author <a href="mailto:dviner@apache.org">Dave Viner</a>
 39    * @version $Revision: 595817 $, $Date: 2007-11-16 20:49:03 +0000 (Fri, 16 Nov 2007) $
 40    */
 41    public class SetCollectionMeta extends RPCDefaultMessage {
 42   
 43    /**
 44    * Set the MetaData object for the requested collection.
 45    *
 46    * This method expects the Map to contain the name of the collection
 47    * in the RPCDefaultMessage.COLLECTION key, and the XML for the new MetaData
 48    * object in the RPCDefaultMessage.META key. It will return an XML
 49    * representation of the MetaData object associated with this collection.
 50    * The XML will be stored in the RPCDefaultMessage.RESULT key.
 51    *
 52    * @param message the parameters passed to the xmlrpc method.
 53    * @return Map containing XML of the newly created MetaData object.
 54    */
 55  2 public Map execute(Map message) throws Exception {
 56   
 57  2 if (!message.containsKey(COLLECTION)) {
 58  0 throw new Exception(MISSING_COLLECTION_PARAM);
 59    }
 60   
 61  2 if (!message.containsKey(META)) {
 62  0 throw new Exception(MISSING_META_PARAM);
 63    }
 64   
 65  2 Collection col = getCollection((String) message.get(COLLECTION));
 66  2 if (!col.isMetaEnabled()) {
 67    // meta information is not enabled !
 68  0 throw new Exception(MISSING_META_CONFIGURATION);
 69    }
 70   
 71    // Read and store sent meta data
 72  2 MetaData meta = new MetaData();
 73  2 Document doc = DOMParser.toDocument((String) message.get(META));
 74  2 meta.streamFromXML(doc.getDocumentElement());
 75  2 col.setCollectionMeta(meta);
 76   
 77    // Retreive stored meta data and sent back
 78  2 meta = col.getCollectionMeta();
 79  2 doc = new DocumentImpl();
 80  2 doc.appendChild(meta.streamToXML(doc, true));
 81   
 82  2 Map result = new HashMap(3);
 83  2 result.put(RESULT, TextWriter.toString(doc));
 84  2 return result;
 85    }
 86    }