head	1.11;
access;
symbols
	TIGRIS_0_9_2_4:1.8
	TIGRIS_0_9_2_3:1.8
	HELM_PEER_PORT_BRANCH:1.10.0.2
	TURBINE_PEER:1.10
	TIGRIS_0_9_2_1:1.10
	TIGRIS_0_9_2:1.8.0.2;
locks; strict;
comment	@# @;


1.11
date	2001.02.21.02.17.29;	author dlr;	state dead;
branches;
next	1.10;

1.10
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.10.2.1;
next	1.9;

1.9
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.8;

1.8
date	2001.01.18.18.09.19;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2001.01.18.15.45.04;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2001.01.17.22.07.33;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2001.01.17.21.22.16;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.16.20.11.58;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.16.20.05.55;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.01.16.19.36.47;	author leonardr;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.16.02.33.02;	author leonardr;	state Exp;
branches;
next	;

1.10.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.11
log
@Deprecated by peer port merge.
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.business;

import java.sql.*;
import java.util.*;
import java.io.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.database.*;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.database.SkinManager;
import org.tigris.helm.database.StyleManager;
import org.tigris.helm.domain.*;
import org.tigris.helm.project.Project;

public class Skin extends BusinessObject
{

    protected final String getTableName() 
    { 
        return SkinManager.TABLE_NAME;
    }

    public static Log log = new Log("Skin", "Skin");
    public static final boolean debug = true;

    private SkinManager skinMgr;
    private StyleManager styleMgr;

    /**
     *A static Map of all Skins.
     */
    private static Map skins = new HashMap();

    /**
     *A Map of all styles for a Skin.
     */
    private Map styles;
    
    protected void createManagers() 
    {
        skinMgr = (SkinManager)dMgr.getManager("org.tigris.helm.database.SkinManager");
        styleMgr = (StyleManager)dMgr.getManager("org.tigris.helm.database.StyleManager");
    }

    /**
     * Business object constructor.
     */           
    public Skin (Connection conn, DataManager dMgr, String skinID)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);        
        setRecord(skinMgr.getSkin(conn, skinID));
        styles = new HashMap();
    }

    /**
     * Static method which gets a skin from the cache if it exists,
     * and builds and caches the skin if it doesn't.
     */
    public static Skin getSkin(Connection conn, DataManager dMgr, String skinID)
        throws SQLException, DataSetException, DoesNotExist
    {
        Skin s = null;
        if (skinID != null)
        {
            if (skins.containsKey(skinID))
            {
                s = (Skin)skins.get(skinID);
            } else {
                s = new Skin(conn, dMgr, skinID);
                skins.put(skinID, s);
            }
        }
        return s;
    }

    /**
     * Builds or retrieves a style for this skin by name.
     */
    public Style getStyle(String styleName)
        throws SQLException, DataSetException, DoesNotExist
    {
        Style style = null;
        if (styles.containsKey(styleName))
        {
            //If we have this style for this skin cached, just use it.
            style = (Style)styles.get(styleName);
        } else {
            //Otherwise, make a new one and cache it.
            style = new Style(conn, dMgr, this, styleName);
            styles.put(styleName, style);
        }
        return style;
    }

    /**
     * Returns a List of all the Styles this skin defines.
     */
    public List getStyles()
        throws SQLException, DataSetException, DoesNotExist
    {
        List styles = new ArrayList();
        DataSet s = styleMgr.listStyles(conn);
        for (int i = 0; i < s.size(); i++)
        {
            Record r = s.getRecord(i);
            String name = r.getValue(StyleManager.NAME).asString();
            Style style = getStyle(name);
            styles.add(style);
        }
        return styles;
    }

    /**
     * Returns the skin which this skin uses as its base. Returns null
     * if this skin is a base skin.
     */
    public Skin getParent()
        throws SQLException, DataSetException, DoesNotExist
    {
        Skin base = null;
        if (!isBase())
        {            
            base = new Skin(conn, dMgr, getBaseID());
        }
        return base;
    }

    public boolean isBase()
    throws DataSetException
    {
        return (getBaseID() == null);
    }

    public String getID()
        throws DataSetException
    {
        return getField(SkinManager.SKIN_ID);
    }

    public String getBaseID()
        throws DataSetException
    {
        return getField(SkinManager.BASE_SKIN_ID);
    }

    public String getName()
        throws DataSetException
    {
        return getField(SkinManager.NAME);
    }

    public String getResource()
        throws DataSetException
    {
        return getField(SkinManager.RESOURCE);
    }

}

@


1.10
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@@


1.10.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.9
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.8
log
@Skins can now be recursively based upon other skins.
@
text
@@


1.7
log
@Added methods to business objects so that ProjectCSS could get an enumeration over all the styles provided by a skin.
@
text
@d159 2
a160 1
            styles.add(getStyle(name));
@


1.6
log
@How about making sure a new business object initializes properly before committing code that puts it into HelmServlet.
@
text
@d62 1
d78 1
d93 1
d104 1
d148 17
d173 1
a173 1
        {
@


1.5
log
@There's no reason why skins can't have multiple layers of parentage.
@
text
@d81 1
a81 1
    private static Map skins;
@


1.4
log
@Null skinID means null Skin.
@
text
@a154 5
        if (!base.isBase())
        {
            throw new DataSetException
                ("Composite skin cannot be based upon another composite skin.");
        }
@


1.3
log
@Added static cache of Skin objects.
@
text
@d111 1
a111 1
        if (skins.containsKey(skinID))
d113 7
a119 4
            s = (Skin)skins.get(skinID);
        } else {
            s = new Skin(conn, dMgr, skinID);
            skins.put(skinID, s);
@


1.2
log
@More code written for skins and styles.
@
text
@d87 1
a87 1

d92 4
a95 1
        
d103 17
d122 1
a122 1
     * Builds or retrieves a style by name.
@


1.1
log
@Added minimal business object and TableManager for Skin object.
@
text
@d78 3
d83 5
d100 4
a103 1
    /*
d105 21
d127 12
d140 4
d145 1
a145 2
    */
    
@

