KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrintWriter JavaDoc;
23
24 import org.apache.cayenne.conf.ConfigSaver;
25 import org.apache.cayenne.conf.ConfigSaverDelegate;
26 import org.apache.cayenne.conf.Configuration;
27 import org.apache.cayenne.conf.RuntimeSaveDelegate;
28
29 /**
30  * ApplicationProjectFile is a ProjectFile abstraction of the main project file in a
31  * Cayenne project. Right now Cayenne projects can not be renamed, so all the name
32  * tracking functionality is pretty much noop.
33  *
34  * @author Andrus Adamchik
35  */

36 public class ApplicationProjectFile extends ProjectFile {
37
38     protected ConfigSaverDelegate saveDelegate;
39
40     private String JavaDoc objectName = null;
41
42     private ApplicationProjectFile() {
43         super();
44     }
45
46     /**
47      * Constructor for default ApplicationProjectFile.
48      */

49     public ApplicationProjectFile(Project project) {
50         this(project, Configuration.DEFAULT_DOMAIN_FILE);
51     }
52
53     /**
54      * Constructor for ApplicationProjectFile with an existing file.
55      */

56     public ApplicationProjectFile(Project project, String JavaDoc fileName) {
57         super(project, fileName);
58         this.objectName = fileName.substring(0, fileName.lastIndexOf(this
59                 .getLocationSuffix()));
60     }
61
62     /**
63      * Returns suffix to append to object name when creating a file name. Default
64      * implementation returns empty string.
65      */

66     public String JavaDoc getLocationSuffix() {
67         return ".xml";
68     }
69
70     /**
71      * Returns a project.
72      */

73     public Object JavaDoc getObject() {
74         return getProject();
75     }
76
77     /**
78      * @see org.apache.cayenne.project.ProjectFile#getObjectName()
79      */

80     public String JavaDoc getObjectName() {
81         return this.objectName;
82     }
83
84     public void save(PrintWriter JavaDoc out) throws Exception JavaDoc {
85         ConfigSaverDelegate localDelegate = (saveDelegate != null)
86                 ? saveDelegate
87                 : new RuntimeSaveDelegate(((ApplicationProject) projectObj)
88                         .getConfiguration());
89         new ConfigSaver(localDelegate).storeDomains(out);
90     }
91
92     public boolean canHandle(Object JavaDoc obj) {
93         return obj instanceof ApplicationProject;
94     }
95
96     /**
97      * Returns the saveDelegate.
98      *
99      * @return ConfigSaverDelegate
100      */

101     public ConfigSaverDelegate getSaveDelegate() {
102         return saveDelegate;
103     }
104
105     /**
106      * Sets the saveDelegate.
107      *
108      * @param saveDelegate The saveDelegate to set
109      */

110     public void setSaveDelegate(ConfigSaverDelegate saveDelegate) {
111         this.saveDelegate = saveDelegate;
112     }
113 }
114
Popular Tags