use of org.adempiere.pipo2.Element in project sonar-cxx by SonarOpenCommunity.
the class CxxSquidConfiguration method getValues.
/**
* Used to read multi-valued properties.
*
* Collects all found values over all levels. It starts with the given level and further found values in parent levels
* are added to the end of the list. The method can return an empty list if the property is not set.
*
* @param level level at which the search is started
* @param property key that is searched for
* @return the values with the specified key value
*/
public List<String> getValues(String level, String key) {
List<String> result = new ArrayList<>();
Element eLevel = findLevel(level, parentList.getFirst());
do {
if (eLevel != null) {
Element eKey = eLevel.getChild(key);
if (eKey != null) {
for (var value : eKey.getChildren("Value")) {
result.add(value.getText());
}
}
}
eLevel = getParentElement(eLevel);
} while (eLevel != null);
return result;
}
use of org.adempiere.pipo2.Element in project VERDICT by ge-high-assurance.
the class ThreatModelUtil method getTypes.
/**
* Build a map from type names to types. Traverses all files
* in the current project looking for property declarations, which
* are used to populate fields for the built-in types.
*
* Built-in types are system, connection, and port (also portDirection).
*
* This method is not very efficient, and it gets called several times
* on every keystroke. Fortunately there still seems to be reasonably fast.
* A crucial optimization will be caching the results because the set of
* properties does not change that frequently.
*
* @param obj an AST node context, used to get access to project files
* @param indexProvider an index provider, may be obtained through Guice
* @return the constructed type map
*/
public static LinkedHashMap<String, VerdictType> getTypes(EObject obj, ResourceDescriptionsProvider indexProvider) {
LinkedHashMap<String, VerdictType> types = new LinkedHashMap<>();
// Three main built-in types
BuiltInType connection = new BuiltInType("connection");
BuiltInType port = new BuiltInType("port");
BuiltInType system = new BuiltInType("system");
addBuiltin(types, connection);
addBuiltin(types, port);
addBuiltin(types, system);
// Connection fields
connection.addField("inPort", port);
connection.addField("outPort", port);
connection.addField("source", system);
connection.addField("dest", system);
// Port direction
BuiltInType portDir = new BuiltInType("portDirection");
portDir.addValue("in");
portDir.addValue("out");
// Port fields
port.addField("direction", portDir);
port.addField("connections", connection.getListType());
// System fields
system.addField("subcomponents", system.getListType());
system.addField("connections", connection.getListType());
system.addField("ports", port.getListType());
// Get the path to the current resource, used to get the project path
String[] resSegments = obj.eResource().getURI().segments();
// Iterate through all resources
IResourceDescriptions index = indexProvider.getResourceDescriptions(obj.eResource());
descLoop: for (IEObjectDescription desc : index.getExportedObjectsByType(Aadl2Package.eINSTANCE.getPropertySet())) {
// Get the path to the resource we are examining
String[] propsResSegments = desc.getEObjectURI().segments();
// The project is determined by the first two URI segments
for (int i = 0; i < Math.min(2, Math.min(resSegments.length, propsResSegments.length)); i++) {
if (!resSegments[i].equals(propsResSegments[i])) {
continue descLoop;
}
}
// Load the resource into EMF-land; dynamically loads if necessary
Resource res = obj.eResource().getResourceSet().getResource(desc.getEObjectURI(), true);
if (res != null) {
// Search the AST
TreeIterator<EObject> it = res.getAllContents();
while (it.hasNext()) {
EObject next = it.next();
if (next instanceof PropertySet) {
PropertySet props = (PropertySet) next;
// Iterate the declared properties
for (Element elem : props.getOwnedElements()) {
if (elem instanceof Property) {
Property prop = (Property) elem;
// Make sure type information is present
if (prop.getPropertyType() != null) {
// the types for which the property is a field
for (MetaclassReference meta : prop.getAppliesToMetaclasses()) {
// Get type name, lowercase it because it is a class name
String appliesToMetaclass = meta.getMetaclass().getName().toLowerCase();
// Hopefully this is a type that we have accounted for
if (types.containsKey(appliesToMetaclass)) {
((BuiltInType) types.get(appliesToMetaclass)).addField(prop.getName(), new AadlTypeWrapper(prop.getName(), prop.getPropertyType()));
} else {
// If we get this error message, then perhaps need to add
// some built-in types
System.err.println("could not find built in type: " + appliesToMetaclass);
}
}
}
}
}
// Discard all children of the property set
it.prune();
}
}
}
}
// Prevent synchronization issues
portDir.lock();
connection.lock();
port.lock();
system.lock();
return types;
}
use of org.adempiere.pipo2.Element in project mule-migration-assistant by mulesoft.
the class ValidateClientTagMigrationStep method onValidMigrationElement.
private void onValidMigrationElement(Element element, MigrationReport migrationReport) {
element.setNamespace(CLIENT_ID_ENFORCEMENT_NAMESPACE);
Element root = getRootElement(element);
addConfigElement(root);
final String onUnacceptedName = element.getAttributeValue(ON_UNACCEPTED_ATTR_NAME);
if (root != null && hasProcessorChain(root, onUnacceptedName)) {
migrateProcessorChain(root, onUnacceptedName, migrationReport);
}
element.removeAttribute(ON_UNACCEPTED_ATTR_NAME);
element.setAttribute(CONFIG_REF, CLIENT_ID_ENFORCEMENT_CONFIG);
}
use of org.adempiere.pipo2.Element in project mule-migration-assistant by mulesoft.
the class AbstractFederationValidateMigrationStep method setConfigElement.
private void setConfigElement(Element rootElement, Element validateElement, List<Attribute> attributes) {
Element oauth2ConfigElement = new Element(getConfigElementTagName(), FEDERATION_NAMESPACE).setAttribute(NAME_ATTR_NAME, CONFIG_VALUE);
attributes.forEach(attr -> oauth2ConfigElement.setAttribute(attr.clone()));
new ArrayList<>(attributes).forEach(attr -> validateElement.removeAttribute(attr));
rootElement.addContent(oauth2ConfigElement);
}
use of org.adempiere.pipo2.Element in project mule-migration-assistant by mulesoft.
the class RamlTagMigrationStep method execute.
@Override
public void execute(Element element, MigrationReport migrationReport) throws RuntimeException {
element.setName(VALIDATE_REQUEST_TAG_NAME);
element.setNamespace(REST_VALIDATOR_NAMESPACE);
String configRef = element.getAttributeValue(CONFIG_REF_ATTR_NAME);
Optional<Element> ramlProxyConfigOptional = findChildElementWithMatchingAttributeValue(getRootElement(element), RAML_PROXY_CONFIG, PROXY_NAMESPACE, NAME_ATTR_NAME, configRef);
if (ramlProxyConfigOptional.isPresent()) {
Element ramlProxyConfig = ramlProxyConfigOptional.get();
ramlProxyConfig.setName(CONFIG_TAG_NAME);
ramlProxyConfig.setNamespace(REST_VALIDATOR_NAMESPACE);
ramlProxyConfig.setAttribute(NAME_ATTR_NAME, "rest-validator-config");
element.setAttribute(CONFIG_REF_ATTR_NAME, "rest-validator-config");
migrateConfigAttributes(ramlProxyConfig, migrationReport);
migrateErrorHandlerElement(element.getParentElement(), migrationReport);
addNamespaceDeclaration(getRootElement(element), REST_VALIDATOR_NAMESPACE, REST_VALIDATOR_XSI_SCHEMA_LOCATION_URI + " " + REST_VALIDATOR_XSI_SCHEMA_LOCATION_XSD);
addNamespaceDeclaration(getRootElement(element), EE_NAMESPACE, EE_XSI_SCHEMA_LOCATION_URI);
} else {
migrationReport.report("raml.noMatchingConfig", element, element);
throw new RuntimeException("No matching config was found for RAML element.");
}
}
Aggregations