private static String getCharset(Procedure procedure) { String charset = null; try { // try new way first ModelObjectExtensionAssistant assistant = (ModelObjectExtensionAssistant) ExtensionPlugin.getInstance() .getRegistry() .getModelExtensionAssistant(NAMESPACE_PROVIDER.getNamespacePrefix()); charset = assistant.getPropertyValue(procedure, RestModelExtensionConstants.PropertyIds.CHARSET); if (CoreStringUtil.isEmpty(charset)) { charset = (String) ANNOTATION_HELPER.getPropertyValueAnyCase( procedure, ModelObjectAnnotationHelper.EXTENDED_PROPERTY_NAMESPACE + "CHARSET"); //$NON-NLS-1$ } } catch (Exception e) { UTIL.log(e); } return charset; }
private static String getHeaders(Procedure procedure) { Object headers = null; try { // try new way first ModelObjectExtensionAssistant assistant = (ModelObjectExtensionAssistant) ExtensionPlugin.getInstance() .getRegistry() .getModelExtensionAssistant(NAMESPACE_PROVIDER.getNamespacePrefix()); headers = assistant.getPropertyValue(procedure, RestModelExtensionConstants.PropertyIds.HEADERS); if (headers == null || CoreStringUtil.isEmpty((String) headers)) { headers = ANNOTATION_HELPER.getPropertyValueAnyCase( procedure, ModelObjectAnnotationHelper.EXTENDED_PROPERTY_NAMESPACE + "headers"); // $NON-NLS-1$ } } catch (Exception e) { UTIL.log(e); } return headers == null ? StringUtilities.EMPTY_STRING : (String) headers; }
/** * If a MED with the same NS Prefix is already registered, it will be removed and replaced with * the supplied MED * * @param medFile the file containing the med definition * @throws Exception throws exception if the add operation failed */ private static void updateExtensionInRegistry(IFile medFile) throws Exception { ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry(); // If MED with this prefix is registered, remove it first ModelExtensionDefinition med = RegistryDeploymentValidator.parseMed(medFile.getContents(), false); if (registry.isNamespacePrefixRegistered(med.getNamespacePrefix())) { registry.removeDefinition(med.getNamespacePrefix()); } // Add the supplied MED addExtensionToRegistry(medFile); }
/** Construct an instance of AvailableModelExtensionDefinitionsDialog. */ public AvailableModelExtensionDefinitionsDialog( Shell shell, ModelResource resource, List<ModelExtensionDefinitionHeader> currentModelHeaders) { super(shell); this.setTitle(Messages.availableMedsDialogTitle); setShellStyle(getShellStyle() | SWT.RESIZE); setStatusLineAboveButtons(true); this.registry = (Platform.isRunning() ? ExtensionPlugin.getInstance().getRegistry() : null); this.modelResource = resource; this.availableMedsList = getAddableMEDs(this.modelResource, currentModelHeaders); this.selectedMedsList = new ArrayList(); }
/** * Determine if the supplied File contains a valid ModelExtensionDefinition. 'valid' meaning that * the file contents are parsable against the MED schema. If the contents are not valid, a dialog * is displayed. * * @param mxdContents the file contents of the extension definition * @param showInfoDialog flag indicates whether info dialog should be shown to user * @return the ModelExtensionDefinition, null if invalid */ private static ModelExtensionDefinition parseMed( InputStream mxdContents, boolean showInfoDialog) { ModelExtensionDefinition med = null; try { med = ExtensionPlugin.getInstance().parse(mxdContents); } catch (Exception e) { UTIL.log(Messages.medFileParseErrorMsg); } // Notify user if parse fails if (med == null && showInfoDialog) { showMedNotValidDialog(); } return med; }
/** * Add a ModelExtensionDefinition to the Extension Registry * * @param medFile the file containing the med definition * @throws Exception throws exception if the add operation failed */ private static void addExtensionToRegistry(IFile medFile) throws Exception { ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry(); registry.addDefinition( medFile.getContents(), ExtensionPlugin.getInstance().createDefaultModelObjectExtensionAssistant()); }
public static void deploy(final IFile medToDeploy) { CoreArgCheck.isNotNull(medToDeploy, "medToDeploy is null"); // $NON-NLS-1$ // Check whether there is currently an open editor for the selected Med IEditorPart editor = getOpenEditor(medToDeploy); // If editor is open and dirty, ask user whether to save if ((editor != null) && editor.isDirty()) { if (!MessageDialog.openQuestion( getShell(), Messages.updateMedInRegistryMedDirtyTitle, Messages.updateMedInRegistryMedDirtyMsg)) { return; } editor.doSave(new NullProgressMonitor()); } // If the file has any error markers, user is informed to fix them first if (RegistryDeploymentValidator.checkProblemMarkers(medToDeploy)) { return; } ModelExtensionRegistry registry = ExtensionPlugin.getInstance().getRegistry(); InputStream fileContents = null; try { fileContents = medToDeploy.getContents(); } catch (CoreException e) { UTIL.log( IStatus.ERROR, e, NLS.bind(Messages.medFileGetContentsErrorMsg, medToDeploy.getName())); } if (fileContents != null) { // Parse file contents to get the MED. Show info dialog if parse errors. ModelExtensionDefinition med = null; try { ModelExtensionDefinitionParser parser = new ModelExtensionDefinitionParser(ExtensionPlugin.getInstance().getMedSchema()); med = parser.parse( fileContents, ExtensionPlugin.getInstance().createDefaultModelObjectExtensionAssistant()); if (!parser.getErrors().isEmpty()) { MessageDialog.openError( getShell(), Messages.registerMedActionFailedTitle, NLS.bind(Messages.medFileParseErrorMsg, medToDeploy.getName())); return; } } catch (Exception e) { UTIL.log(e); MessageDialog.openError( getShell(), Messages.registerMedActionFailedTitle, Messages.registerMedActionFailedMsg); return; } // Continue checks on parsable MED if (med != null) { ModelExtensionDefinition medNSPrefixMatch = RegistryDeploymentValidator.getRegisteredMedWithNSPrefix( registry, med.getNamespacePrefix()); ModelExtensionDefinition medNSUriMatch = RegistryDeploymentValidator.getRegisteredMedWithNSUri(registry, med.getNamespaceUri()); boolean nsPrefixConflict = false; boolean nsUriConflict = false; boolean nsPrefixAndUriConflictSameMed = false; boolean nsPrefixConflictMedBuiltIn = false; boolean nsUriConflictMedBuiltIn = false; if (medNSPrefixMatch != null) { nsPrefixConflict = true; nsPrefixConflictMedBuiltIn = medNSPrefixMatch.isBuiltIn(); } if (medNSUriMatch != null) { nsUriConflict = true; nsUriConflictMedBuiltIn = medNSUriMatch.isBuiltIn(); } if (nsPrefixConflict && nsUriConflict && medNSPrefixMatch.equals(medNSUriMatch)) nsPrefixAndUriConflictSameMed = true; // No conflicts - add it to the registry if (!nsPrefixConflict && !nsUriConflict) { // Add the selected Med BusyIndicator.showWhile( Display.getDefault(), new Runnable() { @Override public void run() { internalRun(medToDeploy, false); } }); // If the NS Prefix conflicts with a Built-in, prompt user to fix } else if (nsPrefixConflictMedBuiltIn) { RegistryDeploymentValidator.showMedNSPrefixConflictsWBuiltInDialog(); // If the NS URI conflicts with a Built-in, prompt user to fix } else if (nsUriConflictMedBuiltIn) { RegistryDeploymentValidator.showMedNSUriConflictsWBuiltInDialog(); // If there is (1) just a NS Prefix Conflict or (2) NS Prefix AND URI, but they are same // MED, prompt user // whether to update } else if (nsPrefixConflict && (!nsUriConflict || (nsUriConflict && nsPrefixAndUriConflictSameMed))) { // Do not re-deploy the same MED if (med.equals(medNSPrefixMatch)) { RegistryDeploymentValidator.showMedNSPrefixAlreadyRegisteredDialog(); } else { boolean doUpdate = RegistryDeploymentValidator.showMedNSPrefixAlreadyRegisteredDoUpdateDialog(); if (doUpdate) { // Add the selected Med BusyIndicator.showWhile( Display.getDefault(), new Runnable() { @Override public void run() { internalRun(medToDeploy, true); } }); } } // If there is a NS URI Conflict, prompt user to fix it } else if (nsUriConflict) { RegistryDeploymentValidator.showMedNSUriAlreadyRegisteredDialog(); } } } }