You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ob...@apache.org on 2004/02/02 21:15:29 UTC

cvs commit: avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/docs/eclipse/html/downloads .cvsignore

oberhack    2004/02/02 12:15:29

  Modified:    ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource
                        XMLResource.java TemplateResource.java
                        SystemResource.java
               ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/xmlmodel
                        XStream.java AttributeContainerConverter.java
               ide/org.apache.avalon.ide.eclipse.core plugin.xml .classpath
               ide/org.apache.avalon.ide.eclipse.core/docs/eclipse/html/downloads
                        .cvsignore
  Added:       ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource
                        Test.java
  Log:
  xstream 0.2
  
  Revision  Changes    Path
  1.2       +0 -1      avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/XMLResource.java
  
  Index: XMLResource.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/XMLResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLResource.java	26 Jan 2004 08:36:48 -0000	1.1
  +++ XMLResource.java	2 Feb 2004 20:15:28 -0000	1.2
  @@ -71,7 +71,6 @@
       {
           super();
           xs = new XStream();
  -        xs.registerConverter(new AttributeContainerConverter(xs.getClassMapper()));
       }
   
       public void alias(String name, Class clazz)
  
  
  
  1.2       +16 -6     avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/TemplateResource.java
  
  Index: TemplateResource.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/TemplateResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TemplateResource.java	26 Jan 2004 08:36:48 -0000	1.1
  +++ TemplateResource.java	2 Feb 2004 20:15:28 -0000	1.2
  @@ -117,7 +117,12 @@
                       {
                           if ((line.indexOf(key)) != -1)
                           {
  -                            line = line.replaceAll(key, (String) map.get(key));
  +                            /* 
  +                             * to retain 1.3.1 compatibiliy (WSAD) dont use "replace"
  +                             * line = line.replaceAll(key, (String) map.get(key));
  +                             */
  +                            line = SystemResource.replaceAll(line, key, (String) map.get(key)); 
  +                            
                           }
                       }
                   }
  @@ -132,23 +137,28 @@
               System.out.println(e);
           }
       }
  -    public static String replaceParam(String input, DynProjectParam param)
  +    public static String replaceParam(String line, DynProjectParam map)
       {
   
  -        Iterator it = param.keySet().iterator();
  +        Iterator it = map.keySet().iterator();
           String key;
   
           while (it.hasNext())
           {
               if ((key = (String) it.next()).startsWith("%"))
               {
  -                if ((input.indexOf(key)) != -1)
  +                if ((line.indexOf(key)) != -1)
                   {
  -                    input = input.replaceAll(key, (String) param.get(key));
  +                    /* 
  +                     * to retain 1.3.1 compatibiliy (WSAD) dont use "replace"
  +                     * line = line.replaceAll(key, (String) map.get(key));
  +                     */
  +                    line = SystemResource.replaceAll(line, key, (String) map.get(key));
  +               
                   }
               }
           }
  -        return input;
  +        return line;
   
       }
       /**
  
  
  
  1.2       +114 -7    avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/SystemResource.java
  
  Index: SystemResource.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/SystemResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SystemResource.java	26 Jan 2004 08:36:48 -0000	1.1
  +++ SystemResource.java	2 Feb 2004 20:15:28 -0000	1.2
  @@ -47,8 +47,9 @@
   import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.io.InputStreamReader;
  -import java.nio.channels.FileChannel;
  +import java.io.OutputStream;
   
   import org.apache.avalon.ide.eclipse.merlin.core.MerlinDeveloperCore;
   
  @@ -66,15 +67,100 @@
       {
           super();
       }
  +    /*
  +	 * java 1.4 version to retain 1.3.1 compatibility (WSAD!) dont use it now
  +	 * 
  +	 * public static void copyFile(File in, File out) throws Exception {
  +	 * FileChannel sourceChannel = new FileInputStream(in).getChannel();
  +	 * FileChannel destinationChannel = new FileOutputStream(out).getChannel();
  +	 * sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
  +	 * sourceChannel.close(); destinationChannel.close(); }
  +	 */
  +    /*
  +	 * This method makes a copy of a file.
  +	 * 
  +	 * java CopyFile source.dat copy.dat
  +	 * 
  +	 * This command will fail if a file named copy.dat already exists. To force
  +	 * the command to succede, add the -f command line option:
  +	 * 
  +	 * java CopyFile -f source.dat copy.dat
  +	 * 
  +	 * Either command will fail if the source file does not exist.
  +	 */
   
       public static void copyFile(File in, File out) throws Exception
       {
  -        FileChannel sourceChannel = new FileInputStream(in).getChannel();
  -        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
  -        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
  -        sourceChannel.close();
  -        destinationChannel.close();
  -    }
  +        InputStream source; // Stream for reading from the source file.
  +        OutputStream copy; // Stream for writing the copy.
  +        boolean force = true; // This is set to true if the "-f" option is
  +							  // specified.
  +        int byteCount; // The number of bytes copied from the source file.
  +
  +        /* Create the input stream. If an error occurs, end the program. */
  +
  +        try
  +        {
  +            source = new FileInputStream(in);
  +        } catch (FileNotFoundException e)
  +        {
  +            MerlinDeveloperCore.log(e, "Can't find file \"" + in.getName() + "\".");
  +            return;
  +        }
  +
  +        /*
  +		 * If the output file alrady exists and the -f option was not
  +		 * specified,
  +		 */
  +
  +        File file = out;
  +        if (file.exists() && force == false)
  +        {
  +            MerlinDeveloperCore.log(null, "Output file exists.  Use the -f option to replace it.");
  +            return;
  +        }
  +
  +        /* Create the output stream. If an error occurs, end the program. */
  +
  +        try
  +        {
  +            copy = new FileOutputStream(out);
  +        } catch (IOException e)
  +        {
  +            System.out.println("Can't open output file \"" + out.getName() + "\".");
  +            return;
  +        }
  +
  +        /*
  +		 * Copy one byte at a time from the input stream to the out put stream,
  +		 * ending when the read() method returns -1 (which is the signal that
  +		 * the end of the stream has been reached. If any error occurs, print
  +		 * an error message. Also print a message if the file has bee copied
  +		 */
  +
  +        byteCount = 0;
  +
  +        try
  +        {
  +            while (true)
  +            {
  +                int data = source.read();
  +                if (data < 0)
  +                    break;
  +                copy.write(data);
  +                byteCount++;
  +            }
  +            source.close();
  +            copy.close();
  +
  +        } catch (Exception e)
  +        {
  +            MerlinDeveloperCore.log(
  +                e,
  +                "Error occured while copying.  " + byteCount + " bytes copied.");
  +        }
  +
  +    } // end copyFile()
   
       public static String getFileContents(String fileName)
       {
  @@ -100,5 +186,26 @@
               MerlinDeveloperCore.log(e, "");
           }
           return buf.toString();
  +    }
  +    /**
  +     * @param pLine
  +     * @param pKey
  +     * @param pString
  +     * @return
  +     */
  +    public static String replaceAll(String source, String pKey, String pReplacement)
  +    {
  +        int start = 0;
  +        int next;
  +        StringBuffer in = new StringBuffer(source);
  +        StringBuffer out = new StringBuffer();
  +        while((next = in.indexOf(pKey, start)) != -1){
  +            out.append(source.substring(start, next));
  +            out.append(pReplacement);
  +            start = next + pKey.length();
  +        };
  +        out.append(source.substring(start, source.length()));
  +        
  +        return out.toString();
       }
   }
  
  
  
  1.1                  avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/Test.java
  
  Index: Test.java
  ===================================================================
  /*
   * Created on 30.01.2004
   *
   * To change the template for this generated file go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  package org.apache.avalon.ide.eclipse.core.resource;
  
  /**
   * @author Andreas Develop
   *
   * To change the template for this generated type comment go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  public class Test
  {
  
      public static void main(String[] args)
      {
          String str = SystemResource.replaceAll("hallo %test% gg %test% o", "%test%", "neu");
          Object obj = str;
      }
  }
  
  
  
  1.2       +25 -45    avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/xmlmodel/XStream.java
  
  Index: XStream.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/xmlmodel/XStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XStream.java	26 Jan 2004 08:36:49 -0000	1.1
  +++ XStream.java	2 Feb 2004 20:15:28 -0000	1.2
  @@ -41,8 +41,10 @@
    * Apache Software Foundation, please see <http://www.apache.org/> .
    */
   package org.apache.avalon.ide.eclipse.core.xmlmodel;
  -
   import com.thoughtworks.xstream.alias.DefaultClassMapper;
  +import com.thoughtworks.xstream.alias.ClassMapper;
  +import com.thoughtworks.xstream.alias.DefaultElementMapper;
  +import com.thoughtworks.xstream.alias.ElementMapper;
   import com.thoughtworks.xstream.converters.Converter;
   import com.thoughtworks.xstream.converters.ConverterLookup;
   import com.thoughtworks.xstream.converters.basic.*;
  @@ -65,29 +67,21 @@
   import java.io.Writer;
   import java.util.*;
   
  -/**
  - * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>*
  - */
  -public class XStream
  -{
  -
  -    /**
  -	 * @uml property=classMapper associationEnd={multiplicity={(1 1)}}
  -	 */
  -    private DefaultClassMapper classMapper = new DefaultClassMapper();
  -
  -    /**
  -	 * @uml property=converterLookup associationEnd={multiplicity={(1 1)}}
  -	 */
  -    private ConverterLookup converterLookup = new DefaultConverterLookup();
  +public class XStream {
   
  -    /**
  -	 * @uml property=xmlReaderDriver associationEnd={multiplicity={(1 1)}}
  -	 */
  +    private ConverterLookup converterLookup = new DefaultConverterLookup();
       private XMLReaderDriver xmlReaderDriver = new DomXMLReaderDriver();
  +    private ClassMapper classMapper;
  +    private ObjectFactory objectFactory;
  +
  +    public XStream() {
  +        this(new SunReflectionObjectFactory(), new DefaultClassMapper(), new DefaultElementMapper());
  +    }
  +
  +    public XStream(ObjectFactory objectFactory, ClassMapper classMapper, ElementMapper elementMapper) {
  +        this.classMapper = classMapper;
  +        this.objectFactory = objectFactory;
   
  -    public XStream()
  -    {
           alias("int", Integer.class);
           alias("float", Float.class);
           alias("double", Double.class);
  @@ -112,7 +106,9 @@
           alias("tree-map", TreeMap.class);
           alias("tree-set", TreeSet.class);
   
  -        registerConverter(new ObjectWithFieldsConverter(classMapper));
  +        registerConverter(new ObjectWithFieldsConverter(classMapper,elementMapper));
  +        // added to work with attributes. MerlinDeveloper
  +        registerConverter(new AttributeContainerConverter(classMapper,elementMapper));        
   
           registerConverter(new IntConverter());
           registerConverter(new FloatConverter());
  @@ -134,27 +130,22 @@
   
       }
   
  -    public void alias(String elementName, Class type, Class defaultImplementation)
  -    {
  +    public void alias(String elementName, Class type, Class defaultImplementation) {
           classMapper.alias(elementName, type, defaultImplementation);
       }
   
  -    public void alias(String elementName, Class type)
  -    {
  +    public void alias(String elementName, Class type) {
           alias(elementName, type, type);
       }
   
  -    public String toXML(Object obj)
  -    {
  +    public String toXML(Object obj) {
           Writer stringWriter = new StringWriter();
           XMLWriter xmlWriter = new PrettyPrintXMLWriter(stringWriter);
           toXML(obj, xmlWriter);
           return stringWriter.toString();
       }
   
  -    public void toXML(Object obj, XMLWriter xmlWriter)
  -    {
  -        ObjectFactory objectFactory = new SunReflectionObjectFactory();
  +    public void toXML(Object obj, XMLWriter xmlWriter) {
           ObjectTree objectGraph = new ReflectionObjectGraph(obj, objectFactory);
           Converter rootConverter = converterLookup.lookupConverterForType(obj.getClass());
           xmlWriter.startElement(classMapper.lookupName(obj.getClass()));
  @@ -162,13 +153,11 @@
           xmlWriter.endElement();
       }
   
  -    public Object fromXML(String xml)
  -    {
  +    public Object fromXML(String xml) {
           return fromXML(xmlReaderDriver.createReader(xml));
       }
   
  -    public Object fromXML(XMLReader xmlReader)
  -    {
  +    public Object fromXML(XMLReader xmlReader) {
           Class type = classMapper.lookupType(xmlReader.name());
           ObjectFactory objectFactory = new SunReflectionObjectFactory();
           ObjectTree objectGraph = new ReflectionObjectGraph(type, objectFactory);
  @@ -177,17 +166,8 @@
           return objectGraph.get();
       }
   
  -    public void registerConverter(Converter converter)
  -    {
  +    public void registerConverter(Converter converter) {
           converterLookup.registerConverter(converter);
  -    }
  -
  -    /**
  -	 * @return Returns the classMapper. @uml property=classMapper
  -	 */
  -    public DefaultClassMapper getClassMapper()
  -    {
  -        return classMapper;
       }
   
   }
  
  
  
  1.2       +38 -19    avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/xmlmodel/AttributeContainerConverter.java
  
  Index: AttributeContainerConverter.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/xmlmodel/AttributeContainerConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeContainerConverter.java	26 Jan 2004 08:36:49 -0000	1.1
  +++ AttributeContainerConverter.java	2 Feb 2004 20:15:28 -0000	1.2
  @@ -43,6 +43,7 @@
   package org.apache.avalon.ide.eclipse.core.xmlmodel;
   
   import com.thoughtworks.xstream.alias.ClassMapper;
  +import com.thoughtworks.xstream.alias.ElementMapper;
   import com.thoughtworks.xstream.converters.Converter;
   import com.thoughtworks.xstream.converters.ConverterLookup;
   import com.thoughtworks.xstream.objecttree.ObjectTree;
  @@ -60,10 +61,12 @@
   	 * @uml property=classMapper associationEnd={multiplicity={(1 1)}}
   	 */
       private ClassMapper classMapper;
  +    private ElementMapper elementMapper;
   
  -    public AttributeContainerConverter(ClassMapper classMapper)
  +    public AttributeContainerConverter(ClassMapper classMapper, ElementMapper elementMapper)
       {
           this.classMapper = classMapper;
  +        this.elementMapper = elementMapper;
       }
       public boolean canConvert(Class type)
       {
  @@ -73,6 +76,7 @@
       public void toXML(ObjectTree objectGraph, XMLWriter xmlWriter, ConverterLookup converterLookup)
       {
           String[] fieldNames = objectGraph.fieldNames();
  +        //        circularityTracker.track(objectGraph.get());
           for (int i = 0; i < fieldNames.length; i++)
           {
               String fieldName = fieldNames[i];
  @@ -81,7 +85,11 @@
   
               if (objectGraph.get() != null)
               {
  -                writeFieldAsXML(xmlWriter, fieldName, objectGraph, converterLookup);
  +                writeFieldAsXML(
  +                    xmlWriter,
  +                    elementMapper.toXml(fieldName),
  +                    objectGraph,
  +                    converterLookup);
               }
   
               objectGraph.pop();
  @@ -94,9 +102,25 @@
           ObjectTree objectGraph,
           ConverterLookup converterLookup)
       {
  +        xmlWriter.startElement(fieldName);
   
  -        xmlWriter.addAttribute(fieldName, (String) objectGraph.get());
  +        writeClassAttributeInXMLIfNotDefaultImplementation(objectGraph, xmlWriter);
  +        Converter converter = converterLookup.lookupConverterForType(objectGraph.type());
  +        converter.toXML(objectGraph, xmlWriter, converterLookup);
   
  +        xmlWriter.endElement();
  +    }
  +
  +    protected void writeClassAttributeInXMLIfNotDefaultImplementation(
  +        ObjectTree objectGraph,
  +        XMLWriter xmlWriter)
  +    {
  +        Class actualType = objectGraph.get().getClass();
  +        Class defaultType = classMapper.lookupDefaultType(objectGraph.type());
  +        if (!actualType.equals(defaultType))
  +        {
  +            xmlWriter.addAttribute("class", classMapper.lookupName(actualType));
  +        }
       }
   
       public void fromXML(
  @@ -116,16 +140,19 @@
                   objectGraph.set(xmlReader.attribute(fieldName));
                   objectGraph.pop();
                   //xmlReader.pop();
  -            } else if (xmlReader.childExists(fieldName))
  +            } else
               {
  -                objectGraph.push(fieldName);
  -                xmlReader.child(fieldName);
  -                Class type = determineWhichImplementationToUse(xmlReader, objectGraph);
  -                Converter converter = converterLookup.lookupConverterForType(type);
  -                converter.fromXML(objectGraph, xmlReader, converterLookup, type);
  +                while (xmlReader.nextChild())
  +                {
  +                    objectGraph.push(elementMapper.fromXml(xmlReader.name()));
  +
  +                    Class type = determineWhichImplementationToUse(xmlReader, objectGraph);
  +                    Converter converter = converterLookup.lookupConverterForType(type);
  +                    converter.fromXML(objectGraph, xmlReader, converterLookup, type);
  +                    objectGraph.pop();
   
  -                xmlReader.pop();
  -                objectGraph.pop();
  +                    xmlReader.pop();
  +                }
               }
           }
       }
  @@ -144,13 +171,5 @@
               type = classMapper.lookupType(classAttribute);
           }
           return type;
  -    }
  -
  -    private int read(String field, XMLReader reader)
  -    {
  -        reader.child(field);
  -        int result = Integer.parseInt(reader.text());
  -        reader.pop();
  -        return result;
       }
   }
  
  
  
  1.2       +2 -2      avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/plugin.xml
  
  Index: plugin.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/plugin.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- plugin.xml	26 Jan 2004 08:36:49 -0000	1.1
  +++ plugin.xml	2 Feb 2004 20:15:29 -0000	1.2
  @@ -2,7 +2,7 @@
   <plugin
      id="org.apache.avalon.MerlinDeveloperCore"
      name="MerlinDeveloper Core"
  -   version="0.0.1"
  +   version="0.0.2"
      provider-name="Apache Software Foundation"
      class="org.apache.avalon.ide.eclipse.merlin.core.MerlinDeveloperCore">
   
  @@ -10,7 +10,7 @@
         <library name="MerlinDeveloperCore.jar">
            <export name="*"/>
         </library>
  -      <library name="lib/xstream-0.1.jar"/>
  +      <library name="lib/xstream-0.2.jar"/>
         <library name="lib/xdoclet-1.2b4.jar"/>
         <library name="lib/xjavadoc-1.0.jar"/>
      </runtime>
  
  
  
  1.4       +1 -1      avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/.classpath
  
  Index: .classpath
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/.classpath,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- .classpath	27 Jan 2004 15:51:14 -0000	1.3
  +++ .classpath	2 Feb 2004 20:15:29 -0000	1.4
  @@ -5,6 +5,6 @@
   	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   	<classpathentry kind="lib" path="lib/xdoclet-1.2b4.jar"/>
   	<classpathentry kind="lib" path="lib/xjavadoc-1.0.jar"/>
  -	<classpathentry kind="lib" path="lib/xstream-0.1.jar"/>
  +	<classpathentry kind="lib" path="lib/xstream-0.2.jar"/>
   	<classpathentry kind="output" path="bin"/>
   </classpath>
  
  
  
  1.2       +1 -1      avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/docs/eclipse/html/downloads/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/docs/eclipse/html/downloads/.cvsignore,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- .cvsignore	27 Jan 2004 15:34:57 -0000	1.1
  +++ .cvsignore	2 Feb 2004 20:15:29 -0000	1.2
  @@ -1 +1 @@
  -MerlinDeveloper_0.0.1.zip
  +*.zip
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org