Fiddling about with making the composite artifact path do something
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1127474 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f83f5e8e0
commit
01d244ef26
4 changed files with 105 additions and 29 deletions
|
@ -20,6 +20,7 @@
|
|||
package org.apache.tuscany.sca.domain;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
|
|
@ -25,6 +25,14 @@ import java.util.List;
|
|||
import javax.ws.rs.core.PathSegment;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.tuscany.sca.assembly.Binding;
|
||||
import org.apache.tuscany.sca.assembly.Component;
|
||||
import org.apache.tuscany.sca.assembly.Composite;
|
||||
import org.apache.tuscany.sca.assembly.Reference;
|
||||
import org.apache.tuscany.sca.assembly.Service;
|
||||
import org.apache.tuscany.sca.assembly.xml.Utils;
|
||||
import org.apache.tuscany.sca.runtime.DomainRegistry;
|
||||
|
||||
/**
|
||||
* Some hand crafted HTTP code to help me think about what info is missing
|
||||
* from the domain registry
|
||||
|
@ -32,33 +40,86 @@ import javax.ws.rs.core.UriInfo;
|
|||
public class CompositeArtifactViewImpl implements CompositeArtifactView {
|
||||
|
||||
private String domainName;
|
||||
private Composite composite;
|
||||
private String artifacturi;
|
||||
|
||||
public CompositeArtifactViewImpl(String domainName){
|
||||
public CompositeArtifactViewImpl(String domainName, Composite composite, String artifacturi){
|
||||
this.domainName = domainName;
|
||||
this.composite = composite;
|
||||
this.artifacturi = artifacturi;
|
||||
}
|
||||
|
||||
public String get(UriInfo uriInfo){
|
||||
Iterator<PathSegment> pathSegmentsIter = uriInfo.getPathSegments().iterator();
|
||||
|
||||
// get past the sca/domain/domainname/composite/compositename segments
|
||||
pathSegmentsIter.next();
|
||||
pathSegmentsIter.next();
|
||||
pathSegmentsIter.next();
|
||||
pathSegmentsIter.next();
|
||||
pathSegmentsIter.next();
|
||||
|
||||
// now expecting componentname/componentname/componentname/service or reference/binding
|
||||
while (pathSegmentsIter.hasNext()){
|
||||
pathSegmentsIter.next();
|
||||
if (composite == null){
|
||||
return "<p/>composite not found";
|
||||
}
|
||||
|
||||
// get list of pairs of artifact type and name
|
||||
return "Yippeeeee! Show the composite artifact at " + uriInfo.getPath();
|
||||
String[] artifactNames = artifacturi.split("/");
|
||||
|
||||
Component component = null;
|
||||
Service service = null;
|
||||
Reference reference = null;
|
||||
Binding binding = null;
|
||||
|
||||
// iterate down the artifact uri
|
||||
for (int i=0; i < artifactNames.length; i++){
|
||||
String name = artifactNames[i];
|
||||
|
||||
if (service != null) {
|
||||
binding = service.getBinding(name);
|
||||
break;
|
||||
} else if (reference != null){
|
||||
binding = reference.getBinding(name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (component != null) {
|
||||
service = component.getService(name);
|
||||
reference = component.getReference(name);
|
||||
}
|
||||
|
||||
component = composite.getComponent(name);
|
||||
}
|
||||
|
||||
// not sure how to print out the artifacts
|
||||
if (binding != null){
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(binding, true, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
}
|
||||
|
||||
if (service != null){
|
||||
/* need to register stax processors for this to work
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(service, false, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
*/
|
||||
return "Service: " + service.toString();
|
||||
}
|
||||
|
||||
if (reference != null){
|
||||
/* need to register stax processors for this to work
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(reference, false, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
*/
|
||||
return "Reference: " + reference.toString();
|
||||
}
|
||||
|
||||
if (component != null){
|
||||
/* need to register stax processors for this to work
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(component, false, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
*/
|
||||
return "Component: " + component.toString();
|
||||
}
|
||||
|
||||
return "artifact " + artifacturi + " not found in composite " + composite.getURI();
|
||||
}
|
||||
|
||||
class Artifact {
|
||||
public String type;
|
||||
public String name;
|
||||
public Component findComponent(Composite composite, String name){
|
||||
return composite.getComponent(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -41,7 +41,11 @@ public interface CompositeView {
|
|||
@Path("{compositename}")
|
||||
public String getComposite(@PathParam("compositename") String compositeName, @Context UriInfo uriInfo);
|
||||
|
||||
@Path("{compositename}/{compositeartifact}")
|
||||
public CompositeArtifactView getCompositeArtifact();
|
||||
// Hack to make it call this with any path added to the end of the composite name
|
||||
// Want the user to be able to do something like
|
||||
// http://localhost:80/sca/domain/mydomain/composite/mycomposite/component1/component2/service1
|
||||
@Path("{compositename}/{artifacturi:.*}")
|
||||
public CompositeArtifactView getCompositeArtifact(@PathParam("compositename") String compositeName,
|
||||
@PathParam("artifacturi") String artifacturi);
|
||||
|
||||
}
|
|
@ -51,21 +51,31 @@ public class CompositeViewImpl implements CompositeView {
|
|||
}
|
||||
|
||||
public String getComposite(String compositeName, UriInfo uriInfo) {
|
||||
Composite composite = getComposite(compositeName);
|
||||
if(composite != null){
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(composite, true, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
} else {
|
||||
return "<p/>composite not found";
|
||||
}
|
||||
}
|
||||
|
||||
public CompositeArtifactView getCompositeArtifact(String compositeName, String artifacturi){
|
||||
return new CompositeArtifactViewImpl(domainName, getComposite(compositeName), artifacturi);
|
||||
}
|
||||
|
||||
// utlilities
|
||||
|
||||
public Composite getComposite(String compositeName){
|
||||
DomainRegistry domainRegistry = DomainViewRunner.domainRegistry;
|
||||
Composite composite = domainRegistry.getDomainComposite();
|
||||
for (Composite tmpComposite : composite.getIncludes()){
|
||||
if (tmpComposite.getName().getLocalPart().equals(compositeName)){
|
||||
return "<p/><textarea rows=\"40\" cols=\"80\">" +
|
||||
Utils.modelToXML(tmpComposite, true, DomainViewRunner.extensionPointRegistry) +
|
||||
"</textarea>";
|
||||
return tmpComposite;
|
||||
}
|
||||
}
|
||||
|
||||
return "<p/>composite not found";
|
||||
}
|
||||
|
||||
public CompositeArtifactView getCompositeArtifact(){
|
||||
return new CompositeArtifactViewImpl(domainName);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue