taylor      02/04/05 17:52:11

  Modified:    src/java/org/apache/jetspeed/om/profile/psml
                        PsmlPortlets.java
               src/java/org/apache/jetspeed/services/psmlmanager
                        TestMarshalPsml.java
  Log:
  added marshalling of references. Next: we need a feature in the customizer to add 
references.
  Currently references can only be added by editing the psml file directly.
  
  Revision  Changes    Path
  1.4       +35 -13    
jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/psml/PsmlPortlets.java
  
  Index: PsmlPortlets.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/profile/psml/PsmlPortlets.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PsmlPortlets.java 4 Apr 2002 18:39:49 -0000       1.3
  +++ PsmlPortlets.java 6 Apr 2002 01:52:11 -0000       1.4
  @@ -64,7 +64,7 @@
    * suitable for Castor XML serialization.
    * 
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Sean Taylor</a>
  - * @version $Id: PsmlPortlets.java,v 1.3 2002/04/04 18:39:49 taylor Exp $
  + * @version $Id: PsmlPortlets.java,v 1.4 2002/04/06 01:52:11 taylor Exp $
    */
   public class PsmlPortlets extends PsmlIdentityElement implements Portlets, 
java.io.Serializable                                                
   {
  @@ -114,7 +114,17 @@
   
       public Vector getPortlets()
       {
  -        return this.portlets;
  +        Vector v = new Vector();
  +        for (int ix=0; ix < this.portlets.size(); ix++)
  +        {
  +            Portlets p = (Portlets)this.portlets.get(ix);
  +            if (p instanceof Reference)
  +            {
  +                continue;
  +            }
  +            v.add(p);
  +        }
  +        return v;
       }
   
       public void setPortlets(Vector portlets)
  @@ -127,12 +137,22 @@
           return this.refs;
       }
   
  -    public void setReferences(Vector refs)
  +    public void addPortlets(PsmlPortlets p)
  +    {
  +        portlets.addElement(p);
  +    } 
  +
  +    public void addReference(PsmlReference ref) 
       {
  -        // DST: LEFT OFF HERE: WHY THE HELL ISN'T CASTOR CALLING THIS FUCKING METHOD
  -        // I THINK I HAVE 'DIRECT' SET ON -- WHAT GIVES?
  -        this.refs = refs;
  -        this.portlets.addAll(this.refs);
  +       refs.addElement(ref);
  +       portlets.addElement(ref);
  +    }
  +
  +    public void addReference(Reference ref)
  +        throws java.lang.IndexOutOfBoundsException
  +    {
  +        refs.addElement(ref);
  +        portlets.addElement(ref);
       }
   
       public int getEntryCount()
  @@ -160,7 +180,14 @@
       public Portlets removePortlets(int index)
       {
           Object obj = portlets.elementAt(index);
  +        if (null == obj)
  +            return (Portlets)obj;
  +
           portlets.removeElementAt(index);
  +        if (obj instanceof Reference)
  +        {
  +            refs.remove(obj);                    
  +        }
           return (Portlets) obj;
       } 
   
  @@ -168,6 +195,7 @@
       {
           Object obj = refs.elementAt(index);
           refs.removeElementAt(index);
  +        portlets.remove(obj);
           return (Reference) obj;
       }
   
  @@ -230,12 +258,6 @@
       {
           portlets.addElement(p);
       } 
  -
  -    public void addReference(Reference ref)
  -        throws java.lang.IndexOutOfBoundsException
  -    {
  -        refs.addElement(ref);
  -    }
   
   
       public Entry[] getEntriesArray()
  
  
  
  1.5       +92 -16    
jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/TestMarshalPsml.java
  
  Index: TestMarshalPsml.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/TestMarshalPsml.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestMarshalPsml.java      4 Apr 2002 18:39:50 -0000       1.4
  +++ TestMarshalPsml.java      6 Apr 2002 01:52:11 -0000       1.5
  @@ -2,8 +2,12 @@
   
   import java.io.File;
   import java.io.FileReader;
  +import java.io.Writer;
  +import java.io.FileWriter;
  +import java.io.IOException;
   
   import java.util.Iterator;
  +import java.util.Vector;
   
   // Junit imports
   import junit.framework.Test;
  @@ -13,10 +17,15 @@
   //castor support
   import org.exolab.castor.xml.MarshalException;
   import org.exolab.castor.xml.Unmarshaller;
  +import org.exolab.castor.xml.Marshaller;
   import org.exolab.castor.xml.ValidationException;
   import org.exolab.castor.mapping.Mapping;
   import org.exolab.castor.mapping.MappingException;
   import org.xml.sax.InputSource;
  +// serialization support
  +import org.apache.xml.serialize.Serializer;
  +import org.apache.xml.serialize.XMLSerializer;
  +import org.apache.xml.serialize.OutputFormat;
   
   import org.apache.jetspeed.om.profile.*;
   
  @@ -31,7 +40,7 @@
    * TestMarshalPsml
    *
    * @author <a href="[EMAIL PROTECTED]">David Sean Taylor</a>
  - * @version $Id: TestMarshalPsml.java,v 1.4 2002/04/04 18:39:50 taylor Exp $
  + * @version $Id: TestMarshalPsml.java,v 1.5 2002/04/06 01:52:11 taylor Exp $
    */
   //public class TestMarshalPsml extends ServletTestCase {
   public class TestMarshalPsml extends TestCase {    
  @@ -154,8 +163,11 @@
                   InputSource is = new InputSource( new FileReader(map) );
                   is.setSystemId( mapFile );
                   mapping.loadMapping( is );
  +                
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
                   Unmarshaller unmarshaller = new Unmarshaller(mapping);
                   Portlets rootset = (Portlets)unmarshaller.unmarshal(reader);
  +                
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
  +
                   assertTrue(rootset.getName().equals("theRootSet"));
                   assertTrue(rootset.getId().equals("01"));
   
  @@ -300,29 +312,16 @@
                   Entry ent = epr2.getEntry(0);
                   assertTrue(ent.getParent().equals("Apacheweek"));
   
  -                // LEFT OFF HERE: need to get refs put in the fricken portlets 
collection
                   Iterator itt = p.getPortletsIterator();
                   while (itt.hasNext())
                   {
                       Portlets pp = (Portlets)itt.next();
  -                    System.out.println(" %%% " + pp.getId());
  -                    if (pp instanceof Reference)
  -                    {
  -                        System.out.println(" %%% WHOOPEE A REF: " + pp.getId());
  -                    }
  -                }
  -                Iterator itrr = p.getReferenceIterator();
  -                while (itrr.hasNext())
  -                {
  -                    Portlets pp = (Portlets)itrr.next();
  -                    System.out.println(" %%% " + pp.getId());
  +                    System.out.println(" PORTLETS %%% " + pp.getId());
                       if (pp instanceof Reference)
                       {
  -                        System.out.println(" %%% WHOOPEE A REF: " + pp.getId());
  +                        System.out.println(" PORTLETS %%% REF: " + pp.getId());
                       }
                   }
  -
  -
               }
               catch (Exception e)
               {
  @@ -411,5 +410,82 @@
           }
       }
   
  +    public void testMarshalPsml() throws Exception 
  +    {
  +        System.out.println("Testing marshalling of PSML on base *** IdentityElement 
***");
  +
  +        String psmlFile = "../webapp/WEB-INF/psml/test/testcaseMarshall.psml";
  +
  +        Mapping mapping = null;
  +        String mapFile = getMappingFileName();
  +        File map = new File(mapFile);
  +        if (map.exists() && map.isFile() && map.canRead())
  +        {
  +            try
  +            {
  +                FileReader reader = new FileReader(psmlFile);
  +                mapping = new Mapping();
  +                InputSource is = new InputSource( new FileReader(map) );
  +                is.setSystemId( mapFile );
  +                mapping.loadMapping( is );
  +                
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
  +                Unmarshaller unmarshaller = new Unmarshaller(mapping);
  +                Portlets rootset = (Portlets)unmarshaller.unmarshal(reader);
  +                
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++");
  +
  +                assertTrue(rootset.getName().equals("theRootSet"));
  +                assertTrue(rootset.getId().equals("01"));
  +
  +                Iterator itt = rootset.getPortletsIterator();
  +                while (itt.hasNext())
  +                {
  +                    Portlets pp = (Portlets)itt.next();
  +                    System.out.println(" PORTLETS %%% " + pp.getId());
  +                    if (pp instanceof Reference)
  +                    {
  +                        System.out.println(" PORTLETS %%% REF: " + pp.getId());
  +                    }
  +                }
  +
  +                Iterator itr = rootset.getReferenceIterator();
  +                while (itr.hasNext())
  +                {
  +                    Reference r = (Reference)itr.next();
  +                    System.out.println(" REFERENCE %%% " + r.getId());
  +                }
  +
  +                OutputFormat format = new OutputFormat();
  +                format.setIndenting(true);
  +                format.setIndent(4);
  +    
  +                File f = new File("marshalled.psml");
  +                FileWriter writer = null;
  +
  +                writer = new FileWriter(f);
  +
  +                
System.out.println("-----------------------------------------------------------------");
  +                Serializer serializer = new XMLSerializer(writer, format); 
  +                Marshaller marshaller = new 
Marshaller(serializer.asDocumentHandler());
  +                marshaller.setMapping(mapping);
  +                marshaller.marshal(rootset);
  +                
System.out.println("-----------------------------------------------------------------");
  +                System.out.println("done");
  +
  +            }
  +            catch (Exception e)
  +            {
  +                String errmsg = "Error in psml mapping creation: " + e.toString();
  +                e.printStackTrace();
  +                System.err.println(errmsg);
  +                assertNotNull(errmsg, null);
  +            }
  +        }
  +        else
  +        {
  +            String errmsg = "PSML Mapping not found or not a file or unreadable: ";
  +            System.err.println(errmsg);
  +            assertNotNull(errmsg, null);
  +        }  
  +    }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to