svn commit: r12860 - branches/gsoc2007/maurelio1234/argouml/org/argouml: kernel persistence

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: maurelio1234
Date: 2007-06-16 04:57:48-0700
New Revision: 12860

Added:
   branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ProfileConfigurationFilePersister.java
Modified:
   branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java
   branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java

Log:
adding support for profile persistence

Modified: branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java?view=diff&rev=12860&p1=branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java&p2=branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java&r1=12859&r2=12860
==============================================================================
--- branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java	(original)
+++ branches/gsoc2007/maurelio1234/argouml/org/argouml/kernel/MemberList.java	2007-06-16 04:57:48-0700
@@ -29,11 +29,13 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Vector;
 
 import org.apache.log4j.Logger;
 import org.argouml.uml.ProjectMemberModel;
 import org.argouml.uml.cognitive.ProjectMemberTodoList;
 import org.argouml.uml.diagram.ProjectMemberDiagram;
+import org.argouml.uml.profile.ProfileConfiguration;
 import org.tigris.gef.base.Diagram;
 
 /**
@@ -49,7 +51,10 @@
     private AbstractProjectMember model;
     private List diagramMembers = new ArrayList(10);
     private AbstractProjectMember todoList;
-
+    private AbstractProjectMember profileConfiguration;
+    
+    private Vector allMembers = new Vector();
+    
     /**
      * The constructor.
      */
@@ -61,12 +66,15 @@
 
         if (member instanceof ProjectMemberModel) {
             // Always put the model at the top
-            model = (AbstractProjectMember) member;
+            model = (AbstractProjectMember) member;            
             return true;
         } else if (member instanceof ProjectMemberTodoList) {
             // otherwise add the diagram at the start
             setTodoList((AbstractProjectMember) member);
             return true;
+        } else if (member instanceof ProfileConfiguration) {
+            setProfileConfiguration((AbstractProjectMember) member);
+            return true;
         } else if (member instanceof ProjectMemberDiagram) {
             // otherwise add the diagram at the start
             return diagramMembers.add(member);
@@ -87,6 +95,10 @@
             LOG.info("Removing todo list");
             setTodoList(null);
             return true;
+        } else if (profileConfiguration == member) {
+            LOG.info("Removing profile configuration");
+            setProfileConfiguration(null);
+            return true;
         } else {
             return diagramMembers.remove(member);
         }
@@ -101,6 +113,9 @@
         if (todoList != null) {
             temp.add(todoList);
         }
+        if (profileConfiguration != null) {
+            temp.add(profileConfiguration);
+        }
         return temp.iterator();
     }
 
@@ -113,6 +128,9 @@
         if (todoList != null) {
             temp.add(todoList);
         }
+        if (profileConfiguration != null) {
+            temp.add(profileConfiguration);
+        }
         return temp.listIterator();
     }
 
@@ -125,6 +143,9 @@
         if (todoList != null) {
             temp.add(todoList);
         }
+        if (profileConfiguration != null) {
+            temp.add(profileConfiguration);
+        }
         return temp.listIterator(arg0);
     }
 
@@ -150,6 +171,9 @@
         if (todoList != null) {
             ++size;
         }
+        if (profileConfiguration != null) {
+            ++size;
+        }
         return size;
     }
 
@@ -160,6 +184,9 @@
         if (model == member) {
             return true;
         }
+        if (profileConfiguration == member) {
+            return true;
+        }
         return diagramMembers.contains(member);
     }
 
@@ -171,6 +198,10 @@
         if (todoList != null) {
             todoList.remove();
         }
+        if (profileConfiguration != null) {
+            profileConfiguration.remove();
+        }
+
         Iterator membersIt = diagramMembers.iterator();
         while (membersIt.hasNext()) {
             ((AbstractProjectMember) membersIt.next()).remove();
@@ -189,6 +220,9 @@
         if (type == ProjectMemberTodoList.class) {
             return todoList;
         }
+        if (type == ProfileConfiguration.class) {
+            return profileConfiguration;
+        }
         throw new IllegalArgumentException(
             "There is no single instance of a " + type.getName() + " member");
     }
@@ -211,6 +245,11 @@
         if (type == ProjectMemberDiagram.class) {
             return diagramMembers;
         }
+        if (type == ProfileConfiguration.class) {
+            List temp = new ArrayList(1);
+            temp.add(profileConfiguration);
+            return temp;
+        }
         throw new IllegalArgumentException(
             "There is no single instance of a " + type.getName() + " member");
     }
@@ -226,6 +265,9 @@
         if (i == diagramMembers.size()) {
             return todoList;
         }
+        if (i == diagramMembers.size()+1) {
+            return profileConfiguration;
+        }
 
         return diagramMembers.get(i);
     }
@@ -246,6 +288,9 @@
         if (todoList != null) {
             temp[pos++] = todoList;
         }
+        if (profileConfiguration != null) {
+            temp[pos++] = profileConfiguration;
+        }
         return temp;
     }
 
@@ -301,4 +346,12 @@
     public List subList(int arg0, int arg1) {
         throw new UnsupportedOperationException();
     }
+
+    public AbstractProjectMember getProfileConfiguration() {
+        return profileConfiguration;
+    }
+
+    public void setProfileConfiguration(AbstractProjectMember profileConfiguration) {
+        this.profileConfiguration = profileConfiguration;
+    }
 }

Added: branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ProfileConfigurationFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ProfileConfigurationFilePersister.java?view=auto&rev=12860
==============================================================================
--- (empty file)
+++ branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ProfileConfigurationFilePersister.java	2007-06-16 04:57:48-0700
@@ -0,0 +1,157 @@
+// $Id: eclipse-argo-codetemplates.xml 11347 2006-10-26 22:37:44Z linus $

+// Copyright (c) 2007 The Regents of the University of California. All

+// Rights Reserved. Permission to use, copy, modify, and distribute this

+// software and its documentation without fee, and without a written

+// agreement is hereby granted, provided that the above copyright notice

+// and this paragraph appear in all copies. This software program and

+// documentation are copyrighted by The Regents of the University of

+// California. The software program and documentation are supplied "AS

+// IS", without any accompanying services from The Regents. The Regents

+// does not warrant that the operation of the program will be

+// uninterrupted or error-free. The end-user understands that the program

+// was developed for research purposes and is advised not to rely

+// exclusively on the program for any reason. IN NO EVENT SHALL THE

+// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,

+// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,

+// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF

+// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF

+// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY

+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE

+// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF

+// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,

+// UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

+

+package org.argouml.persistence;

+

+import java.io.BufferedReader;

+import java.io.File;

+import java.io.InputStream;

+import java.io.InputStreamReader;

+import java.io.PrintWriter;

+import java.io.Writer;

+import java.util.StringTokenizer;

+import java.util.Vector;

+

+import org.argouml.kernel.Project;

+import org.argouml.kernel.ProjectMember;

+import org.argouml.uml.profile.Profile;

+import org.argouml.uml.profile.ProfileConfiguration;

+import org.argouml.uml.profile.ProfileManagerImpl;

+import org.argouml.uml.profile.UserDefinedProfile;

+

+public class ProfileConfigurationFilePersister extends MemberFilePersister {

+

+    @Override

+    public String getMainTag() {

+	return "profile";

+    }

+

+    @Override

+    public void load(Project project, InputStream inputStream)

+	    throws OpenException {

+	try {

+	    ProfileConfiguration pc = new ProfileConfiguration(project);

+

+	    BufferedReader br = new BufferedReader(new InputStreamReader(

+		    inputStream));

+

+	    String line = null;

+	    while (!(line = br.readLine().trim()).equals("<profile>"));

+

+	    while (true) {

+		line = br.readLine().trim();

+

+		if (line.equals("</profile>")) {

+		    break;

+		}

+

+		Profile profile = null;

+		Vector profiles = ProfileManagerImpl.getInstance()

+			.getRegisteredProfiles();

+

+		if (line.equals("<userDefined>")) {

+		    String fileName = br.readLine().trim();

+

+		    File file = new File(fileName);

+

+		    boolean found = false;

+		    for (int i = 0; i < profiles.size(); ++i) {

+			if (profiles.get(i) instanceof UserDefinedProfile) {

+			    UserDefinedProfile p = (UserDefinedProfile) profiles

+				    .get(i);

+			    if (p.getModelFile().equals(file)) {

+				found = true;

+				profile = p;

+				break;

+			    }

+			}

+		    }

+

+		    if (!found) {

+			UserDefinedProfile ud = new UserDefinedProfile(file);

+			profile = ud;

+		    }

+		    

+		    line = br.readLine().trim();		    

+		} else if (line.equals("<plugin>")) {

+		    String className = br.readLine().trim();

+		    for (int i = 0; i < profiles.size(); ++i) {

+			Profile p = (Profile) profiles.get(i);

+			if (p.getClass().getName().equals(className)) {

+			    profile = p;

+			    break;

+			}

+		    }

+		    

+		    line = br.readLine().trim();

+		}

+

+		if (profile != null) {

+		    pc.addProfile(profile);

+		}

+	    }

+	    project.setProfileConfiguration(pc);

+	} catch (Exception e) {

+	    // LOG.error("Exception", e);

+	    throw new OpenException(e);

+	}

+    }

+

+    @Override

+    public void save(ProjectMember member, Writer writer, boolean xmlFragment) throws SaveException {

+	try {

+	    if (member instanceof ProfileConfiguration) {

+		ProfileConfiguration pc = (ProfileConfiguration) member;

+		PrintWriter w = new PrintWriter(writer);

+

+		w.println("<?xml version = \"1.0\" encoding = \"UTF-8\" ?>");

+		w.println("<!DOCTYPE profile SYSTEM \"profile.dtd\" >");

+		w.println("<profile>");

+		

+		for (Object p : pc.getProfiles()) {

+		    Profile profile = (Profile) p;

+

+		    if (profile != pc.getDefaultProfile()) {

+			if (profile instanceof UserDefinedProfile) {

+			    w.println("\t\t<userDefined>");

+			    w.println("\t\t\t"+((UserDefinedProfile) profile)

+				    .getModelFile().getCanonicalPath());

+			    w.println("\t\t</userDefined>");

+			} else {

+			    w.println("\t\t<plugin>");

+			    w.println("\t\t\t"+p.getClass().getName());

+			    w.println("\t\t</plugin>");			    

+			}

+		    }

+		}

+

+		w.println("</profile>");

+	    }

+	} catch (Exception e) {

+	    e.printStackTrace();

+	    throw new SaveException(e);

+	}

+    }

+

+}


Modified: branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java?view=diff&rev=12860&p1=branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java&p2=branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java&r1=12859&r2=12860
==============================================================================
--- branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java	(original)
+++ branches/gsoc2007/maurelio1234/argouml/org/argouml/persistence/ZargoFilePersister.java	2007-06-16 04:57:48-0700
@@ -47,6 +47,7 @@
 import org.argouml.i18n.Translator;
 import org.argouml.kernel.Project;
 import org.argouml.kernel.ProjectMember;
+import org.argouml.uml.profile.ProfileConfiguration;
 import org.argouml.util.FileConstants;
 import org.argouml.util.ThreadUtils;
 
@@ -200,7 +201,7 @@
         throws OpenException, InterruptedException {
         
         ProgressMgr progressMgr = new ProgressMgr();
-        progressMgr.setNumberOfPhases(3 + UML_PHASES_LOAD);
+        progressMgr.setNumberOfPhases(4 + UML_PHASES_LOAD);
         ThreadUtils.checkIfInterrupted();
 
         try {
@@ -220,7 +221,8 @@
                     + encoding + "\" ?>");
             
             int pgmlCount = getPgmlCount(file);
-            boolean containsToDo = containsTodo(file);
+            boolean containsToDo    = containsTodo(file);
+            boolean containsProfile = containsProfile(file);
 
             // first read the .argo file from Zip
             ZipInputStream zis =
@@ -266,6 +268,10 @@
                     if (containsToDo) {
                         writer.println("<member type='todo' name='.todo' />");
                     }
+                    if (containsProfile) {
+                	String type = ProfileConfiguration.EXTENSION;
+                        writer.println("<member type='"+type+"' name='."+type+"' />");
+                    }
                 }
                 writer.println(line);
             }
@@ -318,6 +324,33 @@
                 reader.close();
             }
 
+            // save the profile information
+            zis = openZipStreamAt(file.toURL(), "." + ProfileConfiguration.EXTENSION);
+            
+            if (zis != null) {
+                InputStreamReader isr = new InputStreamReader(zis, encoding);
+                reader = new BufferedReader(isr);
+                
+                String firstLine = reader.readLine();
+                if (firstLine.startsWith("<?xml")) {
+                    // Skip the 2 lines
+                    //<?xml version="1.0" encoding="UTF-8" ?>
+                    //<!DOCTYPE todo SYSTEM "todo.dtd" >
+                    reader.readLine();
+                } else {
+                    writer.println(firstLine);
+                }
+                
+                
+
+                readerToWriter(reader, writer);
+
+                progressMgr.nextPhase();
+                
+                zis.close();
+                reader.close();
+            }
+
             writer.println("</uml>");
             writer.close();
             LOG.info("Completed combining files");
@@ -459,10 +492,18 @@
     }
     
     private boolean containsTodo(File file) throws IOException {
+	return containsType(file, "todo");
+    }
+
+    private boolean containsProfile(File file) throws IOException {
+	return containsType(file, ProfileConfiguration.EXTENSION);
+    }
+
+    private boolean containsType(File file, String type) throws IOException {
         ZipInputStream zis = new ZipInputStream(file.toURL().openStream());
         ZipEntry entry = zis.getNextEntry();
         while (entry != null) {
-            if (entry.getName().endsWith(".todo")) {
+            if (entry.getName().endsWith("." + type)) {
                 return true;
             }
             entry = zis.getNextEntry();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.