12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901 |
- /* Query.java -- Static methods for query construction.
- Copyright (C) 2007 Free Software Foundation, Inc.
- This file is part of GNU Classpath.
- GNU Classpath is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
- GNU Classpath is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNU Classpath; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301 USA.
- Linking this library statically or dynamically with other modules is
- making a combined work based on this library. Thus, the terms and
- conditions of the GNU General Public License cover the whole
- combination.
- As a special exception, the copyright holders of this library give you
- permission to link this library with independent modules to produce an
- executable, regardless of the license terms of these independent
- modules, and to copy and distribute the resulting executable under
- terms of your choice, provided that you also meet, for each linked
- independent module, the terms and conditions of the license of that
- module. An independent module is a module which is not derived from
- or based on this library. If you modify this library, you may extend
- this exception to your version of the library, but you are not
- obligated to do so. If you do not wish to do so, delete this
- exception statement from your version. */
- package javax.management;
- /**
- * Provides static methods for constructing queries. Queries
- * may be used to list and enumerate management beans, via
- * the {@link MBeanServer}. By using the methods in this class,
- * complex queries can be created from their more basic
- * components.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- public class Query
- {
- /**
- * A code representing the {@link #plus(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int PLUS = 0;
- /**
- * A code representing the {@link #minus(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int MINUS = 1;
- /**
- * A code representing the {@link #times(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int TIMES = 2;
- /**
- * A code representing the {@link #div(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int DIV = 3;
- /**
- * A code representing the {@link #gt(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int GT = 0;
- /**
- * A code representing the {@link #lt(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int LT = 1;
- /**
- * A code representing the {@link #ge(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int GE = 2;
- /**
- * A code representing the {@link #le(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int LE = 3;
- /**
- * A code representing the {@link #eq(ValueExp, ValueExp)
- * query to be used in serialization.
- */
- public static final int EQ = 4;
- /**
- * Returns a query expression formed from the conjunction
- * of the two supplied query expressions.
- *
- * @param q1 the first query expression.
- * @param q2 the second query expression.
- * @return a query expression representing q1 && q2. This
- * will be serialized as the non-public class
- * {@link AndQueryExp}.
- */
- public static QueryExp and(QueryExp q1, QueryExp q2)
- {
- return new AndQueryExp(q1, q2);
- }
- /**
- * Returns a query expression which checks that an
- * attribute value held by the specified
- * {@link AttributeValueExp} contains the string
- * specified by the given {@link StringValueExp}.
- *
- * @param attrib the attribute to match.
- * @param string the substring to find.
- * @return a query expression representing
- * <code>attrib.matches("*" + string + "*")</code>.
- * This will be serialized as the non-public class
- * {@link MatchQueryExp}.
- */
- public static QueryExp anySubString(AttributeValueExp attrib,
- StringValueExp string)
- {
- return new MatchQueryExp(attrib, "*" + string.getValue() + "*");
- }
- /**
- * Returns a value expression for the value of the
- * named attribute. Evaluating this using an
- * {@link ObjectName} involves an underlying call
- * to {@link MBeanServer#getAttribute(ObjectName,String)}.
- *
- * @param name the name of the attribute.
- * @return a value expression which returns the value
- * of the named attribute when applied.
- */
- public static AttributeValueExp attr(String name)
- {
- return new AttributeValueExp(name);
- }
- /**
- * Returns a value expression for the value of the
- * named attribute from the specified class. Evaluating
- * this using an {@link ObjectName} involves an underlying call
- * to both {@link MBeanServer#getObjectInstance(ObjectName)} and
- * {@link MBeanServer#getAttribute(ObjectName,String)}.
- *
- * @param className the class containing the attribute.
- * @param name the name of the attribute.
- * @return a value expression which returns the value
- * of the named attribute when applied.
- * This will be serialized as the non-public class
- * {@link QualifiedAttributeValueExp}.
- */
- public static AttributeValueExp attr(String className,
- String name)
- {
- return new QualifiedAttributeValueExp(className, name);
- }
- /**
- * Returns a query expression representing the constraint
- * that the value, <code>v1</code>, lies between <code>v2</code>
- * and <code>v3</code>.
- *
- * @param v1 the value to compare against the boundaries.
- * @param v2 the lower boundary.
- * @param v3 the upper boundary.
- * @return a query expression representing a comparison
- * of <code>v1</code> against <code>v2</code>
- * and <code>v3</code>. It returns true if
- * <code>v2 <= v1 <= v3</code>. This
- * will be serialized as the non-public class
- * {@link BetweenQueryExp}.
- */
- public static QueryExp between(ValueExp v1, ValueExp v2,
- ValueExp v3)
- {
- return new BetweenQueryExp(v1, v2, v3);
- }
- /**
- * Returns a value expression which evaluates to the name of
- * the class of the bean when applied. Associating the expression
- * with an {@link ObjectName} involves an underlying call
- * to both {@link MBeanServer#getObjectInstance(ObjectName)}
- * to obtain this information.
- *
- * @return a value expression which returns the class name
- * of the bean to which it is applied.
- * This will be serialized as the non-public class
- * {@link ClassAttributeValueExp}.
- */
- public static AttributeValueExp classattr()
- {
- return new ClassAttributeValueExp();
- }
- /**
- * Returns a value expression which evaluates to the result of
- * dividing <code>v1</code> by <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the division when applied. This will be serialized
- * as the non-public class {@link BinaryOpValueExp}
- * with an operation of {@link #DIV}.
- */
- public static ValueExp div(ValueExp v1, ValueExp v2)
- {
- return new BinaryOpValueExp(DIV, v1, v2);
- }
- /**
- * Returns a query expression which evaluates to the result of
- * comparing <code>v1</code> to <code>v2</code> for equality.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the comparison when applied. This will be serialized
- * as the non-public class {@link BinaryRelQueryExp}
- * with an operation of {@link #EQ}.
- */
- public static QueryExp eq(ValueExp v1, ValueExp v2)
- {
- return new BinaryRelQueryExp(EQ, v1, v2);
- }
- /**
- * Returns a query expression which checks that an
- * attribute value held by the specified
- * {@link AttributeValueExp} ends with the string
- * specified by the given {@link StringValueExp}.
- *
- * @param attrib the attribute to match.
- * @param string the substring to find.
- * @return a query expression representing
- * <code>attrib.matches("*" + string)</code>.
- * This will be serialized as the non-public class
- * {@link MatchQueryExp}.
- */
- public static QueryExp finalSubString(AttributeValueExp attrib,
- StringValueExp string)
- {
- return new MatchQueryExp(attrib, "*" + string.getValue());
- }
- /**
- * Returns a query expression which evaluates to the result of
- * comparing <code>v1</code> to <code>v2</code> to see if
- * <code>v1</code> is greater than or equal to <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the comparison when applied. This will be serialized
- * as the non-public class {@link BinaryRelQueryExp}
- * with an operation of {@link #GE}.
- */
- public static QueryExp geq(ValueExp v1, ValueExp v2)
- {
- return new BinaryRelQueryExp(GE, v1, v2);
- }
- /**
- * Returns a query expression which evaluates to the result of
- * comparing <code>v1</code> to <code>v2</code> to see if
- * <code>v1</code> is greater than <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the comparison when applied. This will be serialized
- * as the non-public class {@link BinaryRelQueryExp}
- * with an operation of {@link #GT}.
- */
- public static QueryExp gt(ValueExp v1, ValueExp v2)
- {
- return new BinaryRelQueryExp(GT, v1, v2);
- }
- /**
- * Returns a query expression representing the constraint
- * that the value, <code>v</code>, is a member of the
- * list, <code>vlist</code>.
- *
- * @param v the value to look for in the list.
- * @param vlist the list of allowed values.
- * @return a query expression representing a membership check
- * of <code>v</code> against the list, <code>vlist</code>.
- * This will be serialized as the non-public class
- * {@link InQueryExp}.
- */
- public static QueryExp in(ValueExp v, ValueExp[] vlist)
- {
- return new InQueryExp(v, vlist);
- }
- /**
- * Returns a query expression which checks that an
- * attribute value held by the specified
- * {@link AttributeValueExp} starts with the string
- * specified by the given {@link StringValueExp}.
- *
- * @param attrib the attribute to match.
- * @param string the substring to find.
- * @return a query expression representing
- * <code>attrib.matches(string + "*")</code>.
- * This will be serialized as the non-public class
- * {@link MatchQueryExp}.
- */
- public static QueryExp initialSubString(AttributeValueExp attrib,
- StringValueExp string)
- {
- return new MatchQueryExp(attrib, string.getValue() + "*");
- }
- /**
- * Returns a query expression which checks that a
- * bean is an instance of the class specified
- * by the given {@link StringValueExp}. Associating the
- * expression with an {@link ObjectName} involves an underlying
- * call to {@link MBeanServer#isInstanceOf(ObjectName, String)}
- * using the value of <code>((StringValueExp)
- * className.apply(objectName)).getValue()</code> as the
- * class name.
- *
- * @param className the name of the class which the bean
- * should be an instance of.
- * @return a query expression representing
- * the inheritance check. This will be serialized
- * as the non-public class {@link InstanceOfQueryExp}.
- * @since 1.6
- */
- public static QueryExp isInstanceOf(StringValueExp className)
- {
- return new InstanceOfQueryExp(className);
- }
- /**
- * Returns a query expression which evaluates to the result of
- * comparing <code>v1</code> to <code>v2</code> to see if
- * <code>v1</code> is less than or equal to <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the comparison when applied. This will be serialized
- * as the non-public class {@link BinaryRelQueryExp}
- * with an operation of {@link #LE}.
- */
- public static QueryExp leq(ValueExp v1, ValueExp v2)
- {
- return new BinaryRelQueryExp(LE, v1, v2);
- }
- /**
- * Returns a query expression which evaluates to the result of
- * comparing <code>v1</code> to <code>v2</code> to see if
- * <code>v1</code> is less than <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the comparison when applied. This will be serialized
- * as the non-public class {@link BinaryRelQueryExp}
- * with an operation of {@link #LT}.
- */
- public static QueryExp lt(ValueExp v1, ValueExp v2)
- {
- return new BinaryRelQueryExp(LT, v1, v2);
- }
- /**
- * <p>
- * Returns a query expression which checks that an
- * attribute value matches the pattern
- * specified by the given {@link StringValueExp}.
- * The pattern uses file-globbing syntax:
- * </p>
- * <ul>
- * <li>'*' stands for any number of arbitrary characters.</li>
- * <li>'?' stands for a single arbitrary characters.</li>
- * <li>An expression within '[' and ']' specify a character
- * class.</li>
- * <ul>
- * <li>A range of characters can be specified by separating
- * the start and end character with '-'.</li>
- * <li>The complement of the class can be obtained by using
- * '!' as the first character of the class.</li>
- * <li>'?', '*' and '[' can occur freely within the class. '-'
- * may occur as the first or last character. '!' may occur
- * normally in any position other than the first. ']' may occur
- * as the first element of the class.</li>
- * </ul>
- * <li>'?', '*' and '[' may be escaped using a backslash
- * character, '\'.</li>
- * </ul>
- *
- * @param attrib the attribute to match.
- * @param string the substring to find.
- * @return a query expression representing the result of
- * matching the pattern against the evaluated
- * value of the attribute. This will be serialized
- * as the non-public class {@link MatchQueryExp}.
- */
- public static QueryExp match(AttributeValueExp attrib,
- StringValueExp string)
- {
- return new MatchQueryExp(attrib, string.getValue());
- }
- /**
- * Returns a value expression which evaluates to the result of
- * subtracting <code>v2</code> from <code>v1</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the subtraction when applied. This will be serialized
- * as the non-public class {@link BinaryOpValueExp}
- * with an operation of {@link #MINUS}.
- */
- public static ValueExp minus(ValueExp v1, ValueExp v2)
- {
- return new BinaryOpValueExp(MINUS, v1, v2);
- }
- /**
- * Returns a query expression representing the negation
- * of the specified query expression.
- *
- * @param q the query to negate.
- * @return a query expression representing the negation of
- * <code>q</code>. This will be serialized as the
- * non-public class {@link NotQueryExp}.
- */
- public static QueryExp not(QueryExp q)
- {
- return new NotQueryExp(q);
- }
- /**
- * Returns a query expression formed from the disjunction
- * of the two supplied query expressions.
- *
- * @param q1 the first query expression.
- * @param q2 the second query expression.
- * @return a query expression representing q1 || q2. This
- * will be serialized as the non-public class
- * {@link OrQueryExp}.
- */
- public static QueryExp or(QueryExp q1, QueryExp q2)
- {
- return new OrQueryExp(q1, q2);
- }
- /**
- * Returns a value expression which evaluates to the result of
- * adding <code>v1</code> to <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the addition when applied. This will be serialized
- * as the non-public class {@link BinaryOpValueExp}
- * with an operation of {@link #PLUS}.
- */
- public static ValueExp plus(ValueExp v1, ValueExp v2)
- {
- return new BinaryOpValueExp(PLUS, v1, v2);
- }
- /**
- * Returns a value expression which evaluates to the result of
- * multiplying <code>v1</code> by <code>v2</code>.
- *
- * @param v1 the left-hand operand.
- * @param v2 the right-hand operand.
- * @return a value expression which returns the result of
- * the multiplication when applied. This will be serialized
- * as the non-public class {@link BinaryOpValueExp}
- * with an operation of {@link #TIMES}.
- */
- public static ValueExp times(ValueExp v1, ValueExp v2)
- {
- return new BinaryOpValueExp(TIMES, v1, v2);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the boolean value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link BooleanValueExp}.
- */
- public static ValueExp value(boolean val)
- {
- return new BooleanValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the double value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link NumericValueExp}.
- */
- public static ValueExp value(double val)
- {
- return new NumericValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the float value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link NumericValueExp}.
- */
- public static ValueExp value(float val)
- {
- return new NumericValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the integer value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link NumericValueExp}.
- */
- public static ValueExp value(int val)
- {
- return new NumericValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the long value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link NumericValueExp}.
- */
- public static ValueExp value(long val)
- {
- return new NumericValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified value.
- *
- * @param val the {@link Number} value to wrap.
- * @return a value expression wrapping <code>val</code>. This
- * will be serialized as the non-public class
- * {@link NumericValueExp}.
- */
- public static ValueExp value(Number val)
- {
- return new NumericValueExp(val);
- }
- /**
- * Returns a value expression wrapping the specified string.
- *
- * @param val the {@link String} to wrap.
- * @return a {@link StringValueExp} wrapping <code>val</code>.
- */
- public static StringValueExp value(String val)
- {
- return new StringValueExp(val);
- }
- /**
- * Representation of the conjunction formed using
- * {@link #and(QueryExp, QueryExp).
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class AndQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -1081892073854801359L;
- /**
- * The first operand.
- */
- private QueryExp exp1;
- /**
- * The second operand.
- */
- private QueryExp exp2;
- /**
- * Constructs a new {@link AndQueryExp} using
- * the two specified operands.
- *
- * @param exp1 the first query expression.
- * @param exp2 the second query expression.
- */
- public AndQueryExp(QueryExp exp1, QueryExp exp2)
- {
- this.exp1 = exp1;
- this.exp2 = exp2;
- }
- /**
- * Returns the conjunction of the two query
- * expressions.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the conjunction of applying the name
- * to both operands.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- return exp1.apply(name) && exp2.apply(name);
- }
- }
- /**
- * Representation of a query that matches an
- * attribute's value against a given pattern.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class MatchQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -7156603696948215014L;
- /**
- * The attribute to match against.
- */
- private AttributeValueExp exp;
- /**
- * The pattern to be matched.
- */
- private String pattern;
- /**
- * Constructs a new {@link MatchQueryExp} using
- * the specified attribute value and pattern.
- *
- * @param exp the attribute value expression.
- * @param pattern the pattern.
- */
- public MatchQueryExp(AttributeValueExp exp,
- String pattern)
- {
- this.exp = exp;
- this.pattern = pattern;
- }
- /**
- * Returns the result of matching the attribute
- * value against the pattern.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the match.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- String val = ((StringValueExp) exp.apply(name)).getValue();
- int valPos = 0;
- int fallback = -1;
- int fallbackP = -1;
- boolean backslash = false;
- for (int a = 0; a < pattern.length(); ++a)
- {
- boolean matched = false;
- int next = pattern.codePointAt(a);
- if (!backslash)
- {
- if (next == '?' && valPos < val.length())
- {
- ++valPos;
- matched = true;
- }
- else if (next == '*')
- {
- fallback = valPos;
- fallbackP = a;
- matched = true;
- }
- else if (next == '[' && valPos < val.length())
- {
- boolean negated = false;
- int b = a + 1;
- int classChar = pattern.codePointAt(b);
- do
- {
- if (classChar == '!' && b == a + 1)
- negated = true;
- else if (pattern.codePointAt(b + 1) == '-' &&
- pattern.codePointAt(b + 2) != ']')
- {
- if (classChar > pattern.codePointAt(b + 2))
- throw new BadStringOperationException("Invalid range: " +
- classChar + " to " +
- pattern.codePointAt(b+2));
- for (int c = classChar; c <= pattern.codePointAt(b+2); ++c)
- if (val.codePointAt(valPos) == c)
- matched = true;
- b = b + 2;
- }
- else if (val.codePointAt(valPos) == classChar)
- matched = true;
- ++b;
- classChar = pattern.codePointAt(b);
- } while (classChar != ']');
- if (negated)
- matched = !matched;
- ++valPos;
- a = b;
- }
- else if (next == '\\')
- backslash = true;
- else if (valPos < val.length() && next == val.codePointAt(valPos))
- {
- matched = true;
- ++valPos;
- }
- }
- else
- {
- backslash = false;
- if (valPos < val.length() && next == val.codePointAt(valPos))
- {
- matched = true;
- ++valPos;
- }
- }
- if (!matched)
- if (fallback != -1)
- {
- ++fallback;
- valPos = fallback;
- a = fallbackP;
- if (valPos == val.length())
- return false;
- continue;
- }
- else
- return false;
- }
- return true;
- }
- }
- /**
- * Representation of the retrieval of an attribute
- * value from a certain class for {@link #attr(String,String)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class QualifiedAttributeValueExp
- extends AttributeValueExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = 8832517277410933254L;
- /**
- * The name of the class from which the attribute is taken.
- */
- private String className;
- /**
- * Constructs a new {@link QualifiedAttributeValueExp} using
- * the specified class name and attribute name.
- *
- * @param className the class name.
- * @param name the attribute name.
- */
- public QualifiedAttributeValueExp(String className, String name)
- {
- super(name);
- this.className = className;
- }
- /**
- * Applies the {@link AttributeValueExp} to the specified
- * management bean by checking that the attribute will be
- * obtained from the correct class (by a class to
- * {@link MBeanServer#getObjectInstance(ObjectName)} and
- * then obtaining the attribute value from the
- * {@link MBeanServer}, using it to create a
- * {@link StringValueExp}.
- *
- * @param name the {@link ObjectName} of the bean to obtain
- * the value from.
- * @return a {@link StringValueExp} containing the result.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the value expression.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the value expression.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the value expression.
- * @throws InvalidApplicationException if the value expression is applied
- * to the wrong type of bean.
- */
- public ValueExp apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- try
- {
- if (!(QueryEval.getMBeanServer().getObjectInstance(name).getClassName().equals(className)))
- throw new BadAttributeValueExpException("The value is not from " +
- "the correct class.");
- }
- catch (InstanceNotFoundException e)
- {
- throw (BadAttributeValueExpException)
- new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
- }
- return super.apply(name);
- }
- }
- /**
- * Representation of the comparison of a value with
- * a pair of bounds formed using
- * {@link #between(ValueExp, ValueExp, ValueExp).
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class BetweenQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -2933597532866307444L;
- /**
- * The value to compare.
- */
- private ValueExp exp1;
- /**
- * The lower boundary.
- */
- private ValueExp exp2;
- /**
- * The upper boundary.
- */
- private ValueExp exp3;
- /**
- * Constructs a new {@link BetweenQueryExp} using
- * the specified comparison value and the given
- * bounds.
- *
- * @param exp1 the value to compare.
- * @param exp2 the lower bound.
- * @param exp3 the upper bound.
- */
- public BetweenQueryExp(ValueExp exp1, ValueExp exp2,
- ValueExp exp3)
- {
- this.exp1 = exp1;
- this.exp2 = exp2;
- this.exp3 = exp3;
- }
- /**
- * Returns the result of the comparison between
- * the value and the two bounds.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the comparison.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- String v1 = exp1.apply(name).toString();
- String v2 = exp2.apply(name).toString();
- String v3 = exp3.apply(name).toString();
- return v1.compareTo(v2) >= 0 && v1.compareTo(v3) <= 0;
- }
- }
- /**
- * Representation of the retrieval of the name of
- * a bean's class for {@link #classattr()}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class ClassAttributeValueExp
- extends AttributeValueExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -1081892073854801359L;
- /**
- * Obtains the name of the specified bean's class using a call
- * to {@link MBeanServer#getObjectInstance(ObjectName)}.
- *
- * @param name the {@link ObjectName} of the bean to obtain
- * the class name from.
- * @return a {@link StringValueExp} containing the result.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the value expression.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the value expression.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the value expression.
- * @throws InvalidApplicationException if the value expression is applied
- * to the wrong type of bean.
- */
- public ValueExp apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- try
- {
- return new StringValueExp(QueryEval.getMBeanServer().getObjectInstance(name).getClassName());
- }
- catch (InstanceNotFoundException e)
- {
- throw (BadAttributeValueExpException)
- new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
- }
- }
- }
- /**
- * Representation of a binary operation formed using
- * {@link #div(ValueExp, ValueExp), {@link #plus(ValueExp,ValueExp)},
- * {@link #minus(ValueExp, ValueExp) or
- * {@link #times(ValueExp, ValueExp)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class BinaryOpValueExp
- extends QueryEval
- implements ValueExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = 1216286847881456786L;
- /**
- * The operation to perform.
- */
- private int op;
- /**
- * The left-hand operand.
- */
- private ValueExp exp1;
- /**
- * The right-hand operand.
- */
- private ValueExp exp2;
- /**
- * Constructs a new {@link BinaryOpValueExp} using
- * the specified operation and the two values supplied.
- *
- * @param op the operation to perform.
- * @param exp1 the left-hand operand.
- * @param exp2 the right-hand operand.
- */
- public BinaryOpValueExp(int op, ValueExp exp1, ValueExp exp2)
- {
- this.op = op;
- this.exp1 = exp1;
- this.exp2 = exp2;
- }
- /**
- * Returns the result of performing the operation on
- * <code>exp1</code> and <code>exp2</code>.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the operation.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public ValueExp apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- NumericValueExp v1 = (NumericValueExp) exp1.apply(name);
- NumericValueExp v2 = (NumericValueExp) exp2.apply(name);
- switch (op)
- {
- case PLUS:
- return v1.plus(v2);
- case MINUS:
- return v1.minus(v2);
- case TIMES:
- return v1.times(v2);
- case DIV:
- return v1.div(v2);
- default:
- throw new BadBinaryOpValueExpException(this);
- }
- }
- /**
- * Returns a textual representation of the operation.
- *
- * @return a textual version of the operation.
- */
- public String toString()
- {
- String opS;
- switch (op)
- {
- case PLUS:
- opS = "+";
- break;
- case MINUS:
- opS = "-";
- break;
- case TIMES:
- opS = "x";
- break;
- case DIV:
- opS = "/";
- break;
- default:
- opS = "?";
- }
- return exp1 + " " + opS + " " + exp2;
- }
- }
- /**
- * Representation of a binary operation formed using
- * {@link #eq(ValueExp, ValueExp), {@link #geq(ValueExp, ValueExp)},
- * {@link #leq(ValueExp, ValueExp), {@link #gt(ValueExp, ValueExp)}
- * or {@link #lt(ValueExp, ValueExp)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class BinaryRelQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -5690656271650491000L;
- /**
- * The operation to perform.
- */
- private int relOp;
- /**
- * The left-hand operand.
- */
- private ValueExp exp1;
- /**
- * The right-hand operand.
- */
- private ValueExp exp2;
- /**
- * Constructs a new {@link BinaryRelQueryExp} using
- * the specified operation and the two values supplied.
- *
- * @param relOp the operation to perform.
- * @param exp1 the left-hand operand.
- * @param exp2 the right-hand operand.
- */
- public BinaryRelQueryExp(int relOp, ValueExp exp1, ValueExp exp2)
- {
- this.relOp = relOp;
- this.exp1 = exp1;
- this.exp2 = exp2;
- }
- /**
- * Returns the result of performing the operation on
- * <code>exp1</code> and <code>exp2</code>.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the comparison.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- String v1 = exp1.apply(name).toString();
- String v2 = exp2.apply(name).toString();
- switch (relOp)
- {
- case EQ:
- return v1.equals(v2);
- case GT:
- return v1.compareTo(v2) > 0;
- case GE:
- return v1.compareTo(v2) >= 0;
- case LE:
- return v1.compareTo(v2) <= 0;
- case LT:
- return v1.compareTo(v2) < 0;
- default:
- throw new BadStringOperationException("Invalid operator: " + relOp);
- }
- }
- /**
- * Returns a textual representation of the operation.
- *
- * @return a textual version of the operation.
- */
- public String toString()
- {
- String op;
- switch (relOp)
- {
- case EQ:
- op = "=";
- break;
- case GT:
- op = ">";
- break;
- case GE:
- op = ">=";
- break;
- case LE:
- op = "<=";
- break;
- case LT:
- op = "<";
- break;
- default:
- op = "?";
- }
- return exp1 + " " + op + " " + exp2;
- }
- }
- /**
- * Representation of the comparison of a value with
- * the members of a list formed using
- * {@link #in(ValueExp, ValueExp[]).
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class InQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -5801329450358952434L;
- /**
- * The value to look for.
- */
- private ValueExp val;
- /**
- * The array to search.
- */
- private ValueExp[] valueList;
- /**
- * Constructs a new {@link InQueryExp} using
- * the specified comparison value and the given
- * list.
- *
- * @param val the value to compare.
- * @param valueList the list of values.
- */
- public InQueryExp(ValueExp val, ValueExp[] valueList)
- {
- this.val = val;
- this.valueList = valueList;
- }
- /**
- * Returns the result of the comparison between
- * the value and the list of allowed values.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the comparison.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- String v = val.apply(name).toString();
- for (ValueExp vl : valueList)
- if (v.equals(vl.apply(name).toString()))
- return true;
- return false;
- }
- }
- /**
- * Representation of the inheritance check on a
- * bean for {@link #isInstanceOf(StringValueExp)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.6
- */
- private static final class InstanceOfQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -1081892073854801359L;
- /**
- * The name of the class from which the attribute is taken.
- */
- private StringValueExp classNameValue;
- /**
- * Constructs a new {@link InstanceOfQueryExp} using
- * the specified class name.
- *
- * @param classNameValue the class name.
- */
- public InstanceOfQueryExp(StringValueExp classNameValue)
- {
- this.classNameValue = classNameValue;
- }
- /**
- * Checks that the bean specified by the supplied
- * {@link ObjectName} is of the correct class
- * using {@link MBeanServer#isInstanceOf(ObjectName,String)}.
- * where the string is obtained by evaluating
- * <code>classNameValue</code>.
- *
- * @param name the {@link ObjectName} of the bean to obtain
- * the value from.
- * @return true if the bean is an instance of the class.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the value expression.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the value expression.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the value expression.
- * @throws InvalidApplicationException if the value expression is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- try
- {
- String className = ((StringValueExp)
- classNameValue.apply(name)).getValue();
- return QueryEval.getMBeanServer().isInstanceOf(name, className);
- }
- catch (InstanceNotFoundException e)
- {
- throw (BadAttributeValueExpException)
- new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
- }
- }
- }
- /**
- * Representation of the negation of a query formed using
- * {@link #not(QueryExp).
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class NotQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = 5269643775896723397L;
- /**
- * The expression to negate.
- */
- private QueryExp exp;
- /**
- * Constructs a new {@link NotQueryExp} using
- * the specified query expression.
- *
- * @param exp the expression to negate.
- */
- public NotQueryExp(QueryExp exp)
- {
- this.exp = exp;
- }
- /**
- * Returns the result of the negation.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the result of the negation.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- return !(exp.apply(name));
- }
- }
- /**
- * Representation of the disjunction formed using
- * {@link #or(QueryExp, QueryExp).
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class OrQueryExp
- extends QueryEval
- implements QueryExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = 2962973084421716523L;
- /**
- * The first operand.
- */
- private QueryExp exp1;
- /**
- * The second operand.
- */
- private QueryExp exp2;
- /**
- * Constructs a new {@link OrQueryExp} using
- * the two specified operands.
- *
- * @param exp1 the first query expression.
- * @param exp2 the second query expression.
- */
- public OrQueryExp(QueryExp exp1, QueryExp exp2)
- {
- this.exp1 = exp1;
- this.exp2 = exp2;
- }
- /**
- * Returns the disjunction of the two query
- * expressions.
- *
- * @param name the {@link ObjectName} to apply
- * the query to.
- * @return the disjunction of applying the name
- * to both operands.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the query.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the query.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the query.
- * @throws InvalidApplicationException if the query is applied
- * to the wrong type of bean.
- */
- public boolean apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- return exp1.apply(name) || exp2.apply(name);
- }
- }
- /**
- * Representation of a boolean being used as an argument
- * to a relational constraint, formed using
- * {@link #value(boolean)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class BooleanValueExp
- extends QueryEval
- implements ValueExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = 7754922052666594581L;
- /**
- * The boolean value.
- */
- private boolean val;
- /**
- * Constructs a new {@link BooleanValueExp} using the
- * specified value.
- *
- * @param val the boolean value used for this expression.
- */
- public BooleanValueExp(boolean val)
- {
- this.val = val;
- }
- /**
- * Applies the {@link BooleanValueExp} to the specified
- * management bean by simply returning the value.
- *
- * @param name the {@link ObjectName} of the bean.
- * @return the {@link BooleanValueExp} itself.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the value expression.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the value expression.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the value expression.
- * @throws InvalidApplicationException if the value expression is applied
- * to the wrong type of bean.
- */
- public ValueExp apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- return this;
- }
- /**
- * Returns the value as a string.
- *
- * @return the value in textual form.
- */
- public String toString()
- {
- return Boolean.toString(val);
- }
- }
- /**
- * Representation of a number being used as an argument
- * to a relational constraint, formed using
- * {@link #value(double)}, {@link #value(float)},
- * {@link #value(int)}, {@link #value(long)} or
- * {@link #value(Number)}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
- private static final class NumericValueExp
- extends QueryEval
- implements ValueExp
- {
- /**
- * Compatible with JDK 1.6
- */
- private static final long serialVersionUID = -4679739485102359104L;
- /**
- * The numeric value.
- */
- private Number val;
- /**
- * Constructs a new {@link NumericValueExp} using the
- * specified value.
- *
- * @param val the numeric value used for this expression.
- */
- public NumericValueExp(Number val)
- {
- this.val = val;
- }
- /**
- * Applies the {@link NumericValueExp} to the specified
- * management bean by simply returning the value.
- *
- * @param name the {@link ObjectName} of the bean.
- * @return the {@link NumericValueExp} itself.
- * @throws BadStringOperationException if an invalid string
- * operation is used by
- * the value expression.
- * @throws BadBinaryOpValueExpException if an invalid expression
- * is used by the value expression.
- * @throws BadAttributeValueExpException if an invalid attribute
- * is used by the value expression.
- * @throws InvalidApplicationException if the value expression is applied
- * to the wrong type of bean.
- */
- public ValueExp apply(ObjectName name)
- throws BadStringOperationException, BadBinaryOpValueExpException,
- BadAttributeValueExpException, InvalidApplicationException
- {
- return this;
- }
- /**
- * Returns the value.
- */
- public Number getValue()
- {
- return val;
- }
- /**
- * Returns the value as a string.
- *
- * @return the value in textual form.
- */
- public String toString()
- {
- return val.toString();
- }
- /**
- * Return the result of adding the specified
- * {@link NumericValueExp} to this one.
- *
- * @param o the value to add.
- * @return the result of the addition.
- */
- public NumericValueExp plus(NumericValueExp o)
- {
- Number v = o.getValue();
- if (val instanceof Double)
- {
- double d = val.doubleValue();
- if (v instanceof Double)
- return new NumericValueExp(d + v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(d + v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(d + v.longValue());
- else
- return new NumericValueExp(d + v.intValue());
- }
- else if (val instanceof Float)
- {
- float f = val.floatValue();
- if (v instanceof Double)
- return new NumericValueExp(f + v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(f + v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(f + v.longValue());
- else
- return new NumericValueExp(f + v.intValue());
- }
- else if (val instanceof Long)
- {
- long l = val.longValue();
- if (v instanceof Double)
- return new NumericValueExp(l + v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(l + v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(l + v.longValue());
- else
- return new NumericValueExp(l + v.intValue());
- }
- int i = val.intValue();
- if (v instanceof Double)
- return new NumericValueExp(i + v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(i + v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(i + v.longValue());
- else
- return new NumericValueExp(i + v.intValue());
- }
- /**
- * Return New NumericValueExp(the result of subtracting the specified
- * {@link NumericValueExp} from this one.
- *
- * @param o the value to subtract.
- * @return new NumericValueExp(the result of the subtraction.
- */
- public NumericValueExp minus(NumericValueExp o)
- {
- Number v = o.getValue();
- if (val instanceof Double)
- {
- double d = val.doubleValue();
- if (v instanceof Double)
- return new NumericValueExp(d - v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(d - v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(d - v.longValue());
- else
- return new NumericValueExp(d - v.intValue());
- }
- else if (val instanceof Float)
- {
- float f = val.floatValue();
- if (v instanceof Double)
- return new NumericValueExp(f - v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(f - v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(f - v.longValue());
- else
- return new NumericValueExp(f - v.intValue());
- }
- else if (val instanceof Long)
- {
- long l = val.longValue();
- if (v instanceof Double)
- return new NumericValueExp(l - v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(l - v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(l - v.longValue());
- else
- return new NumericValueExp(l - v.intValue());
- }
- int i = val.intValue();
- if (v instanceof Double)
- return new NumericValueExp(i - v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(i - v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(i - v.longValue());
- else
- return new NumericValueExp(i - v.intValue());
- }
- /**
- * Return New NumericValueExp(the result of multiplying the specified
- * {@link NumericValueExp} to this one.
- *
- * @param o the value to multiply by.
- * @return new NumericValueExp(the result of the multiplication.
- */
- public NumericValueExp times(NumericValueExp o)
- {
- Number v = o.getValue();
- if (val instanceof Double)
- {
- double d = val.doubleValue();
- if (v instanceof Double)
- return new NumericValueExp(d * v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(d * v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(d * v.longValue());
- else
- return new NumericValueExp(d * v.intValue());
- }
- else if (val instanceof Float)
- {
- float f = val.floatValue();
- if (v instanceof Double)
- return new NumericValueExp(f * v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(f * v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(f * v.longValue());
- else
- return new NumericValueExp(f * v.intValue());
- }
- else if (val instanceof Long)
- {
- long l = val.longValue();
- if (v instanceof Double)
- return new NumericValueExp(l * v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(l * v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(l * v.longValue());
- else
- return new NumericValueExp(l * v.intValue());
- }
- int i = val.intValue();
- if (v instanceof Double)
- return new NumericValueExp(i * v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(i * v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(i * v.longValue());
- else
- return new NumericValueExp(i * v.intValue());
- }
- /**
- * Return New NumericValueExp(the result of dividing this
- * number by value of the specified
- * {@link NumericValueExp}.
- *
- * @param o the value to divide by.
- * @return new NumericValueExp(the result of the division.
- */
- public NumericValueExp div(NumericValueExp o)
- {
- Number v = o.getValue();
- if (val instanceof Double)
- {
- double d = val.doubleValue();
- if (v instanceof Double)
- return new NumericValueExp(d / v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(d / v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(d / v.longValue());
- else
- return new NumericValueExp(d / v.intValue());
- }
- else if (val instanceof Float)
- {
- float f = val.floatValue();
- if (v instanceof Double)
- return new NumericValueExp(f / v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(f / v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(f / v.longValue());
- else
- return new NumericValueExp(f / v.intValue());
- }
- else if (val instanceof Long)
- {
- long l = val.longValue();
- if (v instanceof Double)
- return new NumericValueExp(l / v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(l / v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(l / v.longValue());
- else
- return new NumericValueExp(l / v.intValue());
- }
- int i = val.intValue();
- if (v instanceof Double)
- return new NumericValueExp(i / v.doubleValue());
- else if (v instanceof Float)
- return new NumericValueExp(i / v.floatValue());
- else if (v instanceof Long)
- return new NumericValueExp(i / v.longValue());
- else
- return new NumericValueExp(i / v.intValue());
- }
- }
- }
|