KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > setup > impl > sl > SchemaLoaderConfiBase


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.setup.impl.sl;
10
11 import org.jboss.portal.setup.sl.SchemaLoaderConfig;
12 import org.jboss.portal.setup.sl.SchemaLoadType;
13 import org.jboss.portal.setup.PortalSetupException;
14 import org.jboss.portal.setup.impl.config.ConfigurationImpl;
15 import org.jboss.portal.setup.config.Configuration;
16
17 import java.util.List JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Arrays JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:palber@novell.com">Polina Alber</a>
27  * Date: Apr 13, 2005; Time: 2:03:42 PM
28  * @since JBoss portal 2.0
29  * Class org.jboss.portal.setup.impl.sl.SchemaLoaderConfiBase
30  */

31 public abstract class SchemaLoaderConfiBase extends ConfigurationImpl implements SchemaLoaderConfig
32 {
33    private List JavaDoc m_schemaURIs = new ArrayList JavaDoc();
34    private List JavaDoc m_filePatterns = new ArrayList JavaDoc();
35    private SchemaLoadType m_type = null;
36
37    protected SchemaLoaderConfiBase(String JavaDoc[] filePatterns)
38    {
39       m_filePatterns.addAll(Arrays.asList(filePatterns));
40
41    }
42
43    /**
44     * @return a type of schema loading; supported types are new only, always (reloads every time),
45     * never (never performs schema load)
46     */

47    public SchemaLoadType getSchemaLoadType()
48    {
49       return m_type;
50    }
51
52    /**
53     * Set a type of schema loading; supported types are new only, always (reloads every time),
54     * never (never performs schema load)
55     */

56    public void setSchemaLoadType(String JavaDoc type) throws PortalSetupException
57    {
58       m_type = SchemaLoadType.parseString(type);
59    }
60
61
62    /**
63     * return a <code>List</code> of schema files URI;
64     * may include a directory uri, where all schema files are located.
65     */

66    public List JavaDoc getSchemaLoadURIs()
67    {
68       return m_schemaURIs;
69    }
70
71    /**
72     * @param schemaFileURI - a String that defines either file URI, or dirrectory URI
73     * where load data files are located.Does not perform scanning of a directory all the time.
74     * gets directory file list only once upon addition.
75     * @throws PortalSetupException if URI cannot be resolved - resource cannot be found
76     */

77    public void addSchemaLoadURI(String JavaDoc schemaFileURI) throws PortalSetupException
78    {
79       //XXX perform pattern match, check if uri is a dirrectory and explode all files in it
80
ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
81       URL JavaDoc resource = cl.getResource(schemaFileURI);
82       if (null == resource)
83       {
84          throw new PortalSetupException("Specified resource '" + schemaFileURI + "' cannot be found!");
85       }
86       m_schemaURIs.add(schemaFileURI);
87    }
88
89    /**
90     * @param schemaFilesURIs - a <code>List</code> of Strings that defines either file URI, or dirrectory URI
91     * where schema files are located.Does not perform scanning of a directory all the time.
92     * gets directory file list only once upon addition.
93     * @throws PortalSetupException if URI cannot be resolved
94     */

95    public void setSchemaLoadURIs(List JavaDoc schemaFilesURIs) throws PortalSetupException
96    {
97       if (schemaFilesURIs != null)
98       {
99          Iterator JavaDoc iter = schemaFilesURIs.iterator();
100          while (iter.hasNext())
101          {
102             String JavaDoc uri = (String JavaDoc)iter.next();
103             this.addSchemaLoadURI(uri);
104          }
105       }
106    }
107
108    /**
109     * @return a <code>List</code> of strings, that defines schema file name pattern, like
110     * '*.hbm.xml, *.ddl' - supported by a type of schema loader this configuration reffers to.
111     */

112    public List JavaDoc getSchemaFilePattern()
113    {
114       return m_filePatterns;
115    }
116
117 }
118
Popular Tags