All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.modules.payara.spi.ResourceDesc Maven / Gradle / Ivy

The newest version!
/*
 * 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.netbeans.modules.payara.spi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.netbeans.modules.payara.tooling.TaskState;
import org.netbeans.modules.payara.tooling.admin.CommandListResources;
import org.netbeans.modules.payara.tooling.admin.ResultList;
import org.netbeans.modules.payara.common.PayaraLogger;
import org.netbeans.modules.payara.common.PayaraInstance;

/**
 * Resource description.
 * 

* @author Peter Williams, Tomas Kraus */ public class ResourceDesc implements Comparable { //////////////////////////////////////////////////////////////////////////// // Class attributes // //////////////////////////////////////////////////////////////////////////// /** Local logger. */ private static final Logger LOGGER = PayaraLogger.get(ResourceDesc.class); //////////////////////////////////////////////////////////////////////////// // Static methods // //////////////////////////////////////////////////////////////////////////// /** * Fetch list of resource descriptions of given resource type from given * Payara instance. *

* @param instance Payara instance from which to retrieve * resource descriptions. * @param type Resource type to search for (jdbc-resource, * jdbc-connection-pool, ...). * @return List of resource descriptions retrieved from Payara server. */ public static List getResources( PayaraInstance instance, String type) { List resourcesList; List values; ResultList result = CommandListResources.listResources(instance, type, null); if (result != null && result.getState() == TaskState.COMPLETED) { values = result.getValue(); } else { values = null; } if (values != null && values.size() > 0) { resourcesList = new ArrayList(values.size()); for (String value : values) { resourcesList.add(new ResourceDesc(value, type)); } } else { resourcesList = Collections.emptyList(); } return resourcesList; } //////////////////////////////////////////////////////////////////////////// // Instance attributes // //////////////////////////////////////////////////////////////////////////// /** Resource name. */ private final String name; /** Command type (jdbc-resource, * jdbc-connection-pool, ...). */ private final String cmdType; //////////////////////////////////////////////////////////////////////////// // Constructors // //////////////////////////////////////////////////////////////////////////// /** * Creates an instance of resource description. *

* @param name Resource name. * @param cmdType Command type. */ public ResourceDesc(final String name, final String cmdType) { this.name = name; this.cmdType = cmdType; } //////////////////////////////////////////////////////////////////////////// // Getters // //////////////////////////////////////////////////////////////////////////// /** * Get resource name from resource description. *

* @return Resource name. */ public String getName() { return name; } /** * Get command type from resource description. *

* @return Command type. */ public String getCommandType() { return cmdType; } //////////////////////////////////////////////////////////////////////////// // Methods // //////////////////////////////////////////////////////////////////////////// /** * Compare this resource description with another one. *

* @param resourceDesc Resource description to be compared with this object. * @return The value 0 if resource name and command type * String values of this and provided objects * are equal. * The value >0 if this resource name (or command * type when resource names are equal) String value * is lexicographically less than in provided object. * The value <0 if this resource name (or command * type when resource names are equal) String value * is lexicographically greater than in provided object. */ @Override public int compareTo(ResourceDesc resourceDesc) { int result = name.compareTo(resourceDesc.name); if(result == 0) { result = cmdType.compareTo(resourceDesc.cmdType); } return result; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy