001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console.jmsmanager;
017:
018: import javax.jms.Queue;
019:
020: public class DestinationInfo implements Comparable {
021:
022: private final String name;
023:
024: private final String physicalName;
025:
026: private final Class type;
027:
028: private final String applicationName;
029:
030: private final String moduleName;
031:
032: private final String configURI;
033:
034: public DestinationInfo(String name, String physicalName,
035: Class type, String applicationName, String moduleName,
036: String configURI) {
037: this .name = name;
038: this .physicalName = physicalName;
039: this .type = type;
040: this .applicationName = applicationName;
041: this .moduleName = moduleName;
042: this .configURI = configURI;
043: }
044:
045: public String getName() {
046: return name;
047: }
048:
049: public String getPhysicalName() {
050: return physicalName;
051: }
052:
053: public Class getType() {
054: return type;
055: }
056:
057: public String getApplicationName() {
058: return applicationName;
059: }
060:
061: public String getModuleName() {
062: return moduleName;
063: }
064:
065: public String getConfigURI() {
066: return configURI;
067: }
068:
069: /**
070: * Determines if the destination that this objects represents is viewable
071: * from the console this means that either the destination that this object
072: * represents was added via the Geronimo JMS Console or it is a Queue.
073: *
074: * @return true if the console knows how to display this Destination
075: * otherwise returns false.
076: */
077: public boolean isViewable() {
078: return Queue.class.isAssignableFrom(type) || isConsoleManaged();
079: }
080:
081: /**
082: * Determines if the destination that this objects represents is removable
083: * from the console this means that the destination that this object
084: * represents was added via the Geronimo JMS Console.
085: *
086: * @return true if the console knows how to remove this Destination
087: * otherwise returns false.
088: */
089: public boolean isRemovable() {
090: return isConsoleManaged();
091: }
092:
093: /**
094: * Determines if the destination that this objects represents was added via
095: * the console.
096: *
097: * @return true if the destination that this objects represents was added
098: * via the console otherwise returns false.
099: */
100: private boolean isConsoleManaged() {
101: return configURI.indexOf(AbstractJMSManager.BASE_CONFIG_URI
102: + name) > -1;
103: }
104:
105: public int compareTo(Object o) {
106: if (o instanceof DestinationInfo) {
107: DestinationInfo rhs = (DestinationInfo) o;
108: // If one of the objects is removable and the other is not, the
109: // removable one is less (comes first in a descending sort).
110: if (rhs.isRemovable() != this .isRemovable()) {
111: if (this .isRemovable()) {
112: return -1;
113: } else {
114: return 1;
115: }
116: // If one of the objects is viewable and the other is not the
117: // viewable one is less (comes first in a descending sort).
118: } else if (rhs.isViewable() != this .isViewable()) {
119: if (this .isViewable()) {
120: return -1;
121: } else {
122: return 1;
123: }
124: // Sort by name if all else fails.
125: } else {
126: return this .name.compareTo(rhs.getName());
127: }
128: }
129: return 1;
130: }
131:
132: }
|