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 com.sun.jndi.url.nntp;
019:
020: import java.util.Hashtable;
021:
022: import javax.naming.Context;
023: import javax.naming.Name;
024: import javax.naming.spi.ObjectFactory;
025:
026: import org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest;
027:
028: public class nntpURLContextFactory implements ObjectFactory {
029:
030: public Object getObjectInstance(Object o, Name n, Context c,
031: Hashtable<?, ?> h) throws Exception {
032:
033: NamingManagerTest.issueIndicatedExceptions(h);
034: if (NamingManagerTest.returnNullIndicated(h)) {
035: return null;
036: }
037:
038: return new MockObject(o, n, c, h);
039: }
040:
041: public static class MockObject {
042: private Object o;
043:
044: private Name n;
045:
046: private Context c;
047:
048: private Hashtable<?, ?> envmt;
049:
050: public MockObject(Object o, Name n, Context c,
051: Hashtable<?, ?> envmt) {
052: this .o = o;
053: this .n = n;
054: this .c = c;
055: this .envmt = envmt;
056: }
057:
058: @Override
059: public String toString() {
060: String s = "MockObject {";
061:
062: s += "Object= " + o + "\n";
063: s += "Name= " + n + "\n";
064: s += "Context= " + c + "\n";
065: s += "Env= " + envmt;
066:
067: s += "}";
068:
069: return s;
070: }
071:
072: @Override
073: public boolean equals(Object obj) {
074: if (obj instanceof MockObject) {
075: MockObject theOther = (MockObject) obj;
076: if (o != theOther.o) {
077: return false;
078: }
079:
080: boolean nameEqual = (null == n ? null == theOther.n : n
081: .equals(theOther.n));
082: if (!nameEqual) {
083: return false;
084: }
085:
086: if (c != theOther.c) {
087: return false;
088: }
089:
090: boolean envmtEqual = (null == envmt ? null == theOther.envmt
091: : envmt.equals(theOther.envmt));
092: if (!envmtEqual) {
093: return false;
094: }
095:
096: return true;
097: }
098: return false;
099: }
100: }
101: }
|