View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.ole.module.purap.util;
17  
18  import org.apache.struts.upload.FormFile;
19  import org.kuali.ole.module.purap.businessobject.PurApItem;
20  
21  import java.util.List;
22  
23  /**
24   * Defines an abstraction for parsing serialized <code>PurApItem</code> lines.
25   */
26  public interface ItemParser {
27  
28      /**
29       * Returns the defined format of item lines in the item import file.
30       *
31       * @return the item line format as an array of item property names
32       */
33      public String[] getItemFormat();
34  
35      /**
36       * Returns the expected format of the items to be imported.
37       *
38       * @param itemClass the class of the items to be imported
39       * @return the concatenation of the actual property names of the items to be imported
40       */
41      public String getExpectedItemFormatAsString(Class<? extends PurApItem> itemClass);
42  
43      /**
44       * Parses the specified item line into an instance of the specified PurApItem subclass.
45       *
46       * @param itemLine       the item line string to be parsed
47       * @param itemClass      the subclass of the item to be generated
48       * @param documentNumber the number of the docment that contains the item to be generated
49       * @return the generated item
50       */
51      public PurApItem parseItem(String itemLine, Class<? extends PurApItem> itemClass, String documentNumber);
52  
53      /**
54       * Parses the items from the specified import file line by line,
55       * and generates items of the specified type from the parsed data.
56       *
57       * @param itemFile       the input file from which items are parsed
58       * @param itemClass      a subclass of PurApItem, of which new items shall be generated
59       * @param documentNumber the number of the docment that contains the items to be imported
60       * @return a list of items of a subclass of PurApItem.
61       */
62      public List<PurApItem> importItems(FormFile itemFile, Class<? extends PurApItem> itemClass, String documentNumber);
63  
64  /****    
65   *
66   */
67      /**
68       * Reads lines of <code>PurApItem</code> fields from the <code>InputStream</code> and parses them.
69       *
70       * @param inputStream The <code>{@link InputStream}</code> to read data from.
71       * @param itemClass The subclass of <code>PurApItem</code> which parsed items belong to.
72       * @return A list of <code>{@link PurApItem}</code> instances.
73       * @exception IOException
74       *
75      public List importItemLines(InputStream inputStream, Class<? extends PurApItem> itemClass)
76      throws IOException, IllegalAccessException, InstantiationException;
77  
78      /**
79       * Determines the number of fields to be parsed.
80       *
81       * @return int number of fields expected.
82       *
83      public int getExpectedFieldCount();
84  
85       ****/
86  }
87