diff --git a/core/src/main/java/org/jclouds/rest/domain/Link.java b/core/src/main/java/org/jclouds/rest/domain/Link.java index dc0b316441..b8fa64bfc4 100644 --- a/core/src/main/java/org/jclouds/rest/domain/Link.java +++ b/core/src/main/java/org/jclouds/rest/domain/Link.java @@ -38,8 +38,6 @@ import com.google.inject.ImplementedBy; @ImplementedBy(LinkImpl.class) public interface Link { - String getName(); - String getType(); URI getLocation(); diff --git a/core/src/main/java/org/jclouds/rest/domain/NamedLink.java b/core/src/main/java/org/jclouds/rest/domain/NamedLink.java new file mode 100644 index 0000000000..ed2139c8ce --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/domain/NamedLink.java @@ -0,0 +1,41 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.rest.domain; + +import org.jclouds.rest.domain.internal.NamedLinkImpl; + +import com.google.inject.ImplementedBy; + +/** + * Location of a Rest resource + * + * @author Adrian Cole + * + */ +@ImplementedBy(NamedLinkImpl.class) +public interface NamedLink extends Link { + + String getName(); + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/domain/internal/LinkImpl.java b/core/src/main/java/org/jclouds/rest/domain/internal/LinkImpl.java index 4edf685678..62b17d706b 100644 --- a/core/src/main/java/org/jclouds/rest/domain/internal/LinkImpl.java +++ b/core/src/main/java/org/jclouds/rest/domain/internal/LinkImpl.java @@ -34,20 +34,14 @@ import org.jclouds.rest.domain.Link; * */ public class LinkImpl implements Link { - private final String name; private final String type; private final URI location; - public LinkImpl(String name, String type, URI location) { - this.name = name; + public LinkImpl(String type, URI location) { this.type = type; this.location = location; } - public String getName() { - return name; - } - public String getType() { return type; } @@ -56,17 +50,11 @@ public class LinkImpl implements Link { return location; } - @Override - public String toString() { - return "Link [name=" + name + ", type=" + type + ", location=" + location + "]"; - } - @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((location == null) ? 0 : location.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } @@ -85,11 +73,6 @@ public class LinkImpl implements Link { return false; } else if (!location.equals(other.location)) return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; if (type == null) { if (other.type != null) return false; @@ -97,4 +80,9 @@ public class LinkImpl implements Link { return false; return true; } + + @Override + public String toString() { + return "LinkImpl [location=" + location + ", type=" + type + "]"; + } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/domain/internal/NamedLinkImpl.java b/core/src/main/java/org/jclouds/rest/domain/internal/NamedLinkImpl.java new file mode 100644 index 0000000000..ee0c4e3ffa --- /dev/null +++ b/core/src/main/java/org/jclouds/rest/domain/internal/NamedLinkImpl.java @@ -0,0 +1,79 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.jclouds.rest.domain.internal; + +import java.net.URI; + +import org.jclouds.rest.domain.NamedLink; + +/** + * Location of a Rest resource + * + * @author Adrian Cole + * + */ +public class NamedLinkImpl extends LinkImpl implements NamedLink { + private final String name; + + public NamedLinkImpl(String name, String type, URI location) { + super(type, location); + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + NamedLinkImpl other = (NamedLinkImpl) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "NamedLinkImpl [name=" + name + ", getLocation()=" + getLocation() + ", getType()=" + + getType() + "]"; + } + +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/util/Utils.java b/core/src/main/java/org/jclouds/rest/util/Utils.java index 1c4ba8c2e7..bce73c5e33 100644 --- a/core/src/main/java/org/jclouds/rest/util/Utils.java +++ b/core/src/main/java/org/jclouds/rest/util/Utils.java @@ -27,7 +27,9 @@ import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.Link; +import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.internal.LinkImpl; +import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.xml.sax.Attributes; /** @@ -36,12 +38,17 @@ import org.xml.sax.Attributes; */ public class Utils { - public static void putLink(Map map, Attributes attributes) { - map.put(attributes.getValue(attributes.getIndex("name")), newLink(attributes)); + public static void putNamedLink(Map map, Attributes attributes) { + map.put(attributes.getValue(attributes.getIndex("name")), newNamedLink(attributes)); } public static Link newLink(Attributes attributes) { - return new LinkImpl(attributes.getValue(attributes.getIndex("name")), attributes + return new LinkImpl(attributes.getValue(attributes.getIndex("type")), URI.create(attributes + .getValue(attributes.getIndex("href")))); + } + + public static NamedLink newNamedLink(Attributes attributes) { + return new NamedLinkImpl(attributes.getValue(attributes.getIndex("name")), attributes .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes .getIndex("href")))); }