use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project archi by archimatetool.
the class ViewpointManager method loadDefaultViewpointsFile.
/**
* Load viewpoints from XML file
*/
void loadDefaultViewpointsFile() throws IOException, JDOMException {
URL url = Platform.getBundle(BUNDLE_ID).getEntry(VIEWPOINTS_FILE);
Document doc = new SAXBuilder().build(url);
Element rootElement = doc.getRootElement();
for (Element xmlViewpoint : rootElement.getChildren("viewpoint")) {
// $NON-NLS-1$
// $NON-NLS-1$
String id = xmlViewpoint.getAttributeValue("id");
if (id == null || "".equals(id)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank id for viewpoint");
continue;
}
// $NON-NLS-1$
Element xmlName = xmlViewpoint.getChild("name");
if (xmlName == null) {
// $NON-NLS-1$
System.err.println("No name element for viewpoint");
continue;
}
String name = xmlName.getText();
if (name == null || "".equals(name)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank name for viewpoint");
continue;
}
Viewpoint vp = new Viewpoint(id, name);
for (Element xmlConcept : xmlViewpoint.getChildren("concept")) {
// $NON-NLS-1$
String conceptName = xmlConcept.getText();
if (conceptName == null || "".equals(conceptName)) {
// $NON-NLS-1$
// $NON-NLS-1$
System.err.println("Blank concept name for viewpoint");
continue;
}
if (ELEMENTS_MAP.containsKey(conceptName)) {
addCollection(vp, conceptName);
} else {
EClass eClass = (EClass) IArchimatePackage.eINSTANCE.getEClassifier(conceptName);
if (eClass != null) {
addConcept(vp, eClass);
} else {
// $NON-NLS-1$
System.err.println("Couldn't get eClass: " + conceptName);
}
}
}
VIEWPOINTS.put(id, vp);
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project coprhd-controller by CoprHD.
the class ServiceCatalogBuilder method build.
/**
* Parses xml file to ServiceCatalog with Jdom
*
* @param xmlFile
* The instance of xml file
* @return instance of ServiceCatalog
*/
public static ServiceCatalog build(final File xmlFile) {
String fileName = xmlFile.getName().trim().toLowerCase();
// remove suffix
if (fileName.endsWith(Constants.XML_FILE_SUFFIX)) {
fileName = fileName.substring(0, fileName.length() - Constants.XML_FILE_SUFFIX.length() - 1);
} else {
throw new IllegalArgumentException("API file is not xml format: " + fileName);
}
// filter name
int separatorIndex = fileName.indexOf(Constants.NAME_STRING_SEPARATOR);
if (separatorIndex == -1) {
throw new IllegalArgumentException("API file name should split with " + Constants.NAME_STRING_SEPARATOR + " actually: " + fileName);
}
String serviceName = fileName.substring(0, separatorIndex);
String version = fileName.substring(separatorIndex + 1, fileName.length());
Document document;
try {
document = new SAXBuilder().build(xmlFile);
} catch (Exception ex) {
throw new IllegalArgumentException("Invalid XML file:\n " + xmlFile.getAbsolutePath(), ex);
}
if (document == null) {
return null;
}
// Navigates to resource tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> resourceList = document.getRootElement().getChild(Constants.REST_NODE).getChild(Constants.RESOURCES_NODE).getChildren();
// Navigates to element tag, it's a little tricky here, depends on structure of xml file completely.
List<Element> elementList = document.getRootElement().getChild(Constants.DATA_NODE).getChild(Constants.DATA_SCHEMA_NODE).getChild(Constants.ELEMENTS_NODE).getChildren();
return new ServiceCatalog(parseResource(resourceList), parseElement(elementList), serviceName, version);
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method analyzeSyntaxExceptionTest.
@Test
@SuppressWarnings("all")
public void analyzeSyntaxExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockLanguageService.addException(exception);
try {
Document document = Document.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
client.analyzeSyntax(document, encodingType);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method annotateTextExceptionTest.
@Test
@SuppressWarnings("all")
public void annotateTextExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockLanguageService.addException(exception);
try {
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
client.annotateText(document, features, encodingType);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project google-cloud-java by GoogleCloudPlatform.
the class LanguageServiceClientTest method annotateTextTest.
@Test
@SuppressWarnings("all")
public void annotateTextTest() {
String language = "language-1613589672";
AnnotateTextResponse expectedResponse = AnnotateTextResponse.newBuilder().setLanguage(language).build();
mockLanguageService.addResponse(expectedResponse);
Document document = Document.newBuilder().build();
AnnotateTextRequest.Features features = AnnotateTextRequest.Features.newBuilder().build();
EncodingType encodingType = EncodingType.NONE;
AnnotateTextResponse actualResponse = client.annotateText(document, features, encodingType);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockLanguageService.getRequests();
Assert.assertEquals(1, actualRequests.size());
AnnotateTextRequest actualRequest = (AnnotateTextRequest) actualRequests.get(0);
Assert.assertEquals(document, actualRequest.getDocument());
Assert.assertEquals(features, actualRequest.getFeatures());
Assert.assertEquals(encodingType, actualRequest.getEncodingType());
}
Aggregations