001: /*
002:
003: Derby - Class org.apache.derby.impl.services.monitor.ModuleInstance
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.services.monitor;
023:
024: import org.apache.derby.iapi.services.monitor.PersistentService;
025:
026: import java.util.Properties;
027:
028: /**
029: A description of an instance of a module.
030: */
031:
032: class ModuleInstance {
033:
034: /*
035: ** Fields.
036: */
037:
038: /**
039: The module instance
040: */
041: protected Object instance;
042:
043: /**
044: name of module, can be null
045: */
046: protected String identifier;
047:
048: /**
049: the top-level service this module lives in, can be null or the service itself
050: */
051: protected Object topLevelService;
052:
053: /**
054: the actual service to which I belong, could be null.
055: */
056: protected Object service;
057:
058: /*
059: ** Constructor
060: */
061:
062: protected ModuleInstance(Object instance, String identifier,
063: Object service, Object topLevelService) {
064: super ();
065: this .instance = instance;
066: this .identifier = identifier;
067: this .topLevelService = topLevelService;
068: this .service = service;
069:
070: }
071:
072: protected ModuleInstance(Object instance) {
073:
074: this (instance, null, null, null);
075: }
076:
077: protected boolean isTypeAndName(PersistentService serviceType,
078: Class factoryInterface, String otherCanonicalName) {
079: // see if the correct interface is implemented
080: if (!factoryInterface.isInstance(instance))
081: return false;
082:
083: if ((serviceType != null) && (otherCanonicalName != null))
084: return serviceType.isSameService(identifier,
085: otherCanonicalName);
086:
087: // see if the identifiers match
088: if (otherCanonicalName != null) {
089: if (identifier == null)
090: return false;
091: if (!otherCanonicalName.equals(identifier))
092: return false;
093: } else if (identifier != null) {
094: return false;
095: }
096:
097: return true;
098: }
099:
100: protected String getIdentifier() {
101: return identifier;
102: }
103:
104: protected Object getTopLevelService() {
105: return topLevelService;
106: }
107:
108: protected Object getInstance() {
109: return instance;
110: }
111: }
|