Skip to content

Commit 8fdeeaa

Browse files
claudiamurialdosgomez
authored andcommitted
Change implementation of AllowMultiple support (#169)
(cherry picked from commit 54cdc41)
1 parent 768ff7b commit 8fdeeaa

File tree

7 files changed

+78
-229
lines changed

7 files changed

+78
-229
lines changed

common/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
<artifactId>simple-xml</artifactId>
3535
<version>2.7.1</version>
3636
</dependency>
37-
<dependency>
38-
<groupId>com.fasterxml.jackson.dataformat</groupId>
39-
<artifactId>jackson-dataformat-xml</artifactId>
40-
<version>2.9.9</version>
41-
</dependency>
4237
</dependencies>
4338

4439
<build>

java/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@
115115
<artifactId>jackson-databind</artifactId>
116116
<version>2.9.9</version>
117117
</dependency>
118-
<dependency>
119-
<groupId>com.fasterxml.jackson.dataformat</groupId>
120-
<artifactId>jackson-dataformat-xml</artifactId>
121-
<version>2.9.9</version>
122-
</dependency>
123118
<dependency>
124119
<groupId>com.google.apis</groupId>
125120
<artifactId>google-api-services-androidpublisher</artifactId>
Lines changed: 78 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
package com.genexus.util;
22

33
import java.io.File;
4-
import java.io.IOException;
54
import java.util.Hashtable;
65

7-
import com.fasterxml.jackson.core.JsonParseException;
8-
import com.fasterxml.jackson.databind.JsonMappingException;
9-
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
10-
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
6+
import com.genexus.ApplicationContext;
117
import com.genexus.ModelContext;
128
import com.genexus.internet.HttpContext;
13-
import com.genexus.util.cloudservice.Property;
14-
import com.genexus.util.cloudservice.Service;
15-
import com.genexus.util.cloudservice.Services;
169
import com.genexus.webpanels.HttpContextWeb;
17-
import com.genexus.diagnostics.core.ILogger;
18-
import com.genexus.diagnostics.core.LogManager;
10+
import com.genexus.xml.XMLReader;
1911

2012
public class GXServices {
21-
22-
public static final ILogger logger = LogManager.getLogger(GXServices.class);
23-
2413
private static final boolean DEBUG = com.genexus.DebugFlag.DEBUG;
2514
public static final String WEBNOTIFICATIONS_SERVICE = "WebNotifications";
2615
public static final String STORAGE_SERVICE = "Storage";
@@ -55,46 +44,29 @@ public static void endGXServices() {
5544
instance = null;
5645
}
5746

58-
public static void loadFromFile(String basePath, String fileName, GXServices services) {
47+
public static void loadFromFile(String basePath, String fileName, GXServices services){
5948
if (basePath.equals("")) {
6049
basePath = services.configBaseDirectory();
6150
}
6251
String fullPath = basePath + fileName;
63-
XmlMapper xmlMapper = new XmlMapper();
64-
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
65-
Services xmlServices = null;
66-
try {
67-
xmlServices = xmlMapper.readValue(new File(fullPath), Services.class);
68-
} catch (JsonParseException e) {
69-
logger.error(e.getMessage(), e);
70-
e.printStackTrace();
71-
} catch (JsonMappingException e) {
72-
logger.error(e.getMessage(), e);
73-
e.printStackTrace();
74-
} catch (IOException e) {
75-
logger.error(e.getMessage(), e);
76-
e.printStackTrace();
77-
}
78-
79-
if (services == null)
80-
services = new GXServices();
81-
82-
for (Service xmlService : xmlServices.getService()) {
83-
GXService service = new GXService();
84-
service.setName(xmlService.getName());
85-
service.setType(xmlService.getType());
86-
service.setClassName(xmlService.getClassName());
87-
service.setAllowMultiple(xmlService.getAllowMultiple());
88-
GXProperties ptys = new GXProperties();
89-
for (Property xmlPty : xmlService.getProperties().getProperty()) {
90-
ptys.add(xmlPty.getName(), xmlPty.getValue());
52+
XMLReader reader = new XMLReader();
53+
reader.open(fullPath);
54+
reader.readType(1, "Services");
55+
reader.read();
56+
if (reader.getErrCode() == 0) {
57+
while (!reader.getName().equals("Services")) {
58+
services.processService(reader);
59+
reader.read();
60+
if (reader.getName().equals("Service") && reader.getNodeType() == 2) //</Service>
61+
reader.read();
9162
}
92-
service.setProperties(ptys);
93-
94-
if (service.getAllowMultiple()) {
95-
services.services.put(service.getType() + ":" + service.getName(), service);
96-
} else {
97-
services.services.put(service.getType(), service);
63+
reader.close();
64+
}
65+
else
66+
{
67+
if (!ApplicationContext.getInstance().getReorganization() && DEBUG)
68+
{
69+
System.out.println("GXServices - Could not load Services Config: " + fullPath + " - " + reader.getErrDescription());
9870
}
9971
}
10072
}
@@ -108,13 +80,15 @@ private String configBaseDirectory() {
10880
if (ModelContext.getModelContext() != null) {
10981
HttpContext webContext = (HttpContext) ModelContext.getModelContext().getHttpContext();
11082
if ((webContext != null) && (webContext instanceof HttpContextWeb)) {
111-
baseDir = com.genexus.ModelContext.getModelContext().getHttpContext().getDefaultPath() + File.separator
112-
+ "WEB-INF" + File.separatorChar;
83+
baseDir = com.genexus.ModelContext.getModelContext()
84+
.getHttpContext().getDefaultPath()
85+
+ File.separator + "WEB-INF" + File.separatorChar;
11386
}
11487
}
11588
if (baseDir.equals("")) {
11689
String servletPath = com.genexus.ApplicationContext.getInstance().getServletEngineDefaultPath();
117-
if (servletPath != null && !servletPath.equals("")) {
90+
if (servletPath != null && !servletPath.equals(""))
91+
{
11892
baseDir = servletPath + File.separator + "WEB-INF" + File.separatorChar;
11993
}
12094
}
@@ -125,15 +99,66 @@ private void readServices(String basePath) {
12599

126100
if (basePath.equals(""))
127101
basePath = configBaseDirectory();
128-
if (new File(basePath + SERVICES_DEV_FILE).exists()) {
102+
if (new File(basePath + SERVICES_DEV_FILE).exists()){
129103
loadFromFile(basePath, SERVICES_DEV_FILE, this);
130104
}
131-
if (new File(basePath + SERVICES_FILE).exists()) {
105+
if (new File(basePath + SERVICES_FILE).exists()){
132106
loadFromFile(basePath, SERVICES_FILE, this);
133107
}
134108
}
135109

110+
private void processService(XMLReader reader) {
111+
short result;
112+
result = reader.readType(1, "Name");
113+
String name = new String(reader.getValue());
114+
115+
result = reader.readType(1, "Type");
116+
String type = new String(reader.getValue());
117+
118+
result = reader.readType(1, "ClassName");
119+
String className = new String(reader.getValue());
120+
121+
boolean allowMultiple = false;
122+
reader.read();
123+
if (reader.getName() == "AllowMultiple")
124+
{
125+
allowMultiple = Boolean.parseBoolean(reader.getValue());
126+
reader.read();
127+
}
128+
GXProperties properties = processProperties(reader);
129+
130+
GXService service = new GXService();
131+
service.setName(name);
132+
service.setType(type);
133+
service.setClassName(className);
134+
service.setAllowMultiple(allowMultiple);
135+
service.setProperties(properties);
136+
if (service.getAllowMultiple()){
137+
services.put(service.getType() + ":" + service.getName(), service);
138+
}
139+
else{
140+
services.put(type, service);
141+
}
142+
}
143+
144+
private GXProperties processProperties(XMLReader reader) {
145+
short result;
146+
GXProperties properties = new GXProperties();
147+
reader.read();
148+
while (reader.getName().equals("Property")) {
149+
result = reader.readType(1, "Name");
150+
String name = new String(reader.getValue());
151+
result = reader.readType(1, "Value");
152+
String value = new String(reader.getValue());
153+
properties.add(name, value);
154+
reader.read();
155+
reader.read();
156+
}
157+
return properties;
158+
}
159+
136160
public GXService get(String name) {
137161
return services.get(name);
138162
}
163+
139164
}

java/src/main/java/com/genexus/util/cloudservice/Properties.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

java/src/main/java/com/genexus/util/cloudservice/Property.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

java/src/main/java/com/genexus/util/cloudservice/Service.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

java/src/main/java/com/genexus/util/cloudservice/Services.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)