1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Java OCA: Some formatting, and a couple of new helper methods for OneResponse and Pool

This commit is contained in:
Carlos Martín 2011-07-07 19:21:03 +02:00
parent 598ec3e18b
commit 7b19d4a866
4 changed files with 58 additions and 18 deletions

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
*
*
* Licensed 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.
@ -16,14 +16,14 @@
package org.opennebula.client;
/**
* This class encapsulates OpenNebula's XML-RPC responses. Each response
* carries a boolean indicating if it is an error. It can also contain a
* success message, or an error message.
* This class encapsulates OpenNebula's XML-RPC responses. Each response
* carries a boolean indicating if it is an error. It can also contain a
* success message, or an error message.
*/
public class OneResponse{
/**
* Creates a new response.
*
*
* @param success Indicates if the call was successful, and if
* the message is an error or an information string.
* @param message String containing the response message, or
@ -37,7 +37,7 @@ public class OneResponse{
/**
* Returns true if the call resulted in error.
*
*
* @return True if the call resulted in error.
*/
public boolean isError()
@ -48,7 +48,7 @@ public class OneResponse{
/**
* Returns a string containing the error message, or null
* if the response isn't an error.
*
*
* @return A string containing the error message, or null
* if the response isn't an error.
*/
@ -61,7 +61,7 @@ public class OneResponse{
* Returns a string containing the response information, or
* null if the response was an error. Note that the success
* message could be also null.
*
*
* @return A string containing the response information, or
* null if the response was an error. Note that the success
* message could be also null.
@ -71,6 +71,26 @@ public class OneResponse{
return success ? msg : null;
}
/**
* Parses the string returned by getMessage
*
* @return The parsed int, or Integer.MIN_VALUE in case of error
*
* @see #getMessage
*/
public int getIntMessage()
{
int ret = Integer.MIN_VALUE;
try
{
ret = Integer.parseInt( getMessage() );
}
catch (NumberFormatException e) {}
return ret;
}
// ------------------------------------------------------------------------
// PRIVATE ATTRIBUTES
// ------------------------------------------------------------------------

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
*
*
* Licensed 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.
@ -82,7 +82,7 @@ public abstract class Pool{
new ByteArrayInputStream(info.getMessage().getBytes()));
xml = doc.getDocumentElement();
poolElements = xml.getElementsByTagName(elementName);
poolElements = xml.getElementsByTagName(elementName);
}
catch (ParserConfigurationException e) {}
catch (SAXException e) {}
@ -92,7 +92,7 @@ public abstract class Pool{
/**
* Returns the indexth element in the pool. If index is greater than or
* equal to the number of elements in the pool, this returns null.
*
*
* @param index Index of the element.
* @return The element at the indexth position in the pool, or
* null if that is not a valid index.
@ -103,7 +103,7 @@ public abstract class Pool{
if (poolElements != null)
{
Node node =poolElements.item(index);
Node node = poolElements.item(index);
if (node != null)
{
@ -114,6 +114,26 @@ public abstract class Pool{
return theElement;
}
protected PoolElement getById(int id)
{
// TODO: Use xpath to find the element /<elementName>/ID
PoolElement theElement = null;
PoolElement tmpElement = null;
for( int i = 0; i < getLength(); i++ )
{
tmpElement = item(i);
if( tmpElement.id() == id )
{
theElement = tmpElement;
break;
}
}
return theElement;
}
/**
* The number of elements in the pool.
* @return The number of elements in the pool.

View File

@ -36,7 +36,7 @@ public class Group extends PoolElement{
/**
* Creates a new Group representation.
*
* @param id The group id (hid) of the machine.
* @param id The group id.
* @param client XML-RPC Client.
*/
public Group(int id, Client client)

View File

@ -50,7 +50,7 @@ public class GroupPool extends Pool implements Iterable<Group>{
}
/**
* Retrieves all the hosts in the pool.
* Retrieves all the groups in the pool.
*
* @param client XML-RPC Client.
* @return If successful the message contains the string