Source Code Cross Referenced for SQLGenericOperatorImpl.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » sql » framework » model » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » etl.project » org.netbeans.modules.sql.framework.model.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.sql.framework.model.impl;
042:
043:        import java.util.Iterator;
044:        import java.util.List;
045:
046:        import org.netbeans.modules.sql.framework.common.utils.TagParserUtility;
047:        import org.netbeans.modules.sql.framework.codegen.SQLOperatorFactory;
048:        import org.netbeans.modules.sql.framework.model.GUIInfo;
049:        import org.netbeans.modules.sql.framework.model.SQLConstants;
050:        import org.netbeans.modules.sql.framework.model.SQLGenericOperator;
051:        import org.netbeans.modules.sql.framework.model.SQLInputObject;
052:        import org.netbeans.modules.sql.framework.model.SQLLiteral;
053:        import org.netbeans.modules.sql.framework.model.SQLObject;
054:        import org.netbeans.modules.sql.framework.model.SQLOperator;
055:        import org.netbeans.modules.sql.framework.model.SQLOperatorArg;
056:        import org.netbeans.modules.sql.framework.model.SQLOperatorDefinition;
057:        import org.netbeans.modules.sql.framework.model.utils.GeneratorUtil;
058:        import org.netbeans.modules.sql.framework.model.utils.OperatorUtil;
059:        import org.netbeans.modules.sql.framework.model.visitors.SQLVisitor;
060:        import org.netbeans.modules.sql.framework.ui.graph.IOperatorField;
061:        import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo;
062:        import org.w3c.dom.Element;
063:        import org.w3c.dom.NodeList;
064:
065:        import com.sun.sql.framework.exception.BaseException;
066:        import com.sun.sql.framework.utils.Attribute;
067:        import com.sun.sql.framework.utils.StringUtil;
068:
069:        /**
070:         * Model for operators supported by SQLBuilder
071:         * 
072:         * @author Ritesh Adval, Sudhi Seshahcala
073:         * @version $Revision$
074:         */
075:        public class SQLGenericOperatorImpl extends SQLConnectableObjectImpl
076:                implements  SQLGenericOperator {
077:
078:            /* Log4J category name */
079:            static final String LOG_CATEGORY = SQLGenericOperator.class
080:                    .getName();
081:
082:            /* script of this operator. */
083:            protected SQLOperatorDefinition operatorDefinition;
084:
085:            /* GUI state info */
086:            private GUIInfo guiInfo = new GUIInfo();
087:
088:            /* flag indicating if operator can take variable arguments. */
089:            protected boolean hasVariableArgs = false;
090:
091:            protected IOperatorXmlInfo operatorXmlInfo;
092:
093:            /** Creates a new default instance of SQLGenericOperator */
094:            public SQLGenericOperatorImpl() {
095:                super ();
096:                this .type = SQLConstants.GENERIC_OPERATOR;
097:            }
098:
099:            /** Creates a new default instance of SQLGenericOperator 
100:             * @param src 
101:             * @throws com.sun.sql.framework.exception.BaseException 
102:             */
103:            public SQLGenericOperatorImpl(SQLGenericOperator src)
104:                    throws BaseException {
105:                this ();
106:                copyFrom(src);
107:            }
108:
109:            /**
110:             * Constructs a new instance of SQLGenericOperator with the given name and canonical
111:             * operator type.
112:             * 
113:             * @param newName for Operator
114:             * @param aType for Operator
115:             * @throws com.sun.sql.framework.exception.BaseException 
116:             */
117:            public SQLGenericOperatorImpl(String newName, String aType)
118:                    throws BaseException {
119:                this ();
120:                this .displayName = newName;
121:                IOperatorXmlInfo operatorXml = OperatorUtil
122:                        .findOperatorXmlInfo(aType);
123:                if (operatorXml != null) {
124:                    this .setOperatorXmlInfo(operatorXml);
125:                } else {
126:                    throw new BaseException(
127:                            "Cannot locate definition for operator " + aType);
128:                }
129:            }
130:
131:            /**
132:             * @throws com.sun.sql.framework.exception.BaseException 
133:             * @see org.netbeans.modules.sql.framework.model.SQLConnectableObject#addInput
134:             */
135:            public void addInput(String argName, SQLObject newInput)
136:                    throws BaseException {
137:                if (argName == null || newInput == null) {
138:                    throw new BaseException("Input arguments not specified");
139:                }
140:
141:                int newType = newInput.getObjectType();
142:                String objType = TagParserUtility.getDisplayStringFor(newType);
143:
144:                if (!isInputValid(argName, newInput)) {
145:                    throw new BaseException("Cannot link " + objType + " '"
146:                            + newInput.getDisplayName() + "' as input to '"
147:                            + argName + "' in "
148:                            + TagParserUtility.getDisplayStringFor(type) + " '"
149:                            + this .getDisplayName() + "'");
150:                }
151:
152:                // If operator is not of type variable arguments then we know its number
153:                // of inputs
154:                if (!hasVariableArgs) {
155:                    SQLInputObject inputObject = (SQLInputObject) this .inputMap
156:                            .get(argName);
157:                    if (inputObject != null) {
158:                        inputObject.setSQLObject(newInput);
159:                    } else {
160:                        throw new BaseException(
161:                                "Could not resolve link for argument '"
162:                                        + argName
163:                                        + "' in "
164:                                        + TagParserUtility
165:                                                .getDisplayStringFor(type)
166:                                        + " '" + this .getDisplayName() + "'");
167:
168:                    }
169:                } else {
170:                    // we need to do this check, bcos at reload time argument name is already set
171:                    // only at link time argument name will not be set
172:                    SQLOperatorArg operatorArg = operatorDefinition
173:                            .getOperatorArg(0);
174:                    String name = operatorArg.getArgName();
175:
176:                    if (argName.equals(name)) {
177:                        argName = generateVarOperatorArgName(argName);
178:                    }
179:
180:                    SQLInputObject inputObject = new SQLInputObjectImpl(
181:                            argName, displayName, null);
182:                    inputObject.setSQLObject(newInput);
183:                    inputMap.put(argName, inputObject);
184:                }
185:            }
186:
187:            public Object clone() throws CloneNotSupportedException {
188:                try {
189:                    SQLGenericOperator op = new SQLGenericOperatorImpl(this );
190:                    return op;
191:                } catch (BaseException ex) {
192:                    throw new CloneNotSupportedException(
193:                            "can not create clone of " + this .getOperatorType());
194:                }
195:            }
196:
197:            // We need to add more for equals ???
198:            /**
199:             * @param refObj 
200:             * @see java.lang.Object#equals
201:             */
202:            public boolean equals(Object refObj) {
203:                return super .equals(refObj);
204:            }
205:
206:            public Object getArgumentValue(String argName) throws BaseException {
207:                return this .getSQLObject(argName);
208:            }
209:
210:            public String getCustomOperatorName() {
211:                String ufName = (String) getAttributeObject(ATTR_CUSTOM_OPERATOR_NAME);
212:                if (ufName == null) {
213:                    ufName = this .displayName;
214:                }
215:
216:                return ufName;
217:            }
218:
219:            public String getDisplayName() {
220:                String dName = super .getDisplayName();
221:                if (dName == null) {
222:                    return this .getOperatorType();
223:                }
224:
225:                return dName;
226:            }
227:
228:            /**
229:             * Gets GUI-related attributes for this instance in the form of a GuiInfo instance.
230:             * 
231:             * @return associated GuiInfo instance
232:             * @see GUIInfo
233:             */
234:            public GUIInfo getGUIInfo() {
235:                return guiInfo;
236:            }
237:
238:            /**
239:             * Overrides default implementation to return JDBC type as specified by the operator
240:             * script.
241:             * 
242:             * @return operator JDBC type
243:             */
244:            public int getJdbcType() {
245:                return (operatorDefinition != null) ? operatorDefinition
246:                        .getOutputJdbcSQLType()
247:                        : SQLConstants.JDBCSQL_TYPE_UNDEFINED;
248:            }
249:
250:            /**
251:             * Get the script of this operator.
252:             * 
253:             * @return Return script of this operator.
254:             */
255:            public SQLOperatorDefinition getOperatorDefinition() {
256:                return operatorDefinition;
257:            }
258:
259:            /**
260:             * Gets canonical operator type, e.g., "concat", "tolowercase", etc..
261:             * 
262:             * @return canonical operator name
263:             */
264:            public String getOperatorType() {
265:                if (operatorDefinition != null) {
266:                    return operatorDefinition.getOperatorName();
267:                }
268:
269:                Attribute attr = getAttribute(SQLOperator.ATTR_SCRIPTREF);
270:                return (attr != null) ? attr.getAttributeValue().toString()
271:                        : null;
272:            }
273:
274:            public IOperatorXmlInfo getOperatorXmlInfo() {
275:                return this .operatorXmlInfo;
276:            }
277:
278:            /**
279:             * @see java.lang.Object#hashCode
280:             */
281:            public int hashCode() {
282:                return super .hashCode();
283:            }
284:
285:            /**
286:             * Indicates weather this operator has variable number of arguments.
287:             * 
288:             * @return true if operator has variable number of arguments; else, false.
289:             */
290:            public boolean hasVariableArgs() {
291:                return (this .hasVariableArgs);
292:            }
293:
294:            /**
295:             * check if operator is an aggregate function
296:             * 
297:             * @return bool
298:             */
299:            public boolean isAggregateFunction() {
300:                SQLOperatorDefinition opdef = this .getOperatorDefinition();
301:
302:                if (opdef != null) {
303:                    Boolean aggFunc = (Boolean) opdef
304:                            .getAttributeValue(SQLOperatorDefinition.ATTR_AGGREGATE_FUNCTION);
305:                    if (aggFunc != null) {
306:                        return aggFunc.booleanValue();
307:                    }
308:                }
309:                return false;
310:            }
311:
312:            /**
313:             * Determines if input referenced by the given argument name can received a link from
314:             * the given SQLObject without breaking type casting rules.
315:             * 
316:             * @param argName name of the operator input to which the source operator is being
317:             *        connected.
318:             * @param input SQLObject to which input argument is being connected.
319:             * @return true if 'argName' can be connected to input, false otherwise
320:             */
321:            public int isCastable(String argName, SQLObject input) {
322:                int srcType = SQLConstants.JDBCSQL_TYPE_UNDEFINED;
323:
324:                if (hasVariableArgs) {
325:                    argName = operatorDefinition.getVarOperatorArgName();
326:                }
327:
328:                int destType = operatorDefinition.getArgJdbcSQLType(argName);
329:
330:                // XXX Refactor to completely reflect SQL syntax rules for sql operators.
331:                switch (input.getObjectType()) {
332:                case SQLConstants.GENERIC_OPERATOR:
333:                case SQLConstants.CUSTOM_OPERATOR:
334:                case SQLConstants.CAST_OPERATOR:
335:                case SQLConstants.DATE_DIFF_OPERATOR:
336:                case SQLConstants.DATE_ADD_OPERATOR:
337:                case SQLConstants.SOURCE_COLUMN:
338:                case SQLConstants.VISIBLE_LITERAL:
339:                case SQLConstants.COLUMN_REF:
340:                case SQLConstants.CASE:
341:                    srcType = input.getJdbcType();
342:                    break;
343:
344:                case SQLConstants.LITERAL:
345:                    return SQLConstants.TYPE_CHECK_SAME;
346:                default:
347:                    srcType = SQLConstants.JDBCSQL_TYPE_UNDEFINED;
348:                }
349:
350:                return SQLOperatorFactory.getDefault().getCastingRuleFor(
351:                        srcType, destType);
352:            }
353:
354:            public boolean isCustomOperator() {
355:                Boolean uf = (Boolean) getAttributeObject(ATTR_CUSTOM_OPERATOR);
356:                if (uf == null) {
357:                    uf = Boolean.FALSE;
358:                }
359:                return uf.booleanValue();
360:            }
361:
362:            /**
363:             * @see org.netbeans.modules.sql.framework.model.SQLConnectableObject#isInputCompatible
364:             */
365:            public int isInputCompatible(String argName, SQLObject input) {
366:                return isCastable(argName, input);
367:            }
368:
369:            public boolean isInputStatic(String argName) {
370:                IOperatorField field = getOperatorXmlInfo().getInputField(
371:                        argName);
372:                if (field != null) {
373:                    return getOperatorXmlInfo().getInputField(argName)
374:                            .isStatic();
375:                }
376:                return false;
377:            }
378:
379:            /**
380:             * @see org.netbeans.modules.sql.framework.model.SQLConnectableObject#isInputValid
381:             */
382:            public boolean isInputValid(String argName, SQLObject input) {
383:                if (input == null) {
384:                    return false;
385:                }
386:
387:                // XXX Refactor to completely reflect SQL syntax rules for generic operators.
388:                switch (input.getObjectType()) {
389:                case SQLConstants.GENERIC_OPERATOR:
390:                case SQLConstants.CUSTOM_OPERATOR:
391:                case SQLConstants.CAST_OPERATOR:
392:                case SQLConstants.DATE_ARITHMETIC_OPERATOR:
393:                case SQLConstants.DATE_DIFF_OPERATOR:
394:                case SQLConstants.DATE_ADD_OPERATOR:
395:                case SQLConstants.SOURCE_COLUMN:
396:                case SQLConstants.LITERAL:
397:                case SQLConstants.COLUMN_REF:
398:                case SQLConstants.CASE:
399:                    return true;
400:
401:                case SQLConstants.VISIBLE_LITERAL:
402:                    return this .checkRange(argName, input);
403:
404:                default:
405:                    return false;
406:                }
407:            }
408:
409:            /**
410:             * check if open and close parenthesis should be used
411:             * 
412:             * @return bool
413:             */
414:            public boolean isShowParenthesis() {
415:                Boolean paran = (Boolean) getAttributeObject(ATTR_PARENTHESIS);
416:                SQLOperatorDefinition opdef = this .getOperatorDefinition();
417:
418:                if (paran != null) {
419:                    return paran.booleanValue();
420:                } else if (opdef != null) {
421:                    Boolean showParan = (Boolean) opdef
422:                            .getAttributeValue(SQLOperatorDefinition.ATTR_SHOWPARENTHESIS);
423:                    if (showParan != null) {
424:                        return showParan.booleanValue();
425:                    }
426:                }
427:
428:                return false;
429:            }
430:
431:            /**
432:             * @param xmlElement 
433:             * @throws com.sun.sql.framework.exception.BaseException 
434:             * @see SQLObject#parseXML
435:             */
436:            public void parseXML(Element xmlElement) throws BaseException {
437:                super .parseXML(xmlElement);
438:
439:                String opName = (String) getAttributeObject(SQLOperator.ATTR_SCRIPTREF);
440:                IOperatorXmlInfo operatorXml = OperatorUtil
441:                        .findOperatorXmlInfo(opName);
442:                if (operatorXml != null) {
443:                    this .setOperatorXmlInfo(operatorXml);
444:                } else {
445:                    throw new BaseException(
446:                            "Cannot locate definition for operator " + opName);
447:                }
448:
449:                NodeList inputArgList = xmlElement
450:                        .getElementsByTagName(TAG_INPUT);
451:                if (inputArgList != null && inputArgList.getLength() != 0) {
452:                    TagParserUtility.parseInputTagList(this , inputArgList);
453:                }
454:
455:                NodeList guiInfoList = xmlElement
456:                        .getElementsByTagName(GUIInfo.TAG_GUIINFO);
457:                if (guiInfoList != null && guiInfoList.getLength() != 0) {
458:                    Element elem = (Element) guiInfoList.item(0);
459:                    guiInfo = new GUIInfo(elem);
460:                }
461:            }
462:
463:            public SQLObject removeInputByArgName(String argName,
464:                    SQLObject sqlObj) throws BaseException {
465:                // if operator is not of variable argument then call super class's
466:                // removeInputByArgName method
467:                if (!hasVariableArgs) {
468:                    return super .removeInputByArgName(argName, sqlObj);
469:                }
470:
471:                // we need to handle deletion of variable argument operator seperately here
472:                Iterator it = inputMap.keySet().iterator();
473:                while (it.hasNext()) {
474:                    String name = (String) it.next();
475:                    SQLInputObject inputObject = (SQLInputObject) inputMap
476:                            .get(name);
477:                    if (inputObject != null) {
478:                        SQLObject sqlObject = inputObject.getSQLObject();
479:                        if (sqlObject != null && sqlObject.equals(sqlObj)) {
480:                            // (Bug #6795) For variable arguments, don't dissociate the
481:                            // source object...rather, delete the SQLInputObject itself.
482:                            SQLInputObject obj = (SQLInputObject) inputMap
483:                                    .remove(name);
484:                            if (obj != null) {
485:                                obj.setSQLObject(null);
486:                            }
487:                            return sqlObject;
488:                        }
489:                    }
490:                }
491:                return null;
492:            }
493:
494:            /**
495:             * Second call parse
496:             * 
497:             * @param element to be parsed
498:             * @exception BaseException thrown while parsing
499:             */
500:            public void secondPassParse(Element element) throws BaseException {
501:                TagParserUtility.parseInputTag(this , element);
502:            }
503:
504:            public void setArgument(String argName, Object val)
505:                    throws BaseException {
506:                if (val instanceof  String) {
507:                    String strVal = (String) val;
508:                    int argJdbc = this .operatorDefinition
509:                            .getArgJdbcSQLType(argName);
510:                    SQLLiteral literal = new SQLLiteralImpl(strVal, strVal,
511:                            argJdbc);
512:                    this .addInput(argName, literal);
513:                } else if (val instanceof  SQLObject) {
514:                    this .addInput(argName, (SQLObject) val);
515:                } else {
516:                    throw new BaseException("Can not set argument, object "
517:                            + val + "is not a valid SQLObject");
518:                }
519:            }
520:
521:            public void setArguments(List opArgs) throws BaseException {
522:                if (operatorDefinition == null) {
523:                    throw new BaseException("Operator Definition is null.");
524:                }
525:
526:                int argCount = operatorDefinition.getArgCount();
527:
528:                if (opArgs != null) {
529:                    if (!this .hasVariableArgs && opArgs.size() != argCount) {
530:                        throw new BaseException("expected " + argCount
531:                                + " argument for operator "
532:                                + this .getDisplayName() + ", but found "
533:                                + opArgs + " arguments.");
534:                    }
535:
536:                    // now add inputs from the argument list
537:                    Iterator it = opArgs.iterator();
538:                    int argIdx = 0;
539:                    while (it.hasNext()) {
540:                        SQLObject argValue = (SQLObject) it.next();
541:
542:                        SQLOperatorArg operatorArg = operatorDefinition
543:                                .getOperatorArg(argIdx);
544:                        String argName = operatorArg.getArgName();
545:                        setArgument(argName, argValue);
546:
547:                        if (!hasVariableArgs) {
548:                            argIdx++;
549:                        }
550:                    }
551:                }
552:            }
553:
554:            public void setCustomOperator(boolean userFx) {
555:                throw new UnsupportedOperationException("Not a User function");
556:            }
557:
558:            public void setCustomOperatorName(String userFxName) {
559:                throw new UnsupportedOperationException("Not a User function");
560:            }
561:
562:            public void setDbSpecificOperator(String dbSpName)
563:                    throws BaseException {
564:                // first try all lower case
565:                String cdbSpName = dbSpName.toLowerCase();
566:                operatorDefinition = SQLOperatorFactory.getDefault()
567:                        .getDbSpecficOperatorDefinition(dbSpName);
568:                if (operatorDefinition == null) {
569:                    // now try upper case
570:                    cdbSpName = dbSpName.toUpperCase();
571:                    operatorDefinition = SQLOperatorFactory.getDefault()
572:                            .getDbSpecficOperatorDefinition(cdbSpName);
573:                    // if it is still null then throw exception
574:                    if (operatorDefinition == null) {
575:                        throw new BaseException(dbSpName
576:                                + " is not a recognized operator.");
577:                    }
578:                }
579:
580:                // set IOperatorXmlInfo
581:                IOperatorXmlInfo operatorXml = OperatorUtil
582:                        .findOperatorXmlInfo(operatorDefinition
583:                                .getOperatorName());
584:                if (operatorXml != null) {
585:                    this .setOperatorXmlInfo(operatorXml);
586:                } else {
587:                    throw new BaseException(
588:                            "Cannot locate definition for operator "
589:                                    + operatorDefinition.getOperatorName());
590:                }
591:            }
592:
593:            /**
594:             * sets canonical operator type, e.g., "concat", "tolowercase", etc..
595:             * 
596:             * @param opName canonical operator name
597:             */
598:            public void setOperatorType(String opName) throws BaseException {
599:                // set IOperatorXmlInfo
600:                IOperatorXmlInfo operatorXml = OperatorUtil
601:                        .findOperatorXmlInfo(opName);
602:                if (operatorXml != null) {
603:                    this .setOperatorXmlInfo(operatorXml);
604:                } else {
605:                    throw new BaseException(
606:                            "Cannot locate definition for operator " + opName);
607:                }
608:            }
609:
610:            /**
611:             * Sets canonical operator type, obtaining configuration information from the operator
612:             * factory based on the given String param.
613:             * 
614:             * @param opInfo 
615:             * @throws com.sun.sql.framework.exception.BaseException 
616:             */
617:            public void setOperatorXmlInfo(IOperatorXmlInfo opInfo)
618:                    throws BaseException {
619:                this .operatorXmlInfo = opInfo;
620:                String aType = opInfo.getName();
621:                setAttribute(SQLOperator.ATTR_SCRIPTREF, aType);
622:                operatorDefinition = SQLOperatorFactory.getDefault()
623:                        .getSQLOperatorDefinition(aType);
624:                if (operatorDefinition == null) {
625:                    throw new BaseException(aType
626:                            + " is not a recognized operator.");
627:                }
628:                int argCount = operatorDefinition.getArgCount();
629:                this .hasVariableArgs = (operatorDefinition.getArgCountType() == SQLConstants.OPERATOR_ARGS_VARIABLE);
630:
631:                if (!hasVariableArgs) {
632:                    init(argCount);
633:                }
634:            }
635:
636:            /**
637:             * set to true if parenthesis needs to be appended
638:             * 
639:             * @param show bool
640:             */
641:            public void setShowParenthesis(boolean show) {
642:                setAttribute(ATTR_PARENTHESIS, new Boolean(show));
643:            }
644:
645:            public String toString() {
646:                try {
647:                    return GeneratorUtil.getInstance().getEvaluatedString(this );
648:                } catch (BaseException ignore) {
649:                    return "Unknown";
650:                }
651:            }
652:
653:            /**
654:             * Overrides parent implementation to append GUIInfo information.
655:             * 
656:             * @param prefix String to append to each new line of the XML representation
657:             * @return XML representation of this SQLObject instance
658:             */
659:            public String toXMLString(String prefix) {
660:                StringBuilder buffer = new StringBuilder(500);
661:                if (prefix == null) {
662:                    prefix = "";
663:                }
664:
665:                buffer.append(prefix).append(getHeader());
666:                buffer.append(toXMLAttributeTags(prefix));
667:                buffer.append(TagParserUtility.toXMLInputTag(prefix + "\t",
668:                        this .inputMap));
669:                buffer.append(this .guiInfo.toXMLString(prefix + "\t"));
670:                buffer.append(prefix).append(getFooter());
671:
672:                return buffer.toString();
673:            }
674:
675:            public void visit(SQLVisitor visitor) {
676:                visitor.visit(this );
677:            }
678:
679:            protected void copyFrom(SQLGenericOperator op) throws BaseException {
680:                this .hasVariableArgs = op.hasVariableArgs();
681:                this .operatorDefinition = op.getOperatorDefinition();
682:                this .setOperatorXmlInfo(op.getOperatorXmlInfo());
683:                // then call super.copyFromSource so that inputs are copied
684:                super .copyFromSource(op);
685:
686:                GUIInfo gInfo = op.getGUIInfo();
687:                this .guiInfo = gInfo != null ? (GUIInfo) gInfo.clone() : null;
688:            }
689:
690:            private boolean checkRange(String argName, SQLObject obj) {
691:                SQLLiteral lit = (SQLLiteral) obj;
692:                String range = operatorDefinition.getRange(argName);
693:
694:                if (!StringUtil.isNullString(range)) {
695:                    if (range.equals("unsigned")
696:                            && obj.getJdbcType() == java.sql.Types.INTEGER) {
697:                        String val = lit.getValue();
698:                        try {
699:                            int intVal = Integer.parseInt(val);
700:                            return (intVal >= 0);
701:                        } catch (NumberFormatException ne) {
702:                            return false;
703:                        }
704:                    }
705:                    return false;
706:                }
707:                return true;
708:            }
709:
710:            private String generateVarOperatorArgName(String argName) {
711:                int cnt = 0;
712:                String aName = argName + "_" + cnt;
713:                while (isVarOperatorArgNameExist(aName)) {
714:                    cnt++;
715:                    aName = argName + "_" + cnt;
716:                }
717:
718:                return aName;
719:            }
720:
721:            private void init(int argCount) {
722:                for (int i = 0; i < argCount; i++) {
723:                    SQLOperatorArg operatorArg = operatorDefinition
724:                            .getOperatorArg(i);
725:                    String argName = operatorArg.getArgName();
726:                    IOperatorField field = null;
727:                    if (operatorXmlInfo != null) {
728:                        field = operatorXmlInfo.getInputField(argName);
729:                    }
730:
731:                    SQLInputObject inputObject = new SQLInputObjectImpl(
732:                            argName, (field != null ? field.getDisplayName()
733:                                    : argName), null);
734:                    this .inputMap.put(argName, inputObject);
735:                }
736:            }
737:
738:            private boolean isVarOperatorArgNameExist(String argName) {
739:                Iterator it = inputMap.keySet().iterator();
740:                while (it.hasNext()) {
741:                    String aName = (String) it.next();
742:                    if (aName.equals(argName)) {
743:                        return true;
744:                    }
745:                }
746:
747:                return false;
748:            }
749:        }
www.__j__a__v___a2___s.__co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.