KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jcr > base > BaseNode


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jcr.base;
31
32 import com.caucho.util.L10N;
33
34 import javax.jcr.*;
35 import javax.jcr.lock.Lock;
36 import javax.jcr.lock.LockException;
37 import javax.jcr.nodetype.ConstraintViolationException;
38 import javax.jcr.nodetype.NoSuchNodeTypeException;
39 import javax.jcr.nodetype.NodeDefinition;
40 import javax.jcr.nodetype.NodeType;
41 import javax.jcr.version.Version;
42 import javax.jcr.version.VersionException;
43 import javax.jcr.version.VersionHistory;
44 import java.io.InputStream JavaDoc;
45 import java.util.Calendar JavaDoc;
46
47 /**
48  * Represents a directory node in the repository.
49  */

50 public class BaseNode extends BaseItem implements Node {
51   private static final L10N L = new L10N(BaseNode.class);
52   /**
53    * Returns true for a node.
54    */

55   public boolean isNode()
56   {
57     return true;
58   }
59   
60   /**
61    * Creates a new node given by the relative path.
62    *
63    * @param relPath relative path to the new node.
64    */

65   public Node addNode(String JavaDoc relPath)
66     throws ItemExistsException,
67        PathNotFoundException,
68        VersionException,
69        ConstraintViolationException,
70        LockException,
71        RepositoryException
72   {
73     throw new UnsupportedOperationException JavaDoc(getClass().getName());
74   }
75   
76   /**
77    * Creates a new node given by the relative path.
78    *
79    * @param relPath relative path to the new node.
80    * @param primaryNodeTypeName the node type of the new node
81    */

82   public Node addNode(String JavaDoc relPath,
83               String JavaDoc primaryNodeTypeName)
84     throws ItemExistsException,
85        PathNotFoundException,
86        NoSuchNodeTypeException,
87        LockException,
88        VersionException,
89        ConstraintViolationException,
90        RepositoryException
91   {
92     throw new UnsupportedOperationException JavaDoc(getClass().getName());
93   }
94   
95   /**
96    * Moves the source node before the dest
97    *
98    * @param srcChildRelPath relative path to the source item
99    * @param destChildRelPath relative path to the destination item
100    */

101   public void orderBefore(String JavaDoc srcChildRelPath,
102               String JavaDoc destChildRelPath)
103     throws UnsupportedRepositoryOperationException,
104        VersionException,
105        ConstraintViolationException,
106        ItemNotFoundException,
107        LockException,
108        RepositoryException
109   {
110     throw new UnsupportedOperationException JavaDoc(getClass().getName());
111   }
112
113
114   /**
115    * Sets a property of the node.
116    *
117    * @param name single-level name identifying the property
118    * @param value the property's new value
119    */

120   public Property setProperty(String JavaDoc name, Value value)
121     throws ValueFormatException,
122        VersionException,
123        LockException,
124        ConstraintViolationException,
125        RepositoryException
126   {
127     throw new UnsupportedOperationException JavaDoc(getClass().getName());
128   }
129   
130   /**
131    * Sets a property of the node.
132    *
133    * @param name single-level name identifying the property
134    * @param value the property's new value
135    * @param type the property's value type
136    */

137   public Property setProperty(String JavaDoc name, Value value, int type)
138     throws ValueFormatException,
139        VersionException,
140        LockException,
141        ConstraintViolationException,
142        RepositoryException
143   {
144     throw new UnsupportedOperationException JavaDoc(getClass().getName());
145   }
146
147   /**
148    * Sets a property of the node with a value array.
149    *
150    * @param name single-level name identifying the property
151    * @param values array of values for the property
152    */

153   public Property setProperty(String JavaDoc name, Value[] values)
154     throws ValueFormatException,
155        VersionException,
156        LockException,
157        ConstraintViolationException,
158        RepositoryException
159   {
160     throw new UnsupportedOperationException JavaDoc(getClass().getName());
161   }
162   
163   /**
164    * Sets a property of the node with a value array.
165    *
166    * @param name single-level name identifying the property
167    * @param values array of values for the property
168    * @param type the expected type of the property
169    */

170   public Property setProperty(String JavaDoc name,
171                   Value[] values,
172                   int type)
173     throws ValueFormatException,
174        VersionException,
175        LockException,
176        ConstraintViolationException,
177        RepositoryException
178   {
179     throw new UnsupportedOperationException JavaDoc(getClass().getName());
180   }
181   
182   /**
183    * Sets a property of the node with an array of string values
184    *
185    * @param name single-level name identifying the property
186    * @param values array of values for the property
187    */

188   public Property setProperty(String JavaDoc name, String JavaDoc[] values)
189     throws ValueFormatException,
190        VersionException,
191        LockException,
192        ConstraintViolationException,
193        RepositoryException
194   {
195     throw new UnsupportedOperationException JavaDoc(getClass().getName());
196   }
197
198   /**
199    * Sets a property of the node with an array of string values
200    *
201    * @param name single-level name identifying the property
202    * @param values array of values for the property
203    * @param type the expected type of the property
204    */

205   public Property setProperty(String JavaDoc name, String JavaDoc[] values, int type)
206     throws ValueFormatException,
207        VersionException,
208        LockException,
209        ConstraintViolationException,
210        RepositoryException
211   {
212     throw new UnsupportedOperationException JavaDoc(getClass().getName());
213   }
214
215   /**
216    * Sets a property of the node with a single string value
217    *
218    * @param name single-level name identifying the property
219    * @param values array of values for the property
220    * @param type the expected type of the property
221    */

222   public Property setProperty(String JavaDoc name, String JavaDoc value)
223     throws ValueFormatException,
224        VersionException,
225        LockException,
226        ConstraintViolationException,
227        RepositoryException
228   {
229     throw new UnsupportedOperationException JavaDoc(getClass().getName());
230   }
231
232   /**
233    * Sets a property of the node with a single string value
234    *
235    * @param name single-level name identifying the property
236    * @param values array of values for the property
237    * @param type the expected type of the property
238    */

239   public Property setProperty(String JavaDoc name, String JavaDoc value, int type)
240     throws ValueFormatException,
241        VersionException,
242        LockException,
243        ConstraintViolationException,
244        RepositoryException
245   {
246     throw new UnsupportedOperationException JavaDoc(getClass().getName());
247   }
248   
249   /**
250    * Sets a property of the node from an input stream
251    *
252    * @param name single-level name identifying the property
253    * @param value input stream containing the data
254    */

255   public Property setProperty(String JavaDoc name, InputStream JavaDoc value)
256     throws ValueFormatException,
257        VersionException,
258        LockException,
259        ConstraintViolationException,
260        RepositoryException
261   {
262     throw new UnsupportedOperationException JavaDoc(getClass().getName());
263   }
264   
265   /**
266    * Sets a property of the node from a boolean
267    *
268    * @param name single-level name identifying the property
269    * @param value boolean data
270    */

271   public Property setProperty(String JavaDoc name, boolean value)
272     throws ValueFormatException,
273        VersionException,
274        LockException,
275        ConstraintViolationException,
276        RepositoryException
277   {
278     throw new UnsupportedOperationException JavaDoc(getClass().getName());
279   }
280   
281   /**
282    * Sets a property of the node from a double
283    *
284    * @param name single-level name identifying the property
285    * @param value double data
286    */

287   public Property setProperty(String JavaDoc name, double value)
288     throws ValueFormatException,
289        VersionException,
290        LockException,
291        ConstraintViolationException,
292        RepositoryException
293   {
294     throw new UnsupportedOperationException JavaDoc(getClass().getName());
295   }
296   
297   /**
298    * Sets a property of the node from a long
299    *
300    * @param name single-level name identifying the property
301    * @param value long data
302    */

303   public Property setProperty(String JavaDoc name, long value)
304     throws ValueFormatException,
305        VersionException,
306        LockException,
307        ConstraintViolationException,
308        RepositoryException
309   {
310     throw new UnsupportedOperationException JavaDoc(getClass().getName());
311   }
312   
313   /**
314    * Sets a property of the node from a date
315    *
316    * @param name single-level name identifying the property
317    * @param value calendar data
318    */

319   public Property setProperty(String JavaDoc name, Calendar JavaDoc value)
320     throws ValueFormatException,
321        VersionException,
322        LockException,
323        ConstraintViolationException,
324        RepositoryException
325   {
326     throw new UnsupportedOperationException JavaDoc(getClass().getName());
327   }
328
329   /**
330    * Sets a property of the node from a based on a reference to a node
331    *
332    * @param name single-level name identifying the property
333    * @param value node reference
334    */

335   public Property setProperty(String JavaDoc name, Node value)
336     throws ValueFormatException,
337        VersionException,
338        LockException,
339        ConstraintViolationException,
340        RepositoryException
341   {
342     throw new UnsupportedOperationException JavaDoc(getClass().getName());
343   }
344   
345   /**
346    * Returns the node with the given relative path.
347    *
348    * @param name relPath path to the given ndoe.
349    */

350   public Node getNode(String JavaDoc relPath)
351     throws PathNotFoundException,
352        RepositoryException
353   {
354     String JavaDoc []segments = relPath.split("/");
355
356     Node node = this;
357     for (int i = 0; i < segments.length; i++) {
358       String JavaDoc subPath = segments[i];
359
360       if (subPath.length() == 0)
361     continue;
362
363       Node nextNode = null;
364       
365       NodeIterator iter = node.getNodes();
366       while (iter.hasNext()) {
367     Node subNode = iter.nextNode();
368
369     if (subPath.equals(subNode.getName())) {
370       nextNode = subNode;
371       break;
372     }
373       }
374
375       if (nextNode == null) {
376     throw new PathNotFoundException(L.l("'{0}' is an unknown node in {1}",
377                         relPath, this));
378       }
379
380       node = nextNode;
381     }
382
383     return node;
384   }
385   
386   /**
387    * Returns the direct child nodes.
388    */

389   public NodeIterator getNodes()
390     throws RepositoryException
391   {
392     throw new UnsupportedOperationException JavaDoc(getClass().getName());
393   }
394
395   /**
396    * Returns the child nodes matching the name pattern.
397    */

398   public NodeIterator getNodes(String JavaDoc namePattern)
399     throws RepositoryException
400   {
401     throw new UnsupportedOperationException JavaDoc(getClass().getName());
402   }
403   
404   /**
405    * Returns the property based on the relative path.
406    */

407   public Property getProperty(String JavaDoc relPath)
408     throws PathNotFoundException,
409        RepositoryException
410   {
411     int p = relPath.lastIndexOf('/');
412
413     if (p >= 0) {
414       String JavaDoc nodePath = relPath.substring(0, p);
415       String JavaDoc tailPath = relPath.substring(p + 1);
416     
417       return getNode(nodePath).getProperty(tailPath);
418     }
419
420     throw new PathNotFoundException(L.l("'{0}' is an unknown property in {1}'",
421                     relPath, this));
422   }
423   
424   /**
425    * Returns the an iterator of the properties of the node.
426    */

427   public PropertyIterator getProperties()
428     throws RepositoryException
429   {
430     throw new UnsupportedOperationException JavaDoc(getClass().getName());
431   }
432   
433   /**
434    * Returns the an iterator of the properties of the node matching
435    * the pattern.
436    */

437   public PropertyIterator getProperties(String JavaDoc namePattern)
438     throws RepositoryException
439   {
440     throw new UnsupportedOperationException JavaDoc(getClass().getName());
441   }
442
443   /**
444    * Returns the node's primary item.
445    */

446   public Item getPrimaryItem()
447     throws ItemNotFoundException,
448        RepositoryException
449   {
450     throw new UnsupportedOperationException JavaDoc(getClass().getName());
451   }
452
453   /**
454    * Returns the node's UUID
455    */

456   public String JavaDoc getUUID()
457     throws UnsupportedRepositoryOperationException,
458        RepositoryException
459   {
460     throw new UnsupportedOperationException JavaDoc(getClass().getName());
461   }
462   
463   /**
464    * Returns the node's index
465    */

466   public int getIndex()
467     throws RepositoryException
468   {
469     return 0;
470   }
471   
472   /**
473    * Returns the an iterator of the references
474    */

475   public PropertyIterator getReferences()
476     throws RepositoryException
477   {
478     throw new UnsupportedOperationException JavaDoc(getClass().getName());
479   }
480   
481   /**
482    * Returns true if the path points to a node.
483    *
484    * @param relPath path to a property
485    */

486   public boolean hasNode(String JavaDoc relPath)
487     throws RepositoryException
488   {
489     try {
490       return getNode(relPath) != null;
491     } catch (PathNotFoundException e) {
492       return false;
493     }
494   }
495   
496   /**
497    * Returns true if the path points to a property.
498    *
499    * @param relPath path to a property
500    */

501   public boolean hasProperty(String JavaDoc relPath)
502     throws RepositoryException
503   {
504     try {
505       return getProperty(relPath) != null;
506     } catch (PathNotFoundException e) {
507       return false;
508     }
509   }
510   
511   /**
512    * Returns true if the node has child nodes.
513    */

514   public boolean hasNodes()
515     throws RepositoryException
516   {
517     return false;
518   }
519   
520   /**
521    * Returns true if the node has any properties.
522    */

523   public boolean hasProperties()
524     throws RepositoryException
525   {
526     return false;
527   }
528   
529   /**
530    * Returns the node's primary type.
531    */

532   public NodeType getPrimaryNodeType()
533     throws RepositoryException
534   {
535     return BaseNodeType.NT_BASE;
536   }
537   
538   /**
539    * Returns any mixin types for the node.
540    */

541   public NodeType[] getMixinNodeTypes()
542     throws RepositoryException
543   {
544     return new NodeType[0];
545   }
546   
547   /**
548    * Returns true if the node supports the given node type.
549    */

550   public boolean isNodeType(String JavaDoc nodeTypeName)
551     throws RepositoryException
552   {
553     NodeType nodeType = getPrimaryNodeType();
554
555     if (nodeType.getName().equals(nodeTypeName))
556       return true;
557
558     NodeType []superTypes = nodeType.getSupertypes();
559     
560     for (int i = superTypes.length - 1; i >= 0; i--) {
561       if (superTypes[i].getName().equals(nodeTypeName))
562     return true;
563     }
564
565     return false;
566   }
567   
568   /**
569    * Adds a mixin type to the node.
570    */

571   public void addMixin(String JavaDoc mixinName)
572     throws NoSuchNodeTypeException,
573        VersionException,
574        ConstraintViolationException,
575        LockException,
576        RepositoryException
577   {
578     throw new UnsupportedOperationException JavaDoc(getClass().getName());
579   }
580   
581   /**
582    * Removes a mixin type to the node.
583    */

584   public void removeMixin(String JavaDoc mixinName)
585     throws NoSuchNodeTypeException,
586        VersionException,
587        ConstraintViolationException,
588        LockException,
589        RepositoryException
590   {
591     throw new UnsupportedOperationException JavaDoc(getClass().getName());
592   }
593   
594   /**
595    * Returns true if the given mixin type can be added to the node.
596    */

597   public boolean canAddMixin(String JavaDoc mixinName)
598     throws NoSuchNodeTypeException,
599        RepositoryException
600   {
601     return false;
602   }
603   
604   /**
605    * Returns a description of the node.
606    */

607   public NodeDefinition getDefinition()
608     throws RepositoryException
609   {
610     throw new UnsupportedOperationException JavaDoc(getClass().getName());
611   }
612   
613   /**
614    * Checks in a new version for to the node.
615    */

616   public Version checkin()
617     throws VersionException,
618        UnsupportedRepositoryOperationException,
619        InvalidItemStateException,
620        LockException,
621        RepositoryException
622   {
623     throw new UnsupportedOperationException JavaDoc(getClass().getName());
624   }
625   
626   /**
627    * Checks out a version.
628    */

629   public void checkout()
630     throws UnsupportedRepositoryOperationException,
631        LockException,
632        RepositoryException
633   {
634     throw new UnsupportedOperationException JavaDoc(getClass().getName());
635   }
636   
637   /**
638    * Mark the version merge as complete.
639    */

640   public void doneMerge(Version version)
641     throws VersionException,
642        InvalidItemStateException,
643        UnsupportedRepositoryOperationException,
644        RepositoryException
645   {
646     throw new UnsupportedOperationException JavaDoc(getClass().getName());
647   }
648   
649   /**
650    * Cancel a version merge.
651    */

652   public void cancelMerge(Version version)
653     throws VersionException,
654        InvalidItemStateException,
655        UnsupportedRepositoryOperationException,
656        RepositoryException
657   {
658     throw new UnsupportedOperationException JavaDoc(getClass().getName());
659   }
660   
661   /**
662    * Updates a workspace
663    */

664   public void update(String JavaDoc srcWorkspaceName)
665     throws NoSuchWorkspaceException,
666        AccessDeniedException,
667        LockException,
668        InvalidItemStateException,
669        RepositoryException
670   {
671     throw new UnsupportedOperationException JavaDoc(getClass().getName());
672   }
673   
674   /**
675    * Merges child nodes.
676    */

677   public NodeIterator merge(String JavaDoc srcWorkspace, boolean bestEffort)
678     throws NoSuchWorkspaceException,
679        AccessDeniedException,
680        MergeException,
681        LockException,
682        InvalidItemStateException,
683        RepositoryException
684   {
685     throw new UnsupportedOperationException JavaDoc(getClass().getName());
686   }
687   
688   /**
689    * Returns the node path to a workspace.
690    */

691   public String JavaDoc getCorrespondingNodePath(String JavaDoc workspaceName)
692     throws ItemNotFoundException,
693        NoSuchWorkspaceException,
694        AccessDeniedException,
695        RepositoryException
696   {
697     throw new UnsupportedOperationException JavaDoc(getClass().getName());
698   }
699   
700   /**
701    * Returns true for a checked out node.
702    */

703   public boolean isCheckedOut()
704     throws RepositoryException
705   {
706     throw new UnsupportedOperationException JavaDoc(getClass().getName());
707   }
708   
709   /**
710    * Restore the node based on an older version.
711    */

712   public void restore(String JavaDoc versionName, boolean removeExisting)
713     throws VersionException,
714        ItemExistsException,
715        UnsupportedRepositoryOperationException,
716        LockException,
717        InvalidItemStateException,
718        RepositoryException
719   {
720     throw new UnsupportedOperationException JavaDoc(getClass().getName());
721   }
722   
723   /**
724    * Restore the node based on an older version.
725    */

726   public void restore(Version version, boolean removeExisting)
727     throws VersionException,
728        ItemExistsException,
729        UnsupportedRepositoryOperationException,
730        LockException,
731        RepositoryException
732   {
733     throw new UnsupportedOperationException JavaDoc(getClass().getName());
734   }
735   
736   /**
737    * Restore the node based on an older version.
738    */

739   public void restore(Version version,
740               String JavaDoc relPath,
741               boolean removeExisting)
742     throws PathNotFoundException,
743        ItemExistsException,
744        VersionException,
745        ConstraintViolationException,
746        UnsupportedRepositoryOperationException,
747        LockException,
748        InvalidItemStateException,
749        RepositoryException
750   {
751     throw new UnsupportedOperationException JavaDoc(getClass().getName());
752   }
753   
754   /**
755    * Restore the node based on an older version.
756    */

757   public void restoreByLabel(String JavaDoc versionLabel,
758                  boolean removeExisting)
759     throws VersionException,
760        ItemExistsException,
761        UnsupportedRepositoryOperationException,
762        LockException,
763        InvalidItemStateException,
764        RepositoryException
765   {
766     throw new UnsupportedOperationException JavaDoc(getClass().getName());
767   }
768   
769   /**
770    * Returns the node's version history.
771    */

772   public VersionHistory getVersionHistory()
773     throws UnsupportedRepositoryOperationException,
774        RepositoryException
775   {
776     throw new UnsupportedOperationException JavaDoc(getClass().getName());
777   }
778   
779   /**
780    * Returns the base version.
781    */

782   public Version getBaseVersion()
783     throws UnsupportedRepositoryOperationException,
784        RepositoryException
785   {
786     throw new UnsupportedOperationException JavaDoc(getClass().getName());
787   }
788   
789   /**
790    * Lock the node.
791    */

792   public Lock lock(boolean isDeep, boolean isSessionScoped)
793     throws UnsupportedRepositoryOperationException,
794        LockException,
795        AccessDeniedException,
796        InvalidItemStateException,
797        RepositoryException
798   {
799     throw new UnsupportedOperationException JavaDoc(getClass().getName());
800   }
801   
802   /**
803    * Returns the current lock.
804    */

805   public Lock getLock()
806     throws UnsupportedRepositoryOperationException,
807        LockException,
808        AccessDeniedException,
809        RepositoryException
810   {
811     throw new UnsupportedOperationException JavaDoc(getClass().getName());
812   }
813   
814   /**
815    * Unlocks the node.
816    */

817   public void unlock()
818     throws UnsupportedRepositoryOperationException,
819        LockException,
820        AccessDeniedException,
821        InvalidItemStateException,
822        RepositoryException
823   {
824     throw new UnsupportedOperationException JavaDoc(getClass().getName());
825   }
826   
827   /**
828    * Returns true if the node owns a lock.
829    */

830   public boolean holdsLock()
831     throws RepositoryException
832   {
833     return false;
834   }
835   
836   /**
837    * Returns true if the node is locked.
838    */

839   public boolean isLocked()
840     throws RepositoryException
841   {
842     return false;
843   }
844 }
845
Popular Tags