0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: /*
0043: * Created on Apr 22, 2003
0044: *
0045: */
0046: package org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework;
0047:
0048: import java.io.File;
0049: import java.io.IOException;
0050: import java.util.Enumeration;
0051: import java.util.Hashtable;
0052: import java.util.List;
0053: import java.util.Vector;
0054:
0055: import org.dom4j.Document;
0056: import org.dom4j.Node;
0057:
0058: import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
0059: import org.netbeans.modules.uml.core.generativeframework.IExpansionVariable;
0060: import org.netbeans.modules.uml.core.generativeframework.ITemplateManager;
0061: import org.netbeans.modules.uml.core.generativeframework.IVariableFactory;
0062: import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
0063: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0064: import org.netbeans.modules.uml.core.metamodel.core.foundation.UMLXMLManip;
0065: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0066: import org.netbeans.modules.uml.core.reverseengineering.reframework.IDataTypeKind;
0067: import org.netbeans.modules.uml.core.reverseengineering.reframework.ITokenKind;
0068: import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
0069: import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
0070: import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
0071: import org.netbeans.modules.uml.core.support.umlsupport.Strings;
0072: import org.netbeans.modules.uml.core.support.umlsupport.URILocator;
0073: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
0074: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0075: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0076: import org.netbeans.modules.uml.core.support.umlsupport.Log;
0077: import org.openide.modules.InstalledFileLocator;
0078:
0079: /**
0080: * @author sumitabhk
0081: *
0082: */
0083: public class LanguageManager implements ILanguageManager {
0084: private String m_ConfigLocation = "";
0085:
0086: //<LangName, ILanguage>
0087: private Hashtable<String, ILanguage> m_LanguageMap = new Hashtable<String, ILanguage>();
0088: private IStrings m_LanguageNames = null;
0089:
0090: //<LangName, Extension>
0091: private Hashtable<String, String> m_ExtensionMap = new Hashtable<String, String>();
0092:
0093: //<LangName, Vector<ILangaugeFilter>>
0094: private Hashtable<String, ETList<ILanguageFilter>> m_FilterMap = new Hashtable();
0095:
0096: /**
0097: *
0098: */
0099: public LanguageManager() {
0100: initializeManager();
0101: }
0102:
0103: /**
0104: *
0105: * Retrieves the RequestProcessor progid associated with the given file.
0106: *
0107: * @param fileName[in] A file path. Can be relative or absolute
0108: * @param procID[out] The ProgID of the appropriate RequestProcessor
0109: *
0110: * @return HRESULT
0111: *
0112: */
0113: public String retrieveContextForFile(String filename, String context) {
0114: String retContext = "";
0115: try {
0116: String lang = getLanguageNameForFile(filename);
0117: if (lang != null && lang.length() > 0) {
0118: retContext = retrieveContextForLanguage(lang, context);
0119: }
0120: } catch (Exception e) {
0121: }
0122: return retContext;
0123: }
0124:
0125: /**
0126: *
0127: * Retrieves the current, absolute path to the Languages.etc
0128: * configuration file.
0129: *
0130: * @param pVal [out] The current value
0131: *
0132: * @return HRESULT
0133: *
0134: */
0135: public String getConfigLocation() {
0136: String retLoc = "";
0137: try {
0138: if (m_ConfigLocation.length() == 0) {
0139: m_ConfigLocation = getConfigHome();
0140: }
0141:
0142: retLoc = m_ConfigLocation;
0143: } catch (Exception e) {
0144: }
0145: return retLoc;
0146: }
0147:
0148: /**
0149: *
0150: * Sets the location of the configuration file to use. This
0151: * must be an absolute path.
0152: *
0153: * @param newVal[in] Absolute path to the config file
0154: *
0155: * @return HRESULT
0156: *
0157: */
0158: public void setConfigLocation(String newVal) {
0159: m_ExtensionMap.clear();
0160: m_LanguageMap.clear();
0161: m_LanguageNames = null;
0162: m_ConfigLocation = newVal;
0163:
0164: initializeManager();
0165: }
0166:
0167: /**
0168: *
0169: * Retrieves the instantiation directive for the RequestProcessor
0170: * associated with the passed-in language name.
0171: *
0172: * @param language[in] The name of the language
0173: * @param procID[out] The RequestProcessor associated with that language
0174: *
0175: * @return HRESULT
0176: *
0177: */
0178: public String retrieveContextForLanguage(String language,
0179: String context) {
0180: String retContext = null;
0181: try {
0182: ILanguage lang = getLanguage(language);
0183: if (lang != null) {
0184: retContext = lang.getContextCLSID(context);
0185: }
0186: } catch (Exception e) {
0187: }
0188: return retContext;
0189: }
0190:
0191: /**
0192: * Retrieves the language defintion from the language manager.
0193: *
0194: * @param langName [in] The name of the language
0195: * @param pVal [out] The language definition
0196: * @return E_INVALID_ARG if pVal = NULL, IDS_E_LANG_CONFIG_MISSING if langName
0197: * is not found in the language config file.
0198: */
0199: public ILanguage getLanguage(String langName) {
0200: ILanguage retLang = null;
0201: try {
0202: // Check if I have already retrieve the ILanguage data from the
0203: // configuration file. If I have not already retrieved the langugae
0204: // information the retrieve it of course.
0205: if (m_LanguageMap.size() > 0) {
0206: if (m_LanguageMap.containsKey(langName)) {
0207: retLang = m_LanguageMap.get(langName);
0208: } else {
0209: retLang = retrieveLanguage(langName);
0210: }
0211: } else {
0212: retLang = retrieveLanguage(langName);
0213: }
0214:
0215: // If I was not able to find the language information in the configuration
0216: // file then the error LM_E_INVALID_LANG_NAME must reported to the caller.
0217: if (retLang == null) {
0218: Log.out("LM_E_INVALID_LANG_NAME");
0219: }
0220: } catch (Exception e) {
0221: }
0222: return retLang;
0223: }
0224:
0225: /**
0226: * Retrieves a language parser for the specified language. A language can support
0227: * more than one way to parse a stream. Examples of different parses
0228: * are a complete parser, a parser that retrieves classes only, and a parser that
0229: * only retrieves package and class defintions (no attribute or operatons).
0230: *
0231: * @param language [in] The language
0232: * @param type [in] The parser type
0233: * @param pVal [out] The parser
0234: */
0235: public ILanguageParser retrieveParserForLanguage(String language,
0236: String type) {
0237: ILanguageParser retParser = null;
0238: ILanguage lang = getLanguage(language);
0239: if (lang != null) {
0240: retParser = lang.getParser(type);
0241: }
0242: return retParser;
0243: }
0244:
0245: /**
0246: * Retrieves a langauge parser that will parse the specified file. The parser will be
0247: * selected based on the file extension. A language can support more than one way
0248: * to parse a stream. Examples of different parses are a complete parser,
0249: * a parser that retrieves classes only, and a parser that only retrieves package
0250: * and class defintions (no attribute or operations).
0251: *
0252: * @param file [in] The file name
0253: * @param type [in] The parser type
0254: * @param pVal [out] The parser
0255: */
0256: public ILanguageParser getParserForFile(String file, String type) {
0257: ILanguageParser retParser = null;
0258: String lang = getLanguageNameForFile(file);
0259: if (lang != null && lang.length() > 0) {
0260: retParser = retrieveParserForLanguage(lang, type);
0261: }
0262: return retParser;
0263: }
0264:
0265: /**
0266: * Retrieves the name of the languages that are supported by the Language Manager.
0267: *
0268: * @param pVal [out] The list of language names
0269: */
0270: public IStrings getSupportedLanguages() {
0271: return m_LanguageNames;
0272: }
0273:
0274: /**
0275: * Retrieves the language definition from the language manager. The file name is
0276: * used to determine the language defintion to retrieve.
0277: *
0278: * @param filename [in] The name of the file
0279: * @param pVal [out] The language definition
0280: */
0281: public ILanguage getLanguageForFile(String filename) {
0282: ILanguage retLang = null;
0283: String lang = getLanguageNameForFile(filename);
0284: if (lang != null && lang.length() > 0) {
0285: retLang = getLanguage(lang);
0286: } else {
0287: Log.out("LM_E_INVALID_LANG_NAME");
0288: }
0289: return retLang;
0290: }
0291:
0292: /**
0293: * Retrieves the languages that are supported by the Language Manager.
0294: *
0295: * @param pVal [out] The collection of Language objects
0296: */
0297: public ETList<ILanguage> getSupportedLanguages2() {
0298: ETList<ILanguage> retVal = null;
0299: IStrings langs = getSupportedLanguages();
0300: if (langs != null) {
0301: int count = langs.getCount();
0302: retVal = new ETArrayList<ILanguage>();
0303: for (int i = 0; i < count; i++) {
0304: String langName = langs.item(i);
0305: ILanguage language = getLanguage(langName);
0306: if (language != null) {
0307: retVal.add(language);
0308: }
0309: }
0310: }
0311: return retVal;
0312: }
0313:
0314: /**
0315: * Retrieves the default data type for a new attribute. If a data type
0316: * is not defined as the default type then the default type will be
0317: * retrieved from the UML language.
0318: *
0319: * @param pOwner [in] The element that contains the attribute
0320: * @param pType [out] The data type
0321: */
0322: public ILanguageDataType getAttributeDefaultType(Object pOwner) {
0323: ILanguageDataType retType = null;
0324: if (pOwner != null && pOwner instanceof IElement) {
0325: IElement pElement = (IElement) pOwner;
0326:
0327: // Retrieve the default type from the language manager.
0328: ETList<ILanguage> pLanguages = pElement.getLanguages();
0329: if (pLanguages != null) {
0330: int count = pLanguages.size();
0331: for (int i = 0; i < count && (retType == null); i++) {
0332: ILanguage lang = (ILanguage) pLanguages.get(i);
0333: retType = getAttributeDefaultType(lang);
0334: }
0335: } else {
0336: // Since no languages were defined for the element I must use the default
0337: // language.
0338: ILanguage defLang = getDefaultLanguage(pElement);
0339: if (defLang != null) {
0340: retType = getAttributeDefaultType(defLang);
0341: }
0342: }
0343:
0344: // If I have not been able to find a default attribute type check the UML
0345: // language. If I can not find a default type in the UML language the
0346: // user has edited the configuration file and screwed themselves.
0347: if (retType == null) {
0348: ILanguage pUMLLang = getLanguage("UML");
0349: if (pUMLLang != null) {
0350: retType = getAttributeDefaultType(pUMLLang);
0351: }
0352: }
0353: }
0354: return retType;
0355: }
0356:
0357: /**
0358: * Retrieves an attributes default data type for a specified language.
0359: *
0360: * @param pLanguage [in] The language that specifies the default data type
0361: * @param pType [out] The data type
0362: */
0363: private ILanguageDataType getAttributeDefaultType(
0364: ILanguage pLanguage) {
0365: ILanguageDataType pDataType = pLanguage
0366: .getAttributeDefaultType();
0367: return pDataType;
0368: }
0369:
0370: /**
0371: * Retrieves the default data type for a new operation. If a data type is
0372: * not defined as the default type then the default type will be retrieved
0373: * from the UML language.
0374: *
0375: * @param pOwner [in] The element that contains the operation
0376: * @param pType [out] The data type
0377: */
0378: public ILanguageDataType getOperationDefaultType(Object pOwner) {
0379: ILanguageDataType retType = null;
0380: if (pOwner != null && pOwner instanceof IElement) {
0381: IElement pElement = (IElement) pOwner;
0382:
0383: // Retrieve the default type from the language manager.
0384: ETList<ILanguage> pLangs = pElement.getLanguages();
0385: if (pLangs != null) {
0386: int count = pLangs.size();
0387: for (int i = 0; i < count && (retType == null); i++) {
0388: ILanguage lang = (ILanguage) pLangs.get(i);
0389: retType = getOperationDefaultType(lang);
0390: }
0391: } else {
0392: // Since no languages were defined for the element I must use the default
0393: // language.
0394: ILanguage defLang = getDefaultLanguage(pElement);
0395: if (defLang != null) {
0396: retType = getOperationDefaultType(defLang);
0397: }
0398: }
0399:
0400: // If I have not been able to find a default attribute type check the UML
0401: // language. If I can not find a default type in the UML language the
0402: // user has edited the configuration file and screwed themselves.
0403: if (retType == null) {
0404: ILanguage pUMLLang = getLanguage("UML");
0405: if (pUMLLang != null) {
0406: retType = getOperationDefaultType(pUMLLang);
0407: }
0408: }
0409: }
0410: return retType;
0411: }
0412:
0413: /**
0414: * Retrieves an operation default data type for a specified language.
0415: *
0416: * @param pLanguage [in] The language that specifies the default data type
0417: * @param pType [out] The data type
0418: */
0419: private ILanguageDataType getOperationDefaultType(
0420: ILanguage pLanguage) {
0421: ILanguageDataType pDataType = pLanguage
0422: .getOperationDefaultType();
0423: return pDataType;
0424: }
0425:
0426: /**
0427: * Retrieves the default langauge information for a specified element.
0428: * The name of the default language will be retrieved from the project that
0429: * contains a specified element.
0430: *
0431: * @param pElement [in] Must implement the IElement interface
0432: * @param pLanguage [out] The default langauge
0433: */
0434: public ILanguage getDefaultLanguage(Object pElement) {
0435: ILanguage retLang = null;
0436: if (pElement != null && pElement instanceof IElement) {
0437: IElement pElem = (IElement) pElement;
0438: IProject proj = pElem.getProject();
0439: if (proj != null) {
0440: String langName = proj.getDefaultLanguage();
0441: retLang = getLanguage(langName);
0442: }
0443: }
0444: return retLang;
0445: }
0446:
0447: /**
0448: * Returns a list of file extensions for the specified language
0449: *
0450: * @param language[in] the language you want file extensions for
0451: * @param pVal[out] list of languages
0452: *
0453: * @return HRESULT
0454: */
0455: public IStrings getFileExtensionsForLanguage(String language) {
0456: IStrings retVal = new Strings();
0457:
0458: // m_ExtensionMap maps extensions to languages.
0459: // For all entries in m_ExtensionMap where language == @a language,
0460: // add that language to the list of strings.
0461: Enumeration<String> iter = m_ExtensionMap.elements();
0462: Enumeration<String> iter2 = m_ExtensionMap.keys();
0463: while (iter.hasMoreElements()) {
0464: String extension = iter2.nextElement();
0465: String extLang = iter.nextElement();
0466: if (language.equals(extLang)) {
0467: retVal.add(extension);
0468: }
0469: }
0470:
0471: return retVal;
0472: }
0473:
0474: /**
0475: * Returns a list of file extensions for the specified language
0476: *
0477: * @param language[in] the language you want file extensions for
0478: * @param pVal[out] list of languages
0479: *
0480: * @return HRESULT
0481: */
0482: public IStrings getFileExtensionsForLanguage(ILanguage pLanguage) {
0483: IStrings retVal = null;
0484: if (pLanguage != null) {
0485: String langName = pLanguage.getName();
0486: retVal = getFileExtensionsForLanguage(langName);
0487: }
0488: return retVal;
0489: }
0490:
0491: /**
0492: * Retrieves the list of supported language. The output will
0493: * be a delemeted string. The deleminter is '|'.
0494: *
0495: * @param pVal [out] The list of language names.
0496: */
0497: public String getSupportedLanguagesAsString() {
0498: String retLang = "";
0499: IStrings langNames = getSupportedLanguages();
0500: if (langNames != null) {
0501: int count = langNames.getCount();
0502: String separator = "|";
0503: for (int i = 0; i < count; i++) {
0504: String curName = langNames.item(i);
0505: if (curName.length() > 0) {
0506: if (retLang.length() > 0) {
0507: retLang += separator;
0508: }
0509: retLang += curName;
0510: }
0511: }
0512: }
0513: return retLang;
0514: }
0515:
0516: /**
0517: * returns a "default" setting for the language
0518: *
0519: * @param language[in] the name of the language to get the default for
0520: * @param name[in] the name of the setting
0521: * @param value[out] the value of the setting
0522: */
0523: public String getDefaultForLanguage(String language, String name) {
0524: String retVal = "";
0525: ILanguage pLang = getLanguage(language);
0526: if (pLang != null) {
0527: retVal = pLang.getDefault(name);
0528: }
0529: return retVal;
0530: }
0531:
0532: /**
0533: * Returns the default extension for a source file for a particular language
0534: *
0535: * @param language[in] the language
0536: * @param extension[out] the default source file extension
0537: */
0538: public String getDefaultSourceFileExtensionForLanguage(
0539: String language) {
0540: String retVal = "";
0541: ILanguage lang = getLanguage(language);
0542: if (lang != null) {
0543: retVal = lang.getDefaultSourceFileExtension();
0544: }
0545: return retVal;
0546: }
0547:
0548: /**
0549: *
0550: * Retrieves all the languages that contain ICodeGenerationScripts
0551: *
0552: * @param pVal[out] The collection of languages
0553: *
0554: * @return HRESULT
0555: *
0556: */
0557: public ETList<ILanguage> getLanguagesWithCodeGenSupport() {
0558: ETList<ILanguage> retLangs = null;
0559: ETList<ILanguage> langs = getSupportedLanguages2();
0560: if (langs != null) {
0561: int count = langs.size();
0562: for (int i = 0; i < count; i++) {
0563: ILanguage pLang = langs.get(i);
0564: ETList<ICodeGenerationScript> pScripts = pLang
0565: .getCodeGenerationScripts();
0566: if (pScripts != null) {
0567: int numScripts = pScripts.size();
0568: if (numScripts > 0) {
0569: if (retLangs == null) {
0570: retLangs = new ETArrayList<ILanguage>();
0571: }
0572: retLangs.add(pLang);
0573: }
0574: }
0575: }
0576: }
0577: return retLangs;
0578: }
0579:
0580: /**
0581: * Retrieves a collection of file filters for a specified language.
0582: *
0583: * @param langaugeName [in] The name of the language.
0584: * @param groupString [out] The extensions.
0585: * @param
0586: */
0587: public ETList<ILanguageFilter> getFileExtensionFilters(
0588: String languageName) {
0589: ETList<ILanguageFilter> retVal = new ETArrayList<ILanguageFilter>();
0590:
0591: // m_FilterMap maps extensions to languages.
0592: // For all entries in m_ExtensionMap where language == @a language,
0593: // add that language to the list of strings.
0594: Enumeration iter = m_FilterMap.keys();
0595: while (iter.hasMoreElements()) {
0596: String langName = (String) iter.nextElement();
0597: if (languageName.equals(langName)) {
0598: ETList<ILanguageFilter> filters = m_FilterMap
0599: .get(langName);
0600: if (filters != null) {
0601: retVal = filters;
0602: }
0603: }
0604: }
0605:
0606: return retVal;
0607: }
0608:
0609: /**
0610: * Retrieves a collection of file filters for a specified language.
0611: *
0612: */
0613: public ETList<ILanguageFilter> getFileExtensionFilters(
0614: ILanguage language) {
0615: ETList<ILanguageFilter> retVal = new ETArrayList<ILanguageFilter>();
0616: if (language != null) {
0617: String langName = language.getName();
0618: retVal = getFileExtensionFilters(langName);
0619: }
0620: return retVal;
0621: }
0622:
0623: /**
0624: *
0625: * Populates this manager with the contents of the given
0626: * configuration file.
0627: *
0628: * @return HRESULT
0629: *
0630: */
0631: private void initializeManager() {
0632: try {
0633: String loc = getActualConfigLocation();
0634: if (loc != null && loc.length() > 0) {
0635: // For now, we'll just keep the DOM in memory.
0636: // We may want to eventually get rid of this,
0637: // as it will certainly use less memory
0638: Document doc = XMLManip.getDOMDocument(loc);
0639: if (doc != null) {
0640: loadSupportedLanguages(doc);
0641: loadFileExtensions(doc);
0642: }
0643: }
0644: } catch (Exception e) {
0645: }
0646: }
0647:
0648: /**
0649: *
0650: * Determines the default location for the Languages.etc
0651: * file.
0652: *
0653: * @param pVal [out] The location of the config file
0654: * @return HRESULT
0655: *
0656: */
0657: private String getActualConfigLocation() {
0658: String retLoc = "";
0659: String homeLoc = getConfigLocation();
0660: if (homeLoc != null && homeLoc.length() > 0) {
0661: homeLoc += "Languages.etc";
0662: retLoc = homeLoc;
0663: }
0664: return retLoc;
0665: }
0666:
0667: /**
0668: * Retrieves the language details from the configuration file. The configuration
0669: * file location will be retrieved from the applications perferences. After the
0670: * language is retrieved it will be added to the language lookup table.
0671: *
0672: * @param langName [in] The langauge to retrieved
0673: * @param pVal [out] The language details
0674: */
0675: private ILanguage retrieveLanguage(String langName) {
0676: ILanguage retLang = null;
0677: Node node = retrieveLanguageNode(langName);
0678: if (node != null) {
0679: retLang = retrieveLanguageDetails(node);
0680: if (retLang != null) {
0681: m_LanguageMap.put(langName, retLang);
0682: } else {
0683: Log.out("LM_E_INVALID_LANG_NAME");
0684: }
0685: }
0686: return retLang;
0687: }
0688:
0689: private Node retrieveLanguageNode(String langName) {
0690: Node retNode = null;
0691: Document configDoc = getConfigurationDocument();
0692: if (configDoc != null) {
0693: retNode = findLanguage(configDoc, langName);
0694: if (retNode == null) {
0695: // if the language was not defined in the configuration file check if
0696: // the language is defined by a language referenece. If a language
0697: // referenece exist retrieve the language from the referenced file.
0698: Document refDoc = locateReferenced(configDoc, langName);
0699: if (refDoc != null) {
0700: retNode = findLanguage(refDoc, langName);
0701: }
0702: }
0703: }
0704: return retNode;
0705: }
0706:
0707: private Node findLanguage(Document pDoc, String langName) {
0708: Node retNode = null;
0709: String xpath = "//Language[@type=\"";
0710: xpath += findLanguageName(langName);
0711: xpath += "\"]";
0712: retNode = pDoc.selectSingleNode(xpath);
0713: return retNode;
0714: }
0715:
0716: private String findLanguageName(String langName) {
0717: String retLang = langName;
0718: int count = m_LanguageNames.getCount();
0719: for (int i = 0; i < count; i++) {
0720: String realName = m_LanguageNames.item(i);
0721: if (realName.length() > 0) {
0722: if (realName.toLowerCase().equals(
0723: langName.toLowerCase())) {
0724: retLang = realName;
0725: break;
0726: }
0727: }
0728: }
0729: return retLang;
0730: }
0731:
0732: private Document locateReferenced(Document pDoc, String langName) {
0733: Document retDoc = null;
0734:
0735: String xpath = "//LanguageRef[@type=\"";
0736: xpath += findLanguageName(langName);
0737: xpath += "\"]";
0738: Node pNode = pDoc.selectSingleNode(xpath);
0739: if (pNode != null) {
0740: String location = XMLManip.getAttributeValue(pNode,
0741: "location");
0742: String home = getConfigLocation();
0743: if (home != null && home.length() > 0) {
0744: String docLoc = home;
0745: if (location != null) {
0746: docLoc += location;
0747: }
0748:
0749: if (docLoc != null && docLoc.length() > 0) {
0750: retDoc = URILocator.retrieveDocument(docLoc);
0751: }
0752: }
0753: }
0754: return retDoc;
0755: }
0756:
0757: /**
0758: * Retrieves the XML Document that is the Language configuration.
0759: *
0760: * @param pVal [out] The configuraton document
0761: */
0762: private Document getConfigurationDocument() {
0763: Document retDoc = null;
0764: String configLoc = getActualConfigLocation();
0765: if (configLoc != null && configLoc.length() > 0) {
0766: retDoc = XMLManip.getDOMDocument(configLoc);
0767: }
0768: return retDoc;
0769: }
0770:
0771: /**
0772: * Retrieves the details about a specific language.
0773: *
0774: * @param pLanguageNode [in] The XML node that represents the language
0775: * @param pVal [out] The language details
0776: */
0777: private ILanguage retrieveLanguageDetails(Node pLanguageNode) {
0778: ILanguage retLang = new Language();
0779:
0780: getLanguageName(pLanguageNode, retLang);
0781: getDataTypes(pLanguageNode, retLang);
0782: getLanguageSyntax(pLanguageNode, retLang);
0783: getCodeGenScripts(pLanguageNode, retLang);
0784: getExpansionOverrides(pLanguageNode, retLang);
0785: getParsers(pLanguageNode, retLang);
0786: getContexts(pLanguageNode, retLang);
0787: getLibraries(pLanguageNode, retLang);
0788: getFormatDefinitions(pLanguageNode, retLang);
0789: getDefaults(pLanguageNode, retLang);
0790: getSupportedFeatures(pLanguageNode, retLang);
0791: getCollectionTypes(pLanguageNode, retLang);
0792:
0793: return retLang;
0794: }
0795:
0796: /**
0797: * Retrieves the syntax of a language from a XML file and
0798: * initializes the ILanguage object
0799: *
0800: * @param manip [out] The XMLManip use to retrieve XML information.
0801: * @param pLanguageNode [in] The XMLnode that contains language information.
0802: * @param *pLang [in] The ILanguage object to update.
0803: */
0804: private void getLanguageSyntax(Node pLanguageNode, ILanguage pLang) {
0805: ETList<ISyntaxToken> pTokens = new ETArrayList<ISyntaxToken>();
0806: List pNodeList = pLanguageNode.selectNodes("Syntax/Token");
0807: if (pNodeList != null) {
0808: int count = pNodeList.size();
0809: for (int i = 0; i < count; i++) {
0810: Node pNode = (Node) pNodeList.get(i);
0811: ISyntaxToken token = getSyntaxToken(pNode);
0812: if (token != null) {
0813: pTokens.add(token);
0814: }
0815: }
0816: }
0817:
0818: // I have to make sure that I acutally add the collection to the
0819: // language defintion.
0820: ILanguageSyntax pSyntax = new LanguageSyntax();
0821: pSyntax.setSyntaxTokens(pTokens);
0822: pLang.setSyntax(pSyntax);
0823: }
0824:
0825: /**
0826: * Retrieves the information about a syntax token from a XML file
0827: * and initializes the ILanguagae object
0828: *
0829: * @param manip [out] The XMLManip use to retrieve XML information.
0830: * @param pLanguageNode [in] The XMLnode that contains language information.
0831: * @param *pLang [in] The ILanguage object to update.
0832: */
0833: private ISyntaxToken getSyntaxToken(Node pNode) {
0834: ISyntaxToken retToken = new SyntaxToken();
0835: String name = XMLManip.getAttributeValue(pNode, "name");
0836: retToken.setName(name);
0837:
0838: String type = XMLManip.getAttributeValue(pNode, "kind");
0839: int typeKind = ITokenKind.KEYWORD;
0840: if (type != null && type.equals("Operator")) {
0841: typeKind = ITokenKind.OPERATOR;
0842: } else if (type != null && type.equals("Delimiter")) {
0843: typeKind = ITokenKind.DELIMITER;
0844: }
0845:
0846: retToken.setKind(typeKind);
0847:
0848: String category = XMLManip.getAttributeValue(pNode, "category");
0849: retToken.setCategory(category);
0850:
0851: String syntaxType = XMLManip.getAttributeValue(pNode, "type");
0852: retToken.setType(syntaxType);
0853:
0854: return retToken;
0855: }
0856:
0857: /**
0858: * Retrieves the code generation scrips for a language from
0859: * a XML file and initializes the ILanguage object
0860: *
0861: * @param manip [out] The XMLManip use to retrieve XML information.
0862: * @param pLanguageNode [in] The XMLnode that contains language information.
0863: * @param *pLang [in] The ILanguage object to update.
0864: */
0865: private void getCodeGenScripts(Node pLanguageNode, ILanguage pLang) {
0866: ETList<ICodeGenerationScript> pScripts = new ETArrayList<ICodeGenerationScript>();
0867: List pNodeList = pLanguageNode
0868: .selectNodes("CodeGeneration/Script");
0869: if (pNodeList != null) {
0870: // Find out where the scripts live. The XML contains script paths relative
0871: // to the Home Location
0872: String home = getConfigLocation();
0873: if (home != null && home.length() > 0) {
0874: int count = pNodeList.size();
0875: for (int i = 0; i < count; i++) {
0876: Node pNode = (Node) pNodeList.get(i);
0877: ICodeGenerationScript script = getScript(pNode,
0878: home);
0879: if (script != null) {
0880: // Set up the backpoint from the script to the
0881: // language that owns that script
0882: script.setLanguage(pLang);
0883: pScripts.add(script);
0884: }
0885: }
0886: }
0887: }
0888:
0889: // I have to make sure that I acutally add the collection to the
0890: // language defintion.
0891: pLang.setCodeGenerationScripts(pScripts);
0892: }
0893:
0894: /**
0895: * Retrieves a code generation script information from a XML file
0896: * and initializes the ILanguagae object
0897: *
0898: * @param manip [out] The XMLManip use to retrieve XML information.
0899: * @param pLanguageNode [in] The XMLnode that contains language information.
0900: * @param *pLang [in] The ILanguage object to update.
0901: */
0902: private ICodeGenerationScript getScript(Node pNode,
0903: String homeLocation) {
0904: ICodeGenerationScript retScript = new CodeGenerationScript();
0905:
0906: String name = XMLManip.getAttributeValue(pNode, "event");
0907: retScript.setName(name);
0908:
0909: String location = XMLManip.getAttributeValue(pNode, "location");
0910: String scriptLoc = homeLocation + location;
0911: retScript.setFile(scriptLoc);
0912:
0913: return retScript;
0914: }
0915:
0916: /**
0917: *
0918: * Gathers any nodes that override the Default ExpansionVariables and place those on the Language passed in.
0919: *
0920: * @param manip[in] The manip object
0921: * @param pLanguageNode[in] The node representing the current language
0922: * @param pLang[in] The COM object for the Language
0923: *
0924: * @return HRESULT
0925: *
0926: */
0927: private void getExpansionOverrides(Node pLanguageNode,
0928: ILanguage pLang) {
0929: List pNodeList = pLanguageNode
0930: .selectNodes("ExpansionVariables/ExpansionVar");
0931: if (pNodeList != null) {
0932: // Find out where the scripts live. The XML contains script paths relative
0933: // to the Home Location
0934: String home = getConfigLocation();
0935: if (home != null && home.length() > 0) {
0936: int count = pNodeList.size();
0937: if (count > 0) {
0938: ICoreProduct prod = ProductRetriever
0939: .retrieveProduct();
0940: if (prod != null) {
0941: ITemplateManager pMan = prod
0942: .getTemplateManager();
0943: if (pMan != null) {
0944: IVariableFactory pFact = pMan.getFactory();
0945: if (pFact != null) {
0946: ETList<IExpansionVariable> vars = new ETArrayList<IExpansionVariable>();
0947: for (int i = 0; i < count; i++) {
0948: Node node = (Node) pNodeList.get(i);
0949: IExpansionVariable pVar = pFact
0950: .createVariable(node);
0951: if (pVar != null) {
0952: vars.add(pVar);
0953: }
0954: }
0955: pLang.setExpansionVariables(vars);
0956: }
0957: }
0958: }
0959: }
0960: }
0961: }
0962: }
0963:
0964: /**
0965: *
0966: * Retrieves the default configuration location. On a debug box,
0967: * this is typically c:\\development\\uml\\config
0968: *
0969: * @return The absolute path to the config location
0970: *
0971: */
0972: private String getConfigHome() {
0973: String homeLoc = "";
0974: ICoreProduct prod = ProductRetriever.retrieveProduct();
0975: if (prod != null) {
0976: IConfigManager conMan = prod.getConfigManager();
0977: if (conMan != null) {
0978: homeLoc = conMan.getDefaultConfigLocation();
0979: }
0980: }
0981: return homeLoc;
0982: }
0983:
0984: /**
0985: * Retrieves the parsers for a language from a XML file and
0986: * initializes the ILanguage object
0987: *
0988: * @param manip [out] The XMLManip use to retrieve XML information.
0989: * @param pLanguageNode [in] The XMLnode that contains language information.
0990: * @param *pLang [in] The ILanguage object to update.
0991: */
0992: private void getParsers(Node pLanguageNode, ILanguage pLang) {
0993: List pNodeList = pLanguageNode.selectNodes("Parsers/Parser");
0994: if (pNodeList != null) {
0995: int count = pNodeList.size();
0996: for (int i = 0; i < count; i++) {
0997: Node pNode = (Node) pNodeList.get(i);
0998: String name = XMLManip.getAttributeValue(pNode, "name");
0999: String clsid = XMLManip.getAttributeValue(pNode,
1000: "parser");
1001: pLang.addParser(name, clsid);
1002: }
1003: }
1004: }
1005:
1006: /**
1007: * Retrieves the context for a language from a XML file and
1008: * initializes the ILanguage object
1009: *
1010: * @param manip [out] The XMLManip use to retrieve XML information.
1011: * @param pLanguageNode [in] The XMLnode that contains language information.
1012: * @param *pLang [in] The ILanguage object to update.
1013: */
1014: private void getContexts(Node pLanguageNode, ILanguage pLang) {
1015: List pNodeList = pLanguageNode.selectNodes("Contexts/Context");
1016: if (pNodeList != null) {
1017: int count = pNodeList.size();
1018: for (int i = 0; i < count; i++) {
1019: Node pNode = (Node) pNodeList.get(i);
1020: String name = XMLManip.getAttributeValue(pNode, "kind");
1021: String clsid = XMLManip.getAttributeValue(pNode,
1022: "instantiationDirective");
1023: pLang.addContext(name, clsid);
1024: }
1025: }
1026: }
1027:
1028: /**
1029: * Retrieves the libraries for a language from a XML file and
1030: * initializes the ILanguage object
1031: *
1032: * @param manip [out] The XMLManip use to retrieve XML information.
1033: * @param pLanguageNode [in] The XMLnode that contains language information.
1034: * @param *pLang [in] The ILanguage object to update.
1035: */
1036: private void getLibraries(Node pLanguageNode, ILanguage pLang) {
1037: List pNodeList = pLanguageNode.selectNodes("Libraries/Library"); // NOI18N
1038:
1039: if (pNodeList != null) {
1040: int count = pNodeList.size();
1041: for (int i = 0; i < count; i++) {
1042: Node pNode = (Node) pNodeList.get(i);
1043: String name = XMLManip.getAttributeValue(pNode, "name"); // NOI18N
1044: String path = XMLManip.getAttributeValue(pNode, "path"); // NOI18N
1045:
1046: String token = null;
1047: if (path != null && path.length() > 0) {
1048: if (path.indexOf("\\") != -1) // NOI18N
1049: token = "\\"; // NOI18N
1050:
1051: else if (path.indexOf("/") != -1) // NOI18N
1052: token = "/"; // NOI18N
1053:
1054: if (token != null)
1055: path = path.replace(token, File.separator)
1056: .trim();
1057: }
1058:
1059: String fileName = "modules" + File.separator + path
1060: + ".etd"; // NOI18N
1061: String fullPath = InstalledFileLocator.getDefault()
1062: .locate(fileName, "org.netbeans.modules.uml",
1063: false) // NOI18N
1064: .getAbsolutePath();
1065: // remove the .etd extension before storage of path
1066: pLang.addLibrary(name, fullPath.substring(0, fullPath
1067: .length() - 4));
1068: }
1069: }
1070: }
1071:
1072: // private void getLibraries(Node pLanguageNode, ILanguage pLang)
1073: // {
1074: // List pNodeList = pLanguageNode.selectNodes("Libraries/Library");
1075: // String home = getConfigLocation();
1076: //// home = InstalledFileLocator.getDefault().locate(
1077: //// "modules/languagedefs", "org.netbeans.modules.uml", false).getAbsolutePath();
1078: //
1079: // if (pNodeList != null)
1080: // {
1081: // int count = pNodeList.size();
1082: // for (int i=0; i<count; i++)
1083: // {
1084: // Node pNode = (Node)pNodeList.get(i);
1085: // String name = XMLManip.getAttributeValue(pNode, "name");
1086: // String path = XMLManip.getAttributeValue(pNode, "path");
1087: // //System.out.println("home="+home + " path="+path);
1088: //
1089: // // Convert file separator, if any, in the path to platform-specific file separator.
1090: // // Fix for CR # 6389098
1091: // String token = null;
1092: // if(path != null && path.length() > 0)
1093: // {
1094: // if (path.indexOf("\\") != -1) {
1095: // token = "\\";
1096: // } else if (path.indexOf("/") != -1) {
1097: // token = "/";
1098: // }
1099: // if (token != null) {
1100: // path = path.replace(token, File.separator ).trim();
1101: // }
1102: // }
1103: // //System.out.println("path after="+path);
1104: //
1105: // String fulPath = "";
1106: // if (home != null && home.length() > 0)
1107: // {
1108: // // Get the directory separator right:
1109: // // fulPath = new File(home, path).toString();
1110: // File aFile = new File(home, path);
1111: // if (aFile != null)
1112: // {
1113: // try {
1114: // fulPath = aFile.getCanonicalPath();
1115: // } catch (IOException ex) {
1116: // ex.printStackTrace();
1117: // }
1118: // }
1119: // //System.out.println("fullPath(toString)="+fulPath);
1120: // }
1121: // pLang.addLibrary(name, fulPath);
1122: // }
1123: // }
1124: // }
1125:
1126: /**
1127: * Retrieve the DOM node that specifies how to format a
1128: * model elments data.
1129: *
1130: * @param manip [out] The XMLManip use to retrieve XML information.
1131: * @param pLanguageNode [in] The XMLnode that contains language information.
1132: * @param *pLang [in] The ILanguage object to update.
1133: */
1134: private void getFormatDefinitions(Node pLanguageNode,
1135: ILanguage pLang) {
1136: Node pNode = pLanguageNode
1137: .selectSingleNode("FormatDefinitions/PropertyDefinitions");
1138: if (pNode != null) {
1139: pLang.setFormatDefinitions(pNode);
1140: }
1141: }
1142:
1143: /**
1144: * Install of the langauge that are supported by language manager.
1145: * A XML configuration file is used to define the languages supported
1146: * by the language manager.
1147: *
1148: * @param pDoc [in] The configuration file.
1149: */
1150: private void loadSupportedLanguages(Document pDoc) {
1151: if (m_LanguageNames == null) {
1152: m_LanguageNames = new Strings();
1153: retrieveLanguagesNames(pDoc, "//Language", m_LanguageNames);
1154: retrieveLanguagesNames(pDoc, "//LanguageRef",
1155: m_LanguageNames);
1156: }
1157: }
1158:
1159: private void retrieveLanguagesNames(Document pDoc, String xpath,
1160: IStrings pList) {
1161: List pNodeList = pDoc.selectNodes(xpath);
1162: if (pNodeList != null) {
1163: int count = pNodeList.size();
1164: for (int i = 0; i < count; i++) {
1165: Node pNode = (Node) pNodeList.get(i);
1166: String name = XMLManip.getAttributeValue(pNode, "type");
1167: //String location = XMLManip.getAttributeValue(pNode, "location");
1168:
1169: if (name != null && name.length() > 0) {
1170: pList.add(name);
1171: }
1172: }
1173: }
1174: }
1175:
1176: /**
1177: * Retrieves all of the extensions to use when retrieving a language
1178: * for a specific file. Each extension must map to one and only one
1179: * language.
1180: *
1181: * @param pDoc [in] The configuration file.
1182: */
1183: private void loadFileExtensions(Document pDoc) {
1184: List pNodeList = pDoc.selectNodes("//Extensions/Extension");
1185: if (pNodeList != null) {
1186: int count = pNodeList.size();
1187: for (int i = 0; i < count; i++) {
1188: Node pNode = (Node) pNodeList.get(i);
1189: String name = XMLManip.getAttributeValue(pNode, "type");
1190: String language = XMLManip.getAttributeValue(pNode,
1191: "language");
1192:
1193: if (name != null && name.length() > 0) {
1194: m_ExtensionMap.put(name, language);
1195: }
1196: }
1197: }
1198:
1199: m_FilterMap.clear();
1200: List pFilterList = pDoc.selectNodes("//Extensions/Filter");
1201: if (pFilterList != null) {
1202: int count = pFilterList.size();
1203: for (int i = 0; i < count; i++) {
1204: Node pNode = (Node) pFilterList.get(i);
1205: String name = XMLManip.getAttributeValue(pNode, "name");
1206: String language = XMLManip.getAttributeValue(pNode,
1207: "language");
1208: String filter = XMLManip.getAttributeValue(pNode,
1209: "value");
1210:
1211: ETList<ILanguageFilter> pFilters = null;
1212: if (m_FilterMap.containsKey(language)) {
1213: pFilters = m_FilterMap.get(language);
1214: } else {
1215: pFilters = new ETArrayList<ILanguageFilter>();
1216: m_FilterMap.put(language, pFilters);
1217: }
1218:
1219: ILanguageFilter pFilter = new LanguageFilter();
1220: pFilter.setName(name);
1221: pFilter.setFilter(filter);
1222: pFilters.add(pFilter);
1223: }
1224: }
1225: }
1226:
1227: /**
1228: * Retrieve the language definition
1229: *
1230: * @param filename [in] The file name.
1231: *
1232: * @return
1233: */
1234: private String getLanguageNameForFile(String filename) {
1235: String retVal = "";
1236: String ext = StringUtilities.getExtension(filename);
1237: retVal = (String) m_ExtensionMap.get(ext);
1238: return retVal;
1239: }
1240:
1241: /**
1242: * Loads "default" settings for a particular language
1243: *
1244: * @param manip[in] the XML manipulation object
1245: * @param pLanguageNode[in] the XML DOM Node to load the data from
1246: * @param pLang[in] the ILanguage object to load defaults for.
1247: */
1248: private void getDefaults(Node pLanguageNode, ILanguage pLang) {
1249: List pNodeList = pLanguageNode.selectNodes("Defaults/Default");
1250: if (pNodeList != null) {
1251: int count = pNodeList.size();
1252: for (int i = 0; i < count; i++) {
1253: Node pNode = (Node) pNodeList.get(i);
1254: String name = XMLManip.getAttributeValue(pNode, "name");
1255: String value = XMLManip.getAttributeValue(pNode,
1256: "value");
1257: pLang.setDefault(name, value);
1258: }
1259: }
1260: }
1261:
1262: private void getSupportedFeatures(Node pLanguageNode,
1263: ILanguage pLang) {
1264: List pNodeList = pLanguageNode
1265: .selectNodes("SupportedFeatures/Feature");
1266: if (pNodeList != null) {
1267: int count = pNodeList.size();
1268: for (int i = 0; i < count; i++) {
1269: Node pNode = (Node) pNodeList.get(i);
1270: String name = XMLManip.getAttributeValue(pNode, "name");
1271: String value = XMLManip.getAttributeValue(pNode,
1272: "value");
1273: boolean bValue = false;
1274: if (value != null && value.toLowerCase().equals("true")) {
1275: bValue = true;
1276: }
1277: pLang.setFeatureSupported(name, bValue);
1278: }
1279: }
1280: }
1281:
1282: /**
1283: * Retrieves the name of the language and initializes the ILanguage
1284: * object
1285: *
1286: * @param manip [out] The XMLManip use to retrieve XML information.
1287: * @param pLanguageNode [in] The XMLnode that contains language information.
1288: * @param *pLang [in] The ILanguage object to update.
1289: */
1290: private void getLanguageName(Node pLanguageNode, ILanguage pLang) {
1291: String name = XMLManip.getAttributeValue(pLanguageNode, "type");
1292: pLang.setName(name);
1293: }
1294:
1295: private void getCollectionTypes(Node pLanguageNode, ILanguage pLang) {
1296: String xpath = "Collections/Collection";
1297:
1298: ETList<CollectionType> types = new ETArrayList<CollectionType>();
1299: List pNodeList = pLanguageNode.selectNodes(xpath);
1300: if (pNodeList != null) {
1301: int count = pNodeList.size();
1302: for (int i = 0; i < count; i++) {
1303: Node node = (Node) pNodeList.get(i);
1304: CollectionType type = getCollectionType(node);
1305: if (type != null) {
1306: types.add(type);
1307: }
1308: }
1309: }
1310:
1311: // I have to make sure that I acutally add the collection to the
1312: // language defintion.
1313: pLang.setCollectionTypes(types);
1314: }
1315:
1316: /**
1317: * Retrieves a collection type information from a XML file and initializes
1318: * the ILanguage object
1319: *
1320: * @param pNode The XML node for the collection type data
1321: */
1322: private CollectionType getCollectionType(Node pNode) {
1323: CollectionType retVal = new CollectionType();
1324: String name = XMLManip.getAttributeValue(pNode, "name");
1325: retVal.setName(name);
1326:
1327: String packName = XMLManip.getAttributeValue(pNode, "package");
1328: retVal.setPackageName(packName);
1329:
1330: boolean userdefined = XMLManip.getAttributeBooleanValue(pNode,
1331: "userdefined");
1332: retVal.setUserDefined(userdefined);
1333: ;
1334:
1335: boolean defaultValue = XMLManip.getAttributeBooleanValue(pNode,
1336: "default", false);
1337: retVal.setDefaultType(defaultValue);
1338:
1339: return retVal;
1340: }
1341:
1342: /**
1343: * Retrieves the data types from a XML file and initializes the ILanguage
1344: * object
1345: *
1346: * @param manip [out] The XMLManip use to retrieve XML information.
1347: * @param pLanguageNode [in] The XMLnode that contains language information.
1348: * @param *pLang [in] The ILanguage object to update.
1349: */
1350: private void getDataTypes(Node pLanguageNode, ILanguage pLang) {
1351: String xpath = "DataTypes/DataType";
1352:
1353: ETList<ILanguageDataType> pDataTypes = new ETArrayList<ILanguageDataType>();
1354: List pNodeList = pLanguageNode.selectNodes(xpath);
1355: if (pNodeList != null) {
1356: int count = pNodeList.size();
1357: for (int i = 0; i < count; i++) {
1358: Node node = (Node) pNodeList.get(i);
1359: ILanguageDataType pDataType = getDataType(node);
1360: if (pDataType != null) {
1361: pDataTypes.add(pDataType);
1362: boolean attrDefault = pDataType
1363: .getIsDefaultAttributeType();
1364: if (attrDefault) {
1365: pLang.setAttributeDefaultType(pDataType);
1366: }
1367:
1368: boolean opDefault = pDataType
1369: .getIsOperationDefaultType();
1370: if (opDefault) {
1371: pLang.setOperationDefaultType(pDataType);
1372: }
1373: }
1374: }
1375: }
1376:
1377: // I have to make sure that I acutally add the collection to the
1378: // language defintion.
1379: pLang.setDataTypes(pDataTypes);
1380: }
1381:
1382: /**
1383: * Retrieves a data type information from a XML file and initializes
1384: * the ILanguage object
1385: *
1386: * @param manip [out] The XMLManip use to retrieve XML information.
1387: * @param pLanguageNode [in] The XMLnode that contains language information.
1388: * @param *pLang [in] The ILanguage object to update.
1389: */
1390: private ILanguageDataType getDataType(Node pNode) {
1391: ILanguageDataType retVal = new LanguageDataType();
1392: String name = XMLManip.getAttributeValue(pNode, "name");
1393: retVal.setName(name);
1394:
1395: String type = XMLManip.getAttributeValue(pNode, "type");
1396:
1397: int typeKind = IDataTypeKind.PRIMITIVE;
1398: if (type != null && type.equals("user-defined")) {
1399: typeKind = IDataTypeKind.USER_DEFINIED;
1400: } else {
1401: // Only Primitive data types have a UML Name.
1402: String umlNameVal = XMLManip
1403: .getAttributeValue(pNode, "uml");
1404: if (umlNameVal != null && umlNameVal.length() > 0) {
1405: retVal.setUMLName(umlNameVal);
1406: }
1407: }
1408: retVal.setKind(typeKind);
1409:
1410: String defaultVal = XMLManip.getAttributeValue(pNode,
1411: "default_value");
1412: retVal.setDefaultValue(defaultVal);
1413:
1414: String scope = XMLManip.getAttributeValue(pNode, "scope");
1415: retVal.setScope(scope);
1416:
1417: boolean attrDefault = XMLManip.getAttributeBooleanValue(pNode,
1418: "attributedefault");
1419: retVal.setIsDefaultAttributeType(attrDefault);
1420:
1421: boolean opDefault = XMLManip.getAttributeBooleanValue(pNode,
1422: "operationdefault");
1423: retVal.setIsOperationDefaultType(opDefault);
1424:
1425: return retVal;
1426: }
1427: }
|