use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class NavajoContextInstanceFactory method readResources.
private Map<String, Message> readResources(File resource, Map<String, Set<String>> aliases) {
Map<String, Message> result = new HashMap<String, Message>();
FileReader fr = null;
String deployment = repositoryInstance.getDeployment();
try {
fr = new FileReader(resource);
Navajo n = NavajoFactory.getInstance().createNavajo(fr);
Message resources = n.getMessage("datasources");
Message deployments = n.getMessage("deployments");
Message aliasMessage = n.getMessage("alias");
if (resources != null) {
logger.warn("In datasource definitions, please use 'resources' instead of 'datasources' as top level message name");
} else {
resources = n.getMessage("resources");
}
appendResources(aliases, result, resources, aliasMessage, null);
logger.info("# of (deployment independent): resources {}", result.size());
if (deployment != null && deployments != null) {
for (Message deploymentMessage : deployments.getAllMessages()) {
String name = deploymentMessage.getName();
if (name.equals(deployment)) {
Message deploymentResources = deploymentMessage.getMessage("resources");
Message deploymentAliasMessage = deploymentMessage.getMessage("alias");
Message aliasConditionalMessage = deploymentMessage.getMessage("alias_conditional");
appendResources(aliases, result, deploymentResources, deploymentAliasMessage, aliasConditionalMessage);
} else {
logger.debug("Ignoring not-matching datasource ({} vs {})", name, deployment);
}
}
} else {
logger.warn("No deployment whatsoever, ignoring all deployment specific sources. My deployment: {}", deployment);
if (deployments != null) {
deployments.write(System.err);
} else {
logger.warn("No deployments message either!");
}
}
} catch (FileNotFoundException e) {
logger.debug("Problem reading file: {}", resource, e);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
logger.debug("Problem closing file: {}", resource, e);
}
}
}
return result;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class NavajoContextInstanceFactory method appendInstance.
private void appendInstance(String name, File instanceFolder, Map<String, Object> globalProperties, Map<String, Message> globalResources) throws IOException {
logger.info("Instance name: " + name);
if (skipDeployment(instanceFolder)) {
return;
}
Map<String, Object> copyOfProperties = new HashMap<String, Object>(globalProperties);
File config = new File(instanceFolder, "config");
File instanceProperties = new File(config, "application.properties");
if (instanceProperties.exists()) {
final Map<String, Object> instanceSpecific = readProperties(instanceProperties);
logger.info("spec: {}, {}", instanceSpecific.size(), instanceProperties.getAbsolutePath());
copyOfProperties.putAll(instanceSpecific);
}
File instanceResource = new File(config, "resources.xml");
Map<String, Set<String>> aliases = new HashMap<String, Set<String>>();
Map<String, Message> resources = readResources(instanceResource, aliases);
registerInstanceProperties(name, copyOfProperties);
registerInstanceResources(name, resources, aliases);
registerLocalClients(name, instanceFolder);
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class NavajoContextInstanceFactory method appendResources.
private void appendResources(Map<String, Set<String>> aliases, Map<String, Message> result, Message resources, Message aliasMessage, Message aliasConditionalMessage) {
if (aliasMessage != null) {
List<Property> aliasProps = aliasMessage.getAllProperties();
for (Property property : aliasProps) {
String aliasValue = (String) property.getTypedValue();
String name = property.getName();
Set<String> found = aliases.get(aliasValue);
if (found == null) {
found = new HashSet<String>();
aliases.put(aliasValue, found);
}
found.add(name);
}
}
if (aliasConditionalMessage != null) {
appendConditionalAlias(aliasConditionalMessage, aliases);
}
if (resources != null) {
List<Message> sources = resources.getAllMessages();
for (Message rsrc : sources) {
result.put(rsrc.getName(), rsrc);
}
}
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class NavajoContextInstanceFactory method appendConditionalAlias.
private void appendConditionalAlias(Message aliasConditionalMessage, Map<String, Set<String>> aliases) {
for (Message m : aliasConditionalMessage.getAllMessages()) {
String name = m.getName();
Property conditionProp = m.getProperty("condition");
Property trueValueProp = m.getProperty("true_value");
Property falseValueProp = m.getProperty("false_value");
if (conditionProp == null || conditionProp.getTypedValue() == null) {
logger.warn("Invalid conditional alias message! {}", m);
continue;
}
boolean evaluated = checkEliasCondition(conditionProp.getValue());
String aliasValue = null;
if (evaluated && trueValueProp != null) {
aliasValue = trueValueProp.getValue();
} else if (!evaluated && falseValueProp != null) {
aliasValue = falseValueProp.getValue();
}
if (aliasValue != null) {
Set<String> found = aliases.get(aliasValue);
if (found == null) {
found = new HashSet<String>();
aliases.put(aliasValue, found);
}
found.add(name);
}
}
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class DomainObjectMapper method mapObjectToProperties.
/**
* Automatically maps all 'getters' to a property.
*
* Only add property if:
* 1. attribute 'getter' does not expect any arguments.
* 2. attribute has a 'getter'.
* 3. corresponding property does not already exist in message.
* 4. corresponding property is not in exclusion list.
* @throws Exception
*/
private void mapObjectToProperties(Class myClass) throws Exception {
java.lang.reflect.Method[] all = myClass.getMethods();
if (myAccess == null) {
return;
}
Navajo out = myAccess.getOutputDoc();
Message currentOutMsg = myAccess.getCurrentOutMessage();
if (currentOutMsg == null) {
throw new Exception("No current message for mapping object attributes to properties.");
}
for (int i = 0; i < all.length; i++) {
String attributeName = all[i].getName().substring(3);
if (all[i].getParameterTypes().length == 0 && all[i].getName().startsWith("get") && !all[i].getName().startsWith("getClass") && currentOutMsg.getProperty(attributeName) == null && !isAnExcludedProperty(attributeName)) {
Object result = all[i].invoke(myObject, (Object[]) null);
if (result == null || !(result.toString().startsWith("[L") || List.class.isAssignableFrom(result.getClass()))) {
Property p = NavajoFactory.getInstance().createProperty(out, attributeName, "string", "", 0, "", "", "");
p.setAnyValue(result);
p.setDirection(isAnInputProperty(attributeName) ? Property.DIR_IN : Property.DIR_OUT);
currentOutMsg.addProperty(p);
}
}
}
}
Aggregations