Source Code Cross Referenced for Iterator.java in  » IDE-Netbeans » xml » org » netbeans » modules » xslt » project » wizard » element » 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 » xml » org.netbeans.modules.xslt.project.wizard.element 
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.xslt.project.wizard.element;
042:
043:        import java.io.File;
044:        import java.io.IOException;
045:        import java.util.ArrayList;
046:        import java.util.Collection;
047:        import java.util.Collections;
048:        import java.util.HashMap;
049:        import java.util.List;
050:        import java.util.Map;
051:        import java.util.Set;
052:        import java.util.StringTokenizer;
053:        import javax.swing.event.ChangeListener;
054:
055:        import org.openide.WizardDescriptor;
056:        import org.openide.filesystems.FileObject;
057:        import org.openide.loaders.DataObject;
058:        import org.openide.loaders.TemplateWizard;
059:        import org.openide.cookies.SaveCookie;
060:
061:        import org.netbeans.api.project.Project;
062:        import org.netbeans.modules.xml.wsdl.model.Message;
063:        import org.netbeans.spi.project.ui.templates.support.Templates;
064:        import org.netbeans.modules.xml.wsdl.model.Operation;
065:        import org.netbeans.modules.xml.wsdl.model.OperationParameter;
066:        import org.netbeans.modules.xml.wsdl.model.Part;
067:        import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType;
068:        import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role;
069:        import org.netbeans.modules.xml.xam.Reference;
070:        import org.netbeans.modules.xslt.tmap.model.api.Invoke;
071:        import org.netbeans.modules.xslt.tmap.model.api.Service;
072:        import org.netbeans.modules.xslt.tmap.model.api.TMapComponentFactory;
073:        import org.netbeans.modules.xslt.tmap.model.api.TMapModel;
074:        import org.netbeans.modules.xslt.tmap.model.api.Transform;
075:        import org.netbeans.modules.xslt.tmap.model.api.TransformMap;
076:        import org.netbeans.modules.xslt.tmap.model.api.Variable;
077:        import org.netbeans.modules.xslt.tmap.model.api.VariableDeclarator;
078:        import org.netbeans.modules.xslt.tmap.model.api.WSDLReference;
079:        import org.netbeans.modules.xslt.tmap.model.impl.VariableReferenceImpl;
080:        import org.netbeans.modules.xml.catalogsupport.util.ProjectUtilities;
081:        import org.netbeans.modules.soa.ui.SoaUiUtil;
082:        import static org.netbeans.modules.soa.ui.util.UI.*;
083:
084:        /**
085:         * @author Vladimir Yaroslavskiy
086:         * @version 2006.12.25
087:         */
088:        public final class Iterator implements  TemplateWizard.Iterator {
089:
090:            private static final long serialVersionUID = 1L;
091:
092:            public static Iterator createXsl() {
093:                return new Iterator();
094:            }
095:
096:            public Set<DataObject> instantiate(TemplateWizard wizard)
097:                    throws IOException {
098:                return Collections.singleton(createFile(wizard));
099:            }
100:
101:            public void initialize(TemplateWizard wizard) {
102:                myPanel = new PanelStartup<WizardDescriptor>(Templates
103:                        .getProject(wizard), null);
104:            }
105:
106:            public void uninitialize(TemplateWizard wizard) {
107:                myPanel = null;
108:            }
109:
110:            public String name() {
111:                return i18n(Iterator.class, "LBL_Title"); // NOI18N
112:            }
113:
114:            public boolean hasNext() {
115:                return myPanel.getNext() != null;
116:            }
117:
118:            public boolean hasPrevious() {
119:                return myPanel.getPrevious() != null;
120:            }
121:
122:            public void nextPanel() {
123:                myPanel = myPanel.getNext();
124:            }
125:
126:            public void previousPanel() {
127:                myPanel = myPanel.getPrevious();
128:            }
129:
130:            public WizardDescriptor.Panel<WizardDescriptor> current() {
131:                return myPanel;
132:            }
133:
134:            public void addChangeListener(ChangeListener listener) {
135:            }
136:
137:            public void removeChangeListener(ChangeListener listener) {
138:            }
139:
140:            private DataObject createFile(TemplateWizard wizard)
141:                    throws IOException {
142:                FileObject file = null;
143:                Project project = Templates.getProject(wizard);
144:                String choice = (String) wizard.getProperty(Panel.CHOICE);
145:
146:                TransformationUseCasesFactory tUseCaseFactory = TransformationUseCasesFactory
147:                        .getInstance();
148:                file = tUseCaseFactory.createUseCase(project, wizard);
149:
150:                return file == null ? null : DataObject.find(file);
151:            }
152:
153:            private static TransformationUseCase getUseCase(
154:                    TemplateWizard wizard) {
155:                String choice = wizard == null ? null : (String) wizard
156:                        .getProperty(Panel.CHOICE);
157:                return choice == null ? null : TRANSFORMATION_USE_CASE
158:                        .get(choice);
159:            }
160:
161:            private enum TransformationUseCase {
162:                REQUEST_REPLY, FILTER_ONE_WAY, FILTER_REQUEST_REPLY;
163:            }
164:
165:            private static class TransformationUseCasesFactory {
166:
167:                private static TransformationUseCasesFactory INSTANCE = new TransformationUseCasesFactory();
168:
169:                private TransformationUseCasesFactory() {
170:                }
171:
172:                public static TransformationUseCasesFactory getInstance() {
173:                    return INSTANCE;
174:                }
175:
176:                public FileObject createUseCase(Project project,
177:                        TemplateWizard wizard) throws IOException {
178:                    assert project != null && wizard != null;
179:
180:                    List<FileObject> createdFos = new ArrayList<FileObject>();
181:                    TransformationUseCase useCase = getUseCase(wizard);
182:                    assert useCase != null;
183:
184:                    FileObject fo = createXslFiles(useCase, project, wizard,
185:                            createdFos);
186:
187:                    if (fo != null) {
188:                        try {
189:                            configureTMapModel(useCase, project, wizard);
190:                        } catch (IOException ex) {
191:                            rollbackCreatedXslFiles(createdFos);
192:                            fo = null;
193:                            throw ex;
194:                        }
195:                    }
196:                    return fo;
197:                }
198:
199:                private void rollbackCreatedXslFiles(List<FileObject> createdFos)
200:                        throws IOException {
201:                    assert createdFos != null;
202:                    for (FileObject fo : createdFos) {
203:                        if (fo != null && fo.isValid()) {
204:                            fo.delete();
205:                        }
206:                    }
207:                }
208:
209:                private FileObject createXslFiles(
210:                        TransformationUseCase useCase, Project project,
211:                        TemplateWizard wizard, List<FileObject> createdFos)
212:                        throws IOException {
213:                    assert project != null && useCase != null && wizard != null;
214:
215:                    String file1 = (String) wizard
216:                            .getProperty(Panel.INPUT_FILE);
217:                    String file2 = TransformationUseCase.FILTER_REQUEST_REPLY
218:                            .equals(useCase) ? (String) wizard
219:                            .getProperty(Panel.OUTPUT_FILE) : null;
220:
221:                    FileObject file = null;
222:                    if (file1 != null) {
223:                        file = createXslFile(project, file1, createdFos);
224:                    }
225:
226:                    if (file2 != null) {
227:                        file = createXslFile(project, file2, createdFos);
228:                    }
229:                    return file;
230:                }
231:
232:                private FileObject createXslFile(Project project, String file,
233:                        List<FileObject> createdFos) throws IOException {
234:                    if (file == null || "".equals(file)) {
235:                        return null;
236:                    }
237:
238:                    int extIndex = file.lastIndexOf(XSL) - 1;
239:                    if (extIndex <= 0) {
240:                        return null;
241:                    }
242:
243:                    file = file.substring(0, extIndex);
244:
245:                    if ("".equals(file)) {
246:                        return null;
247:                    }
248:
249:                    boolean isAllowSlash = false;
250:                    boolean isAllowBackslash = false;
251:                    if (File.separatorChar == '\\') {
252:                        isAllowBackslash = true;
253:                        file = file.replace('/', File.separatorChar);
254:                    } else {
255:                        isAllowSlash = true;
256:                    }
257:                    StringTokenizer dirTokens = new StringTokenizer(file,
258:                            File.separator);
259:                    int numDirs = dirTokens.countTokens();
260:                    String[] dirs = new String[numDirs];
261:                    int i = 0;
262:                    while (dirTokens.hasMoreTokens()) {
263:                        dirs[i] = dirTokens.nextToken();
264:                        i++;
265:                    }
266:
267:                    FileObject dirFo = ProjectUtilities.getSrcFolder(project);
268:                    boolean isCreatedDir = false;
269:                    if (numDirs > 1) {
270:                        file = dirs[numDirs - 1];
271:                        for (int j = 0; j < numDirs - 1; j++) {
272:                            FileObject tmpDirFo = dirFo.getFileObject(dirs[j]);
273:                            if (tmpDirFo == null) {
274:                                try {
275:                                    dirFo = dirFo.createFolder(dirs[j]);
276:                                } catch (IOException ex) {
277:                                    rollbackCreatedXslFiles(createdFos);
278:                                    throw ex;
279:                                }
280:
281:                                if (dirFo == null) {
282:                                    rollbackCreatedXslFiles(createdFos);
283:                                    break;
284:                                }
285:                                // add just parentFo 
286:                                if (!isCreatedDir) {
287:                                    isCreatedDir = true;
288:                                    createdFos.add(dirFo);
289:                                }
290:                            } else {
291:                                dirFo = tmpDirFo;
292:                            }
293:                        }
294:                    }
295:                    FileObject xslFo = null;
296:
297:                    if (dirFo != null) {
298:                        xslFo = dirFo.getFileObject(file);
299:                        if (xslFo == null) {
300:                            xslFo = PanelUtil.copyFile(dirFo, TEMPLATES_PATH,
301:                                    XSLT_SERVICE, file, XSL);
302:                            if (!isCreatedDir) {
303:                                createdFos.add(xslFo);
304:                            }
305:                            SoaUiUtil
306:                                    .fixEncoding(DataObject.find(xslFo), dirFo);
307:                        }
308:                    }
309:                    return xslFo;
310:                }
311:
312:                private void configureTMapModel(TransformationUseCase useCase,
313:                        Project project, TemplateWizard wizard)
314:                        throws IOException {
315:                    assert useCase != null && project != null && wizard != null;
316:
317:                    FileObject tMapFo = getTMapFo(project);
318:                    TMapModel tMapModel = tMapFo == null ? null
319:                            : org.netbeans.modules.xslt.tmap.util.Util
320:                                    .getTMapModel(tMapFo);
321:
322:                    if (tMapModel == null
323:                            || !TMapModel.State.VALID.equals(tMapModel
324:                                    .getState())) {
325:                        throw new IllegalStateException(""
326:                                + tMapModel.getState());
327:                    }
328:
329:                    switch (useCase) {
330:                    case REQUEST_REPLY:
331:                        configureRequestReply(tMapModel, wizard);
332:                        break;
333:                    case FILTER_ONE_WAY:
334:                        configureFilterOneWay(tMapModel, wizard);
335:                        break;
336:                    case FILTER_REQUEST_REPLY:
337:                        configureFilterRequestReply(tMapModel, wizard);
338:                        break;
339:                    }
340:
341:                    saveConfiguredModel(tMapFo);
342:                }
343:
344:                private void saveConfiguredModel(FileObject tMapFo)
345:                        throws IOException {
346:                    if (tMapFo == null) {
347:                        return;
348:                    }
349:
350:                    DataObject dObj = DataObject.find(tMapFo);
351:                    if (dObj != null && dObj.isModified()) {
352:
353:                        SaveCookie saveCookie = dObj.getLookup().lookup(
354:                                SaveCookie.class);
355:                        assert saveCookie != null;
356:                        saveCookie.save();
357:                    }
358:                }
359:
360:                private FileObject getTMapFo(Project project) {
361:                    FileObject tMapFo = org.netbeans.modules.xslt.tmap.util.Util
362:                            .getTMapFo(project);
363:                    if (tMapFo == null) {
364:                        tMapFo = org.netbeans.modules.xslt.tmap.util.Util
365:                                .createDefaultTransformmap(project);
366:                    }
367:                    return tMapFo;
368:                }
369:
370:                public void configureRequestReply(TMapModel tMapModel,
371:                        TemplateWizard wizard) {
372:                    assert tMapModel != null && wizard != null;
373:                    try {
374:                        tMapModel.startTransaction();
375:                        TMapComponentFactory componentFactory = tMapModel
376:                                .getFactory();
377:
378:                        org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp = setOperation(
379:                                tMapModel, wizard, componentFactory);
380:
381:                        Transform rrTransform = null;
382:                        if (tMapOp != null) {
383:                            rrTransform = createTransform(componentFactory,
384:                                    (String) wizard
385:                                            .getProperty(Panel.INPUT_FILE),
386:                                    tMapOp);
387:                        }
388:
389:                        if (rrTransform != null) {
390:                            tMapOp.addTransform(rrTransform);
391:                        }
392:                    } finally {
393:                        tMapModel.endTransaction();
394:                    }
395:                }
396:
397:                public void configureFilterOneWay(TMapModel tMapModel,
398:                        TemplateWizard wizard) {
399:                    assert tMapModel != null && wizard != null;
400:                    try {
401:                        tMapModel.startTransaction();
402:                        TMapComponentFactory componentFactory = tMapModel
403:                                .getFactory();
404:
405:                        org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp = setOperation(
406:                                tMapModel, wizard, componentFactory);
407:
408:                        Transform foTransform = null;
409:                        if (tMapOp != null) {
410:                            foTransform = createTransform(componentFactory,
411:                                    (String) wizard
412:                                            .getProperty(Panel.INPUT_FILE),
413:                                    tMapOp);
414:                        }
415:
416:                        Invoke invoke = null;
417:                        if (tMapOp != null) {
418:                            invoke = createInvoke(tMapOp, wizard,
419:                                    componentFactory);
420:                        }
421:
422:                        if (foTransform != null) {
423:                            tMapOp.addTransform(foTransform);
424:                        }
425:                        if (invoke != null) {
426:                            tMapOp.addInvoke(invoke);
427:                        }
428:
429:                        if (tMapOp != null) {
430:                            List<Transform> children = tMapOp.getTransforms();
431:                            if (children != null) {
432:                                for (Transform child : children) {
433:                                    if (child.equals(foTransform)) {
434:                                        foTransform = child;
435:                                        break;
436:                                    }
437:                                }
438:                            }
439:
440:                            List<Invoke> invokes = tMapOp.getInvokes();
441:                            invoke = invokes == null || invokes.size() < 1 ? invoke
442:                                    : invokes.get(invokes.size() - 1);
443:
444:                        }
445:
446:                        if (foTransform != null) {
447:                            String result = getTMapVarRef(invoke
448:                                    .getInputVariable());
449:                            if (result != null) {
450:                                foTransform.setResult(result);
451:                            }
452:                        }
453:
454:                    } finally {
455:                        tMapModel.endTransaction();
456:                    }
457:                }
458:
459:                public void configureFilterRequestReply(TMapModel tMapModel,
460:                        TemplateWizard wizard) {
461:                    assert tMapModel != null && wizard != null;
462:                    try {
463:                        tMapModel.startTransaction();
464:                        TMapComponentFactory componentFactory = tMapModel
465:                                .getFactory();
466:
467:                        org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp = setOperation(
468:                                tMapModel, wizard, componentFactory);
469:
470:                        if (tMapOp == null) {
471:                            return;
472:                        }
473:                        Invoke invoke = null;
474:                        String inputInvokeVar = getVariableName(
475:                                INPUT_INVOKE_VARIABLE_PREFIX,
476:                                getVariableNumber(tMapOp,
477:                                        INPUT_INVOKE_VARIABLE_PREFIX, 1));
478:                        String outputInvokeVar = getVariableName(
479:                                OUTPUT_INVOKE_VARIABLE_PREFIX,
480:                                getVariableNumber(tMapOp,
481:                                        OUTPUT_INVOKE_VARIABLE_PREFIX, 1));
482:
483:                        Transform inTransform = null;
484:                        inTransform = createTransform(componentFactory,
485:                                (String) wizard.getProperty(Panel.INPUT_FILE),
486:                                tMapOp);
487:
488:                        invoke = createInvoke(tMapOp, inputInvokeVar,
489:                                outputInvokeVar, wizard, componentFactory);
490:
491:                        Transform outTransform = null;
492:                        outTransform = createTransform(componentFactory,
493:                                (String) wizard.getProperty(Panel.OUTPUT_FILE),
494:                                tMapOp);
495:
496:                        if (inTransform != null) {
497:                            tMapOp.addTransform(inTransform);
498:                        }
499:                        if (invoke != null) {
500:                            tMapOp.addInvoke(invoke);
501:                        }
502:                        if (outTransform != null) {
503:                            tMapOp.addTransform(outTransform);
504:                            String source = getTMapVarRef(invoke
505:                                    .getOutputVariable());
506:                            if (source != null) {
507:                                outTransform.setSource(source);
508:                            }
509:                        }
510:
511:                        if (inTransform != null) {
512:                            String result = getTMapVarRef(invoke
513:                                    .getInputVariable());
514:                            if (result != null) {
515:                                inTransform.setResult(result);
516:                            }
517:                        }
518:
519:                    } finally {
520:                        tMapModel.endTransaction();
521:                    }
522:                }
523:
524:                private int getVariableNumber(
525:                        org.netbeans.modules.xslt.tmap.model.api.Operation operation,
526:                        String varNamePrefix, int startNumber) {
527:                    if (operation == null || varNamePrefix == null) {
528:                        return startNumber;
529:                    }
530:
531:                    List<Variable> vars = operation.getVariables();
532:                    if (vars == null || vars.size() < 1) {
533:                    }
534:
535:                    int count = startNumber;
536:                    List<String> varNames = new ArrayList<String>();
537:
538:                    for (Variable var : vars) {
539:                        String tmpVarName = var == null ? null : var.getName();
540:                        if (tmpVarName != null) {
541:                            varNames.add(tmpVarName);
542:                        }
543:                    }
544:
545:                    while (true) {
546:                        if (!varNames.contains(varNamePrefix + count)) {
547:                            break;
548:                        }
549:                        count++;
550:                    }
551:                    return count;
552:                }
553:
554:                private String getVariableName(String varPrefix, int varNumber) {
555:                    varPrefix = varPrefix == null ? DEFAULT_VARIABLE_PREFIX
556:                            : varPrefix;
557:                    return varPrefix + varNumber;
558:                }
559:
560:                private Service getTMapService(TMapModel model,
561:                        PartnerLinkType wizardInPlt, Role wizardInRole) {
562:                    if (model == null || wizardInPlt == null
563:                            || wizardInRole == null) {
564:                        return null;
565:                    }
566:
567:                    Service service = null;
568:                    TransformMap root = model.getTransformMap();
569:                    if (root == null) {
570:                        return service;
571:                    }
572:
573:                    List<Service> services = root.getServices();
574:                    if (services == null || services.size() < 1) {
575:                        return service;
576:                    }
577:
578:                    for (Service serviceElem : services) {
579:                        WSDLReference<PartnerLinkType> pltRef = serviceElem
580:                                .getPartnerLinkType();
581:                        WSDLReference<Role> roleRef = serviceElem.getRole();
582:
583:                        if (roleRef != null && pltRef != null
584:                                && wizardInPlt.equals(pltRef.get())
585:                                && wizardInRole.equals(roleRef.get())) {
586:                            service = serviceElem;
587:                            break;
588:                        }
589:                    }
590:                    return service;
591:                }
592:
593:                private org.netbeans.modules.xslt.tmap.model.api.Operation getTMapOperation(
594:                        Service tMapService, Operation wizardInputOperation) {
595:                    org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp = null;
596:
597:                    if (tMapService == null) {
598:                        return tMapOp;
599:                    }
600:
601:                    List<org.netbeans.modules.xslt.tmap.model.api.Operation> operations = tMapService
602:                            .getOperations();
603:                    if (operations == null || operations.size() < 1) {
604:                        return tMapOp;
605:                    }
606:
607:                    for (org.netbeans.modules.xslt.tmap.model.api.Operation operationElem : operations) {
608:                        Reference<Operation> opRef = operationElem
609:                                .getOperation();
610:
611:                        if (opRef != null
612:                                && wizardInputOperation.equals(opRef.get())) {
613:                            tMapOp = operationElem;
614:                            break;
615:                        }
616:                    }
617:                    return tMapOp;
618:                }
619:
620:                private org.netbeans.modules.xslt.tmap.model.api.Operation getTMapOperation(
621:                        TMapModel model, PartnerLinkType wizardInPlt,
622:                        Role wizardInRole, Operation wizardInputOperation) {
623:                    return getTMapOperation(getTMapService(model, wizardInPlt,
624:                            wizardInRole), wizardInputOperation);
625:                }
626:
627:                private org.netbeans.modules.xslt.tmap.model.api.Operation setOperation(
628:                        TMapModel tMapModel, TemplateWizard wizard,
629:                        TMapComponentFactory componentFactory) {
630:                    assert tMapModel != null && wizard != null
631:                            && componentFactory != null;
632:
633:                    String inputFileStr = (String) wizard
634:                            .getProperty(Panel.INPUT_FILE);
635:                    Operation wizardInputOperation = (Operation) wizard
636:                            .getProperty(Panel.INPUT_OPERATION);
637:                    Panel.PartnerRolePort wizardInputPartnerRolePort = (Panel.PartnerRolePort) wizard
638:                            .getProperty(Panel.INPUT_PARTNER_ROLE_PORT);
639:
640:                    PartnerLinkType wizardInPlt = wizardInputPartnerRolePort == null ? null
641:                            : wizardInputPartnerRolePort.getPartnerLinkType();
642:                    Role wizardInRole = wizardInputPartnerRolePort == null ? null
643:                            : wizardInputPartnerRolePort.getRole();
644:
645:                    if (wizardInPlt == null || wizardInRole == null
646:                            || wizardInputOperation == null) {
647:                        return null;
648:                    }
649:
650:                    Service tMapService = getTMapService(tMapModel,
651:                            wizardInPlt, wizardInRole);
652:                    if (tMapService == null) {
653:                        tMapService = createTMapService(componentFactory,
654:                                tMapModel, wizardInPlt, wizardInRole);
655:                    }
656:                    if (tMapService == null) {
657:                        return null;
658:                    }
659:                    org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp = null;
660:                    tMapOp = getTMapOperation(tMapService, wizardInputOperation);
661:
662:                    if (tMapOp == null) {
663:                        tMapOp = componentFactory.createOperation();
664:                        tMapOp.setOperation(tMapOp.createWSDLReference(
665:                                wizardInputOperation, Operation.class));
666:
667:                        tMapService.addOperation(tMapOp);
668:                        tMapOp.setInputVariableName(getVariableName(
669:                                INPUT_OPERATION_VARIABLE_PREFIX, 1));
670:
671:                        tMapOp.setOutputVariableName(getVariableName(
672:                                OUTPUT_OPERATION_VARIABLE_PREFIX, 1));
673:                    }
674:                    return tMapOp;
675:                }
676:
677:                private Service createTMapService(
678:                        TMapComponentFactory componentFactory,
679:                        TMapModel tMapModel, PartnerLinkType wizardInPlt,
680:                        Role wizardInRole) {
681:                    assert componentFactory != null && tMapModel != null
682:                            && wizardInPlt != null && wizardInRole != null;
683:                    Service tMapService = null;
684:
685:                    TransformMap root = tMapModel.getTransformMap();
686:
687:                    if (root == null) {
688:                        root = componentFactory.createTransformMap();
689:                        tMapModel.addChildComponent(null, root, -1);
690:                    }
691:                    if (root == null) {
692:                        return null;
693:                    }
694:                    tMapService = componentFactory.createService();
695:                    tMapService.setPartnerLinkType(tMapService
696:                            .createWSDLReference(wizardInPlt,
697:                                    PartnerLinkType.class));
698:                    tMapService.setRole(tMapService.createWSDLReference(
699:                            wizardInRole, Role.class));
700:
701:                    root.addService(tMapService);
702:
703:                    return tMapService;
704:                }
705:
706:                private Transform createTransform(
707:                        TMapComponentFactory componentFactory,
708:                        String inputFileStr, Variable source, Variable result) {
709:                    if (source == null || result == null) {
710:                        return null;
711:                    }
712:
713:                    Transform transform = componentFactory.createTransform();
714:                    if (inputFileStr != null && !"".equals(inputFileStr)) {
715:                        transform.setFile(inputFileStr);
716:                    }
717:                    String sourcePartName = getFirstPartName(source);
718:                    transform.setSource(getTMapVarRef(source, sourcePartName));
719:
720:                    String resultPartName = getFirstPartName(result);
721:                    transform.setResult(getTMapVarRef(result, resultPartName));
722:                    return transform;
723:                }
724:
725:                private Transform createTransform(
726:                        TMapComponentFactory componentFactory,
727:                        String inputFileStr, VariableDeclarator variableHolder) {
728:                    if (variableHolder == null) {
729:                        return null;
730:                    }
731:                    return createTransform(componentFactory, inputFileStr,
732:                            variableHolder.getInputVariable(), variableHolder
733:                                    .getOutputVariable());
734:                }
735:
736:                private String getTMapVarRef(Variable var) {
737:                    String firstPartName = var == null ? null
738:                            : getFirstPartName(var);
739:                    return getTMapVarRef(var, firstPartName);
740:                }
741:
742:                private String getTMapVarRef(Variable var, String partName) {
743:                    if (partName == null || var == null) {
744:                        return null;
745:                    }
746:                    String varName = var.getName();
747:
748:                    return varName == null ? null : VariableReferenceImpl
749:                            .getVarRefString(varName, partName);
750:                }
751:
752:                private String getFirstPartName(Reference<Message> messageRef) {
753:                    String partName = null;
754:                    if (messageRef == null) {
755:                        return partName;
756:                    }
757:
758:                    Message message = messageRef.get();
759:
760:                    Collection<Part> parts = null;
761:                    if (message != null) {
762:                        parts = message.getParts();
763:                    }
764:
765:                    Part part = null;
766:                    if (parts != null && parts.size() > 0) {
767:                        java.util.Iterator<Part> partIter = parts.iterator();
768:                        part = partIter.next();
769:                    }
770:
771:                    if (part != null) {
772:                        partName = part.getName();
773:                    }
774:                    return partName;
775:                }
776:
777:                private String getFirstPartName(Variable var) {
778:                    if (var == null) {
779:                        return null;
780:                    }
781:                    return getFirstPartName(var.getMessage());
782:                }
783:
784:                private String getFirstPartName(OperationParameter opParam) {
785:                    if (opParam == null) {
786:                        return null;
787:                    }
788:                    return getFirstPartName(opParam.getMessage());
789:                }
790:
791:                private Invoke createInvoke(
792:                        org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp,
793:                        TemplateWizard wizard,
794:                        TMapComponentFactory componentFactory) {
795:                    return createInvoke(tMapOp, null, null, wizard,
796:                            componentFactory);
797:                }
798:
799:                private Invoke createInvoke(
800:                        org.netbeans.modules.xslt.tmap.model.api.Operation tMapOp,
801:                        String inputInvokeVar, String outputInvokeVar,
802:                        TemplateWizard wizard,
803:                        TMapComponentFactory componentFactory) {
804:                    assert tMapOp != null && wizard != null
805:                            && componentFactory != null;
806:                    Invoke invoke = null;
807:
808:                    Operation wizardOutputOperation = (Operation) wizard
809:                            .getProperty(Panel.OUTPUT_OPERATION);
810:                    Panel.PartnerRolePort wizardOutputPartnerRolePort = (Panel.PartnerRolePort) wizard
811:                            .getProperty(Panel.OUTPUT_PARTNER_ROLE_PORT);
812:
813:                    PartnerLinkType wizardOutPlt = wizardOutputPartnerRolePort == null ? null
814:                            : wizardOutputPartnerRolePort.getPartnerLinkType();
815:                    Role wizardOutRole = wizardOutputPartnerRolePort == null ? null
816:                            : wizardOutputPartnerRolePort.getRole();
817:
818:                    if (wizardOutPlt != null && wizardOutRole != null
819:                            && wizardOutputOperation != null) {
820:                        invoke = componentFactory.createInvoke();
821:                        invoke.setPartnerLinkType(invoke.createWSDLReference(
822:                                wizardOutPlt, PartnerLinkType.class));
823:                        invoke.setRole(invoke.createWSDLReference(
824:                                wizardOutRole, Role.class));
825:                        invoke.setOperation(invoke.createWSDLReference(
826:                                wizardOutputOperation, Operation.class));
827:
828:                        if (inputInvokeVar == null || "".equals(inputInvokeVar)) {
829:                            inputInvokeVar = getVariableName(
830:                                    INPUT_INVOKE_VARIABLE_PREFIX,
831:                                    getVariableNumber(tMapOp,
832:                                            INPUT_INVOKE_VARIABLE_PREFIX, 1));
833:                        }
834:                        if (outputInvokeVar == null
835:                                || "".equals(outputInvokeVar)) {
836:                            outputInvokeVar = getVariableName(
837:                                    OUTPUT_INVOKE_VARIABLE_PREFIX,
838:                                    getVariableNumber(tMapOp,
839:                                            OUTPUT_INVOKE_VARIABLE_PREFIX, 1));
840:                        }
841:                        invoke.setInputVariableName(inputInvokeVar);
842:                        invoke.setOutputVariableName(outputInvokeVar);
843:                    }
844:                    return invoke;
845:                }
846:            }
847:
848:            private static Map<String, TransformationUseCase> TRANSFORMATION_USE_CASE = new HashMap<String, TransformationUseCase>();
849:            static {
850:                TRANSFORMATION_USE_CASE.put(Panel.CHOICE_REQUEST_REPLY,
851:                        TransformationUseCase.REQUEST_REPLY);
852:                TRANSFORMATION_USE_CASE.put(Panel.CHOICE_FILTER_ONE_WAY,
853:                        TransformationUseCase.FILTER_ONE_WAY);
854:                TRANSFORMATION_USE_CASE.put(Panel.CHOICE_FILTER_REQUEST_REPLY,
855:                        TransformationUseCase.FILTER_REQUEST_REPLY);
856:            }
857:
858:            private static String TEMPLATES_PATH = "Templates/SOA_XSLT/"; // NOI18N
859:            private static String XSLT_SERVICE = "xslt.service"; // NOI18N
860:            private static String XSL = "xsl"; // NOI18N
861:            private Panel<WizardDescriptor> myPanel;
862:
863:            private static final String DEFAULT_VARIABLE_PREFIX = "var"; // NOI18N
864:            private static final String INPUT_OPERATION_VARIABLE_PREFIX = "inOpVar"; // NOI18N
865:            private static final String OUTPUT_OPERATION_VARIABLE_PREFIX = "outOpVar"; // NOI18N
866:            private static final String INPUT_INVOKE_VARIABLE_PREFIX = "inInvokeVar"; // NOI18N
867:            private static final String OUTPUT_INVOKE_VARIABLE_PREFIX = "outInvokeVar"; // NOI18N
868:        }
w_ww___.j_a___v_a___2___s_._c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.