KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > model > impl > CommonLength


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.xml.schema.model.impl;
22
23 import org.netbeans.modules.xml.schema.model.LengthFacet;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * Common implementation for length-related components.
28  *
29  * @author nn136682
30  */

31
32 public abstract class CommonLength extends SchemaComponentImpl implements LengthFacet {
33
34     /** Creates a new instance of CommonLength */
35     public CommonLength(SchemaModelImpl model, Element JavaDoc e) {
36         super(model, e);
37     }
38
39     public abstract String JavaDoc getComponentName();
40
41     public void setValue(int v) {
42         if (v < 0) {
43             throw new IllegalArgumentException JavaDoc("Element '" + getComponentName() + "' can only have positive integer value.");
44         }
45         setAttribute(VALUE_PROPERTY, SchemaAttributes.VALUE, String.valueOf(v));
46     }
47     
48     public int getValue() {
49         String JavaDoc v = super.getAttribute(SchemaAttributes.VALUE);
50         if (v == null) {
51             return 1;
52         }
53         int i = Integer.valueOf(v);
54         if (i < 0) {
55             throw new IllegalArgumentException JavaDoc("Element '" + getComponentName() + "' can only has positive integer value.");
56         }
57         return i;
58     }
59     
60     public Boolean JavaDoc isFixed() {
61         String JavaDoc v = super.getAttribute(SchemaAttributes.FIXED);
62         return v == null ? null : Boolean.valueOf(v);
63     }
64     
65     public void setFixed(Boolean JavaDoc isFixed) {
66         setAttribute(FIXED_PROPERTY, SchemaAttributes.FIXED, isFixed);
67     }
68     
69     protected Class JavaDoc getAttributeType(SchemaAttributes attr) {
70         switch(attr) {
71             case FIXED:
72                 return String JavaDoc.class;
73             default:
74                 return super.getAttributeType(attr);
75         }
76     }
77
78     public boolean getFixedEffective() {
79         Boolean JavaDoc v = isFixed();
80         return v == null ? getFixedDefault() : v;
81     }
82
83     public boolean getFixedDefault() {
84         return false;
85     }
86 }
87
Popular Tags