use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class DatabaseObjectsManager method clearCache.
public void clearCache(String projectName) {
Object lock;
synchronized (importLocks) {
lock = importLocks.get(projectName);
if (lock == null) {
importLocks.put(projectName, lock = new Object());
}
}
synchronized (lock) {
Project project;
synchronized (projects) {
project = projects.remove(projectName);
}
RestApiManager.getInstance().removeUrlMapper(projectName);
MobileBuilder.releaseBuilder(project);
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class DatabaseObjectsManager method symbolsProjectCheckUndefined.
public boolean symbolsProjectCheckUndefined(String projectName) throws Exception {
final Project project = getOriginalProjectByName(projectName, false);
if (project == null) {
return false;
}
if (project.undefinedGlobalSymbols) {
project.undefinedGlobalSymbols = false;
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject.isSymbolError()) {
project.undefinedGlobalSymbols = true;
} else {
super.walk(databaseObject);
}
}
}.init(project);
}
return project.undefinedGlobalSymbols;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class SchemaManager method getSchemaForProject.
public XmlSchema getSchemaForProject(final String projectName, Option... options) throws Exception {
final boolean fullSchema = Option.fullSchema.is(options);
final Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
XmlSchemaCacheEntry cacheEntry = getCacheEntry(projectName);
synchronized (cacheEntry) {
boolean forceRebuild = needSchemaRebuild(projectName, cacheEntry.lastBuildTime);
long lastChange = project.getLastChange();
if (Option.noCache.not(options)) {
if (cacheEntry != null && cacheEntry.lastChange == lastChange && !forceRebuild) {
if (!fullSchema && cacheEntry.schema != null) {
// System.out.println("Schema for project \"" + projectName + "\" returned from cache");
return cacheEntry.schema;
}
if (fullSchema && cacheEntry.fullSchema != null) {
// System.out.println("Full schema for project \"" + projectName + "\" returned from cache");
return cacheEntry.fullSchema;
}
}
}
try {
XmlSchema schema = new XmlSchemaBuilderExecutor().buildSchema(projectName, options);
// always cache
cacheEntry.lastChange = lastChange;
cacheEntry.lastBuildTime = System.currentTimeMillis();
if (fullSchema) {
cacheEntry.fullSchema = schema;
} else {
cacheEntry.schema = schema;
}
return schema;
} catch (Exception e) {
System.out.println("Unabled to build schema for project \"" + projectName + "\" (see the complete error in logs)");
Engine.logEngine.error("Unabled to build schema for project \"" + projectName + "\"", e);
throw e;
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class SchemaManager method makeResponse.
public synchronized Document makeResponse(Document document) {
try {
Element documentElement = document.getDocumentElement();
if (documentElement != null) {
String project = documentElement.getAttribute("project");
String sequence = documentElement.getAttribute("sequence");
String connector = documentElement.getAttribute("connector");
String transaction = documentElement.getAttribute("transaction");
XmlSchema schema = getSchemaForProject(project);
XmlSchemaCollection collection = SchemaMeta.getCollection(schema);
String targetNamespace = schema.getTargetNamespace();
String prefix = collection.getNamespaceContext().getPrefix(targetNamespace);
String requestableName = sequence != null && sequence.length() > 0 ? sequence : connector + "__" + transaction;
String tagname = prefix + ":" + requestableName + "Response";
QName qname = new QName(targetNamespace, requestableName + "Response");
Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(project);
boolean isIncludeResponseElement = true;
if (!"".equals(sequence)) {
try {
Sequence seqObj = p.getSequenceByName(sequence);
isIncludeResponseElement = seqObj.isIncludeResponseElement();
} catch (Exception e) {
}
}
Document responseDoc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element requestableResponse = responseDoc.createElementNS(targetNamespace, tagname);
if (isIncludeResponseElement) {
Node renamed = responseDoc.renameNode(responseDoc.importNode(documentElement, true), "", "response");
requestableResponse.appendChild(renamed);
} else {
NodeList children = documentElement.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
requestableResponse.appendChild(responseDoc.importNode(children.item(i), true));
}
}
final Map<XmlSchemaObject, List<List<XmlSchemaObject>>> map = new LinkedHashMap<XmlSchemaObject, List<List<XmlSchemaObject>>>();
new XmlSchemaWalker(true, true) {
List<XmlSchemaObject> elist = null;
List<XmlSchemaObject> alist = null;
Map<QName, XmlSchemaObject> mso = new HashMap<QName, XmlSchemaObject>();
Map<QName, XmlSchemaObject> mto = new HashMap<QName, XmlSchemaObject>();
public void init(XmlSchema xmlSchema, QName qname, Element element) {
XmlSchemaElement rxe = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
if (rxe != null) {
List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
list.add(new ArrayList<XmlSchemaObject>());
list.add(new ArrayList<XmlSchemaObject>());
map.put(rxe, list);
mso.put(qname, rxe);
elist = list.get(0);
alist = list.get(1);
walkElement(xmlSchema, rxe);
/*for (XmlSchemaObject xso: map.keySet()) {
System.out.println(((XmlSchemaElement)xso).getName());
System.out.print("\t[");
for (XmlSchemaObject child: map.get(xso).get(1)) {
System.out.print(((XmlSchemaAttribute)child).getName()+",");
}
System.out.println("]");
for (XmlSchemaObject child: map.get(xso).get(0)) {
System.out.println("\t"+((XmlSchemaElement)child).getName());
}
}*/
makeCompliant(rxe, element);
}
}
protected boolean makeCompliant(XmlSchemaObject xso, Node node) {
String tns = node.getNamespaceURI();
String nodeName = node.getNodeName();
String localName = nodeName.substring(nodeName.indexOf(":") + 1);
String xsoName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getName() : ((XmlSchemaAttribute) xso).getName();
if (xsoName.equals(localName)) {
Document doc = node.getOwnerDocument();
QName xsoQName = xso instanceof XmlSchemaElement ? ((XmlSchemaElement) xso).getQName() : ((XmlSchemaAttribute) xso).getQName();
boolean elementQualified = SchemaMeta.getSchema(xso).getElementFormDefault().getValue().equals("qualified");
boolean attributeQualified = SchemaMeta.getSchema(xso).getAttributeFormDefault().getValue().equals("qualified");
boolean isQualified = (xsoQName != null && !xsoQName.getNamespaceURI().equals("")) || (xso instanceof XmlSchemaElement ? elementQualified : attributeQualified);
// String targetNamespace = SchemaMeta.getSchema(xso).getTargetNamespace();
// String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
String targetNamespace = xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getNamespaceURI() : SchemaMeta.getSchema(xso).getTargetNamespace();
String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(targetNamespace);
prefix = prefix == null ? (xsoQName != null && !xsoQName.getNamespaceURI().equals("") ? xsoQName.getPrefix() : "") : prefix;
if (isQualified)
node = doc.renameNode(node, targetNamespace, prefix + ":" + localName);
else
node = doc.renameNode(node, "", localName);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
if (element.hasAttributes()) {
NamedNodeMap attributes = element.getAttributes();
List<Node> list = new ArrayList<Node>();
for (int i = 0; i < attributes.getLength(); i++) {
Node attr = attributes.item(i);
String attrNodeName = attr.getNodeName();
boolean found = false;
for (XmlSchemaObject a : map.get(xso).get(1)) {
if (makeCompliant(a, attr)) {
found = true;
break;
}
}
if (!found) {
if (attrNodeName.equals("xsi:type") || attrNodeName.startsWith("xmlns:") || attrNodeName.endsWith(":encodingStyle")) {
list.add(attr);
}
} else {
if (attrNodeName.startsWith("xsi:")) {
attr = doc.renameNode(attr, Constants.URI_2001_SCHEMA_XSI, attrNodeName);
String attrNodeValue = attr.getNodeValue();
int index = attrNodeValue.indexOf(":");
if (index != -1) {
String pref = attrNodeValue.substring(0, index);
if (attributes.getNamedItem("xmlns:" + pref) == null) {
String ns = SchemaMeta.getCollection(xso).getNamespaceContext().getNamespaceURI(pref);
if ("".equals(ns) || ns == null)
ns = SchemaMeta.getSchema(xso).getTargetNamespace();
element.setAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + pref, ns);
}
}
}
if (attrNodeName.startsWith("xmlns:")) {
attr = doc.renameNode(attr, Constants.XMLNS_ATTRIBUTE_NS_URI, attrNodeName);
}
}
}
for (Node attr : list) {
element.removeAttributeNode((Attr) attr);
}
}
if (element.hasChildNodes()) {
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.TEXT_NODE)
continue;
// System.out.println("element: "+children.item(i).getNodeName());
for (XmlSchemaObject e : map.get(xso).get(0)) {
// System.out.println(" test "+((XmlSchemaElement)e).getName());
if (makeCompliant(e, children.item(i))) {
break;
}
}
}
}
}
return true;
} else {
// System.out.println(nodeName);
if ((tns != null) && !tns.equals("")) {
Document doc = node.getOwnerDocument();
String prefix = SchemaMeta.getCollection(xso).getNamespaceContext().getPrefix(tns);
if ((prefix != null) && !prefix.equals("")) {
node = doc.renameNode(node, tns, prefix + ":" + localName);
}
}
}
return false;
}
@Override
public void walkByTypeName(XmlSchema xmlSchema, QName qname) {
XmlSchemaType obj = SchemaMeta.getCollection(xmlSchema).getTypeByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByTypeName(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk type "+ qname);
elist.addAll(map.get(mto.get(qname)).get(0));
}
}
}
}
@Override
public void walkByElementRef(XmlSchema xmlSchema, QName qname) {
XmlSchemaElement obj = SchemaMeta.getCollection(xmlSchema).getElementByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByElementRef(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk elem ref "+ qname);
elist.add(mto.get(qname));
}
}
}
}
@Override
public void walkByAttributeGroupRef(XmlSchema xmlSchema, QName qname) {
XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
XmlSchemaAttributeGroup obj = (XmlSchemaAttributeGroup) schema.getAttributeGroups().getItem(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByAttributeGroupRef(xmlSchema, qname);
}
}
}
@Override
public void walkByAttributeRef(XmlSchema xmlSchema, QName qname) {
XmlSchemaAttribute obj = SchemaMeta.getCollection(xmlSchema).getAttributeByQName(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByAttributeRef(xmlSchema, qname);
} else {
if (mto.containsKey(qname)) {
// System.out.println("\nWalk attr ref "+ qname);
alist.add(mto.get(qname));
}
}
}
}
@Override
public void walkByGroupRef(XmlSchema xmlSchema, QName qname) {
XmlSchema schema = SchemaMeta.getCollection(xmlSchema).schemaForNamespace(qname.getNamespaceURI());
XmlSchemaGroup obj = (XmlSchemaGroup) schema.getGroups().getItem(qname);
if (obj != null) {
if (!mso.containsKey(qname)) {
mso.put(qname, obj);
super.walkByGroupRef(xmlSchema, qname);
}
}
}
@Override
protected void walkElement(XmlSchema xmlSchema, XmlSchemaElement obj) {
List<XmlSchemaObject> el = elist;
List<XmlSchemaObject> al = alist;
QName qname = obj.getQName();
QName refName = obj.getRefName();
QName typeName = obj.getSchemaTypeName();
if (refName == null) {
el.add(obj);
List<List<XmlSchemaObject>> list = new ArrayList<List<XmlSchemaObject>>();
list.add(new ArrayList<XmlSchemaObject>());
list.add(new ArrayList<XmlSchemaObject>());
map.put(obj, list);
// System.out.print("\nname="+obj.getName());
String ns = SchemaMeta.getSchema(obj).getTargetNamespace();
if (typeName != null) {
if (!mto.containsKey(typeName)) {
if (typeName.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
typeName = new QName(ns, obj.getName());
}
mto.put(typeName, obj);
// System.out.print("; typeN="+typeName);
} else {
map.put(obj, map.get(mto.get(typeName)));
// type already done
return;
}
} else {
if (qname != null) {
if (qname.getNamespaceURI().equals("")) {
qname = new QName(ns, obj.getName());
}
} else
qname = new QName(ns, obj.getName());
if (!mto.containsKey(qname)) {
mto.put(qname, obj);
// System.out.print("; qname="+qname);
}
}
elist = list.get(0);
alist = list.get(1);
super.walkElement(xmlSchema, obj);
elist = el;
alist = al;
} else {
super.walkElement(xmlSchema, obj);
elist = el;
alist = al;
}
}
@Override
protected void walkAttribute(XmlSchema xmlSchema, XmlSchemaAttribute obj) {
if (obj.getRefName() == null) {
alist.add(obj);
}
super.walkAttribute(xmlSchema, obj);
}
}.init(schema, qname, requestableResponse);
responseDoc.appendChild(requestableResponse);
// System.out.println(XMLUtils.prettyPrintDOM(responseDoc));
return responseDoc;
}
} catch (Exception e) {
e.printStackTrace();
}
return document;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class SchemaManager method getProjectReferences.
protected static void getProjectReferences(List<String> refs, String projectName) {
if (refs == null)
return;
try {
Project p = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
if (p != null) {
if (!refs.contains(projectName)) {
refs.add(projectName);
for (Reference ref : p.getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
ProjectSchemaReference psr = (ProjectSchemaReference) ref;
getProjectReferences(refs, psr.getParser().getProjectName());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations