01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.components.dao;
18:
19: import java.net.URL;
20:
21: import org.apache.ojb.broker.metadata.DescriptorRepository;
22: import org.apache.ojb.broker.metadata.MetadataManager;
23: import org.apache.ojb.broker.metadata.RepositoryPersistor;
24: import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport;
25:
26: /**
27: * <p>
28: * InitablePersistenceBrokerDaoSupport
29: * </p>
30: * <p>
31: *
32: * </p>
33: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
34: * @version $Id: InitablePersistenceBrokerDaoSupport.java 224631 2005-07-24 17:03:46Z taylor $
35: *
36: */
37: public class InitablePersistenceBrokerDaoSupport extends
38: PersistenceBrokerDaoSupport {
39:
40: protected String repositoryPath;
41:
42: /**
43: *
44: */
45: public InitablePersistenceBrokerDaoSupport(String repositoryPath) {
46: super ();
47: this .repositoryPath = repositoryPath;
48:
49: }
50:
51: /**
52: *
53: * <p>
54: * init
55: * </p>
56: * Loads the correct repository descriptor for InitablePersistenceBrokerDaoSupport
57: *
58: * @see org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport
59: * @throws Exception
60: */
61: public void init() throws Exception {
62: MetadataManager metaManager = MetadataManager.getInstance();
63: RepositoryPersistor persistor = new RepositoryPersistor();
64: URL descriptorUrl = getClass().getClassLoader().getResource(
65: repositoryPath);
66:
67: logger.info("Merging OJB respository " + descriptorUrl
68: + " for DAO class " + getClass().getName());
69: DescriptorRepository repo = persistor
70: .readDescriptorRepository(descriptorUrl.openStream());
71: metaManager.mergeDescriptorRepository(repo);
72: }
73:
74: }
|