KickJava   Java API By Example, From Geeks To Geeks.

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


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.map.DataMap;
25
26 /**
27  * DataMapFile is a ProjectFile abstraction of the
28  * DataMap file in a Cayenne project.
29  *
30  * @author Andrus Adamchik
31  */

32 public class DataMapFile extends ProjectFile {
33     public static final String JavaDoc LOCATION_SUFFIX = ".map.xml";
34     
35     protected DataMap map;
36     
37     public DataMapFile() {}
38
39     /**
40      * Constructor for DataMapFile.
41      */

42     public DataMapFile(Project project, DataMap map) {
43         super(project, map.getLocation());
44         this.map = map;
45     }
46
47     /**
48      * Returns DataMap associated with this project.
49      */

50     public Object JavaDoc getObject() {
51         return map;
52     }
53
54     /**
55      * @see org.apache.cayenne.project.ProjectFile#getObjectName()
56      */

57     public String JavaDoc getObjectName() {
58         return map.getName();
59     }
60
61     public void save(PrintWriter JavaDoc out) throws Exception JavaDoc {
62         map.encodeAsXML(out);
63     }
64
65     /**
66      * @see org.apache.cayenne.project.ProjectFile#canHandle(Object)
67      */

68     public boolean canHandle(Object JavaDoc obj) {
69         return obj instanceof DataMap;
70     }
71
72     /**
73      * Updates map location to match the name before save.
74      */

75     public void willSave() {
76         super.willSave();
77
78         if (map != null) {
79             map.setLocation(getLocation());
80         }
81     }
82
83     /**
84      * Returns ".map.xml" that should be used as a file suffix for DataMaps.
85      */

86     public String JavaDoc getLocationSuffix() {
87         return LOCATION_SUFFIX;
88     }
89 }
90
Popular Tags