diff options
Diffstat (limited to 'sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl')
2 files changed, 187 insertions, 0 deletions
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java new file mode 100644 index 0000000000..02e18bafbb --- /dev/null +++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java @@ -0,0 +1,31 @@ +/* + * 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.binding.p2p.impl; + +import org.apache.tuscany.sca.binding.p2p.P2PBindingImpl; +import org.apache.tuscany.sca.binding.p2p.P2PBindingFactory; + +public class P2PBindingFactoryImpl implements P2PBindingFactory, { + public P2Pinding createP2PBinding() { + // TODO Auto-generated method stub + return new P2PBindingImpl(); + } + +} diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java new file mode 100644 index 0000000000..acece50f9d --- /dev/null +++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java @@ -0,0 +1,156 @@ +/* + * 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.binding.p2p.impl; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.tuscany.sca.binding.p2p.P2PBinding; + +/** + * Represents a binding to an overlay weaver P2P service. + * + * @version $Rev$ $Date$ + */ +public class P2PBindingImpl implements P2PBinding { + private String name; + private String uri; + private String host; + private String port; + private String serviceName; + + /** + * @return the host name of the P2P Service + */ + public String getHost() { + return host; + } + + /** + * @param rmiHostName the hostname of the P2P Service + */ + public void setHost(String rmiHostName) { + this.host = rmiHostName; + } + + /** + * @return the port number for the RMI Service + */ + public String getPort() { + return port; + } + + /** + * @param rmiPort the port number for the RMI Service + */ + public void setPort(String rmiPort) { + this.port = rmiPort; + } + + /** + * @return returns the RMI Service Name + */ + public String getServiceName() { + return serviceName; + } + + /** + * Sets the service name for the RMI Server + * + * @param rmiServiceName the name of the RMI service + */ + public void setServiceName(String rmiServiceName) { + this.serviceName = rmiServiceName; + } + + public String getName() { + return name; + } + + public String getURI() { + compose(); + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + parse(uri); + } + + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /* + p2p://[host][:port][/[object]] + */ + private void parse(String uriStr) { + if (uriStr == null) { + return; + } + URI uri = URI.create(uriStr); + if (host == null) { + this.host = uri.getHost(); + } + if (port == null) { + this.port = String.valueOf(uri.getPort()); + } + if (serviceName == null) { + String path = uri.getPath(); + if (path != null && path.charAt(0) == '/') { + path = path.substring(1); + } + this.serviceName = path; + } + } + + private void compose() { + if (uri == null) { + int p = -1; + if (port != null && port.length() > 0) { + p = Integer.decode(port); + } + String path = serviceName; + if (path != null) { + path = "/" + path; + } + try { + uri = new URI("p2p", null, host, p, path, null, null).toString(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(e); + } + } + } + + +} |