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


Java Mirror类代码示例

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


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

示例1: getField

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
public static Optional<Field> getField(Object base, String fieldName) {

    if (declaredFieldCache.containsKey(base.getClass())
            && declaredFieldCache.get(base.getClass()).containsKey(fieldName)) {

      return declaredFieldCache.get(base.getClass()).get(fieldName);
    } else {

      Optional<Field> fieldFound = new Mirror().on(base.getClass())
              .reflectAll().fields()
              .matching(field -> field.getName().equals(fieldName))
              .stream().findFirst();

      if (declaredFieldCache.containsKey(base.getClass())) {
        declaredFieldCache.get(base.getClass()).put(fieldName, fieldFound);
      } else {
        Map<String, Optional<Field>> fieldClass = new HashMap<>();
        fieldClass.put(fieldName, fieldFound);

        declaredFieldCache.put(base.getClass(), fieldClass);
      }

      return fieldFound;
    }

  }
 
开发者ID:mmaico,项目名称:ddd-reflection,代码行数:27,代码来源:ReflectionUtils.java

示例2: getChildren

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
public static List<ChildNode> getChildren(Object base) {
  Collection<String> fieldsToUpdate = getAttributesToUpdateDeclared(base);

  List<Field> fieldsFound = new Mirror().on(base.getClass())
          .reflectAll().fields()
          .matching(field -> !PrimitiveTypeFields.getInstance().contains(field.getType())
                  && field.getAnnotation(UpdateAttributes.class) == null);

  if (fieldsToUpdate.isEmpty()) {
      return fieldsFound.stream().map(field -> getChildNode(field))
            .collect(Collectors.toList());
  } else {
      return fieldsFound.stream().filter(field -> fieldsToUpdate.contains(field.getName()))
              .map(field -> getChildNode(field))
            .collect(Collectors.toList());
  }

}
 
开发者ID:mmaico,项目名称:ddd-reflection,代码行数:19,代码来源:ReflectionCloneUtils.java

示例3: intercept

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@Override
public void intercept(InterceptorStack stack, ControllerMethod method,
		Object obj) throws InterceptionException {
	ClassController<KarmaCalculator> mirrorOnKarma = new Mirror().on(KarmaCalculator.class);
	List<Field> karmaCalculatorFields = mirrorOnKarma.reflectAll().fields();
		
	for (Field field : karmaCalculatorFields) {
		result.include(field.getName(), mirrorOnKarma.get().field(field));
	}
	
	PermissionRules[] rules = PermissionRules.values();
	for (PermissionRules rule : rules) {
		long karma = environmentKarma.get(rule);
		result.include(rule.name(), karma);
	}

	stack.next(method, obj);
}
 
开发者ID:caelum,项目名称:mamute,代码行数:19,代码来源:RulesInterceptor.java

示例4: should_search_by_email_and_legacy_password_and_update_password

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@Test
public void should_search_by_email_and_legacy_password_and_update_password() {
    String password = "654321";
       User gui = user("Guilherme Sonar", "[email protected]");
	LoginMethod brutalLogin = LoginMethod.brutalLogin(gui, "[email protected]", password);
    new Mirror().on(brutalLogin).set().field("token").withValue(MD5.crypt(password));

    gui.add(brutalLogin);
    users.save(gui);
    session.save(brutalLogin);
    
    assertNull(users.findByMailAndPassword("[email protected]", password));
    
    User found = users.findByMailAndLegacyPasswordAndUpdatePassword("[email protected]", password);
    
       assertEquals(gui, found);
    assertEquals(Digester.encrypt(password), found.getBrutalLogin().getToken());
    
    assertNull(users.findByMailAndPassword("[email protected]", password));
    assertNull(users.findByMailAndPassword("[email protected]", "123456"));
}
 
开发者ID:caelum,项目名称:mamute,代码行数:22,代码来源:UserDAOTest.java

示例5: configure

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
private void configure(NodeManager manager, ApplicationContext context)
{
    Mirror mirror = new Mirror();

    for (Field field : manager.getClass().getDeclaredFields())
    {
        if (field.isAnnotationPresent(Autowired.class))
        {
            mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
        }
        else if (field.isAnnotationPresent(Resource.class))
        {
            Resource resource = field.getAnnotation(Resource.class);
            if (!isNullOrEmpty(resource.name()))
            {
                mirror.on(manager).set().field(field).withValue(context.getBean(resource.name()));
            }
            else
            {
                mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
            }
        }
    }
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:25,代码来源:CreateNodeManagerHandler.java

示例6: apply

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Iterable<T> apply(final Iterable<T> input) 
{
	if (input == null) 
	{
		return input;
	}
	
	Iterable<T> result = new Mirror().on(input.getClass()).invoke().constructor().withoutArgs();
	
	for (T t: input)
	{
		new Mirror().on(result).invoke().method("add").withArgs(Objects2.clone(t));
	}
	
	return result;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:19,代码来源:CloneIterableFunction.java

示例7: shouldDeserializeFromGenericTypeTwoParams

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@Test
public void shouldDeserializeFromGenericTypeTwoParams() {
	InputStream stream = asStream("{'entity':{'name':'Brutus','age':7,'birthday':'2013-07-23T17:14:14-03:00'}, 'param': 'test', 'over': 'value'}");
	BeanClass resourceClass = new DefaultBeanClass(DogGenericController.class);
	Method method = new Mirror().on(DogGenericController.class).reflect().method("anotherMethod").withAnyArgs();
	ControllerMethod resource = new DefaultControllerMethod(resourceClass, method);
	
	Object[] deserialized = deserializer.deserialize(stream, resource);

	Dog dog = (Dog) deserialized[0];
	String param = (String) deserialized[1];

	assertThat(dog.name, equalTo("Brutus"));
	assertThat(param, equalTo("test"));
	assertThat(deserialized.length, equalTo(2));
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:17,代码来源:GsonDeserializerTest.java

示例8: invoke

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
private String invoke(Object obj, String methodName, Object...args) throws Throwable {
	Class<?>[] types = extractTypes(args);
	
	try {
		Method method = null;
		for (int length = types.length; length >= 0; length--) {
			method = new Mirror().on(obj.getClass()).reflect().method(methodName)
				.withArgs(Arrays.copyOf(types, length));
			if (method != null) 
				break;
		}
		
		if (methodName.startsWith("get")) {
			return method.invoke(obj).toString();
		}
		return new Mirror().on(obj).invoke().method(method).withArgs(args).toString();
	} catch (MirrorException | InvocationTargetException e) {
		throw e.getCause() == null? e : e.getCause();
	}
}
 
开发者ID:caelum,项目名称:vraptor4,代码行数:21,代码来源:LinkToHandlerTest.java

示例9: getBluetoothAdapterAddress

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
private static String getBluetoothAdapterAddress(BluetoothAdapter bluetoothAdapter) {
    @SuppressLint("HardwareIds") // Pair-free peer-to-peer communication should qualify as an "advanced telephony use case".
    String address = bluetoothAdapter.getAddress();
    if (address.equals(FAKE_MAC_ADDRESS)) {
        Log.w(TAG, "bluetoothAdapter.getAddress() did not return the physical address");

        // HACK HACK HACK: getAddress is intentionally broken (but not deprecated?!) on Marshmallow and up:
        //   * https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-notifications
        //   * https://code.google.com/p/android/issues/detail?id=197718
        // However, we need it to establish pair-free Bluetooth Classic connections:
        //   * All BLE advertisements include a MAC address, but Android broadcasts a temporary, randomly-generated address.
        //   * Currently, it is only possible to listen for connections using the device's physical address.
        // So we use reflection to get it anyway: http://stackoverflow.com/a/35984808
        // This hack won't be necessary if getAddress is ever fixed (unlikely) or (preferably) we can listen using an arbitrary address.

        Object bluetoothManagerService = new Mirror().on(bluetoothAdapter).get().field("mService");
        if (bluetoothManagerService == null) {
            Log.w(TAG, "Couldn't retrieve bluetoothAdapter.mService using reflection");
            return null;
        }

        Object internalAddress = new Mirror().on(bluetoothManagerService).invoke().method("getAddress").withoutArgs();
        if (internalAddress == null || !(internalAddress instanceof String)) {
            Log.w(TAG, "Couldn't call bluetoothAdapter.mService.getAddress() using reflection");
            return null;
        }

        address = (String) internalAddress;
    }

    return address;
}
 
开发者ID:aarmea,项目名称:noise,代码行数:33,代码来源:BluetoothSyncService.java

示例10: getFields

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
public static List<Field> getFields(Object base) {

    if (declaredFieldsCache.get(base.getClass()) == null) {
      MirrorList<Field> fields = new Mirror().on(base.getClass())
              .reflectAll().fields()
              .matching(field -> PrimitiveTypeFields.getInstance().contains(field.getType()));
      declaredFieldsCache.put(base.getClass(), fields);
      return fields;
    }

    return declaredFieldsCache.get(base.getClass());
  }
 
开发者ID:mmaico,项目名称:ddd-reflection,代码行数:13,代码来源:ReflectionUtils.java

示例11: getChildWithCustomConverter

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
public static List<Field> getChildWithCustomConverter(Object origin) {
  return new Mirror().on(origin.getClass()).reflectAll()
          .fields().matching(field -> {
              Attribute annotation = field.getAnnotation(Attribute.class);
              if (annotation != null && !annotation.converter().isInterface()) {
                return Boolean.TRUE;
              } else {
                return Boolean.FALSE;
              }
          });
}
 
开发者ID:mmaico,项目名称:ddd-reflection,代码行数:12,代码来源:ReflectionCloneUtils.java

示例12: setUp

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@Before
public void setUp() {
    when(module.abbreviation()).thenReturn("FooCategory");
    when(moduleConfiguration.getModule()).thenReturn(module);
    ParameterEntity        userParameterEntity = new ParameterEntity();
    userParameterEntity.setValue("USER");
    Mockito.when(parameterService.findByNameAndModule(DatabaseAdminCredentialChecker.PARAM_ADMINUSERNAME, "FooCategory")).thenReturn(Optional.of(userParameterEntity));
    ParameterEntity passParameterEntity = new ParameterEntity();
    passParameterEntity.setValue(credentialChecker.getSHA1("123456"));
    Mockito.when(parameterService.findByNameAndModule(DatabaseAdminCredentialChecker.PARAM_PASSHASHADMIN, "FooCategory")).thenReturn(Optional.of(passParameterEntity));
    new Mirror().on(credentialChecker).set().field("parameterService").withValue(parameterService);

    administrationAuthenticationProvider = new AdministrationAuthenticationProvider(credentialChecker, ServerContext.WORKLIST);
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:15,代码来源:AdministrationAuthenticationProviderTest.java

示例13: testCheckWithModule

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
@Test
public void testCheckWithModule() {
    when(module.abbreviation()).thenReturn("FooCategory");

    ParameterEntity  userParameterEntity = new ParameterEntity();
    userParameterEntity.setValue("FooUser");
    Mockito.when(parameterService.findByNameAndModule(DatabaseAdminCredentialChecker.PARAM_ADMINUSERNAME, "FooCategory")).thenReturn(Optional.of(userParameterEntity));
    ParameterEntity passParameterEntity = new ParameterEntity();
    passParameterEntity.setValue(credentialChecker.getSHA1("BarPass"));
    Mockito.when(parameterService.findByNameAndModule(DatabaseAdminCredentialChecker.PARAM_PASSHASHADMIN, "FooCategory")).thenReturn(Optional.of(passParameterEntity));
    new Mirror().on(credentialChecker).set().field("parameterService").withValue(parameterService);

    Assert.assertTrue(credentialChecker.check("FooUser", "BarPass"));
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:15,代码来源:AdminCredentialCheckerTest.java

示例14: registerMockitoTestClassMocksAndSpies

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
private void registerMockitoTestClassMocksAndSpies(ApplicationContextMock applicationContext) {
    new Mirror().on(myTestClass.getClass()).reflectAll().fields().matching(f -> f.isAnnotationPresent(Mock.class) || f.isAnnotationPresent(Spy.class)).forEach(
            f -> {
                try {
                    applicationContext.putOrReplaceBean(f.get(myTestClass));
                } catch (IllegalAccessException e) {
                    getLogger().trace(e.getMessage(), e);
                }
            }
    );
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:12,代码来源:SingularServerSpringMockitoTestConfig.java

示例15: registerMockBean

import net.vidageek.mirror.dsl.Mirror; //导入依赖的package包/类
private void registerMockBean(ApplicationContextMock applicationContext, Class<?> targetClass) {
    new Mirror().on(targetClass).reflectAll().methods().matching(element -> element.isAnnotationPresent(Bean.class)).forEach(m -> {
        if (m.getParameterCount() == 0) {
            try {
                applicationContext.putOrReplaceBean(m.invoke(Mockito.spy(targetClass)));
            } catch (Exception e) {
                getLogger().trace(e.getMessage(), e);
            }
        }
    });
}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:12,代码来源:SingularServerSpringMockitoTestConfig.java


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