01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.core;
16:
17: import java.util.Collection;
18: import java.util.Iterator;
19: import java.util.LinkedList;
20: import java.util.StringTokenizer;
21: import org.araneaframework.Path;
22:
23: /**
24: * Default implementation of {@link org.araneaframework.Path}, uses simple string
25: * identifiers like "a" or "b" and combines them using dots forming full
26: * pathes like "a.b.c".
27: *
28: * @author "Toomas Römer" <toomas@webmedia.ee>
29: */
30: public class StandardPath implements Path {
31: private LinkedList path = new LinkedList();
32:
33: /**
34: * Constructs a path from the fullPath. Expects fullPath to be a dot-separated String.
35: * @param fullPath
36: */
37: public StandardPath(String fullPath) {
38: Assert.notNull(fullPath, "Path cannot be null!");
39:
40: StringTokenizer tokenizer = new StringTokenizer(fullPath, ".");
41:
42: while (tokenizer.hasMoreElements()) {
43: path.add(tokenizer.nextElement());
44: }
45: }
46:
47: /**
48: * @see org.araneaframework.Path#getNext()
49: */
50: public Object getNext() {
51: return path.getFirst();
52: }
53:
54: /**
55: * @see org.araneaframework.Path#next()
56: */
57: public Object next() {
58: return path.removeFirst();
59: }
60:
61: /**
62: * @see org.araneaframework.Path#hasNext()
63: */
64: public boolean hasNext() {
65: return path.size() > 0;
66: }
67:
68: /**
69: * @since 1.1
70: */
71: public StandardPath(Collection fullPath) {
72: path.addAll(fullPath);
73: }
74:
75: /**
76: * Returns this {@link org.araneaframework.Path} as a dot-separated String.
77: * @return this {@link org.araneaframework.Path} as a dot-separated String
78: */
79: public String toString() {
80: StringBuffer result = new StringBuffer();
81:
82: for (Iterator i = path.iterator(); i.hasNext();) {
83: result.append((String) i.next());
84: if (i.hasNext())
85: result.append('.');
86: }
87:
88: return result.toString();
89: }
90: }
|