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     */
017    
018    package org.apache.geronimo.console.jmsmanager;
019    
020    import javax.jms.Queue;
021    
022    public class DestinationInfo implements Comparable {
023    
024        private final String name;
025    
026        private final String physicalName;
027    
028        private final Class type;
029    
030        private final String applicationName;
031    
032        private final String moduleName;
033    
034        private final String configURI;
035    
036        public DestinationInfo(String name, String physicalName, Class type,
037                String applicationName, String moduleName, String configURI) {
038            this.name = name;
039            this.physicalName = physicalName;
040            this.type = type;
041            this.applicationName = applicationName;
042            this.moduleName = moduleName;
043            this.configURI = configURI;
044        }
045    
046        public String getName() {
047            return name;
048        }
049    
050        public String getPhysicalName() {
051            return physicalName;
052        }
053    
054        public Class getType() {
055            return type;
056        }
057    
058        public String getApplicationName() {
059            return applicationName;
060        }
061    
062        public String getModuleName() {
063            return moduleName;
064        }
065    
066        public String getConfigURI() {
067            return configURI;
068        }
069    
070        /**
071         * Determines if the destination that this objects represents is viewable
072         * from the console this means that either the destination that this object
073         * represents was added via the Geronimo JMS Console or it is a Queue.
074         *
075         * @return true if the console knows how to display this Destination
076         *         otherwise returns false.
077         */
078        public boolean isViewable() {
079            return Queue.class.isAssignableFrom(type) || isConsoleManaged();
080        }
081    
082        /**
083         * Determines if the destination that this objects represents is removable
084         * from the console this means that the destination that this object
085         * represents was added via the Geronimo JMS Console.
086         *
087         * @return true if the console knows how to remove this Destination
088         *         otherwise returns false.
089         */
090        public boolean isRemovable() {
091            return isConsoleManaged();
092        }
093    
094        /**
095         * Determines if the destination that this objects represents was added via
096         * the console.
097         *
098         * @return true if the destination that this objects represents was added
099         *         via the console otherwise returns false.
100         */
101        private boolean isConsoleManaged() {
102            return configURI.indexOf(AbstractJMSManager.BASE_CONFIG_URI + 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    }