This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 136595
Collapse All | Expand All

(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/EjbJarProject.java (-30 / +2 lines)
Lines 77-83 Link Here
77
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
77
import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
78
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbJarSupport;
78
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbJarSupport;
79
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
79
import org.netbeans.modules.java.api.common.classpath.ClassPathSupport.Item;
80
import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
81
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
80
import org.netbeans.modules.j2ee.deployment.devmodules.spi.ArtifactListener.Artifact;
82
import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSClientSupport;
81
import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSClientSupport;
83
import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSSupport;
82
import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSSupport;
Lines 99-105 Link Here
99
import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarFactory;
98
import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarFactory;
100
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport;
99
import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport;
101
import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
100
import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
102
import org.netbeans.modules.websvc.api.jaxws.project.WSUtils;
103
import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
101
import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
104
import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportFactory;
102
import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportFactory;
105
import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory;
103
import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory;
Lines 174-179 Link Here
174
import org.openide.filesystems.FileStateInvalidException;
172
import org.openide.filesystems.FileStateInvalidException;
175
import org.openide.filesystems.FileSystem.AtomicAction;
173
import org.openide.filesystems.FileSystem.AtomicAction;
176
import org.openide.util.Exceptions;
174
import org.openide.util.Exceptions;
175
import org.openide.xml.XMLUtil;
177
176
178
/**
177
/**
179
 * Represents one ejb module project
178
 * Represents one ejb module project
Lines 626-632 Link Here
626
        if (element != null) {
625
        if (element != null) {
627
            Document doc = element.getOwnerDocument();
626
            Document doc = element.getOwnerDocument();
628
            Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
627
            Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
629
            copyDocument (doc, element, newRoot);
628
            XMLUtil.copyDocument (doc, element, newRoot, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
630
            Element srcRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots");  //NOI18N
629
            Element srcRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots");  //NOI18N
631
            Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
630
            Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root");   //NOI18N
632
            root.setAttribute ("id","src.dir");   //NOI18N
631
            root.setAttribute ("id","src.dir");   //NOI18N
Lines 642-674 Link Here
642
        }
641
        }
643
    }
642
    }
644
643
645
    private static void copyDocument (Document doc, Element from, Element to) {
646
        NodeList nl = from.getChildNodes();
647
        int length = nl.getLength();
648
        for (int i=0; i< length; i++) {
649
            Node node = nl.item (i);
650
            Node newNode = null;
651
            switch (node.getNodeType()) {
652
                case Node.ELEMENT_NODE:
653
                    Element oldElement = (Element) node;
654
                    newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
655
                    copyDocument(doc,oldElement,(Element)newNode);
656
                    break;
657
                case Node.TEXT_NODE:
658
                    Text oldText = (Text) node;
659
                    newNode = doc.createTextNode(oldText.getData());
660
                    break;
661
                case Node.COMMENT_NODE:
662
                    Comment oldComment = (Comment) node;
663
                    newNode = doc.createComment(oldComment.getData());
664
                    break;
665
            }
666
            if (newNode != null) {
667
                to.appendChild (newNode);
668
            }
669
        }
670
    }
671
672
    public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) {
644
    public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) {
673
    }    
645
    }    
674
    
646
    
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/UpdateProjectImpl.java (-53 / +3 lines)
Lines 59-64 Link Here
59
import org.openide.filesystems.FileUtil;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.util.Mutex;
60
import org.openide.util.Mutex;
61
import org.openide.util.NbBundle;
61
import org.openide.util.NbBundle;
62
import org.openide.xml.XMLUtil;
62
import org.w3c.dom.Comment;
63
import org.w3c.dom.Comment;
63
import org.w3c.dom.Document;
64
import org.w3c.dom.Document;
64
import org.w3c.dom.Element;
65
import org.w3c.dom.Element;
Lines 191-197 Link Here
191
            if (oldRoot != null) {
192
            if (oldRoot != null) {
192
                Document doc = oldRoot.getOwnerDocument();
193
                Document doc = oldRoot.getOwnerDocument();
193
                Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
194
                Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
194
                copyDocument (doc, oldRoot, newRoot);
195
                XMLUtil.copyDocument (doc, oldRoot, newRoot, EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE);
195
                if(version == 1) {
196
                if(version == 1) {
196
                    //1=>2 upgrade
197
                    //1=>2 upgrade
197
                    Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
198
                    Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");  //NOI18N
Lines 211-217 Link Here
211
                    for (int i = 0; i < libList.getLength(); i++) {
212
                    for (int i = 0; i < libList.getLength(); i++) {
212
                        if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) {
213
                        if (libList.item(i).getNodeType() == Node.ELEMENT_NODE) {
213
                            Element library = (Element) libList.item(i);
214
                            Element library = (Element) libList.item(i);
214
                            String fileText = findText(library);
215
                            String fileText = XMLUtil.findText(library);
215
                            if (fileText.startsWith ("libs.")) {
216
                            if (fileText.startsWith ("libs.")) {
216
                                String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N
217
                                String libName = fileText.substring(6, fileText.indexOf(".classpath")); //NOI18N
217
                                List/*<URL>*/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N
218
                                List/*<URL>*/ roots = LibraryManager.getDefault().getLibrary(libName).getContent("classpath"); //NOI18N
Lines 253-292 Link Here
253
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
254
        return helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
254
    }
255
    }
255
256
256
    private static void copyDocument (Document doc, Element from, Element to) {
257
        NodeList nl = from.getChildNodes();
258
        int length = nl.getLength();
259
        for (int i=0; i< length; i++) {
260
            Node node = nl.item (i);
261
            Node newNode = null;
262
            switch (node.getNodeType()) {
263
                case Node.ELEMENT_NODE:
264
                    Element oldElement = (Element) node;
265
                    newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
266
                    //copy attributes
267
                    NamedNodeMap m = oldElement.getAttributes();
268
                    Element newElement = (Element) newNode;
269
                    for (int index = 0; index < m.getLength(); index++) {
270
                        Node attr = m.item(index);
271
                        newElement.setAttribute(attr.getNodeName(), attr.getNodeValue());
272
                    }
273
                    copyDocument(doc,oldElement,(Element)newNode);
274
                    break;
275
                case Node.TEXT_NODE:
276
                    Text oldText = (Text) node;
277
                    newNode = doc.createTextNode(oldText.getData());
278
                    break;
279
                case Node.COMMENT_NODE:
280
                    Comment oldComment = (Comment) node;
281
                    newNode = doc.createComment(oldComment.getData());
282
                    break;
283
            }
284
            if (newNode != null) {
285
                to.appendChild (newNode);
286
            }
287
        }
288
    }
289
    
290
    private static Element updateMinAntVersion (final Element root, final Document doc) {
257
    private static Element updateMinAntVersion (final Element root, final Document doc) {
291
        NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
258
        NodeList list = root.getElementsByTagNameNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,MINIMUM_ANT_VERSION_ELEMENT);
292
        if (list.getLength() == 1) {
259
        if (list.getLength() == 1) {
Lines 301-323 Link Here
301
        return root;
268
        return root;
302
    }
269
    }
303
    
270
    
304
    /**
305
     * Extract nested text from a node.
306
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
307
     * @param parent a parent node
308
     * @return the nested text, or null if none was found
309
     */
310
    private static String findText(Node parent) {
311
        NodeList l = parent.getChildNodes();
312
        for (int i = 0; i < l.getLength(); i++) {
313
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
314
                Text text = (Text)l.item(i);
315
                return text.getNodeValue();
316
            }
317
        }
318
        return null;
319
    }
320
    
321
    private boolean showUpdateDialog() {
271
    private boolean showUpdateDialog() {
322
        return DialogDisplayer.getDefault().notify(
272
        return DialogDisplayer.getDefault().notify(
323
            new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate",BUILD_NUMBER),
273
            new NotifyDescriptor.Confirmation (NbBundle.getMessage(UpdateProjectImpl.class,"TXT_ProjectUpdate",BUILD_NUMBER),
(-)a/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/classpath/ClassPathSupportCallbackImpl.java (-76 / +3 lines)
Lines 58-63 Link Here
58
import org.w3c.dom.Text;
58
import org.w3c.dom.Text;
59
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
59
import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
60
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
60
import org.netbeans.modules.java.api.common.util.CommonProjectUtils;
61
import org.openide.xml.XMLUtil;
61
62
62
/**
63
/**
63
 *
64
 *
Lines 95-101 Link Here
95
        for ( int i = 0; i < libs.getLength(); i++ ) {
96
        for ( int i = 0; i < libs.getLength(); i++ ) {
96
            Element item = (Element)libs.item( i );
97
            Element item = (Element)libs.item( i );
97
            // ejbjar is different from other j2ee projects - it stores reference without ${ and }
98
            // ejbjar is different from other j2ee projects - it stores reference without ${ and }
98
            String ref = "${"+findText( item )+"}";
99
            String ref = "${"+XMLUtil.findText( item )+"}";
99
            libraries.add(ref); // NOI18N
100
            libraries.add(ref); // NOI18N
100
            String dirs = item.getAttribute(ATTR_DIRS);
101
            String dirs = item.getAttribute(ATTR_DIRS);
101
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
102
            if (Util.DESTINATION_DIRECTORY_ROOT.equals(dirs) ||
Lines 125-131 Link Here
125
        Document doc = data.getOwnerDocument();
126
        Document doc = data.getOwnerDocument();
126
        for (ClassPathSupport.Item item : classpath) {
127
        for (ClassPathSupport.Item item : classpath) {
127
            if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N
128
            if("true".equals(item.getAdditionalProperty(INCLUDE_IN_DEPLOYMENT))) { // NOI18N
128
                appendChildElement(data, 
129
                XMLUtil.appendChildElement(data,
129
                    createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), 
130
                    createLibraryElement(antProjectHelper, doc, item, includedLibrariesElement), 
130
                    ejbjarElemOrder);
131
                    ejbjarElemOrder);
131
            }
132
            }
Lines 134-195 Link Here
134
        antProjectHelper.putPrimaryConfigurationData( data, true );
135
        antProjectHelper.putPrimaryConfigurationData( data, true );
135
    }
136
    }
136
    
137
    
137
    /**
138
     * Find all direct child elements of an element.
139
     * More useful than {@link Element#getElementsByTagNameNS} because it does
140
     * not recurse into recursive child elements.
141
     * Children which are all-whitespace text nodes are ignored; others cause
142
     * an exception to be thrown.
143
     * @param parent a parent element in a DOM tree
144
     * @return a list of direct child elements (may be empty)
145
     * @throws IllegalArgumentException if there are non-element children besides whitespace
146
     */
147
    private static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
148
        NodeList l = parent.getChildNodes();
149
        List<Element> elements = new ArrayList<Element>(l.getLength());
150
        for (int i = 0; i < l.getLength(); i++) {
151
            Node n = l.item(i);
152
            if (n.getNodeType() == Node.ELEMENT_NODE) {
153
                elements.add((Element)n);
154
            } else if (n.getNodeType() == Node.TEXT_NODE) {
155
                String text = ((Text)n).getNodeValue();
156
                if (text.trim().length() > 0) {
157
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
158
                }
159
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
160
                // skip
161
            } else {
162
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
163
            }
164
        }
165
        return elements;
166
    }
167
    
168
    /**
169
     * Append child element to the correct position according to given
170
     * order.
171
     * @param parent parent to which the child will be added
172
     * @param el element to be added
173
     * @param order order of the elements which must be followed
174
     */
175
    private static void appendChildElement(Element parent, Element el, String[] order) {
176
        Element insertBefore = null;
177
        List l = Arrays.asList(order);
178
        int index = l.indexOf(el.getLocalName());
179
        assert index != -1 : el.getLocalName()+" was not found in "+l; // NOI18N
180
        Iterator it = findSubElements(parent).iterator();
181
        while (it.hasNext()) {
182
            Element e = (Element)it.next();
183
            int index2 = l.indexOf(e.getLocalName());
184
            assert index2 != -1 : e.getLocalName()+" was not found in "+l; // NOI18N
185
            if (index2 > index) {
186
                insertBefore = e;
187
                break;
188
            }
189
        }
190
        parent.insertBefore(el, insertBefore);
191
    }
192
        
193
    private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) {
138
    private static Element createLibraryElement(AntProjectHelper antProjectHelper, Document doc, Item item, String includedLibrariesElement) {
194
        Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
139
        Element libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
195
        // ejbjar is different from other j2ee projects - it stores reference without ${ and }
140
        // ejbjar is different from other j2ee projects - it stores reference without ${ and }
Lines 197-220 Link Here
197
        Util.updateDirsAttributeInCPSItem(item, libraryElement);
142
        Util.updateDirsAttributeInCPSItem(item, libraryElement);
198
        return libraryElement;
143
        return libraryElement;
199
    }
144
    }
200
       
201
    /**
202
     * Extracts <b>the first</b> nested text from an element.
203
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
204
     * @param parent a parent element
205
     * @return the nested text, or null if none was found
206
     */
207
    private static String findText( Element parent ) {
208
        NodeList l = parent.getChildNodes();
209
        for ( int i = 0; i < l.getLength(); i++ ) {
210
            if ( l.item(i).getNodeType() == Node.TEXT_NODE ) {
211
                Text text = (Text)l.item( i );
212
                return text.getNodeValue();
213
            }
214
        }
215
        return null;
216
    }
217
        
218
145
219
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
146
    public void readAdditionalProperties(List<Item> items, String projectXMLElement) {
220
        Map<String, String> destination = new HashMap<String, String>();
147
        Map<String, String> destination = new HashMap<String, String>();

Return to bug 136595