01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import java.util.Properties;
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: 57200 $
36: */
37: public class HeirarchicalLoaderRepository3ConfigParser implements
38: LoaderRepositoryConfigParser {
39: /** Set the HeirarchicalLoaderRepository3.UseParentFirst attribute based on
40: * the value of the java2ParentDelegation property found in the config.
41: *
42: * @param repository the HeirarchicalLoaderRepository3 to set the
43: * UseParentFirst attribute on.
44: * @param config A string representation of a Properties file
45: * @throws Exception
46: */
47: public void configure(LoaderRepository repository, String config)
48: throws Exception {
49: HeirarchicalLoaderRepository3 hlr3 = (HeirarchicalLoaderRepository3) repository;
50: Properties props = new Properties();
51: ByteArrayInputStream bais = new ByteArrayInputStream(config
52: .getBytes());
53: props.load(bais);
54: String java2ParentDelegation = props
55: .getProperty("java2ParentDelegation");
56: if (java2ParentDelegation == null) {
57: // Check for previous mis-spelled property name
58: java2ParentDelegation = props.getProperty(
59: "java2ParentDelegaton", "false");
60: }
61: boolean useParentFirst = Boolean.valueOf(java2ParentDelegation)
62: .booleanValue();
63: hlr3.setUseParentFirst(useParentFirst);
64: }
65: }
|