Home | History | Annotate | Download | only in dexlib
      1 /*
      2  * [The "BSD licence"]
      3  * Copyright (c) 2010 Ben Gruver (JesusFreke)
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 package org.jf.dexlib;
     30 
     31 class ItemFactory {
     32     protected static Item makeItem(ItemType itemType, DexFile dexFile) {
     33         switch (itemType) {
     34             case TYPE_STRING_ID_ITEM:
     35                 return new StringIdItem(dexFile);
     36             case TYPE_TYPE_ID_ITEM:
     37                 return new TypeIdItem(dexFile);
     38             case TYPE_PROTO_ID_ITEM:
     39                 return new ProtoIdItem(dexFile);
     40             case TYPE_FIELD_ID_ITEM:
     41                 return new FieldIdItem(dexFile);
     42             case TYPE_METHOD_ID_ITEM:
     43                 return new MethodIdItem(dexFile);
     44             case TYPE_CLASS_DEF_ITEM:
     45                 return new ClassDefItem(dexFile);
     46             case TYPE_TYPE_LIST:
     47                 return new TypeListItem(dexFile);
     48             case TYPE_ANNOTATION_SET_REF_LIST:
     49                 return new AnnotationSetRefList(dexFile);
     50             case TYPE_ANNOTATION_SET_ITEM:
     51                 return new AnnotationSetItem(dexFile);
     52             case TYPE_CLASS_DATA_ITEM:
     53                 return new ClassDataItem(dexFile);
     54             case TYPE_CODE_ITEM:
     55                 return new CodeItem(dexFile);
     56             case TYPE_STRING_DATA_ITEM:
     57                 return new StringDataItem(dexFile);
     58             case TYPE_DEBUG_INFO_ITEM:
     59                 return new DebugInfoItem(dexFile);
     60             case TYPE_ANNOTATION_ITEM:
     61                 return new AnnotationItem(dexFile);
     62             case TYPE_ENCODED_ARRAY_ITEM:
     63                 return new EncodedArrayItem(dexFile);
     64             case TYPE_ANNOTATIONS_DIRECTORY_ITEM:
     65                 return new AnnotationDirectoryItem(dexFile);
     66             default:
     67                 assert false;
     68         }
     69         return null;
     70     }
     71 }
     72