<%@ page contentType="text/html"
		import="olstore.entity.*"
        import="olstore.framework.EJBHomeFactory"
        import="java.util.Collection"
         %>

<%-- Get the home Type --%>
<%
    EJBHomeFactory factory = EJBHomeFactory.getInstance();
%>

<h2> Populating Types</h2>
<p> Connecting to TypeLocalHome</p>
<%
    TypeLocalHome home = (TypeLocalHome)factory.getLocalHome (EJBHomeFactory.TYPE);
    PropertyLocalHome propHome= (PropertyLocalHome)factory.getLocalHome (EJBHomeFactory.PROP);
%>

<p> Adding new types to the database</p>
<%
    if ( true ) {
        //if statement just for scope
        TypeLocal type = null ;
        try {
            type = home.findByName ( "Computer" );
    %>      <p> type EXISTS! moving on </p> <%
        } catch (Exception e) {
    %>      <p> Type does not exist, creating it </p> <%
        } 

        if ( type == null ) {
            type = home.create("Computer");
            Collection props = type.getProperties();
            props.add ( propHome.create ( "CPU Speed", null ) );
            props.add ( propHome.create ( "Harddrive Size", null ) );
            props.add ( propHome.create ( "Memory", null ) );
            props.add ( propHome.create ( "CD-ROM", null ) );
            props.add ( propHome.create ( "Motherboard", null ) );
            type.setProperties ( props );
        }
    }

    if ( true ) {
        //if statement just for scope
        TypeLocal type = null ;
        try {
            type = home.findByName ( "Book" );
    %>      <p> type EXISTS! moving on </p> <%
        } catch (Exception e) {
    %>      <p> Type does not exist, creating it </p> <%
        } 

        if ( type == null ) {
            type = home.create("Book");
            Collection props = type.getProperties();
            props.add ( propHome.create ( "Title", null ) );
            props.add ( propHome.create ( "Author", null ) );
            props.add ( propHome.create ( "ISBN", null ) );
            props.add ( propHome.create ( "Number of Pages", null ) );
            props.add ( propHome.create ( "Genre", null ) );
        }
    }

    if ( true ) {
        //if statement just for scope
        TypeLocal type = null ;
        try {
            type = home.findByName ( "Furniture" );
    %>      <p> type EXISTS! moving on </p> <%
        } catch (Exception e) {
    %>      <p> Type does not exist, creating it </p> <%
        }

        if ( type == null ) {
            type = home.create("Furniture");
            Collection props = type.getProperties();
            props.add ( propHome.create ( "Type of Furniture", null ) );
            props.add ( propHome.create ( "Colour", null ) );
            props.add ( propHome.create ( "Dimensions", null ) );
            props.add ( propHome.create ( "Finish", null ) );
            props.add ( propHome.create ( "Material", null ) );
        }
    }

     if ( true ) {
        //if statement just for scope
        TypeLocal type = null ;
        try {
            type = home.findByName ( "Monitor" );
    %>      <p> type EXISTS! moving on </p> <%
        } catch (Exception e) {
    %>      <p> Type does not exist, creating it </p> <%
        }

        if ( type == null ) {
            type = home.create("Monitor");
            Collection props = type.getProperties();
            props.add ( propHome.create ( "Brand", null ) );
	    props.add ( propHome.create ( "Model", null ) );
	    props.add ( propHome.create ( "Type", null ) );
	    props.add ( propHome.create ( "Screen Size", null ) );
            props.add ( propHome.create ( "Maximum Resolution", null ) );
            props.add ( propHome.create ( "Widescreen", null ) );
	    props.add ( propHome.create ( "Built in Speakers", null));
	    props.add ( propHome.create ( "Tv Tuner", null));
	}
    }
%>

<jsp:include page="../views/viewAllTypes.jsp" />
