KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > descriptor > TreeValueDescriptor


1 /*
2  * $Header: /home/cvs/jakarta-slide/projector/src/java/org/apache/slide/projector/descriptor/Attic/TreeValueDescriptor.java,v 1.3 2004/08/03 14:27:18 dflorey Exp $
3  * $Revision: 1.3 $
4  * $Date: 2004/08/03 14:27:18 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.projector.descriptor;
25
26 import org.apache.slide.projector.Context;
27 import org.apache.slide.projector.value.ArrayValue;
28 import org.apache.slide.projector.value.Value;
29
30 /**
31  * The TreeValueDescriptor class
32  *
33  */

34 public class TreeValueDescriptor implements ValueDescriptor {
35     private ValueDescriptor entryValueDescriptor;
36     private ValueDescriptor arrayValueDescriptor;
37
38     public TreeValueDescriptor() {
39         this.entryValueDescriptor = null;
40         arrayValueDescriptor = new ArrayValueDescriptor(this);
41     }
42
43     public TreeValueDescriptor(ValueDescriptor entryValueDescriptor) {
44         this.entryValueDescriptor = entryValueDescriptor;
45         arrayValueDescriptor = new ArrayValueDescriptor(this);
46     }
47
48     public Value valueOf(Object JavaDoc value, Context context) throws ValueCastException {
49         try {
50             return arrayValueDescriptor.valueOf(value, context);
51         } catch ( ValueCastException exception ) {
52             return entryValueDescriptor.valueOf(value, context);
53         }
54     }
55
56     public void validate(Value value, Context context) throws ValidationException {
57         if ( value instanceof ArrayValue ) {
58             arrayValueDescriptor.validate(value, context);
59         } else {
60             entryValueDescriptor.validate(value, context);
61         }
62     }
63 }
Popular Tags