org.simpleframework.xml.stream.Format Java Examples

The following examples show how to use org.simpleframework.xml.stream.Format. 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: CompositeListUnionTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testLargeList() throws Exception {
   Context context = getContext();
   Group group = getGroup();
   Type type = new ClassType(CompositeListUnionTest.class);
   List<Shape> list = new ArrayList<Shape>();
   Expression expression = new PathParser("some/path", type, new Format());
   CompositeListUnion union = new CompositeListUnion(
         context,
         group,
         expression,
         type);
   InputNode node = NodeBuilder.read(new StringReader(LARGE_SOURCE));
   
   for(InputNode next = node.getNext(); next != null; next = node.getNext()) {
      union.read(next, list);
   }
   OutputNode output = NodeBuilder.write(new PrintWriter(System.err), new Format(3));
   OutputNode parent = output.getChild("parent");
   
   union.write(parent, list);
}
 
Example #2
Source File: UnionStyleTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testCamelCaseStyle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Persister persister = new Persister(format);
   UnionListExample example = persister.read(UnionListExample.class, CAMEL_CASE_SOURCE);
   List<Entry> entry = example.list;
   assertEquals(entry.size(), 4);
   assertEquals(entry.get(0).getClass(), IntegerEntry.class);
   assertEquals(entry.get(0).foo(), 111);
   assertEquals(entry.get(1).getClass(), DoubleEntry.class);
   assertEquals(entry.get(1).foo(), 222.0);
   assertEquals(entry.get(2).getClass(), StringEntry.class);
   assertEquals(entry.get(2).foo(), "A");
   assertEquals(entry.get(3).getClass(), StringEntry.class);
   assertEquals(entry.get(3).foo(), "B");
   assertEquals(example.entry.getClass(), IntegerEntry.class);
   assertEquals(example.entry.foo(), 777);
   persister.write(example, System.out);
   validate(persister, example);
}
 
Example #3
Source File: PathCaseTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testOtherStyle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   OtherCaseExample example = new OtherCaseExample("a", "b");
   Persister persister = new Persister(format);
   StringWriter writer = new StringWriter();
   boolean exception = false;
   try {
      persister.write(example, writer);
   }catch(Exception e) {
      e.printStackTrace();
      exception = true;
   }
   System.out.println(writer.toString());
   assertFalse("No exception should be thrown with the elements are not the same name", exception);
}
 
Example #4
Source File: RegistryConverterCycleTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testCycle() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Registry registry = new Registry();
   Address address = new Address("An Address");
   Person person = new Person(address, "Niall", 30);
   CycleStrategy referencer = new CycleStrategy();
   RegistryStrategy strategy = new RegistryStrategy(registry, referencer);
   Serializer serializer = new Persister(strategy, format);
   Converter converter = new PersonConverter(serializer);
   Club club = new Club(address);
   
   club.addMember(person);
   registry.bind(Person.class, converter);
   
   serializer.write(club, System.out);
}
 
Example #5
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onRenameConfiguration(final String newName) {
	final boolean exists = databaseHelper.configurationExists(newName);
	if (exists) {
		Toast.makeText(this, R.string.uart_configuration_name_already_taken, Toast.LENGTH_LONG).show();
		return;
	}

	final String oldName = configuration.getName();
	configuration.setName(newName);

	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(configuration, writer);
		final String xml = writer.toString();

		databaseHelper.renameConfiguration(oldName, newName, xml);
		wearableSynchronizer.onConfigurationAddedOrEdited(preferences.getLong(PREFS_CONFIGURATION, 0), configuration);
		refreshConfigurations();
	} catch (final Exception e) {
		Log.e(TAG, "Error while renaming configuration", e);
	}
}
 
Example #6
Source File: PathParserTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testAttribute() throws Exception {
   Expression expression = new PathParser("./some[3]/path[2]/to/parse/@attribute", new ClassType(PathParserTest.class), new Format());
   assertEquals(expression.getFirst(), "some");
   assertEquals(expression.getIndex(), 3);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "some[3]/path[2]/to/parse/@attribute");
   assertTrue(expression.isPath());
   assertTrue(expression.isAttribute());
   
   expression = expression.getPath(2);
   assertEquals(expression.getFirst(), "to");
   assertEquals(expression.getIndex(), 1);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "to/parse/@attribute");
   assertTrue(expression.isPath());
   assertTrue(expression.isAttribute());
   
   expression = expression.getPath(2);
   assertEquals(expression.getFirst(), "attribute");
   assertEquals(expression.getIndex(), 1);
   assertEquals(expression.getLast(), "attribute");
   assertEquals(expression.toString(), "@attribute");
   assertFalse(expression.isPath());
   assertTrue(expression.isAttribute());
}
 
Example #7
Source File: RegistryConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testPersonConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Registry registry = new Registry();
   Person person = new Person("Niall", 30);
   RegistryStrategy strategy = new RegistryStrategy(registry);
   Serializer serializer = new Persister(strategy, format);
   Converter converter = new PersonConverter(serializer);
   StringWriter writer = new StringWriter();
   
   registry.bind(Person.class, converter);
   
   PersonProfile profile = new PersonProfile(person);
   serializer.write(profile, writer);
   
   System.out.println(writer.toString());
   
   PersonProfile read = serializer.read(PersonProfile.class, writer.toString());
   
   assertEquals(read.person.name, "Niall");
   assertEquals(read.person.age, 30);
}
 
Example #8
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Saves the given configuration in the database.
 */
private void saveConfiguration() {
	final UartConfiguration configuration = this.configuration;
	try {
		final Format format = new Format(new HyphenStyle());
		final Strategy strategy = new VisitorStrategy(new CommentVisitor());
		final Serializer serializer = new Persister(strategy, format);
		final StringWriter writer = new StringWriter();
		serializer.write(configuration, writer);
		final String xml = writer.toString();

		databaseHelper.updateConfiguration(configuration.getName(), xml);
		wearableSynchronizer.onConfigurationAddedOrEdited(preferences.getLong(PREFS_CONFIGURATION, 0), configuration);
	} catch (final Exception e) {
		Log.e(TAG, "Error while creating a new configuration", e);
	}
}
 
Example #9
Source File: ConverterDecorationTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Strategy cycle = new CycleStrategy();
   Strategy strategy = new AnnotationStrategy(cycle);
   Persister persister = new Persister(strategy, format);
   List<ConverterDecorationExample> list = new ArrayList<ConverterDecorationExample>();
   List<NormalExample> normal = new ArrayList<NormalExample>();
   ConverterDecoration example = new ConverterDecoration(list, normal);
   ConverterDecorationExample duplicate = new ConverterDecorationExample("duplicate");
   NormalExample normalDuplicate = new NormalExample("duplicate");
   list.add(duplicate);
   list.add(new ConverterDecorationExample("a"));
   list.add(new ConverterDecorationExample("b"));
   list.add(new ConverterDecorationExample("c"));
   list.add(duplicate);
   list.add(new ConverterDecorationExample("d"));
   list.add(duplicate);
   normal.add(normalDuplicate);
   normal.add(new NormalExample("1"));
   normal.add(new NormalExample("2"));
   normal.add(normalDuplicate);
   persister.write(example, System.err);     
}
 
Example #10
Source File: PathParserTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testSimplePath() throws Exception {
   Expression expression = new PathParser("path1/path2/path3/path4", new ClassType(PathParserTest.class), new Format());
   assertEquals(expression.getFirst(), "path1");
   assertEquals(expression.getPrefix(), null);
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "path1/path2/path3/path4");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
   
   expression = expression.getPath(1);
   assertEquals(expression.getFirst(), "path2");
   assertEquals(expression.getPrefix(), null);
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "path2/path3/path4");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
}
 
Example #11
Source File: PathWithConverterTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testConverterWithPathInHyphenStyle() throws Exception {
   Style style = new HyphenStyle();
   Format format = new Format(style);
   Strategy strategy = new AnnotationStrategy();
   Persister persister = new Persister(strategy, format);
   ServerDetails primary = new ServerDetails("host1.blah.com", 4567, "PRIMARY");
   ServerDetails secondary = new ServerDetails("host2.foo.com", 4567, "SECONDARY");
   ServerDetailsReference reference = new ServerDetailsReference(primary, secondary);
   StringWriter writer = new StringWriter();
   persister.write(reference, writer);
   System.out.println(writer);
   ServerDetailsReference recovered = persister.read(ServerDetailsReference.class, writer.toString());
   assertEquals(recovered.getPrimary().getHost(), reference.getPrimary().getHost());
   assertEquals(recovered.getPrimary().getPort(), reference.getPrimary().getPort());
   assertEquals(recovered.getPrimary().getName(), reference.getPrimary().getName());
   assertEquals(recovered.getSecondary().getHost(), reference.getSecondary().getHost());
   assertEquals(recovered.getSecondary().getPort(), reference.getSecondary().getPort());
   assertEquals(recovered.getSecondary().getName(), reference.getSecondary().getName());
}
 
Example #12
Source File: PathParserTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testAttributePath() throws Exception {
   Type type = new ClassType(PathParserTest.class);
   Expression expression = new PathParser("some/path", type, new Format());
   String element = expression.getElement("element");
   assertEquals(element, "some[1]/path[1]/element[1]");
   String attribute = expression.getAttribute("attribute");
   assertEquals(attribute, "some[1]/path[1]/@attribute");
   assertFalse(expression.isEmpty());
   Expression attr = new PathParser(attribute, type, new Format());
   assertFalse(attr.isEmpty());   
   assertTrue(attr.isAttribute());
   assertEquals(attr.getLast(), "attribute");
   assertEquals(attr.getFirst(), "some");
   Expression ending = new PathParser("a/b@c", type, new Format());
   assertTrue(ending.isAttribute());
   assertEquals(ending.getFirst(), "a");
   assertEquals(ending.getLast(), "c");
   
}
 
Example #13
Source File: UnionStyleTest.java    From simplexml with Apache License 2.0 6 votes vote down vote up
public void testHyphenStyle() throws Exception {
   Style style = new HyphenStyle();
   Format format = new Format(style);
   Persister persister = new Persister(format);
   UnionListExample example = persister.read(UnionListExample.class, HYPHEN_SOURCE);
   List<Entry> entry = example.list;
   assertEquals(entry.size(), 4);
   assertEquals(entry.get(0).getClass(), IntegerEntry.class);
   assertEquals(entry.get(0).foo(), 111);
   assertEquals(entry.get(1).getClass(), DoubleEntry.class);
   assertEquals(entry.get(1).foo(), 222.0);
   assertEquals(entry.get(2).getClass(), StringEntry.class);
   assertEquals(entry.get(2).foo(), "A");
   assertEquals(entry.get(3).getClass(), StringEntry.class);
   assertEquals(entry.get(3).foo(), "B");
   assertEquals(example.entry.getClass(), IntegerEntry.class);
   assertEquals(example.entry.foo(), 777);
   persister.write(example, System.out);
   validate(persister, example);
}
 
Example #14
Source File: PathParserTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testPathPrefix() throws Exception {
   Expression expression = new PathParser("ns1:path1/ns2:path2/path3/ns3:path4[2]", new ClassType(PathParserTest.class), new Format());
   assertEquals(expression.getFirst(), "path1");
   assertEquals(expression.getPrefix(), "ns1");
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "ns1:path1/ns2:path2/path3/ns3:path4[2]");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
   
   expression = expression.getPath(1);
   assertEquals(expression.getFirst(), "path2");
   assertEquals(expression.getPrefix(), "ns2");
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "ns2:path2/path3/ns3:path4[2]");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
   
   expression = expression.getPath(1);
   assertEquals(expression.getFirst(), "path3");
   assertEquals(expression.getPrefix(), null);
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.toString(), "path3/ns3:path4[2]");
   assertTrue(expression.isPath());
   assertFalse(expression.isAttribute());
   
   expression = expression.getPath(1);
   assertEquals(expression.getFirst(), "path4");
   assertEquals(expression.getPrefix(), "ns3");
   assertEquals(expression.getLast(), "path4");
   assertEquals(expression.getIndex(), 2);
   assertEquals(expression.toString(), "ns3:path4[2]");
   assertFalse(expression.isPath());
   assertFalse(expression.isAttribute());
}
 
Example #15
Source File: PathParserTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testEmptyPath() throws Exception {
   Type type = new ClassType(PathParserTest.class);
   Expression expression = new PathParser( ".", type, new Format());
   String element = expression.getElement("a");
   assertEquals(expression.getPath(), "");
   assertEquals(element, "a");
   String attribute = expression.getAttribute("a");
   assertEquals(attribute, "a");
   assertTrue(expression.isEmpty());
   Expression single = new PathParser("name", type, new Format());
   Expression empty = single.getPath(1);
   assertTrue(empty.isEmpty());
}
 
Example #16
Source File: ElementParameter.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**   
 * Constructor for the <code>ElementParameter</code> object.
 * This is used to create a parameter that can be used to 
 * determine a consistent name using the provided XML annotation.
 * 
 * @param factory this is the constructor the parameter is in
 * @param value this is the annotation used for the parameter
 * @param format this is the format used to style the parameter
 * @param index this is the index the parameter appears at
 */
public ElementParameter(Constructor factory, Element value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new ElementLabel(contact, value, format);
   this.expression = label.getExpression();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.key = label.getKey();
   this.index = index;
}
 
Example #17
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Method called when Google API Client connects to Wearable.API.
 */
@Override
public void onConnected(final Bundle bundle) {
	// Ensure the Wearable API was connected
	if (!wearableSynchronizer.hasConnectedApi())
		return;

	if (!preferences.getBoolean(PREFS_WEAR_SYNCED, false)) {
		new Thread(() -> {
			final Cursor cursor = databaseHelper.getConfigurations();
			try {
				while (cursor.moveToNext()) {
					final long id = cursor.getLong(0 /* _ID */);
					try {
						final String xml = cursor.getString(2 /* XML */);
						final Format format = new Format(new HyphenStyle());
						final Serializer serializer = new Persister(format);
						final UartConfiguration configuration = serializer.read(UartConfiguration.class, xml);
						wearableSynchronizer.onConfigurationAddedOrEdited(id, configuration).await();
					} catch (final Exception e) {
						Log.w(TAG, "Deserializing configuration with id " + id + " failed", e);
					}
				}
				preferences.edit().putBoolean(PREFS_WEAR_SYNCED, true).apply();
			} finally {
				cursor.close();
			}
		}).start();
	}
}
 
Example #18
Source File: ElementLabel.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the <code>ElementLabel</code> object. This is
 * used to create a label that can convert a XML node into a 
 * composite object or a primitive type from an XML element. 
 * 
 * @param contact this is the field that this label represents
 * @param label this is the annotation for the contact 
 * @param format this is the format used to style this element
 */
public ElementLabel(Contact contact, Element label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.decorator = new Qualifier(contact);
   this.required = label.required();
   this.type = contact.getType();
   this.override = label.name();     
   this.expect = label.type();
   this.data = label.data();
   this.format = format;
   this.label = label; 
}
 
Example #19
Source File: ElementListParameter.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**   
 * Constructor for the <code>ElementListParameter</code> object.
 * This is used to create a parameter that can be used to 
 * determine a consistent name using the provided XML annotation.
 * 
 * @param factory this is the constructor the parameter is in
 * @param value this is the annotation used for the parameter
 * @param format this is the format used to style this parameter
 * @param index this is the index the parameter appears at
 */
public ElementListParameter(Constructor factory, ElementList value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new ElementListLabel(contact, value, format);
   this.expression = label.getExpression();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.key = label.getKey();
   this.index = index;
}
 
Example #20
Source File: CompositeListUnionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
private static Group getGroup() throws Exception {
   Field field = CompositeListUnionTest.class.getDeclaredField("EXAMPLE");
   Annotation annotation = field.getAnnotation(ElementListUnion.class);
   Annotation path = field.getAnnotation(Path.class);
   return new GroupExtractor(
         new FieldContact(field, annotation, new Annotation[]{annotation, path}),
         annotation,
         new Format());
}
 
Example #21
Source File: PathParserTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testStyledPathWithPrefixes() throws Exception {
   Type type = new ClassType(PathParserTest.class);
   Expression expression = new PathParser("pre:this/is/a/pre:path", type, new Format(new CamelCaseStyle()));
   String attributePath = expression.getAttribute("final");
   assertEquals(attributePath, "pre:This[1]/Is[1]/A[1]/pre:Path[1]/@final");
   String elementPath = expression.getElement("final");
   assertEquals(elementPath, "pre:This[1]/Is[1]/A[1]/pre:Path[1]/Final[1]");
}
 
Example #22
Source File: PathParserTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testStyledPath() throws Exception {
   Type type = new ClassType(PathParserTest.class);
   Expression expression = new PathParser( "this/is/a/path", type, new Format(new CamelCaseStyle()));
   String attributePath = expression.getAttribute("final");
   assertEquals(attributePath, "This[1]/Is[1]/A[1]/Path[1]/@final");
   String elementPath = expression.getElement("final");
   assertEquals(elementPath, "This[1]/Is[1]/A[1]/Path[1]/Final[1]");
}
 
Example #23
Source File: ConstructorInjectionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testArrayExample() throws Exception {   
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Persister persister = new Persister(format);
   ArrayExample example = persister.read(ArrayExample.class, ARRAY);
   
   assertEquals(example.getArray().length, 5);
   assertEquals(example.getArray()[0], "entry one");
   assertEquals(example.getArray()[1], "entry two");
   assertEquals(example.getArray()[2], "entry three");
   assertEquals(example.getArray()[3], "entry four");
   assertEquals(example.getArray()[4], "entry five");
   
   validate(persister, example);
}
 
Example #24
Source File: NoAnnotationsRequiredTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testTypeVerbose() throws Exception {
   Format format = new Format(Verbosity.LOW);
   Persister persister = new Persister(format);
   PrimitiveEntry entry = new PrimitiveEntry();
   StringWriter writer = new StringWriter();
   
   persister.write(entry, writer);
   validate(persister, entry);
}
 
Example #25
Source File: CompositeListUnionTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testSimpleList() throws Exception {
   Context context = getContext();
   Group group = getGroup();
   Type type = new ClassType(CompositeListUnionTest.class);
   List<Shape> list = new ArrayList<Shape>();
   Expression expression = new PathParser("some/path", type, new Format());
   CompositeListUnion union = new CompositeListUnion(
         context,
         group,
         expression,
         type);
   InputNode node = NodeBuilder.read(new StringReader(SOURCE));
   
   InputNode circle = node.getNext();
   union.read(circle, list);
   
   InputNode square = node.getNext();
   union.read(square, list);
   
   InputNode triangle = node.getNext();
   union.read(triangle, list);
   
   assertEquals(list.get(0).getClass(), Circle.class);
   assertEquals(list.get(1).getClass(), Square.class);
   assertEquals(list.get(2).getClass(), Triangle.class);
   
   OutputNode output = NodeBuilder.write(new PrintWriter(System.out), new Format(3));
   OutputNode parent = output.getChild("parent");
   
   union.write(parent, list);
}
 
Example #26
Source File: RegistryConverterTest.java    From simplexml with Apache License 2.0 5 votes vote down vote up
public void testConverter() throws Exception {
   Style style = new CamelCaseStyle();
   Format format = new Format(style);
   Registry registry = new Registry();
   Customer customer = new Customer("Niall", "Some Place");
   Envelope envelope = new Envelope(customer);
   RegistryStrategy strategy = new RegistryStrategy(registry);
   Serializer serializer = new Persister(strategy, format);
   Converter converter = new EnvelopeConverter(serializer);
   
   registry.bind(Envelope.class, converter);
   
   OrderItem order = new OrderItem(envelope);
   serializer.write(order, System.out);
}
 
Example #27
Source File: TextLabel.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the <code>TextLabel</code> object. This is
 * used to create a label that can convert a XML node into a 
 * primitive value from an XML element text value.
 * 
 * @param contact this is the contact this label represents
 * @param label this is the annotation for the contact 
 * @param format this is the format used for this label
 */
public TextLabel(Contact contact, Text label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.required = label.required();
   this.type = contact.getType();
   this.empty = label.empty();
   this.data = label.data();
   this.contact = contact;
   this.label = label;  
}
 
Example #28
Source File: AttributeLabel.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the <code>AttributeLabel</code> object. This 
 * is used to create a label that can convert from an object to an
 * XML attribute and vice versa. This requires the annotation and
 * contact extracted from the XML schema class.
 * 
 * @param contact this is the field from the XML schema class
 * @param label represents the annotation for the field
 * @param format this is the format used to style the path
 */
public AttributeLabel(Contact contact, Attribute label, Format format) {
   this.detail = new Introspector(contact, this, format);
   this.decorator = new Qualifier(contact);
   this.required = label.required();
   this.type = contact.getType();
   this.empty = label.empty();
   this.name = label.name();      
   this.format = format;
   this.label = label; 
}
 
Example #29
Source File: ElementMapParameter.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**   
 * Constructor for the <code>ElementMapParameter</code> object.
 * This is used to create a parameter that can be used to 
 * determine a consistent name using the provided XML annotation.
 * 
 * @param factory this is the constructor the parameter is in
 * @param value this is the annotation used for the parameter
 * @param format this is the format used to style this parameter
 * @param index this is the index the parameter appears at
 */
public ElementMapParameter(Constructor factory, ElementMap value, Format format, int index) throws Exception {
   this.contact = new Contact(value, factory, index);
   this.label = new ElementMapLabel(contact, value, format);
   this.expression = label.getExpression();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.key = label.getKey();
   this.index = index;
}
 
Example #30
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int position, final long id) {
	if (position > 0) { // FIXME this is called twice after rotation.
		try {
			final String xml = databaseHelper.getConfiguration(id);
			final Format format = new Format(new HyphenStyle());
			final Serializer serializer = new Persister(format);
			configuration = serializer.read(UartConfiguration.class, xml);
			configurationListener.onConfigurationChanged(configuration);
		} catch (final Exception e) {
			Log.e(TAG, "Selecting configuration failed", e);

			String message;
			if (e.getLocalizedMessage() != null)
				message = e.getLocalizedMessage();
			else if (e.getCause() != null && e.getCause().getLocalizedMessage() != null)
				message = e.getCause().getLocalizedMessage();
			else
				message = "Unknown error";
			final String msg = message;
			Snackbar.make(container, R.string.uart_configuration_loading_failed, Snackbar.LENGTH_INDEFINITE)
					.setAction(R.string.uart_action_details, v ->
							new AlertDialog.Builder(UARTActivity.this)
									.setMessage(msg)
									.setTitle(R.string.uart_action_details)
									.setPositiveButton(R.string.ok, null)
									.show())
					.show();
			return;
		}

		preferences.edit().putLong(PREFS_CONFIGURATION, id).apply();
	}
}