Android Open Source - BCC File Data Store Factory






From Project

Back to project page BCC.

License

The source code is released under:

MIT License

If you think the Android project BCC listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sdsu.bcc.file;
//  www.j  a va2s .c o m
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.bcc.R;
import android.app.Activity;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;

public class FileDataStoreFactory {
  private static FileDataStoreFactory m_store = null;
  private Map<String,ParserInfo> parserInfos = new HashMap<String,ParserInfo>();
  
  private FileDataStoreFactory(Activity activity) throws XmlPullParserException, IOException {
    parseFileMetaData(activity);
  }
  
  public static FileDataStoreFactory getFileStore(Activity activity) throws XmlPullParserException, IOException {
    if(m_store == null) {
      m_store = new FileDataStoreFactory(activity);
    }
    
    return m_store;
  }
  
  private void parseFileMetaData(Activity activity) throws XmlPullParserException, IOException {
    ParserInfo parserInfo = null;
    boolean isName = false;
    boolean isType = false;
    boolean isClassName = false;
    
    Resources res = activity.getResources();
    XmlResourceParser xpp = res.getXml(R.xml.filestoremetadata);
    xpp.next();
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      switch (eventType) {
        case XmlPullParser.START_DOCUMENT:
          break;
        case XmlPullParser.START_TAG:
          if ("FileStore".equals(xpp.getName())) {
            parserInfo = new ParserInfo();
          } else if ("Name".equals(xpp.getName())) {
            isName = true;
          }else if ("Type".equals(xpp.getName())) {
            isType = true;
          }else if ("ClassName".equals(xpp.getName())) {
            isClassName = true;
          }
          break;
        case XmlPullParser.END_TAG:
          if ("FileStore".equals(xpp.getName())) {
            this.parserInfos.put(parserInfo.getType(), parserInfo);
          } else if ("Name".equals(xpp.getName())) {
            isName = false;
          }else if ("Type".equals(xpp.getName())) {
            isType = false;
          }else if ("ClassName".equals(xpp.getName())) {
            isClassName = false;
          }
          break;
        case XmlPullParser.TEXT:
          if (isName) {
            parserInfo.setName(xpp.getText());
          } else if (isType) {
            parserInfo.setType(xpp.getText());
          } else if (isClassName) {
            parserInfo.setClassName(xpp.getText());
          }
          break;
      }
      eventType = xpp.next();
    }
  }
  
  public FileDataStoreOperations<?> getFileStore(String type, Activity activity) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    ParserInfo parserInfo = this.parserInfos.get(type);
    if(parserInfo == null) {
      throw new ClassNotFoundException("File Store of Type " + type + " is not available. Please check File Store Meta Data File.");
    }
    
    FileDataStoreOperations<?> fileStore = (FileDataStoreOperations<?>) Class.forName(parserInfo.getClassName()).newInstance();
    fileStore.setActivity(activity);
    
    return fileStore;
  }
  
  private static class ParserInfo {
    private String name = null;
    private String type = null;
    private String className = null;
    
    @SuppressWarnings("unused")
    public String getName() {
      return name;
    }
    public void setName(String name) {
      this.name = name;
    }
    public String getType() {
      return type;
    }
    public void setType(String type) {
      this.type = type;
    }
    public String getClassName() {
      return className;
    }
    public void setClassName(String className) {
      this.className = className;
      
    }
  }
}




Java Source Code List

com.bcc.AddBCCManage.java
com.bcc.AddBCC.java
com.bcc.BCCActivity.java
com.bcc.ImportExportBCC.java
com.bcc.ImportExportManage.java
com.bcc.OCRResult.java
com.bcc.SetPrefs.java
com.bcc.util.BCCUtil.java
com.bcc.util.Facade.java
com.bcc.util.adaptor.ManageBCCListAdaptor.java
com.bcc.util.adaptor.ManageListAdaptor.java
com.itwizard.mezzofanti.AssetsManager.java
com.itwizard.mezzofanti.CameraManager.java
com.itwizard.mezzofanti.CaptureLayout.java
com.itwizard.mezzofanti.CustomImageButton.java
com.itwizard.mezzofanti.DownloadManager.java
com.itwizard.mezzofanti.InstallActivity.java
com.itwizard.mezzofanti.Mezzofanti.java
com.itwizard.mezzofanti.OCR.java
com.itwizard.mezzofanti.OnScreenHint.java
com.sdsu.bcc.BCCConstants.java
com.sdsu.bcc.database.DatabaseImpl.java
com.sdsu.bcc.database.DatabaseOperation.java
com.sdsu.bcc.database.data.CardInformation.java
com.sdsu.bcc.database.data.CategoryInformation.java
com.sdsu.bcc.database.data.ContactInformation.java
com.sdsu.bcc.database.data.FilesInformation.java
com.sdsu.bcc.database.data.ImageInformation.java
com.sdsu.bcc.database.impl.BCCDataStore.java
com.sdsu.bcc.database.impl.CategoryDataStore.java
com.sdsu.bcc.database.impl.ContactDataStore.java
com.sdsu.bcc.database.impl.FilesDataStore.java
com.sdsu.bcc.database.impl.ImageDataStore.java
com.sdsu.bcc.file.FileDataStoreFactory.java
com.sdsu.bcc.file.FileDataStoreOperations.java
com.sdsu.bcc.file.impl.CSVDataStore.java