added support for links with names

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2246 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-11 02:57:33 +00:00
parent 37d5d4f071
commit 78fbcd0688
5 changed files with 136 additions and 23 deletions

View File

@ -38,8 +38,6 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(LinkImpl.class)
public interface Link {
String getName();
String getType();
URI getLocation();

View File

@ -0,0 +1,41 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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();
}

View File

@ -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 + "]";
}
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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() + "]";
}
}

View File

@ -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<String, Link> map, Attributes attributes) {
map.put(attributes.getValue(attributes.getIndex("name")), newLink(attributes));
public static void putNamedLink(Map<String, NamedLink> 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"))));
}