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: package com.sun.jndi.url.dir2;
018:
019: import java.util.Hashtable;
020:
021: import javax.naming.Context;
022: import javax.naming.Name;
023: import javax.naming.directory.Attributes;
024: import javax.naming.spi.DirObjectFactory;
025:
026: import org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest;
027: import org.apache.harmony.jndi.tests.javax.naming.util.Log;
028:
029: public class dir2URLContextFactory implements DirObjectFactory {
030:
031: Log log = new Log(dir2URLContextFactory.class);
032:
033: public Object getObjectInstance(Object o, Name n, Context c,
034: Hashtable<?, ?> h) throws Exception {
035: log.setMethod("getObjectInstance");
036: log.log("wrong method call");
037: return getObjectInstance(o, n, c, h, null);
038:
039: }
040:
041: public static class MockObject {
042: private Attributes a;
043:
044: private Object o;
045:
046: private Name n;
047:
048: private Context c;
049:
050: private Hashtable<?, ?> envmt;
051:
052: public MockObject(Object o, Name n, Context c,
053: Hashtable<?, ?> envmt, Attributes a) {
054: this .o = o;
055: this .n = n;
056: this .c = c;
057: this .envmt = envmt;
058: this .a = a;
059: }
060:
061: @Override
062: public String toString() {
063: String s = "MockObject {";
064:
065: s += "Object= " + o + "\n";
066: s += "Name= " + n + "\n";
067: s += "Context= " + c + "\n";
068: s += "Env= " + envmt;
069: s += "Attr= " + a;
070: s += "}";
071:
072: return s;
073: }
074:
075: @Override
076: public boolean equals(Object obj) {
077: if (obj instanceof MockObject) {
078: MockObject theOther = (MockObject) obj;
079: if (o != theOther.o) {
080: return false;
081: }
082:
083: boolean nameEqual = (null == n ? null == theOther.n : n
084: .equals(theOther.n));
085: if (!nameEqual) {
086: return false;
087: }
088:
089: if (c != theOther.c) {
090: return false;
091: }
092:
093: boolean envmtEqual = (null == envmt ? null == theOther.envmt
094: : envmt.equals(theOther.envmt));
095: if (!envmtEqual) {
096: return false;
097: }
098:
099: // This comparison is ignored, why??
100: // DirectoryManagerTest fails if this is enabled
101: //boolean attrEqual = (null == a ? null == theOther.a : a.equals(theOther.a));
102:
103: return true;
104: }
105: return false;
106: }
107: }
108:
109: public Object getObjectInstance(Object o, Name n, Context c,
110: Hashtable<?, ?> h, Attributes a) throws Exception {
111: NamingManagerTest.issueIndicatedExceptions(h);
112: if (NamingManagerTest.returnNullIndicated(h)) {
113: return null;
114: }
115:
116: return new MockObject(o, n, c, h, a);
117: }
118: }
|