001: /**
002: *
003: */package com.bostechcorp.cbesb.common.util.generators;
004:
005: import java.util.Enumeration;
006: import java.util.HashMap;
007: import java.util.Properties;
008:
009: import org.jdom.Element;
010: import org.jdom.Namespace;
011:
012: import com.bostechcorp.cbesb.common.sa.service.EndPoint;
013: import com.bostechcorp.cbesb.common.sa.service.PropertiesKey;
014:
015: /**
016: * @author LPS
017: *
018: */
019: public class SequencerServiceListDOMXmlGenerator extends
020: AbstractDOMGenerator {
021:
022: private final String FILENAME = "ServiceList.xml";
023:
024: //
025: private final String SERVICELIST_T = "servicelist";
026:
027: private final String SERVICELIST_NS = "http://cbesb.bostechcorp.com/sequencer/servicelist/1.0";
028:
029: private final String TARGET_T = "target";
030:
031: private final String SERVICE_T = "service";
032:
033: public SequencerServiceListDOMXmlGenerator(String path) {
034: super (path);
035: }
036:
037: /*
038: * (non-Javadoc)
039: *
040: * @see com.bostechcorp.cbesb.common.util.AbstractDOMGenerator#buildDocumentStructure()
041: */
042: @Override
043: protected void buildDocumentStructure() {
044: rootElement = jdomFactory.element(SERVICELIST_T);
045: rootElement
046: .setNamespace(Namespace.getNamespace(SERVICELIST_NS));
047: rootElement.addNamespaceDeclaration(Namespace.getNamespace(
048: TARGET_T, "xxx"));
049: }
050:
051: public void setServiceList(EndPoint endPoint, String saName) {
052: HashMap<String, Properties> propertiesHm = new HashMap<String, Properties>();
053:
054: int j = 0;
055: for (int i = 1; i <= Integer.parseInt(endPoint.getSettings()
056: .getProperty(
057: PropertiesKey.SEQUENCER_WSDL_SERVICE_MAXORDER)); i++) {
058: String root = "sequencer.provider.Service";
059: String rootMatch = root + i + ".";
060: Enumeration e = endPoint.getSettings().propertyNames();
061: Properties subProperties = new Properties();
062: while (e.hasMoreElements()) {
063: String key = (String) e.nextElement();
064: if (key.indexOf(rootMatch) == 0) {
065: String subKey = key.substring(rootMatch.length());
066: String value = endPoint.getSettings().getProperty(
067: key);
068: subProperties.setProperty(subKey, value);
069: }
070: }
071: if (!subProperties.isEmpty()) {
072: j++;
073: String unit = "Unit";
074: propertiesHm.put(unit + j, subProperties);
075: }
076:
077: }
078: // setting namespace
079: for (int k = 1; k <= propertiesHm.size(); k++) {
080: rootElement.addNamespaceDeclaration(Namespace.getNamespace(
081: "unit" + k, "http://bostechcorp.com/SU/"
082: + saName
083: + "_"
084: + ((Properties) propertiesHm
085: .get("Unit" + k))
086: .getProperty("name")));
087: }
088: // setting service list
089: for (int l = 1; l <= propertiesHm.size(); l++) {
090: Properties suProperties = (Properties) propertiesHm
091: .get("Unit" + l);
092: Enumeration sE = suProperties.propertyNames();
093:
094: Element targetElement = jdomFactory.element(TARGET_T);
095: targetElement.setNamespace(Namespace.NO_NAMESPACE);
096: rootElement.addContent(targetElement);
097: while (sE.hasMoreElements()) {
098: String sKey = (String) sE.nextElement();
099: if (!"interfaceName".equals(sKey)
100: && !"name".equals(sKey)) {
101: if ("serviceName".equals(sKey)) {
102: Element servicElement = jdomFactory
103: .element(SERVICE_T);
104: servicElement.addContent("unit" + l + ":"
105: + saName + "_"
106: + suProperties.getProperty(sKey));
107:
108: targetElement.addContent(servicElement);
109: } else {
110: Element otherElement = jdomFactory
111: .element(sKey);
112: otherElement.addContent(suProperties
113: .getProperty(sKey));
114: targetElement.addContent(otherElement);
115: }
116: }
117: }
118: }
119:
120: }
121:
122: /*
123: * (non-Javadoc)
124: *
125: * @see com.bostechcorp.cbesb.common.util.AbstractDOMGenerator#getFileOut()
126: */
127: @Override
128: protected String getFileOut() {
129: if (filePath.endsWith("/")) {
130: return filePath + FILENAME;
131: } else {
132: return filePath + "/" + FILENAME;
133: }
134: }
135:
136: }
|