Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjrellerme2010-06-03 09:40:55 +0000
committerjrellerme2010-06-03 09:40:55 +0000
commit18751d72c64fa254d90e262a7bac25015c5a31a4 (patch)
tree6a18aad01f1dc1def343fab41b4e02aed224e8c1 /protocols
parente963b6491955364d6946b238eb8f2079dc924d9b (diff)
downloadorg.eclipse.ecf-18751d72c64fa254d90e262a7bac25015c5a31a4.tar.gz
org.eclipse.ecf-18751d72c64fa254d90e262a7bac25015c5a31a4.tar.xz
org.eclipse.ecf-18751d72c64fa254d90e262a7bac25015c5a31a4.zip
replaced old implementation by a new, cleanroom implementation
Diffstat (limited to 'protocols')
-rw-r--r--protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/ServiceType.java151
1 files changed, 62 insertions, 89 deletions
diff --git a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/ServiceType.java b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/ServiceType.java
index b55a9460b..5ad6f54b0 100644
--- a/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/ServiceType.java
+++ b/protocols/bundles/ch.ethz.iks.slp/src/main/java/ch/ethz/iks/slp/ServiceType.java
@@ -1,15 +1,16 @@
-/* modified version by Jan S. Rellermeyer, ETH Zurich
- * Copyright 2005-2007 Systems Group, ETH Zurich. All rights reserved.
+/****************************************************************************
+ * Copyright (c) 2005, 2010 Jan S. Rellermeyer, Systems Group,
+ * Department of Computer Science, ETH Zurich and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
*
- * based on the Java SLP implementation by Solers Corporation
- * Copyright 2003 Solers Corporation. All rights reserved.
+ * Contributors:
+ * Jan S. Rellermeyer - initial API and implementation
+ * Markus Alexander Kuppe - enhancements and bug fixes
*
- * Modification and use of this SLP API software and associated documentation
- * ("Software") is permitted provided that the conditions specified in the
- * LICENSE.txt file included within this distribution are met.
- *
- * Author of the original class: Patrick Callis
- */
+*****************************************************************************/
package ch.ethz.iks.slp;
import java.io.Serializable;
@@ -18,15 +19,14 @@ import java.io.Serializable;
* Implementation of the SLP ServiceType class defined in RFC 2614.
*
* @author Jan S. Rellermeyer, Systems Group, ETH Zurich
- * @author Patrick Callis, Solers Corp.
- * @since 0.1
+ * @since 1.0
*/
public final class ServiceType implements Serializable {
/**
- * the serial UID.
+ *
*/
- private static final long serialVersionUID = 1652247274399819356L;
+ private static final long serialVersionUID = 2821061127250972623L;
/**
* the type.
@@ -34,34 +34,29 @@ public final class ServiceType implements Serializable {
private String type = new String();
/**
- * is it a service ?
- */
- private boolean isService = false;
-
- /**
* is it abstract ?
*/
- private boolean isAbstract = false;
+ private final boolean isAbstract;
/**
* the concrete type.
*/
- private String concreteType = new String();
+ private final String concreteType;
/**
* the principle type.
*/
- private String principleType = new String();
+ private final String principleType;
/**
* the abstract type.
*/
- private String abstractType = new String();
+ private final String abstractType;
/**
* the naming authority.
*/
- private String namingAuthority = new String();
+ private final String namingAuthority;
/**
* creates a new ServiceType instance.
@@ -69,60 +64,53 @@ public final class ServiceType implements Serializable {
* @param serviceType
* the string representation of a ServiceType, e.g.
*
- * <pre>
+ * <pre>
* service:osgi:remote
* </pre>
*/
public ServiceType(final String serviceType) {
type = serviceType;
- if (type.startsWith("service:")) {
- isService = true;
-
- int principleStart = 8;
- int principleEnd = type.indexOf(":", principleStart);
+ if (!type.startsWith("service:")) {
+ throw new IllegalArgumentException("Invalid service type: "
+ + serviceType);
+ }
+ final int principleStart = 8;
+ final int principleEnd = type.indexOf(":", principleStart);
+
+ if (principleEnd != -1) {
+ isAbstract = true;
+ principleType = type.substring(principleStart, principleEnd);
+ abstractType = type.substring(0, principleEnd);
+ concreteType = type.substring(principleEnd + 1);
+ } else {
+ isAbstract = false;
+ principleType = type.substring(principleStart);
+ abstractType = "";
+ concreteType = "";
+ }
- if (principleEnd != -1) {
- isAbstract = true;
- principleType = type.substring(principleStart, principleEnd);
- abstractType = type.substring(0, principleEnd);
- concreteType = type.substring(principleEnd + 1);
+ final int namingStart = type.indexOf(".") + 1;
+ if (namingStart != 0) {
+ final int namingEnd = type.indexOf(":", namingStart);
+ String na = "";
+ if (namingEnd == -1) {
+ na = type.substring(namingStart);
} else {
- isAbstract = false;
- principleType = type.substring(principleStart);
- abstractType = "";
- concreteType = "";
+ na = type.substring(namingStart, namingEnd);
}
-
- int namingStart = type.indexOf(".") + 1;
- if (namingStart != 0) {
- int namingEnd = type.indexOf(":", namingStart);
- String na = "";
- if (namingEnd == -1) {
- na = type.substring(namingStart);
- } else {
- na = type.substring(namingStart, namingEnd);
- }
- // 1954772: isNADefault returns false for "IANA"
- if("IANA".equalsIgnoreCase(na)) {
- namingAuthority = "";
- // remove "iana" from type so toString() is consistent
- type = type.substring(0, namingStart - 1) + type.substring(namingStart + 4, type.length());
- } else {
- namingAuthority = na;
- }
- } else {
+ // 1954772: isNADefault returns false for "IANA"
+ if ("IANA".equalsIgnoreCase(na)) {
namingAuthority = "";
+ // remove "iana" from type so toString() is consistent
+ type = type.substring(0, namingStart - 1)
+ + type.substring(namingStart + 4, type.length());
+ } else {
+ namingAuthority = na;
}
+ } else {
+ namingAuthority = "";
}
- }
- /**
- * is the ServiceType instance a ServiceURL ?
- *
- * @return true if this is the case.
- */
- public boolean isServiceURL() {
- return isService;
}
/**
@@ -190,8 +178,8 @@ public final class ServiceType implements Serializable {
if (!(obj instanceof ServiceType)) {
return false;
}
- ServiceType t = (ServiceType) obj;
- return (isService == t.isService && isAbstract == t.isAbstract
+ final ServiceType t = (ServiceType) obj;
+ return (isAbstract == t.isAbstract
&& concreteType.equals(t.concreteType)
&& principleType.equals(t.principleType)
&& abstractType.equals(t.abstractType) && namingAuthority
@@ -209,12 +197,9 @@ public final class ServiceType implements Serializable {
if (!(obj instanceof ServiceType)) {
return false;
}
- ServiceType t = (ServiceType) obj;
- if (!isAbstract) {
- return equals(t);
- } else {
- return equals(t) || t.toString().equals(getAbstractTypeName());
- }
+ final ServiceType t = (ServiceType) obj;
+ return isAbstract ? equals(t)
+ || t.toString().equals(getAbstractTypeName()) : equals(t);
}
/**
@@ -232,21 +217,9 @@ public final class ServiceType implements Serializable {
* @return the int value of the hashCode.
*/
public int hashCode() {
- int code = 0;
-
- if (concreteType != null) {
- code ^= (concreteType.hashCode());
- }
- if (principleType != null) {
- code ^= (principleType.hashCode() << 8);
- }
- if (abstractType != null) {
- code ^= (abstractType.hashCode() << 16);
- }
- if (namingAuthority != null) {
- code ^= (namingAuthority.hashCode() << 24);
- }
- return code;
+ return (concreteType.hashCode()) ^ (principleType.hashCode() << 24)
+ ^ (abstractType.hashCode() << 16)
+ ^ (namingAuthority.hashCode() << 8);
}
}

Back to the top