use of com.cosylab.cdb.jdal.XMLTreeNode in project ACS by ACS-Community.
the class DOMJavaClassIntrospector method getNodes.
public static String[] getNodes(Object node, String nodeName, Logger log) {
if (node instanceof DAOImpl) {
return getNodes(((DAOImpl) node).getRootNode().getNodesMap());
} else if (node instanceof XMLTreeNode) {
return getNodes(((XMLTreeNode) node).getNodesMap());
} else if (node instanceof Map) {
Set<String> subnodes = new LinkedHashSet<String>();
Set keySet = ((Map) node).keySet();
for (Object key : keySet) subnodes.add(key.toString());
return subnodes.toArray(new String[subnodes.size()]);
} else if (node instanceof Element) {
List<String> list = new ArrayList<String>();
for (Node childNode = ((Element) node).getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
if (childNode.getNodeType() == Element.ELEMENT_NODE)
list.add(childNode.getNodeName());
}
return list.toArray(new String[list.size()]);
} else if (node instanceof ExtraDataFeature) {
String[] extraFields = null;
Element extraData = ((ExtraDataFeature) node).getExtraData();
if (extraData != null)
extraFields = getNodes(extraData);
String[] fields = getAccessibleFields(node, false);
if (extraFields == null)
return fields;
// concat and remove duplicates
LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(fields));
for (String ef : extraFields) if (!set.add(ef))
if (log != null)
log.warning("Duplicate node '" + nodeName + "/" + ef + "'.");
return set.toArray(new String[0]);
} else
return getAccessibleFields(node, false);
}
use of com.cosylab.cdb.jdal.XMLTreeNode in project ACS by ACS-Community.
the class BrowserJNDIXMLContext method lookup.
/*
* method that will create the next level of the XMLTree
*/
public Object lookup(Name name) throws NamingException {
//last selected node
String nameToLookup = name.toString();
String fullLookupName = this.name + "/" + nameToLookup;
//if '/' does not exist, then: int slashIndex = -1
int slashIndex = nameToLookup.indexOf('/');
CDBLogic.setKey(fullLookupName);
if (slashIndex != -1) {
//nameToLookup is String rep. of the full path to last selected node
//path of the parent node
String nodeName = nameToLookup.substring(0, slashIndex);
if (node.getNodesMap().containsKey(nodeName)) {
//Returns true if map contains a mapping for the specified key.
XMLTreeNode nextNode = (XMLTreeNode) node.getNodesMap().get(nodeName);
return new BrowserJNDIXMLContext(fullLookupName, nextNode, logger).lookup(nameToLookup.substring(slashIndex + 1));
}
}
//nestedElement = hashtable
if (nestedElements != null && nestedElements.containsKey(nameToLookup)) {
return super.lookup(name);
}
// The new XMLTreeNode will contain all Attributes as its childern
if (node.getNodesMap().containsKey(nameToLookup)) {
XMLTreeNode nextNode = (XMLTreeNode) node.getNodesMap().get(nameToLookup);
return new BrowserJNDIXMLContext(fullLookupName, nextNode, logger);
}
// ??
if (node.getFieldMap().containsKey(nameToLookup)) {
return (String) node.getFieldMap().get(nameToLookup);
}
throw new NamingException("No name " + nameToLookup);
}
use of com.cosylab.cdb.jdal.XMLTreeNode in project ACS by ACS-Community.
the class CDBDefault method setDefault.
/**
* Recursively go throw the xml finding nodes with the same Type. If the type match,
* compares the Name. If is the same name, sets the Default=true, in the other case
* sets the Default attribute to false.
* @param node_root the root of all components xml .
* @param in_type the type of the component.
* @param in_name the name of the component to set up default.
*
*/
public static void setDefault(XMLTreeNode node_root, String in_type, String in_name) {
try {
Iterator<String> nodesIter = node_root.getNodesMap().keySet().iterator();
WDAL wdal = WDALHelper.narrow(orb.string_to_object(strIOR));
while (nodesIter.hasNext()) {
String key = nodesIter.next();
XMLTreeNode node = node_root.getNodesMap().get(key);
String name = node.getFieldMap().get("Name");
String type = node.getFieldMap().get("Type");
String isDefault = node.getFieldMap().get("Default");
String strTrue = "true";
if (in_type.equals(type)) {
if (strTrue.equals(isDefault)) {
if (in_name.equals(name))
return;
else {
//write Default = false
try {
//System.out.println("1-"+curl_allComponents+"\t"+name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
wdao.set_string(name + "/Default", "false");
} catch (Exception e) {
//System.out.println("2-"+curl_allComponents+ "/" + name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents + "/" + name);
wdao.set_string("Default", "false");
}
}
} else if (in_name.equals(name)) {
// write Default = true
try {
//System.out.println("3-"+curl_allComponents+ "\t" + name);
WDAO wdao = wdal.get_WDAO_Servant(curl_allComponents);
wdao.set_string(name + "/Default", "true");
} catch (Exception e) {
//System.out.println("4-"+curl);
WDAO wdao = wdal.get_WDAO_Servant(curl);
wdao.set_string("Default", "true");
}
}
}
XMLTreeNode value = node_root.getNodesMap().get(key);
setDefault(value, in_type, in_name);
}
} catch (CDBXMLErrorEx e) {
m_logger.log(AcsLogLevel.NOTICE, "Xml Error", e);
e.printStackTrace();
} catch (Exception e) {
m_logger.log(AcsLogLevel.NOTICE, "Error", e);
e.printStackTrace();
}
}
use of com.cosylab.cdb.jdal.XMLTreeNode in project ACS by ACS-Community.
the class DALRead method walk.
public static void walk(XMLTreeNode node) {
Iterator<String> i = node.getFieldMap().keySet().iterator();
if (i.hasNext()) {
outputIndentation(indent);
System.out.print("Node " + node.getName());
System.out.println();
}
while (i.hasNext()) {
String key = i.next();
String value = node.getFieldMap().get(key);
System.out.print(" " + key + "=\"" + value + "\"");
System.out.println();
}
indent++;
Iterator nodesIter = node.getNodesMap().keySet().iterator();
while (nodesIter.hasNext()) {
String key = (String) nodesIter.next();
XMLTreeNode value = (XMLTreeNode) node.getNodesMap().get(key);
walk(value);
}
indent--;
}
use of com.cosylab.cdb.jdal.XMLTreeNode in project ACS by ACS-Community.
the class DOMJavaClassIntrospector method getNodesObjects.
public static NamedObject[] getNodesObjects(Object node, String nodeName, Logger log) {
if (node instanceof DAOImpl) {
return getNodesObjects(((DAOImpl) node).getRootNode().getNodesMap(), null, null);
} else if (node instanceof XMLTreeNode) {
return getNodesObjects(((XMLTreeNode) node).getNodesMap(), null, null);
} else if (node instanceof Map) {
ArrayList<NamedObject> subnodes = new ArrayList<NamedObject>();
Map nodeMap = (Map) node;
Set keySet = nodeMap.keySet();
for (Object key : keySet) subnodes.add(new NamedObject(key.toString(), nodeMap.get(key)));
return subnodes.toArray(new NamedObject[subnodes.size()]);
} else if (node instanceof Element) {
ArrayList<NamedObject> list = new ArrayList<NamedObject>();
for (Node childNode = ((Element) node).getFirstChild(); childNode != null; childNode = childNode.getNextSibling()) {
if (childNode.getNodeType() == Element.ELEMENT_NODE)
list.add(new NamedObject(childNode.getNodeName(), (Element) childNode));
}
return list.toArray(new NamedObject[list.size()]);
} else {
ArrayList<NamedObject> list = new ArrayList<NamedObject>();
if (node instanceof ExtraDataFeature) {
NamedObject[] extraFields = null;
Element extraData = ((ExtraDataFeature) node).getExtraData();
if (extraData != null)
extraFields = getNodesObjects(extraData, null, null);
getAccessibleFieldsObjects(node, false, list);
if (extraFields != null) {
for (NamedObject no : extraFields) list.add(no);
}
} else
getAccessibleFieldsObjects(node, false, list);
return list.toArray(new NamedObject[list.size()]);
}
}
Aggregations