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:
042: /*
043: * RequirementsManager.java
044: *
045: * Created on June 24, 2004, 2:23 PM
046: */
047:
048: package org.netbeans.modules.uml.core.requirementsframework;
049:
050: import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
052: import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
053: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
054:
055: import java.util.ArrayList;
056: import java.util.Collection;
057: import java.util.HashMap;
058: import java.util.ResourceBundle;
059:
060: import org.dom4j.Branch;
061: import org.dom4j.Document;
062: import org.dom4j.Element;
063: import org.dom4j.Node;
064: import org.openide.cookies.InstanceCookie;
065: import org.openide.filesystems.FileObject;
066: import org.openide.filesystems.FileSystem;
067: import org.openide.filesystems.Repository;
068: import org.openide.loaders.DataObject;
069:
070: /**
071: *
072: * @author Trey Spiva
073: */
074: public class RequirementsManager
075: /*extends AddInManagerImpl*/implements IRequirementsManager {
076: private ResourceBundle m_Bundle = ResourceBundle
077: .getBundle("org/netbeans/modules/uml/core/requirementsframework/Bundle");
078:
079: /** DOM document to load the RequirementSources.etrp file into. */
080: protected Document m_ReqProxyDoc;
081:
082: /** Path and name of the RequirementSources.etd file */
083: protected String m_ReqSourcesFile;
084:
085: /** Path and name of the RequirementSources.etrp file */
086: protected String m_ReqProxyFile;
087:
088: /** DOM document to load the RequirementSources.etd file into. */
089: private Document m_ReqSourcesDoc;
090:
091: private HashMap<String, IRequirementsProvider> mAddins = new HashMap<String, IRequirementsProvider>();
092:
093: public RequirementsManager() {
094: initialize();
095: }
096:
097: /**
098: *
099: * Initialize the requirements manager. The layer file repository will
100: * be searched for all registered requiremennts addins.
101: *
102: * @return HRESULT
103: *
104: */
105: public void initialize() {
106:
107: IRequirementsProvider[] addins = getAddinsFromRegistry("UML/requirements");
108: for (IRequirementsProvider curAddin : addins) {
109: String progID = curAddin.getProgID();
110: mAddins.put(progID, curAddin);
111: }
112:
113: }
114:
115: /**
116: * Retrieves all of the reqistered requirements IAddIn instances
117: */
118: public IRequirementsProvider[] getAddIns() {
119: IRequirementsProvider[] retVal = null;
120:
121: Collection<IRequirementsProvider> addins = mAddins.values();
122: if (addins.size() > 0) {
123: retVal = new IRequirementsProvider[addins.size()];
124: addins.toArray(retVal);
125: } else {
126: retVal = new IRequirementsProvider[0];
127: }
128:
129: return retVal;
130: }
131:
132: /**
133: * The requirements manager knows about the requirements addins.
134: * This routine retrieves a particular addin based on the prog id passed in.
135: *
136: *
137: * @param sProgID[in] The prog id of the addin to get
138: * @param pAddIn[out] The found add in
139: *
140: * @return HRESULT
141: *
142: */
143: public IRequirementsProvider getRequirementsProvider(String sProgID) {
144: IRequirementsProvider pIn = mAddins.get(sProgID);
145: return pIn;
146: }
147:
148: /**
149: *
150: * Callback from ReqProxyManager, when the "Display Sources" button is pressed
151: * on the Requirements Provider Dialog. The ReqProviderDialogImpl is in
152: * the RequirementsFramework project. See RequirementsManagerImpl::PopulateTreeItem
153: * for how the dialog is created and this requirements manager is set to
154: * recieve callbacks from the dialog.
155: *
156: * @param desc[in] RequirementSource for the addin selected in the Requirements Provider dialog.
157: *
158: * @return HRESULT
159: *
160: */
161: public void processSource(IRequirementSource requirementSource)
162: throws RequirementsException {
163: boolean fileLoaded = getReqSourcesDoc();
164: if (m_ReqSourcesDoc != null) {
165: if (fileLoaded == false) {
166: initializeReqSourcesDoc(m_ReqSourcesDoc);
167: }
168:
169: String location = requirementSource.getLocation();
170: String pattern = "RequirementSources/RequirementSource[@location='"
171: + location + "']";
172:
173: Node requirementSourceNode = XMLManip.selectSingleNode(
174: m_ReqSourcesDoc, pattern);
175: if (requirementSourceNode != null) {
176: throw new RequirementsException(
177: RequirementsException.RP_E_DUPLICATESOURCE,
178: m_Bundle.getString("IDS_DUPLICATESOURCE"));
179: } else {
180: // check for duplicate display name as well
181: // fix for bug 5107636
182: String displayName = requirementSource.getDisplayName();
183: pattern = "RequirementSources/RequirementSource[@displayName='"
184: + displayName + "']";
185: requirementSourceNode = XMLManip.selectSingleNode(
186: m_ReqSourcesDoc, pattern);
187: if (requirementSourceNode != null) {
188: throw new RequirementsException(
189: RequirementsException.RP_E_DUPLICATESOURCE,
190: m_Bundle.getString("IDS_DUPLICATESOURCE"));
191: } else {
192: Element sourceElement = convertReqSourceToXMLElement(
193: m_ReqSourcesDoc, requirementSource);
194: if (sourceElement != null) {
195: //addReqSourceToDoc(m_ReqSourcesDoc, sourceElement);
196: saveReqSourcesDoc();
197: }
198: }
199: }
200: }
201: }
202:
203: /**
204: *
205: * Given a RequirementSourceID, read the etd file and return the
206: * RequirementSource.
207: *
208: * @param strRequirementSourceID RequirementSource Identifier
209: * @return RequirementSource
210: *
211: */
212: public IRequirementSource getSource(String strRequirementSourceID) {
213: IRequirementSource requirementSource = null;
214:
215: boolean bFileLoaded = getReqSourcesDoc();
216: if (m_ReqSourcesDoc != null) {
217: if (bFileLoaded != true) {
218: initializeReqSourcesDoc(m_ReqSourcesDoc);
219: }
220: // Find the RequirementSourceID
221: String strPattern = "RequirementSources/RequirementSource[@id='";
222: strPattern += strRequirementSourceID;
223: strPattern += "']";
224:
225: Node requirementSourceNode = m_ReqSourcesDoc
226: .selectSingleNode(strPattern);
227:
228: if (requirementSourceNode != null) {
229: requirementSource = new RequirementSource();
230:
231: requirementSource.setID(strRequirementSourceID);
232:
233: if (requirementSourceNode instanceof Element) {
234: Element sourceElement = (Element) requirementSourceNode;
235:
236: String strLocation = sourceElement
237: .attributeValue("location");
238: if (strLocation != null) {
239: requirementSource.setLocation(strLocation);
240: }
241: }
242: }
243: }
244:
245: return requirementSource;
246: }
247:
248: /**
249: *
250: * Callback from ReqProxyManager when a Requirement(s) has been dropped on a
251: * presentation element. Creates <code><RequirementProxy><Requirement>
252: * <Satisfiers><Satisfier> </code> nodes as needed.
253: *
254: * @param requirement The requirement.
255: * @param satisfier The requirements satisfier.
256: *
257: */
258: public void processProxy(IRequirement requirement,
259: ISatisfier satisfier) {
260: String strRequirementSourceID = requirement.getSourceID();
261: String strRequirementID = requirement.getID();
262: String strRequirementName = requirement.getName();
263:
264: String strSatisfierID = satisfier.getXMIID();
265: String strSatisfierName = satisfier.getName();
266: String strProjectName = satisfier.getProjectName();
267: String strProjectID = satisfier.getProjectID();
268:
269: boolean bFileLoaded = getReqProxyDoc();
270: if (m_ReqProxyDoc != null) {
271: if (bFileLoaded == false) {
272: // File does NOT exist: Add the XML declaration and all child nodes.
273: //m_ReqProxyDoc.addProcessingInstruction("xml", "version = '1.0' ");
274:
275: Element reqProxiesElement = XMLManip.createElement(
276: m_ReqProxyDoc, "RequirementProxies");
277:
278: // Append RequirementProxy element and set source equal to Provider's RequirementSourceID.
279: if (reqProxiesElement != null) {
280: Element reqProxyElement = XMLManip.createElement(
281: reqProxiesElement, "RequirementProxy");
282:
283: // Append RequirementProxy element and set source equal to Provider's RequirementSourceID.
284: if (reqProxyElement != null) {
285: reqProxyElement.addAttribute("source",
286: strRequirementSourceID);
287:
288: Element requirementElement = XMLManip
289: .createElement(reqProxyElement,
290: "Requirement");
291:
292: // Append Requirement element and set RequirementID and Name.
293: if (requirementElement != null) {
294: requirementElement.addAttribute("id",
295: strRequirementID);
296: requirementElement.addAttribute("name",
297: strRequirementName);
298:
299: Element satisfiersElement = XMLManip
300: .createElement(requirementElement,
301: "Satisfiers");
302:
303: // Append <Satisfiers> container element.
304: if (satisfiersElement != null) {
305: Element satisfierElement = XMLManip
306: .createElement(
307: satisfiersElement,
308: "Satisfier");
309:
310: // Add Satisfier element with Name and XMIID of the Model element.
311: if (satisfierElement != null) {
312: satisfierElement.addAttribute(
313: "name", strSatisfierName);
314: satisfierElement.addAttribute(
315: "xmiid", strSatisfierID);
316: satisfierElement.addAttribute(
317: "projectname",
318: strProjectName);
319: satisfierElement.addAttribute(
320: "projectid", strProjectID);
321: }
322: }
323: }
324: }
325: }
326:
327: updateProxyFileLocation(strRequirementSourceID);
328: } else {
329: // The Proxy file exists. Repeatedly call findOrCreate(...) for each element in
330: // <RequirementProxies><RequirementProxy><Requirement><Satisfiers><Satisfier>.
331:
332: Element reqProxiesElement = findOrCreateElement(
333: m_ReqProxyDoc, "RequirementProxies", "", "");
334:
335: if (reqProxiesElement != null) {
336: Element reqProxyElement = findOrCreateElement(
337: reqProxiesElement, "RequirementProxy",
338: "source", strRequirementSourceID);
339:
340: if (reqProxyElement != null) {
341: reqProxyElement.addAttribute("source",
342: strRequirementSourceID);
343: Element requirementElement = findOrCreateElement(
344: reqProxyElement, "Requirement", "id",
345: strRequirementID);
346:
347: if (requirementElement != null) {
348: requirementElement.addAttribute("id",
349: strRequirementID);
350: requirementElement.addAttribute("name",
351: strRequirementName);
352:
353: Element satisfiersElement = findOrCreateElement(
354: requirementElement, "Satisfiers",
355: "", "");
356:
357: if (satisfiersElement != null) {
358: Element satisfierElement = findOrCreateElement(
359: satisfiersElement, "Satisfier",
360: "xmiid", strSatisfierID);
361:
362: if (satisfierElement != null) {
363: satisfierElement.addAttribute(
364: "name", strSatisfierName);
365: satisfierElement.addAttribute(
366: "xmiid", strSatisfierID);
367: satisfierElement.addAttribute(
368: "projectname",
369: strProjectName);
370: satisfierElement.addAttribute(
371: "projectid", strProjectID);
372: }
373: }
374: }
375:
376: }
377: }
378: }
379: XMLManip.save(m_ReqProxyDoc, m_ReqProxyFile);
380: }
381: }
382:
383: /**
384: *
385: * Callback from ReqProxyManager when a Requirement(s) has been dropped on a presentation
386: * element. Creates <RequirementProxy><Requirement><Satisfiers><Satisfier> nodes as
387: * needed.
388: *
389: * @param strRequirementSourceID[in] RequirementSourceID of the Provider.
390: * @param strRequirementID[in] RequirementID.
391: * @param strRequirementName[in] RequirementName.
392: * @param strSatisfierID[in] SatisfierID of the Presentation element. - Not Used Yet, need to be
393: * able to retrieve this from the TreeItem.
394: * @param strSatisfierName[in] SatisfierName of the Presentation element.
395: *
396: * @return HRESULT
397: *
398: */
399: public void deleteProxy(IRequirement requirement,
400: ISatisfier satisfier) {
401: String strRequirementSourceID = requirement.getSourceID();
402: String strRequirementID = requirement.getID();
403:
404: String strSatisfierID = satisfier.getXMIID();
405:
406: boolean bFileLoaded = getReqProxyDoc();
407:
408: if (m_ReqProxyDoc != null) {
409: if (bFileLoaded != true) {
410: // TODO: Cannot maintain proxy if it is inaccessible.
411: } else {
412: // Get the <RequiremenProxy> element matching the RequirementSource/.
413: String strPattern = "RequirementProxies/RequirementProxy[@source='";
414: strPattern += strRequirementSourceID;
415: strPattern += "']";
416:
417: Node requirementProxyNode = m_ReqProxyDoc
418: .selectSingleNode(strPattern);
419: if (requirementProxyNode != null) {
420: // Get the <Requirement> Node.
421: strPattern = "Requirement[@id='";
422: strPattern += strRequirementID;
423: strPattern += "']";
424:
425: Node requirementNode = requirementProxyNode
426: .selectSingleNode(strPattern);
427: if (requirementNode != null) {
428: // Get the <Satisfiers> container node.
429: strPattern = "Satisfiers";
430:
431: Node satisfiersNode = requirementNode
432: .selectSingleNode(strPattern);
433: if (satisfiersNode != null) {
434: // Get the <Satisfier>: currently matching on name, switch to xmiid when available.
435: strPattern = "Satisfier[@xmiid=\"";
436: strPattern += strSatisfierID;
437: strPattern += "\"]";
438:
439: Node satisfierNode = satisfiersNode
440: .selectSingleNode(strPattern);
441:
442: if (satisfierNode != null) {
443: // Delete the Satisfier from the Satisfiers container.
444: satisfierNode.detach();
445:
446: // Save the Proxy XML file.
447: XMLManip.save(m_ReqProxyDoc,
448: m_ReqProxyFile);
449: }
450: }
451: }
452: }
453: }
454: }
455: }
456:
457: ////////////////////////////////////////////////////////////////////////////////////////////////////
458:
459: /**
460: *
461: * Creates an XML element for the passed in IAddInDescriptor and writes it to
462: * the RequirementSources.etd file.
463: *
464: * @param *bFileLoaded[out] Returns true if the RequirementSources.etd file is loaded.
465: *
466: * @return void
467: *
468: */
469: protected boolean getReqSourcesDoc() {
470: boolean bFileLoaded = true;
471:
472: if (null == m_ReqSourcesDoc) {
473: // Load the RequirementSources.etd file into the DOM. The .etd file's
474: // elements contains AddIn data for each requirement provider.
475: String strFile = getReqSourcesFile();
476: m_ReqSourcesDoc = XMLManip.getDOMDocument(strFile);
477:
478: // The requiriements file must not exist yet so lets just create a new
479: // documents.
480: if (m_ReqSourcesDoc == null) {
481: m_ReqSourcesDoc = XMLManip.getDOMDocument();
482: bFileLoaded = false;
483: }
484: }
485:
486: return bFileLoaded;
487: }
488:
489: /**
490: *
491: * Gets or creates the .RequirementSources.etrp proxy file
492: *
493: * @param *bFileLoaded[out] Returns true if the RequirementSources.etrp file is loaded.
494: *
495: * @return void
496: *
497: */
498: protected boolean getReqProxyDoc() {
499: boolean bFileLoaded = true;
500:
501: if (null == m_ReqProxyDoc) {
502: // Load the RequirementSources.etrp file into the DOM. The .etd file's
503: // elements contains AddIn data for each requirement provider.
504:
505: String strFile = "";
506: if ((m_ReqProxyFile != null)
507: && (m_ReqProxyFile.length() > 0)) {
508: strFile = m_ReqProxyFile;
509: } else {
510: String strConfigDir = getConfigDir();
511: if (strConfigDir.length() > 0) {
512: strFile = strConfigDir + "RequirementSources.etrp";
513: m_ReqProxyFile = strFile;
514: }
515: }
516:
517: m_ReqProxyDoc = XMLManip.getDOMDocument(strFile);
518:
519: // The requiriements file must not exist yet so lets just create a new
520: // documents.
521: if (m_ReqProxyDoc == null) {
522: m_ReqProxyDoc = XMLManip.getDOMDocument();
523:
524: if (m_ReqProxyDoc.getRootElement() != null) {
525: m_ReqProxyDoc.getRootElement().detach();
526: }
527: bFileLoaded = false;
528: }
529:
530: }
531:
532: return bFileLoaded;
533: }
534:
535: /**
536: * Updates the location of the proxy file in the RequirementSources.etd document
537: *
538: * @param *bFileLoaded[out] Returns true if the RequirementSources.etrp file is loaded.
539: *
540: * @return void
541: *
542: */
543: protected void updateProxyFileLocation(String strRequirementSourceID) {
544:
545: if (m_ReqSourcesDoc != null) {
546: boolean bFileLoaded = getReqSourcesDoc();
547: if (bFileLoaded == true) {
548: String strPattern = "RequirementSources/RequirementSource";
549: strPattern += "[@id='";
550: strPattern += strRequirementSourceID;
551: strPattern += "']";
552:
553: // Update the <proxyFile> location element in the .etd file
554: Node reqSourceNode = m_ReqSourcesDoc
555: .selectSingleNode(strPattern);
556: if (reqSourceNode instanceof Element) {
557: Element reqSourceElement = (Element) reqSourceNode;
558: if (reqSourceElement != null) {
559: reqSourceElement.addAttribute("proxyFile",
560: m_ReqProxyFile);
561: saveReqSourcesDoc();
562: }
563: }
564: }
565: }
566: }
567:
568: /**
569: *
570: * Creates the initial elements for a RequirementSources.etd document.
571: *
572: * @param *document[in] XML Document to initialize.
573: *
574: * @return void
575: *
576: */
577: protected void initializeReqSourcesDoc(Document document) {
578: if (null == document)
579: throw new IllegalArgumentException();
580:
581: // Add the XML declaration
582: //document.addProcessingInstruction("xml", "version = '1.0' ");
583:
584: // I want the RequirementSources to be the root element.
585: Element root = document.getRootElement();
586: if (root != null) {
587: root.detach();
588: }
589: Element reqSourcesElem = XMLManip.createElement(document,
590: "RequirementSources");
591: // if (reqSourcesElem != null)
592: // {
593: // document.getRootElement().add(reqSourcesElem);
594: // }
595: }
596:
597: /**
598: *
599: * Returns the path and file name for the RequirementSources.etd file,
600: * which contains data for the available requirement provider addins.
601: *
602: * @return String Location the RequirementsSources.etd file.
603: *
604: */
605: protected String getReqSourcesFile() {
606: String strFile = "";
607:
608: if ((m_ReqSourcesFile != null)
609: && (m_ReqSourcesFile.length() > 0)) {
610: strFile = m_ReqSourcesFile;
611: } else {
612: String strConfigDir = getConfigDir();
613: if (strConfigDir.length() > 0) {
614: strFile = strConfigDir + "RequirementSources.etd";
615: }
616: }
617: return strFile;
618: }
619:
620: protected String getConfigDir() {
621: String strDir = "";
622:
623: ICoreProduct product = ProductRetriever.retrieveProduct();
624: if (product != null) {
625: IConfigManager configMgr = product.getConfigManager();
626:
627: if (configMgr != null) {
628: String strLoc = configMgr.getDefaultConfigLocation();
629: if (strLoc != null) {
630: strDir = strLoc;
631: }
632: }
633: }
634:
635: return strDir;
636: }
637:
638: /**
639: *
640: * Create a <RequirementSource> element for the RequirementSources.etd file, from an
641: * IRequriementsSource class.
642: *
643: * @param *document[in] XML Document to create the element for.
644: * @param *requirementSource[in] Describe IRequirementSource that contains the data.
645: * @param *sourceElem[out] Returns the new XML Element.
646: *
647: * @return void
648: *
649: */
650: protected Element convertReqSourceToXMLElement(Document document,
651: IRequirementSource requirementSource) {
652: if (null == document)
653: throw new IllegalArgumentException();
654: if (null == requirementSource)
655: throw new IllegalArgumentException();
656:
657: String strPattern = "/RequirementSources";
658: Node reqSourcesNode = document.selectSingleNode(strPattern);
659:
660: Element sourceElem = null;
661: if (reqSourcesNode instanceof Element) {
662: Element sourcesBranch = (Element) reqSourcesNode;
663: sourceElem = XMLManip.createElement(sourcesBranch,
664: "RequirementSource");
665: if (sourceElem != null) {
666: // Set the id for the element.
667: String strID = requirementSource.getID();
668: sourceElem.addAttribute("id", strID);
669:
670: // Set the display name attr for the element
671: String strDisplayName = requirementSource
672: .getDisplayName();
673: sourceElem.addAttribute("displayName", strDisplayName);
674:
675: // Set the provider (addin Prog_ID) attr for the element
676: String strProgID = requirementSource.getProvider();
677: sourceElem.addAttribute("provider", strProgID);
678:
679: // Set the location of the provider's requirements file.
680: String strLocation = requirementSource.getLocation();
681: sourceElem.addAttribute("location", strLocation);
682:
683: // Set whether a login is required for this requirement source.
684: String strRequiresLogin;
685: if (requirementSource.getRequiresLogin()) {
686: strRequiresLogin = "True";
687: } else {
688: strRequiresLogin = "False";
689: }
690: sourceElem.addAttribute("loginRequired",
691: strRequiresLogin);
692:
693: // Set the location of the proxy file (which connects Describe symbols with the
694: // requirements that they fullfill).
695: String strProxyFile = requirementSource.getProxyFile();
696: sourceElem.addAttribute("proxyFile", strProxyFile);
697: }
698: }
699:
700: return sourceElem;
701: }
702:
703: /**
704: *
705: * Insert the passed in <RequirementSource> element to the RequirementsSources.etd file.
706: *
707: * @param *document[in] The XML document to add the passed in element to.
708: * @param *sourceElem[in] The XML element to add to the document.
709: *
710: * @return void
711: *
712: */
713: protected void addReqSourceToDoc(Document document,
714: Element sourceElem) {
715: if (null == document)
716: throw new IllegalArgumentException();
717: if (null == sourceElem)
718: throw new IllegalArgumentException();
719:
720: //ptemp - do we want to make sure there are no duplicate provider names
721: // under "Requirements" ??
722: String strPattern = "/RequirementSources";
723: Node reqSourcesNode = document.selectSingleNode(strPattern);
724:
725: if (reqSourcesNode instanceof Branch) {
726: Branch sourcesBranch = (Branch) reqSourcesNode;
727:
728: sourceElem.detach();
729: sourcesBranch.add(sourceElem);
730: }
731: }
732:
733: /**
734: *
735: * Looks for a child node on the parent. Returns found node or newly created node.
736: *
737: * @param parentNode[in] Node where search will start from.
738: * @param childElement[in,out] The found or newly created node.
739: * @param strNodeName[in] Node Name
740: * @param strAttributeName[in] Attribute name ( if null, will match on first selected node eq to node name.
741: * @param strAttributeValue[in] Attribute Value, used in conjunction with non null attribute name.
742: *
743: * @return void
744: *
745: */
746: protected Element findOrCreateElement(Node parentNode,
747: String strNodeName, String strAttributeName,
748: String strAttributeValue) {
749: Element childElement = null;
750:
751: String strPattern = strNodeName;
752:
753: // Search for node equal to input arg's node name. Optionally match on attribute.
754: if (strAttributeName.length() > 0) {
755: strPattern += "[@";
756: strPattern += strAttributeName;
757: strPattern += "='";
758: strPattern += strAttributeValue;
759: strPattern += "']";
760: }
761:
762: Node node = parentNode.selectSingleNode(strPattern);
763: if (node != null) {
764: // Return found node.
765: if (node instanceof Element) {
766: childElement = (Element) node;
767: }
768: } else {
769: // Create new node and append to the parent.
770: if (parentNode instanceof Element) {
771: childElement = XMLManip.createElement(
772: (Element) parentNode, strNodeName);
773: } else {
774: childElement = XMLManip.createElement(m_ReqProxyDoc,
775: strNodeName);
776: }
777: }
778:
779: return childElement;
780: }
781:
782: /**
783: *
784: * Saves the RequirementSources.etd document to disk.
785: *
786: * @return void
787: *
788: */
789: protected void saveReqSourcesDoc() {
790: if (m_ReqSourcesDoc != null) {
791: String strReqFile = getReqSourcesFile();
792: if (strReqFile.length() > 0) {
793: XMLManip.save(m_ReqSourcesDoc, strReqFile);
794: }
795: }
796: }
797:
798: /**
799: *
800: * Load the passed in IRequriementsSource class from the passed in <RequirementSource>
801: * element (element type that goes in the RequirementSources.etd file) .
802: *
803: * @param *sourceElem[in] The XML element that contains the Requirement Source data.
804: * @param *requirementSource[in] The IRequirements object to fill with data.
805: *
806: * @return void
807: *
808: */
809: protected void convertXMLElementToReqSource(Element sourceElem,
810: IRequirementSource requirementSource) {
811: if (null == sourceElem)
812: throw new IllegalArgumentException();
813: if (null == requirementSource)
814: throw new IllegalArgumentException();
815:
816: String strValue;
817:
818: // Set the id of the requirement source.
819: strValue = sourceElem.attributeValue("id");
820: if (strValue != null) {
821: requirementSource.setID(strValue);
822: }
823:
824: // Set the displayed name of the requirement source.
825: strValue = sourceElem.attributeValue("displayName");
826: if (strValue != null) {
827: requirementSource.setDisplayName(strValue);
828: }
829:
830: // Set the provider (addin Prog_ID) of the requierment soruce.
831: strValue = sourceElem.attributeValue("provider");
832: if (strValue != null) {
833: requirementSource.setProvider(strValue);
834: }
835:
836: // Set the location of the requirement source's requirement file.
837: strValue = sourceElem.attributeValue("location");
838: if (strValue != null) {
839: requirementSource.setLocation(strValue);
840: }
841:
842: // Set whether a login is required for this requirement source.
843: strValue = sourceElem.attributeValue("loginRequired");
844: if (strValue != null) {
845: boolean bLogin = strValue.equals("True");
846: requirementSource.setRequiresLogin(bLogin);
847: }
848:
849: // Set the location of the proxy file (which connects Describe symbols with the
850: // requirements that they fullfill).
851: strValue = sourceElem.attributeValue("proxyFile");
852: if (strValue != null) {
853: requirementSource.setProxyFile(strValue);
854: }
855: }
856:
857: /**
858: * The registry information that is retrieved from layer files to build
859: * the list of design center addins supported by this node.
860: *
861: * @param path The registry path that is used for the lookup.
862: * @return The list of addins in the path. null will be used if when
863: * seperators can be placed.
864: */
865: protected IRequirementsProvider[] getAddinsFromRegistry(String path) {
866: ArrayList<IRequirementsProvider> addins = new ArrayList<IRequirementsProvider>();
867: FileSystem system = Repository.getDefault()
868: .getDefaultFileSystem();
869: try {
870: if (system != null) {
871: org.openide.filesystems.FileObject lookupDir = system
872: .findResource(path);
873: if (lookupDir != null) {
874: org.openide.filesystems.FileObject[] children = lookupDir
875: .getChildren();
876:
877: for (FileObject curObj : children) {
878: try {
879: DataObject dObj = DataObject.find(curObj);
880: if (dObj != null) {
881: InstanceCookie cookie = (InstanceCookie) dObj
882: .getCookie(InstanceCookie.class);
883: if (cookie != null) {
884: Object obj = cookie
885: .instanceCreate();
886: if (obj instanceof IRequirementsProvider) {
887: //String id = (String)curObj.getAttribute("id");
888: addins
889: .add((IRequirementsProvider) obj);
890: }
891: }
892: }
893: } catch (ClassNotFoundException e) {
894: // Unable to create the instance for some reason. So the
895: // do not worry about adding the instance to the list.
896: }
897: }
898: }
899: }
900: } catch (org.openide.loaders.DataObjectNotFoundException e) {
901: // Basically Bail at this time.
902: } catch (java.io.IOException ioE) {
903:
904: }
905:
906: IRequirementsProvider[] retVal = new IRequirementsProvider[addins
907: .size()];
908: addins.toArray(retVal);
909: return retVal;
910: }
911: }
|