directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r651611 - in /directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations: ./ lib/ src/main/java/org/apache/directory/studio/apacheds/experimentations/model/
Date Fri, 25 Apr 2008 14:07:33 GMT
Author: pamarcelot
Date: Fri Apr 25 07:07:32 2008
New Revision: 651611

URL: http://svn.apache.org/viewvc?rev=651611&view=rev
Log:
o Added dom4j dependency.
o Added an empty constructor and a method to create a new ID to the ServerInstance class.
o Added an IO class to read/write an XML file containing server instances.

Added:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/dom4j-1.6.1.jar
  (with props)
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIOException.java
Modified:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath?rev=651611&r1=651610&r2=651611&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/.classpath
Fri Apr 25 07:07:32 2008
@@ -8,5 +8,6 @@
 	<classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/>
 	<classpathentry kind="lib" path="lib/slf4j-api-1.4.3.jar"/>
 	<classpathentry kind="lib" path="lib/slf4j-log4j12-1.4.3.jar"/>
+	<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
 	<classpathentry kind="output" path="target"/>
 </classpath>

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/dom4j-1.6.1.jar
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/dom4j-1.6.1.jar?rev=651611&view=auto
==============================================================================
Binary file - no diff available.

Propchange: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/lib/dom4j-1.6.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java?rev=651611&r1=651610&r2=651611&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
Fri Apr 25 07:07:32 2008
@@ -20,6 +20,9 @@
 package org.apache.directory.studio.apacheds.experimentations.model;
 
 
+import java.util.UUID;
+
+
 /**
  * This class represents an Apache DS instance.
  *
@@ -37,6 +40,14 @@
 
     /**
      * Creates a new instance of ApacheDsInstance.
+     */
+    public ServerInstance()
+    {
+    }
+
+
+    /**
+     * Creates a new instance of ApacheDsInstance.
      *
      * @param name
      *      the name of the instance
@@ -95,5 +106,17 @@
     public void setId( String id )
     {
         this.id = id;
+    }
+
+
+    /**
+     * Creates a new ID.
+     *
+     * @return
+     *      a new ID
+     */
+    public static String createId()
+    {
+        return UUID.randomUUID().toString();
     }
 }

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java?rev=651611&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
Fri Apr 25 07:07:32 2008
@@ -0,0 +1,180 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.experimentations.model;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+
+/**
+ * This class is used to read/write the 'servers.xml' file.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServersHandlerIO
+{
+    // XML tags and attributes
+    private static final String SERVER_INSTANCES_TAG = "serverInstances";
+    private static final String SERVER_INSTANCE_TAG = "serverInstance";
+    private static final String SERVER_ID_ATTRIBUTE = "id";
+    private static final String SERVER_NAME_ATTRIBUTE = "name";
+
+
+    /**
+     * Reads the given input stream.
+     *
+     * @param stream
+     *      the input stream
+     * @return
+     *      
+     * @throws ServersHandlerIOException
+     */
+    public static List<ServerInstance> read( InputStream stream ) throws ServersHandlerIOException
+    {
+        List<ServerInstance> serverInstances = new ArrayList<ServerInstance>();
+
+        SAXReader saxReader = new SAXReader();
+        Document document = null;
+
+        try
+        {
+            document = saxReader.read( stream );
+        }
+        catch ( DocumentException e )
+        {
+            throw new ServersHandlerIOException( e.getMessage() );
+        }
+
+        Element rootElement = document.getRootElement();
+        if ( !rootElement.getName().equals( SERVER_INSTANCES_TAG ) )
+        {
+            throw new ServersHandlerIOException( "The file does not seem to be a valid servers
file." );
+        }
+
+        for ( Iterator<?> i = rootElement.elementIterator( SERVER_INSTANCE_TAG ); i.hasNext();
)
+        {
+            serverInstances.add( readServerInstance( ( Element ) i.next() ) );
+        }
+
+        return serverInstances;
+    }
+
+
+    /**
+     * Reads a server instance element.
+     *
+     * @param element
+     *      the element
+     * @return
+     *      the corresponding {@link ServerInstance}
+     */
+    private static ServerInstance readServerInstance( Element element )
+    {
+        ServerInstance serverInstance = new ServerInstance();
+
+        // ID
+        Attribute idAttribute = element.attribute( SERVER_ID_ATTRIBUTE );
+        if ( idAttribute != null )
+        {
+            serverInstance.setId( idAttribute.getValue() );
+        }
+
+        // Name
+        Attribute nameAttribute = element.attribute( SERVER_NAME_ATTRIBUTE );
+        if ( nameAttribute != null )
+        {
+            serverInstance.setName( nameAttribute.getValue() );
+        }
+
+        return serverInstance;
+    }
+
+
+    /**
+     * Writes the list of server instances to the given stream.
+     *
+     * @param serverInstances
+     *      the server instances
+     * @param outputStream
+     *      the output stream
+     * @throws IOException
+     *      if an error occurs when writing to the stream
+     */
+    public static void write( List<ServerInstance> serverInstances, OutputStream outputStream
) throws IOException
+    {
+        // Creating the Document
+        Document document = DocumentHelper.createDocument();
+
+        // Creating the root element
+        Element root = document.addElement( SERVER_INSTANCES_TAG );
+
+        if ( serverInstances != null )
+        {
+            for ( ServerInstance serverInstance : serverInstances )
+            {
+                addServerInstance( serverInstance, root );
+            }
+        }
+
+        // Writing the file to the stream
+        OutputFormat outformat = OutputFormat.createPrettyPrint();
+        outformat.setEncoding( "UTF-8" );
+        XMLWriter writer = new XMLWriter( outputStream, outformat );
+        writer.write( document );
+        writer.flush();
+    }
+
+
+    /**
+     * Adds the XML representation of the server instance to the given parent. 
+     *
+     * @param serverInstance
+     *      the server instance
+     * @param parent
+     *      the parent element
+     */
+    private static void addServerInstance( ServerInstance serverInstance, Element parent
)
+    {
+        // Server instance element
+        Element serverInstanceElement = parent.addElement( SERVER_INSTANCE_TAG );
+
+        // ID
+        serverInstanceElement.addAttribute( SERVER_ID_ATTRIBUTE, serverInstance.getId() );
+
+        // Name
+        serverInstanceElement.addAttribute( SERVER_NAME_ATTRIBUTE, serverInstance.getName()
);
+    }
+}

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIOException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIOException.java?rev=651611&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIOException.java
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIOException.java
Fri Apr 25 07:07:32 2008
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.experimentations.model;
+
+
+/**
+ * This exception can be raised when an error occurs when loading or saving 
+ * the server instances to the store.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServersHandlerIOException extends Exception
+{
+    private static final long serialVersionUID = 1L;
+
+
+    /**
+     * Creates a new instance of ServersHandlerIOException.
+     *
+     * @param message
+     *      the detail message
+     */
+    public ServersHandlerIOException( String message )
+    {
+        super( message );
+    }
+}



Mime
View raw message