<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="output" path="target/classes"/>
<Export-Package>
org.argeo.slc.detached.*
</Export-Package>
+ <Import-Package>
+ *,
+ org.springframework.beans.factory;version="2.0",
+ org.springframework.beans.factory.support;version="2.0",
+ org.springframework.beans.factory.xml;version="2.0",
+ org.springframework.context;version="2.0",
+ org.springframework.context.support;version="2.0",
+ org.springframework.core.io;version="2.0"
+ </Import-Package>
</instructions>
</configuration>
</plugin>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
- <version>2.0.8</version>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.castor</groupId>
- <artifactId>castor</artifactId>
- <version>1.1.2</version>
- <exclusions>
- <exclusion>
- <groupId>adaptx</groupId>
- <artifactId>adaptx</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
import javax.xml.transform.Source;
public interface DetachedXmlConverter {
- public void marshallRequest(DetachedRequest request, Result result);
+ public void marshallCommunication(DetachedCommunication detCom,
+ Result result);
- public DetachedRequest unmarshallRequest(Source source);
-
- public void marshallAnswer(DetachedAnswer answer, Result result);
-
- public DetachedAnswer unmarshallAnswer(Source source);
+ public DetachedCommunication unmarshallCommunication(Source source);
}
}
}
+ public void marshallCommunication(DetachedCommunication detCom,
+ Result result) {
+ if (detCom instanceof DetachedRequest) {
+ marshallRequest((DetachedRequest) detCom, result);
+ } else if (detCom instanceof DetachedAnswer) {
+ marshallAnswer((DetachedAnswer) detCom, result);
+ } else {
+ throw new DetachedException("Unkown communication type "
+ + detCom.getClass());
+ }
+ }
+
+ public DetachedCommunication unmarshallCommunication(Source source) {
+ // Parse
+ DOMResult result = new DOMResult();
+ try {
+ copy.transform(source, result);
+ } catch (TransformerException e) {
+ throw new DetachedException("Could not copy xml source", e);
+ }
+ Element root = (Element) ((Document) result.getNode())
+ .getDocumentElement();
+
+ // Create objects
+ String requestType = root.getLocalName();
+ if (requestType.equals("detached-request")) {
+ DetachedRequest request = new DetachedRequest();
+ request.setUuid(root.getElementsByTagNameNS(
+ SLC_DETACHED_NAMESPACE_URI, "uuid").item(0)
+ .getTextContent());
+ request
+ .setRef(root.getElementsByTagNameNS(
+ SLC_DETACHED_NAMESPACE_URI, "ref").item(0)
+ .getTextContent());
+ request.setPath(root.getElementsByTagNameNS(
+ SLC_DETACHED_NAMESPACE_URI, "path").item(0)
+ .getTextContent());
+ Element propertiesElement = (Element) root.getElementsByTagNameNS(
+ SLC_DETACHED_NAMESPACE_URI, "properties").item(0);
+ NodeList propElements = propertiesElement.getElementsByTagNameNS(
+ SLC_DETACHED_NAMESPACE_URI, "prop");
+ Properties properties = new Properties();
+ for (int i = 0; i < propElements.getLength(); i++) {
+ Element propElement = (Element) propElements.item(i);
+ String key = propElement.getAttribute("key");
+ String value = propElement.getTextContent();
+ properties.setProperty(key, value);
+ }
+ request.setProperties(properties);
+ return request;
+ } else {
+ throw new DetachedException(requestType + " not implemented.");
+ }
+ }
+
public void marshallAnswer(DetachedAnswer answer, Result result) {
StringBuffer buf = new StringBuffer("");
buf.append("<slc-det:detached-answer xmlns:slc-det=\""
}
public void marshallRequest(DetachedRequest request, Result result) {
- throw new DetachedException("Not implemented.");
- }
-
- public DetachedAnswer unmarshallAnswer(Source source) {
- throw new DetachedException("Not implemented.");
+ throw new DetachedException(" Not implemented.");
}
public DetachedRequest unmarshallRequest(Source source) {
import org.argeo.slc.detached.DetachedDriver;
import org.argeo.slc.detached.DetachedExecutionServer;
import org.argeo.slc.detached.DetachedRequest;
+import org.argeo.slc.detached.DetachedXmlConverter;
public abstract class AbstractDriver implements DetachedDriver {
private boolean active = true;
private DetachedExecutionServer executionServer = null;
+ private DetachedXmlConverter xmlConverter = null;
+
public synchronized void start() {
Thread driverThread = new Thread(new Runnable() {
this.active = active;
}
+ public DetachedXmlConverter getXmlConverter() {
+ return xmlConverter;
+ }
+
+ public void setXmlConverter(DetachedXmlConverter xmlConverter) {
+ this.xmlConverter = xmlConverter;
+ }
+
}
package org.argeo.slc.detached.drivers;
import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.detached.DetachedAnswer;
private File processedRequestsDir;
private File processedAnswersDir;
+ private String lockFileExt = "lck";
+ private FileFilter notLockFileFilter = new NotFileFilter(
+ new SuffixFileFilter("." + lockFileExt));
+
public synchronized DetachedRequest receiveRequest() throws Exception {
DetachedRequest request = (DetachedRequest) receiveFile(requestsDir,
processedRequestsDir);
protected void sendFile(File dir, DetachedCommunication detCom)
throws Exception {
- File file = new File(dir.getPath() + File.separator + detCom.getUuid());
+ final File file;
+ if (getXmlConverter() != null)
+ file = new File(dir.getPath() + File.separator + detCom.getUuid()
+ + ".xml");
+ else
+ file = new File(dir.getPath() + File.separator + detCom.getUuid());
+
File lockFile = createLockFile(file);
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- file));
- out.writeObject(detCom);
- out.close();
+ if (getXmlConverter() != null) {
+ FileOutputStream outFile = new FileOutputStream(file);
+ try {
+ StreamResult result = new StreamResult(outFile);
+ getXmlConverter().marshallCommunication(detCom, result);
+ } finally {
+ IOUtils.closeQuietly(outFile);
+ }
+ } else {
+ ObjectOutputStream out = new ObjectOutputStream(
+ new FileOutputStream(file));
+ try {
+ out.writeObject(detCom);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ }
lockFile.delete();
}
if (!dir.exists())
throw new DetachedException("Dir " + dir + " does not exist.");
- File[] files = dir.listFiles();
+ File[] files = dir.listFiles(notLockFileFilter);
if (files.length > 0)
file = files[0];
else {
File lockFile = nameLockFile(file);
while (lockFile.exists())
- // TODO: implements time out
+ // FIXME: implements time out
Thread.sleep(100);
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
- DetachedCommunication detCom = (DetachedCommunication) in.readObject();
- in.close();
-
+ // Read the file
+ final DetachedCommunication detCom;
+ if (FilenameUtils.getExtension(file.getName()).equals("xml")) {
+ if (getXmlConverter() == null)
+ throw new DetachedException("No XML converter defined.");
+ FileInputStream in = new FileInputStream(file);
+ try {
+ StreamSource source = new StreamSource(in);
+ detCom = getXmlConverter().unmarshallCommunication(source);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ } else {
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(
+ file));
+ try {
+ detCom = (DetachedCommunication) in.readObject();
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
// Move to processed dir
- file.renameTo(new File(processedDir.getAbsolutePath() + File.separator
- + file.getName()));
+ FileUtils.moveFileToDirectory(file, processedDir, false);
+ // file.renameTo(new File(processedDir.getAbsolutePath() +
+ // File.separator
+ // + file.getName()));
return detCom;
-
}
protected File createLockFile(File file) {
}
protected File nameLockFile(File file) {
- return new File(file.getAbsolutePath() + ".lck");
+ return new File(file.getAbsolutePath() + "." + lockFileExt);
}
public void setBaseDir(File baseDir) {
ached.ui;uses:="org.argeo.slc.detached",org.argeo.slc.detached;uses:=\r
"org.apache.commons.logging,org.springframework.context.support,org.s\r
pringframework.core.io,org.springframework.context,org.springframewor\r
- k.beans.factory.xml,org.argeo.slc.detached.drivers,org.springframewor\r
- k.beans.factory.support,org.argeo.slc.detached.admin,org.osgi.framewo\r
- rk,org.springframework.beans.factory",org.argeo.slc.detached.drivers;\r
- uses:="org.apache.commons.logging,org.argeo.slc.detached,org.springfr\r
+ k.beans.factory.xml,javax.xml.transform.dom,org.argeo.slc.detached.dr\r
+ ivers,org.w3c.dom,org.springframework.beans.factory.support,org.argeo\r
+ .slc.detached.admin,javax.xml.transform,javax.xml.transform.stream,or\r
+ g.osgi.framework,org.apache.commons.io,org.springframework.beans.fact\r
+ ory",org.argeo.slc.detached.drivers;uses:="org.apache.commons.logging\r
+ ,org.apache.commons.io.filefilter,javax.xml.transform,javax.xml.trans\r
+ form.stream,org.apache.commons.io,org.argeo.slc.detached,org.springfr\r
amework.beans.factory"\r
Built-By: mbaudier\r
Tool: Bnd-0.0.255\r
Bundle-Vendor: Argeo\r
Build-Jdk: 1.6.0\r
Bundle-Version: 0.11.1.SNAPSHOT\r
-Bnd-LastModified: 1223022716810\r
+Bnd-LastModified: 1223214001545\r
Bundle-ManifestVersion: 2\r
Bundle-Activator: org.argeo.slc.detached.Activator\r
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt\r
Bundle-Description: SLC Distribution\r
-Import-Package: org.apache.commons.logging,org.argeo.slc.detached,org.\r
- argeo.slc.detached.admin,org.argeo.slc.detached.drivers,org.argeo.slc\r
- .detached.ui,org.osgi.framework,org.springframework.beans.factory,org\r
- .springframework.beans.factory.support,org.springframework.beans.fact\r
- ory.xml,org.springframework.context,org.springframework.context.suppo\r
- rt,org.springframework.core.io\r
+Import-Package: javax.xml.transform,javax.xml.transform.dom,javax.xml.\r
+ transform.stream,org.apache.commons.io;version="1.4",org.apache.commo\r
+ ns.io.filefilter;version="1.4",org.apache.commons.logging,org.argeo.s\r
+ lc.detached,org.argeo.slc.detached.admin,org.argeo.slc.detached.drive\r
+ rs,org.argeo.slc.detached.ui,org.osgi.framework,org.springframework.b\r
+ eans.factory;version="2.0",org.springframework.beans.factory.support;\r
+ version="2.0",org.springframework.beans.factory.xml;version="2.0",org\r
+ .springframework.context;version="2.0",org.springframework.context.su\r
+ pport;version="2.0",org.springframework.core.io;version="2.0",org.w3c\r
+ .dom\r
Bundle-SymbolicName: org.argeo.slc.detached\r
Bundle-DocURL: http://www.argeo.org\r
Originally-Created-By: Apache Maven Bundle Plugin\r
<bean id="slcDefault.detached.admin.closeSession"
class="org.argeo.slc.detached.admin.CloseSession">
</bean>
- <!--
- <bean id="jemmyTest" class="org.argeo.slc.jemmytest.DummyStep">
- </bean>
-
- <bean id="slcDefault.detached.admin.openSession"
- class="org.argeo.slc.detached.DetachedExecutionServerImpl">
- <property name="driver" ref="driver" />
- </bean>
-
- <bean id="driver"
- class="org.argeo.slc.detached.drivers.FileDriver">
- <property name="baseDir" value="file:${slc.workDir}/detached" />
- </bean>
- -->
+
+ <bean id="slcDefault.detached.xmlConverterCompat"
+ class="org.argeo.slc.detached.DetachedXmlConverterCompat">
+ </bean>
</beans>
\ No newline at end of file