001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.mock;
016:
017: import java.util.ArrayList;
018: import java.util.Collections;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Map;
023: import org.apache.commons.lang.NotImplementedException;
024: import org.araneaframework.InputData;
025: import org.araneaframework.OutputData;
026: import org.araneaframework.Path;
027: import org.araneaframework.core.StandardPath;
028:
029: /**
030: * @author "Toomas Römer" <toomas@webmedia.ee>
031: *
032: */
033: public class MockOutputData implements OutputData {
034: private Map data;
035: private List pathPrefix;
036:
037: public MockOutputData(Map data) {
038: this ();
039: this .data = data;
040: }
041:
042: public MockOutputData() {
043: data = new HashMap();
044: pathPrefix = new ArrayList();
045: }
046:
047: public Path getScope() {
048: return new StandardPath(getScopePathString());
049: }
050:
051: public Object getAttribute(Object key) {
052: //XXX
053: return getScopedData().get(key);
054: }
055:
056: public Map getAttributes() {
057: //XXX
058: return Collections.unmodifiableMap(getScopedData());
059: }
060:
061: public void pushScope(Object step) {
062: pathPrefix.add(step);
063: }
064:
065: public void popScope() {
066: pathPrefix.remove(pathPrefix.size() - 1);
067: }
068:
069: public String toString() {
070: return getScopePathString();
071: }
072:
073: /*
074: ** PRIVATE METHODS
075: */
076: private Map getScopedData() {
077: String path = getScopePathString();
078: if (data.get(path) == null) {
079: return new HashMap();
080: } else {
081: return (Map) data.get(path);
082: }
083: }
084:
085: private String getScopePathString() {
086: StringBuffer result = new StringBuffer();
087: Iterator ite = pathPrefix.iterator();
088: while (ite.hasNext()) {
089: result.append(ite.next() + ".");
090: }
091: if (result.length() > 0) {
092: result = new StringBuffer(result.substring(0, result
093: .length() - 1));
094: }
095: return result.toString();
096: }
097:
098: public void extend(Class interfaceClass, Object implementation) {
099: //XXX
100: throw new NotImplementedException();
101: }
102:
103: public Object narrow(Class interfaceClass) {
104: //XXX
105: throw new NotImplementedException();
106: }
107:
108: public void pushAttribute(Object key, Object value) {
109: //XXX
110: }
111:
112: public Object popAttribute(Object key) {
113: //XXX
114: return null;
115: }
116:
117: public void restoreScope(Path scope) {
118: //XXX
119: }
120:
121: public InputData getInputData() {
122: return null;
123: }
124: }
|