Package net.sf.cannagrower.data

Source Code of net.sf.cannagrower.data.Resources

package net.sf.cannagrower.data;

import java.util.Vector;
import de.schlichtherle.io.File;
import java.io.IOException;

import net.sf.orexio.lopf.Data;
import net.sf.orexio.lopf.DataSource;
import net.sf.orexio.lopf.container.ContainerVector;
import net.sf.orexio.lopf.repository.TrueZipRepository;

import net.sf.cannagrower.CannaGrower;
import net.sf.cannagrower.i18n.Messages;

public class Resources extends DataSource<File>{
  private static final long   serialVersionUID = 1L;
    //private ContainerVector     produits??;
    private ContainerVector       varieties;

    private static Resources   resources;
   
    private static DataFactory   varietiesFactory=new VarietiesFactory();

    public static Resources getResources(){
            if(resources==null){
                try{
                    resources=open();
                }catch(IOException e){
                    Messages.showException(e);
                }catch(ClassNotFoundException e){
                    Messages.showException(e);
                }finally{
                  resources.setNew(false);
                    resources.setModified(false);
                }
            }
            return resources;
    }
   
    public static DataFactory getVarietiesFactory(){return varietiesFactory;}
   
    public ContainerVector getVarieties(){
    Variety         variety;

    if(varieties.isEmpty()){
      boolean  status=isModified();
     
      // TODO VARIETIES / Add here new variety type
      // TODO to_v0.2.0_Beta:  Add basic variety with real value
      variety=new Variety();
      variety.setName("Big Bud");
      varieties.store(variety);

      variety=new Variety();
      variety.setName("Northern Lights");
      varieties.store(variety);
     
      variety=new Variety();
      variety.setName("Skunk");
      varieties.store(variety);
     
      variety=new Variety();
      variety.setName("Top 44");
      varieties.store(variety);
     
      variety=new Variety();
      variety.setName("White Widow");
      varieties.store(variety);
     
      setModified(status);
    }
      return varieties;
    }
    private static Resources open()throws IOException,ClassNotFoundException{
      TrueZipRepository     repository;
      String              folder=CannaGrower.getCannaGrowerFolder().getPath();

    if(!folder.endsWith(System.getProperty("file.separator"))){folder+=System.getProperty("file.separator");}
      repository=new TrueZipRepository(new File(folder+CannaGrower.class.getSimpleName()+"."+Resources.class.getSimpleName()+".jar"));
    repository.open();
    repository.read();
    return new Resources(repository);
  }
   


    protected Vector<ContainerVector> addContainerVectors() throws IOException,ClassNotFoundException{
      Vector<ContainerVector> ghostVectors=new Vector<ContainerVector>();
   
      varieties=new ContainerVector(this,repository,null,Variety.class);
   
    ghostVectors.add(varieties);
   
    return ghostVectors;
    }


  private Resources(TrueZipRepository repository)throws IOException,ClassNotFoundException{
    super(repository);
  }
}

class VarietiesFactory implements DataFactory{
  public Data create(){return new Variety();}
}
TOP

Related Classes of net.sf.cannagrower.data.Resources

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.