KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > SimpleFlexCondition


1 /**
2  * $Id: SimpleFlexCondition.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2003 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.condition;
30
31 import org.apache.tools.ant.Project;
32
33 import com.idaremedia.antx.FlexString;
34 import com.idaremedia.antx.parameters.IsA;
35
36 /**
37  * A simple single-value condition whose unknown value can be either an inlined literal
38  * value, a property's value, a variable's value, or a reference's value. Property,
39  * variable, and reference values are determined at evaluation time.
40  *
41  * @since JWare/AntX 0.2
42  * @author ssmc, &copy;2002-2003 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
43  * @version 0.5
44  * @.safety single
45  * @.group impl,infra
46  **/

47
48 public abstract class SimpleFlexCondition extends FlexCondition
49     implements URIable
50 {
51     /**
52      * Initializes a new simple flex condition.
53      **/

54     protected SimpleFlexCondition()
55     {
56         super();
57         m_impl.setLenient(false);
58     }
59
60
61     /**
62      * Initializes a new CV-labeled simple flex condition.
63      * @param iam CV-label (non-null)
64      **/

65     protected SimpleFlexCondition(String JavaDoc iam)
66     {
67         super(iam);
68         m_impl.setLenient(false);
69     }
70
71
72
73     /**
74      * Updates this condition's enclosing project; also updates
75      * any nested project components.
76      **/

77     public void setProject(Project project)
78     {
79         super.setProject(project);
80         m_impl.setProject(project);
81     }
82
83
84
85     /**
86      * Returns the underlying value's flex string for this
87      * condition. Never returns <i>null</i>.
88      **/

89     protected final FlexString getValueHelper()
90     {
91         return m_impl;
92     }
93
94
95
96     /**
97      * Sets this condition's value as part of a value URI. To
98      * differentiate between a literal value, and a property, etc&#46;,
99      * set the URI's query string to the correct "isa" setting;
100      * for example: <span class="src">$isnumeric:@(it)?variable</span>.
101      * @param uriFragment the value uri bits (non-null)
102      * @since JWare/AntX 0.5
103      */

104     public void xsetFromURI(String JavaDoc uriFragment)
105     {
106         String JavaDoc flexvalue = uriFragment;
107         IsA isa= getDefaultIsAForURI();
108
109         int i = uriFragment.lastIndexOf("?");
110         if (i>0) {
111             flexvalue = uriFragment.substring(0,i++);
112             if (i<uriFragment.length()) {
113                 String JavaDoc isaName = uriFragment.substring(i);
114                 isa = IsA.from(isaName,isa);
115            }
116         }
117         switch (isa.getIndex()) {
118             case IsA.PROPERTY_INDEX: {
119                 setProperty(flexvalue);
120                 break;
121             }
122             case IsA.VARIABLE_INDEX: {
123                 setVariable(flexvalue);
124                 break;
125             }
126             case IsA.REFERENCE_INDEX:{
127                 setReference(flexvalue);
128                 break;
129             }
130             default: {
131                 setLiteral(flexvalue);
132             }
133         }
134     }
135
136
137     /**
138      * Marks this condition's as setting a literal for the
139      * default field set by a value URI.
140      * @since JWare/AntX 0.5
141      * @return IsA.LITERAL always.
142      */

143     protected IsA getDefaultIsAForURI()
144     {
145         return IsA.LITERAL;
146     }
147
148
149     private FlexString m_impl = new FlexString();
150 }
151
152 /* end-of-SimpleFlexCondition.java */
153
Popular Tags