001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xml.xpath.ext.metadata.impl;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024: import javax.swing.Icon;
025: import org.netbeans.modules.xml.xpath.ext.metadata.AbstractArgument;
026: import org.netbeans.modules.xml.xpath.ext.metadata.ArgumentDescriptor;
027: import org.netbeans.modules.xml.xpath.ext.metadata.GeneralFunctionMetadata.FunctionType;
028: import org.netbeans.modules.xml.xpath.ext.metadata.OperationMetadata;
029: import org.netbeans.modules.xml.xpath.ext.metadata.ResultTypeCalculator;
030: import org.netbeans.modules.xml.xpath.ext.metadata.XPathType;
031: import org.netbeans.modules.xml.xpath.ext.metadata.impl.images.IconLoader;
032: import org.openide.util.NbBundle;
033:
034: /**
035: * Contains static metadata classes for all XPath operations.
036: *
037: * @author nk160297
038: */
039: public abstract class OperationMetadataImpl implements
040: OperationMetadata {
041:
042: protected ArrayList<AbstractArgument> mArguments = new ArrayList<AbstractArgument>();
043:
044: protected Icon mIcon;
045:
046: protected OperationMetadataImpl() {
047: initArguments();
048: }
049:
050: public String getId() {
051: return getName();
052: }
053:
054: public Icon getIcon() {
055: if (mIcon == null) {
056: loadIcon();
057: }
058: return mIcon;
059: }
060:
061: public String getShortDescription() {
062: return "";
063: }
064:
065: public String getLongDescription() {
066: return "";
067: }
068:
069: public FunctionType getFunctionType() {
070: return FunctionType.OPERATION;
071: }
072:
073: public ResultTypeCalculator getResultTypeCalculator() {
074: return null;
075: }
076:
077: public List<AbstractArgument> getArguments() {
078: return mArguments;
079: }
080:
081: protected void loadIcon() {
082: mIcon = IconLoader.getIcon(getId()); // NOI18N
083: }
084:
085: protected void initArguments() {
086: mArguments.add(ArgumentDescriptor.Predefined.ANY_TYPE);
087: mArguments.add(ArgumentDescriptor.Predefined.ANY_TYPE);
088: }
089:
090: //==========================================================================
091: // Boolean operations
092: //==========================================================================
093:
094: protected static abstract class BooleanOperMetadata extends
095: OperationMetadataImpl {
096: public XPathType getResultType() {
097: return XPathType.BOOLEAN_TYPE;
098: }
099: }
100:
101: public static final class OrOperationMetadata extends
102: BooleanOperMetadata {
103:
104: public int getPrecedenceLevel() {
105: return 10;
106: }
107:
108: public String getName() {
109: return "or"; // NOI18N
110: }
111:
112: public String getDisplayName() {
113: return NbBundle.getMessage(OperationMetadataImpl.class,
114: "DN_LogicalOr"); // NOI18N
115: }
116:
117: // public String getShortDescription() {
118: // }
119: //
120: // public String getLongDescription() {
121: // }
122:
123: @Override
124: protected void initArguments() {
125: mArguments
126: .add(ArgumentDescriptor.Predefined.SIMPLE_BOOLEAN);
127: mArguments
128: .add(ArgumentDescriptor.Predefined.SIMPLE_BOOLEAN);
129: }
130:
131: }
132:
133: public static final class AndOperationMetadata extends
134: BooleanOperMetadata {
135:
136: public int getPrecedenceLevel() {
137: return 20;
138: }
139:
140: public String getName() {
141: return "and"; // NOI18N
142: }
143:
144: public String getDisplayName() {
145: return NbBundle.getMessage(OperationMetadataImpl.class,
146: "DN_LogicalAnd"); // NOI18N
147: }
148:
149: // public String getShortDescription() {
150: // }
151: //
152: // public String getLongDescription() {
153: // }
154:
155: @Override
156: protected void initArguments() {
157: mArguments
158: .add(ArgumentDescriptor.Predefined.SIMPLE_BOOLEAN);
159: mArguments
160: .add(ArgumentDescriptor.Predefined.SIMPLE_BOOLEAN);
161: }
162: }
163:
164: public static final class EqualOperationMetadata extends
165: BooleanOperMetadata {
166:
167: public int getPrecedenceLevel() {
168: return 30;
169: }
170:
171: public String getName() {
172: return "="; // NOI18N
173: }
174:
175: @Override
176: public String getId() {
177: return "equal"; // NOI18N
178: }
179:
180: public String getDisplayName() {
181: return NbBundle.getMessage(OperationMetadataImpl.class,
182: "DN_Equal"); // NOI18N
183: }
184:
185: // public String getShortDescription() {
186: // }
187: //
188: // public String getLongDescription() {
189: // }
190:
191: @Override
192: protected void initArguments() {
193: mArguments.add(ArgumentDescriptor.Predefined.ANY_TYPE);
194: mArguments.add(ArgumentDescriptor.Predefined.ANY_TYPE);
195: }
196: }
197:
198: public static final class NotEqualOperationMetadata extends
199: BooleanOperMetadata {
200:
201: public int getPrecedenceLevel() {
202: return 30;
203: }
204:
205: public String getName() {
206: return "!="; // NOI18N
207: }
208:
209: @Override
210: public String getId() {
211: return "not_equal"; // NOI18N
212: }
213:
214: public String getDisplayName() {
215: return NbBundle.getMessage(OperationMetadataImpl.class,
216: "DN_NotEqual"); // NOI18N
217: }
218:
219: // public String getShortDescription() {
220: // }
221: //
222: // public String getLongDescription() {
223: // }
224: }
225:
226: public static final class LEOperationMetadata extends
227: BooleanOperMetadata {
228:
229: public int getPrecedenceLevel() {
230: return 40;
231: }
232:
233: public String getName() {
234: return "<="; // NOI18N
235: }
236:
237: @Override
238: public String getId() {
239: return "lesser_or_equal"; // NOI18N
240: }
241:
242: public String getDisplayName() {
243: return NbBundle.getMessage(OperationMetadataImpl.class,
244: "DN_LessOrEqual"); // NOI18N
245: }
246:
247: // public String getShortDescription() {
248: // }
249: //
250: // public String getLongDescription() {
251: // }
252: }
253:
254: public static final class LTOperationMetadata extends
255: BooleanOperMetadata {
256:
257: public int getPrecedenceLevel() {
258: return 40;
259: }
260:
261: public String getName() {
262: return "<"; // NOI18N
263: }
264:
265: @Override
266: public String getId() {
267: return "lesser_than"; // NOI18N
268: }
269:
270: public String getDisplayName() {
271: return NbBundle.getMessage(OperationMetadataImpl.class,
272: "DN_Less"); // NOI18N
273: }
274:
275: // public String getShortDescription() {
276: // }
277: //
278: // public String getLongDescription() {
279: // }
280: }
281:
282: public static final class GEOperationMetadata extends
283: BooleanOperMetadata {
284:
285: public int getPrecedenceLevel() {
286: return 40;
287: }
288:
289: public String getName() {
290: return ">="; // NOI18N
291: }
292:
293: @Override
294: public String getId() {
295: return "greater_or_equal"; // NOI18N
296: }
297:
298: public String getDisplayName() {
299: return NbBundle.getMessage(OperationMetadataImpl.class,
300: "DN_GreaterOrEqual"); // NOI18N
301: }
302:
303: // public String getShortDescription() {
304: // }
305: //
306: // public String getLongDescription() {
307: // }
308: }
309:
310: public static final class GTOperationMetadata extends
311: BooleanOperMetadata {
312:
313: public int getPrecedenceLevel() {
314: return 40;
315: }
316:
317: public String getName() {
318: return ">"; // NOI18N
319: }
320:
321: @Override
322: public String getId() {
323: return "greater_than"; // NOI18N
324: }
325:
326: public String getDisplayName() {
327: return NbBundle.getMessage(OperationMetadataImpl.class,
328: "DN_Greater"); // NOI18N
329: }
330:
331: // public String getShortDescription() {
332: // }
333: //
334: // public String getLongDescription() {
335: // }
336: }
337:
338: //==========================================================================
339: // Number operations
340: //==========================================================================
341:
342: protected static abstract class NumberOperMetadata extends
343: OperationMetadataImpl {
344: public XPathType getResultType() {
345: return XPathType.NUMBER_TYPE;
346: }
347:
348: @Override
349: protected void initArguments() {
350: mArguments.add(ArgumentDescriptor.Predefined.SIMPLE_NUMBER);
351: mArguments.add(ArgumentDescriptor.Predefined.SIMPLE_NUMBER);
352: }
353: }
354:
355: public static final class AdditionOperationMetadata extends
356: NumberOperMetadata {
357:
358: public int getPrecedenceLevel() {
359: return 50;
360: }
361:
362: public String getName() {
363: return "+"; // NOI18N
364: }
365:
366: @Override
367: public String getId() {
368: return "addition"; // NOI18N
369: }
370:
371: public String getDisplayName() {
372: return NbBundle.getMessage(OperationMetadataImpl.class,
373: "DN_Addition"); // NOI18N
374: }
375:
376: // public String getShortDescription() {
377: // }
378: //
379: // public String getLongDescription() {
380: // }
381:
382: @Override
383: protected void initArguments() {
384: mArguments
385: .add(ArgumentDescriptor.Predefined.REPEATED_NUMBER_2MIN);
386: }
387:
388: }
389:
390: public static final class SubtractionOperationMetadata extends
391: NumberOperMetadata {
392:
393: public int getPrecedenceLevel() {
394: return 50;
395: }
396:
397: public String getName() {
398: return "-"; // NOI18N
399: }
400:
401: @Override
402: public String getId() {
403: return "subtraction"; // NOI18N
404: }
405:
406: public String getDisplayName() {
407: return NbBundle.getMessage(OperationMetadataImpl.class,
408: "DN_Subtraction"); // NOI18N
409: }
410:
411: // public String getShortDescription() {
412: // }
413: //
414: // public String getLongDescription() {
415: // }
416: }
417:
418: public static final class MultOperationMetadata extends
419: NumberOperMetadata {
420:
421: public int getPrecedenceLevel() {
422: return 60;
423: }
424:
425: public String getName() {
426: return "*"; // NOI18N
427: }
428:
429: @Override
430: public String getId() {
431: return "multiplication"; // NOI18N
432: }
433:
434: public String getDisplayName() {
435: return NbBundle.getMessage(OperationMetadataImpl.class,
436: "DN_Multiplication"); // NOI18N
437: }
438:
439: // public String getShortDescription() {
440: // }
441: //
442: // public String getLongDescription() {
443: // }
444: }
445:
446: public static final class DivOperationMetadata extends
447: NumberOperMetadata {
448:
449: public int getPrecedenceLevel() {
450: return 70;
451: }
452:
453: public String getName() {
454: return "div"; // NOI18N
455: }
456:
457: @Override
458: public String getId() {
459: return "division"; // NOI18N
460: }
461:
462: public String getDisplayName() {
463: return NbBundle.getMessage(OperationMetadataImpl.class,
464: "DN_Division"); // NOI18N
465: }
466:
467: // public String getShortDescription() {
468: // }
469: //
470: // public String getLongDescription() {
471: // }
472: }
473:
474: public static final class ModOperationMetadata extends
475: NumberOperMetadata {
476:
477: public int getPrecedenceLevel() {
478: return 80;
479: }
480:
481: public String getName() {
482: return "mod"; // NOI18N
483: }
484:
485: public String getDisplayName() {
486: return NbBundle.getMessage(OperationMetadataImpl.class,
487: "DN_Remainder"); // NOI18N
488: }
489:
490: // public String getShortDescription() {
491: // }
492: //
493: // public String getLongDescription() {
494: // }
495: }
496:
497: public static final class NegativeOperationMetadata extends
498: NumberOperMetadata {
499:
500: public int getPrecedenceLevel() {
501: return 100; // Unary operation have maximum precedence
502: }
503:
504: public String getName() {
505: return "-"; // NOI18N
506: }
507:
508: @Override
509: public String getId() {
510: return "negative"; // NOI18N
511: }
512:
513: public String getDisplayName() {
514: return NbBundle.getMessage(OperationMetadataImpl.class,
515: "DN_Negative"); // NOI18N
516: }
517:
518: // public String getShortDescription() {
519: // }
520: //
521: // public String getLongDescription() {
522: // }
523:
524: @Override
525: protected void initArguments() {
526: mArguments.add(ArgumentDescriptor.Predefined.SIMPLE_NUMBER);
527: }
528:
529: }
530:
531: //==========================================================================
532: // Node Set operations
533: //==========================================================================
534:
535: public static final class UnionOperationMetadata extends
536: OperationMetadataImpl {
537:
538: public int getPrecedenceLevel() {
539: return 90;
540: }
541:
542: public String getName() {
543: return "|"; // NOI18N
544: }
545:
546: @Override
547: public String getId() {
548: return "union"; // NOI18N
549: }
550:
551: public String getDisplayName() {
552: return NbBundle.getMessage(OperationMetadataImpl.class,
553: "DN_Union"); // NOI18N
554: }
555:
556: // public String getShortDescription() {
557: // }
558: //
559: // public String getLongDescription() {
560: // }
561:
562: public XPathType getResultType() {
563: return XPathType.NODE_SET_TYPE;
564: }
565:
566: @Override
567: protected void initArguments() {
568: mArguments
569: .add(ArgumentDescriptor.Predefined.REPEATED_NODE_SET_2MIN);
570: }
571: }
572: }
|