|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsav.z.ClassNavigation
sav.z.Variable
The Variable class is main instrument for interface Java with Zigzag. Variable allows to manipulate and navigate through Zigzag objects, to convert their into Java String, array or Vectors. Variable is a simple mechanism to pass Zigzag objects, having "name", "name:value" or "name:...value" views from Java code into Zigzag scripts. To create Variable object, the var() method of Session is used.
Look at the following Java/Zigzag fragment, which creates a "table" with employee key column. It needs to understand next examples, primarily possible values of the Variables.
String script =
"$readTable() <" +
"employee; name; department; salary \n" +
"101; 'Adams Smith'; 1; 50000 \n" +
"102; 'Clark White'; 1; 30000 \n" +
"103; 'Jones Hunter'; 2; 60000 \n" +
"104; 'Blake Dull'; 3; 65000 \n" +
"105; 'Sylvia Smith'; 1; 25000 \n" +
"108; 'Albert Green'; 3; 40000 \n" +
"109; 'Clark Ringer'; 2; 50000 \n" +
">;"
;
Session ss = new Session();
ss.modifyBase("CompanyX");
ss.z(script);
We know database contents and can form the $x variable
by means of Zigzag query $x = employee:(salary:$z^);.
Values of $x are employees with salary $z
or more. First attempt to set $z the 70000
is not successful. So we try to find employee with salary
30000, that is with $z = 30000. To control a
failure result, we will use compare ss.z(...) == 0 and
even ZException via ss.setFailExcepted(true).
ss.exploreBase("CompanyX");
Variable varz = ss.var("$z");
varz.set("70000");
script = "$x = employee:(salary:$z^);";
if (ss.z(script) == 0) {
varz.set("30000");
ss.setFailExcepted(true);
ss.z(script);
ss.setFailExcepted(false);
}
Variable varx = ss.var("$x");
To check $x result we could use the
varx.isEmpty() method.
Values of $x and correspondently varx are objects:
employee:101, employee:102, employee:103
and so on except employee:105. To get employee
values like 101, 102, ... we had to use Zigzag
statement $x = employee/(salary:$z^);.
Now let's select the first three objects of the $x variable into the $y variable.
Variable vary = ss.var("$y");
int max = 3;
int n = 0;
for (String emp = varx.first(); emp != null; emp = varx.next(emp)) {
vary.add(emp);
if (++n == max)
break;
}
We can execute some acts with $y via Zigzag or with
vary via Java code. For example, to print
table of $y employees we can use following.
Printer prt = new WPrinter(new PrintWriter(System.out));
ss.setReportPrinter(prt);
prt.println("--- 3 potential workers ---");
ss.z("$printTable($y)");
prt.flush();
Session.var(String)| Method Summary | |
void |
add(java.lang.String value)
Adds the specified value to this Variable. |
void |
add(java.lang.String[] array)
Adds the specified array values to this Variable.
|
void |
add(java.lang.String zclass,
java.lang.String value)
Adds the specified value to the
Zigzag class with name zclass inside this Variable. |
void |
add(java.lang.String zclass,
java.lang.String[] array)
Adds the specified array values to the
Zigzag class with name zclass inside this Variable.
|
java.lang.String[] |
array()
Returns a string array of this Variable values. |
java.lang.String |
back()
Returns back value before current. |
java.lang.String |
back(java.lang.String value)
Returns back value before parameter value.
|
void |
clear()
Removes all of the values from this Variable. |
void |
clear(java.lang.String zclass)
Removes all the values of zclass Zigzag class inside this Variable. |
java.lang.String |
first()
Returns the first value of this Variable. |
void |
generalizeTo(Variable var)
Copy general values to var Zigzag Variable.
|
boolean |
has(java.lang.String value)
Returns true if Variable has the specified value. |
boolean |
hasNumber()
Returns true if Variable has value of number type. |
boolean |
isEmpty()
Tests if Variable has no value. |
java.lang.String |
last()
Returns the last value of this Variable. |
java.lang.String |
name()
Returns a Zigzag name of this Variable, which begins with $ symbol. |
java.lang.String |
next()
Returns next value after current. |
java.lang.String |
next(java.lang.String value)
Returns next value after parameter value.
|
java.lang.String[] |
nextArray(java.lang.String value,
int size)
Returns a next size array of values
after the value.
|
void |
remove(java.lang.String value)
Removes a single value from this Variable, if it is present. |
void |
remove(java.lang.String zclass,
java.lang.String value)
Removes the value of zclass
Zigzag class inside this Variable. |
void |
set(java.lang.String value)
Sets up the specified value to this Variable.
|
void |
set(java.lang.String[] array)
Sets the specified array of values to this Variable.
|
int |
size()
Returns number of Variable values. |
java.lang.String |
term()
Returns one (first) non-quoted string value of this Variable. |
java.lang.String |
value()
Returns one (first) string value of this Variable. |
java.util.Vector |
values()
Returns a Vector of this Variable values. |
VariableExtension |
ve()
Returns VariableExtension representing functional extension of the Variable. |
| Methods inherited from class sav.z.ClassNavigation |
array, back, first, generalizeTo, has, hasNumber, isEmpty, last, next, nextArray, size, term, value, values |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public VariableExtension ve()
VariableExtensionpublic java.lang.String name()
var
made with Variable var = session.var("$x");
Session.var(String)
public java.lang.String[] array()
throws java.io.IOException
session.z("$x = User/");
Variable var = session.var("$x");
String users[] = var.array();
java.io.IOExceptionset(String),
set(String[]),
add(String),
add(String[])
public java.lang.String value()
throws java.io.IOException
session.z("$x = User/");
Variable var = session.var("$x");
String userName = var.value();
java.io.IOExceptionset(String),
term()
public java.lang.String term()
throws java.io.IOException
session.z("$x = 'John':'Smit'");
Variable var = session.var("$x");
String term = var.term();
java.io.IOExceptionvalue()
public java.util.Vector values()
throws java.io.IOException
session.z("$x = User/");
Variable var = session.var("$x");
Vector values = var.values();
java.io.IOExceptionset(String),
set(String[]),
add(String),
add(String[])
public int size()
throws java.io.IOException
java.io.IOExceptionarray()
public java.lang.String first()
throws java.io.IOException
value().
java.io.IOExceptionnext(),
last()
public java.lang.String last()
throws java.io.IOException
java.io.IOExceptionback(),
first()
public java.lang.String next(java.lang.String value)
throws java.io.IOException
value.
Variable varx = session.var("$x");
for (String s = varx.first(); s != null; s = varx.next(s)) {
...
int i = Integer.parseInt(s);
s = String.valueOf(++i);
}
java.io.IOExceptionfirst(),
next()
public java.lang.String back(java.lang.String value)
throws java.io.IOException
value.
Variable varx = session.var("$x");
for (String s = varx.last(); s != null; s = varx.back(s)) {
...
int i = Integer.parseInt(s);
s = String.valueOf(++i);
}
java.io.IOExceptionlast(),
back()
public java.lang.String next()
throws java.io.IOException
Variable varx = session.var("$x");
for (String s = varx.first(); s != null; s = varx.next()) {
...
}
java.io.IOExceptionfirst()
public java.lang.String back()
throws java.io.IOException
Variable varx = session.var("$x");
for (String s = varx.last(); s != null; s = varx.back()) {
...
}
java.io.IOExceptionlast()
public java.lang.String[] nextArray(java.lang.String value,
int size)
throws java.io.IOException
size array of values
after the value.
Variable varx = session.var("$x");
int size = 10;
String current = null;
while (true) {
String array[] = varx.nextArray(current, size);
...
if (array.length < size)
break;
current = array[size - 1];
}
java.io.IOExceptionnext(String)
public void generalizeTo(Variable var)
throws java.io.IOException
var Zigzag Variable.
For example, if values are programmer and
programmer:'John', the var
will contain only programmer.
java.io.IOExceptionvalues()
public boolean has(java.lang.String value)
throws java.io.IOException
value.
java.io.IOExceptionClassNavigation.value(String)
public boolean hasNumber()
throws java.io.IOException
java.io.IOExceptionvalue(),
has(String)
public boolean isEmpty()
throws java.io.IOException
java.io.IOExceptionsize()
public void add(java.lang.String value)
throws java.io.IOException
value to this Variable.
java.io.IOExceptionClassNavigation.value(String),
ClassNavigation.values(String),
set(String)
public void add(java.lang.String[] array)
throws java.io.IOException
array values to this Variable.
The example makes "data1" resource for "ann1" and "dan" users.
String users[] = { "ann1", "dan" }
variable.add(users);
java.io.IOExceptionadd(String)
public void clear()
throws java.io.IOException
java.io.IOExceptionadd(String[]),
set(String[])
public void remove(java.lang.String value)
throws java.io.IOException
value from this Variable, if it is present.
java.io.IOExceptionclear()
public void set(java.lang.String value)
throws java.io.IOException
value to this Variable.
The setting means assigning a new value
with removing all the old values.
java.io.IOExceptionadd(String)
public void set(java.lang.String[] array)
throws java.io.IOException
array of values to this Variable.
The old values are removed. The example below assumes the $x
equal to user names 'ann1', 'dan'. Then via User:$x=
the User:['ann1','dan'] users are assigned to the database
and $y variable. The users array will be
equal { "User:'ann1', User:'dan' }.
Variable varx = session.var("$x");
String userNames[] = { "'ann1'", "'dan'" }
varx.set(users);
session.z($y = User:$x=");
Variable vary = session.var("$y");
String users[] = vary.array();
java.io.IOExceptionset(String)
public void add(java.lang.String zclass,
java.lang.String value)
throws java.io.IOException
value to the
Zigzag class with name zclass inside this Variable.
java.io.IOExceptionadd(String)
public void add(java.lang.String zclass,
java.lang.String[] array)
throws java.io.IOException
array values to the
Zigzag class with name zclass inside this Variable.
Really following example adds { "User:'ann1'", "User:'dan'" }
to the varx Variable.
String userNames[] = { "'ann1'", "'dan'" }
Variable varx = session.var("$x");
varx.add("User", userNames);
java.io.IOExceptionadd(String, String)
public void clear(java.lang.String zclass)
throws java.io.IOException
zclass Zigzag class inside this Variable.
java.io.IOExceptionadd(String, String),
add(String, String[])
public void remove(java.lang.String zclass,
java.lang.String value)
throws java.io.IOException
value of zclass
Zigzag class inside this Variable.
java.io.IOExceptionclear(String),
add(String, String),
add(String, String[])
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||