KickJava   Java API By Example, From Geeks To Geeks.

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


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.access.DataDomain;
25 import org.apache.cayenne.access.DataNode;
26 import org.apache.cayenne.conf.Configuration;
27
28 /**
29  * Stores information necessary to reconfigure nodes of existing projects.
30  *
31  * @author Andrus Adamchik
32  */

33 public class DataNodeConfigInfo {
34     protected String JavaDoc name;
35     protected String JavaDoc domain;
36     protected String JavaDoc adapter;
37     protected String JavaDoc dataSource;
38     protected File JavaDoc driverFile;
39
40     /**
41      * Searches for the DataNode described by this DataNodeConfigInfo in the
42      * provided configuration object. Throws ProjectException if there is no
43      * matching DataNode.
44      */

45     public DataNode findDataNode(Configuration config)
46         throws ProjectException {
47         DataDomain domainObj = null;
48
49         // domain name is either explicit, or use default domain
50
if (domain != null) {
51             domainObj = config.getDomain(domain);
52
53             if (domainObj == null) {
54                 throw new ProjectException("Can't find domain named " + domain);
55             }
56         } else {
57             try {
58                 domainObj = config.getDomain();
59             } catch (Exception JavaDoc ex) {
60                 throw new ProjectException("Project has no default domain.", ex);
61             }
62
63             if (domainObj == null) {
64                 throw new ProjectException("Project has no domains configured.");
65             }
66         }
67
68         DataNode node = domainObj.getNode(name);
69         if (node == null) {
70             throw new ProjectException(
71                 "Domain "
72                     + domainObj.getName()
73                     + " has no node named '"
74                     + name
75                     + "'.");
76         }
77         return node;
78     }
79
80     /**
81      * Returns the adapter.
82      * @return String
83      */

84     public String JavaDoc getAdapter() {
85         return adapter;
86     }
87
88     /**
89      * Returns the dataSource.
90      * @return String
91      */

92     public String JavaDoc getDataSource() {
93         return dataSource;
94     }
95
96     /**
97      * Returns the domain.
98      * @return String
99      */

100     public String JavaDoc getDomain() {
101         return domain;
102     }
103
104     /**
105      * Returns the driverFile.
106      * @return File
107      */

108     public File JavaDoc getDriverFile() {
109         return driverFile;
110     }
111
112     /**
113      * Returns the name.
114      * @return String
115      */

116     public String JavaDoc getName() {
117         return name;
118     }
119
120     /**
121      * Sets the adapter.
122      * @param adapter The adapter to set
123      */

124     public void setAdapter(String JavaDoc adapter) {
125         this.adapter = adapter;
126     }
127
128     /**
129      * Sets the dataSource.
130      * @param dataSource The dataSource to set
131      */

132     public void setDataSource(String JavaDoc dataSource) {
133         this.dataSource = dataSource;
134     }
135
136     /**
137      * Sets the domain.
138      * @param domain The domain to set
139      */

140     public void setDomain(String JavaDoc domain) {
141         this.domain = domain;
142     }
143
144     /**
145      * Sets the driverFile.
146      * @param driverFile The driverFile to set
147      */

148     public void setDriverFile(File JavaDoc driverFile) {
149         this.driverFile = driverFile;
150     }
151
152     /**
153      * Sets the name.
154      * @param name The name to set
155      */

156     public void setName(String JavaDoc name) {
157         this.name = name;
158     }
159
160 }
161
Popular Tags