/*
* Embedded Jopr Project
* Copyright (C) 2006-2009 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.jboss.on.embedded.converter;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.rhq.core.domain.operation.OperationDefinition;
import org.rhq.core.domain.resource.ResourceType;
/**
* @author Mark Spritzler
*/
public class OperationDefinitionConverter implements Converter {
private static final String ATTRIBUTE_VALUE_SEPARATOR = ":";
private static final int OPERATION_NAME_ELEMENT = 0;
private static final int RESOURCE_TYPE_NAME_ELEMENT = 1;
private static final int PLUGIN_ELEMENT = 2;
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) {
String[] values = string.split(ATTRIBUTE_VALUE_SEPARATOR);
// TODO: Pass a resource category to constructor.
ResourceType resourceType = new ResourceType(values[RESOURCE_TYPE_NAME_ELEMENT], values[PLUGIN_ELEMENT], null,
null);
return new OperationDefinition(resourceType, values[OPERATION_NAME_ELEMENT]);
//return string;
}
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) {
String operation = "";
if (object instanceof OperationDefinition) {
OperationDefinition operationDefinition = (OperationDefinition) object;
ResourceType resourceType = operationDefinition.getResourceType();
operation = operationDefinition.getName() + ":" + resourceType.getName() + ":" + resourceType.getPlugin();
//operation = operationDefinition.getName();
}
return operation;
}
}