KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > project > ProjectConfiguration


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.project;
21
22 import java.io.File JavaDoc;
23
24 import org.apache.cayenne.conf.Configuration;
25 import org.apache.cayenne.conf.DataSourceFactory;
26 import org.apache.cayenne.conf.FileConfiguration;
27 import org.apache.cayenne.util.ResourceLocator;
28
29 /**
30  * Subclass of FileConfiguration used in the project model.
31  *
32  * @author Misha Shengaout
33  * @author Andrus Adamchik
34  */

35 public class ProjectConfiguration extends FileConfiguration {
36
37     /**
38      * Override parent implementation to ignore loading failures.
39      *
40      * @see FileConfiguration#FileConfiguration(File)
41      */

42     public ProjectConfiguration(File JavaDoc projectFile) {
43         super(projectFile);
44
45         // ignore loading failures
46
this.setIgnoringLoadFailures(true);
47
48         // configure deterministic file opening rules
49
ResourceLocator locator = this.getResourceLocator();
50         locator.setSkipAbsolutePath(false);
51         locator.setSkipClasspath(true);
52         locator.setSkipCurrentDirectory(true);
53         locator.setSkipHomeDirectory(true);
54     }
55
56     /**
57      * Override parent implementation to prevent loading of nonexisting files.
58      *
59      * @see FileConfiguration#canInitialize()
60      */

61     public boolean canInitialize() {
62         return (super.canInitialize() && this.getProjectFile().isFile());
63     }
64
65     /**
66      * Override parent implementation to allow for null files.
67      *
68      * @see FileConfiguration#setProjectFile(File)
69      */

70     protected void setProjectFile(File JavaDoc projectFile) {
71         if ((projectFile != null) && (projectFile.exists())) {
72             super.setProjectFile(projectFile);
73         }
74         else {
75             super.projectFile = projectFile;
76             this.setDomainConfigurationName(Configuration.DEFAULT_DOMAIN_FILE);
77         }
78     }
79
80     /**
81      * Returns a DataSource factory for projects.
82      *
83      * @see org.apache.cayenne.project.ProjectDataSourceFactory
84      */

85     public DataSourceFactory getDataSourceFactory() {
86         try {
87             return new ProjectDataSourceFactory(this.getProjectDirectory());
88         }
89         catch (Exception JavaDoc e) {
90             throw new ProjectException("Error creating DataSourceFactory.", e);
91         }
92     }
93 }
94
Popular Tags