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: package org.netbeans.modules.xslt.project.anttasks;
020:
021: import java.io.File;
022: import java.util.Collection;
023: import java.util.List;
024: import java.util.logging.Level;
025: import java.util.logging.Logger;
026: import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent;
027: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
028: import org.netbeans.modules.xslt.tmap.model.spi.ExternalModelRetriever;
029: import org.netbeans.modules.xslt.tmap.model.api.TMapModel;
030: import org.openide.util.Lookup;
031: import org.openide.util.Lookup.Result;
032: import org.netbeans.modules.xslt.project.CommandlineTransformmapCatalogModel;
033: import org.netbeans.modules.xslt.project.CommandlineWSDLModelRetriever;
034:
035: /**
036: *
037: * @author Vitaly Bychkov
038: * @author Sreenivasan Genipudi
039: */
040: public class JBIGenerator extends AbstractJBIGenerator {
041:
042: private Logger logger = Logger.getLogger(JBIGenerator.class
043: .getName());
044: private List<File> myDependentProjectDirs;
045: private List<File> mySourceDirs;
046:
047: // private WSDLModelRetriever myWSDLModelRetriever;
048:
049: public JBIGenerator(List<File> depedentProjectDirs,
050: List<File> sourceDirs, String srcDir, String buildDir) {
051: super (srcDir, buildDir);
052: myDependentProjectDirs = depedentProjectDirs;
053: mySourceDirs = sourceDirs;
054:
055: Result<ExternalModelRetriever> result = Lookup.getDefault()
056: .lookup(
057: new Lookup.Template<ExternalModelRetriever>(
058: ExternalModelRetriever.class));
059:
060: Collection<? extends ExternalModelRetriever> retrievers = null;
061: if (result != null) {
062: retrievers = result.allInstances();
063: }
064:
065: if (retrievers != null) {
066:
067: for (ExternalModelRetriever retriever : retrievers) {
068: if (retriever instanceof CommandlineWSDLModelRetriever) {
069: CommandlineWSDLModelRetriever wsdlModelRetriever = (CommandlineWSDLModelRetriever) retriever;
070: if (!wsdlModelRetriever.isInitialized()) {
071: wsdlModelRetriever.init(depedentProjectDirs,
072: sourceDirs);
073: }
074: break;
075: }
076: }
077: }
078: }
079:
080: public List<File> getDepedentProjectDirs() {
081: return myDependentProjectDirs;
082: }
083:
084: public List<File> getSourceDirs() {
085: return mySourceDirs;
086: }
087:
088: protected TMapModel getTMapModel() {
089: File transformmapFile = getTransformmapFile();
090: if (transformmapFile == null) {
091: logger.log(Level.SEVERE,
092: "Error encountered while processing transformmap file - "
093: + transformmapFile.getAbsolutePath());
094: throw new RuntimeException(
095: "Can't find transformation descriptor");
096: }
097: TMapModel tMapModel = null;
098: try {
099: tMapModel = CommandlineTransformmapCatalogModel
100: .getDefault()
101: .getTMapModel(transformmapFile.toURI());
102: } catch (Exception ex) {
103: this .logger.log(java.util.logging.Level.SEVERE,
104: "Error while creating Tramsformap Model ", ex);
105: throw new RuntimeException(
106: "Error while creating Transformmap Model ", ex);
107: }
108:
109: if (tMapModel == null
110: || !TMapModel.State.VALID.equals(tMapModel.getState())) {
111: this .logger.log(java.util.logging.Level.SEVERE,
112: "Error while creating Transformmap Model - "
113: + (tMapModel == null ? " is null"
114: : " is not valid"));
115: throw new RuntimeException(
116: "Error while creating Transformmap Model ");
117: }
118: return tMapModel;
119: }
120:
121: protected <T extends ReferenceableWSDLComponent> T resolveReference(
122: NamedComponentReference<T> ref) {
123: if (ref == null) {
124: return null;
125: }
126: return ref.get();
127: }
128: }
|