From ee596e5eb61a49931dde8794bdf3c30a9b5852ba Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 13 May 2011 13:57:16 +0000 Subject: change to follow the pattern Luciano has in node-manager. Also take a copy of the html page from there to see what that's doing. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1102740 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/slaws/domain-view/pom.xml | 5 + .../org/apache/tuscany/sca/domain/Composite.java | 47 ++++ .../apache/tuscany/sca/domain/CompositeImpl.java | 40 ++++ .../java/org/apache/tuscany/sca/domain/Domain.java | 85 +++++++ .../org/apache/tuscany/sca/domain/DomainImpl.java | 90 ++++++++ .../org/apache/tuscany/sca/domain/DomainView.java | 56 +++++ .../org/apache/tuscany/sca/domain/Tuscany.java | 133 +++++++++++ .../src/main/resources/domain.composite | 26 ++- .../src/main/resources/ui/component.gif | Bin 0 -> 547 bytes .../src/main/resources/ui/composite.gif | Bin 0 -> 536 bytes .../domain-view/src/main/resources/ui/index.html | 250 +++++++++++++++++++++ .../src/main/resources/ui/interface.gif | Bin 0 -> 734 bytes .../domain-view/src/main/resources/ui/property.gif | Bin 0 -> 333 bytes .../src/main/resources/ui/reference.gif | Bin 0 -> 524 bytes .../domain-view/src/main/resources/ui/service.gif | Bin 0 -> 513 bytes 15 files changed, 730 insertions(+), 2 deletions(-) create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/component.gif create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/composite.gif create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/index.html create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/interface.gif create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/property.gif create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/reference.gif create mode 100644 sandbox/slaws/domain-view/src/main/resources/ui/service.gif (limited to 'sandbox/slaws') diff --git a/sandbox/slaws/domain-view/pom.xml b/sandbox/slaws/domain-view/pom.xml index 9ddd29dc3c..6b68628752 100644 --- a/sandbox/slaws/domain-view/pom.xml +++ b/sandbox/slaws/domain-view/pom.xml @@ -40,6 +40,11 @@ tuscany-implementation-java-runtime 2.0-SNAPSHOT + + org.apache.tuscany.sca + tuscany-implementation-widget-runtime-dojo + 2.0-SNAPSHOT + org.apache.tuscany.sca tuscany-binding-sca-runtime diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java new file mode 100644 index 0000000000..8163f160aa --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.sca.domain; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Composite { + + @GET + @Produces( {MediaType.TEXT_HTML}) + @Path("{domainname}/composite") + public String get(); + + + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + @Path("{domainname}/composite/{compositename}") + public String getComposite(@PathParam("compositename") String domainName); + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java new file mode 100644 index 0000000000..1011a5b693 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.domain; + +/** + * Some hand crafted HTTP code to help me think about what info is missing + * from the domain registry + * + */ +public class CompositeImpl implements Composite { + + public String get() { + String outputHTML = "

get"; + return outputHTML; + } + + + public String getComposite(String domainName) { + String outputHTML = "

get composite"; + return outputHTML; + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java new file mode 100644 index 0000000000..773e649202 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java @@ -0,0 +1,85 @@ +/* + * 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.tuscany.sca.domain; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Domain { + + @GET + @Produces( {MediaType.TEXT_HTML}) + public String get(); + + @Path("{domainname}") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getDomainServiceDocument(@PathParam("domainname") String domainName); + + @Path("{domainname}/contribution") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getContributions(@PathParam("domainname") String domainName); + + @Path("{domainname}/composite") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getComposites(@PathParam("domainname") String domainName); + + @Path("{domainname}/component") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getComponents(@PathParam("domainname") String domainName); + + @Path("{domainname}/endpoints") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getEndpoints(@PathParam("domainname") String domainName); + + @Path("{domainname}/node") + @GET + @Produces( {MediaType.APPLICATION_ATOM_XML, + MediaType.APPLICATION_JSON, + MediaType.APPLICATION_XML, + MediaType.TEXT_HTML}) + public String getNodes(@PathParam("domainname") String domainName); + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java new file mode 100644 index 0000000000..41ca341763 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java @@ -0,0 +1,90 @@ +/* + * 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.tuscany.sca.domain; + +import java.io.File; +import java.util.List; + +import org.apache.tuscany.sca.impl.NodeImpl; + + +/** + * Some hand crafted HTTP code to help me think about what info is missing + * from the domain registry + * + */ +public class DomainImpl implements Domain { + + public String get() { + String outputHTML = "

enter URL in the form http://host:port/sca/domain/yourdomainnamehere"; + return outputHTML; + } + + public String getDomainServiceDocument(String domainName) { + String outputHTML = "

contributions" + + "

composites" + + "

endpoints" + + "

nodes"; + return outputHTML; + } + + public String getContributions(String domainName) { + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + List contributions = node.getInstalledContributionURIs(); + return contributions.toString(); + } + + public String getComposites(String domainName){ + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + return node.getDomainLevelCompositeAsString(); + } + + public String getComponents(String domainName) { + // TODO Auto-generated method stub + return null; + } + + public String getEndpoints(String domainName) { + NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode; + return node.getEndpointRegistry().getEndpoints().toString(); + } + + public String getNodes(String domainName){ + // use the domain on the file system in lieu of info in the registry + File domainDir = new File("target/test-classes/" + domainName); + String nodes = ""; + + for (File subDir : domainDir.listFiles()){ + if (subDir.isDirectory()){ + nodes += subDir.getName() + "\n"; + } + } + return nodes; + } + + // utilities + + public String prettyPrintXMLString(String inXML){ + return inXML.replaceAll("<", "<").replaceAll(">", ">"); + + // etc. need to read and write a structured version + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java new file mode 100644 index 0000000000..e8d9aa416a --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.sca.domain; + +import org.apache.tuscany.sca.Node; +import org.apache.tuscany.sca.TuscanyRuntime; + +/** + * Main class for Tuscany. Just looking at what it means to read config from a directory structure. + * + */ +public class DomainView { + + public static Node domainAccessPointNode = null; + private static Node domainViewNode = null; + + public static void main(String[] args) throws Exception { + String domainName = args[0]; + + TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); + + // a node to access the specified domain + domainAccessPointNode = tuscanyRuntime.createNode("uri:" + domainName); + + // a node to run the domain view app. Just starts in the local domain "domainview" + domainViewNode = tuscanyRuntime.createNode("domainview"); + domainViewNode.installContribution("target/classes"); + + System.out.print("Press a key to stop"); + try{ + System.in.read(); + } catch(Exception ex){ + // do nothing + } + + domainViewNode.stop(); + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java new file mode 100644 index 0000000000..81687f9e5c --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java @@ -0,0 +1,133 @@ +/* + * 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.tuscany.sca.domain; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; + +import org.apache.tuscany.sca.Node; +import org.apache.tuscany.sca.TuscanyRuntime; + +/** + * Main class for Tuscany. Just looking at what it means to read config from a directory structure. + * + */ +public class Tuscany { + + public static Node node = null; + + public static void main(String[] args) throws Exception { + String domainName = args[0]; + String nodeName = args[1]; + int deamonPort = -1; + + if (args.length > 2){ + deamonPort = Integer.parseInt(args[2]); + } + + // find the domain directory + File currentDirectory = new File("."); + File domainDirectory = findDirectory(currentDirectory, domainName); + System.out.println("Domain: " + domainDirectory.getPath()); + + // find a sub directory that ends in nodeName + File nodeDirectory = findDirectory(currentDirectory, nodeName); + System.out.println("Node: " + nodeDirectory.getPath()); + + TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); + + URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL(); + node = tuscanyRuntime.createNodeFromXML(nodeConfigURL.toString()); + + try { + //node.start(); + + // for testing we're going to set up a deamon that listens for + // a shutdown message on a specified port (well it actually just + // waits for a client to connect to the port as that's all we need + // for now). If no port is specified then just stop straight away + + if (deamonPort >= 0){ + // Its a runtime that has to act as a deamon + ServerSocket serverSocket = null; + + try { + serverSocket = new ServerSocket(deamonPort); + } catch (IOException e) { + System.out.println("Can't create a ServerSocket on port: " + deamonPort); + return; + } + + // all we're doing here is waiting for a connection. If we wanted to implement + // a real deamon we should perhaps listen to what's coming in over the resulting socket + // and see if a shutdown has been requested + Socket clientSocket = null; + try { + clientSocket = serverSocket.accept(); + } catch (IOException e) { + System.out.println("Accept failed on port: " + deamonPort); + return; + } + } + + } finally { + node.stop(); + } + } + + /** + * Just walks down the tree (depth first) looking for a directory ending in the + * name. + */ + private static File findDirectory(File currentDirectory, String name){ + File directory = null; + + if (currentDirectory.getPath().endsWith(name)){ + directory = currentDirectory; + } else { + File[] subDirectories = currentDirectory.listFiles(new DirectoryFilter()); + for (File aDirectory : subDirectories) { + directory = findDirectory(aDirectory, name); + + if (directory != null){ + break; + } + } + } + + return directory; + } + + private static class DirectoryFilter implements FilenameFilter { + + public boolean accept(File dir, String name) { + if(new File(dir, name).isDirectory()) { + return true; + } + + return false; + } + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/resources/domain.composite b/sandbox/slaws/domain-view/src/main/resources/domain.composite index de236611f6..b86485d6b0 100644 --- a/sandbox/slaws/domain-view/src/main/resources/domain.composite +++ b/sandbox/slaws/domain-view/src/main/resources/domain.composite @@ -22,11 +22,33 @@ targetNamespace="http://sample" name="domainview"> + + + + + + + + - + - + + + + + diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/component.gif b/sandbox/slaws/domain-view/src/main/resources/ui/component.gif new file mode 100644 index 0000000000..46b8963f4c Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/component.gif differ diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/composite.gif b/sandbox/slaws/domain-view/src/main/resources/ui/composite.gif new file mode 100644 index 0000000000..6749240e15 Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/composite.gif differ diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/index.html b/sandbox/slaws/domain-view/src/main/resources/ui/index.html new file mode 100644 index 0000000000..7862cd5f82 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/resources/ui/index.html @@ -0,0 +1,250 @@ + + + + +Tuscany SCA Domain Components + + + + + + + + +

+ +
+ + +
+ + + + + + + + + +
prevnext
+
+ +
+
+ +
+ + + + + + + + diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/interface.gif b/sandbox/slaws/domain-view/src/main/resources/ui/interface.gif new file mode 100644 index 0000000000..1d11c37913 Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/interface.gif differ diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/property.gif b/sandbox/slaws/domain-view/src/main/resources/ui/property.gif new file mode 100644 index 0000000000..354ad64645 Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/property.gif differ diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/reference.gif b/sandbox/slaws/domain-view/src/main/resources/ui/reference.gif new file mode 100644 index 0000000000..b3e2c80188 Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/reference.gif differ diff --git a/sandbox/slaws/domain-view/src/main/resources/ui/service.gif b/sandbox/slaws/domain-view/src/main/resources/ui/service.gif new file mode 100644 index 0000000000..9b986e3788 Binary files /dev/null and b/sandbox/slaws/domain-view/src/main/resources/ui/service.gif differ -- cgit v1.2.3