当前位置: 首页>>代码示例>>Java>>正文


Java Strategy类代码示例

本文整理汇总了Java中org.simpleframework.xml.strategy.Strategy的典型用法代码示例。如果您正苦于以下问题:Java Strategy类的具体用法?Java Strategy怎么用?Java Strategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Strategy类属于org.simpleframework.xml.strategy包,在下文中一共展示了Strategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRenameConfiguration

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
@Override
public void onRenameConfiguration(final String newName) {
	final boolean exists = mDatabaseHelper.configurationExists(newName);
	if (exists) {
		Toast.makeText(this, R.string.uart_configuration_name_already_taken, Toast.LENGTH_LONG).show();
		return;
	}

	final String oldName = mConfiguration.getName();
	mConfiguration.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(mConfiguration, writer);
		final String xml = writer.toString();

		mDatabaseHelper.renameConfiguration(oldName, newName, xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), mConfiguration);
		refreshConfigurations();
	} catch (final Exception e) {
		Log.e(TAG, "Error while renaming configuration", e);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:UARTActivity.java

示例2: saveConfiguration

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
/**
 * Saves the given configuration in the database.
 */
private void saveConfiguration() {
	final UartConfiguration configuration = mConfiguration;
	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();

		mDatabaseHelper.updateConfiguration(configuration.getName(), xml);
		mWearableSynchronizer.onConfigurationAddedOrEdited(mPreferences.getLong(PREFS_CONFIGURATION, 0), configuration);
	} catch (final Exception e) {
		Log.e(TAG, "Error while creating a new configuration", e);
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:20,代码来源:UARTActivity.java

示例3: getReadSerializer

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
private static Serializer getReadSerializer() throws Exception {
	if (readSerializer == null) {
	Log.d("hv", "Begin Creating Serializer");
       RegistryMatcher matcher = new RegistryMatcher();
       matcher.bind(Date.class, new DateFormatTransformer());

       Registry registry = new Registry();
       registry.bind(String.class, SimpleXMLStringConverter.class);
       Strategy strategy = new RegistryStrategy(registry);

       Serializer s = new Persister(strategy, matcher);
	Log.d("hv", "Done Creating Serializer");
	
	readSerializer = s;
	}
       return readSerializer;
}
 
开发者ID:Microsoft,项目名称:healthvault-java-sdk,代码行数:18,代码来源:XmlSerializer.java

示例4: load

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public static DefaultingModel load(String filename) {
	DefaultingModel read = null;
	Strategy strategy = new CycleStrategy("id", "ref");
	Serializer serializer = new Persister(strategy);
	File source = new File(filename);

	try {
		read = serializer.read(DefaultingModel.class, source);

		if (read != null ) {
			read.finish();
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	
	return read;
}
 
开发者ID:aroog,项目名称:code,代码行数:20,代码来源:DefaultingPersist.java

示例5: load

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public static Model load(String filename) {
	Model read = null;
	Strategy strategy = new CycleStrategy("id", "ref");
	Serializer serializer = new Persister(strategy);
	File source = new File(filename);

	try {
		read = serializer.read(Model.class, source);

		if (read != null ) {
			read.finish();
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	
	return read;
}
 
开发者ID:aroog,项目名称:code,代码行数:20,代码来源:Persist.java

示例6: load

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public static HeuristicsModel load(String filename) {
	HeuristicsModel read = null;
	Strategy strategy = new CycleStrategy("id", "ref");
	Serializer serializer = new Persister(strategy);
	File source = new File(filename);
	try {
		if (source.exists()) {
			read = serializer.read(HeuristicsModel.class, source);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	return read;
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:Persist.java

示例7: load

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public static BaseTraceability load(String filename) {
	BaseTraceability read = null;
	Strategy strategy = new CycleStrategy("id", "ref");
	Serializer serializer = new Persister(strategy);
	File source = new File(filename);

	try {
		read = serializer.read(BaseTraceability.class, source);
	}
	catch (Exception e) {
		System.err.println("Exception when loading file:"+ filename);
		e.printStackTrace();
	}

	return read;
}
 
开发者ID:aroog,项目名称:code,代码行数:17,代码来源:TestUtils.java

示例8: importRoomGroups

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
private void importRoomGroups(File f) throws Exception {
	log.info("Room import complete, starting room groups import");
	Registry registry = new Registry();
	Strategy strategy = new RegistryStrategy(registry);
	Serializer serializer = new Persister(strategy);

	registry.bind(Group.class, new GroupConverter(groupDao, groupMap));
	registry.bind(Room.class, new RoomConverter(roomDao, roomMap));

	List<RoomGroup> list = readList(serializer, f, "rooms_organisation.xml", "room_organisations", RoomGroup.class);
	for (RoomGroup ro : list) {
		Room r = roomDao.get(ro.getRoom().getId());
		if (r == null || ro.getGroup() == null || ro.getGroup().getId() == null) {
			continue;
		}
		if (r.getGroups() == null) {
			r.setGroups(new ArrayList<>());
		}
		ro.setId(null);
		ro.setRoom(r);
		r.getGroups().add(ro);
		roomDao.update(r, null);
	}
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:25,代码来源:BackupImport.java

示例9: importChat

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
private void importChat(File f) throws Exception {
	log.info("Room groups import complete, starting chat messages import");
	Registry registry = new Registry();
	Strategy strategy = new RegistryStrategy(registry);
	Serializer serializer = new Persister(strategy);

	registry.bind(User.class, new UserConverter(userDao, userMap));
	registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
	registry.bind(Date.class, DateConverter.class);

	List<ChatMessage> list = readList(serializer, f, "chat_messages.xml", "chat_messages", ChatMessage.class);
	for (ChatMessage m : list) {
		m.setId(null);
		if (m.getFromUser() == null || m.getFromUser().getId() == null) {
			continue;
		}
		chatDao.update(m, m.getSent());
	}
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:20,代码来源:BackupImport.java

示例10: importContacts

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
private void importContacts(File f) throws Exception {
	log.info("Private message folder import complete, starting user contacts import");
	Registry registry = new Registry();
	Strategy strategy = new RegistryStrategy(registry);
	Serializer serializer = new Persister(strategy);

	registry.bind(User.class, new UserConverter(userDao, userMap));

	List<UserContact> list = readList(serializer, f, "userContacts.xml", "usercontacts", UserContact.class);
	for (UserContact uc : list) {
		Long ucId = uc.getId();
		UserContact storedUC = userContactDao.get(ucId);

		if (storedUC == null && uc.getContact() != null && uc.getContact().getId() != null) {
			uc.setId(null);
			if (uc.getOwner() != null && uc.getOwner().getId() == null) {
				uc.setOwner(null);
			}
			uc = userContactDao.update(uc);
			userContactMap.put(ucId, uc.getId());
		}
	}
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:24,代码来源:BackupImport.java

示例11: importRoomFiles

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
private void importRoomFiles(File f) throws Exception {
	log.info("Poll import complete, starting room files import");
	Registry registry = new Registry();
	Strategy strategy = new RegistryStrategy(registry);
	Serializer serializer = new Persister(strategy);

	registry.bind(BaseFileItem.class, new BaseFileItemConverter(fileItemDao, fileItemMap));

	List<RoomFile> list = readList(serializer, f, "roomFiles.xml", "RoomFiles", RoomFile.class, true);
	for (RoomFile rf : list) {
		Room r = roomDao.get(roomMap.get(rf.getRoomId()));
		if (r == null || rf.getFile() == null || rf.getFile().getId() == null) {
			continue;
		}
		if (r.getFiles() == null) {
			r.setFiles(new ArrayList<>());
		}
		rf.setId(null);
		rf.setRoomId(r.getId());
		r.getFiles().add(rf);
		roomDao.update(r, null);
	}
}
 
开发者ID:apache,项目名称:openmeetings,代码行数:24,代码来源:BackupImport.java

示例12: testConverter

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public void testConverter() throws Exception {
   Strategy strategy = new AnnotationStrategy();
   Serializer serializer = new Persister(strategy);
   StringWriter buffer = new StringWriter();
   Car car = serializer.read(Car.class, SOURCE, false);
   
   assertNotNull(car);
   assertEquals(car.length, 3.3);
   assertEquals(car.color, "green");
   assertEquals(car.nrOfDoors, 2);
   assertEquals(car.furtherAttributes.get("topSpeed"), "190");
   assertEquals(car.furtherAttributes.get("brand"), "audi");
   
   serializer.write(car, System.out);
   serializer.write(car, buffer);
   
   String text = buffer.toString();
   assertElementExists(text, "/Car");
   assertElementHasAttribute(text, "/Car", "length", "3.3");
   assertElementHasAttribute(text, "/Car", "color", "green");
   assertElementHasAttribute(text, "/Car", "nrOfDoors", "2");
   assertElementHasAttribute(text, "/Car", "topSpeed", "190");
   assertElementHasAttribute(text, "/Car", "brand", "audi");
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:25,代码来源:DynamicMapOfAttributesTest.java

示例13: testWrapper

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public void testWrapper() throws Exception{
   Strategy strategy = new AnnotationStrategy();
   Serializer serializer = new Persister(strategy);
   Entry entry = new Entry("name", "value");
   EntryHolder holder = new EntryHolder(entry, "test", 10);
   StringWriter writer = new StringWriter();
   serializer.write(holder, writer);
   System.out.println(writer.toString());
   serializer.read(EntryHolder.class, writer.toString());
   System.err.println(writer.toString());
   String sourceXml = writer.toString();
   assertElementExists(sourceXml, "/entryHolder");
   assertElementHasAttribute(sourceXml, "/entryHolder", "code", "10");
   assertElementExists(sourceXml, "/entryHolder/entry");
   assertElementExists(sourceXml, "/entryHolder/entry/name");
   assertElementHasValue(sourceXml, "/entryHolder/entry/name", "name");
   assertElementExists(sourceXml, "/entryHolder/entry/value");
   assertElementHasValue(sourceXml, "/entryHolder/entry/value", "value");
   assertElementExists(sourceXml, "/entryHolder/name");
   assertElementHasValue(sourceXml, "/entryHolder/name", "test");
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:22,代码来源:HideEnclosingConverterTest.java

示例14: testEntryMap

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
public void testEntryMap() throws Exception {
   Strategy strategy = new CycleStrategy();
   Serializer serializer = new Persister(strategy);
   EntryMap example = serializer.read(EntryMap.class, ENTRY_MAP);
   
   assertEquals("example 1", example.getValue("a"));
   assertEquals("example 2", example.getValue("b"));
   assertEquals("example 1", example.getValue("c"));
   assertEquals("example 1", example.getValue("d"));
   
   MapEntry a = example.getEntry("a");
   MapEntry b = example.getEntry("b");
   MapEntry c = example.getEntry("c");      
   MapEntry d = example.getEntry("d");
   
   assertTrue(a == c);
   assertTrue(c == d);
   assertFalse(a == b);
   
   validate(example, serializer);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:22,代码来源:MapCycleTest.java

示例15: testEmptyMapEntry

import org.simpleframework.xml.strategy.Strategy; //导入依赖的package包/类
/**
 * @param args the command line arguments
 */
public void testEmptyMapEntry() throws Exception {
    Strategy resolver = new CycleStrategy("id", "ref");
    Serializer s = new Persister(resolver);
    StringWriter w = new StringWriter();
    SimpleBug1 bug1 = new SimpleBug1();
    
    assertEquals(bug1.test1.data.get("key1"), "value1");
    assertEquals(bug1.test1.data.get("key2"), "value1");
    assertEquals(bug1.test1.data.get("key3"), "");
    assertEquals(bug1.test1.data.get(""), "");
    
    s.write(bug1, w);
    System.err.println(w.toString());

    SimpleBug1 bug2 = s.read(SimpleBug1.class, w.toString());

    assertEquals(bug1.test1.data.get("key1"), bug2.test1.data.get("key1"));
    assertEquals(bug1.test1.data.get("key2"), bug2.test1.data.get("key2"));       
    assertEquals(bug2.test1.data.get("key1"), "value1");
    assertEquals(bug2.test1.data.get("key2"), "value1");
    assertNull(bug2.test1.data.get("key3"));
    assertNull(bug2.test1.data.get(null));
    
    validate(s, bug1);
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:29,代码来源:EmptyMapEntryTest.java


注:本文中的org.simpleframework.xml.strategy.Strategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。