Java Code Examples for com.intellij.util.xmlb.XmlSerializer#serializeInto()

The following examples show how to use com.intellij.util.xmlb.XmlSerializer#serializeInto() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MuleSdkManagerImpl.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Element getState()
{
    Element element = new Element("mule-sdks");
    try
    {
        for (MuleSdk sdk : sdks)
        {
            final Element sdkElement = new Element("mule-sdk");
            XmlSerializer.serializeInto(sdk, sdkElement, new SkipDefaultValuesSerializationFilters());
            element.addContent(sdkElement);
        }
    }
    catch (XmlSerializationException e)
    {
        LOG.error(e);
    }
    return element;
}
 
Example 2
Source File: SdkFieldsTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void roundTripShouldPreserveFields() {
  final SdkFields before = new SdkFields();
  before.setFilePath("main.dart");
  before.setAdditionalArgs("--trace-startup");

  final Element elt = new Element("test");
  XmlSerializer.serializeInto(before, elt, new SkipDefaultValuesSerializationFilters());

  // Make sure we no longer serialize workingDirectory
  assertArrayEquals(new String[]{"additionalArgs", "filePath"}, getOptionNames(elt).toArray());

  final SdkFields after = new SdkFields();
  XmlSerializer.deserializeInto(after, elt);
  assertEquals("main.dart", before.getFilePath());
  assertEquals("--trace-startup", before.getAdditionalArgs());
}
 
Example 3
Source File: LocalServerRunConfiguration.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
  ConfigurationState state = new ConfigurationState();
  if (myDeploymentSource != null) {
    DeploymentSourceType type = myDeploymentSource.getType();
    Element deploymentTag = new Element("deployment").setAttribute(DEPLOYMENT_SOURCE_TYPE_ATTRIBUTE, type.getId());
    type.save(myDeploymentSource, deploymentTag);
    if (myDeploymentConfiguration != null) {
      Object configurationState = myDeploymentConfiguration.getSerializer().getState();
      if (configurationState != null) {
        Element settingsTag = new Element(SETTINGS_ELEMENT);
        XmlSerializer.serializeInto(configurationState, settingsTag, SERIALIZATION_FILTERS);
        deploymentTag.addContent(settingsTag);
      }
    }
    state.myDeploymentTag = deploymentTag;
  }
  XmlSerializer.serializeInto(state, element, SERIALIZATION_FILTERS);
  super.writeExternal(element);
}
 
Example 4
Source File: SdkFieldsTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void roundTripShouldPreserveFields() {
  final SdkFields before = new SdkFields();
  before.setFilePath("main.dart");
  before.setAdditionalArgs("--trace-startup");

  final Element elt = new Element("test");
  XmlSerializer.serializeInto(before, elt, new SkipDefaultValuesSerializationFilters());

  // Make sure we no longer serialize workingDirectory
  assertArrayEquals(new String[]{"additionalArgs", "filePath"}, getOptionNames(elt).toArray());

  final SdkFields after = new SdkFields();
  XmlSerializer.deserializeInto(after, elt);
  assertEquals("main.dart", before.getFilePath());
  assertEquals("--trace-startup", before.getAdditionalArgs());
}
 
Example 5
Source File: DeployToServerRunConfiguration.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
  ConfigurationState state = new ConfigurationState();
  state.myServerName = myServerName;
  if (myDeploymentSource != null) {
    DeploymentSourceType type = myDeploymentSource.getType();
    Element deploymentTag = new Element("deployment").setAttribute(DEPLOYMENT_SOURCE_TYPE_ATTRIBUTE, type.getId());
    type.save(myDeploymentSource, deploymentTag);
    if (myDeploymentConfiguration != null) {
      Object configurationState = myDeploymentConfiguration.getSerializer().getState();
      if (configurationState != null) {
        Element settingsTag = new Element(SETTINGS_ELEMENT);
        XmlSerializer.serializeInto(configurationState, settingsTag, SERIALIZATION_FILTERS);
        deploymentTag.addContent(settingsTag);
      }
    }
    state.myDeploymentTag = deploymentTag;
  }
  XmlSerializer.serializeInto(state, element, SERIALIZATION_FILTERS);
  super.writeExternal(element);
}
 
Example 6
Source File: FeatureUsageTrackerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Element getState() {
  Element element = new Element("state");
  ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance();
  Set<String> ids = registry.getFeatureIds();
  for (String id: ids) {
    Element featureElement = new Element(FEATURE_TAG);
    featureElement.setAttribute(ATT_ID, id);
    FeatureDescriptor descriptor = registry.getFeatureDescriptor(id);
    descriptor.writeStatistics(featureElement);
    element.addContent(featureElement);
  }

  Element statsTag = new Element(COMPLETION_STATS_TAG);
  XmlSerializer.serializeInto(myCompletionStats, statsTag);
  element.addContent(statsTag);

  Element fstatsTag = new Element(FIXES_STATS_TAG);
  XmlSerializer.serializeInto(myFixesStats, fstatsTag);
  element.addContent(fstatsTag);

  element.setAttribute(ATT_HAVE_BEEN_SHOWN, String.valueOf(HAVE_BEEN_SHOWN));

  return element;
}
 
Example 7
Source File: ArtifactManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Element serializePackagingElement(PackagingElement<?> packagingElement) {
  Element element = new Element(PACKAGING_ELEMENT_NAME);
  element.setAttribute(TYPE_ID_ATTRIBUTE, packagingElement.getType().getId());
  final Object bean = packagingElement.getState();
  if (bean != null) {
    XmlSerializer.serializeInto(bean, element, new SkipDefaultValuesSerializationFilters());
  }
  if (packagingElement instanceof CompositePackagingElement) {
    for (PackagingElement<?> child : ((CompositePackagingElement<?>)packagingElement).getChildren()) {
      element.addContent(serializePackagingElement(child));
    }
  }
  return element;
}
 
Example 8
Source File: ArtifactManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static <S> ArtifactPropertiesState serializeProperties(ArtifactPropertiesProvider provider, ArtifactProperties<S> properties) {
  final ArtifactPropertiesState state = new ArtifactPropertiesState();
  state.setId(provider.getId());
  final Element options = new Element("options");
  XmlSerializer.serializeInto(properties.getState(), options, new SkipDefaultValuesSerializationFilters());
  if (options.getContent().isEmpty() && options.getAttributes().isEmpty()) return null;
  state.setOptions(options);
  return state;
}
 
Example 9
Source File: DefaultProjectProfileManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public synchronized Element getState() {
  Element state = new Element("settings");

  String[] sortedProfiles = myProfiles.keySet().toArray(new String[myProfiles.size()]);
  Arrays.sort(sortedProfiles);
  for (String profile : sortedProfiles) {
    final Profile projectProfile = myProfiles.get(profile);
    if (projectProfile != null) {
      Element profileElement = new Element(PROFILE);
      try {
        projectProfile.writeExternal(profileElement);
      }
      catch (WriteExternalException e) {
        LOG.error(e);
      }
      boolean hasSmthToSave = sortedProfiles.length > 1 || isDefaultProfileUsed();
      if (!hasSmthToSave) {
        for (Element child : profileElement.getChildren()) {
          if (!child.getName().equals("option")) {
            hasSmthToSave = true;
            break;
          }
        }
      }
      if (!hasSmthToSave) {
        continue;
      }

      state.addContent(profileElement);
    }
  }

  if (!state.getChildren().isEmpty() || isDefaultProfileUsed()) {
    XmlSerializer.serializeInto(this, state);
    state.addContent(new Element("version").setAttribute("value", VERSION));
  }
  return state;
}
 
Example 10
Source File: InspectionProfileEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Store current settings in XML config.
 * Default implementation uses XmlSerializer so you may use public fields (like <code>int TOOL_OPTION</code>)
 * and bean-style getters/setters (like <code>int getToolOption(), void setToolOption(int)</code>) to store your options.
 *
 * @param node to store settings to.
 * @throws WriteExternalException if no data should be saved for this component.
 */
@SuppressWarnings("deprecation")
public void writeSettings(@Nonnull Element node) throws WriteExternalException {
  if (useNewSerializer()) {
    XmlSerializer.serializeInto(this, node, getSerializationFilter());
  }
  else {
    //noinspection UnnecessaryFullyQualifiedName
    com.intellij.openapi.util.DefaultJDOMExternalizer.writeExternal(this, node);
  }
}
 
Example 11
Source File: JpsHaxeSdkType.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static JpsSdkPropertiesSerializer<JpsHaxeSdkAdditionalData> createJpsSdkPropertiesSerializer() {
  return new JpsSdkPropertiesSerializer<JpsHaxeSdkAdditionalData>(HaxeCommonBundle.message("haxe.sdk.name"), INSTANCE) {
    @NotNull
    public JpsHaxeSdkAdditionalData loadProperties(@Nullable final Element propertiesElement) {
      final HaxeSdkAdditionalDataBase sdkData = XmlSerializer.deserialize(propertiesElement, HaxeSdkAdditionalDataBaseImpl.class);
      return new JpsHaxeSdkAdditionalDataImpl(sdkData);
    }

    public void saveProperties(@NotNull final JpsHaxeSdkAdditionalData properties, @NotNull final Element element) {
      XmlSerializer.serializeInto(properties.getSdkData(), element);
    }
  };
}
 
Example 12
Source File: Unity3dTestConfiguration.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException
{
	super.writeExternal(element);

	XmlSerializer.serializeInto(this, element);
}
 
Example 13
Source File: Unity3dAttachConfiguration.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException
{
	super.writeExternal(element);

	XmlSerializer.serializeInto(this, element);
}
 
Example 14
Source File: EmbeddedLinuxJVMRunConfiguration.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Write External
 * @param element
 * @throws WriteExternalException
 */
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    if (embeddedLinuxJVMRunConfigurationRunnerParameters != null) {
        XmlSerializer.serializeInto(embeddedLinuxJVMRunConfigurationRunnerParameters, element);
    }
}
 
Example 15
Source File: PluginManagerUISettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Element getState() {
  Element element = new Element("state");
  XmlSerializer.serializeInto(this, element, FILTERS);
  XmlSerializer.serializeInto(mySplitterProportionsData, element, FILTERS);

  final Element availableProportions = new Element(AVAILABLE_PROPORTIONS);
  XmlSerializer.serializeInto(myAvailableSplitterProportionsData, availableProportions, FILTERS);
  element.addContent(availableProportions);
  return element;
}
 
Example 16
Source File: HaxeTestsConfiguration.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public void writeExternal(final Element element) throws WriteExternalException {
  super.writeExternal(element);
  writeModule(element);
  XmlSerializer.serializeInto(this, element);
}
 
Example 17
Source File: HaxeSdkType.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public void saveAdditionalData(SdkAdditionalData additionalData, Element additional) {
  if (additionalData instanceof HaxeSdkData) {
    XmlSerializer.serializeInto(additionalData, additional);
  }
}
 
Example 18
Source File: HaxeApplicationConfiguration.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public void writeExternal(final Element element) throws WriteExternalException {
  super.writeExternal(element);
  writeModule(element);
  XmlSerializer.serializeInto(this, element);
}
 
Example 19
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void writeExternal(@NotNull final Element element) throws WriteExternalException {
  super.writeExternal(element);
  XmlSerializer.serializeInto(getFields(), element, new SkipDefaultValuesSerializationFilters());
}
 
Example 20
Source File: TomcatRunConfiguration.java    From SmartTomcat with Apache License 2.0 4 votes vote down vote up
@Override
public void writeExternal(Element element) throws WriteExternalException {
    super.writeExternal(element);
    XmlSerializer.serializeInto(this, element);
}