KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > loading > HeirarchicalLoaderRepository3ConfigParser


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.mx.loading;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfigParser;
28
29 /** The LoaderRepositoryConfigParser implementation for the HeirarchicalLoaderRepository3.
30  * This implementation supports the single java2ParentDelegation property which
31  * indicates whether the HeirarchicalLoaderRepository3 should load classes from
32  * its scope first followed by its parent repository (java2ParentDelegation=true).
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 37459 $
36  */

37 public class HeirarchicalLoaderRepository3ConfigParser
38    implements LoaderRepositoryConfigParser
39 {
40    /** Set the HeirarchicalLoaderRepository3.UseParentFirst attribute based on
41     * the value of the java2ParentDelegation property found in the config.
42     *
43     * @param repository the HeirarchicalLoaderRepository3 to set the
44     * UseParentFirst attribute on.
45     * @param config A string representation of a Properties file
46     * @throws Exception
47     */

48    public void configure(LoaderRepository repository, String JavaDoc config)
49       throws Exception JavaDoc
50    {
51       HeirarchicalLoaderRepository3 hlr3 = (HeirarchicalLoaderRepository3) repository;
52       Properties JavaDoc props = new Properties JavaDoc();
53       ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(config.getBytes());
54       props.load(bais);
55       String JavaDoc java2ParentDelegation = props.getProperty("java2ParentDelegation");
56       if( java2ParentDelegation == null )
57       {
58          // Check for previous mis-spelled property name
59
java2ParentDelegation = props.getProperty("java2ParentDelegaton", "false");
60       }
61       boolean useParentFirst = Boolean.valueOf(java2ParentDelegation).booleanValue();
62       hlr3.setUseParentFirst(useParentFirst);
63    }
64 }
65
Popular Tags