KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > DefaultMOQuery


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - DefaultMOQuery.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22 package org.snmp4j.agent;
23
24 // For JavaDoc
25
import org.snmp4j.agent.request.Request;
26
27 /**
28  * The <code>DefaultMOQuery</code> class is the default implementation of a
29  * managed object query. It is used to lookup managed objects, for example in
30  * a {@link MOServer} repository.
31  *
32  * @author Frank Fock
33  * @version 1.1
34  */

35 public class DefaultMOQuery implements MOQuery {
36
37   private MOContextScope scope;
38   private boolean writeAccessQuery;
39   private Object JavaDoc source;
40
41   /**
42    * Creates a context aware query from a context aware OID scope.
43    * @param scope
44    * a scope that defines the possible result set of OIDs from a specific
45    * context for this query.
46    */

47   public DefaultMOQuery(MOContextScope scope) {
48     this.scope = scope;
49   }
50
51   /**
52    * Creates a context aware query from a context aware OID scope.
53    * @param scope
54    * a scope that defines the possible result set of OIDs from a specific
55    * context for this query.
56    * @param isWriteAccessIntended
57    * indicates whether this query serves a write access on
58    * {@link ManagedObject}s or not.
59    * @since 1.1
60    */

61   public DefaultMOQuery(MOContextScope scope, boolean isWriteAccessIntended) {
62     this(scope);
63     this.writeAccessQuery = isWriteAccessIntended;
64   }
65
66   /**
67    * Creates a context aware query from a context aware OID scope.
68    * @param scope
69    * a scope that defines the possible result set of OIDs from a specific
70    * context for this query.
71    * @param isWriteAccessIntended
72    * indicates whether this query serves a write access on
73    * {@link ManagedObject}s or not.
74    * @since 1.1
75    */

76   public DefaultMOQuery(MOContextScope scope, boolean isWriteAccessIntended,
77                         Object JavaDoc source) {
78     this(scope, isWriteAccessIntended);
79     this.source = source;
80   }
81
82   /**
83    * Gets the search range of this query.
84    *
85    * @return a <code>MORange</code> instance denoting upper and lower bound of
86    * this queries scope.
87    */

88   public MOContextScope getScope() {
89     return scope;
90   }
91
92   /**
93    * Checks whether a managed object matches the internal query criteria
94    * defined by this query.
95    *
96    * @param managedObject the <code>ManagedObject</code> instance to check.
97    * @return <code>true</code> if the <code>managedObject</code> matches the
98    * query.
99    */

100   public boolean matchesQuery(ManagedObject managedObject) {
101     return true;
102   }
103
104   public void substractScope(MOScope scope) {
105     if (this.scope instanceof MutableMOScope) {
106       ((MutableMOScope)this.scope).substractScope(scope);
107     }
108     else {
109       throw new UnsupportedOperationException JavaDoc();
110     }
111   }
112
113   public String JavaDoc toString() {
114     return getClass().getName()+"["+getScope().getContext()+"]="+
115         getScope().getLowerBound()+"<"+
116         (getScope().isLowerIncluded() ? "=" : "")+" x <"+
117         (getScope().isUpperIncluded() ? "=" : "")+
118         getScope().getUpperBound();
119   }
120
121   public boolean isWriteAccessQuery() {
122     return writeAccessQuery;
123   }
124
125   /**
126    * Gets the source ({@link Request}) object on whose behalf this query is
127    * executed. This object reference can be used to determine whether a query
128    * needs to update {@link ManagedObject} content or not. When the reference
129    * is the same as those from the last query then an update is not necessary.
130    *
131    * @return
132    * an Object on whose behalf this query is executed which will be in most
133    * cases a {@link Request} instance, but code should not rely on that. If
134    * <code>null</code> is returned, the query source cannot be determined.
135    * @since 1.1
136    */

137   public Object JavaDoc getSource() {
138     return source;
139   }
140
141   /**
142    * This method checks whether the supplied query and the given source
143    * reference refer to the same source (request).
144    *
145    * @param query
146    * a <code>MOQuery</code> instance.
147    * @param source
148    * any source object reference.
149    * @return
150    * <code>true</code> only if <code>query</code> is a
151    * <code>DefaultMOQuery</code> instance and
152    * <code>{@link DefaultMOQuery#getSource()} == source</code> and source
153    * is not <code>null</code>.
154    * @since 1.1
155    */

156   public static boolean isSameSource(MOQuery query, Object JavaDoc source) {
157     if (query instanceof DefaultMOQuery) {
158       return ((source != null) &&
159               (((DefaultMOQuery)query).getSource() == source));
160     }
161     return false;
162   }
163 }
164
Popular Tags