Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/objectstyle/woproject/pb/PBProject.java


1   /* ====================================================================
2    * 
3    * The ObjectStyle Group Software License, Version 1.0 
4    *
5    * Copyright (c) 2002 The ObjectStyle Group 
6    * and individual authors of the software.  All rights reserved.
7    *
8    * Redistribution and use in source and binary forms, with or without
9    * modification, are permitted provided that the following conditions
10   * are met:
11   *
12   * 1. Redistributions of source code must retain the above copyright
13   *    notice, this list of conditions and the following disclaimer. 
14   *
15   * 2. Redistributions in binary form must reproduce the above copyright
16   *    notice, this list of conditions and the following disclaimer in
17   *    the documentation and/or other materials provided with the
18   *    distribution.
19   *
20   * 3. The end-user documentation included with the redistribution, if
21   *    any, must include the following acknowlegement:  
22   *       "This product includes software developed by the 
23   *        ObjectStyle Group (http://objectstyle.org/)."
24   *    Alternately, this acknowlegement may appear in the software itself,
25   *    if and wherever such third-party acknowlegements normally appear.
26   *
27   * 4. The names "ObjectStyle Group" and "Cayenne" 
28   *    must not be used to endorse or promote products derived
29   *    from this software without prior written permission. For written 
30   *    permission, please contact andrus@objectstyle.org.
31   *
32   * 5. Products derived from this software may not be called "ObjectStyle"
33   *    nor may "ObjectStyle" appear in their names without prior written
34   *    permission of the ObjectStyle Group.
35   *
36   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39   * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
40   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47   * SUCH DAMAGE.
48   * ====================================================================
49   *
50   * This software consists of voluntary contributions made by many
51   * individuals on behalf of the ObjectStyle Group.  For more
52   * information on the ObjectStyle Group, please see
53   * <http://objectstyle.org/>.
54   *
55   */
56  
57  package org.objectstyle.woproject.pb;
58  
59  import java.io.File;
60  import java.io.IOException;
61  import java.io.InputStream;
62  import java.util.List;
63  import java.util.Map;
64  
65  import org.objectstyle.cayenne.wocompat.PropertyListSerialization;
66  
67  /**
68   * A <b>PBProject</b> represents a ProjectBuilder project file
69   * traditionally called <code>PB.project</code>.
70   * 
71   * 
72   * @author uli
73   * @author Andrei Adamchik
74   */
75  public class PBProject {
76    public static final String DEFAULT_APP_PROJECT = "pbindex/woapp/PB.project";
77    public static final String DEFAULT_FRAMEWORK_PROJECT =
78      "pbindex/woframework/PB.project";
79  
80    public static final String DYNAMIC_CODE_GEN = "DYNAMIC_CODE_GEN";
81    public static final String FILESTABLE = "FILESTABLE";
82    public static final String CLASSES = "CLASSES";
83    public static final String FRAMEWORKS = "FRAMEWORKS";
84    public static final String OTHER_LINKED = "OTHER_LINKED";
85    public static final String OTHER_SOURCES = "OTHER_SOURCES";
86    public static final String WOAPP_RESOURCES = "WOAPP_RESOURCES";
87    public static final String WOCOMPONENTS = "WO_COMPONENTS";
88    public static final String WEB_SERVER_RESOURCES = "WEBSERVER_RESOURCES";
89    public static final String PROJECTNAME = "PROJECTNAME";
90    public static final String PROJECTTYPE = "PROJECTTYPE";
91    public static final String PROJECTVERSION = "PROJECTVERSION";
92    public static final String SUBPROJECTS = "SUBPROJECTS";
93    public static final String YES = "YES";
94    public static final String NO = "NO";
95  
96    protected boolean isFramework;
97    protected File projectFile;
98    protected Map pbProject;
99    protected Map filesTable;
100 
101   /**
102    * Creates a new PBProject object
103    * with an associated project file assumed to be called "PB.project"
104    * and located in the current directory. If file does not exist,
105    * PBProject object is initialized using default template.
106    */
107   public PBProject(boolean isFramework) throws IOException {
108     this(new File("PB.project"), isFramework);
109   }
110 
111   /**
112    * Creates a new PBProject object
113    * with an associated project file. If file does not exist,
114    * PBProject object is initialized using default template.
115    */
116   public PBProject(File projectFile, boolean isFramework) throws IOException {
117     this.projectFile = projectFile;
118     this.isFramework = isFramework;
119 
120     if (projectFile == null) {
121       throw new NullPointerException("Project file is null.");
122     }
123 
124     this.update();
125   }
126 
127   public String getDefaultTemplate() {
128     return (isFramework) ? DEFAULT_FRAMEWORK_PROJECT : DEFAULT_APP_PROJECT;
129   }
130 
131   /**
132    * Updates itself from the underlying <code>PB.project</code> file.
133    * If the file does not exist, uses a default template to load a 
134    * skeleton project.
135    */
136   public void update() throws IOException {
137     if (projectFile == null || !projectFile.exists()) {
138       InputStream in =
139         this.getClass().getClassLoader().getResourceAsStream(
140           getDefaultTemplate());
141       pbProject = (Map) PropertyListSerialization.propertyListFromStream(in);
142     } else {
143       pbProject = (Map) PropertyListSerialization.propertyListFromFile(projectFile);
144     }
145     
146     if(pbProject == null) {
147       throw new IOException("Error reading project file: " + projectFile);
148     }
149 
150     readFilesTable();
151   }
152 
153   /**
154    * Stores changes made to this object in the underlying PB.project file.
155    */
156   public void saveChanges() throws IOException {
157     this.saveFilesTable();
158     PropertyListSerialization.propertyListToFile(projectFile, pbProject);
159   }
160 
161   public boolean isDynamicCodeGen() {
162     return PBProject.YES.equals(pbProject.get(PBProject.DYNAMIC_CODE_GEN));
163   }
164 
165   public void setDynamicCodeGen(boolean aBoolean) {
166     String flag = (aBoolean) ? PBProject.YES : PBProject.NO;
167     pbProject.put(PBProject.DYNAMIC_CODE_GEN, flag);
168   }
169 
170   public List getClasses() {
171     return (List) getFilesTable().get(PBProject.CLASSES);
172   }
173 
174   public void setClasses(List anArray) {
175     getFilesTable().put(PBProject.CLASSES, anArray);
176   }
177 
178   public List getWebServerResources() {
179     return (List) getFilesTable().get(PBProject.WEB_SERVER_RESOURCES);
180   }
181 
182   public void setWebServerResources(List anArray) {
183     getFilesTable().put(PBProject.WEB_SERVER_RESOURCES, anArray);
184   }
185 
186   public List getFrameworks() {
187     return (List) getFilesTable().get(PBProject.FRAMEWORKS);
188   }
189 
190   public void setFrameworks(List anArray) {
191     getFilesTable().put(PBProject.FRAMEWORKS, anArray);
192   }
193 
194   public List getSubprojects() {
195     return (List) getFilesTable().get(PBProject.SUBPROJECTS);
196   }
197 
198   public void setSubprojects(List anArray) {
199     getFilesTable().put(PBProject.SUBPROJECTS, anArray);
200   }
201 
202   public List getOtherLinked() {
203     return (List) getFilesTable().get(PBProject.OTHER_LINKED);
204   }
205 
206   public void setOtherLinked(List anArray) {
207     getFilesTable().put(PBProject.OTHER_LINKED, anArray);
208   }
209 
210   public List getOtherSources() {
211     return (List) getFilesTable().get(PBProject.OTHER_SOURCES);
212   }
213 
214   public void setOtherSources(List anArray) {
215     getFilesTable().put(PBProject.OTHER_SOURCES, anArray);
216   }
217 
218   public List getWoAppResources() {
219     return (List) getFilesTable().get(PBProject.WOAPP_RESOURCES);
220   }
221 
222   public void setWoAppResources(List anArray) {
223     getFilesTable().put(PBProject.WOAPP_RESOURCES, anArray);
224   }
225 
226   public List getWoComponents() {
227     return (List) getFilesTable().get(PBProject.WOCOMPONENTS);
228   }
229 
230   public void setWoComponents(List anArray) {
231     getFilesTable().put(PBProject.WOCOMPONENTS, anArray);
232   }
233 
234   public String getProjectName() {
235     return (String) pbProject.get(PBProject.PROJECTNAME);
236   }
237 
238   public void setProjectName(String aString) {
239     pbProject.put(PBProject.PROJECTNAME, aString);
240   }
241 
242   public String getProjectType() {
243     return (String) pbProject.get(PBProject.PROJECTTYPE);
244   }
245 
246   public void setProjectType(String aString) {
247     pbProject.put(PBProject.PROJECTTYPE, aString);
248   }
249 
250   public String getProjectVersion() {
251     return (String) pbProject.get(PBProject.PROJECTVERSION);
252   }
253 
254   public void setProjectVersion(String aString) {
255     pbProject.put(PBProject.PROJECTVERSION, aString);
256   }
257 
258   protected Map getFilesTable() {
259     return filesTable;
260   }
261 
262   protected void saveFilesTable() {
263     pbProject.put(PBProject.FILESTABLE, filesTable);
264   }
265 
266   protected void readFilesTable() {
267     filesTable = (Map) pbProject.get(PBProject.FILESTABLE);
268   }
269 
270   /**
271    * Returns the projectFile.
272    * @return File
273    */
274   public File getProjectFile() {
275     return projectFile;
276   }
277 
278   /**
279    * Sets the projectFile.
280    * @param projectFile The projectFile to set
281    */
282   public void setProjectFile(File projectFile) {
283     this.projectFile = projectFile;
284   }
285 }