001: /*
002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jcr.base;
031:
032: import com.caucho.util.L10N;
033:
034: import javax.jcr.*;
035: import javax.jcr.lock.Lock;
036: import javax.jcr.lock.LockException;
037: import javax.jcr.nodetype.ConstraintViolationException;
038: import javax.jcr.nodetype.NoSuchNodeTypeException;
039: import javax.jcr.nodetype.NodeDefinition;
040: import javax.jcr.nodetype.NodeType;
041: import javax.jcr.version.Version;
042: import javax.jcr.version.VersionException;
043: import javax.jcr.version.VersionHistory;
044: import java.io.InputStream;
045: import java.util.Calendar;
046:
047: /**
048: * Represents a directory node in the repository.
049: */
050: public class BaseNode extends BaseItem implements Node {
051: private static final L10N L = new L10N(BaseNode.class);
052:
053: /**
054: * Returns true for a node.
055: */
056: public boolean isNode() {
057: return true;
058: }
059:
060: /**
061: * Creates a new node given by the relative path.
062: *
063: * @param relPath relative path to the new node.
064: */
065: public Node addNode(String relPath) throws ItemExistsException,
066: PathNotFoundException, VersionException,
067: ConstraintViolationException, LockException,
068: RepositoryException {
069: throw new UnsupportedOperationException(getClass().getName());
070: }
071:
072: /**
073: * Creates a new node given by the relative path.
074: *
075: * @param relPath relative path to the new node.
076: * @param primaryNodeTypeName the node type of the new node
077: */
078: public Node addNode(String relPath, String primaryNodeTypeName)
079: throws ItemExistsException, PathNotFoundException,
080: NoSuchNodeTypeException, LockException, VersionException,
081: ConstraintViolationException, RepositoryException {
082: throw new UnsupportedOperationException(getClass().getName());
083: }
084:
085: /**
086: * Moves the source node before the dest
087: *
088: * @param srcChildRelPath relative path to the source item
089: * @param destChildRelPath relative path to the destination item
090: */
091: public void orderBefore(String srcChildRelPath,
092: String destChildRelPath)
093: throws UnsupportedRepositoryOperationException,
094: VersionException, ConstraintViolationException,
095: ItemNotFoundException, LockException, RepositoryException {
096: throw new UnsupportedOperationException(getClass().getName());
097: }
098:
099: /**
100: * Sets a property of the node.
101: *
102: * @param name single-level name identifying the property
103: * @param value the property's new value
104: */
105: public Property setProperty(String name, Value value)
106: throws ValueFormatException, VersionException,
107: LockException, ConstraintViolationException,
108: RepositoryException {
109: throw new UnsupportedOperationException(getClass().getName());
110: }
111:
112: /**
113: * Sets a property of the node.
114: *
115: * @param name single-level name identifying the property
116: * @param value the property's new value
117: * @param type the property's value type
118: */
119: public Property setProperty(String name, Value value, int type)
120: throws ValueFormatException, VersionException,
121: LockException, ConstraintViolationException,
122: RepositoryException {
123: throw new UnsupportedOperationException(getClass().getName());
124: }
125:
126: /**
127: * Sets a property of the node with a value array.
128: *
129: * @param name single-level name identifying the property
130: * @param values array of values for the property
131: */
132: public Property setProperty(String name, Value[] values)
133: throws ValueFormatException, VersionException,
134: LockException, ConstraintViolationException,
135: RepositoryException {
136: throw new UnsupportedOperationException(getClass().getName());
137: }
138:
139: /**
140: * Sets a property of the node with a value array.
141: *
142: * @param name single-level name identifying the property
143: * @param values array of values for the property
144: * @param type the expected type of the property
145: */
146: public Property setProperty(String name, Value[] values, int type)
147: throws ValueFormatException, VersionException,
148: LockException, ConstraintViolationException,
149: RepositoryException {
150: throw new UnsupportedOperationException(getClass().getName());
151: }
152:
153: /**
154: * Sets a property of the node with an array of string values
155: *
156: * @param name single-level name identifying the property
157: * @param values array of values for the property
158: */
159: public Property setProperty(String name, String[] values)
160: throws ValueFormatException, VersionException,
161: LockException, ConstraintViolationException,
162: RepositoryException {
163: throw new UnsupportedOperationException(getClass().getName());
164: }
165:
166: /**
167: * Sets a property of the node with an array of string values
168: *
169: * @param name single-level name identifying the property
170: * @param values array of values for the property
171: * @param type the expected type of the property
172: */
173: public Property setProperty(String name, String[] values, int type)
174: throws ValueFormatException, VersionException,
175: LockException, ConstraintViolationException,
176: RepositoryException {
177: throw new UnsupportedOperationException(getClass().getName());
178: }
179:
180: /**
181: * Sets a property of the node with a single string value
182: *
183: * @param name single-level name identifying the property
184: * @param values array of values for the property
185: * @param type the expected type of the property
186: */
187: public Property setProperty(String name, String value)
188: throws ValueFormatException, VersionException,
189: LockException, ConstraintViolationException,
190: RepositoryException {
191: throw new UnsupportedOperationException(getClass().getName());
192: }
193:
194: /**
195: * Sets a property of the node with a single string value
196: *
197: * @param name single-level name identifying the property
198: * @param values array of values for the property
199: * @param type the expected type of the property
200: */
201: public Property setProperty(String name, String value, int type)
202: throws ValueFormatException, VersionException,
203: LockException, ConstraintViolationException,
204: RepositoryException {
205: throw new UnsupportedOperationException(getClass().getName());
206: }
207:
208: /**
209: * Sets a property of the node from an input stream
210: *
211: * @param name single-level name identifying the property
212: * @param value input stream containing the data
213: */
214: public Property setProperty(String name, InputStream value)
215: throws ValueFormatException, VersionException,
216: LockException, ConstraintViolationException,
217: RepositoryException {
218: throw new UnsupportedOperationException(getClass().getName());
219: }
220:
221: /**
222: * Sets a property of the node from a boolean
223: *
224: * @param name single-level name identifying the property
225: * @param value boolean data
226: */
227: public Property setProperty(String name, boolean value)
228: throws ValueFormatException, VersionException,
229: LockException, ConstraintViolationException,
230: RepositoryException {
231: throw new UnsupportedOperationException(getClass().getName());
232: }
233:
234: /**
235: * Sets a property of the node from a double
236: *
237: * @param name single-level name identifying the property
238: * @param value double data
239: */
240: public Property setProperty(String name, double value)
241: throws ValueFormatException, VersionException,
242: LockException, ConstraintViolationException,
243: RepositoryException {
244: throw new UnsupportedOperationException(getClass().getName());
245: }
246:
247: /**
248: * Sets a property of the node from a long
249: *
250: * @param name single-level name identifying the property
251: * @param value long data
252: */
253: public Property setProperty(String name, long value)
254: throws ValueFormatException, VersionException,
255: LockException, ConstraintViolationException,
256: RepositoryException {
257: throw new UnsupportedOperationException(getClass().getName());
258: }
259:
260: /**
261: * Sets a property of the node from a date
262: *
263: * @param name single-level name identifying the property
264: * @param value calendar data
265: */
266: public Property setProperty(String name, Calendar value)
267: throws ValueFormatException, VersionException,
268: LockException, ConstraintViolationException,
269: RepositoryException {
270: throw new UnsupportedOperationException(getClass().getName());
271: }
272:
273: /**
274: * Sets a property of the node from a based on a reference to a node
275: *
276: * @param name single-level name identifying the property
277: * @param value node reference
278: */
279: public Property setProperty(String name, Node value)
280: throws ValueFormatException, VersionException,
281: LockException, ConstraintViolationException,
282: RepositoryException {
283: throw new UnsupportedOperationException(getClass().getName());
284: }
285:
286: /**
287: * Returns the node with the given relative path.
288: *
289: * @param name relPath path to the given ndoe.
290: */
291: public Node getNode(String relPath) throws PathNotFoundException,
292: RepositoryException {
293: String[] segments = relPath.split("/");
294:
295: Node node = this ;
296: for (int i = 0; i < segments.length; i++) {
297: String subPath = segments[i];
298:
299: if (subPath.length() == 0)
300: continue;
301:
302: Node nextNode = null;
303:
304: NodeIterator iter = node.getNodes();
305: while (iter.hasNext()) {
306: Node subNode = iter.nextNode();
307:
308: if (subPath.equals(subNode.getName())) {
309: nextNode = subNode;
310: break;
311: }
312: }
313:
314: if (nextNode == null) {
315: throw new PathNotFoundException(L.l(
316: "'{0}' is an unknown node in {1}", relPath,
317: this ));
318: }
319:
320: node = nextNode;
321: }
322:
323: return node;
324: }
325:
326: /**
327: * Returns the direct child nodes.
328: */
329: public NodeIterator getNodes() throws RepositoryException {
330: throw new UnsupportedOperationException(getClass().getName());
331: }
332:
333: /**
334: * Returns the child nodes matching the name pattern.
335: */
336: public NodeIterator getNodes(String namePattern)
337: throws RepositoryException {
338: throw new UnsupportedOperationException(getClass().getName());
339: }
340:
341: /**
342: * Returns the property based on the relative path.
343: */
344: public Property getProperty(String relPath)
345: throws PathNotFoundException, RepositoryException {
346: int p = relPath.lastIndexOf('/');
347:
348: if (p >= 0) {
349: String nodePath = relPath.substring(0, p);
350: String tailPath = relPath.substring(p + 1);
351:
352: return getNode(nodePath).getProperty(tailPath);
353: }
354:
355: throw new PathNotFoundException(L.l(
356: "'{0}' is an unknown property in {1}'", relPath, this ));
357: }
358:
359: /**
360: * Returns the an iterator of the properties of the node.
361: */
362: public PropertyIterator getProperties() throws RepositoryException {
363: throw new UnsupportedOperationException(getClass().getName());
364: }
365:
366: /**
367: * Returns the an iterator of the properties of the node matching
368: * the pattern.
369: */
370: public PropertyIterator getProperties(String namePattern)
371: throws RepositoryException {
372: throw new UnsupportedOperationException(getClass().getName());
373: }
374:
375: /**
376: * Returns the node's primary item.
377: */
378: public Item getPrimaryItem() throws ItemNotFoundException,
379: RepositoryException {
380: throw new UnsupportedOperationException(getClass().getName());
381: }
382:
383: /**
384: * Returns the node's UUID
385: */
386: public String getUUID()
387: throws UnsupportedRepositoryOperationException,
388: RepositoryException {
389: throw new UnsupportedOperationException(getClass().getName());
390: }
391:
392: /**
393: * Returns the node's index
394: */
395: public int getIndex() throws RepositoryException {
396: return 0;
397: }
398:
399: /**
400: * Returns the an iterator of the references
401: */
402: public PropertyIterator getReferences() throws RepositoryException {
403: throw new UnsupportedOperationException(getClass().getName());
404: }
405:
406: /**
407: * Returns true if the path points to a node.
408: *
409: * @param relPath path to a property
410: */
411: public boolean hasNode(String relPath) throws RepositoryException {
412: try {
413: return getNode(relPath) != null;
414: } catch (PathNotFoundException e) {
415: return false;
416: }
417: }
418:
419: /**
420: * Returns true if the path points to a property.
421: *
422: * @param relPath path to a property
423: */
424: public boolean hasProperty(String relPath)
425: throws RepositoryException {
426: try {
427: return getProperty(relPath) != null;
428: } catch (PathNotFoundException e) {
429: return false;
430: }
431: }
432:
433: /**
434: * Returns true if the node has child nodes.
435: */
436: public boolean hasNodes() throws RepositoryException {
437: return false;
438: }
439:
440: /**
441: * Returns true if the node has any properties.
442: */
443: public boolean hasProperties() throws RepositoryException {
444: return false;
445: }
446:
447: /**
448: * Returns the node's primary type.
449: */
450: public NodeType getPrimaryNodeType() throws RepositoryException {
451: return BaseNodeType.NT_BASE;
452: }
453:
454: /**
455: * Returns any mixin types for the node.
456: */
457: public NodeType[] getMixinNodeTypes() throws RepositoryException {
458: return new NodeType[0];
459: }
460:
461: /**
462: * Returns true if the node supports the given node type.
463: */
464: public boolean isNodeType(String nodeTypeName)
465: throws RepositoryException {
466: NodeType nodeType = getPrimaryNodeType();
467:
468: if (nodeType.getName().equals(nodeTypeName))
469: return true;
470:
471: NodeType[] super Types = nodeType.getSupertypes();
472:
473: for (int i = super Types.length - 1; i >= 0; i--) {
474: if (super Types[i].getName().equals(nodeTypeName))
475: return true;
476: }
477:
478: return false;
479: }
480:
481: /**
482: * Adds a mixin type to the node.
483: */
484: public void addMixin(String mixinName)
485: throws NoSuchNodeTypeException, VersionException,
486: ConstraintViolationException, LockException,
487: RepositoryException {
488: throw new UnsupportedOperationException(getClass().getName());
489: }
490:
491: /**
492: * Removes a mixin type to the node.
493: */
494: public void removeMixin(String mixinName)
495: throws NoSuchNodeTypeException, VersionException,
496: ConstraintViolationException, LockException,
497: RepositoryException {
498: throw new UnsupportedOperationException(getClass().getName());
499: }
500:
501: /**
502: * Returns true if the given mixin type can be added to the node.
503: */
504: public boolean canAddMixin(String mixinName)
505: throws NoSuchNodeTypeException, RepositoryException {
506: return false;
507: }
508:
509: /**
510: * Returns a description of the node.
511: */
512: public NodeDefinition getDefinition() throws RepositoryException {
513: throw new UnsupportedOperationException(getClass().getName());
514: }
515:
516: /**
517: * Checks in a new version for to the node.
518: */
519: public Version checkin() throws VersionException,
520: UnsupportedRepositoryOperationException,
521: InvalidItemStateException, LockException,
522: RepositoryException {
523: throw new UnsupportedOperationException(getClass().getName());
524: }
525:
526: /**
527: * Checks out a version.
528: */
529: public void checkout()
530: throws UnsupportedRepositoryOperationException,
531: LockException, RepositoryException {
532: throw new UnsupportedOperationException(getClass().getName());
533: }
534:
535: /**
536: * Mark the version merge as complete.
537: */
538: public void doneMerge(Version version) throws VersionException,
539: InvalidItemStateException,
540: UnsupportedRepositoryOperationException,
541: RepositoryException {
542: throw new UnsupportedOperationException(getClass().getName());
543: }
544:
545: /**
546: * Cancel a version merge.
547: */
548: public void cancelMerge(Version version) throws VersionException,
549: InvalidItemStateException,
550: UnsupportedRepositoryOperationException,
551: RepositoryException {
552: throw new UnsupportedOperationException(getClass().getName());
553: }
554:
555: /**
556: * Updates a workspace
557: */
558: public void update(String srcWorkspaceName)
559: throws NoSuchWorkspaceException, AccessDeniedException,
560: LockException, InvalidItemStateException,
561: RepositoryException {
562: throw new UnsupportedOperationException(getClass().getName());
563: }
564:
565: /**
566: * Merges child nodes.
567: */
568: public NodeIterator merge(String srcWorkspace, boolean bestEffort)
569: throws NoSuchWorkspaceException, AccessDeniedException,
570: MergeException, LockException, InvalidItemStateException,
571: RepositoryException {
572: throw new UnsupportedOperationException(getClass().getName());
573: }
574:
575: /**
576: * Returns the node path to a workspace.
577: */
578: public String getCorrespondingNodePath(String workspaceName)
579: throws ItemNotFoundException, NoSuchWorkspaceException,
580: AccessDeniedException, RepositoryException {
581: throw new UnsupportedOperationException(getClass().getName());
582: }
583:
584: /**
585: * Returns true for a checked out node.
586: */
587: public boolean isCheckedOut() throws RepositoryException {
588: throw new UnsupportedOperationException(getClass().getName());
589: }
590:
591: /**
592: * Restore the node based on an older version.
593: */
594: public void restore(String versionName, boolean removeExisting)
595: throws VersionException, ItemExistsException,
596: UnsupportedRepositoryOperationException, LockException,
597: InvalidItemStateException, RepositoryException {
598: throw new UnsupportedOperationException(getClass().getName());
599: }
600:
601: /**
602: * Restore the node based on an older version.
603: */
604: public void restore(Version version, boolean removeExisting)
605: throws VersionException, ItemExistsException,
606: UnsupportedRepositoryOperationException, LockException,
607: RepositoryException {
608: throw new UnsupportedOperationException(getClass().getName());
609: }
610:
611: /**
612: * Restore the node based on an older version.
613: */
614: public void restore(Version version, String relPath,
615: boolean removeExisting) throws PathNotFoundException,
616: ItemExistsException, VersionException,
617: ConstraintViolationException,
618: UnsupportedRepositoryOperationException, LockException,
619: InvalidItemStateException, RepositoryException {
620: throw new UnsupportedOperationException(getClass().getName());
621: }
622:
623: /**
624: * Restore the node based on an older version.
625: */
626: public void restoreByLabel(String versionLabel,
627: boolean removeExisting) throws VersionException,
628: ItemExistsException,
629: UnsupportedRepositoryOperationException, LockException,
630: InvalidItemStateException, RepositoryException {
631: throw new UnsupportedOperationException(getClass().getName());
632: }
633:
634: /**
635: * Returns the node's version history.
636: */
637: public VersionHistory getVersionHistory()
638: throws UnsupportedRepositoryOperationException,
639: RepositoryException {
640: throw new UnsupportedOperationException(getClass().getName());
641: }
642:
643: /**
644: * Returns the base version.
645: */
646: public Version getBaseVersion()
647: throws UnsupportedRepositoryOperationException,
648: RepositoryException {
649: throw new UnsupportedOperationException(getClass().getName());
650: }
651:
652: /**
653: * Lock the node.
654: */
655: public Lock lock(boolean isDeep, boolean isSessionScoped)
656: throws UnsupportedRepositoryOperationException,
657: LockException, AccessDeniedException,
658: InvalidItemStateException, RepositoryException {
659: throw new UnsupportedOperationException(getClass().getName());
660: }
661:
662: /**
663: * Returns the current lock.
664: */
665: public Lock getLock()
666: throws UnsupportedRepositoryOperationException,
667: LockException, AccessDeniedException, RepositoryException {
668: throw new UnsupportedOperationException(getClass().getName());
669: }
670:
671: /**
672: * Unlocks the node.
673: */
674: public void unlock()
675: throws UnsupportedRepositoryOperationException,
676: LockException, AccessDeniedException,
677: InvalidItemStateException, RepositoryException {
678: throw new UnsupportedOperationException(getClass().getName());
679: }
680:
681: /**
682: * Returns true if the node owns a lock.
683: */
684: public boolean holdsLock() throws RepositoryException {
685: return false;
686: }
687:
688: /**
689: * Returns true if the node is locked.
690: */
691: public boolean isLocked() throws RepositoryException {
692: return false;
693: }
694: }
|