KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jmx > adaptor > snmp > agent > RequestHandlerImpl


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.jmx.adaptor.snmp.agent;
23
24 import java.io.InputStream JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.SortedMap JavaDoc;
29 import java.util.SortedSet JavaDoc;
30 import java.util.TreeMap JavaDoc;
31 import java.util.TreeSet JavaDoc;
32
33 import javax.management.Attribute JavaDoc;
34 import javax.management.MBeanServer JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36
37 import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
38 import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
39 import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
40 import org.jboss.logging.Logger;
41 import org.jboss.xb.binding.ObjectModelFactory;
42 import org.jboss.xb.binding.Unmarshaller;
43 import org.jboss.xb.binding.UnmarshallerFactory;
44 import org.opennms.protocols.snmp.SnmpAgentSession;
45 import org.opennms.protocols.snmp.SnmpInt32;
46 import org.opennms.protocols.snmp.SnmpNull;
47 import org.opennms.protocols.snmp.SnmpObjectId;
48 import org.opennms.protocols.snmp.SnmpOctetString;
49 import org.opennms.protocols.snmp.SnmpPduPacket;
50 import org.opennms.protocols.snmp.SnmpPduRequest;
51 import org.opennms.protocols.snmp.SnmpSyntax;
52 import org.opennms.protocols.snmp.SnmpUInt32;
53 import org.opennms.protocols.snmp.SnmpVarBind;
54
55 /**
56  * Implement RequestHandler with mapping of snmp get/set requests
57  * to JMX mbean attribute gets/sets
58  *
59  * @author <a HREF="mailto:hwr@pilhuhn.de>">Heiko W. Rupp</a>
60  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
61  * @version $Revision: 46150 $
62  */

63 public class RequestHandlerImpl extends RequestHandlerSupport
64    implements Reconfigurable
65 {
66     // Protected Data ------------------------------------------------
67

68     private static final String JavaDoc NO_ENTRY_FOUND_FOR_OID = "No entry found for oid ";
69     private static final String JavaDoc SKIP_ENTRY = " - skipping entry";
70
71
72     /** Bindings from oid to mbean */
73     protected SortedMap JavaDoc bindings = new TreeMap JavaDoc();
74
75     private SortedSet JavaDoc oidKeys = null;
76
77     /** Has this RequestHandler instance been initialized? */
78     private boolean initialized = false;
79
80     // Constructors --------------------------------------------------
81

82     /**
83      * Default CTOR
84      */

85     public RequestHandlerImpl()
86     {
87         bindings = new TreeMap JavaDoc();
88         oidKeys = new TreeSet JavaDoc();
89     }
90
91     // RequestHandler Implementation ---------------------------------
92

93     /**
94      * Initialize
95      *
96      * @param resourceName A file containing get/set mappings
97      * @param server Our MBean-Server
98      * @param log The logger we use
99      * @param uptime The uptime of the snmp-agent subsystem.
100      */

101     public void initialize(String JavaDoc resourceName, MBeanServer JavaDoc server, Logger log, Clock uptime)
102       throws Exception JavaDoc
103    {
104       log.debug("initialize() with res=" + resourceName);
105        super.initialize(resourceName, server, log, uptime);
106         if (resourceName != null)
107             initializeBindings();
108         else
109             log.warn("No RequestHandlerResName configured, disabling snmp-get");
110
111         initialized = true;
112     }
113
114    // Reconfigurable Implementation ---------------------------------
115
/**
116     * Reconfigures the RequestHandler
117     */

118    public void reconfigure(String JavaDoc resName) throws Exception JavaDoc
119    {
120       if (resName == null || resName.equals(""))
121          throw new IllegalArgumentException JavaDoc("Null or empty resName, cannot reconfigure");
122
123       if (initialized == false)
124          throw new IllegalStateException JavaDoc("Cannot reconfigure, not initialized yet");
125       
126       this.resourceName = resName;
127    
128       // Wipe out old entries
129
bindings.clear();
130       
131       // Fetch them again
132
initializeBindings();
133    }
134    
135     // SnmpAgentHandler Implementation -------------------------------
136

137     /**
138      * <P>
139      * This method is defined to handle SNMP Get requests that are received by
140      * the session. The request has already been validated by the system. This
141      * routine will build a response and pass it back to the caller.
142      * </P>
143      *
144      * @param pdu
145      * The SNMP pdu
146      * @param getNext
147      * The agent is requesting the lexically NEXT item after each
148      * item in the pdu.
149      *
150      * @return SnmpPduRequest filled in with the proper response, or null if
151      * cannot process NOTE: this might be changed to throw an exception.
152      */

153     public SnmpPduRequest snmpReceivedGet(SnmpPduPacket pdu, boolean getNext)
154     {
155         try
156         {
157             SnmpPduRequest response = null;
158             int pduLength = pdu.getLength();
159             final boolean trace = log.isTraceEnabled();
160
161             if (trace)
162                 log.trace("requestId=" + pdu.getRequestId() + ", pduLength="
163                         + pduLength + ", getNext=" + getNext);
164
165             SnmpVarBind[] vblist = new SnmpVarBind[pduLength];
166             int errorStatus = SnmpPduPacket.ErrNoError;
167             int errorIndex = 0;
168
169             // Process for each varibind in the request
170
for (int i = 0; i < pduLength; i++)
171             {
172                 boolean good = true;
173                 SnmpVarBind vb = pdu.getVarBindAt(i);
174                 SnmpObjectId oid = vb.getName();
175                 if (getNext)
176                 {
177                     /*
178                      * We call getNextOid() to find out what is the next valid OID
179                      * instance in the supported MIB (sub-)tree. Assign that OID to the
180                      * VB List and then proceed same as that of get request. If the
181                      * passed oid is already the last, we flag it.
182                      */

183                     ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
184                     oid = getNextOid(coid, true);
185                     if (oid == null)
186                     {
187                         good = false;
188                     }
189                     else
190                     {
191                         pdu.setVarBindAt(i, new SnmpVarBind(oid));
192                     }
193                 }
194                 if (oid!=null)
195                     vblist[i] = new SnmpVarBind(oid);
196                 else
197                     vblist[i] = new SnmpVarBind(vb.getName()); // oid passed in
198

199
200                 if (trace)
201                     log.trace("oid=" + oid);
202
203                 SnmpSyntax result = null;
204                 if (good && bindings != null)
205                     result = getValueFor(oid);
206
207                 if (trace)
208                     log.trace("got result of " + result);
209
210                 if (result == null || !good)
211                 {
212                     errorStatus = SnmpPduPacket.ErrNoSuchName;
213                     errorIndex = i + 1;
214                     log.debug("Error Occured " + vb.getName().toString());
215                 }
216                 else
217                 {
218                     vblist[i].setValue(result);
219                     log.debug("Varbind[" + i + "] := "
220                                     + vblist[i].getName().toString());
221                     log.debug(" --> " + vblist[i].getValue().toString());
222                 }
223             } // for ...
224
response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
225             response.setErrorStatus(errorStatus);
226             response.setErrorIndex(errorIndex);
227             return response;
228         } catch (Exception JavaDoc e)
229         {
230             // TODO Auto-generated catch block
231
e.printStackTrace();
232             return null;
233         }
234     }
235
236     /**
237      * <P>
238      * This method is defined to handle SNMP Set requests that are received by
239      * the session. The request has already been validated by the system. This
240      * routine will build a response and pass it back to the caller.
241      * </P>
242      *
243      * @param pdu
244      * The SNMP pdu
245      *
246      * @return SnmpPduRequest filled in with the proper response, or null if
247      * cannot process NOTE: this might be changed to throw an exception.
248      */

249     public SnmpPduRequest snmpReceivedSet(SnmpPduPacket pdu)
250    {
251         final boolean trace = log.isTraceEnabled();
252         SnmpPduRequest response = null;
253         int errorStatus = SnmpPduPacket.ErrNoError;
254         int errorIndex = 0;
255         int k = pdu.getLength();
256         SnmpVarBind[] vblist = new SnmpVarBind[k];
257
258         for (int i = 0; i < k; i++)
259       {
260             SnmpVarBind vb = pdu.getVarBindAt(i);
261             vblist[i] = new SnmpVarBind(vb);
262             SnmpObjectId oid = vb.getName();
263             SnmpSyntax newVal = vb.getValue();
264             if (trace)
265                 log.trace("set: received oid " + oid.toString() + " with value " + newVal.toString());
266             SnmpSyntax result = null;
267             try
268          {
269                 result = setValueFor(oid,newVal);
270             }
271          catch (ReadOnlyException e)
272          {
273                 errorStatus = SnmpPduPacket.ErrReadOnly;
274                 errorIndex = i + 1;
275             }
276
277              if (result != null)
278              {
279                 errorStatus = SnmpPduPacket.ErrReadOnly;
280                 errorIndex = i + 1;
281                 log.debug("Error occured " + vb.getName().toString());
282              }
283
284              if (trace)
285           {
286                  log.trace("Varbind[" + i + "] := " + vb.getName().toString());
287                  log.trace(" --> " + vb.getValue().toString());
288              }
289         }
290         response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
291         response.setErrorStatus(errorStatus);
292         response.setErrorIndex(errorIndex);
293
294         return response;
295     }
296
297     /**
298      * <P>
299      * This method is defined to handle SNMP requests that are received by the
300      * session. The parameters allow the handler to determine the host, port,
301      * and community string of the received PDU
302      * </P>
303      *
304      * @param session
305      * The SNMP session
306      * @param manager
307      * The remote sender
308      * @param port
309      * The remote senders port
310      * @param community
311      * The community string
312      * @param pdu
313      * The SNMP pdu
314      *
315      */

316     public void snmpReceivedPdu(SnmpAgentSession session, InetAddress JavaDoc manager,
317             int port, SnmpOctetString community, SnmpPduPacket pdu)
318    {
319         log.error("Message from manager " + manager.toString() + " on port " + port);
320         int cmd = pdu.getCommand();
321         log.error("Unsupported PDU command......... " + cmd);
322     }
323
324     /**
325      * <P>
326      * This method is invoked if an error occurs in the session. The error code
327      * that represents the failure will be passed in the second parameter,
328      * 'error'. The error codes can be found in the class SnmpAgentSession
329      * class.
330      * </P>
331      *
332      * <P>
333      * If a particular PDU is part of the error condition it will be passed in
334      * the third parameter, 'pdu'. The pdu will be of the type SnmpPduRequest or
335      * SnmpPduTrap object. The handler should use the "instanceof" operator to
336      * determine which type the object is. Also, the object may be null if the
337      * error condition is not associated with a particular PDU.
338      * </P>
339      *
340      * @param session
341      * The SNMP Session
342      * @param error
343      * The error condition value.
344      * @param ref
345      * The PDU reference, or potentially null. It may also be an
346      * exception.
347      */

348     public void SnmpAgentSessionError(SnmpAgentSession session, int error, Object JavaDoc ref)
349    {
350         log.error("An error occured in the trap session");
351         log.error("Session error code = " + error);
352         if (ref != null)
353       {
354             log.error("Session error reference: " + ref.toString());
355         }
356
357         if (error == SnmpAgentSession.ERROR_EXCEPTION)
358       {
359             synchronized (session)
360          {
361                 session.notify(); // close the session
362
}
363         }
364     }
365
366    // Private -------------------------------------------------------
367

368     /**
369      * Initialize the bindings from the file given in resourceName
370      */

371     private void initializeBindings() throws Exception JavaDoc
372    {
373       log.debug("Reading resource: '" + resourceName + "'");
374       
375       ObjectModelFactory omf = new AttributeMappingsBinding();
376       InputStream JavaDoc is = null;
377       AttributeMappings mappings = null;
378       try
379       {
380          // locate resource
381
is = getClass().getResourceAsStream(resourceName);
382          
383          // create unmarshaller
384
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
385
386          // let JBossXB do it's magic using the AttributeMappingsBinding
387
mappings = (AttributeMappings)unmarshaller.unmarshal(is, omf, null);
388       }
389       catch (Exception JavaDoc e)
390       {
391          log.error("Accessing resource '" + resourceName + "'");
392          throw e;
393       }
394       finally
395       {
396          if (is != null)
397          {
398             // close the XML stream
399
is.close();
400          }
401       }
402       if (mappings == null)
403       {
404          log.warn("No bindings found in " + resourceName);
405          return;
406       }
407       log.debug("Found " + mappings.size() + " attribute mappings");
408         /**
409          * We have the MBeans now. Put them into the bindungs.
410          */

411
412         Iterator JavaDoc it = mappings.iterator();
413         while (it.hasNext())
414       {
415            ManagedBean mmb = (ManagedBean)it.next();
416            String JavaDoc oidPrefix = mmb.getOidPrefix();
417            List JavaDoc attrs = mmb.getAttributes();
418            Iterator JavaDoc aIt = attrs.iterator();
419            while (aIt.hasNext())
420            {
421               MappedAttribute ma = (MappedAttribute)aIt.next();
422               String JavaDoc oid;
423               if (oidPrefix != null)
424                  oid = oidPrefix + ma.getOid();
425               else
426                  oid = ma.getOid();
427            
428               BindEntry be = new BindEntry(oid, mmb.getName(), ma.getName());
429               be.isReadWrite = ma.isReadWrite();
430               
431               ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
432               
433               if (log.isTraceEnabled())
434                  log.trace("New bind entry " + be);
435               if (bindings.containsKey(coid)) {
436                  log.info("Duplicate oid " + oid + SKIP_ENTRY);
437                  continue;
438               }
439               if (mmb.getName() == null || mmb.getName().equals(""))
440               {
441                  log.info("Invalid mbean name for oid " + oid + SKIP_ENTRY);
442                  continue;
443               }
444               if (ma.getName() == null || ma.getName().equals(""))
445               {
446                  log.info("Invalid attribute name " + ma.getName() + " for oid " + oid + SKIP_ENTRY);
447                  continue;
448               }
449               bindings.put(coid, be);
450               oidKeys.add(coid);
451               
452            }
453       }
454    }
455
456     /**
457      * Return the current value for the given oid
458      *
459      * @param oid
460      * The oid we want a value for
461      * @return SnmpNull if no value present
462      */

463     private SnmpSyntax getValueFor(final SnmpObjectId oid) {
464
465         BindEntry be = findBindEntryForOid(oid);
466         SnmpSyntax ssy = null;
467         if (be != null)
468       {
469             if (log.isTraceEnabled())
470                 log.trace("Found entry " + be.toString() + " for oid " + oid);
471          
472             try
473          {
474                Object JavaDoc val = server.getAttribute(be.mbean, be.attr.getName());
475
476                 if (val instanceof Long JavaDoc)
477             {
478                     Long JavaDoc uin = (Long JavaDoc) val;
479                     ssy = new SnmpUInt32(uin);
480                 }
481             else if (val instanceof String JavaDoc)
482             {
483                     String JavaDoc in = (String JavaDoc) val;
484                     ssy = new SnmpOctetString(in.getBytes());
485                 }
486             else if (val instanceof Integer JavaDoc)
487             {
488                     Integer JavaDoc in = (Integer JavaDoc) val;
489                     ssy = new SnmpInt32(in);
490                 }
491             else if (val instanceof SnmpObjectId)
492             {
493                     ssy = (SnmpObjectId)val;
494                 }
495             else
496                     log.info("Unknown type for " + be);
497             }
498          catch (Exception JavaDoc e)
499          {
500                 log.warn("getValueFor (" + be.mbean.toString() + ", "
501                         + be.attr.getName() + ": " + e.toString());
502          }
503       }
504       else
505       {
506             ssy = new SnmpNull();
507             log.info(NO_ENTRY_FOUND_FOR_OID + oid);
508         }
509         return ssy;
510     }
511     
512     /**
513      * Set a jmx attribute
514      * @param oid The oid to set. This is translated into a mbean / attribute pair
515      * @param newVal The new value to set
516      * @return null on success, non-null on failure
517      * @throws ReadOnlyException If the referred entry is read only.
518      */

519     private SnmpSyntax setValueFor(final SnmpObjectId oid, final SnmpSyntax newVal) throws ReadOnlyException
520    {
521         final boolean trace = log.isTraceEnabled();
522         
523         BindEntry be = findBindEntryForOid(oid);
524         
525         if (trace)
526             log.trace("setValueFor: found bind entry for " + oid);
527         
528         SnmpSyntax ssy = null;
529         if (be != null)
530       {
531             if (trace)
532                 log.trace("setValueFor: " + be.toString());
533          
534             if (be.isReadWrite == false)
535          {
536                 if (trace)
537                     log.trace("setValueFor: this is marked read only");
538             
539                 throw new ReadOnlyException(oid);
540             }
541             try
542          {
543                 Object JavaDoc val = null;
544                 if (newVal instanceof SnmpOctetString)
545             {
546                     val = newVal.toString();
547                 }
548                 else if (newVal instanceof SnmpInt32)
549             {
550                     val = new Integer JavaDoc(((SnmpInt32)newVal).getValue());
551                 }
552                 else if (newVal instanceof SnmpUInt32)
553             {
554                     val = new Long JavaDoc(((SnmpUInt32)newVal).getValue());
555                 }
556                 // TODO do more mumbo jumbo for type casting / changing
557

558                 if (val != null)
559             {
560                     Attribute JavaDoc at = new Attribute JavaDoc(be.attr.getName(), val);
561                     server.setAttribute(be.mbean, at);
562                     if (trace)
563                         log.trace("setValueFor: set attribute in mbean-Server");
564                 }
565                 else
566             {
567                     log.debug("Did not find a suitable data type for newVal " + newVal);
568                     ssy = new SnmpNull();
569                 }
570                 // TODO
571
}
572             catch (Exception JavaDoc e )
573          {
574                 log.debug("setValueFor: exception " + e.getMessage());
575                 ssy = new SnmpNull();
576             }
577         }
578         else
579       {
580             ssy = new SnmpNull();
581             log.info(NO_ENTRY_FOUND_FOR_OID + oid);
582         }
583         return ssy;
584     }
585
586
587     /**
588      * Lookup a BinEntry on the given oid. If the oid ends in .0,
589      * then the .0 will be stripped of before the search.
590      * @param oid The oid look up.
591      * @return a bind entry or null.
592      */

593     private BindEntry findBindEntryForOid(final SnmpObjectId oid) {
594         
595         ComparableSnmpObjectId coid= new ComparableSnmpObjectId(oid);
596         
597         if (coid.isLeaf())
598         {
599             coid = coid.removeLastPart();
600         }
601         BindEntry be = (BindEntry)bindings.get(coid);
602
603         return be;
604     }
605
606     /**
607      * Return the next oid that is larger than ours.
608      * @param oid the starting oid
609      * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
610      * @return the next oid or null if none found.
611      */

612     private ComparableSnmpObjectId getNextOid(final ComparableSnmpObjectId oid, boolean stayInSubtree) {
613         ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
614
615
616         if (coid.isLeaf())
617             coid = coid.removeLastPart();
618
619         SortedSet JavaDoc ret;
620         ret= oidKeys.tailSet(oid); // get oids >= oid
621
Iterator JavaDoc it = ret.iterator();
622         ComparableSnmpObjectId roid=null;
623         
624         /*
625          * If there are elements in the tail set, then
626          * - get first one.
627          * - if first is input (which it is supposed to be according to the contract of
628          * SortedSet.tailSet() , then get next, which is the
629          * one we look for.
630          */

631         if (it.hasNext())
632         {
633             roid = (ComparableSnmpObjectId)it.next(); // oid
634
}
635         
636         if (roid == null)
637         {
638             return null; // roid is null,
639
}
640         
641         if (roid.compareTo(coid)==0) // input elment
642
{
643             // if there is a next element, then it is ours.
644
if (it.hasNext())
645             {
646                 roid = (ComparableSnmpObjectId)it.next();
647             }
648             else
649             {
650                 roid = null; // end of list
651
}
652         }
653       
654         /*
655          * Check if still in subtree if requested to stay within
656          */

657         if (stayInSubtree && roid != null)
658         {
659             ComparableSnmpObjectId parent = coid.removeLastPart();
660             if (!parent.isRootOf(roid))
661                 roid = null;
662         }
663
664         return roid;
665     }
666
667
668    // Inner Class ---------------------------------------------------
669

670     /**
671      * An entry containing the mapping between oid and mbean/attribute
672      *
673      * @author <a HREF="mailto:pilhuhn@user.sf.net>">Heiko W. Rupp</a>
674      */

675     private class BindEntry implements Comparable JavaDoc {
676         private final ComparableSnmpObjectId oid;
677
678         private ObjectName JavaDoc mbean;
679       private Attribute JavaDoc attr;
680         private String JavaDoc mName;
681       private String JavaDoc aName;
682         private boolean isReadWrite = false;
683
684         /**
685          * Constructs a new BindEntry
686          *
687          * @param oid
688          * The SNMP-oid, this entry will use.
689          * @param mbName
690          * The name of an MBean with attribute to query
691          * @param attrName
692          * The name of the attribute to query
693          */

694         BindEntry(final String JavaDoc oidString, final String JavaDoc mbName, final String JavaDoc attrName) {
695             this(new ComparableSnmpObjectId(oidString),
696                     mbName,
697                     attrName);
698         }
699         
700         /**
701          * Constructs a new BindEntry.
702          * @param coid The SNMP-oid, this entry will use.
703          * @param mbName The name of an MBean with attribute to query
704          * @param attrName The name of the attribute to query
705          */

706         BindEntry(final ComparableSnmpObjectId coid, final String JavaDoc mbName, final String JavaDoc attrName) {
707             oid = coid;
708             this.mName = mbName;
709             this.aName = attrName;
710             try
711          {
712                mbean = new ObjectName JavaDoc(mbName);
713                 attr = new Attribute JavaDoc(attrName, null);
714
715             }
716          catch (Exception JavaDoc e)
717          {
718             log.warn(e.toString());
719                 mName = "-unset-";
720                 aName = "-unset-";
721             }
722         }
723
724         /**
725          * A string representation of this BindEntry
726          */

727         public String JavaDoc toString() {
728             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
729             buf.append("[oid=");
730             buf.append(oid).append(", mbean=");
731             buf.append(mName).append(", attr=");
732             buf.append(aName).append(", rw=");
733             buf.append(isReadWrite).append("]");
734
735             return buf.toString();
736         }
737
738         public Attribute JavaDoc getAttr() {
739             return attr;
740         }
741
742         public ObjectName JavaDoc getMbean()
743       {
744             return mbean;
745         }
746
747         public ComparableSnmpObjectId getOid()
748       {
749             return oid;
750         }
751
752
753         /**
754          * Compare two BindEntries. Ordering is defined at oid-level.
755          *
756          * @param other
757          * The BindEntry to compare to.
758          * @return 0 on equals, 1 if this is bigger than other
759          */

760         public int compareTo(Object JavaDoc other)
761       {
762             if (other == null)
763                 throw new NullPointerException JavaDoc("Can't compare to NULL");
764
765             if (!(other instanceof BindEntry))
766                 throw new ClassCastException JavaDoc("Parameter is no BindEntry");
767
768             // trivial case
769
if (this.equals(other))
770                 return 0;
771          
772             BindEntry obe = (BindEntry) other;
773             if (getOid().equals(obe.getOid()))
774                 return 0;
775
776             int res =oid.compare(obe.getOid());
777             return res;
778         }
779
780     }
781
782 }
783
Popular Tags